Permalink
Browse files

Do not crash the exmpp_component process if it receives an erroneous …

…stanza (thanks Thiago Camargo!)

Try to not crash the process, instead, deliver a #received_packet{} to the client code,
with all but the raw_packet fields set to 'undefined'.

Note that the exmpp_component is still expected to be part of some supervision tree.
  • Loading branch information...
1 parent 95ba37c commit 56d6cf5a469564ebf052ff340be3690a8aa2f494 @ppolv ppolv committed Sep 20, 2010
Showing with 22 additions and 2 deletions.
  1. +22 −2 src/network/exmpp_component.erl
@@ -459,7 +459,27 @@ start_parser() ->
[{xmlstreamstart,new}]).
%% Packet processing functions
+parse_and_deliver(ClientPid, Attrs, Packet, F) ->
+ try
+ F(ClientPid, Attrs, Packet)
+ catch
+ _:_ ->
+ %%Some error, deliver only the raw packet
+ ClientPid ! #received_packet{packet_type = undefined,
+ type_attr = undefined,
+ from = undefined,
+ id = undefined,
+ raw_packet = Packet}
+ end.
+
process_presence(ClientPid, Attrs, Packet) ->
+ parse_and_deliver(ClientPid, Attrs, Packet, fun do_process_presence/3).
+process_message(ClientPid, Attrs, Packet) ->
+ parse_and_deliver(ClientPid, Attrs, Packet, fun do_process_message/3).
+process_iq(ClientPid, Attrs, Packet) ->
+ parse_and_deliver(ClientPid, Attrs, Packet, fun do_process_iq/3).
+
+do_process_presence(ClientPid, Attrs, Packet) ->
Type = get_attribute_value(Attrs, type, "available"),
Who = exmpp_jid:to_lower(get_attribute_value(Attrs, from, "")),
Id = get_attribute_value(Attrs, id, ""),
@@ -469,7 +489,7 @@ process_presence(ClientPid, Attrs, Packet) ->
id = Id,
raw_packet = Packet}.
-process_message(ClientPid, Attrs, Packet) ->
+do_process_message(ClientPid, Attrs, Packet) ->
Type = get_attribute_value(Attrs, type, "normal"),
Who = exmpp_jid:to_lower(get_attribute_value(Attrs, from, "")),
Id = get_attribute_value(Attrs, id, ""),
@@ -479,7 +499,7 @@ process_message(ClientPid, Attrs, Packet) ->
id = Id,
raw_packet = Packet}.
-process_iq(ClientPid, Attrs, Packet) ->
+do_process_iq(ClientPid, Attrs, Packet) ->
Type = get_attribute_value(Attrs, type, ""),
Who = exmpp_jid:to_lower(get_attribute_value(Attrs, from, "")),
Id = get_attribute_value(Attrs, id, ""),

0 comments on commit 56d6cf5

Please sign in to comment.