Mercurial > pidgin.yaz
comparison libpurple/protocols/myspace/myspace.c @ 16749:0fa4a3e9b318
Stylistic improvements - use type *name instead of type* name for pointers
everywhere. Now "egrep '[0-9A-Za-z][*]' *.c *.h" shows nothing.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Thu, 31 May 2007 03:06:38 +0000 |
parents | 496855295bd7 |
children | 793301c04e3a |
comparison
equal
deleted
inserted
replaced
16748:da7621e799b7 | 16749:0fa4a3e9b318 |
---|---|
162 * | 162 * |
163 * This string replace method is based on | 163 * This string replace method is based on |
164 * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html | 164 * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html |
165 * | 165 * |
166 */ | 166 */ |
167 gchar *str_replace(const gchar* str, const gchar *old, const gchar *new) | 167 gchar *str_replace(const gchar *str, const gchar *old, const gchar *new) |
168 { | 168 { |
169 char **items; | 169 char **items; |
170 char *ret; | 170 char *ret; |
171 | 171 |
172 items = g_strsplit(str, old, -1); | 172 items = g_strsplit(str, old, -1); |
183 * @param msg The message string to parse, will be g_free()'d. | 183 * @param msg The message string to parse, will be g_free()'d. |
184 * | 184 * |
185 * @return Hash table of message. Caller should destroy with | 185 * @return Hash table of message. Caller should destroy with |
186 * g_hash_table_destroy() when done. | 186 * g_hash_table_destroy() when done. |
187 */ | 187 */ |
188 GHashTable* msim_parse(gchar* msg) | 188 GHashTable *msim_parse(gchar *msg) |
189 { | 189 { |
190 GHashTable *table; | 190 GHashTable *table; |
191 gchar *token; | 191 gchar *token; |
192 gchar **tokens; | 192 gchar **tokens; |
193 gchar *key; | 193 gchar *key; |
327 | 327 |
328 | 328 |
329 #ifdef MSIM_DEBUG_MSG | 329 #ifdef MSIM_DEBUG_MSG |
330 void print_hash_item(gpointer key, gpointer value, gpointer user_data) | 330 void print_hash_item(gpointer key, gpointer value, gpointer user_data) |
331 { | 331 { |
332 purple_debug_info("msim", "%s=%s\n", (char*)key, (char*)value); | 332 purple_debug_info("msim", "%s=%s\n", (char *)key, (char *)value); |
333 } | 333 } |
334 #endif | 334 #endif |
335 | 335 |
336 /** | 336 /** |
337 * Send raw data to the server. | 337 * Send raw data to the server. |
442 | 442 |
443 purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4); | 443 purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4); |
444 | 444 |
445 purple_debug_info("msim", "nc=<%s>\n", nc_str); | 445 purple_debug_info("msim", "nc=<%s>\n", nc_str); |
446 | 446 |
447 nc = (guchar*)purple_base64_decode(nc_str, &nc_len); | 447 nc = (guchar *)purple_base64_decode(nc_str, &nc_len); |
448 purple_debug_info("msim", "base64 decoded to %d bytes\n", nc_len); | 448 purple_debug_info("msim", "base64 decoded to %d bytes\n", nc_len); |
449 if (nc_len != 0x40) | 449 if (nc_len != 0x40) |
450 { | 450 { |
451 purple_debug_info("msim", "bad nc length: %x != 0x40\n", nc_len); | 451 purple_debug_info("msim", "bad nc length: %x != 0x40\n", nc_len); |
452 purple_connection_error(session->gc, _("Unexpected challenge length from server")); | 452 purple_connection_error(session->gc, _("Unexpected challenge length from server")); |
590 * @param response_len Will be written with response length. | 590 * @param response_len Will be written with response length. |
591 * | 591 * |
592 * @return Binary login challenge response, ready to send to the server. Must be g_free()'d | 592 * @return Binary login challenge response, ready to send to the server. Must be g_free()'d |
593 * when finished. | 593 * when finished. |
594 */ | 594 */ |
595 gchar* msim_compute_login_response(guchar nonce[2*NONCE_SIZE], | 595 gchar *msim_compute_login_response(guchar nonce[2 * NONCE_SIZE], |
596 gchar* email, gchar* password, guint* response_len) | 596 gchar *email, gchar *password, guint *response_len) |
597 { | 597 { |
598 PurpleCipherContext *key_context; | 598 PurpleCipherContext *key_context; |
599 PurpleCipher *sha1; | 599 PurpleCipher *sha1; |
600 #ifdef MSIM_USE_PURPLE_RC4 | 600 #ifdef MSIM_USE_PURPLE_RC4 |
601 PurpleCipherContext *rc4; | 601 PurpleCipherContext *rc4; |
603 rc4_state_struct rc4; | 603 rc4_state_struct rc4; |
604 #endif | 604 #endif |
605 | 605 |
606 guchar hash_pw[HASH_SIZE]; | 606 guchar hash_pw[HASH_SIZE]; |
607 guchar key[HASH_SIZE]; | 607 guchar key[HASH_SIZE]; |
608 gchar* password_utf16le; | 608 gchar *password_utf16le; |
609 guchar* data; | 609 guchar *data; |
610 guchar* data_out; | 610 guchar *data_out; |
611 size_t data_len, data_out_len; | 611 size_t data_len, data_out_len; |
612 gsize conv_bytes_read, conv_bytes_written; | 612 gsize conv_bytes_read, conv_bytes_written; |
613 GError* conv_error; | 613 GError *conv_error; |
614 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE | 614 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
615 int i; | 615 int i; |
616 #endif | 616 #endif |
617 | |
618 //memset(nonce, 0, NONCE_SIZE); | |
619 //memset(nonce + NONCE_SIZE, 1, NONCE_SIZE); | |
620 | 617 |
621 /* Convert ASCII password to UTF16 little endian */ | 618 /* Convert ASCII password to UTF16 little endian */ |
622 purple_debug_info("msim", "converting password to UTF-16LE\n"); | 619 purple_debug_info("msim", "converting password to UTF-16LE\n"); |
623 conv_error = NULL; | 620 conv_error = NULL; |
624 password_utf16le = g_convert(password, -1, "UTF-16LE", "UTF-8", | 621 password_utf16le = g_convert(password, -1, "UTF-16LE", "UTF-8", |
631 conv_error->message); | 628 conv_error->message); |
632 g_error_free(conv_error); | 629 g_error_free(conv_error); |
633 } | 630 } |
634 | 631 |
635 /* Compute password hash */ | 632 /* Compute password hash */ |
636 purple_cipher_digest_region("sha1", (guchar*)password_utf16le, | 633 purple_cipher_digest_region("sha1", (guchar *)password_utf16le, |
637 conv_bytes_written, sizeof(hash_pw), hash_pw, NULL); | 634 conv_bytes_written, sizeof(hash_pw), hash_pw, NULL); |
638 g_free(password_utf16le); | 635 g_free(password_utf16le); |
639 | 636 |
640 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE | 637 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
641 purple_debug_info("msim", "pwhash = "); | 638 purple_debug_info("msim", "pwhash = "); |
689 "\x00\x00\x00\x00\x05\x7f\x00\x00\x01\x00\x00\x00\x00\x0a\x00\x00\x40\xc0\xa8\x58\x01\xc0\xa8\x3c\x01", 25); | 686 "\x00\x00\x00\x00\x05\x7f\x00\x00\x01\x00\x00\x00\x00\x0a\x00\x00\x40\xc0\xa8\x58\x01\xc0\xa8\x3c\x01", 25); |
690 | 687 |
691 #ifdef MSIM_USE_PURPLE_RC4 | 688 #ifdef MSIM_USE_PURPLE_RC4 |
692 data_out = g_new0(guchar, data_len); | 689 data_out = g_new0(guchar, data_len); |
693 | 690 |
694 purple_cipher_context_encrypt(rc4, (const guchar*)data, | 691 purple_cipher_context_encrypt(rc4, (const guchar *)data, |
695 data_len, data_out, &data_out_len); | 692 data_len, data_out, &data_out_len); |
696 purple_cipher_context_destroy(rc4); | 693 purple_cipher_context_destroy(rc4); |
697 #else | 694 #else |
698 /* Use our own RC4 code */ | 695 /* Use our own RC4 code */ |
699 purple_debug_info("msim", "Using non-purple RC4 cipher code in this version\n"); | 696 purple_debug_info("msim", "Using non-purple RC4 cipher code in this version\n"); |
709 purple_debug_info("msim", "response=<%s>\n", data_out); | 706 purple_debug_info("msim", "response=<%s>\n", data_out); |
710 #endif | 707 #endif |
711 | 708 |
712 *response_len = data_out_len; | 709 *response_len = data_out_len; |
713 | 710 |
714 return (gchar*)data_out; | 711 return (gchar *)data_out; |
715 } | 712 } |
716 | 713 |
717 /** | 714 /** |
718 * Schedule an IM to be sent once the user ID is looked up. | 715 * Schedule an IM to be sent once the user ID is looked up. |
719 * | 716 * |
831 * Calls msim_send_im_by_userid. | 828 * Calls msim_send_im_by_userid. |
832 * | 829 * |
833 * @param session | 830 * @param session |
834 * @param userinfo User info message from server containing a 'body' field | 831 * @param userinfo User info message from server containing a 'body' field |
835 * with a 'UserID' key. This is where the user ID is taken from. | 832 * with a 'UserID' key. This is where the user ID is taken from. |
836 * @param data A send_im_cb_struct* of information on the IM to send. | 833 * @param data A send_im_cb_struct * of information on the IM to send. |
837 * | 834 * |
838 */ | 835 */ |
839 void msim_send_im_by_userid_cb(MsimSession *session, GHashTable *userinfo, gpointer data) | 836 void msim_send_im_by_userid_cb(MsimSession *session, GHashTable *userinfo, gpointer data) |
840 { | 837 { |
841 send_im_cb_struct *s; | 838 send_im_cb_struct *s; |
848 body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); | 845 body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); |
849 g_return_if_fail(body != NULL); | 846 g_return_if_fail(body != NULL); |
850 | 847 |
851 userid = g_hash_table_lookup(body, "UserID"); | 848 userid = g_hash_table_lookup(body, "UserID"); |
852 | 849 |
853 s = (send_im_cb_struct*)data; | 850 s = (send_im_cb_struct *)data; |
854 msim_send_im_by_userid(session, userid, s->message, s->flags); | 851 msim_send_im_by_userid(session, userid, s->message, s->flags); |
855 | 852 |
856 g_hash_table_destroy(body); | 853 g_hash_table_destroy(body); |
857 g_hash_table_destroy(userinfo); | 854 g_hash_table_destroy(userinfo); |
858 g_free(s->message); | 855 g_free(s->message); |
862 /** | 859 /** |
863 * Callback to handle incoming messages, after resolving userid. | 860 * Callback to handle incoming messages, after resolving userid. |
864 * | 861 * |
865 * @param session | 862 * @param session |
866 * @param userinfo Message from server on user's info, containing UserName. | 863 * @param userinfo Message from server on user's info, containing UserName. |
867 * @param data A gchar* of the incoming instant message's text. | 864 * @param data A gchar * of the incoming instant message's text. |
868 */ | 865 */ |
869 void msim_incoming_im_cb(MsimSession *session, GHashTable *userinfo, gpointer data) | 866 void msim_incoming_im_cb(MsimSession *session, GHashTable *userinfo, gpointer data) |
870 { | 867 { |
871 gchar *msg; | 868 gchar *msg; |
872 gchar *username; | 869 gchar *username; |
878 body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); | 875 body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); |
879 g_return_if_fail(body != NULL); | 876 g_return_if_fail(body != NULL); |
880 | 877 |
881 username = g_hash_table_lookup(body, "UserName"); | 878 username = g_hash_table_lookup(body, "UserName"); |
882 | 879 |
883 msg = (gchar*)data; | 880 msg = (gchar *)data; |
884 serv_got_im(session->gc, username, msg, PURPLE_MESSAGE_RECV, time(NULL)); | 881 serv_got_im(session->gc, username, msg, PURPLE_MESSAGE_RECV, time(NULL)); |
885 | 882 |
886 g_hash_table_destroy(body); | 883 g_hash_table_destroy(body); |
887 g_hash_table_destroy(userinfo); | 884 g_hash_table_destroy(userinfo); |
888 } | 885 } |
931 MsimSession *session; | 928 MsimSession *session; |
932 | 929 |
933 g_return_val_if_fail(gc != NULL, -1); | 930 g_return_val_if_fail(gc != NULL, -1); |
934 g_return_val_if_fail(table != NULL, -1); | 931 g_return_val_if_fail(table != NULL, -1); |
935 | 932 |
936 session = (MsimSession*)gc->proto_data; | 933 session = (MsimSession *)gc->proto_data; |
937 | 934 |
938 #ifdef MSIM_DEBUG_MSG | 935 #ifdef MSIM_DEBUG_MSG |
939 purple_debug_info("msim", "-------- message -------------\n"); | 936 purple_debug_info("msim", "-------- message -------------\n"); |
940 g_hash_table_foreach(table, print_hash_item, NULL); | 937 g_hash_table_foreach(table, print_hash_item, NULL); |
941 purple_debug_info("msim", "------------------------------\n"); | 938 purple_debug_info("msim", "------------------------------\n"); |
943 | 940 |
944 if (g_hash_table_lookup(table, "nc")) | 941 if (g_hash_table_lookup(table, "nc")) |
945 { | 942 { |
946 return msim_login_challenge(session, table); | 943 return msim_login_challenge(session, table); |
947 } else if (g_hash_table_lookup(table, "sesskey")) { | 944 } else if (g_hash_table_lookup(table, "sesskey")) { |
948 purple_debug_info("msim", "SESSKEY=<%s>\n", (gchar*)g_hash_table_lookup(table, "sesskey")); | 945 purple_debug_info("msim", "SESSKEY=<%s>\n", (gchar *)g_hash_table_lookup(table, "sesskey")); |
949 | 946 |
950 purple_connection_update_progress(gc, _("Connected"), 3, 4); | 947 purple_connection_update_progress(gc, _("Connected"), 3, 4); |
951 | 948 |
952 session->sesskey = g_strdup(g_hash_table_lookup(table, "sesskey")); | 949 session->sesskey = g_strdup(g_hash_table_lookup(table, "sesskey")); |
953 | 950 |
1114 /** | 1111 /** |
1115 * Callback to update incoming status messages, after looked up username. | 1112 * Callback to update incoming status messages, after looked up username. |
1116 * | 1113 * |
1117 * @param session | 1114 * @param session |
1118 * @param userinfo Looked up user information from server. | 1115 * @param userinfo Looked up user information from server. |
1119 * @param data gchar* status string. | 1116 * @param data gchar * status string. |
1120 * | 1117 * |
1121 */ | 1118 */ |
1122 void msim_status_cb(MsimSession *session, GHashTable *userinfo, gpointer data) | 1119 void msim_status_cb(MsimSession *session, GHashTable *userinfo, gpointer data) |
1123 { | 1120 { |
1124 PurpleBuddyList *blist; | 1121 PurpleBuddyList *blist; |
1134 gchar *username; | 1131 gchar *username; |
1135 | 1132 |
1136 g_return_if_fail(MSIM_SESSION_VALID(session)); | 1133 g_return_if_fail(MSIM_SESSION_VALID(session)); |
1137 g_return_if_fail(userinfo != NULL); | 1134 g_return_if_fail(userinfo != NULL); |
1138 | 1135 |
1139 status_str = (gchar*)data; | 1136 status_str = (gchar *)data; |
1140 | 1137 |
1141 body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); | 1138 body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); |
1142 g_return_if_fail(body != NULL); | 1139 g_return_if_fail(body != NULL); |
1143 | 1140 |
1144 username = g_hash_table_lookup(body, "UserName"); | 1141 username = g_hash_table_lookup(body, "UserName"); |
1260 int n; | 1257 int n; |
1261 | 1258 |
1262 g_return_if_fail(gc_uncasted != NULL); | 1259 g_return_if_fail(gc_uncasted != NULL); |
1263 g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */ | 1260 g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */ |
1264 | 1261 |
1265 gc = (PurpleConnection*)(gc_uncasted); | 1262 gc = (PurpleConnection *)(gc_uncasted); |
1266 account = purple_connection_get_account(gc); | 1263 account = purple_connection_get_account(gc); |
1267 session = gc->proto_data; | 1264 session = gc->proto_data; |
1268 | 1265 |
1269 g_return_if_fail(MSIM_SESSION_VALID(session)); | 1266 g_return_if_fail(MSIM_SESSION_VALID(session)); |
1270 g_return_if_fail(cond == PURPLE_INPUT_READ); | 1267 g_return_if_fail(cond == PURPLE_INPUT_READ); |
1378 PurpleConnection *gc; | 1375 PurpleConnection *gc; |
1379 MsimSession *session; | 1376 MsimSession *session; |
1380 | 1377 |
1381 g_return_if_fail(data != NULL); | 1378 g_return_if_fail(data != NULL); |
1382 | 1379 |
1383 gc = (PurpleConnection*)data; | 1380 gc = (PurpleConnection *)data; |
1384 session = gc->proto_data; | 1381 session = gc->proto_data; |
1385 | 1382 |
1386 if (source < 0) | 1383 if (source < 0) |
1387 { | 1384 { |
1388 purple_connection_error(gc, _("Couldn't connect to host")); | 1385 purple_connection_error(gc, _("Couldn't connect to host")); |
1584 GHashTable *userinfo; | 1581 GHashTable *userinfo; |
1585 gchar *display_name; | 1582 gchar *display_name; |
1586 | 1583 |
1587 g_return_val_if_fail(buddy != NULL, NULL); | 1584 g_return_val_if_fail(buddy != NULL, NULL); |
1588 | 1585 |
1589 session = (MsimSession*)buddy->account->gc->proto_data; | 1586 session = (MsimSession *)buddy->account->gc->proto_data; |
1590 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); | 1587 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); |
1591 g_return_val_if_fail(session->user_lookup_cache != NULL, NULL); | 1588 g_return_val_if_fail(session->user_lookup_cache != NULL, NULL); |
1592 | 1589 |
1593 userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name); | 1590 userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name); |
1594 if (!userinfo) | 1591 if (!userinfo) |
1618 if (PURPLE_BUDDY_IS_ONLINE(buddy)) | 1615 if (PURPLE_BUDDY_IS_ONLINE(buddy)) |
1619 { | 1616 { |
1620 MsimSession *session; | 1617 MsimSession *session; |
1621 GHashTable *userinfo; | 1618 GHashTable *userinfo; |
1622 | 1619 |
1623 session = (MsimSession*)buddy->account->gc->proto_data; | 1620 session = (MsimSession *)buddy->account->gc->proto_data; |
1624 | 1621 |
1625 g_return_if_fail(MSIM_SESSION_VALID(session)); | 1622 g_return_if_fail(MSIM_SESSION_VALID(session)); |
1626 g_return_if_fail(session->user_lookup_cache); | 1623 g_return_if_fail(session->user_lookup_cache); |
1627 | 1624 |
1628 userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name); | 1625 userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name); |
1634 purple_notify_user_info_add_pair(user_info, "Display Name", g_hash_table_lookup(userinfo, "DisplayName")); | 1631 purple_notify_user_info_add_pair(user_info, "Display Name", g_hash_table_lookup(userinfo, "DisplayName")); |
1635 purple_notify_user_info_add_pair(user_info, "User Name", g_hash_table_lookup(userinfo, "UserName")); | 1632 purple_notify_user_info_add_pair(user_info, "User Name", g_hash_table_lookup(userinfo, "UserName")); |
1636 purple_notify_user_info_add_pair(user_info, "Total Friends", g_hash_table_lookup(userinfo, "TotalFriends")); | 1633 purple_notify_user_info_add_pair(user_info, "Total Friends", g_hash_table_lookup(userinfo, "TotalFriends")); |
1637 purple_notify_user_info_add_pair(user_info, "Song", | 1634 purple_notify_user_info_add_pair(user_info, "Song", |
1638 g_strdup_printf("%s - %s", | 1635 g_strdup_printf("%s - %s", |
1639 (gchar*)g_hash_table_lookup(userinfo, "BandName"), | 1636 (gchar *)g_hash_table_lookup(userinfo, "BandName"), |
1640 (gchar*)g_hash_table_lookup(userinfo, "SongName"))); | 1637 (gchar *)g_hash_table_lookup(userinfo, "SongName"))); |
1641 } | 1638 } |
1642 } | 1639 } |
1643 | 1640 |
1644 /** Callbacks called by Purple, to access this plugin. */ | 1641 /** Callbacks called by Purple, to access this plugin. */ |
1645 PurplePluginProtocolInfo prpl_info = | 1642 PurplePluginProtocolInfo prpl_info = |