So it turns out that NSS_Init *isn't* idempotent, so we have to protect
authorJeffrey Stedfast <fejj@ximian.com>
Thu, 15 Mar 2001 01:59:00 +0000 (01:59 +0000)
committerJeffrey Stedfast <fejj@src.gnome.org>
Thu, 15 Mar 2001 01:59:00 +0000 (01:59 +0000)
2001-03-14  Jeffrey Stedfast  <fejj@ximian.com>

* camel.c (camel_init): So it turns out that NSS_Init *isn't*
idempotent, so we have to protect against initializing it more
than once(contrary to what their design specs suggest).

* camel-session.c (camel_session_get_service): Use
camel_exception_is_set() - Makes no difference but it's more
consistant with how we normally do it.

* camel-provider.h (CAMEL_URL_ALLOW_SSL): We don't need this.

* providers/imap/camel-imap-provider.c: Define the imaps provider.
(camel_provider_module_init): Register the imaps provider.

* camel-provider.c (camel_provider_init): Only add the protocol to
the hash table if it's non empty. Also, g_strdup() the filename
into the hash table.

* providers/imap/camel-imap-store.c (camel_imap_store_init): Eek!
So the service's URL isn't set until after this is
initialized. This means we can't check for SSL here.
(imap_connect): Set the SSL options here instead.

camel/ChangeLog
camel/camel-provider.c
camel/camel-provider.h
camel/camel-session.c
camel/camel.c
camel/camel.h
camel/providers/imap/camel-imap-provider.c

index 5413446..a1f0bca 100644 (file)
@@ -1,5 +1,22 @@
 2001-03-14  Jeffrey Stedfast  <fejj@ximian.com>
 
+       * camel.c (camel_init): So it turns out that NSS_Init *isn't*
+       idempotent, so we have to protect against initializing it more
+       than once(contrary to what their design specs suggest).
+
+       * camel-session.c (camel_session_get_service): Use
+       camel_exception_is_set() - Makes no difference but it's more
+       consistant with how we normally do it.
+
+       * camel-provider.h (CAMEL_URL_ALLOW_SSL): We don't need this.
+
+       * providers/imap/camel-imap-provider.c: Define the imaps provider.
+       (camel_provider_module_init): Register the imaps provider.
+
+       * camel-provider.c (camel_provider_init): Only add the protocol to
+       the hash table if it's non empty. Also, g_strdup() the filename
+       into the hash table.
+
        * providers/imap/camel-imap-store.c (camel_imap_store_init): Eek!
        So the service's URL isn't set until after this is
        initialized. This means we can't check for SSL here.
index 03be7cd..4549445 100644 (file)
@@ -61,8 +61,7 @@ camel_provider_init (void)
        DIR *dir;
        struct dirent *d;
        char *p, *name, buf[80];
-       FILE *f;
-
+       
        providers = g_hash_table_new (g_strcase_hash, g_strcase_equal);
 
        dir = opendir (CAMEL_PROVIDERDIR);
@@ -73,30 +72,35 @@ camel_provider_init (void)
        }
 
        while ((d = readdir (dir))) {
+               FILE *fp;
+               
                p = strchr (d->d_name, '.');
                if (!p || strcmp (p, ".urls") != 0)
                        continue;
 
                name = g_strdup_printf ("%s/%s", CAMEL_PROVIDERDIR, d->d_name);
-               f = fopen (name, "r");
-               if (!f) {
+               fp = fopen (name, "r");
+               if (!fp) {
                        g_warning ("Could not read provider info file %s: %s",
                                   name, g_strerror (errno));
                        g_free (name);
                        continue;
                }
-
+               
                p = strrchr (name, '.');
                strcpy (p, ".so");
-               while ((fgets (buf, sizeof (buf), f))) {
+               while ((fgets (buf, sizeof (buf), fp))) {
                        buf[sizeof (buf) - 1] = '\0';
                        p = strchr (buf, '\n');
                        if (p)
                                *p = '\0';
-
-                       g_hash_table_insert (providers, g_strdup (buf), name);
+                       
+                       if (*buf)
+                               g_hash_table_insert (providers, g_strdup (buf), g_strdup (name));
                }
-               fclose (f);
+               
+               g_free (name);
+               fclose (fp);
        }
 
        closedir (dir);
index f6c5882..07d6210 100644 (file)
@@ -78,8 +78,6 @@ extern char *camel_provider_type_name[CAMEL_NUM_PROVIDER_TYPES];
 
 #define CAMEL_URL_PATH_IS_ABSOLUTE (1 << 12)
 
-#define CAMEL_URL_ALLOW_SSL      (1 << 13)
-
 typedef struct {
        /* Provider name used in CamelURLs. */
        char *protocol;
index 6fed6bf..cb402a3 100644 (file)
@@ -308,8 +308,7 @@ camel_session_get_service (CamelSession *session, const char *url_string,
                path = g_hash_table_lookup (session->modules, url->protocol);
                if (path) {
                        camel_provider_load (session, path, ex);
-                       if (camel_exception_get_id (ex) !=
-                           CAMEL_EXCEPTION_NONE) {
+                       if (camel_exception_is_set (ex)) {
                                camel_url_free (url);
                                CAMEL_SESSION_UNLOCK(session, lock);
                                return NULL;
index 38ad4a9..5b10247 100644 (file)
@@ -27,8 +27,8 @@
 #include "camel.h"
 #include <unicode.h>
 #ifdef HAVE_NSS
-#include <mozilla/nspr.h>
-#include <mozilla/prthread.h>
+#include <nspr.h>
+#include <prthread.h>
 #include <nss.h>
 #include <ssl.h>
 #endif /* HAVE_NSS */
@@ -36,7 +36,7 @@
 gboolean camel_verbose_debug = FALSE;
 
 gint
-camel_init (const char *certdb)
+camel_init (const char *certdb_dir, gboolean nss_init)
 {
 #ifdef ENABLE_THREADS
 #ifdef G_THREADS_ENABLED       
@@ -52,15 +52,17 @@ camel_init (const char *certdb)
        unicode_init ();
        
 #ifdef HAVE_NSS
-       PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 10);
-       
-       if (NSS_Init ("/home/fejj/.mozilla/default") == SECFailure) {
-               g_warning ("Failed to initialize NSS");
-               return -1;
+       if (nss_init) {
+               PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 10);
+               
+               if (NSS_Init ("/home/fejj/.mozilla/default") == SECFailure) {
+                       g_warning ("Failed to initialize NSS");
+                       return -1;
+               }
+               
+               NSS_SetDomesticPolicy ();
        }
        
-       NSS_SetDomesticPolicy ();
-       
        SSL_OptionSetDefault (SSL_ENABLE_SSL2, PR_TRUE);
        SSL_OptionSetDefault (SSL_ENABLE_SSL3, PR_TRUE);
        SSL_OptionSetDefault (SSL_ENABLE_TLS, PR_TRUE);
index fc50f3e..cc66090 100644 (file)
@@ -68,7 +68,7 @@ extern "C" {
 #include <camel/hash-table-utils.h>
 #include <camel/string-utils.h>
 
-gint camel_init (const char *certdb);
+gint camel_init (const char *certdb_dir, gboolean nss_init);
 
 void camel_shutdown (void);
 
index 91f3972..1fff8dc 100644 (file)
@@ -46,23 +46,54 @@ static CamelProvider imap_provider = {
        CAMEL_PROVIDER_IS_STORAGE,
 
        CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST |
-       CAMEL_URL_ALLOW_PATH | CAMEL_URL_ALLOW_AUTH |
-       CAMEL_URL_ALLOW_SSL,
+       CAMEL_URL_ALLOW_PATH | CAMEL_URL_ALLOW_AUTH,
 
        { 0, 0 },
 
        NULL
 };
 
+#if defined (HAVE_NSS) || defined (HAVE_OPENSSL)
+static CamelProvider imaps_provider = {
+       "imaps",
+       N_("Secure IMAPv4"),
+
+       N_("For reading and storing mail on IMAP servers over an SSL connection."),
+
+       "mail",
+
+       CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
+       CAMEL_PROVIDER_IS_STORAGE,
+
+       CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST |
+       CAMEL_URL_ALLOW_PATH | CAMEL_URL_ALLOW_AUTH,
+
+       { 0, 0 },
+
+       NULL
+};
+#endif /* HAVE_NSS or HAVE_OPENSSL */
+
 void
 camel_provider_module_init (CamelSession *session)
 {
        imap_provider.object_types[CAMEL_PROVIDER_STORE] =
-               camel_imap_store_get_type();
-
+               camel_imap_store_get_type ();
+#if defined (HAVE_NSS) || defined (HAVE_OPENSSL)
+       imaps_provider.object_types[CAMEL_PROVIDER_STORE] = 
+               camel_imap_store_get_type ();
+#endif
+       
        imap_provider.service_cache = g_hash_table_new (imap_url_hash, imap_url_equal);
-
+       
+#if defined (HAVE_NSS) || defined (HAVE_OPENSSL)
+       imaps_provider.service_cache = g_hash_table_new (imap_url_hash, imap_url_equal);
+#endif
+       
        camel_session_register_provider (session, &imap_provider);
+#if defined (HAVE_NSS) || defined (HAVE_OPENSSL)
+       camel_session_register_provider (session, &imaps_provider);
+#endif
 }
 
 static void