comparison libpurple/protocols/qq/buddy_list.c @ 24026:25f62d21b3f8

disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 15 Sep 2008 03:04:07 +0000
parents 147ada94a1d8
children 225e0e9e1055
comparison
equal deleted inserted replaced
24019:147ada94a1d8 24026:25f62d21b3f8
54 guint16 unknown2; 54 guint16 unknown2;
55 guint8 ending; /* 0x00 */ 55 guint8 ending; /* 0x00 */
56 } qq_buddy_online; 56 } qq_buddy_online;
57 57
58 /* get a list of online_buddies */ 58 /* get a list of online_buddies */
59 void qq_request_get_buddies_online(PurpleConnection *gc, guint8 position, gint update_class) 59 void qq_send_packet_get_buddies_online(PurpleConnection *gc, guint8 position)
60 { 60 {
61 qq_data *qd; 61 qq_data *qd;
62 guint8 *raw_data; 62 guint8 *raw_data;
63 gint bytes = 0; 63 gint bytes = 0;
64 64
75 /* 002-002 */ 75 /* 002-002 */
76 bytes += qq_put8(raw_data + bytes, 0x00); 76 bytes += qq_put8(raw_data + bytes, 0x00);
77 /* 003-004 */ 77 /* 003-004 */
78 bytes += qq_put16(raw_data + bytes, 0x0000); 78 bytes += qq_put16(raw_data + bytes, 0x0000);
79 79
80 qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDIES_ONLINE, raw_data, 5, update_class, 0); 80 qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_ONLINE, raw_data, 5);
81 qd->last_get_online = time(NULL); 81 qd->last_get_online = time(NULL);
82 } 82 }
83 83
84 /* position starts with 0x0000, 84 /* position starts with 0x0000,
85 * server may return a position tag if list is too long for one packet */ 85 * server may return a position tag if list is too long for one packet */
86 void qq_request_get_buddies_list(PurpleConnection *gc, guint16 position, gint update_class) 86 void qq_send_packet_get_buddies_list(PurpleConnection *gc, guint16 position)
87 { 87 {
88 qq_data *qd = (qq_data *) gc->proto_data;
88 guint8 raw_data[16] = {0}; 89 guint8 raw_data[16] = {0};
89 gint bytes = 0; 90 gint bytes = 0;
90 91
91 /* 000-001 starting position, can manually specify */ 92 /* 000-001 starting position, can manually specify */
92 bytes += qq_put16(raw_data + bytes, position); 93 bytes += qq_put16(raw_data + bytes, position);
95 * even can sending packets 00 and get no response. 96 * even can sending packets 00 and get no response.
96 * Now I tested that 00,00,00,00,00,01 work perfectly 97 * Now I tested that 00,00,00,00,00,01 work perfectly
97 * March 22, found the 00,00,00 starts to work as well */ 98 * March 22, found the 00,00,00 starts to work as well */
98 bytes += qq_put8(raw_data + bytes, 0x00); 99 bytes += qq_put8(raw_data + bytes, 0x00);
99 100
100 qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDIES_LIST, raw_data, bytes, update_class, 0); 101 qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_LIST, raw_data, bytes);
101 } 102 }
102 103
103 /* get all list, buddies & Quns with groupsid support */ 104 /* get all list, buddies & Quns with groupsid support */
104 void qq_request_get_buddies_and_rooms(PurpleConnection *gc, guint32 position, gint update_class) 105 void qq_send_packet_get_buddies_and_rooms(PurpleConnection *gc, guint32 position)
105 { 106 {
107 qq_data *qd = (qq_data *) gc->proto_data;
106 guint8 raw_data[16] = {0}; 108 guint8 raw_data[16] = {0};
107 gint bytes = 0; 109 gint bytes = 0;
108 110
109 /* 0x01 download, 0x02, upload */ 111 /* 0x01 download, 0x02, upload */
110 bytes += qq_put8(raw_data + bytes, 0x01); 112 bytes += qq_put8(raw_data + bytes, 0x01);
112 bytes += qq_put8(raw_data + bytes, 0x02); 114 bytes += qq_put8(raw_data + bytes, 0x02);
113 /* unknown 00 00 00 00 */ 115 /* unknown 00 00 00 00 */
114 bytes += qq_put32(raw_data + bytes, 0x00000000); 116 bytes += qq_put32(raw_data + bytes, 0x00000000);
115 bytes += qq_put32(raw_data + bytes, position); 117 bytes += qq_put32(raw_data + bytes, position);
116 118
117 qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDIES_AND_ROOMS, raw_data, bytes, update_class, 0); 119 qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_AND_ROOMS, raw_data, bytes);
118 } 120 }
119 121
120 /* parse the data into qq_buddy_status */ 122 /* parse the data into qq_buddy_status */
121 static gint get_buddy_status(qq_buddy_status *bs, guint8 *data) 123 static gint get_buddy_status(qq_buddy_status *bs, guint8 *data)
122 { 124 {
142 /* 013-014: client_version */ 144 /* 013-014: client_version */
143 bytes += qq_get16(&bs->unknown3, data + bytes); 145 bytes += qq_get16(&bs->unknown3, data + bytes);
144 /* 015-030: unknown key */ 146 /* 015-030: unknown key */
145 bytes += qq_getdata(&(bs->unknown_key[0]), QQ_KEY_LENGTH, data + bytes); 147 bytes += qq_getdata(&(bs->unknown_key[0]), QQ_KEY_LENGTH, data + bytes);
146 148
147 purple_debug_info("QQ_STATUS", 149 purple_debug(PURPLE_DEBUG_INFO, "QQ_STATUS",
148 "uid: %d, U1: %d, ip: %s:%d, U2:%d, status:%d, U3:%04X\n", 150 "uid: %d, U1: %d, ip: %s:%d, U2:%d, status:%d, U3:%04X\n",
149 bs->uid, bs->unknown1, inet_ntoa(bs->ip), bs->port, 151 bs->uid, bs->unknown1, inet_ntoa(bs->ip), bs->port,
150 bs->unknown2, bs->status, bs->unknown3); 152 bs->unknown2, bs->status, bs->unknown3);
151 153
152 return bytes; 154 return bytes;
153 } 155 }
176 bytes += qq_get8(&position, data + bytes); 178 bytes += qq_get8(&position, data + bytes);
177 179
178 count = 0; 180 count = 0;
179 while (bytes < data_len) { 181 while (bytes < data_len) {
180 if (data_len - bytes < QQ_ONLINE_BUDDY_ENTRY_LEN) { 182 if (data_len - bytes < QQ_ONLINE_BUDDY_ENTRY_LEN) {
181 purple_debug_error("QQ", "[buddies online] only %d, need %d", 183 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
184 "[buddies online] only %d, need %d",
182 (data_len - bytes), QQ_ONLINE_BUDDY_ENTRY_LEN); 185 (data_len - bytes), QQ_ONLINE_BUDDY_ENTRY_LEN);
183 break; 186 break;
184 } 187 }
185 memset(&bo, 0 ,sizeof(bo)); 188 memset(&bo, 0 ,sizeof(bo));
186 189
187 /* set flag */ 190 /* set flag */
188 bytes_buddy = bytes; 191 bytes_buddy = bytes;
189 /* based on one online buddy entry */ 192 /* based on one online buddy entry */
190 /* 000-030 qq_buddy_status */ 193 /* 000-030 qq_buddy_status */
191 bytes += get_buddy_status(&(bo.bs), data + bytes); 194 bytes += get_buddy_status(&(bo.bs), data + bytes);
199 bytes += qq_get16(&bo.unknown2, data + bytes); 202 bytes += qq_get16(&bo.unknown2, data + bytes);
200 /* 037-037: */ 203 /* 037-037: */
201 bytes += qq_get8(&bo.ending, data + bytes); /* 0x00 */ 204 bytes += qq_get8(&bo.ending, data + bytes); /* 0x00 */
202 205
203 if (bo.bs.uid == 0 || (bytes - bytes_buddy) != QQ_ONLINE_BUDDY_ENTRY_LEN) { 206 if (bo.bs.uid == 0 || (bytes - bytes_buddy) != QQ_ONLINE_BUDDY_ENTRY_LEN) {
204 purple_debug_error("QQ", "uid=0 or entry complete len(%d) != %d", 207 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
208 "uid=0 or entry complete len(%d) != %d",
205 (bytes - bytes_buddy), QQ_ONLINE_BUDDY_ENTRY_LEN); 209 (bytes - bytes_buddy), QQ_ONLINE_BUDDY_ENTRY_LEN);
206 continue; 210 continue;
207 } /* check if it is a valid entry */ 211 } /* check if it is a valid entry */
208 212
209 if (bo.bs.uid == qd->uid) { 213 if (bo.bs.uid == qd->uid) {
210 purple_debug_warning("QQ", "I am in online list %d\n", bo.bs.uid); 214 purple_debug(PURPLE_DEBUG_WARNING, "QQ",
215 "I am in online list %d\n", bo.bs.uid);
211 continue; 216 continue;
212 } 217 }
213 218
214 /* update buddy information */ 219 /* update buddy information */
215 purple_name = uid_to_purple_name(bo.bs.uid); 220 purple_name = uid_to_purple_name(bo.bs.uid);
216 if (purple_name == NULL) { 221 if (purple_name == NULL) {
217 purple_debug_error("QQ", 222 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
218 "Got an online buddy %d, but not find purple name\n", bo.bs.uid); 223 "Got an online buddy %d, but not find purple name\n", bo.bs.uid);
219 continue; 224 continue;
220 } 225 }
221 b = purple_find_buddy(purple_connection_get_account(gc), purple_name); 226 b = purple_find_buddy(purple_connection_get_account(gc), purple_name);
222 g_free(purple_name); 227 g_free(purple_name);
223 228
224 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; 229 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
225 if (q_bud == NULL) { 230 if (q_bud == NULL) {
226 purple_debug_error("QQ", 231 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
227 "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);
228 continue; 233 continue;
229 } 234 }
230 /* we find one and update qq_buddy */ 235 /* we find one and update qq_buddy */
231 /* 236 /*
240 qq_update_buddy_contact(gc, q_bud); 245 qq_update_buddy_contact(gc, q_bud);
241 count++; 246 count++;
242 } 247 }
243 248
244 if(bytes > data_len) { 249 if(bytes > data_len) {
245 purple_debug_error("QQ", 250 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
246 "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");
247 } 252 }
248 253
249 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",
250 count, (guint) position); 255 count, (guint) position);
251 return position; 256 return position;
252 } 257 }
253 258
254 259
267 g_return_val_if_fail(data != NULL && data_len != 0, -1); 272 g_return_val_if_fail(data != NULL && data_len != 0, -1);
268 273
269 qd = (qq_data *) gc->proto_data; 274 qd = (qq_data *) gc->proto_data;
270 275
271 if (data_len <= 2) { 276 if (data_len <= 2) {
272 purple_debug_error("QQ", "empty buddies list"); 277 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "empty buddies list");
273 return -1; 278 return -1;
274 } 279 }
275 /* qq_show_packet("QQ get buddies list", data, data_len); */ 280 /* qq_show_packet("QQ get buddies list", data, data_len); */
276 bytes = 0; 281 bytes = 0;
277 bytes += qq_get16(&position, data + bytes); 282 bytes += qq_get16(&position, data + bytes);
298 bytes += qq_get8(&q_bud->comm_flag, data + bytes); 303 bytes += qq_get8(&q_bud->comm_flag, data + bytes);
299 304
300 bytes_expected = 12 + pascal_len; 305 bytes_expected = 12 + pascal_len;
301 306
302 if (q_bud->uid == 0 || (bytes - buddy_bytes) != bytes_expected) { 307 if (q_bud->uid == 0 || (bytes - buddy_bytes) != bytes_expected) {
303 purple_debug_info("QQ", 308 purple_debug(PURPLE_DEBUG_INFO, "QQ",
304 "Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes - buddy_bytes); 309 "Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes - buddy_bytes);
305 g_free(q_bud->nickname); 310 g_free(q_bud->nickname);
306 g_free(q_bud); 311 g_free(q_bud);
307 continue; 312 continue;
308 } else { 313 } else {
309 count++; 314 count++;
310 } 315 }
311 316
312 #if 1 317 #if 1
313 purple_debug_info("QQ", 318 purple_debug(PURPLE_DEBUG_INFO, "QQ",
314 "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",
315 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);
316 #endif 321 #endif
317 322
318 name = uid_to_purple_name(q_bud->uid); 323 name = uid_to_purple_name(q_bud->uid);
327 qd->buddies = g_list_append(qd->buddies, q_bud); 332 qd->buddies = g_list_append(qd->buddies, q_bud);
328 qq_update_buddy_contact(gc, q_bud); 333 qq_update_buddy_contact(gc, q_bud);
329 } 334 }
330 335
331 if(bytes > data_len) { 336 if(bytes > data_len) {
332 purple_debug_error("QQ", 337 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
333 "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!");
334 } 339 }
335 340
336 purple_debug_info("QQ", "Received %d buddies, nextposition=%u\n", 341 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d buddies, nextposition=%u\n",
337 count, (guint) position); 342 count, (guint) position);
338 return position; 343 return position;
339 } 344 }
340 345
341 guint32 qq_process_get_buddies_and_rooms(guint8 *data, gint data_len, PurpleConnection *gc) 346 guint32 qq_process_get_buddies_and_rooms(guint8 *data, gint data_len, PurpleConnection *gc)
357 bytes += qq_get8(&sub_cmd, data + bytes); 362 bytes += qq_get8(&sub_cmd, data + bytes);
358 g_return_val_if_fail(sub_cmd == 0x01, -1); 363 g_return_val_if_fail(sub_cmd == 0x01, -1);
359 364
360 bytes += qq_get8(&reply_code, data + bytes); 365 bytes += qq_get8(&reply_code, data + bytes);
361 if(0 != reply_code) { 366 if(0 != reply_code) {
362 purple_debug_warning("QQ", "qq_process_get_buddies_and_rooms, %d", reply_code); 367 purple_debug(PURPLE_DEBUG_WARNING, "QQ",
368 "qq_process_get_buddies_and_rooms, %d", reply_code);
363 } 369 }
364 370
365 bytes += qq_get32(&unknown, data + bytes); 371 bytes += qq_get32(&unknown, data + bytes);
366 bytes += qq_get32(&position, data + bytes); 372 bytes += qq_get32(&position, data + bytes);
367 /* the following data is all list in this packet */ 373 /* the following data is all list in this packet */
373 /* 04: type 0x1:buddy 0x4:Qun */ 379 /* 04: type 0x1:buddy 0x4:Qun */
374 bytes += qq_get8(&type, data + bytes); 380 bytes += qq_get8(&type, data + bytes);
375 /* 05: groupid*4 */ /* seems to always be 0 */ 381 /* 05: groupid*4 */ /* seems to always be 0 */
376 bytes += qq_get8(&groupid, data + bytes); 382 bytes += qq_get8(&groupid, data + bytes);
377 /* 383 /*
378 purple_debug_info("QQ", "groupid: %i\n", groupid); 384 purple_debug(PURPLE_DEBUG_INFO, "QQ", "groupid: %i\n", groupid);
379 groupid >>= 2; 385 groupid >>= 2;
380 */ 386 */
381 if (uid == 0 || (type != 0x1 && type != 0x4)) { 387 if (uid == 0 || (type != 0x1 && type != 0x4)) {
382 purple_debug_info("QQ", "Buddy entry, uid=%d, type=%d", uid, type); 388 purple_debug(PURPLE_DEBUG_INFO, "QQ",
389 "Buddy entry, uid=%d, type=%d", uid, type);
383 continue; 390 continue;
384 } 391 }
385 if(0x1 == type) { /* a buddy */ 392 if(0x1 == type) { /* a buddy */
386 /* don't do anything but count - buddies are handled by 393 /* don't do anything but count - buddies are handled by
387 * qq_request_get_buddies_list */ 394 * qq_send_packet_get_buddies_list */
388 ++i; 395 ++i;
389 } else { /* a group */ 396 } else { /* a group */
390 group = qq_room_search_id(gc, uid); 397 group = qq_room_search_id(gc, uid);
391 if(group == NULL) { 398 if(group == NULL) {
392 purple_debug_info("QQ", 399 purple_debug(PURPLE_DEBUG_INFO, "QQ",
393 "Not find room id %d in qq_process_get_buddies_and_rooms\n", uid); 400 "Not find room id %d in qq_process_get_buddies_and_rooms\n", uid);
394 qq_set_pending_id(&qd->adding_groups_from_server, uid, TRUE); 401 qq_set_pending_id(&qd->adding_groups_from_server, uid, TRUE);
402 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, uid);
395 } else { 403 } else {
396 group->my_role = QQ_ROOM_ROLE_YES; 404 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
397 qq_group_refresh(gc, group); 405 qq_group_refresh(gc, group);
406 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id);
398 } 407 }
399 ++j; 408 ++j;
400 } 409 }
401 } 410 }
402 411
403 if(bytes > data_len) { 412 if(bytes > data_len) {
404 purple_debug_error("QQ", 413 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
405 "qq_process_get_buddies_and_rooms: Dangerous error! maybe protocol changed, notify developers!"); 414 "qq_process_get_buddies_and_rooms: Dangerous error! maybe protocol changed, notify developers!");
406 } 415 }
407 416
408 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);
409 return position; 418 return position;
410 } 419 }
411 420
412 #define QQ_MISC_STATUS_HAVING_VIIDEO 0x00000001 421 #define QQ_MISC_STATUS_HAVING_VIIDEO 0x00000001
413 #define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 0x30 /* ASCII value of "0" */ 422 #define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 0x30 /* ASCII value of "0" */
414 423
415 /* TODO: figure out what's going on with the IP region. Sometimes I get valid IP addresses, 424 /* TODO: figure out what's going on with the IP region. Sometimes I get valid IP addresses,
416 * but the port number's weird, other times I get 0s. I get these simultaneously on the same buddy, 425 * but the port number's weird, other times I get 0s. I get these simultaneously on the same buddy,
417 * using different accounts to get info. */ 426 * using different accounts to get info. */
418 427
419 /* check if status means online or offline */ 428 /* check if status means online or offline */
420 gboolean is_online(guint8 status) 429 gboolean is_online(guint8 status)
421 { 430 {
430 return FALSE; 439 return FALSE;
431 } 440 }
432 441
433 /* Help calculate the correct icon index to tell the server. */ 442 /* Help calculate the correct icon index to tell the server. */
434 gint get_icon_offset(PurpleConnection *gc) 443 gint get_icon_offset(PurpleConnection *gc)
435 { 444 {
436 PurpleAccount *account; 445 PurpleAccount *account;
437 PurplePresence *presence; 446 PurplePresence *presence;
438 447
439 account = purple_connection_get_account(gc); 448 account = purple_connection_get_account(gc);
440 presence = purple_account_get_presence(account); 449 presence = purple_account_get_presence(account);
441 450
442 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_INVISIBLE)) { 451 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_INVISIBLE)) {
449 return 0; 458 return 0;
450 } 459 }
451 } 460 }
452 461
453 /* send a packet to change my online status */ 462 /* send a packet to change my online status */
454 void qq_request_change_status(PurpleConnection *gc, gint update_class) 463 void qq_send_packet_change_status(PurpleConnection *gc)
455 { 464 {
456 qq_data *qd; 465 qq_data *qd;
457 guint8 raw_data[16] = {0}; 466 guint8 raw_data[16] = {0};
458 gint bytes = 0; 467 gint bytes = 0;
459 guint8 away_cmd; 468 guint8 away_cmd;
460 guint32 misc_status; 469 guint32 misc_status;
461 gboolean fake_video; 470 gboolean fake_video;
462 PurpleAccount *account; 471 PurpleAccount *account;
463 PurplePresence *presence; 472 PurplePresence *presence;
464 473
465 account = purple_connection_get_account(gc); 474 account = purple_connection_get_account(gc);
466 presence = purple_account_get_presence(account); 475 presence = purple_account_get_presence(account);
467 476
468 qd = (qq_data *) gc->proto_data; 477 qd = (qq_data *) gc->proto_data;
469 if (!qd->is_login) 478 if (!qd->logged_in)
470 return; 479 return;
471 480
472 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_INVISIBLE)) { 481 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_INVISIBLE)) {
473 away_cmd = QQ_BUDDY_ONLINE_INVISIBLE; 482 away_cmd = QQ_BUDDY_ONLINE_INVISIBLE;
474 } else if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_AWAY) 483 } else if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_AWAY)
486 495
487 bytes = 0; 496 bytes = 0;
488 bytes += qq_put8(raw_data + bytes, away_cmd); 497 bytes += qq_put8(raw_data + bytes, away_cmd);
489 bytes += qq_put32(raw_data + bytes, misc_status); 498 bytes += qq_put32(raw_data + bytes, misc_status);
490 499
491 qq_send_cmd_mess(gc, QQ_CMD_CHANGE_STATUS, raw_data, bytes, update_class, 0); 500 qq_send_cmd(qd, QQ_CMD_CHANGE_ONLINE_STATUS, raw_data, bytes);
492 } 501 }
493 502
494 /* parse the reply packet for change_status */ 503 /* parse the reply packet for change_status */
495 void qq_process_change_status_reply(guint8 *data, gint data_len, PurpleConnection *gc) 504 void qq_process_change_status_reply(guint8 *data, gint data_len, PurpleConnection *gc)
496 { 505 {
502 gchar *name; 511 gchar *name;
503 512
504 g_return_if_fail(data != NULL && data_len != 0); 513 g_return_if_fail(data != NULL && data_len != 0);
505 514
506 qd = (qq_data *) gc->proto_data; 515 qd = (qq_data *) gc->proto_data;
507 516
508 bytes = 0; 517 bytes = 0;
509 bytes = qq_get8(&reply, data + bytes); 518 bytes = qq_get8(&reply, data + bytes);
510 if (reply != QQ_CHANGE_ONLINE_STATUS_REPLY_OK) { 519 if (reply != QQ_CHANGE_ONLINE_STATUS_REPLY_OK) {
511 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);
512 return; 521 return;
513 } 522 }
514 523
515 /* purple_debug_info("QQ", "Change status OK\n"); */ 524 /* purple_debug(PURPLE_DEBUG_INFO, "QQ", "Change status OK\n"); */
516 name = uid_to_purple_name(qd->uid); 525 name = uid_to_purple_name(qd->uid);
517 b = purple_find_buddy(gc->account, name); 526 b = purple_find_buddy(gc->account, name);
518 g_free(name); 527 g_free(name);
519 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; 528 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
520 if (q_bud != NULL) { 529 if (q_bud != NULL) {
521 qq_update_buddy_contact(gc, q_bud); 530 qq_update_buddy_contact(gc, q_bud);
522 } 531 }
523 } 532 }
524 533
525 /* 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 */
526 void qq_process_buddy_change_status(guint8 *data, gint data_len, PurpleConnection *gc) 535 void qq_process_buddy_change_status(guint8 *data, gint data_len, PurpleConnection *gc)
527 { 536 {
528 qq_data *qd; 537 qq_data *qd;
529 gint bytes; 538 gint bytes;
530 guint32 my_uid; 539 guint32 my_uid;
531 PurpleBuddy *b; 540 PurpleBuddy *b;
536 g_return_if_fail(data != NULL && data_len != 0); 545 g_return_if_fail(data != NULL && data_len != 0);
537 546
538 qd = (qq_data *) gc->proto_data; 547 qd = (qq_data *) gc->proto_data;
539 548
540 if (data_len < 35) { 549 if (data_len < 35) {
541 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);
542 return; 551 return;
543 } 552 }
544 553
545 memset(&bs, 0, sizeof(bs)); 554 memset(&bs, 0, sizeof(bs));
546 bytes = 0; 555 bytes = 0;
547 /* 000-030: qq_buddy_status */ 556 /* 000-030: qq_buddy_status */
548 bytes += get_buddy_status(&bs, data + bytes); 557 bytes += get_buddy_status(&bs, data + bytes);
549 /* 031-034: Unknow, maybe my uid */ 558 /* 031-034: Unknow, maybe my uid */
550 /* This has a value of 0 when we've changed our status to 559 /* This has a value of 0 when we've changed our status to
551 * QQ_BUDDY_ONLINE_INVISIBLE */ 560 * QQ_BUDDY_ONLINE_INVISIBLE */
552 bytes += qq_get32(&my_uid, data + bytes); 561 bytes += qq_get32(&my_uid, data + bytes);
553 562
554 name = uid_to_purple_name(bs.uid); 563 name = uid_to_purple_name(bs.uid);
555 b = purple_find_buddy(gc->account, name); 564 b = purple_find_buddy(gc->account, name);
556 g_free(name); 565 g_free(name);
557 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; 566 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
558 if (q_bud == NULL) { 567 if (q_bud == NULL) {
559 purple_debug_error("QQ", 568 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
560 "got information of unknown buddy %d\n", bs.uid); 569 "got information of unknown buddy %d\n", bs.uid);
561 return; 570 return;
562 } 571 }
563 572
564 purple_debug_info("QQ", "status:.uid = %d, q_bud->uid = %d\n", bs.uid , q_bud->uid); 573 purple_debug(PURPLE_DEBUG_INFO, "QQ", "status:.uid = %d, q_bud->uid = %d\n", bs.uid , q_bud->uid);
565 if(bs.ip.s_addr != 0) { 574 if(bs.ip.s_addr != 0) {
566 q_bud->ip.s_addr = bs.ip.s_addr; 575 q_bud->ip.s_addr = bs.ip.s_addr;
567 q_bud->port = bs.port; 576 q_bud->port = bs.port;
568 } 577 }
569 q_bud->status =bs.status; 578 q_bud->status =bs.status;
570 579
578 void qq_update_buddy_contact(PurpleConnection *gc, qq_buddy *q_bud) 587 void qq_update_buddy_contact(PurpleConnection *gc, qq_buddy *q_bud)
579 { 588 {
580 gchar *purple_name; 589 gchar *purple_name;
581 PurpleBuddy *bud; 590 PurpleBuddy *bud;
582 gchar *status_id; 591 gchar *status_id;
583 592
584 g_return_if_fail(q_bud != NULL); 593 g_return_if_fail(q_bud != NULL);
585 594
586 purple_name = uid_to_purple_name(q_bud->uid); 595 purple_name = uid_to_purple_name(q_bud->uid);
587 if (purple_name == NULL) { 596 if (purple_name == NULL) {
588 purple_debug_error("QQ", "Not find purple name: %d\n", q_bud->uid); 597 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Not find purple name: %d\n", q_bud->uid);
589 return; 598 return;
590 } 599 }
591 600
592 bud = purple_find_buddy(gc->account, purple_name); 601 bud = purple_find_buddy(gc->account, purple_name);
593 if (bud == NULL) { 602 if (bud == NULL) {
594 purple_debug_error("QQ", "Not find buddy: %d\n", q_bud->uid); 603 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Not find buddy: %d\n", q_bud->uid);
595 g_free(purple_name); 604 g_free(purple_name);
596 return; 605 return;
597 } 606 }
598 607
599 purple_blist_server_alias_buddy(bud, q_bud->nickname); /* server */ 608 purple_blist_server_alias_buddy(bud, q_bud->nickname); /* server */
600 q_bud->last_update = time(NULL); 609 q_bud->last_refresh = time(NULL);
601 610
602 /* purple supports signon and idle time 611 /* purple supports signon and idle time
603 * but it is not much use for QQ, I do not use them */ 612 * but it is not much use for QQ, I do not use them */
604 /* serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); */ 613 /* serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); */
605 status_id = "available"; 614 status_id = "available";
619 case QQ_BUDDY_ONLINE_INVISIBLE: 628 case QQ_BUDDY_ONLINE_INVISIBLE:
620 status_id = "invisible"; 629 status_id = "invisible";
621 break; 630 break;
622 default: 631 default:
623 status_id = "invisible"; 632 status_id = "invisible";
624 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);
625 break; 634 break;
626 } 635 }
627 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);
628 purple_prpl_got_user_status(gc->account, purple_name, status_id, NULL); 637 purple_prpl_got_user_status(gc->account, purple_name, status_id, NULL);
629 638
630 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)
631 purple_prpl_got_user_status(gc->account, purple_name, "mobile", NULL); 640 purple_prpl_got_user_status(gc->account, purple_name, "mobile", NULL);
632 else 641 else
653 now = time(NULL); 662 now = time(NULL);
654 list = qd->buddies; 663 list = qd->buddies;
655 664
656 while (list != NULL) { 665 while (list != NULL) {
657 q_bud = (qq_buddy *) list->data; 666 q_bud = (qq_buddy *) list->data;
658 if (q_bud != NULL && now > q_bud->last_update + QQ_UPDATE_ONLINE_INTERVAL 667 if (q_bud != NULL && now > q_bud->last_refresh + QQ_UPDATE_ONLINE_INTERVAL
659 && q_bud->status != QQ_BUDDY_ONLINE_INVISIBLE) { 668 && q_bud->status != QQ_BUDDY_ONLINE_INVISIBLE) {
660 q_bud->status = QQ_BUDDY_ONLINE_OFFLINE; 669 q_bud->status = QQ_BUDDY_ONLINE_OFFLINE;
661 qq_update_buddy_contact(gc, q_bud); 670 qq_update_buddy_contact(gc, q_bud);
662 } 671 }
663 list = list->next; 672 list = list->next;