jabberd2  2.3.1
mod_iq_ping.c
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19  */
20 
21 #include "sm.h"
22 
30 static int ns_PING = 0;
31 
32 void _iq_ping_reply(pkt_t pkt) {
33  int ns, elem;
34 
35  ns = nad_find_scoped_namespace(pkt->nad, urn_PING, NULL);
36  elem = nad_find_elem(pkt->nad, 1, ns, "ping", 1);
37  if (elem>=0)
38  nad_drop_elem(pkt->nad, elem);
39 
40  nad_set_attr(pkt->nad, 1, -1, "type", "result", 6);
41 
42  return;
43 }
44 
46  if(pkt->to != NULL || pkt->type != pkt_IQ || pkt->ns != ns_PING)
47  return mod_PASS;
48  _iq_ping_reply(pkt);
49  pkt_sess(pkt, sess);
50  return mod_HANDLED;
51 }
52 
54  if(pkt->type != pkt_IQ || pkt->ns != ns_PING)
55  return mod_PASS;
56  _iq_ping_reply(pkt);
57  pkt_router(pkt_tofrom(pkt));
58  return mod_HANDLED;
59 }
60 
61 static void _iq_ping_free(module_t mod) {
64 }
65 
66 DLLEXPORT int module_init(mod_instance_t mi, const char *arg) {
67  module_t mod = mi->mod;
68 
69  if(mod->init) return 0;
70 
72  mod->pkt_sm = _iq_ping_pkt_sm;
73  mod->free = _iq_ping_free;
74 
77 
78  return 0;
79 }
mod_ret_t(* pkt_sm)(mod_instance_t mi, pkt_t pkt)
pkt-sm handler
Definition: sm.h:428
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
data structures and prototypes for the session manager
void sm_unregister_ns(sm_t sm, const char *uri)
unregister a global ns
Definition: sm.c:338
pkt_t pkt_tofrom(pkt_t pkt)
swap a packet's to and from attributes
Definition: pkt.c:57
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
static int ns_PING
Definition: mod_iq_ping.c:30
int init
number of times the module intialiser has been called
Definition: sm.h:415
void _iq_ping_reply(pkt_t pkt)
Definition: mod_iq_ping.c:32
static mod_ret_t _iq_ping_pkt_sm(mod_instance_t mi, pkt_t pkt)
Definition: mod_iq_ping.c:53
mm_t mm
module manager
Definition: sm.h:403
#define DLLEXPORT
Definition: c2s.h:47
void nad_set_attr(nad_t nad, int elem, int ns, const char *name, const char *val, int vallen)
create, update, or zap any matching attr on this elem
Definition: nad.c:375
sm_t sm
sm context
Definition: sm.h:365
module_t mod
module that this is an instance of
Definition: sm.h:448
void feature_unregister(sm_t sm, const char *feature)
unregister feature
Definition: feature.c:45
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
void pkt_router(pkt_t pkt)
Definition: pkt.c:379
DLLEXPORT int module_init(mod_instance_t mi, const char *arg)
Definition: mod_active.c:70
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
packet was handled (and freed)
Definition: sm.h:338
There is one instance of this struct per user who is logged in to this c2s instance.
Definition: c2s.h:74
void(* free)(module_t mod)
called when module is freed
Definition: sm.h:441
jid_t to
Definition: sm.h:140
void nad_drop_elem(nad_t nad, int elem)
remove an element (and its subelements)
Definition: nad.c:452
static void _iq_ping_free(module_t mod)
Definition: mod_iq_ping.c:61
#define urn_PING
Definition: uri.h:77
data for a single module
Definition: sm.h:402
static mod_ret_t _iq_ping_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt)
Definition: mod_iq_ping.c:45
mod_ret_t
module return values
Definition: sm.h:337
void pkt_sess(pkt_t pkt, sess_t sess)
Definition: pkt.c:459
int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix)
find a namespace in scope
Definition: nad.c:290