From 312574cbc5a0591aefc1ea94e3b77e419a372f10 Mon Sep 17 00:00:00 2001 From: Christopher tofu Zorn Date: Tue, 1 Jun 2010 14:52:15 -0400 Subject: [PATCH] add the ability to send raw xml packets over http bind --- src/ejabberd_c2s.erl | 4 ++++ src/web/ejabberd_http_bind.erl | 30 +++++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 8af5f47a7..bb5e288e6 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -1499,6 +1499,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 = ~s", [Text]), (StateData#state.sockmod):send(StateData#state.socket, Text). diff --git a/src/web/ejabberd_http_bind.erl b/src/web/ejabberd_http_bind.erl index c83b59534..e04858eb5 100644 --- a/src/web/ejabberd_http_bind.erl +++ b/src/web/ejabberd_http_bind.erl @@ -992,6 +992,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, ""}; @@ -1135,20 +1136,25 @@ send_outpacket(#http_bind{pid = FsmRef}, OutPacket) -> declared_ns = [{undefined, ?NS_XMPP_pfx}]}}) -> false; % {xmlelement, "stream:error", _, _}}) -> false; ({xmlstreamelement, _}) -> true; + ({xmlstreamraw, _}) -> true; (_) -> false end, OutPacket), case AllElements of true -> - TypedEls = [check_default_xmlns(OEl) || - {xmlstreamelement, OEl} <- OutPacket], - Body = exmpp_xml:document_to_list( - #xmlel{name = 'body', - ns = ?NS_HTTP_BIND_s, - children = TypedEls}), -% {xmlelement,"body", -% [{"xmlns", -% ?NS_HTTP_BIND_s}], -% TypedEls}), + TypedEls = lists:foldr(fun({xmlstreamelement, El}, Acc) -> + Acc ++ + [exmpp_xml:document_to_list( + check_default_xmlns(El) + )]; + ({xmlstreamraw, R}, Acc) -> + Acc ++ [R] + end, + [], + OutPacket), + + Body = "" + ++ TypedEls ++ + "", ?DEBUG(" --- outgoing data --- ~n~s~n --- END --- ~n", [Body]), {200, ?HEADER, Body}; @@ -1345,7 +1351,9 @@ check_default_xmlns(#xmlel{name = Name, ns = Xmlns, attrs = Attrs, children = El "" -> #xmlel{name = Name, ns = ?NS_JABBER_CLIENT_s, attrs = Attrs, children = Els}; % "" -> {xmlelement, Name, [{"xmlns", ?NS_JABBER_CLIENT_s} | 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.