evolution-data-server r8382 - in trunk/calendar: . backends/caldav backends/http backends/weather
- From: kmaraas svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r8382 - in trunk/calendar: . backends/caldav backends/http backends/weather
- Date: Thu, 17 Jan 2008 13:11:35 +0000 (GMT)
Author: kmaraas
Date: Thu Jan 17 13:11:35 2008
New Revision: 8382
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8382&view=rev
Log:
2008-01-15 Dan Winship <danw gnome org>
* backends/caldav/e-cal-backend-caldav.c: Update for libsoup 2.4.
* backends/http/e-cal-backend-http.c: Update for libsoup 2.4
* backends/weather/e-weather-source-ccf.c: Update for libsoup 2.4.
Remove the manual redirection handling that was copied from
e-cal-backend-http, since we can let libsoup do it here. (The http
backend needs to worry about "webcal:" URIs; weather doesn't.)
Modified:
trunk/calendar/ChangeLog
trunk/calendar/backends/caldav/e-cal-backend-caldav.c
trunk/calendar/backends/http/e-cal-backend-http.c
trunk/calendar/backends/weather/e-weather-source-ccf.c
Modified: trunk/calendar/backends/caldav/e-cal-backend-caldav.c
==============================================================================
--- trunk/calendar/backends/caldav/e-cal-backend-caldav.c (original)
+++ trunk/calendar/backends/caldav/e-cal-backend-caldav.c Thu Jan 17 13:11:35 2008
@@ -43,9 +43,6 @@
/* LibSoup includes */
#include <libsoup/soup.h>
-#include <libsoup/soup-headers.h>
-#include <libsoup/soup-uri.h>
-#include <libsoup/soup-soap-message.h>
#include "e-cal-backend-caldav.h"
@@ -218,112 +215,26 @@
return FALSE;
}
-static void
-message_debug_print_header (gpointer name, gpointer value, gpointer data)
-{
- g_debug ("%s: %s", (char *) name, (char *) value);
-}
-
#define DEBUG_MAX_BODY_SIZE (100 * 1024 * 1024)
static void
-message_response_debug_handler (SoupMessage *msg, gpointer user_data)
+caldav_debug_setup (SoupSession *session)
{
+ SoupLogger *logger;
+ SoupLoggerLogLevel level;
- g_debug ("%d %s\nMessage-Debug: %p @ %lu",
- msg->status_code,
- msg->reason_phrase,
- msg,
- time (0));
-
- if (caldav_debug_show (DEBUG_MESSAGE_HEADER)) {
- /* print headers */
- soup_message_foreach_header (msg->response_headers,
- message_debug_print_header,
- NULL);
-
- }
-
- if (caldav_debug_show (DEBUG_MESSAGE_BODY)) {
-
- /* print response */
- if (msg->response.length) {
- char *body;
-
- //needed for null terminal and truncation
- body = g_strndup (msg->response.body,
- MIN (msg->response.length,
- DEBUG_MAX_BODY_SIZE));
-
- g_debug ("Response: \n[%s%s]%s", body,
- msg->response.length > DEBUG_MAX_BODY_SIZE ?
- " ..." : "",
- msg->response.length > DEBUG_MAX_BODY_SIZE ?
- " (trunkated)" : "");
-
- g_free (body);
- }
- }
+ if (caldav_debug_show (DEBUG_MESSAGE_BODY))
+ level = SOUP_LOGGER_LOG_BODY;
+ else if (caldav_debug_show (DEBUG_MESSAGE_HEADER))
+ level = SOUP_LOGGER_LOG_HEADERS;
+ else
+ level = SOUP_LOGGER_LOG_MINIMAL;
+
+ logger = soup_logger_new (level, DEBUG_MAX_BODY_SIZE);
+ soup_logger_attach (logger, session);
+ g_object_unref (logger);
}
-static void
-message_setup_debug (SoupMessage *msg)
-{
- const SoupUri *suri;
-
- if (G_LIKELY (! caldav_debug_show (DEBUG_MESSAGE))) {
- return;
- }
-
- suri = soup_message_get_uri (msg);
-
- g_debug ("%s %s%s%s HTTP/1.1\nMessage-ID: %p @ %lu",
- SOUP_MESSAGE (msg)->method,
- suri->path,
- suri->query ? "?" : "",
- suri->query ? suri->query : "",
- msg,
- (unsigned long) time (0));
-
- soup_message_add_handler (SOUP_MESSAGE (msg),
- SOUP_HANDLER_POST_BODY,
- message_response_debug_handler,
- NULL);
-
- if (G_LIKELY (! caldav_debug_show (DEBUG_MESSAGE_HEADER))) {
- return;
- }
-
- /* print message headers */
- message_debug_print_header ("Host", suri->host, NULL);
-
- soup_message_foreach_header (SOUP_MESSAGE (msg)->request_headers,
- message_debug_print_header,
- NULL);
-
- if (caldav_debug_show (DEBUG_MESSAGE_BODY)) {
-
- /* print response */
- if (msg->request.length) {
- char *body;
-
- //needed for null terminal and truncation
- body = g_strndup (msg->request.body,
- MIN (msg->request.length,
- DEBUG_MAX_BODY_SIZE));
-
- g_debug ("Request: \n[%s%s]%s", body,
- msg->request.length > DEBUG_MAX_BODY_SIZE ?
- " ..." : "",
- msg->request.length > DEBUG_MAX_BODY_SIZE ?
- " (trunkated)" : "");
-
- g_free (body);
- }
- }
-}
-
-
static ECalBackendSyncClass *parent_class = NULL;
/* ************************************************************************* */
@@ -504,42 +415,6 @@
}
/* ************************************************************************* */
-static char **
-sm_join_and_split_header (SoupMessage *message, const char *header)
-{
- const GSList *list;
- char *str;
- char **sa;
- char *tofree;
-
- sa = NULL;
- list = soup_message_get_header_list (message->response_headers, header);
-
- if (list == NULL || list->data == NULL) {
- return NULL;
- }
-
- /* Only do string manipulation if really necessary */
- if (list->next) {
- GString *stmp;
- stmp = g_string_new ((gchar *) list->data);
-
- while ((list = list->next)) {
- g_string_append_printf (stmp, ",%s", (gchar *) list->data);
- }
-
- str = tofree = g_string_free (stmp, FALSE);
- } else {
- str = (char *) list->data;
- tofree = NULL;
- }
-
- g_assert (str != NULL);
- sa = g_strsplit (str, ",", 20);
- g_free (tofree);
-
- return sa;
-}
static ECalBackendSyncStatus
status_code_to_result (guint status_code)
@@ -571,23 +446,6 @@
return result;
}
-static gboolean
-match_header (const char *header, const char *string)
-{
- g_assert (string != NULL);
-
- if (header == NULL || header[0] == '\0') {
- return FALSE;
- }
-
- /* skip leading whitespaces */
- while (g_ascii_isspace (header[0])) {
- header++;
- }
-
- return !g_ascii_strncasecmp (header, string, strlen (string));
-}
-
/* !TS, call with lock held */
static ECalBackendSyncStatus
check_state (ECalBackendCalDAV *cbdav, gboolean *online)
@@ -818,8 +676,8 @@
g_return_val_if_fail (objs != NULL || len != NULL, FALSE);
res = TRUE;
- doc = xmlReadMemory (soup_message->response.body,
- soup_message->response.length,
+ doc = xmlReadMemory (soup_message->response_body->data,
+ soup_message->response_body->length,
"response.xml",
NULL,
0);
@@ -893,10 +751,8 @@
static void
soup_authenticate (SoupSession *session,
SoupMessage *msg,
- const char *auth_type,
- const char *auth_realm,
- char **username,
- char **password,
+ SoupAuth *auth,
+ gboolean retrying,
gpointer data)
{
ECalBackendCalDAVPrivate *priv;
@@ -905,36 +761,13 @@
cbdav = E_CAL_BACKEND_CALDAV (data);
priv = E_CAL_BACKEND_CALDAV_GET_PRIVATE (cbdav);
- *username = priv->username;
- *password = priv->password;
+ soup_auth_authenticate (auth, priv->username, priv->password);
priv->username = NULL;
priv->password = NULL;
}
-static void
-soup_reauthenticate (SoupSession *session,
- SoupMessage *msg,
- const char *auth_type,
- const char *auth_realm,
- char **username,
- char **password,
- gpointer data)
-{
- ECalBackendCalDAVPrivate *priv;
- ECalBackendCalDAV *cbdav;
-
- cbdav = E_CAL_BACKEND_CALDAV (data);
- priv = E_CAL_BACKEND_CALDAV_GET_PRIVATE (cbdav);
-
- *username = priv->username;
- *password = priv->password;
-
- priv->username = NULL;
- priv->password = NULL;
-}
-
static gint
caldav_ignore_host(gconstpointer a, gconstpointer b)
{
@@ -950,7 +783,7 @@
caldav_set_session_proxy(ECalBackendCalDAVPrivate *priv)
{
GConfClient *conf_client;
- SoupUri *uri_base;
+ SoupURI *uri_base;
if (priv->session == NULL)
return;
@@ -973,7 +806,7 @@
port = gconf_client_get_int (conf_client, "/system/http_proxy/port", NULL);
if (server && server[0]) {
- SoupUri *suri;
+ SoupURI *suri;
if (gconf_client_get_bool (conf_client, "/system/http_proxy/use_authentication", NULL)) {
char *user, *password;
user = gconf_client_get_string (conf_client,
@@ -1026,8 +859,7 @@
{
ECalBackendCalDAVPrivate *priv;
SoupMessage *message;
- char **sa;
- char **siter;
+ const char *header;
gboolean calendar_access;
gboolean put_allowed;
gboolean delete_allowed;
@@ -1037,10 +869,9 @@
/* FIXME: setup text_uri */
message = soup_message_new (SOUP_METHOD_OPTIONS, priv->uri);
- soup_message_add_header (message->request_headers,
- "User-Agent", "Evolution/" VERSION);
+ soup_message_headers_append (message->request_headers,
+ "User-Agent", "Evolution/" VERSION);
- message_setup_debug (message);
soup_session_send_message (priv->session, message);
if (! SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
@@ -1051,38 +882,20 @@
/* parse the dav header, we are intreseted in the
* calendar-access bit only at the moment */
- sa = sm_join_and_split_header (message, "DAV");
-
- calendar_access = FALSE;
- for (siter = sa; siter && *siter; siter++) {
-
- if (match_header (*siter, "calendar-access")) {
- calendar_access = TRUE;
- break;
- }
- }
-
- g_strfreev (sa);
-
-
- sa = sm_join_and_split_header (message, "Allow");
+ header = soup_message_headers_get (message->response_headers, "DAV");
+ if (header)
+ calendar_access = soup_header_contains (header, "calendar-access");
+ else
+ calendar_access = FALSE;
/* parse the Allow header and look for PUT, DELETE at the
* moment (maybe we should check more here, for REPORT eg) */
- put_allowed = delete_allowed = FALSE;
- for (siter = sa; siter && *siter; siter++) {
- if (match_header (*siter, "DELETE")) {
- delete_allowed = TRUE;
- } else if (match_header (*siter, "PUT")) {
- put_allowed = TRUE;
- }
-
- if (put_allowed && delete_allowed) {
- break;
- }
- }
-
- g_strfreev (sa);
+ header = soup_message_headers_get (message->response_headers, "Allow");
+ if (header) {
+ put_allowed = soup_header_contains (header, "PUT");
+ delete_allowed = soup_header_contains (header, "DELETE");
+ } else
+ put_allowed = delete_allowed = FALSE;
g_object_unref (message);
@@ -1140,19 +953,17 @@
/* Prepare the soup message */
message = soup_message_new ("REPORT", priv->uri);
- soup_message_add_header (message->request_headers,
- "User-Agent", "Evolution/" VERSION);
- soup_message_add_header (message->request_headers,
- "Depth", "1");
+ soup_message_headers_append (message->request_headers,
+ "User-Agent", "Evolution/" VERSION);
+ soup_message_headers_append (message->request_headers,
+ "Depth", "1");
soup_message_set_request (message,
"application/xml",
- SOUP_BUFFER_USER_OWNED,
+ SOUP_MEMORY_COPY,
(char *) buf->buffer->content,
buf->buffer->use);
- message_setup_debug (message);
-
/* Send the request now */
soup_session_send_message (priv->session, message);
@@ -1192,10 +1003,8 @@
message = soup_message_new (SOUP_METHOD_GET, uri);
g_free (uri);
- soup_message_add_header (message->request_headers,
- "User-Agent", "Evolution/" VERSION);
-
- message_setup_debug (message);
+ soup_message_headers_append (message->request_headers,
+ "User-Agent", "Evolution/" VERSION);
soup_session_send_message (priv->session, message);
@@ -1206,7 +1015,7 @@
return result;
}
- hdr = soup_message_get_header (message->response_headers, "Content-Type");
+ hdr = soup_message_headers_get (message->response_headers, "Content-Type");
if (hdr == NULL || g_ascii_strcasecmp (hdr, "text/calendar")) {
result = GNOME_Evolution_Calendar_InvalidObject;
@@ -1215,7 +1024,7 @@
return result;
}
- hdr = soup_message_get_header (message->response_headers, "ETag");
+ hdr = soup_message_headers_get (message->response_headers, "ETag");
if (hdr == NULL) {
g_warning ("UUHH no ETag, now that's bad!");
@@ -1224,9 +1033,7 @@
object->etag = quote_etag (hdr);
}
- /* Need to NULL terminate the string, do we? */
- object->cdata = g_malloc0 (message->response.length + 1);
- memcpy (object->cdata, message->response.body, message->response.length);
+ object->cdata = g_strdup (message->response_body->data);
g_object_unref (message);
return result;
@@ -1251,38 +1058,36 @@
message = soup_message_new (SOUP_METHOD_PUT, uri);
g_free (uri);
- soup_message_add_header (message->request_headers,
- "User-Agent", "Evolution/" VERSION);
+ soup_message_headers_append (message->request_headers,
+ "User-Agent", "Evolution/" VERSION);
/* For new items we use the If-None-Match so we don't
* acidently override resources, for item updates we
* use the If-Match header to avoid the Lost-update
* problem */
if (object->etag == NULL) {
- soup_message_add_header (message->request_headers,
- "If-None-Match", "*");
+ soup_message_headers_append (message->request_headers,
+ "If-None-Match", "*");
} else {
- soup_message_add_header (message->request_headers,
- "If-Match", object->etag);
+ soup_message_headers_append (message->request_headers,
+ "If-Match", object->etag);
}
soup_message_set_request (message,
"text/calendar",
- SOUP_BUFFER_USER_OWNED,
+ SOUP_MEMORY_COPY,
object->cdata,
strlen (object->cdata));
- message_setup_debug (message);
-
soup_session_send_message (priv->session, message);
/* FIXME: sepcial case precondition errors ?*/
result = status_code_to_result (message->status_code);
if (result == GNOME_Evolution_Calendar_Success) {
- hdr = soup_message_get_header (message->response_headers,
- "ETag");
+ hdr = soup_message_headers_get (message->response_headers,
+ "ETag");
}
if (hdr != NULL) {
@@ -1314,16 +1119,14 @@
message = soup_message_new (SOUP_METHOD_DELETE, uri);
g_free (uri);
- soup_message_add_header (message->request_headers,
- "User-Agent", "Evolution/" VERSION);
+ soup_message_headers_append (message->request_headers,
+ "User-Agent", "Evolution/" VERSION);
if (object->etag != NULL) {
- soup_message_add_header (message->request_headers,
- "If-Match", object->etag);
+ soup_message_headers_append (message->request_headers,
+ "If-Match", object->etag);
}
- message_setup_debug (message);
-
soup_session_send_message (priv->session, message);
result = status_code_to_result (message->status_code);
@@ -2781,6 +2584,9 @@
priv->session = soup_session_sync_new ();
+ if (G_UNLIKELY (caldav_debug_show (DEBUG_MESSAGE)))
+ caldav_debug_setup (priv->session);
+
priv->disposed = FALSE;
priv->do_synch = FALSE;
priv->loaded = FALSE;
@@ -2795,8 +2601,6 @@
g_signal_connect (priv->session, "authenticate",
G_CALLBACK (soup_authenticate), cbdav);
- g_signal_connect (priv->session, "reauthenticate",
- G_CALLBACK (soup_reauthenticate), cbdav);
e_cal_backend_sync_set_lock (E_CAL_BACKEND_SYNC (cbdav), FALSE);
}
Modified: trunk/calendar/backends/http/e-cal-backend-http.c
==============================================================================
--- trunk/calendar/backends/http/e-cal-backend-http.c (original)
+++ trunk/calendar/backends/http/e-cal-backend-http.c Thu Jan 17 13:11:35 2008
@@ -35,8 +35,7 @@
#include <libedata-cal/e-cal-backend-cache.h>
#include <libedata-cal/e-cal-backend-util.h>
#include <libedata-cal/e-cal-backend-sexp.h>
-#include <libsoup/soup-session-async.h>
-#include <libsoup/soup-uri.h>
+#include <libsoup/soup.h>
#include "e-cal-backend-http.h"
@@ -238,13 +237,12 @@
}
static void
-retrieval_done (SoupMessage *msg, ECalBackendHttp *cbhttp)
+retrieval_done (SoupSession *session, SoupMessage *msg, ECalBackendHttp *cbhttp)
{
ECalBackendHttpPrivate *priv;
icalcomponent *icalcomp, *subcomp;
icalcomponent_kind kind;
const char *newuri;
- char *str;
GHashTable *old_cache;
GList *comps_in_cache;
@@ -255,8 +253,8 @@
/* Handle redirection ourselves */
if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
- newuri = soup_message_get_header (msg->response_headers,
- "Location");
+ newuri = soup_message_headers_get (msg->response_headers,
+ "Location");
d(g_message ("Redirected to %s\n", newuri));
@@ -285,10 +283,7 @@
}
/* get the calendar from the response */
- str = g_malloc0 (msg->response.length + 1);
- strncpy (str, msg->response.body, msg->response.length);
- icalcomp = icalparser_parse_string (str);
- g_free (str);
+ icalcomp = icalparser_parse_string (msg->response_body->data);
if (!icalcomp) {
if (!priv->opened)
@@ -386,10 +381,8 @@
static void
soup_authenticate (SoupSession *session,
SoupMessage *msg,
- const char *auth_type,
- const char *auth_realm,
- char **username,
- char **password,
+ SoupAuth *auth,
+ gboolean retrying,
gpointer data)
{
ECalBackendHttpPrivate *priv;
@@ -398,36 +391,13 @@
cbhttp = E_CAL_BACKEND_HTTP (data);
priv = cbhttp->priv;
- *username = priv->username;
- *password = priv->password;
+ soup_auth_authenticate (auth, priv->username, priv->password);
priv->username = NULL;
priv->password = NULL;
}
-static void
-soup_reauthenticate (SoupSession *session,
- SoupMessage *msg,
- const char *auth_type,
- const char *auth_realm,
- char **username,
- char **password,
- gpointer data)
-{
- ECalBackendHttpPrivate *priv;
- ECalBackendHttp *cbhttp;
-
- cbhttp = E_CAL_BACKEND_HTTP (data);
- priv = cbhttp->priv;
-
- *username = priv->username;
- *password = priv->password;
-
- priv->username = NULL;
- priv->password = NULL;
-}
-
static gboolean reload_cb (ECalBackendHttp *cbhttp);
static void maybe_start_reload_timeout (ECalBackendHttp *cbhttp);
@@ -459,8 +429,6 @@
g_signal_connect (priv->soup_session, "authenticate",
G_CALLBACK (soup_authenticate), cbhttp);
- g_signal_connect (priv->soup_session, "reauthenticate",
- G_CALLBACK (soup_reauthenticate), cbhttp);
/* set the HTTP proxy, if configuration is set to do so */
conf_client = gconf_client_get_default ();
@@ -472,7 +440,7 @@
port = gconf_client_get_int (conf_client, "/system/http_proxy/port", NULL);
if (server && server[0]) {
- SoupUri *suri;
+ SoupURI *suri;
if (gconf_client_get_bool (conf_client, "/system/http_proxy/use_authentication", NULL)) {
char *user, *password;
@@ -512,12 +480,12 @@
/* create message to be sent to server */
soup_message = soup_message_new (SOUP_METHOD_GET, priv->uri);
- soup_message_add_header (soup_message->request_headers, "User-Agent",
- "Evolution/" VERSION);
+ soup_message_headers_append (soup_message->request_headers, "User-Agent",
+ "Evolution/" VERSION);
soup_message_set_flags (soup_message, SOUP_MESSAGE_NO_REDIRECT);
soup_session_queue_message (priv->soup_session, soup_message,
- (SoupMessageCallbackFn) retrieval_done, cbhttp);
+ (SoupSessionCallback) retrieval_done, cbhttp);
d(g_message ("Retrieval started.\n"));
return FALSE;
Modified: trunk/calendar/backends/weather/e-weather-source-ccf.c
==============================================================================
--- trunk/calendar/backends/weather/e-weather-source-ccf.c (original)
+++ trunk/calendar/backends/weather/e-weather-source-ccf.c Thu Jan 17 13:11:35 2008
@@ -390,38 +390,15 @@
}
static void
-retrieval_done (SoupMessage *message, EWeatherSourceCCF *source)
+retrieval_done (SoupSession *session, SoupMessage *message, EWeatherSourceCCF *source)
{
- char *str;
- const char *newuri;
-
- /* Handle redirection ourselves */
- if (SOUP_STATUS_IS_REDIRECTION (message->status_code)) {
- newuri = soup_message_get_header (message->response_headers, "Location");
-
- if (newuri) {
- SoupMessage *soup_message;
- soup_message = soup_message_new (SOUP_METHOD_GET, newuri);
- soup_message_set_flags (soup_message, SOUP_MESSAGE_NO_REDIRECT);
- soup_session_queue_message (source->soup_session, soup_message, (SoupMessageCallbackFn) retrieval_done, source);
- return;
- } else {
- source->done (NULL, source->finished_data);
- }
-
- return;
- }
-
/* check status code */
if (!SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
source->done (NULL, source->finished_data);
return;
}
- str = g_malloc0 (message->response.length + 1);
- strncpy (str, message->response.body, message->response.length);
- e_weather_source_ccf_do_parse (source, str);
- g_free (str);
+ e_weather_source_ccf_do_parse (source, (char *)message->response_body->data);
}
static void
@@ -448,7 +425,7 @@
port = gconf_client_get_int (conf_client, "/system/http_proxy/port", NULL);
if (server && server[0]) {
- SoupUri *suri;
+ SoupURI *suri;
if (gconf_client_get_bool (conf_client, "/system/http_proxy/use_authentication", NULL)) {
char *user, *password;
@@ -478,8 +455,7 @@
}
soup_message = soup_message_new (SOUP_METHOD_GET, ccfsource->url);
- soup_message_set_flags (soup_message, SOUP_MESSAGE_NO_REDIRECT);
- soup_session_queue_message (ccfsource->soup_session, soup_message, (SoupMessageCallbackFn) retrieval_done, source);
+ soup_session_queue_message (ccfsource->soup_session, soup_message, (SoupSessionCallback) retrieval_done, source);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]