comparison libpurple/protocols/jabber/buddy.c @ 25877:1260a3fb60f4

propagate from branch 'im.pidgin.pidgin' (head b8d6086aef6b2e65d86e8ce60220ab7f460d5079) to branch 'im.pidgin.pidgin.next.minor' (head c165595260a2efa0ca23704ada46a303e0412e19)
author Richard Laager <rlaager@wiktel.com>
date Fri, 12 Dec 2008 20:03:58 +0000
parents aa1fe87558d8 61e0924de04a
children 94a6eb10c691
comparison
equal deleted inserted replaced
24710:d1d9d085d626 25877:1260a3fb60f4
420 */ 420 */
421 void jabber_set_info(PurpleConnection *gc, const char *info) 421 void jabber_set_info(PurpleConnection *gc, const char *info)
422 { 422 {
423 PurpleStoredImage *img; 423 PurpleStoredImage *img;
424 JabberIq *iq; 424 JabberIq *iq;
425 JabberStream *js = gc->proto_data; 425 JabberStream *js = purple_connection_get_protocol_data(gc);
426 xmlnode *vc_node; 426 xmlnode *vc_node;
427 const struct tag_attr *tag_attr; 427 const struct tag_attr *tag_attr;
428 428
429 /* if we have't grabbed the remote vcard yet, we can't 429 /* if we have't grabbed the remote vcard yet, we can't
430 * assume that what we have here is correct */ 430 * assume that what we have here is correct */
485 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) 485 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img)
486 { 486 {
487 PurplePresence *gpresence; 487 PurplePresence *gpresence;
488 PurpleStatus *status; 488 PurpleStatus *status;
489 489
490 if(((JabberStream*)gc->proto_data)->pep) { 490 if(((JabberStream*)purple_connection_get_protocol_data(gc))->pep) {
491 /* XEP-0084: User Avatars */ 491 /* XEP-0084: User Avatars */
492 if(img) { 492 if(img) {
493 /* 493 /*
494 * TODO: This is pretty gross. The Jabber PRPL really shouldn't 494 * TODO: This is pretty gross. The Jabber PRPL really shouldn't
495 * do voodoo to try to determine the image type, height 495 * do voodoo to try to determine the image type, height
547 base64avatar = purple_base64_encode(purple_imgstore_get_data(img), purple_imgstore_get_size(img)); 547 base64avatar = purple_base64_encode(purple_imgstore_get_data(img), purple_imgstore_get_size(img));
548 xmlnode_insert_data(data,base64avatar,-1); 548 xmlnode_insert_data(data,base64avatar,-1);
549 g_free(base64avatar); 549 g_free(base64avatar);
550 550
551 /* publish the avatar itself */ 551 /* publish the avatar itself */
552 jabber_pep_publish((JabberStream*)gc->proto_data, publish); 552 jabber_pep_publish((JabberStream*)purple_connection_get_protocol_data(gc), publish);
553 553
554 /* next step: publish the metadata */ 554 /* next step: publish the metadata */
555 publish = xmlnode_new("publish"); 555 publish = xmlnode_new("publish");
556 xmlnode_set_attrib(publish,"node",AVATARNAMESPACEMETA); 556 xmlnode_set_attrib(publish,"node",AVATARNAMESPACEMETA);
557 557
573 heightstring = g_strdup_printf("%u", height); 573 heightstring = g_strdup_printf("%u", height);
574 xmlnode_set_attrib(info, "height", heightstring); 574 xmlnode_set_attrib(info, "height", heightstring);
575 g_free(heightstring); 575 g_free(heightstring);
576 576
577 /* publish the metadata */ 577 /* publish the metadata */
578 jabber_pep_publish((JabberStream*)gc->proto_data, publish); 578 jabber_pep_publish((JabberStream*)purple_connection_get_protocol_data(gc), publish);
579 579
580 g_free(hash); 580 g_free(hash);
581 } else { /* if(img) */ 581 } else { /* if(img) */
582 /* remove the metadata */ 582 /* remove the metadata */
583 xmlnode *metadata, *item; 583 xmlnode *metadata, *item;
590 xmlnode_set_namespace(metadata,AVATARNAMESPACEMETA); 590 xmlnode_set_namespace(metadata,AVATARNAMESPACEMETA);
591 591
592 xmlnode_new_child(metadata, "stop"); 592 xmlnode_new_child(metadata, "stop");
593 593
594 /* publish the metadata */ 594 /* publish the metadata */
595 jabber_pep_publish((JabberStream*)gc->proto_data, publish); 595 jabber_pep_publish((JabberStream*)purple_connection_get_protocol_data(gc), publish);
596 } 596 }
597 } else { 597 } else {
598 purple_debug(PURPLE_DEBUG_ERROR, "jabber", 598 purple_debug(PURPLE_DEBUG_ERROR, "jabber",
599 "jabber_set_buddy_icon received non-png data"); 599 "jabber_set_buddy_icon received non-png data");
600 } 600 }
1775 jbi->timeout_handle = purple_timeout_add(30000, jabber_buddy_get_info_timeout, jbi); 1775 jbi->timeout_handle = purple_timeout_add(30000, jabber_buddy_get_info_timeout, jbi);
1776 } 1776 }
1777 1777
1778 void jabber_buddy_get_info(PurpleConnection *gc, const char *who) 1778 void jabber_buddy_get_info(PurpleConnection *gc, const char *who)
1779 { 1779 {
1780 JabberStream *js = gc->proto_data; 1780 JabberStream *js = purple_connection_get_protocol_data(gc);
1781 JabberID *jid = jabber_id_new(who); 1781 JabberID *jid = jabber_id_new(who);
1782 1782
1783 if (!jid) 1783 if (!jid)
1784 return; 1784 return;
1785 1785
1835 JabberStream *js; 1835 JabberStream *js;
1836 1836
1837 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); 1837 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1838 1838
1839 buddy = (PurpleBuddy *) node; 1839 buddy = (PurpleBuddy *) node;
1840 gc = purple_account_get_connection(buddy->account); 1840 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1841 js = gc->proto_data; 1841 js = purple_connection_get_protocol_data(gc);
1842 1842
1843 jabber_buddy_set_invisibility(js, buddy->name, TRUE); 1843 jabber_buddy_set_invisibility(js, purple_buddy_get_name(buddy), TRUE);
1844 } 1844 }
1845 1845
1846 static void jabber_buddy_make_visible(PurpleBlistNode *node, gpointer data) 1846 static void jabber_buddy_make_visible(PurpleBlistNode *node, gpointer data)
1847 { 1847 {
1848 PurpleBuddy *buddy; 1848 PurpleBuddy *buddy;
1850 JabberStream *js; 1850 JabberStream *js;
1851 1851
1852 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); 1852 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1853 1853
1854 buddy = (PurpleBuddy *) node; 1854 buddy = (PurpleBuddy *) node;
1855 gc = purple_account_get_connection(buddy->account); 1855 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1856 js = gc->proto_data; 1856 js = purple_connection_get_protocol_data(gc);
1857 1857
1858 jabber_buddy_set_invisibility(js, buddy->name, FALSE); 1858 jabber_buddy_set_invisibility(js, purple_buddy_get_name(buddy), FALSE);
1859 } 1859 }
1860 1860
1861 static void jabber_buddy_cancel_presence_notification(PurpleBlistNode *node, 1861 static void jabber_buddy_cancel_presence_notification(PurpleBlistNode *node,
1862 gpointer data) 1862 gpointer data)
1863 { 1863 {
1866 JabberStream *js; 1866 JabberStream *js;
1867 1867
1868 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); 1868 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1869 1869
1870 buddy = (PurpleBuddy *) node; 1870 buddy = (PurpleBuddy *) node;
1871 gc = purple_account_get_connection(buddy->account); 1871 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1872 js = gc->proto_data; 1872 js = purple_connection_get_protocol_data(gc);
1873 1873
1874 /* I wonder if we should prompt the user before doing this */ 1874 /* I wonder if we should prompt the user before doing this */
1875 jabber_presence_subscription_set(js, buddy->name, "unsubscribed"); 1875 jabber_presence_subscription_set(js, purple_buddy_get_name(buddy), "unsubscribed");
1876 } 1876 }
1877 1877
1878 static void jabber_buddy_rerequest_auth(PurpleBlistNode *node, gpointer data) 1878 static void jabber_buddy_rerequest_auth(PurpleBlistNode *node, gpointer data)
1879 { 1879 {
1880 PurpleBuddy *buddy; 1880 PurpleBuddy *buddy;
1882 JabberStream *js; 1882 JabberStream *js;
1883 1883
1884 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); 1884 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1885 1885
1886 buddy = (PurpleBuddy *) node; 1886 buddy = (PurpleBuddy *) node;
1887 gc = purple_account_get_connection(buddy->account); 1887 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1888 js = gc->proto_data; 1888 js = purple_connection_get_protocol_data(gc);
1889 1889
1890 jabber_presence_subscription_set(js, buddy->name, "subscribe"); 1890 jabber_presence_subscription_set(js, purple_buddy_get_name(buddy), "subscribe");
1891 } 1891 }
1892 1892
1893 1893
1894 static void jabber_buddy_unsubscribe(PurpleBlistNode *node, gpointer data) 1894 static void jabber_buddy_unsubscribe(PurpleBlistNode *node, gpointer data)
1895 { 1895 {
1898 JabberStream *js; 1898 JabberStream *js;
1899 1899
1900 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); 1900 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1901 1901
1902 buddy = (PurpleBuddy *) node; 1902 buddy = (PurpleBuddy *) node;
1903 gc = purple_account_get_connection(buddy->account); 1903 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1904 js = gc->proto_data; 1904 js = purple_connection_get_protocol_data(gc);
1905 1905
1906 jabber_presence_subscription_set(js, buddy->name, "unsubscribe"); 1906 jabber_presence_subscription_set(js, purple_buddy_get_name(buddy), "unsubscribe");
1907 } 1907 }
1908 1908
1909 static void jabber_buddy_login(PurpleBlistNode *node, gpointer data) { 1909 static void jabber_buddy_login(PurpleBlistNode *node, gpointer data) {
1910 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { 1910 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
1911 /* simply create a directed presence of the current status */ 1911 /* simply create a directed presence of the current status */
1912 PurpleBuddy *buddy = (PurpleBuddy *) node; 1912 PurpleBuddy *buddy = (PurpleBuddy *) node;
1913 PurpleConnection *gc = purple_account_get_connection(buddy->account); 1913 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1914 JabberStream *js = gc->proto_data; 1914 JabberStream *js = purple_connection_get_protocol_data(gc);
1915 PurpleAccount *account = purple_connection_get_account(gc); 1915 PurpleAccount *account = purple_connection_get_account(gc);
1916 PurplePresence *gpresence = purple_account_get_presence(account); 1916 PurplePresence *gpresence = purple_account_get_presence(account);
1917 PurpleStatus *status = purple_presence_get_active_status(gpresence); 1917 PurpleStatus *status = purple_presence_get_active_status(gpresence);
1918 xmlnode *presence; 1918 xmlnode *presence;
1919 JabberBuddyState state; 1919 JabberBuddyState state;
1923 purple_status_to_jabber(status, &state, &msg, &priority); 1923 purple_status_to_jabber(status, &state, &msg, &priority);
1924 presence = jabber_presence_create_js(js, state, msg, priority); 1924 presence = jabber_presence_create_js(js, state, msg, priority);
1925 1925
1926 g_free(msg); 1926 g_free(msg);
1927 1927
1928 xmlnode_set_attrib(presence, "to", buddy->name); 1928 xmlnode_set_attrib(presence, "to", purple_buddy_get_name(buddy));
1929 1929
1930 jabber_send(js, presence); 1930 jabber_send(js, presence);
1931 xmlnode_free(presence); 1931 xmlnode_free(presence);
1932 } 1932 }
1933 } 1933 }
1934 1934
1935 static void jabber_buddy_logout(PurpleBlistNode *node, gpointer data) { 1935 static void jabber_buddy_logout(PurpleBlistNode *node, gpointer data) {
1936 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { 1936 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
1937 /* simply create a directed unavailable presence */ 1937 /* simply create a directed unavailable presence */
1938 PurpleBuddy *buddy = (PurpleBuddy *) node; 1938 PurpleBuddy *buddy = (PurpleBuddy *) node;
1939 JabberStream *js = purple_account_get_connection(buddy->account)->proto_data; 1939 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1940 JabberStream *js = purple_connection_get_protocol_data(gc);
1940 xmlnode *presence; 1941 xmlnode *presence;
1941 1942
1942 presence = jabber_presence_create_js(js, JABBER_BUDDY_STATE_UNAVAILABLE, NULL, 0); 1943 presence = jabber_presence_create_js(js, JABBER_BUDDY_STATE_UNAVAILABLE, NULL, 0);
1943 1944
1944 xmlnode_set_attrib(presence, "to", buddy->name); 1945 xmlnode_set_attrib(presence, "to", purple_buddy_get_name(buddy));
1945 1946
1946 jabber_send(js, presence); 1947 jabber_send(js, presence);
1947 xmlnode_free(presence); 1948 xmlnode_free(presence);
1948 } 1949 }
1949 } 1950 }
1950 1951
1951 static GList *jabber_buddy_menu(PurpleBuddy *buddy) 1952 static GList *jabber_buddy_menu(PurpleBuddy *buddy)
1952 { 1953 {
1953 PurpleConnection *gc = purple_account_get_connection(buddy->account); 1954 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1954 JabberStream *js = gc->proto_data; 1955 JabberStream *js = purple_connection_get_protocol_data(gc);
1955 JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE); 1956 const char *name = purple_buddy_get_name(buddy);
1957 JabberBuddy *jb = jabber_buddy_find(js, name, TRUE);
1956 GList *jbrs; 1958 GList *jbrs;
1957 1959
1958 GList *m = NULL; 1960 GList *m = NULL;
1959 PurpleMenuAction *act; 1961 PurpleMenuAction *act;
1960 1962
2005 * According to stpeter, there is no way to know if a jid on the roster is a gateway without sending a disco#info. 2007 * According to stpeter, there is no way to know if a jid on the roster is a gateway without sending a disco#info.
2006 * However, since the gateway might appear offline to us, we cannot get that information. Therefore, I just assume 2008 * However, since the gateway might appear offline to us, we cannot get that information. Therefore, I just assume
2007 * that gateways on the roster can be identified by having no '@' in their jid. This is a faily safe assumption, since 2009 * that gateways on the roster can be identified by having no '@' in their jid. This is a faily safe assumption, since
2008 * people don't tend to have a server or other service there. 2010 * people don't tend to have a server or other service there.
2009 */ 2011 */
2010 if (g_utf8_strchr(buddy->name, -1, '@') == NULL) { 2012 if (g_utf8_strchr(name, -1, '@') == NULL) {
2011 act = purple_menu_action_new(_("Log In"), 2013 act = purple_menu_action_new(_("Log In"),
2012 PURPLE_CALLBACK(jabber_buddy_login), 2014 PURPLE_CALLBACK(jabber_buddy_login),
2013 NULL, NULL); 2015 NULL, NULL);
2014 m = g_list_append(m, act); 2016 m = g_list_append(m, act);
2015 act = purple_menu_action_new(_("Log Out"), 2017 act = purple_menu_action_new(_("Log Out"),
2473 } 2475 }
2474 2476
2475 void jabber_user_search_begin(PurplePluginAction *action) 2477 void jabber_user_search_begin(PurplePluginAction *action)
2476 { 2478 {
2477 PurpleConnection *gc = (PurpleConnection *) action->context; 2479 PurpleConnection *gc = (PurpleConnection *) action->context;
2478 JabberStream *js = gc->proto_data; 2480 JabberStream *js = purple_connection_get_protocol_data(gc);
2479 2481
2480 purple_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"), 2482 purple_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"),
2481 _("Select a user directory to search"), 2483 _("Select a user directory to search"),
2482 js->user_directories ? js->user_directories->data : NULL, 2484 js->user_directories ? js->user_directories->data : NULL,
2483 FALSE, FALSE, NULL, 2485 FALSE, FALSE, NULL,