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
|
14021
|
23 #include <string.h>
|
|
24 #include "debug.h"
|
|
25 #include "prefs.h"
|
13870
|
26
|
|
27 #include "buddy_status.h"
|
14021
|
28 #include "crypt.h"
|
|
29 #include "header_info.h"
|
|
30 #include "keep_alive.h"
|
|
31 #include "packet_parse.h"
|
|
32 #include "send_core.h"
|
|
33 #include "utils.h"
|
13870
|
34
|
13989
|
35 #include "qq_proxy.h"
|
|
36
|
13870
|
37 #define QQ_MISC_STATUS_HAVING_VIIDEO 0x00000001
|
|
38
|
|
39 #define QQ_ICON_SUFFIX_DEFAULT QQ_ICON_SUFFIX_OFFLINE
|
14021
|
40 #define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 0x30 /* ASCII value of "0" */
|
13870
|
41
|
|
42 enum {
|
|
43 QQ_ICON_SUFFIX_NORMAL = 1,
|
|
44 QQ_ICON_SUFFIX_OFFLINE = 2,
|
|
45 QQ_ICON_SUFFIX_AWAY = 3,
|
|
46 };
|
|
47
|
14021
|
48 void qq_buddy_status_dump_unclear(qq_buddy_status *s)
|
13870
|
49 {
|
|
50 GString *dump;
|
|
51
|
|
52 g_return_if_fail(s != NULL);
|
|
53
|
|
54 dump = g_string_new("");
|
|
55 g_string_append_printf(dump, "unclear fields for [%d]:\n", s->uid);
|
|
56 g_string_append_printf(dump, "004: %02x (unknown)\n", s->unknown1);
|
14021
|
57 /* g_string_append_printf(dump, "005-008: %09x (ip)\n", *(s->ip)); */
|
13989
|
58 g_string_append_printf(dump, "009-010: %04x (port)\n", s->port);
|
13870
|
59 g_string_append_printf(dump, "011: %02x (unknown)\n", s->unknown2);
|
13989
|
60 g_string_append_printf(dump, "012: %02x (status)\n", s->status);
|
|
61 g_string_append_printf(dump, "013-014: %04x (client_version)\n", s->client_version);
|
14021
|
62 /* g_string_append_printf(dump, "015-030: %s (unknown key)\n", s->unknown_key); */
|
13870
|
63 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Buddy status entry, %s", dump->str);
|
13989
|
64 _qq_show_packet("Unknown key", s->unknown_key, QQ_KEY_LENGTH);
|
13870
|
65 g_string_free(dump, TRUE);
|
13989
|
66 }
|
13870
|
67
|
14021
|
68 /* TODO: figure out what's going on with the IP region. Sometimes I get valid IP addresses,
|
|
69 * but the port number's weird, other times I get 0s. I get these simultaneously on the same buddy,
|
|
70 * using different accounts to get info. */
|
|
71
|
|
72 /* parse the data into qq_buddy_status */
|
|
73 gint qq_buddy_status_read(guint8 *data, guint8 **cursor, gint len, qq_buddy_status *s)
|
|
74 {
|
13870
|
75 gint bytes;
|
|
76
|
|
77 g_return_val_if_fail(data != NULL && *cursor != NULL && s != NULL, -1);
|
|
78
|
|
79 bytes = 0;
|
|
80
|
14021
|
81 /* 000-003: uid */
|
13870
|
82 bytes += read_packet_dw(data, cursor, len, &s->uid);
|
14021
|
83 /* 004-004: 0x01 */
|
13870
|
84 bytes += read_packet_b(data, cursor, len, &s->unknown1);
|
14021
|
85 /* this is no longer the IP, it seems QQ (as of 2006) no longer sends
|
|
86 * the buddy's IP in this packet. all 0s */
|
|
87 /* 005-008: ip */
|
13870
|
88 s->ip = g_new0(guint8, 4);
|
|
89 bytes += read_packet_data(data, cursor, len, s->ip, 4);
|
14021
|
90 /* port info is no longer here either */
|
|
91 /* 009-010: port */
|
13870
|
92 bytes += read_packet_w(data, cursor, len, &s->port);
|
14021
|
93 /* 011-011: 0x00 */
|
13870
|
94 bytes += read_packet_b(data, cursor, len, &s->unknown2);
|
14021
|
95 /* 012-012: status */
|
13870
|
96 bytes += read_packet_b(data, cursor, len, &s->status);
|
14021
|
97 /* 013-014: client_version */
|
13870
|
98 bytes += read_packet_w(data, cursor, len, &s->client_version);
|
14021
|
99 /* 015-030: unknown key */
|
13870
|
100 s->unknown_key = g_new0(guint8, QQ_KEY_LENGTH);
|
|
101 bytes += read_packet_data(data, cursor, len, s->unknown_key, QQ_KEY_LENGTH);
|
|
102
|
|
103 if (s->uid == 0 || bytes != 31)
|
|
104 return -1;
|
|
105
|
|
106 return bytes;
|
13989
|
107 }
|
13870
|
108
|
14021
|
109 /* check if status means online or offline */
|
13870
|
110 gboolean is_online(guint8 status)
|
|
111 {
|
|
112 switch(status) {
|
|
113 case QQ_BUDDY_ONLINE_NORMAL:
|
|
114 case QQ_BUDDY_ONLINE_AWAY:
|
|
115 case QQ_BUDDY_ONLINE_INVISIBLE:
|
|
116 return TRUE;
|
|
117 case QQ_BUDDY_ONLINE_OFFLINE:
|
|
118 return FALSE;
|
|
119 }
|
|
120 return FALSE;
|
14021
|
121 }
|
13870
|
122
|
14021
|
123 /* the icon suffix is detemined by status
|
|
124 * although QQ server may return the right icon, I set it here myself */
|
13870
|
125 gchar get_suffix_from_status(guint8 status)
|
|
126 {
|
|
127 switch (status) {
|
|
128 case QQ_BUDDY_ONLINE_NORMAL:
|
|
129 return QQ_ICON_SUFFIX_NORMAL;
|
|
130 case QQ_BUDDY_ONLINE_AWAY:
|
|
131 return QQ_ICON_SUFFIX_AWAY;
|
|
132 case QQ_BUDDY_ONLINE_INVISIBLE:
|
|
133 case QQ_BUDDY_ONLINE_OFFLINE:
|
|
134 return QQ_ICON_SUFFIX_OFFLINE;
|
|
135 default:
|
|
136 return QQ_ICON_SUFFIX_DEFAULT;
|
14021
|
137 }
|
|
138 }
|
13870
|
139
|
14021
|
140 /* send a packet to change my online status */
|
|
141 void qq_send_packet_change_status(GaimConnection *gc)
|
13870
|
142 {
|
|
143 qq_data *qd;
|
|
144 guint8 *raw_data, *cursor, away_cmd;
|
|
145 guint32 misc_status;
|
|
146 gboolean fake_video;
|
|
147
|
|
148 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
149
|
|
150 qd = (qq_data *) gc->proto_data;
|
|
151 if (!qd->logged_in)
|
|
152 return;
|
|
153
|
|
154 switch (qd->status) {
|
|
155 case QQ_SELF_STATUS_AVAILABLE:
|
|
156 away_cmd = QQ_BUDDY_ONLINE_NORMAL;
|
|
157 break;
|
|
158 case QQ_SELF_STATUS_INVISIBLE:
|
|
159 away_cmd = QQ_BUDDY_ONLINE_INVISIBLE;
|
|
160 break;
|
|
161 case QQ_SELF_STATUS_AWAY:
|
|
162 case QQ_SELF_STATUS_IDLE:
|
|
163 case QQ_SELF_STATUS_CUSTOM:
|
|
164 away_cmd = QQ_BUDDY_ONLINE_AWAY;
|
|
165 break;
|
|
166 default:
|
|
167 away_cmd = QQ_BUDDY_ONLINE_NORMAL;
|
13989
|
168 }
|
13870
|
169
|
|
170 raw_data = g_new0(guint8, 5);
|
|
171 cursor = raw_data;
|
|
172 misc_status = 0x00000000;
|
|
173
|
|
174 fake_video = gaim_prefs_get_bool("/plugins/prpl/qq/show_fake_video");
|
|
175 if (fake_video)
|
|
176 misc_status |= QQ_MISC_STATUS_HAVING_VIIDEO;
|
|
177
|
|
178 create_packet_b(raw_data, &cursor, away_cmd);
|
|
179 create_packet_dw(raw_data, &cursor, misc_status);
|
|
180
|
|
181 qq_send_cmd(gc, QQ_CMD_CHANGE_ONLINE_STATUS, TRUE, 0, TRUE, raw_data, 5);
|
|
182
|
|
183 g_free(raw_data);
|
13989
|
184 }
|
13870
|
185
|
14021
|
186 /* parse the reply packet for change_status */
|
|
187 void qq_process_change_status_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
|
|
188 {
|
13870
|
189 qq_data *qd;
|
|
190 gint len;
|
|
191 guint8 *data, *cursor, reply;
|
|
192
|
|
193 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
194 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
195
|
|
196 qd = (qq_data *) gc->proto_data;
|
|
197 len = buf_len;
|
|
198 data = g_newa(guint8, len);
|
|
199
|
|
200 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
201 cursor = data;
|
|
202 read_packet_b(data, &cursor, len, &reply);
|
|
203 if (reply != QQ_CHANGE_ONLINE_STATUS_REPLY_OK) {
|
|
204 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Change status fail\n");
|
|
205 } else
|
|
206 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Change status OK\n");
|
|
207 } else
|
|
208 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt chg status reply\n");
|
|
209
|
13989
|
210 }
|
13870
|
211
|
14021
|
212 /* it is a server message indicating that one of my buddies has changed its status */
|
|
213 void qq_process_friend_change_status(guint8 *buf, gint buf_len, GaimConnection *gc)
|
|
214 {
|
13870
|
215 qq_data *qd;
|
|
216 gint len, bytes;
|
|
217 guint32 my_uid;
|
|
218 guint8 *data, *cursor;
|
|
219 GaimBuddy *b;
|
|
220 qq_buddy *q_bud;
|
|
221 qq_buddy_status *s;
|
|
222 gchar *name;
|
|
223
|
|
224 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
225 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
226
|
|
227 qd = (qq_data *) gc->proto_data;
|
|
228 len = buf_len;
|
|
229 data = g_newa(guint8, len);
|
|
230 cursor = data;
|
|
231
|
|
232 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
233 s = g_new0(qq_buddy_status, 1);
|
|
234 bytes = 0;
|
14021
|
235 /* 000-030: qq_buddy_status */
|
13989
|
236 bytes += qq_buddy_status_read(data, &cursor, len, s);
|
14021
|
237 /* 031-034: my uid */
|
13870
|
238 bytes += read_packet_dw(data, &cursor, len, &my_uid);
|
|
239
|
|
240 if (my_uid == 0 || bytes != 35) {
|
|
241 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "my_uid == 0 || bytes(%d) != 35\n", bytes);
|
|
242 g_free(s->ip);
|
|
243 g_free(s->unknown_key);
|
|
244 g_free(s);
|
|
245 return;
|
|
246 }
|
|
247
|
13989
|
248 name = uid_to_gaim_name(s->uid);
|
13870
|
249 b = gaim_find_buddy(gc->account, name);
|
|
250 g_free(name);
|
|
251 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
|
|
252 if (q_bud) {
|
|
253 gaim_debug(GAIM_DEBUG_INFO, "QQ", "s->uid = %d, q_bud->uid = %d\n", s->uid , q_bud->uid);
|
13989
|
254 if(0 != *((guint32 *)s->ip)) {
|
13870
|
255 g_memmove(q_bud->ip, s->ip, 4);
|
|
256 q_bud->port = s->port;
|
|
257 }
|
|
258 q_bud->status = s->status;
|
|
259 if(0 != s->client_version)
|
13989
|
260 q_bud->client_version = s->client_version;
|
13870
|
261 qq_update_buddy_contact(gc, q_bud);
|
14021
|
262 } else {
|
|
263 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
264 "got information of unknown buddy by gfhuang %d\n", s->uid);
|
13870
|
265 }
|
|
266
|
|
267 g_free(s->ip);
|
|
268 g_free(s->unknown_key);
|
|
269 g_free(s);
|
14021
|
270 } else {
|
13870
|
271 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddy status change packet\n");
|
14021
|
272 }
|
13989
|
273 }
|