From b6c8b96f5db84019503c805f7e1d6d5e9aff138e Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Tue, 14 Jun 2005 11:15:07 +0000 Subject: [PATCH] uses XmlPushParser instead of Pxp for parsing getter resolve answer --- helm/ocaml/getter/Makefile | 2 +- helm/ocaml/getter/http_getter.ml | 38 +++++++++++++++------------- helm/ocaml/getter/http_getter_env.ml | 3 --- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/helm/ocaml/getter/Makefile b/helm/ocaml/getter/Makefile index 820b1628e..2895f12e1 100644 --- a/helm/ocaml/getter/Makefile +++ b/helm/ocaml/getter/Makefile @@ -3,7 +3,7 @@ PACKAGE = getter REQUIRES = \ http dbm pcre shell zip \ - helm-pxp helm-thread helm-logger helm-urimanager helm-registry + helm-xml helm-thread helm-logger helm-urimanager helm-registry INTERFACE_FILES = \ tree.mli \ diff --git a/helm/ocaml/getter/http_getter.ml b/helm/ocaml/getter/http_getter.ml index d0ecf9ba2..58c94ac95 100644 --- a/helm/ocaml/getter/http_getter.ml +++ b/helm/ocaml/getter/http_getter.ml @@ -35,8 +35,6 @@ open Http_getter_types exception Not_implemented of string exception UnexpectedGetterOutput -(* resolve_result is needed because it is not possible to raise *) -(* an exception in a pxp ever-processing callback. Too bad. *) type resolve_result = | Unknown | Exception of exn @@ -262,22 +260,26 @@ let resolve_remote uri = (* deliver resolve request to http_getter *) let doc = ClientHTTP.get (sprintf "%sresolve?uri=%s" (getter_url ()) uri) in let res = ref Unknown in - Pxp_ev_parser.process_entity PxpHelmConf.pxp_config (`Entry_content []) - (Pxp_ev_parser.create_entity_manager ~is_document:true - PxpHelmConf.pxp_config (Pxp_yacc.from_string doc)) - (function - | Pxp_types.E_start_tag ("url",["value",url],_,_) -> res := Resolved url - | Pxp_types.E_start_tag ("unresolvable",[],_,_) -> - res := Exception (Unresolvable_URI uri) - | Pxp_types.E_start_tag ("not_found",[],_,_) -> - res := Exception (Key_not_found uri) - | Pxp_types.E_start_tag (x,_,_,_) -> - res := Exception UnexpectedGetterOutput - | _ -> ()); - match !res with - | Unknown -> raise UnexpectedGetterOutput - | Exception e -> raise e - | Resolved url -> url + let start_element tag attrs = + match tag with + | "url" -> + (try + res := Resolved (List.assoc "value" attrs) + with Not_found -> ()) + | "unresolvable" -> res := Exception (Unresolvable_URI uri) + | "not_found" -> res := Exception (Key_not_found uri) + | _ -> () + in + let callbacks = { + XmlPushParser.default_callbacks with + XmlPushParser.start_element = Some start_element + } in + let xml_parser = XmlPushParser.create_parser callbacks in + XmlPushParser.parse xml_parser (`String doc); + match !res with + | Unknown -> raise UnexpectedGetterOutput + | Exception e -> raise e + | Resolved url -> url let register_remote ~uri ~url = ClientHTTP.send (sprintf "%sregister?uri=%s&url=%s" (getter_url ()) uri url) diff --git a/helm/ocaml/getter/http_getter_env.ml b/helm/ocaml/getter/http_getter_env.ml index 575207057..be278da6e 100644 --- a/helm/ocaml/getter/http_getter_env.ml +++ b/helm/ocaml/getter/http_getter_env.ml @@ -27,9 +27,6 @@ *) open Printf -open Pxp_document -open Pxp_types -open Pxp_yacc open Http_getter_types -- 2.39.2