From 8e6a3010266acfafc8d9e4e64f3335d5621dad36 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 7 Mar 2016 14:47:42 +0100 Subject: [PATCH] Fixed type specifications for 'rebar doc' - Fixed type @specs and -specs to remove 'rebar doc' errors - Removed a lot of wrong and deprecated documentation in ejabberd_piefxis.erl --- src/ejabberd_auth_external.erl | 4 +- src/ejabberd_config.erl | 2 +- src/ejabberd_logger.erl | 6 +++ src/ejabberd_piefxis.erl | 81 ---------------------------------- src/mod_pubsub.erl | 16 ++++++- 5 files changed, 23 insertions(+), 86 deletions(-) diff --git a/src/ejabberd_auth_external.erl b/src/ejabberd_auth_external.erl index 2a1cbf085..2944ac3f3 100644 --- a/src/ejabberd_auth_external.erl +++ b/src/ejabberd_auth_external.erl @@ -222,7 +222,7 @@ check_password_cache(User, Server, Password, get_password_internal(User, Server) -> ejabberd_auth_internal:get_password(User, Server). -%% @spec (User, Server, CacheTime) -> false | Password::string() +-spec get_password_cache(User::binary(), Server::binary(), CacheTime::integer()) -> Password::string() | false. get_password_cache(User, Server, CacheTime) -> case get_last_access(User, Server) of online -> get_password_internal(User, Server); @@ -273,10 +273,10 @@ is_fresh_enough(TimeStampLast, CacheTime) -> Now = p1_time_compat:system_time(seconds), TimeStampLast + CacheTime > Now. -%% @spec (User, Server) -> online | never | mod_last_required | TimeStamp::integer() %% Code copied from mod_configure.erl %% Code copied from web/ejabberd_web_admin.erl %% TODO: Update time format to XEP-0202: Entity Time +-spec(get_last_access(User::binary(), Server::binary()) -> (online | never | mod_last_required | integer())). get_last_access(User, Server) -> case ejabberd_sm:get_user_resources(User, Server) of [] -> diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl index 1f2eaa142..c500ee4ea 100644 --- a/src/ejabberd_config.erl +++ b/src/ejabberd_config.erl @@ -112,7 +112,7 @@ get_env_config() -> %% @doc Read the ejabberd configuration file. %% It also includes additional configuration files and replaces macros. %% This function will crash if finds some error in the configuration file. -%% @spec (File::string()) -> #state{}. +%% @spec (File::string()) -> #state{} read_file(File) -> read_file(File, [{replace_macros, true}, {include_files, true}, diff --git a/src/ejabberd_logger.erl b/src/ejabberd_logger.erl index 05499b45c..605b1d633 100644 --- a/src/ejabberd_logger.erl +++ b/src/ejabberd_logger.erl @@ -50,6 +50,7 @@ %% "ejabberd.log" in current directory. %% Note: If the directory where to place the ejabberd log file to not exist, %% it is not created and no log file will be generated. +%% @spec () -> string() get_log_path() -> case ejabberd_config:env_binary_to_list(ejabberd, log_path) of {ok, Path} -> @@ -99,6 +100,7 @@ get_string_env(Name, Default) -> Default end. +%% @spec () -> ok start() -> application:load(sasl), application:set_env(sasl, sasl_error_logger, false), @@ -126,10 +128,12 @@ start() -> ejabberd:start_app(lager), ok. +%% @spec () -> ok reopen_log() -> %% Lager detects external log rotation automatically. ok. +%% @spec () -> ok rotate_log() -> lager_crash_log ! rotate, lists:foreach( @@ -139,6 +143,7 @@ rotate_log() -> ok end, gen_event:which_handlers(lager_event)). +%% @spec () -> {loglevel(), atom(), string()} get() -> case lager:get_loglevel(lager_console_backend) of none -> {0, no_log, "No log"}; @@ -152,6 +157,7 @@ get() -> debug -> {5, debug, "Debug"} end. +%% @spec (loglevel() | {loglevel(), list()}) -> {module, module()} set(LogLevel) when is_integer(LogLevel) -> LagerLogLevel = case LogLevel of 0 -> none; diff --git a/src/ejabberd_piefxis.erl b/src/ejabberd_piefxis.erl index 028a8a8b3..123189dde 100644 --- a/src/ejabberd_piefxis.erl +++ b/src/ejabberd_piefxis.erl @@ -80,7 +80,6 @@ import_file(FileName) -> import_file(FileName, #state{}). -spec import_file(binary(), state()) -> ok | {error, atom()}. - import_file(FileName, State) -> case file:open(FileName, [read, binary]) of {ok, Fd} -> @@ -97,72 +96,14 @@ import_file(FileName, State) -> {error, Reason} end. -%%%================================== -%%%% Process Elements -%%%================================== -%%%% Process Element -%%%================================== -%%%% Add user -%% @spec (El::xmlel(), Domain::string(), User::binary(), Password::binary() | none) -%% -> ok | {error, ErrorText::string()} -%% @doc Add a new user to the database. -%% If user already exists, it will be only updated. -spec export_server(binary()) -> any(). - -%% @spec (User::string(), Password::string(), Domain::string()) -%% -> ok | {atomic, exists} | {error, not_allowed} -%% @doc Create a new user export_server(Dir) -> export_hosts(?MYHOSTS, Dir). -%%%================================== -%%%% Populate user -%% @spec (User::string(), Domain::string(), El::xml()) -%% -> ok | {error, not_found} -%% -%% @doc Add a new user from a XML file with a roster list. -%% -%% Example of a file: -%% ``` -%% -%% -%% -%% -%% -%% -%% Friends -%% -%% -%% -%% -%% -%% ''' -spec export_host(binary(), binary()) -> any(). - export_host(Dir, Host) -> export_hosts([Host], Dir). -%% @spec User = String with the user name -%% Domain = String with a domain name -%% El = Sub XML element with vCard tags values -%% @ret ok | {error, not_found} -%% @doc Read vcards from the XML and send it to the server -%% -%% Example: -%% ``` -%% -%% -%% -%% -%% -%% Admin -%% -%% -%% -%% -%% ''' %%%=================================================================== %%% Internal functions %%%=================================================================== @@ -194,11 +135,6 @@ export_hosts(Hosts, Dir) -> {error, Reason} end. -%% @spec User = String with the user name -%% Domain = String with a domain name -%% El = Sub XML element with offline messages values -%% @ret ok | {error, not_found} -%% @doc Read off-line message from the XML and send it to the server export_host(Dir, FnH, Host) -> DFn = make_host_basefilename(Dir, FnH), case file:open(DFn, [raw, write]) of @@ -223,11 +159,6 @@ export_host(Dir, FnH, Host) -> {error, Reason} end. -%% @spec User = String with the user name -%% Domain = String with a domain name -%% El = Sub XML element with private storage values -%% @ret ok | {error, not_found} -%% @doc Private storage parsing export_users([{User, _S}|Users], Server, Fd) -> case export_user(User, Server, Fd) of ok -> @@ -238,8 +169,6 @@ export_users([{User, _S}|Users], Server, Fd) -> export_users([], _Server, _Fd) -> ok. -%%%================================== -%%%% Utilities export_user(User, Server, Fd) -> Password = ejabberd_auth:get_password_s(User, Server), LServer = jid:nameprep(Server), @@ -289,7 +218,6 @@ get_vcard(User, Server) -> [] end. -%%%================================== get_offline(User, Server) -> case mod_offline:get_offline_els(User, Server) of [] -> @@ -306,7 +234,6 @@ get_offline(User, Server) -> [#xmlel{name = <<"offline-messages">>, children = NewEls}] end. -%%%% Export hosts get_privacy(User, Server) -> case mod_privacy:get_user_lists(User, Server) of {ok, #privacy{default = Default, @@ -333,7 +260,6 @@ get_privacy(User, Server) -> [] end. -%% @spec (Dir::string(), Hosts::[string()]) -> ok get_roster(User, Server) -> JID = jid:make(User, Server, <<>>), case mod_roster:get_roster(User, Server) of @@ -576,8 +502,6 @@ process_roster(El, State = #state{user = U, server = S}) -> stop("Failed to write roster: ~p", [Err]) end. -%%%================================== -%%%% Export server process_privacy(El, State = #state{user = U, server = S}) -> JID = jid:make(U, S, <<"">>), case mod_privacy:process_iq_set( @@ -603,7 +527,6 @@ process_privacy(El, State = #state{user = U, server = S}) -> {ok, State} end. -%% @spec (Dir::string()) -> ok process_private(El, State = #state{user = U, server = S}) -> JID = jid:make(U, S, <<"">>), case mod_private:process_sm_iq( @@ -614,8 +537,6 @@ process_private(El, State = #state{user = U, server = S}) -> stop("Failed to write private: ~p", [Err]) end. -%%%================================== -%%%% Export host process_vcard(El, State = #state{user = U, server = S}) -> JID = jid:make(U, S, <<"">>), case mod_vcard:process_sm_iq( @@ -626,7 +547,6 @@ process_vcard(El, State = #state{user = U, server = S}) -> stop("Failed to write vcard: ~p", [Err]) end. -%% @spec (Dir::string(), Host::string()) -> ok process_offline_msg(El, State = #state{user = U, server = S}) -> FromS = fxml:get_attr_s(<<"from">>, El#xmlel.attrs), case jid:from_string(FromS) of @@ -643,7 +563,6 @@ process_offline_msg(El, State = #state{user = U, server = S}) -> stop("Invalid 'from' = ~s", [FromS]) end. -%% @spec (Dir::string(), Fn::string(), Host::string()) -> ok process_presence(El, #state{user = U, server = S} = State) -> FromS = fxml:get_attr_s(<<"from">>, El#xmlel.attrs), case jid:from_string(FromS) of diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index f1f60f2cf..61546353f 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -1775,6 +1775,20 @@ update_auth(Host, Node, Type, Nidx, Subscriber, Allow, Subs) -> %%
  • nodetree create_node checks if nodeid already exists
  • %%
  • node plugin create_node just sets default affiliation/subscription
  • %% +-spec(create_node/5 :: + ( + Host :: mod_pubsub:host(), + ServerHost :: binary(), + Node :: <<>> | mod_pubsub:nodeId(), + Owner :: jid(), + Type :: binary()) + -> {result, [xmlel(),...]} + %%% + | {error, xmlel()} + ). +create_node(Host, ServerHost, Node, Owner, Type) -> + create_node(Host, ServerHost, Node, Owner, Type, all, []). + -spec(create_node/7 :: ( Host :: mod_pubsub:host(), @@ -1788,8 +1802,6 @@ update_auth(Host, Node, Type, Nidx, Subscriber, Allow, Subs) -> %%% | {error, xmlel()} ). -create_node(Host, ServerHost, Node, Owner, Type) -> - create_node(Host, ServerHost, Node, Owner, Type, all, []). create_node(Host, ServerHost, <<>>, Owner, Type, Access, Configuration) -> case lists:member(<<"instant-nodes">>, plugin_features(Host, Type)) of true ->