Implemented base64 encoder based on CamelStreams. Should the
[platform/upstream/evolution-data-server.git] / camel / camel-service.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camelService.c : Abstract class for an email service */
3
4 /* 
5  *
6  * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
7  *
8  * This program is free software; you can redistribute it and/or 
9  * modify it under the terms of the GNU General Public License as 
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  */
23 #include <config.h>
24 #include "camel-service.h"
25
26 static GtkObjectClass *parent_class=NULL;
27
28 /* Returns the class for a CamelService */
29 #define CSERV_CLASS(so) CAMEL_SERVICE_CLASS (GTK_OBJECT(so)->klass)
30
31 static void _connect(CamelService *service);
32 static void _connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd);
33 static void _connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port);
34 static gboolean _is_connected(CamelService *service);
35 static void _set_connected(CamelService *service, gboolean state);
36 static GString *_get_url(CamelService *service);
37
38 static void
39 camel_service_class_init (CamelServiceClass *camel_service_class)
40 {
41         parent_class = gtk_type_class (gtk_object_get_type ());
42         
43         /* virtual method definition */
44         camel_service_class->connect = _connect;
45         camel_service_class->connect_to_with_login_passwd = _connect_to_with_login_passwd;
46         camel_service_class->connect_to_with_login_passwd_port = _connect_to_with_login_passwd_port;
47         camel_service_class->is_connected = _is_connected;
48         camel_service_class->set_connected = _set_connected;
49         camel_service_class->get_url = _get_url;
50
51         /* virtual method overload */
52 }
53
54
55
56
57
58
59
60 GtkType
61 camel_service_get_type (void)
62 {
63         static GtkType camel_service_type = 0;
64         
65         if (!camel_service_type)        {
66                 GtkTypeInfo camel_service_info =        
67                 {
68                         "CamelService",
69                         sizeof (CamelService),
70                         sizeof (CamelServiceClass),
71                         (GtkClassInitFunc) camel_service_class_init,
72                         (GtkObjectInitFunc) NULL,
73                                 /* reserved_1 */ NULL,
74                                 /* reserved_2 */ NULL,
75                         (GtkClassInitFunc) NULL,
76                 };
77                 
78                 camel_service_type = gtk_type_unique (gtk_object_get_type (), &camel_service_info);
79         }
80         
81         return camel_service_type;
82 }
83
84
85
86
87
88 /**
89  * _connect : connect to a service 
90  *
91  * connect to the service using the parameters 
92  * stored in the session it is initialized with
93  * WARNING: session not implemented for the moment
94  *
95  * @service: object to connect
96  **/
97 static void
98 _connect(CamelService *service)
99 {
100         CSERV_CLASS(service)->set_connected(service, TRUE);
101 }
102
103
104 /**
105  * camel_service_connect : connect to a service 
106  *
107  * connect to the service using the parameters 
108  * stored in the session it is initialized with
109  * WARNING: session not implemented for the moment
110  *
111  * @service: object to connect to
112  **/
113 void
114 camel_service_connect(CamelService *service)
115 {
116         CSERV_CLASS(service)->connect(service);
117 }
118
119
120
121 /**
122  * _connect_to: connect to the specified address
123  * 
124  * Connect to the service, but do not use the session
125  * default parameters to retrieve server's address
126  *
127  * @service: object to connect
128  * @host: host to connect to
129  * @login: user name used to log in
130  * @passwd: password used to log in
131  **/
132 static void
133 _connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd)
134 {
135   CSERV_CLASS(service)->set_connected(service, TRUE);
136 }
137
138 /**
139  * camel_service_connect_to_with_login_passwd: connect a service 
140  * @service: the service to connect
141  * @host: host to connect to
142  * @login: login to connect with
143  * @passwd: password to connect with
144  * 
145  * Connect to a service, but do not use the session
146  * default parameters to retrieve server's address
147  * 
148  **/
149 void
150 camel_service_connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd)
151 {
152     CSERV_CLASS(service)->connect_to_with_login_passwd (service, host, login, passwd);
153 }
154
155
156
157 /**
158  * _connect_to:login:password : connect to the specified address
159  * 
160  * Connect to the service, but do not use the session
161  * default parameters to retrieve server's address
162  *
163  * @service: object to connect
164  * @host: host to connect to
165  * @login: user name used to log in
166  * @passwd: password used to log in
167  * @port: port to connect to
168  *
169  **/
170 static void
171 _connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port)
172 {
173     CSERV_CLASS(service)->set_connected(service, TRUE);
174 }
175
176
177 /**
178  * camel_service_connect_to_with_login_passwd_port: connect a service 
179  * @service: the service to connect
180  * @host: host to connect to
181  * @login: login to connect with
182  * @passwd: password to connect with
183  * @port: port to connect to 
184  * 
185  * Connect to a service, but do not use the session
186  * default parameters to retrieve server's address
187  * 
188  **/
189 void
190 camel_service_connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port)
191 {
192     CSERV_CLASS(service)->connect_to_with_login_passwd_port (service, host, login, passwd, port);
193 }
194
195
196
197
198 /**
199  * _is_connected: test if the service object is connected
200  *
201  *
202  * @service: object to test
203  *  
204  **/
205 static gboolean
206 _is_connected(CamelService *service)
207 {
208   return service->connected;
209 }
210
211
212 /**
213  * camel_service_is_connected: test if a service object is connected
214  *
215  * @service:  the service
216  * 
217  * 
218  * 
219  * Return value: TRUE is the service is connected
220  **/
221 gboolean
222 camel_service_is_connected(CamelService *service)
223 {
224   return CSERV_CLASS(service)->is_connected(service);
225 }
226
227
228 /**
229  * _set_connected: set the connected state
230  * 
231  * This routine has to be called by providers to set the 
232  * connection state, mainly when the service is disconnected
233  * wheras the close() method has not been called.
234  *
235  * @service: object to set the state of
236  * @state: connected/disconnected
237  *  
238  **/
239 static void
240 _set_connected(CamelService *service, gboolean state)
241 {
242   service->connected = state;
243 }
244
245
246
247 /**
248  * _get_url: get url representing a service
249  * @service: the service
250  * 
251  * This method merely returns the "url" field. Subclasses
252  * may provide more active implementations.
253  * 
254  * Return value: 
255  **/
256 static GString *
257 _get_url(CamelService *service)
258 {
259         return service->url;
260 }
261
262 /**
263  * camel_service_get_url: get the url representing a service
264  * @service: the service
265  * 
266  * returns the URL representing a service. For security reasons 
267  * This routine may not always return the password.
268  * 
269  * Return value: the url name
270  **/
271 GString *
272 camel_service_get_url(CamelService *service)
273 {
274         return CSERV_CLASS(service)->get_url(service);
275 }
276
277