Replace xmerl with erlsom

Also includes small syntax fixes to sys.config, as well as one
compilation warning removal.
This commit is contained in:
Maciej Szlosarczyk 2020-02-27 09:50:24 +02:00
parent 8d46c736d7
commit 83aae9baee
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
8 changed files with 43 additions and 37 deletions

View file

@ -2,27 +2,25 @@
-export([find_cltrid/1, get_command/1, parse/1]). -export([find_cltrid/1, get_command/1, parse/1]).
-include_lib("xmerl/include/xmerl.hrl"). %% We are only interested in start element of a kind. The list produced
%% by this will need reversing after it is complete.
%% This parsing is naive, expects command/hello element to come right
%% after epp, but this should be everything we need for the purpose.
-define(PARSER_FUN,
fun (Event, Acc) ->
case Event of
{startElement, _, Name, _, _} -> [Name | Acc];
_ -> Acc
end
end).
%% Get command from an xmlElement. Otherwise return undefined. %% Get command a list of elements found by erlsom.
get_command(Record) %% Otherwise return undefined.
when is_record(Record, xmlElement) -> get_command(["epp", "command", Command | _Rest]) ->
case xmerl_xpath:string("name(/epp/*[1])", Record) of Command;
{xmlObj, string, "hello"} -> "hello"; get_command(["epp", "hello" | _Rest]) -> "hello";
{xmlObj, string, "command"} -> get_command1(Record);
{xmlObj, string, []} -> undefined
end;
get_command(_) -> undefined. get_command(_) -> undefined.
get_command1(Record)
when is_record(Record, xmlElement) ->
case xmerl_xpath:string("name(/epp/command/*[1])",
Record)
of
{xmlObj, string, []} -> undefined;
{xmlObj, string, Command} -> Command
end.
%% xml_erl expects a list of characters, so let's give it to it. %% xml_erl expects a list of characters, so let's give it to it.
%% Otherwise return an error tuple. %% Otherwise return an error tuple.
parse(Text) when is_list(Text) -> parse_list(Text); parse(Text) when is_list(Text) -> parse_list(Text);
@ -30,13 +28,14 @@ parse(Text) when is_binary(Text) ->
List = binary_to_list(Text), parse_list(List); List = binary_to_list(Text), parse_list(List);
parse(_) -> {error, {fatal, {expected_binary_or_list}}}. parse(_) -> {error, {fatal, {expected_binary_or_list}}}.
%% Parse a record that came from the wire and return a xmlElement record.
parse_list(List) when is_list(List) -> parse_list(List) when is_list(List) ->
try xmerl_scan:string(List, [{quiet, true}]) of try erlsom:parse_sax(List, [], ?PARSER_FUN) of
{Record, []} when is_record(Record, xmlElement) -> {ok, Result, _} ->
{ok, Record} ProperResult = lists:reverse(Result), {ok, ProperResult}
catch catch
exit:X -> {error, X} {error, Error} -> {error, Error};
error:Error -> {error, Error};
Error -> {error, Error}
end. end.
%% The idea is that even when XML command is invalid, %% The idea is that even when XML command is invalid,

View file

@ -74,6 +74,5 @@ readable_ip_test_case(_Config) ->
path_for_file_test_case(_Config) -> path_for_file_test_case(_Config) ->
AbsoluteFilename = "/usr/bin", AbsoluteFilename = "/usr/bin",
AbsoluteFilename = epp_util:path_for_file(AbsoluteFilename), AbsoluteFilename = epp_util:path_for_file(AbsoluteFilename),
RelativeFilename = "usr/bin",
true = (AbsoluteFilename =:= epp_util:path_for_file(AbsoluteFilename)), true = (AbsoluteFilename =:= epp_util:path_for_file(AbsoluteFilename)),
ok. ok.

View file

@ -1,9 +1,7 @@
-module(epp_xml_SUITE). -module(epp_xml_SUITE).
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-include_lib("stdlib/include/assert.hrl").
%% This is required for parse tests.
-include_lib("xmerl/include/xmerl.hrl").
-define(sampleCommandList, -define(sampleCommandList,
"<epp> "<epp>
@ -59,24 +57,28 @@ parse_not_a_list_or_binary_test_case(_Config) ->
parse_sample_valid_xml_list_test_case(_Config) -> parse_sample_valid_xml_list_test_case(_Config) ->
Input = ?sampleCommandList, Input = ?sampleCommandList,
{ok, Record} = epp_xml:parse(Input), {ok, Result} = epp_xml:parse(Input),
true = is_record(Record, xmlElement), ?assertEqual(["epp", "command", "login", "clID", "pw", "clTRID"],
Result),
ok. ok.
parse_sample_valid_xml_binary_test_case(_Config) -> parse_sample_valid_xml_binary_test_case(_Config) ->
Input = list_to_binary(?sampleCommandList), Input = list_to_binary(?sampleCommandList),
{ok, Record} = epp_xml:parse(Input), {ok, Result} = epp_xml:parse(Input),
true = is_record(Record, xmlElement), ?assertEqual(["epp", "command", "login", "clID", "pw", "clTRID"],
Result),
ok. ok.
parse_sample_invalid_xml_list_test_case(_Config) -> parse_sample_invalid_xml_list_test_case(_Config) ->
Input = "Some text", Input = "Some text",
{error, {fatal, _Details}} = epp_xml:parse(Input), ExpectedResult = {error, "Malformed: Illegal character in prolog"},
?assertEqual(ExpectedResult, epp_xml:parse(Input)),
ok. ok.
parse_sample_invalid_xml_binary_test_case(_Config) -> parse_sample_invalid_xml_binary_test_case(_Config) ->
Input = list_to_binary("Some text"), Input = <<"</epp>\n">>,
{error, {fatal, _Details}} = epp_xml:parse(Input), ExpectedResult = {error, {badmatch, []}},
?assertEqual(ExpectedResult, epp_xml:parse(Input)),
ok. ok.
%% find_cltrid %% find_cltrid

View file

@ -1,3 +1,4 @@
%% -*- erlang -*-
[ [
{epp_proxy, [ {epp_proxy, [
{dev_mode, true}, {dev_mode, true},

View file

@ -1,3 +1,4 @@
%% -*- erlang -*-
[ [
{epp_proxy, [ {epp_proxy, [
%% Enables or disable TCP connections without TLS (true/false) %% Enables or disable TCP connections without TLS (true/false)
@ -9,7 +10,7 @@
{tls_port, 700}, {tls_port, 700},
%% When set to true, you can connect to EPP over HTTPS endpoints without %% When set to true, you can connect to EPP over HTTPS endpoints without
%% verifying their TLS certificates. %% verifying their TLS certificates.
{insecure, false} {insecure, false},
%% URL of EPP endpoints. Can be pointed at a web server (Apache/NGINX) %% URL of EPP endpoints. Can be pointed at a web server (Apache/NGINX)
%% Can contain port (https://some-host:3000/epp/session) %% Can contain port (https://some-host:3000/epp/session)
%% Honors the prepended protocol (http / https). %% Honors the prepended protocol (http / https).

View file

@ -1,3 +1,4 @@
%% -*- erlang -*-
[ [
{epp_proxy, [{dev_mode, true}, {epp_proxy, [{dev_mode, true},
{tcp_port, 1180}, {tcp_port, 1180},

View file

@ -3,7 +3,8 @@
{deps, [{hackney, "1.15.1"}, {deps, [{hackney, "1.15.1"},
{syslog, {git, "https://github.com/Vagabond/erlang-syslog.git", {branch, "master"}}}, {syslog, {git, "https://github.com/Vagabond/erlang-syslog.git", {branch, "master"}}},
{lager, "3.7.0"}, {lager, "3.7.0"},
{lager_syslog, {git, "https://github.com/erlang-lager/lager_syslog.git"}}]}. {lager_syslog, {git, "https://github.com/erlang-lager/lager_syslog.git"}},
{erlsom, "1.5.0"}]}.
{relx, [{release, {epp_proxy, "git"}, {relx, [{release, {epp_proxy, "git"},
[epp_proxy, [epp_proxy,
@ -11,7 +12,7 @@
lager_syslog, lager_syslog,
hackney, hackney,
sasl, sasl,
xmerl]}, erlsom]},
{sys_config, "./config/sys.config"}, {sys_config, "./config/sys.config"},
{dev_mode, false}, {dev_mode, false},

View file

@ -1,5 +1,6 @@
{"1.1.0", {"1.1.0",
[{<<"certifi">>,{pkg,<<"certifi">>,<<"2.5.1">>},1}, [{<<"certifi">>,{pkg,<<"certifi">>,<<"2.5.1">>},1},
{<<"erlsom">>,{pkg,<<"erlsom">>,<<"1.5.0">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1}, {<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.15.1">>},0}, {<<"hackney">>,{pkg,<<"hackney">>,<<"1.15.1">>},0},
{<<"idna">>,{pkg,<<"idna">>,<<"6.0.0">>},1}, {<<"idna">>,{pkg,<<"idna">>,<<"6.0.0">>},1},
@ -20,6 +21,7 @@
[ [
{pkg_hash,[ {pkg_hash,[
{<<"certifi">>, <<"867CE347F7C7D78563450A18A6A28A8090331E77FA02380B4A21962A65D36EE5">>}, {<<"certifi">>, <<"867CE347F7C7D78563450A18A6A28A8090331E77FA02380B4A21962A65D36EE5">>},
{<<"erlsom">>, <<"C5A5CDD0EE0E8DCA62BCC4B13FF08DA24FDEFC16CCD8B25282A2FDA2BA1BE24A">>},
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>}, {<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
{<<"hackney">>, <<"9F8F471C844B8CE395F7B6D8398139E26DDCA9EBC171A8B91342EE15A19963F4">>}, {<<"hackney">>, <<"9F8F471C844B8CE395F7B6D8398139E26DDCA9EBC171A8B91342EE15A19963F4">>},
{<<"idna">>, <<"689C46CBCDF3524C44D5F3DDE8001F364CD7608A99556D8FBD8239A5798D4C10">>}, {<<"idna">>, <<"689C46CBCDF3524C44D5F3DDE8001F364CD7608A99556D8FBD8239A5798D4C10">>},