1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
4 * Bertrand Guiheneuf <bertrand@helixcode.com>
6 * Copyright 1999-2003 Ximian, Inc. (www.ximian.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
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
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
34 #include "nss.h" /* Don't use <> here or it will include the system nss.h instead */
39 #include "camel-certdb.h"
40 #include "camel-debug.h"
41 #include "camel-i18n.h"
42 #include "camel-provider.h"
43 #include "camel-private.h"
45 static int initialised = FALSE;
55 #if defined (HAVE_NSS) && !defined (G_OS_WIN32)
56 /* For some reason we get into trouble on Win32 if we call these.
57 * But they shouldn't be necessary as the process is exiting anywy?
64 certdb = camel_certdb_get_default ();
66 camel_certdb_save (certdb);
67 camel_object_unref (certdb);
74 camel_init (const char *configdir, gboolean nss_init)
82 bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
83 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
87 /* initialise global camel_object_type */
88 camel_object_get_type();
92 PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 10);
94 if (NSS_InitReadWrite (configdir) == SECFailure) {
95 /* fall back on using volatile dbs? */
96 if (NSS_NoDB_Init (configdir) == SECFailure) {
97 g_warning ("Failed to initialize NSS");
102 NSS_SetDomesticPolicy ();
104 SSL_OptionSetDefault (SSL_ENABLE_SSL2, PR_TRUE);
105 SSL_OptionSetDefault (SSL_ENABLE_SSL3, PR_TRUE);
106 SSL_OptionSetDefault (SSL_ENABLE_TLS, PR_TRUE);
107 SSL_OptionSetDefault (SSL_V2_COMPATIBLE_HELLO, PR_TRUE /* maybe? */);
109 #endif /* HAVE_NSS */
111 path = g_strdup_printf ("%s/camel-cert.db", configdir);
112 certdb = camel_certdb_new ();
113 camel_certdb_set_filename (certdb, path);
116 /* if we fail to load, who cares? it'll just be a volatile certdb */
117 camel_certdb_load (certdb);
119 /* set this certdb as the default db */
120 camel_certdb_set_default (certdb);
122 camel_object_unref (certdb);
125 g_atexit (camel_shutdown);
127 /* In GLib (<= 2.8.0 at least, might get fixed later),
128 * g_atexit() is a function in the GLib DLL that calls the
129 * atexit() in the C runtime DLL. atexit() is implemented so
130 * that registered function will be called when the DLL
131 * containing the calling function is being detached from a
132 * process (not when exit() is called).
134 * We want to run camel_shutdown when the the process exits,
135 * or at least when the camel DLL is being detached, not when
136 * the GLib DLL is being detached.
138 atexit (camel_shutdown);