comparison libpurple/protocols/qq/buddy_list.c @ 15823:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 0d43518fd943
children 85d5942e80e9
comparison
equal deleted inserted replaced
15822:84b0f9b23ede 15823:32c366eeeb99
1 /** 1 /**
2 * @file buddy_list.c 2 * @file buddy_list.c
3 * 3 *
4 * gaim 4 * purple
5 * 5 *
6 * Gaim is the legal property of its developers, whose names are too numerous 6 * Purple is the legal property of its developers, whose names are too numerous
7 * to list here. Please refer to the COPYRIGHT file distributed with this 7 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * source distribution. 8 * source distribution.
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
58 guint16 unknown2; 58 guint16 unknown2;
59 guint8 ending; /* 0x00 */ 59 guint8 ending; /* 0x00 */
60 } qq_friends_online_entry; 60 } qq_friends_online_entry;
61 61
62 /* get a list of online_buddies */ 62 /* get a list of online_buddies */
63 void qq_send_packet_get_buddies_online(GaimConnection *gc, guint8 position) 63 void qq_send_packet_get_buddies_online(PurpleConnection *gc, guint8 position)
64 { 64 {
65 qq_data *qd; 65 qq_data *qd;
66 guint8 *raw_data, *cursor; 66 guint8 *raw_data, *cursor;
67 67
68 qd = (qq_data *) gc->proto_data; 68 qd = (qq_data *) gc->proto_data;
85 qd->last_get_online = time(NULL); 85 qd->last_get_online = time(NULL);
86 } 86 }
87 87
88 /* position starts with 0x0000, 88 /* position starts with 0x0000,
89 * server may return a position tag if list is too long for one packet */ 89 * server may return a position tag if list is too long for one packet */
90 void qq_send_packet_get_buddies_list(GaimConnection *gc, guint16 position) 90 void qq_send_packet_get_buddies_list(PurpleConnection *gc, guint16 position)
91 { 91 {
92 guint8 *raw_data, *cursor; 92 guint8 *raw_data, *cursor;
93 gint data_len; 93 gint data_len;
94 94
95 data_len = 3; 95 data_len = 3;
106 106
107 qq_send_cmd(gc, QQ_CMD_GET_FRIENDS_LIST, TRUE, 0, TRUE, raw_data, data_len); 107 qq_send_cmd(gc, QQ_CMD_GET_FRIENDS_LIST, TRUE, 0, TRUE, raw_data, data_len);
108 } 108 }
109 109
110 /* get all list, buddies & Quns with groupsid support */ 110 /* get all list, buddies & Quns with groupsid support */
111 void qq_send_packet_get_all_list_with_group(GaimConnection *gc, guint32 position) 111 void qq_send_packet_get_all_list_with_group(PurpleConnection *gc, guint32 position)
112 { 112 {
113 guint8 *raw_data, *cursor; 113 guint8 *raw_data, *cursor;
114 gint data_len; 114 gint data_len;
115 115
116 data_len = 10; 116 data_len = 10;
140 g_string_append_printf(dump, "031-032: %04x (unknown)\n", fe->unknown1); 140 g_string_append_printf(dump, "031-032: %04x (unknown)\n", fe->unknown1);
141 g_string_append_printf(dump, "033: %02x (flag1)\n", fe->flag1); 141 g_string_append_printf(dump, "033: %02x (flag1)\n", fe->flag1);
142 g_string_append_printf(dump, "034: %02x (comm_flag)\n", fe->comm_flag); 142 g_string_append_printf(dump, "034: %02x (comm_flag)\n", fe->comm_flag);
143 g_string_append_printf(dump, "035-036: %04x (unknown)\n", fe->unknown2); 143 g_string_append_printf(dump, "035-036: %04x (unknown)\n", fe->unknown2);
144 144
145 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Online buddy entry, %s", dump->str); 145 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Online buddy entry, %s", dump->str);
146 g_string_free(dump, TRUE); 146 g_string_free(dump, TRUE);
147 } 147 }
148 148
149 /* process the reply packet for get_buddies_online packet */ 149 /* process the reply packet for get_buddies_online packet */
150 void qq_process_get_buddies_online_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 150 void qq_process_get_buddies_online_reply(guint8 *buf, gint buf_len, PurpleConnection *gc)
151 { 151 {
152 qq_data *qd; 152 qq_data *qd;
153 gint len, bytes; 153 gint len, bytes;
154 guint8 *data, *cursor, position; 154 guint8 *data, *cursor, position;
155 GaimBuddy *b; 155 PurpleBuddy *b;
156 qq_buddy *q_bud; 156 qq_buddy *q_bud;
157 qq_friends_online_entry *fe; 157 qq_friends_online_entry *fe;
158 158
159 g_return_if_fail(buf != NULL && buf_len != 0); 159 g_return_if_fail(buf != NULL && buf_len != 0);
160 160
161 qd = (qq_data *) gc->proto_data; 161 qd = (qq_data *) gc->proto_data;
162 len = buf_len; 162 len = buf_len;
163 data = g_newa(guint8, len); 163 data = g_newa(guint8, len);
164 cursor = data; 164 cursor = data;
165 165
166 gaim_debug(GAIM_DEBUG_INFO, "QQ", "processing get_buddies_online_reply\n"); 166 purple_debug(PURPLE_DEBUG_INFO, "QQ", "processing get_buddies_online_reply\n");
167 167
168 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 168 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
169 169
170 _qq_show_packet("Get buddies online reply packet", data, len); 170 _qq_show_packet("Get buddies online reply packet", data, len);
171 171
189 bytes += read_packet_w(data, &cursor, len, &fe->unknown2); 189 bytes += read_packet_w(data, &cursor, len, &fe->unknown2);
190 /* 037-037: */ 190 /* 037-037: */
191 bytes += read_packet_b(data, &cursor, len, &fe->ending); /* 0x00 */ 191 bytes += read_packet_b(data, &cursor, len, &fe->ending); /* 0x00 */
192 192
193 if (fe->s->uid == 0 || bytes != QQ_ONLINE_BUDDY_ENTRY_LEN) { 193 if (fe->s->uid == 0 || bytes != QQ_ONLINE_BUDDY_ENTRY_LEN) {
194 gaim_debug(GAIM_DEBUG_ERROR, "QQ", 194 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
195 "uid=0 or entry complete len(%d) != %d", 195 "uid=0 or entry complete len(%d) != %d",
196 bytes, QQ_ONLINE_BUDDY_ENTRY_LEN); 196 bytes, QQ_ONLINE_BUDDY_ENTRY_LEN);
197 g_free(fe->s->ip); 197 g_free(fe->s->ip);
198 g_free(fe->s->unknown_key); 198 g_free(fe->s->unknown_key);
199 continue; 199 continue;
201 201
202 if (QQ_DEBUG) 202 if (QQ_DEBUG)
203 _qq_buddies_online_reply_dump_unclear(fe); 203 _qq_buddies_online_reply_dump_unclear(fe);
204 204
205 /* update buddy information */ 205 /* update buddy information */
206 b = gaim_find_buddy(gaim_connection_get_account(gc), uid_to_gaim_name(fe->s->uid)); 206 b = purple_find_buddy(purple_connection_get_account(gc), uid_to_purple_name(fe->s->uid));
207 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; 207 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
208 208
209 if (q_bud != NULL) { /* we find one and update qq_buddy */ 209 if (q_bud != NULL) { /* we find one and update qq_buddy */
210 if(0 != fe->s->client_version) 210 if(0 != fe->s->client_version)
211 q_bud->client_version = fe->s->client_version; 211 q_bud->client_version = fe->s->client_version;
214 q_bud->status = fe->s->status; 214 q_bud->status = fe->s->status;
215 q_bud->flag1 = fe->flag1; 215 q_bud->flag1 = fe->flag1;
216 q_bud->comm_flag = fe->comm_flag; 216 q_bud->comm_flag = fe->comm_flag;
217 qq_update_buddy_contact(gc, q_bud); 217 qq_update_buddy_contact(gc, q_bud);
218 } else { 218 } else {
219 gaim_debug(GAIM_DEBUG_ERROR, "QQ", 219 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
220 "Got an online buddy %d, but not in my buddy list\n", fe->s->uid); 220 "Got an online buddy %d, but not in my buddy list\n", fe->s->uid);
221 } 221 }
222 222
223 g_free(fe->s->ip); 223 g_free(fe->s->ip);
224 g_free(fe->s->unknown_key); 224 g_free(fe->s->unknown_key);
225 } 225 }
226 226
227 if(cursor > (data + len)) { 227 if(cursor > (data + len)) {
228 gaim_debug(GAIM_DEBUG_ERROR, "QQ", 228 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
229 "qq_process_get_buddies_online_reply: Dangerous error! maybe protocol changed, notify developers!\n"); 229 "qq_process_get_buddies_online_reply: Dangerous error! maybe protocol changed, notify developers!\n");
230 } 230 }
231 231
232 if (position != QQ_FRIENDS_ONLINE_POSITION_END) { 232 if (position != QQ_FRIENDS_ONLINE_POSITION_END) {
233 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Has more online buddies, position from %d\n", position); 233 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Has more online buddies, position from %d\n", position);
234 234
235 qq_send_packet_get_buddies_online(gc, position); 235 qq_send_packet_get_buddies_online(gc, position);
236 } else { 236 } else {
237 /* qq_send_packet_get_buddies_levels(gc); */ 237 /* qq_send_packet_get_buddies_levels(gc); */
238 qq_refresh_all_buddy_status(gc); 238 qq_refresh_all_buddy_status(gc);
239 } 239 }
240 240
241 } else { 241 } else {
242 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddies online"); 242 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt buddies online");
243 } 243 }
244 } 244 }
245 245
246 /* process reply for get_buddies_list */ 246 /* process reply for get_buddies_list */
247 void qq_process_get_buddies_list_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 247 void qq_process_get_buddies_list_reply(guint8 *buf, gint buf_len, PurpleConnection *gc)
248 { 248 {
249 qq_data *qd; 249 qq_data *qd;
250 qq_buddy *q_bud; 250 qq_buddy *q_bud;
251 gint len, bytes, bytes_expected, i; 251 gint len, bytes, bytes_expected, i;
252 guint16 position, unknown; 252 guint16 position, unknown;
253 guint8 *data, *cursor, pascal_len; 253 guint8 *data, *cursor, pascal_len;
254 gchar *name; 254 gchar *name;
255 GaimBuddy *b; 255 PurpleBuddy *b;
256 256
257 g_return_if_fail(buf != NULL && buf_len != 0); 257 g_return_if_fail(buf != NULL && buf_len != 0);
258 258
259 qd = (qq_data *) gc->proto_data; 259 qd = (qq_data *) gc->proto_data;
260 len = buf_len; 260 len = buf_len;
293 bytes += read_packet_b(data, &cursor, len, &q_bud->comm_flag); 293 bytes += read_packet_b(data, &cursor, len, &q_bud->comm_flag);
294 294
295 bytes_expected = 12 + pascal_len; 295 bytes_expected = 12 + pascal_len;
296 296
297 if (q_bud->uid == 0 || bytes != bytes_expected) { 297 if (q_bud->uid == 0 || bytes != bytes_expected) {
298 gaim_debug(GAIM_DEBUG_INFO, "QQ", 298 purple_debug(PURPLE_DEBUG_INFO, "QQ",
299 "Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes); 299 "Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes);
300 g_free(q_bud->nickname); 300 g_free(q_bud->nickname);
301 g_free(q_bud); 301 g_free(q_bud);
302 continue; 302 continue;
303 } else { 303 } else {
304 i++; 304 i++;
305 } 305 }
306 306
307 if (QQ_DEBUG) { 307 if (QQ_DEBUG) {
308 gaim_debug(GAIM_DEBUG_INFO, "QQ", 308 purple_debug(PURPLE_DEBUG_INFO, "QQ",
309 "buddy [%09d]: flag1=0x%02x, comm_flag=0x%02x\n", 309 "buddy [%09d]: flag1=0x%02x, comm_flag=0x%02x\n",
310 q_bud->uid, q_bud->flag1, q_bud->comm_flag); 310 q_bud->uid, q_bud->flag1, q_bud->comm_flag);
311 } 311 }
312 312
313 name = uid_to_gaim_name(q_bud->uid); 313 name = uid_to_purple_name(q_bud->uid);
314 b = gaim_find_buddy(gc->account, name); 314 b = purple_find_buddy(gc->account, name);
315 g_free(name); 315 g_free(name);
316 316
317 if (b == NULL) 317 if (b == NULL)
318 b = qq_add_buddy_by_recv_packet(gc, q_bud->uid, TRUE, FALSE); 318 b = qq_add_buddy_by_recv_packet(gc, q_bud->uid, TRUE, FALSE);
319 319
321 qd->buddies = g_list_append(qd->buddies, q_bud); 321 qd->buddies = g_list_append(qd->buddies, q_bud);
322 qq_update_buddy_contact(gc, q_bud); 322 qq_update_buddy_contact(gc, q_bud);
323 } 323 }
324 324
325 if(cursor > (data + len)) { 325 if(cursor > (data + len)) {
326 gaim_debug(GAIM_DEBUG_ERROR, "QQ", 326 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
327 "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!"); 327 "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!");
328 } 328 }
329 if (position == QQ_FRIENDS_LIST_POSITION_END) { 329 if (position == QQ_FRIENDS_LIST_POSITION_END) {
330 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Get friends list done, %d buddies\n", i); 330 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Get friends list done, %d buddies\n", i);
331 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START); 331 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START);
332 } else { 332 } else {
333 qq_send_packet_get_buddies_list(gc, position); 333 qq_send_packet_get_buddies_list(gc, position);
334 } 334 }
335 } else { 335 } else {
336 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddies list"); 336 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt buddies list");
337 } 337 }
338 } 338 }
339 339
340 void qq_process_get_all_list_with_group_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 340 void qq_process_get_all_list_with_group_reply(guint8 *buf, gint buf_len, PurpleConnection *gc)
341 { 341 {
342 qq_data *qd; 342 qq_data *qd;
343 gint len, i, j; 343 gint len, i, j;
344 guint8 *data, *cursor; 344 guint8 *data, *cursor;
345 guint8 sub_cmd, reply_code; 345 guint8 sub_cmd, reply_code;
358 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 358 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
359 read_packet_b(data, &cursor, len, &sub_cmd); 359 read_packet_b(data, &cursor, len, &sub_cmd);
360 g_return_if_fail(sub_cmd == 0x01); 360 g_return_if_fail(sub_cmd == 0x01);
361 read_packet_b(data, &cursor, len, &reply_code); 361 read_packet_b(data, &cursor, len, &reply_code);
362 if(0 != reply_code) { 362 if(0 != reply_code) {
363 gaim_debug(GAIM_DEBUG_WARNING, "QQ", 363 purple_debug(PURPLE_DEBUG_WARNING, "QQ",
364 "Get all list with group reply, reply_code(%d) is not zero", reply_code); 364 "Get all list with group reply, reply_code(%d) is not zero", reply_code);
365 } 365 }
366 read_packet_dw(data, &cursor, len, &unknown); 366 read_packet_dw(data, &cursor, len, &unknown);
367 read_packet_dw(data, &cursor, len, &position); 367 read_packet_dw(data, &cursor, len, &position);
368 /* the following data is all list in this packet */ 368 /* the following data is all list in this packet */
374 /* 04: type 0x1:buddy 0x4:Qun */ 374 /* 04: type 0x1:buddy 0x4:Qun */
375 read_packet_b(data, &cursor, len, &type); 375 read_packet_b(data, &cursor, len, &type);
376 /* 05: groupid*4 */ /* seems to always be 0 */ 376 /* 05: groupid*4 */ /* seems to always be 0 */
377 read_packet_b(data, &cursor, len, &groupid); 377 read_packet_b(data, &cursor, len, &groupid);
378 /* 378 /*
379 gaim_debug(GAIM_DEBUG_INFO, "QQ", "groupid: %i\n", groupid); 379 purple_debug(PURPLE_DEBUG_INFO, "QQ", "groupid: %i\n", groupid);
380 groupid >>= 2; 380 groupid >>= 2;
381 */ 381 */
382 if (uid == 0 || (type != 0x1 && type != 0x4)) { 382 if (uid == 0 || (type != 0x1 && type != 0x4)) {
383 gaim_debug(GAIM_DEBUG_INFO, "QQ", 383 purple_debug(PURPLE_DEBUG_INFO, "QQ",
384 "Buddy entry, uid=%d, type=%d", uid, type); 384 "Buddy entry, uid=%d, type=%d", uid, type);
385 continue; 385 continue;
386 } 386 }
387 if(0x1 == type) { /* a buddy */ 387 if(0x1 == type) { /* a buddy */
388 /* don't do anything but count - buddies are handled by 388 /* don't do anything but count - buddies are handled by
402 } 402 }
403 ++j; 403 ++j;
404 } 404 }
405 } 405 }
406 if(cursor > (data + len)) { 406 if(cursor > (data + len)) {
407 gaim_debug(GAIM_DEBUG_ERROR, "QQ", 407 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
408 "qq_process_get_all_list_with_group_reply: Dangerous error! maybe protocol changed, notify developers!"); 408 "qq_process_get_all_list_with_group_reply: Dangerous error! maybe protocol changed, notify developers!");
409 } 409 }
410 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Get all list done, %d buddies and %d Quns\n", i, j); 410 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Get all list done, %d buddies and %d Quns\n", i, j);
411 } else { 411 } else {
412 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt all list with group"); 412 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt all list with group");
413 } 413 }
414 } 414 }