[evolution-kolab/ek-wip-porting] libekolabutil: fixed KolabUtilHttpJob password handling for Camel changes



commit 3f78d7cae34cab246e2059589d5b875c73d97014
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Mar 19 12:00:59 2012 +0100

    libekolabutil: fixed KolabUtilHttpJob password handling for Camel changes
    
    * CamelURL does no longer carry authentication information
    * thus added the password housekeeping to KolabUtilHttpJob
    * depending on KolabUtilHttpJob::passwd being set or unset,
      it will be set or unset in the resulting Curl request

 src/libekolabutil/kolab-util-http.c |   53 +++++++++++++++++++----------------
 src/libekolabutil/kolab-util-http.h |    1 +
 2 files changed, 30 insertions(+), 24 deletions(-)
---
diff --git a/src/libekolabutil/kolab-util-http.c b/src/libekolabutil/kolab-util-http.c
index e38e047..f5f24fb 100644
--- a/src/libekolabutil/kolab-util-http.c
+++ b/src/libekolabutil/kolab-util-http.c
@@ -111,6 +111,7 @@ kolab_util_http_job_new (void)
 	job->url = NULL;
 	job->buffer = NULL;
 	job->nbytes = 0;
+	job->passwd = NULL;
 	job->pkcs11pin = NULL;
 
 	return job;
@@ -124,9 +125,10 @@ kolab_util_http_job_free (KolabUtilHttpJob *job)
 
 	if (job->url != NULL)
 		camel_url_free (job->url);
-	if (job->buffer != NULL) {
+	if (job->buffer != NULL)
 		g_byte_array_free (job->buffer, TRUE);
-	}
+	if (job->passwd != NULL)
+		g_free (job->passwd);
 	if (job->pkcs11pin != NULL)
 		g_free (job->pkcs11pin);
 	g_free (job);
@@ -181,8 +183,8 @@ kolab_util_http_soup_get (const KolabUtilHttpJob *job, GError **error)
 	 */
 	if (g_signal_handler_is_connected (kolab_soup_session,
 	                                   kolab_soup_auth_handler_id))
-	    g_signal_handler_disconnect (kolab_soup_session,
-	                                 kolab_soup_auth_handler_id);
+		g_signal_handler_disconnect (kolab_soup_session,
+		                             kolab_soup_auth_handler_id);
 	kolab_soup_auth_handler_id = g_signal_connect (kolab_soup_session,
 	                                               "authenticate",
 	                                               G_CALLBACK (kolab_util_http_soup_authenticate),
@@ -324,23 +326,26 @@ kolab_util_http_curl_set_jobopts (const KolabUtilHttpJob *job)
 
 	/* set username/password for basic auth */
 	if (job->url->user != NULL) {
-		/* FIXME get password from CamelSettings (change KolabUtilHttpJob) */
-		g_warning ("%s: FIXME get password from CamelSettings", __func__);
-#if 0
-		if (job->url->passwd != NULL)
+		if (job->passwd != NULL) {
 			usrpwd = g_strconcat (job->url->user,
 			                      ":",
-			                      job->url->passwd,
+			                      job->passwd,
 			                      NULL);
-		else
+		} else {
+			usrpwd = g_strdup (job->url->user);
 			g_debug ("%s: username given but password not set",
 			         __func__);
-#endif
+		}
 	}
 	if (usrpwd != NULL) {
-		curlcode = curl_easy_setopt (kolab_curl_handle,
-			                     CURLOPT_USERPWD,
-			                     usrpwd);
+		if (job->passwd != NULL)
+			curlcode = curl_easy_setopt (kolab_curl_handle,
+			                             CURLOPT_USERPWD,
+			                             usrpwd);
+		else
+			curlcode = curl_easy_setopt (kolab_curl_handle,
+			                             CURLOPT_USERNAME,
+			                             usrpwd);
 		g_free (usrpwd);
 		if (curlcode)
 			return curlcode;
@@ -514,15 +519,15 @@ kolab_util_http_get (KolabUtilHttpJob *job, GError **error)
 	KolabUtilHttpLib httplib = KOLAB_UTIL_HTTP_LIB_CURL;
 
 	switch (httplib) {
-		case KOLAB_UTIL_HTTP_LIB_SOUP:
-			nbytes = kolab_util_http_soup_get (job, error);
-			break;
-		case KOLAB_UTIL_HTTP_LIB_CURL:
-			nbytes = kolab_util_http_curl_get (job, error);
-			break;
-		default:
-			/* can't happen */
-			g_assert_not_reached();
+	case KOLAB_UTIL_HTTP_LIB_SOUP:
+		nbytes = kolab_util_http_soup_get (job, error);
+		break;
+	case KOLAB_UTIL_HTTP_LIB_CURL:
+		nbytes = kolab_util_http_curl_get (job, error);
+		break;
+	default:
+		/* can't happen */
+		g_assert_not_reached();
 	}
 #endif
 
@@ -608,7 +613,7 @@ kolab_util_http_protocol_is_ssl (const gchar *url_string)
 	scheme_utf8_tmp1 = g_utf8_casefold ("https\0", -1); /* TODO improve! */
 	if (g_utf8_collate (scheme_utf8_tmp1, scheme_utf8_tmp2) == 0)
 		is_ssl = TRUE;
-skip:
+ skip:
 	if (scheme_utf8_tmp2 != NULL)
 		g_free (scheme_utf8_tmp2);
 	if (scheme_utf8_tmp1 != NULL)
diff --git a/src/libekolabutil/kolab-util-http.h b/src/libekolabutil/kolab-util-http.h
index 08809e3..4dcdab1 100644
--- a/src/libekolabutil/kolab-util-http.h
+++ b/src/libekolabutil/kolab-util-http.h
@@ -74,6 +74,7 @@ typedef struct _KolabUtilHttpJob {
 	CamelURL *url;
 	GByteArray *buffer;
 	gssize nbytes;
+	gchar *passwd;
 	gchar *pkcs11pin;
 } KolabUtilHttpJob;
 



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