forked from processone/xmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xep0131.erl
157 lines (136 loc) · 5.96 KB
/
xep0131.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
%% Created automatically by XML generator (fxml_gen.erl)
%% Source: xmpp_codec.spec
-module(xep0131).
-compile(export_all).
do_decode(<<"headers">>,
<<"http://jabber.org/protocol/shim">>, El, Opts) ->
decode_shim_headers(<<"http://jabber.org/protocol/shim">>,
Opts,
El);
do_decode(<<"header">>,
<<"http://jabber.org/protocol/shim">>, El, Opts) ->
decode_shim_header(<<"http://jabber.org/protocol/shim">>,
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() ->
[{<<"headers">>, <<"http://jabber.org/protocol/shim">>},
{<<"header">>, <<"http://jabber.org/protocol/shim">>}].
do_encode({shim, _} = Headers, TopXMLNS) ->
encode_shim_headers(Headers, TopXMLNS).
do_get_name({shim, _}) -> <<"headers">>.
do_get_ns({shim, _}) ->
<<"http://jabber.org/protocol/shim">>.
pp(shim, 1) -> [headers];
pp(_, _) -> no.
records() -> [{shim, 1}].
decode_shim_headers(__TopXMLNS, __Opts,
{xmlel, <<"headers">>, _attrs, _els}) ->
Headers = decode_shim_headers_els(__TopXMLNS,
__Opts,
_els,
[]),
{shim, Headers}.
decode_shim_headers_els(__TopXMLNS, __Opts, [],
Headers) ->
lists:reverse(Headers);
decode_shim_headers_els(__TopXMLNS, __Opts,
[{xmlel, <<"header">>, _attrs, _} = _el | _els],
Headers) ->
case xmpp_codec:get_attr(<<"xmlns">>,
_attrs,
__TopXMLNS)
of
<<"http://jabber.org/protocol/shim">> ->
decode_shim_headers_els(__TopXMLNS,
__Opts,
_els,
[decode_shim_header(<<"http://jabber.org/protocol/shim">>,
__Opts,
_el)
| Headers]);
_ ->
decode_shim_headers_els(__TopXMLNS,
__Opts,
_els,
Headers)
end;
decode_shim_headers_els(__TopXMLNS, __Opts, [_ | _els],
Headers) ->
decode_shim_headers_els(__TopXMLNS,
__Opts,
_els,
Headers).
encode_shim_headers({shim, Headers}, __TopXMLNS) ->
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"http://jabber.org/protocol/shim">>,
[],
__TopXMLNS),
_els =
lists:reverse('encode_shim_headers_$headers'(Headers,
__NewTopXMLNS,
[])),
_attrs = xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS),
{xmlel, <<"headers">>, _attrs, _els}.
'encode_shim_headers_$headers'([], __TopXMLNS, _acc) ->
_acc;
'encode_shim_headers_$headers'([Headers | _els],
__TopXMLNS, _acc) ->
'encode_shim_headers_$headers'(_els,
__TopXMLNS,
[encode_shim_header(Headers, __TopXMLNS)
| _acc]).
decode_shim_header(__TopXMLNS, __Opts,
{xmlel, <<"header">>, _attrs, _els}) ->
Cdata = decode_shim_header_els(__TopXMLNS,
__Opts,
_els,
<<>>),
Name = decode_shim_header_attrs(__TopXMLNS,
_attrs,
undefined),
{Name, Cdata}.
decode_shim_header_els(__TopXMLNS, __Opts, [], Cdata) ->
decode_shim_header_cdata(__TopXMLNS, Cdata);
decode_shim_header_els(__TopXMLNS, __Opts,
[{xmlcdata, _data} | _els], Cdata) ->
decode_shim_header_els(__TopXMLNS,
__Opts,
_els,
<<Cdata/binary, _data/binary>>);
decode_shim_header_els(__TopXMLNS, __Opts, [_ | _els],
Cdata) ->
decode_shim_header_els(__TopXMLNS, __Opts, _els, Cdata).
decode_shim_header_attrs(__TopXMLNS,
[{<<"name">>, _val} | _attrs], _Name) ->
decode_shim_header_attrs(__TopXMLNS, _attrs, _val);
decode_shim_header_attrs(__TopXMLNS, [_ | _attrs],
Name) ->
decode_shim_header_attrs(__TopXMLNS, _attrs, Name);
decode_shim_header_attrs(__TopXMLNS, [], Name) ->
decode_shim_header_attr_name(__TopXMLNS, Name).
encode_shim_header({Name, Cdata}, __TopXMLNS) ->
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"http://jabber.org/protocol/shim">>,
[],
__TopXMLNS),
_els = encode_shim_header_cdata(Cdata, []),
_attrs = encode_shim_header_attr_name(Name,
xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS)),
{xmlel, <<"header">>, _attrs, _els}.
decode_shim_header_attr_name(__TopXMLNS, undefined) ->
erlang:error({xmpp_codec,
{missing_attr, <<"name">>, <<"header">>, __TopXMLNS}});
decode_shim_header_attr_name(__TopXMLNS, _val) -> _val.
encode_shim_header_attr_name(_val, _acc) ->
[{<<"name">>, _val} | _acc].
decode_shim_header_cdata(__TopXMLNS, <<>>) -> <<>>;
decode_shim_header_cdata(__TopXMLNS, _val) -> _val.
encode_shim_header_cdata(<<>>, _acc) -> _acc;
encode_shim_header_cdata(_val, _acc) ->
[{xmlcdata, _val} | _acc].