comparison libpurple/protocols/qq/buddy_opt.c @ 15822:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 5fe8042783c1
children 08db93bbd798
comparison
equal deleted inserted replaced
15821:84b0f9b23ede 15822:32c366eeeb99
1 /** 1 /**
2 * @file buddy_opt.c 2 * @file buddy_opt.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
37 #include "keep_alive.h" 37 #include "keep_alive.h"
38 #include "packet_parse.h" 38 #include "packet_parse.h"
39 #include "send_core.h" 39 #include "send_core.h"
40 #include "utils.h" 40 #include "utils.h"
41 41
42 #define GAIM_GROUP_QQ_FORMAT "QQ (%s)" 42 #define PURPLE_GROUP_QQ_FORMAT "QQ (%s)"
43 #define GAIM_GROUP_QQ_UNKNOWN "QQ Unknown" 43 #define PURPLE_GROUP_QQ_UNKNOWN "QQ Unknown"
44 #define GAIM_GROUP_QQ_BLOCKED "QQ Blocked" 44 #define PURPLE_GROUP_QQ_BLOCKED "QQ Blocked"
45 45
46 #define QQ_REMOVE_BUDDY_REPLY_OK 0x00 46 #define QQ_REMOVE_BUDDY_REPLY_OK 0x00
47 #define QQ_REMOVE_SELF_REPLY_OK 0x00 47 #define QQ_REMOVE_SELF_REPLY_OK 0x00
48 #define QQ_ADD_BUDDY_AUTH_REPLY_OK 0x30 /* ASCII value of "0" */ 48 #define QQ_ADD_BUDDY_AUTH_REPLY_OK 0x30 /* ASCII value of "0" */
49 49
57 guint32 uid; 57 guint32 uid;
58 guint16 seq; 58 guint16 seq;
59 } qq_add_buddy_request; 59 } qq_add_buddy_request;
60 60
61 /* send packet to remove a buddy from my buddy list */ 61 /* send packet to remove a buddy from my buddy list */
62 static void _qq_send_packet_remove_buddy(GaimConnection *gc, guint32 uid) 62 static void _qq_send_packet_remove_buddy(PurpleConnection *gc, guint32 uid)
63 { 63 {
64 gchar uid_str[11]; 64 gchar uid_str[11];
65 65
66 g_return_if_fail(uid > 0); 66 g_return_if_fail(uid > 0);
67 67
69 qq_send_cmd(gc, QQ_CMD_DEL_FRIEND, TRUE, 0, 69 qq_send_cmd(gc, QQ_CMD_DEL_FRIEND, TRUE, 0,
70 TRUE, (guint8 *) uid_str, strlen(uid_str)); 70 TRUE, (guint8 *) uid_str, strlen(uid_str));
71 } 71 }
72 72
73 /* try to remove myself from someone's buddy list */ 73 /* try to remove myself from someone's buddy list */
74 static void _qq_send_packet_remove_self_from(GaimConnection *gc, guint32 uid) 74 static void _qq_send_packet_remove_self_from(PurpleConnection *gc, guint32 uid)
75 { 75 {
76 guint8 *raw_data, *cursor; 76 guint8 *raw_data, *cursor;
77 77
78 g_return_if_fail(uid > 0); 78 g_return_if_fail(uid > 0);
79 79
83 83
84 qq_send_cmd(gc, QQ_CMD_REMOVE_SELF, TRUE, 0, TRUE, raw_data, 4); 84 qq_send_cmd(gc, QQ_CMD_REMOVE_SELF, TRUE, 0, TRUE, raw_data, 4);
85 } 85 }
86 86
87 /* try to add a buddy without authentication */ 87 /* try to add a buddy without authentication */
88 static void _qq_send_packet_add_buddy(GaimConnection *gc, guint32 uid) 88 static void _qq_send_packet_add_buddy(PurpleConnection *gc, guint32 uid)
89 { 89 {
90 qq_data *qd; 90 qq_data *qd;
91 qq_add_buddy_request *req; 91 qq_add_buddy_request *req;
92 gchar uid_str[11]; 92 gchar uid_str[11];
93 93
105 req->uid = uid; 105 req->uid = uid;
106 qd->add_buddy_request = g_list_append(qd->add_buddy_request, req); 106 qd->add_buddy_request = g_list_append(qd->add_buddy_request, req);
107 } 107 }
108 108
109 /* this buddy needs authentication, text conversion is done at lowest level */ 109 /* this buddy needs authentication, text conversion is done at lowest level */
110 static void _qq_send_packet_buddy_auth(GaimConnection *gc, guint32 uid, const gchar response, const gchar *text) 110 static void _qq_send_packet_buddy_auth(PurpleConnection *gc, guint32 uid, const gchar response, const gchar *text)
111 { 111 {
112 gchar *text_qq, uid_str[11]; 112 gchar *text_qq, uid_str[11];
113 guint8 bar, *cursor, *raw_data; 113 guint8 bar, *cursor, *raw_data;
114 114
115 g_return_if_fail(uid != 0); 115 g_return_if_fail(uid != 0);
133 qq_send_cmd(gc, QQ_CMD_BUDDY_AUTH, TRUE, 0, TRUE, raw_data, cursor - raw_data); 133 qq_send_cmd(gc, QQ_CMD_BUDDY_AUTH, TRUE, 0, TRUE, raw_data, cursor - raw_data);
134 } 134 }
135 135
136 static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid *g, const gchar *text) 136 static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid *g, const gchar *text)
137 { 137 {
138 GaimConnection *gc; 138 PurpleConnection *gc;
139 guint32 uid; 139 guint32 uid;
140 g_return_if_fail(g != NULL); 140 g_return_if_fail(g != NULL);
141 141
142 gc = g->gc; 142 gc = g->gc;
143 uid = g->uid; 143 uid = g->uid;
149 149
150 /* the real packet to reject and request is sent from here */ 150 /* the real packet to reject and request is sent from here */
151 static void _qq_reject_add_request_real(gc_and_uid *g, const gchar *reason) 151 static void _qq_reject_add_request_real(gc_and_uid *g, const gchar *reason)
152 { 152 {
153 gint uid; 153 gint uid;
154 GaimConnection *gc; 154 PurpleConnection *gc;
155 155
156 g_return_if_fail(g != NULL); 156 g_return_if_fail(g != NULL);
157 157
158 gc = g->gc; 158 gc = g->gc;
159 uid = g->uid; 159 uid = g->uid;
165 165
166 /* we approve other's request of adding me as friend */ 166 /* we approve other's request of adding me as friend */
167 void qq_approve_add_request_with_gc_and_uid(gc_and_uid *g) 167 void qq_approve_add_request_with_gc_and_uid(gc_and_uid *g)
168 { 168 {
169 gint uid; 169 gint uid;
170 GaimConnection *gc; 170 PurpleConnection *gc;
171 171
172 g_return_if_fail(g != NULL); 172 g_return_if_fail(g != NULL);
173 173
174 gc = g->gc; 174 gc = g->gc;
175 uid = g->uid; 175 uid = g->uid;
187 /* we reject other's request of adding me as friend */ 187 /* we reject other's request of adding me as friend */
188 void qq_reject_add_request_with_gc_and_uid(gc_and_uid *g) 188 void qq_reject_add_request_with_gc_and_uid(gc_and_uid *g)
189 { 189 {
190 gint uid; 190 gint uid;
191 gchar *msg1, *msg2; 191 gchar *msg1, *msg2;
192 GaimConnection *gc; 192 PurpleConnection *gc;
193 gc_and_uid *g2; 193 gc_and_uid *g2;
194 194
195 g_return_if_fail(g != NULL); 195 g_return_if_fail(g != NULL);
196 196
197 gc = g->gc; 197 gc = g->gc;
205 g2->uid = uid; 205 g2->uid = uid;
206 206
207 msg1 = g_strdup_printf(_("You rejected %d's request"), uid); 207 msg1 = g_strdup_printf(_("You rejected %d's request"), uid);
208 msg2 = g_strdup(_("Input your reason:")); 208 msg2 = g_strdup(_("Input your reason:"));
209 209
210 gaim_request_input(gc, _("Reject request"), msg1, msg2, 210 purple_request_input(gc, _("Reject request"), msg1, msg2,
211 _("Sorry, you are not my type..."), TRUE, FALSE, 211 _("Sorry, you are not my type..."), TRUE, FALSE,
212 NULL, _("Reject"), G_CALLBACK(_qq_reject_add_request_real), _("Cancel"), NULL, g2); 212 NULL, _("Reject"), G_CALLBACK(_qq_reject_add_request_real), _("Cancel"), NULL, g2);
213 } 213 }
214 214
215 void qq_add_buddy_with_gc_and_uid(gc_and_uid *g) 215 void qq_add_buddy_with_gc_and_uid(gc_and_uid *g)
216 { 216 {
217 gint uid; 217 gint uid;
218 GaimConnection *gc; 218 PurpleConnection *gc;
219 219
220 g_return_if_fail(g != NULL); 220 g_return_if_fail(g != NULL);
221 221
222 gc = g->gc; 222 gc = g->gc;
223 uid = g->uid; 223 uid = g->uid;
228 } 228 }
229 229
230 void qq_block_buddy_with_gc_and_uid(gc_and_uid *g) 230 void qq_block_buddy_with_gc_and_uid(gc_and_uid *g)
231 { 231 {
232 guint32 uid; 232 guint32 uid;
233 GaimConnection *gc; 233 PurpleConnection *gc;
234 GaimBuddy buddy; 234 PurpleBuddy buddy;
235 GaimGroup group; 235 PurpleGroup group;
236 236
237 g_return_if_fail(g != NULL); 237 g_return_if_fail(g != NULL);
238 238
239 gc = g->gc; 239 gc = g->gc;
240 uid = g->uid; 240 uid = g->uid;
241 g_return_if_fail(uid > 0); 241 g_return_if_fail(uid > 0);
242 242
243 buddy.name = uid_to_gaim_name(uid); 243 buddy.name = uid_to_purple_name(uid);
244 group.name = GAIM_GROUP_QQ_BLOCKED; 244 group.name = PURPLE_GROUP_QQ_BLOCKED;
245 245
246 qq_remove_buddy(gc, &buddy, &group); 246 qq_remove_buddy(gc, &buddy, &group);
247 _qq_send_packet_remove_self_from(gc, uid); 247 _qq_send_packet_remove_self_from(gc, uid);
248 } 248 }
249 249
250 /* process reply to add_buddy_auth request */ 250 /* process reply to add_buddy_auth request */
251 void qq_process_add_buddy_auth_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 251 void qq_process_add_buddy_auth_reply(guint8 *buf, gint buf_len, PurpleConnection *gc)
252 { 252 {
253 qq_data *qd; 253 qq_data *qd;
254 gint len; 254 gint len;
255 guint8 *data, *cursor, reply; 255 guint8 *data, *cursor, reply;
256 gchar **segments, *msg_utf8; 256 gchar **segments, *msg_utf8;
263 cursor = data; 263 cursor = data;
264 264
265 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 265 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
266 read_packet_b(data, &cursor, len, &reply); 266 read_packet_b(data, &cursor, len, &reply);
267 if (reply != QQ_ADD_BUDDY_AUTH_REPLY_OK) { 267 if (reply != QQ_ADD_BUDDY_AUTH_REPLY_OK) {
268 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add buddy with auth request fails\n"); 268 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Add buddy with auth request fails\n");
269 if (NULL == (segments = split_data(data, len, "\x1f", 2))) 269 if (NULL == (segments = split_data(data, len, "\x1f", 2)))
270 return; 270 return;
271 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); 271 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT);
272 gaim_notify_error(gc, NULL, _("Add buddy with auth request fails"), msg_utf8); 272 purple_notify_error(gc, NULL, _("Add buddy with auth request fails"), msg_utf8);
273 g_free(msg_utf8); 273 g_free(msg_utf8);
274 } else { 274 } else {
275 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Add buddy with auth request OK\n"); 275 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Add buddy with auth request OK\n");
276 } 276 }
277 } else { 277 } else {
278 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt add buddy with auth reply\n"); 278 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt add buddy with auth reply\n");
279 } 279 }
280 } 280 }
281 281
282 /* process the server reply for my request to remove a buddy */ 282 /* process the server reply for my request to remove a buddy */
283 void qq_process_remove_buddy_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 283 void qq_process_remove_buddy_reply(guint8 *buf, gint buf_len, PurpleConnection *gc)
284 { 284 {
285 qq_data *qd; 285 qq_data *qd;
286 gint len; 286 gint len;
287 guint8 *data, *cursor, reply; 287 guint8 *data, *cursor, reply;
288 288
295 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 295 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
296 cursor = data; 296 cursor = data;
297 read_packet_b(data, &cursor, len, &reply); 297 read_packet_b(data, &cursor, len, &reply);
298 if (reply != QQ_REMOVE_BUDDY_REPLY_OK) { 298 if (reply != QQ_REMOVE_BUDDY_REPLY_OK) {
299 /* there is no reason return from server */ 299 /* there is no reason return from server */
300 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Remove buddy fails\n"); 300 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Remove buddy fails\n");
301 } else { /* if reply */ 301 } else { /* if reply */
302 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Remove buddy OK\n"); 302 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Remove buddy OK\n");
303 gaim_notify_info(gc, NULL, _("You have successfully removed a buddy"), NULL); 303 purple_notify_info(gc, NULL, _("You have successfully removed a buddy"), NULL);
304 } 304 }
305 } else { 305 } else {
306 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt remove buddy reply\n"); 306 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt remove buddy reply\n");
307 } 307 }
308 } 308 }
309 309
310 /* process the server reply for my request to remove myself from a buddy */ 310 /* process the server reply for my request to remove myself from a buddy */
311 void qq_process_remove_self_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 311 void qq_process_remove_self_reply(guint8 *buf, gint buf_len, PurpleConnection *gc)
312 { 312 {
313 qq_data *qd; 313 qq_data *qd;
314 gint len; 314 gint len;
315 guint8 *data, *cursor, reply; 315 guint8 *data, *cursor, reply;
316 316
323 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 323 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
324 cursor = data; 324 cursor = data;
325 read_packet_b(data, &cursor, len, &reply); 325 read_packet_b(data, &cursor, len, &reply);
326 if (reply != QQ_REMOVE_SELF_REPLY_OK) 326 if (reply != QQ_REMOVE_SELF_REPLY_OK)
327 /* there is no reason return from server */ 327 /* there is no reason return from server */
328 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Remove self fails\n"); 328 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Remove self fails\n");
329 else { /* if reply */ 329 else { /* if reply */
330 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Remove self from a buddy OK\n"); 330 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Remove self from a buddy OK\n");
331 gaim_notify_info(gc, NULL, _("You have successfully removed yourself from a buddy"), NULL); 331 purple_notify_info(gc, NULL, _("You have successfully removed yourself from a buddy"), NULL);
332 } 332 }
333 } else { 333 } else {
334 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt remove self reply\n"); 334 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt remove self reply\n");
335 } 335 }
336 } 336 }
337 337
338 void qq_process_add_buddy_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc) 338 void qq_process_add_buddy_reply(guint8 *buf, gint buf_len, guint16 seq, PurpleConnection *gc)
339 { 339 {
340 qq_data *qd; 340 qq_data *qd;
341 gint len, for_uid; 341 gint len, for_uid;
342 gchar *msg, **segments, *uid, *reply; 342 gchar *msg, **segments, *uid, *reply;
343 guint8 *data; 343 guint8 *data;
344 GList *list; 344 GList *list;
345 GaimBuddy *b; 345 PurpleBuddy *b;
346 gc_and_uid *g; 346 gc_and_uid *g;
347 qq_add_buddy_request *req; 347 qq_add_buddy_request *req;
348 348
349 g_return_if_fail(buf != NULL && buf_len != 0); 349 g_return_if_fail(buf != NULL && buf_len != 0);
350 350
363 } 363 }
364 list = list->next; 364 list = list->next;
365 } 365 }
366 366
367 if (for_uid == 0) { /* we have no record for this */ 367 if (for_uid == 0) { /* we have no record for this */
368 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "We have no record for add buddy reply [%d], discard\n", seq); 368 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "We have no record for add buddy reply [%d], discard\n", seq);
369 return; 369 return;
370 } else { 370 } else {
371 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Add buddy reply [%d] is for id [%d]\n", seq, for_uid); 371 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Add buddy reply [%d] is for id [%d]\n", seq, for_uid);
372 } 372 }
373 373
374 data = g_newa(guint8, len); 374 data = g_newa(guint8, len);
375 375
376 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 376 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
377 if (NULL == (segments = split_data(data, len, "\x1f", 2))) 377 if (NULL == (segments = split_data(data, len, "\x1f", 2)))
378 return; 378 return;
379 uid = segments[0]; 379 uid = segments[0];
380 reply = segments[1]; 380 reply = segments[1];
381 if (strtol(uid, NULL, 10) != qd->uid) { /* should not happen */ 381 if (strtol(uid, NULL, 10) != qd->uid) { /* should not happen */
382 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Add buddy reply is to [%s], not me!", uid); 382 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Add buddy reply is to [%s], not me!", uid);
383 g_strfreev(segments); 383 g_strfreev(segments);
384 return; 384 return;
385 } 385 }
386 386
387 if (strtol(reply, NULL, 10) > 0) { /* need auth */ 387 if (strtol(reply, NULL, 10) > 0) { /* need auth */
388 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add buddy attempt fails, need authentication\n"); 388 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Add buddy attempt fails, need authentication\n");
389 b = gaim_find_buddy(gc->account, uid_to_gaim_name(for_uid)); 389 b = purple_find_buddy(gc->account, uid_to_purple_name(for_uid));
390 if (b != NULL) 390 if (b != NULL)
391 gaim_blist_remove_buddy(b); 391 purple_blist_remove_buddy(b);
392 g = g_new0(gc_and_uid, 1); 392 g = g_new0(gc_and_uid, 1);
393 g->gc = gc; 393 g->gc = gc;
394 g->uid = for_uid; 394 g->uid = for_uid;
395 msg = g_strdup_printf(_("User %d needs authentication"), for_uid); 395 msg = g_strdup_printf(_("User %d needs authentication"), for_uid);
396 gaim_request_input(gc, NULL, msg, 396 purple_request_input(gc, NULL, msg,
397 _("Input request here"), 397 _("Input request here"),
398 _("Would you be my friend?"), 398 _("Would you be my friend?"),
399 TRUE, FALSE, NULL, _("Send"), 399 TRUE, FALSE, NULL, _("Send"),
400 G_CALLBACK 400 G_CALLBACK
401 (_qq_send_packet_add_buddy_auth_with_gc_and_uid), 401 (_qq_send_packet_add_buddy_auth_with_gc_and_uid),
402 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g); 402 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g);
403 g_free(msg); 403 g_free(msg);
404 } else { /* add OK */ 404 } else { /* add OK */
405 qq_add_buddy_by_recv_packet(gc, for_uid, TRUE, TRUE); 405 qq_add_buddy_by_recv_packet(gc, for_uid, TRUE, TRUE);
406 msg = g_strdup_printf(_("You have added %d in buddy list"), for_uid); 406 msg = g_strdup_printf(_("You have added %d in buddy list"), for_uid);
407 gaim_notify_info(gc, NULL, msg, NULL); 407 purple_notify_info(gc, NULL, msg, NULL);
408 g_free(msg); 408 g_free(msg);
409 } 409 }
410 g_strfreev(segments); 410 g_strfreev(segments);
411 } else { 411 } else {
412 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt add buddy reply\n"); 412 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt add buddy reply\n");
413 } 413 }
414 } 414 }
415 415
416 GaimGroup *qq_get_gaim_group(const gchar *group_name) 416 PurpleGroup *qq_get_purple_group(const gchar *group_name)
417 { 417 {
418 GaimGroup *g; 418 PurpleGroup *g;
419 419
420 g_return_val_if_fail(group_name != NULL, NULL); 420 g_return_val_if_fail(group_name != NULL, NULL);
421 421
422 g = gaim_find_group(group_name); 422 g = purple_find_group(group_name);
423 if (g == NULL) { 423 if (g == NULL) {
424 g = gaim_group_new(group_name); 424 g = purple_group_new(group_name);
425 gaim_blist_add_group(g, NULL); 425 purple_blist_add_group(g, NULL);
426 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add new group: %s\n", group_name); 426 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Add new group: %s\n", group_name);
427 } 427 }
428 428
429 return g; 429 return g;
430 } 430 }
431 431
432 /* we add new buddy, if the received packet is from someone not in my list 432 /* we add new buddy, if the received packet is from someone not in my list
433 * return the GaimBuddy that is just created */ 433 * return the PurpleBuddy that is just created */
434 GaimBuddy *qq_add_buddy_by_recv_packet(GaimConnection *gc, guint32 uid, gboolean is_known, gboolean create) 434 PurpleBuddy *qq_add_buddy_by_recv_packet(PurpleConnection *gc, guint32 uid, gboolean is_known, gboolean create)
435 { 435 {
436 GaimAccount *a; 436 PurpleAccount *a;
437 GaimBuddy *b; 437 PurpleBuddy *b;
438 GaimGroup *g; 438 PurpleGroup *g;
439 qq_data *qd; 439 qq_data *qd;
440 qq_buddy *q_bud; 440 qq_buddy *q_bud;
441 gchar *name, *group_name; 441 gchar *name, *group_name;
442 442
443 a = gc->account; 443 a = gc->account;
444 qd = (qq_data *) gc->proto_data; 444 qd = (qq_data *) gc->proto_data;
445 g_return_val_if_fail(a != NULL && uid != 0, NULL); 445 g_return_val_if_fail(a != NULL && uid != 0, NULL);
446 446
447 group_name = is_known ? 447 group_name = is_known ?
448 g_strdup_printf(GAIM_GROUP_QQ_FORMAT, gaim_account_get_username(a)) : g_strdup(GAIM_GROUP_QQ_UNKNOWN); 448 g_strdup_printf(PURPLE_GROUP_QQ_FORMAT, purple_account_get_username(a)) : g_strdup(PURPLE_GROUP_QQ_UNKNOWN);
449 449
450 g = qq_get_gaim_group(group_name); 450 g = qq_get_purple_group(group_name);
451 451
452 name = uid_to_gaim_name(uid); 452 name = uid_to_purple_name(uid);
453 b = gaim_find_buddy(gc->account, name); 453 b = purple_find_buddy(gc->account, name);
454 /* remove old, we can not simply return here 454 /* remove old, we can not simply return here
455 * because there might be old local copy of this buddy */ 455 * because there might be old local copy of this buddy */
456 if (b != NULL) 456 if (b != NULL)
457 gaim_blist_remove_buddy(b); 457 purple_blist_remove_buddy(b);
458 458
459 b = gaim_buddy_new(a, name, NULL); 459 b = purple_buddy_new(a, name, NULL);
460 460
461 if (!create) 461 if (!create)
462 b->proto_data = NULL; 462 b->proto_data = NULL;
463 else { 463 else {
464 q_bud = g_new0(qq_buddy, 1); 464 q_bud = g_new0(qq_buddy, 1);
467 qd->buddies = g_list_append(qd->buddies, q_bud); 467 qd->buddies = g_list_append(qd->buddies, q_bud);
468 qq_send_packet_get_info(gc, q_bud->uid, FALSE); 468 qq_send_packet_get_info(gc, q_bud->uid, FALSE);
469 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START); 469 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START);
470 } 470 }
471 471
472 gaim_blist_add_buddy(b, NULL, g, NULL); 472 purple_blist_add_buddy(b, NULL, g, NULL);
473 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add new buddy: [%s]\n", name); 473 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Add new buddy: [%s]\n", name);
474 474
475 g_free(name); 475 g_free(name);
476 g_free(group_name); 476 g_free(group_name);
477 477
478 return b; 478 return b;
479 } 479 }
480 480
481 /* add a buddy and send packet to QQ server 481 /* add a buddy and send packet to QQ server
482 * note that when gaim load local cached buddy list into its blist 482 * note that when purple load local cached buddy list into its blist
483 * it also calls this funtion, so we have to 483 * it also calls this funtion, so we have to
484 * define qd->logged_in=TRUE AFTER serv_finish_login(gc) */ 484 * define qd->logged_in=TRUE AFTER serv_finish_login(gc) */
485 void qq_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) 485 void qq_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
486 { 486 {
487 qq_data *qd; 487 qq_data *qd;
488 guint32 uid; 488 guint32 uid;
489 GaimBuddy *b; 489 PurpleBuddy *b;
490 490
491 qd = (qq_data *) gc->proto_data; 491 qd = (qq_data *) gc->proto_data;
492 if (!qd->logged_in) 492 if (!qd->logged_in)
493 return; /* IMPORTANT ! */ 493 return; /* IMPORTANT ! */
494 494
495 uid = gaim_name_to_uid(buddy->name); 495 uid = purple_name_to_uid(buddy->name);
496 if (uid > 0) 496 if (uid > 0)
497 _qq_send_packet_add_buddy(gc, uid); 497 _qq_send_packet_add_buddy(gc, uid);
498 else { 498 else {
499 b = gaim_find_buddy(gc->account, buddy->name); 499 b = purple_find_buddy(gc->account, buddy->name);
500 if (b != NULL) 500 if (b != NULL)
501 gaim_blist_remove_buddy(b); 501 purple_blist_remove_buddy(b);
502 gaim_notify_error(gc, NULL, 502 purple_notify_error(gc, NULL,
503 _("QQid Error"), 503 _("QQid Error"),
504 _("Invalid QQid")); 504 _("Invalid QQid"));
505 } 505 }
506 } 506 }
507 507
508 /* remove a buddy and send packet to QQ server accordingly */ 508 /* remove a buddy and send packet to QQ server accordingly */
509 void qq_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) 509 void qq_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
510 { 510 {
511 qq_data *qd; 511 qq_data *qd;
512 GaimBuddy *b; 512 PurpleBuddy *b;
513 qq_buddy *q_bud; 513 qq_buddy *q_bud;
514 guint32 uid; 514 guint32 uid;
515 515
516 qd = (qq_data *) gc->proto_data; 516 qd = (qq_data *) gc->proto_data;
517 uid = gaim_name_to_uid(buddy->name); 517 uid = purple_name_to_uid(buddy->name);
518 518
519 if (!qd->logged_in) 519 if (!qd->logged_in)
520 return; 520 return;
521 521
522 if (uid > 0) 522 if (uid > 0)
523 _qq_send_packet_remove_buddy(gc, uid); 523 _qq_send_packet_remove_buddy(gc, uid);
524 524
525 b = gaim_find_buddy(gc->account, buddy->name); 525 b = purple_find_buddy(gc->account, buddy->name);
526 if (b != NULL) { 526 if (b != NULL) {
527 q_bud = (qq_buddy *) b->proto_data; 527 q_bud = (qq_buddy *) b->proto_data;
528 if (q_bud != NULL) 528 if (q_bud != NULL)
529 qd->buddies = g_list_remove(qd->buddies, q_bud); 529 qd->buddies = g_list_remove(qd->buddies, q_bud);
530 else 530 else
531 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We have no qq_buddy record for %s\n", buddy->name); 531 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "We have no qq_buddy record for %s\n", buddy->name);
532 /* remove buddy on blist, this does not trigger qq_remove_buddy again 532 /* remove buddy on blist, this does not trigger qq_remove_buddy again
533 * do this only if the request comes from block request, 533 * do this only if the request comes from block request,
534 * otherwise gaim segmentation fault */ 534 * otherwise purple segmentation fault */
535 if (g_ascii_strcasecmp(group->name, GAIM_GROUP_QQ_BLOCKED) == 0) 535 if (g_ascii_strcasecmp(group->name, PURPLE_GROUP_QQ_BLOCKED) == 0)
536 gaim_blist_remove_buddy(b); 536 purple_blist_remove_buddy(b);
537 } 537 }
538 } 538 }
539 539
540 /* free add buddy request queue */ 540 /* free add buddy request queue */
541 void qq_add_buddy_request_free(qq_data *qd) 541 void qq_add_buddy_request_free(qq_data *qd)
548 p = (qq_add_buddy_request *) (qd->add_buddy_request->data); 548 p = (qq_add_buddy_request *) (qd->add_buddy_request->data);
549 qd->add_buddy_request = g_list_remove(qd->add_buddy_request, p); 549 qd->add_buddy_request = g_list_remove(qd->add_buddy_request, p);
550 g_free(p); 550 g_free(p);
551 i++; 551 i++;
552 } 552 }
553 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d add buddy requests are freed!\n", i); 553 purple_debug(PURPLE_DEBUG_INFO, "QQ", "%d add buddy requests are freed!\n", i);
554 } 554 }
555 555
556 /* free up all qq_buddy */ 556 /* free up all qq_buddy */
557 void qq_buddies_list_free(GaimAccount *account, qq_data *qd) 557 void qq_buddies_list_free(PurpleAccount *account, qq_data *qd)
558 { 558 {
559 gint i; 559 gint i;
560 qq_buddy *p; 560 qq_buddy *p;
561 gchar *name; 561 gchar *name;
562 GaimBuddy *b; 562 PurpleBuddy *b;
563 563
564 i = 0; 564 i = 0;
565 while (qd->buddies) { 565 while (qd->buddies) {
566 p = (qq_buddy *) (qd->buddies->data); 566 p = (qq_buddy *) (qd->buddies->data);
567 qd->buddies = g_list_remove(qd->buddies, p); 567 qd->buddies = g_list_remove(qd->buddies, p);
568 name = uid_to_gaim_name(p->uid); 568 name = uid_to_purple_name(p->uid);
569 b = gaim_find_buddy(account, name); 569 b = purple_find_buddy(account, name);
570 if(b != NULL) 570 if(b != NULL)
571 b->proto_data = NULL; 571 b->proto_data = NULL;
572 else 572 else
573 gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_buddy %s not found in gaim proto_data\n", name); 573 purple_debug(PURPLE_DEBUG_INFO, "QQ", "qq_buddy %s not found in purple proto_data\n", name);
574 g_free(name); 574 g_free(name);
575 575
576 g_free(p); 576 g_free(p);
577 i++; 577 i++;
578 } 578 }
579 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d qq_buddy structures are freed!\n", i); 579 purple_debug(PURPLE_DEBUG_INFO, "QQ", "%d qq_buddy structures are freed!\n", i);
580 } 580 }