forked from processone/xmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxep0158.erl
78 lines (65 loc) · 2.68 KB
/
xep0158.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
%% Created automatically by XML generator (fxml_gen.erl)
%% Source: xmpp_codec.spec
-module(xep0158).
-compile(export_all).
do_decode(<<"captcha">>, <<"urn:xmpp:captcha">>, El,
Opts) ->
decode_captcha(<<"urn:xmpp:captcha">>, Opts, El);
do_decode(Name, <<>>, _, _) ->
erlang:error({xmpp_codec, {missing_tag_xmlns, Name}});
do_decode(Name, XMLNS, _, _) ->
erlang:error({xmpp_codec, {unknown_tag, Name, XMLNS}}).
tags() -> [{<<"captcha">>, <<"urn:xmpp:captcha">>}].
do_encode({xcaptcha, _} = Captcha, TopXMLNS) ->
encode_captcha(Captcha, TopXMLNS).
do_get_name({xcaptcha, _}) -> <<"captcha">>.
do_get_ns({xcaptcha, _}) -> <<"urn:xmpp:captcha">>.
pp(xcaptcha, 1) -> [xdata];
pp(_, _) -> no.
records() -> [{xcaptcha, 1}].
decode_captcha(__TopXMLNS, __Opts,
{xmlel, <<"captcha">>, _attrs, _els}) ->
Xdata = decode_captcha_els(__TopXMLNS,
__Opts,
_els,
error),
{xcaptcha, Xdata}.
decode_captcha_els(__TopXMLNS, __Opts, [], Xdata) ->
case Xdata of
error ->
erlang:error({xmpp_codec,
{missing_tag, <<"x">>, __TopXMLNS}});
{value, Xdata1} -> Xdata1
end;
decode_captcha_els(__TopXMLNS, __Opts,
[{xmlel, <<"x">>, _attrs, _} = _el | _els], Xdata) ->
case xmpp_codec:get_attr(<<"xmlns">>,
_attrs,
__TopXMLNS)
of
<<"jabber:x:data">> ->
decode_captcha_els(__TopXMLNS,
__Opts,
_els,
{value,
xep0004:decode_xdata(<<"jabber:x:data">>,
__Opts,
_el)});
_ -> decode_captcha_els(__TopXMLNS, __Opts, _els, Xdata)
end;
decode_captcha_els(__TopXMLNS, __Opts, [_ | _els],
Xdata) ->
decode_captcha_els(__TopXMLNS, __Opts, _els, Xdata).
encode_captcha({xcaptcha, Xdata}, __TopXMLNS) ->
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"urn:xmpp:captcha">>,
[],
__TopXMLNS),
_els = lists:reverse('encode_captcha_$xdata'(Xdata,
__NewTopXMLNS,
[])),
_attrs = xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS),
{xmlel, <<"captcha">>, _attrs, _els}.
'encode_captcha_$xdata'(Xdata, __TopXMLNS, _acc) ->
[xep0004:encode_xdata(Xdata, __TopXMLNS) | _acc].