jabberd2
2.2.16
|
00001 /* 00002 * jabberd - Jabber Open Source Server 00003 * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 00004 * Ryan Eatmon, Robert Norris 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 00019 */ 00020 00021 #include "sm.h" 00022 00030 static int ns_PING = 0; 00031 00032 void _iq_ping_reply(pkt_t pkt) { 00033 int ns, elem; 00034 00035 ns = nad_find_scoped_namespace(pkt->nad, urn_PING, NULL); 00036 elem = nad_find_elem(pkt->nad, 1, ns, "ping", 1); 00037 if (elem>=0) 00038 nad_drop_elem(pkt->nad, elem); 00039 00040 nad_set_attr(pkt->nad, 1, -1, "type", "result", 6); 00041 00042 return; 00043 } 00044 00045 static mod_ret_t _iq_ping_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) { 00046 if(pkt->to != NULL || pkt->type != pkt_IQ || pkt->ns != ns_PING) 00047 return mod_PASS; 00048 _iq_ping_reply(pkt); 00049 pkt_sess(pkt, sess); 00050 return mod_HANDLED; 00051 } 00052 00053 static mod_ret_t _iq_ping_pkt_sm(mod_instance_t mi, pkt_t pkt) { 00054 if(pkt->type != pkt_IQ || pkt->ns != ns_PING) 00055 return mod_PASS; 00056 _iq_ping_reply(pkt); 00057 pkt_router(pkt_tofrom(pkt)); 00058 return mod_HANDLED; 00059 } 00060 00061 static void _iq_ping_free(module_t mod) { 00062 sm_unregister_ns(mod->mm->sm, urn_PING); 00063 feature_unregister(mod->mm->sm, urn_PING); 00064 } 00065 00066 DLLEXPORT int module_init(mod_instance_t mi, char *arg) { 00067 module_t mod = mi->mod; 00068 00069 if(mod->init) return 0; 00070 00071 mod->in_sess = _iq_ping_in_sess; 00072 mod->pkt_sm = _iq_ping_pkt_sm; 00073 mod->free = _iq_ping_free; 00074 00075 ns_PING = sm_register_ns(mod->mm->sm, urn_PING); 00076 feature_register(mod->mm->sm, urn_PING); 00077 00078 return 0; 00079 }