Skip to content

Commit

Permalink
Make xref works
Browse files Browse the repository at this point in the history
  • Loading branch information
vkatsuba committed Jul 12, 2021
1 parent 9ee015a commit 0790218
Show file tree
Hide file tree
Showing 267 changed files with 1,079 additions and 32 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -109,6 +109,19 @@ jobs:
otp-version: ${{matrix.otp}}
- run: tools/test.sh -p dialyzer_only

xref:
name: xref on OTP ${{matrix.otp}}
strategy:
matrix:
otp: ['23.0.3']
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: ErlGang/setup-erlang@v1.0.0
with:
otp-version: ${{matrix.otp}}
- run: tools/test.sh -p xref_only

pkg:
name: ${{matrix.pkg}} package
strategy:
Expand Down
24 changes: 12 additions & 12 deletions doc/developers-guide/mod_amp_developers_guide.md
Expand Up @@ -8,10 +8,10 @@ This is a quick, introductory guide for developers wishing to extend `mod_amp` o
This header file contains the amp XML namespace and the types used by mod_amp: `amp_rule()` and `amp_strategy()` are the top-level points of interest.

* `src/mod_amp.erl`
This module is responsible for plugging in all the other components.
It's main driving function is `filter_packet`.
This module is responsible for plugging in all the other components.
It's main driving function is `filter_packet`.
After determining that a given message contains amp rules, the module proceeds by determining its strategy for the message and comparing it against the rules.
The server may return an error at multiple points in its work-flow.
The server may return an error at multiple points in its work-flow.
This is signaled by calling the function `send_error_and_drop/3` or `send_errors_and_drop/2`.

* `src/amp.erl`
Expand All @@ -22,24 +22,24 @@ This is a quick, introductory guide for developers wishing to extend `mod_amp` o
Tests for the API functions exported by `amp.erl`

* `src/amp_strategy.erl`
This module is where the server-side hook for determining a default action for a given message is performed.
This module is where the server-side hook for determining a default action for a given message is performed.
Calls to `ejabberd_sm` are made here.

* `src/amp_resolver.erl`
This module models the resolution of amp rules, given a certain strategy.
This module models the resolution of amp rules, given a certain strategy.
Also, the function verify_rule_support is hard-coded here to return an `unsupported-` type error for unsupported rule actions and values.

* `test/amp_resolver_SUITE.erl`
These tests verify that the `amp_resolver:check_condition/4` hook works as intended, i.e: that the rules which would be triggered given a particular server-side strategy actually do get triggered, and that all others get rejected.
These tests verify that the `amp_resolver:check_condition/3` hook works as intended, i.e: that the rules which would be triggered given a particular server-side strategy actually do get triggered, and that all others get rejected.

* `test/amp_gen.erl`
This module contains PropEr generators for server-side strategies, as well as valid and invalid amp rules.
This module contains PropEr generators for server-side strategies, as well as valid and invalid amp rules.
Used in both test suites.

## Hooks for Other Modules

If your module would like to have some say in the amp decision making process, please refer to the hooks: `amp_determine_strategy` and `amp_check_condition`.
Remember that the hook for check_condition is a fold on a boolean(), and should behave like a variadic `or`.
Remember that the hook for check_condition is a fold on a boolean(), and should behave like a variadic `or`.
I.e: once a rule is deemed to apply, other hooks SHOULD NOT revert this value to false.

Cf. this code from `amp_resolver`:
Expand All @@ -63,14 +63,14 @@ check_condition(HookAcc, Strategy, Condition, Value) ->

### Medium

* Implement the security policy described in the third bullet point of XEP-0079, Section 9 (Security Considerations).
This will require that `amp_resolver:verify_support` also take the `{From, To, Packet} :: hook_data()` parameter and check that `From` is permitted to know about `To`'s presence.
* Implement the security policy described in the third bullet point of XEP-0079, Section 9 (Security Considerations).
This will require that `amp_resolver:verify_support` also take the `{From, To, Packet} :: hook_data()` parameter and check that `From` is permitted to know about `To`'s presence.
If they are not, then the server should treat this as a `not-acceptable` amp request.

* Make support for various actions, conditions and values configurable.
This will require implementing an intelligent mechanism for matching the user-supplied rules with what's configured server-side.
This will require implementing an intelligent mechanism for matching the user-supplied rules with what's configured server-side.
Currently, server-side support is hard-coded in several places:

1. Disco announcements are in `mod_amp:amp_features/0`
2. Rule support is in `amp_resolver:verify_rule_support/1`
3. Every other function that deals with rules can handle unsupported rules, but ignores their meaning and decides that these rules don't apply.
Expand Down
32 changes: 32 additions & 0 deletions rebar.config
Expand Up @@ -15,6 +15,38 @@
deprecated_function_calls,
deprecated_functions]}.

{xref_ignores, [
eldap_filter_yecc, 'XmppAddr', mongoose_xmpp_errors,
%% *_backend
mongoose_rdbms_backend, mod_vcard_backend,
ejabberd_sm_backend, mod_auth_token_backend,
mod_bosh_backend, mod_event_pusher_push_backend,
mod_global_distrib_mapping_backend, mod_http_upload_backend,
mod_inbox_backend, mod_keystore_backend,
mod_last_backend, mod_mam_cassandra_arch_params,
mod_mam_cassandra_prefs_params, mod_mam_muc_cassandra_arch_params,
mod_muc_db_backend, mod_muc_light_codec_backend,
mod_muc_light_db_backend, mod_offline_backend,
mod_offline_chatmarkers_backend, mod_privacy_backend,
mod_private_backend, mod_pubsub_cache_backend,
mod_pubsub_db_backend, mod_revproxy_dynamic,
mod_roster_backend, mod_routing_machine,
mod_shared_roster, mod_smart_markers_backend, mongoose_rdbms_type,
%% Deprecated functions
{ssl, ssl_accept, 2}, % use ssl:handshake/2 instead
{crypto, rand_uniform, 2},
{ranch, start_listener, 6},
{ranch, accept_ack, 1},
{mongoose_lib, deprecated_logging, 1},
{crypto, hmac, 3},
{http_uri, parse, 1},
{http_uri, scheme_defaults, 0},
{pg2, get_members, 1},
{pg2, create, 1},
{pg2, join, 2},
{sys, get_debug, 3}
]}.

{port_specs,
[
{".*", "priv/lib/ejabberd_zlib_drv.so", ["c_src/ejabberd_zlib_drv.c"], [{env, [{"LDFLAGS", "$LDFLAGS -lz"}]}]},
Expand Down
2 changes: 2 additions & 0 deletions src/acl.erl
Expand Up @@ -35,6 +35,8 @@
match_rule_for_host_type/4,
match_rule_for_host_type/5]).

-ignore_xref([add/3, delete/3, match_rule/4]).

-include("mongoose.hrl").

-export_type([rule/0, host/0]).
Expand Down
6 changes: 6 additions & 0 deletions src/admin_extra/service_admin_extra_accounts.erl
Expand Up @@ -39,6 +39,12 @@
check_account/2,
check_password/3]).

-ignore_xref([
commands/0, set_password/3, check_password_hash/4,
delete_old_users/1, delete_old_users_for_domain/2,
ban_account/3, num_active_users/2, check_account/2, check_password/3
]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").
-include("jlib.hrl").
Expand Down
4 changes: 3 additions & 1 deletion src/admin_extra/service_admin_extra_gdpr.erl
Expand Up @@ -9,6 +9,8 @@
% Exported for RPC call
-export([retrieve_logs/2, get_data_from_modules/2]).

-ignore_xref([commands/0, retrieve_all/3, retrieve_logs/2, get_data_from_modules/2]).

-define(CMD_TIMEOUT, 300000).

-spec commands() -> [ejabberd_commands:cmd()].
Expand Down Expand Up @@ -45,7 +47,7 @@ retrieve_all(Username, Domain, ResultFilePath) ->
DataToWrite),

LogFiles = get_all_logs(Username, Domain, TmpDir),

ZipFile = binary_to_list(ResultFilePath),
{ok, ZipFile} = zip:create(ZipFile, CsvFiles ++ LogFiles, [{cwd, TmpDir}]),
remove_tmp_dir(TmpDir),
Expand Down
2 changes: 2 additions & 0 deletions src/admin_extra/service_admin_extra_last.erl
Expand Up @@ -31,6 +31,8 @@
set_last/4
]).

-ignore_xref([commands/0, set_last/4]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").
-include("mod_roster.hrl").
Expand Down
4 changes: 4 additions & 0 deletions src/admin_extra/service_admin_extra_node.erl
Expand Up @@ -34,6 +34,10 @@
remove_node/1
]).

-ignore_xref([
commands/0, load_config/1, get_cookie/0, remove_node/1
]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").

Expand Down
4 changes: 4 additions & 0 deletions src/admin_extra/service_admin_extra_private.erl
Expand Up @@ -32,6 +32,10 @@
private_set/3
]).

-ignore_xref([
commands/0, private_get/4, private_set/3
]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").
-include("jlib.hrl").
Expand Down
5 changes: 5 additions & 0 deletions src/admin_extra/service_admin_extra_roster.erl
Expand Up @@ -36,6 +36,11 @@
push_alltoall/2
]).

-ignore_xref([
commands/0, add_rosteritem/7, delete_rosteritem/4, process_rosteritems/5,
get_roster/2, push_roster/3, push_roster_all/1, push_alltoall/2
]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").
-include("mod_roster.hrl").
Expand Down
7 changes: 7 additions & 0 deletions src/admin_extra/service_admin_extra_sessions.erl
Expand Up @@ -42,6 +42,13 @@
user_sessions_info/2
]).

-ignore_xref([
commands/0, num_resources/2, resource_num/3, kick_session/2, kick_session/4,
prepare_reason/1, status_num/2, status_num/1, status_list/2, status_list/1,
connected_users_info/0, connected_users_info/1, set_presence/7,
user_sessions_info/2
]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").
-include("jlib.hrl").
Expand Down
13 changes: 13 additions & 0 deletions src/admin_extra/service_admin_extra_srg.erl
Expand Up @@ -38,6 +38,19 @@
srg_user_del/4
]).

-define(MOD_SHARED_ROSTER, mod_shared_roster).
-ignore_xref([
{?MOD_SHARED_ROSTER, create_group, 3},
{?MOD_SHARED_ROSTER, delete_group, 2},
{?MOD_SHARED_ROSTER, get_group_opts, 2},
{?MOD_SHARED_ROSTER, get_group_explicit_users, 2},
{?MOD_SHARED_ROSTER, list_groups, 1},
{?MOD_SHARED_ROSTER, add_user_to_group, 3},
{?MOD_SHARED_ROSTER, remove_user_from_group, 3},
commands/0, srg_create/5, srg_delete/2, srg_list/1, srg_get_info/2,
srg_get_members/2, srg_user_add/4, srg_user_del/4
]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").
-include("mod_roster.hrl").
Expand Down
2 changes: 2 additions & 0 deletions src/admin_extra/service_admin_extra_stanza.erl
Expand Up @@ -34,6 +34,8 @@
send_stanza_c2s/4
]).

-ignore_xref([commands/0, send_message_chat/3, send_message_headline/4, send_stanza_c2s/4]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").
-include("jlib.hrl").
Expand Down
2 changes: 2 additions & 0 deletions src/admin_extra/service_admin_extra_stats.erl
Expand Up @@ -33,6 +33,8 @@
stats/1, stats/2
]).

-ignore_xref([commands/0, stats/1, stats/2]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").

Expand Down
2 changes: 2 additions & 0 deletions src/admin_extra/service_admin_extra_upload.erl
Expand Up @@ -6,6 +6,8 @@

-export([commands/0, get_urls/5]).

-ignore_xref([commands/0, get_urls/5]).

-define(CMD_TIMEOUT, 300000).

-spec commands() -> [ejabberd_commands:cmd()].
Expand Down
2 changes: 2 additions & 0 deletions src/admin_extra/service_admin_extra_vcard.erl
Expand Up @@ -35,6 +35,8 @@
set_vcard/5
]).

-ignore_xref([commands/0, get_vcard/3, get_vcard/4, set_vcard/5, set_vcard/4, set_vcard/5]).

-include("mongoose.hrl").
-include("ejabberd_commands.hrl").
-include("mod_roster.hrl").
Expand Down
2 changes: 2 additions & 0 deletions src/amp.erl
Expand Up @@ -19,6 +19,8 @@
is_amp_request/1
]).

-ignore_xref([binaries_to_rule/3, is_amp_request/1, rule_to_xmlel/1]).

-export_type([amp_rule/0,
amp_rules/0]).

Expand Down
2 changes: 2 additions & 0 deletions src/amp_resolver.erl
Expand Up @@ -6,6 +6,8 @@
verify_support/2
]).

-ignore_xref([check_condition/3, verify_support/2]).

-include("amp.hrl").
-include("mongoose.hrl").
-include("jlib.hrl").
Expand Down
2 changes: 2 additions & 0 deletions src/amp_strategy.erl
Expand Up @@ -9,6 +9,8 @@
-export([determine_strategy/5,
null_strategy/0]).

-ignore_xref([determine_strategy/5]).

-include("amp.hrl").
-include("mongoose.hrl").
-include("jlib.hrl").
Expand Down
5 changes: 5 additions & 0 deletions src/auth/ejabberd_auth.erl
Expand Up @@ -64,6 +64,11 @@
-export([remove_domain/3]).
-export([does_user_exist/4]).

-ignore_xref([
auth_methods/1, auth_modules/1, check_password/4, does_user_exist/4,
get_vh_registered_users/2, get_vh_registered_users_number/2,
remove_domain/3, start/1, stop/1]).

-include("mongoose.hrl").
-include("jlib.hrl").

Expand Down
3 changes: 3 additions & 0 deletions src/auth/ejabberd_auth_anonymous.erl
Expand Up @@ -50,6 +50,9 @@
-export([check_password/4,
check_password/6]).

-ignore_xref([register_connection/5, session_cleanup/5, unregister_connection/5,
login/3]).

-include("mongoose.hrl").
-include("jlib.hrl").
-include("session.hrl").
Expand Down
2 changes: 2 additions & 0 deletions src/auth/ejabberd_auth_dummy.erl
Expand Up @@ -21,6 +21,8 @@
supports_sasl_module/2,
scram_passwords/0]).

-ignore_xref([scram_passwords/0]).

-include("mongoose.hrl").

%%%----------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/auth/ejabberd_auth_internal.erl
Expand Up @@ -53,6 +53,8 @@
%% Utilities
-export([dirty_get_registered_users/0]).

-ignore_xref([dirty_get_registered_users/0, scram_passwords/0]).

-include("mongoose.hrl").
-include("scram.hrl").

Expand Down
2 changes: 2 additions & 0 deletions src/auth/ejabberd_auth_ldap.erl
Expand Up @@ -52,6 +52,8 @@
-export([check_password/4,
check_password/6]).

-ignore_xref([start_link/1]).

-include("mongoose.hrl").
-include("eldap.hrl").

Expand Down
2 changes: 2 additions & 0 deletions src/auth/ejabberd_auth_rdbms.erl
Expand Up @@ -50,6 +50,8 @@

-export([scram_passwords/2, scram_passwords/4]).

-ignore_xref([scram_passwords/2, scram_passwords/4]).

-import(mongoose_rdbms, [prepare/4, execute_successfully/3]).

-include("mongoose.hrl").
Expand Down
2 changes: 2 additions & 0 deletions src/auth/mongoose_gen_auth.erl
Expand Up @@ -18,6 +18,8 @@
remove_user/4,
remove_domain/3]).

-ignore_xref([behaviour_info/1]).

%% Mandatory callbacks

-callback start(HostType :: mongooseim:host_type()) -> ok.
Expand Down
5 changes: 3 additions & 2 deletions src/backend_module.erl
Expand Up @@ -26,8 +26,9 @@
-author('alexey@process-one.net').
-author('konrad.zemek@erlang-solutions.com').

-export([create/2, create/3]).
-export([backend_module/2]).
-export([create/2, backend_module/2, create/3]).

-ignore_xref([create/2, backend_module/2, behaviour_info/1]).

%% Callback implemented by proxy modules.
-callback backend() -> module().
Expand Down
3 changes: 3 additions & 0 deletions src/cassandra/mongoose_cassandra.erl
Expand Up @@ -51,6 +51,9 @@
-export([prepared_queries/0, total_count_query_cql/1, test_query_sql/0]).
-export([test_query/1, test_query/2, total_count_query/2]).

-ignore_xref([behaviour_info/1, prepared_queries/0, test_query/1, test_query/2,
test_query_sql/0, total_count_query/2, total_count_query_cql/1]).

%% Types
-export_type([pool_name/0, query_name/0]).
-export_type([row/0, rows/0, parameters/0, fold_fun/0, fold_accumulator/0]).
Expand Down

0 comments on commit 0790218

Please sign in to comment.