jabberd2
2.2.17
Main Page
Data Structures
Files
File List
Globals
sm
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
36
static
mod_ret_t
_pep_in_sess
(
mod_instance_t
mi,
sess_t
sess,
pkt_t
pkt) {
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
54
static
mod_ret_t
_pep_out_sess
(
mod_instance_t
mi,
sess_t
sess,
pkt_t
pkt) {
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,
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
86
ns_PUBSUB
=
sm_register_ns
(mod->
mm
->
sm
,
uri_PUBSUB
);
87
feature_register
(mod->
mm
->
sm
,
uri_PUBSUB
);
88
89
return
0;
90
}
Generated by
1.8.1.1