Skip to content

Commit

Permalink
elvis-compliance and some bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekgorny committed Sep 12, 2017
1 parent 55aeb66 commit 89f5e80
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 79 deletions.
48 changes: 22 additions & 26 deletions apps/ejabberd/src/ejabberd_local.erl
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,29 @@ start_link() ->
process_iq(Acc0, From, To, El) ->
Acc = mongoose_acc:require(iq_query_info, Acc0),
IQ = mongoose_acc:get(iq_query_info, Acc),
case IQ of
#iq{xmlns = XMLNS} ->
Host = To#jid.lserver,
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
[{_, Module, Function}] ->
ResIQ = Module:Function(From, To, IQ),
if
ResIQ /= ignore ->
ejabberd_router:route(
To, From, Acc, jlib:iq_to_xml(ResIQ));
true ->
ok
end;
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Acc, IQ);
[] ->
ejabberd_router:route_error_reply(To, From, Acc, ?ERR_FEATURE_NOT_IMPLEMENTED)
process_iq(IQ, Acc, From, To, El).

process_iq(#iq{xmlns = XMLNS} = IQ, Acc, From, To, _El) ->
Host = To#jid.lserver,
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
[{_, Module, Function}] ->
case Module:Function(From, To, IQ) of
ignore -> ok;
ResIQ -> ejabberd_router:route(To, From, Acc, jlib:iq_to_xml(ResIQ))
end;
reply ->
IQReply = jlib:iq_query_or_response_info(El),
process_iq_reply(From, To, Acc, IQReply);
_ ->
Err = jlib:make_error_reply(El, ?ERR_BAD_REQUEST),
ejabberd_router:route(To, From, Acc, Err),
ok
end.
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Acc, IQ);
[] ->
ejabberd_router:route_error_reply(To, From, Acc, ?ERR_FEATURE_NOT_IMPLEMENTED)
end;
process_iq(reply, Acc, From, To, El) ->
IQReply = jlib:iq_query_or_response_info(El),
process_iq_reply(From, To, Acc, IQReply);
process_iq(_, Acc, From, To, El) ->
Err = jlib:make_error_reply(El, ?ERR_BAD_REQUEST),
ejabberd_router:route(To, From, Acc, Err),
ok.

-spec process_iq_reply(From :: ejabberd:jid(),
To :: ejabberd:jid(),
Expand Down
52 changes: 25 additions & 27 deletions apps/ejabberd/src/ejabberd_sm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -960,34 +960,32 @@ get_max_user_sessions(LUser, Host) ->
process_iq(From, To, Acc0, Packet) ->
Acc = mongoose_acc:require(iq_query_info, Acc0),
IQ = mongoose_acc:get(iq_query_info, Acc),
case IQ of
#iq{xmlns = XMLNS} ->
Host = To#jid.lserver,
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
[{_, Module, Function}] ->
ResIQ = Module:Function(From, To, IQ),
if
ResIQ /= ignore ->
ejabberd_router:route(To, From, Acc,
jlib:iq_to_xml(ResIQ));
true ->
ok
end;
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Acc, IQ);
[] ->
Err = jlib:make_error_reply(
Packet, ?ERR_SERVICE_UNAVAILABLE),
ejabberd_router:route(To, From, Acc, Err)
process_iq(IQ, From, To, Acc0, Packet).

process_iq(#iq{xmlns = XMLNS} = IQ, From, To, Acc, Packet) ->
Host = To#jid.lserver,
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
[{_, Module, Function}] ->
case Module:Function(From, To, IQ) of
ignore -> ok;
ResIQ ->
ejabberd_router:route(To, From, Acc,
jlib:iq_to_xml(ResIQ))
end;
reply ->
ok;
_ ->
Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST),
ejabberd_router:route(To, From, Acc, Err),
ok
end.
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Acc, IQ);
[] ->
Err = jlib:make_error_reply(
Packet, ?ERR_SERVICE_UNAVAILABLE),
ejabberd_router:route(To, From, Acc, Err)
end;
process_iq(reply, _From, _To, _Acc, _Packet) ->
ok;
process_iq(_, From, To, Acc, Packet) ->
Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST),
ejabberd_router:route(To, From, Acc, Err),
ok.


-spec force_update_presence({binary(), ejabberd:server()}) -> 'ok'.
Expand Down
11 changes: 4 additions & 7 deletions apps/ejabberd/src/gen_iq_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,11 @@ process_iq(_Host, Module, Function, From, To, Acc, IQ) ->
case catch Module:Function(From, To, Acc, IQ) of
{'EXIT', Reason} ->
?ERROR_MSG("~p", [Reason]);
{Acc1, ignore} ->
Acc1;
{Acc1, ResIQ} ->
if
ResIQ /= ignore ->
ejabberd_router:route(To, From, Acc1,
jlib:iq_to_xml(ResIQ));
true ->
Acc1
end
ejabberd_router:route(To, From, Acc1,
jlib:iq_to_xml(ResIQ))
end.

-spec check_type(type()) -> type().
Expand Down
15 changes: 8 additions & 7 deletions apps/ejabberd/src/mod_auth_token.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-export([clean_tokens/2]).

%% gen_iq_handler handlers
-export([process_iq/3]).
-export([process_iq/4]).

%% Public API
-export([authenticate/1,
Expand Down Expand Up @@ -243,14 +243,15 @@ is_revoked(#token{type = refresh, sequence_no = TokenSeqNo} = T) ->
true
end.

-spec process_iq(jid(), jid(), iq()) -> iq() | error().
process_iq(From, To, #iq{xmlns = ?NS_ESL_TOKEN_AUTH} = IQ) ->
case lists:member(From#jid.lserver, ?MYHOSTS) of
-spec process_iq(jid(), mongoose_acc:t(), jid(), iq()) -> {mongoose_acc:t(), iq()} | error().
process_iq(From, To, Acc, #iq{xmlns = ?NS_ESL_TOKEN_AUTH} = IQ) ->
IQResp = case lists:member(From#jid.lserver, ?MYHOSTS) of
true -> process_local_iq(From, To, IQ);
false -> iq_error(IQ, [?ERR_ITEM_NOT_FOUND])
end;
process_iq(_From, _To, #iq{} = IQ) ->
iq_error(IQ, [?ERR_BAD_REQUEST]).
end,
{Acc, IQResp};
process_iq(_From, _To, Acc, #iq{} = IQ) ->
{Acc, iq_error(IQ, [?ERR_BAD_REQUEST])}.

process_local_iq(From, _To, IQ) ->
try create_token_response(From, IQ) of
Expand Down
1 change: 0 additions & 1 deletion apps/ejabberd/src/mod_carboncopy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
-include_lib("ejabberd/include/jlib.hrl").

-type classification() :: 'ignore' | 'forward'.
-type matchspec_atom() :: '_' | '$1' | '$2' | '$3'.

is_carbon_copy(Packet) ->
case xml:get_subtag(Packet, <<"sent">>) of
Expand Down
9 changes: 5 additions & 4 deletions apps/ejabberd/src/mod_push.erl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ filter_packet({From, To = #jid{lserver = Host}, Acc, Packet}) ->
true ->
case mod_push_plugin:should_publish(Host, From, To, Packet) of
true ->
publish_message(From, To, Packet);
publish_message(From, To, Acc, Packet);
false ->
skip
end;
Expand Down Expand Up @@ -169,8 +169,9 @@ handle_publish_response(BareRecipient, PubsubJID, Node, #iq{type = error}) ->
%% Module API
%%--------------------------------------------------------------------

-spec publish_message(From :: ejabberd:jid(), To :: ejabberd:jid(), Packet :: jlib:xmlel()) -> ok.
publish_message(From, To = #jid{lserver = Host}, Packet) ->
-spec publish_message(From :: ejabberd:jid(), To :: ejabberd:jid(), Acc :: mongoose_acc:t(),
Packet :: jlib:xmlel()) -> ok.
publish_message(From, To = #jid{lserver = Host}, Acc, Packet) ->
?DEBUG("Handle push notification ~p", [{From, To, Packet}]),

BareRecipient = jid:to_bare(To),
Expand All @@ -183,7 +184,7 @@ publish_message(From, To = #jid{lserver = Host}, Packet) ->
cast(Host, handle_publish_response,
[BareRecipient, PubsubJID, Node, Response])
end,
cast(Host, ejabberd_local, route_iq, [To, PubsubJID, Stanza, ResponseHandler])
cast(Host, ejabberd_local, route_iq, [To, PubsubJID, Acc, Stanza, ResponseHandler])
end, Services),

ok.
Expand Down
14 changes: 7 additions & 7 deletions apps/ejabberd/src/mod_version.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-include("jlib.hrl").
-include("ejabberd.hrl").

-export([start/2, stop/1, process_iq/3]).
-export([start/2, stop/1, process_iq/4]).

-xep([{xep, 92}, {version, "1.1"}]).

Expand All @@ -21,13 +21,13 @@ stop(Host) ->
mod_disco:unregister_feature(Host, ?NS_VERSION),
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_VERSION).

-spec process_iq(jid(), jid(), iq()) -> iq().
process_iq(_From, _To, #iq{type = set, sub_el = SubEl} = IQ) ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
process_iq(From, _To, #iq{type = get} = IQ) ->
-spec process_iq(jid(), jid(), mongoose_acc:t(), iq()) -> iq().
process_iq(_From, _To, Acc, #iq{type = set, sub_el = SubEl} = IQ) ->
{Acc, IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}};
process_iq(From, _To, Acc, #iq{type = get} = IQ) ->
{Name, Version} = mongoose_info(),
Host = From#jid.lserver,
IQ#iq{type = result,
{Acc, IQ#iq{type = result,
sub_el =
[#xmlel{name = <<"query">>,
attrs = [{<<"xmlns">>, ?NS_VERSION}],
Expand All @@ -36,7 +36,7 @@ process_iq(From, _To, #iq{type = get} = IQ) ->
children =[#xmlcdata{content = Name}]},
#xmlel{name = <<"version">>, attrs = [],
children =[#xmlcdata{content = Version}]}
] ++ add_os_info(Host)}]}.
] ++ add_os_info(Host)}]}}.

-spec add_os_info(binary()) -> [exml:element()] | [].
add_os_info(Host) ->
Expand Down

0 comments on commit 89f5e80

Please sign in to comment.