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