changeset 23689:7cb8e04bca7a

merge of '14f8b4609456592014383ef4957124a07f57ac3a' and '79758530b2d043ca03126b97fdcf3f5b004fb3f1'
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 09 Aug 2008 04:25:58 +0000
parents 357168efca68 (diff) 38c76b5b846b (current diff)
children 107166bb2a64
files
diffstat 13 files changed, 113 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Sat Aug 09 04:24:54 2008 +0000
+++ b/COPYRIGHT	Sat Aug 09 04:25:58 2008 +0000
@@ -157,6 +157,7 @@
 Konrad Gräfe
 Miah Gregory
 David Grohmann
+Christian Grothoff
 Vladislav Guberinić
 Gideon N. Guillen
 Christian Hammond
@@ -192,6 +193,7 @@
 Greg Hudson
 Magnus Hult
 Karsten Huneycutt
+Andrew Hunt
 Kevin Hunter
 Rian Hunter
 Thomas Huriaux
--- a/ChangeLog.API	Sat Aug 09 04:24:54 2008 +0000
+++ b/ChangeLog.API	Sat Aug 09 04:25:58 2008 +0000
@@ -21,6 +21,8 @@
 		* purple_cmds_get_handle, purple_cmds_init, purple_cmds_uninit
 		* cmd-added and cmd-removed signals
 		* purple_get_host_name
+		* purple_util_fetch_url_len (temporary function overload to add max_len param)
+		* purple_util_fetch_url_request_len
 
 		Deprecated:
 		* purple_blist_update_buddy_icon
@@ -28,6 +30,8 @@
 		* purple_buddy_icons_find_custom_icon
 		* purple_buddy_icons_set_custom_icon
 		* pidgin_set_custom_buddy_icon
+		* purple_util_fetch_url_len
+		* purple_util_fetch_url_request_len
 
 		Changed:
 		* xmlnode_copy now copies the prefix and namespace map for nodes.
--- a/libpurple/certificate.c	Sat Aug 09 04:24:54 2008 +0000
+++ b/libpurple/certificate.c	Sat Aug 09 04:25:58 2008 +0000
@@ -746,7 +746,7 @@
 						   "ca-certs", NULL));
 #else
 # ifdef SSL_CERTIFICATES_DIR
-		x509_ca_paths = g_list_append(NULL, SSL_CERTIFICATES_DIR);
+		x509_ca_paths = g_list_append(NULL, g_strdup(SSL_CERTIFICATES_DIR));
 # else
 		x509_ca_paths = g_list_append(NULL, g_build_filename(DATADIR,
 						   "purple", "ca-certs", NULL));
--- a/libpurple/protocols/jabber/buddy.c	Sat Aug 09 04:24:54 2008 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Sat Aug 09 04:25:58 2008 +0000
@@ -37,6 +37,8 @@
 #include "pep.h"
 #include "adhoccommands.h"
 
+#define MAX_HTTP_BUDDYICON_BYTES (200 * 1024)
+
 typedef struct {
 	long idle_seconds;
 } JabberBuddyInfoResource;
@@ -1535,18 +1537,27 @@
 			}
 		}
 		if(goodinfo) {
-			const char *url = xmlnode_get_attrib(goodinfo,"url");
+			const char *url = xmlnode_get_attrib(goodinfo, "url");
 			const char *id = xmlnode_get_attrib(goodinfo,"id");
 			
 			/* the avatar might either be stored in a pep node, or on a HTTP/HTTPS URL */
 			if(!url)
 				jabber_pep_request_item(js, from, AVATARNAMESPACEDATA, id, do_buddy_avatar_update_data);
 			else {
+				PurpleUtilFetchUrlData *url_data;
 				JabberBuddyAvatarUpdateURLInfo *info = g_new0(JabberBuddyAvatarUpdateURLInfo, 1);
 				info->js = js;
-				info->from = g_strdup(from);
-				info->id = g_strdup(id);
-				purple_util_fetch_url(url, TRUE, NULL, TRUE, do_buddy_avatar_update_fromurl, info);
+
+				url_data = purple_util_fetch_url_len(url, TRUE, NULL, TRUE,
+										  MAX_HTTP_BUDDYICON_BYTES,
+										  do_buddy_avatar_update_fromurl, info);
+				if (url_data) {
+					info->from = g_strdup(from);
+					info->id = g_strdup(id);
+					js->url_datas = g_slist_prepend(js->url_datas, url_data);
+				} else
+					g_free(info);
+
 			}
 		}
 	}
--- a/libpurple/protocols/jabber/jabber.c	Sat Aug 09 04:24:54 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Aug 09 04:25:58 2008 +0000
@@ -1322,6 +1322,11 @@
 		js->bs_proxies = g_list_delete_link(js->bs_proxies, js->bs_proxies);
 	}
 
+	while(js->url_datas) {
+		purple_util_fetch_url_cancel(js->url_datas->data);
+		js->url_datas = g_slist_delete_link(js->url_datas, js->url_datas);
+	}
+
 	g_free(js->stream_id);
 	if(js->user)
 		jabber_id_free(js->user);
--- a/libpurple/protocols/jabber/jabber.h	Sat Aug 09 04:24:54 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Sat Aug 09 04:25:58 2008 +0000
@@ -236,6 +236,11 @@
 	PurpleSrvResponse *srv_rec;
 	guint srv_rec_idx;
 	guint max_srv_rec_idx;
+	/**
+	 * This linked list contains PurpleUtilFetchUrlData structs
+	 * for when we lookup buddy icons from a url
+	 */
+	GSList *url_datas;
 };
 
 typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *shortname, const gchar *namespace);
--- a/libpurple/protocols/msn/msn.c	Sat Aug 09 04:24:54 2008 +0000
+++ b/libpurple/protocols/msn/msn.c	Sat Aug 09 04:25:58 2008 +0000
@@ -48,6 +48,7 @@
 #include "slplink.h"
 
 #if PHOTO_SUPPORT
+#define MAX_HTTP_BUDDYICON_BYTES (200 * 1024)
 #include "imgstore.h"
 #endif
 
@@ -1886,6 +1887,7 @@
 	purple_debug_info("msn", "In msn_got_info,url_text:{%s}\n",url_text);
 
 	/* Make sure the connection is still valid */
+	/* TODO: Instead of this, we should be canceling this when we disconnect */
 	if (g_list_find(purple_connections_get_all(), info_data->gc) == NULL)
 	{
 		purple_debug_warning("msn", "invalid connection. ignoring buddy info.\n");
@@ -2275,7 +2277,7 @@
 	/* Try to put the photo in there too, if there's one */
 	if (photo_url_text)
 	{
-		purple_util_fetch_url(photo_url_text, FALSE, NULL, FALSE, msn_got_photo,
+		purple_util_fetch_url_len(photo_url_text, FALSE, NULL, FALSE, MAX_HTTP_BUDDYICON_BYTES, msn_got_photo,
 					   info2_data);
 	}
 	else
@@ -2301,6 +2303,7 @@
 	char *photo_url_text = info2_data->photo_url_text;
 
 	/* Make sure the connection is still valid if we got here by fetching a photo url */
+	/* TODO: Instead of this, we should be canceling this when we disconnect */
 	if (url_text && (error_message != NULL ||
 					 g_list_find(purple_connections_get_all(), info_data->gc) == NULL))
 	{
--- a/libpurple/upnp.c	Sat Aug 09 04:24:54 2008 +0000
+++ b/libpurple/upnp.c	Sat Aug 09 04:25:58 2008 +0000
@@ -41,6 +41,8 @@
 #define HTTP_OK "200 OK"
 #define DEFAULT_HTTP_PORT 80
 #define DISCOVERY_TIMEOUT 1000
+/* limit UPnP-triggered http downloads to 128k */
+#define MAX_UPNP_DOWNLOAD (128 * 1024)
 
 /***************************************************************
 ** Discovery/Description Defines                               *
@@ -443,8 +445,8 @@
 	purple_timeout_remove(dd->tima);
 	dd->tima = 0;
 
-	purple_util_fetch_url_request(descriptionURL, TRUE, NULL, TRUE, httpRequest,
-			TRUE, upnp_parse_description_cb, dd);
+	purple_util_fetch_url_request_len(descriptionURL, TRUE, NULL, TRUE, httpRequest,
+			TRUE, MAX_UPNP_DOWNLOAD, upnp_parse_description_cb, dd);
 
 	g_free(httpRequest);
 
@@ -708,8 +710,8 @@
 	g_free(pathOfControl);
 	g_free(soapMessage);
 
-	gfud = purple_util_fetch_url_request(control_info.control_url, FALSE, NULL, TRUE,
-				totalSendMessage, TRUE, cb, cb_data);
+	gfud = purple_util_fetch_url_request_len(control_info.control_url, FALSE, NULL, TRUE,
+				totalSendMessage,  TRUE, MAX_UPNP_DOWNLOAD, cb, cb_data);
 
 	g_free(totalSendMessage);
 	g_free(addressOfControl);
@@ -1047,7 +1049,7 @@
 {
 	static int handle;
 	
-	return &handle;	
+	return &handle;
 }
 
 void
@@ -1055,5 +1057,5 @@
 {
 	purple_signal_connect(purple_network_get_handle(), "network-configuration-changed",
 						  purple_upnp_get_handle(), PURPLE_CALLBACK(purple_upnp_network_config_changed_cb),
-						  GINT_TO_POINTER(0));		
+						  NULL);
 }
--- a/libpurple/util.c	Sat Aug 09 04:24:54 2008 +0000
+++ b/libpurple/util.c	Sat Aug 09 04:25:58 2008 +0000
@@ -65,6 +65,7 @@
 	char *webdata;
 	unsigned long len;
 	unsigned long data_len;
+	gssize max_len;
 };
 
 static char *custom_user_dir = NULL;
@@ -718,6 +719,12 @@
 const char *
 purple_date_format_long(const struct tm *tm)
 {
+	/*
+	 * This string determines how some dates are displayed.  The default
+	 * string "%x %X" shows the date then the time.  Translators can
+	 * change this to "%X %x" if they want the time to be shown first,
+	 * followed by the date.
+	 */
 	return purple_utf8_strftime(_("%x %X"), tm);
 }
 
@@ -3748,6 +3755,15 @@
 	gboolean got_eof = FALSE;
 
 	while((len = read(source, buf, sizeof(buf))) > 0) {
+
+		if(gfud->max_len != -1 && (gfud->len + len) > gfud->max_len) {
+			/* TODO: Fix this when not string frozen */
+			/*purple_util_fetch_url_error(gfud, _("Error reading from %s: response too long (%d bytes limit)"),*/
+			purple_util_fetch_url_error(gfud, "Error reading from %s: response too long (%d bytes limit)",
+						    gfud->website.address, gfud->max_len);
+			return;
+		}
+
 		/* If we've filled up our buffer, make it bigger */
 		if((gfud->len + len) >= gfud->data_len) {
 			while((gfud->len + len) >= gfud->data_len)
@@ -3909,8 +3925,7 @@
 
 	gfud->fd = source;
 
-	if (!gfud->request)
-	{
+	if (!gfud->request) {
 		if (gfud->user_agent) {
 			/* Host header is not forbidden in HTTP/1.0 requests, and HTTP/1.1
 			 * clients must know how to handle the "chunked" transfer encoding.
@@ -3954,6 +3969,18 @@
 		const char *request, gboolean include_headers,
 		PurpleUtilFetchUrlCallback callback, void *user_data)
 {
+	return purple_util_fetch_url_request_len(url, full,
+					     user_agent, http11,
+					     request, include_headers, -1,
+					     callback, user_data);
+}
+
+PurpleUtilFetchUrlData *
+purple_util_fetch_url_request_len(const char *url, gboolean full,
+		const char *user_agent, gboolean http11,
+		const char *request, gboolean include_headers, gssize max_len,
+		PurpleUtilFetchUrlCallback callback, void *user_data)
+{
 	PurpleUtilFetchUrlData *gfud;
 
 	g_return_val_if_fail(url      != NULL, NULL);
@@ -3974,6 +4001,7 @@
 	gfud->request = g_strdup(request);
 	gfud->include_headers = include_headers;
 	gfud->fd = -1;
+	gfud->max_len = max_len;
 
 	purple_url_parse(url, &gfud->website.address, &gfud->website.port,
 				   &gfud->website.page, &gfud->website.user, &gfud->website.passwd);
--- a/libpurple/util.h	Sat Aug 09 04:24:54 2008 +0000
+++ b/libpurple/util.h	Sat Aug 09 04:25:58 2008 +0000
@@ -1041,6 +1041,23 @@
  *                   partial URL.
  * @param user_agent The user agent field to use, or NULL.
  * @param http11     TRUE if HTTP/1.1 should be used to download the file.
+ * @param max_len    The maximum number of bytes to retrieve (-1 for unlimited)
+ * @param cb         The callback function.
+ * @param data       The user data to pass to the callback function.
+ * @deprecated       In 3.0.0, we'll rename this to "purple_util_fetch_url" and get rid of the old one
+ */
+#define purple_util_fetch_url_len(url, full, user_agent, http11, max_len, cb, data) \
+	purple_util_fetch_url_request_len(url, full, user_agent, http11, NULL, \
+		FALSE, max_len, cb, data);
+
+/**
+ * Fetches the data from a URL, and passes it to a callback function.
+ *
+ * @param url        The URL.
+ * @param full       TRUE if this is the full URL, or FALSE if it's a
+ *                   partial URL.
+ * @param user_agent The user agent field to use, or NULL.
+ * @param http11     TRUE if HTTP/1.1 should be used to download the file.
  * @param request    A HTTP request to send to the server instead of the
  *                   standard GET
  * @param include_headers
@@ -1054,6 +1071,28 @@
 		PurpleUtilFetchUrlCallback callback, gpointer data);
 
 /**
+ * Fetches the data from a URL, and passes it to a callback function.
+ *
+ * @param url        The URL.
+ * @param full       TRUE if this is the full URL, or FALSE if it's a
+ *                   partial URL.
+ * @param user_agent The user agent field to use, or NULL.
+ * @param http11     TRUE if HTTP/1.1 should be used to download the file.
+ * @param request    A HTTP request to send to the server instead of the
+ *                   standard GET
+ * @param include_headers
+ *                   If TRUE, include the HTTP headers in the response.
+ * @param max_len    The maximum number of bytes to retrieve (-1 for unlimited)
+ * @param callback   The callback function.
+ * @param data       The user data to pass to the callback function.
+ * @deprecated       In 3.0.0, we'll rename this to "purple_util_fetch_url_request" and get rid of the old one
+ */
+PurpleUtilFetchUrlData *purple_util_fetch_url_request_len(const gchar *url,
+		gboolean full, const gchar *user_agent, gboolean http11,
+		const gchar *request, gboolean include_headers, gssize max_len,
+		PurpleUtilFetchUrlCallback callback, gpointer data);
+
+/**
  * Cancel a pending URL request started with either
  * purple_util_fetch_url_request() or purple_util_fetch_url().
  *
Binary file pidgin/pixmaps/protocols/16/facebook.png has changed
Binary file pidgin/pixmaps/protocols/22/facebook.png has changed
Binary file pidgin/pixmaps/protocols/48/facebook.png has changed