Make camel-service use a Gurl internally. Remove the login/password
[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@helixcode.com>
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 gboolean _connect(CamelService *service, CamelException *ex);
36 static gboolean _connect_with_url (CamelService *service, Gurl *url,
37                                    CamelException *ex);
38 static gboolean _disconnect(CamelService *service, CamelException *ex);
39 static gboolean _is_connected (CamelService *service);
40 static void _finalize (GtkObject *object);
41
42 static void
43 camel_service_class_init (CamelServiceClass *camel_service_class)
44 {
45         GtkObjectClass *gtk_object_class =
46                 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_with_url = _connect_with_url;
53         camel_service_class->disconnect = _disconnect;
54         camel_service_class->is_connected = _is_connected;
55
56         /* virtual method overload */
57         gtk_object_class->finalize = _finalize;
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 (),
79                                                       &camel_service_info);
80         }
81         
82         return camel_service_type;
83 }
84
85
86 static void           
87 _finalize (GtkObject *object)
88 {
89         CamelService *camel_service = CAMEL_SERVICE (object);
90
91         CAMEL_LOG_FULL_DEBUG ("Entering CamelService::finalize\n");
92
93         if (camel_service->url)
94                 g_url_free (camel_service->url);
95
96         GTK_OBJECT_CLASS (parent_class)->finalize (object);
97         CAMEL_LOG_FULL_DEBUG ("Leaving CamelService::finalize\n");
98 }
99
100
101
102 /**
103  * _connect : connect to a service 
104  *
105  * connect to the service using the parameters 
106  * stored in the session it is initialized with
107  * WARNING: session not implemented for the moment
108  *
109  * @service: object to connect
110  **/
111 static gboolean
112 _connect (CamelService *service, CamelException *ex)
113 {
114 #warning need to get default URL from somewhere
115         return CSERV_CLASS(service)->connect_with_url(service, NULL, ex);
116 }
117
118
119
120 /**
121  * camel_service_connect:connect to a service 
122  * @service: CamelService object
123  * 
124  * connect to the service using the parameters 
125  * stored in the session it is initialized with
126  * WARNING: session not implemented for the moment
127  * 
128  **/
129 gboolean
130 camel_service_connect (CamelService *service, CamelException *ex)
131 {
132         return CSERV_CLASS(service)->connect(service, ex);
133 }
134
135
136
137 /**
138  * _connect_with_url: connect to the specified address
139  * 
140  * Connect to the service, but do not use the session
141  * default parameters to retrieve server's address
142  *
143  * @service: object to connect
144  * @url: URL describing service to connect to
145  **/
146 static gboolean
147 _connect_with_url (CamelService *service, Gurl *url, CamelException *ex)
148 {
149         service->connected = TRUE;
150         service->url = url;
151
152         return TRUE;
153 }
154
155 /**
156  * camel_service_connect_with_url: connect a service 
157  * @service:  the service to connect
158  * @url:  URL describing the service to connect to
159  * 
160  * Connect to a service, but do not use the session
161  * default parameters to retrieve server's address
162  * 
163  **/
164 gboolean
165 camel_service_connect_with_url (CamelService *service, char *url,
166                                 CamelException *ex)
167 {
168         return CSERV_CLASS(service)->connect_with_url (service, g_url_new(url),
169                                                        ex);
170 }
171
172
173
174 /**
175  * _disconnect : disconnect from a service 
176  *
177  * disconnect from the service
178  *
179  * @service: object to disconnect
180  **/
181 static gboolean
182 _disconnect (CamelService *service, CamelException *ex)
183 {
184         service->connected = FALSE;
185         if (service->url) {
186                 g_url_free(service->url);
187                 service->url = NULL;
188         }
189
190         return TRUE;
191 }
192
193
194
195 /**
196  * camel_service_disconnect: disconnect from a service 
197  * @service: CamelService object
198  **/
199 gboolean
200 camel_service_disconnect (CamelService *service, CamelException *ex)
201 {
202         return CSERV_CLASS(service)->disconnect(service, ex);
203 }
204
205
206
207 /**
208  * _is_connected: test if the service object is connected
209  * @service: object to test
210  * 
211  * Return value: 
212  **/
213 static gboolean
214 _is_connected (CamelService *service)
215 {
216         return service->connected;
217 }
218
219
220 /**
221  * camel_service_is_connected: test if the service object is connected
222  * @service: object to test
223  * 
224  * Return value: 
225  **/
226 gboolean
227 camel_service_is_connected (CamelService *service)
228 {
229         return CSERV_CLASS(service)->is_connected(service);
230 }
231
232
233 /**
234  * camel_service_get_url: get the url representing a service
235  * @service: the service
236  * 
237  * returns the URL representing a service. For security reasons 
238  * This routine does not return the password. 
239  * 
240  * Return value: the url name
241  **/
242 gchar *
243 camel_service_get_url (CamelService *service)
244 {
245         return g_url_to_string(service->url, FALSE);
246 }
247
248