Skip to content

Commit 1428ceb

Browse files
authored
Merge pull request #4473 from esl/xml_cleanups
Cleanup exml types
2 parents ce1b5f6 + 2c9994c commit 1428ceb

16 files changed

+66
-87
lines changed

big_tests/rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
%% We use https:// instead of git://
1010
{deps, [
11-
{exml, "4.0.0", {pkg, hexml}},
11+
{exml, "4.1.1", {pkg, hexml}},
1212
{bbmustache, "1.12.2"},
1313
{jiffy, "1.1.2"},
1414
{proper, "1.4.0"},

big_tests/rebar.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
0},
1313
{<<"escalus">>,{pkg,<<"escalus">>,<<"4.3.0">>},0},
1414
{<<"esip">>,{pkg,<<"esip">>,<<"1.0.56">>},0},
15-
{<<"exml">>,{pkg,<<"hexml">>,<<"4.0.0">>},0},
15+
{<<"exml">>,{pkg,<<"hexml">>,<<"4.1.1">>},0},
1616
{<<"fast_pbkdf2">>,{pkg,<<"fast_pbkdf2">>,<<"1.0.6">>},2},
1717
{<<"fast_scram">>,{pkg,<<"fast_scram">>,<<"0.6.1">>},1},
1818
{<<"fast_tls">>,{pkg,<<"fast_tls">>,<<"1.1.21">>},1},
@@ -44,7 +44,7 @@
4444
{<<"ct_groups_summary_hook">>, <<"21B94902B6CF2D345F4D790D34B49654E71CB8E570DCCC9C1C3616DAE720A7AA">>},
4545
{<<"escalus">>, <<"80301D57F4C863FA95F09AE148524508F18D7389B5070E2A5FFB7A38B51527C5">>},
4646
{<<"esip">>, <<"63C0FDC667BE751714E1E5C14621A9334F21B60AC1BB68BE889454CA9CA021B7">>},
47-
{<<"exml">>, <<"54C1AAD5BD290EC31C19CE4A5D449C7E3236107AA2D3610FC04FC963DC8EAF13">>},
47+
{<<"exml">>, <<"D46272177F3B779D75058005C744997034823AB3A237F9B30B56A583B063FDE3">>},
4848
{<<"fast_pbkdf2">>, <<"199BCEC73A1A246941E9465D3DC41052953B638128841ED24B29ED03CF70AF27">>},
4949
{<<"fast_scram">>, <<"BEEADB03D774640F0671681759CE53B2FF33CB58C86FD9BF2A793E2FC1ED0F5D">>},
5050
{<<"fast_tls">>, <<"65D7D547A09EEFB37A1C0D04D8601FAC4F3E6E2C1EDE859A7787081670F9648D">>},
@@ -75,7 +75,7 @@
7575
{<<"ct_groups_summary_hook">>, <<"997CDE48FEB0C398989E4091A341D4FFF43CFA06CDB8FB2E80CC4A0E0362691C">>},
7676
{<<"escalus">>, <<"8C4D39677D55C48B04EDE4EAC0FD0AD2A574BEDE7180761E6E3D3877900C7708">>},
7777
{<<"esip">>, <<"9EF3660CEF93B623F7368DCD5C79F4E704358631909E6DD464E335378815DA1F">>},
78-
{<<"exml">>, <<"08CC97527C708D57A03F467049AC260B5951BD67906AA154BE56B5D8BDD3238C">>},
78+
{<<"exml">>, <<"86C154396A9B21EEB0EDB9636D0E2D493FE0F59EAAF40FCFE795210F31119D8F">>},
7979
{<<"fast_pbkdf2">>, <<"35EEC22629AAA739915843C7B7DE0D84657D1ECE972D8BBC86368747E9C14012">>},
8080
{<<"fast_scram">>, <<"FE0650A309FDF97C75E1EA812CCFB40EB464ECAFD3783E83AA17C7F572EDAB0B">>},
8181
{<<"fast_tls">>, <<"131542913937025E48CD80AA81F00359686D5501B75621E72026A87B5229505B">>},

big_tests/tests/graphql_private_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ parse_xml_error(Config) ->
159159
parse_xml_error(Config, Alice) ->
160160
ResultSet = user_set_private(Alice, <<"AAAABBBB">>, Config),
161161
?assertEqual(<<"Input coercion failed for type XmlElement with value <<\"AAAABBBB\">>."
162-
" The reason it failed is: \"expected <\"">>,
162+
" The reason it failed is: <<\"expected <\">>">>,
163163
get_coercion_err_msg(ResultSet)).
164164

165165
% User private not configured test cases

big_tests/tests/graphql_stanza_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ user_send_stanza_with_spoofed_from_story(Config, Alice, Bob) ->
393393
admin_send_unparsable_stanza(Config) ->
394394
Res = send_stanza(<<"<test">>, Config),
395395
?assertEqual(<<"Input coercion failed for type XmlElement with value <<\"<test\">>. "
396-
"The reason it failed is: \"expected >\"">>,
396+
"The reason it failed is: <<\"expected >\">>">>,
397397
get_coercion_err_msg(Res)).
398398

399399
admin_send_stanza_from_unknown_user(Config) ->

include/mod_muc_light.hrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
-record(msg, {
5959
id = <<>> :: binary(),
60-
children = [] :: [jlib:xmlch()]
60+
children = [] :: [exml:child()]
6161
}).
6262

6363
-record(config, {

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{deps,
4747
[
4848
%%% Stateless parsers
49-
{exml, "4.0.0", {pkg, hexml}},
49+
{exml, "4.1.1", {pkg, hexml}},
5050
{jiffy, "1.1.2"},
5151
{jid, "2.2.0", {pkg, mongoose_jid}},
5252
{tomerl, "0.5.0"},

rebar.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{<<"erl_csv">>,{pkg,<<"erl_csv">>,<<"0.3.3">>},0},
2727
{<<"erlang_doctor">>,{pkg,<<"erlang_doctor">>,<<"0.2.7">>},0},
2828
{<<"erlcloud">>,{pkg,<<"erlcloud">>,<<"3.8.2">>},0},
29-
{<<"exml">>,{pkg,<<"hexml">>,<<"4.0.0">>},0},
29+
{<<"exml">>,{pkg,<<"hexml">>,<<"4.1.1">>},0},
3030
{<<"exometer_core">>,
3131
{git,"https://github.com/esl/exometer_core.git",
3232
{ref,"123daa053a4abb3ff4bdbf52f08344da535294e9"}},
@@ -142,7 +142,7 @@
142142
{<<"erl_csv">>, <<"94FBA776D493FE0DA76786D694CC2A788F14C864766DBB04C1786272515898C4">>},
143143
{<<"erlang_doctor">>, <<"38DCCF531B0DCF01B327EF437C7422EA3123457CF664C75BA8219D6022A7DA4B">>},
144144
{<<"erlcloud">>, <<"E0EE55C4B11826E79737655A52282C5C62EB31F7FDFACF4E314C12422C64A95F">>},
145-
{<<"exml">>, <<"54C1AAD5BD290EC31C19CE4A5D449C7E3236107AA2D3610FC04FC963DC8EAF13">>},
145+
{<<"exml">>, <<"D46272177F3B779D75058005C744997034823AB3A237F9B30B56A583B063FDE3">>},
146146
{<<"fast_pbkdf2">>, <<"6045138C4C209FC8222A0B18B2CB1D7BD7407EF4ADAD0F14C5E0F7F4726E3E41">>},
147147
{<<"fast_scram">>, <<"70724F584A118DA147A51EE38DEE56203F217D58AD61E0BB2C2EF834C16B35B8">>},
148148
{<<"fast_tls">>, <<"44356B256AFAD4399C2FC5059A3066669DAFD8BD4E4E796C9C1CF8910DDD265E">>},
@@ -213,7 +213,7 @@
213213
{<<"erl_csv">>, <<"B1B4B5F6578B2AFC307E8CBF67277AC8E3D721FE5E6B5A4D53BA49215C9600F3">>},
214214
{<<"erlang_doctor">>, <<"5895F16E04666843895479D60624751330F87D8296411E03EC405F42F697796D">>},
215215
{<<"erlcloud">>, <<"36207854A37BF157B45A9A115A7EEE814430808ADB2CC713C72E0048DD6351A1">>},
216-
{<<"exml">>, <<"08CC97527C708D57A03F467049AC260B5951BD67906AA154BE56B5D8BDD3238C">>},
216+
{<<"exml">>, <<"86C154396A9B21EEB0EDB9636D0E2D493FE0F59EAAF40FCFE795210F31119D8F">>},
217217
{<<"fast_pbkdf2">>, <<"BC3B5A3CAB47AD114FF8BB815FEDE62A6187ACD14D8B37412F2AF8236A089CEF">>},
218218
{<<"fast_scram">>, <<"771D034341599CFC6A6C5E56CF924B68D2C7478088CAF17419E3147B66914667">>},
219219
{<<"fast_tls">>, <<"E65779AEFB7AB15C4755230FEF8077E687D20CC5A3984A5974F9F657E8E2485B">>},

src/c2s/mongoose_c2s.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ handle_socket_packet(StateData = #c2s_data{parser = Parser}, Packet) ->
273273
?LOG_DEBUG(#{what => received_xml_on_stream, packet => Packet, c2s_pid => self()}),
274274
case exml_stream:parse(Parser, Packet) of
275275
{error, Reason} ->
276-
NextEvent = {next_event, internal, #xmlstreamerror{name = iolist_to_binary(Reason)}},
276+
NextEvent = {next_event, internal, #xmlstreamerror{name = Reason}},
277277
{keep_state, StateData, NextEvent};
278278
{ok, NewParser, XmlElements} ->
279279
Size = iolist_size(Packet),

src/jlib.erl

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@
6666
-type xmlstreamerror() :: #xmlstreamerror{}.
6767
-type xmlstreamel() :: exml:element() | exml_stream:start() | exml_stream:stop() | xmlstreamerror().
6868

69-
-type xmlcdata() :: #xmlcdata{}.
70-
71-
-type xmlch() :: exml:element() | xmlcdata(). % (XML ch)ild
72-
7369
-type iq() :: #iq{}.
7470

7571
-type rsm_in() :: #rsm_in{}.
@@ -80,8 +76,6 @@
8076

8177
-export_type([xmlstreamel/0, xmlstreamerror/0,
8278
rsm_in/0, rsm_out/0,
83-
xmlcdata/0,
84-
xmlch/0,
8579
iq/0,
8680
rfc3339_string/0]).
8781

@@ -100,8 +94,7 @@ make_result_iq_reply_attrs(#xmlel{attrs = Attrs}) ->
10094
Attrs1 = swap_from_to_attrs(Attrs),
10195
Attrs1#{<<"type">> => <<"result">>}.
10296

103-
-spec make_error_reply(exml:element() | mongoose_acc:t(),
104-
xmlcdata() | exml:element()) ->
97+
-spec make_error_reply(exml:element() | mongoose_acc:t(), exml:child()) ->
10598
exml:element() | {mongoose_acc:t(), exml:element() | {error, {already_an_error, _, _}}}.
10699
make_error_reply(#xmlel{} = Elem, Error) ->
107100
?LOG_DEBUG(#{what => make_error_reply,
@@ -191,12 +184,9 @@ swap_from_to_attrs(Attrs) ->
191184
To :: jid:simple_jid() | jid:jid(),
192185
XE :: exml:element()) -> exml:element().
193186
replace_from_to(From, To, XE = #xmlel{attrs = Attrs}) ->
194-
NewAttrs = replace_from_to_attrs(jid:to_binary(From),
195-
jid:to_binary(To),
196-
Attrs),
187+
NewAttrs = replace_from_to_attrs(jid:to_binary(From), jid:to_binary(To), Attrs),
197188
XE#xmlel{attrs = NewAttrs}.
198189

199-
200190
-spec remove_attr(binary(), exml:element()) -> exml:element().
201191
remove_attr(Attr, XE = #xmlel{attrs = Attrs}) ->
202192
NewAttrs = maps:remove(Attr, Attrs),
@@ -467,41 +457,30 @@ maybe_append_delay(Packet = #xmlel{children = Children}, From, TS, Desc) ->
467457
Packet
468458
end.
469459

470-
remove_delay_tags(#xmlel{children = Els} = Packet) ->
471-
NEl = lists:foldl(
472-
fun(#xmlel{name= <<"delay">>} = R, El) ->
473-
case exml_query:attr(R, <<"xmlns">>) of
474-
?NS_DELAY ->
475-
El;
476-
_ ->
477-
El ++ [R]
478-
end;
479-
(#xmlel{name= <<"x">>} = R, El) ->
480-
case exml_query:attr(R, <<"xmlns">>) of
481-
?NS_DELAY91 ->
482-
El;
483-
_ ->
484-
El ++ [R]
485-
end;
486-
(R, El) ->
487-
El ++ [R]
488-
end, [], Els),
489-
Packet#xmlel{children = NEl}.
490-
491-
-spec remove_cdata([xmlch()]) -> [xmlch()].
460+
remove_delay_tags(#xmlel{children = Children} = Packet) ->
461+
Fun = fun(#xmlel{name = <<"delay">>, attrs = #{<<"xmlns">> := ?NS_DELAY}}, Els) ->
462+
Els;
463+
(#xmlel{name = <<"x">>, attrs = #{<<"xmlns">> := ?NS_DELAY91}}, Els) ->
464+
Els;
465+
(R, Els) ->
466+
[R | Els]
467+
end,
468+
NEls = lists:foldl(Fun, [], Children),
469+
Packet#xmlel{children = lists:reverse(NEls)}.
470+
471+
-spec remove_cdata([exml:child()]) -> [exml:element()].
492472
remove_cdata(L) ->
493473
[E || E <- L, remove_cdata_p(E)].
494474

495-
-spec remove_cdata_p(xmlch()) -> boolean().
475+
-spec remove_cdata_p(exml:child()) -> boolean().
496476
remove_cdata_p(#xmlel{}) -> true;
497477
remove_cdata_p(_) -> false.
498478

499-
-spec append_subtags(exml:element(), [xmlch()]) -> exml:element().
479+
-spec append_subtags(exml:element(), [exml:child()]) -> exml:element().
500480
append_subtags(XE = #xmlel{children = SubTags1}, SubTags2) ->
501481
XE#xmlel{children = SubTags1 ++ SubTags2}.
502482

503-
-spec replace_tag_attr(Attr :: binary(), Value :: binary(), exml:element()
504-
) -> exml:element().
483+
-spec replace_tag_attr(Attr :: binary(), Value :: binary(), exml:element()) -> exml:element().
505484
replace_tag_attr(Attr, Value, XE = #xmlel{attrs = Attrs}) ->
506485
Attrs1 = Attrs#{Attr => Value},
507486
XE#xmlel{attrs = Attrs1}.

src/mam/mod_mam_utils.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ result_set(FirstId, LastId, FirstIndexI, CountI)
582582
children = FirstEl ++ LastEl ++ [CountEl]}.
583583

584584

585-
-spec result_query(jlib:xmlcdata() | exml:element(), binary()) -> exml:element().
585+
-spec result_query(exml:child(), binary()) -> exml:element().
586586
result_query(SetEl, Namespace) ->
587587
#xmlel{
588588
name = <<"query">>,

0 commit comments

Comments
 (0)