Split camel-imapx library and merge into camel so that providers can be written on...
[platform/upstream/evolution-data-server.git] / camel / camel-imapx-stream.h
1 /*
2  *  Copyright (C) 2000 Ximian Inc.
3  *
4  *  Authors: Michael Zucchi <notzed@ximian.com>
5  *
6  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of version 2 of the GNU Lesser General Public
10  * License as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
24 #error "Only <camel/camel.h> can be included directly."
25 #endif
26
27
28 #ifndef CAMEL_IMAPX_STREAM_H
29 #define CAMEL_IMAPX_STREAM_H
30
31 #include <camel/camel-stream.h>
32
33 /* Standard GObject macros */
34 #define CAMEL_TYPE_IMAPX_STREAM \
35         (camel_imapx_stream_get_type ())
36 #define CAMEL_IMAPX_STREAM(obj) \
37         (G_TYPE_CHECK_INSTANCE_CAST \
38         ((obj), CAMEL_TYPE_IMAPX_STREAM, CamelIMAPXStream))
39 #define CAMEL_IMAPX_STREAM_CLASS(cls) \
40         (G_TYPE_CHECK_CLASS_CAST \
41         ((cls), CAMEL_TYPE_IMAPX_STREAM, CamelIMAPXStreamClass))
42 #define CAMEL_IS_IMAPX_STREAM(obj) \
43         (G_TYPE_CHECK_INSTANCE_TYPE \
44         ((obj), CAMEL_TYPE_IMAPX_STREAM))
45 #define CAMEL_IS_IMAPX_STREAM_CLASS(cls) \
46         (G_TYPE_CHECK_CLASS_TYPE \
47         ((cls), CAMEL_TYPE_IMAPX_STREAM))
48 #define CAMEL_IMAPX_STREAM_GET_CLASS(obj) \
49         (G_TYPE_INSTANCE_GET_CLASS \
50         ((obj), CAMEL_TYPE_IMAPX_STREAM, CamelIMAPXStreamClass))
51
52 #define CAMEL_IMAPX_ERROR \
53         (camel_imapx_error_quark ())
54
55 G_BEGIN_DECLS
56
57 typedef struct _CamelIMAPXStream CamelIMAPXStream;
58 typedef struct _CamelIMAPXStreamClass CamelIMAPXStreamClass;
59
60 typedef enum {
61         IMAPX_TOK_PROTOCOL = -2,
62         IMAPX_TOK_ERROR = -1,
63         IMAPX_TOK_TOKEN = 256,
64         IMAPX_TOK_STRING,
65         IMAPX_TOK_INT,
66         IMAPX_TOK_LITERAL,
67 } camel_imapx_token_t;
68
69 struct _CamelIMAPXStream {
70         CamelStream parent;
71
72         CamelStream *source;
73         gchar tagprefix; /* For debugging output */
74
75         /*int state;*/
76         guchar *buf, *ptr, *end;
77         guint literal;
78
79         guint unget;
80         camel_imapx_token_t unget_tok;
81         guchar *unget_token;
82         guint unget_len;
83
84         guchar *tokenbuf;
85         guint bufsize;
86 };
87
88 struct _CamelIMAPXStreamClass {
89         CamelStreamClass parent_class;
90 };
91
92 GType           camel_imapx_stream_get_type     (void);
93 GQuark          camel_imapx_error_quark         (void) G_GNUC_CONST;
94 CamelStream *   camel_imapx_stream_new          (CamelStream *source);
95 gint            camel_imapx_stream_buffered     (CamelIMAPXStream *is);
96
97 /* throws IO,PARSE exception */
98 camel_imapx_token_t
99                 camel_imapx_stream_token        (CamelIMAPXStream *is,
100                                                  guchar **start,
101                                                  guint *len,
102                                                  GCancellable *cancellable,
103                                                  GError **error);
104
105 void            camel_imapx_stream_ungettoken   (CamelIMAPXStream *is,
106                                                  camel_imapx_token_t tok,
107                                                  guchar *token,
108                                                  guint len);
109 void            camel_imapx_stream_set_literal  (CamelIMAPXStream *is,
110                                                  guint literal);
111 gint            camel_imapx_stream_gets         (CamelIMAPXStream *is,
112                                                  guchar **start,
113                                                  guint *len,
114                                                  GCancellable *cancellable,
115                                                  GError **error);
116 gint             camel_imapx_stream_getl        (CamelIMAPXStream *is,
117                                                  guchar **start,
118                                                  guint *len,
119                                                  GCancellable *cancellable,
120                                                  GError **error);
121
122 /* all throw IO,PARSE exceptions */
123
124 /* gets an atom, upper-cases */
125 gint            camel_imapx_stream_atom         (CamelIMAPXStream *is,
126                                                  guchar **start,
127                                                  guint *len,
128                                                  GCancellable *cancellable,
129                                                  GError **error);
130 /* gets an atom or string */
131 gint            camel_imapx_stream_astring      (CamelIMAPXStream *is,
132                                                  guchar **start,
133                                                  GCancellable *cancellable,
134                                                  GError **error);
135 /* gets a NIL or a string, start==NULL if NIL */
136 gint            camel_imapx_stream_nstring      (CamelIMAPXStream *is,
137                                                  guchar **start,
138                                                  GCancellable *cancellable,
139                                                  GError **error);
140 /* gets a NIL or string into a stream, stream==NULL if NIL */
141 gint            camel_imapx_stream_nstring_stream
142                                                 (CamelIMAPXStream *is,
143                                                  CamelStream **stream,
144                                                  GCancellable *cancellable,
145                                                  GError **error);
146 /* gets 'text' */
147 gint            camel_imapx_stream_text         (CamelIMAPXStream *is,
148                                                  guchar **text,
149                                                  GCancellable *cancellable,
150                                                  GError **error);
151
152 /* gets a 'number' */
153 guint64          camel_imapx_stream_number      (CamelIMAPXStream *is,
154                                                  GCancellable *cancellable,
155                                                  GError **error);
156
157 /* skips the rest of a line, including literals, etc */
158 gint            camel_imapx_stream_skip         (CamelIMAPXStream *is,
159                                                  GCancellable *cancellable,
160                                                  GError **error);
161
162 G_END_DECLS
163
164 #endif /* CAMEL_IMAPX_STREAM_H */