Mercurial > pidgin
annotate libpurple/protocols/jabber/pep.c @ 17845:2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
author | Andreas Monitzer <pidgin@monitzer.com> |
---|---|
date | Tue, 12 Jun 2007 01:25:46 +0000 |
parents | df5bb342b10e |
children | 2f067d8fb19a |
rev | line source |
---|---|
17834
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
1 /* |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
2 * purple - Jabber Protocol Plugin |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
3 * |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
4 * Copyright (C) 2007, Andreas Monitzer <andy@monitzer.com> |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
5 * |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
9 * (at your option) any later version. |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
10 * |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17845
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17834
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
15 * |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
17 * along with this program; if not, write to the Free Software |
17845
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17834
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
19 * |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
20 */ |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
21 |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
22 #include "pep.h" |
17838
2f67cb504a51
Implemented publishing events
Andreas Monitzer <pidgin@monitzer.com>
parents:
17834
diff
changeset
|
23 #include "iq.h" |
17839
0370da969e8a
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <pidgin@monitzer.com>
parents:
17838
diff
changeset
|
24 #include <string.h> |
17834
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
25 |
17839
0370da969e8a
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <pidgin@monitzer.com>
parents:
17838
diff
changeset
|
26 static GHashTable *pep_handlers = NULL; |
0370da969e8a
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <pidgin@monitzer.com>
parents:
17838
diff
changeset
|
27 |
0370da969e8a
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <pidgin@monitzer.com>
parents:
17838
diff
changeset
|
28 void jabber_pep_init(void) { |
17845
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
29 if(!pep_handlers) { |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
30 pep_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
31 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
32 /* register PEP handlers */ |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
33 jabber_mood_init(); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
34 } |
17839
0370da969e8a
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <pidgin@monitzer.com>
parents:
17838
diff
changeset
|
35 } |
0370da969e8a
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <pidgin@monitzer.com>
parents:
17838
diff
changeset
|
36 |
0370da969e8a
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <pidgin@monitzer.com>
parents:
17838
diff
changeset
|
37 void jabber_pep_register_handler(const char *shortname, const char *xmlns, JabberPEPHandler handlerfunc) { |
17845
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
38 gchar *notifyns = g_strdup_printf("%s+notify", xmlns); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
39 jabber_add_feature(shortname, notifyns); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
40 g_free(notifyns); |
17839
0370da969e8a
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <pidgin@monitzer.com>
parents:
17838
diff
changeset
|
41 g_hash_table_replace(pep_handlers, g_strdup(xmlns), handlerfunc); |
17834
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
42 } |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
43 |
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
44 void jabber_handle_event(JabberMessage *jm) { |
17845
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
45 /* this may be called even when the own server doesn't support pep! */ |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
46 JabberPEPHandler *jph; |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
47 GList *itemslist; |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
48 char *jid = jabber_get_bare_jid(jm->from); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
49 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
50 for(itemslist = jm->eventitems; itemslist; itemslist = itemslist->next) { |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
51 xmlnode *items = (xmlnode*)itemslist->data; |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
52 const char *xmlns = xmlnode_get_namespace(items); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
53 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
54 if((jph = g_hash_table_lookup(pep_handlers, xmlns))) |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
55 jph(jm->js, jid, items); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
56 } |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
57 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
58 /* discard items we don't have a handler for */ |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
59 g_free(jid); |
17834
a75079eae085
added preliminary frame for pep-support
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
60 } |
17838
2f67cb504a51
Implemented publishing events
Andreas Monitzer <pidgin@monitzer.com>
parents:
17834
diff
changeset
|
61 |
2f67cb504a51
Implemented publishing events
Andreas Monitzer <pidgin@monitzer.com>
parents:
17834
diff
changeset
|
62 void jabber_pep_publish(JabberStream *js, xmlnode *publish) { |
17845
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
63 JabberIq *iq; |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
64 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
65 if(js->pep != TRUE) /* ignore when there's no PEP support on the server */ |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
66 return; |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
67 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
68 iq = jabber_iq_new(js, JABBER_IQ_SET); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
69 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
70 xmlnode *pubsub = xmlnode_new("pubsub"); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
71 xmlnode_set_namespace(pubsub, "http://jabber.org/protocol/pubsub"); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
72 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
73 xmlnode_insert_child(pubsub, publish); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
74 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
75 xmlnode_insert_child(iq->node, pubsub); |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
76 |
2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents:
17841
diff
changeset
|
77 jabber_iq_send(iq); |
17838
2f67cb504a51
Implemented publishing events
Andreas Monitzer <pidgin@monitzer.com>
parents:
17834
diff
changeset
|
78 } |