diff options
author | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-07-09 01:01:56 +0300 |
---|---|---|
committer | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-07-09 01:01:56 +0300 |
commit | 3e88a0b0b4bc72d4b35024ef9416c922d4189780 (patch) | |
tree | 269af4dd7af073efbe9e48815952bb031e2d70ad /src/mod_admin_extra.erl | |
parent | Don't expose internal FSM API of mod_muc_room (diff) |
Don't expose internal FSM API of ejabberd_c2s
Diffstat (limited to 'src/mod_admin_extra.erl')
-rw-r--r-- | src/mod_admin_extra.erl | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/mod_admin_extra.erl b/src/mod_admin_extra.erl index 5de3a96c9..8d6689613 100644 --- a/src/mod_admin_extra.erl +++ b/src/mod_admin_extra.erl @@ -1510,16 +1510,24 @@ send_stanza(FromString, ToString, Stanza) -> {error, "JID malformed"} end. +-spec send_stanza_c2s(binary(), binary(), binary(), binary()) -> ok | {error, any()}. send_stanza_c2s(Username, Host, Resource, Stanza) -> - case {fxml_stream:parse_element(Stanza), - ejabberd_sm:get_session_pid(Username, Host, Resource)} - of - {{error, Error}, _} -> - {error, Error}; - {_, none} -> - {error, no_session}; - {XmlEl, C2sPid} -> - p1_fsm:send_event(C2sPid, {xmlstreamelement, XmlEl}) + try + #xmlel{} = El = fxml_stream:parse_element(Stanza), + CodecOpts = ejabberd_config:codec_options(), + Pkt = xmpp:decode(El, ?NS_CLIENT, CodecOpts), + case ejabberd_sm:get_session_pid(Username, Host, Resource) of + Pid when is_pid(Pid) -> + ejabberd_c2s:send(Pid, Pkt); + _ -> + {error, no_session} + end + catch _:{badmatch, {error, Why} = Err} -> + io:format("invalid xml: ~p~n", [Why]), + Err; + _:{xmpp_codec, Why} -> + io:format("incorrect stanza: ~s~n", [xmpp:format_error(Why)]), + {error, Why} end. privacy_set(Username, Host, QueryS) -> |