comparison libpurple/protocols/qq/buddy_opt.c @ 24557:1aca68fe730c

Change QQ number to unsigned long
author Hu Yong <ccpaging@gmail.com>
date Tue, 11 Nov 2008 07:01:45 +0000
parents 2a19984c0005
children 8f757b2139d2 d8452c0bec7b 367b3ddcf5c3
comparison
equal deleted inserted replaced
24556:b22f6fb98cca 24557:1aca68fe730c
108 if (who == NULL) return NULL; 108 if (who == NULL) return NULL;
109 buddy = purple_find_buddy(purple_connection_get_account(gc), who); 109 buddy = purple_find_buddy(purple_connection_get_account(gc), who);
110 g_free(who); 110 g_free(who);
111 111
112 if (buddy == NULL) { 112 if (buddy == NULL) {
113 purple_debug_error("QQ", "Can not find purple buddy of %d\n", uid); 113 purple_debug_error("QQ", "Can not find purple buddy of %u\n", uid);
114 return NULL; 114 return NULL;
115 } 115 }
116 if (buddy->proto_data == NULL) { 116 if (buddy->proto_data == NULL) {
117 purple_debug_error("QQ", "Can not find buddy data of %d\n", uid); 117 purple_debug_error("QQ", "Can not find buddy data of %u\n", uid);
118 return NULL; 118 return NULL;
119 } 119 }
120 return (qq_buddy_data *)buddy->proto_data; 120 return (qq_buddy_data *)buddy->proto_data;
121 } 121 }
122 122
144 if (group == NULL) { 144 if (group == NULL) {
145 purple_debug_error("QQ", "Failed creating group %s\n", group_name); 145 purple_debug_error("QQ", "Failed creating group %s\n", group_name);
146 return NULL; 146 return NULL;
147 } 147 }
148 148
149 purple_debug_info("QQ", "Add new purple buddy: [%u]\n", uid);
149 who = uid_to_purple_name(uid); 150 who = uid_to_purple_name(uid);
150
151 purple_debug_info("QQ", "Add new purple buddy: [%s]\n", who);
152 buddy = purple_buddy_new(gc->account, who, NULL); /* alias is NULL */ 151 buddy = purple_buddy_new(gc->account, who, NULL); /* alias is NULL */
153 buddy->proto_data = NULL; 152 buddy->proto_data = NULL;
154 153
155 g_free(who); 154 g_free(who);
156 155
212 gchar uid_str[11]; 211 gchar uid_str[11];
213 gint bytes; 212 gint bytes;
214 213
215 g_return_if_fail(uid > 0); 214 g_return_if_fail(uid > 0);
216 215
217 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 216 g_snprintf(uid_str, sizeof(uid_str), "%u", uid);
218 bytes = strlen(uid_str); 217 bytes = strlen(uid_str);
219 qq_send_cmd_mess(gc, QQ_CMD_REMOVE_BUDDY, (guint8 *) uid_str, bytes, 0, uid); 218 qq_send_cmd_mess(gc, QQ_CMD_REMOVE_BUDDY, (guint8 *) uid_str, bytes, 0, uid);
220 } 219 }
221 220
222 static void request_remove_buddy_ex(PurpleConnection *gc, 221 static void request_remove_buddy_ex(PurpleConnection *gc,
232 raw_data = g_newa(guint8, auth_len + sizeof(uid_str) ); 231 raw_data = g_newa(guint8, auth_len + sizeof(uid_str) );
233 bytes = 0; 232 bytes = 0;
234 bytes += qq_put8(raw_data + bytes, auth_len); 233 bytes += qq_put8(raw_data + bytes, auth_len);
235 bytes += qq_putdata(raw_data + bytes, auth, auth_len); 234 bytes += qq_putdata(raw_data + bytes, auth, auth_len);
236 235
237 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 236 g_snprintf(uid_str, sizeof(uid_str), "%u", uid);
238 bytes += qq_putdata(raw_data + bytes, (guint8 *)uid_str, strlen(uid_str)); 237 bytes += qq_putdata(raw_data + bytes, (guint8 *)uid_str, strlen(uid_str));
239 238
240 qq_send_cmd_mess(gc, QQ_CMD_REMOVE_BUDDY, raw_data, bytes, 0, uid); 239 qq_send_cmd_mess(gc, QQ_CMD_REMOVE_BUDDY, raw_data, bytes, 0, uid);
241 } 240 }
242 241
316 add_req->uid = uid; 315 add_req->uid = uid;
317 add_req->auth = NULL; 316 add_req->auth = NULL;
318 add_req->auth_len = 0; 317 add_req->auth_len = 0;
319 318
320 who = uid_to_purple_name(uid); 319 who = uid_to_purple_name(uid);
321 msg = g_strdup_printf(_("%d needs Q&A"), uid); 320 msg = g_strdup_printf(_("%u needs Q&A"), uid);
322 purple_request_input(gc, _("Add buddy Q&A"), msg, 321 purple_request_input(gc, _("Add buddy Q&A"), msg,
323 _("Input answer here"), 322 _("Input answer here"),
324 NULL, 323 NULL,
325 TRUE, FALSE, NULL, 324 TRUE, FALSE, NULL,
326 _("Send"), G_CALLBACK(add_buddy_question_cb), 325 _("Send"), G_CALLBACK(add_buddy_question_cb),
479 gchar uid_str[11]; 478 gchar uid_str[11];
480 479
481 g_return_if_fail(uid > 0); 480 g_return_if_fail(uid > 0);
482 481
483 /* we need to send the ascii code of this uid to qq server */ 482 /* we need to send the ascii code of this uid to qq server */
484 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 483 g_snprintf(uid_str, sizeof(uid_str), "%u", uid);
485 qq_send_cmd_mess(gc, QQ_CMD_ADD_BUDDY_NO_AUTH, 484 qq_send_cmd_mess(gc, QQ_CMD_ADD_BUDDY_NO_AUTH,
486 (guint8 *) uid_str, strlen(uid_str), 0, uid); 485 (guint8 *) uid_str, strlen(uid_str), 0, uid);
487 } 486 }
488 487
489 static void request_add_buddy_no_auth_ex(PurpleConnection *gc, guint32 uid) 488 static void request_add_buddy_no_auth_ex(PurpleConnection *gc, guint32 uid)
499 } 498 }
500 499
501 /* this buddy needs authentication, text conversion is done at lowest level */ 500 /* this buddy needs authentication, text conversion is done at lowest level */
502 static void request_add_buddy_auth(PurpleConnection *gc, guint32 uid, const gchar response, const gchar *text) 501 static void request_add_buddy_auth(PurpleConnection *gc, guint32 uid, const gchar response, const gchar *text)
503 { 502 {
504 gchar *text_qq, uid_str[11]; 503 guint8 raw_data[MAX_PACKET_SIZE - 16];
505 guint8 bar, *raw_data; 504 gint bytes;
506 gint bytes = 0; 505 gchar *msg, uid_str[11];
507 506 guint8 bar;
508 g_return_if_fail(uid != 0); 507
509 508 g_return_if_fail(uid != 0);
510 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 509
510 g_snprintf(uid_str, sizeof(uid_str), "%u", uid);
511 bar = 0x1f; 511 bar = 0x1f;
512 raw_data = g_newa(guint8, QQ_MSG_IM_MAX); 512
513 513 bytes = 0;
514 bytes += qq_putdata(raw_data + bytes, (guint8 *) uid_str, strlen(uid_str)); 514 bytes += qq_putdata(raw_data + bytes, (guint8 *) uid_str, strlen(uid_str));
515 bytes += qq_put8(raw_data + bytes, bar); 515 bytes += qq_put8(raw_data + bytes, bar);
516 bytes += qq_put8(raw_data + bytes, response); 516 bytes += qq_put8(raw_data + bytes, response);
517 517
518 if (text != NULL) { 518 if (text != NULL) {
519 text_qq = utf8_to_qq(text, QQ_CHARSET_DEFAULT); 519 msg = utf8_to_qq(text, QQ_CHARSET_DEFAULT);
520 bytes += qq_put8(raw_data + bytes, bar); 520 bytes += qq_put8(raw_data + bytes, bar);
521 bytes += qq_putdata(raw_data + bytes, (guint8 *) text_qq, strlen(text_qq)); 521 bytes += qq_putdata(raw_data + bytes, (guint8 *) msg, strlen(msg));
522 g_free(text_qq); 522 g_free(msg);
523 } 523 }
524 524
525 qq_send_cmd(gc, QQ_CMD_ADD_BUDDY_AUTH, raw_data, bytes); 525 qq_send_cmd(gc, QQ_CMD_ADD_BUDDY_AUTH, raw_data, bytes);
526 } 526 }
527 527
659 g_memmove(add_req->auth, auth, auth_len); 659 g_memmove(add_req->auth, auth, auth_len);
660 add_req->auth_len = auth_len; 660 add_req->auth_len = auth_len;
661 } 661 }
662 662
663 who = uid_to_purple_name(uid); 663 who = uid_to_purple_name(uid);
664 msg = g_strdup_printf(_("%d needs authentication"), uid); 664 msg = g_strdup_printf(_("%u needs authentication"), uid);
665 purple_request_input(gc, _("Add buddy authorize"), msg, 665 purple_request_input(gc, _("Add buddy authorize"), msg,
666 _("Input request here"), 666 _("Input request here"),
667 _("Would you be my friend?"), 667 _("Would you be my friend?"),
668 TRUE, FALSE, NULL, 668 TRUE, FALSE, NULL,
669 _("Send"), G_CALLBACK(add_buddy_auth_cb), 669 _("Send"), G_CALLBACK(add_buddy_auth_cb),
704 purple_notify_error(gc, _("QQ Buddy"), _("Add buddy"), _("Invalid QQ Number")); 704 purple_notify_error(gc, _("QQ Buddy"), _("Add buddy"), _("Invalid QQ Number"));
705 if (buddy == NULL) { 705 if (buddy == NULL) {
706 return; 706 return;
707 } 707 }
708 708
709 purple_debug_info("QQ", "Remove buddy with invalid QQ number %d\n", uid); 709 purple_debug_info("QQ", "Remove buddy with invalid QQ number %u\n", uid);
710 qq_buddy_free(buddy); 710 qq_buddy_free(buddy);
711 } 711 }
712 712
713 /* process reply to add_buddy_auth request */ 713 /* process reply to add_buddy_auth request */
714 void qq_process_add_buddy_auth(guint8 *data, gint data_len, PurpleConnection *gc) 714 void qq_process_add_buddy_auth(guint8 *data, gint data_len, PurpleConnection *gc)
743 g_return_if_fail(data != NULL && data_len != 0); 743 g_return_if_fail(data != NULL && data_len != 0);
744 g_return_if_fail(uid != 0); 744 g_return_if_fail(uid != 0);
745 745
746 buddy = qq_buddy_find(gc, uid); 746 buddy = qq_buddy_find(gc, uid);
747 if (data[0] != 0) { 747 if (data[0] != 0) {
748 msg = g_strdup_printf(_("Failed removing buddy %d"), uid); 748 msg = g_strdup_printf(_("Failed removing buddy %u"), uid);
749 purple_notify_info(gc, _("QQ Buddy"), msg, NULL); 749 purple_notify_info(gc, _("QQ Buddy"), msg, NULL);
750 g_free(msg); 750 g_free(msg);
751 } 751 }
752 752
753 purple_debug_info("QQ", "Reply OK for removing buddy\n"); 753 purple_debug_info("QQ", "Reply OK for removing buddy\n");
765 765
766 g_return_if_fail(data != NULL && data_len != 0); 766 g_return_if_fail(data != NULL && data_len != 0);
767 qd = (qq_data *) gc->proto_data; 767 qd = (qq_data *) gc->proto_data;
768 768
769 if (data[0] == 0) { 769 if (data[0] == 0) {
770 purple_debug_info("QQ", "Reply OK for removing me from %d's buddy list\n", uid); 770 purple_debug_info("QQ", "Reply OK for removing me from %u's buddy list\n", uid);
771 return; 771 return;
772 } 772 }
773 msg = g_strdup_printf(_("Failed removing me from %d's buddy list"), uid); 773 msg = g_strdup_printf(_("Failed removing me from %d's buddy list"), uid);
774 purple_notify_info(gc, _("QQ Buddy"), msg, NULL); 774 purple_notify_info(gc, _("QQ Buddy"), msg, NULL);
775 g_free(msg); 775 g_free(msg);
786 g_return_if_fail(data != NULL && data_len != 0); 786 g_return_if_fail(data != NULL && data_len != 0);
787 g_return_if_fail(uid != 0); 787 g_return_if_fail(uid != 0);
788 788
789 qd = (qq_data *) gc->proto_data; 789 qd = (qq_data *) gc->proto_data;
790 790
791 purple_debug_info("QQ", "Process buddy add for id [%d]\n", uid); 791 purple_debug_info("QQ", "Process buddy add for id [%u]\n", uid);
792 qq_show_packet("buddy_add_no_auth", data, data_len); 792 qq_show_packet("buddy_add_no_auth", data, data_len);
793 793
794 if (NULL == (segments = split_data(data, data_len, "\x1f", 2))) 794 if (NULL == (segments = split_data(data, data_len, "\x1f", 2)))
795 return; 795 return;
796 796
797 dest_uid = segments[0]; 797 dest_uid = segments[0];
798 reply = segments[1]; 798 reply = segments[1];
799 if (strtol(dest_uid, NULL, 10) != qd->uid) { /* should not happen */ 799 if (strtoul(dest_uid, NULL, 10) != qd->uid) { /* should not happen */
800 purple_debug_error("QQ", "Add buddy reply is to [%s], not me!", dest_uid); 800 purple_debug_error("QQ", "Add buddy reply is to [%s], not me!", dest_uid);
801 g_strfreev(segments); 801 g_strfreev(segments);
802 return; 802 return;
803 } 803 }
804 804
812 } else { 812 } else {
813 qq_request_get_level(gc, uid); 813 qq_request_get_level(gc, uid);
814 } 814 }
815 qq_request_get_buddies_online(gc, 0, 0); 815 qq_request_get_buddies_online(gc, 0, 0);
816 816
817 purple_debug_info("QQ", "Successed adding into %d's buddy list", uid); 817 purple_debug_info("QQ", "Successed adding into %u's buddy list", uid);
818 g_strfreev(segments); 818 g_strfreev(segments);
819 return; 819 return;
820 } 820 }
821 821
822 /* need auth */ 822 /* need auth */
848 g_return_if_fail(data != NULL && data_len >= 5); 848 g_return_if_fail(data != NULL && data_len >= 5);
849 g_return_if_fail(uid != 0); 849 g_return_if_fail(uid != 0);
850 850
851 qd = (qq_data *) gc->proto_data; 851 qd = (qq_data *) gc->proto_data;
852 852
853 purple_debug_info("QQ", "Process buddy add no auth for id [%d]\n", uid); 853 purple_debug_info("QQ", "Process buddy add no auth for id [%u]\n", uid);
854 qq_show_packet("buddy_add_no_auth_ex", data, data_len); 854 qq_show_packet("buddy_add_no_auth_ex", data, data_len);
855 855
856 bytes = 0; 856 bytes = 0;
857 bytes += qq_get32(&dest_uid, data + bytes); 857 bytes += qq_get32(&dest_uid, data + bytes);
858 bytes += qq_get8(&reply, data + bytes); 858 bytes += qq_get8(&reply, data + bytes);
859 859
860 g_return_if_fail(dest_uid == uid); 860 g_return_if_fail(dest_uid == uid);
861 861
862 if (reply == 0x99) { 862 if (reply == 0x99) {
863 purple_debug_info("QQ", "Successed adding buddy %d\n", uid); 863 purple_debug_info("QQ", "Successed adding buddy %u\n", uid);
864 qq_buddy_find_or_new(gc, uid); 864 qq_buddy_find_or_new(gc, uid);
865 865
866 qq_request_buddy_info(gc, uid, 0, 0); 866 qq_request_buddy_info(gc, uid, 0, 0);
867 if (qd->client_version >= 2007) { 867 if (qd->client_version >= 2007) {
868 qq_request_get_level_2007(gc, uid); 868 qq_request_get_level_2007(gc, uid);
872 qq_request_get_buddies_online(gc, 0, 0); 872 qq_request_get_buddies_online(gc, 0, 0);
873 return; 873 return;
874 } 874 }
875 875
876 if (reply != 0) { 876 if (reply != 0) {
877 purple_debug_info("QQ", "Failed adding buddy %d, Unknow reply 0x%02X\n", 877 purple_debug_info("QQ", "Failed adding buddy %u, Unknow reply 0x%02X\n",
878 uid, reply); 878 uid, reply);
879 } 879 }
880 880
881 /* need auth */ 881 /* need auth */
882 g_return_if_fail(data_len > bytes); 882 g_return_if_fail(data_len > bytes);
941 qq_buddy_req *add_req; 941 qq_buddy_req *add_req;
942 gchar *who; 942 gchar *who;
943 943
944 g_return_if_fail(uid != 0 && reason != NULL); 944 g_return_if_fail(uid != 0 && reason != NULL);
945 945
946 purple_debug_info("QQ", "Buddy %d request adding, msg: %s\n", uid, reason); 946 purple_debug_info("QQ", "Buddy %u request adding, msg: %s\n", uid, reason);
947 947
948 add_req = g_new0(qq_buddy_req, 1); 948 add_req = g_new0(qq_buddy_req, 1);
949 add_req->gc = gc; 949 add_req->gc = gc;
950 add_req->uid = uid; 950 add_req->uid = uid;
951 951
971 { 971 {
972 guint32 uid; 972 guint32 uid;
973 gchar *msg, *reason; 973 gchar *msg, *reason;
974 974
975 g_return_if_fail(from != NULL && to != NULL); 975 g_return_if_fail(from != NULL && to != NULL);
976 uid = strtol(from, NULL, 10); 976 uid = strtoul(from, NULL, 10);
977 g_return_if_fail(uid != 0); 977 g_return_if_fail(uid != 0);
978 978
979 if (purple_prefs_get_bool("/plugins/prpl/qq/auto_get_authorize_info")) { 979 if (purple_prefs_get_bool("/plugins/prpl/qq/auto_get_authorize_info")) {
980 qq_request_buddy_info(gc, uid, 0, QQ_BUDDY_INFO_DISPLAY); 980 qq_request_buddy_info(gc, uid, 0, QQ_BUDDY_INFO_DISPLAY);
981 } 981 }
1020 1020
1021 bytes += qq_get32(&uid, data + bytes); 1021 bytes += qq_get32(&uid, data + bytes);
1022 g_return_if_fail(uid != 0); 1022 g_return_if_fail(uid != 0);
1023 bytes += qq_get16(&flag1, data + bytes); 1023 bytes += qq_get16(&flag1, data + bytes);
1024 bytes += qq_get16(&flag2, data + bytes); 1024 bytes += qq_get16(&flag2, data + bytes);
1025 purple_debug_info("QQ", "Check code reply Ok, uid %d, flag 0x%04X-0x%04X\n", 1025 purple_debug_info("QQ", "Check code reply Ok, uid %u, flag 0x%04X-0x%04X\n",
1026 uid, flag1, flag2); 1026 uid, flag1, flag2);
1027 return; 1027 return;
1028 } 1028 }
1029 1029
1030 static void request_buddy_check_code(PurpleConnection *gc, 1030 static void request_buddy_check_code(PurpleConnection *gc,
1034 gint bytes; 1034 gint bytes;
1035 guint32 uid; 1035 guint32 uid;
1036 1036
1037 g_return_if_fail(code != NULL && code_len > 0 && from != NULL); 1037 g_return_if_fail(code != NULL && code_len > 0 && from != NULL);
1038 1038
1039 uid = strtol(from, NULL, 10); 1039 uid = strtoul(from, NULL, 10);
1040 raw_data = g_newa(guint8, code_len + 16); 1040 raw_data = g_newa(guint8, code_len + 16);
1041 bytes = 0; 1041 bytes = 0;
1042 bytes += qq_put8(raw_data + bytes, 0x03); 1042 bytes += qq_put8(raw_data + bytes, 0x03);
1043 bytes += qq_put8(raw_data + bytes, 0x01); 1043 bytes += qq_put8(raw_data + bytes, 0x01);
1044 bytes += qq_put32(raw_data + bytes, uid); 1044 bytes += qq_put32(raw_data + bytes, uid);
1083 gchar *msg; 1083 gchar *msg;
1084 guint8 allow_reverse; 1084 guint8 allow_reverse;
1085 1085
1086 g_return_if_fail(from != NULL && to != NULL); 1086 g_return_if_fail(from != NULL && to != NULL);
1087 g_return_if_fail(data != NULL && data_len >= 3); 1087 g_return_if_fail(data != NULL && data_len >= 3);
1088 uid = strtol(from, NULL, 10); 1088 uid = strtoul(from, NULL, 10);
1089 g_return_if_fail(uid != 0); 1089 g_return_if_fail(uid != 0);
1090 1090
1091 /* qq_show_packet("server_buddy_add_request_ex", data, data_len); */ 1091 /* qq_show_packet("server_buddy_add_request_ex", data, data_len); */
1092 1092
1093 bytes = 0; 1093 bytes = 0;
1114 gchar *who; 1114 gchar *who;
1115 gchar *primary; 1115 gchar *primary;
1116 1116
1117 g_return_if_fail(from != NULL && to != NULL); 1117 g_return_if_fail(from != NULL && to != NULL);
1118 1118
1119 uid = strtol(from, NULL, 10); 1119 uid = strtoul(from, NULL, 10);
1120 who = uid_to_purple_name(uid); 1120 who = uid_to_purple_name(uid);
1121 1121
1122 buddy = purple_find_buddy(account, who); 1122 buddy = purple_find_buddy(account, who);
1123 if (buddy != NULL) { 1123 if (buddy != NULL) {
1124 purple_account_notify_added(account, from, to, NULL, NULL); 1124 purple_account_notify_added(account, from, to, NULL, NULL);
1187 1187
1188 g_return_if_fail(from != NULL && to != NULL); 1188 g_return_if_fail(from != NULL && to != NULL);
1189 1189
1190 qd = (qq_data *) gc->proto_data; 1190 qd = (qq_data *) gc->proto_data;
1191 1191
1192 uid = strtol(from, NULL, 10); 1192 uid = strtoul(from, NULL, 10);
1193 g_return_if_fail(uid > 0); 1193 g_return_if_fail(uid > 0);
1194 1194
1195 server_buddy_check_code(gc, from, data, data_len); 1195 server_buddy_check_code(gc, from, data, data_len);
1196 1196
1197 qq_buddy_find_or_new(gc, uid); 1197 qq_buddy_find_or_new(gc, uid);
1249 1249
1250 g_free(msg_utf8); 1250 g_free(msg_utf8);
1251 g_free(primary); 1251 g_free(primary);
1252 g_free(secondary); 1252 g_free(secondary);
1253 1253
1254 uid = strtol(from, NULL, 10); 1254 uid = strtoul(from, NULL, 10);
1255 g_return_if_fail(uid != 0); 1255 g_return_if_fail(uid != 0);
1256 1256
1257 buddy = qq_buddy_find(gc, uid); 1257 buddy = qq_buddy_find(gc, uid);
1258 if (buddy != NULL && buddy->proto_data != NULL) { 1258 if (buddy != NULL && buddy->proto_data != NULL) {
1259 /* Not authorized now, free buddy data */ 1259 /* Not authorized now, free buddy data */