<commit_before>%%==============================================================================
%% Copyright 2010 Erlang Solutions Ltd.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%==============================================================================

%% Note: This module requires ejabberd_node and ejabberd_cookie
%%       to be set if common test configuration file

-module(escalus_ejabberd).

-behaviour(escalus_user_db).
%% escalus_user_db callbacks
-export([start/1,
         stop/1,
         create_users/1,
         create_users/2,
         delete_users/1,
         delete_users/2]).

-export([rpc/3,
         remote_display/1,
         remote_format/1,
         remote_format/2,
         get_global_option/1,
         with_global_option/3,
         with_local_option/3,
         get_c2s_status/1,
         get_remote_sessions/1,
         default_get_remote_sessions/0,
         legacy_get_remote_sessions/0,
         unify_str_arg/1,
         unify_str_arg/2,
         wait_for_session_count/2,
         setup_option/2,
         reset_option/2]).


-include("include/escalus.hrl").


%%%
%%% Escalus_users API
%%%

start(_Opts) -> ok.
stop(_Opts) -> ok.

create_users(Config) ->
    create_users(Config, all).

create_users(Config, Who) ->
    AllUsers = escalus_users:get_users(Who),
    lists:foreach(fun({_Name, UserSpec}) ->
        register_user(Config, UserSpec)
    end, AllUsers),
    Config.

delete_users(Config) ->
    AllUsers = escalus_config:get_config(escalus_users, Config),
    lists:foreach(fun({_Name, UserSpec}) ->
        unregister_user(Config, UserSpec)
    end, AllUsers).

delete_users(Config, Who) when is_atom(Who); is_tuple(Who) ->
    Users = escalus_users:get_users(Who),
    delete_users(Config, Users);

delete_users(Config, Users) ->
    lists:foreach(fun({_Name, UserSpec}) ->
        unregister_user(Config, UserSpec)
    end, Users).


%%%
%%% Business API
%%%

rpc(M, F, A) ->
    Node = escalus_ct:get_config(ejabberd_node),
    Cookie = escalus_ct:get_config(ejabberd_cookie),
    escalus_ct:rpc_call(Node, M, F, A, 3000, Cookie).

remote_display(String) ->
    Line = [$\n, [$- || _ <- String], $\n],
    remote_format("~s~s~s", [Line, String, Line]).<commit_msg>add check if the tested server is MongooseIM<commit_after>%%==============================================================================
%% Copyright 2010 Erlang Solutions Ltd.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%==============================================================================

%% Note: This module requires ejabberd_node and ejabberd_cookie
%%       to be set if common test configuration file

-module(escalus_ejabberd).

-behaviour(escalus_user_db).
%% escalus_user_db callbacks
-export([start/1,
         stop/1,
         create_users/1,
         create_users/2,
         delete_users/1,
         delete_users/2]).

-export([rpc/3,
         is_mongoose/0,
         remote_display/1,
         remote_format/1,
         remote_format/2,
         get_global_option/1,
         with_global_option/3,
         with_local_option/3,
         get_c2s_status/1,
         get_remote_sessions/1,
         default_get_remote_sessions/0,
         legacy_get_remote_sessions/0,
         unify_str_arg/1,
         unify_str_arg/2,
         wait_for_session_count/2,
         setup_option/2,
         reset_option/2]).


-include("include/escalus.hrl").


%%%
%%% Escalus_users API
%%%

start(_Opts) -> ok.
stop(_Opts) -> ok.

create_users(Config) ->
    create_users(Config, all).

create_users(Config, Who) ->
    AllUsers = escalus_users:get_users(Who),
    lists:foreach(fun({_Name, UserSpec}) ->
        register_user(Config, UserSpec)
    end, AllUsers),
    Config.

delete_users(Config) ->
    AllUsers = escalus_config:get_config(escalus_users, Config),
    lists:foreach(fun({_Name, UserSpec}) ->
        unregister_user(Config, UserSpec)
    end, AllUsers).

delete_users(Config, Who) when is_atom(Who); is_tuple(Who) ->
    Users = escalus_users:get_users(Who),
    delete_users(Config, Users);

delete_users(Config, Users) ->
    lists:foreach(fun({_Name, UserSpec}) ->
        unregister_user(Config, UserSpec)
    end, Users).


%%%
%%% Business API
%%%

rpc(M, F, A) ->
    Node = escalus_ct:get_config(ejabberd_node),
    Cookie = escalus_ct:get_config(ejabberd_cookie),
    escalus_ct:rpc_call(Node, M, F, A, 3000, Cookie).

is_mongoose() ->
    Apps = escalus_ejabberd:rpc(application, loaded_applications, []),
    lists:keymember(mongooseim, 1, Apps).

remote_display(String) ->
    Line = [$\n, [$- || _ <- String], $\n],
    remote_format("~s~s~s", [Line, String, Line]).
{'fraction_non_alphanumeric': 0.17250530785562632, 'fraction_numerical': 0.012738853503184714, 'mean_word_length': 3.500796178343949, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4478591', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1779, 'n_words': 408}