summaryrefslogtreecommitdiff
path: root/src/mod_admin_extra.erl
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2016-01-19 16:16:04 +0100
committerChristophe Romain <christophe.romain@process-one.net>2016-01-19 16:16:04 +0100
commit2ddbd032ee96778434c07389f075b7b59f52f49e (patch)
tree22581d55c59096fa39cc51a28dbcdf6f534ed5be /src/mod_admin_extra.erl
parentmod_mam: Strip existing JID tags from MUC messages (diff)
Add error handling to send_stanza
Diffstat (limited to 'src/mod_admin_extra.erl')
-rw-r--r--src/mod_admin_extra.erl28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/mod_admin_extra.erl b/src/mod_admin_extra.erl
index e7911fc2..1c228a35 100644
--- a/src/mod_admin_extra.erl
+++ b/src/mod_admin_extra.erl
@@ -1332,16 +1332,28 @@ build_packet(Type, Subject, Body) ->
[{xmlel, <<"body">>, [], [{xmlcdata, Body}]} | Tail]
}.
-send_stanza(FromString, ToString, Data) ->
- Stanza = {xmlel, _, _, _} = xml_stream:parse_element(Data),
- From = jid:from_string(FromString),
- To = jid:from_string(ToString),
- ejabberd_router:route(From, To, Stanza).
+send_stanza(FromString, ToString, Stanza) ->
+ case xml_stream:parse_element(Stanza) of
+ {error, Error} ->
+ {error, Error};
+ XmlEl ->
+ #xmlel{attrs = Attrs} = XmlEl,
+ From = jid:from_string(proplists:get_value(<<"from">>, Attrs, FromString)),
+ To = jid:from_string(proplists:get_value(<<"to">>, Attrs, ToString)),
+ ejabberd_router:route(From, To, XmlEl)
+ end.
send_stanza_c2s(Username, Host, Resource, Stanza) ->
- C2sPid = ejabberd_sm:get_session_pid(Username, Host, Resource),
- XmlEl = xml_stream:parse_element(Stanza),
- p1_fsm:send_event(C2sPid, {xmlstreamelement, XmlEl}).
+ case {xml_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})
+ end.
privacy_set(Username, Host, QueryS) ->
From = jid:make(Username, Host, <<"">>),