~ubuntu-branches/ubuntu/karmic/libtinymail/karmic

« back to all changes in this revision

Viewing changes to libtinymail-camel/camel-lite/camel/providers/nntp/camel-nntp-provider.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-10-12 11:21:12 UTC
  • Revision ID: james.westby@ubuntu.com-20071012112112-fod9fs7yrooxjr7i
Tags: upstream-0.0.2
ImportĀ upstreamĀ versionĀ 0.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/* camel-nntp-provider.c: nntp provider registration code */
 
3
 
 
4
/* 
 
5
 * Authors :
 
6
 *   Chris Toshok <toshok@ximian.com>
 
7
 *
 
8
 * Copyright (C) 2000 Ximian, Inc. (www.ximian.com)
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or 
 
11
 * modify it under the terms of version 2 of the GNU Lesser General Public 
 
12
 * License as published by the Free Software Foundation.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU Lesser General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
22
 * USA
 
23
 */
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include <config.h>
 
27
#endif
 
28
 
 
29
#include <string.h>
 
30
 
 
31
#include <glib/gi18n-lib.h>
 
32
 
 
33
#include "camel-nntp-store.h"
 
34
#include "camel-provider.h"
 
35
#include "camel-session.h"
 
36
 
 
37
static void add_hash (guint *hash, char *s);
 
38
static guint nntp_url_hash (gconstpointer key);
 
39
static gint check_equal (char *s1, char *s2);
 
40
static gint nntp_url_equal (gconstpointer a, gconstpointer b);
 
41
 
 
42
static CamelProviderConfEntry nntp_conf_entries[] = {
 
43
        { CAMEL_PROVIDER_CONF_SECTION_START, "folders", NULL,
 
44
          N_("Folders") },
 
45
        { CAMEL_PROVIDER_CONF_CHECKBOX, "show_short_notation", NULL,
 
46
          N_("Show folders in short notation (e.g. c.o.linux rather than comp.os.linux)"), "1" },
 
47
        { CAMEL_PROVIDER_CONF_CHECKBOX, "folder_hierarchy_relative", NULL,
 
48
          N_("In the subscription dialog, show relative folder names"), "1" },
 
49
        { CAMEL_PROVIDER_CONF_SECTION_END },
 
50
        { CAMEL_PROVIDER_CONF_END }
 
51
};
 
52
 
 
53
static CamelProvider news_provider = {
 
54
        "nntp",
 
55
        N_("USENET news"),
 
56
 
 
57
        N_("This is a provider for reading from and posting to "
 
58
           "USENET newsgroups."),
 
59
 
 
60
        "news",
 
61
 
 
62
        CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
 
63
        CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL,
 
64
 
 
65
        CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_USER |
 
66
        CAMEL_URL_ALLOW_PASSWORD | CAMEL_URL_ALLOW_AUTH,
 
67
 
 
68
        nntp_conf_entries
 
69
 
 
70
        /* ... */
 
71
};
 
72
 
 
73
CamelServiceAuthType camel_nntp_password_authtype = {
 
74
        N_("Password"),
 
75
 
 
76
        N_("This option will authenticate with the NNTP server using a "
 
77
           "plaintext password."),
 
78
 
 
79
        "",
 
80
        TRUE
 
81
};
 
82
 
 
83
void
 
84
camel_provider_module_init(void)
 
85
{
 
86
        news_provider.object_types[CAMEL_PROVIDER_STORE] = camel_nntp_store_get_type();
 
87
 
 
88
        news_provider.url_hash = nntp_url_hash;
 
89
        news_provider.url_equal = nntp_url_equal;
 
90
        news_provider.authtypes = g_list_append (NULL, &camel_nntp_password_authtype);
 
91
        news_provider.translation_domain = GETTEXT_PACKAGE;
 
92
        
 
93
        camel_provider_register(&news_provider);
 
94
}
 
95
 
 
96
static void
 
97
add_hash (guint *hash, char *s)
 
98
{
 
99
        if (s)
 
100
                *hash ^= g_str_hash(s);
 
101
}
 
102
 
 
103
static guint
 
104
nntp_url_hash (gconstpointer key)
 
105
{
 
106
        const CamelURL *u = (CamelURL *)key;
 
107
        guint hash = 0;
 
108
 
 
109
        add_hash (&hash, u->user);
 
110
        add_hash (&hash, u->host);
 
111
        hash ^= u->port;
 
112
        
 
113
        return hash;
 
114
}
 
115
 
 
116
static gint
 
117
check_equal (char *s1, char *s2)
 
118
{
 
119
        if (s1 == NULL) {
 
120
                if (s2 == NULL)
 
121
                        return TRUE;
 
122
                else
 
123
                        return FALSE;
 
124
        }
 
125
        
 
126
        if (s2 == NULL)
 
127
                return FALSE;
 
128
 
 
129
        return strcmp (s1, s2) == 0;
 
130
}
 
131
 
 
132
static gint
 
133
nntp_url_equal (gconstpointer a, gconstpointer b)
 
134
{
 
135
        const CamelURL *u1 = a, *u2 = b;
 
136
        
 
137
        return check_equal(u1->protocol, u2->protocol)
 
138
                && check_equal (u1->user, u2->user)
 
139
                && check_equal (u1->host, u2->host)
 
140
                && u1->port == u2->port;
 
141
}