From 4221d56c04183dee57e531b946e7353de01c2bbb Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Thu, 20 Jun 2013 17:07:40 +0200 Subject: [PATCH] fix pubsub issue on binary switch --- src/mod_pubsub.erl | 4 +-- src/mod_pubsub_odbc.erl | 7 ++--- src/node_hometree_odbc.erl | 61 +++++++++++++++++--------------------- src/node_pep_odbc.erl | 4 +-- src/nodetree_tree_odbc.erl | 18 +++++------ 5 files changed, 44 insertions(+), 50 deletions(-) diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index ad9fd4b59..b5ebcf23c 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -4402,7 +4402,7 @@ broadcast_stanza(Host, _Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTy From = service_jid(Host), Stanza = case NotificationType of normal -> BaseStanza; - MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType)) + MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType))) end, %% Handles explicit subscriptions SubIDsByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth), @@ -4445,7 +4445,7 @@ broadcast_stanza({LUser, LServer, LResource}, Publisher, Node, NodeId, Type, Nod C2SPid when is_pid(C2SPid) -> Stanza = case get_option(NodeOptions, notification_type, headline) of normal -> BaseStanza; - MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType)) + MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType))) end, %% set the from address on the notification to the bare JID of the account owner %% Also, add "replyto" if entity has presence subscription to the account owner diff --git a/src/mod_pubsub_odbc.erl b/src/mod_pubsub_odbc.erl index ee438843d..cc035f347 100644 --- a/src/mod_pubsub_odbc.erl +++ b/src/mod_pubsub_odbc.erl @@ -3004,8 +3004,7 @@ send_items(Host, Node, NodeId, Type, LJID, last) -> ModifNow, ModifUSR) end, ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza); -send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, - Number) -> +send_items(Host, Node, NodeId, Type, LJID, Number) -> ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of @@ -4017,7 +4016,7 @@ broadcast_stanza(Host, _Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTy From = service_jid(Host), Stanza = case NotificationType of normal -> BaseStanza; - MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType)) + MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType))) end, %% Handles explicit subscriptions SubIDsByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth), @@ -4060,7 +4059,7 @@ broadcast_stanza({LUser, LServer, LResource}, Publisher, Node, NodeId, Type, Nod C2SPid when is_pid(C2SPid) -> Stanza = case get_option(NodeOptions, notification_type, headline) of normal -> BaseStanza; - MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType)) + MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType))) end, %% set the from address on the notification to the bare JID of the account owner %% Also, add "replyto" if entity has presence subscription to the account owner diff --git a/src/node_hometree_odbc.erl b/src/node_hometree_odbc.erl index 0b6ddbeb0..36d6c8866 100644 --- a/src/node_hometree_odbc.erl +++ b/src/node_hometree_odbc.erl @@ -232,8 +232,8 @@ delete_node(Removed) -> [<<"jid">>, <<"subscriptions">>], RItems} -> - lists:map(fun ({SJID, - Subscriptions}) -> + lists:map(fun ([SJID, + Subscriptions]) -> {decode_jid(SJID), decode_subscriptions(Subscriptions)} end, @@ -658,12 +658,12 @@ get_entity_affiliations(Host, Owner) -> [<<"node">>, <<"type">>, <<"nodeid">>, <<"affiliation">>], RItems} -> - lists:map(fun ({N, T, I, A}) -> + lists:map(fun ([N, T, I, A]) -> Node = nodetree_tree_odbc:raw_to_node(Host, - {N, + [N, <<"">>, T, - I}), + I]), {Node, decode_affiliation(A)} end, RItems); @@ -683,7 +683,7 @@ get_node_affiliations(NodeIdx) -> NodeIdx, <<"';">>]) of {selected, [<<"jid">>, <<"affiliation">>], RItems} -> - lists:map(fun ({J, A}) -> + lists:map(fun ([J, A]) -> {decode_jid(J), decode_affiliation(A)} end, RItems); @@ -708,7 +708,7 @@ get_affiliation(NodeIdx, Owner) -> NodeIdx, <<"' and jid='">>, J, <<"';">>]) of - {selected, [<<"affiliation">>], [{A}]} -> + {selected, [<<"affiliation">>], [[A]]} -> decode_affiliation(A); _ -> none end, @@ -777,13 +777,13 @@ get_entity_subscriptions(Host, Owner) -> [<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} -> - lists:foldl(fun ({N, T, I, J, S}, Acc) -> + lists:foldl(fun ([N, T, I, J, S], Acc) -> Node = nodetree_tree_odbc:raw_to_node(Host, - {N, + [N, <<"">>, T, - I}), + I]), Jid = decode_jid(J), case decode_subscriptions(S) of [] -> [{Node, none, Jid} | Acc]; @@ -852,13 +852,13 @@ get_entity_subscriptions_for_send_last(Host, Owner) -> [<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} -> - lists:foldl(fun ({N, T, I, J, S}, Acc) -> + lists:foldl(fun ([N, T, I, J, S], Acc) -> Node = nodetree_tree_odbc:raw_to_node(Host, - {N, + [N, <<"">>, T, - I}), + I]), Jid = decode_jid(J), case decode_subscriptions(S) of [] -> [{Node, none, Jid} | Acc]; @@ -886,7 +886,7 @@ get_node_subscriptions(NodeIdx) -> NodeIdx, <<"';">>]) of {selected, [<<"jid">>, <<"subscriptions">>], RItems} -> - lists:foldl(fun ({J, S}, Acc) -> + lists:foldl(fun ([J, S], Acc) -> Jid = decode_jid(J), case decode_subscriptions(S) of [] -> [{Jid, none} | Acc]; @@ -917,7 +917,7 @@ get_subscriptions(NodeIdx, Owner) -> NodeIdx, <<"' and jid='">>, J, <<"';">>]) of - {selected, [<<"subscriptions">>], [{S}]} -> + {selected, [<<"subscriptions">>], [[S]]} -> decode_subscriptions(S); _ -> [] end, @@ -1104,7 +1104,7 @@ get_states(NodeIdx) -> [<<"jid">>, <<"affiliation">>, <<"subscriptions">>], RItems} -> {result, - lists:map(fun ({SJID, Affiliation, Subscriptions}) -> + lists:map(fun ([SJID, Affiliation, Subscriptions]) -> #pubsub_state{stateid = {decode_jid(SJID), NodeIdx}, items = itemids(NodeIdx, SJID), affiliation = decode_affiliation(Affiliation), @@ -1147,7 +1147,7 @@ get_state_without_itemids(NodeIdx, JID) -> of {selected, [<<"jid">>, <<"affiliation">>, <<"subscriptions">>], - [{SJID, Affiliation, Subscriptions}]} -> + [[SJID, Affiliation, Subscriptions]]} -> #pubsub_state{stateid = {decode_jid(SJID), NodeIdx}, affiliation = decode_affiliation(Affiliation), subscriptions = decode_subscriptions(Subscriptions)}; @@ -1243,7 +1243,7 @@ get_items(NodeId, From, none) -> NodeId, <<"' and name='max_items';">>]) of - {selected, [<<"val">>], [{Value}]} -> + {selected, [<<"val">>], [[Value]]} -> Tokens = element(2, erl_scan:string(<>)), element(2, erl_parse:parse_term(Tokens)); @@ -1274,7 +1274,7 @@ get_items(NodeId, _From, (?PUBSUB):escape(i2l(IncIndex)), <<" );">>]) of - {selected, [_], [{O}]} -> + {selected, [_], [[O]]} -> [<<"modification">>, <<"'", O/binary, "'">>]; _ -> [<<"modification">>, <<"null">>] end; @@ -1290,7 +1290,7 @@ get_items(NodeId, _From, "nodeid='">>, NodeId, <<"';">>]) of - {selected, [_], [{C}]} -> C; + {selected, [_], [[C]]} -> C; _ -> <<"0">> end, case catch @@ -1309,7 +1309,7 @@ get_items(NodeId, _From, case str:len(RItems) of 0 -> {result, {[], #rsm_out{count = Count}}}; _ -> - {_, _, _, F, _} = hd(RItems), + [_, _, _, F, _] = hd(RItems), Index = case catch ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item where " "nodeid='">>, @@ -1318,10 +1318,10 @@ get_items(NodeId, _From, F, <<"';">>]) of %{selected, [_], [{C}, {In}]} -> [string:strip(C, both, $"), string:strip(In, both, $")]; - {selected, [_], [{In}]} -> In; + {selected, [_], [[In]]} -> In; _ -> <<"0">> end, - {_, _, _, L, _} = lists:last(RItems), + [_, _, _, L, _] = lists:last(RItems), RsmOut = #rsm_out{count = Count, index = Index, first = <<"modification@", F/binary>>, last = <<"modification@", (i2l(L))/binary>>}, @@ -1462,14 +1462,9 @@ set_item(Item) -> {M, JID} = Item#pubsub_item.modification, P = encode_jid(JID), Payload = Item#pubsub_item.payload, - XML = (?PUBSUB):escape(lists:flatten(lists:map(fun - (X) -> - xml:element_to_binary(X) - end, - Payload))), + XML = (?PUBSUB):escape(str:join([xml:element_to_binary(X) || X<-Payload], <<>>)), S = fun ({T1, T2, T3}) -> - lists:flatten([i2l(T1, 6), <<":">>, i2l(T2, 6), <<":">>, - i2l(T3, 6)]) + str:join([i2l(T1, 6), i2l(T2, 6), i2l(T3, 6)], <<":">>) end, case catch ejabberd_odbc:sql_query_t([<<"update pubsub_item set publisher='">>, @@ -1557,7 +1552,7 @@ itemids(NodeId, SJID) -> <<"%' order by modification desc;">>]) of {selected, [<<"itemid">>], RItems} -> - lists:map(fun ({ItemId}) -> ItemId end, RItems); + lists:map(fun ([ItemId]) -> ItemId end, RItems); _ -> [] end. @@ -1569,7 +1564,7 @@ select_affiliation_subscriptions(NodeId, JID) -> NodeId, <<"' and jid='">>, J, <<"';">>]) of {selected, [<<"affiliation">>, <<"subscriptions">>], - [{A, S}]} -> + [[A, S]]} -> {decode_affiliation(A), decode_subscriptions(S)}; _ -> {none, []} end. @@ -1681,7 +1676,7 @@ state_to_raw(NodeId, State) -> <<"', '">>, S, <<"'">>]. raw_to_item(NodeId, - {ItemId, SJID, Creation, Modification, XML}) -> + [ItemId, SJID, Creation, Modification, XML]) -> JID = decode_jid(SJID), ToTime = fun (Str) -> [T1, T2, T3] = str:tokens(Str, <<":">>), diff --git a/src/node_pep_odbc.erl b/src/node_pep_odbc.erl index d997d9ce1..df820437d 100644 --- a/src/node_pep_odbc.erl +++ b/src/node_pep_odbc.erl @@ -303,7 +303,7 @@ get_entity_subscriptions(_Host, Owner) -> [<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} -> - lists:map(fun ({H, N, T, I, J, S}) -> + lists:map(fun ([H, N, T, I, J, S]) -> O = node_hometree_odbc:decode_jid(H), Node = nodetree_tree_odbc:raw_to_node(O, {N, @@ -351,7 +351,7 @@ get_entity_subscriptions_for_send_last(_Host, Owner) -> [<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} -> - lists:map(fun ({H, N, T, I, J, S}) -> + lists:map(fun ([H, N, T, I, J, S]) -> O = node_hometree_odbc:decode_jid(H), Node = nodetree_tree_odbc:raw_to_node(O, {N, diff --git a/src/nodetree_tree_odbc.erl b/src/nodetree_tree_odbc.erl index 9756b897b..1b82b45e5 100644 --- a/src/nodetree_tree_odbc.erl +++ b/src/nodetree_tree_odbc.erl @@ -122,8 +122,8 @@ get_node(NodeIdx) -> of {selected, [<<"host">>, <<"node">>, <<"parent">>, <<"type">>], - [{Host, Node, Parent, Type}]} -> - raw_to_node(Host, {Node, Parent, Type, NodeIdx}); + [[Host, Node, Parent, Type]]} -> + raw_to_node(Host, [Node, Parent, Type, NodeIdx]); {'EXIT', _Reason} -> {error, ?ERR_INTERNAL_SERVER_ERROR}; _ -> {error, ?ERR_ITEM_NOT_FOUND} @@ -331,19 +331,19 @@ delete_node(Host, Node) -> NodeIdx::mod_pubsub:nodeIdx()}) -> mod_pubsub:pubsubNode() ). -raw_to_node(Host, {Node, Parent, Type, NodeIdx}) -> +raw_to_node(Host, [Node, Parent, Type, NodeIdx]) -> Options = case catch ejabberd_odbc:sql_query_t([<<"select name,val from pubsub_node_option " "where nodeid='">>, NodeIdx, <<"';">>]) of {selected, [<<"name">>, <<"val">>], ROptions} -> - DbOpts = lists:map(fun ({Key, Value}) -> + DbOpts = lists:map(fun ([Key, Value]) -> RKey = jlib:binary_to_atom(Key), Tokens = element(2, - erl_scan:string(<>)), + erl_scan:string( + binary_to_list(<>))), RValue = element(2, erl_parse:parse_term(Tokens)), {RKey, RValue} @@ -415,8 +415,8 @@ set_node(Record) -> lists:foreach(fun ({Key, Value}) -> SKey = iolist_to_binary(atom_to_list(Key)), SValue = - (?PUBSUB):escape(lists:flatten(io_lib:fwrite("~p", - [Value]))), + (?PUBSUB):escape(list_to_binary(lists:flatten(io_lib:fwrite("~p", + [Value])))), catch ejabberd_odbc:sql_query_t([<<"insert into pubsub_node_option(nodeid, " "name, val) values('">>, @@ -445,7 +445,7 @@ nodeid(Host, NodeId) -> "host='">>, H, <<"' and node='">>, N, <<"';">>]) of - {selected, [<<"nodeid">>], [{NodeIdx}]} -> + {selected, [<<"nodeid">>], [[NodeIdx]]} -> {result, NodeIdx}; {'EXIT', _Reason} -> {error, ?ERR_INTERNAL_SERVER_ERROR};