forked from processone/xmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xep0328.erl
72 lines (58 loc) · 2.28 KB
/
xep0328.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
%% Created automatically by XML generator (fxml_gen.erl)
%% Source: xmpp_codec.spec
-module(xep0328).
-compile(export_all).
do_decode(<<"jid">>, <<"urn:xmpp:jidprep:0">>, El,
Opts) ->
decode_jidprep(<<"urn:xmpp:jidprep: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() -> [{<<"jid">>, <<"urn:xmpp:jidprep:0">>}].
do_encode({jidprep, _} = Jid, TopXMLNS) ->
encode_jidprep(Jid, TopXMLNS).
do_get_name({jidprep, _}) -> <<"jid">>.
do_get_ns({jidprep, _}) -> <<"urn:xmpp:jidprep:0">>.
pp(jidprep, 1) -> [jid];
pp(_, _) -> no.
records() -> [{jidprep, 1}].
decode_jidprep(__TopXMLNS, __Opts,
{xmlel, <<"jid">>, _attrs, _els}) ->
Jid = decode_jidprep_els(__TopXMLNS,
__Opts,
_els,
<<>>),
{jidprep, Jid}.
decode_jidprep_els(__TopXMLNS, __Opts, [], Jid) ->
decode_jidprep_cdata(__TopXMLNS, Jid);
decode_jidprep_els(__TopXMLNS, __Opts,
[{xmlcdata, _data} | _els], Jid) ->
decode_jidprep_els(__TopXMLNS,
__Opts,
_els,
<<Jid/binary, _data/binary>>);
decode_jidprep_els(__TopXMLNS, __Opts, [_ | _els],
Jid) ->
decode_jidprep_els(__TopXMLNS, __Opts, _els, Jid).
encode_jidprep({jidprep, Jid}, __TopXMLNS) ->
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"urn:xmpp:jidprep:0">>,
[],
__TopXMLNS),
_els = encode_jidprep_cdata(Jid, []),
_attrs = xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS),
{xmlel, <<"jid">>, _attrs, _els}.
decode_jidprep_cdata(__TopXMLNS, <<>>) ->
erlang:error({xmpp_codec,
{missing_cdata, <<>>, <<"jid">>, __TopXMLNS}});
decode_jidprep_cdata(__TopXMLNS, _val) ->
case catch jid:decode(_val) of
{'EXIT', _} ->
erlang:error({xmpp_codec,
{bad_cdata_value, <<>>, <<"jid">>, __TopXMLNS}});
_res -> _res
end.
encode_jidprep_cdata(_val, _acc) ->
[{xmlcdata, jid:encode(_val)} | _acc].