Skip to content
Browse files

Add new function failure/2, related to EJAB-1425

  • Loading branch information...
1 parent c5b92b1 commit 2b66b5267a46465cdbcf1b5ae7eb32fb279aa30f @badlop badlop committed Mar 16, 2011
Showing with 24 additions and 1 deletion.
  1. +24 −1 src/server/exmpp_server_sasl.erl
View
25 src/server/exmpp_server_sasl.erl
@@ -38,6 +38,7 @@
success/1,
failure/0,
failure/1,
+ failure/2,
next_step/1
]).
@@ -154,7 +155,7 @@ failure() ->
%% @spec (Condition) -> Failure
%% Condition = atom()
%% Failure = exmpp_xml:xmlel()
-%% @doc Prepare a `<failure/>' element.
+%% @doc Prepare a `<failure/>' element with a defined condition.
failure(Condition) ->
case lists:keymember(Condition, 1, standard_conditions()) of
@@ -166,6 +167,28 @@ failure(Condition) ->
},
exmpp_xml:append_child(failure(), Condition_El).
+%% @spec (Condition, Text) -> Failure
+%% Condition = atom()
+%% Text = string()
+%% Failure = exmpp_xml:xmlel()
+%% @doc Prepare a `<failure/>' element with a defined condition and text.
+
+failure(Condition, "") ->
+ failure(Condition);
+failure(Condition, Text) ->
+ case lists:keymember(Condition, 1, standard_conditions()) of
+ true -> ok;
+ false -> throw({sasl, failure, invalid_condition, Condition})
+ end,
+ Condition_El = #xmlel{ns = ?NS_SASL,
+ name = Condition
+ },
+ Text_El = #xmlel{ns = ?NS_SASL,
+ name = text,
+ children = exmpp_xml:cdata(Text)
+ },
+ exmpp_xml:append_children(failure(), [Condition_El, Text_El]).
+
%% @spec (El) -> Type
%% El = exmpp_xml:xmlel()
%% Type = Auth | Response | Abort

0 comments on commit 2b66b52

Please sign in to comment.
Something went wrong with that request. Please try again.