summaryrefslogtreecommitdiff
path: root/camel/providers/imap/camel-imapx-stream.h
blob: b565b4ccd9d1b6718323cbd86f80ade5e28bdadc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 *  Copyright (C) 2000 Ximian Inc.
 *
 *  Authors: Michael Zucchi <notzed@ximian.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef _CAMEL_IMAPX_STREAM_H
#define _CAMEL_IMAPX_STREAM_H

#include <camel/camel-stream.h>

#define CAMEL_IMAPX_STREAM(obj)         CAMEL_CHECK_CAST (obj, camel_imapx_stream_get_type (), CamelIMAPXStream)
#define CAMEL_IMAPX_STREAM_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_imapx_stream_get_type (), CamelIMAPXStreamClass)
#define CAMEL_IS_IMAPX_STREAM(obj)      CAMEL_CHECK_TYPE (obj, camel_imapx_stream_get_type ())

typedef struct _CamelIMAPXStreamClass CamelIMAPXStreamClass;
typedef struct _CamelIMAPXStream CamelIMAPXStream;

typedef enum {
	IMAP_TOK_PROTOCOL = -2,
	IMAP_TOK_ERROR = -1,
	IMAP_TOK_TOKEN = 256,
	IMAP_TOK_STRING,
	IMAP_TOK_INT,
	IMAP_TOK_LITERAL,
} camel_imapx_token_t;

struct _CamelIMAPXStream {
	CamelStream parent;

	CamelStream *source;

	/*int state;*/
	unsigned char *buf, *ptr, *end;
	unsigned int literal;

	unsigned int unget;
	camel_imapx_token_t unget_tok;
	unsigned char *unget_token;
	unsigned int unget_len;

	unsigned char *tokenbuf, *tokenptr, *tokenend;
};

struct _CamelIMAPXStreamClass {
	CamelStreamClass parent_class;
};

CamelType	 camel_imapx_stream_get_type	(void);

CamelStream     *camel_imapx_stream_new		(CamelStream *source);

int 		 camel_imapx_stream_buffered	(CamelIMAPXStream *is);

camel_imapx_token_t camel_imapx_stream_token	(CamelIMAPXStream *is, unsigned char **start, unsigned int *len); /* throws IO,PARSE exception */
void		 camel_imapx_stream_ungettoken	(CamelIMAPXStream *is, camel_imapx_token_t tok, unsigned char *token, unsigned int len);

void		 camel_imapx_stream_set_literal	(CamelIMAPXStream *is, unsigned int literal);
int 		 camel_imapx_stream_gets		(CamelIMAPXStream *is, unsigned char **start, unsigned int *len);
int 		 camel_imapx_stream_getl		(CamelIMAPXStream *is, unsigned char **start, unsigned int *len);

/* all throw IO,PARSE exceptions */

/* gets an atom, upper-cases */
int		 camel_imapx_stream_atom		(CamelIMAPXStream *is, unsigned char **start, unsigned int *len);
/* gets an atom or string */
int		 camel_imapx_stream_astring	(CamelIMAPXStream *is, unsigned char **start);
/* gets a NIL or a string, start==NULL if NIL */
int		 camel_imapx_stream_nstring	(CamelIMAPXStream *is, unsigned char **start);
/* gets a NIL or string into a stream, stream==NULL if NIL */
int		 camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream);
/* gets 'text' */
int		 camel_imapx_stream_text		(CamelIMAPXStream *is, unsigned char **text);

/* gets a 'number' */
guint32		 camel_imapx_stream_number(CamelIMAPXStream *is);

/* skips the rest of a line, including literals, etc */
int camel_imapx_stream_skip(CamelIMAPXStream *is);

#endif /* ! _CAMEL_IMAPX_STREAM_H */