/soc/2013/ankitkv/gobjectification: 70adf2e77c4f: Merged default...
Ankit Vani
a at nevitus.org
Sun Jun 23 10:59:53 EDT 2013
Changeset: 70adf2e77c4f90782be9884a6bad7bad5e2dbdb0
Author: Ankit Vani <a at nevitus.org>
Date: 2013-06-23 20:29 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/70adf2e77c4f
Description:
Merged default branch
diffstat:
finch/plugins/gnttinyurl.c | 51 +++++++++++++++++++++++++++-------------
libpurple/http.c | 3 +-
pidgin/gtkprefs.c | 55 +++++++++++++++++++++++++++-----------------
pidgin/gtksmiley.c | 56 +++++++++++++++++----------------------------
pidgin/gtkstatusbox.c | 51 -----------------------------------------
5 files changed, 91 insertions(+), 125 deletions(-)
diffs (truncated from 443 to 300 lines):
diff --git a/finch/plugins/gnttinyurl.c b/finch/plugins/gnttinyurl.c
--- a/finch/plugins/gnttinyurl.c
+++ b/finch/plugins/gnttinyurl.c
@@ -21,7 +21,6 @@
#include "internal.h"
#include <glib.h>
-#include "obsolete.h"
#define PLUGIN_STATIC_NAME TinyURL
#define PREFS_BASE "/plugins/gnt/tinyurl"
@@ -30,6 +29,7 @@
#include <conversation.h>
+#include <http.h>
#include <signals.h>
#include <glib.h>
@@ -203,17 +203,26 @@ static GList *extract_urls(const char *t
return ret;
}
-static void url_fetched(PurpleUtilFetchUrlData *url_data, gpointer cb_data,
- const gchar *url_text, gsize len, const gchar *error_message)
+
+
+static void url_fetched(PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer _data)
{
- CbInfo *data = (CbInfo *)cb_data;
+ CbInfo *data = (CbInfo *)_data;
PurpleConversation *conv = data->conv;
GList *convs = purple_conversations_get();
+ const gchar *url;
+
+ if (purple_http_response_is_successfull(response))
+ url = purple_http_response_get_data(response, NULL);
+ else
+ url = _("Error while querying TinyURL");
+
/* ensure the conversation still exists */
for (; convs; convs = convs->next) {
if ((PurpleConversation *)(convs->data) == conv) {
FinchConv *fconv = FINCH_CONV(conv);
- gchar *str = g_strdup_printf("[%d] %s", data->num, url_text);
+ gchar *str = g_strdup_printf("[%d] %s", data->num, url);
GntTextView *tv = GNT_TEXT_VIEW(fconv->tv);
gnt_text_view_tag_change(tv, data->tag, str, FALSE);
g_free(str);
@@ -320,7 +329,7 @@ process_urls(PurpleConversation *conv, G
url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(tmp));
}
g_free(tmp);
- purple_util_fetch_url(url, TRUE, "finch", FALSE, -1, url_fetched, cbdata);
+ purple_http_get(NULL, url, url_fetched, cbdata);
i = gnt_text_view_get_lines_below(tv);
str = g_strdup_printf(_("\nFetching TinyURL..."));
gnt_text_view_append_text_with_tag((tv), str, GNT_TEXT_FLAG_DIM, cbdata->tag);
@@ -342,20 +351,27 @@ free_conv_urls(PurpleConversation *conv)
g_list_free(urls);
}
-static void tinyurl_notify_fetch_cb(PurpleUtilFetchUrlData *urldata, gpointer cbdata,
- const gchar *urltext, gsize len, const gchar *error)
+static void
+tinyurl_notify_fetch_cb(PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer _win)
{
- GntWidget *win = cbdata;
+ GntWidget *win = _win;
GntWidget *label = g_object_get_data(G_OBJECT(win), "info-widget");
char *message;
+ const gchar *url;
- message = g_strdup_printf(_("TinyURL for above: %s"), urltext);
+ if (!purple_http_response_is_successfull(response))
+ return;
+
+ url = purple_http_response_get_data(response, NULL);
+
+ message = g_strdup_printf(_("TinyURL for above: %s"), url);
gnt_label_set_text(GNT_LABEL(label), message);
g_free(message);
g_signal_handlers_disconnect_matched(G_OBJECT(win), G_SIGNAL_MATCH_FUNC,
0, 0, NULL,
- G_CALLBACK(purple_util_fetch_url_cancel), NULL);
+ G_CALLBACK(purple_http_conn_cancel), NULL);
}
static void *
@@ -363,7 +379,7 @@ tinyurl_notify_uri(const char *uri)
{
char *fullurl = NULL;
GntWidget *win;
- PurpleUtilFetchUrlData *urlcb;
+ PurpleHttpConnection *hc;
/* XXX: The following expects that finch_notify_message gets called. This
* may not always happen, e.g. when another plugin sets its own
@@ -381,13 +397,14 @@ tinyurl_notify_uri(const char *uri)
purple_url_encode(uri));
}
- /* Store the return value of _fetch_url and destroy that when win is
- destroyed, so that the callback for _fetch_url does not try to molest a
- non-existent window */
- urlcb = purple_util_fetch_url(fullurl, TRUE, "finch", FALSE, -1, tinyurl_notify_fetch_cb, win);
+ /* Store the return value of purple_http_get and destroy that when win
+ * is destroyed, so that the callback for purple_http_get does not try
+ * to molest a non-existent window
+ */
+ hc = purple_http_get(NULL, fullurl, tinyurl_notify_fetch_cb, win);
g_free(fullurl);
g_signal_connect_swapped(G_OBJECT(win), "destroy",
- G_CALLBACK(purple_util_fetch_url_cancel), urlcb);
+ G_CALLBACK(purple_http_conn_cancel), hc);
return win;
}
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -38,6 +38,7 @@
#define PURPLE_HTTP_REQUEST_DEFAULT_MAX_REDIRECTS 20
#define PURPLE_HTTP_REQUEST_DEFAULT_TIMEOUT 30
+#define PURPLE_HTTP_REQUEST_DEFAULT_MAX_LENGTH 1048576
typedef struct _PurpleHttpSocket PurpleHttpSocket;
@@ -1714,7 +1715,7 @@ PurpleHttpRequest * purple_http_request_
request->timeout = PURPLE_HTTP_REQUEST_DEFAULT_TIMEOUT;
request->max_redirects = PURPLE_HTTP_REQUEST_DEFAULT_MAX_REDIRECTS;
request->http11 = TRUE;
- request->max_length = -1;
+ request->max_length = PURPLE_HTTP_REQUEST_DEFAULT_MAX_LENGTH;
return request;
}
diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c
--- a/pidgin/gtkprefs.c
+++ b/pidgin/gtkprefs.c
@@ -26,9 +26,9 @@
*/
#include "internal.h"
#include "pidgin.h"
-#include "obsolete.h"
#include "debug.h"
+#include "http.h"
#include "nat-pmp.h"
#include "notify.h"
#include "prefs.h"
@@ -87,6 +87,9 @@
#define PREFS_OPTIMAL_ICON_SIZE 32
+/* 25MB */
+#define PREFS_MAX_DOWNLOADED_THEME_SIZE 26214400
+
struct theme_info {
gchar *type;
gchar *extension;
@@ -110,6 +113,7 @@ static GtkWidget *prefs_conv_themes_comb
static GtkWidget *prefs_conv_variants_combo_box;
static GtkWidget *prefs_status_themes_combo_box;
static GtkWidget *prefs_smiley_themes_combo_box;
+static PurpleHttpConnection *prefs_conv_themes_running_request = NULL;
/* Keyrings page */
static GtkWidget *keyring_page_instance = NULL;
@@ -535,6 +539,10 @@ static void keyring_page_cleanup(void);
static void
delete_prefs(GtkWidget *asdf, void *gdsa)
{
+ /* Cancel HTTP requests */
+ purple_http_conn_cancel(prefs_conv_themes_running_request);
+ prefs_conv_themes_running_request = NULL;
+
/* Close any "select sound" request dialogs */
purple_request_close_with_handle(prefs);
@@ -1060,18 +1068,26 @@ theme_install_theme(char *path, struct t
}
static void
-theme_got_url(PurpleUtilFetchUrlData *url_data, gpointer user_data,
- const gchar *themedata, size_t len, const gchar *error_message)
+theme_got_url(PurpleHttpConnection *http_conn, PurpleHttpResponse *response,
+ gpointer _info)
{
+ struct theme_info *info = _info;
+ const gchar *themedata;
+ size_t len;
FILE *f;
gchar *path;
size_t wc;
- if ((error_message != NULL) || (len == 0)) {
- free_theme_info(user_data);
+ g_assert(http_conn == prefs_conv_themes_running_request);
+ prefs_conv_themes_running_request = NULL;
+
+ if (!purple_http_response_is_successfull(response)) {
+ free_theme_info(info);
return;
}
+ themedata = purple_http_response_get_data(response, &len);
+
f = purple_mkstemp(&path, TRUE);
wc = fwrite(themedata, len, 1, f);
if (wc != 1) {
@@ -1079,12 +1095,12 @@ theme_got_url(PurpleUtilFetchUrlData *ur
fclose(f);
g_unlink(path);
g_free(path);
- free_theme_info(user_data);
+ free_theme_info(info);
return;
}
fclose(f);
- theme_install_theme(path, user_data);
+ theme_install_theme(path, info);
g_unlink(path);
g_free(path);
@@ -1121,22 +1137,19 @@ theme_dnd_recv(GtkWidget *widget, GdkDra
}
theme_install_theme(tmp, info);
g_free(tmp);
- } else if (!g_ascii_strncasecmp(name, "http://", 7)) {
+ } else if (!g_ascii_strncasecmp(name, "http://", 7) ||
+ !g_ascii_strncasecmp(name, "https://", 8)) {
/* Oo, a web drag and drop. This is where things
* will start to get interesting */
- purple_util_fetch_url(name, TRUE, NULL, FALSE, -1, theme_got_url, info);
- } else if (!g_ascii_strncasecmp(name, "https://", 8)) {
- /* purple_util_fetch_url() doesn't support HTTPS, but we want users
- * to be able to drag and drop links from the SF trackers, so
- * we'll try it as an HTTP URL. */
- char *tmp = g_strdup(name + 1);
- tmp[0] = 'h';
- tmp[1] = 't';
- tmp[2] = 't';
- tmp[3] = 'p';
-
- purple_util_fetch_url(tmp, TRUE, NULL, FALSE, -1, theme_got_url, info);
- g_free(tmp);
+ PurpleHttpRequest *hr;
+ purple_http_conn_cancel(prefs_conv_themes_running_request);
+
+ hr = purple_http_request_new(name);
+ purple_http_request_set_max_len(hr,
+ PREFS_MAX_DOWNLOADED_THEME_SIZE);
+ prefs_conv_themes_running_request = purple_http_request(
+ NULL, hr, theme_got_url, info);
+ purple_http_request_unref(hr);
} else
free_theme_info(info);
diff --git a/pidgin/gtksmiley.c b/pidgin/gtksmiley.c
--- a/pidgin/gtksmiley.c
+++ b/pidgin/gtksmiley.c
@@ -27,9 +27,9 @@
#include "internal.h"
#include "pidgin.h"
-#include "obsolete.h"
#include "debug.h"
+#include "http.h"
#include "notify.h"
#include "smiley.h"
@@ -61,6 +61,7 @@ typedef struct
GtkWidget *treeview;
GtkListStore *model;
+ PurpleHttpConnection *running_request;
} SmileyManager;
enum
@@ -723,34 +724,23 @@ edit_selected_cb(GtkTreeModel *model, Gt
}
static void
-smiley_got_url(PurpleUtilFetchUrlData *url_data, gpointer user_data,
- const gchar *smileydata, size_t len, const gchar *error_message)
+smiley_got_url(PurpleHttpConnection *http_conn, PurpleHttpResponse *response,
+ gpointer _dialog)
{
- SmileyManager *dialog = user_data;
- FILE *f;
- gchar *path;
- size_t wc;
+ SmileyManager *dialog = _dialog;
More information about the Commits
mailing list