From 44abf1ff28baa2e8a294776909a419b95eeafbbf Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Thu, 8 Apr 2010 13:58:47 +0200 Subject: [PATCH] fix subscriptions, subscribe, and configure options (thanks to Karim Gemayel) --- src/mod_pubsub/mod_pubsub.erl | 18 +++++++++--------- src/mod_pubsub/pubsub_subscription.erl | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index 06850d397..0a6f44140 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -1286,7 +1286,7 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) -> end; {set, 'subscribe'} -> Config = case Rest of - [#xmlel{name = 'configure', children = C}] -> C; + [#xmlel{name = 'options', children = C}] -> C; _ -> [] end, JID = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'jid', ""), @@ -1312,11 +1312,11 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) -> get_subscriptions(Host, Node, From, Plugins); {get, 'affiliations'} -> get_affiliations(Host, From, Plugins); - {get, "options"} -> + {get, 'options'} -> SubID = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'subid', ""), JID = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'jid', ""), get_options(Host, Node, JID, SubID, Lang); - {set, "options"} -> + {set, 'options'} -> SubID = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'subid', ""), JID = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'jid', ""), set_options(Host, Node, JID, SubID, Els); @@ -2542,16 +2542,16 @@ get_options(Host, Node, JID, SubID, Lang) -> end end, case transaction(Host, Node, Action, sync_dirty) of - {result, {_Node, XForm}} -> {result, [XForm]}; + {result, {_Node, XForm}} -> {result, XForm}; Error -> Error end. get_options_helper(JID, Lang, Node, NodeID, SubID, Type) -> Subscriber = try exmpp_jid:parse(JID) of - J -> jlib:short_jid(J) + J -> J catch _ -> - {"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries + exmpp_jid:make("", "", "") end, {result, Subs} = node_call(Type, get_subscriptions, [NodeID, Subscriber]), @@ -2579,7 +2579,7 @@ read_sub(Subscriber, Node, NodeID, SubID, Lang) -> {result, XdataEl} = pubsub_subscription:get_options_xform(Lang, Options), OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options', attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)), - ?XMLATTR('Subid', SubID) | nodeAttr(Node)], + ?XMLATTR('subid', SubID) | nodeAttr(Node)], children = [XdataEl]}, PubsubEl = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [OptionsEl]}, {result, PubsubEl} @@ -2608,9 +2608,9 @@ set_options_helper(Configuration, JID, NodeID, SubID, Type) -> _ -> invalid end, Subscriber = try exmpp_jid:parse(JID) of - J -> jlib:short_jid(J) + J -> J catch - _ -> {"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries + _ -> exmpp_jid:make("", "", "") end, {result, Subs} = node_call(Type, get_subscriptions, [NodeID, Subscriber]), diff --git a/src/mod_pubsub/pubsub_subscription.erl b/src/mod_pubsub/pubsub_subscription.erl index 31e4aea4c..dbfa63d86 100644 --- a/src/mod_pubsub/pubsub_subscription.erl +++ b/src/mod_pubsub/pubsub_subscription.erl @@ -129,7 +129,7 @@ get_options_xform(Lang, Options) -> Keys = [deliver, show_values, subscription_type, subscription_depth], XFields = [get_option_xfield(Lang, Key, Options) || Key <- Keys], - {result, #xmlel{ns = ?NS_DATA_FORMS, name = 'x', children = + {result, #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"form">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('var', <<"FORM_TYPE">>), ?XMLATTR('type', <<"hidden">>)], @@ -140,7 +140,7 @@ get_options_xform(Lang, Options) -> parse_options_xform(XFields) -> case XFields of [] -> {result, []}; - _ -> case exmpp_xml:get_child_elements(XFields) of + _ -> case exmpp_xml:remove_cdata_from_list(XFields) of [] -> {result, []}; [#xmlel{name = 'x'} = XEl] -> case jlib:parse_xdata_submit(XEl) of @@ -271,7 +271,7 @@ type_and_options(Type, _Lang) -> tr_xfield_options({Value, Label}, Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'option', - attrs = [?XMLATTR('label', transalte:translate(Lang, Label))], + attrs = [?XMLATTR('label', translate:translate(Lang, Label))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [?XMLCDATA(Value)]}]}.