2009-06-16 19:43:35 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_http_bind.erl
|
|
|
|
%%% Author : Stefan Strigler <steve@zeank.in-berlin.de>
|
|
|
|
%%% Purpose : Implementation of XMPP over BOSH (XEP-0206)
|
|
|
|
%%% Created : Tue Feb 20 13:15:52 CET 2007
|
2009-06-16 19:44:13 +02:00
|
|
|
%%% Id : $Id: $
|
2009-06-16 19:43:35 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% this module acts as a bridge to ejabberd_http_bind which implements
|
|
|
|
%%% the real stuff, this is to handle the new pluggable architecture for
|
|
|
|
%%% extending ejabberd's http service
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_http_bind).
|
|
|
|
-author('steve@zeank.in-berlin.de').
|
|
|
|
|
2009-06-16 19:44:13 +02:00
|
|
|
-define(MOD_HTTP_BIND_VERSION, "1.0").
|
2009-06-16 19:43:35 +02:00
|
|
|
-vsn(?MOD_HTTP_BIND_VERSION).
|
2009-06-16 19:44:04 +02:00
|
|
|
|
|
|
|
%%-define(ejabberd_debug, true).
|
2009-06-16 19:43:35 +02:00
|
|
|
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
|
|
|
-export([
|
|
|
|
start/2,
|
|
|
|
stop/1,
|
|
|
|
process/2
|
|
|
|
]).
|
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
|
|
|
-include("jlib.hrl").
|
|
|
|
-include("ejabberd_http.hrl").
|
|
|
|
|
|
|
|
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% API
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
process([], #request{method = 'POST',
|
|
|
|
data = []}) ->
|
|
|
|
?DEBUG("Bad Request: no data", []),
|
|
|
|
{400, [], {xmlelement, "h1", [],
|
|
|
|
[{xmlcdata, "400 Bad Request"}]}};
|
|
|
|
process([], #request{method = 'POST',
|
|
|
|
data = Data}) ->
|
2009-06-16 19:44:04 +02:00
|
|
|
?DEBUG("Incoming data: ~s", [Data]),
|
2009-06-16 19:43:35 +02:00
|
|
|
ejabberd_http_bind:process_request(Data);
|
|
|
|
process([], #request{method = 'GET',
|
|
|
|
data = []}) ->
|
2009-06-16 19:44:13 +02:00
|
|
|
Heading = "Ejabberd " ++ atom_to_list(?MODULE) ++ " v" ++ ?MOD_HTTP_BIND_VERSION,
|
2009-06-16 19:43:35 +02:00
|
|
|
{xmlelement, "html", [{"xmlns", "http://www.w3.org/1999/xhtml"}],
|
|
|
|
[{xmlelement, "head", [],
|
|
|
|
[{xmlelement, "title", [], [{xmlcdata, Heading}]}]},
|
|
|
|
{xmlelement, "body", [],
|
|
|
|
[{xmlelement, "h1", [], [{xmlcdata, Heading}]},
|
|
|
|
{xmlelement, "p", [],
|
|
|
|
[{xmlcdata, "An implementation of "},
|
|
|
|
{xmlelement, "a", [{"href", "http://www.xmpp.org/extensions/xep-0206.html"}],
|
2009-06-16 19:44:13 +02:00
|
|
|
[{xmlcdata, "XMPP over BOSH (XEP-0206)"}]}]},
|
2009-06-16 19:43:35 +02:00
|
|
|
{xmlelement, "p", [],
|
2009-06-16 19:44:13 +02:00
|
|
|
[{xmlcdata, integer_to_list(mnesia:table_info(http_bind, size)) ++ " sessions found."}]},
|
|
|
|
{xmlelement, "p", [],
|
|
|
|
[{xmlcdata, "Sponsored by "},
|
|
|
|
{xmlelement, "a", [{"href", "http://mabber.com"}],
|
|
|
|
[{xmlcdata, "mabber"}]},
|
|
|
|
{xmlcdata, "."}]}
|
|
|
|
]}]};
|
2009-06-16 19:43:35 +02:00
|
|
|
process(_Path, _Request) ->
|
|
|
|
?DEBUG("Bad Request: ~p", [_Request]),
|
|
|
|
{400, [], {xmlelement, "h1", [],
|
|
|
|
[{xmlcdata, "400 Bad Request"}]}}.
|
|
|
|
|
2009-06-16 19:44:13 +02:00
|
|
|
|
2009-06-16 19:43:35 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% BEHAVIOUR CALLBACKS
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
start(_Host, _Opts) ->
|
2009-06-16 19:44:00 +02:00
|
|
|
HTTPBindSupervisor =
|
|
|
|
{ejabberd_http_bind_sup,
|
|
|
|
{ejabberd_tmp_sup, start_link,
|
|
|
|
[ejabberd_http_bind_sup, ejabberd_http_bind]},
|
|
|
|
permanent,
|
|
|
|
infinity,
|
|
|
|
supervisor,
|
|
|
|
[ejabberd_tmp_sup]},
|
|
|
|
case supervisor:start_child(ejabberd_sup, HTTPBindSupervisor) of
|
|
|
|
{ok, _Pid} ->
|
|
|
|
ok;
|
|
|
|
{ok, _Pid, _Info} ->
|
|
|
|
ok;
|
|
|
|
{error, Error} ->
|
|
|
|
{'EXIT', {start_child_error, Error}}
|
|
|
|
end.
|
2009-06-16 19:43:35 +02:00
|
|
|
|
|
|
|
stop(_Host) ->
|
2009-06-16 19:44:00 +02:00
|
|
|
case supervisor:terminate_child(ejabberd_sup, ejabberd_http_bind_sup) of
|
|
|
|
ok ->
|
|
|
|
ok;
|
|
|
|
{error, Error} ->
|
|
|
|
{'EXIT', {terminate_child_error, Error}}
|
|
|
|
end.
|