1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camelService.c : Abstract class for an email service */
7 * Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org>
9 * Copyright 1999, 2000 HelixCode (http://www.helixcode.com) .
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.
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.
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
27 #include "camel-service.h"
28 #include "camel-log.h"
30 static GtkObjectClass *parent_class=NULL;
32 /* Returns the class for a CamelService */
33 #define CSERV_CLASS(so) CAMEL_SERVICE_CLASS (GTK_OBJECT(so)->klass)
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);
44 camel_service_class_init (CamelServiceClass *camel_service_class)
46 GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_service_class);
48 parent_class = gtk_type_class (gtk_object_get_type ());
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;
58 /* virtual method overload */
59 gtk_object_class->finalize = _finalize;
69 camel_service_get_type (void)
71 static GtkType camel_service_type = 0;
73 if (!camel_service_type) {
74 GtkTypeInfo camel_service_info =
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,
86 camel_service_type = gtk_type_unique (gtk_object_get_type (), &camel_service_info);
89 return camel_service_type;
94 _finalize (GtkObject *object)
96 CamelService *camel_service = CAMEL_SERVICE (object);
98 CAMEL_LOG_FULL_DEBUG ("Entering CamelService::finalize\n");
100 g_free (camel_service->url);
102 GTK_OBJECT_CLASS (parent_class)->finalize (object);
103 CAMEL_LOG_FULL_DEBUG ("Leaving CamelService::finalize\n");
109 * _connect : connect to a service
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
115 * @service: object to connect
118 _connect (CamelService *service)
120 CSERV_CLASS(service)->set_connected(service, TRUE);
126 * camel_service_connect:connect to a service
127 * @service: CamelService object
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
135 camel_service_connect (CamelService *service)
137 CSERV_CLASS(service)->connect(service);
143 * _connect_to: connect to the specified address
145 * Connect to the service, but do not use the session
146 * default parameters to retrieve server's address
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
154 _connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd)
156 CSERV_CLASS(service)->set_connected(service, TRUE);
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
166 * Connect to a service, but do not use the session
167 * default parameters to retrieve server's address
171 camel_service_connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd)
173 CSERV_CLASS(service)->connect_to_with_login_passwd (service, host, login, passwd);
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
190 _connect_to_with_login_passwd_port (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port)
192 CSERV_CLASS(service)->set_connected(service, TRUE);
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
204 * Connect to a service, but do not use the session
205 * default parameters to retrieve server's address
209 camel_service_connect_to_with_login_passwd_port (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port)
211 CSERV_CLASS(service)->connect_to_with_login_passwd_port (service, host, login, passwd, port);
218 * _is_connected: test if the service object is connected
219 * @service: object to test
226 _is_connected (CamelService *service)
228 return service->connected;
233 * camel_service_is_connected: test if the service object is connected
234 * @service: object to test
241 camel_service_is_connected (CamelService *service)
243 return CSERV_CLASS(service)->is_connected(service);
249 * _set_connected:set the connected state
250 * @service: object to set the state of
251 * @state: connected/disconnected
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.
259 _set_connected (CamelService *service, gboolean state)
261 service->connected = state;
267 * _get_url: get url representing a service
268 * @service: the service
270 * This method merely returns the "url" field. Subclasses
271 * may provide more active implementations.
277 _get_url (CamelService *service)
283 * camel_service_get_url: get the url representing a service
284 * @service: the service
286 * returns the URL representing a service. For security reasons
287 * This routine may not always return the password.
289 * Return value: the url name
292 camel_service_get_url (CamelService *service)
294 return CSERV_CLASS(service)->get_url(service);