Skip to content

Commit

Permalink
Merge pull request #3156 from esl/caps-with-dynamic-domains
Browse files Browse the repository at this point in the history
Support dynamic domains in mod_caps
  • Loading branch information
arcusfelis authored Jun 17, 2021
2 parents 0d82dc9 + de4082a commit a40d5fa
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 256 deletions.
4 changes: 0 additions & 4 deletions big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
{suites, "tests", carboncopy_SUITE}.

{suites, "tests", disco_and_caps_SUITE}.
{skip_cases, "tests", disco_and_caps_SUITE,
[caps_feature_is_advertised,
user_can_query_server_caps_via_disco],
"at the moment mod_caps doesn't support dynamic domains"}.
{skip_cases, "tests", disco_and_caps_SUITE,
[user_can_query_friend_resources,
user_can_query_friend_features,
Expand Down
15 changes: 6 additions & 9 deletions src/ejabberd_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
-xep([{xep, 18}, {version, "0.2"}]).
-behaviour(p1_fsm_old).

-export_type([broadcast/0, packet/0]).
-export_type([broadcast/0, packet/0, state/0]).

-type packet() :: {jid:jid(), jid:jid(), exml:element()}.

Expand Down Expand Up @@ -403,11 +403,11 @@ maybe_sasl_mechanisms(#state{host_type = HostType} = S) ->
Mechanisms ->
[#xmlel{name = <<"mechanisms">>,
attrs = [{<<"xmlns">>, ?NS_SASL}],
children = [ mechanism(M) || M <- Mechanisms, filter_mechanism(M,S) ]}]
children = [ mechanism(M) || M <- Mechanisms, filter_mechanism(M, S) ]}]
end.

hook_enabled_features(#state{server = Server, host_type = HostType}) ->
mongoose_hooks:c2s_stream_features(HostType, Server).
hook_enabled_features(#state{host_type = HostType, server = LServer}) ->
mongoose_hooks:c2s_stream_features(HostType, LServer).

starttls_stanza(TLSRequired)
when TLSRequired =:= required;
Expand Down Expand Up @@ -1135,13 +1135,11 @@ handle_incoming_message({route, From, To, Acc}, StateName, StateData) ->
process_incoming_stanza_with_conflict_check(From, To, Acc, StateName, StateData);
handle_incoming_message({send_filtered, Feature, From, To, Packet}, StateName, StateData) ->
% this is used by pubsub and should be rewritten when someone rewrites pubsub module
#state{server = Server, host_type = HostType} = StateData,
Acc = new_acc(StateData, #{location => ?LOCATION,
from_jid => From,
to_jid => To,
element => Packet}),
Drop = mongoose_hooks:c2s_filter_packet(HostType, Server, StateData,
Feature, To, Packet),
Drop = mongoose_hooks:c2s_filter_packet(StateData, Feature, To, Packet),
case {Drop, StateData#state.jid} of
{true, _} ->
?LOG_DEBUG(#{what => c2s_dropped_packet, acc => Acc,
Expand Down Expand Up @@ -1400,8 +1398,7 @@ privacy_list_push_iq(PrivListName) ->
Acc0 :: mongoose_acc:t(), StateData :: state()) -> routing_result().
handle_routed_presence(From, To, Acc, StateData) ->
Packet = mongoose_acc:element(Acc),
State = mongoose_hooks:c2s_presence_in(StateData#state.host_type,
StateData, From, To, Packet),
State = mongoose_hooks:c2s_presence_in(StateData, From, To, Packet),
case mongoose_acc:stanza_type(Acc) of
<<"probe">> ->
{LFrom, LBFrom} = lowcase_and_bare(From),
Expand Down
4 changes: 3 additions & 1 deletion src/ejabberd_c2s_state.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

-export([server/1, jid/1, host_type/1]).

-spec server(state()) -> jid:lserver().
server(#state{ server = Server }) ->
Server.

-spec host_type(state()) -> mongooseim:host_type().
host_type(#state{ host_type = HostType }) ->
HostType.

-spec jid(state()) -> jid:jid().
jid(#state{ jid = JID }) ->
JID.

8 changes: 5 additions & 3 deletions src/mod_amp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-export([run_initial_check/2,
check_packet/2,
disco_local_features/1,
add_stream_feature/2
c2s_stream_features/3
]).

-include("amp.hrl").
Expand All @@ -32,7 +32,7 @@ stop(Host) ->
ejabberd_hooks:delete(hooks(Host)).

hooks(Host) ->
[{c2s_stream_features, Host, ?MODULE, add_stream_feature, 50},
[{c2s_stream_features, Host, ?MODULE, c2s_stream_features, 50},
{disco_local_features, Host, ?MODULE, disco_local_features, 99},
{c2s_preprocessing_hook, Host, ?MODULE, run_initial_check, 10},
{amp_verify_support, Host, ?AMP_RESOLVER, verify_support, 10},
Expand Down Expand Up @@ -64,7 +64,9 @@ disco_local_features(Acc = #{node := Node}) ->
Features -> mongoose_disco:add_features(Features, Acc)
end.

add_stream_feature(Acc, _Host) ->
-spec c2s_stream_features([exml:element()], mongooseim:host_type(), jid:lserver()) ->
[exml:element()].
c2s_stream_features(Acc, _HostType, _Lserver) ->
lists:keystore(<<"amp">>, #xmlel.name, Acc, ?AMP_FEATURE).

%% Internal
Expand Down
Loading

0 comments on commit a40d5fa

Please sign in to comment.