Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/buddy_memo.c @ 25148:59ed7712be5e
2009.02.21 - flos <lonicerae(at)gmail.com>
* Rewrite whole buddy memo part
* Remove 'qq_to_utf8_len' and 'utf8_to_qq_len' functions in char_conv.c
* Update ChangeLog, AUTHORS
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Fri, 20 Feb 2009 18:00:32 +0000 |
parents | 8bc9f89f305e |
children | 7da3cf2530b7 |
comparison
equal
deleted
inserted
replaced
25147:8bc9f89f305e | 25148:59ed7712be5e |
---|---|
1 | |
2 #include "buddy_memo.h" | |
3 #include "internal.h" | 1 #include "internal.h" |
4 #include "debug.h" | 2 #include "debug.h" |
5 #include "notify.h" | 3 #include "notify.h" |
6 #include "request.h" | 4 #include "request.h" |
7 | 5 |
6 #include "buddy_memo.h" | |
8 #include "utils.h" | 7 #include "utils.h" |
9 #include "packet_parse.h" | 8 #include "packet_parse.h" |
10 #include "buddy_list.h" | 9 #include "buddy_list.h" |
11 #include "buddy_info.h" | 10 #include "buddy_info.h" |
12 #include "char_conv.h" | 11 #include "char_conv.h" |
13 #include "im.h" | 12 #include "im.h" |
14 #include "qq_define.h" | 13 #include "qq_define.h" |
15 #include "qq_base.h" | 14 #include "qq_base.h" |
16 #include "qq_network.h" | 15 #include "qq_network.h" |
17 #include "../../blist.h" | 16 #include "qq.h" |
18 | 17 |
19 | 18 |
20 #include<string.h> | 19 #include <string.h> |
21 #include<stdlib.h> | |
22 #include<stdio.h> | |
23 | |
24 #include <stdlib.h> | 20 #include <stdlib.h> |
25 #include <stdio.h> | 21 #include <stdio.h> |
26 static const gchar* buddy_memo_txt[] = { | 22 |
27 "Name", | 23 #include <stdlib.h> |
28 "Mobile", | 24 #include <stdio.h> |
29 "Telephone", | 25 |
30 "Address", | 26 /* memo index */ |
31 "Email", | 27 enum { |
32 "ZipCode", | 28 QQ_MEMO_ALIAS = 0, |
33 "Note" | 29 QQ_MEMO_MOBILD, |
34 };/* 备注信息的名称 */ | 30 QQ_MEMO_TELEPHONE, |
35 | 31 QQ_MEMO_ADDRESS, |
36 | 32 QQ_MEMO_EMAIL, |
37 /** | 33 QQ_MEMO_ZIPCODE, |
38 * 打印出好友备注信息 | 34 QQ_MEMO_NOTE, |
39 * | 35 QQ_MEMO_SIZE |
40 * @param memo | 36 }; |
41 */ | 37 |
42 static void buddy_memo_debug( gchar* memo[] ); | 38 /* memo id */ |
43 | 39 static const gchar *memo_id[] = { |
44 /** | 40 N_("mm_alias"), |
45 * 好友备注对话框中上传按钮的响应函数 | 41 N_("mm_mobile"), |
46 * | 42 N_("mm_telephone"), |
47 * @param info_request | 43 N_("mm_address"), |
48 * @param fields | 44 N_("mm_email"), |
49 */ | 45 N_("mm_zipcode"), |
50 static void buddy_memo_on_upload(void *info_request, PurpleRequestFields *fields); | 46 N_("mm_note") |
51 | 47 }; |
52 | 48 |
53 static gchar** buddy_memo_init_data( ); | 49 /* memo text */ |
54 | 50 static const gchar *memo_txt[] = { |
55 | 51 N_("Alias"), |
56 | 52 N_("Mobile"), |
57 /** | 53 N_("Telephone"), |
58 * 弹出窗口显示好友备注信息 | 54 N_("Address"), |
59 * | 55 N_("Email"), |
60 * @param node | 56 N_("ZipCode"), |
61 * @param buddy_data | 57 N_("Note") |
62 */ | 58 }; |
63 static void qq_show_buddy_memo( void* node, void* buddy_data ); | 59 |
64 | 60 typedef struct _modify_memo_request { |
65 | 61 PurpleConnection *gc; |
66 | 62 guint32 bd_uid; |
67 | 63 gchar **segments; |
68 | 64 } modify_memo_request; |
69 /** | 65 |
70 * 向服务器发送更新好友信息请求 | 66 |
71 * | 67 static void memo_debug(gchar **segments) |
72 * @param gc | 68 { |
73 * @param buddy_data | 69 gint index; |
74 */ | 70 g_return_if_fail(NULL != segments); |
75 static void qq_request_buddy_memo_upload( PurpleBuddy * buddy ); | 71 for (index = 0; index < QQ_MEMO_SIZE; index++) { |
76 | 72 purple_debug_info("QQ","memo[%i]=%s\n", index, segments[index]); |
77 | 73 } |
78 | 74 } |
79 /*********************************************************************************************/ | 75 |
80 | 76 static void memo_free(gchar **segments) |
81 | 77 { |
82 | 78 gint index; |
83 | 79 g_return_if_fail(NULL != segments); |
84 | 80 for (index = 0; index < QQ_MEMO_SIZE; index++) { |
85 void buddy_memo_on_upload(void *bd, PurpleRequestFields *fields) | 81 g_free(segments[index]); |
86 { | 82 } |
87 int index; | 83 purple_debug_info("QQ", "memo freed\n"); |
88 PurpleBuddy *buddy; | 84 } |
89 qq_buddy_data* buddy_data; | 85 |
90 int memoChanged; | 86 static void update_buddy_memo(PurpleConnection *gc, guint32 bd_uid, gchar *alias) |
91 const char *utf8_str; | 87 { |
92 buddy = ( PurpleBuddy* )bd; | 88 PurpleAccount *account; |
93 buddy_data = ( qq_buddy_data* )( buddy->proto_data ); | |
94 | |
95 | |
96 purple_debug_info("QQ", "update memo\n"); | |
97 memoChanged = 0; | |
98 for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){ | |
99 utf8_str = purple_request_fields_get_string(fields, buddy_memo_txt[index]); | |
100 if( utf8_str == NULL ){ | |
101 if( buddy_data->memo[index] != NULL ){ | |
102 g_free( buddy_data->memo[index] ); | |
103 memoChanged = 1; | |
104 } | |
105 buddy_data->memo[index] = g_new0( gchar,1 ); | |
106 } | |
107 else if( buddy_data->memo[index] == NULL || | |
108 strcmp( utf8_str, buddy_data->memo[index] ) != 0 ) | |
109 { | |
110 if( buddy_data->memo[index] != NULL ) | |
111 g_free( buddy_data->memo[index] ); | |
112 buddy_data->memo[index] = g_new( gchar,strlen(utf8_str)+2 ); | |
113 strcpy( buddy_data->memo[index], utf8_str ); | |
114 memoChanged = 1; | |
115 purple_debug_info( "QQ","%s=%s\n",buddy_memo_txt[index],utf8_str ); | |
116 } | |
117 | |
118 } | |
119 if( memoChanged == 1 ){ | |
120 qq_request_buddy_memo_upload( buddy ); | |
121 purple_blist_alias_buddy( buddy,buddy_data->memo[QQ_BUDDY_MEMO_NAME] ); | |
122 } | |
123 return; | |
124 } | |
125 | |
126 void qq_request_buddy_memo_upload( PurpleBuddy * buddy ) | |
127 { | |
128 PurpleConnection* gc; | |
129 qq_buddy_data* buddy_data; | |
130 guint8* rawData; | |
131 gint bytes; | |
132 int rawDataSize; | |
133 int index; | |
134 int memoItemSize[QQ_BUDDY_MEMO_SIZE]; | |
135 gchar* qqCharSetTxt[QQ_BUDDY_MEMO_SIZE]; | |
136 | |
137 gc = buddy->account->gc; | |
138 buddy_data = ( qq_buddy_data* )buddy->proto_data; | |
139 purple_debug_info( "QQ","call qq_request_buddy_memo_download_upload\n" ); | |
140 rawDataSize = 7; | |
141 for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){ | |
142 qqCharSetTxt[index] = utf8_to_qq( buddy_data->memo[index], QQ_CHARSET_DEFAULT ); | |
143 memoItemSize[index] = strlen( qqCharSetTxt[index] ); | |
144 rawDataSize += memoItemSize[index]+1; | |
145 } | |
146 rawData = g_new0( guint8,rawDataSize ); | |
147 bytes = 0; | |
148 bytes += qq_put8( rawData+bytes,QQ_BUDDY_MEMO_UPLOAD ); | |
149 bytes += qq_put8( rawData+bytes,0 ); | |
150 bytes += qq_put32( rawData+bytes, buddy_data->uid ); | |
151 bytes += qq_put8( rawData+bytes,0 ); | |
152 for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){ | |
153 bytes += qq_put8( rawData+bytes,0xff&memoItemSize[index] ); //TODO: 0xff? | |
154 bytes += qq_putdata( rawData+bytes, (const guint8 *)qqCharSetTxt[index], memoItemSize[index] ); | |
155 } | |
156 | |
157 qq_send_cmd( gc, QQ_CMD_BUDDY_MEMO, rawData, rawDataSize ); | |
158 for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){ | |
159 g_free( qqCharSetTxt[index] ); | |
160 } | |
161 } | |
162 | |
163 | |
164 | |
165 void qq_request_buddy_memo_download(PurpleConnection *gc, guint32 uid) | |
166 { | |
167 guint8 raw_data[16] = {0}; | |
168 //unsigned int tmp; | |
169 gint bytes; | |
170 | |
171 purple_debug_info("QQ", "Call qq_request_buddy_memo_download! qq number =%u\n", uid); | |
172 g_return_if_fail(uid != 0); | |
173 bytes = 0; | |
174 bytes += qq_put8( raw_data+bytes, QQ_BUDDY_MEMO_GET ); | |
175 bytes += qq_put32( raw_data+bytes, uid ); | |
176 | |
177 qq_send_cmd(gc, QQ_CMD_BUDDY_MEMO, (guint8*)raw_data, bytes); | |
178 } | |
179 | |
180 | |
181 void qq_process_get_buddy_memo( PurpleConnection *gc, guint8* data, gint len ) | |
182 { | |
183 qq_data *qd; | |
184 PurpleBuddy *buddy; | 89 PurpleBuddy *buddy; |
185 gchar *who; | 90 gchar *who; |
186 qq_buddy_data* bd; | 91 g_return_if_fail(NULL != gc && NULL != alias); |
92 | |
93 account = (PurpleAccount *)gc->account; | |
94 g_return_if_fail(NULL != account); | |
95 | |
96 who = uid_to_purple_name(bd_uid); | |
97 buddy = purple_find_buddy(account, who); | |
98 if (buddy == NULL || buddy->proto_data == NULL) { | |
99 g_free(who); | |
100 purple_debug_info("QQ", "Error Can not find %d!\n", bd_uid); | |
101 return; | |
102 } | |
103 purple_blist_alias_buddy(buddy, (const char*)alias); | |
104 } | |
105 | |
106 static void request_change_memo(PurpleConnection *gc, guint32 bd_uid, gchar **segments) | |
107 { | |
187 gint bytes; | 108 gint bytes; |
188 guint8 lenth; | 109 /* Attention, length of each segment must be guint8(0~255), |
189 guint32 qq_number; | 110 * so length of memo string is limited. |
190 guint8 receive_cmd; | 111 * convert it to guint8 first before put data */ |
191 guint8 receive_data; | 112 guint seg_len; |
192 int k; | 113 gint index; |
114 guint8 raw_data[MAX_PACKET_SIZE - 16] = {0}; | |
115 | |
116 purple_debug_info( "QQ", "request_change_memo\n" ); | |
117 g_return_if_fail(NULL != gc && NULL != segments); | |
193 | 118 |
194 bytes = 0; | 119 bytes = 0; |
195 bytes += qq_get8( &receive_cmd, data+bytes ); | 120 bytes += qq_put8(raw_data+bytes, QQ_BUDDY_MEMO_MODIFY); |
196 switch( receive_cmd ){ | 121 bytes += qq_put8(raw_data+bytes, 0x00); |
197 case QQ_BUDDY_MEMO_UPLOAD : | 122 bytes += qq_put32(raw_data+bytes, (guint32)bd_uid); |
198 case QQ_BUDDY_MEMO_REMOVE : | 123 bytes += qq_put8(raw_data+bytes, 0x00); |
199 bytes += qq_get8( &receive_data, data+bytes ); | 124 for (index = 0; index < QQ_MEMO_SIZE; index++) { |
200 if( receive_data == QQ_BUDDY_MEMO_REQUEST_SUCCESS ){//显示服务器接受请求对话框 | 125 seg_len = strlen(segments[index]); |
201 purple_debug_info( "QQ","服务器接受了请求\n" ); | 126 seg_len = seg_len & 0xff; |
202 purple_notify_message( gc, | 127 bytes += qq_put8(raw_data+bytes, (guint8)seg_len); |
203 PURPLE_NOTIFY_MSG_INFO, | 128 bytes += qq_putdata(raw_data+bytes, (const guint8 *)segments[index], (guint8)seg_len); |
204 _( "Your request was accepted" ), | 129 } |
205 _( "Your request was accepted" ), | 130 |
206 _( "Your request was accepted" ), | 131 /* debug */ |
207 NULL, | 132 /* |
208 NULL); | 133 qq_show_packet("MEMO MODIFY", raw_data, bytes); |
209 } | 134 */ |
210 else{ | 135 |
211 purple_debug_info( "QQ","服务器拒绝了请求\n" ); | 136 qq_send_cmd(gc, QQ_CMD_BUDDY_MEMO, raw_data, bytes); |
212 purple_notify_message( gc, | 137 } |
213 PURPLE_NOTIFY_MSG_INFO, | 138 |
214 _( "Your request was rejected" ), | 139 static void memo_modify_cancle_cb(modify_memo_request *memo_request, PurpleRequestFields *fields) |
215 _( "Your request was rejected" ), | 140 { |
216 _( "Your request was rejected" ), | 141 memo_free(memo_request->segments); |
217 NULL, | 142 g_free(memo_request); |
218 NULL); | 143 } |
219 } | 144 |
220 break; | 145 /* prepare segments to be sent, string all convert to qq charset */ |
221 case QQ_BUDDY_MEMO_GET: | 146 static void memo_modify_ok_cb(modify_memo_request *memo_request, PurpleRequestFields *fields) |
222 qd = (qq_data *) gc->proto_data; | 147 { |
223 bytes += qq_get32( &qq_number, data+bytes ); | 148 PurpleConnection *gc; |
224 bytes ++;//qq号后面有一个字节不知道什么作用 | 149 guint32 bd_uid; |
225 who = uid_to_purple_name( qq_number ); | 150 gchar **segments; |
226 buddy = purple_find_buddy( gc->account, who ); | 151 const gchar *utf8_str; |
227 if (buddy == NULL || buddy->proto_data == NULL) { | 152 gchar *value = NULL; |
228 g_free(who); | 153 gint index; |
229 purple_debug_info("QQ", "Error Can not find %d!\n", qq_number); | 154 |
230 return; | 155 g_return_if_fail(NULL != memo_request); |
231 } | 156 gc = (PurpleConnection *)memo_request->gc; |
232 bd = (qq_buddy_data *)buddy->proto_data; | 157 segments = (gchar **)memo_request->segments; |
233 | 158 g_return_if_fail(NULL != gc && NULL != segments); |
234 if( bd->memo == NULL ){ | 159 bd_uid = (guint32)memo_request->bd_uid; |
235 bd->memo = g_new0( gchar*,QQ_BUDDY_MEMO_SIZE ); | 160 |
236 } | 161 |
237 for( k=0; k<QQ_BUDDY_MEMO_SIZE; k++ ){ | 162 for (index = 0; index < QQ_MEMO_SIZE; index++) { |
238 bytes += qq_get8( &lenth, data+bytes ); | 163 utf8_str = purple_request_fields_get_string(fields, memo_id[index]); |
239 if( bd->memo[k] != NULL ) | 164 /* update alias */ |
240 g_free( bd->memo[k] ); | 165 if (QQ_MEMO_ALIAS == index) { |
241 bd->memo[k] = qq_to_utf8_len( (gchar*)(data+bytes), lenth, QQ_CHARSET_DEFAULT ); | 166 update_buddy_memo(gc, bd_uid, segments[QQ_MEMO_ALIAS]); |
242 bytes += lenth; | 167 } |
243 } | 168 if (NULL == utf8_str) { |
244 buddy_memo_debug( bd->memo ); | 169 value = g_strdup(""); |
245 purple_blist_alias_buddy( buddy, | 170 } |
246 (const char*)bd->memo[QQ_BUDDY_MEMO_NAME] );//改名 | 171 else { |
247 break; | 172 value = utf8_to_qq(utf8_str, QQ_CHARSET_DEFAULT); |
248 default: | 173 /* Warnning: value will be string "(NULL)" instead of NULL */ |
249 purple_debug_info( "QQ","error: unknown memo cmd \n" ); | 174 if (!g_strcmp0("(NULL)", value)) { |
250 break; | 175 value = g_strdup(""); |
251 } | 176 } |
252 | 177 } |
253 | 178 g_free(segments[index]); |
254 } | 179 segments[index] = value; |
255 | 180 } |
256 void buddy_memo_debug( gchar* memo[] ) | 181 |
257 { | 182 memo_debug(segments); |
258 gint k=0; | 183 /* send segments */ |
259 for( k=0; k<QQ_BUDDY_MEMO_SIZE; k++ ){ | 184 request_change_memo(gc, bd_uid, segments); |
260 purple_debug_info( "QQ","备注: %s=%s\n",buddy_memo_txt[k],memo[k] ); | 185 |
261 } | 186 /* free segments */ |
262 } | 187 memo_free(segments); |
263 | 188 g_free(memo_request); |
264 void qq_show_buddy_memo( void* node, void* buddy_data ) | 189 } |
265 { | 190 |
266 qq_buddy_data* data; | 191 /* memo modify dialogue */ |
192 static void memo_modify_dialogue(PurpleConnection *gc, guint32 bd_uid, gchar **segments, gint iclass) | |
193 { | |
194 modify_memo_request *memo_request; | |
267 PurpleRequestField *field; | 195 PurpleRequestField *field; |
268 PurpleRequestFields *fields; | 196 PurpleRequestFields *fields; |
269 PurpleRequestFieldGroup *group; | 197 PurpleRequestFieldGroup *group; |
270 int index; | 198 int index; |
271 | 199 gchar *utf8_title; |
272 data = ( qq_buddy_data* )buddy_data; | 200 gchar *utf8_primary; |
273 | 201 |
274 fields = purple_request_fields_new(); | 202 g_return_if_fail(NULL != gc && NULL != segments); |
275 group = purple_request_field_group_new(NULL); | 203 |
276 purple_request_fields_add_group(fields, group); | 204 switch (iclass) { |
277 | 205 case QQ_BUDDY_MEMO_GET: |
278 for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){ | 206 break; |
279 if( data->memo == NULL ){ | 207 case QQ_BUDDY_MEMO_MODIFY: |
280 data->memo = buddy_memo_init_data( ); | 208 /* Keep one dialog once a time */ |
281 } | 209 purple_request_close_with_handle(gc); |
282 field = purple_request_field_string_new(buddy_memo_txt[index], | 210 /* show dialog */ |
283 buddy_memo_txt[index], | 211 fields = purple_request_fields_new(); |
284 data->memo[index], | 212 group = purple_request_field_group_new(NULL); |
285 FALSE); | 213 purple_request_fields_add_group(fields, group); |
286 purple_request_field_group_add_field(group, field); | 214 |
287 } | 215 for(index = 0; index < QQ_MEMO_SIZE; index++) { |
288 | 216 /* |
289 purple_request_fields(node, | 217 purple_debug_info("QQ", "id:%s txt:%s segment:%s\n", |
290 _( "Buddy_memo" ), | 218 memo_id[index], memo_txt[index], segments[index]); |
291 "", | 219 */ |
292 NULL, | 220 |
293 fields, | 221 field = purple_request_field_string_new(memo_id[index], memo_txt[index], |
294 _("_Upload"), G_CALLBACK(buddy_memo_on_upload), | 222 segments[index], FALSE); |
295 _("_Cancel"), NULL, | 223 purple_request_field_group_add_field(group, field); |
296 ((PurpleBuddy *)node)->account, ((PurpleBuddy *)node)->name, NULL, | 224 } |
297 node); | 225 |
298 } | 226 /* for upload cb */ |
299 | 227 memo_request = g_new0(modify_memo_request, 1); |
300 | 228 memo_request->gc = gc; |
301 | 229 memo_request->bd_uid = bd_uid; |
302 void qq_on_show_memo(PurpleBlistNode *node, gpointer data) | 230 memo_request->segments = segments; |
303 { | 231 /* callback */ |
304 | 232 utf8_title = g_strdup(_("Buddy Memo")); |
305 PurpleBuddy *buddy; | 233 utf8_primary = g_strdup(_("Change his/her memo as you like")); |
306 | 234 |
307 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); | 235 purple_request_fields(gc, utf8_title, utf8_primary, NULL, |
308 | 236 fields, |
309 buddy = (PurpleBuddy *) node; | 237 _("_Modify"), G_CALLBACK(memo_modify_ok_cb), |
310 | 238 _("_Cancel"), G_CALLBACK(memo_modify_cancle_cb), |
311 qq_show_buddy_memo( node, buddy->proto_data ); | 239 purple_connection_get_account(gc), NULL, NULL, |
312 | 240 memo_request); |
313 | 241 |
314 purple_debug_info( "QQ","show memo" ); | 242 g_free(utf8_title); |
315 } | 243 g_free(utf8_primary); |
316 | 244 break; |
317 | 245 default: |
318 gchar** buddy_memo_init_data( ) | 246 purple_debug_info("QQ", "unknown memo action\n"); |
319 { | 247 break; |
320 gchar** pmemo; | 248 } |
321 int index; | 249 } |
322 pmemo = g_new0( gchar*,QQ_BUDDY_MEMO_SIZE ); | 250 |
323 for( index=0; index<QQ_BUDDY_MEMO_SIZE; index++ ){ | 251 /* process reply to get_memo packet */ |
324 pmemo[index] = g_new0( gchar,1 ); | 252 void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len, guint32 action) |
325 } | 253 { |
326 return pmemo; | 254 gchar **segments; |
327 } | 255 gint bytes; |
256 gint index; | |
257 guint8 rcv_cmd; | |
258 guint32 rcv_uid; | |
259 guint8 unk1_8; | |
260 guint8 is_success; | |
261 | |
262 g_return_if_fail(data != NULL && data_len != 0); | |
263 /* | |
264 qq_show_packet("MEMO REACH", data, data_len); | |
265 */ | |
266 purple_debug_info("QQ", "action:0x%x\n", action); | |
267 | |
268 bytes = 0; | |
269 | |
270 /* TX looks a bit clever than before... :) */ | |
271 bytes += qq_get8(&rcv_cmd, data+bytes); | |
272 purple_debug_info("QQ", "rcv_cmd:0x%x\n", rcv_cmd); | |
273 /* it's possible that no buddy uid and no memo!!! */ | |
274 if (1 == data_len) { | |
275 purple_debug_info("QQ", "memo packet contains no buddy uid and memo...\n"); | |
276 return; | |
277 } | |
278 | |
279 switch (rcv_cmd) { | |
280 case QQ_BUDDY_MEMO_MODIFY: | |
281 case QQ_BUDDY_MEMO_REMOVE: | |
282 bytes += qq_get8(&is_success, data+bytes); | |
283 if (QQ_BUDDY_MEMO_REQUEST_SUCCESS == is_success) { | |
284 purple_notify_message(gc, PURPLE_NOTIFY_MSG_INFO, | |
285 _("Memo Modify"), _("Your request was accepted."), NULL, | |
286 NULL, NULL); | |
287 purple_debug_info("QQ", "memo change succeessfully!"); | |
288 } | |
289 else { | |
290 purple_notify_message(gc, PURPLE_NOTIFY_MSG_INFO, | |
291 _("Memo Modify"), _("Your request was rejected."), NULL, | |
292 NULL, NULL); | |
293 purple_debug_info("QQ", "memo change failed"); | |
294 } | |
295 break; | |
296 case QQ_BUDDY_MEMO_GET: | |
297 bytes += qq_get32(&rcv_uid, data+bytes); | |
298 purple_debug_info("QQ", "rcv_uid:%u\n", rcv_uid); | |
299 bytes += qq_get8(&unk1_8, data+bytes); | |
300 purple_debug_info("QQ", "unk1_8:0x%x\n", unk1_8); | |
301 segments = g_new0(gchar*, QQ_MEMO_SIZE); | |
302 for (index = 0; index < QQ_MEMO_SIZE; index++) { | |
303 /* get utf8 string */ | |
304 bytes += qq_get_vstr(&segments[index], QQ_CHARSET_DEFAULT, data+bytes); | |
305 /* | |
306 purple_debug_info("QQ", "bytes:%d, seg:%s\n", bytes, segments[index]); | |
307 */ | |
308 } | |
309 | |
310 /* common action, update buddy memo */ | |
311 update_buddy_memo(gc, rcv_uid, segments[QQ_MEMO_ALIAS]); | |
312 | |
313 /* memo is thing that we regard our buddy as, so we need one more buddy_uid */ | |
314 memo_modify_dialogue(gc, rcv_uid, segments, action); | |
315 | |
316 break; | |
317 default: | |
318 purple_debug_info("QQ", "received an UNKNOWN memo cmd!!!"); | |
319 break; | |
320 } | |
321 } | |
322 | |
323 /* request buddy memo */ | |
324 void qq_request_buddy_memo(PurpleConnection *gc, guint32 bd_uid, gint update_class, int action) | |
325 { | |
326 guint8 raw_data[16] = {0}; | |
327 gint bytes; | |
328 | |
329 purple_debug_info("QQ", "qq_request_buddy_memo, buddy uid=%u\n", bd_uid); | |
330 g_return_if_fail(NULL != gc); | |
331 /* '0' is ok | |
332 g_return_if_fail(uid != 0); | |
333 */ | |
334 bytes = 0; | |
335 bytes += qq_put8(raw_data+bytes, QQ_BUDDY_MEMO_GET); | |
336 bytes += qq_put32(raw_data+bytes, bd_uid); | |
337 /* | |
338 qq_show_packet("MEMO REQUEST", raw_data, bytes); | |
339 */ | |
340 | |
341 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_MEMO, (guint8*)raw_data, bytes, update_class, action); | |
342 } | |
343 | |
344 void qq_create_buddy_memo(PurpleConnection *gc, guint32 bd_uid, int action) | |
345 { | |
346 gchar **segments; | |
347 gint index; | |
348 g_return_if_fail(NULL != gc); | |
349 | |
350 segments = g_new0(gchar*, QQ_MEMO_SIZE); | |
351 for (index = 0; index < QQ_MEMO_SIZE; index++) { | |
352 segments[index] = g_strdup("");; | |
353 } | |
354 memo_modify_dialogue(gc, bd_uid, segments, action); | |
355 } | |
356 |