changeset 19800:da3f8f7ec3ce

[gaim-migrate @ 16737] can send Message to Yahoo Messenger can receive the Yahoo Message, Need to post it to the conversation committed by Ma Yuan<mayuan2006@gmail.com> committer: Ethan Blanton <elb@pidgin.im>
author Ma Yuan <mayuan2006@gmail.com>
date Sun, 13 Aug 2006 16:01:52 +0000
parents 88b0c434259a
children 90f89601d6d3
files src/protocols/msn/command.c src/protocols/msn/contact.c src/protocols/msn/msg.c src/protocols/msn/msn.c src/protocols/msn/notification.c src/protocols/msn/notification.h src/protocols/msn/switchboard.c src/protocols/msn/user.c src/protocols/msn/userlist.c src/protocols/msn/userlist.h
diffstat 10 files changed, 176 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/command.c	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/command.c	Sun Aug 13 16:01:52 2006 +0000
@@ -51,6 +51,8 @@
 		(!strcmp(str,"RML")) ||
 		(!strcmp(str,"UBX")) ||
 		(!strcmp(str,"UBN")) ||
+		(!strcmp(str,"UUM")) ||
+		(!strcmp(str,"UBM")) ||
 		(!strcmp(str,"UUN")) ||
 		(!strcmp(str,"UUX"))){
 			return TRUE;
@@ -66,6 +68,11 @@
 	if(!(strcmp(str,"MSG"))|| (!strcmp(str,"UBX")) ){
 		return 2;
 	}
+	/*Yahoo User Message UBM 
+	 * Format UBM email@yahoo.com 32 1 [payload length]*/
+	if(!(strcmp(str,"UBM"))|| (!strcmp(str,"UUM")) ){
+		return 3;
+	}
 
 	return 1;
 }
--- a/src/protocols/msn/contact.c	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/contact.c	Sun Aug 13 16:01:52 2006 +0000
@@ -112,14 +112,13 @@
 msn_parse_contact_list(MsnContact * contact)
 {
 	MsnSession * session;
-	MsnUser *user;
 	int list_op =0;
 	char * passport;
 	xmlnode * node,*body,*response,*result,*services,*service,*memberships;
 	xmlnode *membershipnode,*members,*member,*passportNode,*role;
 
 	session = contact->session;
-//	gaim_debug_misc("xml","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len);
+	gaim_debug_misc("xml","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len);
 	node = 	xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len);
 //	node = 	xmlnode_from_str(contact->soapconn->body, -1);
 
@@ -148,6 +147,7 @@
 		members = xmlnode_get_child(membershipnode,"Members");
 		for(member = xmlnode_get_child(members, "Member"); member;
 				member = xmlnode_get_next_twin(member)){
+			MsnUser *user;
 			xmlnode * typeNode;
 			char * type;
 
@@ -158,17 +158,20 @@
 				typeNode = xmlnode_get_child(member,"Type");
 				type = xmlnode_get_data(typeNode);
 				gaim_debug_misc("Passport","name:%s,type:%s\n",passport,type);
-				user = msn_userlist_find_user(session->userlist, passport);
-				if (user == NULL){
-					user = msn_user_new(session->userlist, passport, "");
-					msn_userlist_add_user(session->userlist, user);
-				}
-//				user->list_op |= list_op;
+
+				user = msn_userlist_find_add_user(session->userlist,passport,NULL);
 				msn_got_lst_user(session, user, list_op, NULL);
 			}
 			if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PhoneMember")){
 			}
 			if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")){
+				xmlnode *emailNode;
+
+				emailNode = xmlnode_get_child(member,"Email");
+				passport = xmlnode_get_data(emailNode);
+				gaim_debug_info("Email","name:%s,list_op:%d\n",passport,list_op);
+				user = msn_userlist_find_add_user(session->userlist,passport,NULL);
+				msn_got_lst_user(session,user,list_op,NULL);
 			}
 		}
 	}
@@ -306,10 +309,27 @@
 
 		passportName = xmlnode_get_child(contactInfo,"passportName");
 		if(passportName == NULL){
+			xmlnode *emailsNode, *contactEmailNode, *emailNode;
+			xmlnode *messengerEnabledNode;
+			char *msnEnabled;
+
 			/*TODO: add it to the none-instant Messenger group and recognize as email Membership*/
-			continue;
+			/*Yahoo User?*/
+			emailsNode = xmlnode_get_child(contactInfo,"emails");
+			for(contactEmailNode = xmlnode_get_child(emailsNode,"ContactEmail");contactEmailNode;
+					contactEmailNode = xmlnode_get_next_twin(contactEmailNode) ){
+				messengerEnabledNode = xmlnode_get_child(contactEmailNode,"isMessengerEnabled");
+				msnEnabled = xmlnode_get_data(messengerEnabledNode);
+				if(!strcmp(msnEnabled,"true")){
+					emailNode = xmlnode_get_child(contactEmailNode,"email");
+					passport = xmlnode_get_data(emailNode);
+					gaim_debug_info("Ma Yuan","Yahoo User %s\n",passport);
+					break;
+				}
+			}
+		}else{
+			passport = xmlnode_get_data(passportName);
 		}
-		passport = xmlnode_get_data(passportName);
 
 		displayName = xmlnode_get_child(contactInfo,"displayName");
 		Name =xmlnode_get_data(displayName);
@@ -319,11 +339,7 @@
 						xmlnode_get_data(contactId),
 						Name);
 
-		user = msn_userlist_find_user(session->userlist, passport);
-		if (user == NULL){
-			user = msn_user_new(session->userlist, passport, Name);
-			msn_userlist_add_user(session->userlist, user);
-		}
+		user = msn_userlist_find_add_user(session->userlist, passport,Name);
 		msn_user_set_uid(user,uid);
 		msn_user_set_type(user,msn_get_user_type(type));
 		user->list_op |= MSN_LIST_FL_OP;
--- a/src/protocols/msn/msg.c	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/msg.c	Sun Aug 13 16:01:52 2006 +0000
@@ -471,6 +471,7 @@
 		{
 			memcpy(n, body, body_len);
 			n += body_len;
+			n = "\0";
 		}
 	}
 
--- a/src/protocols/msn/msn.c	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/msn.c	Sun Aug 13 16:01:52 2006 +0000
@@ -780,7 +780,7 @@
 	char *msgformat;
 	char *msgtext;
 
-	gaim_debug_info("MaYuan","send IM {%s}\n",message);
+	gaim_debug_info("MaYuan","send IM {%s} to %s\n",message,who);
 	account = gaim_connection_get_account(gc);
 
 	msn_import_html(message, &msgformat, &msgtext);
@@ -794,20 +794,27 @@
 	}
 
 	msg = msn_message_new_plain(msgtext);
+	msg->remote_user = g_strdup(who);
 	msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat);
 
 	g_free(msgformat);
 	g_free(msgtext);
 
+	gaim_debug_info("MaYuan","prepare to send...\n");
 	if (g_ascii_strcasecmp(who, gaim_account_get_username(account)))
 	{
 		MsnSession *session;
 		MsnSwitchBoard *swboard;
 
 		session = gc->proto_data;
-		swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM);
-
-		msn_switchboard_send_msg(swboard, msg, TRUE);
+		if(strstr(who,"yahoo") != NULL){
+			gaim_debug_info("MaYuan","send to Yahoo!\n");
+			uum_send_msg(session,msg);
+		}else{
+			gaim_debug_info("MaYuan","send via switchboard\n");
+			swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM);
+			msn_switchboard_send_msg(swboard, msg, TRUE);
+		}
 	}
 	else
 	{
--- a/src/protocols/msn/notification.c	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/notification.c	Sun Aug 13 16:01:52 2006 +0000
@@ -161,7 +161,7 @@
  **************************************************************************/
 
 static void
-group_error_helper(MsnSession *session, const char *msg, int group_id, int error)
+group_error_helper(MsnSession *session, const char *msg, const char *group_id, int error)
 {
 	GaimAccount *account;
 	GaimConnection *gc;
@@ -400,6 +400,94 @@
 	}
 }
 
+/*send Message to Yahoo Messenger*/
+void
+uum_send_msg(MsnSession *session,MsnMessage *msg)
+{
+	MsnCmdProc *cmdproc;
+	MsnTransaction *trans;
+	char *payload;
+	gsize payload_len;
+	int type;
+	
+	cmdproc = session->notification->cmdproc;
+	g_return_if_fail(msg     != NULL);
+	payload = msn_message_gen_payload(msg, &payload_len);
+	gaim_debug_info("MaYuan","send UUM,payload{%s}\n",payload);
+	type = msg->type;
+	trans = msn_transaction_new(cmdproc, "UUM","%s 32 %d %d",msg->remote_user,type,strlen(payload));
+	msn_transaction_set_payload(trans, payload, strlen(payload));
+	msn_cmdproc_send_trans(cmdproc, trans);
+}
+
+static void
+ubm_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload,
+			 size_t len)
+{
+	MsnMessage *msg;
+	GaimConnection *gc;
+
+	gaim_debug_info("MaYuan","Process UBM payload:%s\n",payload);
+	msg = msn_message_new_from_cmd(cmdproc->session, cmd);
+
+	msn_message_parse_payload(msg, payload, len);
+#ifdef MSN_DEBUG_NS
+	msn_message_show_readable(msg, "Notification", TRUE);
+#endif
+
+	gaim_debug_info("MaYuan","type:%d\n",msg->type);
+	if(msg->type == MSN_MSG_TEXT){
+		const char *value;
+		const char *body;
+		char *body_str;
+		char *body_enc;
+		char *body_final;
+		size_t body_len;
+		const char *passport;
+
+		body = msn_message_get_bin_data(msg, &body_len);
+		body_str = g_strndup(body, body_len);
+		body_enc = g_markup_escape_text(body_str, -1);
+		g_free(body_str);
+
+		passport = msg->remote_user;
+		gc = cmdproc->session->account->gc;
+			if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL)	{
+					char *pre, *post;
+
+				msn_parse_format(value, &pre, &post);
+				body_final = g_strdup_printf("%s%s%s", pre ? pre : "",
+								body_enc ? body_enc : "", post ? post : "");
+				g_free(pre);
+				g_free(post);
+				g_free(body_enc);
+		}
+		serv_got_im(gc, passport, body_final, 0, time(NULL));
+	}
+	msn_message_destroy(msg);
+}
+
+/*Yahoo msg process*/
+static void
+ubm_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
+{
+	gaim_debug_info("MaYuan","Processing UBM... \n");
+	if(cmd->payload_len == 0){
+		return;
+	}
+	/* NOTE: cmd is not always cmdproc->last_cmd, sometimes cmd is a queued
+	 * command and we are processing it */
+	if (cmd->payload == NULL){
+		cmdproc->last_cmd->payload_cb  = ubm_cmd_post;
+		cmdproc->servconn->payload_len = atoi(cmd->params[2]);
+	}else{
+		g_return_if_fail(cmd->payload_cb != NULL);
+
+		gaim_debug_info("MaYuan","UBM payload:{%s}\n",cmd->payload);
+		ubm_cmd_post(cmdproc, cmd, cmd->payload, cmd->payload_len);
+	}
+}
+
 /**************************************************************************
  * Challenges
  *  we use MD5 to caculate the Chanllenges 
@@ -481,12 +569,12 @@
 	gaim_debug_info("MaYuan","list_op:%d\n",list_op_str);
 	xmlnode_set_attrib(c_node,"l",list_op_str);
 	g_free(list_op_str);
-#if 1
+#if 0
 	type_str = g_strdup_printf("%d",type);
 	xmlnode_set_attrib(c_node,"t",type_str);
 #else
 	if(g_strrstr(domain,"yahoo") != NULL){
-		type_str = g_strdup_printf("31");
+		type_str = g_strdup_printf("32");
 	}else{
 		/*passport*/
 		type_str = g_strdup_printf("1");
@@ -932,12 +1020,12 @@
 static void
 reg_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
 {
-	int group_id;
+	const char * group_id;
 	char **params;
 
 	params = g_strsplit(trans->params, " ", 0);
 
-	group_id = atoi(params[0]);
+	group_id = params[0];
 
 	group_error_helper(cmdproc->session, _("Unable to rename group"), group_id, error);
 
@@ -1640,6 +1728,7 @@
 	/* Asynchronous */
 	msn_table_add_cmd(cbs_table, NULL, "IPG", ipg_cmd);
 	msn_table_add_cmd(cbs_table, NULL, "MSG", msg_cmd);
+	msn_table_add_cmd(cbs_table, NULL, "UBM", ubm_cmd);
 	msn_table_add_cmd(cbs_table, NULL, "GCF", gcf_cmd);
 	msn_table_add_cmd(cbs_table, NULL, "SBS", sbs_cmd);
 	msn_table_add_cmd(cbs_table, NULL, "NOT", not_cmd);
--- a/src/protocols/msn/notification.h	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/notification.h	Sun Aug 13 16:01:52 2006 +0000
@@ -48,6 +48,7 @@
 };
 
 #include "state.h"
+void uum_send_msg(MsnSession *session,MsnMessage *msg);
 
 void msn_notification_end(void);
 void msn_notification_init(void);
--- a/src/protocols/msn/switchboard.c	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/switchboard.c	Sun Aug 13 16:01:52 2006 +0000
@@ -742,6 +742,14 @@
 }
 
 static void
+ubm_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
+{
+	gaim_debug_misc("MaYuan","get UBM...\n");
+	cmdproc->servconn->payload_len = atoi(cmd->params[4]);
+	cmdproc->last_cmd->payload_cb = msg_cmd_post;
+}
+
+static void
 nak_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
 	MsnMessage *msg;
@@ -1236,6 +1244,7 @@
 	msn_table_add_cmd(cbs_table, "USR", "USR", usr_cmd);
 
 	msn_table_add_cmd(cbs_table, NULL, "MSG", msg_cmd);
+	msn_table_add_cmd(cbs_table, NULL, "UBM", ubm_cmd);
 	msn_table_add_cmd(cbs_table, NULL, "JOI", joi_cmd);
 	msn_table_add_cmd(cbs_table, NULL, "BYE", bye_cmd);
 	msn_table_add_cmd(cbs_table, NULL, "OUT", out_cmd);
--- a/src/protocols/msn/user.c	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/user.c	Sun Aug 13 16:01:52 2006 +0000
@@ -142,8 +142,10 @@
 {
 	g_return_if_fail(user != NULL);
 
-	g_free(user->store_name);
-	user->store_name = g_strdup(name);
+	if (name != NULL){
+		g_free(user->store_name);
+		user->store_name = g_strdup(name);
+	}
 }
 
 void
--- a/src/protocols/msn/userlist.c	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/userlist.c	Sun Aug 13 16:01:52 2006 +0000
@@ -448,6 +448,19 @@
 	g_free(userlist);
 }
 
+MsnUser *
+msn_userlist_find_add_user(MsnUserList *userlist,const char *passport,const char *userName)
+{
+	MsnUser *user;
+
+	user = msn_userlist_find_user(userlist, passport);
+	if (user == NULL){
+		user = msn_user_new(userlist, passport, userName);
+		msn_userlist_add_user(userlist, user);
+	}
+	return user;
+}
+
 void
 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user)
 {
--- a/src/protocols/msn/userlist.h	Sun Aug 13 06:09:48 2006 +0000
+++ b/src/protocols/msn/userlist.h	Sun Aug 13 16:01:52 2006 +0000
@@ -75,10 +75,14 @@
 
 MsnUserList *msn_userlist_new(MsnSession *session);
 void msn_userlist_destroy(MsnUserList *userlist);
+
 void msn_userlist_add_user(MsnUserList *userlist, MsnUser *user);
 void msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user);
 MsnUser *msn_userlist_find_user(MsnUserList *userlist,
-								const char *passport);
+				const char *passport);
+MsnUser *msn_userlist_find_add_user(MsnUserList *userlist,
+				const char *passport,const char *userName);
+
 void msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group);
 void msn_userlist_remove_group(MsnUserList *userlist, MsnGroup *group);
 MsnGroup *msn_userlist_find_group_with_id(MsnUserList *userlist, const char *id);