mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Rewrite mod_sic to use XML generator
This commit is contained in:
parent
f19d2fdcff
commit
d2d3b961eb
@ -161,6 +161,8 @@
|
|||||||
-define(NS_HTTP_UPLOAD_OLD, <<"eu:siacs:conversations:http:upload">>).
|
-define(NS_HTTP_UPLOAD_OLD, <<"eu:siacs:conversations:http:upload">>).
|
||||||
-define(NS_THUMBS_1, <<"urn:xmpp:thumbs:1">>).
|
-define(NS_THUMBS_1, <<"urn:xmpp:thumbs:1">>).
|
||||||
-define(NS_NICK, <<"http://jabber.org/protocol/nick">>).
|
-define(NS_NICK, <<"http://jabber.org/protocol/nick">>).
|
||||||
|
-define(NS_SIC_0, <<"urn:xmpp:sic:0">>).
|
||||||
|
-define(NS_SIC_1, <<"urn:xmpp:sic:1">>).
|
||||||
-define(NS_MIX_0, <<"urn:xmpp:mix:0">>).
|
-define(NS_MIX_0, <<"urn:xmpp:mix:0">>).
|
||||||
-define(NS_MIX_SERVICEINFO_0, <<"urn:xmpp:mix:0#serviceinfo">>).
|
-define(NS_MIX_SERVICEINFO_0, <<"urn:xmpp:mix:0#serviceinfo">>).
|
||||||
-define(NS_MIX_NODES_MESSAGES, <<"urn:xmpp:mix:nodes:messages">>).
|
-define(NS_MIX_NODES_MESSAGES, <<"urn:xmpp:mix:nodes:messages">>).
|
||||||
|
@ -343,6 +343,11 @@
|
|||||||
items = [] :: [#pubsub_item{}]}).
|
items = [] :: [#pubsub_item{}]}).
|
||||||
-type pubsub_items() :: #pubsub_items{}.
|
-type pubsub_items() :: #pubsub_items{}.
|
||||||
|
|
||||||
|
-record(sic, {ip :: any(),
|
||||||
|
port :: non_neg_integer(),
|
||||||
|
xmlns :: binary()}).
|
||||||
|
-type sic() :: #sic{}.
|
||||||
|
|
||||||
-record(carbons_sent, {forwarded :: #forwarded{}}).
|
-record(carbons_sent, {forwarded :: #forwarded{}}).
|
||||||
-type carbons_sent() :: #carbons_sent{}.
|
-type carbons_sent() :: #carbons_sent{}.
|
||||||
|
|
||||||
@ -909,7 +914,6 @@
|
|||||||
muc_decline() |
|
muc_decline() |
|
||||||
legacy_auth() |
|
legacy_auth() |
|
||||||
search() |
|
search() |
|
||||||
unblock() |
|
|
||||||
nick() |
|
nick() |
|
||||||
p1_ack() |
|
p1_ack() |
|
||||||
block() |
|
block() |
|
||||||
@ -939,6 +943,7 @@
|
|||||||
stream_features() |
|
stream_features() |
|
||||||
stats() |
|
stats() |
|
||||||
pubsub_items() |
|
pubsub_items() |
|
||||||
|
sic() |
|
||||||
starttls() |
|
starttls() |
|
||||||
mam_prefs() |
|
mam_prefs() |
|
||||||
sasl_mechanisms() |
|
sasl_mechanisms() |
|
||||||
@ -979,4 +984,5 @@
|
|||||||
sasl_auth() |
|
sasl_auth() |
|
||||||
p1_push() |
|
p1_push() |
|
||||||
oob_x() |
|
oob_x() |
|
||||||
pubsub_publish().
|
pubsub_publish() |
|
||||||
|
unblock().
|
||||||
|
@ -31,73 +31,66 @@
|
|||||||
|
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2, stop/1, process_local_iq/3,
|
-export([start/2, stop/1, process_local_iq/1,
|
||||||
process_sm_iq/3, mod_opt_type/1, depends/2]).
|
process_sm_iq/1, mod_opt_type/1, depends/2]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
-include("xmpp.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
|
|
||||||
-define(NS_SIC, <<"urn:xmpp:sic:0">>).
|
|
||||||
|
|
||||||
start(Host, Opts) ->
|
start(Host, Opts) ->
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
|
||||||
one_queue),
|
one_queue),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_SIC_0,
|
||||||
?NS_SIC, ?MODULE, process_local_iq, IQDisc),
|
?MODULE, process_local_iq, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_SIC_0,
|
||||||
?NS_SIC, ?MODULE, process_sm_iq, IQDisc).
|
?MODULE, process_sm_iq, IQDisc),
|
||||||
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_SIC_1,
|
||||||
|
?MODULE, process_local_iq, IQDisc),
|
||||||
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_SIC_1,
|
||||||
|
?MODULE, process_sm_iq, IQDisc).
|
||||||
|
|
||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_SIC_0),
|
||||||
?NS_SIC),
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_SIC_0),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_SIC_1),
|
||||||
?NS_SIC).
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_SIC_1).
|
||||||
|
|
||||||
depends(_Host, _Opts) ->
|
depends(_Host, _Opts) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
process_local_iq(#jid{user = User, server = Server,
|
process_local_iq(#iq{from = #jid{user = User, server = Server,
|
||||||
resource = Resource},
|
resource = Resource},
|
||||||
_To, #iq{type = get, sub_el = _SubEl} = IQ) ->
|
type = get} = IQ) ->
|
||||||
get_ip({User, Server, Resource}, IQ);
|
get_ip({User, Server, Resource}, IQ);
|
||||||
process_local_iq(_From, _To,
|
process_local_iq(#iq{type = set, lang = Lang} = IQ) ->
|
||||||
#iq{type = set, sub_el = SubEl, lang = Lang} = IQ) ->
|
|
||||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]}.
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang)).
|
||||||
|
|
||||||
process_sm_iq(#jid{user = User, server = Server,
|
process_sm_iq(#iq{from = #jid{user = User, server = Server,
|
||||||
resource = Resource},
|
resource = Resource},
|
||||||
#jid{user = User, server = Server},
|
to = #jid{user = User, server = Server},
|
||||||
#iq{type = get, sub_el = _SubEl} = IQ) ->
|
type = get} = IQ) ->
|
||||||
get_ip({User, Server, Resource}, IQ);
|
get_ip({User, Server, Resource}, IQ);
|
||||||
process_sm_iq(_From, _To,
|
process_sm_iq(#iq{type = get, lang = Lang} = IQ) ->
|
||||||
#iq{type = get, sub_el = SubEl, lang = Lang} = IQ) ->
|
|
||||||
Txt = <<"Query to another users is forbidden">>,
|
Txt = <<"Query to another users is forbidden">>,
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]};
|
xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang));
|
||||||
process_sm_iq(_From, _To,
|
process_sm_iq(#iq{type = set, lang = Lang} = IQ) ->
|
||||||
#iq{type = set, sub_el = SubEl, lang = Lang} = IQ) ->
|
|
||||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]}.
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang)).
|
||||||
|
|
||||||
get_ip({User, Server, Resource},
|
get_ip({User, Server, Resource},
|
||||||
#iq{lang = Lang,
|
#iq{lang = Lang, sub_els = [#sic{xmlns = NS}]} = IQ) ->
|
||||||
sub_el =
|
|
||||||
#xmlel{name = Name, attrs = Attrs} = SubEl} =
|
|
||||||
IQ) ->
|
|
||||||
case ejabberd_sm:get_user_ip(User, Server, Resource) of
|
case ejabberd_sm:get_user_ip(User, Server, Resource) of
|
||||||
{IP, _} when is_tuple(IP) ->
|
{IP, Port} when is_tuple(IP) ->
|
||||||
IQ#iq{type = result,
|
Result = case NS of
|
||||||
sub_el =
|
?NS_SIC_0 -> #sic{ip = IP, xmlns = NS};
|
||||||
[#xmlel{name = Name, attrs = Attrs,
|
?NS_SIC_1 -> #sic{ip = IP, port = Port, xmlns = NS}
|
||||||
children =
|
end,
|
||||||
[{xmlcdata,
|
xmpp:make_iq_result(IQ, Result);
|
||||||
iolist_to_binary(jlib:ip_to_list(IP))}]}]};
|
|
||||||
_ ->
|
_ ->
|
||||||
Txt = <<"User session not found">>,
|
Txt = <<"User session not found">>,
|
||||||
IQ#iq{type = error,
|
xmpp:make_error(IQ, xmpp:err_item_not_found(Txt, Lang))
|
||||||
sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
|
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
|
||||||
|
@ -15,6 +15,16 @@ decode(_el) -> decode(_el, []).
|
|||||||
decode({xmlel, _name, _attrs, _} = _el, Opts) ->
|
decode({xmlel, _name, _attrs, _} = _el, Opts) ->
|
||||||
IgnoreEls = proplists:get_bool(ignore_els, Opts),
|
IgnoreEls = proplists:get_bool(ignore_els, Opts),
|
||||||
case {_name, get_attr(<<"xmlns">>, _attrs)} of
|
case {_name, get_attr(<<"xmlns">>, _attrs)} of
|
||||||
|
{<<"address">>, <<"urn:xmpp:sic:0">>} ->
|
||||||
|
decode_sic(<<"urn:xmpp:sic:0">>, IgnoreEls, _el);
|
||||||
|
{<<"address">>, <<"urn:xmpp:sic:1">>} ->
|
||||||
|
decode_sic(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
|
||||||
|
{<<"port">>, <<"urn:xmpp:sic:1">>} ->
|
||||||
|
decode_sip_port(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
|
||||||
|
{<<"ip">>, <<"urn:xmpp:sic:0">>} ->
|
||||||
|
decode_sic_ip(<<"urn:xmpp:sic:0">>, IgnoreEls, _el);
|
||||||
|
{<<"ip">>, <<"urn:xmpp:sic:1">>} ->
|
||||||
|
decode_sic_ip(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
|
||||||
{<<"x">>, <<"jabber:x:oob">>} ->
|
{<<"x">>, <<"jabber:x:oob">>} ->
|
||||||
decode_oob_x(<<"jabber:x:oob">>, IgnoreEls, _el);
|
decode_oob_x(<<"jabber:x:oob">>, IgnoreEls, _el);
|
||||||
{<<"desc">>, <<"jabber:x:oob">>} ->
|
{<<"desc">>, <<"jabber:x:oob">>} ->
|
||||||
@ -1309,6 +1319,11 @@ decode({xmlel, _name, _attrs, _} = _el, Opts) ->
|
|||||||
|
|
||||||
is_known_tag({xmlel, _name, _attrs, _} = _el) ->
|
is_known_tag({xmlel, _name, _attrs, _} = _el) ->
|
||||||
case {_name, get_attr(<<"xmlns">>, _attrs)} of
|
case {_name, get_attr(<<"xmlns">>, _attrs)} of
|
||||||
|
{<<"address">>, <<"urn:xmpp:sic:0">>} -> true;
|
||||||
|
{<<"address">>, <<"urn:xmpp:sic:1">>} -> true;
|
||||||
|
{<<"port">>, <<"urn:xmpp:sic:1">>} -> true;
|
||||||
|
{<<"ip">>, <<"urn:xmpp:sic:0">>} -> true;
|
||||||
|
{<<"ip">>, <<"urn:xmpp:sic:1">>} -> true;
|
||||||
{<<"x">>, <<"jabber:x:oob">>} -> true;
|
{<<"x">>, <<"jabber:x:oob">>} -> true;
|
||||||
{<<"desc">>, <<"jabber:x:oob">>} -> true;
|
{<<"desc">>, <<"jabber:x:oob">>} -> true;
|
||||||
{<<"url">>, <<"jabber:x:oob">>} -> true;
|
{<<"url">>, <<"jabber:x:oob">>} -> true;
|
||||||
@ -2609,7 +2624,9 @@ encode({media, _, _, _} = Media) ->
|
|||||||
encode_media(Media,
|
encode_media(Media,
|
||||||
[{<<"xmlns">>, <<"urn:xmpp:media-element">>}]);
|
[{<<"xmlns">>, <<"urn:xmpp:media-element">>}]);
|
||||||
encode({oob_x, _, _, _} = X) ->
|
encode({oob_x, _, _, _} = X) ->
|
||||||
encode_oob_x(X, [{<<"xmlns">>, <<"jabber:x:oob">>}]).
|
encode_oob_x(X, [{<<"xmlns">>, <<"jabber:x:oob">>}]);
|
||||||
|
encode({sic, _, _, _} = Address) ->
|
||||||
|
encode_sic(Address, []).
|
||||||
|
|
||||||
get_name({last, _, _}) -> <<"query">>;
|
get_name({last, _, _}) -> <<"query">>;
|
||||||
get_name({version, _, _, _}) -> <<"query">>;
|
get_name({version, _, _, _}) -> <<"query">>;
|
||||||
@ -2802,7 +2819,8 @@ get_name({bob_data, _, _, _, _}) -> <<"data">>;
|
|||||||
get_name({xcaptcha, _}) -> <<"captcha">>;
|
get_name({xcaptcha, _}) -> <<"captcha">>;
|
||||||
get_name({media_uri, _, _}) -> <<"uri">>;
|
get_name({media_uri, _, _}) -> <<"uri">>;
|
||||||
get_name({media, _, _, _}) -> <<"media">>;
|
get_name({media, _, _, _}) -> <<"media">>;
|
||||||
get_name({oob_x, _, _, _}) -> <<"x">>.
|
get_name({oob_x, _, _, _}) -> <<"x">>;
|
||||||
|
get_name({sic, _, _, _}) -> <<"address">>.
|
||||||
|
|
||||||
get_ns({last, _, _}) -> <<"jabber:iq:last">>;
|
get_ns({last, _, _}) -> <<"jabber:iq:last">>;
|
||||||
get_ns({version, _, _, _}) -> <<"jabber:iq:version">>;
|
get_ns({version, _, _, _}) -> <<"jabber:iq:version">>;
|
||||||
@ -3070,7 +3088,8 @@ get_ns({media_uri, _, _}) ->
|
|||||||
<<"urn:xmpp:media-element">>;
|
<<"urn:xmpp:media-element">>;
|
||||||
get_ns({media, _, _, _}) ->
|
get_ns({media, _, _, _}) ->
|
||||||
<<"urn:xmpp:media-element">>;
|
<<"urn:xmpp:media-element">>;
|
||||||
get_ns({oob_x, _, _, _}) -> <<"jabber:x:oob">>.
|
get_ns({oob_x, _, _, _}) -> <<"jabber:x:oob">>;
|
||||||
|
get_ns({sic, _, _, Xmlns}) -> Xmlns.
|
||||||
|
|
||||||
dec_int(Val) -> dec_int(Val, infinity, infinity).
|
dec_int(Val) -> dec_int(Val, infinity, infinity).
|
||||||
|
|
||||||
@ -3319,8 +3338,18 @@ pp(xcaptcha, 1) -> [xdata];
|
|||||||
pp(media_uri, 2) -> [type, uri];
|
pp(media_uri, 2) -> [type, uri];
|
||||||
pp(media, 3) -> [height, width, uri];
|
pp(media, 3) -> [height, width, uri];
|
||||||
pp(oob_x, 3) -> [url, desc, sid];
|
pp(oob_x, 3) -> [url, desc, sid];
|
||||||
|
pp(sic, 3) -> [ip, port, xmlns];
|
||||||
pp(_, _) -> no.
|
pp(_, _) -> no.
|
||||||
|
|
||||||
|
enc_ip({0, 0, 0, 0, 0, 65535, A, B}) ->
|
||||||
|
enc_ip({(A bsr 8) band 255, A band 255,
|
||||||
|
(B bsr 8) band 255, B band 255});
|
||||||
|
enc_ip(Addr) -> list_to_binary(inet_parse:ntoa(Addr)).
|
||||||
|
|
||||||
|
dec_ip(S) ->
|
||||||
|
{ok, Addr} = inet_parse:address(binary_to_list(S)),
|
||||||
|
Addr.
|
||||||
|
|
||||||
join([], _Sep) -> <<>>;
|
join([], _Sep) -> <<>>;
|
||||||
join([H | T], Sep) ->
|
join([H | T], Sep) ->
|
||||||
<<H/binary, << <<Sep, X/binary>> || X <- T >>/binary>>.
|
<<H/binary, << <<Sep, X/binary>> || X <- T >>/binary>>.
|
||||||
@ -3365,6 +3394,155 @@ dec_tzo(Val) ->
|
|||||||
M = jlib:binary_to_integer(M1),
|
M = jlib:binary_to_integer(M1),
|
||||||
if H >= -12, H =< 12, M >= 0, M < 60 -> {H, M} end.
|
if H >= -12, H =< 12, M >= 0, M < 60 -> {H, M} end.
|
||||||
|
|
||||||
|
decode_sic(__TopXMLNS, __IgnoreEls,
|
||||||
|
{xmlel, <<"address">>, _attrs, _els}) ->
|
||||||
|
{Ip, Port} = decode_sic_els(__TopXMLNS, __IgnoreEls,
|
||||||
|
_els, undefined, undefined),
|
||||||
|
Xmlns = decode_sic_attrs(__TopXMLNS, _attrs, undefined),
|
||||||
|
{sic, Ip, Port, Xmlns}.
|
||||||
|
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, [], Ip, Port) ->
|
||||||
|
{Ip, Port};
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls,
|
||||||
|
[{xmlel, <<"ip">>, _attrs, _} = _el | _els], Ip,
|
||||||
|
Port) ->
|
||||||
|
case get_attr(<<"xmlns">>, _attrs) of
|
||||||
|
<<"">>
|
||||||
|
when __TopXMLNS == <<"urn:xmpp:sic:1">>;
|
||||||
|
__TopXMLNS == <<"urn:xmpp:sic:0">> ->
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, _els,
|
||||||
|
decode_sic_ip(__TopXMLNS, __IgnoreEls, _el), Port);
|
||||||
|
<<"urn:xmpp:sic:0">> ->
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, _els,
|
||||||
|
decode_sic_ip(<<"urn:xmpp:sic:0">>, __IgnoreEls, _el),
|
||||||
|
Port);
|
||||||
|
<<"urn:xmpp:sic:1">> ->
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, _els,
|
||||||
|
decode_sic_ip(<<"urn:xmpp:sic:1">>, __IgnoreEls, _el),
|
||||||
|
Port);
|
||||||
|
_ ->
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip, Port)
|
||||||
|
end;
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls,
|
||||||
|
[{xmlel, <<"port">>, _attrs, _} = _el | _els], Ip,
|
||||||
|
Port) ->
|
||||||
|
case get_attr(<<"xmlns">>, _attrs) of
|
||||||
|
<<"">> when __TopXMLNS == <<"urn:xmpp:sic:1">> ->
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip,
|
||||||
|
decode_sip_port(__TopXMLNS, __IgnoreEls, _el));
|
||||||
|
<<"urn:xmpp:sic:1">> ->
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip,
|
||||||
|
decode_sip_port(<<"urn:xmpp:sic:1">>, __IgnoreEls,
|
||||||
|
_el));
|
||||||
|
_ ->
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip, Port)
|
||||||
|
end;
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, [_ | _els], Ip,
|
||||||
|
Port) ->
|
||||||
|
decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip, Port).
|
||||||
|
|
||||||
|
decode_sic_attrs(__TopXMLNS,
|
||||||
|
[{<<"xmlns">>, _val} | _attrs], _Xmlns) ->
|
||||||
|
decode_sic_attrs(__TopXMLNS, _attrs, _val);
|
||||||
|
decode_sic_attrs(__TopXMLNS, [_ | _attrs], Xmlns) ->
|
||||||
|
decode_sic_attrs(__TopXMLNS, _attrs, Xmlns);
|
||||||
|
decode_sic_attrs(__TopXMLNS, [], Xmlns) ->
|
||||||
|
decode_sic_attr_xmlns(__TopXMLNS, Xmlns).
|
||||||
|
|
||||||
|
encode_sic({sic, Ip, Port, Xmlns}, _xmlns_attrs) ->
|
||||||
|
_els = lists:reverse('encode_sic_$ip'(Ip,
|
||||||
|
'encode_sic_$port'(Port, []))),
|
||||||
|
_attrs = encode_sic_attr_xmlns(Xmlns, _xmlns_attrs),
|
||||||
|
{xmlel, <<"address">>, _attrs, _els}.
|
||||||
|
|
||||||
|
'encode_sic_$ip'(undefined, _acc) -> _acc;
|
||||||
|
'encode_sic_$ip'(Ip, _acc) ->
|
||||||
|
[encode_sic_ip(Ip, []) | _acc].
|
||||||
|
|
||||||
|
'encode_sic_$port'(undefined, _acc) -> _acc;
|
||||||
|
'encode_sic_$port'(Port, _acc) ->
|
||||||
|
[encode_sip_port(Port, []) | _acc].
|
||||||
|
|
||||||
|
decode_sic_attr_xmlns(__TopXMLNS, undefined) ->
|
||||||
|
undefined;
|
||||||
|
decode_sic_attr_xmlns(__TopXMLNS, _val) -> _val.
|
||||||
|
|
||||||
|
encode_sic_attr_xmlns(undefined, _acc) -> _acc;
|
||||||
|
encode_sic_attr_xmlns(_val, _acc) ->
|
||||||
|
[{<<"xmlns">>, _val} | _acc].
|
||||||
|
|
||||||
|
decode_sip_port(__TopXMLNS, __IgnoreEls,
|
||||||
|
{xmlel, <<"port">>, _attrs, _els}) ->
|
||||||
|
Cdata = decode_sip_port_els(__TopXMLNS, __IgnoreEls,
|
||||||
|
_els, <<>>),
|
||||||
|
Cdata.
|
||||||
|
|
||||||
|
decode_sip_port_els(__TopXMLNS, __IgnoreEls, [],
|
||||||
|
Cdata) ->
|
||||||
|
decode_sip_port_cdata(__TopXMLNS, Cdata);
|
||||||
|
decode_sip_port_els(__TopXMLNS, __IgnoreEls,
|
||||||
|
[{xmlcdata, _data} | _els], Cdata) ->
|
||||||
|
decode_sip_port_els(__TopXMLNS, __IgnoreEls, _els,
|
||||||
|
<<Cdata/binary, _data/binary>>);
|
||||||
|
decode_sip_port_els(__TopXMLNS, __IgnoreEls, [_ | _els],
|
||||||
|
Cdata) ->
|
||||||
|
decode_sip_port_els(__TopXMLNS, __IgnoreEls, _els,
|
||||||
|
Cdata).
|
||||||
|
|
||||||
|
encode_sip_port(Cdata, _xmlns_attrs) ->
|
||||||
|
_els = encode_sip_port_cdata(Cdata, []),
|
||||||
|
_attrs = _xmlns_attrs,
|
||||||
|
{xmlel, <<"port">>, _attrs, _els}.
|
||||||
|
|
||||||
|
decode_sip_port_cdata(__TopXMLNS, <<>>) ->
|
||||||
|
erlang:error({xmpp_codec,
|
||||||
|
{missing_cdata, <<>>, <<"port">>, __TopXMLNS}});
|
||||||
|
decode_sip_port_cdata(__TopXMLNS, _val) ->
|
||||||
|
case catch dec_int(_val, 0, 65535) of
|
||||||
|
{'EXIT', _} ->
|
||||||
|
erlang:error({xmpp_codec,
|
||||||
|
{bad_cdata_value, <<>>, <<"port">>, __TopXMLNS}});
|
||||||
|
_res -> _res
|
||||||
|
end.
|
||||||
|
|
||||||
|
encode_sip_port_cdata(_val, _acc) ->
|
||||||
|
[{xmlcdata, enc_int(_val)} | _acc].
|
||||||
|
|
||||||
|
decode_sic_ip(__TopXMLNS, __IgnoreEls,
|
||||||
|
{xmlel, <<"ip">>, _attrs, _els}) ->
|
||||||
|
Cdata = decode_sic_ip_els(__TopXMLNS, __IgnoreEls, _els,
|
||||||
|
<<>>),
|
||||||
|
Cdata.
|
||||||
|
|
||||||
|
decode_sic_ip_els(__TopXMLNS, __IgnoreEls, [], Cdata) ->
|
||||||
|
decode_sic_ip_cdata(__TopXMLNS, Cdata);
|
||||||
|
decode_sic_ip_els(__TopXMLNS, __IgnoreEls,
|
||||||
|
[{xmlcdata, _data} | _els], Cdata) ->
|
||||||
|
decode_sic_ip_els(__TopXMLNS, __IgnoreEls, _els,
|
||||||
|
<<Cdata/binary, _data/binary>>);
|
||||||
|
decode_sic_ip_els(__TopXMLNS, __IgnoreEls, [_ | _els],
|
||||||
|
Cdata) ->
|
||||||
|
decode_sic_ip_els(__TopXMLNS, __IgnoreEls, _els, Cdata).
|
||||||
|
|
||||||
|
encode_sic_ip(Cdata, _xmlns_attrs) ->
|
||||||
|
_els = encode_sic_ip_cdata(Cdata, []),
|
||||||
|
_attrs = _xmlns_attrs,
|
||||||
|
{xmlel, <<"ip">>, _attrs, _els}.
|
||||||
|
|
||||||
|
decode_sic_ip_cdata(__TopXMLNS, <<>>) ->
|
||||||
|
erlang:error({xmpp_codec,
|
||||||
|
{missing_cdata, <<>>, <<"ip">>, __TopXMLNS}});
|
||||||
|
decode_sic_ip_cdata(__TopXMLNS, _val) ->
|
||||||
|
case catch dec_ip(_val) of
|
||||||
|
{'EXIT', _} ->
|
||||||
|
erlang:error({xmpp_codec,
|
||||||
|
{bad_cdata_value, <<>>, <<"ip">>, __TopXMLNS}});
|
||||||
|
_res -> _res
|
||||||
|
end.
|
||||||
|
|
||||||
|
encode_sic_ip_cdata(_val, _acc) ->
|
||||||
|
[{xmlcdata, enc_ip(_val)} | _acc].
|
||||||
|
|
||||||
decode_oob_x(__TopXMLNS, __IgnoreEls,
|
decode_oob_x(__TopXMLNS, __IgnoreEls,
|
||||||
{xmlel, <<"x">>, _attrs, _els}) ->
|
{xmlel, <<"x">>, _attrs, _els}) ->
|
||||||
{Desc, Url} = decode_oob_x_els(__TopXMLNS, __IgnoreEls,
|
{Desc, Url} = decode_oob_x_els(__TopXMLNS, __IgnoreEls,
|
||||||
|
@ -2997,6 +2997,30 @@
|
|||||||
#ref{name = oob_desc, default = <<"">>,
|
#ref{name = oob_desc, default = <<"">>,
|
||||||
min = 0, max = 1, label = '$desc'}]}).
|
min = 0, max = 1, label = '$desc'}]}).
|
||||||
|
|
||||||
|
-xml(sic_ip,
|
||||||
|
#elem{name = <<"ip">>,
|
||||||
|
xmlns = [<<"urn:xmpp:sic:0">>, <<"urn:xmpp:sic:1">>],
|
||||||
|
result = '$cdata',
|
||||||
|
cdata = #cdata{required = true,
|
||||||
|
dec = {dec_ip, []},
|
||||||
|
enc = {enc_ip, []}}}).
|
||||||
|
|
||||||
|
-xml(sip_port,
|
||||||
|
#elem{name = <<"port">>,
|
||||||
|
xmlns = <<"urn:xmpp:sic:1">>,
|
||||||
|
result = '$cdata',
|
||||||
|
cdata = #cdata{required = true,
|
||||||
|
dec = {dec_int, [0, 65535]},
|
||||||
|
enc = {enc_int, []}}}).
|
||||||
|
|
||||||
|
-xml(sic,
|
||||||
|
#elem{name = <<"address">>,
|
||||||
|
xmlns = [<<"urn:xmpp:sic:0">>, <<"urn:xmpp:sic:1">>],
|
||||||
|
result = {sic, '$ip', '$port', '$xmlns'},
|
||||||
|
attrs = [#attr{name = <<"xmlns">>}],
|
||||||
|
refs = [#ref{name = sic_ip, min = 0, max = 1, label = '$ip'},
|
||||||
|
#ref{name = sip_port, min = 0, max = 1, label = '$port'}]}).
|
||||||
|
|
||||||
dec_tzo(Val) ->
|
dec_tzo(Val) ->
|
||||||
[H1, M1] = str:tokens(Val, <<":">>),
|
[H1, M1] = str:tokens(Val, <<":">>),
|
||||||
H = jlib:binary_to_integer(H1),
|
H = jlib:binary_to_integer(H1),
|
||||||
@ -3050,6 +3074,16 @@ join([], _Sep) -> <<>>;
|
|||||||
join([H | T], Sep) ->
|
join([H | T], Sep) ->
|
||||||
<<H/binary, (<< <<Sep, X/binary>> || X <- T >>)/binary>>.
|
<<H/binary, (<< <<Sep, X/binary>> || X <- T >>)/binary>>.
|
||||||
|
|
||||||
|
dec_ip(S) ->
|
||||||
|
{ok, Addr} = inet_parse:address(binary_to_list(S)),
|
||||||
|
Addr.
|
||||||
|
|
||||||
|
enc_ip({0,0,0,0,0,16#ffff,A,B}) ->
|
||||||
|
enc_ip({(A bsr 8) band 16#ff, A band 16#ff,
|
||||||
|
(B bsr 8) band 16#ff, B band 16#ff});
|
||||||
|
enc_ip(Addr) ->
|
||||||
|
list_to_binary(inet_parse:ntoa(Addr)).
|
||||||
|
|
||||||
%% Local Variables:
|
%% Local Variables:
|
||||||
%% mode: erlang
|
%% mode: erlang
|
||||||
%% End:
|
%% End:
|
||||||
|
Loading…
Reference in New Issue
Block a user