comparison libpurple/protocols/oscar/family_icbm.c @ 30362:879baaf87aa2

Added an error handler for family_icq.c. So far it works for icq fullinfo and alias requests. This was originally motivated by me getting "Server rate limit exceeded" while testing authorization requests. This error completely prevented the authorization request dialog from showing up.
author ivan.komarov@soc.pidgin.im
date Sun, 30 May 2010 19:01:30 +0000
parents f18b6eb0ed02
children 47dfe1d54e9e
comparison
equal deleted inserted replaced
30361:9881f18b95b1 30362:879baaf87aa2
2491 flap_connection_send_snac(od, conn, SNAC_FAMILY_ICBM, 0x000b, 0x0000, snacid, &bs); 2491 flap_connection_send_snac(od, conn, SNAC_FAMILY_ICBM, 0x000b, 0x0000, snacid, &bs);
2492 2492
2493 byte_stream_destroy(&bs); 2493 byte_stream_destroy(&bs);
2494 2494
2495 return 0; 2495 return 0;
2496 }
2497
2498 static void parse_status_note_text(OscarData *od, guchar *cookie, char *bn, ByteStream *bs)
2499 {
2500 struct aim_icq_info *info;
2501 struct aim_icq_info *prev_info;
2502 char *response;
2503 char *encoding;
2504 char *stripped_encoding;
2505 char *status_note_title;
2506 char *status_note_text;
2507 char *stripped_status_note_text;
2508 char *status_note;
2509 guint32 length;
2510 guint16 version;
2511 guint32 capability;
2512 guint8 message_type;
2513 guint16 status_code;
2514 guint16 text_length;
2515 guint32 request_length;
2516 guint32 response_length;
2517 guint32 encoding_length;
2518 PurpleAccount *account;
2519 PurpleBuddy *buddy;
2520 PurplePresence *presence;
2521 PurpleStatus *status;
2522
2523 for (prev_info = NULL, info = od->icq_info; info != NULL; prev_info = info, info = info->next)
2524 {
2525 if (memcmp(&info->icbm_cookie, cookie, 8) == 0)
2526 {
2527 if (prev_info == NULL)
2528 od->icq_info = info->next;
2529 else
2530 prev_info->next = info->next;
2531
2532 break;
2533 }
2534 }
2535
2536 if (info == NULL)
2537 return;
2538
2539 status_note_title = info->status_note_title;
2540 g_free(info);
2541
2542 length = byte_stream_getle16(bs);
2543 if (length != 27) {
2544 purple_debug_misc("oscar", "clientautoresp: incorrect header "
2545 "size; expected 27, received %u.\n", length);
2546 g_free(status_note_title);
2547 return;
2548 }
2549
2550 version = byte_stream_getle16(bs);
2551 if (version != 9) {
2552 purple_debug_misc("oscar", "clientautoresp: incorrect version; "
2553 "expected 9, received %u.\n", version);
2554 g_free(status_note_title);
2555 return;
2556 }
2557
2558 capability = aim_locate_getcaps(od, bs, 0x10);
2559 if (capability != OSCAR_CAPABILITY_EMPTY) {
2560 purple_debug_misc("oscar", "clientautoresp: plugin ID is not null.\n");
2561 g_free(status_note_title);
2562 return;
2563 }
2564
2565 byte_stream_advance(bs, 2); /* unknown */
2566 byte_stream_advance(bs, 4); /* client capabilities flags */
2567 byte_stream_advance(bs, 1); /* unknown */
2568 byte_stream_advance(bs, 2); /* downcouner? */
2569
2570 length = byte_stream_getle16(bs);
2571 if (length != 14) {
2572 purple_debug_misc("oscar", "clientautoresp: incorrect header "
2573 "size; expected 14, received %u.\n", length);
2574 g_free(status_note_title);
2575 return;
2576 }
2577
2578 byte_stream_advance(bs, 2); /* downcounter? */
2579 byte_stream_advance(bs, 12); /* unknown */
2580
2581 message_type = byte_stream_get8(bs);
2582 if (message_type != 0x1a) {
2583 purple_debug_misc("oscar", "clientautoresp: incorrect message "
2584 "type; expected 0x1a, received 0x%x.\n", message_type);
2585 g_free(status_note_title);
2586 return;
2587 }
2588
2589 byte_stream_advance(bs, 1); /* message flags */
2590
2591 status_code = byte_stream_getle16(bs);
2592 if (status_code != 0) {
2593 purple_debug_misc("oscar", "clientautoresp: incorrect status "
2594 "code; expected 0, received %u.\n", status_code);
2595 g_free(status_note_title);
2596 return;
2597 }
2598
2599 byte_stream_advance(bs, 2); /* priority code */
2600
2601 text_length = byte_stream_getle16(bs);
2602 byte_stream_advance(bs, text_length); /* text */
2603
2604 length = byte_stream_getle16(bs);
2605 byte_stream_advance(bs, 18); /* unknown */
2606
2607 request_length = byte_stream_getle32(bs);
2608 if (length != 18 + 4 + request_length + 17) {
2609 purple_debug_misc("oscar", "clientautoresp: incorrect block; "
2610 "expected length is %u, got %u.\n",
2611 18 + 4 + request_length + 17, length);
2612 g_free(status_note_title);
2613 return;
2614 }
2615
2616 byte_stream_advance(bs, request_length); /* x request */
2617 byte_stream_advance(bs, 17); /* unknown */
2618
2619 length = byte_stream_getle32(bs);
2620 response_length = byte_stream_getle32(bs);
2621 response = byte_stream_getstr(bs, response_length);
2622 encoding_length = byte_stream_getle32(bs);
2623 if (length != 4 + response_length + 4 + encoding_length) {
2624 purple_debug_misc("oscar", "clientautoresp: incorrect block; "
2625 "expected length is %u, got %u.\n",
2626 4 + response_length + 4 + encoding_length, length);
2627 g_free(status_note_title);
2628 g_free(response);
2629 return;
2630 }
2631
2632 encoding = byte_stream_getstr(bs, encoding_length);
2633
2634 account = purple_connection_get_account(od->gc);
2635
2636 stripped_encoding = oscar_encoding_extract(encoding);
2637 status_note_text = oscar_encoding_to_utf8(account, stripped_encoding, response, response_length);
2638 stripped_status_note_text = purple_markup_strip_html(status_note_text);
2639
2640 if (stripped_status_note_text != NULL && stripped_status_note_text[0] != 0)
2641 status_note = g_strdup_printf("%s: %s", status_note_title, stripped_status_note_text);
2642 else
2643 status_note = g_strdup(status_note_title);
2644
2645 g_free(status_note_title);
2646 g_free(response);
2647 g_free(encoding);
2648 g_free(stripped_encoding);
2649 g_free(status_note_text);
2650 g_free(stripped_status_note_text);
2651
2652 buddy = purple_find_buddy(account, bn);
2653 if (buddy == NULL)
2654 {
2655 purple_debug_misc("oscar", "clientautoresp: buddy %s was not found.\n", bn);
2656 g_free(status_note);
2657 return;
2658 }
2659
2660 purple_debug_misc("oscar", "clientautoresp: setting status "
2661 "message to \"%s\".\n", status_note);
2662
2663 presence = purple_buddy_get_presence(buddy);
2664 status = purple_presence_get_active_status(presence);
2665
2666 purple_prpl_got_user_status(account, bn,
2667 purple_status_get_id(status),
2668 "message", status_note, NULL);
2669
2670 g_free(status_note);
2671 } 2496 }
2672 2497
2673 /* 2498 /*
2674 * Subtype 0x000b - Receive the response from an ICQ status message 2499 * Subtype 0x000b - Receive the response from an ICQ status message
2675 * request (in which case this contains the ICQ status message) or 2500 * request (in which case this contains the ICQ status message) or