annotate src/protocols/qq/buddy_info.c @ 13871:2be9dfa9569b

[gaim-migrate @ 16341] Fixed a bug that prevented libqq from being loaded as a plugin. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Mon, 26 Jun 2006 03:44:39 +0000
parents 983fd420e86b
children 16102b9c5c4a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
1 /**
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
2 * The QQ2003C protocol plugin
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
3 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
4 * for gaim
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
5 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
6 * Copyright (C) 2004 Puzzlebird
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
7 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
11 * (at your option) any later version.
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
12 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
16 * GNU General Public License for more details.
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
17 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
21 */
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
22
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
23 // START OF FILE
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
24 /*****************************************************************************/
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
25 #include "internal.h" // strlen, _("get_text)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
26 #include "debug.h" // gaim_debug
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
27 #include "notify.h" // gaim_notify
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
28
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
29 #include "utils.h" // uid_to_gaim_name
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
30 #include "packet_parse.h" // MAX_PACKET_SIZE
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
31 #include "buddy_info.h" //
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
32 #include "char_conv.h" // qq_to_utf8
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
33 #include "crypt.h" // qq_crypt
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
34 #include "header_info.h" // cmd alias
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
35 #include "infodlg.h" // info_window
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
36 #include "keep_alive.h" // qq_update_buddy_contact
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
37 #include "send_core.h" // qq_send_cmd
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
38
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
39 // amount of fiedls in user info
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
40 #define QQ_CONTACT_FIELDS 37
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
41
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
42 // There is no user id stored in the reply packet for information query
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
43 // we have to manually store the query, so that we know the query source
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
44 typedef struct _qq_info_query {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
45 guint32 uid;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
46 gboolean show_window;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
47 contact_info *ret_info;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
48 } qq_info_query;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
49
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
50 /*****************************************************************************/
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
51 // send a packet to get detailed information of uid,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
52 // if show_window, a info window will be display upon receiving a reply
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
53 void qq_send_packet_get_info(GaimConnection * gc, guint32 uid, gboolean show_window)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
54 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
55 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
56 gchar *uid_str;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
57 GList *list;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
58 qq_info_query *query;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
59 gboolean is_exist;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
60 contact_info_window *info_window;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
61
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
62 g_return_if_fail(gc != NULL && gc->proto_data != NULL && uid != 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
63
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
64 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
65 uid_str = g_strdup_printf("%d", uid);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
66 qq_send_cmd(gc, QQ_CMD_GET_USER_INFO, TRUE, 0, TRUE, uid_str, strlen(uid_str));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
67
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
68 if (show_window) { // prepare the window
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
69 is_exist = FALSE; // see if there is already a window for this uid
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
70 list = qd->contact_info_window;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
71 while (list != NULL) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
72 info_window = (contact_info_window *) list->data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
73 if (uid == info_window->uid) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
74 is_exist = TRUE;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
75 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
76 } else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
77 list = list->next;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
78 } // while list
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
79 if (!is_exist) { // create a new one
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
80 info_window = g_new0(contact_info_window, 1);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
81 info_window->uid = uid;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
82 qd->contact_info_window = g_list_append(qd->contact_info_window, info_window);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
83 } // if !is_exist
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
84 } // if show_window
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
85
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
86 query = g_new0(qq_info_query, 1);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
87 query->uid = uid;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
88 query->show_window = show_window;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
89 qd->info_query = g_list_append(qd->info_query, query);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
90
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
91 g_free(uid_str);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
92 } // qq_send_packet_get_info
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
93
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
94 /*****************************************************************************/
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
95 // send packet to modify personal information, and/or change password
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
96 void qq_send_packet_modify_info(GaimConnection * gc, contact_info * info, gchar * new_passwd)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
97 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
98 GaimAccount *a;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
99 gchar *old_passwd, *info_field[QQ_CONTACT_FIELDS];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
100 gint i;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
101 guint8 *raw_data, *cursor, bar;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
102
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
103 g_return_if_fail(gc != NULL && info != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
104
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
105 a = gc->account;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
106 old_passwd = a->password;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
107 bar = 0x1f;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
108 raw_data = g_newa(guint8, MAX_PACKET_SIZE - 128);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
109 cursor = raw_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
110
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
111 g_memmove(info_field, info, sizeof(gchar *) * QQ_CONTACT_FIELDS);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
112
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
113 if (new_passwd == NULL || strlen(new_passwd) == 0)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
114 create_packet_b(raw_data, &cursor, bar);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
115 else { // we gonna change passwd
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
116 create_packet_data(raw_data, &cursor, old_passwd, strlen(old_passwd));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
117 create_packet_b(raw_data, &cursor, bar);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
118 create_packet_data(raw_data, &cursor, new_passwd, strlen(new_passwd));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
119 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
120
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
121 // important!, skip the first uid entry
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
122 for (i = 1; i < QQ_CONTACT_FIELDS; i++) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
123 create_packet_b(raw_data, &cursor, bar);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
124 create_packet_data(raw_data, &cursor, info_field[i], strlen(info_field[i]));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
125 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
126 create_packet_b(raw_data, &cursor, bar);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
127
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
128 qq_send_cmd(gc, QQ_CMD_UPDATE_INFO, TRUE, 0, TRUE, raw_data, cursor - raw_data);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
129
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
130 } // qq_send_packet_modify_info
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
131
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
132 /*****************************************************************************/
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
133 // process the reply of modidy_info packet
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
134 void qq_process_modify_info_reply(guint8 * buf, gint buf_len, GaimConnection * gc)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
135 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
136 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
137 gint len;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
138 guint8 *data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
139
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
140 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
141 g_return_if_fail(buf != NULL && buf_len != 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
142
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
143 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
144 len = buf_len;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
145 data = g_newa(guint8, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
146
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
147 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
148 if (qd->uid == atoi(data)) { // return should be my uid
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
149 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Update info ACK OK\n");
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
150 gaim_notify_info(gc, NULL, _("You information have been updated"), NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
151 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
152 } else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
153 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt modify info reply\n");
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
154
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
155 } // qq_process_modify_info_reply
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
156
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
157 /*****************************************************************************/
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
158 // after getting info or modify myself, refresh the buddy list accordingly
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
159 void qq_refresh_buddy_and_myself(contact_info * info, GaimConnection * gc)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
160 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
161 GaimBuddy *b;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
162 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
163 qq_buddy *q_bud;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
164 gchar *alias_utf8;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
165
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
166 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
167 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
168
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
169 alias_utf8 = qq_to_utf8(info->nick, QQ_CHARSET_DEFAULT);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
170 if (qd->uid == strtol(info->uid, NULL, 10)) { // it is me
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
171 qd->my_icon = strtol(info->face, NULL, 10);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
172 if (alias_utf8 != NULL)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
173 gaim_account_set_alias(gc->account, alias_utf8);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
174 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
175 // update buddy list (including myself, if myself is the buddy)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
176 b = gaim_find_buddy(gc->account, uid_to_gaim_name(strtol(info->uid, NULL, 10)));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
177 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
178 if (q_bud != NULL) { // I have this buddy
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
179 q_bud->age = strtol(info->age, NULL, 10);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
180 q_bud->gender = strtol(info->gender, NULL, 10);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
181 q_bud->icon = strtol(info->face, NULL, 10);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
182 if (alias_utf8 != NULL)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
183 q_bud->nickname = g_strdup(alias_utf8);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
184 qq_update_buddy_contact(gc, q_bud);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
185 } // if q_bud
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
186 g_free(alias_utf8);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
187 } // qq_refresh_buddy_and_myself
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
188
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
189 /*****************************************************************************/
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
190 // process reply to get_info packet
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
191 void qq_process_get_info_reply(guint8 * buf, gint buf_len, GaimConnection * gc)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
192 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
193 gint len;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
194 guint8 *data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
195 gchar **segments;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
196 qq_info_query *query;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
197 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
198 contact_info *info;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
199 contact_info_window *info_window;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
200 gboolean show_window;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
201 GList *list, *query_list;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
202
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
203 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
204 g_return_if_fail(buf != NULL && buf_len != 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
205
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
206 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
207 list = query_list = NULL;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
208 len = buf_len;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
209 data = g_newa(guint8, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
210 info = NULL;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
211
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
212 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
213 if (NULL == (segments = split_data(data, len, "\x1e", QQ_CONTACT_FIELDS)))
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
214 return;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
215
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
216 info = (contact_info *) segments;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
217 qq_refresh_buddy_and_myself(info, gc);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
218
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
219 query_list = qd->info_query;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
220 show_window = FALSE;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
221 while (query_list != NULL) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
222 query = (qq_info_query *) query_list->data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
223 if (query->uid == atoi(info->uid)) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
224 show_window = query->show_window;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
225 qd->info_query = g_list_remove(qd->info_query, qd->info_query->data);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
226 g_free(query);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
227 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
228 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
229 query_list = query_list->next;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
230 } // while query_list
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
231
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
232 if (!show_window) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
233 g_strfreev(segments);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
234 return;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
235 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
236 // if not show_window, we can not find the window here either
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
237 list = qd->contact_info_window;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
238 while (list != NULL) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
239 info_window = (contact_info_window *) (list->data);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
240 if (info_window->uid == atoi(info->uid)) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
241 if (info_window->window)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
242 qq_refresh_contact_info_dialog(info, gc, info_window);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
243 else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
244 qq_show_contact_info_dialog(info, gc, info_window);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
245 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
246 } else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
247 list = list->next;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
248 } // while list
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
249 g_strfreev(segments);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
250 } else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
251 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt get info reply\n");
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
252
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
253 } // qq_process_get_info_reply
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
254
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
255 /*****************************************************************************/
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
256 void qq_info_query_free(qq_data * qd)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
257 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
258 gint i;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
259 qq_info_query *p;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
260
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
261 g_return_if_fail(qd != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
262
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
263 i = 0;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
264 while (qd->info_query != NULL) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
265 p = (qq_info_query *) (qd->info_query->data);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
266 qd->info_query = g_list_remove(qd->info_query, p);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
267 g_free(p);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
268 i++;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
269 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
270 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d info queries are freed!\n", i);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
271 } // qq_add_buddy_request_free
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
272
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
273 /*****************************************************************************/
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
274 // END OF FILE