1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452 | ------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2003-2022, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 3, or (at your option) any --
-- later version. This software is distributed in the hope that it will --
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- distributed with this software; see file COPYING3. If not, go --
-- to http://www.gnu.org/licenses for a complete copy of the license. --
------------------------------------------------------------------------------
with Ada.Command_Line;
with Ada.Exceptions;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with GNAT.Command_Line;
with GNAT.Directory_Operations;
with GNAT.OS_Lib;
with GNAT.String_Split;
with AWS.Client;
with AWS.Response;
with SOAP.Name_Space;
with SOAP.WSDL;
with WSDL2AWS.Generator;
with WSDL2AWS.WSDL.Parser;
procedure WSDL2AWS.Main is
use Ada.Exceptions;
use Ada.Strings.Unbounded;
use GNAT;
use AWS;
use type WSDL2AWS.WSDL.Parser.Verbose_Level;
Syntax_Error : exception;
procedure Parse_Command_Line;
-- Parse command line arguments
function Get_Document (URL : Unbounded_String) return Unbounded_String;
-- Get WSDL document pointed to by URL, returns the name of the local
-- filename.
Gen : Generator.Object;
Def : SOAP.WSDL.Object;
Filename : Unbounded_String;
Out_Filename : Unbounded_String;
Proxy : Unbounded_String;
Pu, Pp : Unbounded_String;
Force : Boolean := False;
WSDL_Des : Boolean := False;
Verbose : WSDL2AWS.WSDL.Parser.Verbose_Level := 0;
Gen_CB : Boolean := False;
Types : Boolean := False;
Spec : Boolean := False;
Main : Boolean := False;
------------------
-- Get_Document --
------------------
function Get_Document (URL : Unbounded_String) return Unbounded_String is
use Ada;
L_URL : constant String := To_String (URL);
Filename : Unbounded_String :=
To_Unbounded_String
(Directory_Operations.File_Name (L_URL));
Response : AWS.Response.Data;
File : Text_IO.File_Type;
begin
if Out_Filename /= Null_Unbounded_String then
Filename := Out_Filename;
end if;
-- Check if filename exists and can be overwritten
if OS_Lib.Is_Regular_File (To_String (Filename)) and then not Force then
Exceptions.Raise_Exception
(Constraint_Error'Identity,
"WSDL file " & To_String (Filename)
& " already present, use -f option to overwrite");
end if;
-- Get document
Response := AWS.Client.Get
(L_URL,
Proxy => To_String (Proxy),
Proxy_User => To_String (Pu),
Proxy_Pwd => To_String (Pp));
-- Write WSDL
Text_IO.Create (File, Text_IO.Out_File, To_String (Filename));
Text_IO.Put_Line (File, AWS.Response.Message_Body (Response));
Text_IO.Close (File);
-- Returns the filename
return Filename;
exception
when Text_IO.Name_Error =>
Text_IO.Put_Line ("Can't create file " & To_String (Filename));
raise;
end Get_Document;
------------------------
-- Parse_Command_Line --
------------------------
procedure Parse_Command_Line is
All_Options : Unbounded_String;
begin
-- Get all options
for K in 1 .. Ada.Command_Line.Argument_Count loop
Append (All_Options, Ada.Command_Line.Argument (K));
if K /= Ada.Command_Line.Argument_Count then
Append (All_Options, " ");
end if;
end loop;
Generator.Options (Gen, To_String (All_Options));
-- Now parse arguments
loop
case Command_Line.Getopt
("d q a e: f v s sp o: p: proxy: pu: pp: doc wsdl nostub noskel "
& "x: http2 debug cb traces types: spec: main: n: timeouts: cvs")
is
when ASCII.NUL => exit;
when 'q' =>
Generator.Quiet (Gen);
when 'a' =>
Generator.Ada_Style (Gen);
when 'e' =>
Generator.Endpoint (Gen, GNAT.Command_Line.Parameter);
when 'f' =>
Force := True;
Generator.Overwrite (Gen);
when 'h' =>
if Command_Line.Full_Switch = "http2" then
Generator.HTTP_Version (Gen, HTTPv2);
else
raise Syntax_Error;
end if;
when 'o' =>
Out_Filename
:= To_Unbounded_String (GNAT.Command_Line.Parameter);
when 'd' =>
if Command_Line.Full_Switch = "doc" then
WSDL2AWS.WSDL.Parser.Accept_Document (Gen);
elsif Command_Line.Full_Switch = "d" then
Generator.Disable_Time_Stamp (Gen);
elsif Command_Line.Full_Switch = "debug" then
Generator.Debug (Gen);
else
raise Syntax_Error;
end if;
when 's' =>
if Command_Line.Full_Switch = "spec" then
Generator.Specs_From
(Gen, GNAT.Command_Line.Parameter);
Spec := True;
elsif Command_Line.Full_Switch = "sp" then
Generator.Gen_Safe_Pointer (Gen);
elsif Command_Line.Full_Switch = "s" then
WSDL2AWS.WSDL.Parser.Continue_On_Error;
else
raise Syntax_Error;
end if;
when 'v' =>
Verbose := Verbose + 1;
WSDL2AWS.WSDL.Parser.Verbose (Verbose);
when 'w' =>
if Command_Line.Full_Switch = "wsdl" then
WSDL_Des := True;
else
raise Syntax_Error;
end if;
when 'c' =>
if Command_Line.Full_Switch = "cvs" then
Generator.CVS_Tag (Gen);
elsif Command_Line.Full_Switch = "cb" then
Generator.Gen_CB (Gen);
Gen_CB := True;
else
raise Syntax_Error;
end if;
when 'm' =>
if Command_Line.Full_Switch = "main" then
Generator.Main (Gen, GNAT.Command_Line.Parameter);
Main := True;
else
raise Syntax_Error;
end if;
when 'n' =>
if Command_Line.Full_Switch = "nostub" then
Generator.No_Stub (Gen);
elsif Command_Line.Full_Switch = "noskel" then
Generator.No_Skel (Gen);
elsif Command_Line.Full_Switch = "n" then
SOAP.Name_Space.Set_AWS_NS
(Value => GNAT.Command_Line.Parameter);
else
raise Syntax_Error;
end if;
when 'p' =>
if Command_Line.Full_Switch = "proxy" then
Proxy := To_Unbounded_String (GNAT.Command_Line.Parameter);
elsif Command_Line.Full_Switch = "pu" then
Pu := To_Unbounded_String (GNAT.Command_Line.Parameter);
elsif Command_Line.Full_Switch = "pp" then
Pp := To_Unbounded_String (GNAT.Command_Line.Parameter);
elsif Command_Line.Full_Switch = "p" then
Generator.Set_Prefix
(Gen, GNAT.Command_Line.Parameter);
else
raise Syntax_Error;
end if;
when 't' =>
if Command_Line.Full_Switch = "types" then
Generator.Types_From
(Gen, GNAT.Command_Line.Parameter);
Types := True;
elsif Command_Line.Full_Switch = "timeouts" then
declare
use String_Split;
Timeouts : constant String := GNAT.Command_Line.Parameter;
Slices : String_Split.Slice_Set;
begin
String_Split.Create (Slices, Timeouts, ",");
case String_Split.Slice_Count (Slices) is
when 1 =>
Generator.Set_Timeouts
(Gen,
Client.Timeouts
(Connect => Duration'Value (Slice (Slices, 1)),
Send => Duration'Value (Slice (Slices, 1)),
Receive => Duration'Value
(Slice (Slices, 1))));
when 3 =>
Generator.Set_Timeouts
(Gen,
Client.Timeouts
(Connect => Duration'Value (Slice (Slices, 1)),
Send => Duration'Value (Slice (Slices, 2)),
Receive => Duration'Value
(Slice (Slices, 3))));
when 4 =>
Generator.Set_Timeouts
(Gen,
Client.Timeouts
(Connect => Duration'Value
(Slice (Slices, 1)),
Send => Duration'Value
(Slice (Slices, 2)),
Receive => Duration'Value
(Slice (Slices, 3)),
Response => Duration'Value
(Slice (Slices, 4))));
when others =>
raise Syntax_Error
with "wrong number of arguments for timeouts";
end case;
end;
elsif Command_Line.Full_Switch = "traces" then
Generator.Traces (Gen);
else
raise Syntax_Error;
end if;
when 'x' =>
Generator.Exclude (Gen, GNAT.Command_Line.Parameter);
when others =>
raise Program_Error;
end case;
end loop;
Filename := To_Unbounded_String (Command_Line.Get_Argument);
end Parse_Command_Line;
use Ada.Text_IO;
begin
Parse_Command_Line;
-- Checks parameters
if Proxy = Null_Unbounded_String then
if Pu /= Null_Unbounded_String or else Pp /= Null_Unbounded_String then
Raise_Exception
(Constraint_Error'Identity,
"Proxy user/password specified, but no proxy set.");
end if;
elsif Proxy /= Null_Unbounded_String then
Generator.Set_Proxy
(Gen, To_String (Proxy), To_String (Pu), To_String (Pp));
end if;
if Gen_CB and then not Types and then not Spec then
Raise_Exception
(Constraint_Error'Identity,
"Callback can't be generated if no Ada spec specified");
end if;
if Main and then not Gen_CB then
Raise_Exception
(Constraint_Error'Identity,
"Server main can't be generated if callback not generated.");
end if;
if Filename = Null_Unbounded_String then
-- No file specified
raise Syntax_Error;
elsif Length (Filename) > 7 and then Slice (Filename, 1, 7) = "http://" then
-- This is an URL, retrieve the WSDL document
Filename := Get_Document (Filename);
elsif Out_Filename /= Null_Unbounded_String then
-- Not an URL, file specified, this option is not valid
Raise_Exception
(Constraint_Error'Identity,
"Option -o must be used when parsing a Web document (URL).");
end if;
-- Set WSDL file
if WSDL_Des then
Generator.WSDL_File (Gen, To_String (Filename));
end if;
-- Load WSDL document, return it
Def := SOAP.WSDL.Load (To_String (Filename));
-- Parse the document and generate the code
WSDL2AWS.WSDL.Parser.Parse
(Gen, Def, OS_Lib.Normalize_Pathname (To_String (Filename)));
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Success);
exception
when Syntax_Error | Command_Line.Invalid_Switch =>
New_Line;
Put_Line ("wsdl2aws SOAP Generator v" & Version);
New_Line;
Put_Line ("Usage: wsdl2aws [options] <file|URL>");
Put_Line (" -q Quiet mode");
Put_Line (" -d no date/time stamp in generated sources");
Put_Line (" -debug Generate debug code");
Put_Line (" -a Ada style identifiers");
Put_Line (" -f Force files creation stub/skeleton/types");
Put_Line (" -e URL Endpoint to use");
Put_Line (" -s Skip non supported SOAP routines");
Put_Line (" -o name Output filename for Web Document (URL mode)");
Put_Line (" -p name Name prefix for all SOAPActions");
Put_Line
(" -doc Document style binding handled as RPC");
Put_Line
(" -sp Use legacy safe-pointers for arrays");
Put_Line (" -http2 Use HTTP/2 protocol");
Put_Line (" -v Verbose mode");
Put_Line (" -v -v Very verbose mode");
Put_Line (" -wsdl Add WSDL file in unit comment");
Put_Line (" -cvs Add CVS tag in unit's headers");
Put_Line (" -nostub Do not create stub units");
Put_Line (" -noskel Do not create skeleton units");
Put_Line (" -cb Generate SOAP server callback routine");
Put_Line (" -traces Generate SOAP client callbacks");
Put_Line (" -x operation Exclude operation from code generation");
Put_Line (" -spec spec Use procs/types from Ada spec");
Put_Line (" -types spec Use types from Ada spec");
Put_Line (" -main file Generate SOAP main server's procedure");
Put_Line (" -n name Schema root name (default soapaws)");
Put_Line (" -proxy addr Name or IP of the proxy");
Put_Line (" -pu name The proxy user name");
Put_Line (" -pp pwd The proxy password");
Put_Line (" -timeouts The connect/read/write/response timeouts");
New_Line;
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
when W : SOAP.WSDL.WSDL_Error =>
New_Line;
Put_Line ("Error: " & Exception_Message (W));
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
when E : others =>
New_Line;
Put_Line ("wsdl2aws SOAP Generator v" & Version);
New_Line;
Put_Line ("Error: " & Exception_Information (E));
New_Line;
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
end WSDL2AWS.Main;
|