mirror of
https://github.com/processone/ejabberd.git
synced 2024-10-11 15:08:56 +02:00
4098c3ecba
SVN Revision: 370
48 lines
1.1 KiB
Erlang
48 lines
1.1 KiB
Erlang
%%%----------------------------------------------------------------------
|
|
%%% File : mod_echo.erl
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
|
%%% Purpose :
|
|
%%% Created : 15 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
|
|
%%% Id : $Id$
|
|
%%%----------------------------------------------------------------------
|
|
|
|
-module(mod_echo).
|
|
-author('alexey@sevcom.net').
|
|
-vsn('$Revision$ ').
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
-export([start/2, init/1, stop/1]).
|
|
|
|
-include("ejabberd.hrl").
|
|
-include("jlib.hrl").
|
|
|
|
-define(PROCNAME, ejabberd_mod_echo).
|
|
|
|
start(Host, Opts) ->
|
|
MyHost = gen_mod:get_opt(host, Opts, "echo." ++ Host),
|
|
register(gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
spawn(?MODULE, init, [MyHost])).
|
|
|
|
init(Host) ->
|
|
ejabberd_router:register_route(Host),
|
|
loop(Host).
|
|
|
|
loop(Host) ->
|
|
receive
|
|
{route, From, To, Packet} ->
|
|
ejabberd_router:route(To, From, Packet),
|
|
loop(Host);
|
|
stop ->
|
|
ejabberd_router:unregister_route(Host),
|
|
ok;
|
|
_ ->
|
|
loop(Host)
|
|
end.
|
|
|
|
stop(Host) ->
|
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
Proc ! stop,
|
|
{wait, Proc}.
|
|
|