comparison GEMBASSY-1.0.3/gsoap/wsdl/wsdl2h.cpp @ 0:8300eb051bea draft

Initial upload
author ktnyt
date Fri, 26 Jun 2015 05:19:29 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8300eb051bea
1 /*
2 wsdl2h.cpp
3
4 WSDL parser, translator, and generator (of the gSOAP header file format)
5
6 --------------------------------------------------------------------------------
7 gSOAP XML Web services tools
8 Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc. All Rights Reserved.
9 This software is released under one of the following licenses:
10 GPL or Genivia's license for commercial use.
11 --------------------------------------------------------------------------------
12 GPL license.
13
14 This program is free software; you can redistribute it and/or modify it under
15 the terms of the GNU General Public License as published by the Free Software
16 Foundation; either version 2 of the License, or (at your option) any later
17 version.
18
19 This program is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 PARTICULAR PURPOSE. See the GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
25 Place, Suite 330, Boston, MA 02111-1307 USA
26
27 Author contact information:
28 engelen@genivia.com / engelen@acm.org
29 --------------------------------------------------------------------------------
30 A commercial use license is available from Genivia, Inc., contact@genivia.com
31 --------------------------------------------------------------------------------
32
33 Build:
34 soapcpp2 -ipwsdl wsdl.h
35 g++ -o wsdl2h wsdl2h.cpp types.cpp service.cpp wsdl.cpp schema.cpp wsdlC.cpp stdsoap2.cpp
36
37 TODO:
38 Resolve relative versus absolute import paths for reading imported WSDL/schema (use URL local addresses)
39 Do not generate abstract complexTypes, but include defs in derived types
40 Handle simpleType derivation from base64
41
42 */
43
44 #include "includes.h"
45 #include "types.h"
46 #include "service.h"
47
48 #ifndef WSDL2H_IMPORT_PATH
49 #define WSDL2H_IMPORT_PATH (NULL)
50 #endif
51
52 #ifndef WSDL_TYPEMAP_FILE
53 #define WSDL_TYPEMAP_FILE "typemap.dat"
54 #endif
55
56 static void init();
57 static void options(int argc, char **argv);
58
59 int _flag = 0,
60 aflag = 0,
61 bflag = 0,
62 cflag = 0,
63 dflag = 0,
64 eflag = 0,
65 fflag = 0,
66 gflag = 0,
67 iflag = 0,
68 jflag = 0,
69 kflag = 0,
70 mflag = 0,
71 pflag = 0,
72 Pflag = 0,
73 Rflag = 0,
74 sflag = 0,
75 uflag = 0,
76 vflag = 0,
77 wflag = 0,
78 Wflag = 0,
79 xflag = 0,
80 yflag = 0,
81 zflag = 0;
82
83 int infiles = 0;
84 char *infile[MAXINFILES],
85 *outfile = NULL,
86 *proxy_host = NULL,
87 *proxy_userid = NULL,
88 *proxy_passwd = NULL,
89 *auth_userid = NULL,
90 *auth_passwd = NULL;
91 const char
92 *mapfile = WSDL_TYPEMAP_FILE,
93 *import_path = WSDL2H_IMPORT_PATH,
94 *cwd_path = NULL,
95 *cppnamespace = NULL;
96
97 int proxy_port = 8080;
98
99 FILE *stream = stdout;
100
101 SetOfString exturis;
102
103 extern struct Namespace namespaces[];
104
105 const char *service_prefix = NULL;
106 const char *schema_prefix = "ns";
107
108 const char elementformat[] = " %-35s %-30s";
109 const char pointerformat[] = " %-35s *%-30s";
110 const char attributeformat[] = " @%-35s %-30s";
111 const char vectorformat[] = " std::vector<%-23s> %-30s";
112 const char pointervectorformat[] = " std::vector<%-22s> *%-30s";
113 const char vectorformat_open[] = " std::vector<%s";
114 const char arrayformat[] = " %-35s *__ptr%-25s";
115 const char arraysizeformat[] = " %-35s __size%-24s";
116 const char arrayoffsetformat[] = "// %-35s __offset%-22s";
117 const char sizeformat[] = " $%-35s __size%-24s";
118 const char choiceformat[] = " $%-35s __union%-23s";
119 const char schemaformat[] = "//gsoap %-5s schema %s:\t%s\n";
120 const char serviceformat[] = "//gsoap %-4s service %s:\t%s %s\n";
121 const char paraformat[] = " %-35s%s%s%s";
122 const char anonformat[] = " %-35s%s_%s%s";
123
124 const char copyrightnotice[] = "\n** The gSOAP WSDL/Schema processor for C and C++, wsdl2h release " WSDL2H_VERSION "\n** Copyright (C) 2000-2013 Robert van Engelen, Genivia Inc.\n** All Rights Reserved. This product is provided \"as is\", without any warranty.\n** The wsdl2h tool is released under one of the following licenses:\n** GPL or the commercial license by Genivia Inc. Use option -l for details.\n\n";
125
126 const char licensenotice[] = "\
127 --------------------------------------------------------------------------------\n\
128 gSOAP XML Web services tools\n\
129 Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc. All Rights Reserved.\n\
130 \n\
131 This software is released under one of the following licenses:\n\
132 GPL or Genivia's license for commercial use.\n\
133 --------------------------------------------------------------------------------\n\
134 GPL license.\n\
135 \n\
136 This program is free software; you can redistribute it and/or modify it under\n\
137 the terms of the GNU General Public License as published by the Free Software\n\
138 Foundation; either version 2 of the License, or (at your option) any later\n\
139 version.\n\
140 \n\
141 This program is distributed in the hope that it will be useful, but WITHOUT ANY\n\
142 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\n\
143 PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\
144 \n\
145 You should have received a copy of the GNU General Public License along with\n\
146 this program; if not, write to the Free Software Foundation, Inc., 59 Temple\n\
147 Place, Suite 330, Boston, MA 02111-1307 USA\n\
148 \n\
149 Author contact information:\n\
150 engelen@genivia.com / engelen@acm.org\n\
151 \n\
152 This program is released under the GPL with the additional exemption that\n\
153 compiling, linking, and/or using OpenSSL is allowed.\n\
154 --------------------------------------------------------------------------------\n\
155 A commercial-use license is available from Genivia, Inc., contact@genivia.com\n\
156 --------------------------------------------------------------------------------\n";
157
158 int main(int argc, char **argv)
159 { init();
160 fprintf(stderr, "%s", copyrightnotice);
161 options(argc, argv);
162 Definitions def;
163 wsdl__definitions definitions;
164 definitions.read(infiles, infile);
165 if (definitions.error())
166 { definitions.print_fault();
167 exit(1);
168 }
169 definitions.traverse();
170 def.compile(definitions);
171 if (outfile)
172 { fclose(stream);
173 fprintf(stderr, "\nTo complete the process, compile with:\n> soapcpp2 %s\n", outfile);
174 if (!cflag)
175 fprintf(stderr, "or to generate C++ proxy and object classes:\n> soapcpp2 -j %s\n", outfile);
176 fprintf(stderr, "\n");
177 }
178 return 0;
179 }
180
181 ////////////////////////////////////////////////////////////////////////////////
182 //
183 // Initialization
184 //
185 ////////////////////////////////////////////////////////////////////////////////
186
187 static void init()
188 { struct Namespace *p = namespaces;
189 if (p)
190 { for (; p->id; p++)
191 { if (p->in && *p->in)
192 exturis.insert(p->in);
193 if (p->ns && *p->ns)
194 exturis.insert(p->ns);
195 }
196 }
197 }
198
199 ////////////////////////////////////////////////////////////////////////////////
200 //
201 // Parse command line options
202 //
203 ////////////////////////////////////////////////////////////////////////////////
204
205 static void options(int argc, char **argv)
206 { int i;
207 infiles = 0;
208 for (i = 1; i < argc; i++)
209 { char *a = argv[i];
210 if (*a == '-'
211 #ifdef WIN32
212 || *a == '/'
213 #endif
214 )
215 { int g = 1;
216 while (g && *++a)
217 { switch (*a)
218 { case '_':
219 _flag = 1;
220 break;
221 case 'a':
222 aflag = 1;
223 break;
224 case 'b':
225 bflag = 1;
226 break;
227 case 'c':
228 cflag = 1;
229 if (cppnamespace)
230 fprintf(stderr, "wsdl2h: Options -c and -q clash\n");
231 break;
232 case 'd':
233 dflag = 1;
234 break;
235 case 'e':
236 eflag = 1;
237 break;
238 case 'f':
239 fflag = 1;
240 break;
241 case 'g':
242 gflag = 1;
243 break;
244 case 'i':
245 iflag = 1;
246 break;
247 case 'j':
248 jflag = 1;
249 break;
250 case 'k':
251 kflag = 1;
252 break;
253 case 'I':
254 a++;
255 g = 0;
256 if (*a)
257 import_path = a;
258 else if (i < argc && argv[++i])
259 import_path = argv[i];
260 else
261 fprintf(stderr, "wsdl2h: Option -I requires a path argument\n");
262 break;
263 case 'l':
264 fprintf(stderr, "%s", licensenotice);
265 exit(0);
266 break;
267 case 'm':
268 mflag = 1;
269 break;
270 case 'n':
271 a++;
272 g = 0;
273 if (*a)
274 schema_prefix = a;
275 else if (i < argc && argv[++i])
276 schema_prefix = argv[i];
277 else
278 fprintf(stderr, "wsdl2h: Option -n requires a prefix name argument\n");
279 break;
280 case 'N':
281 a++;
282 g = 0;
283 if (*a)
284 service_prefix = a;
285 else if (i < argc && argv[++i])
286 service_prefix = argv[i];
287 else
288 fprintf(stderr, "wsdl2h: Option -N requires a prefix name argument\n");
289 break;
290 case 'o':
291 a++;
292 g = 0;
293 if (*a)
294 outfile = a;
295 else if (i < argc && argv[++i])
296 outfile = argv[i];
297 else
298 fprintf(stderr, "wsdl2h: Option -o requires an output file argument\n");
299 break;
300 case 'p':
301 pflag = 1;
302 break;
303 case 'P':
304 Pflag = 1;
305 break;
306 case 'q':
307 a++;
308 g = 0;
309 if (*a)
310 cppnamespace = a;
311 else if (i < argc && argv[++i])
312 cppnamespace = argv[i];
313 else
314 fprintf(stderr, "wsdl2h: Option -q requires a C++ namespace name argument\n");
315 if (cflag)
316 fprintf(stderr, "wsdl2h: Options -c and -q clash\n");
317 break;
318 case 'r':
319 a++;
320 g = 0;
321 if (*a)
322 proxy_host = a;
323 else if (i < argc && argv[++i])
324 proxy_host = argv[i];
325 else
326 fprintf(stderr, "wsdl2h: Option -r requires proxy host:port:userid:passwd or :userid:passwd authentication argument\n");
327 if (proxy_host)
328 { char *s = (char*)emalloc(strlen(proxy_host + 1));
329 strcpy(s, proxy_host);
330 proxy_host = s;
331 s = strchr(proxy_host, ':');
332 if (s)
333 { *s = '\0';
334 if (*proxy_host)
335 { proxy_port = soap_strtol(s + 1, &s, 10);
336 if (s && *s == ':')
337 { *s = '\0';
338 proxy_userid = s + 1;
339 s = strchr(proxy_userid, ':');
340 if (s && *s == ':')
341 { *s = '\0';
342 proxy_passwd = s + 1;
343 }
344 }
345 }
346 else
347 { s = proxy_host;
348 proxy_host = NULL;
349 auth_userid = s + 1;
350 s = strchr(auth_userid, ':');
351 if (s && *s == ':')
352 { *s = '\0';
353 auth_passwd = s + 1;
354 }
355 }
356 }
357 }
358 break;
359 case 'R':
360 Rflag = 1;
361 break;
362 case 's':
363 sflag = 1;
364 break;
365 case 't':
366 a++;
367 g = 0;
368 if (*a)
369 mapfile = a;
370 else if (i < argc && argv[++i])
371 mapfile = argv[i];
372 else
373 fprintf(stderr, "wsdl2h: Option -t requires a type map file argument\n");
374 break;
375 case 'u':
376 uflag = 1;
377 break;
378 case 'v':
379 vflag = 1;
380 break;
381 case 'w':
382 wflag = 1;
383 break;
384 case 'W':
385 Wflag = 1;
386 break;
387 case 'x':
388 xflag = 1;
389 break;
390 case 'y':
391 yflag = 1;
392 break;
393 case 'z':
394 a++;
395 g = 0;
396 if (*a)
397 zflag = soap_strtol(a, NULL, 10);
398 else if (i < argc && argv[++i])
399 zflag = soap_strtol(argv[i], NULL, 10);
400 else
401 zflag = 1;
402 break;
403 case '?':
404 case 'h':
405 fprintf(stderr, "Usage: wsdl2h [-a] [-b] [-c] [-d] [-e] [-f] [-g] [-h] [-I path] [-i] [-j] [-k] [-l] [-m] [-N name] [-n name] [-P|-p] [-q name] [-R] [-r proxyhost[:port[:uid:pwd]]] [-r:userid:passwd] [-s] [-t typemapfile] [-u] [-v] [-w] [-W] [-x] [-y] [-z#] [-_] [-o outfile.h] infile.wsdl infile.xsd http://www... ...\n\n");
406 fprintf(stderr, "\
407 -a generate indexed struct names for local elements with anonymous types\n\
408 -b bi-directional operations (duplex ops) added to serve one-way responses\n\
409 -c generate C source code\n\
410 -d use DOM to populate xs:any, xs:anyType, and xs:anyAttribute\n\
411 -e don't qualify enum names\n\
412 -f generate flat C++ class hierarchy\n\
413 -g generate global top-level element declarations\n\
414 -h display help info\n\
415 -Ipath use path to find files\n\
416 -i don't import (advanced option)\n\
417 -j don't generate SOAP_ENV__Header and SOAP_ENV__Detail definitions\n\
418 -k don't generate SOAP_ENV__Header mustUnderstand qualifiers\n\
419 -l display license information\n\
420 -m use xsd.h module to import primitive types\n\
421 -Nname use name for service prefixes to produce a service for each binding\n\
422 -nname use name as the base namespace prefix instead of 'ns'\n\
423 -ofile output to file\n\
424 -P don't create polymorphic types inherited from xsd__anyType\n\
425 -p create polymorphic types inherited from base xsd__anyType\n\
426 -qname use name for the C++ namespace of all declarations\n\
427 -R generate REST operations for REST bindings in the WSDL\n\
428 -rhost[:port[:uid:pwd]]\n\
429 connect via proxy host, port, and proxy credentials\n\
430 -r:uid:pwd\n\
431 connect with authentication credentials (digest auth requires SSL)\n\
432 -s don't generate STL code (no std::string and no std::vector)\n\
433 -tfile use type map file instead of the default file typemap.dat\n\
434 -u don't generate unions\n\
435 -v verbose output\n\
436 -W suppress warnings\n\
437 -w always wrap response parameters in a response struct (<=1.1.4 behavior)\n\
438 -x don't generate _XML any/anyAttribute extensibility elements\n\
439 -y generate typedef synonyms for structs and enums\n\
440 -z1 compatibility with 2.7.6e: generate pointer-based arrays\n\
441 -z2 compatibility with 2.7.7 to 2.7.15: qualify element/attribute references\n\
442 -z3 compatibility with 2.7.16 to 2.8.7: qualify element/attribute references\n\
443 -z4 compatibility up to 2.8.11: don't generate union structs in std::vector\n\
444 -z5 compatibility up to 2.8.15\n\
445 -_ don't generate _USCORE (replace with UNICODE _x005f)\n\
446 infile.wsdl infile.xsd http://www... list of input sources (if none: use stdin)\n\
447 \n");
448 exit(0);
449 default:
450 fprintf(stderr, "wsdl2h: Unknown option %s\n", a);
451 exit(1);
452 }
453 }
454 }
455 else
456 { infile[infiles++] = argv[i];
457 if (infiles >= MAXINFILES)
458 { fprintf(stderr, "wsdl2h: too many files\n");
459 exit(1);
460 }
461 }
462 }
463 if (infiles)
464 { if (!outfile)
465 { if (strncmp(infile[0], "http://", 7) && strncmp(infile[0], "https://", 8))
466 { const char *s = strrchr(infile[0], '.');
467 if (s && (!soap_tag_cmp(s, ".wsdl") || !soap_tag_cmp(s, ".gwsdl") || !soap_tag_cmp(s, ".xsd")))
468 { outfile = estrdup(infile[0]);
469 outfile[s - infile[0] + 1] = 'h';
470 outfile[s - infile[0] + 2] = '\0';
471 }
472 else
473 { outfile = (char*)emalloc(strlen(infile[0]) + 3);
474 strcpy(outfile, infile[0]);
475 strcat(outfile, ".h");
476 }
477 }
478 }
479 if (outfile)
480 { stream = fopen(outfile, "w");
481 if (!stream)
482 { fprintf(stderr, "Cannot write to %s\n", outfile);
483 exit(1);
484 }
485 if (cppnamespace)
486 fprintf(stream, "namespace %s {\n", cppnamespace);
487 fprintf(stderr, "Saving %s\n\n", outfile);
488 }
489 }
490 }
491
492 ////////////////////////////////////////////////////////////////////////////////
493 //
494 // Namespaces
495 //
496 ////////////////////////////////////////////////////////////////////////////////
497
498 struct Namespace namespaces[] =
499 {
500 {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope"},
501 {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding"},
502 {"xsi", "http://www.w3.org/2001/XMLSchema-instance"},
503 {"xsd", "-"}, // http://www.w3.org/2001/XMLSchema"}, // don't use this, it might conflict with xs
504 {"xml", "http://www.w3.org/XML/1998/namespace"},
505 {"xs", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema" },
506 {"http", "http://schemas.xmlsoap.org/wsdl/http/"},
507 {"soap", "http://schemas.xmlsoap.org/wsdl/soap/", "http://schemas.xmlsoap.org/wsdl/soap*/"},
508 {"mime", "http://schemas.xmlsoap.org/wsdl/mime/"},
509 {"xmime", "http://www.w3.org/2005/05/xmlmime"},
510 {"dime", "http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/", "http://schemas.xmlsoap.org/ws/*/dime/wsdl/"},
511 {"sp", "http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702", "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"},
512 {"wsdl", "http://schemas.xmlsoap.org/wsdl/", "http://www.w3.org/ns/wsdl"},
513 {"wsdli", "http://www.w3.org/ns/wsdl-instance"},
514 {"wsdlx", "http://www.w3.org/ns/wsdl-extensions"},
515 {"wsoap", "http://www.w3.org/ns/wsdl/soap"},
516 {"whttp", "http://www.w3.org/ns/wsdl/http"},
517 {"wrpc", "http://www.w3.org/ns/wsdl/rpc"},
518 {"wsa_", "http://www.w3.org/2005/08/addressing"},
519 {"wsaw", "http://www.w3.org/2006/05/addressing/wsdl"},
520 {"wsam", "http://www.w3.org/2007/05/addressing/metadata"},
521 {"wsrmp", "http://schemas.xmlsoap.org/ws/2005/02/rm/policy", "http://docs.oasis-open.org/ws-rx/wsrmp/*"},
522 {"wsp", "http://www.w3.org/ns/ws-policy", "http://schemas.xmlsoap.org/ws/2004/09/policy"},
523 {"wst", "http://docs.oasis-open.org/ws-sx/ws-trust/200512"},
524 {"wsu_", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"},
525 {"gwsdl", "http://www.gridforum.org/namespaces/2003/03/gridWSDLExtensions"},
526 {NULL, NULL}
527 };