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