libpurple/protocols/jabber/pep.c

Sun, 15 Sep 2019 17:11:46 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sun, 15 Sep 2019 17:11:46 -0400
changeset 39894
7eab91ea30a1
parent 34935
686fa55b0deb
child 40439
e9838d634d5e
permissions
-rw-r--r--

Replace Purple type macros by GObject macros.

These were necessary to support both static and dynamic plugins, but
we're just leaving the to GPlugin now.

17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
1 /*
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
2 * purple - Jabber Protocol Plugin
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
3 *
28322
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28321
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28321
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28321
diff changeset
6 * source distribution.
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
7 *
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
11 * (at your option) any later version.
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
12 *
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
16 * GNU General Public License for more details.
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
17 *
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
28321
c8d617c408ab Update various header copyrights thanks to licensecheck.
Paul Aurich <darkrain42@pidgin.im>
parents: 27028
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
21 *
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
22 */
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
23
19898
218e4bb04853 Fix mingw build of xmpp prpl
Daniel Atallah <datallah@pidgin.im>
parents: 17809
diff changeset
24 #include "internal.h"
218e4bb04853 Fix mingw build of xmpp prpl
Daniel Atallah <datallah@pidgin.im>
parents: 17809
diff changeset
25
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
26 #include "pep.h"
17772
918f65155a08 Implemented publishing events
Andreas Monitzer <am@adiumx.com>
parents: 17768
diff changeset
27 #include "iq.h"
17773
6956b763b3d1 Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents: 17772
diff changeset
28 #include <string.h>
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents: 24818
diff changeset
29 #include "useravatar.h"
17793
ff1053411f5a Removed a stale include
Andreas Monitzer <am@adiumx.com>
parents: 17789
diff changeset
30 #include "usermood.h"
17803
882abe4d932e Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <am@adiumx.com>
parents: 17793
diff changeset
31 #include "usernick.h"
24737
b8a96a07e7ac Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <darkrain42@pidgin.im>
parents: 23586
diff changeset
32 #include "usertune.h"
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
33
17773
6956b763b3d1 Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents: 17772
diff changeset
34 static GHashTable *pep_handlers = NULL;
6956b763b3d1 Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents: 17772
diff changeset
35
6956b763b3d1 Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents: 17772
diff changeset
36 void jabber_pep_init(void) {
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
37 if(!pep_handlers) {
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
38 pep_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
39
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
40 /* register PEP handlers */
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents: 24818
diff changeset
41 jabber_avatar_init();
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
42 jabber_mood_init();
24737
b8a96a07e7ac Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <darkrain42@pidgin.im>
parents: 23586
diff changeset
43 jabber_tune_init();
17803
882abe4d932e Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <am@adiumx.com>
parents: 17793
diff changeset
44 jabber_nick_init();
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
45 }
17773
6956b763b3d1 Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents: 17772
diff changeset
46 }
6956b763b3d1 Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents: 17772
diff changeset
47
24737
b8a96a07e7ac Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <darkrain42@pidgin.im>
parents: 23586
diff changeset
48 void jabber_pep_uninit(void) {
27028
1a2ef7ddb463 Clean up jabber prpl memory allocations on uninit.
Nick Hebner <hebnern@gmail.com>
parents: 27016
diff changeset
49 /* any PEP handlers that need to clean things up go here. The standard
1a2ef7ddb463 Clean up jabber prpl memory allocations on uninit.
Nick Hebner <hebnern@gmail.com>
parents: 27016
diff changeset
50 * cleanup of removing the handler and feature are handled here and by
1a2ef7ddb463 Clean up jabber prpl memory allocations on uninit.
Nick Hebner <hebnern@gmail.com>
parents: 27016
diff changeset
51 * jabber_features_destroy() in jabber.c
1a2ef7ddb463 Clean up jabber prpl memory allocations on uninit.
Nick Hebner <hebnern@gmail.com>
parents: 27016
diff changeset
52 */
24737
b8a96a07e7ac Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <darkrain42@pidgin.im>
parents: 23586
diff changeset
53 g_hash_table_destroy(pep_handlers);
b8a96a07e7ac Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <darkrain42@pidgin.im>
parents: 23586
diff changeset
54 pep_handlers = NULL;
b8a96a07e7ac Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <darkrain42@pidgin.im>
parents: 23586
diff changeset
55 }
b8a96a07e7ac Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <darkrain42@pidgin.im>
parents: 23586
diff changeset
56
17782
83af68644d0a Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents: 17780
diff changeset
57 void jabber_pep_init_actions(GList **m) {
83af68644d0a Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents: 17780
diff changeset
58 /* register the PEP-specific actions */
17803
882abe4d932e Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <am@adiumx.com>
parents: 17793
diff changeset
59 jabber_nick_init_action(m);
17782
83af68644d0a Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents: 17780
diff changeset
60 }
83af68644d0a Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents: 17780
diff changeset
61
23586
e495a4623f76 Removing short-names for features and calculating own caps hash.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 19899
diff changeset
62 void jabber_pep_register_handler(const char *xmlns, JabberPEPHandler handlerfunc) {
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
63 gchar *notifyns = g_strdup_printf("%s+notify", xmlns);
23586
e495a4623f76 Removing short-names for features and calculating own caps hash.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 19899
diff changeset
64 jabber_add_feature(notifyns, NULL); /* receiving PEPs is always supported */
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
65 g_free(notifyns);
17773
6956b763b3d1 Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents: 17772
diff changeset
66 g_hash_table_replace(pep_handlers, g_strdup(xmlns), handlerfunc);
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
67 }
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
68
26687
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26042
diff changeset
69 static void
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26042
diff changeset
70 do_pep_iq_request_item_callback(JabberStream *js, const char *from,
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26042
diff changeset
71 JabberIqType type, const char *id,
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
72 PurpleXmlNode *packet, gpointer data)
26687
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26042
diff changeset
73 {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
74 PurpleXmlNode *pubsub;
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
75 PurpleXmlNode *items = NULL;
17788
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
76 JabberPEPHandler *cb = data;
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
77
27016
1e21b1e058c0 On errors, don't pretend we did fetch something, pass NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 26958
diff changeset
78 if (type == JABBER_IQ_RESULT) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
79 pubsub = purple_xmlnode_get_child_with_namespace(packet, "pubsub", "http://jabber.org/protocol/pubsub");
27016
1e21b1e058c0 On errors, don't pretend we did fetch something, pass NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 26958
diff changeset
80 if(pubsub)
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
81 items = purple_xmlnode_get_child(pubsub, "items");
27016
1e21b1e058c0 On errors, don't pretend we did fetch something, pass NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 26958
diff changeset
82 }
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
83
17789
f75d542850e3 Turns out the example in XEP-0084 is wrong. Fixed my implementation to not try to work around an issue that isn't one.
Andreas Monitzer <am@adiumx.com>
parents: 17788
diff changeset
84 cb(js, from, items);
17788
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
85 }
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
86
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
87 void jabber_pep_request_item(JabberStream *js, const char *to, const char *node, const char *id, JabberPEPHandler cb) {
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
88 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET);
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
89 PurpleXmlNode *pubsub, *items;
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
90
29782
ca4fedd9e890 jabber: Allow jabber_pep_request_item() to take NULL for JID; server's routing takes care of the rest
Paul Aurich <darkrain42@pidgin.im>
parents: 28884
diff changeset
91 if (to)
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
92 purple_xmlnode_set_attrib(iq->node, "to", to);
29782
ca4fedd9e890 jabber: Allow jabber_pep_request_item() to take NULL for JID; server's routing takes care of the rest
Paul Aurich <darkrain42@pidgin.im>
parents: 28884
diff changeset
93
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
94 pubsub = purple_xmlnode_new_child(iq->node,"pubsub");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
95 purple_xmlnode_set_namespace(pubsub, "http://jabber.org/protocol/pubsub");
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
96
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
97 items = purple_xmlnode_new_child(pubsub, "items");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
98 purple_xmlnode_set_attrib(items,"node",node);
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
99
28884
aa4c9e6ef61c jabber: Properly request just the most recent item from a PEP node.
Paul Aurich <darkrain42@pidgin.im>
parents: 28322
diff changeset
100 if (id) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
101 PurpleXmlNode *item = purple_xmlnode_new_child(items, "item");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
102 purple_xmlnode_set_attrib(item, "id", id);
28884
aa4c9e6ef61c jabber: Properly request just the most recent item from a PEP node.
Paul Aurich <darkrain42@pidgin.im>
parents: 28322
diff changeset
103 } else
aa4c9e6ef61c jabber: Properly request just the most recent item from a PEP node.
Paul Aurich <darkrain42@pidgin.im>
parents: 28322
diff changeset
104 /* Most recent item */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
105 purple_xmlnode_set_attrib(items, "max_items", "1");
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
106
17788
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
107 jabber_iq_set_callback(iq,do_pep_iq_request_item_callback,(gpointer)cb);
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
108
17788
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
109 jabber_iq_send(iq);
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
110 }
e6e381b0c7d6 Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents: 17787
diff changeset
111
23586
e495a4623f76 Removing short-names for features and calculating own caps hash.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 19899
diff changeset
112 gboolean jabber_pep_namespace_only_when_pep_enabled_cb(JabberStream *js, const gchar *namespace) {
17787
439329d20337 Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents: 17783
diff changeset
113 return js->pep;
439329d20337 Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents: 17783
diff changeset
114 }
439329d20337 Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents: 17783
diff changeset
115
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
116 void jabber_handle_event(JabberMessage *jm) {
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
117 /* this may be called even when the own server doesn't support pep! */
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
118 JabberPEPHandler *jph;
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
119 GList *itemslist;
26957
36f75a1d52a6 Don't try to process PEP events if it's not <message type='event'/>
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
120 char *jid;
36f75a1d52a6 Don't try to process PEP events if it's not <message type='event'/>
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
121
36f75a1d52a6 Don't try to process PEP events if it's not <message type='event'/>
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
122 if (jm->type != JABBER_MESSAGE_EVENT)
36f75a1d52a6 Don't try to process PEP events if it's not <message type='event'/>
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
123 return;
36f75a1d52a6 Don't try to process PEP events if it's not <message type='event'/>
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
124
36f75a1d52a6 Don't try to process PEP events if it's not <message type='event'/>
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
125 jid = jabber_get_bare_jid(jm->from);
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
126
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
127 for(itemslist = jm->eventitems; itemslist; itemslist = itemslist->next) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
128 PurpleXmlNode *items = (PurpleXmlNode*)itemslist->data;
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
129 const char *nodename = purple_xmlnode_get_attrib(items,"node");
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
130
17780
749862fd4a87 Fixed a few small mistakes I discovered while testing user mood in Adium.
Andreas Monitzer <am@adiumx.com>
parents: 17779
diff changeset
131 if(nodename && (jph = g_hash_table_lookup(pep_handlers, nodename)))
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
132 jph(jm->js, jid, items);
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
133 }
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24818
diff changeset
134
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
135 /* discard items we don't have a handler for */
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
136 g_free(jid);
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
137 }
17772
918f65155a08 Implemented publishing events
Andreas Monitzer <am@adiumx.com>
parents: 17768
diff changeset
138
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
139 void jabber_pep_delete_node(JabberStream *js, const gchar *node)
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
140 {
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
141 JabberIq *iq;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
142 PurpleXmlNode *pubsub, *del;
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
143
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
144 g_return_if_fail(node != NULL);
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
145 g_return_if_fail(js->pep);
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
146
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
147 iq = jabber_iq_new(js, JABBER_IQ_SET);
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
148
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
149 pubsub = purple_xmlnode_new_child(iq->node, "pubsub");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
150 purple_xmlnode_set_namespace(pubsub, "http://jabber.org/protocol/pubsub#owner");
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
151
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
152 del = purple_xmlnode_new_child(pubsub, "delete");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
153 purple_xmlnode_set_attrib(del, "node", node);
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
154
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
155 jabber_iq_send(iq);
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
156 }
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26941
diff changeset
157
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
158 void jabber_pep_publish(JabberStream *js, PurpleXmlNode *publish) {
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
159 JabberIq *iq;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
160 PurpleXmlNode *pubsub;
19899
483c4f495a6c Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents: 19898
diff changeset
161
17809
f10c83605116 Fixed a leak in the PEP code that leaked PEP nodes when the server doesn't support this XEP.
Andreas Monitzer <am@adiumx.com>
parents: 17803
diff changeset
162 if(js->pep != TRUE) {
f10c83605116 Fixed a leak in the PEP code that leaked PEP nodes when the server doesn't support this XEP.
Andreas Monitzer <am@adiumx.com>
parents: 17803
diff changeset
163 /* ignore when there's no PEP support on the server */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
164 purple_xmlnode_free(publish);
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
165 return;
17809
f10c83605116 Fixed a leak in the PEP code that leaked PEP nodes when the server doesn't support this XEP.
Andreas Monitzer <am@adiumx.com>
parents: 17803
diff changeset
166 }
19899
483c4f495a6c Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents: 19898
diff changeset
167
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
168 iq = jabber_iq_new(js, JABBER_IQ_SET);
19899
483c4f495a6c Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents: 19898
diff changeset
169
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
170 pubsub = purple_xmlnode_new("pubsub");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
171 purple_xmlnode_set_namespace(pubsub, "http://jabber.org/protocol/pubsub");
19899
483c4f495a6c Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents: 19898
diff changeset
172
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
173 purple_xmlnode_insert_child(pubsub, publish);
19899
483c4f495a6c Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents: 19898
diff changeset
174
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 29825
diff changeset
175 purple_xmlnode_insert_child(iq->node, pubsub);
19899
483c4f495a6c Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents: 19898
diff changeset
176
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17775
diff changeset
177 jabber_iq_send(iq);
17772
918f65155a08 Implemented publishing events
Andreas Monitzer <am@adiumx.com>
parents: 17768
diff changeset
178 }

mercurial