#ifndef __MANAGESIEVE_ARG_H
#define __MANAGESIEVE_ARG_H
#include "array.h"
#define IS_QUOTED_SPECIAL(c) \
((c) == '"' || (c) == '\\')
#define IS_ATOM_SPECIAL(c) \
((c) == '(' || (c) == ')' || (c) == '{' || \
(c) <= 32 || (c) == 0x7f || \
IS_QUOTED_SPECIAL(c))
#define IS_CHAR(c) \
(((c) & 0x80) == 0)
#define IS_TEXT_CHAR(c) \
(IS_CHAR(c) && (c) != '\r' && (c) != '\n')
#define IS_SAFE_CHAR(c) \
(IS_TEXT_CHAR(c) && !IS_QUOTED_SPECIAL(c))
enum managesieve_arg_type {
MANAGESIEVE_ARG_NONE = 0,
MANAGESIEVE_ARG_ATOM,
MANAGESIEVE_ARG_STRING,
MANAGESIEVE_ARG_STRING_STREAM,
MANAGESIEVE_ARG_LIST,
MANAGESIEVE_ARG_LITERAL,
MANAGESIEVE_ARG_EOL
};
ARRAY_DEFINE_TYPE(managesieve_arg_list, struct managesieve_arg);
struct managesieve_arg {
enum managesieve_arg_type type;
struct managesieve_arg *parent;
size_t str_len;
union {
const char *str;
struct istream *str_stream;
ARRAY_TYPE(managesieve_arg_list) list;
} _data;
};
#define MANAGESIEVE_ARG_IS_EOL(arg) \
((arg)->type == MANAGESIEVE_ARG_EOL)
bool managesieve_arg_get_atom
(const struct managesieve_arg *arg, const char **str_r)
ATTR_WARN_UNUSED_RESULT;
bool managesieve_arg_get_number
(const struct managesieve_arg *arg, uoff_t *number_r)
ATTR_WARN_UNUSED_RESULT;
bool managesieve_arg_get_quoted
(const struct managesieve_arg *arg, const char **str_r)
ATTR_WARN_UNUSED_RESULT;
bool managesieve_arg_get_string
(const struct managesieve_arg *arg, const char **str_r)
ATTR_WARN_UNUSED_RESULT;
bool managesieve_arg_get_string_stream
(const struct managesieve_arg *arg, struct istream **stream_r)
ATTR_WARN_UNUSED_RESULT;
bool managesieve_arg_get_list
(const struct managesieve_arg *arg, const struct managesieve_arg **list_r)
ATTR_WARN_UNUSED_RESULT;
bool managesieve_arg_get_list_full
(const struct managesieve_arg *arg, const struct managesieve_arg **list_r,
unsigned int *list_count_r)
ATTR_WARN_UNUSED_RESULT;
struct istream *managesieve_arg_as_string_stream
(const struct managesieve_arg *arg);
const struct managesieve_arg *managesieve_arg_as_list
(const struct managesieve_arg *arg);
bool managesieve_arg_atom_equals
(const struct managesieve_arg *arg, const char *str);
#endif