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

fix pubsub issue on binary switch

This commit is contained in:
Christophe Romain 2013-06-20 17:07:40 +02:00
parent 4dc80dddd4
commit 4221d56c04
5 changed files with 44 additions and 50 deletions

View File

@ -4402,7 +4402,7 @@ broadcast_stanza(Host, _Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTy
From = service_jid(Host), From = service_jid(Host),
Stanza = case NotificationType of Stanza = case NotificationType of
normal -> BaseStanza; normal -> BaseStanza;
MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType)) MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType)))
end, end,
%% Handles explicit subscriptions %% Handles explicit subscriptions
SubIDsByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth), 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) -> C2SPid when is_pid(C2SPid) ->
Stanza = case get_option(NodeOptions, notification_type, headline) of Stanza = case get_option(NodeOptions, notification_type, headline) of
normal -> BaseStanza; normal -> BaseStanza;
MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType)) MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType)))
end, end,
%% set the from address on the notification to the bare JID of the account owner %% 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 %% Also, add "replyto" if entity has presence subscription to the account owner

View File

@ -3004,8 +3004,7 @@ send_items(Host, Node, NodeId, Type, LJID, last) ->
ModifNow, ModifUSR) ModifNow, ModifUSR)
end, end,
ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza); ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza);
send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, send_items(Host, Node, NodeId, Type, LJID, Number) ->
Number) ->
ToSend = case node_action(Host, Type, get_items, ToSend = case node_action(Host, Type, get_items,
[NodeId, LJID]) [NodeId, LJID])
of of
@ -4017,7 +4016,7 @@ broadcast_stanza(Host, _Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTy
From = service_jid(Host), From = service_jid(Host),
Stanza = case NotificationType of Stanza = case NotificationType of
normal -> BaseStanza; normal -> BaseStanza;
MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType)) MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType)))
end, end,
%% Handles explicit subscriptions %% Handles explicit subscriptions
SubIDsByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth), 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) -> C2SPid when is_pid(C2SPid) ->
Stanza = case get_option(NodeOptions, notification_type, headline) of Stanza = case get_option(NodeOptions, notification_type, headline) of
normal -> BaseStanza; normal -> BaseStanza;
MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType)) MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType)))
end, end,
%% set the from address on the notification to the bare JID of the account owner %% 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 %% Also, add "replyto" if entity has presence subscription to the account owner

View File

@ -232,8 +232,8 @@ delete_node(Removed) ->
[<<"jid">>, [<<"jid">>,
<<"subscriptions">>], <<"subscriptions">>],
RItems} -> RItems} ->
lists:map(fun ({SJID, lists:map(fun ([SJID,
Subscriptions}) -> Subscriptions]) ->
{decode_jid(SJID), {decode_jid(SJID),
decode_subscriptions(Subscriptions)} decode_subscriptions(Subscriptions)}
end, end,
@ -658,12 +658,12 @@ get_entity_affiliations(Host, Owner) ->
[<<"node">>, <<"type">>, <<"nodeid">>, [<<"node">>, <<"type">>, <<"nodeid">>,
<<"affiliation">>], <<"affiliation">>],
RItems} -> RItems} ->
lists:map(fun ({N, T, I, A}) -> lists:map(fun ([N, T, I, A]) ->
Node = nodetree_tree_odbc:raw_to_node(Host, Node = nodetree_tree_odbc:raw_to_node(Host,
{N, [N,
<<"">>, <<"">>,
T, T,
I}), I]),
{Node, decode_affiliation(A)} {Node, decode_affiliation(A)}
end, end,
RItems); RItems);
@ -683,7 +683,7 @@ get_node_affiliations(NodeIdx) ->
NodeIdx, <<"';">>]) NodeIdx, <<"';">>])
of of
{selected, [<<"jid">>, <<"affiliation">>], RItems} -> {selected, [<<"jid">>, <<"affiliation">>], RItems} ->
lists:map(fun ({J, A}) -> lists:map(fun ([J, A]) ->
{decode_jid(J), decode_affiliation(A)} {decode_jid(J), decode_affiliation(A)}
end, end,
RItems); RItems);
@ -708,7 +708,7 @@ get_affiliation(NodeIdx, Owner) ->
NodeIdx, <<"' and jid='">>, J, NodeIdx, <<"' and jid='">>, J,
<<"';">>]) <<"';">>])
of of
{selected, [<<"affiliation">>], [{A}]} -> {selected, [<<"affiliation">>], [[A]]} ->
decode_affiliation(A); decode_affiliation(A);
_ -> none _ -> none
end, end,
@ -777,13 +777,13 @@ get_entity_subscriptions(Host, Owner) ->
[<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, [<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>,
<<"subscriptions">>], <<"subscriptions">>],
RItems} -> RItems} ->
lists:foldl(fun ({N, T, I, J, S}, Acc) -> lists:foldl(fun ([N, T, I, J, S], Acc) ->
Node = Node =
nodetree_tree_odbc:raw_to_node(Host, nodetree_tree_odbc:raw_to_node(Host,
{N, [N,
<<"">>, <<"">>,
T, T,
I}), I]),
Jid = decode_jid(J), Jid = decode_jid(J),
case decode_subscriptions(S) of case decode_subscriptions(S) of
[] -> [{Node, none, Jid} | Acc]; [] -> [{Node, none, Jid} | Acc];
@ -852,13 +852,13 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
[<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, [<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>,
<<"subscriptions">>], <<"subscriptions">>],
RItems} -> RItems} ->
lists:foldl(fun ({N, T, I, J, S}, Acc) -> lists:foldl(fun ([N, T, I, J, S], Acc) ->
Node = Node =
nodetree_tree_odbc:raw_to_node(Host, nodetree_tree_odbc:raw_to_node(Host,
{N, [N,
<<"">>, <<"">>,
T, T,
I}), I]),
Jid = decode_jid(J), Jid = decode_jid(J),
case decode_subscriptions(S) of case decode_subscriptions(S) of
[] -> [{Node, none, Jid} | Acc]; [] -> [{Node, none, Jid} | Acc];
@ -886,7 +886,7 @@ get_node_subscriptions(NodeIdx) ->
NodeIdx, <<"';">>]) NodeIdx, <<"';">>])
of of
{selected, [<<"jid">>, <<"subscriptions">>], RItems} -> {selected, [<<"jid">>, <<"subscriptions">>], RItems} ->
lists:foldl(fun ({J, S}, Acc) -> lists:foldl(fun ([J, S], Acc) ->
Jid = decode_jid(J), Jid = decode_jid(J),
case decode_subscriptions(S) of case decode_subscriptions(S) of
[] -> [{Jid, none} | Acc]; [] -> [{Jid, none} | Acc];
@ -917,7 +917,7 @@ get_subscriptions(NodeIdx, Owner) ->
NodeIdx, <<"' and jid='">>, J, NodeIdx, <<"' and jid='">>, J,
<<"';">>]) <<"';">>])
of of
{selected, [<<"subscriptions">>], [{S}]} -> {selected, [<<"subscriptions">>], [[S]]} ->
decode_subscriptions(S); decode_subscriptions(S);
_ -> [] _ -> []
end, end,
@ -1104,7 +1104,7 @@ get_states(NodeIdx) ->
[<<"jid">>, <<"affiliation">>, <<"subscriptions">>], [<<"jid">>, <<"affiliation">>, <<"subscriptions">>],
RItems} -> RItems} ->
{result, {result,
lists:map(fun ({SJID, Affiliation, Subscriptions}) -> lists:map(fun ([SJID, Affiliation, Subscriptions]) ->
#pubsub_state{stateid = {decode_jid(SJID), NodeIdx}, #pubsub_state{stateid = {decode_jid(SJID), NodeIdx},
items = itemids(NodeIdx, SJID), items = itemids(NodeIdx, SJID),
affiliation = decode_affiliation(Affiliation), affiliation = decode_affiliation(Affiliation),
@ -1147,7 +1147,7 @@ get_state_without_itemids(NodeIdx, JID) ->
of of
{selected, {selected,
[<<"jid">>, <<"affiliation">>, <<"subscriptions">>], [<<"jid">>, <<"affiliation">>, <<"subscriptions">>],
[{SJID, Affiliation, Subscriptions}]} -> [[SJID, Affiliation, Subscriptions]]} ->
#pubsub_state{stateid = {decode_jid(SJID), NodeIdx}, #pubsub_state{stateid = {decode_jid(SJID), NodeIdx},
affiliation = decode_affiliation(Affiliation), affiliation = decode_affiliation(Affiliation),
subscriptions = decode_subscriptions(Subscriptions)}; subscriptions = decode_subscriptions(Subscriptions)};
@ -1243,7 +1243,7 @@ get_items(NodeId, From, none) ->
NodeId, NodeId,
<<"' and name='max_items';">>]) <<"' and name='max_items';">>])
of of
{selected, [<<"val">>], [{Value}]} -> {selected, [<<"val">>], [[Value]]} ->
Tokens = element(2, Tokens = element(2,
erl_scan:string(<<Value/binary, ".">>)), erl_scan:string(<<Value/binary, ".">>)),
element(2, erl_parse:parse_term(Tokens)); element(2, erl_parse:parse_term(Tokens));
@ -1274,7 +1274,7 @@ get_items(NodeId, _From,
(?PUBSUB):escape(i2l(IncIndex)), (?PUBSUB):escape(i2l(IncIndex)),
<<" );">>]) <<" );">>])
of of
{selected, [_], [{O}]} -> {selected, [_], [[O]]} ->
[<<"modification">>, <<"'", O/binary, "'">>]; [<<"modification">>, <<"'", O/binary, "'">>];
_ -> [<<"modification">>, <<"null">>] _ -> [<<"modification">>, <<"null">>]
end; end;
@ -1290,7 +1290,7 @@ get_items(NodeId, _From,
"nodeid='">>, "nodeid='">>,
NodeId, <<"';">>]) NodeId, <<"';">>])
of of
{selected, [_], [{C}]} -> C; {selected, [_], [[C]]} -> C;
_ -> <<"0">> _ -> <<"0">>
end, end,
case catch case catch
@ -1309,7 +1309,7 @@ get_items(NodeId, _From,
case str:len(RItems) of case str:len(RItems) of
0 -> {result, {[], #rsm_out{count = Count}}}; 0 -> {result, {[], #rsm_out{count = Count}}};
_ -> _ ->
{_, _, _, F, _} = hd(RItems), [_, _, _, F, _] = hd(RItems),
Index = case catch Index = case catch
ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item where " ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item where "
"nodeid='">>, "nodeid='">>,
@ -1318,10 +1318,10 @@ get_items(NodeId, _From,
F, <<"';">>]) F, <<"';">>])
of of
%{selected, [_], [{C}, {In}]} -> [string:strip(C, both, $"), string:strip(In, both, $")]; %{selected, [_], [{C}, {In}]} -> [string:strip(C, both, $"), string:strip(In, both, $")];
{selected, [_], [{In}]} -> In; {selected, [_], [[In]]} -> In;
_ -> <<"0">> _ -> <<"0">>
end, end,
{_, _, _, L, _} = lists:last(RItems), [_, _, _, L, _] = lists:last(RItems),
RsmOut = #rsm_out{count = Count, index = Index, RsmOut = #rsm_out{count = Count, index = Index,
first = <<"modification@", F/binary>>, first = <<"modification@", F/binary>>,
last = <<"modification@", (i2l(L))/binary>>}, last = <<"modification@", (i2l(L))/binary>>},
@ -1462,14 +1462,9 @@ set_item(Item) ->
{M, JID} = Item#pubsub_item.modification, {M, JID} = Item#pubsub_item.modification,
P = encode_jid(JID), P = encode_jid(JID),
Payload = Item#pubsub_item.payload, Payload = Item#pubsub_item.payload,
XML = (?PUBSUB):escape(lists:flatten(lists:map(fun XML = (?PUBSUB):escape(str:join([xml:element_to_binary(X) || X<-Payload], <<>>)),
(X) ->
xml:element_to_binary(X)
end,
Payload))),
S = fun ({T1, T2, T3}) -> S = fun ({T1, T2, T3}) ->
lists:flatten([i2l(T1, 6), <<":">>, i2l(T2, 6), <<":">>, str:join([i2l(T1, 6), i2l(T2, 6), i2l(T3, 6)], <<":">>)
i2l(T3, 6)])
end, end,
case catch case catch
ejabberd_odbc:sql_query_t([<<"update pubsub_item set publisher='">>, ejabberd_odbc:sql_query_t([<<"update pubsub_item set publisher='">>,
@ -1557,7 +1552,7 @@ itemids(NodeId, SJID) ->
<<"%' order by modification desc;">>]) <<"%' order by modification desc;">>])
of of
{selected, [<<"itemid">>], RItems} -> {selected, [<<"itemid">>], RItems} ->
lists:map(fun ({ItemId}) -> ItemId end, RItems); lists:map(fun ([ItemId]) -> ItemId end, RItems);
_ -> [] _ -> []
end. end.
@ -1569,7 +1564,7 @@ select_affiliation_subscriptions(NodeId, JID) ->
NodeId, <<"' and jid='">>, J, <<"';">>]) NodeId, <<"' and jid='">>, J, <<"';">>])
of of
{selected, [<<"affiliation">>, <<"subscriptions">>], {selected, [<<"affiliation">>, <<"subscriptions">>],
[{A, S}]} -> [[A, S]]} ->
{decode_affiliation(A), decode_subscriptions(S)}; {decode_affiliation(A), decode_subscriptions(S)};
_ -> {none, []} _ -> {none, []}
end. end.
@ -1681,7 +1676,7 @@ state_to_raw(NodeId, State) ->
<<"', '">>, S, <<"'">>]. <<"', '">>, S, <<"'">>].
raw_to_item(NodeId, raw_to_item(NodeId,
{ItemId, SJID, Creation, Modification, XML}) -> [ItemId, SJID, Creation, Modification, XML]) ->
JID = decode_jid(SJID), JID = decode_jid(SJID),
ToTime = fun (Str) -> ToTime = fun (Str) ->
[T1, T2, T3] = str:tokens(Str, <<":">>), [T1, T2, T3] = str:tokens(Str, <<":">>),

View File

@ -303,7 +303,7 @@ get_entity_subscriptions(_Host, Owner) ->
[<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>, [<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>,
<<"jid">>, <<"subscriptions">>], <<"jid">>, <<"subscriptions">>],
RItems} -> 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), O = node_hometree_odbc:decode_jid(H),
Node = nodetree_tree_odbc:raw_to_node(O, Node = nodetree_tree_odbc:raw_to_node(O,
{N, {N,
@ -351,7 +351,7 @@ get_entity_subscriptions_for_send_last(_Host, Owner) ->
[<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>, [<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>,
<<"jid">>, <<"subscriptions">>], <<"jid">>, <<"subscriptions">>],
RItems} -> 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), O = node_hometree_odbc:decode_jid(H),
Node = nodetree_tree_odbc:raw_to_node(O, Node = nodetree_tree_odbc:raw_to_node(O,
{N, {N,

View File

@ -122,8 +122,8 @@ get_node(NodeIdx) ->
of of
{selected, {selected,
[<<"host">>, <<"node">>, <<"parent">>, <<"type">>], [<<"host">>, <<"node">>, <<"parent">>, <<"type">>],
[{Host, Node, Parent, Type}]} -> [[Host, Node, Parent, Type]]} ->
raw_to_node(Host, {Node, Parent, Type, NodeIdx}); raw_to_node(Host, [Node, Parent, Type, NodeIdx]);
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, ?ERR_INTERNAL_SERVER_ERROR};
_ -> {error, ?ERR_ITEM_NOT_FOUND} _ -> {error, ?ERR_ITEM_NOT_FOUND}
@ -331,19 +331,19 @@ delete_node(Host, Node) ->
NodeIdx::mod_pubsub:nodeIdx()}) NodeIdx::mod_pubsub:nodeIdx()})
-> mod_pubsub:pubsubNode() -> mod_pubsub:pubsubNode()
). ).
raw_to_node(Host, {Node, Parent, Type, NodeIdx}) -> raw_to_node(Host, [Node, Parent, Type, NodeIdx]) ->
Options = case catch Options = case catch
ejabberd_odbc:sql_query_t([<<"select name,val from pubsub_node_option " ejabberd_odbc:sql_query_t([<<"select name,val from pubsub_node_option "
"where nodeid='">>, "where nodeid='">>,
NodeIdx, <<"';">>]) NodeIdx, <<"';">>])
of of
{selected, [<<"name">>, <<"val">>], ROptions} -> {selected, [<<"name">>, <<"val">>], ROptions} ->
DbOpts = lists:map(fun ({Key, Value}) -> DbOpts = lists:map(fun ([Key, Value]) ->
RKey = RKey =
jlib:binary_to_atom(Key), jlib:binary_to_atom(Key),
Tokens = element(2, Tokens = element(2,
erl_scan:string(<<Value/binary, erl_scan:string(
".">>)), binary_to_list(<<Value/binary, ".">>))),
RValue = element(2, RValue = element(2,
erl_parse:parse_term(Tokens)), erl_parse:parse_term(Tokens)),
{RKey, RValue} {RKey, RValue}
@ -415,8 +415,8 @@ set_node(Record) ->
lists:foreach(fun ({Key, Value}) -> lists:foreach(fun ({Key, Value}) ->
SKey = iolist_to_binary(atom_to_list(Key)), SKey = iolist_to_binary(atom_to_list(Key)),
SValue = SValue =
(?PUBSUB):escape(lists:flatten(io_lib:fwrite("~p", (?PUBSUB):escape(list_to_binary(lists:flatten(io_lib:fwrite("~p",
[Value]))), [Value])))),
catch catch
ejabberd_odbc:sql_query_t([<<"insert into pubsub_node_option(nodeid, " ejabberd_odbc:sql_query_t([<<"insert into pubsub_node_option(nodeid, "
"name, val) values('">>, "name, val) values('">>,
@ -445,7 +445,7 @@ nodeid(Host, NodeId) ->
"host='">>, "host='">>,
H, <<"' and node='">>, N, <<"';">>]) H, <<"' and node='">>, N, <<"';">>])
of of
{selected, [<<"nodeid">>], [{NodeIdx}]} -> {selected, [<<"nodeid">>], [[NodeIdx]]} ->
{result, NodeIdx}; {result, NodeIdx};
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, ?ERR_INTERNAL_SERVER_ERROR};