/pidgin/main: ef0428673cc3: Handle session cookies (expiry of 0)...

Eion Robb eionrobb at gmail.com
Sat Jan 23 14:06:34 EST 2016


Changeset: ef0428673cc32afdb40353ded24509c0e527be5f
Author:	 Eion Robb <eionrobb at gmail.com>
Date:	 2016-01-21 20:54 +1300
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/ef0428673cc3

Description:

Handle session cookies (expiry of 0) and correctly escape/unescape cookies when getting/setting them manually

diffstat:

 libpurple/http.c |  22 +++++++++++++++++-----
 libpurple/http.h |   4 +++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diffs (85 lines):

diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -24,8 +24,10 @@
 #include "internal.h"
 #include "glibcompat.h"
 
+
 #include "debug.h"
 #include "ntlm.h"
+#include "proxy.h"
 #include "purple-socket.h"
 
 #include <zlib.h>
@@ -1990,7 +1992,7 @@ static gchar * purple_http_cookie_jar_ge
 	while (g_hash_table_iter_next(&it, (gpointer*)&key,
 		(gpointer*)&cookie))
 	{
-		if (cookie->expires != -1 && cookie->expires <= now)
+		if (cookie->expires != -1 && cookie->expires != 0 && cookie->expires <= now)
 			continue;
 		g_string_append_printf(str, "%s=%s; ", key, cookie->value);
 	}
@@ -2003,7 +2005,17 @@ static gchar * purple_http_cookie_jar_ge
 void purple_http_cookie_jar_set(PurpleHttpCookieJar *cookie_jar,
 	const gchar *name, const gchar *value)
 {
-	purple_http_cookie_jar_set_ext(cookie_jar, name, value, -1);
+	gchar *escaped_name = g_strdup(purple_url_encode(name));
+	gchar *escaped_value = NULL;
+	
+	if (escaped_value) {
+		escaped_value = g_strdup(purple_url_encode(value));
+	}
+	
+	purple_http_cookie_jar_set_ext(cookie_jar, escaped_name, escaped_value, -1);
+	
+	g_free(escaped_name);
+	g_free(escaped_value);
 }
 
 static void purple_http_cookie_jar_set_ext(PurpleHttpCookieJar *cookie_jar,
@@ -2012,7 +2024,7 @@ static void purple_http_cookie_jar_set_e
 	g_return_if_fail(cookie_jar != NULL);
 	g_return_if_fail(name != NULL);
 
-	if (expires != -1 && time(NULL) >= expires)
+	if (expires != -1 && expires != 0 && time(NULL) >= expires)
 		value = NULL;
 
 	if (value != NULL) {
@@ -2023,7 +2035,7 @@ static void purple_http_cookie_jar_set_e
 		g_hash_table_remove(cookie_jar->tab, name);
 }
 
-const gchar * purple_http_cookie_jar_get(PurpleHttpCookieJar *cookie_jar,
+gchar * purple_http_cookie_jar_get(PurpleHttpCookieJar *cookie_jar,
 	const gchar *name)
 {
 	PurpleHttpCookie *cookie;
@@ -2035,7 +2047,7 @@ const gchar * purple_http_cookie_jar_get
 	if (!cookie)
 		return NULL;
 
-	return cookie->value;
+	return g_strdup(purple_url_decode(cookie->value));
 }
 
 gchar * purple_http_cookie_jar_dump(PurpleHttpCookieJar *cjar)
diff --git a/libpurple/http.h b/libpurple/http.h
--- a/libpurple/http.h
+++ b/libpurple/http.h
@@ -463,9 +463,11 @@ void purple_http_cookie_jar_set(PurpleHt
  *
  * Gets the cookie.
  *
+ * The result must be g_free'd.
+ *
  * Returns:           Cookie contents, or NULL, if cookie doesn't exists.
  */
-const gchar * purple_http_cookie_jar_get(PurpleHttpCookieJar *cookie_jar,
+gchar * purple_http_cookie_jar_get(PurpleHttpCookieJar *cookie_jar,
 	const gchar *name);
 
 /**



More information about the Commits mailing list