comparison src/protocols/qq/buddy_status.c @ 14021:ef8490f9e823

[gaim-migrate @ 16618] Replaced all C++-style comments with C-style ones. Cleaned up some comments and implemented a more consistent formatting scheme. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Wed, 02 Aug 2006 15:35:36 +0000
parents 16102b9c5c4a
children
comparison
equal deleted inserted replaced
14020:13e7ba964993 14021:ef8490f9e823
18 * You should have received a copy of the GNU General Public License 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 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 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23 // START OF FILE 23 #include <string.h>
24 /*****************************************************************************/ 24 #include "debug.h"
25 #include <string.h> // g_memmove 25 #include "prefs.h"
26 #include "debug.h" // gaim_debug 26
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" 27 #include "buddy_status.h"
32 #include "crypt.h" // qq_crypt.h 28 #include "crypt.h"
33 #include "header_info.h" // cmd alias 29 #include "header_info.h"
34 #include "keep_alive.h" // qq_update_buddy_contact 30 #include "keep_alive.h"
35 #include "send_core.h" // qq_send_cmd 31 #include "packet_parse.h"
32 #include "send_core.h"
33 #include "utils.h"
36 34
37 #include "qq_proxy.h" 35 #include "qq_proxy.h"
38 36
39 #define QQ_MISC_STATUS_HAVING_VIIDEO 0x00000001 37 #define QQ_MISC_STATUS_HAVING_VIIDEO 0x00000001
40 38
41 #define QQ_ICON_SUFFIX_DEFAULT QQ_ICON_SUFFIX_OFFLINE 39 #define QQ_ICON_SUFFIX_DEFAULT QQ_ICON_SUFFIX_OFFLINE
42 #define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 0x30 // ASCii value of "0" 40 #define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 0x30 /* ASCII value of "0" */
43 41
44 enum { 42 enum {
45 QQ_ICON_SUFFIX_NORMAL = 1, 43 QQ_ICON_SUFFIX_NORMAL = 1,
46 QQ_ICON_SUFFIX_OFFLINE = 2, 44 QQ_ICON_SUFFIX_OFFLINE = 2,
47 QQ_ICON_SUFFIX_AWAY = 3, 45 QQ_ICON_SUFFIX_AWAY = 3,
48 }; 46 };
49 47
50 /*****************************************************************************/ 48 void qq_buddy_status_dump_unclear(qq_buddy_status *s)
51 void qq_buddy_status_dump_unclear(qq_buddy_status * s)
52 { 49 {
53 GString *dump; 50 GString *dump;
54 51
55 g_return_if_fail(s != NULL); 52 g_return_if_fail(s != NULL);
56 53
57 dump = g_string_new(""); 54 dump = g_string_new("");
58 g_string_append_printf(dump, "unclear fields for [%d]:\n", s->uid); 55 g_string_append_printf(dump, "unclear fields for [%d]:\n", s->uid);
59 g_string_append_printf(dump, "004: %02x (unknown)\n", s->unknown1); 56 g_string_append_printf(dump, "004: %02x (unknown)\n", s->unknown1);
60 //g_string_append_printf(dump, "005-008: %09x (ip)\n", *(s->ip)); 57 /* g_string_append_printf(dump, "005-008: %09x (ip)\n", *(s->ip)); */
61 g_string_append_printf(dump, "009-010: %04x (port)\n", s->port); 58 g_string_append_printf(dump, "009-010: %04x (port)\n", s->port);
62 g_string_append_printf(dump, "011: %02x (unknown)\n", s->unknown2); 59 g_string_append_printf(dump, "011: %02x (unknown)\n", s->unknown2);
63 g_string_append_printf(dump, "012: %02x (status)\n", s->status); 60 g_string_append_printf(dump, "012: %02x (status)\n", s->status);
64 g_string_append_printf(dump, "013-014: %04x (client_version)\n", s->client_version); 61 g_string_append_printf(dump, "013-014: %04x (client_version)\n", s->client_version);
65 //g_string_append_printf(dump, "015-030: %s (unknown key)\n", s->unknown_key); 62 /* g_string_append_printf(dump, "015-030: %s (unknown key)\n", s->unknown_key); */
66 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Buddy status entry, %s", dump->str); 63 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Buddy status entry, %s", dump->str);
67 _qq_show_packet("Unknown key", s->unknown_key, QQ_KEY_LENGTH); 64 _qq_show_packet("Unknown key", s->unknown_key, QQ_KEY_LENGTH);
68 g_string_free(dump, TRUE); 65 g_string_free(dump, TRUE);
69 } 66 }
70 67
71 /*****************************************************************************/ 68 /* TODO: figure out what's going on with the IP region. Sometimes I get valid IP addresses,
72 // TODO: figure out what's going on with the IP region. Sometimes I get things which 69 * but the port number's weird, other times I get 0s. I get these simultaneously on the same buddy,
73 // may be valid IP addresses, but the port number's weird, other times I get 0s. 70 * using different accounts to get info. */
74 // Note: I get these simultaneously on the same buddy, using different accounts to get info. 71
75 // parse the data into qq_buddy_status 72 /* parse the data into qq_buddy_status */
76 gint qq_buddy_status_read(guint8 * data, guint8 ** cursor, gint len, qq_buddy_status * s) { 73 gint qq_buddy_status_read(guint8 *data, guint8 **cursor, gint len, qq_buddy_status *s)
74 {
77 gint bytes; 75 gint bytes;
78 76
79 g_return_val_if_fail(data != NULL && *cursor != NULL && s != NULL, -1); 77 g_return_val_if_fail(data != NULL && *cursor != NULL && s != NULL, -1);
80 78
81 bytes = 0; 79 bytes = 0;
82 80
83 // 000-003: uid 81 /* 000-003: uid */
84 bytes += read_packet_dw(data, cursor, len, &s->uid); 82 bytes += read_packet_dw(data, cursor, len, &s->uid);
85 // 004-004: 0x01 83 /* 004-004: 0x01 */
86 bytes += read_packet_b(data, cursor, len, &s->unknown1); 84 bytes += read_packet_b(data, cursor, len, &s->unknown1);
87 // this is no longer the IP, it seems QQ (as of 2006) no longer sends 85 /* this is no longer the IP, it seems QQ (as of 2006) no longer sends
88 // the buddy's IP in this packet. all 0s 86 * the buddy's IP in this packet. all 0s */
89 // 005-008: ip 87 /* 005-008: ip */
90 s->ip = g_new0(guint8, 4); 88 s->ip = g_new0(guint8, 4);
91 bytes += read_packet_data(data, cursor, len, s->ip, 4); 89 bytes += read_packet_data(data, cursor, len, s->ip, 4);
92 // port info is no longer here either 90 /* port info is no longer here either */
93 // 009-010: port 91 /* 009-010: port */
94 bytes += read_packet_w(data, cursor, len, &s->port); 92 bytes += read_packet_w(data, cursor, len, &s->port);
95 // 011-011: 0x00 93 /* 011-011: 0x00 */
96 bytes += read_packet_b(data, cursor, len, &s->unknown2); 94 bytes += read_packet_b(data, cursor, len, &s->unknown2);
97 // 012-012: status 95 /* 012-012: status */
98 bytes += read_packet_b(data, cursor, len, &s->status); 96 bytes += read_packet_b(data, cursor, len, &s->status);
99 // 013-014: client_version 97 /* 013-014: client_version */
100 bytes += read_packet_w(data, cursor, len, &s->client_version); 98 bytes += read_packet_w(data, cursor, len, &s->client_version);
101 // 015-030: unknown key 99 /* 015-030: unknown key */
102 s->unknown_key = g_new0(guint8, QQ_KEY_LENGTH); 100 s->unknown_key = g_new0(guint8, QQ_KEY_LENGTH);
103 bytes += read_packet_data(data, cursor, len, s->unknown_key, QQ_KEY_LENGTH); 101 bytes += read_packet_data(data, cursor, len, s->unknown_key, QQ_KEY_LENGTH);
104 102
105 if (s->uid == 0 || bytes != 31) 103 if (s->uid == 0 || bytes != 31)
106 return -1; 104 return -1;
107 105
108 return bytes; 106 return bytes;
109 107 }
110 } 108
111 109 /* check if status means online or offline */
112 /*****************************************************************************/
113 // check if status means online or offline
114 gboolean is_online(guint8 status) 110 gboolean is_online(guint8 status)
115 { 111 {
116 // return (status == QQ_BUDDY_ONLINE_NORMAL ? TRUE : (status == QQ_BUDDY_ONLINE_AWAY ? TRUE : FALSE));
117 //rewritten by gfhuang
118 switch(status) { 112 switch(status) {
119 case QQ_BUDDY_ONLINE_NORMAL: 113 case QQ_BUDDY_ONLINE_NORMAL:
120 case QQ_BUDDY_ONLINE_AWAY: 114 case QQ_BUDDY_ONLINE_AWAY:
121 case QQ_BUDDY_ONLINE_INVISIBLE: 115 case QQ_BUDDY_ONLINE_INVISIBLE:
122 return TRUE; 116 return TRUE;
123 case QQ_BUDDY_ONLINE_OFFLINE: 117 case QQ_BUDDY_ONLINE_OFFLINE:
124 return FALSE; 118 return FALSE;
125 } 119 }
126 return FALSE; 120 return FALSE;
127 } // is_online 121 }
128 122
129 /*****************************************************************************/ 123 /* the icon suffix is detemined by status
130 // the icon suffix is detemined by status 124 * although QQ server may return the right icon, I set it here myself */
131 // although QQ server may return the right icon, I set it here myself
132 gchar get_suffix_from_status(guint8 status) 125 gchar get_suffix_from_status(guint8 status)
133 { 126 {
134 switch (status) { 127 switch (status) {
135 case QQ_BUDDY_ONLINE_NORMAL: 128 case QQ_BUDDY_ONLINE_NORMAL:
136 return QQ_ICON_SUFFIX_NORMAL; 129 return QQ_ICON_SUFFIX_NORMAL;
139 case QQ_BUDDY_ONLINE_INVISIBLE: 132 case QQ_BUDDY_ONLINE_INVISIBLE:
140 case QQ_BUDDY_ONLINE_OFFLINE: 133 case QQ_BUDDY_ONLINE_OFFLINE:
141 return QQ_ICON_SUFFIX_OFFLINE; 134 return QQ_ICON_SUFFIX_OFFLINE;
142 default: 135 default:
143 return QQ_ICON_SUFFIX_DEFAULT; 136 return QQ_ICON_SUFFIX_DEFAULT;
144 } // switch 137 }
145 } // get_suffix_from_status 138 }
146 139
147 /*****************************************************************************/ 140 /* send a packet to change my online status */
148 // send a packet to change my online status 141 void qq_send_packet_change_status(GaimConnection *gc)
149 void qq_send_packet_change_status(GaimConnection * gc)
150 { 142 {
151 qq_data *qd; 143 qq_data *qd;
152 guint8 *raw_data, *cursor, away_cmd; 144 guint8 *raw_data, *cursor, away_cmd;
153 guint32 misc_status; 145 guint32 misc_status;
154 gboolean fake_video; 146 gboolean fake_video;
189 qq_send_cmd(gc, QQ_CMD_CHANGE_ONLINE_STATUS, TRUE, 0, TRUE, raw_data, 5); 181 qq_send_cmd(gc, QQ_CMD_CHANGE_ONLINE_STATUS, TRUE, 0, TRUE, raw_data, 5);
190 182
191 g_free(raw_data); 183 g_free(raw_data);
192 } 184 }
193 185
194 /*****************************************************************************/ 186 /* parse the reply packet for change_status */
195 // parse the reply packet for change_status 187 void qq_process_change_status_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
196 void qq_process_change_status_reply(guint8 * buf, gint buf_len, GaimConnection * gc) { 188 {
197 qq_data *qd; 189 qq_data *qd;
198 gint len; 190 gint len;
199 guint8 *data, *cursor, reply; 191 guint8 *data, *cursor, reply;
200 192
201 g_return_if_fail(gc != NULL && gc->proto_data != NULL); 193 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
215 } else 207 } else
216 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt chg status reply\n"); 208 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt chg status reply\n");
217 209
218 } 210 }
219 211
220 /*****************************************************************************/ 212 /* it is a server message indicating that one of my buddies has changed its status */
221 // it is a server message 213 void qq_process_friend_change_status(guint8 *buf, gint buf_len, GaimConnection *gc)
222 // indicating that one of my buddies changes its status 214 {
223 void qq_process_friend_change_status(guint8 * buf, gint buf_len, GaimConnection * gc) {
224 qq_data *qd; 215 qq_data *qd;
225 gint len, bytes; 216 gint len, bytes;
226 guint32 my_uid; 217 guint32 my_uid;
227 guint8 *data, *cursor; 218 guint8 *data, *cursor;
228 GaimBuddy *b; 219 GaimBuddy *b;
239 cursor = data; 230 cursor = data;
240 231
241 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 232 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
242 s = g_new0(qq_buddy_status, 1); 233 s = g_new0(qq_buddy_status, 1);
243 bytes = 0; 234 bytes = 0;
244 // 000-030: qq_buddy_status; 235 /* 000-030: qq_buddy_status */
245 bytes += qq_buddy_status_read(data, &cursor, len, s); 236 bytes += qq_buddy_status_read(data, &cursor, len, s);
246 // 031-034: my uid 237 /* 031-034: my uid */
247 bytes += read_packet_dw(data, &cursor, len, &my_uid); 238 bytes += read_packet_dw(data, &cursor, len, &my_uid);
248 239
249 if (my_uid == 0 || bytes != 35) { 240 if (my_uid == 0 || bytes != 35) {
250 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "my_uid == 0 || bytes(%d) != 35\n", bytes); 241 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "my_uid == 0 || bytes(%d) != 35\n", bytes);
251 g_free(s->ip); 242 g_free(s->ip);
252 g_free(s->unknown_key); 243 g_free(s->unknown_key);
253 g_free(s); 244 g_free(s);
254 return; 245 return;
255 } 246 }
256 // if (QQ_DEBUG) gfhuang
257 // _qq_buddy_status_dump_unclear(s);
258 247
259 name = uid_to_gaim_name(s->uid); 248 name = uid_to_gaim_name(s->uid);
260 b = gaim_find_buddy(gc->account, name); 249 b = gaim_find_buddy(gc->account, name);
261 g_free(name); 250 g_free(name);
262 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; 251 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
268 } 257 }
269 q_bud->status = s->status; 258 q_bud->status = s->status;
270 if(0 != s->client_version) 259 if(0 != s->client_version)
271 q_bud->client_version = s->client_version; 260 q_bud->client_version = s->client_version;
272 qq_update_buddy_contact(gc, q_bud); 261 qq_update_buddy_contact(gc, q_bud);
262 } else {
263 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
264 "got information of unknown buddy by gfhuang %d\n", s->uid);
273 } 265 }
274 else
275 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "got information of unknown buddy by gfhuang %d\n", s->uid);
276 266
277 g_free(s->ip); 267 g_free(s->ip);
278 g_free(s->unknown_key); 268 g_free(s->unknown_key);
279 g_free(s); 269 g_free(s);
280 } else 270 } else {
281 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddy status change packet\n"); 271 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddy status change packet\n");
282 } 272 }
283 273 }
284 /*****************************************************************************/
285 // END OF FILE