Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/buddy.c @ 25286:ede22bc33d56
More struct hiding work
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 31 Oct 2008 05:08:57 +0000 |
parents | 1de1494a13e5 |
children | da46097b4722 |
comparison
equal
deleted
inserted
replaced
25285:d719b9d82540 | 25286:ede22bc33d56 |
---|---|
417 */ | 417 */ |
418 void jabber_set_info(PurpleConnection *gc, const char *info) | 418 void jabber_set_info(PurpleConnection *gc, const char *info) |
419 { | 419 { |
420 PurpleStoredImage *img; | 420 PurpleStoredImage *img; |
421 JabberIq *iq; | 421 JabberIq *iq; |
422 JabberStream *js = gc->proto_data; | 422 JabberStream *js = purple_connection_get_protocol_data(gc); |
423 xmlnode *vc_node; | 423 xmlnode *vc_node; |
424 const struct tag_attr *tag_attr; | 424 const struct tag_attr *tag_attr; |
425 | 425 |
426 /* if we have't grabbed the remote vcard yet, we can't | 426 /* if we have't grabbed the remote vcard yet, we can't |
427 * assume that what we have here is correct */ | 427 * assume that what we have here is correct */ |
494 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) | 494 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) |
495 { | 495 { |
496 PurplePresence *gpresence; | 496 PurplePresence *gpresence; |
497 PurpleStatus *status; | 497 PurpleStatus *status; |
498 | 498 |
499 if(((JabberStream*)gc->proto_data)->pep) { | 499 if(((JabberStream*)purple_connection_get_protocol_data(gc))->pep) { |
500 /* XEP-0084: User Avatars */ | 500 /* XEP-0084: User Avatars */ |
501 if(img) { | 501 if(img) { |
502 /* | 502 /* |
503 * TODO: This is pretty gross. The Jabber PRPL really shouldn't | 503 * TODO: This is pretty gross. The Jabber PRPL really shouldn't |
504 * do voodoo to try to determine the image type, height | 504 * do voodoo to try to determine the image type, height |
566 base64avatar = purple_base64_encode(purple_imgstore_get_data(img), purple_imgstore_get_size(img)); | 566 base64avatar = purple_base64_encode(purple_imgstore_get_data(img), purple_imgstore_get_size(img)); |
567 xmlnode_insert_data(data,base64avatar,-1); | 567 xmlnode_insert_data(data,base64avatar,-1); |
568 g_free(base64avatar); | 568 g_free(base64avatar); |
569 | 569 |
570 /* publish the avatar itself */ | 570 /* publish the avatar itself */ |
571 jabber_pep_publish((JabberStream*)gc->proto_data, publish); | 571 jabber_pep_publish((JabberStream*)purple_connection_get_protocol_data(gc), publish); |
572 | 572 |
573 /* next step: publish the metadata */ | 573 /* next step: publish the metadata */ |
574 publish = xmlnode_new("publish"); | 574 publish = xmlnode_new("publish"); |
575 xmlnode_set_attrib(publish,"node",AVATARNAMESPACEMETA); | 575 xmlnode_set_attrib(publish,"node",AVATARNAMESPACEMETA); |
576 | 576 |
592 heightstring = g_strdup_printf("%u", height); | 592 heightstring = g_strdup_printf("%u", height); |
593 xmlnode_set_attrib(info, "height", heightstring); | 593 xmlnode_set_attrib(info, "height", heightstring); |
594 g_free(heightstring); | 594 g_free(heightstring); |
595 | 595 |
596 /* publish the metadata */ | 596 /* publish the metadata */ |
597 jabber_pep_publish((JabberStream*)gc->proto_data, publish); | 597 jabber_pep_publish((JabberStream*)purple_connection_get_protocol_data(gc), publish); |
598 | 598 |
599 g_free(hash); | 599 g_free(hash); |
600 } else { /* if(img) */ | 600 } else { /* if(img) */ |
601 /* remove the metadata */ | 601 /* remove the metadata */ |
602 xmlnode *metadata, *item; | 602 xmlnode *metadata, *item; |
609 xmlnode_set_namespace(metadata,AVATARNAMESPACEMETA); | 609 xmlnode_set_namespace(metadata,AVATARNAMESPACEMETA); |
610 | 610 |
611 xmlnode_new_child(metadata, "stop"); | 611 xmlnode_new_child(metadata, "stop"); |
612 | 612 |
613 /* publish the metadata */ | 613 /* publish the metadata */ |
614 jabber_pep_publish((JabberStream*)gc->proto_data, publish); | 614 jabber_pep_publish((JabberStream*)purple_connection_get_protocol_data(gc), publish); |
615 } | 615 } |
616 } else { | 616 } else { |
617 purple_debug(PURPLE_DEBUG_ERROR, "jabber", | 617 purple_debug(PURPLE_DEBUG_ERROR, "jabber", |
618 "jabber_set_buddy_icon received non-png data"); | 618 "jabber_set_buddy_icon received non-png data"); |
619 } | 619 } |
1795 jbi->timeout_handle = purple_timeout_add(30000, jabber_buddy_get_info_timeout, jbi); | 1795 jbi->timeout_handle = purple_timeout_add(30000, jabber_buddy_get_info_timeout, jbi); |
1796 } | 1796 } |
1797 | 1797 |
1798 void jabber_buddy_get_info(PurpleConnection *gc, const char *who) | 1798 void jabber_buddy_get_info(PurpleConnection *gc, const char *who) |
1799 { | 1799 { |
1800 JabberStream *js = gc->proto_data; | 1800 JabberStream *js = purple_connection_get_protocol_data(gc); |
1801 char *bare_jid = jabber_get_bare_jid(who); | 1801 char *bare_jid = jabber_get_bare_jid(who); |
1802 | 1802 |
1803 if(bare_jid) { | 1803 if(bare_jid) { |
1804 jabber_buddy_get_info_for_jid(js, bare_jid); | 1804 jabber_buddy_get_info_for_jid(js, bare_jid); |
1805 g_free(bare_jid); | 1805 g_free(bare_jid); |
1846 JabberStream *js; | 1846 JabberStream *js; |
1847 | 1847 |
1848 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); | 1848 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
1849 | 1849 |
1850 buddy = (PurpleBuddy *) node; | 1850 buddy = (PurpleBuddy *) node; |
1851 gc = purple_account_get_connection(buddy->account); | 1851 gc = purple_account_get_connection(purple_buddy_get_account(buddy)); |
1852 js = gc->proto_data; | 1852 js = purple_connection_get_protocol_data(gc); |
1853 | 1853 |
1854 jabber_buddy_set_invisibility(js, buddy->name, TRUE); | 1854 jabber_buddy_set_invisibility(js, purple_buddy_get_name(buddy), TRUE); |
1855 } | 1855 } |
1856 | 1856 |
1857 static void jabber_buddy_make_visible(PurpleBlistNode *node, gpointer data) | 1857 static void jabber_buddy_make_visible(PurpleBlistNode *node, gpointer data) |
1858 { | 1858 { |
1859 PurpleBuddy *buddy; | 1859 PurpleBuddy *buddy; |
1861 JabberStream *js; | 1861 JabberStream *js; |
1862 | 1862 |
1863 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); | 1863 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
1864 | 1864 |
1865 buddy = (PurpleBuddy *) node; | 1865 buddy = (PurpleBuddy *) node; |
1866 gc = purple_account_get_connection(buddy->account); | 1866 gc = purple_account_get_connection(purple_buddy_get_account(buddy)); |
1867 js = gc->proto_data; | 1867 js = purple_connection_get_protocol_data(gc); |
1868 | 1868 |
1869 jabber_buddy_set_invisibility(js, buddy->name, FALSE); | 1869 jabber_buddy_set_invisibility(js, purple_buddy_get_name(buddy), FALSE); |
1870 } | 1870 } |
1871 | 1871 |
1872 static void jabber_buddy_cancel_presence_notification(PurpleBlistNode *node, | 1872 static void jabber_buddy_cancel_presence_notification(PurpleBlistNode *node, |
1873 gpointer data) | 1873 gpointer data) |
1874 { | 1874 { |
1877 JabberStream *js; | 1877 JabberStream *js; |
1878 | 1878 |
1879 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); | 1879 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
1880 | 1880 |
1881 buddy = (PurpleBuddy *) node; | 1881 buddy = (PurpleBuddy *) node; |
1882 gc = purple_account_get_connection(buddy->account); | 1882 gc = purple_account_get_connection(purple_buddy_get_account(buddy)); |
1883 js = gc->proto_data; | 1883 js = purple_connection_get_protocol_data(gc); |
1884 | 1884 |
1885 /* I wonder if we should prompt the user before doing this */ | 1885 /* I wonder if we should prompt the user before doing this */ |
1886 jabber_presence_subscription_set(js, buddy->name, "unsubscribed"); | 1886 jabber_presence_subscription_set(js, purple_buddy_get_name(buddy), "unsubscribed"); |
1887 } | 1887 } |
1888 | 1888 |
1889 static void jabber_buddy_rerequest_auth(PurpleBlistNode *node, gpointer data) | 1889 static void jabber_buddy_rerequest_auth(PurpleBlistNode *node, gpointer data) |
1890 { | 1890 { |
1891 PurpleBuddy *buddy; | 1891 PurpleBuddy *buddy; |
1893 JabberStream *js; | 1893 JabberStream *js; |
1894 | 1894 |
1895 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); | 1895 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
1896 | 1896 |
1897 buddy = (PurpleBuddy *) node; | 1897 buddy = (PurpleBuddy *) node; |
1898 gc = purple_account_get_connection(buddy->account); | 1898 gc = purple_account_get_connection(purple_buddy_get_account(buddy)); |
1899 js = gc->proto_data; | 1899 js = purple_connection_get_protocol_data(gc); |
1900 | 1900 |
1901 jabber_presence_subscription_set(js, buddy->name, "subscribe"); | 1901 jabber_presence_subscription_set(js, purple_buddy_get_name(buddy), "subscribe"); |
1902 } | 1902 } |
1903 | 1903 |
1904 | 1904 |
1905 static void jabber_buddy_unsubscribe(PurpleBlistNode *node, gpointer data) | 1905 static void jabber_buddy_unsubscribe(PurpleBlistNode *node, gpointer data) |
1906 { | 1906 { |
1909 JabberStream *js; | 1909 JabberStream *js; |
1910 | 1910 |
1911 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); | 1911 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
1912 | 1912 |
1913 buddy = (PurpleBuddy *) node; | 1913 buddy = (PurpleBuddy *) node; |
1914 gc = purple_account_get_connection(buddy->account); | 1914 gc = purple_account_get_connection(purple_buddy_get_account(buddy)); |
1915 js = gc->proto_data; | 1915 js = purple_connection_get_protocol_data(gc); |
1916 | 1916 |
1917 jabber_presence_subscription_set(js, buddy->name, "unsubscribe"); | 1917 jabber_presence_subscription_set(js, purple_buddy_get_name(buddy), "unsubscribe"); |
1918 } | 1918 } |
1919 | 1919 |
1920 static void jabber_buddy_login(PurpleBlistNode *node, gpointer data) { | 1920 static void jabber_buddy_login(PurpleBlistNode *node, gpointer data) { |
1921 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { | 1921 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
1922 /* simply create a directed presence of the current status */ | 1922 /* simply create a directed presence of the current status */ |
1923 PurpleBuddy *buddy = (PurpleBuddy *) node; | 1923 PurpleBuddy *buddy = (PurpleBuddy *) node; |
1924 PurpleConnection *gc = purple_account_get_connection(buddy->account); | 1924 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(buddy)); |
1925 JabberStream *js = gc->proto_data; | 1925 JabberStream *js = purple_connection_get_protocol_data(gc); |
1926 PurpleAccount *account = purple_connection_get_account(gc); | 1926 PurpleAccount *account = purple_connection_get_account(gc); |
1927 PurplePresence *gpresence = purple_account_get_presence(account); | 1927 PurplePresence *gpresence = purple_account_get_presence(account); |
1928 PurpleStatus *status = purple_presence_get_active_status(gpresence); | 1928 PurpleStatus *status = purple_presence_get_active_status(gpresence); |
1929 xmlnode *presence; | 1929 xmlnode *presence; |
1930 JabberBuddyState state; | 1930 JabberBuddyState state; |
1934 purple_status_to_jabber(status, &state, &msg, &priority); | 1934 purple_status_to_jabber(status, &state, &msg, &priority); |
1935 presence = jabber_presence_create_js(js, state, msg, priority); | 1935 presence = jabber_presence_create_js(js, state, msg, priority); |
1936 | 1936 |
1937 g_free(msg); | 1937 g_free(msg); |
1938 | 1938 |
1939 xmlnode_set_attrib(presence, "to", buddy->name); | 1939 xmlnode_set_attrib(presence, "to", purple_buddy_get_name(buddy)); |
1940 | 1940 |
1941 jabber_send(js, presence); | 1941 jabber_send(js, presence); |
1942 xmlnode_free(presence); | 1942 xmlnode_free(presence); |
1943 } | 1943 } |
1944 } | 1944 } |
1945 | 1945 |
1946 static void jabber_buddy_logout(PurpleBlistNode *node, gpointer data) { | 1946 static void jabber_buddy_logout(PurpleBlistNode *node, gpointer data) { |
1947 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { | 1947 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
1948 /* simply create a directed unavailable presence */ | 1948 /* simply create a directed unavailable presence */ |
1949 PurpleBuddy *buddy = (PurpleBuddy *) node; | 1949 PurpleBuddy *buddy = (PurpleBuddy *) node; |
1950 JabberStream *js = purple_account_get_connection(buddy->account)->proto_data; | 1950 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(buddy)); |
1951 JabberStream *js = purple_connection_get_protocol_data(gc); | |
1951 xmlnode *presence; | 1952 xmlnode *presence; |
1952 | 1953 |
1953 presence = jabber_presence_create_js(js, JABBER_BUDDY_STATE_UNAVAILABLE, NULL, 0); | 1954 presence = jabber_presence_create_js(js, JABBER_BUDDY_STATE_UNAVAILABLE, NULL, 0); |
1954 | 1955 |
1955 xmlnode_set_attrib(presence, "to", buddy->name); | 1956 xmlnode_set_attrib(presence, "to", purple_buddy_get_name(buddy)); |
1956 | 1957 |
1957 jabber_send(js, presence); | 1958 jabber_send(js, presence); |
1958 xmlnode_free(presence); | 1959 xmlnode_free(presence); |
1959 } | 1960 } |
1960 } | 1961 } |
1961 | 1962 |
1962 static GList *jabber_buddy_menu(PurpleBuddy *buddy) | 1963 static GList *jabber_buddy_menu(PurpleBuddy *buddy) |
1963 { | 1964 { |
1964 PurpleConnection *gc = purple_account_get_connection(buddy->account); | 1965 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(buddy)); |
1965 JabberStream *js = gc->proto_data; | 1966 JabberStream *js = purple_connection_get_protocol_data(gc); |
1966 JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE); | 1967 const char *name = purple_buddy_get_name(buddy); |
1968 JabberBuddy *jb = jabber_buddy_find(js, name, TRUE); | |
1967 GList *jbrs; | 1969 GList *jbrs; |
1968 | 1970 |
1969 GList *m = NULL; | 1971 GList *m = NULL; |
1970 PurpleMenuAction *act; | 1972 PurpleMenuAction *act; |
1971 | 1973 |
2016 * According to stpeter, there is no way to know if a jid on the roster is a gateway without sending a disco#info. | 2018 * According to stpeter, there is no way to know if a jid on the roster is a gateway without sending a disco#info. |
2017 * However, since the gateway might appear offline to us, we cannot get that information. Therefore, I just assume | 2019 * However, since the gateway might appear offline to us, we cannot get that information. Therefore, I just assume |
2018 * that gateways on the roster can be identified by having no '@' in their jid. This is a faily safe assumption, since | 2020 * that gateways on the roster can be identified by having no '@' in their jid. This is a faily safe assumption, since |
2019 * people don't tend to have a server or other service there. | 2021 * people don't tend to have a server or other service there. |
2020 */ | 2022 */ |
2021 if (g_utf8_strchr(buddy->name, -1, '@') == NULL) { | 2023 if (g_utf8_strchr(name, -1, '@') == NULL) { |
2022 act = purple_menu_action_new(_("Log In"), | 2024 act = purple_menu_action_new(_("Log In"), |
2023 PURPLE_CALLBACK(jabber_buddy_login), | 2025 PURPLE_CALLBACK(jabber_buddy_login), |
2024 NULL, NULL); | 2026 NULL, NULL); |
2025 m = g_list_append(m, act); | 2027 m = g_list_append(m, act); |
2026 act = purple_menu_action_new(_("Log Out"), | 2028 act = purple_menu_action_new(_("Log Out"), |
2484 } | 2486 } |
2485 | 2487 |
2486 void jabber_user_search_begin(PurplePluginAction *action) | 2488 void jabber_user_search_begin(PurplePluginAction *action) |
2487 { | 2489 { |
2488 PurpleConnection *gc = (PurpleConnection *) action->context; | 2490 PurpleConnection *gc = (PurpleConnection *) action->context; |
2489 JabberStream *js = gc->proto_data; | 2491 JabberStream *js = purple_connection_get_protocol_data(gc); |
2490 | 2492 |
2491 purple_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"), | 2493 purple_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"), |
2492 _("Select a user directory to search"), | 2494 _("Select a user directory to search"), |
2493 js->user_directories ? js->user_directories->data : NULL, | 2495 js->user_directories ? js->user_directories->data : NULL, |
2494 FALSE, FALSE, NULL, | 2496 FALSE, FALSE, NULL, |