aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap4/camel-imap4-stream.h
blob: c0f870a0bd1f3b2e34712194583fb40d3ca51165 (plain) (blame)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*  Camel
 *  Copyright (C) 1999-2004 Jeffrey Stedfast
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  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 Street #330, Boston, MA 02111-1307, USA.
 */


#ifndef __CAMEL_IMAP4_STREAM_H__
#define __CAMEL_IMAP4_STREAM_H__

#include <camel/camel-stream.h>

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#define CAMEL_TYPE_IMAP4_STREAM     (camel_imap4_stream_get_type ())
#define CAMEL_IMAP4_STREAM(obj)     (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_IMAP4_STREAM, CamelIMAP4Stream))
#define CAMEL_IMAP4_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_TYPE_IMAP4_STREAM, CamelIMAP4StreamClass))
#define CAMEL_IS_IMAP4_STREAM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_TYPE_IMAP4_STREAM))

typedef struct _CamelIMAP4Stream CamelIMAP4Stream;
typedef struct _CamelIMAP4StreamClass CamelIMAP4StreamClass;

#define IMAP4_READ_PRELEN   128
#define IMAP4_READ_BUFLEN   4096

enum {
    CAMEL_IMAP4_TOKEN_NO_DATA       = -8,
    CAMEL_IMAP4_TOKEN_ERROR         = -7,
    CAMEL_IMAP4_TOKEN_NIL           = -6,
    CAMEL_IMAP4_TOKEN_ATOM          = -5,
    CAMEL_IMAP4_TOKEN_FLAG          = -4,
    CAMEL_IMAP4_TOKEN_NUMBER        = -3,
    CAMEL_IMAP4_TOKEN_QSTRING       = -2,
    CAMEL_IMAP4_TOKEN_LITERAL       = -1,
    /* CAMEL_IMAP4_TOKEN_CHAR would just be the char we got */
    CAMEL_IMAP4_TOKEN_EOLN          = '\n',
    CAMEL_IMAP4_TOKEN_LPAREN        = '(',
    CAMEL_IMAP4_TOKEN_RPAREN        = ')',
    CAMEL_IMAP4_TOKEN_ASTERISK      = '*',
    CAMEL_IMAP4_TOKEN_PLUS          = '+',
    CAMEL_IMAP4_TOKEN_LBRACKET      = '[',
    CAMEL_IMAP4_TOKEN_RBRACKET      = ']',
};

typedef struct _camel_imap4_token_t {
    int token;
    union {
        char *atom;
        char *flag;
        char *qstring;
        size_t literal;
        guint32 number;
    } v;
} camel_imap4_token_t;

enum {
    CAMEL_IMAP4_STREAM_MODE_TOKEN   = 0,
    CAMEL_IMAP4_STREAM_MODE_LITERAL = 1,
};

struct _CamelIMAP4Stream {
    CamelStream parent_object;
    
    CamelStream *stream;
    
    guint disconnected:1;  /* disconnected state */
    guint have_unget:1;    /* have an unget token */
    guint mode:1;          /* TOKEN vs LITERAL */
    guint eol:1;           /* end-of-literal */
    
    size_t literal;
    
    /* i/o buffers */
    unsigned char realbuf[IMAP4_READ_PRELEN + IMAP4_READ_BUFLEN + 1];
    unsigned char *inbuf;
    unsigned char *inptr;
    unsigned char *inend;
    
    /* token buffers */
    unsigned char *tokenbuf;
    unsigned char *tokenptr;
    unsigned int tokenleft;
    
    camel_imap4_token_t unget;
};

struct _CamelIMAP4StreamClass {
    CamelStreamClass parent_class;
    
    /* Virtual methods */
};


/* Standard Camel function */
CamelType camel_imap4_stream_get_type (void);

CamelStream *camel_imap4_stream_new (CamelStream *stream);

int camel_imap4_stream_next_token (CamelIMAP4Stream *stream, camel_imap4_token_t *token);
int camel_imap4_stream_unget_token (CamelIMAP4Stream *stream, camel_imap4_token_t *token);

int camel_imap4_stream_line (CamelIMAP4Stream *stream, unsigned char **line, size_t *len);
int camel_imap4_stream_literal (CamelIMAP4Stream *stream, unsigned char **literal, size_t *len);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __CAMEL_IMAP4_STREAM_H__ */