25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

improve previous patch

SVN Revision: 2578
This commit is contained in:
Christophe Romain 2009-09-01 13:16:10 +00:00
parent 55fef3c3e7
commit 07f457f49f
3 changed files with 41 additions and 40 deletions

View File

@ -2424,7 +2424,7 @@ get_options(Host, Node, JID, SubID, Lang) ->
Action = fun(#pubsub_node{type = Type, id = NodeID}) -> Action = fun(#pubsub_node{type = Type, id = NodeID}) ->
case lists:member("subscription-options", features(Type)) of case lists:member("subscription-options", features(Type)) of
true -> true ->
get_options_helper(JID, Lang, NodeID, SubID, Type); get_options_helper(JID, Lang, Node, NodeID, SubID, Type);
false -> false ->
{error, extended_error( {error, extended_error(
?ERR_FEATURE_NOT_IMPLEMENTED, ?ERR_FEATURE_NOT_IMPLEMENTED,
@ -2436,7 +2436,7 @@ get_options(Host, Node, JID, SubID, Lang) ->
Error -> Error Error -> Error
end. end.
get_options_helper(JID, Lang, NodeID, SubID, Type) -> get_options_helper(JID, Lang, Node, NodeID, SubID, Type) ->
Subscriber = case jlib:string_to_jid(JID) of Subscriber = case jlib:string_to_jid(JID) of
error -> {"", "", ""}; error -> {"", "", ""};
J -> jlib:jid_tolower(J) J -> jlib:jid_tolower(J)
@ -2452,25 +2452,21 @@ get_options_helper(JID, Lang, NodeID, SubID, Type) ->
{_, []} -> {_, []} ->
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "not-subscribed")}; {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "not-subscribed")};
{[], [SID]} -> {[], [SID]} ->
read_sub(Subscriber, NodeID, SID, Lang); read_sub(Subscriber, Node, NodeID, SID, Lang);
{[], _} -> {[], _} ->
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "subid-required")}; {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "subid-required")};
{_, _} -> {_, _} ->
read_sub(Subscriber, NodeID, SubID, Lang) read_sub(Subscriber, Node, NodeID, SubID, Lang)
end. end.
read_sub(Subscriber, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of
{error, notfound} -> {error, notfound} ->
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
{result, #pubsub_subscription{options = Options}} -> {result, #pubsub_subscription{options = Options}} ->
{result, XdataEl} = pubsub_subscription:get_options_xform(Lang, Options), {result, XdataEl} = pubsub_subscription:get_options_xform(Lang, Options),
[N] = mnesia:dirty_match_object({pubsub_node,'_',NodeID,'_','_','_','_'}), OptionsEl = {xmlelement, "options", [{"node", node_to_string(Node)},
{_, Node} = N#pubsub_node.nodeid, {"jid", jlib:jid_to_string(Subscriber)},
NodeIDStr = node_to_string(Node),
SubscriberStr = jlib:jid_to_string(Subscriber),
OptionsEl = {xmlelement, "options", [{"node", NodeIDStr},
{"jid", SubscriberStr},
{"subid", SubID}], {"subid", SubID}],
[XdataEl]}, [XdataEl]},
PubsubEl = {xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [OptionsEl]}, PubsubEl = {xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [OptionsEl]},

View File

@ -2250,7 +2250,7 @@ get_options(Host, Node, JID, SubID, Lang) ->
Action = fun(#pubsub_node{type = Type, id = NodeID}) -> Action = fun(#pubsub_node{type = Type, id = NodeID}) ->
case lists:member("subscription-options", features(Type)) of case lists:member("subscription-options", features(Type)) of
true -> true ->
get_options_helper(JID, Lang, NodeID, SubID, Type); get_options_helper(JID, Lang, Node, NodeID, SubID, Type);
false -> false ->
{error, extended_error( {error, extended_error(
?ERR_FEATURE_NOT_IMPLEMENTED, ?ERR_FEATURE_NOT_IMPLEMENTED,
@ -2262,7 +2262,7 @@ get_options(Host, Node, JID, SubID, Lang) ->
Error -> Error Error -> Error
end. end.
get_options_helper(JID, Lang, NodeID, SubID, Type) -> get_options_helper(JID, Lang, Node, NodeID, SubID, Type) ->
Subscriber = case jlib:string_to_jid(JID) of Subscriber = case jlib:string_to_jid(JID) of
error -> {"", "", ""}; error -> {"", "", ""};
J -> jlib:jid_tolower(J) J -> jlib:jid_tolower(J)
@ -2278,19 +2278,25 @@ get_options_helper(JID, Lang, NodeID, SubID, Type) ->
{_, []} -> {_, []} ->
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "not-subscribed")}; {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "not-subscribed")};
{[], [SID]} -> {[], [SID]} ->
read_sub(Subscriber, NodeID, SID, Lang); read_sub(Subscriber, Node, NodeID, SID, Lang);
{[], _} -> {[], _} ->
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "subid-required")}; {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "subid-required")};
{_, _} -> {_, _} ->
read_sub(Subscriber, NodeID, SubID, Lang) read_sub(Subscriber, Node, NodeID, SubID, Lang)
end. end.
read_sub(Subscriber, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of
{error, notfound} -> {error, notfound} ->
pubsub_subscription_odbc:get_options_xform(Lang, []); {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
{result, #pubsub_subscription{options = Options}} -> {result, #pubsub_subscription{options = Options}} ->
pubsub_subscription_odbc:get_options_xform(Lang, Options) {result, XdataEl} = pubsub_subscription_odbc:get_options_xform(Lang, Options),
OptionsEl = {xmlelement, "options", [{"node", node_to_string(Node)},
{"jid", jlib:jid_to_string(Subscriber)},
{"subid", SubID}],
[XdataEl]},
PubsubEl = {xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [OptionsEl]},
{result, PubsubEl}
end. end.
set_options(Host, Node, JID, SubID, Configuration) -> set_options(Host, Node, JID, SubID, Configuration) ->

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2009-08-28 02:05:49.000000000 +0200 --- mod_pubsub.erl 2009-09-01 15:02:18.000000000 +0200
+++ mod_pubsub_odbc.erl 2009-08-28 00:36:01.000000000 +0200 +++ mod_pubsub_odbc.erl 2009-09-01 15:14:29.000000000 +0200
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
%%% TODO %%% TODO
%%% plugin: generate Reply (do not use broadcast atom anymore) %%% plugin: generate Reply (do not use broadcast atom anymore)
@ -544,19 +544,18 @@
@@ -2460,11 +2286,11 @@ @@ -2460,11 +2286,11 @@
end. end.
read_sub(Subscriber, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
- case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of - case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of
+ case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of + case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of
{error, notfound} -> {error, notfound} ->
- {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
+ pubsub_subscription_odbc:get_options_xform(Lang, []);
{result, #pubsub_subscription{options = Options}} -> {result, #pubsub_subscription{options = Options}} ->
- pubsub_subscription:get_options_xform(Lang, Options) - {result, XdataEl} = pubsub_subscription:get_options_xform(Lang, Options),
+ pubsub_subscription_odbc:get_options_xform(Lang, Options) + {result, XdataEl} = pubsub_subscription_odbc:get_options_xform(Lang, Options),
end. OptionsEl = {xmlelement, "options", [{"node", node_to_string(Node)},
{"jid", jlib:jid_to_string(Subscriber)},
set_options(Host, Node, JID, SubID, Configuration) -> {"subid", SubID}],
@@ -2489,7 +2315,7 @@ @@ -2495,7 +2321,7 @@
error -> {"", "", ""}; error -> {"", "", ""};
J -> jlib:jid_tolower(J) J -> jlib:jid_tolower(J)
end, end,
@ -565,7 +564,7 @@
{result, Subs} = node_call(Type, get_subscriptions, {result, Subs} = node_call(Type, get_subscriptions,
[NodeID, Subscriber]), [NodeID, Subscriber]),
SubIDs = lists:foldl(fun({subscribed, SID}, Acc) -> SubIDs = lists:foldl(fun({subscribed, SID}, Acc) ->
@@ -2509,7 +2335,7 @@ @@ -2515,7 +2341,7 @@
end. end.
write_sub(Subscriber, NodeID, SubID, Options) -> write_sub(Subscriber, NodeID, SubID, Options) ->
@ -574,7 +573,7 @@
{error, notfound} -> {error, notfound} ->
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
{result, _} -> {result, _} ->
@@ -2677,8 +2503,8 @@ @@ -2683,8 +2509,8 @@
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]}, {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza} ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza}
end, end,
@ -585,7 +584,7 @@
true -> true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -2960,7 +2786,7 @@ @@ -2966,7 +2792,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]} {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end, end,
@ -594,7 +593,7 @@
{result, CollSubs} -> CollSubs; {result, CollSubs} -> CollSubs;
_ -> [] _ -> []
end. end.
@@ -2974,9 +2800,9 @@ @@ -2980,9 +2806,9 @@
get_options_for_subs(NodeID, Subs) -> get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -606,7 +605,7 @@
_ -> Acc _ -> Acc
end; end;
(_, Acc) -> (_, Acc) ->
@@ -3170,6 +2996,30 @@ @@ -3176,6 +3002,30 @@
Result Result
end. end.
@ -637,7 +636,7 @@
%% @spec (Host, Options) -> MaxItems %% @spec (Host, Options) -> MaxItems
%% Host = host() %% Host = host()
%% Options = [Option] %% Options = [Option]
@@ -3543,7 +3393,13 @@ @@ -3549,7 +3399,13 @@
tree_action(Host, Function, Args) -> tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end, Fun = fun() -> tree_call(Host, Function, Args) end,
@ -652,7 +651,7 @@
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) -> node_call(Type, Function, Args) ->
@@ -3563,13 +3419,13 @@ @@ -3569,13 +3425,13 @@
node_action(Host, Type, Function, Args) -> node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -668,7 +667,7 @@
case tree_call(Host, get_node, [Host, Node]) of case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) -> N when is_record(N, pubsub_node) ->
case Action(N) of case Action(N) of
@@ -3582,8 +3438,14 @@ @@ -3588,8 +3444,14 @@
end end
end, Trans). end, Trans).
@ -685,7 +684,7 @@
{result, Result} -> {result, Result}; {result, Result} -> {result, Result};
{error, Error} -> {error, Error}; {error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result}; {atomic, {result, Result}} -> {result, Result};
@@ -3591,6 +3453,15 @@ @@ -3597,6 +3459,15 @@
{aborted, Reason} -> {aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, ?ERR_INTERNAL_SERVER_ERROR};
@ -701,7 +700,7 @@
{'EXIT', Reason} -> {'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, ?ERR_INTERNAL_SERVER_ERROR};
@@ -3599,6 +3470,17 @@ @@ -3605,6 +3476,17 @@
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, ?ERR_INTERNAL_SERVER_ERROR}
end. end.