From 8bdd6cc92ea8fb3570e2ad4523a877613d1cf048 Mon Sep 17 00:00:00 2001 From: Sivaiah Nallagatla Date: Mon, 10 Jan 2005 09:10:50 +0000 Subject: [PATCH] Add new status code E_GW_CONNECTION_STATUS_REDIRECT moved the loginrequest 2005-01-10 Sivaiah Nallagatla * e-gw-connection.h : Add new status code E_GW_CONNECTION_STATUS_REDIRECT * e-gw-connection.c (form_login_request) : moved the loginrequest forming code to here so it can be called whenever it is needed (e_gw_connection_new) : call form_login_request here. if the status code is E_GW_CONNECTION_STATUS_REDIRECT send the login request to new server (e_gw_connection_move_item) : new api to move/copy mails between folders --- servers/groupwise/ChangeLog | 14 +++++ servers/groupwise/e-gw-connection.c | 102 +++++++++++++++++++++++++++++++----- servers/groupwise/e-gw-connection.h | 2 + 3 files changed, 106 insertions(+), 12 deletions(-) diff --git a/servers/groupwise/ChangeLog b/servers/groupwise/ChangeLog index 19c1271..04d931d 100644 --- a/servers/groupwise/ChangeLog +++ b/servers/groupwise/ChangeLog @@ -1,3 +1,17 @@ +2005-01-10 Sivaiah Nallagatla + + * e-gw-connection.h : Add new status code + E_GW_CONNECTION_STATUS_REDIRECT + * e-gw-connection.c + (form_login_request) : moved the loginrequest + forming code to here so it can be called whenever + it is needed + (e_gw_connection_new) : call form_login_request here. + if the status code is E_GW_CONNECTION_STATUS_REDIRECT + send the login request to new server + (e_gw_connection_move_item) : new api to move/copy mails + between folders + 2005-01-09 Sivaiah Nallagatla * doc/gw-soap-methods.xsd diff --git a/servers/groupwise/e-gw-connection.c b/servers/groupwise/e-gw-connection.c index fad663f..3540d05 100644 --- a/servers/groupwise/e-gw-connection.c +++ b/servers/groupwise/e-gw-connection.c @@ -135,6 +135,7 @@ e_gw_connection_parse_response_status (SoupSoapResponse *response) case 53505 : return E_GW_CONNECTION_STATUS_UNKNOWN_USER; case 59914: return E_GW_CONNECTION_STATUS_ITEM_ALREADY_ACCEPTED; case 59910: return E_GW_CONNECTION_STATUS_INVALID_CONNECTION; + case 59923: return E_GW_CONNECTION_STATUS_REDIRECT; /* FIXME: map all error codes */ } @@ -347,6 +348,23 @@ e_gw_connection_get_type (void) return type; } +static SoupSoapMessage* +form_login_request (const char*uri, const char* username, const char* password) +{ + SoupSoapMessage *msg; + /* build the SOAP message */ + msg = e_gw_message_new_with_header (uri, NULL, "loginRequest"); + soup_soap_message_start_element (msg, "auth", "types", NULL); + soup_soap_message_add_attribute (msg, "type", "types:PlainText", "xsi", + "http://www.w3.org/2001/XMLSchema-instance"); + e_gw_message_write_string_parameter (msg, "username", "types", username); + if (password && *password) + e_gw_message_write_string_parameter (msg, "password", "types", password); + soup_soap_message_end_element (msg); + e_gw_message_write_footer (msg); + return msg; +} + EGwConnection * e_gw_connection_new (const char *uri, const char *username, const char *password) { @@ -356,6 +374,8 @@ e_gw_connection_new (const char *uri, const char *username, const char *password SoupSoapParameter *param; EGwConnectionStatus status; char *hash_key; + char *redirected_uri = NULL; + static GStaticMutex connecting = G_STATIC_MUTEX_INIT; g_static_mutex_lock (&connecting); @@ -380,30 +400,48 @@ e_gw_connection_new (const char *uri, const char *username, const char *password /* not found, so create a new connection */ cnc = g_object_new (E_TYPE_GW_CONNECTION, NULL); - /* build the SOAP message */ - msg = e_gw_message_new_with_header (uri, NULL, "loginRequest"); - soup_soap_message_start_element (msg, "auth", "types", NULL); - soup_soap_message_add_attribute (msg, "type", "types:PlainText", "xsi", - "http://www.w3.org/2001/XMLSchema-instance"); - e_gw_message_write_string_parameter (msg, "username", "types", username); - if (password && *password) - e_gw_message_write_string_parameter (msg, "password", "types", password); - soup_soap_message_end_element (msg); - e_gw_message_write_footer (msg); - + msg = form_login_request (uri, username, password); + /* send message to server */ response = e_gw_connection_send_message (cnc, msg); + if (!response) { g_object_unref (cnc); g_static_mutex_unlock (&connecting); + g_object_unref (msg); return NULL; } status = e_gw_connection_parse_response_status (response); + if (status == E_GW_CONNECTION_STATUS_REDIRECT) { + char *host, *port; + char **tokens; + SoupSoapParameter *subparam; + param = soup_soap_response_get_first_parameter_by_name (response, "redirectToHost"); + subparam = soup_soap_parameter_get_first_child_by_name (param, "ipAddress"); + host = soup_soap_parameter_get_string_value (subparam); + subparam = soup_soap_parameter_get_first_child_by_name (param, "port"); + port = soup_soap_parameter_get_string_value (subparam); + if (host && port) { + tokens = g_strsplit (uri, "://", 2); + redirected_uri = g_strconcat (tokens[0], "://", host, ":", port, "/soap"); + g_object_unref (msg); + g_object_unref (response); + msg = form_login_request (redirected_uri, username, password); + uri = redirected_uri; + response = e_gw_connection_send_message (cnc, msg); + status = e_gw_connection_parse_response_status (response); + g_strfreev (tokens); + g_free (host); + g_free (port); + } + + } param = soup_soap_response_get_first_parameter_by_name (response, "session"); if (!param) { g_object_unref (response); + g_object_unref (msg); g_object_unref (cnc); g_static_mutex_unlock (&connecting); return NULL; @@ -450,8 +488,9 @@ e_gw_connection_new (const char *uri, const char *username, const char *password /* free memory */ g_object_unref (response); + g_object_unref (msg); g_static_mutex_unlock (&connecting); - + g_free (redirected_uri); return cnc; } @@ -2264,3 +2303,42 @@ e_gw_connection_share_folder(EGwConnection *cnc, gchar *id, GList *new_list, con return status; } + +EGwConnectionStatus +e_gw_connection_move_item (EGwConnection *cnc, const char *id, const char *dest_container_id, const char *from_container_id) + +{ + SoupSoapMessage *msg; + SoupSoapResponse *response; + EGwConnectionStatus status; + + g_return_val_if_fail (E_IS_GW_CONNECTION (cnc), E_GW_CONNECTION_STATUS_INVALID_CONNECTION); + g_return_val_if_fail (id != NULL, E_GW_CONNECTION_STATUS_INVALID_OBJECT); + g_return_val_if_fail (dest_container_id != NULL, E_GW_CONNECTION_STATUS_INVALID_OBJECT); + + + /* build the SOAP message */ + msg = e_gw_message_new_with_header (cnc->priv->uri, cnc->priv->session_id, "moveItemsRequest"); + e_gw_message_write_string_parameter (msg, "id", NULL, id); + e_gw_message_write_string_parameter (msg, "container", NULL,dest_container_id); + if (from_container_id) + e_gw_message_write_string_parameter (msg, "from", NULL,from_container_id); + e_gw_message_write_footer (msg); + + /* send message to server */ + response = e_gw_connection_send_message (cnc, msg); + if (!response) { + g_object_unref (msg); + return E_GW_CONNECTION_STATUS_INVALID_RESPONSE; + } + + status = e_gw_connection_parse_response_status (response); + if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION) + reauthenticate (cnc); + /* free memory */ + g_object_unref (response); + g_object_unref (msg); + return status; + + +} diff --git a/servers/groupwise/e-gw-connection.h b/servers/groupwise/e-gw-connection.h index a32ddc2..9eb4114 100644 --- a/servers/groupwise/e-gw-connection.h +++ b/servers/groupwise/e-gw-connection.h @@ -64,6 +64,7 @@ typedef enum { E_GW_CONNECTION_STATUS_UNKNOWN_USER, E_GW_CONNECTION_STATUS_BAD_PARAMETER, E_GW_CONNECTION_STATUS_ITEM_ALREADY_ACCEPTED, + E_GW_CONNECTION_STATUS_REDIRECT, E_GW_CONNECTION_STATUS_OTHER, E_GW_CONNECTION_STATUS_UNKNOWN } EGwConnectionStatus; @@ -121,6 +122,7 @@ EGwConnectionStatus e_gw_connection_create_folder(EGwConnection *cnc, const char EGwConnectionStatus e_gw_connection_get_attachment (EGwConnection *cnc, const char *id, int offset, int length, const char **attachment, int *attach_lenght) ; EGwConnectionStatus e_gw_connection_add_item (EGwConnection *cnc, const char *container, const char *id) ; EGwConnectionStatus e_gw_connection_add_items (EGwConnection *cnc, const char *container, GList *item_ids) ; +EGwConnectionStatus e_gw_connection_move_item (EGwConnection *cnc, const char *id, const char *dest_container_id, const char *from_container_id); EGwConnectionStatus e_gw_connection_rename_folder (EGwConnection *cnc, const char *id ,const char *new_name) ; EGwConnectionStatus e_gw_connection_get_settings (EGwConnection *cnc, EGwSendOptions **opts); EGwConnectionStatus e_gw_connection_add_items (EGwConnection *cnc, const char *container, GList *item_ids) ; -- 2.7.4