25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Fix compilation issues on R19

This commit is contained in:
Paweł Chmielowski 2016-07-01 21:18:55 +02:00
parent 024124decb
commit 0737958b45
10 changed files with 199 additions and 538 deletions

View File

@ -7,12 +7,12 @@
%%% Created : 1 May 2013 by Evgeniy Khramtsov <ekhramtsov@process-one.net> %%% Created : 1 May 2013 by Evgeniy Khramtsov <ekhramtsov@process-one.net>
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
{deps, [{lager, ".*", {git, "https://github.com/basho/lager", {tag, "3.0.2"}}}, {deps, [{lager, ".*", {git, "https://github.com/basho/lager", {tag, "3.2.1"}}},
{p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.4"}}}, {p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.4"}}},
{cache_tab, ".*", {git, "https://github.com/processone/cache_tab", {tag, "1.0.3"}}}, {cache_tab, ".*", {git, "https://github.com/processone/cache_tab", {tag, "1.0.3"}}},
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.5"}}}, {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.5"}}},
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.4"}}}, {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.4"}}},
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.13"}}}, {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.14"}}},
{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.5"}}}, {stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.5"}}},
{esip, ".*", {git, "https://github.com/processone/esip", {tag, "1.0.6"}}}, {esip, ".*", {git, "https://github.com/processone/esip", {tag, "1.0.6"}}},
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.4"}}}, {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.4"}}},
@ -34,7 +34,7 @@
"527722d12d0433b837cdb92a60900c2cb5df8942"}}}, "527722d12d0433b837cdb92a60900c2cb5df8942"}}},
%% Forces correct dependency for riakc and allow using newer meck version) %% Forces correct dependency for riakc and allow using newer meck version)
{if_var_true, riak, {hamcrest, ".*", {git, "https://github.com/hyperthunk/hamcrest-erlang", {if_var_true, riak, {hamcrest, ".*", {git, "https://github.com/hyperthunk/hamcrest-erlang",
"908a24fda4a46776a5135db60ca071e3d783f9f6"}}}, % for riak_pb-2.1.0.7 "13f9bfb9b27d216e8e033b0e0a9a29097ed923dd"}}}, % for riak_pb-2.1.0.7
{if_var_true, riak, {protobuffs, ".*", {git, "https://github.com/basho/erlang_protobuffs", {if_var_true, riak, {protobuffs, ".*", {git, "https://github.com/basho/erlang_protobuffs",
"6e7fc924506e2dc166a6170e580ce1d95ebbd5bd"}}}, % for riak_pb-2.1.0.7 with correct meck dependency "6e7fc924506e2dc166a6170e580ce1d95ebbd5bd"}}}, % for riak_pb-2.1.0.7 with correct meck dependency
%% Elixir support, needed to run tests %% Elixir support, needed to run tests

View File

@ -41,13 +41,7 @@
%% Parse an ad-hoc request. Return either an adhoc_request record or %% Parse an ad-hoc request. Return either an adhoc_request record or
%% an {error, ErrorType} tuple. %% an {error, ErrorType} tuple.
%% %%
-spec(parse_request/1 :: -spec parse_request(IQ :: iq_request()) -> adhoc_response() | {error, _}.
(
IQ :: iq_request())
-> adhoc_response()
%%
| {error, _}
).
parse_request(#iq{type = set, lang = Lang, sub_el = SubEl, xmlns = ?NS_COMMANDS}) -> parse_request(#iq{type = set, lang = Lang, sub_el = SubEl, xmlns = ?NS_COMMANDS}) ->
?DEBUG("entering parse_request...", []), ?DEBUG("entering parse_request...", []),
@ -88,12 +82,9 @@ find_xdata_el1([_ | Els]) -> find_xdata_el1(Els).
%% record, filling in values for language, node and session id from %% record, filling in values for language, node and session id from
%% the request. %% the request.
%% %%
-spec(produce_response/2 :: -spec produce_response(Adhoc_Request :: adhoc_request(),
( Adhoc_Response :: adhoc_response()) ->
Adhoc_Request :: adhoc_request(), Xmlel::xmlel().
Adhoc_Response :: adhoc_response())
-> Xmlel::xmlel()
).
%% Produce a <command/> node to use as response from an adhoc_response %% Produce a <command/> node to use as response from an adhoc_response
%% record. %% record.
@ -104,11 +95,7 @@ produce_response(#adhoc_request{lang = Lang, node = Node, sessionid = SessionID}
}). }).
%% %%
-spec(produce_response/1 :: -spec produce_response(Adhoc_Response::adhoc_response()) -> Xmlel::xmlel().
(
Adhoc_Response::adhoc_response())
-> Xmlel::xmlel()
).
produce_response( produce_response(
#adhoc_response{ #adhoc_response{

View File

@ -88,13 +88,8 @@ start() ->
ok. ok.
%% %%
-spec(register_mechanism/3 :: -spec register_mechanism(Mechanim :: mechanism(), Module :: module(),
( PasswordType :: password_type()) -> any().
Mechanim :: mechanism(),
Module :: module(),
PasswordType :: password_type())
-> any()
).
register_mechanism(Mechanism, Module, PasswordType) -> register_mechanism(Mechanism, Module, PasswordType) ->
case is_disabled(Mechanism) of case is_disabled(Mechanism) of
@ -139,11 +134,7 @@ check_credentials(_State, Props) ->
_LUser -> ok _LUser -> ok
end. end.
-spec(listmech/1 :: -spec listmech(Host ::binary()) -> Mechanisms::mechanisms().
(
Host ::binary())
-> Mechanisms::mechanisms()
).
listmech(Host) -> listmech(Host) ->
Mechs = ets:select(sasl_mechanism, Mechs = ets:select(sasl_mechanism,
@ -213,12 +204,7 @@ server_step(State, ClientIn) ->
%% Remove the anonymous mechanism from the list if not enabled for the given %% Remove the anonymous mechanism from the list if not enabled for the given
%% host %% host
%% %%
-spec(filter_anonymous/2 :: -spec filter_anonymous(Host :: binary(), Mechs :: mechanisms()) -> mechanisms().
(
Host :: binary(),
Mechs :: mechanisms())
-> mechanisms()
).
filter_anonymous(Host, Mechs) -> filter_anonymous(Host, Mechs) ->
case ejabberd_auth_anonymous:is_sasl_anonymous_enabled(Host) of case ejabberd_auth_anonymous:is_sasl_anonymous_enabled(Host) of
@ -226,11 +212,7 @@ filter_anonymous(Host, Mechs) ->
false -> Mechs -- [<<"ANONYMOUS">>] false -> Mechs -- [<<"ANONYMOUS">>]
end. end.
-spec(is_disabled/1 :: -spec is_disabled(Mechanism :: mechanism()) -> boolean().
(
Mechanism :: mechanism())
-> boolean()
).
is_disabled(Mechanism) -> is_disabled(Mechanism) ->
Disabled = ejabberd_config:get_option( Disabled = ejabberd_config:get_option(

View File

@ -90,7 +90,7 @@ hosts_to_start(State) ->
%% @private %% @private
%% At the moment, these functions are mainly used to setup unit tests. %% At the moment, these functions are mainly used to setup unit tests.
-spec(start/2 :: (Hosts :: [binary()], Opts :: [acl:acl() | local_config()]) -> ok). -spec start(Hosts :: [binary()], Opts :: [acl:acl() | local_config()]) -> ok.
start(Hosts, Opts) -> start(Hosts, Opts) ->
mnesia_init(), mnesia_init(),
set_opts(set_hosts_in_options(Hosts, #state{opts = Opts})). set_opts(set_hosts_in_options(Hosts, #state{opts = Opts})).

View File

@ -307,21 +307,16 @@ get_iq_namespace(#xmlel{name = <<"iq">>, children = Els}) ->
get_iq_namespace(_) -> <<"">>. get_iq_namespace(_) -> <<"">>.
%% %%
-spec(iq_query_info/1 :: -spec iq_query_info(Xmlel :: xmlel()) ->
( iq_request() | 'reply' | 'invalid' | 'not_iq'.
Xmlel :: xmlel())
-> iq_request() | 'reply' | 'invalid' | 'not_iq'
).
%% @spec (xmlelement()) -> iq() | reply | invalid | not_iq %% @spec (xmlelement()) -> iq() | reply | invalid | not_iq
iq_query_info(El) -> iq_info_internal(El, request). iq_query_info(El) -> iq_info_internal(El, request).
%% %%
-spec(iq_query_or_response_info/1 :: -spec iq_query_or_response_info(Xmlel :: xmlel()) ->
( iq_request() | iq_reply() |
Xmlel :: xmlel()) 'reply' | 'invalid' | 'not_iq'.
-> iq_request() | iq_reply() | 'reply' | 'invalid' | 'not_iq'
).
iq_query_or_response_info(El) -> iq_query_or_response_info(El) ->
iq_info_internal(El, any). iq_info_internal(El, any).
@ -373,11 +368,7 @@ iq_type_to_string(get) -> <<"get">>;
iq_type_to_string(result) -> <<"result">>; iq_type_to_string(result) -> <<"result">>;
iq_type_to_string(error) -> <<"error">>. iq_type_to_string(error) -> <<"error">>.
-spec(iq_to_xml/1 :: -spec iq_to_xml(IQ :: iq()) -> xmlel().
(
IQ :: iq())
-> xmlel()
).
iq_to_xml(#iq{id = ID, type = Type, sub_el = SubEl}) -> iq_to_xml(#iq{id = ID, type = Type, sub_el = SubEl}) ->
if ID /= <<"">> -> if ID /= <<"">> ->
@ -391,13 +382,8 @@ iq_to_xml(#iq{id = ID, type = Type, sub_el = SubEl}) ->
children = SubEl} children = SubEl}
end. end.
-spec(parse_xdata_submit/1 :: -spec parse_xdata_submit(El :: xmlel()) ->
( [{Var::binary(), Values::[binary()]}] | 'invalid'.
El :: xmlel())
-> [{Var::binary(), Values::[binary()]}]
%%
| 'invalid'
).
parse_xdata_submit(#xmlel{attrs = Attrs, children = Els}) -> parse_xdata_submit(#xmlel{attrs = Attrs, children = Els}) ->
case fxml:get_attr_s(<<"type">>, Attrs) of case fxml:get_attr_s(<<"type">>, Attrs) of
@ -409,12 +395,9 @@ parse_xdata_submit(#xmlel{attrs = Attrs, children = Els}) ->
invalid invalid
end. end.
-spec(parse_xdata_fields/2 :: -spec parse_xdata_fields(Xmlels :: [xmlel() | cdata()],
( Res :: [{Var::binary(), Values :: [binary()]}]) ->
Xmlels :: [xmlel() | cdata()], [{Var::binary(), Values::[binary()]}].
Res :: [{Var::binary(), Values :: [binary()]}])
-> [{Var::binary(), Values::[binary()]}]
).
parse_xdata_fields([], Res) -> Res; parse_xdata_fields([], Res) -> Res;
parse_xdata_fields([#xmlel{name = <<"field">>, attrs = Attrs, children = SubEls} parse_xdata_fields([#xmlel{name = <<"field">>, attrs = Attrs, children = SubEls}
@ -429,12 +412,8 @@ parse_xdata_fields([#xmlel{name = <<"field">>, attrs = Attrs, children = SubEls}
parse_xdata_fields([_ | Els], Res) -> parse_xdata_fields([_ | Els], Res) ->
parse_xdata_fields(Els, Res). parse_xdata_fields(Els, Res).
-spec(parse_xdata_values/2 :: -spec parse_xdata_values(Xmlels :: [xmlel() | cdata()],
( Res :: [binary()]) -> [binary()].
Xmlels :: [xmlel() | cdata()],
Res :: [binary()])
-> [binary()]
).
parse_xdata_values([], Res) -> Res; parse_xdata_values([], Res) -> Res;
parse_xdata_values([#xmlel{name = <<"value">>, children = SubEls} | Els], Res) -> parse_xdata_values([#xmlel{name = <<"value">>, children = SubEls} | Els], Res) ->

View File

@ -234,11 +234,7 @@ stop(Host) ->
%% {stop, Reason} %% {stop, Reason}
%% Description: Initiates the server %% Description: Initiates the server
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec(init/1 :: -spec init([binary() | [{_,_}],...]) -> {'ok',state()}.
(
[binary() | [{_,_}],...])
-> {'ok',state()}
).
init([ServerHost, Opts]) -> init([ServerHost, Opts]) ->
?DEBUG("pubsub init ~p ~p", [ServerHost, Opts]), ?DEBUG("pubsub init ~p ~p", [ServerHost, Opts]),
@ -480,15 +476,10 @@ send_loop(State) ->
%% disco hooks handling functions %% disco hooks handling functions
%% %%
-spec(disco_local_identity/5 :: -spec disco_local_identity(Acc :: [xmlel()], _From :: jid(),
( To :: jid(), Node :: <<>> | mod_pubsub:nodeId(),
Acc :: [xmlel()], Lang :: binary()) -> [xmlel()].
_From :: jid(),
To :: jid(),
Node :: <<>> | mod_pubsub:nodeId(),
Lang :: binary())
-> [xmlel()]
).
disco_local_identity(Acc, _From, To, <<>>, _Lang) -> disco_local_identity(Acc, _From, To, <<>>, _Lang) ->
case lists:member(?PEPNODE, plugins(host(To#jid.lserver))) of case lists:member(?PEPNODE, plugins(host(To#jid.lserver))) of
true -> true ->
@ -502,15 +493,10 @@ disco_local_identity(Acc, _From, To, <<>>, _Lang) ->
disco_local_identity(Acc, _From, _To, _Node, _Lang) -> disco_local_identity(Acc, _From, _To, _Node, _Lang) ->
Acc. Acc.
-spec(disco_local_features/5 :: -spec disco_local_features(Acc :: [xmlel()], _From :: jid(),
( To :: jid(), Node :: <<>> | mod_pubsub:nodeId(),
Acc :: [xmlel()], Lang :: binary()) -> [binary(),...].
_From :: jid(),
To :: jid(),
Node :: <<>> | mod_pubsub:nodeId(),
Lang :: binary())
-> [binary(),...]
).
disco_local_features(Acc, _From, To, <<>>, _Lang) -> disco_local_features(Acc, _From, To, <<>>, _Lang) ->
Host = host(To#jid.lserver), Host = host(To#jid.lserver),
Feats = case Acc of Feats = case Acc of
@ -528,15 +514,10 @@ disco_local_items(Acc, _From, _To, _Node, _Lang) -> Acc.
% when is_binary(Node) -> % when is_binary(Node) ->
% disco_sm_identity(Acc, From, To, iolist_to_binary(Node), % disco_sm_identity(Acc, From, To, iolist_to_binary(Node),
% Lang); % Lang);
-spec(disco_sm_identity/5 :: -spec disco_sm_identity(Acc :: empty | [xmlel()], From :: jid(),
( To :: jid(), Node :: mod_pubsub:nodeId(),
Acc :: empty | [xmlel()], Lang :: binary()) -> [xmlel()].
From :: jid(),
To :: jid(),
Node :: mod_pubsub:nodeId(),
Lang :: binary())
-> [xmlel()]
).
disco_sm_identity(empty, From, To, Node, Lang) -> disco_sm_identity(empty, From, To, Node, Lang) ->
disco_sm_identity([], From, To, Node, Lang); disco_sm_identity([], From, To, Node, Lang);
disco_sm_identity(Acc, From, To, Node, _Lang) -> disco_sm_identity(Acc, From, To, Node, _Lang) ->
@ -571,15 +552,9 @@ disco_identity(Host, Node, From) ->
_ -> [] _ -> []
end. end.
-spec(disco_sm_features/5 :: -spec disco_sm_features(Acc :: empty | {result, Features::[Feature::binary()]},
( From :: jid(), To :: jid(), Node :: mod_pubsub:nodeId(),
Acc :: empty | {result, Features::[Feature::binary()]}, Lang :: binary()) -> {result, Features::[Feature::binary()]}.
From :: jid(),
To :: jid(),
Node :: mod_pubsub:nodeId(),
Lang :: binary())
-> {result, Features::[Feature::binary()]}
).
%disco_sm_features(Acc, From, To, Node, Lang) %disco_sm_features(Acc, From, To, Node, Lang)
% when is_binary(Node) -> % when is_binary(Node) ->
% disco_sm_features(Acc, From, To, iolist_to_binary(Node), % disco_sm_features(Acc, From, To, iolist_to_binary(Node),
@ -607,15 +582,9 @@ disco_features(Host, Node, From) ->
_ -> [] _ -> []
end. end.
-spec(disco_sm_items/5 :: -spec disco_sm_items(Acc :: empty | {result, [xmlel()]}, From :: jid(),
( To :: jid(), Node :: mod_pubsub:nodeId(),
Acc :: empty | {result, [xmlel()]}, Lang :: binary()) -> {result, [xmlel()]}.
From :: jid(),
To :: jid(),
Node :: mod_pubsub:nodeId(),
Lang :: binary())
-> {result, [xmlel()]}
).
%disco_sm_items(Acc, From, To, Node, Lang) %disco_sm_items(Acc, From, To, Node, Lang)
% when is_binary(Node) -> % when is_binary(Node) ->
% disco_sm_items(Acc, From, To, iolist_to_binary(Node), % disco_sm_items(Acc, From, To, iolist_to_binary(Node),
@ -627,13 +596,8 @@ disco_sm_items({result, OtherItems}, From, To, Node, _Lang) ->
disco_items(jid:tolower(jid:remove_resource(To)), Node, From))}; disco_items(jid:tolower(jid:remove_resource(To)), Node, From))};
disco_sm_items(Acc, _From, _To, _Node, _Lang) -> Acc. disco_sm_items(Acc, _From, _To, _Node, _Lang) -> Acc.
-spec(disco_items/3 :: -spec disco_items(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( From :: jid()) -> [xmlel()].
Host :: mod_pubsub:host(),
Node :: mod_pubsub:nodeId(),
From :: jid())
-> [xmlel()]
).
disco_items(Host, <<>>, From) -> disco_items(Host, <<>>, From) ->
Action = fun (#pubsub_node{nodeid = {_, Node}, Action = fun (#pubsub_node{nodeid = {_, Node},
options = Options, type = Type, id = Nidx, owners = O}, options = Options, type = Type, id = Nidx, owners = O},
@ -847,12 +811,8 @@ handle_call(stop, _From, State) ->
%% @private %% @private
handle_cast(_Msg, State) -> {noreply, State}. handle_cast(_Msg, State) -> {noreply, State}.
-spec(handle_info/2 :: -spec handle_info(_ :: {route, From::jid(), To::jid(), Packet::xmlel()},
( State :: state()) -> {noreply, state()}.
_ :: {route, From::jid(), To::jid(), Packet::xmlel()},
State :: state())
-> {noreply, state()}
).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Function: handle_info(Info, State) -> {noreply, State} | %% Function: handle_info(Info, State) -> {noreply, State} |
@ -935,17 +895,9 @@ terminate(_Reason,
%% @private %% @private
code_change(_OldVsn, State, _Extra) -> {ok, State}. code_change(_OldVsn, State, _Extra) -> {ok, State}.
-spec(do_route/7 :: -spec do_route(ServerHost :: binary(), Access :: atom(),
( Plugins :: [binary(),...], Host :: mod_pubsub:hostPubsub(),
ServerHost :: binary(), From :: jid(), To :: jid(), Packet :: xmlel()) -> ok.
Access :: atom(),
Plugins :: [binary(),...],
Host :: mod_pubsub:hostPubsub(),
From :: jid(),
To :: jid(),
Packet :: xmlel())
-> ok
).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%%% Internal functions %%% Internal functions
@ -1132,14 +1084,8 @@ iq_disco_info(Host, SNode, From, Lang) ->
node_disco_info(Host, Node, From) node_disco_info(Host, Node, From)
end. end.
-spec(iq_disco_items/4 :: -spec iq_disco_items(Host :: mod_pubsub:host(), Node :: <<>> | mod_pubsub:nodeId(),
( From :: jid(), Rsm :: none | rsm_in()) -> {result, [xmlel()]}.
Host :: mod_pubsub:host(),
Node :: <<>> | mod_pubsub:nodeId(),
From :: jid(),
Rsm :: none | rsm_in())
-> {result, [xmlel()]}
).
iq_disco_items(Host, <<>>, From, _RSM) -> iq_disco_items(Host, <<>>, From, _RSM) ->
{result, {result,
lists:map(fun (#pubsub_node{nodeid = {_, SubNode}, options = Options}) -> lists:map(fun (#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
@ -1202,13 +1148,7 @@ iq_disco_items(Host, Item, From, RSM) ->
end end
end. end.
-spec(iq_sm/3 :: -spec iq_sm(From :: jid(), To :: jid(), IQ :: iq_request()) -> iq_result() | iq_error().
(
From :: jid(),
To :: jid(),
IQ :: iq_request())
-> iq_result() | iq_error()
).
iq_sm(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) -> iq_sm(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
ServerHost = To#jid.lserver, ServerHost = To#jid.lserver,
LOwner = jid:tolower(jid:remove_resource(To)), LOwner = jid:tolower(jid:remove_resource(To)),
@ -1233,36 +1173,17 @@ iq_get_vcard(Lang) ->
<<(translate:translate(Lang, <<"ejabberd Publish-Subscribe module">>))/binary, <<(translate:translate(Lang, <<"ejabberd Publish-Subscribe module">>))/binary,
"\nCopyright (c) 2004-2016 ProcessOne">>}]}]. "\nCopyright (c) 2004-2016 ProcessOne">>}]}].
-spec(iq_pubsub/6 :: -spec iq_pubsub(Host :: mod_pubsub:host(), ServerHost :: binary(), From :: jid(),
( IQType :: 'get' | 'set', SubEl :: xmlel(), Lang :: binary()) ->
Host :: mod_pubsub:host(), {result, [xmlel()]} | {error, xmlel()}.
ServerHost :: binary(),
From :: jid(),
IQType :: 'get' | 'set',
SubEl :: xmlel(),
Lang :: binary())
-> {result, [xmlel()]}
%%%
| {error, xmlel()}
).
iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang) -> iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang) ->
iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, all, plugins(Host)). iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, all, plugins(Host)).
-spec(iq_pubsub/8 :: -spec iq_pubsub(Host :: mod_pubsub:host(), ServerHost :: binary(), From :: jid(),
( IQType :: 'get' | 'set', SubEl :: xmlel(), Lang :: binary(),
Host :: mod_pubsub:host(), Access :: atom(), Plugins :: [binary(),...]) ->
ServerHost :: binary(), {result, [xmlel()]} | {error, xmlel()}.
From :: jid(),
IQType :: 'get' | 'set',
SubEl :: xmlel(),
Lang :: binary(),
Access :: atom(),
Plugins :: [binary(),...])
-> {result, [xmlel()]}
%%%
| {error, xmlel()}
).
iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) -> iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
#xmlel{children = SubEls} = SubEl, #xmlel{children = SubEls} = SubEl,
@ -1368,18 +1289,10 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
end. end.
-spec(iq_pubsub_owner/6 :: -spec iq_pubsub_owner(Host :: mod_pubsub:host(), ServerHost :: binary(), From :: jid(),
( IQType :: 'get' | 'set', SubEl :: xmlel(), Lang :: binary()) ->
Host :: mod_pubsub:host(), {result, [xmlel()]} | {error, xmlel()}.
ServerHost :: binary(),
From :: jid(),
IQType :: 'get' | 'set',
SubEl :: xmlel(),
Lang :: binary())
-> {result, [xmlel()]}
%%%
| {error, xmlel()}
).
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) -> iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
#xmlel{children = SubEls} = SubEl, #xmlel{children = SubEls} = SubEl,
Action = fxml:remove_cdata(SubEls), Action = fxml:remove_cdata(SubEls),
@ -1802,33 +1715,17 @@ update_auth(Host, Node, Type, Nidx, Subscriber, Allow, Subs) ->
%%<li>nodetree create_node checks if nodeid already exists</li> %%<li>nodetree create_node checks if nodeid already exists</li>
%%<li>node plugin create_node just sets default affiliation/subscription</li> %%<li>node plugin create_node just sets default affiliation/subscription</li>
%%</ul> %%</ul>
-spec(create_node/5 :: -spec create_node(Host :: mod_pubsub:host(), ServerHost :: binary(),
( Node :: <<>> | mod_pubsub:nodeId(), Owner :: jid(),
Host :: mod_pubsub:host(), Type :: binary()) -> {result, [xmlel(),...]} | {error, xmlel()}.
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) ->
create_node(Host, ServerHost, Node, Owner, Type, all, []). create_node(Host, ServerHost, Node, Owner, Type, all, []).
-spec(create_node/7 :: -spec create_node(Host :: mod_pubsub:host(), ServerHost :: binary(),
( Node :: <<>> | mod_pubsub:nodeId(), Owner :: jid(),
Host :: mod_pubsub:host(), Type :: binary(), Access :: atom(), Configuration :: [xmlel()]) ->
ServerHost :: binary(), {result, [xmlel(),...]} | {error, xmlel()}.
Node :: <<>> | mod_pubsub:nodeId(),
Owner :: jid(),
Type :: binary(),
Access :: atom(),
Configuration :: [xmlel()])
-> {result, [xmlel(),...]}
%%%
| {error, xmlel()}
).
create_node(Host, ServerHost, <<>>, Owner, Type, Access, Configuration) -> create_node(Host, ServerHost, <<>>, Owner, Type, Access, Configuration) ->
case lists:member(<<"instant-nodes">>, plugin_features(Host, Type)) of case lists:member(<<"instant-nodes">>, plugin_features(Host, Type)) of
true -> true ->
@ -1942,15 +1839,8 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) ->
%%<li>The node is the root collection node, which cannot be deleted.</li> %%<li>The node is the root collection node, which cannot be deleted.</li>
%%<li>The specified node does not exist.</li> %%<li>The specified node does not exist.</li>
%%</ul> %%</ul>
-spec(delete_node/3 :: -spec delete_node(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( Owner :: jid()) -> {result, [xmlel(),...]} | {error, xmlel()}.
Host :: mod_pubsub:host(),
Node :: mod_pubsub:nodeId(),
Owner :: jid())
-> {result, [xmlel(),...]}
%%%
| {error, xmlel()}
).
delete_node(_Host, <<>>, _Owner) -> delete_node(_Host, <<>>, _Owner) ->
{error, ?ERRT_NOT_ALLOWED(?MYLANG, <<"No node specified">>)}; {error, ?ERRT_NOT_ALLOWED(?MYLANG, <<"No node specified">>)};
delete_node(Host, Node, Owner) -> delete_node(Host, Node, Owner) ->
@ -2026,17 +1916,9 @@ delete_node(Host, Node, Owner) ->
%%<li>The node does not support subscriptions.</li> %%<li>The node does not support subscriptions.</li>
%%<li>The node does not exist.</li> %%<li>The node does not exist.</li>
%%</ul> %%</ul>
-spec(subscribe_node/5 :: -spec subscribe_node(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( From :: jid(), JID :: binary(), Configuration :: [xmlel()]) ->
Host :: mod_pubsub:host(), {result, [xmlel(),...]} | {error, xmlel()}.
Node :: mod_pubsub:nodeId(),
From :: jid(),
JID :: binary(),
Configuration :: [xmlel()])
-> {result, [xmlel(),...]}
%%%
| {error, xmlel()}
).
subscribe_node(Host, Node, From, JID, Configuration) -> subscribe_node(Host, Node, From, JID, Configuration) ->
SubModule = subscription_plugin(Host), SubModule = subscription_plugin(Host),
SubOpts = case SubModule:parse_options_xform(Configuration) of SubOpts = case SubModule:parse_options_xform(Configuration) of
@ -2145,17 +2027,11 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
%%<li>The node does not exist.</li> %%<li>The node does not exist.</li>
%%<li>The request specifies a subscription ID that is not valid or current.</li> %%<li>The request specifies a subscription ID that is not valid or current.</li>
%%</ul> %%</ul>
-spec(unsubscribe_node/5 :: -spec unsubscribe_node(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( From :: jid(), JID :: binary() | ljid(),
Host :: mod_pubsub:host(), SubId :: mod_pubsub:subId()) ->
Node :: mod_pubsub:nodeId(), {result, []} | {error, xmlel()}.
From :: jid(),
JID :: binary() | ljid(),
SubId :: mod_pubsub:subId())
-> {result, []}
%%%
| {error, xmlel()}
).
unsubscribe_node(Host, Node, From, JID, SubId) when is_binary(JID) -> unsubscribe_node(Host, Node, From, JID, SubId) when is_binary(JID) ->
unsubscribe_node(Host, Node, From, string_to_ljid(JID), SubId); unsubscribe_node(Host, Node, From, string_to_ljid(JID), SubId);
unsubscribe_node(Host, Node, From, Subscriber, SubId) -> unsubscribe_node(Host, Node, From, Subscriber, SubId) ->
@ -2183,18 +2059,12 @@ unsubscribe_node(Host, Node, From, Subscriber, SubId) ->
%%<li>The item contains more than one payload element or the namespace of the root payload element does not match the configured namespace for the node.</li> %%<li>The item contains more than one payload element or the namespace of the root payload element does not match the configured namespace for the node.</li>
%%<li>The request does not match the node configuration.</li> %%<li>The request does not match the node configuration.</li>
%%</ul> %%</ul>
-spec(publish_item/6 :: -spec publish_item(Host :: mod_pubsub:host(), ServerHost :: binary(),
( Node :: mod_pubsub:nodeId(), Publisher :: jid(),
Host :: mod_pubsub:host(), ItemId :: <<>> | mod_pubsub:itemId(),
ServerHost :: binary(), Payload :: mod_pubsub:payload()) ->
Node :: mod_pubsub:nodeId(), {result, [xmlel(),...]} | {error, xmlel()}.
Publisher :: jid(),
ItemId :: <<>> | mod_pubsub:itemId(),
Payload :: mod_pubsub:payload())
-> {result, [xmlel(),...]}
%%%
| {error, xmlel()}
).
publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) -> publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload, [], all). publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload, [], all).
publish_item(Host, ServerHost, Node, Publisher, <<>>, Payload, PubOpts, Access) -> publish_item(Host, ServerHost, Node, Publisher, <<>>, Payload, PubOpts, Access) ->
@ -2319,16 +2189,10 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload, PubOpts, Access
%%<li>The node does not support persistent items.</li> %%<li>The node does not support persistent items.</li>
%%<li>The service does not support the deletion of items.</li> %%<li>The service does not support the deletion of items.</li>
%%</ul> %%</ul>
-spec(delete_item/4 :: -spec delete_item(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( Publisher :: jid(), ItemId :: mod_pubsub:itemId()) ->
Host :: mod_pubsub:host(), {result, []} | {error, xmlel()}.
Node :: mod_pubsub:nodeId(),
Publisher :: jid(),
ItemId :: mod_pubsub:itemId())
-> {result, []}
%%%
| {error, xmlel()}
).
delete_item(Host, Node, Publisher, ItemId) -> delete_item(Host, Node, Publisher, ItemId) ->
delete_item(Host, Node, Publisher, ItemId, false). delete_item(Host, Node, Publisher, ItemId, false).
delete_item(_, <<>>, _, _, _) -> delete_item(_, <<>>, _, _, _) ->
@ -2383,15 +2247,10 @@ delete_item(Host, Node, Publisher, ItemId, ForceNotify) ->
%%<li>The node is not configured to persist items.</li> %%<li>The node is not configured to persist items.</li>
%%<li>The specified node does not exist.</li> %%<li>The specified node does not exist.</li>
%%</ul> %%</ul>
-spec(purge_node/3 :: -spec purge_node(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( Owner :: jid()) ->
Host :: mod_pubsub:host(), {result, []} | {error, xmlel()}.
Node :: mod_pubsub:nodeId(),
Owner :: jid())
-> {result, []}
%%%
| {error, xmlel()}
).
purge_node(Host, Node, Owner) -> purge_node(Host, Node, Owner) ->
Action = fun (#pubsub_node{options = Options, type = Type, id = Nidx}) -> Action = fun (#pubsub_node{options = Options, type = Type, id = Nidx}) ->
Features = plugin_features(Host, Type), Features = plugin_features(Host, Type),
@ -2435,19 +2294,12 @@ purge_node(Host, Node, Owner) ->
%% <p>The permission are not checked in this function.</p> %% <p>The permission are not checked in this function.</p>
%% @todo We probably need to check that the user doing the query has the right %% @todo We probably need to check that the user doing the query has the right
%% to read the items. %% to read the items.
-spec(get_items/7 :: -spec get_items(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( From :: jid(), SubId :: mod_pubsub:subId(),
Host :: mod_pubsub:host(), SMaxItems :: binary(), ItemIds :: [mod_pubsub:itemId()],
Node :: mod_pubsub:nodeId(), Rsm :: none | rsm_in()) ->
From :: jid(), {result, [xmlel(),...]} | {error, xmlel()}.
SubId :: mod_pubsub:subId(),
SMaxItems :: binary(),
ItemIds :: [mod_pubsub:itemId()],
Rsm :: none | rsm_in())
-> {result, [xmlel(),...]}
%%%
| {error, xmlel()}
).
get_items(Host, Node, From, SubId, SMaxItems, ItemIds, RSM) -> get_items(Host, Node, From, SubId, SMaxItems, ItemIds, RSM) ->
MaxItems = if SMaxItems == <<>> -> MaxItems = if SMaxItems == <<>> ->
case get_max_items_node(Host) of case get_max_items_node(Host) of
@ -2610,16 +2462,10 @@ dispatch_items(From, To, _Node, Stanza) ->
ejabberd_router:route(service_jid(From), jid:make(To), Stanza). ejabberd_router:route(service_jid(From), jid:make(To), Stanza).
%% @doc <p>Return the list of affiliations as an XMPP response.</p> %% @doc <p>Return the list of affiliations as an XMPP response.</p>
-spec(get_affiliations/4 :: -spec get_affiliations(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( JID :: jid(), Plugins :: [binary()]) ->
Host :: mod_pubsub:host(), {result, [xmlel(),...]} | {error, xmlel()}.
Node :: mod_pubsub:nodeId(),
JID :: jid(),
Plugins :: [binary()])
-> {result, [xmlel(),...]}
%%%
| {error, xmlel()}
).
get_affiliations(Host, Node, JID, Plugins) when is_list(Plugins) -> get_affiliations(Host, Node, JID, Plugins) when is_list(Plugins) ->
Result = lists:foldl( fun (Type, {Status, Acc}) -> Result = lists:foldl( fun (Type, {Status, Acc}) ->
Features = plugin_features(Host, Type), Features = plugin_features(Host, Type),
@ -2663,15 +2509,10 @@ get_affiliations(Host, Node, JID, Plugins) when is_list(Plugins) ->
Error Error
end. end.
-spec(get_affiliations/3 :: -spec get_affiliations(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( JID :: jid()) ->
Host :: mod_pubsub:host(), {result, [xmlel(),...]} | {error, xmlel()}.
Node :: mod_pubsub:nodeId(),
JID :: jid())
-> {result, [xmlel(),...]}
%%%
| {error, xmlel()}
).
get_affiliations(Host, Node, JID) -> get_affiliations(Host, Node, JID) ->
Action = fun (#pubsub_node{type = Type, id = Nidx}) -> Action = fun (#pubsub_node{type = Type, id = Nidx}) ->
Features = plugin_features(Host, Type), Features = plugin_features(Host, Type),
@ -2708,16 +2549,10 @@ get_affiliations(Host, Node, JID) ->
Error Error
end. end.
-spec(set_affiliations/4 :: -spec set_affiliations(Host :: mod_pubsub:host(), Node :: mod_pubsub:nodeId(),
( From :: jid(), EntitiesEls :: [xmlel()]) ->
Host :: mod_pubsub:host(), {result, []} | {error, xmlel()}.
Node :: mod_pubsub:nodeId(),
From :: jid(),
EntitiesEls :: [xmlel()])
-> {result, []}
%%%
| {error, xmlel()}
).
set_affiliations(Host, Node, From, EntitiesEls) -> set_affiliations(Host, Node, From, EntitiesEls) ->
Owner = jid:tolower(jid:remove_resource(From)), Owner = jid:tolower(jid:remove_resource(From)),
Entities = lists:foldl(fun Entities = lists:foldl(fun
@ -3113,15 +2948,13 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
end end
end. end.
-spec(get_presence_and_roster_permissions/5 :: -spec get_presence_and_roster_permissions(Host :: mod_pubsub:host(),
( From :: ljid(), Owners :: [ljid(),...],
Host :: mod_pubsub:host(), AccessModel :: mod_pubsub:accessModel(),
From :: ljid(), AllowedGroups :: [binary()]) ->
Owners :: [ljid(),...], {PresenceSubscription::boolean(),
AccessModel :: mod_pubsub:accessModel(), RosterGroup::boolean()}.
AllowedGroups :: [binary()])
-> {PresenceSubscription::boolean(), RosterGroup::boolean()}
).
get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups) -> get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups) ->
if (AccessModel == presence) or (AccessModel == roster) -> if (AccessModel == presence) or (AccessModel == roster) ->
case Host of case Host of
@ -3179,11 +3012,7 @@ subscription_to_string(pending) -> <<"pending">>;
subscription_to_string(unconfigured) -> <<"unconfigured">>; subscription_to_string(unconfigured) -> <<"unconfigured">>;
subscription_to_string(_) -> <<"none">>. subscription_to_string(_) -> <<"none">>.
-spec(service_jid/1 :: -spec service_jid(Host :: mod_pubsub:host()) -> jid().
(
Host :: mod_pubsub:host())
-> jid()
).
service_jid(#jid{} = Jid) -> Jid; service_jid(#jid{} = Jid) -> Jid;
service_jid({U, S, R}) -> jid:make(U, S, R); service_jid({U, S, R}) -> jid:make(U, S, R);
service_jid(Host) -> jid:make(<<>>, Host, <<>>). service_jid(Host) -> jid:make(<<>>, Host, <<>>).
@ -3217,12 +3046,7 @@ sub_option_can_deliver(_, _, {deliver, false}) -> false;
sub_option_can_deliver(_, _, {expire, When}) -> p1_time_compat:timestamp() < When; sub_option_can_deliver(_, _, {expire, When}) -> p1_time_compat:timestamp() < When;
sub_option_can_deliver(_, _, _) -> true. sub_option_can_deliver(_, _, _) -> true.
-spec(presence_can_deliver/2 :: -spec presence_can_deliver(Entity :: ljid(), _ :: boolean()) -> boolean().
(
Entity :: ljid(),
_ :: boolean())
-> boolean()
).
presence_can_deliver(_, false) -> presence_can_deliver(_, false) ->
true; true;
presence_can_deliver({User, Server, Resource}, true) -> presence_can_deliver({User, Server, Resource}, true) ->
@ -3243,12 +3067,10 @@ presence_can_deliver({User, Server, Resource}, true) ->
false, Ss) false, Ss)
end. end.
-spec(state_can_deliver/2 :: -spec state_can_deliver(Entity::ljid(),
( SubOptions :: mod_pubsub:subOptions() | []) ->
Entity::ljid(), [ljid()].
SubOptions :: mod_pubsub:subOptions() | [])
-> [ljid()]
).
state_can_deliver({U, S, R}, []) -> [{U, S, R}]; state_can_deliver({U, S, R}, []) -> [{U, S, R}];
state_can_deliver({U, S, R}, SubOptions) -> state_can_deliver({U, S, R}, SubOptions) ->
case lists:keysearch(show_values, 1, SubOptions) of case lists:keysearch(show_values, 1, SubOptions) of
@ -3268,13 +3090,10 @@ state_can_deliver({U, S, R}, SubOptions) ->
[], Resources) [], Resources)
end. end.
-spec(get_resource_state/3 :: -spec get_resource_state(Entity :: ljid(), ShowValues :: [binary()],
( JIDs :: [ljid()]) ->
Entity :: ljid(), [ljid()].
ShowValues :: [binary()],
JIDs :: [ljid()])
-> [ljid()]
).
get_resource_state({U, S, R}, ShowValues, JIDs) -> get_resource_state({U, S, R}, ShowValues, JIDs) ->
case ejabberd_sm:get_session_pid(U, S, R) of case ejabberd_sm:get_session_pid(U, S, R) of
none -> none ->
@ -3293,11 +3112,8 @@ get_resource_state({U, S, R}, ShowValues, JIDs) ->
end end
end. end.
-spec(payload_xmlelements/1 :: -spec payload_xmlelements(Payload :: mod_pubsub:payload()) ->
( Count :: non_neg_integer().
Payload :: mod_pubsub:payload())
-> Count :: non_neg_integer()
).
payload_xmlelements(Payload) -> payload_xmlelements(Payload) ->
payload_xmlelements(Payload, 0). payload_xmlelements(Payload, 0).
@ -4040,12 +3856,9 @@ unset_cached_item(Host, Nidx) ->
_ -> ok _ -> ok
end. end.
-spec(get_cached_item/2 :: -spec get_cached_item(Host :: mod_pubsub:host(), Nidx :: mod_pubsub:nodeIdx()) ->
( undefined | mod_pubsub:pubsubItem().
Host :: mod_pubsub:host(),
Nidx :: mod_pubsub:nodeIdx())
-> undefined | mod_pubsub:pubsubItem()
).
get_cached_item({_, ServerHost, _}, Nidx) -> get_cached_item({_, ServerHost, _}, Nidx) ->
get_cached_item(ServerHost, Nidx); get_cached_item(ServerHost, Nidx);
get_cached_item(Host, Nidx) -> get_cached_item(Host, Nidx) ->
@ -4340,7 +4153,7 @@ string_to_ljid(JID) ->
end end
end. end.
-spec(uniqid/0 :: () -> mod_pubsub:itemId()). -spec uniqid() -> mod_pubsub:itemId().
uniqid() -> uniqid() ->
{T1, T2, T3} = p1_time_compat:timestamp(), {T1, T2, T3} = p1_time_compat:timestamp(),
iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])). iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])).
@ -4355,12 +4168,7 @@ itemsEls(Items) ->
[#xmlel{name = <<"item">>, attrs = itemAttr(ItemId), children = Payload} [#xmlel{name = <<"item">>, attrs = itemAttr(ItemId), children = Payload}
|| #pubsub_item{itemid = {ItemId, _}, payload = Payload} <- Items]. || #pubsub_item{itemid = {ItemId, _}, payload = Payload} <- Items].
-spec(add_message_type/2 :: -spec add_message_type(Message :: xmlel(), Type :: atom()) -> xmlel().
(
Message :: xmlel(),
Type :: atom())
-> xmlel()
).
add_message_type(Message, normal) -> Message; add_message_type(Message, normal) -> Message;
add_message_type(#xmlel{name = <<"message">>, attrs = Attrs, children = Els}, Type) -> add_message_type(#xmlel{name = <<"message">>, attrs = Attrs, children = Els}, Type) ->

View File

@ -402,17 +402,13 @@ get_entity_subscriptions(Host, Owner) ->
end, end,
{result, Reply}. {result, Reply}.
-spec(get_entity_subscriptions_for_send_last/2 :: -spec get_entity_subscriptions_for_send_last(Host :: mod_pubsub:hostPubsub(),
( Owner :: jid()) ->
Host :: mod_pubsub:hostPubsub(), {result, [{mod_pubsub:pubsubNode(),
Owner :: jid()) mod_pubsub:subscription(),
-> {result, mod_pubsub:subId(),
[{mod_pubsub:pubsubNode(), ljid()}]}.
mod_pubsub:subscription(),
mod_pubsub:subId(),
ljid()}]
}
).
get_entity_subscriptions_for_send_last(Host, Owner) -> get_entity_subscriptions_for_send_last(Host, Owner) ->
SubKey = jid:tolower(Owner), SubKey = jid:tolower(Owner),
GenKey = jid:remove_resource(SubKey), GenKey = jid:remove_resource(SubKey),
@ -611,11 +607,9 @@ get_state(Nidx, JID) ->
{SJID, _} = State#pubsub_state.stateid, {SJID, _} = State#pubsub_state.stateid,
State#pubsub_state{items = itemids(Nidx, SJID)}. State#pubsub_state{items = itemids(Nidx, SJID)}.
-spec(get_state_without_itemids/2 :: -spec get_state_without_itemids(Nidx :: mod_pubsub:nodeIdx(), Key :: ljid()) ->
(Nidx :: mod_pubsub:nodeIdx(), mod_pubsub:pubsubState().
Key :: ljid()) ->
mod_pubsub:pubsubState()
).
get_state_without_itemids(Nidx, JID) -> get_state_without_itemids(Nidx, JID) ->
J = encode_jid(JID), J = encode_jid(JID),
case catch case catch
@ -973,17 +967,11 @@ update_subscription(Nidx, JID, Subscription) ->
"-affiliation='n'" "-affiliation='n'"
]). ]).
-spec(decode_jid/1 :: -spec decode_jid(SJID :: binary()) -> ljid().
( SJID :: binary())
-> ljid()
).
decode_jid(SJID) -> decode_jid(SJID) ->
jid:tolower(jid:from_string(SJID)). jid:tolower(jid:from_string(SJID)).
-spec(decode_affiliation/1 :: -spec decode_affiliation(Arg :: binary()) -> atom().
( Arg :: binary())
-> atom()
).
decode_affiliation(<<"o">>) -> owner; decode_affiliation(<<"o">>) -> owner;
decode_affiliation(<<"p">>) -> publisher; decode_affiliation(<<"p">>) -> publisher;
decode_affiliation(<<"u">>) -> publish_only; decode_affiliation(<<"u">>) -> publish_only;
@ -991,19 +979,13 @@ decode_affiliation(<<"m">>) -> member;
decode_affiliation(<<"c">>) -> outcast; decode_affiliation(<<"c">>) -> outcast;
decode_affiliation(_) -> none. decode_affiliation(_) -> none.
-spec(decode_subscription/1 :: -spec decode_subscription(Arg :: binary()) -> atom().
( Arg :: binary())
-> atom()
).
decode_subscription(<<"s">>) -> subscribed; decode_subscription(<<"s">>) -> subscribed;
decode_subscription(<<"p">>) -> pending; decode_subscription(<<"p">>) -> pending;
decode_subscription(<<"u">>) -> unconfigured; decode_subscription(<<"u">>) -> unconfigured;
decode_subscription(_) -> none. decode_subscription(_) -> none.
-spec(decode_subscriptions/1 :: -spec decode_subscriptions(Subscriptions :: binary()) -> [] | [{atom(), binary()},...].
( Subscriptions :: binary())
-> [] | [{atom(), binary()},...]
).
decode_subscriptions(Subscriptions) -> decode_subscriptions(Subscriptions) ->
lists:foldl(fun (Subscription, Acc) -> lists:foldl(fun (Subscription, Acc) ->
case str:tokens(Subscription, <<":">>) of case str:tokens(Subscription, <<":">>) of
@ -1013,36 +995,24 @@ decode_subscriptions(Subscriptions) ->
end, end,
[], str:tokens(Subscriptions, <<",">>)). [], str:tokens(Subscriptions, <<",">>)).
-spec(encode_jid/1 :: -spec encode_jid(JID :: ljid()) -> binary().
( JID :: ljid())
-> binary()
).
encode_jid(JID) -> encode_jid(JID) ->
jid:to_string(JID). jid:to_string(JID).
-spec(encode_jid_like/1 :: (JID :: ljid()) -> binary()). -spec encode_jid_like(JID :: ljid()) -> binary().
encode_jid_like(JID) -> encode_jid_like(JID) ->
ejabberd_sql:escape_like_arg_circumflex(jid:to_string(JID)). ejabberd_sql:escape_like_arg_circumflex(jid:to_string(JID)).
-spec(encode_host/1 :: -spec encode_host(Host :: host()) -> binary().
( Host :: host())
-> binary()
).
encode_host({_U, _S, _R} = LJID) -> encode_jid(LJID); encode_host({_U, _S, _R} = LJID) -> encode_jid(LJID);
encode_host(Host) -> Host. encode_host(Host) -> Host.
-spec(encode_host_like/1 :: -spec encode_host_like(Host :: host()) -> binary().
( Host :: host())
-> binary()
).
encode_host_like({_U, _S, _R} = LJID) -> ejabberd_sql:escape(encode_jid_like(LJID)); encode_host_like({_U, _S, _R} = LJID) -> ejabberd_sql:escape(encode_jid_like(LJID));
encode_host_like(Host) -> encode_host_like(Host) ->
ejabberd_sql:escape(ejabberd_sql:escape_like_arg_circumflex(Host)). ejabberd_sql:escape(ejabberd_sql:escape_like_arg_circumflex(Host)).
-spec(encode_affiliation/1 :: -spec encode_affiliation(Arg :: atom()) -> binary().
( Arg :: atom())
-> binary()
).
encode_affiliation(owner) -> <<"o">>; encode_affiliation(owner) -> <<"o">>;
encode_affiliation(publisher) -> <<"p">>; encode_affiliation(publisher) -> <<"p">>;
encode_affiliation(publish_only) -> <<"u">>; encode_affiliation(publish_only) -> <<"u">>;
@ -1050,19 +1020,13 @@ encode_affiliation(member) -> <<"m">>;
encode_affiliation(outcast) -> <<"c">>; encode_affiliation(outcast) -> <<"c">>;
encode_affiliation(_) -> <<"n">>. encode_affiliation(_) -> <<"n">>.
-spec(encode_subscription/1 :: -spec encode_subscription(Arg :: atom()) -> binary().
( Arg :: atom())
-> binary()
).
encode_subscription(subscribed) -> <<"s">>; encode_subscription(subscribed) -> <<"s">>;
encode_subscription(pending) -> <<"p">>; encode_subscription(pending) -> <<"p">>;
encode_subscription(unconfigured) -> <<"u">>; encode_subscription(unconfigured) -> <<"u">>;
encode_subscription(_) -> <<"n">>. encode_subscription(_) -> <<"n">>.
-spec(encode_subscriptions/1 :: -spec encode_subscriptions(Subscriptions :: [] | [{atom(), binary()},...]) -> binary().
( Subscriptions :: [] | [{atom(), binary()},...])
-> binary()
).
encode_subscriptions(Subscriptions) -> encode_subscriptions(Subscriptions) ->
str:join([<<(encode_subscription(S))/binary, ":", SubId/binary>> str:join([<<(encode_subscription(S))/binary, ":", SubId/binary>>
|| {S, SubId} <- Subscriptions], <<",">>). || {S, SubId} <- Subscriptions], <<",">>).

View File

@ -167,12 +167,8 @@ oid(Key, Name) -> {Key, Name}.
%% Key = jlib:jid() | host() %% Key = jlib:jid() | host()
%% Node = string() %% Node = string()
-spec(find_node/2 :: -spec find_node(Key :: mod_pubsub:hostPubsub(), Node :: mod_pubsub:nodeId()) ->
( mod_pubsub:pubsubNode() | false.
Key :: mod_pubsub:hostPubsub(),
Node :: mod_pubsub:nodeId())
-> mod_pubsub:pubsubNode() | false
).
find_node(Key, Node) -> find_node(Key, Node) ->
case mnesia:read(pubsub_node, oid(Key, Node), read) of case mnesia:read(pubsub_node, oid(Key, Node), read) of
[] -> false; [] -> false;
@ -188,14 +184,11 @@ find_opt(Key, Default, Options) ->
_ -> Default _ -> Default
end. end.
-spec(traversal_helper/4 :: -spec traversal_helper(Pred :: fun(), Tr :: fun(), Host :: mod_pubsub:hostPubsub(),
( Nodes :: [mod_pubsub:nodeId(),...]) ->
Pred :: fun(), [{Depth::non_neg_integer(),
Tr :: fun(), Nodes::[mod_pubsub:pubsubNode(),...]}].
Host :: mod_pubsub:hostPubsub(),
Nodes :: [mod_pubsub:nodeId(),...])
-> [{Depth::non_neg_integer(), Nodes::[mod_pubsub:pubsubNode(),...]}]
).
traversal_helper(Pred, Tr, Host, Nodes) -> traversal_helper(Pred, Tr, Host, Nodes) ->
traversal_helper(Pred, Tr, 0, Host, Nodes, []). traversal_helper(Pred, Tr, 0, Host, Nodes, []).
@ -220,15 +213,10 @@ remove_config_parent(Node, [{collection, Parents} | T], Acc) ->
remove_config_parent(Node, [H | T], Acc) -> remove_config_parent(Node, [H | T], Acc) ->
remove_config_parent(Node, T, [H | Acc]). remove_config_parent(Node, T, [H | Acc]).
-spec(validate_parentage/3 :: -spec validate_parentage(Key :: mod_pubsub:hostPubsub(), Owners :: [ljid(),...],
( Parent_Nodes :: [mod_pubsub:nodeId()]) ->
Key :: mod_pubsub:hostPubsub(), true | {error, xmlel()}.
Owners :: [ljid(),...],
Parent_Nodes :: [mod_pubsub:nodeId()])
-> true
%%%
| {error, xmlel()}
).
validate_parentage(_Key, _Owners, []) -> validate_parentage(_Key, _Owners, []) ->
true; true;
validate_parentage(Key, Owners, [[] | T]) -> validate_parentage(Key, Owners, [[] | T]) ->

View File

@ -152,13 +152,9 @@ create_table() ->
Other -> Other Other -> Other
end. end.
-spec(add_subscription/3 :: -spec add_subscription(_JID :: ljid(), _NodeId :: mod_pubsub:nodeIdx(),
( Options :: [] | mod_pubsub:subOptions()) ->
_JID :: ljid(), SubId :: mod_pubsub:subId().
_NodeId :: mod_pubsub:nodeIdx(),
Options :: [] | mod_pubsub:subOptions())
-> SubId :: mod_pubsub:subId()
).
add_subscription(_JID, _NodeId, []) -> make_subid(); add_subscription(_JID, _NodeId, []) -> make_subid();
add_subscription(_JID, _NodeId, Options) -> add_subscription(_JID, _NodeId, Options) ->
@ -166,25 +162,13 @@ add_subscription(_JID, _NodeId, Options) ->
mnesia:write(#pubsub_subscription{subid = SubID, options = Options}), mnesia:write(#pubsub_subscription{subid = SubID, options = Options}),
SubID. SubID.
-spec(delete_subscription/3 :: -spec delete_subscription(_JID :: _, _NodeId :: _, SubId :: mod_pubsub:subId()) -> ok.
(
_JID :: _,
_NodeId :: _,
SubId :: mod_pubsub:subId())
-> ok
).
delete_subscription(_JID, _NodeId, SubID) -> delete_subscription(_JID, _NodeId, SubID) ->
mnesia:delete({pubsub_subscription, SubID}). mnesia:delete({pubsub_subscription, SubID}).
-spec(read_subscription/3 :: -spec read_subscription(_JID :: ljid(), _NodeId :: _, SubID :: mod_pubsub:subId()) ->
( mod_pubsub:pubsubSubscription() | {error, notfound}.
_JID :: ljid(),
_NodeId :: _,
SubID :: mod_pubsub:subId())
-> mod_pubsub:pubsubSubscription()
| {error, notfound}
).
read_subscription(_JID, _NodeId, SubID) -> read_subscription(_JID, _NodeId, SubID) ->
case mnesia:read({pubsub_subscription, SubID}) of case mnesia:read({pubsub_subscription, SubID}) of
@ -192,19 +176,13 @@ read_subscription(_JID, _NodeId, SubID) ->
_ -> {error, notfound} _ -> {error, notfound}
end. end.
-spec(write_subscription/4 :: -spec write_subscription(_JID :: ljid(), _NodeId :: _, SubID :: mod_pubsub:subId(),
( Options :: mod_pubsub:subOptions()) -> ok.
_JID :: ljid(),
_NodeId :: _,
SubID :: mod_pubsub:subId(),
Options :: mod_pubsub:subOptions())
-> ok
).
write_subscription(_JID, _NodeId, SubID, Options) -> write_subscription(_JID, _NodeId, SubID, Options) ->
mnesia:write(#pubsub_subscription{subid = SubID, options = Options}). mnesia:write(#pubsub_subscription{subid = SubID, options = Options}).
-spec(make_subid/0 :: () -> SubId::mod_pubsub:subId()). -spec make_subid() -> SubId::mod_pubsub:subId().
make_subid() -> make_subid() ->
{T1, T2, T3} = p1_time_compat:timestamp(), {T1, T2, T3} = p1_time_compat:timestamp(),
iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])). iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])).
@ -272,13 +250,8 @@ xopt_to_bool(Option, _) ->
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Option])), ErrTxt = iolist_to_binary(io_lib:format(Txt, [Option])),
{error, ?ERRT_NOT_ACCEPTABLE(?MYLANG, ErrTxt)}. {error, ?ERRT_NOT_ACCEPTABLE(?MYLANG, ErrTxt)}.
-spec(get_option_xfield/3 :: -spec get_option_xfield(Lang :: binary(), Key :: atom(),
( Options :: mod_pubsub:subOptions()) -> xmlel().
Lang :: binary(),
Key :: atom(),
Options :: mod_pubsub:subOptions())
-> xmlel()
).
%% Return a field for an XForm for Key, with data filled in, if %% Return a field for an XForm for Key, with data filled in, if
%% applicable, from Options. %% applicable, from Options.

View File

@ -73,54 +73,34 @@
init() -> ok = create_table(). init() -> ok = create_table().
-spec(subscribe_node/3 :: -spec subscribe_node(_JID :: _, _NodeId :: _, Options :: [] | mod_pubsub:subOptions()) ->
( {result, mod_pubsub:subId()}.
_JID :: _,
_NodeId :: _,
Options :: [] | mod_pubsub:subOptions())
-> {result, mod_pubsub:subId()}
).
subscribe_node(_JID, _NodeId, Options) -> subscribe_node(_JID, _NodeId, Options) ->
SubID = make_subid(), SubID = make_subid(),
(?DB_MOD):add_subscription(#pubsub_subscription{subid = SubID, options = Options}), (?DB_MOD):add_subscription(#pubsub_subscription{subid = SubID, options = Options}),
{result, SubID}. {result, SubID}.
-spec(unsubscribe_node/3 :: -spec unsubscribe_node(_JID :: _, _NodeId :: _, SubID :: mod_pubsub:subId()) ->
( {result, mod_pubsub:subscription()} | {error, notfound}.
_JID :: _,
_NodeId :: _,
SubID :: mod_pubsub:subId())
-> {result, mod_pubsub:subscription()}
| {error, notfound}
).
unsubscribe_node(_JID, _NodeId, SubID) -> unsubscribe_node(_JID, _NodeId, SubID) ->
case (?DB_MOD):read_subscription(SubID) of case (?DB_MOD):read_subscription(SubID) of
{ok, Sub} -> (?DB_MOD):delete_subscription(SubID), {result, Sub}; {ok, Sub} -> (?DB_MOD):delete_subscription(SubID), {result, Sub};
notfound -> {error, notfound} notfound -> {error, notfound}
end. end.
-spec(get_subscription/3 :: -spec get_subscription(_JID :: _, _NodeId :: _, SubId :: mod_pubsub:subId()) ->
( {result, mod_pubsub:subscription()} | {error, notfound}.
_JID :: _,
_NodeId :: _,
SubId :: mod_pubsub:subId())
-> {result, mod_pubsub:subscription()}
| {error, notfound}
).
get_subscription(_JID, _NodeId, SubID) -> get_subscription(_JID, _NodeId, SubID) ->
case (?DB_MOD):read_subscription(SubID) of case (?DB_MOD):read_subscription(SubID) of
{ok, Sub} -> {result, Sub}; {ok, Sub} -> {result, Sub};
notfound -> {error, notfound} notfound -> {error, notfound}
end. end.
-spec(set_subscription/4 :: -spec set_subscription(_JID :: _, _NodeId :: _, SubId :: mod_pubsub:subId(),
( Options :: mod_pubsub:subOptions()) -> {result, ok}.
_JID :: _,
_NodeId :: _,
SubId :: mod_pubsub:subId(),
Options :: mod_pubsub:subOptions())
-> {result, ok}
).
set_subscription(_JID, _NodeId, SubID, Options) -> set_subscription(_JID, _NodeId, SubID, Options) ->
case (?DB_MOD):read_subscription(SubID) of case (?DB_MOD):read_subscription(SubID) of
{ok, _} -> {ok, _} ->
@ -167,7 +147,7 @@ parse_options_xform(XFields) ->
%%==================================================================== %%====================================================================
create_table() -> ok. create_table() -> ok.
-spec(make_subid/0 :: () -> mod_pubsub:subId()). -spec make_subid() -> mod_pubsub:subId().
make_subid() -> make_subid() ->
{T1, T2, T3} = p1_time_compat:timestamp(), {T1, T2, T3} = p1_time_compat:timestamp(),
iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])). iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])).