From 426f6072dc8e87da76cc12de11a88235f2e25416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20R=C3=A9mond?= Date: Thu, 1 Nov 2007 13:59:29 +0000 Subject: [PATCH] * src/web/ejabberd_http_poll.erl: Support for c2s ACL access, max_stanza and shaper on http_bind connections (EJAB-243, EJAB-415, EJAB-416) SVN Revision: 965 --- ChangeLog | 6 +++++ src/web/ejabberd_http_poll.erl | 44 ++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 97a8bf7ae..f117e4252 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-11-01 Mickael Remond + + * src/web/ejabberd_http_poll.erl: Support for c2s ACL access, + max_stanza and shaper on http_bind connections (EJAB-243, + EJAB-415, EJAB-416) + 2007-10-30 Jerome Sautret * src/ejabberd_s2s.erl: don't use the resource of the sender to choose diff --git a/src/web/ejabberd_http_poll.erl b/src/web/ejabberd_http_poll.erl index 912865116..ba85c940a 100644 --- a/src/web/ejabberd_http_poll.erl +++ b/src/web/ejabberd_http_poll.erl @@ -1,13 +1,13 @@ %%%---------------------------------------------------------------------- %%% File : ejabberd_http_poll.erl -%%% Author : Alexey Shchepin +%%% Author : Alexey Shchepin %%% Purpose : HTTP Polling support (JEP-0025) -%%% Created : 4 Mar 2004 by Alexey Shchepin +%%% Created : 4 Mar 2004 by Alexey Shchepin %%% Id : $Id$ %%%---------------------------------------------------------------------- -module(ejabberd_http_poll). --author('alexey@sevcom.net'). +-author('alexey@process-one.net'). -vsn('$Revision$ '). -behaviour(gen_fsm). @@ -153,7 +153,15 @@ process(_, _Request) -> %%---------------------------------------------------------------------- init([ID, Key]) -> ?INFO_MSG("started: ~p", [{ID, Key}]), - Opts = [], % TODO + + %% Read c2s options from the first ejabberd_c2s configuration in + %% the config file listen section + %% TODO: We should have different access and shaper values for + %% each connector. The default behaviour should be however to use + %% the default c2s restrictions if not defined for the current + %% connector. + Opts = get_c2s_opts(), + ejabberd_socket:start(ejabberd_c2s, ?MODULE, {http_poll, self()}, Opts), %{ok, C2SPid} = ejabberd_c2s:start({?MODULE, {http_poll, self()}}, Opts), %ejabberd_c2s:become_controller(C2SPid), @@ -318,6 +326,34 @@ terminate(Reason, StateName, StateData) -> %%% Internal functions %%%---------------------------------------------------------------------- +%% Get first c2s configuration limitations to apply it to other c2s +%% connectors. +get_c2s_opts() -> + case ejabberd_config:get_local_option(listen) of + undefined -> + []; + C2SFirstListen -> + case lists:keysearch(ejabberd_c2s, 2, C2SFirstListen) of + false -> + []; + {value, {_Port, ejabberd_c2s, Opts}} -> + select_opts_values(Opts) + end + end. +%% Only get access, shaper and max_stanza_size values +select_opts_values(Opts) -> + select_opts_values(Opts, []). +select_opts_values([], SelectedValues) -> + SelectedValues; +select_opts_values([{access,Value}|Opts], SelectedValues) -> + select_opts_values(Opts, [{access, Value}|SelectedValues]); +select_opts_values([{shaper,Value}|Opts], SelectedValues) -> + select_opts_values(Opts, [{shaper, Value}|SelectedValues]); +select_opts_values([{max_stanza_size,Value}|Opts], SelectedValues) -> + select_opts_values(Opts, [{max_stanza_size, Value}|SelectedValues]); +select_opts_values([_Opt|Opts], SelectedValues) -> + select_opts_values(Opts, SelectedValues). + http_put(ID, Key, NewKey, Packet) -> case mnesia:dirty_read({http_poll, ID}) of