Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade exml to 4.0.0 #272

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{require_min_otp_vsn, "26"}.

{deps, [
{exml, "3.4.1", {pkg, hexml}},
{exml, "4.0.0", {pkg, hexml}},
{meck, "1.0.0"},
{bbmustache, "1.12.2"},
{uuid, "2.0.7", {pkg, uuid_erl}},
Expand All @@ -16,6 +16,10 @@
{fast_scram, "0.6.1"}
]}.

{dialyzer, [
{warnings, [unknown]},
{plt_extra_apps, [common_test, exml, uuid, worker_pool, fast_scram]}]}.

%% To override the plugin as installed by worker_pool
{project_plugins,
[rebar3_hex, {rebar3_codecov, "0.6.0"}]}.
Expand Down
6 changes: 3 additions & 3 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{"1.2.0",
[{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.12.2">>},0},
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.13.0">>},1},
{<<"exml">>,{pkg,<<"hexml">>,<<"3.4.1">>},0},
{<<"exml">>,{pkg,<<"hexml">>,<<"4.0.0">>},0},
{<<"fast_pbkdf2">>,{pkg,<<"fast_pbkdf2">>,<<"1.0.6">>},1},
{<<"fast_scram">>,{pkg,<<"fast_scram">>,<<"0.6.1">>},0},
{<<"fast_tls">>,{pkg,<<"fast_tls">>,<<"1.1.21">>},0},
Expand All @@ -15,7 +15,7 @@
{pkg_hash,[
{<<"bbmustache">>, <<"0CABDCE0DB9FE6D3318131174B9F2B351328A4C0AFBEB3E6E99BB0E02E9B621D">>},
{<<"cowlib">>, <<"DB8F7505D8332D98EF50A3EF34B34C1AFDDEC7506E4EE4DD4A3A266285D282CA">>},
{<<"exml">>, <<"9581FE6512D9772C61BBE611CD4A8E5BB90B4D4481275325EC520F7A931A9393">>},
{<<"exml">>, <<"54C1AAD5BD290EC31C19CE4A5D449C7E3236107AA2D3610FC04FC963DC8EAF13">>},
{<<"fast_pbkdf2">>, <<"199BCEC73A1A246941E9465D3DC41052953B638128841ED24B29ED03CF70AF27">>},
{<<"fast_scram">>, <<"BEEADB03D774640F0671681759CE53B2FF33CB58C86FD9BF2A793E2FC1ED0F5D">>},
{<<"fast_tls">>, <<"65D7D547A09EEFB37A1C0D04D8601FAC4F3E6E2C1EDE859A7787081670F9648D">>},
Expand All @@ -28,7 +28,7 @@
{pkg_hash_ext,[
{<<"bbmustache">>, <<"688B33A4D5CC2D51F575ADF0B3683FC40A38314A2F150906EDCFC77F5B577B3B">>},
{<<"cowlib">>, <<"E1E1284DC3FC030A64B1AD0D8382AE7E99DA46C3246B815318A4B848873800A4">>},
{<<"exml">>, <<"D8E7894E2544402B4986EEB2443C15B51B14F686266F091DBF2777D1D99A2FA2">>},
{<<"exml">>, <<"08CC97527C708D57A03F467049AC260B5951BD67906AA154BE56B5D8BDD3238C">>},
{<<"fast_pbkdf2">>, <<"35EEC22629AAA739915843C7B7DE0D84657D1ECE972D8BBC86368747E9C14012">>},
{<<"fast_scram">>, <<"FE0650A309FDF97C75E1EA812CCFB40EB464ECAFD3783E83AA17C7F572EDAB0B">>},
{<<"fast_tls">>, <<"131542913937025E48CD80AA81F00359686D5501B75621E72026A87B5229505B">>},
Expand Down
67 changes: 33 additions & 34 deletions src/escalus_bosh.erl
Original file line number Diff line number Diff line change
Expand Up @@ -169,49 +169,48 @@ session_creation_body(Rid, To) ->
exml:element().
session_creation_body(Wait, Version, Lang, Rid, To, nil) ->
empty_body(Rid, nil,
[{<<"content">>, <<"text/xml; charset=utf-8">>},
{<<"xmlns:xmpp">>, ?NS_BOSH},
{<<"xmpp:version">>, Version},
{<<"ver">>, <<"1.6">>},
{<<"hold">>, <<"1">>},
{<<"wait">>, list_to_binary(integer_to_list(Wait))},
{<<"xml:lang">>, Lang},
{<<"to">>, To}]);
#{<<"content">> => <<"text/xml; charset=utf-8">>,
<<"xmlns:xmpp">> => ?NS_BOSH,
<<"xmpp:version">> => Version,
<<"ver">> => <<"1.6">>,
<<"hold">> => <<"1">>,
<<"wait">> => list_to_binary(integer_to_list(Wait)),
<<"xml:lang">> => Lang,
<<"to">> => To});
session_creation_body(_Wait, _Version, Lang, Rid, To, Sid) ->
empty_body(Rid, Sid,
[{<<"xmlns:xmpp">>, ?NS_BOSH},
{<<"xml:lang">>, Lang},
{<<"to">>, To},
{<<"xmpp:restart">>, <<"true">>}]).
#{<<"xmlns:xmpp">> => ?NS_BOSH,
<<"xml:lang">> => Lang,
<<"to">> => To,
<<"xmpp:restart">> => <<"true">>}).

-spec session_termination_body(Rid :: integer(), Sid :: binary() | nil) -> exml:element().
session_termination_body(Rid, Sid) ->
Body = empty_body(Rid, Sid, [{<<"type">>, <<"terminate">>}]),
Body = empty_body(Rid, Sid, #{<<"type">> => <<"terminate">>}),
Body#xmlel{children = [escalus_stanza:presence(<<"unavailable">>)]}.

-spec empty_body(Rid :: integer(), Sid :: binary()) -> exml:element().
empty_body(Rid, Sid) ->
empty_body(Rid, Sid, []).
empty_body(Rid, Sid, #{}).

-spec empty_body(Rid :: integer(), Sid :: binary() | nil, ExtraAttrs :: [exml:attr()]) ->
-spec empty_body(Rid :: integer(), Sid :: binary() | nil, ExtraAttrs :: exml:attrs()) ->
exml:element().
empty_body(Rid, Sid, ExtraAttrs) ->
#xmlel{name = <<"body">>,
attrs = common_attrs(Rid, Sid) ++ ExtraAttrs}.
attrs = maps:merge(common_attrs(Rid, Sid), ExtraAttrs)}.

pause_body(Rid, Sid, Seconds) ->
Empty = empty_body(Rid, Sid),
Pause = {<<"pause">>, integer_to_binary(Seconds)},
Empty#xmlel{attrs = Empty#xmlel.attrs ++ [Pause]}.
Empty#xmlel{attrs = maps:put(<<"pause">>, integer_to_binary(Seconds), Empty#xmlel.attrs)}.
NelsonVides marked this conversation as resolved.
Show resolved Hide resolved

common_attrs(Rid) ->
[{<<"rid">>, pack_rid(Rid)},
{<<"xmlns">>, ?NS_HTTP_BIND}].
#{<<"rid">> => pack_rid(Rid),
<<"xmlns">> => ?NS_HTTP_BIND}.

common_attrs(Rid, nil) ->
common_attrs(Rid);
common_attrs(Rid, Sid) ->
common_attrs(Rid) ++ [{<<"sid">>, Sid}].
maps:put(<<"sid">>, Sid, common_attrs(Rid)).

pack_rid(Rid) ->
integer_to_binary(Rid).
Expand Down Expand Up @@ -576,35 +575,35 @@ handle_recv(#state{replies = [{#xmlel{name = <<"body">>, attrs = Attrs} = Body,

wrap_elem(#xmlstreamstart{attrs = Attrs},
#state{rid = Rid, sid = Sid, wait = Wait}) ->
Version = proplists:get_value(<<"version">>, Attrs, <<"1.0">>),
Lang = proplists:get_value(<<"xml:lang">>, Attrs, <<"en">>),
To = proplists:get_value(<<"to">>, Attrs, <<"localhost">>),
Version = maps:get(<<"version">>, Attrs, <<"1.0">>),
Lang = maps:get(<<"xml:lang">>, Attrs, <<"en">>),
To = maps:get(<<"to">>, Attrs, <<"localhost">>),
session_creation_body(Wait, Version, Lang, Rid, To, Sid);
wrap_elem(#xmlstreamend{}, #state{sid=Sid, rid=Rid}) ->
session_termination_body(Rid, Sid);
wrap_elem(Element, #state{sid = Sid, rid=Rid}) ->
(empty_body(Rid, Sid))#xmlel{children = [Element]}.

unwrap_elem(#xmlel{name = <<"body">>, children = Body, attrs=Attrs}) ->
unwrap_elem(#xmlel{name = <<"body">>, children = Body, attrs = Attrs}) ->
Type = detect_type(Attrs),
case Type of
{streamstart, Ver} ->
Server = proplists:get_value(<<"from">>, Attrs),
StreamStart = #xmlstreamstart{name = <<"stream:stream">>, attrs=[
{<<"from">>, Server},
{<<"version">>, Ver},
{<<"xml:lang">>, <<"en">>},
{<<"xmlns">>, <<"jabber:client">>},
{<<"xmlns:stream">>,
<<"http://etherx.jabber.org/streams">>}]},
Server = maps:get(<<"from">>, Attrs),
NewAttrs = #{<<"from">> => Server,
<<"version">> => Ver,
<<"xml:lang">> => <<"en">>,
<<"xmlns">> => <<"jabber:client">>,
<<"xmlns:stream">> => <<"http://etherx.jabber.org/streams">>},
StreamStart = #xmlstreamstart{name = <<"stream:stream">>,
attrs = NewAttrs},
[StreamStart];
streamend ->
[escalus_stanza:stream_end()];
_ -> []
end ++ Body.

detect_type(Attrs) ->
Get = fun(A) -> proplists:get_value(A, Attrs) end,
Get = fun(A) -> maps:get(A, Attrs, undefined) end,
case {Get(<<"type">>), Get(<<"xmpp:version">>)} of
{<<"terminate">>, _} -> streamend;
{_, undefined} -> normal;
Expand Down
9 changes: 4 additions & 5 deletions src/escalus_component.erl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ component_start_stream(Conn = #client{props = Props}, []) ->
StreamStartRep = escalus_connection:get_stanza(Conn, wait_for_stream),

#xmlstreamstart{attrs = Attrs} = StreamStartRep,
Id = proplists:get_value(<<"id">>, Attrs),
Id = maps:get(<<"id">>, Attrs, undefined),

{Conn#client{props = [{sid, Id} | Props]}, []}.

Expand All @@ -205,10 +205,9 @@ component_handshake(Conn = #client{props = Props}, []) ->
%% Stanzas
%%--------------------------------------------------------------------
component_stream_start(Component) ->
Attrs = [{<<"to">>, Component},
{<<"xmlns">>, <<"jabber:component:accept">>},
{<<"xmlns:stream">>,
<<"http://etherx.jabber.org/streams">>}],
Attrs = #{<<"to">> => Component,
<<"xmlns">> => <<"jabber:component:accept">>,
<<"xmlns:stream">> => <<"http://etherx.jabber.org/streams">>},
#xmlstreamstart{name = <<"stream:stream">>, attrs = Attrs}.

component_handshake_el(SID, Password) ->
Expand Down
10 changes: 5 additions & 5 deletions src/escalus_event.erl
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ build_elem_event(BaseTime, {story, Type, Time}) ->
build_story_event_elem(Type, BaseTime, Time).

build_story_event_elem(Type, BaseTime, Time) ->
#xmlel{name = list_to_binary(atom_to_list(Type)),
attrs = [{<<"offset">>, time_offset_binary(BaseTime, Time)}]}.
#xmlel{name = atom_to_binary(Type),
NelsonVides marked this conversation as resolved.
Show resolved Hide resolved
attrs = #{<<"offset">> => time_offset_binary(BaseTime, Time)}}.

build_stanza_event_elem(Type, JID, BaseTime, Time, Elem) ->
#xmlel{name = list_to_binary(atom_to_list(Type)),
attrs = [{<<"jid">>, jid_to_binary(JID)},
{<<"offset">>, time_offset_binary(BaseTime, Time)}],
#xmlel{name = atom_to_binary(Type),
attrs = #{<<"jid">> => jid_to_binary(JID),
<<"offset">> => time_offset_binary(BaseTime, Time)},
children = [Elem || Elem =/= undefined]}.

manager(Config) ->
Expand Down
28 changes: 14 additions & 14 deletions src/escalus_pred.erl
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ is_chat_message(Msg, Stanza) ->

-spec is_chat_message_from_to(binary(), binary(), binary(), exml:element())
-> boolean().
is_chat_message_from_to(From, To, Msg, #xmlel{attrs=Attrs} = Stanza) ->
is_chat_message_from_to(From, To, Msg, #xmlel{attrs = Attrs} = Stanza) ->
is_chat_message(Msg, Stanza)
andalso
bin(From) == proplists:get_value(<<"from">>, Attrs)
bin(From) == maps:get(<<"from">>, Attrs, undefined)
andalso
bin(To) == proplists:get_value(<<"to">>, Attrs).
bin(To) == maps:get(<<"to">>, Attrs, undefined).

-spec is_groupchat_message(exml:element()) -> boolean().
is_groupchat_message(Stanza) ->
Expand Down Expand Up @@ -257,24 +257,24 @@ has_type(Type, Stanza) ->
-spec is_0184_request(exml:element()) -> boolean().
is_0184_request(#xmlel{children = Els}) ->
#xmlel{ name = <<"request">>,
attrs = [{<<"xmlns">>, <<"urn:xmpp:receipts">>}],
attrs = #{<<"xmlns">> => <<"urn:xmpp:receipts">>},
children = [] } =:= lists:keyfind(<<"request">>, 2, Els).

-spec is_0184_receipt(exml:element(), exml:element()) -> boolean().
is_0184_receipt(#xmlel{ attrs = ReqAttrs } = Request, Receipt) ->
{_, ReqTo} = lists:keyfind(<<"to">>, 1, ReqAttrs),
is_0184_receipt(#xmlel{attrs = ReqAttrs} = Request, Receipt) ->
ReqTo = maps:get(<<"to">>, ReqAttrs),
is_0184_receipt(Request, ReqTo, Receipt).

-spec is_0184_receipt(exml:element(), binary(), exml:element()) -> boolean().
is_0184_receipt(#xmlel{ attrs = ReqAttrs } = _Request,
is_0184_receipt(#xmlel{attrs = ReqAttrs} = _Request,
ProperResFrom,
#xmlel{ attrs = ResAttrs,
children = [#xmlel{ name = <<"received">>,
attrs = SubAttrs}]} = _Receipt) ->
{_, ResFrom} = lists:keyfind(<<"from">>, 1, ResAttrs),
{_, ReqID} = lists:keyfind(<<"id">>, 1, ReqAttrs),
{_, ResID} = lists:keyfind(<<"id">>, 1, SubAttrs),
{_, ResXmlns} = lists:keyfind(<<"xmlns">>, 1, SubAttrs),
#xmlel{attrs = ResAttrs,
children = [#xmlel{name = <<"received">>,
attrs = SubAttrs}]} = _Receipt) ->
ResFrom = maps:get(<<"from">>, ResAttrs),
ReqID = maps:get(<<"id">>, ReqAttrs),
ResID = maps:get(<<"id">>, SubAttrs),
ResXmlns = maps:get(<<"xmlns">>, SubAttrs),
binary:longest_common_prefix([ProperResFrom, ResFrom]) == byte_size(ProperResFrom)
andalso
ReqID == ResID
Expand Down
Loading