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