/soc/2013/ankitkv/gobjectification: 97f632383c41: Merged soc.201...

Ankit Vani a at nevitus.org
Wed Aug 7 06:25:44 EDT 2013


Changeset: 97f632383c41305b84415df9ff00c57daf0c332c
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-07 15:55 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/97f632383c41

Description:

Merged soc.2013.gobjectification branch

diffstat:

 libpurple/protocols/yahoo/libymsg.c       |    3 +-
 libpurple/protocols/yahoo/libymsg.h       |    7 +-
 libpurple/protocols/yahoo/yahoo_picture.c |  199 +++++++++--------------------
 libpurple/protocols/yahoo/yahoochat.c     |  198 +++++++----------------------
 4 files changed, 111 insertions(+), 296 deletions(-)

diffs (truncated from 575 to 300 lines):

diff --git a/libpurple/protocols/yahoo/libymsg.c b/libpurple/protocols/yahoo/libymsg.c
--- a/libpurple/protocols/yahoo/libymsg.c
+++ b/libpurple/protocols/yahoo/libymsg.c
@@ -3731,8 +3731,7 @@ void yahoo_close(PurpleConnection *gc) {
 	yd->rxlen = 0;
 	g_free(yd->picture_url);
 
-	if (yd->buddy_icon_connect_data)
-		purple_proxy_connect_cancel(yd->buddy_icon_connect_data);
+	purple_http_conn_cancel(yd->picture_upload_hc);
 	if (yd->picture_upload_todo)
 		yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo);
 	if (yd->ycht)
diff --git a/libpurple/protocols/yahoo/libymsg.h b/libpurple/protocols/yahoo/libymsg.h
--- a/libpurple/protocols/yahoo/libymsg.h
+++ b/libpurple/protocols/yahoo/libymsg.h
@@ -150,11 +150,8 @@ typedef enum {
 
 struct yahoo_buddy_icon_upload_data {
 	PurpleConnection *gc;
-	GString *str;
 	char *filename;
-	int pos;
-	int fd;
-	guint watcher;
+	GString *picture_data;
 };
 
 struct yahoo_p2p_data	{
@@ -236,7 +233,7 @@ typedef struct {
 	/* ew. we have to check the icon before we connect,
 	 * but can't upload it til we're connected. */
 	struct yahoo_buddy_icon_upload_data *picture_upload_todo;
-	PurpleProxyConnectData *buddy_icon_connect_data;
+	PurpleHttpConnection *picture_upload_hc;
 
 	struct _YchtConn *ycht;
 
diff --git a/libpurple/protocols/yahoo/yahoo_picture.c b/libpurple/protocols/yahoo/yahoo_picture.c
--- a/libpurple/protocols/yahoo/yahoo_picture.c
+++ b/libpurple/protocols/yahoo/yahoo_picture.c
@@ -328,176 +328,100 @@ void yahoo_buddy_icon_upload_data_free(s
 {
 	purple_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n");
 
-	if (d->str)
-		g_string_free(d->str, TRUE);
+	if (d->picture_data)
+		g_string_free(d->picture_data, TRUE);
 	g_free(d->filename);
-	if (d->watcher)
-		purple_input_remove(d->watcher);
-	if (d->fd != -1)
-		close(d->fd);
 	g_free(d);
 }
 
-/* we couldn't care less about the server's response, but yahoo gets grumpy if we close before it sends it */
-static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, PurpleInputCondition condition)
+static void
+yahoo_buddy_icon_upload_done(PurpleHttpConnection *http_conn,
+	PurpleHttpResponse *response, gpointer _d)
 {
-	struct yahoo_buddy_icon_upload_data *d = data;
+	struct yahoo_buddy_icon_upload_data *d = _d;
 	PurpleConnection *gc = d->gc;
-	char buf[1024];
-	int ret;
+	YahooData *yd = purple_connection_get_protocol_data(gc);
 
-	if (!PURPLE_CONNECTION_IS_VALID(gc)) {
-		yahoo_buddy_icon_upload_data_free(d);
-		return;
-	}
+	yd->picture_upload_hc = NULL;
 
-	ret = read(d->fd, buf, sizeof(buf));
+	if (!purple_http_response_is_successfull(response))
+		purple_debug_info("yahoo", "Error uploading buddy icon.\n");
+	else
+		purple_debug_misc("yahoo", "Finished uploading buddy icon.\n");
 
-	if (ret < 0 && errno == EAGAIN)
-		return;
-	else if (ret <= 0) {
-		/* There are other problems if d->str->len overflows, so shut up the
-		 * warning on 64-bit. */
-		purple_debug_info("yahoo", "Buddy icon upload response (%" G_GSIZE_FORMAT ") bytes (> ~400 indicates failure):\n%.*s\n",
-			d->str->len, (guint)d->str->len, d->str->str);
-
-		yahoo_buddy_icon_upload_data_free(d);
-		return;
-	}
-
-	g_string_append_len(d->str, buf, ret);
+	yahoo_buddy_icon_upload_data_free(d);
 }
 
-static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, PurpleInputCondition condition)
+static void
+yahoo_buddy_icon_build_packet(struct yahoo_buddy_icon_upload_data *d)
 {
-	struct yahoo_buddy_icon_upload_data *d = data;
+	struct yahoo_packet *pkt;
 	PurpleConnection *gc = d->gc;
-	gssize wrote;
+	YahooData *yd = purple_connection_get_protocol_data(gc);
+	gchar *len_str;
+	guchar *pkt_buf;
+	gsize pkt_buf_len;
 
-	if (!PURPLE_CONNECTION_IS_VALID(gc)) {
-		yahoo_buddy_icon_upload_data_free(d);
-		return;
-	}
+	pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPLOAD,
+		YAHOO_STATUS_AVAILABLE, yd->session_id);
 
-	wrote = write(d->fd, d->str->str + d->pos, d->str->len - d->pos);
-	if (wrote < 0 && errno == EAGAIN)
-		return;
-	if (wrote <= 0) {
-		purple_debug_info("yahoo", "Error uploading buddy icon.\n");
-		yahoo_buddy_icon_upload_data_free(d);
-		return;
-	}
-	d->pos += wrote;
-	if (d->pos >= d->str->len) {
-		purple_debug_misc("yahoo", "Finished uploading buddy icon.\n");
-		purple_input_remove(d->watcher);
-		/* Clean out the sent buffer and reuse it to read the result */
-		g_string_free(d->str, TRUE);
-		d->str = g_string_new("");
-		d->watcher = purple_input_add(d->fd, PURPLE_INPUT_READ, yahoo_buddy_icon_upload_reading, d);
-	}
-}
-
-static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, const gchar *error_message)
-{
-	struct yahoo_buddy_icon_upload_data *d = data;
-	struct yahoo_packet *pkt;
-	gchar *tmp, *header;
-	guchar *pkt_buf;
-	const char *host;
-	int port;
-	gsize pkt_buf_len;
-	PurpleConnection *gc = d->gc;
-	PurpleAccount *account;
-	YahooData *yd;
-	/* use whole URL if using HTTP Proxy */
-	gboolean use_whole_url = yahoo_account_use_http_proxy(gc);
-
-	account = purple_connection_get_account(gc);
-	yd = purple_connection_get_protocol_data(gc);
-
-	/* Buddy icon connect is now complete; clear the PurpleProxyConnectData */
-	yd->buddy_icon_connect_data = NULL;
-
-	if (source < 0) {
-		purple_debug_error("yahoo", "Buddy icon upload failed: %s\n", error_message);
-		yahoo_buddy_icon_upload_data_free(d);
-		return;
-	}
-
-	pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPLOAD, YAHOO_STATUS_AVAILABLE, yd->session_id);
-
-	tmp = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len);
-	/* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */
+	len_str = g_strdup_printf("%" G_GSIZE_FORMAT, d->picture_data->len);
+	/* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename,
+	 * 14 = NULL, 29 = data
+	 */
 	yahoo_packet_hash_str(pkt, 1, purple_connection_get_display_name(gc));
 	yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */
-	purple_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800);
+	purple_account_set_int(purple_connection_get_account(gc),
+		YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800);
 	yahoo_packet_hash_str(pkt, 0, purple_connection_get_display_name(gc));
-	yahoo_packet_hash_str(pkt, 28, tmp);
-	g_free(tmp);
+	yahoo_packet_hash_str(pkt, 28, len_str);
+	g_free(len_str);
 	yahoo_packet_hash_str(pkt, 27, d->filename);
 	yahoo_packet_hash_str(pkt, 14, "");
 	/* 4 padding for the 29 key name */
 	pkt_buf_len = yahoo_packet_build(pkt, 4, FALSE, yd->jp, &pkt_buf);
 	yahoo_packet_free(pkt);
 
-	/* header + packet + "29" + 0xc0 + 0x80) + pictureblob */
+	/* There's no magic here, we just need to prepend in reverse order */
+	g_string_prepend(d->picture_data, "29\xc0\x80");
 
-	host = purple_account_get_string(account, "xfer_host", yd->jp? YAHOOJP_XFER_HOST : YAHOO_XFER_HOST);
-	port = purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT);
-	tmp = g_strdup_printf("%s:%d", host, port);
-	header = g_strdup_printf("POST %s%s/notifyft HTTP/1.1\r\n"
-		"User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
-		"Cookie: T=%s; Y=%s\r\n"
-		"Host: %s\r\n"
-		"Content-Length: %" G_GSIZE_FORMAT "\r\n"
-		"Cache-Control: no-cache\r\n\r\n",
-		use_whole_url ? "http://" : "", use_whole_url ? tmp : "",
-		yd->cookie_t, yd->cookie_y,
-		tmp,
-		pkt_buf_len + 4 + d->str->len);
-	g_free(tmp);
-
-	/* There's no magic here, we just need to prepend in reverse order */
-	g_string_prepend(d->str, "29\xc0\x80");
-
-	g_string_prepend_len(d->str, (char *)pkt_buf, pkt_buf_len);
+	g_string_prepend_len(d->picture_data, (char *)pkt_buf, pkt_buf_len);
 	g_free(pkt_buf);
-
-	g_string_prepend(d->str, header);
-	g_free(header);
-
-	/* There are other problems if we're uploading over 4GB of data */
-	purple_debug_info("yahoo", "Buddy icon upload data:\n%.*s\n", (guint)d->str->len, d->str->str);
-
-	d->fd = source;
-	d->watcher = purple_input_add(d->fd, PURPLE_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d);
-
-	yahoo_buddy_icon_upload_pending(d, d->fd, PURPLE_INPUT_WRITE);
 }
 
-void yahoo_buddy_icon_upload(PurpleConnection *gc, struct yahoo_buddy_icon_upload_data *d)
+void
+yahoo_buddy_icon_upload(PurpleConnection *gc,
+	struct yahoo_buddy_icon_upload_data *d)
 {
+	PurpleHttpRequest *req;
+	PurpleHttpCookieJar *cjar;
 	PurpleAccount *account = purple_connection_get_account(gc);
 	YahooData *yd = purple_connection_get_protocol_data(gc);
 
-	if (yd->buddy_icon_connect_data != NULL) {
-		/* Cancel any in-progress buddy icon upload */
-		purple_proxy_connect_cancel(yd->buddy_icon_connect_data);
-		yd->buddy_icon_connect_data = NULL;
-	}
+	/* Cancel any in-progress buddy icon upload */
+	purple_http_conn_cancel(yd->picture_upload_hc);
 
-	yd->buddy_icon_connect_data = purple_proxy_connect(NULL, account,
-			purple_account_get_string(account, "xfer_host",
-				yd->jp? YAHOOJP_XFER_HOST : YAHOO_XFER_HOST),
-			purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT),
-			yahoo_buddy_icon_upload_connected, d);
+	req = purple_http_request_new(NULL);
+	purple_http_request_set_url_printf(req, "http://%s:%d/notifyft",
+		purple_account_get_string(account, "xfer_host", yd->jp ?
+			YAHOOJP_XFER_HOST : YAHOO_XFER_HOST),
+		purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT));
+	purple_http_request_set_method(req, "POST");
+	cjar = purple_http_request_get_cookie_jar(req);
+	purple_http_cookie_jar_set(cjar, "T", yd->cookie_t);
+	purple_http_cookie_jar_set(cjar, "Y", yd->cookie_y);
+	purple_http_request_header_set(req, "Cache-Control", "no-cache");
+	purple_http_request_header_set(req, "User-Agent",
+		YAHOO_CLIENT_USERAGENT);
 
-	if (yd->buddy_icon_connect_data == NULL)
-	{
-		purple_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n");
-		yahoo_buddy_icon_upload_data_free(d);
-	}
+	yahoo_buddy_icon_build_packet(d);
+	purple_http_request_set_contents(req, d->picture_data->str,
+		d->picture_data->len);
+	g_string_free(d->picture_data, TRUE);
+	d->picture_data = NULL;
+
+	yd->picture_upload_hc = purple_http_request(gc, req,
+		yahoo_buddy_icon_upload_done, d);
 }
 
 static int yahoo_buddy_icon_calculate_checksum(const guchar *data, gsize len)
@@ -564,8 +488,7 @@ void yahoo_set_buddy_icon(PurpleConnecti
 		/* We use this solely for sending a filename to the server */
 		d = g_new0(struct yahoo_buddy_icon_upload_data, 1);
 		d->gc = gc;
-		d->str = s;
-		d->fd = -1;
+		d->picture_data = s;
 		d->filename = g_strdup(purple_imgstore_get_filename(img));
 
 		if (!yd->logged_in) {
diff --git a/libpurple/protocols/yahoo/yahoochat.c b/libpurple/protocols/yahoo/yahoochat.c
--- a/libpurple/protocols/yahoo/yahoochat.c
+++ b/libpurple/protocols/yahoo/yahoochat.c
@@ -1178,31 +1178,19 @@ void yahoo_c_invite(PurpleConnection *gc
 }
 
 struct yahoo_roomlist {
-	int fd;
-	int inpa;
-	gchar *txbuf;
-	gsize tx_written;
-	guchar *rxqueue;



More information about the Commits mailing list