comparison libpurple/protocols/qq/buddy_opt.c @ 24094:7f5433ffbf8d

2008.10.22 - ccpaging <ccpaging(at)gmail.com> * 20081022
author SHiNE CsyFeK <csyfek@gmail.com>
date Tue, 28 Oct 2008 16:46:08 +0000
parents f4f29fac96c6
children 2a19984c0005
comparison
equal deleted inserted replaced
24093:f4f29fac96c6 24094:7f5433ffbf8d
54 guint32 uid; 54 guint32 uid;
55 guint8 *auth; 55 guint8 *auth;
56 guint8 auth_len; 56 guint8 auth_len;
57 } qq_buddy_req; 57 } qq_buddy_req;
58 58
59 void buddy_add_authorize_input(PurpleConnection *gc, guint32 uid, 59 void add_buddy_authorize_input(PurpleConnection *gc, guint32 uid,
60 guint8 *auth, guint8 auth_len); 60 guint8 *auth, guint8 auth_len);
61 61
62 static void buddy_add_req_free(qq_buddy_req *add_req) 62 static void buddy_req_free(qq_buddy_req *add_req)
63 { 63 {
64 g_return_if_fail(add_req != NULL); 64 g_return_if_fail(add_req != NULL);
65 if (add_req->auth) g_free(add_req->auth); 65 if (add_req->auth) g_free(add_req->auth);
66 g_free(add_req); 66 g_free(add_req);
67 } 67 }
199 buddy->proto_data = qq_buddy_data_new(uid); 199 buddy->proto_data = qq_buddy_data_new(uid);
200 return buddy; 200 return buddy;
201 } 201 }
202 202
203 /* send packet to remove a buddy from my buddy list */ 203 /* send packet to remove a buddy from my buddy list */
204 static void request_buddy_remove(PurpleConnection *gc, guint32 uid) 204 static void request_remove_buddy(PurpleConnection *gc, guint32 uid)
205 { 205 {
206 gchar uid_str[11]; 206 gchar uid_str[11];
207 gint bytes; 207 gint bytes;
208 208
209 g_return_if_fail(uid > 0); 209 g_return_if_fail(uid > 0);
210 210
211 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 211 g_snprintf(uid_str, sizeof(uid_str), "%d", uid);
212 bytes = strlen(uid_str); 212 bytes = strlen(uid_str);
213 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_REMOVE, (guint8 *) uid_str, bytes, 0, uid); 213 qq_send_cmd_mess(gc, QQ_CMD_REMOVE_BUDDY, (guint8 *) uid_str, bytes, 0, uid);
214 } 214 }
215 215
216 static void request_buddy_remove_2007(PurpleConnection *gc, 216 static void request_remove_buddy_ex(PurpleConnection *gc,
217 guint32 uid, guint8 *auth, guint8 auth_len) 217 guint32 uid, guint8 *auth, guint8 auth_len)
218 { 218 {
219 gint bytes; 219 gint bytes;
220 guint8 *raw_data; 220 guint8 *raw_data;
221 gchar uid_str[16]; 221 gchar uid_str[16];
229 bytes += qq_putdata(raw_data + bytes, auth, auth_len); 229 bytes += qq_putdata(raw_data + bytes, auth, auth_len);
230 230
231 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 231 g_snprintf(uid_str, sizeof(uid_str), "%d", uid);
232 bytes += qq_putdata(raw_data + bytes, (guint8 *)uid_str, strlen(uid_str)); 232 bytes += qq_putdata(raw_data + bytes, (guint8 *)uid_str, strlen(uid_str));
233 233
234 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_REMOVE, raw_data, bytes, 0, uid); 234 qq_send_cmd_mess(gc, QQ_CMD_REMOVE_BUDDY, raw_data, bytes, 0, uid);
235 } 235 }
236 236
237 void qq_request_auth_info(PurpleConnection *gc, guint8 cmd, guint16 sub_cmd, guint32 uid) 237 void qq_request_auth_info(PurpleConnection *gc, guint8 cmd, guint16 sub_cmd, guint32 uid)
238 { 238 {
239 guint8 raw_data[16]; 239 guint8 raw_data[16];
279 qq_show_packet("No auth info", data, data_len); 279 qq_show_packet("No auth info", data, data_len);
280 } 280 }
281 281
282 if (cmd == QQ_AUTH_INFO_BUDDY && sub_cmd == QQ_AUTH_INFO_REMOVE_BUDDY) { 282 if (cmd == QQ_AUTH_INFO_BUDDY && sub_cmd == QQ_AUTH_INFO_REMOVE_BUDDY) {
283 g_return_if_fail(auth != NULL && auth_len > 0); 283 g_return_if_fail(auth != NULL && auth_len > 0);
284 request_buddy_remove_2007(gc, uid, auth, auth_len); 284 request_remove_buddy_ex(gc, uid, auth, auth_len);
285 return; 285 return;
286 } 286 }
287 if (cmd == QQ_AUTH_INFO_BUDDY && sub_cmd == QQ_AUTH_INFO_ADD_BUDDY) { 287 if (cmd == QQ_AUTH_INFO_BUDDY && sub_cmd == QQ_AUTH_INFO_ADD_BUDDY) {
288 buddy_add_authorize_input(gc, uid, auth, auth_len); 288 add_buddy_authorize_input(gc, uid, auth, auth_len);
289 return; 289 return;
290 } 290 }
291 purple_debug_info("QQ", "Got auth info cmd 0x%x, sub 0x%x, reply 0x%x\n", 291 purple_debug_info("QQ", "Got auth info cmd 0x%x, sub 0x%x, reply 0x%x\n",
292 cmd, sub_cmd, reply); 292 cmd, sub_cmd, reply);
293 } 293 }
294 294
295 #define AUHT_TYPE_QUESTION_GET 0x01
296 #define AUTH_TYPE_QUESTION_SET 0x02
297 #define AUTH_TYPE_QUESTION_REQUEST 0x03
298 #define AUTH_TYPE_QUESTION_ANSWER 0x04
299 /*
300 int EvaAddFriendAuthQuestionPacket::putBody( unsigned char * buf )
301 {
302 int pos = 0;
303 buf[pos++] = m_AuthStatus; // 0x01, 0x02, 0x03 or 0x04
304
305 if(m_AuthStatus == AUHT_TYPE_QUESTION_GET) {
306 buf[pos++] = 0x00;
307 return pos;
308 }
309
310 if(m_AuthStatus == AUTH_TYPE_QUESTION_SET){
311 printf("question(%d):%s\n", m_Question.length(), m_Question.c_str());
312 buf[pos++] = (unsigned char)(m_Question.length() & 0xff);
313 memcpy(buf + pos, m_Question.c_str(), m_Question.length());
314 pos += m_Question.length();
315
316 buf[pos++] = (unsigned char)(m_Answer.length() & 0xff);
317 printf("answer(%d):%s\n", m_Answer.length(), m_Answer.c_str());
318 memcpy(buf + pos, m_Answer.c_str(), m_Answer.length());
319 pos += m_Answer.length();
320
321 buf[pos++] = 0x00;
322 printf("EvaAddFriendAuthQuestionPacket\n");
323 for(int i=0;i<pos;i++){
324 if(!(i%8)) printf("\n");
325 printf("%2x ", buf[i]);
326 }
327 printf("\n\n");
328 return pos;
329 }
330 // unknown 2 bytes, always 0x0001
331 buf[pos++] = 0x00;
332 buf[pos++] = 0x01;
333
334 *((unsigned int *)(buf + pos)) = htonl(m_AddQQNum);
335 pos+= 4;
336
337 if(m_AuthStatus == AUTH_TYPE_QUESTION_REQUEST) return pos;
338
339 buf[pos++] = (unsigned char)(m_Answer.length() & 0xff);
340 memcpy(buf + pos, m_Answer.c_str(), m_Answer.length());
341 pos += m_Answer.length();
342
343 return pos;
344 }
345 *
346 void EvaAddFriendAuthQuestionReplyPacket::parseBody( )
347 {
348 printf("EvaAddFriendAuthQuestionReplyPacket\n");
349 for(int i=0;i<bodyLength;i++){
350 if(!(i%8)) printf("\n");
351 printf("%2x ", decryptedBuf[i]);
352 }
353 printf("\n\n");
354 int offset = 0;
355
356 m_AuthStatus = decryptedBuf[offset++];
357
358 if(m_AuthStatus == AUHT_TYPE_QUESTION_GET){
359 m_CodeLen = decryptedBuf[offset++];
360 if(m_CodeLen){
361 if(m_Code) delete [] m_Code;
362 m_Code = new unsigned char[m_CodeLen+1];
363 memcpy(m_Code, decryptedBuf + offset, m_CodeLen);
364 m_Code[m_CodeLen] = 0x00;
365 offset += m_CodeLen;
366 }
367
368 unsigned int len = decryptedBuf[offset++];
369 if(len){
370 char *tmp = new char [len+1];
371 memcpy(tmp, decryptedBuf + offset, len);
372 tmp[len] = 0x00;
373 m_Answer = tmp;
374 delete []tmp;
375 offset += len;
376 }
377 return;
378 }
379
380 if(m_AuthStatus == AUTH_TYPE_QUESTION_SET){
381 m_ReplyCode = decryptedBuf[offset++]; // 0x00: success, (? -- 0x01: error)
382 return;
383 }
384
385 offset+=2; // unknown 2 bytes, always be 0x0001
386
387 m_ReplyCode = decryptedBuf[offset++];
388
389 if(m_ReplyCode == 0x01){
390 // should be error happened
391 return;
392 }
393
394 switch(m_AuthStatus){
395 case AUTH_TYPE_QUESTION_REQUEST:
396 m_CodeLen = decryptedBuf[offset++];
397 break;
398 case AUTH_TYPE_QUESTION_ANSWER:{
399 m_CodeLen = ntohs( *( (unsigned short *)(decryptedBuf + offset)) );
400 offset+=2;
401 }
402 break;
403 default:
404 fprintf(stderr, "Unknown auth status code: 0x%2x\n", m_AuthStatus);
405 return;
406 }
407 if(m_CodeLen){
408 if(m_Code) delete [] m_Code;
409 m_Code = new unsigned char[m_CodeLen+1];
410 memcpy(m_Code, decryptedBuf + offset, m_CodeLen);
411 offset += m_CodeLen;
412 }
413
414 // just in case the url, give it a terminate char
415 if(m_AuthStatus == AUTH_TYPE_QUESTION_REQUEST ||
416 m_AuthStatus == AUHT_TYPE_QUESTION_GET){
417 m_Code[m_CodeLen] = 0x00;
418 m_CodeLen++;
419 }
420 }
421 */
422
295 /* try to remove myself from someone's buddy list */ 423 /* try to remove myself from someone's buddy list */
296 static void request_buddy_remove_me(PurpleConnection *gc, guint32 uid) 424 static void request_buddy_remove_me(PurpleConnection *gc, guint32 uid)
297 { 425 {
298 guint8 raw_data[16] = {0}; 426 guint8 raw_data[16] = {0};
299 gint bytes = 0; 427 gint bytes = 0;
304 432
305 qq_send_cmd_mess(gc, QQ_CMD_REMOVE_ME, raw_data, bytes, 0, uid); 433 qq_send_cmd_mess(gc, QQ_CMD_REMOVE_ME, raw_data, bytes, 0, uid);
306 } 434 }
307 435
308 /* try to add a buddy without authentication */ 436 /* try to add a buddy without authentication */
309 static void request_buddy_add_no_auth(PurpleConnection *gc, guint32 uid) 437 static void request_add_buddy_no_auth(PurpleConnection *gc, guint32 uid)
310 { 438 {
311 gchar uid_str[11]; 439 gchar uid_str[11];
312 440
313 g_return_if_fail(uid > 0); 441 g_return_if_fail(uid > 0);
314 442
315 /* we need to send the ascii code of this uid to qq server */ 443 /* we need to send the ascii code of this uid to qq server */
316 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 444 g_snprintf(uid_str, sizeof(uid_str), "%d", uid);
317 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_ADD_NO_AUTH, 445 qq_send_cmd_mess(gc, QQ_CMD_ADD_BUDDY_NO_AUTH,
318 (guint8 *) uid_str, strlen(uid_str), 0, uid); 446 (guint8 *) uid_str, strlen(uid_str), 0, uid);
319 } 447 }
320 448
321 static void request_buddy_add_no_auth_ex(PurpleConnection *gc, guint32 uid) 449 static void request_add_buddy_no_auth_ex(PurpleConnection *gc, guint32 uid)
322 { 450 {
323 gchar uid_str[11]; 451 guint bytes;
324 452 guint8 raw_data[16];
325 g_return_if_fail(uid > 0); 453
326 454 g_return_if_fail(uid != 0);
327 /* we need to send the ascii code of this uid to qq server */ 455
328 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 456 bytes = 0;
329 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_ADD_NO_AUTH_EX, 457 bytes += qq_put32(raw_data + bytes, uid);
330 (guint8 *) uid_str, strlen(uid_str), 0, uid); 458 qq_send_cmd_mess(gc, QQ_CMD_ADD_BUDDY_NO_AUTH_EX, raw_data, bytes, 0, uid);
331 } 459 }
332 460
333 /* this buddy needs authentication, text conversion is done at lowest level */ 461 /* this buddy needs authentication, text conversion is done at lowest level */
334 static void request_buddy_auth(PurpleConnection *gc, guint32 uid, const gchar response, const gchar *text) 462 static void request_add_buddy_auth(PurpleConnection *gc, guint32 uid, const gchar response, const gchar *text)
335 { 463 {
336 gchar *text_qq, uid_str[11]; 464 gchar *text_qq, uid_str[11];
337 guint8 bar, *raw_data; 465 guint8 bar, *raw_data;
338 gint bytes = 0; 466 gint bytes = 0;
339 467
352 bytes += qq_put8(raw_data + bytes, bar); 480 bytes += qq_put8(raw_data + bytes, bar);
353 bytes += qq_putdata(raw_data + bytes, (guint8 *) text_qq, strlen(text_qq)); 481 bytes += qq_putdata(raw_data + bytes, (guint8 *) text_qq, strlen(text_qq));
354 g_free(text_qq); 482 g_free(text_qq);
355 } 483 }
356 484
357 qq_send_cmd(gc, QQ_CMD_BUDDY_ADD_AUTH, raw_data, bytes); 485 qq_send_cmd(gc, QQ_CMD_ADD_BUDDY_AUTH, raw_data, bytes);
358 } 486 }
359 487
360 static void request_buddy_auth_2007(PurpleConnection *gc, guint32 uid, 488 static void request_add_buddy_auth_ex(PurpleConnection *gc, guint32 uid,
361 const gchar *text, guint8 *auth, guint8 auth_len) 489 const gchar *text, guint8 *auth, guint8 auth_len)
362 { 490 {
363 guint8 *raw_data; 491 guint8 *raw_data;
364 gint bytes = 0; 492 gint bytes = 0;
365 gchar *msg; 493 gchar *msg;
387 msg = utf8_to_qq(text, QQ_CHARSET_DEFAULT); 515 msg = utf8_to_qq(text, QQ_CHARSET_DEFAULT);
388 bytes += qq_put8(raw_data + bytes, strlen(msg)); 516 bytes += qq_put8(raw_data + bytes, strlen(msg));
389 bytes += qq_putdata(raw_data + bytes, (guint8 *)msg, strlen(msg)); 517 bytes += qq_putdata(raw_data + bytes, (guint8 *)msg, strlen(msg));
390 g_free(msg); 518 g_free(msg);
391 } 519 }
392 qq_send_cmd(gc, QQ_CMD_BUDDY_ADD_AUTH_EX, raw_data, bytes); 520 qq_send_cmd(gc, QQ_CMD_ADD_BUDDY_AUTH_EX, raw_data, bytes);
393 } 521 }
394 522
395 static void request_buddy_add_auth_cb(qq_buddy_req *add_req, const gchar *text) 523 static void add_buddy_auth_cb(qq_buddy_req *add_req, const gchar *text)
396 { 524 {
397 qq_data *qd; 525 qq_data *qd;
398 g_return_if_fail(add_req != NULL); 526 g_return_if_fail(add_req != NULL);
399 if (add_req->gc == NULL || add_req->uid == 0) { 527 if (add_req->gc == NULL || add_req->uid == 0) {
400 buddy_add_req_free(add_req); 528 buddy_req_free(add_req);
401 return; 529 return;
402 } 530 }
403 531
404 qd = (qq_data *)add_req->gc->proto_data; 532 qd = (qq_data *)add_req->gc->proto_data;
405 if (qd->client_version > 2005) { 533 if (qd->client_version > 2005) {
406 request_buddy_auth_2007(add_req->gc, add_req->uid, 534 request_add_buddy_auth_ex(add_req->gc, add_req->uid,
407 text, add_req->auth, add_req->auth_len); 535 text, add_req->auth, add_req->auth_len);
408 } else { 536 } else {
409 request_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_REQUEST, text); 537 request_add_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_REQUEST, text);
410 } 538 }
411 buddy_add_req_free(add_req); 539 buddy_req_free(add_req);
412 } 540 }
413 541
414 /* the real packet to reject and request is sent from here */ 542 /* the real packet to reject and request is sent from here */
415 static void buddy_add_deny_reason_cb(qq_buddy_req *add_req, const gchar *reason) 543 static void buddy_add_deny_reason_cb(qq_buddy_req *add_req, const gchar *reason)
416 { 544 {
417 g_return_if_fail(add_req != NULL); 545 g_return_if_fail(add_req != NULL);
418 if (add_req->gc == NULL || add_req->uid == 0) { 546 if (add_req->gc == NULL || add_req->uid == 0) {
419 buddy_add_req_free(add_req); 547 buddy_req_free(add_req);
420 return; 548 return;
421 } 549 }
422 550
423 request_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_REJECT, reason); 551 request_add_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_REJECT, reason);
424 buddy_add_req_free(add_req); 552 buddy_req_free(add_req);
425 } 553 }
426 554
427 static void buddy_add_deny_noreason_cb(qq_buddy_req *add_req) 555 static void buddy_add_deny_noreason_cb(qq_buddy_req *add_req)
428 { 556 {
429 buddy_add_deny_reason_cb(add_req, NULL); 557 buddy_add_deny_reason_cb(add_req, NULL);
434 { 562 {
435 qq_buddy_req *add_req = (qq_buddy_req *)data; 563 qq_buddy_req *add_req = (qq_buddy_req *)data;
436 564
437 g_return_if_fail(add_req != NULL); 565 g_return_if_fail(add_req != NULL);
438 if (add_req->gc == NULL || add_req->uid == 0) { 566 if (add_req->gc == NULL || add_req->uid == 0) {
439 buddy_add_req_free(add_req); 567 buddy_req_free(add_req);
440 return; 568 return;
441 } 569 }
442 570
443 request_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_APPROVE, NULL); 571 request_add_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_APPROVE, NULL);
444 buddy_add_req_free(add_req); 572 buddy_req_free(add_req);
445 } 573 }
446 574
447 /* we reject other's request of adding me as friend */ 575 /* we reject other's request of adding me as friend */
448 static void buddy_add_deny_cb(gpointer data) 576 static void buddy_add_deny_cb(gpointer data)
449 { 577 {
456 purple_connection_get_account(add_req->gc), who, NULL, 584 purple_connection_get_account(add_req->gc), who, NULL,
457 add_req); 585 add_req);
458 g_free(who); 586 g_free(who);
459 } 587 }
460 588
461 static void buddy_cancel_cb(qq_buddy_req *add_req, const gchar *msg) 589 static void buddy_req_cancel_cb(qq_buddy_req *add_req, const gchar *msg)
462 { 590 {
463 g_return_if_fail(add_req != NULL); 591 g_return_if_fail(add_req != NULL);
464 buddy_add_req_free(add_req); 592 buddy_req_free(add_req);
465 } 593 }
466 594
467 static void buddy_add_no_auth_cb(qq_buddy_req *add_req) 595 static void add_buddy_no_auth_cb(qq_buddy_req *add_req)
468 { 596 {
469 qq_data *qd; 597 qq_data *qd;
470 g_return_if_fail(add_req != NULL); 598 g_return_if_fail(add_req != NULL);
471 if (add_req->gc == NULL || add_req->uid == 0) { 599 if (add_req->gc == NULL || add_req->uid == 0) {
472 buddy_add_req_free(add_req); 600 buddy_req_free(add_req);
473 return; 601 return;
474 } 602 }
475 603
476 qd = (qq_data *) add_req->gc->proto_data; 604 qd = (qq_data *) add_req->gc->proto_data;
477 if (qd->client_version > 2005) { 605 if (qd->client_version > 2005) {
478 request_buddy_add_no_auth_ex(add_req->gc, add_req->uid); 606 request_add_buddy_no_auth_ex(add_req->gc, add_req->uid);
479 } else { 607 } else {
480 request_buddy_add_no_auth(add_req->gc, add_req->uid); 608 request_add_buddy_no_auth(add_req->gc, add_req->uid);
481 } 609 }
482 buddy_add_req_free(add_req); 610 buddy_req_free(add_req);
483 } 611 }
484 612
485 void buddy_add_authorize_input(PurpleConnection *gc, guint32 uid, 613 void add_buddy_authorize_input(PurpleConnection *gc, guint32 uid,
486 guint8 *auth, guint8 auth_len) 614 guint8 *auth, guint8 auth_len)
487 { 615 {
488 gchar *who, *msg; 616 gchar *who, *msg;
489 qq_buddy_req *add_req; 617 qq_buddy_req *add_req;
490 g_return_if_fail(uid != 0); 618 g_return_if_fail(uid != 0);
504 msg = g_strdup_printf(_("%d needs authentication"), uid); 632 msg = g_strdup_printf(_("%d needs authentication"), uid);
505 purple_request_input(gc, _("Add buddy authorize"), msg, 633 purple_request_input(gc, _("Add buddy authorize"), msg,
506 _("Input request here"), 634 _("Input request here"),
507 _("Would you be my friend?"), 635 _("Would you be my friend?"),
508 TRUE, FALSE, NULL, 636 TRUE, FALSE, NULL,
509 _("Send"), G_CALLBACK(request_buddy_add_auth_cb), 637 _("Send"), G_CALLBACK(add_buddy_auth_cb),
510 _("Cancel"), G_CALLBACK(buddy_cancel_cb), 638 _("Cancel"), G_CALLBACK(buddy_req_cancel_cb),
511 purple_connection_get_account(gc), who, NULL, 639 purple_connection_get_account(gc), who, NULL,
512 add_req); 640 add_req);
513 641
514 g_free(msg); 642 g_free(msg);
515 g_free(who); 643 g_free(who);
532 return; /* IMPORTANT ! */ 660 return; /* IMPORTANT ! */
533 661
534 uid = purple_name_to_uid(buddy->name); 662 uid = purple_name_to_uid(buddy->name);
535 if (uid > 0) { 663 if (uid > 0) {
536 if (qd->client_version > 2005) { 664 if (qd->client_version > 2005) {
537 request_buddy_add_no_auth_ex(gc, uid); 665 request_add_buddy_no_auth_ex(gc, uid);
538 } else { 666 } else {
539 request_buddy_add_no_auth(gc, uid); 667 request_add_buddy_no_auth(gc, uid);
540 } 668 }
541 return; 669 return;
542 } 670 }
543 671
544 purple_notify_error(gc, _("QQ Buddy"), _("Add buddy"), _("Invalid QQ Number")); 672 purple_notify_error(gc, _("QQ Buddy"), _("Add buddy"), _("Invalid QQ Number"));
549 purple_debug_info("QQ", "Remove buddy with invalid QQ number %d\n", uid); 677 purple_debug_info("QQ", "Remove buddy with invalid QQ number %d\n", uid);
550 qq_buddy_free(buddy); 678 qq_buddy_free(buddy);
551 } 679 }
552 680
553 /* process reply to add_buddy_auth request */ 681 /* process reply to add_buddy_auth request */
554 void qq_process_buddy_add_auth(guint8 *data, gint data_len, PurpleConnection *gc) 682 void qq_process_add_buddy_auth(guint8 *data, gint data_len, PurpleConnection *gc)
555 { 683 {
556 qq_data *qd; 684 qq_data *qd;
557 gchar **segments, *msg_utf8; 685 gchar **segments, *msg_utf8;
558 686
559 g_return_if_fail(data != NULL && data_len != 0); 687 g_return_if_fail(data != NULL && data_len != 0);
573 purple_notify_error(gc, _("QQ Buddy"), _("Failed sending authorize"), msg_utf8); 701 purple_notify_error(gc, _("QQ Buddy"), _("Failed sending authorize"), msg_utf8);
574 g_free(msg_utf8); 702 g_free(msg_utf8);
575 } 703 }
576 704
577 /* process the server reply for my request to remove a buddy */ 705 /* process the server reply for my request to remove a buddy */
578 void qq_process_buddy_remove(PurpleConnection *gc, guint8 *data, gint data_len, guint32 uid) 706 void qq_process_remove_buddy(PurpleConnection *gc, guint8 *data, gint data_len, guint32 uid)
579 { 707 {
580 PurpleBuddy *buddy = NULL; 708 PurpleBuddy *buddy = NULL;
581 gchar *msg; 709 gchar *msg;
582 710
583 g_return_if_fail(data != NULL && data_len != 0); 711 g_return_if_fail(data != NULL && data_len != 0);
613 msg = g_strdup_printf(_("Failed removing me from %d's buddy list"), uid); 741 msg = g_strdup_printf(_("Failed removing me from %d's buddy list"), uid);
614 purple_notify_info(gc, _("QQ Buddy"), msg, NULL); 742 purple_notify_info(gc, _("QQ Buddy"), msg, NULL);
615 g_free(msg); 743 g_free(msg);
616 } 744 }
617 745
618 void qq_process_buddy_add_no_auth(PurpleConnection *gc, 746 void qq_process_add_buddy_no_auth(PurpleConnection *gc,
619 guint8 *data, gint data_len, guint32 uid) 747 guint8 *data, gint data_len, guint32 uid)
620 { 748 {
621 qq_data *qd; 749 qq_data *qd;
622 gchar **segments; 750 gchar **segments;
623 gchar *dest_uid, *reply; 751 gchar *dest_uid, *reply;
670 /* Not authorized now, free buddy data */ 798 /* Not authorized now, free buddy data */
671 qq_buddy_data_free(buddy->proto_data); 799 qq_buddy_data_free(buddy->proto_data);
672 buddy->proto_data = NULL; 800 buddy->proto_data = NULL;
673 } 801 }
674 802
675 buddy_add_authorize_input(gc, uid, NULL, 0); 803 add_buddy_authorize_input(gc, uid, NULL, 0);
676 g_strfreev(segments); 804 g_strfreev(segments);
677 } 805 }
678 806
679 void qq_process_buddy_add_no_auth_ex(PurpleConnection *gc, 807 void qq_process_add_buddy_no_auth_ex(PurpleConnection *gc,
680 guint8 *data, gint data_len, guint32 uid) 808 guint8 *data, gint data_len, guint32 uid)
681 { 809 {
682 qq_data *qd; 810 qq_data *qd;
683 gint bytes; 811 gint bytes;
684 guint32 dest_uid; 812 guint32 dest_uid;
685 guint8 reply; 813 guint8 reply;
814 guint8 auth_type;
686 815
687 g_return_if_fail(data != NULL && data_len >= 5); 816 g_return_if_fail(data != NULL && data_len >= 5);
688 g_return_if_fail(uid != 0); 817 g_return_if_fail(uid != 0);
689 818
690 qd = (qq_data *) gc->proto_data; 819 qd = (qq_data *) gc->proto_data;
691 820
692 purple_debug_info("QQ", "Process buddy add no auth for id [%d]\n", uid); 821 purple_debug_info("QQ", "Process buddy add no auth for id [%d]\n", uid);
693 qq_show_packet("buddy_add_no_auth_2007", data, data_len); 822 qq_show_packet("buddy_add_no_auth_ex", data, data_len);
694 823
695 bytes = 0; 824 bytes = 0;
696 bytes += qq_get32(&dest_uid, data + bytes); 825 bytes += qq_get32(&dest_uid, data + bytes);
697 bytes += qq_get8(&reply, data + bytes); 826 bytes += qq_get8(&reply, data + bytes);
698 827
699 g_return_if_fail(dest_uid == qd->uid); 828 g_return_if_fail(dest_uid == uid);
700 829
701 if (reply == 0) { 830 if (reply == 0x99) {
702 /* need auth */ 831 purple_debug_info("QQ", "Successed adding buddy %d\n", uid);
703 purple_debug_warning("QQ", "Failed adding buddy, need authorize\n"); 832 qq_buddy_find_or_new(gc, uid);
704 qq_request_auth_info(gc, QQ_AUTH_INFO_BUDDY, QQ_AUTH_INFO_ADD_BUDDY, uid); 833
705 return; 834 qq_request_buddy_info(gc, uid, 0, 0);
706 } 835 if (qd->client_version >= 2007) {
707 836 qq_request_get_level_2007(gc, uid);
708 /* add OK */ 837 } else {
709 qq_buddy_find_or_new(gc, uid); 838 qq_request_get_level(gc, uid);
710 839 }
711 qq_request_buddy_info(gc, uid, 0, 0); 840 qq_request_get_buddies_online(gc, 0, 0);
712 if (qd->client_version >= 2007) { 841 return;
713 qq_request_get_level_2007(gc, uid); 842 }
714 } else { 843
715 qq_request_get_level(gc, uid); 844 if (reply != 0) {
716 } 845 purple_debug_info("QQ", "Failed adding buddy %d, Unknow reply 0x%02X\n",
717 qq_request_get_buddies_online(gc, 0, 0); 846 uid, reply);
718 847 }
719 purple_debug_info("QQ", "Successed adding into %d's buddy list", uid); 848
849 /* need auth */
850 g_return_if_fail(data_len > bytes);
851 bytes += qq_get8(&auth_type, data + bytes);
852 purple_debug_warning("QQ", "Adding buddy needs authorize 0x%02X\n", auth_type);
853
854 switch (auth_type) {
855 case 0x00: /* no authorize */
856 break;
857 case 0x01: /* authorize */
858 qq_request_auth_info(gc, QQ_AUTH_INFO_BUDDY, QQ_AUTH_INFO_ADD_BUDDY, uid);
859 break;
860 case 0x02: /* disable */
861 break;
862 case 0x03: /* answer question */
863 //qq_request_question(gc, uid);
864 break;
865 default:
866 g_return_if_reached();
867 break;
868 }
720 return; 869 return;
721 } 870 }
722 871
723 /* remove a buddy and send packet to QQ server accordingly */ 872 /* remove a buddy and send packet to QQ server accordingly */
724 void qq_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 873 void qq_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
736 uid = purple_name_to_uid(buddy->name); 885 uid = purple_name_to_uid(buddy->name);
737 if (uid > 0 && uid != qd->uid) { 886 if (uid > 0 && uid != qd->uid) {
738 if (qd->client_version > 2005) { 887 if (qd->client_version > 2005) {
739 qq_request_auth_info(gc, QQ_AUTH_INFO_BUDDY, QQ_AUTH_INFO_REMOVE_BUDDY, uid); 888 qq_request_auth_info(gc, QQ_AUTH_INFO_BUDDY, QQ_AUTH_INFO_REMOVE_BUDDY, uid);
740 } else { 889 } else {
741 request_buddy_remove(gc, uid); 890 request_remove_buddy(gc, uid);
742 request_buddy_remove_me(gc, uid); 891 request_buddy_remove_me(gc, uid);
743 } 892 }
744 } 893 }
745 894
746 if (buddy->proto_data) { 895 if (buddy->proto_data) {
752 901
753 /* Do not call purple_blist_remove_buddy, 902 /* Do not call purple_blist_remove_buddy,
754 * otherwise purple segmentation fault */ 903 * otherwise purple segmentation fault */
755 } 904 }
756 905
757 static void buddy_add_request(PurpleConnection *gc, guint32 uid, gchar *reason) 906 static void buddy_add_input(PurpleConnection *gc, guint32 uid, gchar *reason)
758 { 907 {
759 PurpleAccount *account = purple_connection_get_account(gc); 908 PurpleAccount *account = purple_connection_get_account(gc);
760 qq_buddy_req *add_req; 909 qq_buddy_req *add_req;
761 gchar *who; 910 gchar *who;
762 911
806 reason = qq_to_utf8(msg, QQ_CHARSET_DEFAULT); 955 reason = qq_to_utf8(msg, QQ_CHARSET_DEFAULT);
807 if (reason == NULL) reason = g_strdup( _("Unknown reason") ); 956 if (reason == NULL) reason = g_strdup( _("Unknown reason") );
808 g_free(msg); 957 g_free(msg);
809 } 958 }
810 959
811 buddy_add_request(gc, uid, reason); 960 buddy_add_input(gc, uid, reason);
812 g_free(reason); 961 g_free(reason);
813 } 962 }
814 963
815 void qq_process_buddy_check_code(PurpleConnection *gc, guint8 *data, gint data_len, guint32 ship32) 964 void qq_process_buddy_check_code(PurpleConnection *gc, guint8 *data, gint data_len)
816 { 965 {
817 qq_data *qd; 966 qq_data *qd;
818 gint bytes; 967 gint bytes;
819 guint8 cmd; 968 guint8 cmd;
820 guint8 reply; 969 guint8 reply;
916 1065
917 if (strlen(msg) <= 0) { 1066 if (strlen(msg) <= 0) {
918 g_free(msg); 1067 g_free(msg);
919 msg = g_strdup( _("No reason given") ); 1068 msg = g_strdup( _("No reason given") );
920 } 1069 }
921 buddy_add_request(gc, uid, msg); 1070 buddy_add_input(gc, uid, msg);
922 g_free(msg); 1071 g_free(msg);
923 } 1072 }
924 1073
925 /* when you are added by a person, QQ server will send sys message */ 1074 /* when you are added by a person, QQ server will send sys message */
926 static void server_buddy_added(PurpleConnection *gc, gchar *from, gchar *to, 1075 static void server_buddy_added(PurpleConnection *gc, gchar *from, gchar *to,
950 purple_request_action(gc, NULL, primary, 1099 purple_request_action(gc, NULL, primary,
951 _("Would you like to add him?"), 1100 _("Would you like to add him?"),
952 PURPLE_DEFAULT_ACTION_NONE, 1101 PURPLE_DEFAULT_ACTION_NONE,
953 purple_connection_get_account(gc), who, NULL, 1102 purple_connection_get_account(gc), who, NULL,
954 add_req, 2, 1103 add_req, 2,
955 _("Cancel"), G_CALLBACK(buddy_cancel_cb), 1104 _("Add"), G_CALLBACK(add_buddy_no_auth_cb),
956 _("Add"), G_CALLBACK(buddy_add_no_auth_cb)); 1105 _("Cancel"), G_CALLBACK(buddy_req_cancel_cb));
957 1106
958 g_free(who); 1107 g_free(who);
959 g_free(primary); 1108 g_free(primary);
960 } 1109 }
961 1110