| 856 |
858 |
| 857 /* Prototypes */ |
859 /* Prototypes */ |
| 858 static void ggp_set_status(PurpleAccount *account, PurpleStatus *status); |
860 static void ggp_set_status(PurpleAccount *account, PurpleStatus *status); |
| 859 static int ggp_to_gg_status(PurpleStatus *status, char **msg); |
861 static int ggp_to_gg_status(PurpleStatus *status, char **msg); |
| 860 |
862 |
| |
863 struct gg_fetch_avatar_data |
| |
864 { |
| |
865 PurpleConnection *gc; |
| |
866 gchar *uin; |
| |
867 gchar *avatar_url; |
| |
868 }; |
| |
869 |
| |
870 |
| |
871 static void gg_fetch_avatar_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, |
| |
872 const gchar *data, size_t len, const gchar *error_message) { |
| |
873 struct gg_fetch_avatar_data *d = user_data; |
| |
874 PurpleAccount *account; |
| |
875 PurpleBuddy *buddy; |
| |
876 gpointer buddy_icon_data; |
| |
877 |
| |
878 /* FIXME: This shouldn't be necessary */ |
| |
879 if (!PURPLE_CONNECTION_IS_VALID(d->gc)) { |
| |
880 g_free(d->uin); |
| |
881 g_free(d->avatar_url); |
| |
882 g_free(d); |
| |
883 g_return_if_reached(); |
| |
884 } |
| |
885 |
| |
886 account = purple_connection_get_account(d->gc); |
| |
887 buddy = purple_find_buddy(account, d->uin); |
| |
888 |
| |
889 if (buddy == NULL) |
| |
890 goto out; |
| |
891 |
| |
892 buddy_icon_data = g_memdup(data, len); |
| |
893 |
| |
894 purple_buddy_icons_set_for_user(account, purple_buddy_get_name(buddy), |
| |
895 buddy_icon_data, len, d->avatar_url); |
| |
896 purple_debug_info("gg", "UIN: %s should have avatar now\n", d->uin); |
| |
897 |
| |
898 out: |
| |
899 g_free(d->uin); |
| |
900 g_free(d->avatar_url); |
| |
901 g_free(d); |
| |
902 } |
| |
903 |
| |
904 static void gg_get_avatar_url_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, |
| |
905 const gchar *url_text, size_t len, const gchar *error_message) { |
| |
906 struct gg_fetch_avatar_data *data; |
| |
907 PurpleConnection *gc = user_data; |
| |
908 PurpleAccount *account; |
| |
909 PurpleBuddy *buddy; |
| |
910 const char *uin; |
| |
911 const char *is_blank; |
| |
912 const char *checksum; |
| |
913 |
| |
914 gchar *bigavatar = NULL; |
| |
915 xmlnode *xml = NULL; |
| |
916 xmlnode *xmlnode_users; |
| |
917 xmlnode *xmlnode_user; |
| |
918 xmlnode *xmlnode_avatars; |
| |
919 xmlnode *xmlnode_avatar; |
| |
920 xmlnode *xmlnode_bigavatar; |
| |
921 |
| |
922 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc)); |
| |
923 account = purple_connection_get_account(gc); |
| |
924 |
| |
925 if (error_message != NULL) |
| |
926 purple_debug_error("gg", "gg_get_avatars_cb error: %s\n", error_message); |
| |
927 else if (len > 0 && url_text && *url_text) { |
| |
928 xml = xmlnode_from_str(url_text, -1); |
| |
929 if (xml == NULL) |
| |
930 goto out; |
| |
931 |
| |
932 xmlnode_users = xmlnode_get_child(xml, "users"); |
| |
933 if (xmlnode_users == NULL) |
| |
934 goto out; |
| |
935 |
| |
936 xmlnode_user = xmlnode_get_child(xmlnode_users, "user"); |
| |
937 if (xmlnode_user == NULL) |
| |
938 goto out; |
| |
939 |
| |
940 uin = xmlnode_get_attrib(xmlnode_user, "uin"); |
| |
941 |
| |
942 xmlnode_avatars = xmlnode_get_child(xmlnode_user, "avatars"); |
| |
943 if (xmlnode_avatars == NULL) |
| |
944 goto out; |
| |
945 |
| |
946 xmlnode_avatar = xmlnode_get_child(xmlnode_avatars, "avatar"); |
| |
947 if (xmlnode_avatar == NULL) |
| |
948 goto out; |
| |
949 |
| |
950 xmlnode_bigavatar = xmlnode_get_child(xmlnode_avatar, "bigAvatar"); |
| |
951 if (xmlnode_bigavatar == NULL) |
| |
952 goto out; |
| |
953 |
| |
954 is_blank = xmlnode_get_attrib(xmlnode_avatar, "blank"); |
| |
955 bigavatar = xmlnode_get_data(xmlnode_bigavatar); |
| |
956 |
| |
957 purple_debug_info("gg", "gg_get_avatar_url_cb: UIN %s, IS_BLANK %s, " |
| |
958 "URL %s\n", |
| |
959 uin ? uin : "(null)", is_blank ? is_blank : "(null)", |
| |
960 bigavatar ? bigavatar : "(null)"); |
| |
961 |
| |
962 if (uin != NULL && bigavatar != NULL) { |
| |
963 buddy = purple_find_buddy(account, uin); |
| |
964 if (buddy == NULL) |
| |
965 goto out; |
| |
966 |
| |
967 checksum = purple_buddy_icons_get_checksum_for_user(buddy); |
| |
968 |
| |
969 if (purple_strequal(is_blank, "1")) { |
| |
970 purple_buddy_icons_set_for_user(account, |
| |
971 purple_buddy_get_name(buddy), NULL, 0, NULL); |
| |
972 } else if (!purple_strequal(checksum, bigavatar)) { |
| |
973 data = g_new0(struct gg_fetch_avatar_data, 1); |
| |
974 data->gc = gc; |
| |
975 data->uin = g_strdup(uin); |
| |
976 data->avatar_url = g_strdup(bigavatar); |
| |
977 |
| |
978 url_data = purple_util_fetch_url_request_len_with_account(account, |
| |
979 bigavatar, TRUE, "Mozilla/4.0 (compatible; MSIE 5.0)", |
| |
980 FALSE, NULL, FALSE, -1, gg_fetch_avatar_cb, data); |
| |
981 } |
| |
982 } |
| |
983 } |
| |
984 |
| |
985 out: |
| |
986 if (xml) |
| |
987 xmlnode_free(xml); |
| |
988 g_free(bigavatar); |
| |
989 } |
| 861 |
990 |
| 862 /** |
991 /** |
| 863 * Handle change of the status of the buddy. |
992 * Handle change of the status of the buddy. |
| 864 * |
993 * |
| 865 * @param gc PurpleConnection |
994 * @param gc PurpleConnection |