From f55afa05846730f59341c5446e1f51472b61b0f3 Mon Sep 17 00:00:00 2001 From: Daniel Finke Date: Mon, 24 Jun 2024 15:32:14 -0700 Subject: [PATCH] Fix record types (p_state, pf_state, faultcode) Address post-OTP 19 requirement for explicit `undefined` see: https://www.erlang.org/doc/system/typespec.html#type-information-in-record-declarations - remove unused `fault_types` field from `#op` - set static parsers early, at parse start, in `soap_client_util` --- src/soap.hrl | 4 ++-- src/soap_client_util.erl | 20 +++++++++++--------- src/soap_fault.erl | 8 ++++---- src/soap_fault.hrl | 4 ++-- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/soap.hrl b/src/soap.hrl index deb9b55..640925b 100644 --- a/src/soap.hrl +++ b/src/soap.hrl @@ -31,8 +31,8 @@ in_type :: [{string(), atom()}] | atom(), %% the list type is only used %% during construction of the %% interface - out_type :: [{string(), atom()}] | undefined | atom(), %% see above - fault_types :: [atom()]}). + out_type :: [{string(), atom()}] | undefined | atom() %% see above +}). -type op() :: #op{}. -record(interface, { diff --git a/src/soap_client_util.erl b/src/soap_client_util.erl index a85840b..0a330e0 100644 --- a/src/soap_client_util.erl +++ b/src/soap_client_util.erl @@ -51,11 +51,11 @@ soap_ns :: string(), state :: atom(), parser :: fun(), - header_parser :: fun(), + header_parser :: fun() | undefined, fault_parser :: fun(), parser_state :: any(), soap_headers = [] :: [string() | tuple()], - soap_body :: string() | tuple(), + soap_body :: string() | tuple() | undefined, is_fault = false :: boolean(), namespaces = [] :: [{prefix(), uri()}] }). @@ -259,7 +259,9 @@ parse_xml(Message, Model, Http_status, Http_headers, try erlsom:parse_sax(Message, #p_state{model = Model, version = Version, soap_ns = Ns, state = start, - handler = Handler}, + handler = Handler, + parser = fun erlsom_parse:xml2StructCallback/2, + fault_parser = fun soap_fault:parse_fault/3}, fun xml_parser_cb_wrapped/2, []) of {ok, #p_state{is_fault = true, soap_headers = Decoded_headers, @@ -355,27 +357,27 @@ xml_parser_cb({startElement, Ns, "Body", _Prfx, _Attrs}, xml_parser_cb({startElement, Ns, "Fault", _Prfx, _Attrs} = Event, #p_state{state = body, version = Version, + fault_parser = Fault_parser, namespaces = Namespaces, soap_ns = Ns} = S) -> Start_state = soap_fault:parse_fault_start(Version), - Fault_parser = fun soap_fault:parse_fault/3, S1 = parse_event(Fault_parser, startDocument, Namespaces, Start_state), %% the event that we just received from the sax parser is recycled S2 = parse_event(Fault_parser, Event, Namespaces, S1), S#p_state{state = parsing_fault, is_fault = true, - fault_parser = Fault_parser, parser_state = S2}; + parser_state = S2}; %% parsing the body xml_parser_cb({startElement, _Namespace, _LocalName, _Prfx, _Attrs} = Event, #p_state{state = body, model = Model, + parser = Parser, namespaces = N_spaces} = S) -> Callback_state = erlsom_parse:new_state(Model, N_spaces), %% a new "startDocument" event is injected to get the body parser going. - S1 = erlsom_parse:xml2StructCallback(startDocument, Callback_state), - S2 = erlsom_parse:xml2StructCallback(Event, S1), - S#p_state{state = parsing_body, parser_state = S2, - parser = fun erlsom_parse:xml2StructCallback/2}; + S1 = Parser(startDocument, Callback_state), + S2 = Parser(Event, S1), + S#p_state{state = parsing_body, parser_state = S2}; xml_parser_cb({endElement, Ns, "Body", _Prfx}, #p_state{state = body, soap_ns = Ns} = S) -> diff --git a/src/soap_fault.erl b/src/soap_fault.erl index 8c1c37e..cf806e9 100644 --- a/src/soap_fault.erl +++ b/src/soap_fault.erl @@ -76,12 +76,12 @@ version :: atom(), state :: atom(), characters = "" :: string(), - code :: fault_code_object(), - fault_string :: fault_string(), + code :: fault_code_object() | undefined, + fault_string :: fault_string() | undefined, actor :: fault_actor(), reasons = [] :: [fault_reason()], - language :: string(), - detail_tag :: {tag(), uri()}, + language :: string() | undefined, + detail_tag :: {tag(), uri()} | undefined, details = [] :: [{tag(), uri(), string()}] }). diff --git a/src/soap_fault.hrl b/src/soap_fault.hrl index 11bc8c9..1e59c20 100644 --- a/src/soap_fault.hrl +++ b/src/soap_fault.hrl @@ -26,9 +26,9 @@ tag :: string(), text :: string()}). --record(faultcode, {uri :: string(), +-record(faultcode, {uri :: string() | undefined, code :: string() | atom(), - subcode :: #faultcode{} % only v. 1.2 + subcode :: #faultcode{} | undefined % only v. 1.2 }). -record(faultreason, {text :: string(),