|
14192
|
1 /**
|
|
15025
|
2 * @file sys_msg.c
|
|
14192
|
3 *
|
|
15025
|
4 * gaim
|
|
14192
|
5 *
|
|
15025
|
6 * Gaim 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
|
|
|
8 * source distribution.
|
|
14192
|
9 *
|
|
|
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
|
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
|
13 * (at your option) any later version.
|
|
|
14 *
|
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 * GNU General Public License for more details.
|
|
|
19 *
|
|
|
20 * You should have received a copy of the GNU General Public License
|
|
|
21 * along with this program; if not, write to the Free Software
|
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
23 */
|
|
|
24
|
|
|
25 #include "debug.h"
|
|
|
26 #include "internal.h"
|
|
|
27 #include "notify.h"
|
|
|
28 #include "request.h"
|
|
|
29
|
|
|
30 #include "buddy_info.h"
|
|
|
31 #include "buddy_list.h"
|
|
|
32 #include "buddy_opt.h"
|
|
|
33 #include "char_conv.h"
|
|
|
34 #include "crypt.h"
|
|
|
35 #include "header_info.h"
|
|
|
36 #include "packet_parse.h"
|
|
|
37 #include "qq.h"
|
|
|
38 #include "send_core.h"
|
|
|
39 #include "sys_msg.h"
|
|
|
40 #include "utils.h"
|
|
|
41
|
|
|
42 enum {
|
|
|
43 QQ_MSG_SYS_BEING_ADDED = 0x01,
|
|
|
44 QQ_MSG_SYS_ADD_CONTACT_REQUEST = 0x02,
|
|
|
45 QQ_MSG_SYS_ADD_CONTACT_APPROVED = 0x03,
|
|
|
46 QQ_MSG_SYS_ADD_CONTACT_REJECTED = 0x04,
|
|
|
47 QQ_MSG_SYS_NEW_VERSION = 0x09
|
|
|
48 };
|
|
|
49
|
|
|
50 /* Henry: private function for reading/writing of system log */
|
|
|
51 static void _qq_sys_msg_log_write(GaimConnection *gc, gchar *msg, gchar *from)
|
|
|
52 {
|
|
|
53 GaimLog *log;
|
|
|
54 GaimAccount *account;
|
|
|
55
|
|
|
56 account = gaim_connection_get_account(gc);
|
|
|
57
|
|
|
58 log = gaim_log_new(GAIM_LOG_IM,
|
|
|
59 "systemim",
|
|
|
60 account,
|
|
|
61 NULL,
|
|
|
62 time(NULL),
|
|
|
63 NULL
|
|
|
64 );
|
|
|
65 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, from,
|
|
|
66 time(NULL), msg);
|
|
|
67 gaim_log_free(log);
|
|
|
68 }
|
|
|
69
|
|
|
70 /* suggested by rakescar@linuxsir, can still approve after search */
|
|
|
71 static void _qq_search_before_auth_with_gc_and_uid(gc_and_uid *g)
|
|
|
72 {
|
|
|
73 GaimConnection *gc;
|
|
|
74 guint32 uid;
|
|
|
75
|
|
|
76 g_return_if_fail(g != NULL);
|
|
|
77
|
|
|
78 gc = g->gc;
|
|
|
79 uid = g->uid;
|
|
|
80 g_return_if_fail(gc != 0 && uid != 0);
|
|
|
81
|
|
|
82 qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */
|
|
|
83 gaim_request_action
|
|
|
84 (gc, NULL, _("Do you wanna approve the request?"), "", 2, g, 2,
|
|
|
85 _("Reject"),
|
|
|
86 G_CALLBACK(qq_reject_add_request_with_gc_and_uid),
|
|
|
87 _("Approve"), G_CALLBACK(qq_approve_add_request_with_gc_and_uid));
|
|
|
88 }
|
|
|
89
|
|
|
90 static void _qq_search_before_add_with_gc_and_uid(gc_and_uid *g)
|
|
|
91 {
|
|
|
92 GaimConnection *gc;
|
|
|
93 guint32 uid;
|
|
|
94
|
|
|
95 g_return_if_fail(g != NULL);
|
|
|
96
|
|
|
97 gc = g->gc;
|
|
|
98 uid = g->uid;
|
|
|
99 g_return_if_fail(gc != 0 && uid != 0);
|
|
|
100
|
|
|
101 qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */
|
|
|
102 gaim_request_action
|
|
|
103 (gc, NULL, _("Do you wanna add this buddy?"), "", 2, g, 2,
|
|
|
104 _("Cancel"), NULL, _("Add"), G_CALLBACK(qq_add_buddy_with_gc_and_uid));
|
|
|
105 }
|
|
|
106
|
|
|
107 /* Send ACK if the sys message needs an ACK */
|
|
|
108 static void _qq_send_packet_ack_msg_sys(GaimConnection *gc, guint8 code, guint32 from, guint16 seq)
|
|
|
109 {
|
|
|
110 guint8 bar, *ack, *cursor;
|
|
|
111 gchar *str;
|
|
|
112 gint ack_len, bytes;
|
|
|
113
|
|
|
114 str = g_strdup_printf("%d", from);
|
|
|
115 bar = 0x1e;
|
|
|
116 ack_len = 1 + 1 + strlen(str) + 1 + 2;
|
|
|
117 ack = g_newa(guint8, ack_len);
|
|
|
118 cursor = ack;
|
|
|
119 bytes = 0;
|
|
|
120
|
|
|
121 bytes += create_packet_b(ack, &cursor, code);
|
|
|
122 bytes += create_packet_b(ack, &cursor, bar);
|
|
|
123 bytes += create_packet_data(ack, &cursor, (guint8 *) str, strlen(str));
|
|
|
124 bytes += create_packet_b(ack, &cursor, bar);
|
|
|
125 bytes += create_packet_w(ack, &cursor, seq);
|
|
|
126
|
|
|
127 g_free(str);
|
|
|
128
|
|
|
129 if (bytes == ack_len) /* creation OK */
|
|
|
130 qq_send_cmd(gc, QQ_CMD_ACK_SYS_MSG, TRUE, 0, FALSE, ack, ack_len);
|
|
|
131 else
|
|
|
132 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
|
133 "Fail creating sys msg ACK, expect %d bytes, build %d bytes\n", ack_len, bytes);
|
|
|
134 }
|
|
|
135
|
|
|
136 /* when you are added by a person, QQ server will send sys message */
|
|
|
137 static void _qq_process_msg_sys_being_added(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8)
|
|
|
138 {
|
|
|
139 gchar *message;
|
|
|
140 GaimBuddy *b;
|
|
|
141 guint32 uid;
|
|
|
142 gc_and_uid *g;
|
|
|
143 gchar *name;
|
|
|
144
|
|
14629
|
145 g_return_if_fail(from != NULL && to != NULL);
|
|
14192
|
146
|
|
|
147 uid = strtol(from, NULL, 10);
|
|
|
148 name = uid_to_gaim_name(uid);
|
|
|
149 b = gaim_find_buddy(gc->account, name);
|
|
|
150 g_free(name);
|
|
|
151 if (b == NULL) { /* the person is not in my list */
|
|
|
152 g = g_new0(gc_and_uid, 1);
|
|
|
153 g->gc = gc;
|
|
|
154 g->uid = uid; /* only need to get value */
|
|
|
155 message = g_strdup_printf(_("You have been added by %s"), from);
|
|
|
156 _qq_sys_msg_log_write(gc, message, from);
|
|
|
157 gaim_request_action(gc, NULL, message,
|
|
|
158 _("Would like to add him?"), 2, g, 3,
|
|
|
159 _("Cancel"), NULL, _("Add"),
|
|
|
160 G_CALLBACK
|
|
|
161 (qq_add_buddy_with_gc_and_uid),
|
|
|
162 _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid));
|
|
|
163 } else {
|
|
|
164 message = g_strdup_printf(_("%s has added you [%s]"), from, to);
|
|
|
165 _qq_sys_msg_log_write(gc, message, from);
|
|
|
166 gaim_notify_info(gc, NULL, message, NULL);
|
|
|
167 }
|
|
|
168
|
|
|
169 g_free(message);
|
|
|
170 }
|
|
|
171
|
|
|
172 /* you are rejected by the person */
|
|
|
173 static void _qq_process_msg_sys_add_contact_rejected(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8)
|
|
|
174 {
|
|
|
175 gchar *message, *reason;
|
|
|
176
|
|
14629
|
177 g_return_if_fail(from != NULL && to != NULL);
|
|
14192
|
178
|
|
|
179 message = g_strdup_printf(_("User %s rejected your request"), from);
|
|
|
180 reason = g_strdup_printf(_("Reason: %s"), msg_utf8);
|
|
|
181 _qq_sys_msg_log_write(gc, message, from);
|
|
|
182
|
|
|
183 gaim_notify_info(gc, NULL, message, reason);
|
|
|
184 g_free(message);
|
|
|
185 g_free(reason);
|
|
|
186 }
|
|
|
187
|
|
|
188 /* the buddy approves your request of adding him/her as your friend */
|
|
|
189 static void _qq_process_msg_sys_add_contact_approved(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8)
|
|
|
190 {
|
|
|
191 gchar *message;
|
|
|
192 qq_data *qd;
|
|
|
193
|
|
14629
|
194 g_return_if_fail(from != NULL && to != NULL);
|
|
14192
|
195
|
|
|
196 qd = (qq_data *) gc->proto_data;
|
|
|
197 qq_add_buddy_by_recv_packet(gc, strtol(from, NULL, 10), TRUE, TRUE);
|
|
|
198
|
|
14345
|
199 message = g_strdup_printf(_("User %s has approved your request"), from);
|
|
14192
|
200 _qq_sys_msg_log_write(gc, message, from);
|
|
|
201 gaim_notify_info(gc, NULL, message, NULL);
|
|
|
202
|
|
|
203 g_free(message);
|
|
|
204 }
|
|
|
205
|
|
|
206 /* someone wants to add you to his buddy list */
|
|
|
207 static void _qq_process_msg_sys_add_contact_request(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8)
|
|
|
208 {
|
|
|
209 gchar *message, *reason;
|
|
|
210 guint32 uid;
|
|
|
211 gc_and_uid *g, *g2;
|
|
|
212 GaimBuddy *b;
|
|
|
213 gchar *name;
|
|
|
214
|
|
14629
|
215 g_return_if_fail(from != NULL && to != NULL);
|
|
14192
|
216
|
|
|
217 uid = strtol(from, NULL, 10);
|
|
|
218 g = g_new0(gc_and_uid, 1);
|
|
|
219 g->gc = gc;
|
|
|
220 g->uid = uid;
|
|
|
221
|
|
|
222 message = g_strdup_printf(_("%s wanna add you [%s] as friends"), from, to);
|
|
|
223 reason = g_strdup_printf(_("Message: %s"), msg_utf8);
|
|
|
224 _qq_sys_msg_log_write(gc, message, from);
|
|
|
225
|
|
|
226 gaim_request_action
|
|
|
227 (gc, NULL, message, reason, 2, g, 3,
|
|
|
228 _("Reject"),
|
|
|
229 G_CALLBACK(qq_reject_add_request_with_gc_and_uid),
|
|
|
230 _("Approve"),
|
|
|
231 G_CALLBACK(qq_approve_add_request_with_gc_and_uid),
|
|
|
232 _("Search"), G_CALLBACK(_qq_search_before_auth_with_gc_and_uid));
|
|
|
233
|
|
|
234 g_free(message);
|
|
|
235 g_free(reason);
|
|
|
236
|
|
|
237 name = uid_to_gaim_name(uid);
|
|
|
238 b = gaim_find_buddy(gc->account, name);
|
|
|
239 g_free(name);
|
|
|
240 if (b == NULL) { /* the person is not in my list */
|
|
|
241 g2 = g_new0(gc_and_uid, 1);
|
|
|
242 g2->gc = gc;
|
|
|
243 g2->uid = strtol(from, NULL, 10);
|
|
|
244 message = g_strdup_printf(_("%s is not in your buddy list"), from);
|
|
|
245 gaim_request_action(gc, NULL, message,
|
|
|
246 _("Would you like to add him?"), 2, g2,
|
|
|
247 3, _("Cancel"), NULL, _("Add"),
|
|
|
248 G_CALLBACK
|
|
|
249 (qq_add_buddy_with_gc_and_uid),
|
|
|
250 _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid));
|
|
|
251 g_free(message);
|
|
|
252 }
|
|
|
253 }
|
|
|
254
|
|
|
255 void qq_process_msg_sys(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc)
|
|
|
256 {
|
|
|
257 qq_data *qd;
|
|
|
258 gint len;
|
|
|
259 guint8 *data;
|
|
|
260 gchar **segments, *code, *from, *to, *msg, *msg_utf8;
|
|
|
261
|
|
|
262 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
|
263
|
|
|
264 qd = (qq_data *) gc->proto_data;
|
|
|
265 len = buf_len;
|
|
|
266 data = g_newa(guint8, len);
|
|
|
267
|
|
|
268 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
|
269 if (NULL == (segments = split_data(data, len, "\x1f", 4)))
|
|
|
270 return;
|
|
|
271 code = segments[0];
|
|
|
272 from = segments[1];
|
|
|
273 to = segments[2];
|
|
|
274 msg = segments[3];
|
|
|
275
|
|
|
276 _qq_send_packet_ack_msg_sys(gc, code[0], strtol(from, NULL, 10), seq);
|
|
|
277
|
|
|
278 if (strtol(to, NULL, 10) != qd->uid) { /* not to me */
|
|
|
279 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Recv sys msg to [%s], not me!, discard\n", to);
|
|
|
280 g_strfreev(segments);
|
|
|
281 return;
|
|
|
282 }
|
|
|
283
|
|
|
284 msg_utf8 = qq_to_utf8(msg, QQ_CHARSET_DEFAULT);
|
|
|
285 switch (strtol(code, NULL, 10)) {
|
|
|
286 case QQ_MSG_SYS_BEING_ADDED:
|
|
|
287 _qq_process_msg_sys_being_added(gc, from, to, msg_utf8);
|
|
|
288 break;
|
|
|
289 case QQ_MSG_SYS_ADD_CONTACT_REQUEST:
|
|
|
290 _qq_process_msg_sys_add_contact_request(gc, from, to, msg_utf8);
|
|
|
291 break;
|
|
|
292 case QQ_MSG_SYS_ADD_CONTACT_APPROVED:
|
|
|
293 _qq_process_msg_sys_add_contact_approved(gc, from, to, msg_utf8);
|
|
|
294 break;
|
|
|
295 case QQ_MSG_SYS_ADD_CONTACT_REJECTED:
|
|
|
296 _qq_process_msg_sys_add_contact_rejected(gc, from, to, msg_utf8);
|
|
|
297 break;
|
|
|
298 case QQ_MSG_SYS_NEW_VERSION:
|
|
|
299 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
|
300 "QQ server says there is newer version than %s\n", qq_get_source_str(QQ_CLIENT));
|
|
|
301 break;
|
|
|
302 default:
|
|
|
303 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Recv unknown sys msg code: %s\n", code);
|
|
|
304 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "the msg is : %s\n", msg_utf8);
|
|
|
305 }
|
|
|
306 g_free(msg_utf8);
|
|
|
307 g_strfreev(segments);
|
|
|
308
|
|
|
309 } else {
|
|
|
310 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt recv msg sys\n");
|
|
|
311 }
|
|
|
312 }
|