Merge with camel-async.
[platform/upstream/evolution-data-server.git] / camel / camel-service.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-service.h : Abstract class for an email service */
3
4 /* 
5  *
6  * Author : 
7  *  Bertrand Guiheneuf <bertrand@helixcode.com>
8  *
9  * Copyright 1999, 2000 Helix Code, Inc. (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
27
28 #ifndef CAMEL_SERVICE_H
29 #define CAMEL_SERVICE_H 1
30
31
32 #ifdef __cplusplus
33 extern "C" {
34 #pragma }
35 #endif /* __cplusplus }*/
36
37 #include <camel/camel-object.h>
38 #include <camel/camel-url.h>
39 #include <netdb.h>
40
41 #define CAMEL_SERVICE_TYPE     (camel_service_get_type ())
42 #define CAMEL_SERVICE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SERVICE_TYPE, CamelService))
43 #define CAMEL_SERVICE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SERVICE_TYPE, CamelServiceClass))
44 #define CAMEL_IS_SERVICE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SERVICE_TYPE))
45
46
47 struct _CamelService {
48         CamelObject parent_object;
49
50         CamelSession *session;
51         gboolean connected;
52         CamelURL *url;
53         int url_flags;
54 };
55
56
57 typedef struct {
58         CamelObjectClass parent_class;
59
60         gboolean  (*connect)           (CamelService *service, 
61                                         CamelException *ex);
62         gboolean  (*disconnect)        (CamelService *service, 
63                                         CamelException *ex);
64
65         gboolean  (*is_connected)      (CamelService *service);
66
67         GList *   (*query_auth_types)  (CamelService *service,
68                                         CamelException *ex);
69         void      (*free_auth_types)   (CamelService *service,
70                                         GList *authtypes);
71
72         char *    (*get_name)          (CamelService *service,
73                                         gboolean brief);
74
75 } CamelServiceClass;
76
77
78
79 /* Flags for url_flags. "ALLOW" means the config dialog will let
80  * the user configure it. "NEED" implies "ALLOW" but means the user
81  * must configure it. Service code can assume that any url part
82  * for which it has set the NEED flag will be set when the service
83  * is created.
84  */
85 #define CAMEL_SERVICE_URL_ALLOW_USER     (1 << 0)
86 #define CAMEL_SERVICE_URL_ALLOW_AUTH     (1 << 1)
87 #define CAMEL_SERVICE_URL_ALLOW_PASSWORD (1 << 2)
88 #define CAMEL_SERVICE_URL_ALLOW_HOST     (1 << 3)
89 #define CAMEL_SERVICE_URL_ALLOW_PORT     (1 << 4)
90 #define CAMEL_SERVICE_URL_ALLOW_PATH     (1 << 5)
91
92 #define CAMEL_SERVICE_URL_NEED_USER      (1 << 6 | 1 << 0)
93 #define CAMEL_SERVICE_URL_NEED_AUTH      (1 << 7 | 1 << 1)
94 #define CAMEL_SERVICE_URL_NEED_PASSWORD  (1 << 8 | 1 << 2)
95 #define CAMEL_SERVICE_URL_NEED_HOST      (1 << 9 | 1 << 3)
96 #define CAMEL_SERVICE_URL_NEED_PORT      (1 << 10 | 1 << 4)
97 #define CAMEL_SERVICE_URL_NEED_PATH      (1 << 11 | 1 << 5)
98
99
100 /* query_auth_types returns a GList of these */
101 typedef struct {
102         char *name, *description, *authproto;
103         gboolean need_password;
104 } CamelServiceAuthType;
105
106
107 /* public methods */
108 CamelService *      camel_service_new                (CamelType type, 
109                                                       CamelSession *session,
110                                                       CamelURL *url, 
111                                                       CamelException *ex);
112
113 gboolean            camel_service_connect            (CamelService *service, 
114                                                       CamelException *ex);
115 gboolean            camel_service_disconnect         (CamelService *service, 
116                                                       CamelException *ex);
117 gboolean            camel_service_is_connected       (CamelService *service);
118
119 char *              camel_service_get_url            (CamelService *service);
120 char *              camel_service_get_name           (CamelService *service,
121                                                       gboolean brief);
122 CamelSession *      camel_service_get_session        (CamelService *service);
123
124 GList *             camel_service_query_auth_types   (CamelService *service,
125                                                       CamelException *ex);
126 void                camel_service_free_auth_types    (CamelService *service,
127                                                       GList *authtypes);
128
129 /* convenience functions */
130 struct hostent *    camel_service_gethost            (CamelService *service,
131                                                       CamelException *ex);
132
133
134 /* Standard Camel function */
135 CamelType camel_service_get_type (void);
136
137 #ifdef __cplusplus
138 }
139 #endif /* __cplusplus */
140
141 #endif /* CAMEL_SERVICE_H */
142