comparison libpurple/protocols/qq/buddy_list.c @ 24146:ce94189f15ad

Flos Lonicerae <lonicerae(at)gmail.com> * Merge lonicerae and ccpaging into trunk
author SHiNE CsyFeK <csyfek@gmail.com>
date Wed, 22 Oct 2008 14:52:26 +0000
parents ec3f7d3e0445
children 1bdf7b602684
comparison
equal deleted inserted replaced
24145:ec3f7d3e0445 24146:ce94189f15ad
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 *q_bud; 254 qq_buddy *buddy;
255 gint bytes_expected, count; 255 gint bytes_expected, count;
256 gint bytes, buddy_bytes; 256 gint bytes, buddy_bytes;
257 gint nickname_len;
257 guint16 position, unknown; 258 guint16 position, unknown;
258 guint8 pascal_len; 259 gchar *purple_name;
259 gchar *name; 260 PurpleBuddy *purple_buddy;
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 q_bud = g_new0(qq_buddy, 1); 276 buddy = 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(&q_bud->uid, data + bytes); 280 bytes += qq_get32(&buddy->uid, data + bytes);
281 /* 004-005: icon index (1-255) */ 281 /* 004-005: icon index (1-255) */
282 bytes += qq_get16(&q_bud->face, data + bytes); 282 bytes += qq_get16(&buddy->face, data + bytes);
283 /* 006-006: age */ 283 /* 006-006: age */
284 bytes += qq_get8(&q_bud->age, data + bytes); 284 bytes += qq_get8(&buddy->age, data + bytes);
285 /* 007-007: gender */ 285 /* 007-007: gender */
286 bytes += qq_get8(&q_bud->gender, data + bytes); 286 bytes += qq_get8(&buddy->gender, data + bytes);
287 287
288 pascal_len = convert_as_pascal_string(data + bytes, &q_bud->nickname, QQ_CHARSET_DEFAULT); 288 nickname_len = qq_get_vstr(&buddy->nickname, QQ_CHARSET_DEFAULT, data + bytes);
289 bytes += pascal_len; 289 bytes += nickname_len;
290 qq_filter_str(q_bud->nickname); 290 qq_filter_str(buddy->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(&q_bud->ext_flag, data + bytes); 294 bytes += qq_get8(&buddy->ext_flag, data + bytes);
295 bytes += qq_get8(&q_bud->comm_flag, data + bytes); 295 bytes += qq_get8(&buddy->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 + pascal_len; 299 bytes_expected = 16 + nickname_len;
300 } else { 300 } else {
301 bytes_expected = 12 + pascal_len; 301 bytes_expected = 12 + nickname_len;
302 } 302 }
303 303
304 304 if (buddy->uid == 0 || (bytes - buddy_bytes) != bytes_expected) {
305 if (q_bud->uid == 0 || (bytes - buddy_bytes) != bytes_expected) {
306 purple_debug_info("QQ", 305 purple_debug_info("QQ",
307 "Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes - buddy_bytes); 306 "Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes - buddy_bytes);
308 g_free(q_bud->nickname); 307 g_free(buddy->nickname);
309 g_free(q_bud); 308 g_free(buddy);
310 continue; 309 continue;
311 } else { 310 } else {
312 count++; 311 count++;
313 } 312 }
314 313
315 #if 1 314 #if 1
316 purple_debug_info("QQ", "buddy [%09d]: ext_flag=0x%02x, comm_flag=0x%02x, nick=%s\n", 315 purple_debug_info("QQ", "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); 316 buddy->uid, buddy->ext_flag, buddy->comm_flag, buddy->nickname);
318 #endif 317 #endif
319 318
320 name = uid_to_purple_name(q_bud->uid); 319 purple_name = uid_to_purple_name(buddy->uid);
321 b = purple_find_buddy(gc->account, name); 320 purple_buddy = purple_find_buddy(gc->account, purple_name);
322 g_free(name); 321 g_free(purple_name);
323 322
324 if (b == NULL) { 323 if (purple_buddy == NULL) {
325 b = qq_create_buddy(gc, q_bud->uid, TRUE, FALSE); 324 purple_buddy = qq_create_buddy(gc, buddy->uid, TRUE, FALSE);
326 } 325 }
327 326
328 b->proto_data = q_bud; 327 purple_buddy->proto_data = buddy;
329 qd->buddies = g_list_append(qd->buddies, q_bud); 328 qd->buddies = g_list_append(qd->buddies, buddy);
330 qq_update_buddy_contact(gc, q_bud); 329 qq_update_buddy_contact(gc, buddy);
331 } 330 }
332 331
333 if(bytes > data_len) { 332 if(bytes > data_len) {
334 purple_debug_error("QQ", 333 purple_debug_error("QQ",
335 "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!"); 334 "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!");
359 bytes += qq_get8(&sub_cmd, data + bytes); 358 bytes += qq_get8(&sub_cmd, data + bytes);
360 g_return_val_if_fail(sub_cmd == 0x01, -1); 359 g_return_val_if_fail(sub_cmd == 0x01, -1);
361 360
362 bytes += qq_get8(&reply_code, data + bytes); 361 bytes += qq_get8(&reply_code, data + bytes);
363 if(0 != reply_code) { 362 if(0 != reply_code) {
364 purple_debug_warning("QQ", "qq_process_get_buddies_and_rooms, %d", reply_code); 363 purple_debug_warning("QQ", "qq_process_get_buddies_and_rooms, %d\n", reply_code);
365 } 364 }
366 365
367 bytes += qq_get32(&unknown, data + bytes); 366 bytes += qq_get32(&unknown, data + bytes);
368 bytes += qq_get32(&position, data + bytes); 367 bytes += qq_get32(&position, data + bytes);
369 /* the following data is all list in this packet */ 368 /* the following data is all list in this packet */
490 || purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_UNAVAILABLE)) { 489 || purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_UNAVAILABLE)) {
491 away_cmd = QQ_BUDDY_ONLINE_AWAY; 490 away_cmd = QQ_BUDDY_ONLINE_AWAY;
492 } else { 491 } else {
493 away_cmd = QQ_BUDDY_ONLINE_NORMAL; 492 away_cmd = QQ_BUDDY_ONLINE_NORMAL;
494 } 493 }
495 494
496 misc_status = 0x00000000; 495 misc_status = 0x00000000;
497 fake_video = purple_prefs_get_bool("/plugins/prpl/qq/show_fake_video"); 496 fake_video = purple_prefs_get_bool("/plugins/prpl/qq/show_fake_video");
498 if (fake_video) 497 if (fake_video)
499 misc_status |= QQ_MISC_STATUS_HAVING_VIIDEO; 498 misc_status |= QQ_MISC_STATUS_HAVING_VIIDEO;
500 499