Skip to content

Commit

Permalink
Merge remote-tracking branch 'processone/pr/84' into fix/xep-0480
Browse files Browse the repository at this point in the history
* processone/pr/84:
  Automatic changes "make spec xdata"
  specs: mix: Fix mix:core:1 mix_participant and drop old version
  • Loading branch information
weiss committed Jan 8, 2025
2 parents e96ea43 + 14b297e commit c44dcae
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 119 deletions.
5 changes: 2 additions & 3 deletions include/xmpp_codec.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -951,9 +951,8 @@
-record(x509_ca_list, {certs = [] :: [binary()]}).
-type x509_ca_list() :: #x509_ca_list{}.

-record(mix_participant, {jid :: jid:jid(),
nick = <<>> :: binary(),
xmlns = <<>> :: binary()}).
-record(mix_participant, {jid :: undefined | jid:jid(),
nick :: 'undefined' | binary()}).
-type mix_participant() :: #mix_participant{}.

-record(compressed, {}).
Expand Down
14 changes: 4 additions & 10 deletions specs/xmpp_codec.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3559,17 +3559,11 @@

-xml(mix_participant,
#elem{name = <<"participant">>,
xmlns = [<<"urn:xmpp:mix:core:0">>, <<"urn:xmpp:mix:core:1">>],
xmlns = <<"urn:xmpp:mix:core:1">>,
module = 'xep0369',
result = {mix_participant, '$jid', '$nick', '$xmlns'},
attrs = [#attr{name = <<"jid">>,
required = true,
label = '$jid',
dec = {jid, decode, []},
enc = {jid, encode, []}},
#attr{name = <<"nick">>,
label = '$nick'},
#attr{name = <<"xmlns">>}]}).
result = {mix_participant, '$jid', '$nick'},
refs = [#ref{name = mix_jid, min = 0, max = 1, label = '$jid'},
#ref{name = mix_nick, min = 0, max = 1, label = '$nick'}]}).

-xml(mix_create,
#elem{name = <<"create">>,
Expand Down
226 changes: 123 additions & 103 deletions src/xep0369.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ do_decode(<<"create">>, <<"urn:xmpp:mix:core:0">>, El,
do_decode(<<"create">>, <<"urn:xmpp:mix:core:1">>, El,
Opts) ->
decode_mix_create(<<"urn:xmpp:mix:core:1">>, Opts, El);
do_decode(<<"participant">>, <<"urn:xmpp:mix:core:0">>,
El, Opts) ->
decode_mix_participant(<<"urn:xmpp:mix:core:0">>,
Opts,
El);
do_decode(<<"participant">>, <<"urn:xmpp:mix:core:1">>,
El, Opts) ->
decode_mix_participant(<<"urn:xmpp:mix:core:1">>,
Expand Down Expand Up @@ -118,7 +113,6 @@ tags() ->
{<<"destroy">>, <<"urn:xmpp:mix:core:1">>},
{<<"create">>, <<"urn:xmpp:mix:core:0">>},
{<<"create">>, <<"urn:xmpp:mix:core:1">>},
{<<"participant">>, <<"urn:xmpp:mix:core:0">>},
{<<"participant">>, <<"urn:xmpp:mix:core:1">>},
{<<"leave">>, <<"urn:xmpp:mix:core:0">>},
{<<"leave">>, <<"urn:xmpp:mix:core:1">>},
Expand Down Expand Up @@ -151,7 +145,7 @@ do_encode({mix_join, _, _, _, _, _} = Join, TopXMLNS) ->
encode_mix_join(Join, TopXMLNS);
do_encode({mix_leave, _} = Leave, TopXMLNS) ->
encode_mix_leave(Leave, TopXMLNS);
do_encode({mix_participant, _, _, _} = Participant,
do_encode({mix_participant, _, _} = Participant,
TopXMLNS) ->
encode_mix_participant(Participant, TopXMLNS);
do_encode({mix_create, _, _} = Create, TopXMLNS) ->
Expand All @@ -166,7 +160,7 @@ do_get_name({mix_create, _, _}) -> <<"create">>;
do_get_name({mix_destroy, _, _}) -> <<"destroy">>;
do_get_name({mix_join, _, _, _, _, _}) -> <<"join">>;
do_get_name({mix_leave, _}) -> <<"leave">>;
do_get_name({mix_participant, _, _, _}) ->
do_get_name({mix_participant, _, _}) ->
<<"participant">>;
do_get_name({mix_setnick, _, _}) -> <<"setnick">>;
do_get_name({mix_update_subscription, _, _, _, _}) ->
Expand All @@ -177,7 +171,8 @@ do_get_ns({mix_create, _, Xmlns}) -> Xmlns;
do_get_ns({mix_destroy, _, Xmlns}) -> Xmlns;
do_get_ns({mix_join, _, _, _, _, Xmlns}) -> Xmlns;
do_get_ns({mix_leave, Xmlns}) -> Xmlns;
do_get_ns({mix_participant, _, _, Xmlns}) -> Xmlns;
do_get_ns({mix_participant, _, _}) ->
<<"urn:xmpp:mix:core:1">>;
do_get_ns({mix_setnick, _, Xmlns}) -> Xmlns;
do_get_ns({mix_update_subscription, Xmlns, _, _, _}) ->
Xmlns.
Expand All @@ -187,7 +182,7 @@ pp(mix_update_subscription, 4) ->
[xmlns, jid, subscribe, unsubscribe];
pp(mix_join, 5) -> [id, jid, nick, subscribe, xmlns];
pp(mix_leave, 1) -> [xmlns];
pp(mix_participant, 3) -> [jid, nick, xmlns];
pp(mix_participant, 2) -> [jid, nick];
pp(mix_create, 2) -> [channel, xmlns];
pp(mix_destroy, 2) -> [channel, xmlns];
pp(mix, 4) -> [submission_id, jid, nick, xmlns];
Expand All @@ -198,7 +193,7 @@ records() ->
{mix_update_subscription, 4},
{mix_join, 5},
{mix_leave, 1},
{mix_participant, 3},
{mix_participant, 2},
{mix_create, 2},
{mix_destroy, 2},
{mix, 4}].
Expand Down Expand Up @@ -517,102 +512,127 @@ decode_mix_create_attr_xmlns(__TopXMLNS, _val) -> _val.

decode_mix_participant(__TopXMLNS, __Opts,
{xmlel, <<"participant">>, _attrs, _els}) ->
{Jid, Nick, Xmlns} =
decode_mix_participant_attrs(__TopXMLNS,
_attrs,
undefined,
undefined,
undefined),
{mix_participant, Jid, Nick, Xmlns}.

decode_mix_participant_attrs(__TopXMLNS,
[{<<"jid">>, _val} | _attrs], _Jid, Nick, Xmlns) ->
decode_mix_participant_attrs(__TopXMLNS,
_attrs,
_val,
Nick,
Xmlns);
decode_mix_participant_attrs(__TopXMLNS,
[{<<"nick">>, _val} | _attrs], Jid, _Nick,
Xmlns) ->
decode_mix_participant_attrs(__TopXMLNS,
_attrs,
Jid,
_val,
Xmlns);
decode_mix_participant_attrs(__TopXMLNS,
[{<<"xmlns">>, _val} | _attrs], Jid, Nick,
_Xmlns) ->
decode_mix_participant_attrs(__TopXMLNS,
_attrs,
Jid,
Nick,
_val);
decode_mix_participant_attrs(__TopXMLNS, [_ | _attrs],
Jid, Nick, Xmlns) ->
decode_mix_participant_attrs(__TopXMLNS,
_attrs,
Jid,
Nick,
Xmlns);
decode_mix_participant_attrs(__TopXMLNS, [], Jid, Nick,
Xmlns) ->
{decode_mix_participant_attr_jid(__TopXMLNS, Jid),
decode_mix_participant_attr_nick(__TopXMLNS, Nick),
decode_mix_participant_attr_xmlns(__TopXMLNS, Xmlns)}.

encode_mix_participant({mix_participant,
Jid,
Nick,
Xmlns},
{Jid, Nick} = decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
undefined,
undefined),
{mix_participant, Jid, Nick}.

decode_mix_participant_els(__TopXMLNS, __Opts, [], Jid,
Nick) ->
{Jid, Nick};
decode_mix_participant_els(__TopXMLNS, __Opts,
[{xmlel, <<"jid">>, _attrs, _} = _el | _els], Jid,
Nick) ->
case xmpp_codec:get_attr(<<"xmlns">>,
_attrs,
__TopXMLNS)
of
<<"urn:xmpp:mix:core:0">> ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
decode_mix_jid(<<"urn:xmpp:mix:core:0">>,
__Opts,
_el),
Nick);
<<"urn:xmpp:mix:core:1">> ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
decode_mix_jid(<<"urn:xmpp:mix:core:1">>,
__Opts,
_el),
Nick);
<<"urn:xmpp:mix:presence:0">> ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
decode_mix_jid(<<"urn:xmpp:mix:presence:0">>,
__Opts,
_el),
Nick);
_ ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
Jid,
Nick)
end;
decode_mix_participant_els(__TopXMLNS, __Opts,
[{xmlel, <<"nick">>, _attrs, _} = _el | _els], Jid,
Nick) ->
case xmpp_codec:get_attr(<<"xmlns">>,
_attrs,
__TopXMLNS)
of
<<"urn:xmpp:mix:core:0">> ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
Jid,
decode_mix_nick(<<"urn:xmpp:mix:core:0">>,
__Opts,
_el));
<<"urn:xmpp:mix:core:1">> ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
Jid,
decode_mix_nick(<<"urn:xmpp:mix:core:1">>,
__Opts,
_el));
<<"urn:xmpp:mix:presence:0">> ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
Jid,
decode_mix_nick(<<"urn:xmpp:mix:presence:0">>,
__Opts,
_el));
_ ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
Jid,
Nick)
end;
decode_mix_participant_els(__TopXMLNS, __Opts,
[_ | _els], Jid, Nick) ->
decode_mix_participant_els(__TopXMLNS,
__Opts,
_els,
Jid,
Nick).

encode_mix_participant({mix_participant, Jid, Nick},
__TopXMLNS) ->
__NewTopXMLNS = xmpp_codec:choose_top_xmlns(Xmlns,
[<<"urn:xmpp:mix:core:0">>,
<<"urn:xmpp:mix:core:1">>],
__TopXMLNS),
_els = [],
_attrs = encode_mix_participant_attr_nick(Nick,
encode_mix_participant_attr_jid(Jid,
xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS))),
__NewTopXMLNS =
xmpp_codec:choose_top_xmlns(<<"urn:xmpp:mix:core:1">>,
[],
__TopXMLNS),
_els = lists:reverse('encode_mix_participant_$jid'(Jid,
__NewTopXMLNS,
'encode_mix_participant_$nick'(Nick,
__NewTopXMLNS,
[]))),
_attrs = xmpp_codec:enc_xmlns_attrs(__NewTopXMLNS,
__TopXMLNS),
{xmlel, <<"participant">>, _attrs, _els}.

decode_mix_participant_attr_jid(__TopXMLNS,
undefined) ->
erlang:error({xmpp_codec,
{missing_attr,
<<"jid">>,
<<"participant">>,
__TopXMLNS}});
decode_mix_participant_attr_jid(__TopXMLNS, _val) ->
case catch jid:decode(_val) of
{'EXIT', _} ->
erlang:error({xmpp_codec,
{bad_attr_value,
<<"jid">>,
<<"participant">>,
__TopXMLNS}});
_res -> _res
end.

encode_mix_participant_attr_jid(_val, _acc) ->
[{<<"jid">>, jid:encode(_val)} | _acc].

decode_mix_participant_attr_nick(__TopXMLNS,
undefined) ->
<<>>;
decode_mix_participant_attr_nick(__TopXMLNS, _val) ->
_val.

encode_mix_participant_attr_nick(<<>>, _acc) -> _acc;
encode_mix_participant_attr_nick(_val, _acc) ->
[{<<"nick">>, _val} | _acc].
'encode_mix_participant_$jid'(undefined, __TopXMLNS,
_acc) ->
_acc;
'encode_mix_participant_$jid'(Jid, __TopXMLNS, _acc) ->
[encode_mix_jid(Jid, __TopXMLNS) | _acc].

decode_mix_participant_attr_xmlns(__TopXMLNS,
undefined) ->
<<>>;
decode_mix_participant_attr_xmlns(__TopXMLNS, _val) ->
_val.
'encode_mix_participant_$nick'(undefined, __TopXMLNS,
_acc) ->
_acc;
'encode_mix_participant_$nick'(Nick, __TopXMLNS,
_acc) ->
[encode_mix_nick(Nick, __TopXMLNS) | _acc].

decode_mix_leave(__TopXMLNS, __Opts,
{xmlel, <<"leave">>, _attrs, _els}) ->
Expand Down
4 changes: 1 addition & 3 deletions src/xmpp_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,6 @@ get_mod(<<"sm">>, <<"urn:xmpp:sm:3">>) -> xep0198;
get_mod(<<"fetch">>,
<<"http://jabber.org/protocol/offline">>) ->
xep0013;
get_mod(<<"participant">>, <<"urn:xmpp:mix:core:0">>) ->
xep0369;
get_mod(<<"failed-transport">>,
<<"urn:xmpp:jingle:1">>) ->
xep0166;
Expand Down Expand Up @@ -1836,6 +1834,7 @@ get_mod({fasten_external, _}) -> xep0422;
get_mod({s2s_bidi_feature}) -> xep0288;
get_mod({shim, _}) -> xep0131;
get_mod({mam_archived, _, _}) -> xep0313;
get_mod({mix_participant, _, _}) -> xep0369;
get_mod({delegated, _, _}) -> xep0355;
get_mod({text, _, _}) -> xep0234;
get_mod({muc_hat, _, _}) -> xep0317;
Expand Down Expand Up @@ -1966,7 +1965,6 @@ get_mod({sasl_upgrade, _}) -> xep0480;
get_mod({stanza_error, _, _, _, _, _}) -> rfc6120;
get_mod({sm_resumed, _, _, _}) -> xep0198;
get_mod({offline_item, _, _}) -> xep0013;
get_mod({mix_participant, _, _, _}) -> xep0369;
get_mod({db_verify, _, _, _, _, _, _}) -> xep0220;
get_mod({upload_slot, _, _, _}) -> xep0363;
get_mod({jingle_ibb_transport, _, _, _}) -> xep0261;
Expand Down

0 comments on commit c44dcae

Please sign in to comment.