diff options
author | Alexey Shchepin <alexey@process-one.net> | 2002-11-24 20:36:57 +0000 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2002-11-24 20:36:57 +0000 |
commit | 9c38be6ca249740e638eb3913930410ca4891739 (patch) | |
tree | 81413b6d35975862aaa249b2696f48164e6c331f /src/xml.erl | |
parent | *** empty log message *** (diff) |
*** empty log message ***
SVN Revision: 6
Diffstat (limited to 'src/xml.erl')
-rw-r--r-- | src/xml.erl | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/xml.erl b/src/xml.erl index e1ae3b1ba..5ae3cb593 100644 --- a/src/xml.erl +++ b/src/xml.erl @@ -11,7 +11,7 @@ -vsn('$Revision$ '). -export([element_to_string/1, crypt/1, remove_cdata/1, get_cdata/1, - get_attr/2, get_attr_s/2]). + get_attr/2, get_attr_s/2, make_error_iq_reply/3]). element_to_string(El) -> case El of @@ -90,3 +90,31 @@ get_attr_s(AttrName, Attrs) -> "" end. + +make_error_iq_reply({xmlelement, Name, Attrs, SubTags}, Code, Desc) + when Name == "iq" -> + NewAttrs = make_error_iq_reply_attrs(Attrs), + {xmlelement, Name, NewAttrs, SubTags ++ [{xmlelement, "error", + [{"code", Code}], + [{xmlcdata, Desc}]}]}. + +make_error_iq_reply_attrs(Attrs) -> + To = get_attr("to", Attrs), + From = get_attr("from", Attrs), + Attrs1 = lists:keydelete("to", 1, Attrs), + Attrs2 = lists:keydelete("from", 1, Attrs1), + Attrs3 = case To of + {value, ToVal} -> + [{"from", ToVal} | Attrs2]; + _ -> + Attrs2 + end, + Attrs4 = case From of + {value, FromVal} -> + [{"to", FromVal} | Attrs3]; + _ -> + Attrs3 + end, + Attrs5 = lists:keydelete("type", 1, Attrs4), + Attrs6 = [{"type", "error"} | Attrs5], + Attrs6. |