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