Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / providers / pop3 / camel-pop3-engine.h
1 /*
2  * Copyright (C) 2001 Ximian Inc.
3  *
4  * Authors: Michael Zucchi <notzed@ximian.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef _CAMEL_POP3_ENGINE_H
22 #define _CAMEL_POP3_ENGINE_H
23
24 #include <camel/camel-object.h>
25 #include <libedataserver/e-msgport.h>
26 #include "camel-pop3-stream.h"
27
28 #define CAMEL_POP3_ENGINE(obj)         CAMEL_CHECK_CAST (obj, camel_pop3_engine_get_type (), CamelPOP3Engine)
29 #define CAMEL_POP3_ENGINE_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_pop3_engine_get_type (), CamelPOP3EngineClass)
30 #define CAMEL_IS_POP3_ENGINE(obj)      CAMEL_CHECK_TYPE (obj, camel_pop3_engine_get_type ())
31
32 G_BEGIN_DECLS
33
34 typedef struct _CamelPOP3EngineClass CamelPOP3EngineClass;
35 typedef struct _CamelPOP3Engine CamelPOP3Engine;
36 typedef struct _CamelPOP3Command CamelPOP3Command;
37
38 /* pop 3 connection states, actually since we're given a connected socket, we always start in auth state */
39 typedef enum {
40         CAMEL_POP3_ENGINE_DISCONNECT = 0,
41         CAMEL_POP3_ENGINE_AUTH,
42         CAMEL_POP3_ENGINE_TRANSACTION,
43         CAMEL_POP3_ENGINE_UPDATE,
44 } camel_pop3_engine_t;
45
46 /* state of a command */
47 typedef enum {
48         CAMEL_POP3_COMMAND_IDLE = 0, /* command created or queued, not yet sent (e.g. non pipelined server) */
49         CAMEL_POP3_COMMAND_DISPATCHED, /* command sent to server */
50
51         /* completion codes */
52         CAMEL_POP3_COMMAND_OK,  /* plain ok response */
53         CAMEL_POP3_COMMAND_DATA, /* processing command response */
54         CAMEL_POP3_COMMAND_ERR, /* error response */
55 } camel_pop3_command_t;
56
57 /* flags for command types */
58 enum {
59         CAMEL_POP3_COMMAND_SIMPLE = 0, /* dont expect multiline response */
60         CAMEL_POP3_COMMAND_MULTI = 1, /* expect multiline response */
61 };
62
63 /* flags for server options */
64 enum {
65         CAMEL_POP3_CAP_APOP = 1<<0,
66         CAMEL_POP3_CAP_UIDL = 1<<1,
67         CAMEL_POP3_CAP_SASL = 1<<2,
68         CAMEL_POP3_CAP_TOP  = 1<<3,
69         CAMEL_POP3_CAP_PIPE = 1<<4,
70         CAMEL_POP3_CAP_STLS = 1<<5
71 };
72
73 /* enable/disable flags for the engine itself */
74 enum {
75         CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS = 1<<0,
76 };
77
78 typedef void (*CamelPOP3CommandFunc)(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data);
79
80 struct _CamelPOP3Command {
81         struct _CamelPOP3Command *next;
82         struct _CamelPOP3Command *prev;
83
84         guint32 flags;
85         camel_pop3_command_t state;
86
87         CamelPOP3CommandFunc func;
88         void *func_data;
89
90         int data_size;
91         char *data;
92 };
93
94 struct _CamelPOP3Engine {
95         CamelObject parent;
96         
97         guint32 flags;
98         
99         camel_pop3_engine_t state;
100
101         GList *auth;            /* authtypes supported */
102
103         guint32 capa;           /* capabilities */
104         char *apop;             /* apop time string */
105
106         unsigned char *line;    /* current line buffer */
107         unsigned int linelen;
108
109         struct _CamelPOP3Stream *stream;
110
111         unsigned int sentlen;   /* data sent (so we dont overflow network buffer) */
112
113         EDList active;          /* active commands */
114         EDList queue;           /* queue of waiting commands */
115         EDList done;            /* list of done commands, awaiting free */
116
117         CamelPOP3Command *current; /* currently busy (downloading) response */
118 };
119
120 struct _CamelPOP3EngineClass {
121         CamelObjectClass parent_class;
122 };
123
124 CamelType                 camel_pop3_engine_get_type    (void);
125
126 CamelPOP3Engine  *camel_pop3_engine_new         (CamelStream *source, guint32 flags);
127
128 void              camel_pop3_engine_reget_capabilities (CamelPOP3Engine *engine);
129
130 void              camel_pop3_engine_command_free(CamelPOP3Engine *pe, CamelPOP3Command *pc);
131
132 int               camel_pop3_engine_iterate     (CamelPOP3Engine *pe, CamelPOP3Command *pc);
133
134 CamelPOP3Command *camel_pop3_engine_command_new (CamelPOP3Engine *pe, guint32 flags, CamelPOP3CommandFunc func, void *data, const char *fmt, ...);
135
136 G_END_DECLS
137
138 #endif /* ! _CAMEL_POP3_ENGINE_H */