jabberd2  2.3.2
mod_pep.c
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2009 Tomasz Sterna
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
18  */
19 
20 #include "sm.h"
21 
22 /*
23  * XEP-0163 is some lunatic nightmare...
24  *
25  * If you want it - YOU implement it!
26  */
27 
33 #define uri_PUBSUB "http://jabber.org/protocol/pubsub"
34 static int ns_PUBSUB = 0;
35 
37  int ns, elem;
38 
39  /* only handle private sets and gets */
40  if((pkt->type != pkt_IQ && pkt->type != pkt_IQ_SET) || pkt->ns != ns_PUBSUB)
41  return mod_PASS;
42 
43  /* we're only interested in no to, to our host, or to us */
44  if(pkt->to != NULL && jid_compare_user(sess->jid, pkt->to) != 0 && strcmp(sess->jid->domain, jid_user(pkt->to)) != 0)
45  return mod_PASS;
46 
47  ns = nad_find_scoped_namespace(pkt->nad, uri_PUBSUB, NULL);
48  elem = nad_find_elem(pkt->nad, 1, ns, "pubsub", 1);
49 
50  log_debug(ZONE, "_pep_in_sess() %d %d", ns, elem);
51  return mod_PASS;
52 }
53 
55  /* add pep identity to disco results from bare JID */
56  if(!(pkt->type & pkt_IQ) || pkt->ns != ns_DISCO_INFO || (pkt->from != NULL && strcmp(jid_user(sess->jid), jid_full(pkt->from))))
57  return mod_PASS;
58 
59  /* add PEP identity */
60  nad_append_elem(pkt->nad, -1, "identity", 3);
61  nad_append_attr(pkt->nad, -1, "category", "pubsub");
62  nad_append_attr(pkt->nad, -1, "type", "pep");
63 
64  nad_append_elem(pkt->nad, -1, "feature", 3);
65  nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#access-presence");
66  nad_append_elem(pkt->nad, -1, "feature", 3);
67  nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#auto-create");
68  nad_append_elem(pkt->nad, -1, "feature", 3);
69  nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#auto-subscribe");
70  nad_append_elem(pkt->nad, -1, "feature", 3);
71  nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#filtered-notifications");
72  nad_append_elem(pkt->nad, -1, "feature", 3);
73  nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#publish");
74 
75  return mod_PASS;
76 }
77 
78 DLLEXPORT int module_init(mod_instance_t mi, const char *arg) {
79  module_t mod = mi->mod;
80 
81  if(mod->init) return 0;
82 
83  mod->in_sess = _pep_in_sess;
84  mod->out_sess = _pep_out_sess;
85 
88 
89  return 0;
90 }
pkt_type_t type
packet type
Definition: sm.h:138
int sm_register_ns(sm_t sm, const char *uri)
register a new global ns
Definition: sm.c:324
jid_t jid
session jid (user@host/res)
Definition: sm.h:257
int nad_append_attr(nad_t nad, int ns, const char *name, const char *val)
attach new attr to the last elem
Definition: nad.c:701
data structures and prototypes for the session manager
#define ns_DISCO_INFO
Definition: sm.h:81
const char * jid_user(jid_t jid)
expand and return the user
Definition: jid.c:339
const char * jid_full(jid_t jid)
expand and return the full
Definition: jid.c:347
single instance of a module in a chain
Definition: sm.h:445
int nad_find_elem(nad_t nad, int elem, int ns, const char *name, int depth)
locate the next elem at a given depth with an optional matching name
Definition: nad.c:204
int init
number of times the module intialiser has been called
Definition: sm.h:415
static mod_ret_t _pep_out_sess(mod_instance_t mi, sess_t sess, pkt_t pkt)
Definition: mod_pep.c:54
info/query (set)
Definition: sm.h:107
int nad_append_elem(nad_t nad, int ns, const char *name, int depth)
create a new elem on the list
Definition: nad.c:667
mm_t mm
module manager
Definition: sm.h:403
#define DLLEXPORT
Definition: c2s.h:47
sm_t sm
sm context
Definition: sm.h:365
static int ns_PUBSUB
Definition: mod_pep.c:34
module_t mod
module that this is an instance of
Definition: sm.h:448
jid_t from
packet addressing (not used for routing)
Definition: sm.h:140
packet summary data wrapper
Definition: sm.h:129
nad_t nad
nad of the entire packet
Definition: sm.h:146
mod_ret_t(* in_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt)
in-sess handler
Definition: sm.h:422
char * domain
Definition: jid.h:45
#define log_debug(...)
Definition: log.h:65
void feature_register(sm_t sm, const char *feature)
register a feature
Definition: feature.c:37
info/query (get)
Definition: sm.h:106
packet was unhandled, should be passed to the next module
Definition: sm.h:339
int ns
iq sub-namespace
Definition: sm.h:142
There is one instance of this struct per user who is logged in to this c2s instance.
Definition: c2s.h:74
int jid_compare_user(jid_t a, jid_t b)
compare the user portion of two jids
Definition: jid.c:355
#define uri_PUBSUB
Definition: mod_pep.c:33
jid_t to
Definition: sm.h:140
mod_ret_t(* out_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt)
out-sess handler
Definition: sm.h:425
#define ZONE
Definition: mio_impl.h:76
data for a single module
Definition: sm.h:402
mod_ret_t
module return values
Definition: sm.h:337
DLLEXPORT int module_init(mod_instance_t mi, const char *arg)
Definition: mod_pep.c:78
static mod_ret_t _pep_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt)
Definition: mod_pep.c:36
int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix)
find a namespace in scope
Definition: nad.c:290