Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/buddy_opt.c @ 23050:9a5d140400f1
patch-02-fix-multiarch
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Tue, 24 Jun 2008 11:58:57 +0000 |
parents | 217fffe3f46f |
children | 51dbe83ebbd3 |
comparison
equal
deleted
inserted
replaced
23048:13a9b56f83b0 | 23050:9a5d140400f1 |
---|---|
71 } | 71 } |
72 | 72 |
73 /* try to remove myself from someone's buddy list */ | 73 /* try to remove myself from someone's buddy list */ |
74 static void _qq_send_packet_remove_self_from(PurpleConnection *gc, guint32 uid) | 74 static void _qq_send_packet_remove_self_from(PurpleConnection *gc, guint32 uid) |
75 { | 75 { |
76 guint8 *raw_data, *cursor; | 76 guint8 raw_data[16] = {0}; |
77 gint bytes = 0; | |
77 | 78 |
78 g_return_if_fail(uid > 0); | 79 g_return_if_fail(uid > 0); |
79 | 80 |
80 raw_data = g_newa(guint8, 4); | 81 bytes += qq_put32(raw_data + bytes, uid); |
81 cursor = raw_data; | 82 |
82 create_packet_dw(raw_data, &cursor, uid); | 83 qq_send_cmd(gc, QQ_CMD_REMOVE_SELF, TRUE, 0, TRUE, raw_data, bytes); |
83 | |
84 qq_send_cmd(gc, QQ_CMD_REMOVE_SELF, TRUE, 0, TRUE, raw_data, 4); | |
85 } | 84 } |
86 | 85 |
87 /* try to add a buddy without authentication */ | 86 /* try to add a buddy without authentication */ |
88 static void _qq_send_packet_add_buddy(PurpleConnection *gc, guint32 uid) | 87 static void _qq_send_packet_add_buddy(PurpleConnection *gc, guint32 uid) |
89 { | 88 { |
108 | 107 |
109 /* this buddy needs authentication, text conversion is done at lowest level */ | 108 /* this buddy needs authentication, text conversion is done at lowest level */ |
110 static void _qq_send_packet_buddy_auth(PurpleConnection *gc, guint32 uid, const gchar response, const gchar *text) | 109 static void _qq_send_packet_buddy_auth(PurpleConnection *gc, guint32 uid, const gchar response, const gchar *text) |
111 { | 110 { |
112 gchar *text_qq, uid_str[11]; | 111 gchar *text_qq, uid_str[11]; |
113 guint8 bar, *cursor, *raw_data; | 112 guint8 bar, *raw_data; |
113 gint bytes = 0; | |
114 | 114 |
115 g_return_if_fail(uid != 0); | 115 g_return_if_fail(uid != 0); |
116 | 116 |
117 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); | 117 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); |
118 bar = 0x1f; | 118 bar = 0x1f; |
119 raw_data = g_newa(guint8, QQ_MSG_IM_MAX); | 119 raw_data = g_newa(guint8, QQ_MSG_IM_MAX); |
120 cursor = raw_data; | 120 |
121 | 121 bytes += qq_putdata(raw_data + bytes, (guint8 *) uid_str, strlen(uid_str)); |
122 create_packet_data(raw_data, &cursor, (guint8 *) uid_str, strlen(uid_str)); | 122 bytes += qq_put8(raw_data + bytes, bar); |
123 create_packet_b(raw_data, &cursor, bar); | 123 bytes += qq_put8(raw_data + bytes, response); |
124 create_packet_b(raw_data, &cursor, response); | |
125 | 124 |
126 if (text != NULL) { | 125 if (text != NULL) { |
127 text_qq = utf8_to_qq(text, QQ_CHARSET_DEFAULT); | 126 text_qq = utf8_to_qq(text, QQ_CHARSET_DEFAULT); |
128 create_packet_b(raw_data, &cursor, bar); | 127 bytes += qq_put8(raw_data + bytes, bar); |
129 create_packet_data(raw_data, &cursor, (guint8 *) text_qq, strlen(text_qq)); | 128 bytes += qq_putdata(raw_data + bytes, (guint8 *) text_qq, strlen(text_qq)); |
130 g_free(text_qq); | 129 g_free(text_qq); |
131 } | 130 } |
132 | 131 |
133 qq_send_cmd(gc, QQ_CMD_BUDDY_AUTH, TRUE, 0, TRUE, raw_data, cursor - raw_data); | 132 qq_send_cmd(gc, QQ_CMD_BUDDY_AUTH, TRUE, 0, TRUE, raw_data, bytes); |
134 } | 133 } |
135 | 134 |
136 static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid *g, const gchar *text) | 135 static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid *g, const gchar *text) |
137 { | 136 { |
138 PurpleConnection *gc; | 137 PurpleConnection *gc; |
208 msg1 = g_strdup_printf(_("You rejected %d's request"), uid); | 207 msg1 = g_strdup_printf(_("You rejected %d's request"), uid); |
209 msg2 = g_strdup(_("Input your reason:")); | 208 msg2 = g_strdup(_("Input your reason:")); |
210 | 209 |
211 nombre = uid_to_purple_name(uid); | 210 nombre = uid_to_purple_name(uid); |
212 purple_request_input(gc, _("Reject request"), msg1, msg2, | 211 purple_request_input(gc, _("Reject request"), msg1, msg2, |
213 _("Sorry, you are not my type..."), TRUE, FALSE, | 212 _("Sorry, you are not my type..."), TRUE, FALSE, |
214 NULL, _("Reject"), G_CALLBACK(_qq_reject_add_request_real), _("Cancel"), NULL, | 213 NULL, _("Reject"), G_CALLBACK(_qq_reject_add_request_real), _("Cancel"), NULL, |
215 purple_connection_get_account(gc), nombre, NULL, | 214 purple_connection_get_account(gc), nombre, NULL, |
216 g2); | 215 g2); |
217 g_free(nombre); | 216 g_free(nombre); |
218 } | 217 } |
219 | 218 |
220 void qq_add_buddy_with_gc_and_uid(gc_and_uid *g) | 219 void qq_add_buddy_with_gc_and_uid(gc_and_uid *g) |
221 { | 220 { |
255 /* process reply to add_buddy_auth request */ | 254 /* process reply to add_buddy_auth request */ |
256 void qq_process_add_buddy_auth_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) | 255 void qq_process_add_buddy_auth_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) |
257 { | 256 { |
258 qq_data *qd; | 257 qq_data *qd; |
259 gint len; | 258 gint len; |
260 guint8 *data, *cursor, reply; | 259 gint bytes = 0; |
260 guint8 *data, reply; | |
261 gchar **segments, *msg_utf8; | 261 gchar **segments, *msg_utf8; |
262 | 262 |
263 g_return_if_fail(buf != NULL && buf_len != 0); | 263 g_return_if_fail(buf != NULL && buf_len != 0); |
264 | 264 |
265 qd = (qq_data *) gc->proto_data; | 265 qd = (qq_data *) gc->proto_data; |
266 len = buf_len; | 266 len = buf_len; |
267 data = g_newa(guint8, len); | 267 data = g_newa(guint8, len); |
268 cursor = data; | 268 |
269 | 269 if (!qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { |
270 if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { | 270 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt add buddy with auth reply\n"); |
271 read_packet_b(data, &cursor, len, &reply); | 271 } |
272 if (reply != QQ_ADD_BUDDY_AUTH_REPLY_OK) { | 272 |
273 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Add buddy with auth request failed\n"); | 273 bytes += qq_get8(&reply, data + bytes); |
274 if (NULL == (segments = split_data(data, len, "\x1f", 2))) | 274 |
275 return; | 275 if (reply != QQ_ADD_BUDDY_AUTH_REPLY_OK) { |
276 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); | 276 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Add buddy with auth request failed\n"); |
277 purple_notify_error(gc, NULL, _("Add buddy with auth request failed"), msg_utf8); | 277 if (NULL == (segments = split_data(data, len, "\x1f", 2))) { |
278 g_free(msg_utf8); | 278 return; |
279 } else { | |
280 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Add buddy with auth request OK\n"); | |
281 } | 279 } |
280 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); | |
281 purple_notify_error(gc, NULL, _("Add buddy with auth request failed"), msg_utf8); | |
282 g_free(msg_utf8); | |
282 } else { | 283 } else { |
283 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt add buddy with auth reply\n"); | 284 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Add buddy with auth request OK\n"); |
284 } | 285 } |
285 } | 286 } |
286 | 287 |
287 /* process the server reply for my request to remove a buddy */ | 288 /* process the server reply for my request to remove a buddy */ |
288 void qq_process_remove_buddy_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) | 289 void qq_process_remove_buddy_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) |
289 { | 290 { |
290 qq_data *qd; | 291 qq_data *qd; |
291 gint len; | 292 gint len; |
292 guint8 *data, *cursor, reply; | 293 gint bytes = 0; |
294 guint8 *data, reply; | |
293 | 295 |
294 g_return_if_fail(buf != NULL && buf_len != 0); | 296 g_return_if_fail(buf != NULL && buf_len != 0); |
295 | 297 |
296 qd = (qq_data *) gc->proto_data; | 298 qd = (qq_data *) gc->proto_data; |
297 len = buf_len; | 299 len = buf_len; |
298 data = g_newa(guint8, len); | 300 data = g_newa(guint8, len); |
299 | 301 |
300 if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { | 302 if (!qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { |
301 cursor = data; | |
302 read_packet_b(data, &cursor, len, &reply); | |
303 if (reply != QQ_REMOVE_BUDDY_REPLY_OK) { | |
304 /* there is no reason return from server */ | |
305 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Remove buddy fails\n"); | |
306 } else { /* if reply */ | |
307 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Remove buddy OK\n"); | |
308 /* TODO: We don't really need to notify the user about this, do we? */ | |
309 purple_notify_info(gc, NULL, _("You have successfully removed a buddy"), NULL); | |
310 } | |
311 } else { | |
312 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt remove buddy reply\n"); | 303 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt remove buddy reply\n"); |
304 } | |
305 | |
306 bytes += qq_get8(&reply, data + bytes); | |
307 | |
308 if (reply != QQ_REMOVE_BUDDY_REPLY_OK) { | |
309 /* there is no reason return from server */ | |
310 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Remove buddy fails\n"); | |
311 } else { /* if reply */ | |
312 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Remove buddy OK\n"); | |
313 /* TODO: We don't really need to notify the user about this, do we? */ | |
314 purple_notify_info(gc, NULL, _("You have successfully removed a buddy"), NULL); | |
313 } | 315 } |
314 } | 316 } |
315 | 317 |
316 /* process the server reply for my request to remove myself from a buddy */ | 318 /* process the server reply for my request to remove myself from a buddy */ |
317 void qq_process_remove_self_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) | 319 void qq_process_remove_self_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) |
318 { | 320 { |
319 qq_data *qd; | 321 qq_data *qd; |
320 gint len; | 322 gint len; |
321 guint8 *data, *cursor, reply; | 323 gint bytes = 0; |
324 guint8 *data, reply; | |
322 | 325 |
323 g_return_if_fail(buf != NULL && buf_len != 0); | 326 g_return_if_fail(buf != NULL && buf_len != 0); |
324 | 327 |
325 qd = (qq_data *) gc->proto_data; | 328 qd = (qq_data *) gc->proto_data; |
326 len = buf_len; | 329 len = buf_len; |
327 data = g_newa(guint8, len); | 330 data = g_newa(guint8, len); |
328 | 331 |
329 if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { | 332 if (!qq_decrypt(buf, buf_len, qd->session_key, data, &len)) { |
330 cursor = data; | |
331 read_packet_b(data, &cursor, len, &reply); | |
332 if (reply != QQ_REMOVE_SELF_REPLY_OK) | |
333 /* there is no reason return from server */ | |
334 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Remove self fails\n"); | |
335 else { /* if reply */ | |
336 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Remove self from a buddy OK\n"); | |
337 /* TODO: Does the user really need to be notified about this? */ | |
338 purple_notify_info(gc, NULL, _("You have successfully removed yourself from your friend's buddy list"), NULL); | |
339 } | |
340 } else { | |
341 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt remove self reply\n"); | 333 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt remove self reply\n"); |
334 } | |
335 | |
336 bytes += qq_get8(&reply, data + bytes); | |
337 | |
338 if (reply != QQ_REMOVE_SELF_REPLY_OK) { | |
339 /* there is no reason return from server */ | |
340 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Remove self fails\n"); | |
341 } else { /* if reply */ | |
342 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Remove self from a buddy OK\n"); | |
343 /* TODO: Does the user really need to be notified about this? */ | |
344 purple_notify_info(gc, NULL, _("You have successfully removed yourself from your friend's buddy list"), NULL); | |
342 } | 345 } |
343 } | 346 } |
344 | 347 |
345 void qq_process_add_buddy_reply(guint8 *buf, gint buf_len, guint16 seq, PurpleConnection *gc) | 348 void qq_process_add_buddy_reply(guint8 *buf, gint buf_len, guint16 seq, PurpleConnection *gc) |
346 { | 349 { |
401 g = g_new0(gc_and_uid, 1); | 404 g = g_new0(gc_and_uid, 1); |
402 g->gc = gc; | 405 g->gc = gc; |
403 g->uid = for_uid; | 406 g->uid = for_uid; |
404 msg = g_strdup_printf(_("User %d needs authentication"), for_uid); | 407 msg = g_strdup_printf(_("User %d needs authentication"), for_uid); |
405 purple_request_input(gc, NULL, msg, | 408 purple_request_input(gc, NULL, msg, |
406 _("Input request here"), /* TODO: Awkward string to fix post string freeze - standardize auth dialogues? -evands */ | 409 _("Input request here"), /* TODO: Awkward string to fix post string freeze - standardize auth dialogues? -evands */ |
407 _("Would you be my friend?"), | 410 _("Would you be my friend?"), |
408 TRUE, FALSE, NULL, _("Send"), | 411 TRUE, FALSE, NULL, _("Send"), |
409 G_CALLBACK | 412 G_CALLBACK |
410 (_qq_send_packet_add_buddy_auth_with_gc_and_uid), | 413 (_qq_send_packet_add_buddy_auth_with_gc_and_uid), |
411 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), | 414 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), |
412 purple_connection_get_account(gc), nombre, NULL, | 415 purple_connection_get_account(gc), nombre, NULL, |
413 g); | 416 g); |
414 g_free(msg); | 417 g_free(msg); |
415 g_free(nombre); | 418 g_free(nombre); |
416 } else { /* add OK */ | 419 } else { /* add OK */ |
417 qq_add_buddy_by_recv_packet(gc, for_uid, TRUE, TRUE); | 420 qq_add_buddy_by_recv_packet(gc, for_uid, TRUE, TRUE); |
418 msg = g_strdup_printf(_("You have added %d to buddy list"), for_uid); | 421 msg = g_strdup_printf(_("You have added %d to buddy list"), for_uid); |
455 a = gc->account; | 458 a = gc->account; |
456 qd = (qq_data *) gc->proto_data; | 459 qd = (qq_data *) gc->proto_data; |
457 g_return_val_if_fail(a != NULL && uid != 0, NULL); | 460 g_return_val_if_fail(a != NULL && uid != 0, NULL); |
458 | 461 |
459 group_name = is_known ? | 462 group_name = is_known ? |
460 g_strdup_printf(PURPLE_GROUP_QQ_FORMAT, purple_account_get_username(a)) : g_strdup(PURPLE_GROUP_QQ_UNKNOWN); | 463 g_strdup_printf(PURPLE_GROUP_QQ_FORMAT, purple_account_get_username(a)) : g_strdup(PURPLE_GROUP_QQ_UNKNOWN); |
461 | 464 |
462 g = qq_get_purple_group(group_name); | 465 g = qq_get_purple_group(group_name); |
463 | 466 |
464 name = uid_to_purple_name(uid); | 467 name = uid_to_purple_name(uid); |
465 b = purple_find_buddy(gc->account, name); | 468 b = purple_find_buddy(gc->account, name); |
510 else { | 513 else { |
511 b = purple_find_buddy(gc->account, buddy->name); | 514 b = purple_find_buddy(gc->account, buddy->name); |
512 if (b != NULL) | 515 if (b != NULL) |
513 purple_blist_remove_buddy(b); | 516 purple_blist_remove_buddy(b); |
514 purple_notify_error(gc, NULL, | 517 purple_notify_error(gc, NULL, |
515 _("QQid Error"), | 518 _("QQid Error"), |
516 _("Invalid QQid")); | 519 _("Invalid QQid")); |
517 } | 520 } |
518 } | 521 } |
519 | 522 |
520 /* remove a buddy and send packet to QQ server accordingly */ | 523 /* remove a buddy and send packet to QQ server accordingly */ |
521 void qq_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) | 524 void qq_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) |