[evolution-kolab/ek-wip-xfb: 6/8] libekolabutil: HTTP init function takes user home argument



commit 88f719d515decbaf8ebfc3ab758e5c565b286863
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Tue Oct 23 12:03:37 2012 +0200

    libekolabutil: HTTP init function takes user home argument
    
    * when initializing HTTP utils, we may want
      to set the path to the nssdb
    * this is a generic (not per-HTTP-job) setting,
      so we need the value in the init() itself
    * adapted all occurrences of kolab_util_http_init()

 src/addressbook/e-book-backend-kolab.c             |   13 ++++++-
 src/calendar/e-cal-backend-kolab.c                 |   11 ++++++-
 src/libekolabutil/kolab-util-http.c                |   34 +++++++++++++++++--
 src/libekolabutil/kolab-util-http.h                |    2 +-
 .../libekolab/test-kolab-util-cal-freebusy.c       |    3 +-
 .../integration/libekolab/test-kolab-util-http.c   |    3 +-
 6 files changed, 56 insertions(+), 10 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-kolab.c b/src/addressbook/e-book-backend-kolab.c
index 0bfb832..456144b 100644
--- a/src/addressbook/e-book-backend-kolab.c
+++ b/src/addressbook/e-book-backend-kolab.c
@@ -250,6 +250,7 @@ book_backend_kolab_open (EBookBackendSync *backend,
 	const gchar *foldername = NULL;
 	gchar *servername = NULL;
 	gchar *username = NULL;
+	const gchar *user_home = NULL;
 	gboolean online = FALSE;
 	gboolean ok = FALSE;
 	GError *tmp_err = NULL;
@@ -282,13 +283,13 @@ book_backend_kolab_open (EBookBackendSync *backend,
 	extension_name = E_SOURCE_EXTENSION_KOLAB_FOLDER;
 	extension = e_source_get_extension (esource, extension_name);
 	sync_value = e_source_kolab_folder_get_sync_strategy (extension);
-	
+
 	online = e_backend_get_online (E_BACKEND (backend));
 	foldername = kolab_util_backend_get_foldername (E_BACKEND (backend));
 
 	/* init subsystems (these are no-ops if already called before) */
 	kolab_util_glib_init ();
-	kolab_util_http_init ();
+
 	/* libcamel
 	 * Curl init may configure the underlying SSL lib,
 	 * but as far as SSL goes, we want Camel to rule here
@@ -316,6 +317,14 @@ book_backend_kolab_open (EBookBackendSync *backend,
 	                                     foldername,
 	                                     &sync_value);
 
+	/* init the HTTP utils */
+	user_home = kolab_settings_handler_get_char_field (ksettings,
+	                                                   KOLAB_SETTINGS_HANDLER_CHAR_FIELD_USER_HOME_DIR,
+	                                                   &tmp_err);
+	if (tmp_err != NULL)
+		goto exit;
+	kolab_util_http_init (user_home);
+
 	/* create new KolabMailAccess instance */
 	priv->book_koma = KOLAB_MAIL_ACCESS (g_object_new (KOLAB_TYPE_MAIL_ACCESS, NULL));
 
diff --git a/src/calendar/e-cal-backend-kolab.c b/src/calendar/e-cal-backend-kolab.c
index c4bc041..f0bdf4b 100644
--- a/src/calendar/e-cal-backend-kolab.c
+++ b/src/calendar/e-cal-backend-kolab.c
@@ -277,6 +277,7 @@ cal_backend_kolab_open (ECalBackendSync *backend,
 	gchar *cache_filename = NULL;
 	gchar *servername = NULL;
 	gchar *username = NULL;
+	const gchar *user_home = NULL;
 	gboolean online = FALSE;
 	gboolean ok = FALSE;
 	GError *tmp_err = NULL;
@@ -370,6 +371,14 @@ cal_backend_kolab_open (ECalBackendSync *backend,
 	                                     foldername,
 	                                     &sync_value);
 
+	/* init the HTTP utils */
+	user_home = kolab_settings_handler_get_char_field (ksettings,
+	                                                   KOLAB_SETTINGS_HANDLER_CHAR_FIELD_USER_HOME_DIR,
+	                                                   &tmp_err);
+	if (tmp_err != NULL)
+		goto exit;
+	kolab_util_http_init (user_home);
+
 	/* create new KolabMailAccess instance */
 	priv->cal_koma = KOLAB_MAIL_ACCESS (g_object_new (KOLAB_TYPE_MAIL_ACCESS, NULL));
 
@@ -1895,7 +1904,7 @@ e_cal_backend_kolab_init (ECalBackendKolab *backend)
 
 	/* init subsystems (these are no-ops if already called before) */
 	kolab_util_glib_init ();
-	kolab_util_http_init ();
+
 	/* libcamel
 	 * Curl init may configure the underlying SSL lib,
 	 * but as far as SSL goes, we want Camel to rule here
diff --git a/src/libekolabutil/kolab-util-http.c b/src/libekolabutil/kolab-util-http.c
index a11ae86..ee32628 100644
--- a/src/libekolabutil/kolab-util-http.c
+++ b/src/libekolabutil/kolab-util-http.c
@@ -60,7 +60,9 @@
 
 #include "camel-kolab-stream.h"
 #include "camel-system-headers.h"
+
 #include "kolab-util-http.h"
+#include "kolab-util.h"
 
 /*----------------------------------------------------------------------------*/
 
@@ -142,10 +144,13 @@ util_http_curl_writefunc (const void *data,
 }
 
 static CURLcode
-util_http_curl_set_genopts (void)
+util_http_curl_set_genopts (const gchar *user_home)
 {
-	/* TODO change this to table-based for-loop */
 	CURLcode curlcode; /* can't bit-or this... */
+	gchar *capath = NULL;
+
+	/* user_home may be NULL */
+
 	curlcode =  curl_easy_setopt (kolab_curl_handle,
 	                              CURLOPT_VERBOSE,
 	                              KOLAB_UTIL_HTTP_CURL_DEBUG);
@@ -174,6 +179,7 @@ util_http_curl_set_genopts (void)
 	                             CURLOPT_FOLLOWLOCATION,
 	                             KOLAB_UTIL_HTTP_CURL_FOLLOW_REDIRECTS);
 	if (curlcode) return curlcode;
+
 	/* SSL setup
 	 * The following may fail if NSS is not yet initialized
 	 */
@@ -186,6 +192,23 @@ util_http_curl_set_genopts (void)
 	                             KOLAB_UTIL_HTTP_CURL_SSL_VERIFY_HOST);
 	if (curlcode) return curlcode;
 
+	/* set the CAPATH to the nssdb (works for NSS only,
+	 * which we depend upon)
+	 */
+	if (user_home == NULL)
+		goto capath_skip;
+
+	capath = g_build_path (KOLAB_PATH_SEPARATOR_S,
+	                       user_home,
+	                       KOLAB_UTIL_HTTP_CURL_NSS_CERTDB,
+	                       NULL);
+	curlcode = curl_easy_setopt (kolab_curl_handle,
+	                             CURLOPT_CAPATH,
+	                             capath);
+	g_free (capath);
+
+ capath_skip:
+
 	/* TODO more here
 	 * - HTTP options (referrers, encoding, follow, user-agent...)
 	 */
@@ -321,6 +344,7 @@ util_http_curl_get (KolabUtilHttpJob *job, GError **error)
 
 /**
  * kolab_util_http_init:
+ * @user_home: path to the user's home directory
  *
  * Initializes the HTTP subsystem. This means
  * <itemizedlist>
@@ -332,11 +356,13 @@ util_http_curl_get (KolabUtilHttpJob *job, GError **error)
  * functions.
  */
 void
-kolab_util_http_init (void)
+kolab_util_http_init (const gchar *user_home)
 {
 	glong curl_global_flags;
 	static gboolean http_is_initialized = FALSE;
 
+	/* user_home may be NULL */
+
 	if (http_is_initialized == TRUE)
 		return;
 
@@ -352,7 +378,7 @@ kolab_util_http_init (void)
 
 	kolab_curl_handle = curl_easy_init ();
 	g_assert (kolab_curl_handle != NULL);
-	util_http_curl_set_genopts ();
+	util_http_curl_set_genopts (user_home);
 	http_is_initialized = TRUE;
 }
 
diff --git a/src/libekolabutil/kolab-util-http.h b/src/libekolabutil/kolab-util-http.h
index 4dcdab1..27401ae 100644
--- a/src/libekolabutil/kolab-util-http.h
+++ b/src/libekolabutil/kolab-util-http.h
@@ -78,7 +78,7 @@ typedef struct _KolabUtilHttpJob {
 	gchar *pkcs11pin;
 } KolabUtilHttpJob;
 
-void kolab_util_http_init (void);
+void kolab_util_http_init (const gchar *user_home);
 void kolab_util_http_shutdown (void);
 
 KolabUtilHttpJob* kolab_util_http_job_new (void);
diff --git a/src/tests/integration/libekolab/test-kolab-util-cal-freebusy.c b/src/tests/integration/libekolab/test-kolab-util-cal-freebusy.c
index a558404..aa66229 100644
--- a/src/tests/integration/libekolab/test-kolab-util-cal-freebusy.c
+++ b/src/tests/integration/libekolab/test-kolab-util-cal-freebusy.c
@@ -144,7 +144,8 @@ test_kolab_util_cal_freebusy (void)
 
 	/* init subsystems */
 	kolab_util_glib_init ();
-	kolab_util_http_init ();
+	kolab_util_http_init (g_get_home_dir ());
+
 	/* libcamel
 	 *
 	 * Curl init may configure the underlying SSL lib,
diff --git a/src/tests/integration/libekolab/test-kolab-util-http.c b/src/tests/integration/libekolab/test-kolab-util-http.c
index 318f172..4449471 100644
--- a/src/tests/integration/libekolab/test-kolab-util-http.c
+++ b/src/tests/integration/libekolab/test-kolab-util-http.c
@@ -68,7 +68,8 @@ test_kolab_util_http (void)
 
 	/* init subsystems */
 	kolab_util_glib_init ();
-	kolab_util_http_init ();
+	kolab_util_http_init (g_get_home_dir ());
+
 	/* libcamel
 	 *
 	 * Curl init may configure the underlying SSL lib,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]