-
Notifications
You must be signed in to change notification settings - Fork 429
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
Add host_type to hook calls in core modules #3097
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3097 +/- ##
==========================================
+ Coverage 79.06% 79.12% +0.06%
==========================================
Files 386 386
Lines 31830 31820 -10
==========================================
+ Hits 25165 25177 +12
+ Misses 6665 6643 -22
Continue to review full report at Codecov.
|
7c57d27
to
438415b
Compare
33f3c69
to
9cfb521
Compare
- For binary: run as before - For 'undefined': log an error and return Acc (no-op) This might happen if host type is taken from the Acc. We need to eradicate this case from the code later.
They have been deprecated for a long time and they conflict with new functions that will be introduced for host_type.
This required adding it to open_session, what in turn required adding it to mongoose_client_api.
Take it from Acc as the hook is always run for a local user.
Reason: The stanza is handled locally and host type can be used when running local hooks. Anyway, this clause is used only for sending MAM messages.
It is safe to take it from the acc created for the local user.
The Acc is constructed in ejabberd_c2s from the local state, which contains the host type of the local user.
Hooks changed: - roster_in_subscription - sm_filter_offline_message - privacy_get_user_list - offline_groupchat_message_hook
Hooks changed: - offline_message_hook - failed_to_store_message
This change is in a separate commit for clarity. The host_type argument is removed as it is always calculated from the server part of the JID.
Motivation: - Simplicity. - They were unused - no handlers in the code base. - One was already global, now they are consistent. - Host type can be introduced anytime when a need arises.
06ab31c
to
f8a8d47
Compare
Also: - Avoid duplicate calculation of host_type in ejabberd_auth:remove_user/1 - Provide host_type in sm_register_connection_hook to pass it in a call to register_user from ejabberd_auth_anonymous
08d6a6c
to
b4b6fcf
Compare
b4b6fcf
to
c376aed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
case lists:any(fun(El) -> El == ok end, RemoveResult) of | ||
true -> | ||
Acc = mongoose_acc:new(#{ location => ?LOCATION, | ||
host_type => HostType, | ||
lserver => LServer, | ||
element => undefined }), | ||
mongoose_hooks:remove_user(LServer, Acc, LUser), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it could be remove_user(Acc, LServer, LUser)
. Though backward compatibility would suffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather rearrange the hook arguments in a separate PR as these changes are quite tricky.
As I said in the PR description: Do not rearrange the arguments when not necessary.
@@ -153,13 +153,14 @@ remove_connection(SID, LUser, LServer) -> | |||
|
|||
%% @doc Register connection | |||
-spec register_connection(Acc, | |||
HostType :: binary(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this type defined in mongooseim:host_type()
since yesterday
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen it. I don't think it makes sense to amend this PR though. I'd rather do it later.
@@ -1098,7 +1098,7 @@ get_roster_old(DestServer, JID) -> | |||
A = mongoose_acc:new(#{ location => ?LOCATION, | |||
lserver => DestServer, | |||
element => undefined }), | |||
A2 = mongoose_hooks:roster_get(DestServer, A, JID), | |||
A2 = mongoose_hooks:roster_get(A, JID), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be Acc
instead of A
, to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I just wanted to minimize changes in mod_*
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks fine. a bit hard to follow, but we all knew it's gonna be like that :)
Make all hook calls not related to any extension modules work with host types.
The following rules were applied:
Acc
is passed, make sure itshost_type
is consistent with theLServer
argument that was passed before and get the host type form the Acc insidemongoose_hooks
.LServer
argument if possible.More details in commit messages.