Skip to content

Commit 6fe907a

Browse files
committed
WiP: switch to Xmlm for output
This requires changing the `type xml` type to match what Xmlm expects, to avoid having to convert to another variant.
1 parent 5fd387a commit 6fe907a

File tree

6 files changed

+147
-251
lines changed

6 files changed

+147
-251
lines changed

ocaml/libs/http-lib/dune

Lines changed: 92 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,103 @@
11
(library
2-
(name http_lib)
3-
(public_name http-lib)
4-
(modes best)
5-
(wrapped false)
6-
(modules (:standard \ http_svr http_proxy server_io http_test radix_tree_test test_client test_server))
7-
(preprocess (per_module ((pps ppx_deriving_rpc) Http)))
8-
(libraries
9-
astring
10-
base64
11-
fmt
12-
ipaddr
13-
mtime
14-
mtime.clock.os
15-
rpclib.core
16-
rpclib.json
17-
rpclib.xml
18-
safe_resources
19-
sha
20-
stunnel
21-
threads.posix
22-
uuid
23-
uri
24-
xapi-backtrace
25-
xapi-consts.xapi_version
26-
xapi-idl.updates
27-
xapi-log
28-
clock
29-
xapi-stdext-pervasives
30-
xapi-stdext-threads
31-
xapi-stdext-unix
32-
xml-light2
33-
)
34-
)
2+
(name http_lib)
3+
(public_name http-lib)
4+
(modes best)
5+
(wrapped false)
6+
(modules
7+
(:standard
8+
\
9+
http_svr
10+
http_proxy
11+
server_io
12+
http_test
13+
radix_tree_test
14+
test_client
15+
test_server))
16+
(preprocess
17+
(per_module
18+
((pps ppx_deriving_rpc)
19+
Http)))
20+
(libraries
21+
astring
22+
base64
23+
fmt
24+
ipaddr
25+
mtime
26+
mtime.clock.os
27+
rpclib.core
28+
rpclib.json
29+
rpclib.xml
30+
xmlm
31+
safe_resources
32+
sha
33+
stunnel
34+
threads.posix
35+
uuid
36+
uri
37+
xapi-backtrace
38+
xapi-consts.xapi_version
39+
xapi-idl.updates
40+
xapi-log
41+
clock
42+
xapi-stdext-pervasives
43+
xapi-stdext-threads
44+
xapi-stdext-unix
45+
xml-light2))
3546

3647
(library
37-
(name httpsvr)
38-
(wrapped false)
39-
(modes best)
40-
(modules http_svr http_proxy server_io)
41-
(libraries
42-
astring
43-
http_lib
44-
ipaddr
45-
polly
46-
tgroup
47-
threads.posix
48-
tracing
49-
tracing_propagator
50-
uri
51-
xapi-log
52-
xapi-stdext-pervasives
53-
xapi-stdext-threads
54-
xapi-stdext-unix
55-
)
56-
)
48+
(name httpsvr)
49+
(wrapped false)
50+
(modes best)
51+
(modules http_svr http_proxy server_io)
52+
(libraries
53+
astring
54+
http_lib
55+
ipaddr
56+
polly
57+
tgroup
58+
threads.posix
59+
tracing
60+
tracing_propagator
61+
uri
62+
xapi-log
63+
xapi-stdext-pervasives
64+
xapi-stdext-threads
65+
xapi-stdext-unix))
5766

5867
(tests
59-
(names http_test radix_tree_test)
60-
(package http-lib)
61-
(modes (best exe))
62-
(modules http_test radix_tree_test)
63-
(libraries
64-
alcotest
65-
66-
fmt
67-
http_lib
68-
)
69-
)
68+
(names http_test radix_tree_test)
69+
(package http-lib)
70+
(modes
71+
(best exe))
72+
(modules http_test radix_tree_test)
73+
(libraries alcotest fmt http_lib))
7074

7175
(executable
72-
(modes exe)
73-
(name test_client)
74-
(modules test_client)
75-
(libraries
76-
77-
http_lib
78-
safe-resources
79-
stunnel
80-
threads.posix
81-
xapi-backtrace
82-
xapi-log
83-
xapi-stdext-pervasives
84-
xapi-stdext-unix
85-
)
86-
)
76+
(modes exe)
77+
(name test_client)
78+
(modules test_client)
79+
(libraries
80+
http_lib
81+
safe-resources
82+
stunnel
83+
threads.posix
84+
xapi-backtrace
85+
xapi-log
86+
xapi-stdext-pervasives
87+
xapi-stdext-unix))
8788

8889
(executable
89-
(modes exe)
90-
(name test_server)
91-
(modules test_server)
92-
(libraries
93-
94-
http_lib
95-
httpsvr
96-
safe-resources
97-
threads.posix
98-
xapi-stdext-threads
99-
xapi-stdext-unix
100-
)
101-
)
90+
(modes exe)
91+
(name test_server)
92+
(modules test_server)
93+
(libraries
94+
http_lib
95+
httpsvr
96+
safe-resources
97+
threads.posix
98+
xapi-stdext-threads
99+
xapi-stdext-unix))
102100

103101
(cram
104-
(package xapi)
105-
(deps
106-
test_client.exe
107-
test_server.exe
108-
)
109-
)
102+
(package xapi)
103+
(deps test_client.exe test_server.exe))

ocaml/libs/http-lib/xMLRPC.ml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ let rtte name xml =
2323

2424
type xmlrpc = Xml.xml
2525

26-
let pretty_print = function
27-
| Xml.Element (tag, _, _) ->
26+
let pretty_print : xmlrpc -> string = function
27+
| `El (((_uri, tag), _), _) ->
2828
"Element=" ^ String.escaped tag
29-
| Xml.PCData d ->
29+
| `Data d ->
3030
"PCData=" ^ String.escaped d
3131

3232
type response =
@@ -53,9 +53,9 @@ module FromString = struct
5353
end
5454

5555
module To = struct
56-
let pcdata string = Xml.PCData string
56+
let pcdata string = `Data string
5757

58-
let box tag vs = Xml.Element (tag, [], vs)
58+
let box tag vs = `El ((("", tag), []), vs)
5959

6060
let value v = box "value" [v]
6161

@@ -136,14 +136,14 @@ end
136136
module From = struct
137137
let id x = x
138138

139-
let pcdata f = function
140-
| Xml.PCData string ->
139+
let pcdata f : Xml.xml -> _ = function
140+
| `Data string ->
141141
f string
142142
| xml ->
143143
rtte "pcdata" xml
144144

145-
let unbox ok f = function
146-
| Xml.Element (s, [], data) when List.mem s ok ->
145+
let unbox ok f : Xml.xml -> _ = function
146+
| `El (((_, s), []), data) when List.mem s ok ->
147147
f data
148148
| xml ->
149149
rtte
@@ -177,7 +177,7 @@ module From = struct
177177
let name f xml =
178178
unbox ["name"]
179179
(function
180-
| [Xml.PCData str] ->
180+
| [`Data str] ->
181181
f str
182182
| [] ->
183183
debug "encountered <name/> within a <structure>" ;
@@ -194,7 +194,7 @@ module From = struct
194194

195195
let array f = value (singleton ["array"] (unbox ["data"] (List.map f)))
196196

197-
let boolean = value (singleton ["boolean"] (( <> ) (Xml.PCData "0")))
197+
let boolean = value (singleton ["boolean"] (( <> ) (`Data "0")))
198198

199199
let datetime x =
200200
Clock.Date.of_iso8601 (value (singleton ["dateTime.iso8601"] (pcdata id)) x)
@@ -209,11 +209,11 @@ module From = struct
209209
(unbox ["params"] (List.map (singleton ["param"] id)))
210210
xml
211211

212-
let string = function
213-
| Xml.Element ("value", [], [Xml.PCData s]) ->
212+
let string : Xml.xml -> string = function
213+
| `El ((("", "value"), []), [`Data s]) ->
214214
s
215-
| Xml.Element ("value", [], [Xml.Element ("string", [], [])])
216-
| Xml.Element ("value", [], []) ->
215+
| `El ((("", "value"), []), [`El ((("", "string"), []), [])])
216+
| `El ((("", "value"), []), []) ->
217217
""
218218
| xml ->
219219
value (singleton ["string"] (pcdata id)) xml
@@ -233,7 +233,7 @@ module From = struct
233233
| "Failure" -> (
234234
match array id (List.assoc "ErrorDescription" bindings) with
235235
| [] ->
236-
rtte "Empty array of error strings" (Xml.PCData "")
236+
rtte "Empty array of error strings" (`Data "")
237237
| code :: strings ->
238238
Failure (string code, List.map string strings)
239239
)
@@ -250,14 +250,14 @@ module From = struct
250250
let methodResponse xml =
251251
singleton ["methodResponse"]
252252
(function
253-
| Xml.Element ("params", _, _) as xml -> (
253+
| `El ((("", "params"), _), _) as xml -> (
254254
match success xml with
255255
| [xml] ->
256256
status xml
257257
| _ ->
258258
rtte "Expected single return value (struct status)" xml
259259
)
260-
| Xml.Element ("fault", _, _) as xml ->
260+
| `El ((("", "fault"), _), _) as xml ->
261261
Fault (fault id xml)
262262
| xml ->
263263
rtte "response" xml

0 commit comments

Comments
 (0)