Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dynamic domains in mod_caps #3156

Merged
merged 13 commits into from
Jun 17, 2021
Merged

Conversation

chrzaszcz
Copy link
Member

@chrzaszcz chrzaszcz commented Jun 16, 2021

Add support for dynamic domains to mod_caps.

Hooks handled or triggered by mod_caps are refactored according to the following rule:

  • If c2s state or mongoose_acc:t() is passed as an argument, do not add host type to the hook and handlers.
  • Otherwise, add host type to the hook and its handlers.

Some lines remain untested as they are quite difficult to hit in the tests. Caps are mostly needed for PEP and it does not support dynamic domains, so the coverage for dynamic_domains is even lower. It could be increased in the future with the conversion of PubSub and PEP.

See individual commits for more details.

@codecov
Copy link

codecov bot commented Jun 16, 2021

Codecov Report

Merging #3156 (de4082a) into master (0d82dc9) will decrease coverage by 0.06%.
The diff coverage is 86.30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3156      +/-   ##
==========================================
- Coverage   79.89%   79.82%   -0.07%     
==========================================
  Files         396      396              
  Lines       32335    32316      -19     
==========================================
- Hits        25834    25797      -37     
- Misses       6501     6519      +18     
Impacted Files Coverage Δ
src/ejabberd_c2s_state.erl 100.00% <ø> (ø)
src/mod_register.erl 74.24% <ø> (ø)
src/mod_stream_management.erl 84.61% <ø> (ø)
src/mod_caps.erl 75.11% <82.45%> (-2.43%) ⬇️
src/ejabberd_c2s.erl 88.98% <100.00%> (-0.31%) ⬇️
src/mod_amp.erl 95.55% <100.00%> (ø)
src/mod_csi.erl 100.00% <100.00%> (ø)
src/mongoose_hooks.erl 94.83% <100.00%> (+0.72%) ⬆️
src/pubsub/mod_pubsub.erl 73.17% <100.00%> (-0.02%) ⬇️
src/ejabberd.erl 45.00% <0.00%> (-10.00%) ⬇️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d82dc9...de4082a. Read the comment docs.

@chrzaszcz chrzaszcz force-pushed the caps-with-dynamic-domains branch 2 times, most recently from f3f6f58 to 436059b Compare June 17, 2021 07:22
@chrzaszcz chrzaszcz force-pushed the caps-with-dynamic-domains branch from 436059b to 47428af Compare June 17, 2021 08:04
@chrzaszcz chrzaszcz marked this pull request as ready for review June 17, 2021 08:43
Insert = (Type == <<>> orelse Type == <<"available">>)
and (Subscription == both orelse Subscription == to),
Delete = Type == <<"unavailable">> orelse Type == <<"error">>,
case Insert orelse Delete of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually prefer or, when operations on booleans are made. because of better type checking at runtime

5> true or 4.
** exception error: bad argument
     in operator  or/2
        called as true or 4
6> true orelse 4.
true

Copy link
Member Author

@chrzaszcz chrzaszcz Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, short-circuit expressions are tail-recursive, quicker to execute and they make it obvious to the reader that the side-effects are not important.

In this particular case, it's priority that makes orelse the natural choice for me. Less parentheses needed, see this:

A == B or C

It is a bit counter-intuitive, that B or C is evaluated first here.

Copy link
Contributor

@arcusfelis arcusfelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

src/mongoose_hooks.erl Outdated Show resolved Hide resolved
@arcusfelis arcusfelis merged commit a40d5fa into master Jun 17, 2021
@arcusfelis arcusfelis deleted the caps-with-dynamic-domains branch June 17, 2021 14:57
@Premwoik Premwoik added this to the 5.0.0 milestone Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants