pidgin.openq: 03a157b9: 2009.02.09 - Chengming Wang <tiger200753...

csyfek at gmail.com csyfek at gmail.com
Mon Feb 9 10:50:29 EST 2009


-----------------------------------------------------------------
Revision: 03a157b94d471daba5c03a25ea316392a4b2001b
Ancestor: 0e02d55d1b8b8badfa78439d77bda433a7c66a73
Author: csyfek at gmail.com
Date: 2009-02-09T15:49:14
Branch: im.pidgin.pidgin.openq
URL: http://d.pidgin.im/viewmtn/revision/info/03a157b94d471daba5c03a25ea316392a4b2001b

Added files:
        libpurple/protocols/qq/buddy_memo.c
        libpurple/protocols/qq/buddy_memo.h
Modified files:
        libpurple/protocols/qq/AUTHORS
        libpurple/protocols/qq/ChangeLog
        libpurple/protocols/qq/Makefile.am
        libpurple/protocols/qq/buddy_list.c
        libpurple/protocols/qq/char_conv.c
        libpurple/protocols/qq/char_conv.h
        libpurple/protocols/qq/qq.c libpurple/protocols/qq/qq.h
        libpurple/protocols/qq/qq_define.c
        libpurple/protocols/qq/qq_define.h
        libpurple/protocols/qq/qq_process.c

ChangeLog: 

2009.02.09 - Chengming Wang <tiger2007532246(at)gmail.com>
	* Added buddy 'get memo', 'remove memo', 'upload memo' functions

-------------- next part --------------
============================================================
--- libpurple/protocols/qq/buddy_memo.c	e05317c103cea4d29edb5d6e4ef0fc1a2a63fa96
+++ libpurple/protocols/qq/buddy_memo.c	e05317c103cea4d29edb5d6e4ef0fc1a2a63fa96
@@ -0,0 +1,317 @@
+
+#include "buddy_memo.h"
+#include "internal.h"
+#include "debug.h"
+#include "notify.h"
+#include "request.h"
+
+#include "utils.h"
+#include "packet_parse.h"
+#include "buddy_list.h"
+#include "buddy_info.h"
+#include "char_conv.h"
+#include "im.h"
+#include "qq_define.h"
+#include "qq_base.h"
+#include "qq_network.h"
+#include "../../blist.h"
+
+
+#include<string.h>
+#include<stdlib.h>
+#include<stdio.h>
+
+
+static const gchar* buddy_memo_txt[] = {
+	"Name",
+	"Mobile",
+	"Telephone",
+	"Address",
+	"Email",
+	"ZipCode",
+	"Note"
+};/* ??????? */
+
+
+/** 
+ * ?????????
+ * 
+ * @param memo 
+ */
+static void buddy_memo_debug( gchar* memo[] );
+
+/** 
+ * ?????????????????
+ * 
+ * @param info_request 
+ * @param fields 
+ */
+static void buddy_memo_on_upload(void *info_request, PurpleRequestFields *fields);
+
+
+static gchar** buddy_memo_init_data(  );
+
+
+
+/** 
+ * ????????????
+ * 
+ * @param node 
+ * @param buddy_data 
+ */
+static void qq_show_buddy_memo( void* node, void* buddy_data );
+
+
+
+
+
+/** 
+ * ??????????????
+ * 
+ * @param gc 
+ * @param buddy_data 
+ */
+static void qq_request_buddy_memo_upload( PurpleBuddy * buddy );
+
+
+
+/*********************************************************************************************/
+
+
+
+
+
+void buddy_memo_on_upload(void *bd, PurpleRequestFields *fields)
+{
+	int index;
+	PurpleBuddy *buddy;
+	qq_buddy_data* buddy_data;
+	int memoChanged;
+	const char *utf8_str;
+	buddy = ( PurpleBuddy* )bd;
+	buddy_data = ( qq_buddy_data* )( buddy->proto_data );
+	
+	
+	purple_debug_info("QQ", "update memo\n");
+	memoChanged = 0;
+	for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){
+		utf8_str = purple_request_fields_get_string(fields, buddy_memo_txt[index]);
+		if( utf8_str == NULL ){
+			if( buddy_data->memo[index] != NULL ){
+				g_free( buddy_data->memo[index] );
+				memoChanged = 1;
+			}
+			buddy_data->memo[index] = g_new0( gchar,1 );
+		}
+		else if( buddy_data->memo[index] == NULL ||
+			strcmp( utf8_str, buddy_data->memo[index] ) != 0 )
+		{
+			if( buddy_data->memo[index] != NULL )
+				g_free( buddy_data->memo[index] );
+			buddy_data->memo[index] = g_new( gchar,strlen(utf8_str)+2 );
+			strcpy( buddy_data->memo[index], utf8_str );
+			memoChanged = 1;
+			purple_debug_info( "QQ","%s=%s\n",buddy_memo_txt[index],utf8_str );
+		}
+
+	}
+	if( memoChanged == 1 ){
+		qq_request_buddy_memo_upload( buddy );
+		purple_blist_alias_buddy( buddy,buddy_data->memo[QQ_BUDDY_MEMO_NAME] );
+	}
+	return;
+}
+
+void qq_request_buddy_memo_upload( PurpleBuddy * buddy )
+{
+	PurpleConnection* gc;
+	qq_buddy_data* buddy_data;
+	guint8* rawData;
+	guint8* pos;
+	int rawDataSize;
+	int index;
+	int memoItemSize[QQ_BUDDY_MEMO_SIZE];
+	gchar* qqCharSetTxt[QQ_BUDDY_MEMO_SIZE];
+
+	gc = buddy->account->gc;
+	buddy_data = ( qq_buddy_data* )buddy->proto_data;
+	purple_debug_info( "QQ","call qq_request_buddy_memo_download_upload\n" );
+	rawDataSize = 7;
+	for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){
+		qqCharSetTxt[index] = utf8_to_qq( buddy_data->memo[index], QQ_CHARSET_DEFAULT );
+		memoItemSize[index] = strlen( qqCharSetTxt[index] );
+		rawDataSize += memoItemSize[index]+1;
+	}
+	rawData = g_new0( guint8,rawDataSize );
+	pos = rawData;
+	(*pos) = QQ_BUDDY_MEMO_UPLOAD;
+	pos += 2;
+	(*(guint32*)pos) = htonl( buddy_data->uid );
+	pos += 5;
+	for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){
+		(*pos) = 0xff&memoItemSize[index];
+		pos++;
+		memcpy( pos, qqCharSetTxt[index], memoItemSize[index] );
+		pos += memoItemSize[index];
+	}
+
+	qq_send_cmd( gc, QQ_CMD_BUDDY_MEMO, rawData, rawDataSize );
+	for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){
+		g_free( qqCharSetTxt[index] );
+	}
+}
+
+
+
+void qq_request_buddy_memo_download(PurpleConnection *gc, guint32 uid)
+{
+	gchar raw_data[16] = {0};
+	unsigned int tmp;
+	purple_debug_info("QQ", "Call qq_request_buddy_memo_download! qq number =%u\n", uid);
+	g_return_if_fail(uid != 0);
+	raw_data[0] = QQ_BUDDY_MEMO_GET;
+
+	tmp = htonl((unsigned int)uid);
+	memcpy(raw_data+1, &tmp, 4);
+	
+	qq_send_cmd(gc, QQ_CMD_BUDDY_MEMO, (guint8*)raw_data, 5);
+}
+
+
+void qq_process_get_buddy_memo( PurpleConnection *gc, guint8* data, gint len )
+{
+	qq_data *qd;
+	//_buddy_memo memo;
+	PurpleBuddy *buddy;
+	gchar *who;
+	qq_buddy_data* bd;
+	guint8* pos;
+	gint lenth;
+	guint32 qq_number;
+	int k;
+
+	pos = data;
+	switch( *pos ){
+	    case QQ_BUDDY_MEMO_UPLOAD :
+    	case QQ_BUDDY_MEMO_REMOVE :
+			if( data[1] == QQ_BUDDY_MEMO_REQUEST_SUCCESS ){//????????????
+				//TODO:
+				purple_debug_info( "QQ","????????\n" );
+				purple_notify_message( gc,
+									   PURPLE_NOTIFY_MSG_INFO,
+									   _( "Your request was accepted" ),
+									   _( "Your request was accepted" ),
+									   _( "Your request was accepted" ),
+									   NULL,
+									   NULL);
+			}
+			break;
+	    case QQ_BUDDY_MEMO_GET:
+			qd = (qq_data *) gc->proto_data;
+			pos++;
+			qq_number = ntohl( *(uint32_t*)pos ); 
+			pos += 5;//qq???????????????
+			who = uid_to_purple_name( qq_number );
+			buddy = purple_find_buddy( gc->account, who );
+			if (buddy == NULL || buddy->proto_data == NULL) {
+				g_free(who);
+				purple_debug_info("QQ", "Error Can not find %d!\n", qq_number);
+				return;
+			}
+			bd = (qq_buddy_data *)buddy->proto_data;
+			
+			if( bd->memo == NULL ){
+				bd->memo = g_new0( gchar*,QQ_BUDDY_MEMO_SIZE );
+			}
+			for( k=0; k<QQ_BUDDY_MEMO_SIZE; k++ ){
+				lenth = pos[0];
+				pos++;
+				if( bd->memo[k] != NULL )
+					g_free( bd->memo[k] );
+				bd->memo[k] = qq_to_utf8_len( (gchar*)pos, lenth, QQ_CHARSET_DEFAULT );
+				pos += lenth;
+			}
+			buddy_memo_debug( bd->memo );
+			purple_blist_alias_buddy( buddy,
+									  (const char*)bd->memo[QQ_BUDDY_MEMO_NAME] );//??
+			break;
+	default:
+			purple_debug_info( "QQ","error: unknown memo cmd\n" );
+	        break;
+	}
+	
+	
+}
+
+void buddy_memo_debug( gchar* memo[] )
+{
+	gint k=0;
+	for( k=0; k<QQ_BUDDY_MEMO_SIZE; k++ ){
+		purple_debug_info( "QQ","??: %s=%s\n",buddy_memo_txt[k],memo[k] );
+	}
+}
+
+void qq_show_buddy_memo( void* node, void* buddy_data )
+{
+	qq_buddy_data* data;
+	PurpleRequestField *field;
+	PurpleRequestFields *fields;
+	PurpleRequestFieldGroup *group;
+	int index;
+	
+	data = ( qq_buddy_data* )buddy_data;
+	
+	fields = purple_request_fields_new();
+	group = purple_request_field_group_new(NULL);
+	purple_request_fields_add_group(fields, group);
+
+	for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){
+		if( data->memo == NULL ){
+			data->memo = buddy_memo_init_data(  );
+		}
+		field = purple_request_field_string_new(buddy_memo_txt[index],
+												buddy_memo_txt[index],
+												data->memo[index],
+												FALSE);
+		purple_request_field_group_add_field(group, field);	
+	}
+	
+	purple_request_fields(node,
+						  _( "Buddy_memo" ),
+						  "",
+						  NULL,
+						  fields,
+						  _("_Upload"), G_CALLBACK(buddy_memo_on_upload),
+						  _("_Cancel"), NULL,
+						  ((PurpleBuddy *)node)->account, ((PurpleBuddy *)node)->name, NULL,
+						  node);
+}
+
+
+
+void qq_on_show_memo(PurpleBlistNode *node, gpointer data)
+{
+
+	PurpleBuddy *buddy;
+
+	g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
+
+	buddy = (PurpleBuddy *) node;
+
+	qq_show_buddy_memo( node, buddy->proto_data );
+
+	
+	purple_debug_info( "QQ","show memo" );
+}
+
+
+static gchar** buddy_memo_init_data(  )
+{
+	gchar** pmemo;
+	int index;
+	pmemo = g_new0( gchar*,QQ_BUDDY_MEMO_SIZE );
+	for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){
+		pmemo[index] = g_new0( gchar,1 );
+	}
+	return pmemo;
+}
============================================================
--- libpurple/protocols/qq/buddy_memo.h	9d632547e0fb65cd4d532a3e7af3175c2921f94a
+++ libpurple/protocols/qq/buddy_memo.h	9d632547e0fb65cd4d532a3e7af3175c2921f94a
@@ -0,0 +1,80 @@
+
+#ifndef _BUDDY_MEMO_H
+#define _BUDDY_MEMO_H 
+
+#include <glib.h>
+
+#include "connection.h"
+#include "buddy_opt.h"
+#include "qq.h"
+
+
+
+#include "internal.h"
+#include "debug.h"
+#include "notify.h"
+#include "request.h"
+#include "utils.h"
+#include "packet_parse.h"
+#include "buddy_list.h"
+#include "buddy_info.h"
+#include "char_conv.h"
+#include "im.h"
+#include "qq_define.h"
+#include "qq_base.h"
+#include "qq_network.h"
+#include "../../blist.h"
+
+
+
+
+
+enum {
+	QQ_BUDDY_MEMO_NAME = 0,
+	QQ_BUDDY_MEMO_MOBILD,
+	QQ_BUDDY_MEMO_TELEPHONE,
+	QQ_BUDDY_MEMO_ADDRESS,
+	QQ_BUDDY_MEMO_EMAIL,
+	QQ_BUDDY_MEMO_ZIPCODE,
+	QQ_BUDDY_MEMO_NOTE,
+	QQ_BUDDY_MEMO_SIZE
+};
+
+
+
+
+
+
+/** 
+ * ?????????????????
+ * 
+ * @param gc 
+ * @param uid ??qq??
+ */
+void qq_request_buddy_memo_download(PurpleConnection *gc, guint32 uid);
+
+
+
+
+
+/** 
+ * ???????????????
+ * 
+ * @param gc 
+ * @param data ??????
+ * @param len data????
+ */
+void qq_process_get_buddy_memo( PurpleConnection *gc, guint8* data, gint len );
+
+
+/** 
+ * ???????????????????????
+ * 
+ * @param node 
+ * @param data 
+ */
+void qq_on_show_memo(PurpleBlistNode *node, gpointer data);
+
+
+#endif /* _BUDDY_MEMO_H */
+
============================================================
--- libpurple/protocols/qq/AUTHORS	1c0fbf253bcc1a0adfe2c135b1b7d47d63d85b7f
+++ libpurple/protocols/qq/AUTHORS	88521b91da0757cbbbaf6a1222d2a64a28f37214
@@ -23,6 +23,8 @@ Emil Alexiev	: captcha verification on l
 Coly Li		: qun processing
 Emil Alexiev	: captcha verification on login based on LumaQQ for MAC (2007), 
 		  login, add buddy, remove buddy, message exchange and logout
+Chengming Wang 	: buddy memo
+lonicerae 	: chat room window bugfix, server list bugfix
 
 Acknowledgement
 =========
============================================================
--- libpurple/protocols/qq/ChangeLog	d5544ef4b5e6fb2fc1eade7846367b5e716d9d37
+++ libpurple/protocols/qq/ChangeLog	ef78d43e7fc75be50b081e13234b0f10c44959d4
@@ -1,3 +1,6 @@
+2009.02.09 - Chengming Wang <tiger2007532246(at)gmail.com>
+	* Added buddy 'get memo', 'remove memo', 'upload memo' functions
+
 2009.02.08 - flos <lonicerae(at)gmail.com>
 	* Fixed showing message of chat room when message comes in
 
============================================================
--- libpurple/protocols/qq/Makefile.am	020c5382862872d6ba26e640519d6ade314792c2
+++ libpurple/protocols/qq/Makefile.am	6108672b34fccc7359980028d05cbd7d4e0df3d3
@@ -6,6 +6,8 @@ QQSOURCES = \
 QQSOURCES = \
 	buddy_info.c \
 	buddy_info.h \
+	buddy_memo.c \
+	buddy_memo.h \
 	buddy_list.c \
 	buddy_list.h \
 	buddy_opt.c \
============================================================
--- libpurple/protocols/qq/buddy_list.c	b7839c214f8b686da4e75148447475890095a4d7
+++ libpurple/protocols/qq/buddy_list.c	9221a3e084ba3681864aaebf688a7754db6b5e86
@@ -31,6 +31,7 @@
 #include "utils.h"
 #include "packet_parse.h"
 #include "buddy_info.h"
+#include "buddy_memo.h"
 #include "buddy_list.h"
 #include "buddy_opt.h"
 #include "char_conv.h"
@@ -346,6 +347,7 @@ guint16 qq_process_get_buddies(guint8 *d
 		/* nickname has been copy to buddy_data do not free
 		   g_free(bd.nickname);
 		*/
+		qq_request_buddy_memo_download( gc,((qq_buddy_data*)buddy->proto_data)->uid );
 	}
 
 	if(bytes > data_len) {
============================================================
--- libpurple/protocols/qq/char_conv.c	9f3691f7dcba0166a9bd35262904439b1de7d6ec
+++ libpurple/protocols/qq/char_conv.c	9d246aa0ac3d15614125e3f8e8296613dced2147
@@ -111,3 +111,14 @@ gchar *qq_to_utf8(const gchar *str, cons
 	return do_convert(str, -1, UTF8, from_charset);
 }
 
+
+
+gchar *utf8_to_qq_len(const gchar *str, const gint len, const gchar *to_charset)
+{
+	return do_convert(str, len, to_charset, UTF8);
+}
+gchar *qq_to_utf8_len(const gchar *str, const gint len, const gchar *from_charset)
+{
+	return do_convert(str, len, UTF8, from_charset);
+}
+
============================================================
--- libpurple/protocols/qq/char_conv.h	1cf091d876bae6da8f5e12edfb399ac9093a30e3
+++ libpurple/protocols/qq/char_conv.h	de23c25ec421fefe23b65ba4eef070e413a70301
@@ -35,4 +35,7 @@ gchar *qq_to_utf8(const gchar *str, cons
 gchar *utf8_to_qq(const gchar *str, const gchar *to_charset);
 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset);
 
+gchar *utf8_to_qq_len(const gchar *str, const gint len, const gchar *to_charset);
+gchar *qq_to_utf8_len(const gchar *str, const gint len, const gchar *from_charset);
+
 #endif
============================================================
--- libpurple/protocols/qq/qq.c	d017561b119c7480a7cd814f67a9cd1f1d117eeb
+++ libpurple/protocols/qq/qq.c	d4153c674b9306aa2c12028ea76ac1c54e2232ec
@@ -36,6 +36,7 @@
 #include "util.h"
 
 #include "buddy_info.h"
+#include "buddy_memo.h"
 #include "buddy_opt.h"
 #include "buddy_list.h"
 #include "char_conv.h"
@@ -826,6 +827,11 @@ static GList *qq_buddy_menu(PurpleBuddy 
 
 	}
 
+
+	act = purple_menu_action_new(_("Buddy memo"), PURPLE_CALLBACK(qq_on_show_memo), NULL, NULL); /* add NULL by gfhuang */
+	m = g_list_append(m, act);
+
+	
 /* TODO : not working, temp commented out by gfhuang */
 #if 0
 	if (bd && is_online(bd->status)) {
============================================================
--- libpurple/protocols/qq/qq.h	17374d17b733cd1891d4ce0e69ccdf3c0e2f7999
+++ libpurple/protocols/qq/qq.h	a205915d300de6ffa69d6fe5467b3751225434eb
@@ -98,6 +98,7 @@ struct _qq_buddy_data {
 	time_t signon;
 	time_t idle;
 	time_t last_update;
+	gchar** memo;
 
 	gint8  role;		/* role in group, used only in group->members list */
 };
============================================================
--- libpurple/protocols/qq/qq_define.c	8451e83cf2edd053b15786172dec94dc626e57f1
+++ libpurple/protocols/qq/qq_define.c	39cbe85d9130d050d169912b9c7eb459c5ddac1a
@@ -189,6 +189,8 @@ const gchar *qq_get_cmd_desc(gint cmd)
 		return "CMD_BUDDY_CHECK_CODE";
 	case QQ_CMD_BUDDY_QUESTION:
 		return "CMD_BUDDY_QUESTION";
+	case QQ_CMD_BUDDY_MEMO:
+		return "CMD_BUDDY_MEMO";
 	default:
 		return "CMD_UNKNOW";
 	}
============================================================
--- libpurple/protocols/qq/qq_define.h	437a3e33ea93b8af0a9cd7252c5ef90528728ee3
+++ libpurple/protocols/qq/qq_define.h	29e7cbb150f33af91c29a533c1ce89cf38a78b8b
@@ -66,7 +66,9 @@ enum {
 	QQ_CMD_TOKEN  = 0x0062, 		/* get login token */
 	QQ_CMD_RECV_MSG_SYS = 0x0080,			/* receive a system message */
 	QQ_CMD_BUDDY_CHANGE_STATUS = 0x0081,	/* buddy change status */
-	/* for QQ2007*/
+	QQ_CMD_BUDDY_MEMO = 0x003E,    /* the message about buddy memo */
+
+    /* for QQ2007*/
 	QQ_CMD_GET_SERVER = 0x0091,					/* select login server */
 	QQ_CMD_TOKEN_EX = 0x00BA,						/* get LOGIN token */
 	QQ_CMD_CHECK_PWD = 0x00DD,				/* Password verify */
@@ -131,6 +133,16 @@ enum {
 	QQ_BUDDY_ONLINE_BUSY = 50
 };
 
+
+enum //??????         
+{   
+	QQ_BUDDY_MEMO_UPLOAD = 0x01,   // ??????
+	QQ_BUDDY_MEMO_REMOVE,          // ??????
+	QQ_BUDDY_MEMO_GET              // ??????
+};
+
+#define QQ_BUDDY_MEMO_REQUEST_SUCCESS 0x00
+
 gboolean is_online(guint8 status);
 
 #endif
============================================================
--- libpurple/protocols/qq/qq_process.c	8705ec2183ad1d7ac08cb90fe9f23216c7c05ace
+++ libpurple/protocols/qq/qq_process.c	f90385e0a6050906e0b91fdf8b79e623fb0b0318
@@ -47,6 +47,7 @@
 #include "qq_network.h"
 #include "qq_trans.h"
 #include "utils.h"
+#include "buddy_memo.h"
 
 enum {
 	QQ_ROOM_CMD_REPLY_OK = 0x00,
@@ -1142,6 +1143,10 @@ void qq_proc_client_cmds(PurpleConnectio
 		case QQ_CMD_BUDDY_CHECK_CODE:
 			qq_process_buddy_check_code(gc, data, data_len);
 			break;
+    	case QQ_CMD_BUDDY_MEMO:
+			purple_debug_info("QQ", "Receive memo from server!\n");
+			qq_process_get_buddy_memo( gc, data, data_len );
+			break;
 		default:
 			process_unknow_cmd(gc, _("Unknown CLIENT CMD"), data, data_len, cmd, seq);
 			is_unknow = TRUE;


More information about the Commits mailing list