Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / providers / hula / camel-hula-provider.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-groupwise-provider.c: GroupWise provider registration code */
3
4 /*
5  *  Author: Harish Krishnaswamy (kharish@novell.com)
6  *
7  *  Copyright 2005 Novell, Inc. (www.novell.com)
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of version 2 of the GNU Lesser General Public
11  * License as published by the Free Software Foundation.
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 GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <string.h>
30
31 #include <glib.h>
32 #include <glib/gi18n-lib.h>
33 #include <gmodule.h>
34
35 #include "camel-provider.h"
36 #include "camel-sasl.h"
37 #include "camel-session.h"
38 #include "camel-url.h"
39
40 static void add_hash (guint *hash, char *s);
41 static guint hula_url_hash (gconstpointer key);
42 static gint check_equal (char *s1, char *s2);
43 static gint hula_url_equal (gconstpointer a, gconstpointer b);
44
45
46 static CamelProviderConfEntry hula_conf_entries[] = {
47         /* override the labels/defaults of the standard settings */
48         { CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
49           N_("Checking for New Mail") },
50         { CAMEL_PROVIDER_CONF_CHECKBOX, "check_all", NULL,
51           N_("C_heck for new messages in all folders"), "1" },
52         { CAMEL_PROVIDER_CONF_SECTION_END },
53         { CAMEL_PROVIDER_CONF_SECTION_START, "cmdsection", NULL,
54           N_("Connection to Server") },
55         { CAMEL_PROVIDER_CONF_CHECKBOX, "use_command", NULL,
56           N_("_Use custom command to connect to server"), "0" },
57         { CAMEL_PROVIDER_CONF_ENTRY, "command", "use_command",
58           N_("Command:"), "ssh -C -l %u %h exec /usr/sbin/imapd" },
59         { CAMEL_PROVIDER_CONF_SECTION_END },
60         { CAMEL_PROVIDER_CONF_SECTION_START, "folders", NULL,
61           N_("Folders") },
62         { CAMEL_PROVIDER_CONF_CHECKBOX, "use_lsub", NULL,
63           N_("_Show only subscribed folders"), "1" },
64         { CAMEL_PROVIDER_CONF_CHECKBOX, "override_namespace", NULL,
65           N_("O_verride server-supplied folder namespace"), "0" },
66         { CAMEL_PROVIDER_CONF_ENTRY, "namespace", "override_namespace",
67           N_("Namespace") },
68         { CAMEL_PROVIDER_CONF_SECTION_END },
69         
70         { CAMEL_PROVIDER_CONF_END }
71         /* revisit each options in other providers (incl. authdomain) for
72          * relevancy - harish*/
73 };
74
75
76 static CamelProvider hula_provider = {
77         "hula",
78         N_("Hula"),
79
80         N_("For accessing Hula servers"),
81
82         "mail",
83
84         CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
85         CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL | CAMEL_PROVIDER_DISABLE_SENT_FOLDER,
86
87         CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
88
89         hula_conf_entries,
90
91         /* ... */
92 };
93
94 static CamelServiceAuthType camel_hula_password_authtype = {
95         N_("Password"),
96         
97         N_("This option will connect to the Hula server using a "
98            "plaintext password."),
99         
100         "",
101         TRUE
102 };
103
104 static int
105 hula_auto_detect_cb (CamelURL *url, GHashTable **auto_detected,
106                          CamelException *ex)
107 {
108         *auto_detected = g_hash_table_new (g_str_hash, g_str_equal);
109
110         g_hash_table_insert (*auto_detected, g_strdup ("caldav_host"),
111                              g_strdup (url->host));
112
113         return 0;
114 }
115
116 void
117 camel_provider_module_init(void)
118 {
119         CamelProvider *imap_provider = NULL;
120         CamelException ex = CAMEL_EXCEPTION_INITIALISER;
121
122         imap_provider =  camel_provider_get("imap://", &ex);
123
124         hula_provider.url_hash = hula_url_hash;
125         hula_provider.url_equal = hula_url_equal;
126         hula_provider.auto_detect = hula_auto_detect_cb;
127         hula_provider.authtypes = g_list_prepend (hula_provider.authtypes, &camel_hula_password_authtype);
128         hula_provider.translation_domain = GETTEXT_PACKAGE;
129         
130         hula_provider.object_types[CAMEL_PROVIDER_STORE] = imap_provider->object_types [CAMEL_PROVIDER_STORE];
131          
132         
133         camel_provider_register (&hula_provider);
134 }
135
136
137 static void
138 add_hash (guint *hash, char *s)
139 {
140         if (s)
141                 *hash ^= g_str_hash(s);
142 }
143
144 static guint
145 hula_url_hash (gconstpointer key)
146 {
147         const CamelURL *u = (CamelURL *)key;
148         guint hash = 0;
149
150         add_hash (&hash, u->user);
151         add_hash (&hash, u->authmech);
152         add_hash (&hash, u->host);
153         hash ^= u->port;
154         
155         return hash;
156 }
157
158 static gint
159 check_equal (char *s1, char *s2)
160 {
161         if (s1 == NULL) {
162                 if (s2 == NULL)
163                         return TRUE;
164                 else
165                         return FALSE;
166         }
167         
168         if (s2 == NULL)
169                 return FALSE;
170
171         return strcmp (s1, s2) == 0;
172 }
173
174 static gint
175 hula_url_equal (gconstpointer a, gconstpointer b)
176 {
177         const CamelURL *u1 = a, *u2 = b;
178         
179         return check_equal (u1->protocol, u2->protocol)
180                 && check_equal (u1->user, u2->user)
181                 && check_equal (u1->authmech, u2->authmech)
182                 && check_equal (u1->host, u2->host)
183                 && u1->port == u2->port;
184 }