forked from processone/xmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xep0333.erl
195 lines (169 loc) · 7.34 KB
/
xep0333.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
%% Created automatically by XML generator (fxml_gen.erl)
%% Source: xmpp_codec.spec
-module(xep0333).
-compile(export_all).
do_decode(<<"acknowledged">>,
<<"urn:xmpp:chat-markers:0">>, El, Opts) ->
decode_mark_acknowledged(<<"urn:xmpp:chat-markers:0">>,
Opts,
El);
do_decode(<<"displayed">>,
<<"urn:xmpp:chat-markers:0">>, El, Opts) ->
decode_mark_displayed(<<"urn:xmpp:chat-markers:0">>,
Opts,
El);
do_decode(<<"received">>, <<"urn:xmpp:chat-markers:0">>,
El, Opts) ->
decode_mark_received(<<"urn:xmpp:chat-markers:0">>,
Opts,
El);
do_decode(<<"markable">>, <<"urn:xmpp:chat-markers:0">>,
El, Opts) ->
decode_mark_markable(<<"urn:xmpp:chat-markers:0">>,
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() ->
[{<<"acknowledged">>, <<"urn:xmpp:chat-markers:0">>},
{<<"displayed">>, <<"urn:xmpp:chat-markers:0">>},
{<<"received">>, <<"urn:xmpp:chat-markers:0">>},
{<<"markable">>, <<"urn:xmpp:chat-markers:0">>}].
do_encode({mark_received, _} = Received, TopXMLNS) ->
encode_mark_received(Received, TopXMLNS);
do_encode({mark_displayed, _} = Displayed, TopXMLNS) ->
encode_mark_displayed(Displayed, TopXMLNS);
do_encode({mark_acknowledged, _} = Acknowledged,
TopXMLNS) ->
encode_mark_acknowledged(Acknowledged, TopXMLNS).
do_get_name({mark_acknowledged, _}) ->
<<"acknowledged">>;
do_get_name({mark_displayed, _}) -> <<"displayed">>;
do_get_name({mark_received, _}) -> <<"received">>.
do_get_ns({mark_acknowledged, _}) ->
<<"urn:xmpp:chat-markers:0">>;
do_get_ns({mark_displayed, _}) ->
<<"urn:xmpp:chat-markers:0">>;
do_get_ns({mark_received, _}) ->
<<"urn:xmpp:chat-markers:0">>.
pp(mark_received, 1) -> [id];
pp(mark_displayed, 1) -> [id];
pp(mark_acknowledged, 1) -> [id];
pp(_, _) -> no.
records() ->
[{mark_received, 1},
{mark_displayed, 1},
{mark_acknowledged, 1}].
decode_mark_acknowledged(__TopXMLNS, __Opts,
{xmlel, <<"acknowledged">>, _attrs, _els}) ->
Id = decode_mark_acknowledged_attrs(__TopXMLNS,
_attrs,
undefined),
{mark_acknowledged, Id}.
decode_mark_acknowledged_attrs(__TopXMLNS,
[{<<"id">>, _val} | _attrs], _Id) ->
decode_mark_acknowledged_attrs(__TopXMLNS,
_attrs,
_val);
decode_mark_acknowledged_attrs(__TopXMLNS, [_ | _attrs],
Id) ->
decode_mark_acknowledged_attrs(__TopXMLNS, _attrs, Id);
decode_mark_acknowledged_attrs(__TopXMLNS, [], Id) ->
decode_mark_acknowledged_attr_id(__TopXMLNS, Id).
encode_mark_acknowledged({mark_acknowledged, Id},
__TopXMLNS) ->
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"urn:xmpp:chat-markers:0">>,
[],
__TopXMLNS),
_els = [],
_attrs = encode_mark_acknowledged_attr_id(Id,
xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS)),
{xmlel, <<"acknowledged">>, _attrs, _els}.
decode_mark_acknowledged_attr_id(__TopXMLNS,
undefined) ->
erlang:error({xmpp_codec,
{missing_attr,
<<"id">>,
<<"acknowledged">>,
__TopXMLNS}});
decode_mark_acknowledged_attr_id(__TopXMLNS, _val) ->
_val.
encode_mark_acknowledged_attr_id(_val, _acc) ->
[{<<"id">>, _val} | _acc].
decode_mark_displayed(__TopXMLNS, __Opts,
{xmlel, <<"displayed">>, _attrs, _els}) ->
Id = decode_mark_displayed_attrs(__TopXMLNS,
_attrs,
undefined),
{mark_displayed, Id}.
decode_mark_displayed_attrs(__TopXMLNS,
[{<<"id">>, _val} | _attrs], _Id) ->
decode_mark_displayed_attrs(__TopXMLNS, _attrs, _val);
decode_mark_displayed_attrs(__TopXMLNS, [_ | _attrs],
Id) ->
decode_mark_displayed_attrs(__TopXMLNS, _attrs, Id);
decode_mark_displayed_attrs(__TopXMLNS, [], Id) ->
decode_mark_displayed_attr_id(__TopXMLNS, Id).
encode_mark_displayed({mark_displayed, Id},
__TopXMLNS) ->
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"urn:xmpp:chat-markers:0">>,
[],
__TopXMLNS),
_els = [],
_attrs = encode_mark_displayed_attr_id(Id,
xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS)),
{xmlel, <<"displayed">>, _attrs, _els}.
decode_mark_displayed_attr_id(__TopXMLNS, undefined) ->
erlang:error({xmpp_codec,
{missing_attr, <<"id">>, <<"displayed">>, __TopXMLNS}});
decode_mark_displayed_attr_id(__TopXMLNS, _val) -> _val.
encode_mark_displayed_attr_id(_val, _acc) ->
[{<<"id">>, _val} | _acc].
decode_mark_received(__TopXMLNS, __Opts,
{xmlel, <<"received">>, _attrs, _els}) ->
Id = decode_mark_received_attrs(__TopXMLNS,
_attrs,
undefined),
{mark_received, Id}.
decode_mark_received_attrs(__TopXMLNS,
[{<<"id">>, _val} | _attrs], _Id) ->
decode_mark_received_attrs(__TopXMLNS, _attrs, _val);
decode_mark_received_attrs(__TopXMLNS, [_ | _attrs],
Id) ->
decode_mark_received_attrs(__TopXMLNS, _attrs, Id);
decode_mark_received_attrs(__TopXMLNS, [], Id) ->
decode_mark_received_attr_id(__TopXMLNS, Id).
encode_mark_received({mark_received, Id}, __TopXMLNS) ->
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"urn:xmpp:chat-markers:0">>,
[],
__TopXMLNS),
_els = [],
_attrs = encode_mark_received_attr_id(Id,
xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS)),
{xmlel, <<"received">>, _attrs, _els}.
decode_mark_received_attr_id(__TopXMLNS, undefined) ->
erlang:error({xmpp_codec,
{missing_attr, <<"id">>, <<"received">>, __TopXMLNS}});
decode_mark_received_attr_id(__TopXMLNS, _val) -> _val.
encode_mark_received_attr_id(_val, _acc) ->
[{<<"id">>, _val} | _acc].
decode_mark_markable(__TopXMLNS, __Opts,
{xmlel, <<"markable">>, _attrs, _els}) ->
true.
encode_mark_markable(true, __TopXMLNS) ->
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"urn:xmpp:chat-markers:0">>,
[],
__TopXMLNS),
_els = [],
_attrs = xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS),
{xmlel, <<"markable">>, _attrs, _els}.