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 mod_ret_t _echo_pkt_sm(mod_instance_t mi, pkt_t pkt) 00031 { 00032 jid_t jid; 00033 char *resource = (char *) mi->mod->private; 00034 00035 /* answer to probes and subscription requests */ 00036 if(pkt->type == pkt_PRESENCE_PROBE || pkt->type == pkt_S10N) { 00037 log_debug(ZONE, "answering presence probe/sub from %s with /echo resource", jid_full(pkt->from)); 00038 00039 /* send presence */ 00040 jid = jid_new(jid_user(pkt->to), -1); 00041 jid_reset_components(jid, jid->node, jid->domain, resource); 00042 pkt_router(pkt_create(mi->mod->mm->sm, "presence", NULL, jid_user(pkt->from), jid_full(jid))); 00043 jid_free(jid); 00044 } 00045 00046 /* we want messages addressed to /echo */ 00047 if(!(pkt->type & pkt_MESSAGE) || strcmp(pkt->to->resource, "echo") != 0) 00048 return mod_PASS; 00049 00050 log_debug(ZONE, "echo request from %s", jid_full(pkt->from)); 00051 00052 /* swap to and from and return it */ 00053 pkt_router(pkt_tofrom(pkt)); 00054 00055 return mod_HANDLED; 00056 } 00057 00058 DLLEXPORT int module_init(mod_instance_t mi, char *arg) { 00059 module_t mod = mi->mod; 00060 00061 if(mod->init) return 0; 00062 00063 /* store /echo resource for use when answering probes */ 00064 mod->private = "echo"; 00065 00066 mod->pkt_sm = _echo_pkt_sm; 00067 /* data is static so nothing to free */ 00068 /* mod->free = _echo_free; */ 00069 00070 return 0; 00071 }