comparison libpurple/protocols/myspace/myspace.c @ 16731:2e0bd3e6f2c7

Incomplete attempt at using msim_send() instead of msim_send_raw(). Changed msim_send() to accept static strings as keys and dynamic strings as values, to ease programming. Using msim_send() over msim_send_raw() still causes login to failure, for reasons not yet clear.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 20 May 2007 08:21:01 +0000
parents a2e9890a57e0
children a8e8482a2dc6
comparison
equal deleted inserted replaced
16730:a2e9890a57e0 16731:2e0bd3e6f2c7
444 { 444 {
445 gchar **items, **items_tmp; 445 gchar **items, **items_tmp;
446 gchar *raw; 446 gchar *raw;
447 guint i; 447 guint i;
448 448
449 items = (gchar **)g_new0(gchar *, g_hash_table_size(table)); 449 /* Create an array with enough elements for each part of the
450 450 * protocol message - one for each item, plus one for the initial \\,
451 items_tmp = items; 451 * another for the ending \\final\\, and the last for NULL terminator.
452 */
453 items = (gchar **)g_new0(gchar *, g_hash_table_size(table) + 3);
454
455 /* Beginning and ending markers. */
456 items[0] = g_strdup("");
457 items[g_hash_table_size(table) + 1] = g_strdup("final");
458 items[g_hash_table_size(table) + 2] = g_strdup("");
459
460 items_tmp = items + 1;
452 g_hash_table_foreach(table, (GHFunc)msim_pack_each, &items_tmp); 461 g_hash_table_foreach(table, (GHFunc)msim_pack_each, &items_tmp);
453 462
454 /* Join each item of the message. */ 463 /* Join each item of the message. */
455 raw = g_strjoinv("\\", items); 464 raw = g_strjoinv("\\", items);
456 465
489 * variable arguments. 498 * variable arguments.
490 * 499 *
491 * @param session 500 * @param session
492 * @param ... A sequence of gchar* key/value pairs, terminated with NULL. The strings will be copied. 501 * @param ... A sequence of gchar* key/value pairs, terminated with NULL. The strings will be copied.
493 * 502 *
503 * IMPORTANT: The key/value pair strings are not copied. The 'key' strings
504 * are not freed, but the 'value' pair is. Use g_strdup() to pass a static
505 * string as a value. This function operates this way so that you can easily
506 * use a call to g_strdup_printf() for the 'value' strings and not have to
507 * worry about freeing the memory.
508 *
509 * It bears repeating: THE VALUE STRINGS WILL BE FREED. Copy if static.
510 *
494 * This function exists for coding convenience: a message can be created 511 * This function exists for coding convenience: a message can be created
495 * and sent in one line of code. Internally it calls msim_sendh(). 512 * and sent in one line of code. Internally it calls msim_sendh().
496 */ 513 */
497 514
498 static gboolean msim_send(MsimSession *session, ...) 515 static gboolean msim_send(MsimSession *session, ...)
501 GHashTable *table; 518 GHashTable *table;
502 gchar *key, *value; 519 gchar *key, *value;
503 gboolean success; 520 gboolean success;
504 521
505 table = g_hash_table_new_full((GHashFunc)g_str_hash, 522 table = g_hash_table_new_full((GHashFunc)g_str_hash,
506 (GEqualFunc)g_str_equal, g_free, g_free); 523 (GEqualFunc)g_str_equal, NULL, g_free);
507 524
508 /* Parse key, value pairs until NULL. */ 525 /* Parse key, value pairs until NULL. */
509 va_start(argp, session); 526 va_start(argp, session);
510 do 527 do
511 { 528 {
520 { 537 {
521 purple_debug_info("msim", "msim_send: no value for key '%s', ignoring\n", key); 538 purple_debug_info("msim", "msim_send: no value for key '%s', ignoring\n", key);
522 break; 539 break;
523 } 540 }
524 541
525 g_hash_table_insert(table, g_strdup(key), g_strdup(value)); 542 g_hash_table_insert(table, key, value);
526 } while(key && value); 543 } while(key && value);
527 544
528 /* Actually send the message. */ 545 /* Actually send the message. */
529 success = msim_sendh(session, table); 546 success = msim_sendh(session, table);
530 547
620 response_str = msim_compute_login_response(nc, account->username, account->password); 637 response_str = msim_compute_login_response(nc, account->username, account->password);
621 638
622 g_free(nc); 639 g_free(nc);
623 640
624 /* Reply */ 641 /* Reply */
642 /* \status\100\id\1\login2\196610\username\msimprpl@xyzzy.cjb.net\clientver\673\reconn\0\response\+6M+DQhovMxwdt1ceIervus9O5K+X9BR02w6B4+4+Zrg66pWrSzX94ER8efSb8Ju9kye2MnDdpTDwybziACy2mQFWIB9Mf5/1Tdlr6kAtJA==\final\
643 this fails. what is it?
644 - escaping? no, removing msim_escape() still causes login failure. should verify.
645 - message order? should login2 come first?
646 - something else?
647 */
648 #if 0
649 msim_send(session,
650 "login2", g_strdup_printf("%d", 196610),
651 "username", g_strdup(account->username),
652 "response", g_strdup(response_str),
653 "clientver", g_strdup_printf("%d", MSIM_CLIENT_VERSION),
654 "reconn", g_strdup_printf("%d", 0),
655 "status", g_strdup_printf("%d", 100),
656 "id", g_strdup_printf("%d", 1),
657 NULL);
658 #else
659
625 /* TODO: escape values. A response_str with a / in it (\ is not in base64) will 660 /* TODO: escape values. A response_str with a / in it (\ is not in base64) will
626 * cause a login failure! / must be encoded as /1. */ 661 * cause a login failure. / must be encoded as /1. */
627 buf = g_strdup_printf("\\login2\\%d\\username\\%s\\response\\%s\\clientver\\%d\\reconn\\%d\\status\\%d\\id\\1\\final\\", 662
628 196610, account->username, response_str, MSIM_CLIENT_VERSION, 0, 100); 663 /* \login2\196610\username\msimprpl@xyzzy.cjb.net\response\nseVXvvrwgQsv7FUAbHJLMP8YPEGKHftwN+Z0zCjmxOTOc0/nVPQWZ5Znv5i6kh26XfZlqNzvoPqaXNbXL6TsSZpU/guAAg0o6XBA1e/Sw==\clientver\673\reconn\0\status\100\id\1\final\ - works*/
629 664 buf = g_strdup_printf("\\login2\\%d\\username\\%s\\response\\%s\\clientver\\%d\\reconn\\%d\\status\\%d\\id\\1\\final\\",
630 g_free(response_str); 665 196610, account->username, response_str, MSIM_CLIENT_VERSION, 0, 100);
666
631 667
632 purple_debug_info("msim", "response=<%s>\n", buf); 668 purple_debug_info("msim", "response=<%s>\n", buf);
633 669
634 msim_send_raw(session, buf); 670 msim_send_raw(session, buf);
635 671
636 g_free(buf); 672 g_free(buf);
673 #endif
674
675 g_free(response_str);
637 676
638 return 0; 677 return 0;
639 } 678 }
640 679
641 #ifndef MSIM_USE_PURPLE_RC4 680 #ifndef MSIM_USE_PURPLE_RC4