~vcs-imports/simias/trunk

« back to all changes in this revision

Viewing changes to simias/tools/gsoap/gsoap-linux-2.7/wsdl/wsdl2h.cpp

  • Committer: kalidasbala
  • Date: 2007-08-25 12:48:51 UTC
  • Revision ID: vcs-imports@canonical.com-20070825124851-vlfvzun3732ld196
Latest gsoap code update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
wsdl2h.cpp
 
4
 
 
5
WSDL parser and converter to gSOAP header file format
 
6
 
 
7
--------------------------------------------------------------------------------
 
8
gSOAP XML Web services tools
 
9
Copyright (C) 2000-2007, Robert van Engelen, Genivia Inc. All Rights Reserved.
 
10
This software is released under one of the following two licenses:
 
11
GPL or Genivia's license for commercial use.
 
12
--------------------------------------------------------------------------------
 
13
GPL license.
 
14
 
 
15
This program is free software; you can redistribute it and/or modify it under
 
16
the terms of the GNU General Public License as published by the Free Software
 
17
Foundation; either version 2 of the License, or (at your option) any later
 
18
version.
 
19
 
 
20
This program is distributed in the hope that it will be useful, but WITHOUT ANY
 
21
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 
22
PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
23
 
 
24
You should have received a copy of the GNU General Public License along with
 
25
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
26
Place, Suite 330, Boston, MA 02111-1307 USA
 
27
 
 
28
Author contact information:
 
29
engelen@genivia.com / engelen@acm.org
 
30
--------------------------------------------------------------------------------
 
31
A commercial use license is available from Genivia, Inc., contact@genivia.com
 
32
--------------------------------------------------------------------------------
 
33
 
 
34
Build:
 
35
        soapcpp2 -ipwsdl wsdl.h
 
36
        g++ -o wsdl2h wsdl2h.cpp types.cpp service.cpp wsdl.cpp schema.cpp wsdlC.cpp stdsoap2.cpp
 
37
        
 
38
TODO:
 
39
        Resolve relative versus absolute import paths for reading imported WSDL/schema (use URL local addresses)
 
40
        Do not generate abstract complexTypes, but include defs in derived types
 
41
        Handle simpleType derivation from base64
 
42
 
 
43
*/
 
44
 
 
45
#include "includes.h"
 
46
#include "types.h"
 
47
#include "service.h"
 
48
 
 
49
static void init();
 
50
static void options(int argc, char **argv);
 
51
 
 
52
int _flag = 0,
 
53
    aflag = 0,
 
54
    cflag = 0,
 
55
    dflag = 0,
 
56
    eflag = 0,
 
57
    fflag = 0,
 
58
    gflag = 0,
 
59
    iflag = 0,
 
60
    jflag = 0,
 
61
    lflag = 0,
 
62
    mflag = 0,
 
63
    pflag = 0,
 
64
    sflag = 0,
 
65
    uflag = 0,
 
66
    vflag = 0,
 
67
    wflag = 0,
 
68
    xflag = 0,
 
69
    yflag = 0,
 
70
    zflag = 0;
 
71
 
 
72
int infiles = 0;
 
73
char *infile[MAXINFILES],
 
74
     *outfile = NULL,
 
75
     *proxy_host = NULL;
 
76
extern const char
 
77
     *mapfile = "typemap.dat",
 
78
     *import_path = NULL,
 
79
     *cwd_path = NULL,
 
80
     *cppnamespace = NULL;
 
81
 
 
82
int proxy_port = 8080;
 
83
 
 
84
FILE *stream = stdout;
 
85
 
 
86
SetOfString exturis;
 
87
 
 
88
extern struct Namespace namespaces[];
 
89
 
 
90
const char *service_prefix = NULL;
 
91
const char *schema_prefix = "ns";
 
92
 
 
93
char elementformat[]       = "    %-35s  %-30s";
 
94
char pointerformat[]       = "    %-35s *%-30s";
 
95
char attributeformat[]     = "   @%-35s  %-30s";
 
96
char vectorformat[]        = "    std::vector<%-23s> %-30s";
 
97
char pointervectorformat[] = "    std::vector<%-22s> *%-30s";
 
98
char arrayformat[]         = "    %-35s *__ptr%-25s";
 
99
char sizeformat[]          = "    %-35s  __size%-24s";
 
100
char offsetformat[]        = "//  %-35s  __offset%-22s";
 
101
char choiceformat[]        = "    %-35s  __union%-23s";
 
102
char schemaformat[]        = "//gsoap %-5s schema %s:\t%s\n";
 
103
char serviceformat[]       = "//gsoap %-4s service %s:\t%s %s\n";
 
104
char paraformat[]          = "    %-35s%s%s%s";
 
105
char anonformat[]          = "    %-35s%s_%s%s";
 
106
 
 
107
char copyrightnotice[] = "\n**  The gSOAP WSDL parser for C and C++ "VERSION"\n**  Copyright (C) 2000-2007 Robert van Engelen, Genivia Inc.\n**  All Rights Reserved. This product is provided \"as is\", without any warranty.\n**  The gSOAP WSDL parser is released under one of the following two licenses:\n**  GPL or the commercial license by Genivia Inc. Use option -l for more info.\n\n";
 
108
 
 
109
char licensenotice[]   = "\
 
110
--------------------------------------------------------------------------------\n\
 
111
gSOAP XML Web services tools\n\
 
112
Copyright (C) 2000-2007, Robert van Engelen, Genivia Inc. All Rights Reserved.\n\
 
113
\n\
 
114
This software is released under one of the following two licenses:\n\
 
115
GPL or Genivia's license for commercial use.\n\
 
116
\n\
 
117
GPL license.\n\
 
118
\n\
 
119
This program is free software; you can redistribute it and/or modify it under\n\
 
120
the terms of the GNU General Public License as published by the Free Software\n\
 
121
Foundation; either version 2 of the License, or (at your option) any later\n\
 
122
version.\n\
 
123
\n\
 
124
This program is distributed in the hope that it will be useful, but WITHOUT ANY\n\
 
125
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\n\
 
126
PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\
 
127
\n\
 
128
You should have received a copy of the GNU General Public License along with\n\
 
129
this program; if not, write to the Free Software Foundation, Inc., 59 Temple\n\
 
130
Place, Suite 330, Boston, MA 02111-1307 USA\n\
 
131
\n\
 
132
Author contact information:\n\
 
133
engelen@genivia.com / engelen@acm.org\n\
 
134
--------------------------------------------------------------------------------\n\
 
135
A commercial use license is available from Genivia, Inc., contact@genivia.com\n\
 
136
--------------------------------------------------------------------------------\n";
 
137
 
 
138
int main(int argc, char **argv)
 
139
{ init();
 
140
  fprintf(stderr, copyrightnotice);
 
141
  options(argc, argv);
 
142
  if (lflag)
 
143
  { fprintf(stderr, licensenotice);
 
144
    if (!infiles)
 
145
      exit(0);
 
146
  }
 
147
  Definitions def;
 
148
  wsdl__definitions definitions;
 
149
  definitions.read(infiles, infile);
 
150
  if (definitions.error())
 
151
  { definitions.print_fault();
 
152
    exit(1);
 
153
  }
 
154
  definitions.traverse();
 
155
  def.compile(definitions);
 
156
  if (outfile)
 
157
  { fclose(stream);
 
158
    fprintf(stderr, "\nTo complete the process, compile with:\nsoapcpp2 %s\n\n", outfile);
 
159
  }
 
160
  return 0;
 
161
}
 
162
 
 
163
////////////////////////////////////////////////////////////////////////////////
 
164
//
 
165
//      Initialization
 
166
//
 
167
////////////////////////////////////////////////////////////////////////////////
 
168
 
 
169
static void init()
 
170
{ struct Namespace *p = namespaces;
 
171
  if (p)
 
172
  { for (; p->id; p++)
 
173
    { if (p->in && *p->in)
 
174
        exturis.insert(p->in);
 
175
      if (p->ns && *p->ns)
 
176
        exturis.insert(p->ns);
 
177
    }
 
178
  }
 
179
}
 
180
 
 
181
////////////////////////////////////////////////////////////////////////////////
 
182
//
 
183
//      Parse command line options
 
184
//
 
185
////////////////////////////////////////////////////////////////////////////////
 
186
 
 
187
static void options(int argc, char **argv)
 
188
{ int i;
 
189
  infiles = 0;
 
190
  for (i = 1; i < argc; i++)
 
191
  { char *a = argv[i];
 
192
    if (*a == '-'
 
193
#ifdef WIN32
 
194
     || *a == '/'
 
195
#endif
 
196
    )
 
197
    { int g = 1;
 
198
      while (g && *++a)
 
199
      { switch (*a)
 
200
        { case '_':
 
201
            _flag = 1;
 
202
            break;
 
203
          case 'a':
 
204
            aflag = 1;
 
205
            break;
 
206
          case 'c':
 
207
            cflag = 1;
 
208
            if (cppnamespace)
 
209
              fprintf(stderr, "wsdl2h: Options -c and -q clash\n");
 
210
            break;
 
211
          case 'd':
 
212
            dflag = 1;
 
213
            break;
 
214
          case 'e':
 
215
            eflag = 1;
 
216
            break;
 
217
          case 'f':
 
218
            fflag = 1;
 
219
            break;
 
220
          case 'g':
 
221
            gflag = 1;
 
222
            break;
 
223
          case 'i':
 
224
            iflag = 1;
 
225
            break;
 
226
          case 'j':
 
227
            jflag = 1;
 
228
            break;
 
229
          case 'I':
 
230
            a++;
 
231
            g = 0;
 
232
            if (*a)
 
233
              import_path = a;
 
234
            else if (i < argc && argv[++i])
 
235
              import_path = argv[i];
 
236
            else
 
237
              fprintf(stderr, "wsdl2h: Option -I requires a path argument\n");
 
238
            break;
 
239
          case 'l':
 
240
            lflag = 1;
 
241
            break;
 
242
          case 'm':
 
243
            mflag = 1;
 
244
            break;
 
245
          case 'n':
 
246
            a++;
 
247
            g = 0;
 
248
            if (*a)
 
249
              schema_prefix = a;
 
250
            else if (i < argc && argv[++i])
 
251
              schema_prefix = argv[i];
 
252
            else
 
253
              fprintf(stderr, "wsdl2h: Option -n requires a prefix name argument\n");
 
254
            break;
 
255
          case 'N':
 
256
            a++;
 
257
            g = 0;
 
258
            if (*a)
 
259
              service_prefix = a;
 
260
            else if (i < argc && argv[++i])
 
261
              service_prefix = argv[i];
 
262
            else
 
263
              fprintf(stderr, "wsdl2h: Option -N requires a prefix name argument\n");
 
264
            break;
 
265
          case 'o':
 
266
            a++;
 
267
            g = 0;
 
268
            if (*a)
 
269
              outfile = a;
 
270
            else if (i < argc && argv[++i])
 
271
              outfile = argv[i];
 
272
            else
 
273
              fprintf(stderr, "wsdl2h: Option -o requires an output file argument\n");
 
274
            break;
 
275
          case 'p':
 
276
            pflag = 1;
 
277
            break;
 
278
          case 'q':
 
279
            a++;
 
280
            g = 0;
 
281
            if (*a)
 
282
              cppnamespace = a;
 
283
            else if (i < argc && argv[++i])
 
284
              cppnamespace = argv[i];
 
285
            else
 
286
              fprintf(stderr, "wsdl2h: Option -q requires a C++ namespace name argument\n");
 
287
            if (cflag)
 
288
              fprintf(stderr, "wsdl2h: Options -c and -q clash\n");
 
289
            break;
 
290
          case 'r':
 
291
            a++;
 
292
            g = 0;
 
293
            if (*a)
 
294
              proxy_host = a;
 
295
            else if (i < argc && argv[++i])
 
296
              proxy_host = argv[i];
 
297
            else
 
298
              fprintf(stderr, "wsdl2h: Option -r requires a proxy host:port argument\n");
 
299
            if (proxy_host)
 
300
            { char *s = (char*)emalloc(strlen(proxy_host + 1));
 
301
              strcpy(s, proxy_host);
 
302
              proxy_host = s;
 
303
              s = strchr(proxy_host, ':');
 
304
              if (s)
 
305
              { proxy_port = soap_strtol(s + 1, NULL, 10);
 
306
                *s = '\0';
 
307
              }
 
308
            }
 
309
            break;
 
310
          case 's':
 
311
            sflag = 1;
 
312
            break;
 
313
          case 't':
 
314
            a++;
 
315
            g = 0;
 
316
            if (*a)
 
317
              mapfile = a;
 
318
            else if (i < argc && argv[++i])
 
319
              mapfile = argv[i];
 
320
            else
 
321
              fprintf(stderr, "wsdl2h: Option -t requires a type map file argument\n");
 
322
            break;
 
323
          case 'u':
 
324
            uflag = 1;
 
325
            break;
 
326
          case 'v':
 
327
            vflag = 1;
 
328
            break;
 
329
          case 'w':
 
330
            wflag = 1;
 
331
            break;
 
332
          case 'x':
 
333
            xflag = 1;
 
334
            break;
 
335
          case 'y':
 
336
            yflag = 1;
 
337
            break;
 
338
          case 'z':
 
339
            zflag = 1;
 
340
            break;
 
341
          case '?':
 
342
          case 'h':
 
343
            fprintf(stderr, "Usage: wsdl2h [-a] [-c] [-d] [-e] [-f] [-g] [-h] [-I path] [-j] [-l] [-m] [-n name] [-N name] [-p] [-q name] [-r proxyhost:port] [-s] [-t typemapfile.dat] [-u] [-v] [-w] [-x] [-y] [-z] [-_] [-o outfile.h] infile.wsdl infile.xsd http://www... ...\n\n");
 
344
            fprintf(stderr, "\
 
345
-a      generate indexed struct names for local elements with anonymous types\n\
 
346
-c      generate C source code\n\
 
347
-d      use DOM to populate xs:any and xsd:anyType elements\n\
 
348
-e      don't qualify enum names\n\
 
349
-f      generate flat C++ class hierarchy\n\
 
350
-g      generate global top-level element declarations\n\
 
351
-h      display help info\n\
 
352
-Ipath  use path to find files\n\
 
353
-j      don't generate SOAP_ENV__Header and SOAP_ENV__Detail definitions\n\
 
354
-l      include license information in output\n\
 
355
-m      use xsd.h module to import primitive types\n\
 
356
-nname  use name as the base namespace prefix instead of 'ns'\n\
 
357
-Nname  use name as the base namespace prefix for service namespaces\n\
 
358
-ofile  output to file\n\
 
359
-p      create polymorphic types with C++ inheritance with base xsd__anyType\n\
 
360
-qname  use name for the C++ namespace for all service declarations\n\
 
361
-rhost:port\n\
 
362
        connect via proxy host and port\n\
 
363
-s      don't generate STL code (no std::string and no std::vector)\n\
 
364
-tfile  use type map file instead of the default file typemap.dat\n\
 
365
-u      don't generate unions\n\
 
366
-v      verbose output\n\
 
367
-w      always wrap response parameters in a response struct (<=1.1.4 behavior)\n\
 
368
-x      don't generate _XML any/anyAttribute extensibility elements\n\
 
369
-y      generate typedef synonyms for structs and enums\n\
 
370
-z      generate pointer-based arrays for backward compatibility < gSOAP 2.7.6e\n\
 
371
-_      don't generate _USCORE (replace with UNICODE _x005f)\n\
 
372
infile.wsdl infile.xsd http://www... list of input sources (if none: use stdin)\n\
 
373
\n");
 
374
            exit(0);
 
375
          default:
 
376
            fprintf(stderr, "wsdl2h: Unknown option %s\n", a);
 
377
            exit(1);
 
378
        }
 
379
      }
 
380
    }
 
381
    else
 
382
    { infile[infiles++] = argv[i];
 
383
      if (infiles >= MAXINFILES)
 
384
      { fprintf(stderr, "wsdl2h: too many files\n");
 
385
        exit(1);
 
386
      }
 
387
    }
 
388
  }
 
389
  if (infiles)
 
390
  { if (!outfile)
 
391
    { if (strncmp(infile[0], "http://", 7) && strncmp(infile[0], "https://", 8))
 
392
      { const char *s = strrchr(infile[0], '.');
 
393
        if (s && (!strcmp(s, ".wsdl") || !strcmp(s, ".gwsdl") || !strcmp(s, ".xsd")))
 
394
        { outfile = estrdup(infile[0]);
 
395
          outfile[s - infile[0] + 1] = 'h';
 
396
          outfile[s - infile[0] + 2] = '\0';
 
397
        }
 
398
        else
 
399
        { outfile = (char*)emalloc(strlen(infile[0]) + 3);
 
400
          strcpy(outfile, infile[0]);
 
401
          strcat(outfile, ".h");
 
402
        }
 
403
      }
 
404
    }
 
405
    if (outfile)
 
406
    { stream = fopen(outfile, "w");
 
407
      if (!stream)
 
408
      { fprintf(stderr, "Cannot write to %s\n", outfile);
 
409
        exit(1);
 
410
      }
 
411
      if (cppnamespace)
 
412
        fprintf(stream, "namespace %s {\n", cppnamespace);
 
413
      fprintf(stderr, "Saving %s\n\n", outfile);
 
414
    }
 
415
  }
 
416
}
 
417
 
 
418
////////////////////////////////////////////////////////////////////////////////
 
419
//
 
420
//      Namespaces
 
421
//
 
422
////////////////////////////////////////////////////////////////////////////////
 
423
 
 
424
struct Namespace namespaces[] =
 
425
{
 
426
  {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope"},
 
427
  {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding"},
 
428
  {"xsi", "http://www.w3.org/2001/XMLSchema-instance"},
 
429
  {"xsd", "-"}, // http://www.w3.org/2001/XMLSchema"}, // don't use this, it might conflict with xs
 
430
  {"xml", "http://www.w3.org/XML/1998/namespace"},
 
431
  {"xs", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema" },
 
432
  {"http", "http://schemas.xmlsoap.org/wsdl/http/"},
 
433
  {"soap", "http://schemas.xmlsoap.org/wsdl/soap/", "http://schemas.xmlsoap.org/wsdl/soap*/"},
 
434
  {"mime", "http://schemas.xmlsoap.org/wsdl/mime/"},
 
435
  {"dime", "http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/", "http://schemas.xmlsoap.org/ws/*/dime/wsdl/"},
 
436
  {"wsdl", "http://schemas.xmlsoap.org/wsdl/"},
 
437
  {"gwsdl", "http://www.gridforum.org/namespaces/2003/03/gridWSDLExtensions"},
 
438
  {NULL, NULL}
 
439
};