Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/qq_process.c @ 24075:a95c7e71064c
2008.10.05 - ccpaging <ccpagint(at)gmail.com>
* Add my uid into buddy list
* Fixed a minor bug in qq_create_buddy. Not get new buddy's info.
* There are 38 fields in protocol 2008, one more than 2005/2007.
* The packet of Modifing buddy info is changed. Need sample to fix it.
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 14:48:46 +0000 |
parents | c2253c485728 |
children | ec3f7d3e0445 |
comparison
equal
deleted
inserted
replaced
24074:c2253c485728 | 24075:a95c7e71064c |
---|---|
93 if (data[0] != 0) { | 93 if (data[0] != 0) { |
94 purple_debug_warning("QQ", "Failed sent IM\n"); | 94 purple_debug_warning("QQ", "Failed sent IM\n"); |
95 purple_notify_error(gc, _("Error"), _("Failed to send IM."), NULL); | 95 purple_notify_error(gc, _("Error"), _("Failed to send IM."), NULL); |
96 return; | 96 return; |
97 } | 97 } |
98 | 98 |
99 purple_debug_info("QQ", "OK sent IM\n"); | 99 purple_debug_info("QQ", "OK sent IM\n"); |
100 } | 100 } |
101 | 101 |
102 static void do_server_news(guint8 *data, gint data_len, PurpleConnection *gc) | 102 static void do_server_news(guint8 *data, gint data_len, PurpleConnection *gc) |
103 { | 103 { |
146 g_free(url); | 146 g_free(url); |
147 g_free(content); | 147 g_free(content); |
148 g_free(content_utf8); | 148 g_free(content_utf8); |
149 } | 149 } |
150 | 150 |
151 /* process im from system administrator */ | 151 static void do_msg_sys_30(PurpleConnection *gc, guint8 *data, gint data_len) |
152 static void do_server_im(guint8 *data, gint data_len, PurpleConnection *gc) | |
153 { | 152 { |
154 gint len; | 153 gint len; |
155 guint8 reply; | 154 guint8 reply; |
156 gchar **segments, *msg_utf8; | 155 gchar **segments, *msg_utf8; |
157 | 156 |
163 return; | 162 return; |
164 | 163 |
165 reply = strtol(segments[0], NULL, 10); | 164 reply = strtol(segments[0], NULL, 10); |
166 if (reply == 1) | 165 if (reply == 1) |
167 purple_debug_warning("QQ", "We are kicked out by QQ server\n"); | 166 purple_debug_warning("QQ", "We are kicked out by QQ server\n"); |
168 | 167 |
169 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); | 168 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); |
170 purple_notify_warning(gc, NULL, _("System Message"), msg_utf8); | 169 qq_got_attention(gc, msg_utf8); |
170 } | |
171 | |
172 static void do_msg_sys_4c(PurpleConnection *gc, guint8 *data, gint data_len) | |
173 { | |
174 gint bytes; | |
175 gint msg_len; | |
176 GString *content; | |
177 gchar *msg = NULL; | |
178 | |
179 g_return_if_fail(data != NULL && data_len > 0); | |
180 | |
181 bytes = 6; /* skip 0x(06 00 01 1e 01 1c)*/ | |
182 | |
183 content = g_string_new(""); | |
184 while (bytes < data_len) { | |
185 msg_len = qq_get_vstr(&msg, QQ_CHARSET_DEFAULT, data + bytes); | |
186 g_string_append(content, msg); | |
187 g_string_append(content, "\n"); | |
188 g_free(msg); | |
189 | |
190 if (msg_len <= 1) { | |
191 break; | |
192 } | |
193 bytes += msg_len; | |
194 } | |
195 if (bytes != data_len) { | |
196 purple_debug_warning("QQ", "Failed to read QQ_MSG_SYS_4C\n"); | |
197 qq_show_packet("do_msg_sys_4c", data, data_len); | |
198 } | |
199 qq_got_attention(gc, content->str); | |
200 g_string_free(content, FALSE); | |
171 } | 201 } |
172 | 202 |
173 static const gchar *get_im_type_desc(gint type) | 203 static const gchar *get_im_type_desc(gint type) |
174 { | 204 { |
175 switch (type) { | 205 switch (type) { |
176 case QQ_RECV_IM_TO_BUDDY: | 206 case QQ_MSG_TO_BUDDY: |
177 return "QQ_RECV_IM_TO_BUDDY"; | 207 return "QQ_MSG_TO_BUDDY"; |
178 case QQ_RECV_IM_TO_UNKNOWN: | 208 case QQ_MSG_TO_UNKNOWN: |
179 return "QQ_RECV_IM_TO_UNKNOWN"; | 209 return "QQ_MSG_TO_UNKNOWN"; |
180 case QQ_RECV_IM_UNKNOWN_QUN_IM: | 210 case QQ_MSG_UNKNOWN_QUN_IM: |
181 return "QQ_RECV_IM_UNKNOWN_QUN_IM"; | 211 return "QQ_MSG_UNKNOWN_QUN_IM"; |
182 case QQ_RECV_IM_ADD_TO_QUN: | 212 case QQ_MSG_ADD_TO_QUN: |
183 return "QQ_RECV_IM_ADD_TO_QUN"; | 213 return "QQ_MSG_ADD_TO_QUN"; |
184 case QQ_RECV_IM_DEL_FROM_QUN: | 214 case QQ_MSG_DEL_FROM_QUN: |
185 return "QQ_RECV_IM_DEL_FROM_QUN"; | 215 return "QQ_MSG_DEL_FROM_QUN"; |
186 case QQ_RECV_IM_APPLY_ADD_TO_QUN: | 216 case QQ_MSG_APPLY_ADD_TO_QUN: |
187 return "QQ_RECV_IM_APPLY_ADD_TO_QUN"; | 217 return "QQ_MSG_APPLY_ADD_TO_QUN"; |
188 case QQ_RECV_IM_CREATE_QUN: | 218 case QQ_MSG_CREATE_QUN: |
189 return "QQ_RECV_IM_CREATE_QUN"; | 219 return "QQ_MSG_CREATE_QUN"; |
190 case QQ_RECV_IM_SYS_NOTIFICATION: | 220 case QQ_MSG_SYS_30: |
191 return "QQ_RECV_IM_SYS_NOTIFICATION"; | 221 return "QQ_MSG_SYS_30"; |
192 case QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN: | 222 case QQ_MSG_SYS_4C: |
193 return "QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN"; | 223 return "QQ_MSG_SYS_4C"; |
194 case QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN: | 224 case QQ_MSG_APPROVE_APPLY_ADD_TO_QUN: |
195 return "QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN"; | 225 return "QQ_MSG_APPROVE_APPLY_ADD_TO_QUN"; |
196 case QQ_RECV_IM_TEMP_QUN_IM: | 226 case QQ_MSG_REJCT_APPLY_ADD_TO_QUN: |
197 return "QQ_RECV_IM_TEMP_QUN_IM"; | 227 return "QQ_MSG_REJCT_APPLY_ADD_TO_QUN"; |
198 case QQ_RECV_IM_QUN_IM: | 228 case QQ_MSG_TEMP_QUN_IM: |
199 return "QQ_RECV_IM_QUN_IM"; | 229 return "QQ_MSG_TEMP_QUN_IM"; |
200 case QQ_RECV_IM_NEWS: | 230 case QQ_MSG_QUN_IM: |
201 return "QQ_RECV_IM_NEWS"; | 231 return "QQ_MSG_QUN_IM"; |
202 case QQ_RECV_IM_EXTEND: | 232 case QQ_MSG_NEWS: |
203 return "QQ_RECV_IM_EXTEND"; | 233 return "QQ_MSG_NEWS"; |
204 case QQ_RECV_IM_EXTEND_85: | 234 case QQ_MSG_EXTEND: |
205 return "QQ_RECV_IM_EXTEND_85"; | 235 return "QQ_MSG_EXTEND"; |
206 default: | 236 case QQ_MSG_EXTEND_85: |
207 return "QQ_RECV_IM_UNKNOWN"; | 237 return "QQ_MSG_EXTEND_85"; |
238 default: | |
239 return "QQ_MSG_UNKNOWN"; | |
208 } | 240 } |
209 } | 241 } |
210 | 242 |
211 /* I receive a message, mainly it is text msg, | 243 /* I receive a message, mainly it is text msg, |
212 * but we need to proess other types (group etc) */ | 244 * but we need to proess other types (group etc) */ |
219 guint32 uid_from; | 251 guint32 uid_from; |
220 guint32 uid_to; | 252 guint32 uid_to; |
221 guint32 seq; | 253 guint32 seq; |
222 struct in_addr ip_from; | 254 struct in_addr ip_from; |
223 guint16 port_from; | 255 guint16 port_from; |
224 guint16 im_type; | 256 guint16 msg_type; |
225 } header; | 257 } header; |
226 | 258 |
227 g_return_if_fail(data != NULL && data_len != 0); | 259 g_return_if_fail(data != NULL && data_len != 0); |
228 | 260 |
229 qd = (qq_data *) gc->proto_data; | 261 qd = (qq_data *) gc->proto_data; |
248 bytes += qq_get32(&(header.uid_to), data + bytes); | 280 bytes += qq_get32(&(header.uid_to), data + bytes); |
249 bytes += qq_get32(&(header.seq), data + bytes); | 281 bytes += qq_get32(&(header.seq), data + bytes); |
250 /* if the message is delivered via server, it is server IP/port */ | 282 /* if the message is delivered via server, it is server IP/port */ |
251 bytes += qq_getIP(&(header.ip_from), data + bytes); | 283 bytes += qq_getIP(&(header.ip_from), data + bytes); |
252 bytes += qq_get16(&(header.port_from), data + bytes); | 284 bytes += qq_get16(&(header.port_from), data + bytes); |
253 bytes += qq_get16(&(header.im_type), data + bytes); | 285 bytes += qq_get16(&(header.msg_type), data + bytes); |
254 /* im_header prepared */ | 286 /* im_header prepared */ |
255 | 287 |
256 if (header.uid_to != qd->uid) { /* should not happen */ | 288 if (header.uid_to != qd->uid) { /* should not happen */ |
257 purple_debug_error("QQ", "MSG to [%d], NOT me\n", header.uid_to); | 289 purple_debug_error("QQ", "MSG to [%d], NOT me\n", header.uid_to); |
258 return; | 290 return; |
262 if (bytes >= data_len - 1) { | 294 if (bytes >= data_len - 1) { |
263 purple_debug_warning("QQ", "Empty MSG\n"); | 295 purple_debug_warning("QQ", "Empty MSG\n"); |
264 return; | 296 return; |
265 } | 297 } |
266 | 298 |
267 switch (header.im_type) { | 299 switch (header.msg_type) { |
268 case QQ_RECV_IM_NEWS: | 300 case QQ_MSG_NEWS: |
269 do_server_news(data + bytes, data_len - bytes, gc); | 301 do_server_news(data + bytes, data_len - bytes, gc); |
270 break; | 302 break; |
271 case QQ_RECV_IM_EXTEND: | 303 case QQ_MSG_EXTEND: |
272 case QQ_RECV_IM_EXTEND_85: | 304 case QQ_MSG_EXTEND_85: |
273 purple_debug_info("QQ", "MSG from buddy [%d]\n", header.uid_from); | 305 purple_debug_info("QQ", "MSG from buddy [%d]\n", header.uid_from); |
274 qq_process_extend_im(gc, data + bytes, data_len - bytes); | 306 qq_process_extend_im(gc, data + bytes, data_len - bytes); |
275 break; | 307 break; |
276 case QQ_RECV_IM_TO_UNKNOWN: | 308 case QQ_MSG_TO_UNKNOWN: |
277 case QQ_RECV_IM_TO_BUDDY: | 309 case QQ_MSG_TO_BUDDY: |
278 purple_debug_info("QQ", "MSG from buddy [%d]\n", header.uid_from); | 310 purple_debug_info("QQ", "MSG from buddy [%d]\n", header.uid_from); |
279 qq_process_im(gc, data + bytes, data_len - bytes); | 311 qq_process_im(gc, data + bytes, data_len - bytes); |
280 break; | 312 break; |
281 case QQ_RECV_IM_UNKNOWN_QUN_IM: | 313 case QQ_MSG_UNKNOWN_QUN_IM: |
282 case QQ_RECV_IM_TEMP_QUN_IM: | 314 case QQ_MSG_TEMP_QUN_IM: |
283 case QQ_RECV_IM_QUN_IM: | 315 case QQ_MSG_QUN_IM: |
284 purple_debug_info("QQ", "MSG from room [%d]\n", header.uid_from); | 316 purple_debug_info("QQ", "MSG from room [%d]\n", header.uid_from); |
285 /* uid_from is in fact id */ | 317 qq_process_room_msg_normal(data + bytes, data_len - bytes, header.uid_from, gc, header.msg_type); |
286 qq_process_room_msg_normal(data + bytes, data_len - bytes, header.uid_from, gc, header.im_type); | 318 break; |
287 break; | 319 case QQ_MSG_ADD_TO_QUN: |
288 case QQ_RECV_IM_ADD_TO_QUN: | |
289 purple_debug_info("QQ", "Notice from [%d], Added\n", header.uid_from); | 320 purple_debug_info("QQ", "Notice from [%d], Added\n", header.uid_from); |
290 /* uid_from is group id | 321 /* uid_from is group id |
291 * we need this to create a dummy group and add to blist */ | 322 * we need this to create a dummy group and add to blist */ |
292 qq_process_room_msg_been_added(data + bytes, data_len - bytes, header.uid_from, gc); | 323 qq_process_room_msg_been_added(data + bytes, data_len - bytes, header.uid_from, gc); |
293 break; | 324 break; |
294 case QQ_RECV_IM_DEL_FROM_QUN: | 325 case QQ_MSG_DEL_FROM_QUN: |
295 purple_debug_info("QQ", "Notice from room [%d], Removed\n", header.uid_from); | 326 purple_debug_info("QQ", "Notice from room [%d], Removed\n", header.uid_from); |
296 /* uid_from is group id */ | 327 /* uid_from is group id */ |
297 qq_process_room_msg_been_removed(data + bytes, data_len - bytes, header.uid_from, gc); | 328 qq_process_room_msg_been_removed(data + bytes, data_len - bytes, header.uid_from, gc); |
298 break; | 329 break; |
299 case QQ_RECV_IM_APPLY_ADD_TO_QUN: | 330 case QQ_MSG_APPLY_ADD_TO_QUN: |
300 purple_debug_info("QQ", "Notice from room [%d], Joined\n", header.uid_from); | 331 purple_debug_info("QQ", "Notice from room [%d], Joined\n", header.uid_from); |
301 /* uid_from is group id */ | 332 /* uid_from is group id */ |
302 qq_process_room_msg_apply_join(data + bytes, data_len - bytes, header.uid_from, gc); | 333 qq_process_room_msg_apply_join(data + bytes, data_len - bytes, header.uid_from, gc); |
303 break; | 334 break; |
304 case QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN: | 335 case QQ_MSG_APPROVE_APPLY_ADD_TO_QUN: |
305 purple_debug_info("QQ", "Notice from room [%d], Confirm add in\n", | 336 purple_debug_info("QQ", "Notice from room [%d], Confirm add in\n", |
306 header.uid_from); | 337 header.uid_from); |
307 /* uid_from is group id */ | 338 /* uid_from is group id */ |
308 qq_process_room_msg_been_approved(data + bytes, data_len - bytes, header.uid_from, gc); | 339 qq_process_room_msg_been_approved(data + bytes, data_len - bytes, header.uid_from, gc); |
309 break; | 340 break; |
310 case QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN: | 341 case QQ_MSG_REJCT_APPLY_ADD_TO_QUN: |
311 purple_debug_info("QQ", "Notice from room [%d], Refuse add in\n", | 342 purple_debug_info("QQ", "Notice from room [%d], Refuse add in\n", |
312 header.uid_from); | 343 header.uid_from); |
313 /* uid_from is group id */ | 344 /* uid_from is group id */ |
314 qq_process_room_msg_been_rejected(data + bytes, data_len - bytes, header.uid_from, gc); | 345 qq_process_room_msg_been_rejected(data + bytes, data_len - bytes, header.uid_from, gc); |
315 break; | 346 break; |
316 case QQ_RECV_IM_SYS_NOTIFICATION: | 347 case QQ_MSG_SYS_30: |
317 purple_debug_info("QQ", "Admin notice from [%d]\n", header.uid_from); | 348 do_msg_sys_30(gc, data + bytes, data_len - bytes); |
318 do_server_im(data + bytes, data_len - bytes, gc); | 349 break; |
319 break; | 350 case QQ_MSG_SYS_4C: |
320 default: | 351 do_msg_sys_4c(gc, data + bytes, data_len - bytes); |
321 purple_debug_warning("QQ", "MSG from [%d], unknown type %s [0x%02x]\n", | 352 break; |
322 header.uid_from, get_im_type_desc(header.im_type), | 353 default: |
323 header.im_type); | 354 purple_debug_warning("QQ", "MSG from [%d], unknown type %s [0x%04X]\n", |
355 header.uid_from, get_im_type_desc(header.msg_type), header.msg_type); | |
324 qq_show_packet("Unknown MSG type", data, data_len); | 356 qq_show_packet("Unknown MSG type", data, data_len); |
325 break; | 357 break; |
326 } | 358 } |
327 } | 359 } |
328 | 360 |