From 17b27ed7e60a6e3cb7f5b8d48fa8f7c6d1256d86 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 31 Mar 2013 16:19:51 +0300 Subject: [PATCH] cal: remvove http_conn Remove it from Domino code. As that code looks at the password this was also the time to remove http_conn_auth from sipe_calendar. None of the modules now references http-conn.h anymore. --- src/core/sipe-cal.c | 45 +++++----------- src/core/sipe-cal.h | 10 ++-- src/core/sipe-domino.c | 144 +++++++++++++++++++++---------------------------- src/core/sipe-http.h | 3 +- 4 files changed, 79 insertions(+), 123 deletions(-) diff --git a/src/core/sipe-cal.c b/src/core/sipe-cal.c index 2584d9db..9b1e5c78 100644 --- a/src/core/sipe-cal.c +++ b/src/core/sipe-cal.c @@ -32,7 +32,6 @@ #include -#include "http-conn.h" #include "sipe-backend.h" #include "sipe-buddy.h" #include "sipe-core.h" @@ -180,12 +179,9 @@ sipe_cal_calendar_free(struct sipe_calendar *cal) { g_free(cal->email); g_free(cal->legacy_dn); - if (cal->auth) { - g_free(cal->auth->domain); - g_free(cal->auth->user); - g_free(cal->auth->password); - g_free(cal->auth); - } + g_free(cal->auth_domain); + g_free(cal->auth_user); + g_free(cal->password); g_free(cal->as_url); g_free(cal->oof_url); g_free(cal->oab_url); @@ -197,18 +193,9 @@ sipe_cal_calendar_free(struct sipe_calendar *cal) sipe_cal_events_free(cal->cal_events); - if (cal->http_conn) { - http_conn_free(cal->http_conn); - } - - if (cal->http_session) { - http_conn_session_free(cal->http_session); - } - if (cal->request) sipe_http_request_cancel(cal->request); - if (cal->session) - sipe_http_session_close(cal->session); + sipe_http_session_close(cal->session); g_free(cal); } @@ -242,19 +229,11 @@ sipe_cal_calendar_init(struct sipe_core_private *sipe_private, gchar **domain_user = g_strsplit_set(value, "/\\", 2); gboolean has_domain = domain_user[1] != NULL; - cal->auth = g_new0(HttpConnAuth, 1); - cal->auth->domain = has_domain ? g_strdup(domain_user[0]) : NULL; - cal->auth->user = g_strdup(domain_user[has_domain ? 1 : 0]); - cal->auth->password = g_strdup(sipe_backend_setting(SIPE_CORE_PUBLIC, - SIPE_SETTING_EMAIL_PASSWORD)); + cal->auth_domain = has_domain ? g_strdup(domain_user[0]) : NULL; + cal->auth_user = g_strdup(domain_user[has_domain ? 1 : 0]); + cal->password = g_strdup(sipe_backend_setting(SIPE_CORE_PUBLIC, + SIPE_SETTING_EMAIL_PASSWORD)); g_strfreev(domain_user); - - } else if (!SIPE_CORE_PRIVATE_FLAG_IS(SSO)) { - /* re-use SIP credentials when SSO is not selected */ - cal->auth = g_new0(HttpConnAuth, 1); - cal->auth->domain = g_strdup(sipe_private->authdomain); - cal->auth->user = g_strdup(sipe_private->authuser); - cal->auth->password = g_strdup(sipe_private->password); } return TRUE; } @@ -1159,11 +1138,11 @@ void sipe_cal_delayed_calendar_update(struct sipe_core_private *sipe_private) void sipe_cal_http_authentication(struct sipe_calendar *cal) { - if (cal->auth) { + if (cal->auth_user) { sipe_http_request_authentication(cal->request, - cal->auth->domain, - cal->auth->user, - cal->auth->password); + cal->auth_domain, + cal->auth_user, + cal->password); } } diff --git a/src/core/sipe-cal.h b/src/core/sipe-cal.h index 954d08f7..dd98da49 100644 --- a/src/core/sipe-cal.h +++ b/src/core/sipe-cal.h @@ -22,9 +22,6 @@ */ /* Forward declarations */ -struct http_conn_auth; -struct http_conn_struct; -struct http_session_struct; struct sipe_buddy; struct sipe_core_private; struct sipe_http_request; @@ -62,7 +59,6 @@ struct sipe_calendar { int state; char *email; char *legacy_dn; - struct http_conn_auth *auth; int auto_disco_method; int is_ews_disabled; int is_domino_disabled; @@ -80,11 +76,11 @@ struct sipe_calendar { time_t updated; gboolean published; - struct http_session_struct *http_session; - struct http_conn_struct *http_conn; - struct sipe_http_session *session; struct sipe_http_request *request; + gchar *auth_domain; + gchar *auth_user; /* NULL -> use default authentication */ + gchar *password; time_t fb_start; /* hex form */ diff --git a/src/core/sipe-domino.c b/src/core/sipe-domino.c index 3588adb7..c6b35fe3 100755 --- a/src/core/sipe-domino.c +++ b/src/core/sipe-domino.c @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2010-12 SIPE Project + * Copyright (C) 2010-2013 SIPE Project * Copyright (C) 2010 pier11 * * @@ -70,16 +70,16 @@ Similar functionality for iCalendar/CalDAV/Google would be great to implement to #include "sipe-win32dep.h" #endif -#include "http-conn.h" +#include "sipe-backend.h" #include "sipe-common.h" +#include "sipe-cal.h" #include "sipe-core.h" #include "sipe-core-private.h" +#include "sipe-domino.h" +#include "sipe-http.h" #include "sipe-nls.h" -#include "sipe-backend.h" #include "sipe-utils.h" -#include "sipe-cal.h" #include "sipe-xml.h" -#include "sipe-domino.h" /** * POST request for Login to Domino server @@ -169,20 +169,18 @@ sipe_domino_get_free_busy(time_t fb_start, return res; } -static void -sipe_domino_process_calendar_response(int return_code, - const char *body, - GSList *headers, - HttpConn *conn, - void *data) +static void sipe_domino_process_calendar_response(struct sipe_core_private *sipe_private, + guint status, + GSList *headers, + const gchar *body, + gpointer data) { struct sipe_calendar *cal = data; const gchar *content_type = sipe_utils_nameval_find(headers, "Content-Type"); SIPE_DEBUG_INFO_NOFORMAT("sipe_domino_process_calendar_response: cb started."); - http_conn_set_close(conn); - cal->http_conn = NULL; + cal->request = NULL; if (content_type && !g_str_has_prefix(content_type, "text/xml")) { cal->is_domino_disabled = TRUE; @@ -190,12 +188,11 @@ sipe_domino_process_calendar_response(int return_code, return; } - if (return_code == 200 && body) { - struct sipe_core_private *sipe_private = cal->sipe_private; + if ((status == SIPE_HTTP_STATUS_OK) && body) { const sipe_xml *node, *node2, *node3; sipe_xml *xml; - SIPE_DEBUG_INFO("sipe_domino_process_calendar_response: SUCCESS, ret=%d", return_code); + SIPE_DEBUG_INFO("sipe_domino_process_calendar_response: SUCCESS, ret=%d", status); xml = sipe_xml_parse(body, strlen(body)); sipe_cal_events_free(cal->cal_events); @@ -284,14 +281,12 @@ sipe_domino_process_calendar_response(int return_code, cal->is_updated = TRUE; sipe_cal_presence_publish(sipe_private, TRUE); - } else if (return_code < 0) { - SIPE_DEBUG_INFO("sipe_domino_process_calendar_response: rather FAILURE, ret=%d", return_code); + } else if (!headers) { + SIPE_DEBUG_INFO("sipe_domino_process_calendar_response: rather FAILURE, ret=%d", status); } - if (cal->http_session) { - http_conn_session_free(cal->http_session); - cal->http_session = NULL; - } + sipe_http_session_close(cal->session); + cal->session = NULL; } /* Domino doesn't like '-' and ':' in ISO timestamps */ @@ -309,8 +304,14 @@ sipe_domino_time_to_str(time_t timestamp) return res; } -static void -sipe_domino_do_calendar_request(struct sipe_calendar *cal) +static void sipe_domino_send_http_request(struct sipe_calendar *cal) +{ + sipe_cal_http_authentication(cal); + sipe_http_request_session(cal->request, cal->session); + sipe_http_request_ready(cal->request); +} + +static void sipe_domino_do_calendar_request(struct sipe_calendar *cal) { if (cal->domino_url) { char *url_req; @@ -342,59 +343,43 @@ sipe_domino_do_calendar_request(struct sipe_calendar *cal) url = g_strconcat(cal->domino_url, url_req, NULL); g_free(url_req); - if (!cal->http_conn || http_conn_is_closed(cal->http_conn)) { - cal->http_conn = http_conn_create( - (struct sipe_core_public *) cal->sipe_private, - cal->http_session, - HTTP_CONN_GET, - HTTP_CONN_SSL, - HTTP_CONN_NO_REDIRECT, - url, - NULL, /* body */ - NULL, /* content-type */ - NULL, - cal->auth, - sipe_domino_process_calendar_response, - cal); - } else { - http_conn_send(cal->http_conn, - HTTP_CONN_GET, - url, - NULL, /* body */ - NULL, /* content-type */ - sipe_domino_process_calendar_response, - cal); - } + cal->request = sipe_http_request_get(cal->sipe_private, + url, + NULL, + sipe_domino_process_calendar_response, + cal); g_free(url); + + sipe_domino_send_http_request(cal); } } -static void -sipe_domino_process_login_response(int return_code, - /* temporary? */ - SIPE_UNUSED_PARAMETER const char *body, - SIPE_UNUSED_PARAMETER GSList *headers, - HttpConn *conn, - void *data) +static void sipe_domino_process_login_response(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private, + guint status, + GSList *headers, + /* temporary? */ + SIPE_UNUSED_PARAMETER const gchar *body, + gpointer data) { struct sipe_calendar *cal = data; SIPE_DEBUG_INFO_NOFORMAT("sipe_domino_process_login_response: cb started."); - if (return_code >= 200 && return_code < 400) { - SIPE_DEBUG_INFO("sipe_domino_process_login_response: rather SUCCESS, ret=%d", return_code); + cal->request = NULL; + + if ((status >= SIPE_HTTP_STATUS_OK) && + (status < SIPE_HTTP_STATUS_CLIENT_ERROR)) { + SIPE_DEBUG_INFO("sipe_domino_process_login_response: rather SUCCESS, ret=%d", status); /* next query */ sipe_domino_do_calendar_request(cal); - } else if (return_code < 0 || return_code >= 400) { - SIPE_DEBUG_INFO("sipe_domino_process_login_response: rather FAILURE, ret=%d", return_code); + } else if (!headers || + (status >= SIPE_HTTP_STATUS_CLIENT_ERROR)) { + SIPE_DEBUG_INFO("sipe_domino_process_login_response: rather FAILURE, ret=%d", status); /* stop here */ /* cal->is_domino_disabled = TRUE; */ - - http_conn_set_close(conn); - cal->http_conn = NULL; } } @@ -450,34 +435,31 @@ sipe_domino_do_login_request(struct sipe_calendar *cal) const char *content_type = "application/x-www-form-urlencoded"; char *login_url = g_strconcat(cal->domino_url, "/?Login", NULL); char *user; - char *password; + gchar *password = cal->password ? cal->password : cal->sipe_private->password; SIPE_DEBUG_INFO_NOFORMAT("sipe_domino_do_login_request: going Login req."); - if (!cal->auth) return; + if (!password) return; /* @TODO replace purple_url_encode() with non-purple equiv. */ user = sipe_domino_uri_escape(cal->email); - password = sipe_domino_uri_escape(cal->auth->password); + password = sipe_domino_uri_escape(password); body = g_strdup_printf(SIPE_DOMINO_LOGIN_REQUEST, user, password); g_free(user); g_free(password); - cal->http_conn = http_conn_create((struct sipe_core_public *) cal->sipe_private, - cal->http_session, - HTTP_CONN_POST, - HTTP_CONN_SSL, - HTTP_CONN_NO_REDIRECT, - login_url, - body, - content_type, - NULL, - cal->auth, - sipe_domino_process_login_response, - cal); + cal->request = sipe_http_request_post(cal->sipe_private, + login_url, + NULL, + body, + content_type, + sipe_domino_process_login_response, + cal); g_free(login_url); g_free(body); + + sipe_domino_send_http_request(cal); } } @@ -629,17 +611,15 @@ sipe_domino_update_calendar(struct sipe_core_private *sipe_private) if (cal) { - /* create session */ - if (cal->http_session) { - http_conn_session_free(cal->http_session); - } - cal->http_session = http_conn_session_create(); - if (cal->is_domino_disabled) { SIPE_DEBUG_INFO_NOFORMAT("sipe_domino_update_calendar: disabled, exiting."); return; } + /* re-create session */ + sipe_http_session_close(cal->session); + cal->session = sipe_http_session_start(); + sipe_domino_do_login_request(cal); } diff --git a/src/core/sipe-http.h b/src/core/sipe-http.h index f84ab477..02b6e32e 100644 --- a/src/core/sipe-http.h +++ b/src/core/sipe-http.h @@ -50,7 +50,8 @@ typedef void (sipe_http_response_callback)(struct sipe_core_private *sipe_privat gpointer callback_data); /* HTTP response status codes */ -#define SIPE_HTTP_STATUS_OK 200 +#define SIPE_HTTP_STATUS_OK 200 +#define SIPE_HTTP_STATUS_CLIENT_ERROR 400 /* - 499 */ /** * Free HTTP data -- 2.11.4.GIT