~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to tools/gsoap/macosx-2.7/wsdl/.svn/text-base/wsdl.cpp.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
wsdl.cpp
4
 
 
5
 
WSDL 1.1 binding schema implementation
6
 
 
7
 
--------------------------------------------------------------------------------
8
 
gSOAP XML Web services tools
9
 
Copyright (C) 2001-2004, 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
 
*/
35
 
 
36
 
#include "wsdlH.h"
37
 
 
38
 
#ifdef WITH_NONAMESPACES
39
 
extern struct Namespace namespaces[];
40
 
#endif
41
 
 
42
 
using namespace std;
43
 
 
44
 
const char *qname_token(const char *QName, const char *URI)
45
 
{ if (QName && URI && *QName == '"') // QNames are stored in the format "URI":name, unless the URI is in the nsmap
46
 
  { int n = strlen(URI);
47
 
    if (!strncmp(QName + 1, URI, n) && QName[n + 1] == '"')
48
 
      return QName + n + 3;
49
 
  }
50
 
  else if (QName && (!URI || !*URI) && *QName != '"' && !strchr(QName, ':')) // Empty namespace
51
 
    return QName;
52
 
  return NULL;
53
 
}
54
 
 
55
 
int is_builtin_qname(const char *QName)
56
 
{ return iflag || (QName ? *QName != '"' : 0); // if the QName does not start with a ", it must be in the nsmap
57
 
}
58
 
 
59
 
////////////////////////////////////////////////////////////////////////////////
60
 
//
61
 
//      wsdl
62
 
//
63
 
////////////////////////////////////////////////////////////////////////////////
64
 
 
65
 
int warn_ignore(struct soap*, const char*);
66
 
int show_ignore(struct soap*, const char*);
67
 
 
68
 
wsdl__definitions::wsdl__definitions()
69
 
{ soap = soap_new1(SOAP_XML_TREE | SOAP_C_UTFSTRING);
70
 
#ifdef WITH_NONAMESPACES
71
 
  soap_set_namespaces(soap, namespaces);
72
 
#endif
73
 
  soap_default(soap);
74
 
  if (vflag)
75
 
    soap->fignore = show_ignore;
76
 
  else
77
 
    soap->fignore = warn_ignore;
78
 
  soap->encodingStyle = NULL;
79
 
  soap->proxy_host = proxy_host;
80
 
  soap->proxy_port = proxy_port;
81
 
  name = NULL;
82
 
  targetNamespace = "";
83
 
  documentation = NULL;
84
 
  types = NULL;
85
 
}
86
 
 
87
 
wsdl__definitions::wsdl__definitions(struct soap *copy, const char *location)
88
 
{ soap = soap_copy(copy);
89
 
  soap->socket = SOAP_INVALID_SOCKET;
90
 
  soap->recvfd = 0;
91
 
  soap->sendfd = 1;
92
 
  strcpy(soap->host, copy->host);
93
 
  soap_default(soap);
94
 
  soap->fignore = warn_ignore;
95
 
  soap->encodingStyle = NULL;
96
 
  read(location);
97
 
}
98
 
 
99
 
wsdl__definitions::~wsdl__definitions()
100
 
{ soap_done(soap);
101
 
  free(soap);
102
 
}
103
 
 
104
 
int wsdl__definitions::get(struct soap *soap)
105
 
{ return traverse();
106
 
}
107
 
 
108
 
int wsdl__definitions::read(const char *location)
109
 
{ if (location)
110
 
  { if (!strncmp(location, "http://", 7) || !strncmp(location, "https://", 8))
111
 
    { fprintf(stderr, "Connecting to '%s' to retrieve WSDL... ", location);
112
 
      if (soap_connect_command(soap, SOAP_GET, location, NULL))
113
 
      { fprintf(stderr, "connection failed\n");
114
 
        exit(1);
115
 
      }
116
 
      fprintf(stderr, "done\n");
117
 
    }
118
 
    else if (*soap->host)
119
 
    { char *URL;
120
 
      URL = strrchr(soap->path, '/');
121
 
      if (URL)
122
 
        *URL = '\0';
123
 
      URL = (char*)soap_malloc(soap, strlen(soap->host) + strlen(soap->path) + strlen(location) + 32);
124
 
      sprintf(URL, "http://%s:%d/%s/%s", soap->host, soap->port, soap->path, location);
125
 
      fprintf(stderr, "Connecting to '%s' to retrieve '%s' WSDL... ", URL, location);
126
 
      if (soap_connect_command(soap, SOAP_GET, URL, NULL))
127
 
      { fprintf(stderr, "connection failed\n");
128
 
        exit(1);
129
 
      }
130
 
      fprintf(stderr, "done\n");
131
 
    }
132
 
    else
133
 
    { fprintf(stderr, "Reading file '%s'\n", location);
134
 
      soap->recvfd = open(location, O_RDONLY, 0);
135
 
      if (soap->recvfd < 0)
136
 
      { fprintf(stderr, "Cannot open '%s'\n", location);
137
 
        exit(1);
138
 
      }
139
 
    }
140
 
  }
141
 
  if (!soap_begin_recv(soap))
142
 
    this->soap_in(soap, "wsdl:definitions", NULL);
143
 
  if (soap->error)
144
 
  { // deal with sloppy WSDLs that import schemas at the top level rather than importing them in <types>
145
 
    if (soap->error == SOAP_TAG_MISMATCH && soap->level == 0)
146
 
    { soap_retry(soap);
147
 
      xs__schema *schema = new xs__schema(soap);
148
 
      schema->soap_in(soap, "xs:schema", NULL);
149
 
      if (schema->error())
150
 
      { soap_print_fault(schema->soap, stderr);
151
 
        soap_print_fault_location(schema->soap, stderr);
152
 
        exit(1);
153
 
      }
154
 
      name = NULL;
155
 
      targetNamespace = schema->targetNamespace;
156
 
      if (vflag)
157
 
        cerr << "Found schema " << (targetNamespace?targetNamespace:"") << " when expecting WSDL" << endl;
158
 
      types = new wsdl__types();
159
 
      types->documentation = NULL;
160
 
      types->xs__schema_.push_back(schema);
161
 
      traverse();
162
 
    }
163
 
    else if ((soap->error >= 301 && soap->error <= 303) || soap->error == 307) // HTTP redirect, socket was closed
164
 
    { fprintf(stderr, "Redirected to '%s'\n", soap->endpoint);
165
 
      return read(soap_strdup(soap, soap->endpoint));
166
 
    }
167
 
    else
168
 
    { fprintf(stderr, "An error occurred while parsing WSDL from '%s'\n", location?location:"");
169
 
      soap_print_fault(soap, stderr);
170
 
      soap_print_fault_location(soap, stderr);
171
 
      exit(1);
172
 
    }
173
 
  }
174
 
  soap_end_recv(soap);
175
 
  if (soap->recvfd >= 0)
176
 
  { close(soap->recvfd);
177
 
    soap->recvfd = -1;
178
 
  }
179
 
  else
180
 
    soap_closesock(soap);
181
 
  return SOAP_OK;
182
 
}
183
 
 
184
 
int wsdl__definitions::traverse()
185
 
{ if (vflag)
186
 
    cerr << "wsdl definitions " << (name?name:"") << " " << (targetNamespace?targetNamespace:"") << endl;
187
 
  if (!targetNamespace)
188
 
  { if (vflag)
189
 
      fprintf(stderr, "Warning: WSDL %s has no targetNamespace\n", name?name:"");
190
 
    targetNamespace = "";
191
 
  }
192
 
  // process import first
193
 
  for (vector<wsdl__import>::iterator im = import.begin(); im != import.end(); ++im)
194
 
    (*im).traverse(*this);
195
 
  // merge imported WSDLs
196
 
again:
197
 
  for (vector<wsdl__import>::iterator i = import.begin(); i != import.end(); ++i)
198
 
  { if ((*i).definitionsPtr())
199
 
    { for (vector<wsdl__import>::iterator j = (*i).definitionsPtr()->import.begin(); j != (*i).definitionsPtr()->import.end(); ++j)
200
 
      { bool found = false;
201
 
        for (vector<wsdl__import>::iterator k = import.begin(); k != import.end(); ++k)
202
 
        { if ((*j).definitionsPtr() && (*k).definitionsPtr() && !strcmp((*j).definitionsPtr()->targetNamespace, (*k).definitionsPtr()->targetNamespace))
203
 
          { found = true;
204
 
            break;
205
 
          }
206
 
        }
207
 
        if (!found)
208
 
        { import.push_back(*j);
209
 
          goto again;
210
 
        }
211
 
      }
212
 
    }
213
 
  }
214
 
  // then process the types
215
 
  if (types)
216
 
    types->traverse(*this);
217
 
  // process messages before portTypes
218
 
  for (vector<wsdl__message>::iterator mg = message.begin(); mg != message.end(); ++mg)
219
 
    (*mg).traverse(*this);
220
 
  // process portTypes before bindings
221
 
  for (vector<wsdl__portType>::iterator pt = portType.begin(); pt != portType.end(); ++pt)
222
 
    (*pt).traverse(*this);
223
 
  // process bindings
224
 
  for (vector<wsdl__binding>::iterator bg = binding.begin(); bg != binding.end(); ++bg)
225
 
    (*bg).traverse(*this);
226
 
  // process services
227
 
  for (vector<wsdl__service>::iterator sv = service.begin(); sv != service.end(); ++sv)
228
 
    (*sv).traverse(*this);
229
 
  if (vflag)
230
 
    cerr << "end of wsdl definitions " << (name?name:"") << " " << (targetNamespace?targetNamespace:"") << endl;
231
 
  return SOAP_OK;
232
 
}
233
 
 
234
 
int wsdl__definitions::error()
235
 
{ return soap->error;
236
 
}
237
 
 
238
 
void wsdl__definitions::print_fault()
239
 
{ soap_print_fault(soap, stderr);
240
 
  soap_print_fault_location(soap, stderr);
241
 
}
242
 
 
243
 
void wsdl__definitions::builtinType(const char *type)
244
 
{ builtinTypeSet.insert(type);
245
 
}
246
 
 
247
 
void wsdl__definitions::builtinTypes(const SetOfString& types)
248
 
{ for (SetOfString::const_iterator tp = types.begin(); tp != types.end(); ++tp)
249
 
    builtinTypeSet.insert(*tp);
250
 
}
251
 
 
252
 
void wsdl__definitions::builtinElement(const char *element)
253
 
{ builtinElementSet.insert(element);
254
 
}
255
 
 
256
 
void wsdl__definitions::builtinElements(const SetOfString& elements)
257
 
{ for (SetOfString::const_iterator el = elements.begin(); el != elements.end(); ++el)
258
 
   builtinElementSet.insert(*el);
259
 
}
260
 
 
261
 
void wsdl__definitions::builtinAttribute(const char *attribute)
262
 
{ builtinAttributeSet.insert(attribute);
263
 
}
264
 
 
265
 
void wsdl__definitions::builtinAttributes(const SetOfString& attributes)
266
 
{ for (SetOfString::const_iterator at = attributes.begin(); at != attributes.end(); ++at)
267
 
    builtinAttributeSet.insert(*at);
268
 
}
269
 
 
270
 
const SetOfString& wsdl__definitions::builtinTypes() const
271
 
{ return builtinTypeSet;
272
 
}
273
 
 
274
 
const SetOfString& wsdl__definitions::builtinElements() const
275
 
{ return builtinElementSet;
276
 
}
277
 
 
278
 
const SetOfString& wsdl__definitions::builtinAttributes() const
279
 
{ return builtinAttributeSet;
280
 
}
281
 
 
282
 
int wsdl__service::traverse(wsdl__definitions& definitions)
283
 
{ if (vflag)
284
 
    cerr << "wsdl service " << (name?name:"") << endl;
285
 
  // process ports
286
 
  for (vector<wsdl__port>::iterator i = port.begin(); i != port.end(); ++i)
287
 
    (*i).traverse(definitions);
288
 
  return SOAP_OK;
289
 
}
290
 
 
291
 
wsdl__port::wsdl__port()
292
 
{ bindingRef = NULL;
293
 
}
294
 
 
295
 
wsdl__port::~wsdl__port()
296
 
{ }
297
 
 
298
 
int wsdl__port::traverse(wsdl__definitions& definitions)
299
 
{ if (vflag)
300
 
    cerr << "wsdl port" << endl;
301
 
  // search binding name
302
 
  const char *token = qname_token(binding, definitions.targetNamespace);
303
 
  bindingRef = NULL;
304
 
  if (token)
305
 
  { for (vector<wsdl__binding>::iterator binding = definitions.binding.begin(); binding != definitions.binding.end(); ++binding)
306
 
    { if ((*binding).name && !strcmp((*binding).name, token))
307
 
      { bindingRef = &(*binding);
308
 
        if (vflag)
309
 
          cerr << "Found port " << (name?name:"") << " binding " << (token?token:"") << endl;
310
 
        break;
311
 
      }
312
 
    }
313
 
  }
314
 
  else
315
 
  { for (vector<wsdl__import>::iterator import = definitions.import.begin(); import != definitions.import.end(); ++import)
316
 
    { wsdl__definitions *importdefinitions = (*import).definitionsPtr();
317
 
      if (importdefinitions)
318
 
      { token = qname_token(binding, importdefinitions->targetNamespace);
319
 
        if (token)
320
 
        { for (vector<wsdl__binding>::iterator binding = importdefinitions->binding.begin(); binding != importdefinitions->binding.end(); ++binding)
321
 
          { if ((*binding).name && !strcmp((*binding).name, token))
322
 
            { bindingRef = &(*binding);
323
 
              if (vflag)
324
 
                cerr << "Found port " << (name?name:"") << " binding " << (token?token:"") << endl;
325
 
              break;
326
 
            }
327
 
          }
328
 
        }
329
 
      }
330
 
    }
331
 
  }
332
 
  if (!bindingRef)
333
 
    cerr << "Warning: could not find port " << (name?name:"") << " binding " << (binding?binding:"") << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
334
 
  return SOAP_OK;
335
 
}
336
 
 
337
 
void wsdl__port::bindingPtr(wsdl__binding *binding)
338
 
{ bindingRef = binding;
339
 
}
340
 
 
341
 
wsdl__binding *wsdl__port::bindingPtr() const
342
 
{ return bindingRef;
343
 
}
344
 
 
345
 
wsdl__binding::wsdl__binding()
346
 
{ portTypeRef = NULL;
347
 
}
348
 
 
349
 
wsdl__binding::~wsdl__binding()
350
 
{ }
351
 
 
352
 
int wsdl__binding::traverse(wsdl__definitions& definitions)
353
 
{ if (vflag)
354
 
    cerr << "wsdl binding" << endl;
355
 
  const char *token = qname_token(type, definitions.targetNamespace);
356
 
  portTypeRef = NULL;
357
 
  if (token)
358
 
  { for (vector<wsdl__portType>::iterator portType = definitions.portType.begin(); portType != definitions.portType.end(); ++portType)
359
 
    { if ((*portType).name && !strcmp((*portType).name, token))
360
 
      { portTypeRef = &(*portType);
361
 
        if (vflag)
362
 
          cerr << "Found binding " << (name?name:"") << " portType " << (token?token:"") << endl;
363
 
        break;
364
 
      }
365
 
    }
366
 
  }
367
 
  else
368
 
  { for (vector<wsdl__import>::iterator import = definitions.import.begin(); import != definitions.import.end(); ++import)
369
 
    { wsdl__definitions *importdefinitions = (*import).definitionsPtr();
370
 
      if (importdefinitions)
371
 
      { token = qname_token(type, importdefinitions->targetNamespace);
372
 
        if (token)
373
 
        { for (vector<wsdl__portType>::iterator portType = importdefinitions->portType.begin(); portType != importdefinitions->portType.end(); ++portType)
374
 
          { if ((*portType).name && !strcmp((*portType).name, token))
375
 
            { portTypeRef = &(*portType);
376
 
              if (vflag)
377
 
                cerr << "Found binding " << (name?name:"") << " portType " << (token?token:"") << endl;
378
 
              break;
379
 
            }
380
 
          }
381
 
        }
382
 
      }
383
 
    }
384
 
  }
385
 
  if (!portTypeRef)
386
 
    cerr << "Warning: could not find binding " << (name?name:"") << " portType " << (type?type:"") << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
387
 
  for (vector<wsdl__binding_operation>::iterator i = operation.begin(); i != operation.end(); ++i)
388
 
    (*i).traverse(definitions, portTypeRef);
389
 
  return SOAP_OK;
390
 
}
391
 
 
392
 
void wsdl__binding::portTypePtr(wsdl__portType *portType)
393
 
{ portTypeRef = portType;
394
 
}
395
 
 
396
 
wsdl__portType *wsdl__binding::portTypePtr() const
397
 
{ return portTypeRef;
398
 
}
399
 
 
400
 
wsdl__binding_operation::wsdl__binding_operation()
401
 
{ operationRef = NULL;
402
 
}
403
 
 
404
 
wsdl__binding_operation::~wsdl__binding_operation()
405
 
{ }
406
 
 
407
 
int wsdl__binding_operation::traverse(wsdl__definitions& definitions, wsdl__portType *portTypeRef)
408
 
{ if (vflag)
409
 
    cerr << "wsdl binding operation" << endl;
410
 
  if (input)
411
 
    input->traverse(definitions);
412
 
  if (output)
413
 
    output->traverse(definitions);
414
 
  for (vector<wsdl__ext_fault>::iterator i = fault.begin(); i != fault.end(); ++i)
415
 
    (*i).traverse(definitions);
416
 
  operationRef = NULL;
417
 
  if (portTypeRef)
418
 
  { for (vector<wsdl__operation>::iterator i = portTypeRef->operation.begin(); i != portTypeRef->operation.end(); ++i)
419
 
    { if ((*i).name && !strcmp((*i).name, name))
420
 
      { operationRef = &(*i);
421
 
        if (vflag)
422
 
          cerr << "Found operation " << (name?name:"") << endl;
423
 
        break;
424
 
      }
425
 
    }
426
 
  }
427
 
  if (!operationRef)
428
 
    cerr << "Warning: could not find operation " << (name?name:"") << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
429
 
  else
430
 
  { for (vector<wsdl__ext_fault>::iterator i = fault.begin(); i != fault.end(); ++i)
431
 
    { if ((*i).name)
432
 
      { for (vector<wsdl__fault>::iterator j = operationRef->fault.begin(); j != operationRef->fault.end(); ++j)
433
 
        { if ((*j).name && !strcmp((*j).name, (*i).name))
434
 
          { (*i).messagePtr((*j).messagePtr());
435
 
            if (vflag)
436
 
              cerr << "Found fault " << ((*j).name?(*j).name:"") << " message " << endl;
437
 
            break;
438
 
          }
439
 
        }
440
 
      }
441
 
      else if ((*i).soap__fault_ && (*i).soap__fault_->name) // try the soap:fault name, this is not elegant, but neither is WSDL 1.1 
442
 
      { for (vector<wsdl__fault>::iterator j = operationRef->fault.begin(); j != operationRef->fault.end(); ++j)
443
 
        { if ((*j).name && !strcmp((*j).name, (*i).soap__fault_->name))
444
 
          { (*i).messagePtr((*j).messagePtr());
445
 
            if (vflag)
446
 
              cerr << "Found fault " << ((*j).name?(*j).name:"") << " message " << endl;
447
 
            break;
448
 
          }
449
 
        }
450
 
      }
451
 
      if (!(*i).messagePtr())
452
 
        cerr << "Warning: could not find soap:fault message in WSDL definitions " << (definitions.name?definitions.name:"") << " operation " << (name?name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
453
 
    }
454
 
  }
455
 
  return SOAP_OK;
456
 
}
457
 
 
458
 
void wsdl__binding_operation::operationPtr(wsdl__operation *operation)
459
 
{ operationRef = operation;
460
 
}
461
 
 
462
 
wsdl__operation *wsdl__binding_operation::operationPtr() const
463
 
{ return operationRef;
464
 
}
465
 
 
466
 
int wsdl__ext_input::traverse(wsdl__definitions& definitions)
467
 
{ if (vflag)
468
 
    cerr << "wsdl ext input" << endl;
469
 
  for (vector<soap__header>::iterator i = soap__header_.begin(); i != soap__header_.end(); ++i)
470
 
    (*i).traverse(definitions);
471
 
  return SOAP_OK;
472
 
}
473
 
 
474
 
int wsdl__ext_output::traverse(wsdl__definitions& definitions)
475
 
{ if (vflag)
476
 
    cerr << "wsdl ext output" << endl;
477
 
  for (vector<soap__header>::iterator i = soap__header_.begin(); i != soap__header_.end(); ++i)
478
 
    (*i).traverse(definitions);
479
 
  return SOAP_OK;
480
 
}
481
 
 
482
 
wsdl__ext_fault::wsdl__ext_fault()
483
 
{ messageRef = NULL;
484
 
}
485
 
 
486
 
wsdl__ext_fault::~wsdl__ext_fault()
487
 
{ }
488
 
 
489
 
int wsdl__ext_fault::traverse(wsdl__definitions& definitions)
490
 
{ if (vflag)
491
 
    cerr << "wsdl ext fault" << endl;
492
 
  messageRef = NULL;
493
 
  return SOAP_OK;
494
 
}
495
 
 
496
 
void wsdl__ext_fault::messagePtr(wsdl__message *message)
497
 
{ messageRef = message;
498
 
}
499
 
 
500
 
wsdl__message *wsdl__ext_fault::messagePtr() const
501
 
{ return messageRef;
502
 
}
503
 
 
504
 
int wsdl__portType::traverse(wsdl__definitions& definitions)
505
 
{ if (vflag)
506
 
    cerr << "wsdl portType" << endl;
507
 
  for (vector<wsdl__operation>::iterator i = operation.begin(); i != operation.end(); ++i)
508
 
    (*i).traverse(definitions);
509
 
  return SOAP_OK;
510
 
}
511
 
 
512
 
int wsdl__operation::traverse(wsdl__definitions& definitions)
513
 
{ if (vflag)
514
 
    cerr << "wsdl operation" << endl;
515
 
  if (input)
516
 
    input->traverse(definitions);
517
 
  if (output)
518
 
    output->traverse(definitions);
519
 
  for (vector<wsdl__fault>::iterator i = fault.begin(); i != fault.end(); ++i)
520
 
    (*i).traverse(definitions);
521
 
  return SOAP_OK;
522
 
}
523
 
 
524
 
wsdl__input::wsdl__input()
525
 
{ messageRef = NULL;
526
 
}
527
 
 
528
 
wsdl__input::~wsdl__input()
529
 
{ }
530
 
 
531
 
int wsdl__input::traverse(wsdl__definitions& definitions)
532
 
{ if (vflag)
533
 
    cerr << "wsdl input" << endl;
534
 
  const char *token = qname_token(message, definitions.targetNamespace);
535
 
  messageRef = NULL;
536
 
  if (token)
537
 
  { for (vector<wsdl__message>::iterator message = definitions.message.begin(); message != definitions.message.end(); ++message)
538
 
    { if ((*message).name && !strcmp((*message).name, token))
539
 
      { messageRef = &(*message);
540
 
        if (vflag)
541
 
          cerr << "Found input " << (name?name:"") << " message " << (token?token:"") << endl;
542
 
        break;
543
 
      }
544
 
    }
545
 
  }
546
 
  else
547
 
  { for (vector<wsdl__import>::iterator import = definitions.import.begin(); import != definitions.import.end(); ++import)
548
 
    { wsdl__definitions *importdefinitions = (*import).definitionsPtr();
549
 
      if (importdefinitions)
550
 
      { token = qname_token(message, importdefinitions->targetNamespace);
551
 
        if (token)
552
 
        { for (vector<wsdl__message>::iterator message = importdefinitions->message.begin(); message != importdefinitions->message.end(); ++message)
553
 
          { if ((*message).name && !strcmp((*message).name, token))
554
 
            { messageRef = &(*message);
555
 
              if (vflag)
556
 
                cerr << "Found input " << (name?name:"") << " message " << (token?token:"") << endl;
557
 
              break;
558
 
            }
559
 
          }
560
 
        }
561
 
      }
562
 
    }
563
 
  }
564
 
  if (!messageRef)
565
 
    cerr << "Warning: could not find input " << (name?name:"") << " message " << (message?message:"") << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
566
 
  return SOAP_OK;
567
 
}
568
 
 
569
 
void wsdl__input::messagePtr(wsdl__message *message)
570
 
{ messageRef = message;
571
 
}
572
 
 
573
 
wsdl__message *wsdl__input::messagePtr() const
574
 
{ return messageRef;
575
 
}
576
 
 
577
 
wsdl__output::wsdl__output()
578
 
{ messageRef = NULL;
579
 
}
580
 
 
581
 
wsdl__output::~wsdl__output()
582
 
{ }
583
 
 
584
 
int wsdl__output::traverse(wsdl__definitions& definitions)
585
 
{ if (vflag)
586
 
    cerr << "wsdl output" << endl;
587
 
  const char *token = qname_token(message, definitions.targetNamespace);
588
 
  messageRef = NULL;
589
 
  if (token)
590
 
  { for (vector<wsdl__message>::iterator message = definitions.message.begin(); message != definitions.message.end(); ++message)
591
 
    { if ((*message).name && !strcmp((*message).name, token))
592
 
      { messageRef = &(*message);
593
 
        if (vflag)
594
 
          cerr << "Found output " << (name?name:"") << " message " << (token?token:"") << endl;
595
 
        break;
596
 
      }
597
 
    }
598
 
  }
599
 
  else
600
 
  { for (vector<wsdl__import>::iterator import = definitions.import.begin(); import != definitions.import.end(); ++import)
601
 
    { wsdl__definitions *importdefinitions = (*import).definitionsPtr();
602
 
      if (importdefinitions)
603
 
      { token = qname_token(message, importdefinitions->targetNamespace);
604
 
        if (token)
605
 
        { for (vector<wsdl__message>::iterator message = importdefinitions->message.begin(); message != importdefinitions->message.end(); ++message)
606
 
          { if ((*message).name && !strcmp((*message).name, token))
607
 
            { messageRef = &(*message);
608
 
              if (vflag)
609
 
                cerr << "Found output " << (name?name:"") << " message " << (token?token:"") << endl;
610
 
              break;
611
 
            }
612
 
          }
613
 
        }
614
 
      }
615
 
    }
616
 
  }
617
 
  if (!messageRef)
618
 
    cerr << "Warning: could not find output " << (name?name:"") << " message " << (message?message:"") << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
619
 
  return SOAP_OK;
620
 
}
621
 
 
622
 
void wsdl__output::messagePtr(wsdl__message *message)
623
 
{ messageRef = message;
624
 
}
625
 
 
626
 
wsdl__message *wsdl__output::messagePtr() const
627
 
{ return messageRef;
628
 
}
629
 
 
630
 
wsdl__fault::wsdl__fault()
631
 
{ messageRef = NULL;
632
 
}
633
 
 
634
 
wsdl__fault::~wsdl__fault()
635
 
{ }
636
 
 
637
 
int wsdl__fault::traverse(wsdl__definitions& definitions)
638
 
{ if (vflag)
639
 
    cerr << "wsdl fault" << endl;
640
 
  const char *token = qname_token(message, definitions.targetNamespace);
641
 
  messageRef = NULL;
642
 
  if (token)
643
 
  { for (vector<wsdl__message>::iterator message = definitions.message.begin(); message != definitions.message.end(); ++message)
644
 
    { if ((*message).name && !strcmp((*message).name, token))
645
 
      { messageRef = &(*message);
646
 
        if (vflag)
647
 
          cerr << "Found fault " << (name?name:"") << " message " << (token?token:"") << endl;
648
 
        break;
649
 
      }
650
 
    }
651
 
  }
652
 
  else
653
 
  { for (vector<wsdl__import>::iterator import = definitions.import.begin(); import != definitions.import.end(); ++import)
654
 
    { wsdl__definitions *importdefinitions = (*import).definitionsPtr();
655
 
      if (importdefinitions)
656
 
      { token = qname_token(message, importdefinitions->targetNamespace);
657
 
        if (token)
658
 
        { for (vector<wsdl__message>::iterator message = importdefinitions->message.begin(); message != importdefinitions->message.end(); ++message)
659
 
          { if ((*message).name && !strcmp((*message).name, token))
660
 
            { messageRef = &(*message);
661
 
              if (vflag)
662
 
                cerr << "Found output " << (name?name:"") << " message " << (token?token:"") << endl;
663
 
              break;
664
 
            }
665
 
          }
666
 
        }
667
 
      }
668
 
    }
669
 
  }
670
 
  if (!messageRef)
671
 
    cerr << "Warning: could not find fault " << (name?name:"") << " message " << (message?message:"") << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
672
 
  return SOAP_OK;
673
 
}
674
 
 
675
 
void wsdl__fault::messagePtr(wsdl__message *message)
676
 
{ messageRef = message;
677
 
}
678
 
 
679
 
wsdl__message *wsdl__fault::messagePtr() const
680
 
{ return messageRef;
681
 
}
682
 
 
683
 
int wsdl__message::traverse(wsdl__definitions& definitions)
684
 
{ if (vflag)
685
 
    cerr << "wsdl message" << endl;
686
 
  for (vector<wsdl__part>::iterator i = part.begin(); i != part.end(); ++i)
687
 
    (*i).traverse(definitions);
688
 
  return SOAP_OK;
689
 
}
690
 
 
691
 
wsdl__part::wsdl__part()
692
 
{ elementRef = NULL;
693
 
  simpleTypeRef = NULL;
694
 
  complexTypeRef = NULL;
695
 
}
696
 
 
697
 
wsdl__part::~wsdl__part()
698
 
{ }
699
 
 
700
 
int wsdl__part::traverse(wsdl__definitions& definitions)
701
 
{ if (vflag)
702
 
    cerr << "wsdl part" << endl;
703
 
  elementRef = NULL;
704
 
  simpleTypeRef = NULL;
705
 
  complexTypeRef = NULL;
706
 
  if (definitions.types)
707
 
  { for (vector<xs__schema*>::iterator schema = definitions.types->xs__schema_.begin(); schema != definitions.types->xs__schema_.end(); ++schema)
708
 
    { const char *token = qname_token(element, (*schema)->targetNamespace);
709
 
      if (token)
710
 
      { for (vector<xs__element>::iterator element = (*schema)->element.begin(); element != (*schema)->element.end(); ++element)
711
 
        { if ((*element).name && !strcmp((*element).name, token))
712
 
          { elementRef = &(*element);
713
 
            if (vflag)
714
 
              cerr << "Found part " << (name?name:"") << " element " << (token?token:"") << endl;
715
 
            break;
716
 
          }
717
 
        }
718
 
      }
719
 
      token = qname_token(type, (*schema)->targetNamespace);
720
 
      if (token)
721
 
      { for (vector<xs__simpleType>::iterator simpleType = (*schema)->simpleType.begin(); simpleType != (*schema)->simpleType.end(); ++simpleType)
722
 
        { if ((*simpleType).name && !strcmp((*simpleType).name, token))
723
 
          { simpleTypeRef = &(*simpleType);
724
 
            if (vflag)
725
 
              cerr << "Found part " << (name?name:"") << " simpleType " << (token?token:"") << endl;
726
 
            break;
727
 
          }
728
 
        }
729
 
      }
730
 
      token = qname_token(type, (*schema)->targetNamespace);
731
 
      if (token)
732
 
      { for (vector<xs__complexType>::iterator complexType = (*schema)->complexType.begin(); complexType != (*schema)->complexType.end(); ++complexType)
733
 
        { if ((*complexType).name && !strcmp((*complexType).name, token))
734
 
          { complexTypeRef = &(*complexType);
735
 
            if (vflag)
736
 
              cerr << "Found part " << (name?name:"") << " complexType " << (token?token:"") << endl;
737
 
            break;
738
 
          }
739
 
        }
740
 
      }
741
 
    }
742
 
  }
743
 
  if (!elementRef && !simpleTypeRef && !complexTypeRef)
744
 
  { if (element)
745
 
    { if (is_builtin_qname(element))
746
 
        definitions.builtinElement(element);
747
 
      else
748
 
        cerr << "Warning: could not find part " << (name?name:"") << " element " << element << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
749
 
    }
750
 
    else if (type)
751
 
    { if (is_builtin_qname(type))
752
 
        definitions.builtinType(type);
753
 
      else
754
 
        cerr << "Warning: could not find part " << (name?name:"") << " type " << type << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
755
 
    }
756
 
    else
757
 
      cerr << "Warning: could not find part " << (name?name:"") << " element or type" << " in WSDL definitions " << (definitions.name?definitions.name:"") << " namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;
758
 
  }
759
 
  return SOAP_OK;
760
 
}
761
 
 
762
 
void wsdl__part::elementPtr(xs__element *element)
763
 
{ elementRef = element;
764
 
}
765
 
 
766
 
void wsdl__part::simpleTypePtr(xs__simpleType *simpleType)
767
 
{ simpleTypeRef = simpleType;
768
 
}
769
 
 
770
 
void wsdl__part::complexTypePtr(xs__complexType *complexType)
771
 
{ complexTypeRef = complexType;
772
 
}
773
 
 
774
 
xs__element *wsdl__part::elementPtr() const
775
 
{ return elementRef;
776
 
}
777
 
 
778
 
xs__simpleType *wsdl__part::simpleTypePtr() const
779
 
{ return simpleTypeRef;
780
 
}
781
 
 
782
 
xs__complexType *wsdl__part::complexTypePtr() const
783
 
{ return complexTypeRef;
784
 
}
785
 
 
786
 
int wsdl__types::traverse(wsdl__definitions& definitions)
787
 
{ if (vflag)
788
 
    cerr << "wsdl types" << endl;
789
 
  // import external schemas
790
 
again:
791
 
  for (vector<xs__schema*>::iterator schema1 = xs__schema_.begin(); schema1 != xs__schema_.end(); ++schema1)
792
 
  { for (vector<xs__import>::iterator import = (*schema1)->import.begin(); import != (*schema1)->import.end(); ++import)
793
 
    { if ((*import).namespace_ && (*import).schemaLocation)
794
 
      { bool found = false;
795
 
        for (vector<xs__schema*>::const_iterator schema2 = xs__schema_.begin(); schema2 != xs__schema_.end(); ++schema2)
796
 
        { if ((*schema2)->targetNamespace && !strcmp((*import).namespace_, (*schema2)->targetNamespace))
797
 
          { found = true;
798
 
            break;
799
 
          }
800
 
        }
801
 
        if (!found)
802
 
        { if ((*import).schemaPtr())
803
 
          { if (strcmp((*import).schemaPtr()->targetNamespace, (*import).namespace_))
804
 
              cerr << "Schema import namespace " << (*import).namespace_ << " does not correspond to imported targetNamespace " << (*import).schemaPtr()->targetNamespace << endl;
805
 
            else
806
 
            { xs__schema_.push_back((*import).schemaPtr());
807
 
              goto again;
808
 
            }
809
 
          }
810
 
          else
811
 
          { struct Namespace *p = definitions.soap->local_namespaces;
812
 
            const char *s = (*import).schemaLocation;
813
 
            if (s && (*import).namespace_)
814
 
            { if (p)
815
 
              { for (; p->id; p++)
816
 
                { if (p->in)
817
 
                  { if (!soap_tag_cmp((*import).namespace_, p->in))
818
 
                      break;
819
 
                  }
820
 
                  if (p->ns)
821
 
                  { if (!soap_tag_cmp((*import).namespace_, p->ns))
822
 
                      break;
823
 
                  }
824
 
                }
825
 
              }
826
 
              else
827
 
                fprintf(stderr, "Warning: no namespace table\n");
828
 
              if (!iflag && (!p || !p->id)) // don't import any of the schemas in the .nsmap table (or when -i option is used)
829
 
              { xs__schema *importschema = new xs__schema(definitions.soap, s);
830
 
                (*import).schemaPtr(importschema);
831
 
                if (!importschema->targetNamespace)
832
 
                  importschema->targetNamespace = (*import).namespace_;
833
 
                if (strcmp(importschema->targetNamespace, (*import).namespace_))
834
 
                  cerr << "Schema import namespace " << (*import).namespace_ << " does not correspond to imported targetNamespace " << importschema->targetNamespace << endl;
835
 
                else
836
 
                { importschema->traverse();
837
 
                  xs__schema_.push_back(importschema);
838
 
                  goto again;
839
 
                }
840
 
              }
841
 
            }
842
 
            else if (vflag)
843
 
              fprintf(stderr, "Warning: no schemaLocation for namespace '%s'\n", (*import).namespace_?(*import).namespace_:"");
844
 
          }
845
 
        }
846
 
      }
847
 
    }
848
 
  }
849
 
  for (vector<xs__schema*>::iterator schema2 = xs__schema_.begin(); schema2 != xs__schema_.end(); ++schema2)
850
 
  { // artificially extend the <import> of each schema to include others so when we traverse schemas we can resolve references
851
 
    for (vector<xs__schema*>::iterator importschema = xs__schema_.begin(); importschema != xs__schema_.end(); ++importschema)
852
 
    { if (schema2 != importschema)
853
 
      { xs__import *import = new xs__import();
854
 
        import->namespace_ = (*importschema)->targetNamespace;
855
 
        import->schemaPtr(*importschema);
856
 
        (*schema2)->import.push_back(*import);
857
 
      }
858
 
    }
859
 
    for (vector<xs__import>::iterator import = (*schema2)->import.begin(); import != (*schema2)->import.end(); ++import)
860
 
    { if ((*import).namespace_)
861
 
      { bool found = false;
862
 
        for (vector<xs__schema*>::const_iterator importschema = xs__schema_.begin(); importschema != xs__schema_.end(); ++importschema)
863
 
        { if ((*importschema)->targetNamespace && !strcmp((*import).namespace_, (*importschema)->targetNamespace))
864
 
          { found = true;
865
 
            break;
866
 
          }
867
 
        }
868
 
        if (!found)
869
 
          cerr << "Schema import namespace " << (*import).namespace_ << " refers to a known external Schema" << endl;
870
 
      }
871
 
      else
872
 
        cerr << "<xs:import> has no namespace" << endl;
873
 
    }
874
 
  }
875
 
  for (vector<xs__schema*>::iterator schema3 = xs__schema_.begin(); schema3 != xs__schema_.end(); ++schema3)
876
 
  { (*schema3)->traverse();
877
 
    if (vflag)
878
 
      for (SetOfString::const_iterator i = (*schema3)->builtinTypes().begin(); i != (*schema3)->builtinTypes().end(); ++i)
879
 
        cerr << "Schema builtin type: " << (*i) << endl;
880
 
    definitions.builtinTypes((*schema3)->builtinTypes());
881
 
    definitions.builtinElements((*schema3)->builtinElements());
882
 
    definitions.builtinAttributes((*schema3)->builtinAttributes());
883
 
  }
884
 
  return SOAP_OK;
885
 
}
886
 
 
887
 
int wsdl__import::traverse(wsdl__definitions& definitions)
888
 
{ if (vflag)
889
 
    cerr << "wsdl import" << endl;
890
 
  definitionsRef = NULL;
891
 
  if (location)
892
 
  { // parse imported definitions
893
 
    definitionsRef = new wsdl__definitions(definitions.soap, location);
894
 
    if (!definitionsRef)
895
 
      return SOAP_EOF;
896
 
    if (namespace_)
897
 
      if (strcmp(namespace_, definitionsRef->targetNamespace))
898
 
        cerr << "Import " << location << " namespace " << namespace_ << " does not match imported targetNamespace " << definitionsRef->targetNamespace << endl;
899
 
    // merge <types>
900
 
    if (definitionsRef->types)
901
 
    { if (definitions.types)
902
 
      { // import schemas
903
 
        /* Removed: now handled by xs__schema::traverse()
904
 
        for (vector<xs__schema>::iterator schema = definitions.types->xs__schema_.begin(); schema != definitions.types->xs__schema_.end(); ++schema)
905
 
        { for (vector<xs__schema>::iterator importschema = definitionsRef->types->xs__schema_.begin(); importschema != definitionsRef->types->xs__schema_.end(); ++importschema)
906
 
          { xs__import *import = new xs__import();
907
 
            if (vflag)
908
 
              cerr << "Importing schema " << (*importschema).targetNamespace << endl;
909
 
            import->namespace_ = (*importschema).targetNamespace; // the schemaRef pointer will be set when traversing <types>
910
 
            (*schema).import.push_back(*import);
911
 
          }
912
 
        }
913
 
        */
914
 
        // merge <types>, check for duplicates
915
 
        for (vector<xs__schema*>::const_iterator importschema = definitionsRef->types->xs__schema_.begin(); importschema != definitionsRef->types->xs__schema_.end(); ++importschema)
916
 
        { bool found = false;
917
 
          for (vector<xs__schema*>::const_iterator schema = definitions.types->xs__schema_.begin(); schema != definitions.types->xs__schema_.end(); ++schema)
918
 
          { if (!strcmp((*importschema)->targetNamespace, (*schema)->targetNamespace))
919
 
            { found = true;
920
 
              break;
921
 
            }
922
 
          }
923
 
          if (!found)
924
 
            definitions.types->xs__schema_.push_back(*importschema);
925
 
        }
926
 
      }
927
 
      else
928
 
        definitions.types = definitionsRef->types;
929
 
    }
930
 
    // combine sets of builtin types, elements, and attributes
931
 
    definitions.builtinTypes(definitionsRef->builtinTypes());
932
 
    definitions.builtinElements(definitionsRef->builtinElements());
933
 
    definitions.builtinAttributes(definitionsRef->builtinAttributes());
934
 
  }
935
 
  return SOAP_OK;
936
 
}
937
 
 
938
 
void wsdl__import::definitionsPtr(wsdl__definitions *definitions)
939
 
{ definitionsRef = definitions;
940
 
}
941
 
 
942
 
wsdl__definitions *wsdl__import::definitionsPtr() const
943
 
{ return definitionsRef;
944
 
}
945
 
 
946
 
wsdl__import::wsdl__import()
947
 
{ definitionsRef = NULL;
948
 
}
949
 
 
950
 
wsdl__import::~wsdl__import()
951
 
{ // if (definitionsRef)
952
 
    // delete definitionsRef;
953
 
}
954
 
 
955
 
////////////////////////////////////////////////////////////////////////////////
956
 
//
957
 
//      streams
958
 
//
959
 
////////////////////////////////////////////////////////////////////////////////
960
 
 
961
 
ostream &operator<<(ostream &o, const wsdl__definitions &e)
962
 
{ if (!e.soap)
963
 
  { struct soap soap;
964
 
    soap_init2(&soap, SOAP_IO_DEFAULT, SOAP_XML_TREE | SOAP_C_UTFSTRING);
965
 
#ifdef WITH_NONAMESPACES
966
 
    soap_set_namespaces(&soap, namespaces);
967
 
#endif
968
 
    e.soap_serialize(&soap);
969
 
    soap_begin_send(&soap);
970
 
    e.soap_out(&soap, "wsdl:definitions", 0, NULL);
971
 
    soap_end_send(&soap);
972
 
    soap_end(&soap);
973
 
    soap_done(&soap);
974
 
  }
975
 
  else
976
 
  { ostream *os = e.soap->os;
977
 
    e.soap->os = &o;
978
 
    e.soap_serialize(e.soap);
979
 
    soap_begin_send(e.soap);
980
 
    e.soap_out(e.soap, "wsdl:definitions", 0, NULL);
981
 
    soap_end_send(e.soap);
982
 
    e.soap->os = os;
983
 
  }
984
 
  return o;
985
 
}
986
 
 
987
 
istream &operator>>(istream &i, wsdl__definitions &e)
988
 
{ if (!e.soap)
989
 
    e.soap = soap_new1(SOAP_XML_TREE | SOAP_C_UTFSTRING);
990
 
#ifdef WITH_NONAMESPACES
991
 
  soap_set_namespaces(e.soap, namespaces);
992
 
#endif
993
 
  istream *is = e.soap->is;
994
 
  e.soap->is = &i;
995
 
  if (soap_begin_recv(e.soap)
996
 
   || !e.soap_in(e.soap, "wsdl:definitions", NULL)
997
 
   || soap_end_recv(e.soap))
998
 
  { // handle error? Note: e.soap->error is set and app should check
999
 
  }
1000
 
  e.soap->is = is;
1001
 
  return i;
1002
 
}
1003
 
 
1004
 
////////////////////////////////////////////////////////////////////////////////
1005
 
//
1006
 
//      Miscellaneous
1007
 
//
1008
 
////////////////////////////////////////////////////////////////////////////////
1009
 
 
1010
 
int warn_ignore(struct soap *soap, const char *tag)
1011
 
{ // We don't warn if the omitted element was an annotation or a documentation in an unexpected place
1012
 
  if (soap_match_tag(soap, tag, "xs:annotation") && soap_match_tag(soap, tag, "xs:documentation"))
1013
 
    fprintf(stderr, "Warning: element '%s' at level %d was not recognized and will be ignored\n", tag, soap->level);
1014
 
  return SOAP_OK;
1015
 
}
1016
 
 
1017
 
int show_ignore(struct soap *soap, const char *tag)
1018
 
{ warn_ignore(soap, tag);
1019
 
  soap_print_fault_location(soap, stderr);
1020
 
  return SOAP_OK;
1021
 
}
1022