| 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 | |
|---|
| 23 | /** @file sm/mod_iq_ping.c |
|---|
| 24 | * @brief xmpp ping |
|---|
| 25 | * @author Tomasz Sieprawski |
|---|
| 26 | * $Date: 2007/04/06 xx:xx:xx $ |
|---|
| 27 | * $Revision: 1.0 $ |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #define uri_PING "urn:xmpp:ping" |
|---|
| 31 | static int ns_PING = 0; |
|---|
| 32 | |
|---|
| 33 | static mod_ret_t _iq_ping_pkt_sm(mod_instance_t mi, pkt_t pkt) |
|---|
| 34 | { |
|---|
| 35 | int ns,elem; |
|---|
| 36 | /* we only want to play with iq:pinggets */ |
|---|
| 37 | if(pkt->type != pkt_IQ || pkt->ns != ns_PING) |
|---|
| 38 | return mod_PASS; |
|---|
| 39 | /* remove <ping xmlns='urn:xmpp:ping'/> tag */ |
|---|
| 40 | ns = nad_find_scoped_namespace(pkt->nad, uri_PING, NULL); |
|---|
| 41 | elem = nad_find_elem(pkt->nad, 1, ns, "ping", 1); |
|---|
| 42 | if (elem>=0) /* too much security wont kill */ |
|---|
| 43 | nad_drop_elem(pkt->nad,elem); |
|---|
| 44 | /* tell them */ |
|---|
| 45 | nad_set_attr(pkt->nad, 1, -1, "type", "result", 6); |
|---|
| 46 | pkt_router(pkt_tofrom(pkt)); |
|---|
| 47 | return mod_HANDLED; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | static void _iq_ping_free(module_t mod) { |
|---|
| 51 | sm_unregister_ns(mod->mm->sm, uri_PING); |
|---|
| 52 | feature_unregister(mod->mm->sm, uri_PING); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | DLLEXPORT int module_init(mod_instance_t mi, char *arg) { |
|---|
| 56 | module_t mod = mi->mod; |
|---|
| 57 | |
|---|
| 58 | if(mod->init) return 0; |
|---|
| 59 | |
|---|
| 60 | mod->pkt_sm = _iq_ping_pkt_sm; |
|---|
| 61 | mod->free = _iq_ping_free; |
|---|
| 62 | |
|---|
| 63 | ns_PING = sm_register_ns(mod->mm->sm, uri_PING); |
|---|
| 64 | feature_register(mod->mm->sm, uri_PING); |
|---|
| 65 | |
|---|
| 66 | return 0; |
|---|
| 67 | } |
|---|