changeset 18769:cddf062baa71

Fix yahoo doodling to work with newer yahoo messenger clients. This breaks doodling with older Pidgin clients (trying to support both looked too painful). Fixes #1445.
author Daniel Atallah <daniel.atallah@gmail.com>
date Wed, 01 Aug 2007 22:38:47 +0000
parents 1b130825466c
children faf6d526ae87
files libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo_doodle.c libpurple/protocols/yahoo/yahoo_doodle.h libpurple/protocols/yahoo/yahoo_filexfer.c
diffstat 4 files changed, 98 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/yahoo.c	Wed Aug 01 19:09:57 2007 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Wed Aug 01 22:38:47 2007 +0000
@@ -398,7 +398,7 @@
 
 	if (message && f)
 		yahoo_friend_set_status_message(f, yahoo_string_decode(gc, message, unicode));
-		
+
 	if (name && f) /* update the last buddy */
 		yahoo_update_status(gc, name, f);
 }
@@ -519,7 +519,7 @@
 		l = l->next;
 
 		switch (pair->key) {
-		case 302: 
+		case 302:
 			/* This is always 318 before a group, 319 before the first s/n in a group, 320 before any ignored s/n.
 			 * It is not sent for s/n's in a group after the first.
 			 * All ignored s/n's are listed last, so when we see a 320 we clear the group and begin marking the
@@ -559,7 +559,7 @@
 
 			} else {
 				/* This buddy is on the ignore list (and therefore in no group) */
-				purple_privacy_deny_add(account, norm_bud, 1);				
+				purple_privacy_deny_add(account, norm_bud, 1);
 			}
 			break;
 		case 241: /* another protocol user */
@@ -829,7 +829,7 @@
 	{
 		g_hash_table_replace(yd->imvironments, g_strdup(im->from), g_strdup(imv));
 
-		if (strcmp(imv, "doodle;11") == 0)
+		if (strstr(imv, "doodle;") != NULL)
 		{
 			PurpleWhiteboard *wb;
 
@@ -838,6 +838,8 @@
 				return;
 			}
 
+			/* I'm not sure the following ever happens -DAA */
+
 			wb = purple_whiteboard_get_session(gc->account, im->from);
 
 			/* If a Doodle session doesn't exist between this user */
@@ -881,17 +883,17 @@
 			PurpleAccount *account;
 			PurpleConversation *c;
 			char *username, *str;
-			
+
 			account = purple_connection_get_account(gc);
 			c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, im->from);
-			
+
 			if ((buddy = purple_find_buddy(account, im->from)) != NULL)
 				username = g_markup_escape_text(purple_buddy_get_alias(buddy), -1);
 			else
 				username = g_markup_escape_text(im->from, -1);
-			
+
 			str = g_strdup_printf(_("%s just sent you a Buzz!"), username);
-			
+
 			purple_conversation_write(c, NULL, str, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, im->time);
 
 			g_free(username);
@@ -997,7 +999,7 @@
 static void
 yahoo_buddy_add_deny_reason_cb(struct yahoo_add_request *add_req) {
 	purple_request_input(add_req->gc, NULL, _("Authorization denied message:"),
-			NULL, _("No reason given."), TRUE, FALSE, NULL, 
+			NULL, _("No reason given."), TRUE, FALSE, NULL,
 			_("OK"), G_CALLBACK(yahoo_buddy_add_deny_cb),
 			_("Cancel"), G_CALLBACK(yahoo_buddy_add_deny_noreason_cb),
 			purple_connection_get_account(add_req->gc), add_req->who, NULL,
@@ -1040,7 +1042,7 @@
 		 */
 		 purple_account_request_authorization(purple_connection_get_account(gc), add_req->who, add_req->id,
                                                     NULL, add_req->msg, purple_find_buddy(purple_connection_get_account(gc),add_req->who) != NULL,
-						    G_CALLBACK(yahoo_buddy_add_authorize_cb), 
+						    G_CALLBACK(yahoo_buddy_add_authorize_cb),
 						    G_CALLBACK(yahoo_buddy_add_deny_reason_cb),
                                                     add_req);
 	} else {
@@ -3401,7 +3403,7 @@
 	 */
 	wb = purple_whiteboard_get_session(gc->account, who);
 	if (wb)
-		yahoo_packet_hash_str(pkt, 63, "doodle;11");
+		yahoo_packet_hash_str(pkt, 63, DOODLE_IMV_KEY);
 	else
 	{
 		const char *imv;
--- a/libpurple/protocols/yahoo/yahoo_doodle.c	Wed Aug 01 19:09:57 2007 +0000
+++ b/libpurple/protocols/yahoo/yahoo_doodle.c	Wed Aug 01 22:38:47 2007 +0000
@@ -125,47 +125,12 @@
 	 * sessions
 	 */
 
+	yahoo_doodle_command_send_ready(gc, to);
 	yahoo_doodle_command_send_request(gc, to);
-	yahoo_doodle_command_send_ready(gc, to);
 
 }
 
-void yahoo_doodle_process(PurpleConnection *gc, const char *me, const char *from,
-						  const char *command, const char *message)
-{
-	if(!command)
-		return;
-
-	/* Now check to see what sort of Doodle message it is */
-	switch(atoi(command))
-	{
-		case DOODLE_CMD_REQUEST:
-			yahoo_doodle_command_got_request(gc, from);
-			break;
-
-		case DOODLE_CMD_READY:
-			yahoo_doodle_command_got_ready(gc, from);
-			break;
-
-		case DOODLE_CMD_CLEAR:
-			yahoo_doodle_command_got_clear(gc, from);
-			break;
-
-		case DOODLE_CMD_DRAW:
-			yahoo_doodle_command_got_draw(gc, from, message);
-			break;
-
-		case DOODLE_CMD_EXTRA:
-			yahoo_doodle_command_got_extra(gc, from, message);
-			break;
-
-		case DOODLE_CMD_CONFIRM:
-			yahoo_doodle_command_got_confirm(gc, from);
-			break;
-	}
-}
-
-void yahoo_doodle_command_got_request(PurpleConnection *gc, const char *from)
+static void yahoo_doodle_command_got_request(PurpleConnection *gc, const char *from)
 {
 	PurpleAccount *account;
 	PurpleWhiteboard *wb;
@@ -197,7 +162,7 @@
 
 		purple_whiteboard_create(account, from, DOODLE_STATE_REQUESTED);
 
-		yahoo_doodle_command_send_request(gc, from);
+		yahoo_doodle_command_send_ready(gc, from);
 	}
 
 	/* TODO Might be required to clear the canvas of an existing doodle
@@ -205,12 +170,12 @@
 	 */
 }
 
-void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from)
+static void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from)
 {
 	PurpleAccount *account;
 	PurpleWhiteboard *wb;
 
-	purple_debug_info("yahoo", "doodle: Got Ready (%s)\n", from);
+	purple_debug_info("yahoo", "doodle: Got Ready(%s)\n", from);
 
 	account = purple_connection_get_account(gc);
 
@@ -230,8 +195,7 @@
 
 		yahoo_doodle_command_send_confirm(gc, from);
 	}
-
-	if(wb->state == DOODLE_STATE_ESTABLISHED)
+	else if(wb->state == DOODLE_STATE_ESTABLISHED)
 	{
 		/* TODO Ask whether to save picture too */
 		purple_whiteboard_clear(wb);
@@ -239,16 +203,16 @@
 
 	/* NOTE Not sure about this... I am trying to handle if the remote user
 	 * already thinks we're in a session with them (when their chat message
-	 * contains the doodle;11 imv key)
+	 * contains the doodle imv key)
 	 */
-	if(wb->state == DOODLE_STATE_REQUESTED)
+	else if(wb->state == DOODLE_STATE_REQUESTED)
 	{
 		/* purple_whiteboard_start(wb); */
-		yahoo_doodle_command_send_request(gc, from);
+		yahoo_doodle_command_send_ready(gc, from);
 	}
 }
 
-void yahoo_doodle_command_got_draw(PurpleConnection *gc, const char *from, const char *message)
+static void yahoo_doodle_command_got_draw(PurpleConnection *gc, const char *from, const char *message)
 {
 	PurpleAccount *account;
 	PurpleWhiteboard *wb;
@@ -304,7 +268,8 @@
 	g_list_free(d_list);
 }
 
-void yahoo_doodle_command_got_clear(PurpleConnection *gc, const char *from)
+
+static void yahoo_doodle_command_got_clear(PurpleConnection *gc, const char *from)
 {
 	PurpleAccount *account;
 	PurpleWhiteboard *wb;
@@ -329,7 +294,8 @@
 	}
 }
 
-void
+
+static void
 yahoo_doodle_command_got_extra(PurpleConnection *gc, const char *from, const char *message)
 {
 	purple_debug_info("yahoo", "doodle: Got Extra (%s)\n", from);
@@ -340,7 +306,7 @@
 	yahoo_doodle_command_send_extra(gc, from, DOODLE_EXTRA_NONE);
 }
 
-void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from)
+static void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from)
 {
 	PurpleAccount *account;
 	PurpleWhiteboard *wb;
@@ -361,14 +327,14 @@
 	/* TODO Combine the following IF's? */
 
 	/* Check if we requested a doodle session */
-	if(wb->state == DOODLE_STATE_REQUESTING)
+	/*if(wb->state == DOODLE_STATE_REQUESTING)
 	{
 		wb->state = DOODLE_STATE_ESTABLISHED;
 
 		purple_whiteboard_start(wb);
 
 		yahoo_doodle_command_send_confirm(gc, from);
-	}
+	}*/
 
 	/* Check if we accepted a request for a doodle session */
 	if(wb->state == DOODLE_STATE_REQUESTED)
@@ -395,25 +361,21 @@
 	 */
 	wb = purple_whiteboard_get_session(account, from);
 
-	/* TODO Ask if user wants to save picture before the session is closed */
-
-	/* If this session doesn't exist, don't try and kill it */
 	if(wb == NULL)
 		return;
-	else
-	{
-		purple_whiteboard_destroy(wb);
+
+	/* TODO Ask if user wants to save picture before the session is closed */
 
-		/* yahoo_doodle_command_send_shutdown(gc, from); */
-	}
+	wb->state = DOODLE_STATE_CANCELED;
+	purple_whiteboard_destroy(wb);
 }
 
 static void yahoo_doodle_command_send_generic(const char *type,
 											  PurpleConnection *gc,
 											  const char *to,
 											  const char *message,
-											  const char *thirteen,
-											  const char *sixtythree,
+											  int command,
+											  const char *imv,
 											  const char *sixtyfour)
 {
 	struct yahoo_data *yd;
@@ -428,48 +390,48 @@
 	yahoo_packet_hash_str(pkt, 49,  "IMVIRONMENT");
 	yahoo_packet_hash_str(pkt, 1,    purple_account_get_username(gc->account));
 	yahoo_packet_hash_str(pkt, 14,   message);
-	yahoo_packet_hash_str(pkt, 13,   thirteen);
+	yahoo_packet_hash_int(pkt, 13,   command);
 	yahoo_packet_hash_str(pkt, 5,    to);
-	yahoo_packet_hash_str(pkt, 63,   sixtythree ? sixtythree : "doodle;11");
+	yahoo_packet_hash_str(pkt, 63,   imv ? imv : DOODLE_IMV_KEY);
 	yahoo_packet_hash_str(pkt, 64,   sixtyfour);
 	yahoo_packet_hash_str(pkt, 1002, "1");
 
 	yahoo_packet_send_and_free(pkt, yd);
 }
 
+void yahoo_doodle_command_send_ready(PurpleConnection *gc, const char *to)
+{
+	yahoo_doodle_command_send_generic("Ready", gc, to, "1", DOODLE_CMD_READY, NULL, "1");
+}
+
 void yahoo_doodle_command_send_request(PurpleConnection *gc, const char *to)
 {
-	yahoo_doodle_command_send_generic("Request", gc, to, "1", "1", NULL, "1");
-}
-
-void yahoo_doodle_command_send_ready(PurpleConnection *gc, const char *to)
-{
-	yahoo_doodle_command_send_generic("Ready", gc, to, "", "0", NULL, "0");
+	yahoo_doodle_command_send_generic("Request", gc, to, "", DOODLE_CMD_REQUEST, NULL, "0");
 }
 
 void yahoo_doodle_command_send_draw(PurpleConnection *gc, const char *to, const char *message)
 {
-	yahoo_doodle_command_send_generic("Draw", gc, to, message, "3", NULL, "1");
+	yahoo_doodle_command_send_generic("Draw", gc, to, message, DOODLE_CMD_DRAW, NULL, "1");
 }
 
 void yahoo_doodle_command_send_clear(PurpleConnection *gc, const char *to)
 {
-	yahoo_doodle_command_send_generic("Clear", gc, to, " ", "2", NULL, "1");
+	yahoo_doodle_command_send_generic("Clear", gc, to, " ", DOODLE_CMD_CLEAR, NULL, "1");
 }
 
 void yahoo_doodle_command_send_extra(PurpleConnection *gc, const char *to, const char *message)
 {
-	yahoo_doodle_command_send_generic("Extra", gc, to, message, "4", NULL, "1");
+	yahoo_doodle_command_send_generic("Extra", gc, to, message, DOODLE_CMD_EXTRA, NULL, "1");
 }
 
 void yahoo_doodle_command_send_confirm(PurpleConnection *gc, const char *to)
 {
-	yahoo_doodle_command_send_generic("Confirm", gc, to, "1", "5", NULL, "1");
+	yahoo_doodle_command_send_generic("Confirm", gc, to, "1", DOODLE_CMD_CONFIRM, NULL, "1");
 }
 
 void yahoo_doodle_command_send_shutdown(PurpleConnection *gc, const char *to)
 {
-	yahoo_doodle_command_send_generic("Shutdown", gc, to, "", "0", ";0", "0");
+	yahoo_doodle_command_send_generic("Shutdown", gc, to, "", DOODLE_CMD_SHUTDOWN, ";0", "0");
 }
 
 void yahoo_doodle_start(PurpleWhiteboard *wb)
@@ -491,7 +453,7 @@
 
 	/* g_debug_debug("yahoo", "doodle: yahoo_doodle_end()\n"); */
 
-	if (gc)
+	if (gc && wb->state != DOODLE_STATE_CANCELED)
 		yahoo_doodle_command_send_shutdown(gc, wb->who);
 
 	g_free(wb->proto_data);
@@ -530,7 +492,7 @@
 	g_return_if_fail(draw_list != NULL);
 
 	message = yahoo_doodle_build_draw_string(ds, draw_list);
-		yahoo_doodle_command_send_draw(wb->account->gc, wb->who, message);
+	yahoo_doodle_command_send_draw(wb->account->gc, wb->who, message);
 	g_free(message);
 }
 
@@ -604,3 +566,37 @@
 	purple_whiteboard_set_brush(wb, size, color);
 }
 
+void yahoo_doodle_process(PurpleConnection *gc, const char *me, const char *from,
+						  const char *command, const char *message)
+{
+	if(!command)
+		return;
+
+	/* Now check to see what sort of Doodle message it is */
+	switch(atoi(command))
+	{
+		case DOODLE_CMD_REQUEST:
+			yahoo_doodle_command_got_request(gc, from);
+			break;
+
+		case DOODLE_CMD_READY:
+			yahoo_doodle_command_got_ready(gc, from);
+			break;
+
+		case DOODLE_CMD_CLEAR:
+			yahoo_doodle_command_got_clear(gc, from);
+			break;
+
+		case DOODLE_CMD_DRAW:
+			yahoo_doodle_command_got_draw(gc, from, message);
+			break;
+
+		case DOODLE_CMD_EXTRA:
+			yahoo_doodle_command_got_extra(gc, from, message);
+			break;
+
+		case DOODLE_CMD_CONFIRM:
+			yahoo_doodle_command_got_confirm(gc, from);
+			break;
+	}
+}
--- a/libpurple/protocols/yahoo/yahoo_doodle.h	Wed Aug 01 19:09:57 2007 +0000
+++ b/libpurple/protocols/yahoo/yahoo_doodle.h	Wed Aug 01 22:38:47 2007 +0000
@@ -31,17 +31,19 @@
 #include "whiteboard.h"
 #include "cmds.h"
 
+#define DOODLE_IMV_KEY "doodle;103"
+
 /******************************************************************************
  * Defines
  *****************************************************************************/
 /* Doodle communication commands */
 /* TODO: Should be an enum. */
-#define DOODLE_CMD_REQUEST  0
-#define DOODLE_CMD_READY    1
-#define DOODLE_CMD_CLEAR    2
-#define DOODLE_CMD_DRAW     3
-#define DOODLE_CMD_EXTRA    4
-#define DOODLE_CMD_CONFIRM  5
+#define DOODLE_CMD_REQUEST	0
+#define DOODLE_CMD_CLEAR	1
+#define DOODLE_CMD_DRAW		2
+#define DOODLE_CMD_EXTRA	3
+#define DOODLE_CMD_READY	4
+#define DOODLE_CMD_CONFIRM	5
 /* Doodle communication command for shutting down (also 0) */
 #define DOODLE_CMD_SHUTDOWN 0
 
@@ -54,6 +56,7 @@
 #define DOODLE_STATE_REQUESTING  0
 #define DOODLE_STATE_REQUESTED   1
 #define DOODLE_STATE_ESTABLISHED 2
+#define DOODLE_STATE_CANCELED    3
 
 /* Doodle canvas dimensions */
 #define DOODLE_CANVAS_WIDTH  368
@@ -104,12 +107,6 @@
 						  const char *command, const char *message);
 void yahoo_doodle_initiate(PurpleConnection *gc, const char *to);
 
-void yahoo_doodle_command_got_request(PurpleConnection *gc, const char *from);
-void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from);
-void yahoo_doodle_command_got_draw(PurpleConnection *gc, const char *from, const char *message);
-void yahoo_doodle_command_got_clear(PurpleConnection *gc, const char *from);
-void yahoo_doodle_command_got_extra(PurpleConnection *gc, const char *from, const char *message);
-void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from);
 void yahoo_doodle_command_got_shutdown(PurpleConnection *gc, const char *from);
 
 void yahoo_doodle_command_send_request(PurpleConnection *gc, const char *to);
--- a/libpurple/protocols/yahoo/yahoo_filexfer.c	Wed Aug 01 19:09:57 2007 +0000
+++ b/libpurple/protocols/yahoo/yahoo_filexfer.c	Wed Aug 01 22:38:47 2007 +0000
@@ -484,7 +484,7 @@
 	if(service != NULL && imv != NULL && !strcmp(service, "IMVIRONMENT"))
 	{
 		/* Check for a Doodle packet and handle it accordingly */
-		if(!strcmp(imv, "doodle;11"))
+		if(strstr(imv, "doodle;") != NULL)
 			yahoo_doodle_process(gc, me, from, command, message);
 
 		/* If an IMVIRONMENT packet comes without a specific imviroment name */
@@ -622,12 +622,12 @@
 {
 	PurpleXfer *xfer;
 	struct yahoo_xfer_data *xfer_data;
-	
+
 	g_return_val_if_fail(who != NULL, NULL);
-	
+
 	xfer_data = g_new0(struct yahoo_xfer_data, 1);
 	xfer_data->gc = gc;
-	
+
 	/* Build the file transfer handle. */
 	xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who);
 	if (xfer)