evolution-data-server r8978 - trunk/servers/google/libgdata-google
- From: mcrha svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r8978 - trunk/servers/google/libgdata-google
- Date: Fri, 13 Jun 2008 08:27:24 +0000 (UTC)
Author: mcrha
Date: Fri Jun 13 08:27:24 2008
New Revision: 8978
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8978&view=rev
Log:
2008-06-13 Milan Crha <mcrha redhat com>
** Fix for bug #521921 (Patch by Sebastian Keller)
* gdata-google-service.c: (send_and_handle_google_redirection),
(gdata_google_service_insert_entry),
(gdata_google_service_delete_entry),
(gdata_google_service_update_entry_with_link):
Handle redirects in a way that works with Google API. Fixes some cases
of entries not being created or deleted.
* gdata-google-service.c: (gdata_google_service_authenticate),
(gdata_google_service_get_feed): Code cleanup.
Modified:
trunk/servers/google/libgdata-google/ChangeLog
trunk/servers/google/libgdata-google/gdata-google-service.c
Modified: trunk/servers/google/libgdata-google/gdata-google-service.c
==============================================================================
--- trunk/servers/google/libgdata-google/gdata-google-service.c (original)
+++ trunk/servers/google/libgdata-google/gdata-google-service.c Fri Jun 13 08:27:24 2008
@@ -89,6 +89,36 @@
g_object_set (priv->soup_session, SOUP_SESSION_PROXY_URI, proxy, NULL);
}
+/* send a message without redirection and if it was required, then redirects itself */
+static void
+send_and_handle_google_redirection (SoupSession *soup_session, SoupMessage *msg)
+{
+ soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+ soup_session_send_message (soup_session, msg);
+ soup_message_set_flags (msg, 0);
+
+ if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
+ SoupURI *new_uri;
+ const char *new_loc;
+
+ new_loc = soup_message_headers_get (msg->response_headers, "Location");
+ g_return_if_fail (new_loc != NULL);
+
+ new_uri = soup_uri_new_with_base (soup_message_get_uri (msg), new_loc);
+ if (!new_uri) {
+ soup_message_set_status_full (msg,
+ SOUP_STATUS_MALFORMED,
+ "Invalid Redirect URL");
+ return;
+ }
+
+ soup_message_set_uri (msg, new_uri);
+ soup_uri_free (new_uri);
+
+ soup_session_send_message (soup_session, msg);
+ }
+}
+
static void
gdata_google_service_set_credentials (GDataService *service, const gchar *username, const gchar *password)
{
@@ -129,7 +159,6 @@
GHashTable *request_form;
gchar *request_body;
gchar *token = NULL;
- int http_status;
priv = GDATA_GOOGLE_SERVICE_GET_PRIVATE(service);
auth = (GDataGoogleServiceAuth *)priv->auth;
@@ -149,11 +178,11 @@
SOUP_MEMORY_TAKE,
request_body, strlen(request_body));
- http_status = soup_session_send_message (priv->soup_session, msg);
+ soup_session_send_message (priv->soup_session, msg);
- if (http_status != 200) {
+ if (msg->status_code != 200) {
g_set_error (error, SOUP_HTTP_ERROR,
- http_status, soup_status_get_phrase (http_status));
+ msg->status_code, msg->reason_phrase);
g_object_unref(msg);
return (NULL != token);
}
@@ -202,7 +231,6 @@
GDataGoogleServiceAuth *auth;
SoupSession *soup_session;
SoupMessage *msg;
- int http_status;
g_return_val_if_fail(service != NULL, NULL);
g_return_val_if_fail(GDATA_IS_GOOGLE_SERVICE(service),NULL);
@@ -221,10 +249,10 @@
soup_message_headers_append(msg->request_headers,
"Authorization", (gchar *)g_strdup_printf("GoogleLogin auth=%s", auth->token));
- http_status = soup_session_send_message(soup_session, msg);
- if (http_status != 200) {
+ soup_session_send_message (soup_session, msg);
+ if (msg->status_code != 200) {
g_set_error (error, SOUP_HTTP_ERROR,
- http_status, soup_status_get_phrase (http_status));
+ msg->status_code, msg->reason_phrase);
g_object_unref (msg);
return NULL;
}
@@ -263,7 +291,6 @@
SoupSession *soup_session;
SoupMessage *msg;
gchar *entry_xml;
- int http_status;
g_return_val_if_fail(service != NULL, NULL);
g_return_val_if_fail(GDATA_IS_GOOGLE_SERVICE(service), NULL);
@@ -292,10 +319,12 @@
entry_xml,
strlen(entry_xml));
- http_status = soup_session_send_message(soup_session, msg);
- if (http_status != 201) {
+ /* Handle redirects ourself, since soup does not behave like google-api expects */
+ send_and_handle_google_redirection (soup_session, msg);
+
+ if (msg->status_code != 201) {
g_set_error (error, SOUP_HTTP_ERROR,
- http_status, soup_status_get_phrase (http_status));
+ msg->status_code, msg->reason_phrase);
g_object_unref (msg);
return NULL;
}
@@ -331,7 +360,6 @@
SoupSession *soup_session;
SoupMessage *msg;
const gchar *entry_edit_url;
- int http_status;
gboolean retval = FALSE;
g_return_val_if_fail (service !=NULL, FALSE);
@@ -352,11 +380,13 @@
"Authorization",
(gchar *)g_strdup_printf ("GoogleLogin auth=%s",
auth->token));
- http_status = soup_session_send_message (soup_session, msg);
- if (http_status != 200) {
+ /* Handle redirects ourself */
+ send_and_handle_google_redirection (soup_session, msg);
+
+ if (msg->status_code != 200) {
g_set_error (error, SOUP_HTTP_ERROR,
- http_status, soup_status_get_phrase (http_status));
+ msg->status_code, msg->reason_phrase);
} else {
retval = TRUE;
}
@@ -406,7 +436,6 @@
SoupSession *soup_session;
SoupMessage *msg;
gchar *entry_xml;
- int http_status;
GDataEntry *updated_entry = NULL;
g_return_val_if_fail (service !=NULL, FALSE);
@@ -436,11 +465,12 @@
entry_xml,
strlen(entry_xml));
- http_status = soup_session_send_message (soup_session, msg);
+ /* Handle redirects ourself */
+ send_and_handle_google_redirection (soup_session, msg);
- if (http_status != 200) {
+ if (msg->status_code != 200) {
g_set_error (error, SOUP_HTTP_ERROR,
- http_status, soup_status_get_phrase (http_status));
+ msg->status_code, msg->reason_phrase);
g_object_unref (msg);
return updated_entry;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]