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