From e2d030b40340c3cad8242a83a44fb4591b1a917f Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 31 Mar 2013 15:34:15 +0300 Subject: [PATCH] cal: remove http_conn from EWS Added APIs for redirect & authentication with dummy implementations. --- src/core/sipe-cal.c | 16 +++++ src/core/sipe-cal.h | 12 +++- src/core/sipe-ews.c | 162 +++++++++++++++++-------------------------- src/core/sipe-http-request.c | 33 ++++++++- src/core/sipe-http.h | 24 ++++++- 5 files changed, 143 insertions(+), 104 deletions(-) diff --git a/src/core/sipe-cal.c b/src/core/sipe-cal.c index 97a3a1cd..2584d9db 100644 --- a/src/core/sipe-cal.c +++ b/src/core/sipe-cal.c @@ -38,6 +38,7 @@ #include "sipe-core.h" #include "sipe-core-private.h" #include "sipe-cal.h" +#include "sipe-http.h" #include "sipe-nls.h" #include "sipe-ocs2005.h" #include "sipe-ocs2007.h" @@ -204,6 +205,11 @@ sipe_cal_calendar_free(struct sipe_calendar *cal) 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); + g_free(cal); } @@ -1151,6 +1157,16 @@ void sipe_cal_delayed_calendar_update(struct sipe_core_private *sipe_private) NULL); } +void sipe_cal_http_authentication(struct sipe_calendar *cal) +{ + if (cal->auth) { + sipe_http_request_authentication(cal->request, + cal->auth->domain, + cal->auth->user, + cal->auth->password); + } +} + /* Local Variables: mode: c diff --git a/src/core/sipe-cal.h b/src/core/sipe-cal.h index 92a5cd6f..954d08f7 100644 --- a/src/core/sipe-cal.h +++ b/src/core/sipe-cal.h @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2010-11 SIPE Project + * Copyright (C) 2010-2013 SIPE Project * Copyright (C) 2009 pier11 * * This program is free software; you can redistribute it and/or modify @@ -27,6 +27,8 @@ struct http_conn_struct; struct http_session_struct; struct sipe_buddy; struct sipe_core_private; +struct sipe_http_request; +struct sipe_http_session; struct _sipe_xml; /* Calendar statuses */ @@ -81,6 +83,9 @@ struct sipe_calendar { struct http_session_struct *http_session; struct http_conn_struct *http_conn; + struct sipe_http_session *session; + struct sipe_http_request *request; + time_t fb_start; /* hex form */ char *free_busy; @@ -192,3 +197,8 @@ void sipe_cal_presence_publish(struct sipe_core_private *sipe_private, * Schedule calendar update */ void sipe_cal_delayed_calendar_update(struct sipe_core_private *sipe_private); + +/** + * Set authentication for HTTP request + */ +void sipe_cal_http_authentication(struct sipe_calendar *cal); diff --git a/src/core/sipe-ews.c b/src/core/sipe-ews.c index a0d22646..7295f294 100644 --- a/src/core/sipe-ews.c +++ b/src/core/sipe-ews.c @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2010-11 SIPE Project + * Copyright (C) 2010-2013 SIPE Project * Copyright (C) 2010, 2009 pier11 * * @@ -49,13 +49,13 @@ be great to implement too. #include -#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-ews.h" +#include "sipe-http.h" #include "sipe-utils.h" #include "sipe-xml.h" @@ -175,23 +175,19 @@ sipe_ews_get_oof_note(struct sipe_calendar *cal) static void sipe_ews_run_state_machine(struct sipe_calendar *cal); -static void -sipe_ews_process_avail_response(int return_code, - const char *body, - SIPE_UNUSED_PARAMETER GSList *headers, - HttpConn *conn, - void *data) +static void sipe_ews_process_avail_response(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private, + guint status, + SIPE_UNUSED_PARAMETER GSList *headers, + const gchar *body, + gpointer data) { struct sipe_calendar *cal = data; SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_avail_response: cb started."); - if(!sipe_strequal(cal->as_url, cal->oof_url)) { /* whether reuse conn */ - http_conn_set_close(conn); - cal->http_conn = NULL; - } + cal->request = NULL; - if (return_code == 200 && body) { + if ((status == SIPE_HTTP_STATUS_OK) && body) { const sipe_xml *node; const sipe_xml *resp; /** ref: [MS-OXWAVLS] */ @@ -283,29 +279,24 @@ Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse sipe_ews_run_state_machine(cal); } else { - if (return_code < 0) { - cal->http_conn = NULL; - } cal->state = SIPE_EWS_STATE_AVAILABILITY_FAILURE; sipe_ews_run_state_machine(cal); } } -static void -sipe_ews_process_oof_response(int return_code, - const char *body, - SIPE_UNUSED_PARAMETER GSList *headers, - HttpConn *conn, - void *data) +static void sipe_ews_process_oof_response(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private, + guint status, + SIPE_UNUSED_PARAMETER GSList *headers, + const gchar *body, + gpointer data) { struct sipe_calendar *cal = data; SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_oof_response: cb started."); - http_conn_set_close(conn); - cal->http_conn = NULL; + cal->request = NULL; - if (return_code == 200 && body) { + if ((status == SIPE_HTTP_STATUS_OK) && body) { char *old_note; const sipe_xml *resp; const sipe_xml *xn_duration; @@ -370,29 +361,24 @@ sipe_ews_process_oof_response(int return_code, sipe_ews_run_state_machine(cal); } else { - if (return_code < 0) { - cal->http_conn = NULL; - } cal->state = SIPE_EWS_STATE_OOF_FAILURE; sipe_ews_run_state_machine(cal); } } -static void -sipe_ews_process_autodiscover(int return_code, - const char *body, - SIPE_UNUSED_PARAMETER GSList *headers, - HttpConn *conn, - void *data) +static void sipe_ews_process_autodiscover(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private, + guint status, + SIPE_UNUSED_PARAMETER GSList *headers, + const gchar *body, + gpointer data) { struct sipe_calendar *cal = data; SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_autodiscover: cb started."); - http_conn_set_close(conn); - cal->http_conn = NULL; + cal->request = NULL; - if (return_code == 200 && body) { + if ((status == SIPE_HTTP_STATUS_OK) && body) { const sipe_xml *node; /** ref: [MS-OXDSCLI] */ sipe_xml *xml = sipe_xml_parse(body, strlen(body)); @@ -433,9 +419,6 @@ sipe_ews_process_autodiscover(int return_code, sipe_ews_run_state_machine(cal); } else { - if (return_code < 0) { - cal->http_conn = NULL; - } switch (cal->auto_disco_method) { case 1: cal->state = SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE; break; @@ -446,33 +429,35 @@ sipe_ews_process_autodiscover(int return_code, } } -static void -sipe_ews_do_autodiscover(struct sipe_calendar *cal, - const char* autodiscover_url) +static void sipe_ews_send_http_request(struct sipe_calendar *cal) { - char *body; + sipe_cal_http_authentication(cal); + sipe_http_request_allow_redirect(cal->request); + sipe_http_request_ready(cal->request); +} - SIPE_DEBUG_INFO("sipe_ews_do_autodiscover: going autodiscover url=%s", autodiscover_url ? autodiscover_url : ""); +static void sipe_ews_do_autodiscover(struct sipe_calendar *cal, + const gchar *autodiscover_url) +{ + gchar *body; + + SIPE_DEBUG_INFO("sipe_ews_do_autodiscover: going autodiscover url=%s", + autodiscover_url ? autodiscover_url : ""); body = g_strdup_printf(SIPE_EWS_AUTODISCOVER_REQUEST, cal->email); - cal->http_conn = http_conn_create( - (struct sipe_core_public *) cal->sipe_private, - NULL, /* HttpSession */ - HTTP_CONN_POST, - HTTP_CONN_SSL, - HTTP_CONN_ALLOW_REDIRECT, - autodiscover_url, - body, - "text/xml", - NULL, - cal->auth, - sipe_ews_process_autodiscover, - cal); + cal->request = sipe_http_request_post(cal->sipe_private, + autodiscover_url, + NULL, + body, + "text/xml", + sipe_ews_process_autodiscover, + cal); g_free(body); + + sipe_ews_send_http_request(cal); } -static void -sipe_ews_do_avail_request(struct sipe_calendar *cal) +static void sipe_ews_do_avail_request(struct sipe_calendar *cal) { if (cal->as_url) { char *body; @@ -498,58 +483,39 @@ sipe_ews_do_avail_request(struct sipe_calendar *cal) end_str = sipe_utils_time_to_str(end); body = g_strdup_printf(SIPE_EWS_USER_AVAILABILITY_REQUEST, cal->email, start_str, end_str); - cal->http_conn = http_conn_create( - (struct sipe_core_public *) cal->sipe_private, - NULL, /* HttpSession */ - HTTP_CONN_POST, - HTTP_CONN_SSL, - HTTP_CONN_ALLOW_REDIRECT, - cal->as_url, - body, - "text/xml; charset=UTF-8", - NULL, - cal->auth, - sipe_ews_process_avail_response, - cal); + cal->request = sipe_http_request_post(cal->sipe_private, + cal->as_url, + NULL, + body, + "text/xml; charset=UTF-8", + sipe_ews_process_avail_response, + cal); g_free(body); g_free(start_str); g_free(end_str); + + sipe_ews_send_http_request(cal); } } -static void -sipe_ews_do_oof_request(struct sipe_calendar *cal) +static void sipe_ews_do_oof_request(struct sipe_calendar *cal) { if (cal->oof_url) { char *body; - const char *content_type = "text/xml; charset=UTF-8"; SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_oof_request: going OOF req."); body = g_strdup_printf(SIPE_EWS_USER_OOF_SETTINGS_REQUEST, cal->email); - if (!cal->http_conn || http_conn_is_closed(cal->http_conn)) { - cal->http_conn = http_conn_create((struct sipe_core_public *)cal->sipe_private, - NULL, /* HttpSession */ - HTTP_CONN_POST, - HTTP_CONN_SSL, - HTTP_CONN_ALLOW_REDIRECT, - cal->oof_url, - body, - content_type, - NULL, - cal->auth, - sipe_ews_process_oof_response, - cal); - } else { - http_conn_send(cal->http_conn, - HTTP_CONN_POST, - cal->oof_url, - body, - content_type, - sipe_ews_process_oof_response, - cal); - } + cal->request = sipe_http_request_post(cal->sipe_private, + cal->as_url, + NULL, + body, + "text/xml; charset=UTF-8", + sipe_ews_process_oof_response, + cal); g_free(body); + + sipe_ews_send_http_request(cal); } } diff --git a/src/core/sipe-http-request.c b/src/core/sipe-http-request.c index ee99b4ea..ccde59db 100644 --- a/src/core/sipe-http-request.c +++ b/src/core/sipe-http-request.c @@ -31,6 +31,8 @@ #include "sipmsg.h" #include "sipe-backend.h" +#include "sipe-core.h" +#include "sipe-core-private.h" #include "sipe-http.h" #define _SIPE_HTTP_PRIVATE_IF_REQUEST @@ -54,8 +56,12 @@ struct sipe_http_request { gchar *path; gchar *headers; - gchar *body; /* NULL for GET */ - gchar *content_type; /* NULL if body == NULL */ + gchar *body; /* NULL for GET */ + gchar *content_type; /* NULL if body == NULL */ + + const gchar *domain; /* not copied */ + const gchar *user; /* not copied */ + const gchar *password; /* not copied */ sipe_http_response_callback *cb; gpointer cb_data; @@ -63,7 +69,8 @@ struct sipe_http_request { guint32 flags; }; -#define SIPE_HTTP_REQUEST_FLAG_FIRST 0x00000001 +#define SIPE_HTTP_REQUEST_FLAG_FIRST 0x00000001 +#define SIPE_HTTP_REQUEST_FLAG_REDIRECT 0x00000002 struct sipe_http_connection_public *sipe_http_connection_new(struct sipe_core_private *sipe_private, const gchar *host, @@ -226,6 +233,11 @@ struct sipe_http_request *sipe_http_request_new(struct sipe_core_private *sipe_p req->content_type = g_strdup(content_type); } + /* default authentication */ + req->domain = sipe_private->authdomain; + req->user = sipe_private->authuser; + req->password = sipe_private->password; + req->cb = callback; req->cb_data = callback_data; @@ -281,6 +293,21 @@ void sipe_http_request_session(struct sipe_http_request *request, request->session = session; } +void sipe_http_request_allow_redirect(struct sipe_http_request *request) +{ + request->flags |= SIPE_HTTP_REQUEST_FLAG_REDIRECT; +} + +void sipe_http_request_authentication(struct sipe_http_request *request, + const gchar *domain, + const gchar *user, + const gchar *password) +{ + request->domain = domain; + request->user = user; + request->password = password; +} + /* Local Variables: mode: c diff --git a/src/core/sipe-http.h b/src/core/sipe-http.h index d0ea74ed..f84ab477 100644 --- a/src/core/sipe-http.h +++ b/src/core/sipe-http.h @@ -114,14 +114,14 @@ struct sipe_http_request *sipe_http_request_post(struct sipe_core_private *sipe_ /** * HTTP request is ready to be sent * - * @param pointer to opaque HTTP request data structure + * @param request pointer to opaque HTTP request data structure */ void sipe_http_request_ready(struct sipe_http_request *request); /** * Cancel pending HTTP request * - * @param pointer to opaque HTTP request data structure + * @param request pointer to opaque HTTP request data structure */ void sipe_http_request_cancel(struct sipe_http_request *request); @@ -133,3 +133,23 @@ void sipe_http_request_cancel(struct sipe_http_request *request); */ void sipe_http_request_session(struct sipe_http_request *request, struct sipe_http_session *session); + +/** + * Allow redirection of HTTP request + * + * @param request pointer to opaque HTTP request data structure + */ +void sipe_http_request_allow_redirect(struct sipe_http_request *request); + +/** + * Provide authentication information for HTTP request + * + * @param request pointer to opaque HTTP request data structure + * @param domain domain name (MUST stay valid for duration of request!) + * @param user user name (MUST stay valid for duration of request!) + * @param password Password (MUST stay valid for duration of request!) + */ +void sipe_http_request_authentication(struct sipe_http_request *request, + const gchar *domain, + const gchar *user, + const gchar *password); -- 2.11.4.GIT