Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-session.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-session.h : Abstract class for an email session */
3
4 /*
5  *
6  * Author :
7  *  Bertrand Guiheneuf <bertrand@helixcode.com>
8  *
9  * Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of version 2 of the GNU Lesser General Public
13  * License as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
23  * USA
24  */
25
26
27 #ifndef CAMEL_SESSION_H
28 #define CAMEL_SESSION_H 1
29
30 #include <camel/camel-object.h>
31 #include <camel/camel-provider.h>
32 #include <camel/camel-junk-plugin.h>
33
34 #include <libedataserver/e-msgport.h>
35
36 #define CAMEL_SESSION_TYPE     (camel_session_get_type ())
37 #define CAMEL_SESSION(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SESSION_TYPE, CamelSession))
38 #define CAMEL_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SESSION_TYPE, CamelSessionClass))
39 #define CAMEL_IS_SESSION(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SESSION_TYPE))
40
41 G_BEGIN_DECLS
42
43 typedef gboolean (*CamelTimeoutCallback) (gpointer data);
44 typedef enum {
45         CAMEL_SESSION_ALERT_INFO,
46         CAMEL_SESSION_ALERT_WARNING,
47         CAMEL_SESSION_ALERT_ERROR
48 } CamelSessionAlertType;
49
50 enum {
51         CAMEL_SESSION_PASSWORD_REPROMPT = 1 << 0,
52         CAMEL_SESSION_PASSWORD_SECRET = 1 << 2,
53         CAMEL_SESSION_PASSWORD_STATIC = 1 << 3,
54         CAMEL_SESSION_PASSPHRASE = 1 << 4,
55 };
56
57 struct _CamelSession
58 {
59         CamelObject parent_object;
60         struct _CamelSessionPrivate *priv;
61
62         char *storage_path;
63         CamelJunkPlugin *junk_plugin;
64
65         guint online:1;
66         guint check_junk:1;
67         guint network_state:1;
68 };
69
70 typedef struct _CamelSessionThreadOps CamelSessionThreadOps;
71 typedef struct _CamelSessionThreadMsg CamelSessionThreadMsg;
72
73 typedef struct {
74         CamelObjectClass parent_class;
75
76         CamelService *  (*get_service)       (CamelSession *session,
77                                               const char *url_string,
78                                               CamelProviderType type,
79                                               CamelException *ex);
80         char *          (*get_storage_path)  (CamelSession *session,
81                                               CamelService *service,
82                                               CamelException *ex);
83
84         char *          (*get_password)      (CamelSession *session,
85                                               CamelService *service,
86                                               const char *domain,
87                                               const char *prompt,
88                                               const char *item,
89                                               guint32 flags,
90                                               CamelException *ex);
91         void            (*forget_password)   (CamelSession *session,
92                                               CamelService *service,
93                                               const char *domain,
94                                               const char *item,
95                                               CamelException *ex);
96         gboolean        (*alert_user)        (CamelSession *session,
97                                               CamelSessionAlertType type,
98                                               const char *prompt,
99                                               gboolean cancel);
100
101         CamelFilterDriver * (*get_filter_driver) (CamelSession *session,
102                                                   const char *type,
103                                                   CamelException *ex);
104         
105         /* mechanism for creating and maintaining multiple threads of control */
106         void *(*thread_msg_new)(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size);
107         void (*thread_msg_free)(CamelSession *session, CamelSessionThreadMsg *msg);
108         int (*thread_queue)(CamelSession *session, CamelSessionThreadMsg *msg, int flags);
109         void (*thread_wait)(CamelSession *session, int id);
110         void (*thread_status)(CamelSession *session, CamelSessionThreadMsg *msg, const char *text, int pc);
111 } CamelSessionClass;
112
113
114 /* public methods */
115
116 /* Standard Camel function */
117 CamelType camel_session_get_type (void);
118
119
120 void            camel_session_construct             (CamelSession *session,
121                                                      const char *storage_path);
122
123 CamelService *  camel_session_get_service           (CamelSession *session,
124                                                      const char *url_string,
125                                                      CamelProviderType type,
126                                                      CamelException *ex);
127 CamelService *  camel_session_get_service_connected (CamelSession *session, 
128                                                      const char *url_string,
129                                                      CamelProviderType type, 
130                                                      CamelException *ex);
131
132 #define camel_session_get_store(session, url_string, ex) \
133         ((CamelStore *) camel_session_get_service_connected (session, url_string, CAMEL_PROVIDER_STORE, ex))
134 #define camel_session_get_transport(session, url_string, ex) \
135         ((CamelTransport *) camel_session_get_service_connected (session, url_string, CAMEL_PROVIDER_TRANSPORT, ex))
136
137 char *             camel_session_get_storage_path   (CamelSession *session,
138                                                      CamelService *service,
139                                                      CamelException *ex);
140
141 char *             camel_session_get_password       (CamelSession *session,
142                                                      CamelService *service,
143                                                      const char *domain,
144                                                      const char *prompt,
145                                                      const char *item,
146                                                      guint32 flags,
147                                                      CamelException *ex);
148 void               camel_session_forget_password    (CamelSession *session,
149                                                      CamelService *service,
150                                                      const char *domain,
151                                                      const char *item,
152                                                      CamelException *ex);
153 gboolean           camel_session_alert_user         (CamelSession *session,
154                                                      CamelSessionAlertType type,
155                                                      const char *prompt,
156                                                      gboolean cancel);
157
158 gboolean           camel_session_is_online          (CamelSession *session);
159 void               camel_session_set_online         (CamelSession *session,
160                                                      gboolean online);
161
162 CamelFilterDriver *camel_session_get_filter_driver  (CamelSession *session,
163                                                      const char *type,
164                                                      CamelException *ex);
165
166 gboolean  camel_session_check_junk               (CamelSession *session);
167 void      camel_session_set_check_junk           (CamelSession *session,
168                                                   gboolean      check_junk);
169
170 struct _CamelSessionThreadOps {
171         void (*receive)(CamelSession *session, struct _CamelSessionThreadMsg *m);
172         void (*free)(CamelSession *session, struct _CamelSessionThreadMsg *m);
173 };
174
175 struct _CamelSessionThreadMsg {
176         EMsg msg;
177
178         int id;
179
180         CamelException ex;
181         CamelSessionThreadOps *ops;
182         struct _CamelOperation *op;
183         CamelSession *session;
184
185         void *data; /* free for implementation to define, not used by camel, do not use in client code */
186         /* user fields follow */
187 };
188
189 void *camel_session_thread_msg_new(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size);
190 void camel_session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg);
191 int camel_session_thread_queue(CamelSession *session, CamelSessionThreadMsg *msg, int flags);
192 void camel_session_thread_wait(CamelSession *session, int id);
193 gboolean camel_session_get_network_state (CamelSession *session);
194 void camel_session_set_network_state (CamelSession *session, gboolean network_state);
195
196 G_END_DECLS
197
198 #endif /* CAMEL_SESSION_H */