Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Waz committed Oct 11, 2022
1 parent 1448964 commit 5865f40
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 137 deletions.
34 changes: 1 addition & 33 deletions src/jlib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
-xep([{xep, 59}, {version, "1.0"}]).
-xep([{xep, 68}, {version, "1.2"}]).
-xep([{xep, 86}, {version, "1.0"}]).
-export([make_result_iq_reply/1,
make_error_reply/2,
-export([make_error_reply/2,
make_error_reply/3,
make_invitation/3,
make_config_change_message/1,
Expand Down Expand Up @@ -86,37 +85,6 @@
iq/0
]).

-spec make_result_iq_reply(exml:element()) -> exml:element();
(iq()) -> iq().
make_result_iq_reply(XE = #xmlel{attrs = Attrs}) ->
NewAttrs = make_result_iq_reply_attrs(Attrs),
XE#xmlel{attrs = NewAttrs};
make_result_iq_reply(IQ = #iq{}) ->
IQ#iq{ type = result }.


-spec make_result_iq_reply_attrs([binary_pair()]) -> [binary_pair(), ...].
make_result_iq_reply_attrs(Attrs) ->
To = xml:get_attr(<<"to">>, Attrs),
From = xml:get_attr(<<"from">>, Attrs),
Attrs1 = lists:keydelete(<<"to">>, 1, Attrs),
Attrs2 = lists:keydelete(<<"from">>, 1, Attrs1),
Attrs3 = case To of
{value, ToVal} ->
[{<<"from">>, ToVal} | Attrs2];
_ ->
Attrs2
end,
Attrs4 = case From of
{value, FromVal} ->
[{<<"to">>, FromVal} | Attrs3];
_ ->
Attrs3
end,
Attrs5 = lists:keydelete(<<"type">>, 1, Attrs4),
[{<<"type">>, <<"result">>} | Attrs5].


-spec make_error_reply(exml:element() | mongoose_acc:t(),
xmlcdata() | exml:element()) ->
exml:element() | {mongoose_acc:t(), exml:element() | {error, {already_an_error, _, _}}}.
Expand Down
1 change: 1 addition & 0 deletions src/mongoose_acc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
-export([strip/1, strip/2]).

-ignore_xref([delete/2, ref/1]).
-ignore_xref([strip/1]). % TODO: Check

%% Note about 'undefined' to_jid and from_jid: these are the special cases when JID may be
%% truly unknown: before a client is authorized.
Expand Down
104 changes: 0 additions & 104 deletions src/mongoose_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,16 @@
rest_user_send_packet/4,
session_cleanup/5,
set_vcard/3,
unacknowledged_message/2,
filter_unacknowledged_messages/3,
unregister_subhost/1,
user_available_hook/2,
user_ping_response/5,
user_receive_packet/6,
user_sent_keep_alive/2,
user_send_packet/4,
vcard_set/4,
xmpp_send_element/3,
xmpp_stanza_dropped/4]).

-export([c2s_broadcast_recipients/4,
c2s_filter_packet/4,
c2s_preprocessing_hook/3,
c2s_presence_in/4,
c2s_stream_features/2,
c2s_unauthenticated_iq/4,
c2s_update_presence/2,
check_bl_c2s/1,
forbidden_session_hook/3,
session_opening_allowed_for_user/2]).
Expand Down Expand Up @@ -153,8 +144,6 @@
-export([mod_global_distrib_known_recipient/4,
mod_global_distrib_unknown_recipient/2]).

-export([c2s_remote_hook/5]).

-export([remove_domain/2,
node_cleanup/1]).

Expand All @@ -172,17 +161,6 @@
Packet :: exml:element()}.
-export_type([filter_packet_acc/0]).

-spec c2s_remote_hook(HostType, Tag, Args, HandlerState, C2SState) -> Result when
HostType :: binary(),
Tag :: atom(),
Args :: term(),
HandlerState :: term(),
C2SState :: ejabberd_c2s:state(),
Result :: term(). % ok | empty_state | HandlerState
c2s_remote_hook(HostType, Tag, Args, HandlerState, C2SState) ->
run_hook_for_host_type(c2s_remote_hook, HostType, HandlerState,
[Tag, Args, C2SState]).

-spec adhoc_local_commands(HostType, From, To, AdhocRequest) -> Result when
HostType :: mongooseim:host_type(),
From :: jid:jid(),
Expand Down Expand Up @@ -411,25 +389,6 @@ set_vcard(HostType, UserJID, VCard) ->
run_hook_for_host_type(set_vcard, HostType, {error, no_handler_defined},
[HostType, UserJID, VCard]).

-spec unacknowledged_message(Acc, JID) -> Result when
Acc :: mongoose_acc:t(),
JID :: jid:jid(),
Result :: mongoose_acc:t().
unacknowledged_message(Acc, JID) ->
HostType = mongoose_acc:host_type(Acc),
Params = #{jid => JID},
Args = [JID],
ParamsWithLegacyArgs = ejabberd_hooks:add_args(Params, Args),
run_hook_for_host_type(unacknowledged_message, HostType, Acc, ParamsWithLegacyArgs).

-spec filter_unacknowledged_messages(HostType, Jid, Buffer) -> Result when
HostType :: mongooseim:host_type(),
Jid :: jid:jid(),
Buffer :: [mongoose_acc:t()],
Result :: [mongoose_acc:t()].
filter_unacknowledged_messages(HostType, Jid, Buffer) ->
run_fold(filter_unacknowledged_messages, HostType, Buffer, #{jid => Jid}).

%%% @doc The `unregister_subhost' hook is called when a component
%%% is unregistered from ejabberd_router or a subdomain is removed from mongoose_subdomain_core.
-spec unregister_subhost(LDomain) -> Result when
Expand Down Expand Up @@ -463,24 +422,6 @@ user_ping_response(HostType, Acc, JID, Response, TDelta) ->
ParamsWithLegacyArgs = ejabberd_hooks:add_args(Params, Args),
run_hook_for_host_type(user_ping_response, HostType, Acc, ParamsWithLegacyArgs).

-spec user_receive_packet(HostType, Acc, JID, From, To, El) -> Result when
HostType :: binary(),
Acc :: mongoose_acc:t(),
JID :: jid:jid(),
From :: jid:jid(),
To :: jid:jid(),
El :: exml:element(),
Result :: mongoose_acc:t().
user_receive_packet(HostType, Acc, JID, From, To, El) ->
run_hook_for_host_type(user_receive_packet, HostType, Acc, [JID, From, To, El]).

-spec user_sent_keep_alive(HostType, JID) -> Result when
HostType :: binary(),
JID :: jid:jid(),
Result :: any().
user_sent_keep_alive(HostType, JID) ->
run_hook_for_host_type(user_sent_keep_alive, HostType, ok, [JID]).

%%% @doc A hook called when a user sends an XMPP stanza.
%%% The hook's handler is expected to accept four parameters:
%%% `Acc', `From', `To' and `Packet'
Expand Down Expand Up @@ -542,58 +483,13 @@ c2s_broadcast_recipients(State, Type, From, Packet) ->
run_hook_for_host_type(c2s_broadcast_recipients, HostType, [],
[State, Type, From, Packet]).

-spec c2s_filter_packet(State, Feature, To, Packet) -> Result when
State :: ejabberd_c2s:state(),
Feature :: {atom(), binary()},
To :: jid:jid(),
Packet :: exml:element(),
Result :: boolean().
c2s_filter_packet(State, Feature, To, Packet) ->
HostType = ejabberd_c2s_state:host_type(State),
run_hook_for_host_type(c2s_filter_packet, HostType, true,
[State, Feature, To, Packet]).

-spec c2s_preprocessing_hook(HostType, Acc, State) -> Result when
HostType :: mongooseim:host_type(),
Acc :: mongoose_acc:t(),
State :: mongoose_c2s:c2s_data(),
Result :: mongoose_acc:t().
c2s_preprocessing_hook(HostType, Acc, State) ->
run_hook_for_host_type(c2s_preprocessing_hook, HostType, Acc, [State]).

-spec c2s_presence_in(State, From, To, Packet) -> Result when
State :: ejabberd_c2s:state(),
From :: jid:jid(),
To :: jid:jid(),
Packet :: exml:element(),
Result :: ejabberd_c2s:state().
c2s_presence_in(State, From, To, Packet) ->
HostType = ejabberd_c2s_state:host_type(State),
run_hook_for_host_type(c2s_presence_in, HostType, State, [From, To, Packet]).

-spec c2s_stream_features(HostType, LServer) -> Result when
HostType :: mongooseim:host_type(),
LServer :: jid:lserver(),
Result :: [exml:element()].
c2s_stream_features(HostType, LServer) ->
run_hook_for_host_type(c2s_stream_features, HostType, [], [HostType, LServer]).

-spec c2s_unauthenticated_iq(HostType, Server, IQ, IP) -> Result when
HostType :: mongooseim:host_type(),
Server :: jid:server(),
IQ :: jlib:iq(),
IP :: {inet:ip_address(), inet:port_number()} | undefined,
Result :: exml:element() | empty.
c2s_unauthenticated_iq(HostType, Server, IQ, IP) ->
run_hook_for_host_type(c2s_unauthenticated_iq, HostType, empty, [HostType, Server, IQ, IP]).

-spec c2s_update_presence(HostType, Acc) -> Result when
HostType :: mongooseim:host_type(),
Acc :: mongoose_acc:t(),
Result :: mongoose_acc:t().
c2s_update_presence(HostType, Acc) ->
run_hook_for_host_type(c2s_update_presence, HostType, Acc, []).

-spec check_bl_c2s(IP) -> Result when
IP :: inet:ip_address(),
Result :: boolean().
Expand Down
1 change: 1 addition & 0 deletions src/mongoose_iq.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
-export([info/1, xmlns/1, command/1]).

-ignore_xref([command/1, empty_result_iq/1, iq_to_sub_el/1, update_acc_info/1]).
-ignore_xref([xmlns/1]).

-include("jlib.hrl").

Expand Down

0 comments on commit 5865f40

Please sign in to comment.