25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

add the ability to send raw xml packets over http bind

This commit is contained in:
Christopher tofu Zorn 2010-06-01 14:52:15 -04:00 committed by Badlop
parent 3e67200d64
commit 3e24408710
2 changed files with 23 additions and 8 deletions

View File

@ -1504,6 +1504,10 @@ change_shaper(StateData, JID) ->
StateData#state.shaper, JID),
(StateData#state.sockmod):change_shaper(StateData#state.socket, Shaper).
send_text(StateData, Text) when StateData#state.xml_socket ->
?DEBUG("Send Text on stream = ~p", [lists:flatten(Text)]),
(StateData#state.sockmod):send_xml(StateData#state.socket,
{xmlstreamraw, Text});
send_text(StateData, Text) ->
?DEBUG("Send XML on stream = ~p", [Text]),
(StateData#state.sockmod):send(StateData#state.socket, Text).

View File

@ -928,6 +928,7 @@ prepare_response(Sess, Rid, OutputEls, StreamStart) ->
prepare_outpacket_response(Sess, _Rid, OutPacket, false) ->
case catch send_outpacket(Sess, OutPacket) of
{'EXIT', _Reason} ->
?DEBUG("Error in sending packet ~p ", [_Reason]),
{200, ?HEADER,
"<body type='terminate' xmlns='"++
?NS_HTTP_BIND++"'/>"};
@ -1034,17 +1035,25 @@ send_outpacket(#http_bind{pid = FsmRef}, OutPacket) ->
lists:all(fun({xmlstreamelement,
{xmlelement, "stream:error", _, _}}) -> false;
({xmlstreamelement, _}) -> true;
({xmlstreamraw, _}) -> true;
(_) -> false
end, OutPacket),
case AllElements of
true ->
TypedEls = [check_default_xmlns(OEl) ||
{xmlstreamelement, OEl} <- OutPacket],
Body = xml:element_to_binary(
{xmlelement,"body",
[{"xmlns",
?NS_HTTP_BIND}],
TypedEls}),
TypedEls = lists:foldr(fun({xmlstreamelement, El}, Acc) ->
Acc ++
[xml:element_to_string(
check_default_xmlns(El)
)];
({xmlstreamraw, R}, Acc) ->
Acc ++ [R]
end,
[],
OutPacket),
Body = "<body xmlns='"++?NS_HTTP_BIND++"'>"
++ TypedEls ++
"</body>",
?DEBUG(" --- outgoing data --- ~n~s~n --- END --- ~n",
[Body]),
{200, ?HEADER, Body};
@ -1218,7 +1227,9 @@ check_default_xmlns({xmlelement, Name, Attrs, Els} = El) ->
case xml:get_tag_attr_s("xmlns", El) of
"" -> {xmlelement, Name, [{"xmlns", ?NS_CLIENT} | Attrs], Els};
_ -> El
end.
end;
check_default_xmlns(El) ->
El.
%% Check that mod_http_bind has been defined in config file.
%% Print a warning in log file if this is not the case.