1 /* imapparse.h -- Header for IMAP parsing functions
2  *
3  * Copyright (c) 1994-2012 Carnegie Mellon University.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * 3. The name "Carnegie Mellon University" must not be used to
18  *    endorse or promote products derived from this software without
19  *    prior written permission. For permission or any legal
20  *    details, please contact
21  *      Carnegie Mellon University
22  *      Center for Technology Transfer and Enterprise Creation
23  *      4615 Forbes Avenue
24  *      Suite 302
25  *      Pittsburgh, PA  15213
26  *      (412) 268-7393, fax: (412) 268-7395
27  *      innovation@andrew.cmu.edu
28  *
29  * 4. Redistributions of any form whatsoever must retain the following
30  *    acknowledgment:
31  *    "This product includes software developed by Computing Services
32  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33  *
34  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41  */
42 
43 #ifndef __CYRUS_IMAP_PARSE_H__
44 #define __CYRUS_IMAP_PARSE_H__
45 
46 #include "libconfig.h"
47 #include "prot.h"
48 #include "index.h"
49 
50 /* imap parsing functions (imapparse.c) */
51 int getword(struct protstream *in, struct buf *buf);
52 
53 /* Flags for getxstring() */
54 /* IMAP_BIN_ASTRING is an IMAP_ASTRING that does not perform the
55  * does-not-contain-a-NULL check (in the case of a literal) */
56 enum getxstring_flags {
57     GXS_ATOM    = (1<<0),   /* result may be a bare atom */
58     GXS_QUOTED  = (1<<1),   /* result may be "quoted" */
59     GXS_LITERAL = (1<<2),   /* result may be {N}literal */
60     GXS_NIL     = (1<<3),   /* result may be the special atom NIL */
61     GXS_BINARY  = (1<<4),   /* result may contain embedded NULs */
62 
63     IMAP_ASTRING = GXS_ATOM|GXS_QUOTED|GXS_LITERAL,
64     IMAP_BIN_ASTRING = IMAP_ASTRING|GXS_BINARY,
65     IMAP_NSTRING = GXS_NIL|GXS_QUOTED|GXS_LITERAL,
66     IMAP_BIN_NSTRING = IMAP_NSTRING|GXS_BINARY,
67     IMAP_QSTRING = GXS_QUOTED,
68     IMAP_STRING = GXS_QUOTED|GXS_LITERAL,
69 
70     /* note: there's some consistency issues here... the special
71      * value "NIL" must be quoted to get returned as a string */
72     IMAP_NASTRING = GXS_NIL|GXS_ATOM|GXS_QUOTED|GXS_LITERAL,
73 };
74 
75 int getxstring(struct protstream *pin, struct protstream *pout,
76                struct buf *buf, enum getxstring_flags);
77 #define getastring(pin, pout, buf) getxstring((pin), (pout), (buf), IMAP_ASTRING)
78 #define getbastring(pin, pout, buf) getxstring((pin), (pout), (buf), IMAP_BIN_ASTRING)
79 #define getnstring(pin, pout, buf) getxstring((pin), (pout), (buf), IMAP_NSTRING)
80 #define getbnstring(pin, pout, buf) getxstring((pin), (pout), (buf), IMAP_BIN_NSTRING)
81 #define getqstring(pin, pout, buf) getxstring((pin), (pout), (buf), IMAP_QSTRING)
82 #define getstring(pin, pout, buf) getxstring((pin), (pout), (buf), IMAP_STRING)
83 #define getnastring(pin, pout, buf) getxstring((pin), (pout), (buf), IMAP_NASTRING)
84 #define getcharset(pin, pout, buf) getxstring((pin), (pout), (buf), GXS_ATOM|GXS_QUOTED)
85 int getint32(struct protstream *pin, int *num);
86 int getint64(struct protstream *pin, int64_t *num);
87 int getsint32(struct protstream *pin, int *num);
88 int getsint64(struct protstream *pin, int64_t *num);
89 int getuint32(struct protstream *pin, unsigned int *num);
90 int getuint64(struct protstream *pin, uint64_t *num);
91 int getmodseq(struct protstream *pin, modseq_t *num);
92 
93 void eatline(struct protstream *pin, int c);
94 
95 int get_search_program(struct protstream *pin, struct protstream *pout,
96                        struct searchargs *searchargs);
97 int get_search_return_opts(struct protstream *pin, struct protstream *pout,
98                            struct searchargs *searchargs);
99 
100 #endif /* __CYRUS_IMAP_PARSE_H__ */
101