comparison libpurple/protocols/qq/buddy_list.c @ 24076:ec3f7d3e0445

2008.10.04 - lonicerae <lonicerae(at)gmail.com> * fixed a bug in qq_base.c
author SHiNE CsyFeK <csyfek@gmail.com>
date Wed, 22 Oct 2008 14:49:38 +0000
parents a95c7e71064c
children ce94189f15ad
comparison
equal deleted inserted replaced
24075:a95c7e71064c 24076:ec3f7d3e0445
99 * March 22, found the 00,00,00 starts to work as well */ 99 * March 22, found the 00,00,00 starts to work as well */
100 bytes += qq_put8(raw_data + bytes, 0x00); 100 bytes += qq_put8(raw_data + bytes, 0x00);
101 if (qd->client_version >= 2007) { 101 if (qd->client_version >= 2007) {
102 bytes += qq_put16(raw_data + bytes, 0x0000); 102 bytes += qq_put16(raw_data + bytes, 0x0000);
103 } 103 }
104 104
105 qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDIES_LIST, raw_data, bytes, update_class, 0); 105 qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDIES_LIST, raw_data, bytes, update_class, 0);
106 } 106 }
107 107
108 /* get all list, buddies & Quns with groupsid support */ 108 /* get all list, buddies & Quns with groupsid support */
109 void qq_request_get_buddies_and_rooms(PurpleConnection *gc, guint32 position, gint update_class) 109 void qq_request_get_buddies_and_rooms(PurpleConnection *gc, guint32 position, gint update_class)
249 249
250 /* process reply for get_buddies_list */ 250 /* process reply for get_buddies_list */
251 guint16 qq_process_get_buddies_list_reply(guint8 *data, gint data_len, PurpleConnection *gc) 251 guint16 qq_process_get_buddies_list_reply(guint8 *data, gint data_len, PurpleConnection *gc)
252 { 252 {
253 qq_data *qd; 253 qq_data *qd;
254 qq_buddy *buddy; 254 qq_buddy *q_bud;
255 gint bytes_expected, count; 255 gint bytes_expected, count;
256 gint bytes, buddy_bytes; 256 gint bytes, buddy_bytes;
257 gint nickname_len;
258 guint16 position, unknown; 257 guint16 position, unknown;
259 gchar *purple_name; 258 guint8 pascal_len;
260 PurpleBuddy *purple_buddy; 259 gchar *name;
260 PurpleBuddy *b;
261 261
262 g_return_val_if_fail(data != NULL && data_len != 0, -1); 262 g_return_val_if_fail(data != NULL && data_len != 0, -1);
263 263
264 qd = (qq_data *) gc->proto_data; 264 qd = (qq_data *) gc->proto_data;
265 265
271 bytes = 0; 271 bytes = 0;
272 bytes += qq_get16(&position, data + bytes); 272 bytes += qq_get16(&position, data + bytes);
273 /* the following data is buddy list in this packet */ 273 /* the following data is buddy list in this packet */
274 count = 0; 274 count = 0;
275 while (bytes < data_len) { 275 while (bytes < data_len) {
276 buddy = g_new0(qq_buddy, 1); 276 q_bud = g_new0(qq_buddy, 1);
277 /* set flag */ 277 /* set flag */
278 buddy_bytes = bytes; 278 buddy_bytes = bytes;
279 /* 000-003: uid */ 279 /* 000-003: uid */
280 bytes += qq_get32(&buddy->uid, data + bytes); 280 bytes += qq_get32(&q_bud->uid, data + bytes);
281 /* 004-005: icon index (1-255) */ 281 /* 004-005: icon index (1-255) */
282 bytes += qq_get16(&buddy->face, data + bytes); 282 bytes += qq_get16(&q_bud->face, data + bytes);
283 /* 006-006: age */ 283 /* 006-006: age */
284 bytes += qq_get8(&buddy->age, data + bytes); 284 bytes += qq_get8(&q_bud->age, data + bytes);
285 /* 007-007: gender */ 285 /* 007-007: gender */
286 bytes += qq_get8(&buddy->gender, data + bytes); 286 bytes += qq_get8(&q_bud->gender, data + bytes);
287 287
288 nickname_len = qq_get_vstr(&buddy->nickname, QQ_CHARSET_DEFAULT, data + bytes); 288 pascal_len = convert_as_pascal_string(data + bytes, &q_bud->nickname, QQ_CHARSET_DEFAULT);
289 bytes += nickname_len; 289 bytes += pascal_len;
290 qq_filter_str(buddy->nickname); 290 qq_filter_str(q_bud->nickname);
291 291
292 /* Fixme: merge following as 32bit flag */ 292 /* Fixme: merge following as 32bit flag */
293 bytes += qq_get16(&unknown, data + bytes); 293 bytes += qq_get16(&unknown, data + bytes);
294 bytes += qq_get8(&buddy->ext_flag, data + bytes); 294 bytes += qq_get8(&q_bud->ext_flag, data + bytes);
295 bytes += qq_get8(&buddy->comm_flag, data + bytes); 295 bytes += qq_get8(&q_bud->comm_flag, data + bytes);
296 296
297 if (qd->client_version >= 2007) { 297 if (qd->client_version >= 2007) {
298 bytes += 4; /* skip 4 bytes */ 298 bytes += 4; /* skip 4 bytes */
299 bytes_expected = 16 + nickname_len; 299 bytes_expected = 16 + pascal_len;
300 } else { 300 } else {
301 bytes_expected = 12 + nickname_len; 301 bytes_expected = 12 + pascal_len;
302 } 302 }
303 303
304 if (buddy->uid == 0 || (bytes - buddy_bytes) != bytes_expected) { 304
305 if (q_bud->uid == 0 || (bytes - buddy_bytes) != bytes_expected) {
305 purple_debug_info("QQ", 306 purple_debug_info("QQ",
306 "Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes - buddy_bytes); 307 "Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes - buddy_bytes);
307 g_free(buddy->nickname); 308 g_free(q_bud->nickname);
308 g_free(buddy); 309 g_free(q_bud);
309 continue; 310 continue;
310 } else { 311 } else {
311 count++; 312 count++;
312 } 313 }
313 314
314 #if 1 315 #if 1
315 purple_debug_info("QQ", "buddy [%09d]: ext_flag=0x%02x, comm_flag=0x%02x, nick=%s\n", 316 purple_debug_info("QQ", "buddy [%09d]: ext_flag=0x%02x, comm_flag=0x%02x, nick=%s\n",
316 buddy->uid, buddy->ext_flag, buddy->comm_flag, buddy->nickname); 317 q_bud->uid, q_bud->ext_flag, q_bud->comm_flag, q_bud->nickname);
317 #endif 318 #endif
318 319
319 purple_name = uid_to_purple_name(buddy->uid); 320 name = uid_to_purple_name(q_bud->uid);
320 purple_buddy = purple_find_buddy(gc->account, purple_name); 321 b = purple_find_buddy(gc->account, name);
321 g_free(purple_name); 322 g_free(name);
322 323
323 if (purple_buddy == NULL) { 324 if (b == NULL) {
324 purple_buddy = qq_create_buddy(gc, buddy->uid, TRUE, FALSE); 325 b = qq_create_buddy(gc, q_bud->uid, TRUE, FALSE);
325 } 326 }
326 327
327 purple_buddy->proto_data = buddy; 328 b->proto_data = q_bud;
328 qd->buddies = g_list_append(qd->buddies, buddy); 329 qd->buddies = g_list_append(qd->buddies, q_bud);
329 qq_update_buddy_contact(gc, buddy); 330 qq_update_buddy_contact(gc, q_bud);
330 } 331 }
331 332
332 if(bytes > data_len) { 333 if(bytes > data_len) {
333 purple_debug_error("QQ", 334 purple_debug_error("QQ",
334 "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!"); 335 "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!");
358 bytes += qq_get8(&sub_cmd, data + bytes); 359 bytes += qq_get8(&sub_cmd, data + bytes);
359 g_return_val_if_fail(sub_cmd == 0x01, -1); 360 g_return_val_if_fail(sub_cmd == 0x01, -1);
360 361
361 bytes += qq_get8(&reply_code, data + bytes); 362 bytes += qq_get8(&reply_code, data + bytes);
362 if(0 != reply_code) { 363 if(0 != reply_code) {
363 purple_debug_warning("QQ", "qq_process_get_buddies_and_rooms, %d\n", reply_code); 364 purple_debug_warning("QQ", "qq_process_get_buddies_and_rooms, %d", reply_code);
364 } 365 }
365 366
366 bytes += qq_get32(&unknown, data + bytes); 367 bytes += qq_get32(&unknown, data + bytes);
367 bytes += qq_get32(&position, data + bytes); 368 bytes += qq_get32(&position, data + bytes);
368 /* the following data is all list in this packet */ 369 /* the following data is all list in this packet */
489 || purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_UNAVAILABLE)) { 490 || purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_UNAVAILABLE)) {
490 away_cmd = QQ_BUDDY_ONLINE_AWAY; 491 away_cmd = QQ_BUDDY_ONLINE_AWAY;
491 } else { 492 } else {
492 away_cmd = QQ_BUDDY_ONLINE_NORMAL; 493 away_cmd = QQ_BUDDY_ONLINE_NORMAL;
493 } 494 }
494 495
495 misc_status = 0x00000000; 496 misc_status = 0x00000000;
496 fake_video = purple_prefs_get_bool("/plugins/prpl/qq/show_fake_video"); 497 fake_video = purple_prefs_get_bool("/plugins/prpl/qq/show_fake_video");
497 if (fake_video) 498 if (fake_video)
498 misc_status |= QQ_MISC_STATUS_HAVING_VIIDEO; 499 misc_status |= QQ_MISC_STATUS_HAVING_VIIDEO;
499 500