/cpw/tomkiewicz/http: 59b3364f690e: Sending cookies
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Thu Oct 18 08:10:30 EDT 2012
Changeset: 59b3364f690e04eb86c256aaf5dfec690e8fe797
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2012-10-18 14:10 +0200
Branch: default
URL: http://hg.pidgin.im/cpw/tomkiewicz/http/rev/59b3364f690e
Description:
Sending cookies
diffstat:
libpurple/http.c | 28 ++++++++++++++++++++++++++--
libpurple/protocols/gg/gg.c | 2 ++
2 files changed, 28 insertions(+), 2 deletions(-)
diffs (71 lines):
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -141,6 +141,7 @@ static void purple_http_response_free(Pu
static void purple_http_cookie_jar_parse(PurpleHttpCookieJar *cookie_jar,
GList *values);
+static gchar * purple_http_cookie_jar_gen(PurpleHttpCookieJar *cookie_jar);
gchar * purple_http_cookie_jar_dump(PurpleHttpCookieJar *cjar);
static PurpleHttpURL * purple_http_url_parse(const char *url);
@@ -488,7 +489,11 @@ static void _purple_http_gen_headers(Pur
kvp->key, (gchar*)kvp->value);
}
- /* TODO: sending cookies */
+ if (!purple_http_cookie_jar_is_empty(req->cookie_jar)) {
+ gchar * cookies = purple_http_cookie_jar_gen(req->cookie_jar);
+ g_string_append_printf(h, "Cookie: %s\r\n", cookies);
+ g_free(cookies);
+ }
g_string_append_printf(h, "\r\n");
@@ -1329,6 +1334,25 @@ static void purple_http_cookie_jar_parse
}
}
+static gchar * purple_http_cookie_jar_gen(PurpleHttpCookieJar *cookie_jar)
+{
+ GHashTableIter it;
+ gchar *key, *value;
+ GString *str;
+
+ g_return_val_if_fail(cookie_jar != NULL, NULL);
+
+ str = g_string_new("");
+
+ g_hash_table_iter_init(&it, cookie_jar->tab);
+ while (g_hash_table_iter_next(&it, (gpointer*)&key, (gpointer*)&value))
+ g_string_append_printf(str, "%s=%s; ", key, value);
+
+ if (str->len > 0)
+ g_string_truncate(str, str->len - 2);
+ return g_string_free(str, FALSE);
+}
+
void purple_http_cookie_jar_set(PurpleHttpCookieJar *cookie_jar,
const gchar *name, const gchar *value)
{
@@ -1626,7 +1650,7 @@ gboolean purple_http_response_is_success
if (code <= 0)
return FALSE;
- if (code == 200)
+ if (code / 100 == 2)
return TRUE;
return FALSE;
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -142,6 +142,8 @@ static void ggp_file_transfer_test_signe
//req = purple_http_request_new("https://drive.mpa.gg.pl/send_ticket");
req = purple_http_request_new("http://drive.mpa.gg.pl/send_ticket");
purple_http_request_set_method(req, "PUT");
+ purple_http_request_set_cookie_jar(req,
+ purple_http_conn_get_cookie_jar(http_conn));
purple_http_request_header_set(req, "X-gged-api-version", "6");
purple_http_request_header_set(req, "X-gged-security-token", security_token);
More information about the Commits
mailing list