~ubuntu-branches/ubuntu/vivid/dovecot/vivid

« back to all changes in this revision

Viewing changes to src/lib-imap/imap-parser.h

  • Committer: Bazaar Package Importer
  • Author(s): Jaldhar H. Vyas
  • Date: 2005-11-05 23:19:19 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20051105231919-ydujs4y7687fpor2
Tags: upstream-1.0.alpha4
ImportĀ upstreamĀ versionĀ 1.0.alpha4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef __IMAP_PARSER_H
2
2
#define __IMAP_PARSER_H
3
3
 
 
4
/* FIXME: we don't have ']' here due to FETCH BODY[] handling failing
 
5
   with it.. also '%' and '*' are banned due to LIST, and '\' due to it being
 
6
   in flags. oh well.. */
 
7
#define IS_ATOM_SPECIAL(c) \
 
8
        ((c) == '(' || (c) == ')' || (c) == '{' || \
 
9
         (c) == '"' || (c) <= 32 || (c) == 0x7f)
 
10
 
4
11
enum imap_parser_flags {
5
12
        /* Set this flag if you wish to read only size of literal argument
6
13
           and not convert literal into string. Useful when you need to deal
46
53
         (arg)->type == IMAP_ARG_LITERAL ? \
47
54
         (arg)->_data.str : _imap_arg_str_error(arg))
48
55
 
 
56
#define IMAP_ARG_STR_NONULL(arg) \
 
57
        ((arg)->type == IMAP_ARG_ATOM || (arg)->type == IMAP_ARG_STRING || \
 
58
         (arg)->type == IMAP_ARG_LITERAL ? \
 
59
         (arg)->_data.str : _imap_arg_str_error(arg))
 
60
 
49
61
#define IMAP_ARG_LITERAL_SIZE(arg) \
50
62
        (((arg)->type == IMAP_ARG_LITERAL_SIZE || \
51
63
         (arg)->type == IMAP_ARG_LITERAL_SIZE_NONSYNC) ? \
60
72
        struct imap_arg args[1]; /* variable size */
61
73
};
62
74
 
63
 
/* Create new IMAP argument parser. There's no limit in argument sizes, only
64
 
   the maximum buffer size of input stream limits it. max_literal_size limits
65
 
   the maximum size of internally handled literals (ie. FLAG_LITERAL_SIZE is
66
 
   unset). max_elements sets the number of elements we allow entirely so that
67
 
   user can't give huge lists or lists inside lists. output is used for sending
68
 
   command continuation requests for literals. */
 
75
/* Create new IMAP argument parser. output is used for sending command
 
76
   continuation requests for literals.
 
77
 
 
78
   max_line_size can be used to approximately limit the maximum amount of
 
79
   memory that gets allocated when parsing a line. Input buffer size limits
 
80
   the maximum size of each parsed token.
 
81
 
 
82
   Usually the largest lines are large only because they have a one huge
 
83
   message set token, so you'll probably want to keep input buffer size the
 
84
   same as max_line_size. That means the maximum memory usage is around
 
85
   2 * max_line_size. */
69
86
struct imap_parser *
70
87
imap_parser_create(struct istream *input, struct ostream *output,
71
 
                   size_t max_literal_size, size_t max_elements);
 
88
                   size_t max_line_size);
72
89
void imap_parser_destroy(struct imap_parser *parser);
73
90
 
74
91
/* Reset the parser to initial state. */
81
98
 
82
99
/* Read a number of arguments. This function doesn't call i_stream_read(), you
83
100
   need to do that. Returns number of arguments read (may be less than count
84
 
   in case of EOL), -2 if more data is needed or -1 if error occured.
 
101
   in case of EOL), -2 if more data is needed or -1 if error occurred.
85
102
 
86
103
   count-sized array of arguments are stored into args when return value is
87
104
   0 or larger. If all arguments weren't read, they're set to NIL. count
90
107
int imap_parser_read_args(struct imap_parser *parser, unsigned int count,
91
108
                          enum imap_parser_flags flags, struct imap_arg **args);
92
109
 
 
110
/* just like imap_parser_read_args(), but assume \n at end of data in
 
111
   input stream. */
 
112
int imap_parser_finish_line(struct imap_parser *parser, unsigned int count,
 
113
                            enum imap_parser_flags flags,
 
114
                            struct imap_arg **args);
 
115
 
93
116
/* Read one word - used for reading tag and command name.
94
117
   Returns NULL if more data is needed. */
95
118
const char *imap_parser_read_word(struct imap_parser *parser);
96
119
 
97
 
/* Read the rest of the line. Returns NULL if more data is needed. */
98
 
const char *imap_parser_read_line(struct imap_parser *parser);
99
 
 
100
120
/* Returns the imap argument as string. NIL returns "" and list returns NULL. */
101
121
const char *imap_arg_string(struct imap_arg *arg);
102
122