Mercurial > pidgin
comparison libpurple/protocols/qq/buddy_list.c @ 23695:5f454b975a99
2008.08.10 - csyfek <csyfek(at)gmail.com>
* Commit to Pidgin
2008.08.06 - ccpaging <ecc_hy(at)hotmail.com>
* Rename names of variables, Group, to Room
* Functions of group_network merged into qq_network and qq_process
* Canceled managing glist of group packet, add sub_cmdd and room_id to transaction
* Fixed error of demo group:
If 'room list' and 'room infor' are not setup, response received from server will emits
'room_id = 0' packet.
2008.08.04 - ccpaging <ecc_hy(at)hotmail.com>
* Use new crypt/decrypt functions
* Rename crypt.c/h to qq_crypt.c/h
* Clean code of decrypt functions
* Fixed decryption failure
2008.08.04 - csyfek <csyfek(at)gmail.com>
* Update AUTHORS
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Sun, 10 Aug 2008 04:32:14 +0000 |
parents | 1c50f12b1c52 |
children | 967344bc404d |
comparison
equal
deleted
inserted
replaced
23690:107166bb2a64 | 23695:5f454b975a99 |
---|---|
32 #include "packet_parse.h" | 32 #include "packet_parse.h" |
33 #include "buddy_info.h" | 33 #include "buddy_info.h" |
34 #include "buddy_list.h" | 34 #include "buddy_list.h" |
35 #include "buddy_opt.h" | 35 #include "buddy_opt.h" |
36 #include "char_conv.h" | 36 #include "char_conv.h" |
37 #include "crypt.h" | |
38 #include "header_info.h" | 37 #include "header_info.h" |
39 #include "qq_base.h" | 38 #include "qq_base.h" |
40 #include "group.h" | 39 #include "group.h" |
41 #include "group_find.h" | 40 #include "group_find.h" |
42 #include "group_internal.h" | 41 #include "group_internal.h" |
101 | 100 |
102 qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_LIST, raw_data, bytes); | 101 qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_LIST, raw_data, bytes); |
103 } | 102 } |
104 | 103 |
105 /* get all list, buddies & Quns with groupsid support */ | 104 /* get all list, buddies & Quns with groupsid support */ |
106 void qq_send_packet_get_all_list_with_group(PurpleConnection *gc, guint32 position) | 105 void qq_send_packet_get_buddies_and_rooms(PurpleConnection *gc, guint32 position) |
107 { | 106 { |
108 qq_data *qd = (qq_data *) gc->proto_data; | 107 qq_data *qd = (qq_data *) gc->proto_data; |
109 guint8 raw_data[16] = {0}; | 108 guint8 raw_data[16] = {0}; |
110 gint bytes = 0; | 109 gint bytes = 0; |
111 | 110 |
115 bytes += qq_put8(raw_data + bytes, 0x02); | 114 bytes += qq_put8(raw_data + bytes, 0x02); |
116 /* unknown 00 00 00 00 */ | 115 /* unknown 00 00 00 00 */ |
117 bytes += qq_put32(raw_data + bytes, 0x00000000); | 116 bytes += qq_put32(raw_data + bytes, 0x00000000); |
118 bytes += qq_put32(raw_data + bytes, position); | 117 bytes += qq_put32(raw_data + bytes, position); |
119 | 118 |
120 qq_send_cmd(qd, QQ_CMD_GET_ALL_LIST_WITH_GROUP, raw_data, bytes); | 119 qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_AND_ROOMS, raw_data, bytes); |
121 } | 120 } |
122 | 121 |
123 /* parse the data into qq_buddy_status */ | 122 /* parse the data into qq_buddy_status */ |
124 static gint get_buddy_status(qq_buddy_status *bs, guint8 *data) | 123 static gint get_buddy_status(qq_buddy_status *bs, guint8 *data) |
125 { | 124 { |
156 } | 155 } |
157 | 156 |
158 #define QQ_ONLINE_BUDDY_ENTRY_LEN 38 | 157 #define QQ_ONLINE_BUDDY_ENTRY_LEN 38 |
159 | 158 |
160 /* process the reply packet for get_buddies_online packet */ | 159 /* process the reply packet for get_buddies_online packet */ |
161 guint8 qq_process_get_buddies_online_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) | 160 guint8 qq_process_get_buddies_online_reply(guint8 *data, gint data_len, PurpleConnection *gc) |
162 { | 161 { |
163 qq_data *qd; | 162 qq_data *qd; |
164 gint len, bytes, bytes_buddy; | 163 gint bytes, bytes_buddy; |
165 gint count; | 164 gint count; |
166 guint8 *data, position; | 165 guint8 position; |
167 PurpleBuddy *b; | 166 PurpleBuddy *b; |
168 qq_buddy *q_bud; | 167 qq_buddy *q_bud; |
169 qq_buddy_online bo; | 168 qq_buddy_online bo; |
170 | 169 gchar *purple_name; |
171 g_return_val_if_fail(buf != NULL && buf_len != 0, -1); | 170 |
171 g_return_val_if_fail(data != NULL && data_len != 0, -1); | |
172 | 172 |
173 qd = (qq_data *) gc->proto_data; | 173 qd = (qq_data *) gc->proto_data; |
174 len = buf_len; | |
175 data = g_newa(guint8, len); | |
176 | |
177 purple_debug(PURPLE_DEBUG_INFO, "QQ", "processing get_buddies_online_reply\n"); | |
178 | |
179 if (!qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { | |
180 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt buddies online"); | |
181 return -1; | |
182 } | |
183 | 174 |
184 /* qq_show_packet("Get buddies online reply packet", data, len); */ | 175 /* qq_show_packet("Get buddies online reply packet", data, len); */ |
185 | 176 |
186 bytes = 0; | 177 bytes = 0; |
187 bytes += qq_get8(&position, data + bytes); | 178 bytes += qq_get8(&position, data + bytes); |
188 | 179 |
189 count = 0; | 180 count = 0; |
190 while (bytes < len) { | 181 while (bytes < data_len) { |
191 if (len - bytes < QQ_ONLINE_BUDDY_ENTRY_LEN) { | 182 if (data_len - bytes < QQ_ONLINE_BUDDY_ENTRY_LEN) { |
192 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | 183 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
193 "[buddies online] only %d, need %d", | 184 "[buddies online] only %d, need %d", |
194 (len - bytes), QQ_ONLINE_BUDDY_ENTRY_LEN); | 185 (data_len - bytes), QQ_ONLINE_BUDDY_ENTRY_LEN); |
195 break; | 186 break; |
196 } | 187 } |
197 memset(&bo, 0 ,sizeof(bo)); | 188 memset(&bo, 0 ,sizeof(bo)); |
198 | 189 |
199 /* set flag */ | 190 /* set flag */ |
217 "uid=0 or entry complete len(%d) != %d", | 208 "uid=0 or entry complete len(%d) != %d", |
218 (bytes - bytes_buddy), QQ_ONLINE_BUDDY_ENTRY_LEN); | 209 (bytes - bytes_buddy), QQ_ONLINE_BUDDY_ENTRY_LEN); |
219 continue; | 210 continue; |
220 } /* check if it is a valid entry */ | 211 } /* check if it is a valid entry */ |
221 | 212 |
213 if (bo.bs.uid == qd->uid) { | |
214 purple_debug(PURPLE_DEBUG_WARNING, "QQ", | |
215 "I am in online list %d\n", bo.bs.uid); | |
216 continue; | |
217 } | |
218 | |
222 /* update buddy information */ | 219 /* update buddy information */ |
223 b = purple_find_buddy(purple_connection_get_account(gc), | 220 purple_name = uid_to_purple_name(bo.bs.uid); |
224 uid_to_purple_name(bo.bs.uid) ); | 221 if (purple_name == NULL) { |
222 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | |
223 "Got an online buddy %d, but not find purple name\n", bo.bs.uid); | |
224 continue; | |
225 } | |
226 b = purple_find_buddy(purple_connection_get_account(gc), purple_name); | |
227 g_free(purple_name); | |
228 | |
225 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; | 229 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; |
226 if (q_bud == NULL) { | 230 if (q_bud == NULL) { |
227 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | 231 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
228 "Got an online buddy %d, but not in my buddy list\n", bo.bs.uid); | 232 "Got an online buddy %d, but not in my buddy list\n", bo.bs.uid); |
229 continue; | 233 continue; |
240 q_bud->comm_flag = bo.comm_flag; | 244 q_bud->comm_flag = bo.comm_flag; |
241 qq_update_buddy_contact(gc, q_bud); | 245 qq_update_buddy_contact(gc, q_bud); |
242 count++; | 246 count++; |
243 } | 247 } |
244 | 248 |
245 if(bytes > len) { | 249 if(bytes > data_len) { |
246 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | 250 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
247 "qq_process_get_buddies_online_reply: Dangerous error! maybe protocol changed, notify developers!\n"); | 251 "qq_process_get_buddies_online_reply: Dangerous error! maybe protocol changed, notify developers!\n"); |
248 } | 252 } |
249 | 253 |
250 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d online buddies, nextposition=%u\n", | 254 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d online buddies, nextposition=%u\n", |
252 return position; | 256 return position; |
253 } | 257 } |
254 | 258 |
255 | 259 |
256 /* process reply for get_buddies_list */ | 260 /* process reply for get_buddies_list */ |
257 guint16 qq_process_get_buddies_list_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) | 261 guint16 qq_process_get_buddies_list_reply(guint8 *data, gint data_len, PurpleConnection *gc) |
258 { | 262 { |
259 qq_data *qd; | 263 qq_data *qd; |
260 qq_buddy *q_bud; | 264 qq_buddy *q_bud; |
261 gint len, bytes_expected, count; | 265 gint bytes_expected, count; |
262 gint bytes, buddy_bytes; | 266 gint bytes, buddy_bytes; |
263 guint16 position, unknown; | 267 guint16 position, unknown; |
264 guint8 *data, pascal_len; | 268 guint8 pascal_len; |
265 gchar *name; | 269 gchar *name; |
266 PurpleBuddy *b; | 270 PurpleBuddy *b; |
267 | 271 |
268 g_return_val_if_fail(buf != NULL && buf_len != 0, -1); | 272 g_return_val_if_fail(data != NULL && data_len != 0, -1); |
269 | 273 |
270 qd = (qq_data *) gc->proto_data; | 274 qd = (qq_data *) gc->proto_data; |
271 len = buf_len; | 275 |
272 data = g_newa(guint8, len); | 276 if (data_len <= 2) { |
273 | 277 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "empty buddies list"); |
274 if (!qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { | |
275 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt buddies list"); | |
276 return -1; | 278 return -1; |
277 } | 279 } |
280 /* qq_show_packet("QQ get buddies list", data, data_len); */ | |
278 bytes = 0; | 281 bytes = 0; |
279 bytes += qq_get16(&position, data + bytes); | 282 bytes += qq_get16(&position, data + bytes); |
280 /* the following data is buddy list in this packet */ | 283 /* the following data is buddy list in this packet */ |
281 count = 0; | 284 count = 0; |
282 while (bytes < len) { | 285 while (bytes < data_len) { |
283 q_bud = g_new0(qq_buddy, 1); | 286 q_bud = g_new0(qq_buddy, 1); |
284 /* set flag */ | 287 /* set flag */ |
285 buddy_bytes = bytes; | 288 buddy_bytes = bytes; |
286 /* 000-003: uid */ | 289 /* 000-003: uid */ |
287 bytes += qq_get32(&q_bud->uid, data + bytes); | 290 bytes += qq_get32(&q_bud->uid, data + bytes); |
309 continue; | 312 continue; |
310 } else { | 313 } else { |
311 count++; | 314 count++; |
312 } | 315 } |
313 | 316 |
314 if (QQ_DEBUG) { | 317 #if 1 |
315 purple_debug(PURPLE_DEBUG_INFO, "QQ", | 318 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
316 "buddy [%09d]: ext_flag=0x%02x, comm_flag=0x%02x, nick=%s\n", | 319 "buddy [%09d]: ext_flag=0x%02x, comm_flag=0x%02x, nick=%s\n", |
317 q_bud->uid, q_bud->ext_flag, q_bud->comm_flag, q_bud->nickname); | 320 q_bud->uid, q_bud->ext_flag, q_bud->comm_flag, q_bud->nickname); |
318 } | 321 #endif |
319 | 322 |
320 name = uid_to_purple_name(q_bud->uid); | 323 name = uid_to_purple_name(q_bud->uid); |
321 b = purple_find_buddy(gc->account, name); | 324 b = purple_find_buddy(gc->account, name); |
322 g_free(name); | 325 g_free(name); |
323 | 326 |
328 b->proto_data = q_bud; | 331 b->proto_data = q_bud; |
329 qd->buddies = g_list_append(qd->buddies, q_bud); | 332 qd->buddies = g_list_append(qd->buddies, q_bud); |
330 qq_update_buddy_contact(gc, q_bud); | 333 qq_update_buddy_contact(gc, q_bud); |
331 } | 334 } |
332 | 335 |
333 if(bytes > len) { | 336 if(bytes > data_len) { |
334 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | 337 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
335 "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!"); | 338 "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!"); |
336 } | 339 } |
337 | 340 |
338 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d buddies, nextposition=%u\n", | 341 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d buddies, nextposition=%u\n", |
339 count, (guint) position); | 342 count, (guint) position); |
340 return position; | 343 return position; |
341 } | 344 } |
342 | 345 |
343 guint32 qq_process_get_all_list_with_group_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) | 346 guint32 qq_process_get_buddies_and_rooms(guint8 *data, gint data_len, PurpleConnection *gc) |
344 { | 347 { |
345 qq_data *qd; | 348 qq_data *qd; |
346 gint len, i, j; | 349 gint i, j; |
347 gint bytes = 0; | 350 gint bytes; |
348 guint8 *data; | |
349 guint8 sub_cmd, reply_code; | 351 guint8 sub_cmd, reply_code; |
350 guint32 unknown, position; | 352 guint32 unknown, position; |
351 guint32 uid; | 353 guint32 uid; |
352 guint8 type, groupid; | 354 guint8 type, groupid; |
353 qq_group *group; | 355 qq_group *group; |
354 | 356 |
355 g_return_val_if_fail(buf != NULL && buf_len != 0, -1); | 357 g_return_val_if_fail(data != NULL && data_len != 0, -1); |
356 | 358 |
357 qd = (qq_data *) gc->proto_data; | 359 qd = (qq_data *) gc->proto_data; |
358 len = buf_len; | 360 |
359 data = g_newa(guint8, len); | 361 bytes = 0; |
360 | |
361 if (!qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { | |
362 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt all list with group"); | |
363 return -1; | |
364 } | |
365 | |
366 bytes += qq_get8(&sub_cmd, data + bytes); | 362 bytes += qq_get8(&sub_cmd, data + bytes); |
367 g_return_val_if_fail(sub_cmd == 0x01, -1); | 363 g_return_val_if_fail(sub_cmd == 0x01, -1); |
368 | 364 |
369 bytes += qq_get8(&reply_code, data + bytes); | 365 bytes += qq_get8(&reply_code, data + bytes); |
370 if(0 != reply_code) { | 366 if(0 != reply_code) { |
371 purple_debug(PURPLE_DEBUG_WARNING, "QQ", | 367 purple_debug(PURPLE_DEBUG_WARNING, "QQ", |
372 "Get all list with group reply, reply_code(%d) is not zero", reply_code); | 368 "qq_process_get_buddies_and_rooms, %d", reply_code); |
373 } | 369 } |
374 | 370 |
375 bytes += qq_get32(&unknown, data + bytes); | 371 bytes += qq_get32(&unknown, data + bytes); |
376 bytes += qq_get32(&position, data + bytes); | 372 bytes += qq_get32(&position, data + bytes); |
377 /* the following data is all list in this packet */ | 373 /* the following data is all list in this packet */ |
378 i = 0; | 374 i = 0; |
379 j = 0; | 375 j = 0; |
380 while (bytes < len) { | 376 while (bytes < data_len) { |
381 /* 00-03: uid */ | 377 /* 00-03: uid */ |
382 bytes += qq_get32(&uid, data + bytes); | 378 bytes += qq_get32(&uid, data + bytes); |
383 /* 04: type 0x1:buddy 0x4:Qun */ | 379 /* 04: type 0x1:buddy 0x4:Qun */ |
384 bytes += qq_get8(&type, data + bytes); | 380 bytes += qq_get8(&type, data + bytes); |
385 /* 05: groupid*4 */ /* seems to always be 0 */ | 381 /* 05: groupid*4 */ /* seems to always be 0 */ |
396 if(0x1 == type) { /* a buddy */ | 392 if(0x1 == type) { /* a buddy */ |
397 /* don't do anything but count - buddies are handled by | 393 /* don't do anything but count - buddies are handled by |
398 * qq_send_packet_get_buddies_list */ | 394 * qq_send_packet_get_buddies_list */ |
399 ++i; | 395 ++i; |
400 } else { /* a group */ | 396 } else { /* a group */ |
401 group = qq_group_find_by_id(gc, uid, QQ_INTERNAL_ID); | 397 group = qq_room_search_id(gc, uid); |
402 if(group == NULL) { | 398 if(group == NULL) { |
399 purple_debug(PURPLE_DEBUG_INFO, "QQ", | |
400 "Not find room id %d in qq_process_get_buddies_and_rooms\n", uid); | |
403 qq_set_pending_id(&qd->adding_groups_from_server, uid, TRUE); | 401 qq_set_pending_id(&qd->adding_groups_from_server, uid, TRUE); |
404 group = g_newa(qq_group, 1); | 402 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, uid); |
405 group->internal_group_id = uid; | |
406 qq_send_cmd_group_get_group_info(gc, group); | |
407 } else { | 403 } else { |
408 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; | 404 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; |
409 qq_group_refresh(gc, group); | 405 qq_group_refresh(gc, group); |
410 qq_send_cmd_group_get_group_info(gc, group); | 406 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id); |
411 } | 407 } |
412 ++j; | 408 ++j; |
413 } | 409 } |
414 } | 410 } |
415 | 411 |
416 if(bytes > len) { | 412 if(bytes > data_len) { |
417 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | 413 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
418 "qq_process_get_all_list_with_group_reply: Dangerous error! maybe protocol changed, notify developers!"); | 414 "qq_process_get_buddies_and_rooms: Dangerous error! maybe protocol changed, notify developers!"); |
419 } | 415 } |
420 | 416 |
421 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d buddies and %d groups, nextposition=%u\n", i, j, (guint) position); | 417 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d buddies and %d groups, nextposition=%u\n", i, j, (guint) position); |
422 return position; | 418 return position; |
423 } | 419 } |
503 | 499 |
504 qq_send_cmd(qd, QQ_CMD_CHANGE_ONLINE_STATUS, raw_data, bytes); | 500 qq_send_cmd(qd, QQ_CMD_CHANGE_ONLINE_STATUS, raw_data, bytes); |
505 } | 501 } |
506 | 502 |
507 /* parse the reply packet for change_status */ | 503 /* parse the reply packet for change_status */ |
508 void qq_process_change_status_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) | 504 void qq_process_change_status_reply(guint8 *data, gint data_len, PurpleConnection *gc) |
509 { | 505 { |
510 qq_data *qd; | 506 qq_data *qd; |
511 gint len, bytes; | 507 gint bytes; |
512 guint8 *data, reply; | 508 guint8 reply; |
513 PurpleBuddy *b; | 509 PurpleBuddy *b; |
514 qq_buddy *q_bud; | 510 qq_buddy *q_bud; |
515 gchar *name; | 511 gchar *name; |
516 | 512 |
517 g_return_if_fail(buf != NULL && buf_len != 0); | 513 g_return_if_fail(data != NULL && data_len != 0); |
518 | 514 |
519 qd = (qq_data *) gc->proto_data; | 515 qd = (qq_data *) gc->proto_data; |
520 len = buf_len; | 516 |
521 data = g_newa(guint8, len); | |
522 | |
523 if ( !qq_decrypt(buf, buf_len, qd->session_key, data, &len) ) { | |
524 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt chg status reply\n"); | |
525 return; | |
526 } | |
527 | |
528 bytes = 0; | 517 bytes = 0; |
529 bytes = qq_get8(&reply, data + bytes); | 518 bytes = qq_get8(&reply, data + bytes); |
530 if (reply != QQ_CHANGE_ONLINE_STATUS_REPLY_OK) { | 519 if (reply != QQ_CHANGE_ONLINE_STATUS_REPLY_OK) { |
531 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Change status fail 0x%02X\n", reply); | 520 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Change status fail 0x%02X\n", reply); |
532 return; | 521 return; |
541 qq_update_buddy_contact(gc, q_bud); | 530 qq_update_buddy_contact(gc, q_bud); |
542 } | 531 } |
543 } | 532 } |
544 | 533 |
545 /* it is a server message indicating that one of my buddies has changed its status */ | 534 /* it is a server message indicating that one of my buddies has changed its status */ |
546 void qq_process_buddy_change_status(guint8 *buf, gint buf_len, PurpleConnection *gc) | 535 void qq_process_buddy_change_status(guint8 *data, gint data_len, PurpleConnection *gc) |
547 { | 536 { |
548 qq_data *qd; | 537 qq_data *qd; |
549 gint bytes; | 538 gint bytes; |
550 guint32 my_uid; | 539 guint32 my_uid; |
551 guint8 *data; | |
552 gint data_len; | |
553 PurpleBuddy *b; | 540 PurpleBuddy *b; |
554 qq_buddy *q_bud; | 541 qq_buddy *q_bud; |
555 qq_buddy_status bs; | 542 qq_buddy_status bs; |
556 gchar *name; | 543 gchar *name; |
557 | 544 |
558 g_return_if_fail(buf != NULL && buf_len != 0); | 545 g_return_if_fail(data != NULL && data_len != 0); |
559 | 546 |
560 qd = (qq_data *) gc->proto_data; | 547 qd = (qq_data *) gc->proto_data; |
561 data_len = buf_len; | |
562 data = g_newa(guint8, data_len); | |
563 | |
564 if ( !qq_decrypt(buf, buf_len, qd->session_key, data, &data_len) ) { | |
565 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[buddy status change] Failed decrypt\n"); | |
566 return; | |
567 } | |
568 | 548 |
569 if (data_len < 35) { | 549 if (data_len < 35) { |
570 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[buddy status change] only %d, need 35 bytes\n", data_len); | 550 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[buddy status change] only %d, need 35 bytes\n", data_len); |
571 return; | 551 return; |
572 } | 552 } |
604 } | 584 } |
605 | 585 |
606 /*TODO: maybe this should be qq_update_buddy_status() ?*/ | 586 /*TODO: maybe this should be qq_update_buddy_status() ?*/ |
607 void qq_update_buddy_contact(PurpleConnection *gc, qq_buddy *q_bud) | 587 void qq_update_buddy_contact(PurpleConnection *gc, qq_buddy *q_bud) |
608 { | 588 { |
609 gchar *name; | 589 gchar *purple_name; |
610 PurpleBuddy *bud; | 590 PurpleBuddy *bud; |
611 gchar *status_id; | 591 gchar *status_id; |
612 | 592 |
613 g_return_if_fail(q_bud != NULL); | 593 g_return_if_fail(q_bud != NULL); |
614 | 594 |
615 name = uid_to_purple_name(q_bud->uid); | 595 purple_name = uid_to_purple_name(q_bud->uid); |
616 bud = purple_find_buddy(gc->account, name); | 596 if (purple_name == NULL) { |
617 | 597 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Not find purple name: %d\n", q_bud->uid); |
598 return; | |
599 } | |
600 | |
601 bud = purple_find_buddy(gc->account, purple_name); | |
618 if (bud == NULL) { | 602 if (bud == NULL) { |
619 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "unknown buddy: %d\n", q_bud->uid); | 603 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Not find buddy: %d\n", q_bud->uid); |
620 g_free(name); | 604 g_free(purple_name); |
621 return; | 605 return; |
622 } | 606 } |
623 | 607 |
624 purple_blist_server_alias_buddy(bud, q_bud->nickname); /* server */ | 608 purple_blist_server_alias_buddy(bud, q_bud->nickname); /* server */ |
625 q_bud->last_refresh = time(NULL); | 609 q_bud->last_refresh = time(NULL); |
648 status_id = "invisible"; | 632 status_id = "invisible"; |
649 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "unknown status: %x\n", q_bud->status); | 633 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "unknown status: %x\n", q_bud->status); |
650 break; | 634 break; |
651 } | 635 } |
652 purple_debug(PURPLE_DEBUG_INFO, "QQ", "buddy %d %s\n", q_bud->uid, status_id); | 636 purple_debug(PURPLE_DEBUG_INFO, "QQ", "buddy %d %s\n", q_bud->uid, status_id); |
653 purple_prpl_got_user_status(gc->account, name, status_id, NULL); | 637 purple_prpl_got_user_status(gc->account, purple_name, status_id, NULL); |
654 | 638 |
655 if (q_bud->comm_flag & QQ_COMM_FLAG_MOBILE && q_bud->status != QQ_BUDDY_OFFLINE) | 639 if (q_bud->comm_flag & QQ_COMM_FLAG_MOBILE && q_bud->status != QQ_BUDDY_OFFLINE) |
656 purple_prpl_got_user_status(gc->account, name, "mobile", NULL); | 640 purple_prpl_got_user_status(gc->account, purple_name, "mobile", NULL); |
657 else | 641 else |
658 purple_prpl_got_user_status_deactive(gc->account, name, "mobile"); | 642 purple_prpl_got_user_status_deactive(gc->account, purple_name, "mobile"); |
659 | 643 |
660 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO && q_bud->status != QQ_BUDDY_OFFLINE) | 644 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO && q_bud->status != QQ_BUDDY_OFFLINE) |
661 purple_prpl_got_user_status(gc->account, name, "video", NULL); | 645 purple_prpl_got_user_status(gc->account, purple_name, "video", NULL); |
662 else | 646 else |
663 purple_prpl_got_user_status_deactive(gc->account, name, "video"); | 647 purple_prpl_got_user_status_deactive(gc->account, purple_name, "video"); |
664 | 648 |
665 g_free(name); | 649 g_free(purple_name); |
666 } | 650 } |
667 | 651 |
668 /* refresh all buddies online/offline, | 652 /* refresh all buddies online/offline, |
669 * after receiving reply for get_buddies_online packet */ | 653 * after receiving reply for get_buddies_online packet */ |
670 void qq_refresh_all_buddy_status(PurpleConnection *gc) | 654 void qq_refresh_all_buddy_status(PurpleConnection *gc) |