fix some dialyzer warnings on pubsub (EJAB-1260)

This commit is contained in:
Christophe Romain 2010-07-01 11:19:48 +02:00
parent 5ca3f221cc
commit 455107ff5f
4 changed files with 62 additions and 74 deletions

View File

@ -643,7 +643,7 @@ disco_sm_items(Acc, From, To, <<>>, _Lang) ->
[] ->
Acc;
Nodes ->
SBJID = jlib:short_prepd_bare_jid(To),
SBJID = exmpp_jid:to_binary(exmpp_jid:bare(To)),
Items = case Acc of
{result, I} -> I;
_ -> []
@ -651,7 +651,7 @@ disco_sm_items(Acc, From, To, <<>>, _Lang) ->
NodeItems = lists:map(
fun(#pubsub_node{nodeid = {_, Node}}) ->
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
[?XMLATTR('jid', exmpp_jid:to_binary(SBJID)) | nodeAttr(Node)]}
[?XMLATTR('jid', SBJID) | nodeAttr(Node)]}
end, Nodes),
{result, NodeItems ++ Items}
end;
@ -661,7 +661,7 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
Node = string_to_node(SNode),
%% TODO, use iq_disco_items(Host, Node, From)
Host = exmpp_jid:prep_domain_as_list(To),
LJID = jlib:short_prepd_bare_jid(To),
SBJID = exmpp_jid:to_binary(exmpp_jid:bare(To)),
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
% TODO call get_items/6 instead for access control (EJAB-1033)
case node_call(Type, get_items, [NodeId, From]) of
@ -676,7 +676,7 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
fun(#pubsub_item{itemid = {Id, _}}) ->
{result, Name} = node_call(Type, get_item_name, [Host, Node, Id]),
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
[?XMLATTR('jid', exmpp_jid:to_binary(LJID)),
[?XMLATTR('jid', SBJID),
?XMLATTR('name', Name)]}
end, AllItems),
{result, NodeItems ++ Items};
@ -994,9 +994,7 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
#iq{} ->
Err = exmpp_iq:error(Packet,
'feature-not-implemented'),
ejabberd_router:route(To, From, Err);
_ ->
ok
ejabberd_router:route(To, From, Err)
end;
'message' ->
case exmpp_stanza:is_stanza_error(Packet) of
@ -1534,7 +1532,7 @@ send_pending_auth_events(Host, Node, Owner) ->
%%% authorization handling
send_authorization_request(#pubsub_node{owners = Owners, nodeid = {Host, Node}}, Subscriber) ->
Lang = "en", %% TODO fix
Lang = <<"en">>, %% TODO fix
{U, S, R} = Subscriber,
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
[#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"form">>)], children =
@ -1549,7 +1547,7 @@ send_authorization_request(#pubsub_node{owners = Owners, nodeid = {Host, Node}},
[?XMLATTR('var', <<"pubsub#node">>), ?XMLATTR('type', <<"text-single">>),
?XMLATTR('label', translate:translate(Lang, "Node ID"))], children =
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children =
[#xmlcdata{cdata = node_to_string(Node)}]}]},
[#xmlcdata{cdata = Node}]}]},
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('var', <<"pubsub#subscriber_jid">>),
?XMLATTR('type', <<"jid-single">>),
?XMLATTR('label', translate:translate(Lang, "Subscriber Address"))], children =
@ -1576,7 +1574,7 @@ find_authorization_response(Packet) ->
end;
(_) ->
none
end, exmpp_xml:remove_cdata(Els)),
end, exmpp_xml:remove_cdata_from_list(Els)),
XData = lists:filter(fun(E) -> E /= none end, XData1),
case XData of
[invalid] -> invalid;
@ -1641,11 +1639,7 @@ handle_authorization_response(Host, From, To, Packet, XFields) ->
exmpp_stanza:reply_with_error(Packet, Error));
{result, _} ->
%% XXX: notify about subscription state change, section 12.11
ok;
_ ->
ejabberd_router:route(
To, From,
exmpp_stanza:reply_with_error(Packet, 'internal-server-error'))
ok
end;
_ ->
ejabberd_router:route(
@ -1956,7 +1950,7 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
Subscriber, AllowedGroups);
_ ->
case Subscriber of
{"", "", ""} ->
{undefined, undefined, undefined} ->
{false, false};
_ ->
{OU, OS, _} = Owner,

View File

@ -453,7 +453,7 @@ disco_sm_items(Acc, From, To, <<>>, _Lang) ->
[] ->
Acc;
Nodes ->
SBJID = jlib:short_prepd_bare_jid(To),
SBJID = exmpp_jid:to_binary(exmpp_jid:bare(To)),
Items = case Acc of
{result, I} -> I;
_ -> []
@ -461,7 +461,7 @@ disco_sm_items(Acc, From, To, <<>>, _Lang) ->
NodeItems = lists:map(
fun(#pubsub_node{nodeid = {_, Node}}) ->
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
[?XMLATTR('jid', exmpp_jid:to_binary(SBJID)) | nodeAttr(Node)]}
[?XMLATTR('jid', SBJID) | nodeAttr(Node)]}
end, Nodes),
{result, NodeItems ++ Items}
end;
@ -471,7 +471,7 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
Node = string_to_node(SNode),
%% TODO, use iq_disco_items(Host, Node, From)
Host = exmpp_jid:prep_domain_as_list(To),
LJID = jlib:short_prepd_bare_jid(To),
SBJID = exmpp_jid:to_binary(exmpp_jid:bare(To)),
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
% TODO call get_items/6 instead for access control (EJAB-1033)
case node_call(Type, get_items, [NodeId, From]) of
@ -486,7 +486,7 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
fun(#pubsub_item{itemid = {Id, _}}) ->
{result, Name} = node_call(Type, get_item_name, [Host, Node, Id]),
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
[?XMLATTR('jid', exmpp_jid:to_binary(LJID)),
[?XMLATTR('jid', SBJID),
?XMLATTR('name', Name)]}
end, AllItems),
{result, NodeItems ++ Items};
@ -805,9 +805,7 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
#iq{} ->
Err = exmpp_iq:error(Packet,
'feature-not-implemented'),
ejabberd_router:route(To, From, Err);
_ ->
ok
ejabberd_router:route(To, From, Err)
end;
'message' ->
case exmpp_stanza:is_stanza_error(Packet) of
@ -1349,7 +1347,7 @@ send_pending_auth_events(Host, Node, Owner) ->
%%% authorization handling
send_authorization_request(#pubsub_node{nodeid = {Host, Node}, type = Type, id = NodeId}, Subscriber) ->
Lang = "en", %% TODO fix
Lang = <<"en">>, %% TODO fix
{U, S, R} = Subscriber,
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
[#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"form">>)], children =
@ -1364,7 +1362,7 @@ send_authorization_request(#pubsub_node{nodeid = {Host, Node}, type = Type, id =
[?XMLATTR('var', <<"pubsub#node">>), ?XMLATTR('type', <<"text-single">>),
?XMLATTR('label', translate:translate(Lang, "Node ID"))], children =
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children =
[#xmlcdata{cdata = node_to_string(Node)}]}]},
[#xmlcdata{cdata = Node}]}]},
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('var', <<"pubsub#subscriber_jid">>),
?XMLATTR('type', <<"jid-single">>),
?XMLATTR('label', translate:translate(Lang, "Subscriber Address"))], children =
@ -1391,7 +1389,7 @@ find_authorization_response(Packet) ->
end;
(_) ->
none
end, exmpp_xml:remove_cdata(Els)),
end, exmpp_xml:remove_cdata_from_list(Els)),
XData = lists:filter(fun(E) -> E /= none end, XData1),
case XData of
[invalid] -> invalid;
@ -1456,11 +1454,7 @@ handle_authorization_response(Host, From, To, Packet, XFields) ->
exmpp_stanza:reply_with_error(Packet, Error));
{result, _} ->
%% XXX: notify about subscription state change, section 12.11
ok;
_ ->
ejabberd_router:route(
To, From,
exmpp_stanza:reply_with_error(Packet, 'internal-server-error'))
ok
end;
_ ->
ejabberd_router:route(
@ -1771,7 +1765,7 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
Subscriber, AllowedGroups);
_ ->
case Subscriber of
{"", "", ""} ->
{undefined, undefined, undefined} ->
{false, false};
_ ->
case node_owners_call(Type, NodeId) of
@ -3759,8 +3753,8 @@ odbc_conn(Host) ->
lists:dropwhile(fun(A) -> A/=$. end, Host) -- ".".
%% escape value for database storage
escape({U, H, R}=JID)->
ejabberd_odbc:escape(exmpp_jid:to_list(U, H, R));
escape({_U, _H, _R}=JID)->
ejabberd_odbc:escape(exmpp_jid:to_list(JID));
escape(Value)->
ejabberd_odbc:escape(Value).
%%%% helpers

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-06-10 18:25:27.000000000 +0200
+++ mod_pubsub_odbc.erl 2010-06-10 18:25:34.000000000 +0200
--- mod_pubsub.erl 2010-07-01 11:15:55.000000000 +0200
+++ mod_pubsub_odbc.erl 2010-07-01 11:18:12.000000000 +0200
@@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18.
@ -299,7 +299,7 @@
{result, IQRes} ->
Result = #xmlel{ns = ?NS_DISCO_ITEMS,
name = 'query', attrs = QAttrs,
@@ -1085,7 +896,7 @@
@@ -1083,7 +894,7 @@
[] ->
["leaf"]; %% No sub-nodes: it's a leaf node
_ ->
@ -308,7 +308,7 @@
{result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"];
_ -> []
@@ -1101,8 +912,9 @@
@@ -1099,8 +910,9 @@
[];
true ->
[#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} |
@ -320,7 +320,7 @@
end, features(Type))]
end,
%% TODO: add meta-data info (spec section 5.4)
@@ -1131,8 +943,9 @@
@@ -1129,8 +941,9 @@
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]},
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]},
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++
@ -332,7 +332,7 @@
end, features(Host, Node))};
?NS_ADHOC_b ->
command_disco_info(Host, Node, From);
@@ -1142,7 +955,7 @@
@@ -1140,7 +953,7 @@
node_disco_info(Host, Node, From)
end.
@ -341,7 +341,7 @@
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) ->
{result, lists:map(
@@ -1159,7 +972,7 @@
@@ -1157,7 +970,7 @@
Other ->
Other
end;
@ -350,7 +350,7 @@
%% TODO: support localization of this string
CommandItems = [
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item',
@@ -1168,10 +981,10 @@
@@ -1166,10 +979,10 @@
?XMLATTR('name', "Get Pending")
]}],
{result, CommandItems};
@ -363,7 +363,7 @@
case string:tokens(Item, "!") of
[_SNode, _ItemID] ->
{result, []};
@@ -1180,9 +993,9 @@
@@ -1178,9 +991,9 @@
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
% TODO call get_items/6 instead for access control (EJAB-1033)
@ -375,7 +375,7 @@
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
@@ -1200,7 +1013,7 @@
@@ -1198,7 +1011,7 @@
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('name', Name)]}
end, NodeItems),
@ -384,7 +384,7 @@
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> {result, Result};
@@ -1332,7 +1145,8 @@
@@ -1330,7 +1143,8 @@
(_, Acc) ->
Acc
end, [], exmpp_xml:remove_cdata_from_list(Els)),
@ -394,7 +394,7 @@
{get, 'subscriptions'} ->
get_subscriptions(Host, Node, From, Plugins);
{get, 'affiliations'} ->
@@ -1489,7 +1303,8 @@
@@ -1487,7 +1301,8 @@
_ -> []
end
end,
@ -404,16 +404,16 @@
sync_dirty) of
{result, Res} -> Res;
Err -> Err
@@ -1533,7 +1348,7 @@
@@ -1531,7 +1346,7 @@
%%% authorization handling
-send_authorization_request(#pubsub_node{owners = Owners, nodeid = {Host, Node}}, Subscriber) ->
+send_authorization_request(#pubsub_node{nodeid = {Host, Node}, type = Type, id = NodeId}, Subscriber) ->
Lang = "en", %% TODO fix
Lang = <<"en">>, %% TODO fix
{U, S, R} = Subscriber,
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
@@ -1563,7 +1378,7 @@
@@ -1561,7 +1376,7 @@
lists:foreach(fun(Owner) ->
{U, S, R} = Owner,
ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
@ -422,7 +422,7 @@
find_authorization_response(Packet) ->
Els = Packet#xmlel.children,
@@ -1622,8 +1437,8 @@
@@ -1620,8 +1435,8 @@
"true" -> true;
_ -> false
end,
@ -433,7 +433,7 @@
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
if
not IsApprover ->
@@ -1826,7 +1641,7 @@
@@ -1820,7 +1635,7 @@
end,
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
@ -442,7 +442,7 @@
{result, {NodeId, SubsByDepth, {Result, broadcast}}} ->
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth),
case Result of
@@ -1930,7 +1745,7 @@
@@ -1924,7 +1739,7 @@
%%<li>The node does not exist.</li>
%%</ul>
subscribe_node(Host, Node, From, JID, Configuration) ->
@ -451,7 +451,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -1940,7 +1755,7 @@
@@ -1934,7 +1749,7 @@
_:_ ->
{undefined, undefined, undefined}
end,
@ -460,8 +460,8 @@
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
@@ -1959,9 +1774,12 @@
{"", "", ""} ->
@@ -1953,9 +1768,12 @@
{undefined, undefined, undefined} ->
{false, false};
_ ->
- {OU, OS, _} = Owner,
@ -476,7 +476,7 @@
end
end,
if
@@ -2307,7 +2125,7 @@
@@ -2301,7 +2119,7 @@
%% <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
%% to read the items.
@ -485,7 +485,7 @@
MaxItems =
if
SMaxItems == "" -> get_max_items_node(Host);
@@ -2346,11 +2164,11 @@
@@ -2340,11 +2158,11 @@
node_call(Type, get_items,
[NodeId, From,
AccessModel, PresenceSubscription, RosterGroup,
@ -499,7 +499,7 @@
SendItems = case ItemIDs of
[] ->
Items;
@@ -2363,7 +2181,7 @@
@@ -2357,7 +2175,7 @@
%% number of items sent to MaxItems:
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
@ -508,7 +508,7 @@
Error ->
Error
end
@@ -2395,16 +2213,29 @@
@@ -2389,16 +2207,29 @@
%% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, LJID, last) ->
@ -544,7 +544,7 @@
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} ->
@@ -2531,7 +2362,8 @@
@@ -2525,7 +2356,8 @@
error ->
{error, 'bad-request'};
_ ->
@ -554,7 +554,7 @@
case lists:member(Owner, Owners) of
true ->
OwnerJID = exmpp_jid:make(Owner),
@@ -2541,24 +2373,8 @@
@@ -2535,24 +2367,8 @@
end,
lists:foreach(
fun({JID, Affiliation}) ->
@ -581,7 +581,7 @@
end, FilteredEntities),
{result, []};
_ ->
@@ -2613,11 +2429,11 @@
@@ -2607,11 +2423,11 @@
end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -595,7 +595,7 @@
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
?XMLATTR('subid', SubID) | nodeAttr(Node)],
@@ -2644,7 +2460,7 @@
@@ -2638,7 +2454,7 @@
end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -604,7 +604,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -2674,7 +2490,7 @@
@@ -2668,7 +2484,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) ->
@ -613,7 +613,7 @@
{error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")};
{result, _} ->
@@ -2847,8 +2663,8 @@
@@ -2841,8 +2657,8 @@
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
ejabberd_router:route(service_jid(Host), JID, Stanza)
end,
@ -624,7 +624,7 @@
true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3194,7 +3010,7 @@
@@ -3188,7 +3004,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end,
@ -633,7 +633,7 @@
{result, CollSubs} -> CollSubs;
_ -> []
end.
@@ -3208,9 +3024,9 @@
@@ -3202,9 +3018,9 @@
get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -645,7 +645,7 @@
_ -> Acc
end;
(_, Acc) ->
@@ -3432,6 +3248,30 @@
@@ -3426,6 +3242,30 @@
Result
end.
@ -676,7 +676,7 @@
%% @spec (Host, Options) -> MaxItems
%% Host = host()
%% Options = [Option]
@@ -3835,7 +3675,13 @@
@@ -3829,7 +3669,13 @@
tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end,
@ -691,7 +691,7 @@
%% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) ->
@@ -3855,13 +3701,13 @@
@@ -3849,13 +3695,13 @@
node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -707,7 +707,7 @@
case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) ->
case Action(N) of
@@ -3874,8 +3720,15 @@
@@ -3868,8 +3714,15 @@
end
end, Trans).
@ -725,7 +725,7 @@
{result, Result} -> {result, Result};
{error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result};
@@ -3883,6 +3736,15 @@
@@ -3877,6 +3730,15 @@
{aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, 'internal-server-error'};
@ -741,7 +741,7 @@
{'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, 'internal-server-error'};
@@ -3891,6 +3753,16 @@
@@ -3885,6 +3747,16 @@
{error, 'internal-server-error'}
end.

View File

@ -126,7 +126,7 @@ set_subscription(JID, NodeID, SubID, Options) ->
end.
get_options_xform(Lang, Options) ->
Keys = [deliver, show_values, subscription_type, subscription_depth],
Keys = [deliver, digest, digest_frequency, expire, include_body, show_values, subscription_type, subscription_depth],
XFields = [get_option_xfield(Lang, Key, Options) || Key <- Keys],
{result, #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"form">>)], children =