comparison GEMBASSY-1.0.3/gsoap/wsdl/schema.cpp @ 2:8947fca5f715 draft default tip

Uploaded
author ktnyt
date Fri, 26 Jun 2015 05:21:44 -0400
parents 84a17b3fad1f
children
comparison
equal deleted inserted replaced
1:84a17b3fad1f 2:8947fca5f715
1 /*
2 schema.cpp
3
4 XSD binding schema implementation
5
6 --------------------------------------------------------------------------------
7 gSOAP XML Web services tools
8 Copyright (C) 2000-2012, 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 */
34
35 #include "wsdlH.h" // cannot include "schemaH.h"
36 #include "includes.h"
37
38 extern struct Namespace namespaces[];
39
40 extern "C" {
41 extern int warn_ignore(struct soap*, const char*);
42 }
43
44 extern const char *qname_token(const char*, const char*);
45 extern int is_builtin_qname(const char*);
46
47 ////////////////////////////////////////////////////////////////////////////////
48 //
49 // schema
50 //
51 ////////////////////////////////////////////////////////////////////////////////
52
53 xs__schema::xs__schema()
54 { soap = soap_new1(SOAP_XML_TREE | SOAP_C_UTFSTRING);
55 #ifdef HTTPDA_H
56 soap_register_plugin(soap, http_da);
57 #endif
58 #ifdef WITH_OPENSSL
59 soap_ssl_client_context(soap, SOAP_SSL_NO_AUTHENTICATION, NULL, NULL, NULL, NULL, NULL);
60 #endif
61 soap_set_namespaces(soap, namespaces);
62 soap_default(soap);
63 soap->fignore = warn_ignore;
64 soap->encodingStyle = NULL;
65 soap->proxy_host = proxy_host;
66 soap->proxy_port = proxy_port;
67 soap->proxy_userid = proxy_userid;
68 soap->proxy_passwd = proxy_passwd;
69 targetNamespace = NULL;
70 version = NULL;
71 updated = false;
72 location = NULL;
73 redirs = 0;
74 }
75
76 xs__schema::xs__schema(struct soap *copy)
77 { soap = soap_copy(copy);
78 soap->socket = SOAP_INVALID_SOCKET;
79 soap->recvfd = 0;
80 soap->sendfd = 1;
81 soap_default(soap);
82 soap->fignore = warn_ignore;
83 soap->encodingStyle = NULL;
84 targetNamespace = NULL;
85 version = NULL;
86 updated = false;
87 location = NULL;
88 redirs = 0;
89 }
90
91 xs__schema::xs__schema(struct soap *copy, const char *cwd, const char *loc)
92 { soap = soap_copy(copy);
93 soap->socket = SOAP_INVALID_SOCKET;
94 soap->recvfd = 0;
95 soap->sendfd = 1;
96 /* no longer required, since we keep the host name:
97 strcpy(soap->host, copy->host);
98 */
99 soap_default(soap);
100 soap->fignore = warn_ignore;
101 soap->encodingStyle = NULL;
102 targetNamespace = NULL;
103 version = NULL;
104 updated = false;
105 location = NULL;
106 redirs = 0;
107 read(cwd, loc);
108 }
109
110 xs__schema::~xs__schema()
111 { }
112
113 int xs__schema::get(struct soap *soap)
114 { return preprocess();
115 }
116
117 int xs__schema::preprocess()
118 { // process xs:include recursively
119 // NOTE: includes are context sensitive (take context info), so keep including
120 for (vector<xs__include>::iterator in = include.begin(); in != include.end(); ++in)
121 { (*in).preprocess(*this); // read schema and recurse over <include>
122 if ((*in).schemaPtr())
123 insert(*(*in).schemaPtr());
124 }
125 for (vector<xs__redefine>::iterator re = redefine.begin(); re != redefine.end(); ++re)
126 { (*re).preprocess(*this); // read schema and recurse over <redefine>
127 if ((*re).schemaPtr())
128 insert(*(*re).schemaPtr());
129 }
130 return SOAP_OK;
131 }
132
133 int xs__schema::insert(xs__schema& schema)
134 { bool found;
135 if (targetNamespace && schema.targetNamespace && strcmp(targetNamespace, schema.targetNamespace))
136 if (!Wflag)
137 fprintf(stderr, "Warning: attempt to include schema with mismatching targetNamespace '%s' in schema '%s'\n", schema.targetNamespace, targetNamespace);
138 if (elementFormDefault != schema.elementFormDefault)
139 if (!Wflag)
140 fprintf(stderr, "Warning: attempt to include schema with mismatching elementFormDefault in schema '%s'\n", targetNamespace?targetNamespace:"");
141 if (attributeFormDefault != schema.attributeFormDefault)
142 if (!Wflag)
143 fprintf(stderr, "Warning: attempt to include schema with mismatching attributeFormDefault in schema '%s'\n", targetNamespace?targetNamespace:"");
144 // insert imports, but only add imports with new namespace
145 for (vector<xs__import>::const_iterator im = schema.import.begin(); im != schema.import.end(); ++im)
146 { found = false;
147 if ((*im).namespace_)
148 { for (vector<xs__import>::const_iterator i = import.begin(); i != import.end(); ++i)
149 { if ((*i).namespace_ && !strcmp((*im).namespace_, (*i).namespace_))
150 { found = true;
151 break;
152 }
153 }
154 }
155 if (!found)
156 import.push_back(*im);
157 }
158 // insert attributes, but only add attributes with new name (limited conflict check)
159 for (vector<xs__attribute>::const_iterator at = schema.attribute.begin(); at != schema.attribute.end(); ++at)
160 { found = false;
161 if ((*at).name)
162 { for (vector<xs__attribute>::const_iterator a = attribute.begin(); a != attribute.end(); ++a)
163 { if ((*a).name && !strcmp((*at).name, (*a).name))
164 { found = true;
165 if ((*at).type && (*a).type && strcmp((*at).type, (*a).type))
166 if (!Wflag)
167 fprintf(stderr, "Warning: attempt to redefine attribute '%s' with type '%s' in schema '%s'\n", (*at).name, (*at).type, targetNamespace?targetNamespace:"");
168 break;
169 }
170 }
171 }
172 if (!found)
173 { attribute.push_back(*at);
174 attribute.back().schemaPtr(this);
175 }
176 }
177 // insert elements, but only add elements with new name (limited conflict check)
178 for (vector<xs__element>::const_iterator el = schema.element.begin(); el != schema.element.end(); ++el)
179 { found = false;
180 if ((*el).name)
181 { for (vector<xs__element>::const_iterator e = element.begin(); e != element.end(); ++e)
182 { if ((*e).name && !strcmp((*el).name, (*e).name))
183 { found = true;
184 if ((*el).type && (*e).type && strcmp((*el).type, (*e).type))
185 if (!Wflag)
186 fprintf(stderr, "Warning: attempt to redefine element '%s' with type '%s' in schema '%s'\n", (*el).name, (*el).type, targetNamespace?targetNamespace:"");
187 break;
188 }
189 }
190 }
191 if (!found)
192 { element.push_back(*el);
193 element.back().schemaPtr(this);
194 }
195 }
196 // insert groups, but only add groups with new name (no conflict check)
197 for (vector<xs__group>::const_iterator gp = schema.group.begin(); gp != schema.group.end(); ++gp)
198 { found = false;
199 if ((*gp).name)
200 { for (vector<xs__group>::const_iterator g = group.begin(); g != group.end(); ++g)
201 { if ((*g).name && !strcmp((*gp).name, (*g).name))
202 { found = true;
203 break;
204 }
205 }
206 }
207 if (!found)
208 { group.push_back(*gp);
209 group.back().schemaPtr(this);
210 }
211 }
212 // insert attributeGroups, but only add attributeGroups with new name (no conflict check)
213 for (vector<xs__attributeGroup>::const_iterator ag = schema.attributeGroup.begin(); ag != schema.attributeGroup.end(); ++ag)
214 { found = false;
215 if ((*ag).name)
216 { for (vector<xs__attributeGroup>::const_iterator g = attributeGroup.begin(); g != attributeGroup.end(); ++g)
217 { if ((*g).name && !strcmp((*ag).name, (*g).name))
218 { found = true;
219 break;
220 }
221 }
222 }
223 if (!found)
224 { attributeGroup.push_back(*ag);
225 attributeGroup.back().schemaPtr(this);
226 }
227 }
228 // insert simpleTypes, but only add simpleTypes with new name (no conflict check)
229 for (vector<xs__simpleType>::const_iterator st = schema.simpleType.begin(); st != schema.simpleType.end(); ++st)
230 { found = false;
231 if ((*st).name)
232 { for (vector<xs__simpleType>::const_iterator s = simpleType.begin(); s != simpleType.end(); ++s)
233 { if ((*s).name && !strcmp((*st).name, (*s).name))
234 { found = true;
235 break;
236 }
237 }
238 }
239 if (!found)
240 { simpleType.push_back(*st);
241 simpleType.back().schemaPtr(this);
242 }
243 }
244 // insert complexTypes, but only add complexTypes with new name (no conflict check)
245 for (vector<xs__complexType>::const_iterator ct = schema.complexType.begin(); ct != schema.complexType.end(); ++ct)
246 { found = false;
247 if ((*ct).name)
248 { for (vector<xs__complexType>::const_iterator c = complexType.begin(); c != complexType.end(); ++c)
249 { if ((*c).name && !strcmp((*ct).name, (*c).name))
250 { found = true;
251 break;
252 }
253 }
254 }
255 if (!found)
256 { complexType.push_back(*ct);
257 complexType.back().schemaPtr(this);
258 }
259 }
260 return SOAP_OK;
261 }
262
263 int xs__schema::traverse()
264 { if (updated)
265 return SOAP_OK;
266 if (vflag)
267 cerr << " Analyzing schema '" << (targetNamespace?targetNamespace:"") << "'" << endl;
268 updated = true;
269 if (!targetNamespace)
270 { if (vflag)
271 fprintf(stderr, "Warning: Schema has no targetNamespace\n");
272 targetNamespace = soap_strdup(soap, "");
273 }
274 else if (exturis.find(targetNamespace) != exturis.end())
275 { if (vflag)
276 fprintf(stderr, "Warning: Built-in schema '%s' content encountered\n", targetNamespace);
277 }
278 // process import
279 for (vector<xs__import>::iterator im = import.begin(); im != import.end(); ++im)
280 (*im).traverse(*this);
281 // process attributes
282 for (vector<xs__attribute>::iterator at = attribute.begin(); at != attribute.end(); ++at)
283 (*at).traverse(*this);
284 // process elements
285 for (vector<xs__element>::iterator el = element.begin(); el != element.end();
286 ++el)
287 (*el).traverse(*this);
288 // process simpleTypes, check conflicts with complexTypes
289 for (vector<xs__simpleType>::iterator st = simpleType.begin(); st != simpleType.end(); ++st)
290 { (*st).traverse(*this);
291 if ((*st).name)
292 { for (vector<xs__complexType>::iterator ct = complexType.begin(); ct != complexType.end(); ++ct)
293 if ((*ct).name && !strcmp((*st).name, (*ct).name))
294 if (!Wflag)
295 fprintf(stderr, "Warning: top-level simpleType name and complexType name '%s' clash in schema '%s'\n", (*st).name, targetNamespace?targetNamespace:"");
296 }
297 }
298 // process complexTypes
299 for (vector<xs__complexType>::iterator ct = complexType.begin(); ct != complexType.end(); ++ct)
300 (*ct).traverse(*this);
301 // process groups
302 for (vector<xs__group>::iterator gp = group.begin(); gp != group.end(); ++gp)
303 (*gp).traverse(*this);
304 // process attributeGroups
305 for (vector<xs__attributeGroup>::iterator ag = attributeGroup.begin(); ag != attributeGroup.end(); ++ag)
306 (*ag).traverse(*this);
307 if (vflag)
308 cerr << " End of schema '" << (targetNamespace?targetNamespace:"") << "'" << endl;
309 return SOAP_OK;
310 }
311
312 int xs__schema::read(const char *cwd, const char *loc)
313 { const char *cwd_temp;
314 if (!cwd)
315 cwd = cwd_path;
316 if (vflag)
317 fprintf(stderr, "\nOpening schema '%s' from '%s'\n", loc?loc:"", cwd?cwd:"");
318 if (loc)
319 { if (soap->recvfd > 2)
320 { soap_end_recv(soap);
321 close(soap->recvfd);
322 soap->recvfd = -1;
323 }
324 else if (soap_valid_socket(soap->socket))
325 { soap_end_recv(soap);
326 soap_closesock(soap);
327 }
328 #ifdef WITH_OPENSSL
329 if (!strncmp(loc, "http://", 7) || !strncmp(loc, "https://", 8))
330 #else
331 if (!strncmp(loc, "https://", 8))
332 { fprintf(stderr, "\nCannot connect to https site: no SSL support, please rebuild with SSL (default) or download the files and rerun wsdl2h\n");
333 exit(1);
334 }
335 else if (!strncmp(loc, "http://", 7))
336 #endif
337 { fprintf(stderr, "\nConnecting to '%s' to retrieve schema...\n", loc);
338 location = soap_strdup(soap, loc);
339 if (soap_connect_command(soap, SOAP_GET, location, NULL))
340 { fprintf(stderr, "\nConnection failed\n");
341 exit(1);
342 }
343 fprintf(stderr, "Connected, receiving...\n");
344 }
345 else if (cwd && (!strncmp(cwd, "http://", 7) || !strncmp(cwd, "https://", 8)))
346 { char *s;
347 location = (char*)soap_malloc(soap, strlen(cwd) + strlen(loc) + 2);
348 strcpy(location, cwd);
349 s = strrchr(location, '/');
350 if (s)
351 *s = '\0';
352 strcat(location, "/");
353 strcat(location, loc);
354 fprintf(stderr, "\nConnecting to '%s' to retrieve relative path '%s' schema...\n", location, loc);
355 if (soap_connect_command(soap, SOAP_GET, location, NULL))
356 { fprintf(stderr, "\nConnection failed\n");
357 exit(1);
358 }
359 fprintf(stderr, "Connected, receiving...\n");
360 }
361 else
362 { soap->recvfd = open(loc, O_RDONLY, 0);
363 if (soap->recvfd < 0)
364 { if (cwd)
365 { char *s;
366 location = (char*)soap_malloc(soap, strlen(cwd) + strlen(loc) + 2);
367 strcpy(location, cwd);
368 s = strrchr(location, '/');
369 #ifdef WIN32
370 if (!s)
371 s = strrchr(location, '\\');
372 #endif
373 if (s)
374 *s = '\0';
375 strcat(location, "/");
376 strcat(location, loc);
377 if (!strncmp(location, "file://", 7))
378 location += 7;
379 soap->recvfd = open(location, O_RDONLY, 0);
380 }
381 if (soap->recvfd < 0 && import_path)
382 { location = (char*)soap_malloc(soap, strlen(import_path) + strlen(loc) + 2);
383 strcpy(location, import_path);
384 strcat(location, "/");
385 strcat(location, loc);
386 if (!strncmp(location, "file://", 7))
387 location += 7;
388 soap->recvfd = open(location, O_RDONLY, 0);
389 }
390 if (soap->recvfd < 0)
391 { fprintf(stderr, "\nCannot open '%s' to retrieve schema\n", loc);
392 exit(1);
393 }
394 }
395 else
396 location = soap_strdup(soap, loc);
397 fprintf(stderr, "\nReading schema file '%s'...\n", location);
398 }
399 }
400 cwd_temp = cwd_path;
401 cwd_path = location;
402 if (!soap_begin_recv(soap))
403 this->soap_in(soap, "xs:schema", NULL);
404 if ((soap->error >= 301 && soap->error <= 303) || soap->error == 307) // HTTP redirect, socket was closed
405 { int r = SOAP_ERR;
406 fprintf(stderr, "Redirected to '%s'...\n", soap->endpoint);
407 if (redirs++ < 10)
408 r = read(cwd, soap->endpoint);
409 else
410 fprintf(stderr, "\nMax redirects exceeded\n");
411 redirs--;
412 return r;
413 }
414 else if (soap->error == 401)
415 { int r = SOAP_ERR;
416 fprintf(stderr, "Authenticating to '%s' realm '%s'...\n", loc, soap->authrealm);
417 if (auth_userid && auth_passwd && redirs++ < 1)
418 {
419 #ifdef HTTPDA_H
420 struct http_da_info info;
421 http_da_save(soap, &info, soap->authrealm, auth_userid, auth_passwd);
422 #else
423 soap->userid = auth_userid;
424 soap->passwd = auth_passwd;
425 #endif
426 r = read(cwd, loc);
427 #ifdef HTTPDA_H
428 http_da_release(soap, &info);
429 #endif
430 redirs--;
431 }
432 else
433 fprintf(stderr, "Authentication failed, use option -r:uid:pwd and (re)build with OpenSSL to enable digest authentication\n");
434 return r;
435 }
436 if (soap->error)
437 { fprintf(stderr, "\nAn error occurred while parsing schema from '%s'\n", loc?loc:"");
438 soap_print_fault(soap, stderr);
439 if (soap->error < 200)
440 soap_print_fault_location(soap, stderr);
441 fprintf(stderr, "\nIf this schema namespace is considered \"built-in\", then add\n namespaceprefix = <namespaceURI>\nto typemap.dat.\n");
442 exit(1);
443 }
444 fprintf(stderr, "Done reading '%s'\n", loc?loc:"");
445 soap_end_recv(soap);
446 if (soap->recvfd > 2)
447 { close(soap->recvfd);
448 soap->recvfd = -1;
449 }
450 else
451 soap_closesock(soap);
452 cwd_path = cwd_temp;
453 return SOAP_OK;
454 }
455
456 void xs__schema::sourceLocation(const char *loc)
457 { location = soap_strdup(soap, loc);
458 }
459
460 const char *xs__schema::sourceLocation()
461 { return location;
462 }
463
464 int xs__schema::error()
465 { return soap->error;
466 }
467
468 void xs__schema::print_fault()
469 { soap_print_fault(soap, stderr);
470 if (soap->error < 200)
471 soap_print_fault_location(soap, stderr);
472 }
473
474 void xs__schema::builtinType(const char *type)
475 { builtinTypeSet.insert(type);
476 }
477
478 void xs__schema::builtinElement(const char *element)
479 { builtinElementSet.insert(element);
480 }
481
482 void xs__schema::builtinAttribute(const char *attribute)
483 { builtinAttributeSet.insert(attribute);
484 }
485
486 const SetOfString& xs__schema::builtinTypes() const
487 { return builtinTypeSet;
488 }
489
490 const SetOfString& xs__schema::builtinElements() const
491 { return builtinElementSet;
492 }
493
494 const SetOfString& xs__schema::builtinAttributes() const
495 { return builtinAttributeSet;
496 }
497
498 bool xs__schema::empty() const
499 { return include.empty() && redefine.empty() && import.empty() && attribute.empty() && element.empty() && group.empty() && attributeGroup.empty() && simpleType.empty() && complexType.empty();
500 }
501
502 xs__include::xs__include()
503 { schemaLocation = NULL;
504 schemaRef = NULL;
505 }
506
507 int xs__include::preprocess(xs__schema &schema)
508 { if (!schemaRef && schemaLocation)
509 { // only read from include locations not read already, uses static std::map
510 static map<const char*, xs__schema*, ltstr> included;
511 map<const char*, xs__schema*, ltstr>::iterator i = included.end();
512 if (schema.targetNamespace)
513 for (i = included.begin(); i != included.end(); ++i)
514 if ((*i).second->targetNamespace
515 && !strcmp(schemaLocation, (*i).first)
516 && !strcmp(schema.targetNamespace, (*i).second->targetNamespace))
517 break;
518 if (i == included.end())
519 { if (vflag)
520 cerr << "Preprocessing schema include '" << (schemaLocation?schemaLocation:"") << "' into schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
521 included[schemaLocation] = schemaRef = new xs__schema(schema.soap);
522 schemaRef->read(schema.sourceLocation(), schemaLocation);
523 schemaRef->targetNamespace = schema.targetNamespace;
524 }
525 else
526 { if (vflag)
527 cerr << "Schema '" << (schemaLocation?schemaLocation:"") << "' already included into schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
528 schemaRef = (*i).second;
529 }
530 }
531 return SOAP_OK;
532 }
533
534 int xs__include::traverse(xs__schema &schema)
535 { return SOAP_OK;
536 }
537
538 void xs__include::schemaPtr(xs__schema *schema)
539 { schemaRef = schema;
540 }
541
542 xs__schema *xs__include::schemaPtr() const
543 { return schemaRef;
544 }
545
546 xs__redefine::xs__redefine()
547 { schemaLocation = NULL;
548 schemaRef = NULL;
549 }
550
551 int xs__redefine::preprocess(xs__schema &schema)
552 { if (vflag)
553 cerr << "Preprocessing schema redefine '" << (schemaLocation?schemaLocation:"") << "' into schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
554 if (!schemaRef)
555 { if (schemaLocation)
556 { schemaRef = new xs__schema(schema.soap, schema.sourceLocation(), schemaLocation);
557 for (vector<xs__group>::iterator gp = schemaRef->group.begin(); gp != schemaRef->group.end(); ++gp)
558 { if ((*gp).name)
559 { for (vector<xs__group>::const_iterator g = group.begin(); g != group.end(); ++g)
560 { if ((*g).name && !strcmp((*gp).name, (*g).name))
561 { *gp = *g;
562 break;
563 }
564 }
565 }
566 }
567 for (vector<xs__attributeGroup>::iterator ag = schemaRef->attributeGroup.begin(); ag != schemaRef->attributeGroup.end(); ++ag)
568 { if ((*ag).name)
569 { for (vector<xs__attributeGroup>::const_iterator g = attributeGroup.begin(); g != attributeGroup.end(); ++g)
570 { if ((*g).name && !strcmp((*ag).name, (*g).name))
571 { *ag = *g;
572 break;
573 }
574 }
575 }
576 }
577 for (vector<xs__simpleType>::iterator st = schemaRef->simpleType.begin(); st != schemaRef->simpleType.end(); ++st)
578 { if ((*st).name)
579 { for (vector<xs__simpleType>::const_iterator s = simpleType.begin(); s != simpleType.end(); ++s)
580 { if ((*s).name && !strcmp((*st).name, (*s).name))
581 { *st = *s;
582 break;
583 }
584 }
585 }
586 }
587 for (vector<xs__complexType>::iterator ct = schemaRef->complexType.begin(); ct != schemaRef->complexType.end(); ++ct)
588 { if ((*ct).name)
589 { for (vector<xs__complexType>::const_iterator c = complexType.begin(); c != complexType.end(); ++c)
590 { if ((*c).name && !strcmp((*ct).name, (*c).name))
591 { *ct = *c;
592 break;
593 }
594 }
595 }
596 }
597 }
598 }
599 return SOAP_OK;
600 }
601
602 int xs__redefine::traverse(xs__schema &schema)
603 { return SOAP_OK;
604 }
605
606 void xs__redefine::schemaPtr(xs__schema *schema)
607 { schemaRef = schema;
608 }
609
610 xs__schema *xs__redefine::schemaPtr() const
611 { return schemaRef;
612 }
613
614 xs__import::xs__import()
615 { namespace_ = NULL;
616 schemaLocation = NULL;
617 schemaRef = NULL;
618 }
619
620 int xs__import::traverse(xs__schema &schema)
621 { if (vflag)
622 cerr << " Analyzing schema import '" << (namespace_?namespace_:"") << "'" << endl;
623 if (!schemaRef)
624 { bool found = false;
625 if (namespace_)
626 { for (SetOfString::const_iterator i = exturis.begin(); i != exturis.end(); ++i)
627 { if (!soap_tag_cmp(namespace_, *i))
628 { found = true;
629 break;
630 }
631 }
632 }
633 else if (!Wflag)
634 fprintf(stderr, "Warning: no namespace in <import>\n");
635 if (!found && !iflag) // don't import any of the schemas in the .nsmap table (or when -i option is used)
636 { const char *s = schemaLocation;
637 if (!s)
638 s = namespace_;
639 // only read from import locations not read already, uses static std::map
640 static map<const char*, xs__schema*, ltstr> included;
641 map<const char*, xs__schema*, ltstr>::iterator i = included.find(s);
642 if (i == included.end())
643 { included[s] = schemaRef = new xs__schema(schema.soap);
644 schemaRef->read(schema.sourceLocation(), s);
645 }
646 else
647 schemaRef = (*i).second;
648 if (schemaRef)
649 { if (!schemaRef->targetNamespace || !*schemaRef->targetNamespace)
650 schemaRef->targetNamespace = namespace_;
651 else
652 if (!namespace_ || strcmp(schemaRef->targetNamespace, namespace_))
653 if (!Wflag)
654 fprintf(stderr, "Warning: schema import '%s' with schema targetNamespace '%s' mismatch\n", namespace_?namespace_:"", schemaRef->targetNamespace);
655 }
656 }
657 }
658 if (schemaRef)
659 schemaRef->traverse();
660 return SOAP_OK;
661 }
662
663 void xs__import::schemaPtr(xs__schema *schema)
664 { schemaRef = schema;
665 }
666
667 xs__schema *xs__import::schemaPtr() const
668 { return schemaRef;
669 }
670
671 xs__attribute::xs__attribute()
672 { schemaRef = NULL;
673 attributeRef = NULL;
674 simpleTypeRef = NULL;
675 }
676
677 int xs__attribute::traverse(xs__schema &schema)
678 { if (vflag)
679 cerr << " Analyzing schema attribute '" << (name?name:"") << "'" << endl;
680 schemaRef = &schema;
681 const char *token = qname_token(ref, schema.targetNamespace);
682 attributeRef = NULL;
683 if (token)
684 { for (vector<xs__attribute>::iterator i = schema.attribute.begin(); i != schema.attribute.end(); ++i)
685 if (!strcmp((*i).name, token))
686 { attributeRef = &(*i);
687 if (vflag)
688 cerr << " Found attribute '" << (name?name:"") << "' ref '" << (token?token:"") << "'" << endl;
689 break;
690 }
691 }
692 if (!attributeRef)
693 { for (vector<xs__import>::iterator i = schema.import.begin(); i != schema.import.end(); ++i)
694 { xs__schema *s = (*i).schemaPtr();
695 if (s)
696 { token = qname_token(ref, s->targetNamespace);
697 if (token)
698 { for (vector<xs__attribute>::iterator j = s->attribute.begin(); j != s->attribute.end(); ++j)
699 { if (!strcmp((*j).name, token))
700 { attributeRef = &(*j);
701 if (vflag)
702 cerr << " Found attribute '" << (name?name:"") << "' ref '" << (token?token:"") << "'" << endl;
703 break;
704 }
705 }
706 if (attributeRef)
707 break;
708 }
709 }
710 }
711 }
712 if (simpleType)
713 { simpleType->traverse(schema);
714 simpleTypeRef = simpleType;
715 }
716 else
717 { token = qname_token(type, schema.targetNamespace);
718 simpleTypeRef = NULL;
719 if (token)
720 { for (vector<xs__simpleType>::iterator i = schema.simpleType.begin(); i != schema.simpleType.end(); ++i)
721 if (!strcmp((*i).name, token))
722 { simpleTypeRef = &(*i);
723 if (vflag)
724 cerr << " Found attribute '" << (name?name:"") << "' type '" << (token?token:"") << "'" << endl;
725 break;
726 }
727 }
728 if (!simpleTypeRef)
729 { for (vector<xs__import>::iterator i = schema.import.begin(); i != schema.import.end(); ++i)
730 { xs__schema *s = (*i).schemaPtr();
731 if (s)
732 { token = qname_token(type, s->targetNamespace);
733 if (token)
734 { for (vector<xs__simpleType>::iterator j = s->simpleType.begin(); j != s->simpleType.end(); ++j)
735 { if (!strcmp((*j).name, token))
736 { simpleTypeRef = &(*j);
737 if (vflag)
738 cerr << " Found attribute '" << (name?name:"") << "' type '" << (token?token:"") << "'" << endl;
739 break;
740 }
741 }
742 if (simpleTypeRef)
743 break;
744 }
745 }
746 }
747 }
748 }
749 if (!attributeRef && !simpleTypeRef)
750 { if (ref)
751 { if (is_builtin_qname(ref))
752 schema.builtinAttribute(ref);
753 else if (!Wflag)
754 cerr << "Warning: could not find attribute '" << (name?name:"") << "' ref '" << ref << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
755 }
756 else if (type)
757 { if (is_builtin_qname(type))
758 schema.builtinType(type);
759 else if (!Wflag)
760 cerr << "Warning: could not find attribute '" << (name?name:"") << "' type '" << type << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
761 }
762 }
763 return SOAP_OK;
764 }
765
766 void xs__attribute::schemaPtr(xs__schema *schema)
767 { schemaRef = schema;
768 }
769
770 xs__schema* xs__attribute::schemaPtr() const
771 { return schemaRef;
772 }
773
774 void xs__attribute::attributePtr(xs__attribute *attribute)
775 { attributeRef = attribute;
776 }
777
778 void xs__attribute::simpleTypePtr(xs__simpleType *simpleType)
779 { simpleTypeRef = simpleType;
780 }
781
782 xs__attribute *xs__attribute::attributePtr() const
783 { return attributeRef;
784 }
785
786 xs__simpleType *xs__attribute::simpleTypePtr() const
787 { return simpleTypeRef;
788 }
789
790 xs__element::xs__element()
791 { schemaRef = NULL;
792 elementRef = NULL;
793 simpleTypeRef = NULL;
794 complexTypeRef = NULL;
795 }
796
797 int xs__element::traverse(xs__schema &schema)
798 { if (vflag)
799 cerr << " Analyzing schema element '" << (name?name:"") << "'" << endl;
800 schemaRef = &schema;
801 const char *token = qname_token(ref, schema.targetNamespace);
802 elementRef = NULL;
803 if (token)
804 { for (vector<xs__element>::iterator i = schema.element.begin(); i != schema.element.end(); ++i)
805 { if ((*i).name && !strcmp((*i).name, token))
806 { elementRef = &(*i);
807 if (vflag)
808 cerr << " Found element '" << (name?name:"") << "' ref '" << (token?token:"") << "'" << endl;
809 break;
810 }
811 }
812 }
813 if (!elementRef)
814 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
815 { xs__schema *s = (*i).schemaPtr();
816 if (s)
817 { token = qname_token(ref, s->targetNamespace);
818 if (token)
819 { for (vector<xs__element>::iterator j = s->element.begin(); j != s->element.end(); ++j)
820 { if ((*j).name && !strcmp((*j).name, token))
821 { elementRef = &(*j);
822 if (vflag)
823 cerr << " Found element '" << (name?name:"") << "' ref '" << (token?token:"") << "'" << endl;
824 break;
825 }
826 }
827 if (elementRef)
828 break;
829 }
830 }
831 }
832 }
833 if (simpleType)
834 { simpleType->traverse(schema);
835 simpleTypeRef = simpleType;
836 }
837 else
838 { token = qname_token(type, schema.targetNamespace);
839 simpleTypeRef = NULL;
840 if (token)
841 { for (vector<xs__simpleType>::iterator i = schema.simpleType.begin(); i != schema.simpleType.end(); ++i)
842 if ((*i).name && !strcmp((*i).name, token))
843 { simpleTypeRef = &(*i);
844 if (vflag)
845 cerr << " Found element '" << (name?name:"") << "' simpleType '" << (token?token:"") << "'" << endl;
846 break;
847 }
848 }
849 if (!simpleTypeRef)
850 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
851 { xs__schema *s = (*i).schemaPtr();
852 if (s)
853 { token = qname_token(type, s->targetNamespace);
854 if (token)
855 { for (vector<xs__simpleType>::iterator j = s->simpleType.begin(); j != s->simpleType.end(); ++j)
856 { if ((*j).name && !strcmp((*j).name, token))
857 { simpleTypeRef = &(*j);
858 if (vflag)
859 cerr << " Found element '" << (name?name:"") << "' simpleType '" << (token?token:"") << "'" << endl;
860 break;
861 }
862 }
863 if (simpleTypeRef)
864 break;
865 }
866 }
867 }
868 }
869 }
870 if (complexType)
871 { complexType->traverse(schema);
872 complexTypeRef = complexType;
873 }
874 else
875 { token = qname_token(type, schema.targetNamespace);
876 complexTypeRef = NULL;
877 if (token)
878 { for (vector<xs__complexType>::iterator i = schema.complexType.begin(); i != schema.complexType.end(); ++i)
879 if ((*i).name && !strcmp((*i).name, token))
880 { complexTypeRef = &(*i);
881 if (vflag)
882 cerr << " Found element '" << (name?name:"") << "' complexType '" << (token?token:"") << "'" << endl;
883 break;
884 }
885 }
886 if (!complexTypeRef)
887 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
888 { xs__schema *s = (*i).schemaPtr();
889 if (s)
890 { token = qname_token(type, s->targetNamespace);
891 if (token)
892 { for (vector<xs__complexType>::iterator j = s->complexType.begin(); j != s->complexType.end(); ++j)
893 { if ((*j).name && !strcmp((*j).name, token))
894 { complexTypeRef = &(*j);
895 if (vflag)
896 cerr << " Found element '" << (name?name:"") << "' complexType '" << (token?token:"") << "'" << endl;
897 break;
898 }
899 }
900 if (complexTypeRef)
901 break;
902 }
903 }
904 }
905 }
906 }
907 token = qname_token(substitutionGroup, schema.targetNamespace);
908 if (token)
909 { for (vector<xs__element>::iterator i = schema.element.begin(); i != schema.element.end(); ++i)
910 if (!strcmp((*i).name, token))
911 { (*i).substitutions.push_back(this);
912 if (vflag)
913 cerr << " Found substitutionGroup element '" << (name?name:"") << "' for abstract element '" << (token?token:"") << "'" << endl;
914 break;
915 }
916 }
917 for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
918 { xs__schema *s = (*i).schemaPtr();
919 if (s)
920 { token = qname_token(substitutionGroup, s->targetNamespace);
921 if (token)
922 { for (vector<xs__element>::iterator j = s->element.begin(); j != s->element.end(); ++j)
923 { if (!strcmp((*j).name, token))
924 { (*j).substitutions.push_back(this);
925 if (vflag)
926 cerr << " Found substitutionGroup element '" << (name?name:"") << "' for abstract element '" << (token?token:"") << "'" << endl;
927 break;
928 }
929 }
930 }
931 }
932 }
933 if (!elementRef && !simpleTypeRef && !complexTypeRef)
934 { if (ref)
935 { if (is_builtin_qname(ref))
936 schema.builtinElement(ref);
937 else if (!Wflag)
938 cerr << "Warning: could not find element '" << (name?name:"") << "' ref '" << ref << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
939 }
940 else if (type)
941 { if (is_builtin_qname(type))
942 schema.builtinType(type);
943 else if (!Wflag)
944 cerr << "Warning: could not find element '" << (name?name:"") << "' type '" << type << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
945 }
946 }
947 return SOAP_OK;
948 }
949
950 void xs__element::schemaPtr(xs__schema *schema)
951 { schemaRef = schema;
952 }
953
954 xs__schema* xs__element::schemaPtr() const
955 { return schemaRef;
956 }
957
958 void xs__element::elementPtr(xs__element *element)
959 { elementRef = element;
960 }
961
962 void xs__element::simpleTypePtr(xs__simpleType *simpleType)
963 { simpleTypeRef = simpleType;
964 }
965
966 void xs__element::complexTypePtr(xs__complexType *complexType)
967 { complexTypeRef = complexType;
968 }
969
970 xs__element *xs__element::elementPtr() const
971 { return elementRef;
972 }
973
974 const std::vector<xs__element*>* xs__element::substitutionsPtr() const
975 { return &substitutions;
976 }
977
978 xs__simpleType *xs__element::simpleTypePtr() const
979 { return simpleTypeRef;
980 }
981
982 xs__complexType *xs__element::complexTypePtr() const
983 { return complexTypeRef;
984 }
985
986 xs__simpleType::xs__simpleType()
987 { schemaRef = NULL;
988 level = 0;
989 }
990
991 int xs__simpleType::traverse(xs__schema &schema)
992 { if (vflag)
993 cerr << " Analyzing schema simpleType '" << (name?name:"") << "'" << endl;
994 schemaRef = &schema;
995 if (list)
996 list->traverse(schema);
997 else if (restriction)
998 restriction->traverse(schema);
999 else if (union_)
1000 union_->traverse(schema);
1001 return SOAP_OK;
1002 }
1003
1004 void xs__simpleType::schemaPtr(xs__schema *schema)
1005 { schemaRef = schema;
1006 }
1007
1008 xs__schema *xs__simpleType::schemaPtr() const
1009 { return schemaRef;
1010 }
1011
1012 int xs__simpleType::baseLevel()
1013 { if (!level)
1014 { if (restriction)
1015 { level = -1;
1016 if (restriction->simpleTypePtr())
1017 level = restriction->simpleTypePtr()->baseLevel() + 1;
1018 else
1019 level = 2;
1020 }
1021 else if (list && list->restriction)
1022 { level = -1;
1023 if (list->restriction->simpleTypePtr())
1024 level = list->restriction->simpleTypePtr()->baseLevel() + 1;
1025 else
1026 level = 2;
1027 }
1028 else
1029 level = 1;
1030 }
1031 else if (level < 0)
1032 { cerr << "Error: cyclic simpleType restriction/extension base dependency in '" << (name?name:"") << "'" << endl;
1033 }
1034 return level;
1035 }
1036
1037 xs__complexType::xs__complexType()
1038 { schemaRef = NULL;
1039 level = 0;
1040 }
1041
1042 int xs__complexType::traverse(xs__schema &schema)
1043 { if (vflag)
1044 cerr << " Analyzing schema complexType '" << (name?name:"") << "'" << endl;
1045 schemaRef = &schema;
1046 if (simpleContent)
1047 simpleContent->traverse(schema);
1048 else if (complexContent)
1049 complexContent->traverse(schema);
1050 else if (all)
1051 all->traverse(schema);
1052 else if (choice)
1053 choice->traverse(schema);
1054 else if (sequence)
1055 sequence->traverse(schema);
1056 else if (any)
1057 any->traverse(schema);
1058 for (vector<xs__attribute>::iterator at = attribute.begin(); at != attribute.end(); ++at)
1059 (*at).traverse(schema);
1060 for (vector<xs__attributeGroup>::iterator ag = attributeGroup.begin(); ag != attributeGroup.end(); ++ag)
1061 (*ag).traverse(schema);
1062 return SOAP_OK;
1063 }
1064
1065 void xs__complexType::schemaPtr(xs__schema *schema)
1066 { schemaRef = schema;
1067 }
1068
1069 xs__schema *xs__complexType::schemaPtr() const
1070 { return schemaRef;
1071 }
1072
1073 int xs__complexType::baseLevel()
1074 { if (!level)
1075 { if (simpleContent)
1076 { if (simpleContent->restriction)
1077 { level = -1;
1078 if (simpleContent->restriction->simpleTypePtr())
1079 level = simpleContent->restriction->simpleTypePtr()->baseLevel() + 1;
1080 else if (simpleContent->restriction->complexTypePtr())
1081 level = simpleContent->restriction->complexTypePtr()->baseLevel() + 1;
1082 else
1083 level = 2;
1084 }
1085 else if (simpleContent->extension)
1086 { level = -1;
1087 if (simpleContent->extension->simpleTypePtr())
1088 level = simpleContent->extension->simpleTypePtr()->baseLevel() + 1;
1089 else if (simpleContent->extension->complexTypePtr())
1090 level = simpleContent->extension->complexTypePtr()->baseLevel() + 1;
1091 else
1092 level = 2;
1093 }
1094 }
1095 else if (complexContent)
1096 { if (complexContent->restriction)
1097 { level = -1;
1098 if (complexContent->restriction->simpleTypePtr())
1099 level = complexContent->restriction->simpleTypePtr()->baseLevel() + 1;
1100 else if (complexContent->restriction->complexTypePtr())
1101 level = complexContent->restriction->complexTypePtr()->baseLevel() + 1;
1102 else
1103 level = 2;
1104 }
1105 else if (complexContent->extension)
1106 { level = -1;
1107 if (complexContent->extension->simpleTypePtr())
1108 level = complexContent->extension->simpleTypePtr()->baseLevel() + 1;
1109 else if (complexContent->extension->complexTypePtr())
1110 level = complexContent->extension->complexTypePtr()->baseLevel() + 1;
1111 else
1112 level = 2;
1113 }
1114 }
1115 else
1116 level = 1;
1117 }
1118 else if (level < 0)
1119 { cerr << "Error: cyclic complexType restriction/extension base dependency in '" << (name?name:"") << "'" << endl;
1120 }
1121 return level;
1122 }
1123
1124 int xs__simpleContent::traverse(xs__schema &schema)
1125 { if (vflag)
1126 cerr << " Analyzing schema simpleContent" << endl;
1127 if (extension)
1128 extension->traverse(schema);
1129 else if (restriction)
1130 restriction->traverse(schema);
1131 return SOAP_OK;
1132 }
1133
1134 int xs__complexContent::traverse(xs__schema &schema)
1135 { if (vflag)
1136 cerr << " Analyzing schema complexContent" << endl;
1137 if (extension)
1138 extension->traverse(schema);
1139 else if (restriction)
1140 restriction->traverse(schema);
1141 return SOAP_OK;
1142 }
1143
1144 xs__extension::xs__extension()
1145 { simpleTypeRef = NULL;
1146 complexTypeRef = NULL;
1147 }
1148
1149 int xs__extension::traverse(xs__schema &schema)
1150 { if (vflag)
1151 cerr << " Analyzing schema extension '" << (base?base:"") << "'" << endl;
1152 if (group)
1153 group->traverse(schema);
1154 else if (all)
1155 all->traverse(schema);
1156 else if (choice)
1157 choice->traverse(schema);
1158 else if (sequence)
1159 sequence->traverse(schema);
1160 for (vector<xs__attribute>::iterator at = attribute.begin(); at != attribute.end(); ++at)
1161 (*at).traverse(schema);
1162 for (vector<xs__attributeGroup>::iterator ag = attributeGroup.begin(); ag != attributeGroup.end(); ++ag)
1163 (*ag).traverse(schema);
1164 const char *token = qname_token(base, schema.targetNamespace);
1165 simpleTypeRef = NULL;
1166 if (token)
1167 { for (vector<xs__simpleType>::iterator i = schema.simpleType.begin(); i != schema.simpleType.end(); ++i)
1168 if (!strcmp((*i).name, token))
1169 { simpleTypeRef = &(*i);
1170 if (vflag)
1171 cerr << " Found extension base type '" << (token?token:"") << "'" << endl;
1172 break;
1173 }
1174 }
1175 if (!simpleTypeRef)
1176 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
1177 { xs__schema *s = (*i).schemaPtr();
1178 if (s)
1179 { token = qname_token(base, s->targetNamespace);
1180 if (token)
1181 { for (vector<xs__simpleType>::iterator j = s->simpleType.begin(); j != s->simpleType.end(); ++j)
1182 { if (!strcmp((*j).name, token))
1183 { simpleTypeRef = &(*j);
1184 if (vflag)
1185 cerr << " Found extension base type '" << (token?token:"") << "'" << endl;
1186 break;
1187 }
1188 }
1189 if (simpleTypeRef)
1190 break;
1191 }
1192 }
1193 }
1194 }
1195 token = qname_token(base, schema.targetNamespace);
1196 complexTypeRef = NULL;
1197 if (token)
1198 { for (vector<xs__complexType>::iterator i = schema.complexType.begin(); i != schema.complexType.end(); ++i)
1199 if ((*i).name && !strcmp((*i).name, token))
1200 { complexTypeRef = &(*i);
1201 if (vflag)
1202 cerr << " Found extension base type '" << (token?token:"") << "'" << endl;
1203 break;
1204 }
1205 }
1206 if (!complexTypeRef)
1207 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
1208 { xs__schema *s = (*i).schemaPtr();
1209 if (s)
1210 { token = qname_token(base, s->targetNamespace);
1211 if (token)
1212 { for (vector<xs__complexType>::iterator j = s->complexType.begin(); j != s->complexType.end(); ++j)
1213 { if ((*j).name && !strcmp((*j).name, token))
1214 { complexTypeRef = &(*j);
1215 if (vflag)
1216 cerr << " Found extension base type '" << (token?token:"") << "'" << endl;
1217 break;
1218 }
1219 }
1220 if (complexTypeRef)
1221 break;
1222 }
1223 }
1224 }
1225 }
1226 if (!simpleTypeRef && !complexTypeRef)
1227 { if (base)
1228 { if (is_builtin_qname(base))
1229 schema.builtinType(base);
1230 else if (!Wflag)
1231 cerr << "Warning: could not find extension base type '" << base << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
1232 }
1233 else
1234 cerr << "Extension has no base" << endl;
1235 }
1236 return SOAP_OK;
1237 }
1238
1239 void xs__extension::simpleTypePtr(xs__simpleType *simpleType)
1240 { simpleTypeRef = simpleType;
1241 }
1242
1243 void xs__extension::complexTypePtr(xs__complexType *complexType)
1244 { complexTypeRef = complexType;
1245 }
1246
1247 xs__simpleType *xs__extension::simpleTypePtr() const
1248 { return simpleTypeRef;
1249 }
1250
1251 xs__complexType *xs__extension::complexTypePtr() const
1252 { return complexTypeRef;
1253 }
1254
1255 xs__restriction::xs__restriction()
1256 { simpleTypeRef = NULL;
1257 complexTypeRef = NULL;
1258 }
1259
1260 int xs__restriction::traverse(xs__schema &schema)
1261 { if (vflag)
1262 cerr << " Analyzing schema restriction '" << (base?base:"") << "'" << endl;
1263 if (simpleType)
1264 simpleType->traverse(schema);
1265 if (attributeGroup)
1266 attributeGroup->traverse(schema);
1267 if (group)
1268 group->traverse(schema);
1269 else if (all)
1270 all->traverse(schema);
1271 else if (choice)
1272 choice->traverse(schema);
1273 else if (sequence)
1274 sequence->traverse(schema);
1275 else
1276 { for (vector<xs__enumeration>::iterator en = enumeration.begin(); en != enumeration.end(); ++en)
1277 (*en).traverse(schema);
1278 for (vector<xs__pattern>::iterator pn = pattern.begin(); pn != pattern.end(); ++pn)
1279 (*pn).traverse(schema);
1280 }
1281 for (vector<xs__attribute>::iterator at = attribute.begin(); at != attribute.end(); ++at)
1282 (*at).traverse(schema);
1283 const char *token = qname_token(base, schema.targetNamespace);
1284 simpleTypeRef = NULL;
1285 if (token)
1286 { for (vector<xs__simpleType>::iterator i = schema.simpleType.begin(); i != schema.simpleType.end(); ++i)
1287 if (!strcmp((*i).name, token))
1288 { simpleTypeRef = &(*i);
1289 if (vflag)
1290 cerr << " Found restriction base type '" << (token?token:"") << "'" << endl;
1291 break;
1292 }
1293 }
1294 if (!simpleTypeRef)
1295 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
1296 { xs__schema *s = (*i).schemaPtr();
1297 if (s)
1298 { token = qname_token(base, s->targetNamespace);
1299 if (token)
1300 { for (vector<xs__simpleType>::iterator j = s->simpleType.begin(); j != s->simpleType.end(); ++j)
1301 { if (!strcmp((*j).name, token))
1302 { simpleTypeRef = &(*j);
1303 if (vflag)
1304 cerr << " Found restriction base type '" << (token?token:"") << "'" << endl;
1305 break;
1306 }
1307 }
1308 if (simpleTypeRef)
1309 break;
1310 }
1311 }
1312 }
1313 }
1314 token = qname_token(base, schema.targetNamespace);
1315 complexTypeRef = NULL;
1316 if (token)
1317 { for (vector<xs__complexType>::iterator i = schema.complexType.begin(); i != schema.complexType.end(); ++i)
1318 if ((*i).name && !strcmp((*i).name, token))
1319 { complexTypeRef = &(*i);
1320 if (vflag)
1321 cerr << " Found restriction base type '" << (token?token:"") << "'" << endl;
1322 break;
1323 }
1324 }
1325 if (!complexTypeRef)
1326 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
1327 { xs__schema *s = (*i).schemaPtr();
1328 if (s)
1329 { token = qname_token(base, s->targetNamespace);
1330 if (token)
1331 { for (vector<xs__complexType>::iterator j = s->complexType.begin(); j != s->complexType.end(); ++j)
1332 { if ((*j).name && !strcmp((*j).name, token))
1333 { complexTypeRef = &(*j);
1334 if (vflag)
1335 cerr << " Found restriction base type '" << (token?token:"") << "'" << endl;
1336 break;
1337 }
1338 }
1339 if (complexTypeRef)
1340 break;
1341 }
1342 }
1343 }
1344 }
1345 if (!simpleTypeRef && !complexTypeRef)
1346 { if (base)
1347 { if (is_builtin_qname(base))
1348 schema.builtinType(base);
1349 else if (!Wflag)
1350 cerr << "Warning: could not find restriction base type '" << base << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
1351 }
1352 else if (!simpleType)
1353 cerr << "Restriction has no base" << endl;
1354 }
1355 return SOAP_OK;
1356 }
1357
1358 void xs__restriction::simpleTypePtr(xs__simpleType *simpleType)
1359 { simpleTypeRef = simpleType;
1360 }
1361
1362 void xs__restriction::complexTypePtr(xs__complexType *complexType)
1363 { complexTypeRef = complexType;
1364 }
1365
1366 xs__simpleType *xs__restriction::simpleTypePtr() const
1367 { return simpleTypeRef;
1368 }
1369
1370 xs__complexType *xs__restriction::complexTypePtr() const
1371 { return complexTypeRef;
1372 }
1373
1374 xs__list::xs__list()
1375 { itemTypeRef = NULL;
1376 }
1377
1378 int xs__list::traverse(xs__schema &schema)
1379 { if (vflag)
1380 cerr << " Analyzing schema list" << endl;
1381 if (restriction)
1382 restriction->traverse(schema);
1383 for (vector<xs__simpleType>::iterator i = simpleType.begin(); i != simpleType.end(); ++i)
1384 (*i).traverse(schema);
1385 itemTypeRef = NULL;
1386 const char *token = qname_token(itemType, schema.targetNamespace);
1387 if (token)
1388 { for (vector<xs__simpleType>::iterator i = schema.simpleType.begin(); i != schema.simpleType.end(); ++i)
1389 if (!strcmp((*i).name, token))
1390 { itemTypeRef = &(*i);
1391 if (vflag)
1392 cerr << " Found list itemType '" << (token?token:"") << "'" << endl;
1393 break;
1394 }
1395 }
1396 if (!itemTypeRef)
1397 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
1398 { xs__schema *s = (*i).schemaPtr();
1399 if (s)
1400 { token = qname_token(itemType, s->targetNamespace);
1401 if (token)
1402 { for (vector<xs__simpleType>::iterator j = s->simpleType.begin(); j != s->simpleType.end(); ++j)
1403 { if (!strcmp((*j).name, token))
1404 { itemTypeRef = &(*j);
1405 if (vflag)
1406 cerr << " Found list itemType '" << (token?token:"") << "'" << endl;
1407 break;
1408 }
1409 }
1410 if (itemTypeRef)
1411 break;
1412 }
1413 }
1414 }
1415 }
1416 if (itemType && !itemTypeRef)
1417 { if (is_builtin_qname(itemType))
1418 schema.builtinType(itemType);
1419 else if (!Wflag)
1420 cerr << "Warning: could not find list itemType '" << itemType << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
1421 }
1422 return SOAP_OK;
1423 }
1424
1425 void xs__list::itemTypePtr(xs__simpleType *simpleType)
1426 { itemTypeRef = simpleType;
1427 }
1428
1429 xs__simpleType *xs__list::itemTypePtr() const
1430 { return itemTypeRef;
1431 }
1432
1433 int xs__union::traverse(xs__schema &schema)
1434 { if (vflag)
1435 cerr << " Analyzing schema union" << endl;
1436 for (vector<xs__simpleType>::iterator i = simpleType.begin(); i != simpleType.end(); ++i)
1437 (*i).traverse(schema);
1438 return SOAP_OK;
1439 }
1440
1441 int xs__all::traverse(xs__schema &schema)
1442 { if (vflag)
1443 cerr << " Analyzing schema all" << endl;
1444 for (vector<xs__element>::iterator i = element.begin(); i != element.end(); ++i)
1445 (*i).traverse(schema);
1446 return SOAP_OK;
1447 }
1448
1449 int xs__contents::traverse(xs__schema &schema)
1450 { switch (__union)
1451 { case SOAP_UNION_xs__union_content_element:
1452 if (__content.element)
1453 __content.element->traverse(schema);
1454 break;
1455 case SOAP_UNION_xs__union_content_group:
1456 if (__content.group)
1457 __content.group->traverse(schema);
1458 break;
1459 case SOAP_UNION_xs__union_content_choice:
1460 if (__content.choice)
1461 __content.choice->traverse(schema);
1462 break;
1463 case SOAP_UNION_xs__union_content_sequence:
1464 if (__content.sequence)
1465 __content.sequence->traverse(schema);
1466 break;
1467 case SOAP_UNION_xs__union_content_any:
1468 if (__content.any)
1469 __content.any->traverse(schema);
1470 break;
1471 }
1472 return SOAP_OK;
1473 }
1474
1475 xs__seqchoice::xs__seqchoice()
1476 { schemaRef = NULL;
1477 }
1478
1479 int xs__seqchoice::traverse(xs__schema &schema)
1480 { if (vflag)
1481 cerr << " Analyzing schema sequence/choice" << endl;
1482 schemaRef = &schema;
1483 for (vector<xs__contents>::iterator c = __contents.begin(); c != __contents.end(); ++c)
1484 (*c).traverse(schema);
1485 return SOAP_OK;
1486 }
1487
1488 void xs__seqchoice::schemaPtr(xs__schema *schema)
1489 { schemaRef = schema;
1490 }
1491
1492 xs__schema *xs__seqchoice::schemaPtr() const
1493 { return schemaRef;
1494 }
1495
1496 xs__attributeGroup::xs__attributeGroup()
1497 { schemaRef = NULL;
1498 attributeGroupRef = NULL;
1499 }
1500
1501 int xs__attributeGroup::traverse(xs__schema& schema)
1502 { if (vflag)
1503 cerr << " Analyzing schema attributeGroup" << endl;
1504 schemaRef = &schema;
1505 for (vector<xs__attribute>::iterator at = attribute.begin(); at != attribute.end(); ++at)
1506 (*at).traverse(schema);
1507 for (vector<xs__attributeGroup>::iterator ag = attributeGroup.begin(); ag != attributeGroup.end(); ++ag)
1508 (*ag).traverse(schema);
1509 attributeGroupRef = NULL;
1510 if (ref)
1511 { const char *token = qname_token(ref, schema.targetNamespace);
1512 if (token)
1513 { for (vector<xs__attributeGroup>::iterator i = schema.attributeGroup.begin(); i != schema.attributeGroup.end(); ++i)
1514 if (!strcmp((*i).name, token))
1515 { attributeGroupRef = &(*i);
1516 if (vflag)
1517 cerr << " Found attributeGroup '" << (name?name:"") << "' ref '" << (token?token:"") << "'" << endl;
1518 break;
1519 }
1520 }
1521 if (!attributeGroupRef)
1522 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
1523 { xs__schema *s = (*i).schemaPtr();
1524 if (s)
1525 { token = qname_token(ref, s->targetNamespace);
1526 if (token)
1527 { for (vector<xs__attributeGroup>::iterator j = s->attributeGroup.begin(); j != s->attributeGroup.end(); ++j)
1528 { if (!strcmp((*j).name, token))
1529 { attributeGroupRef = &(*j);
1530 if (vflag)
1531 cerr << " Found attribute Group '" << (name?name:"") << "' ref '" << (token?token:"") << "'" << endl;
1532 break;
1533 }
1534 }
1535 if (attributeGroupRef)
1536 break;
1537 }
1538 }
1539 }
1540 }
1541 if (!attributeGroupRef)
1542 if (!Wflag)
1543 cerr << "Warning: could not find attributeGroup '" << (name?name:"") << "' ref '" << (ref?ref:"") << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
1544 }
1545 return SOAP_OK;
1546 }
1547
1548 void xs__attributeGroup::schemaPtr(xs__schema *schema)
1549 { schemaRef = schema;
1550 }
1551
1552 void xs__attributeGroup::attributeGroupPtr(xs__attributeGroup *attributeGroup)
1553 { attributeGroupRef = attributeGroup;
1554 }
1555
1556 xs__schema *xs__attributeGroup::schemaPtr() const
1557 { return schemaRef;
1558 }
1559
1560 xs__attributeGroup *xs__attributeGroup::attributeGroupPtr() const
1561 { return attributeGroupRef;
1562 }
1563
1564 int xs__any::traverse(xs__schema &schema)
1565 { if (vflag)
1566 cerr << " Analyzing schema any" << endl;
1567 for (vector<xs__element>::iterator i = element.begin(); i != element.end(); ++i)
1568 (*i).traverse(schema);
1569 return SOAP_OK;
1570 }
1571
1572 xs__group::xs__group()
1573 { schemaRef = NULL;
1574 groupRef = NULL;
1575 }
1576
1577 int xs__group::traverse(xs__schema &schema)
1578 { if (vflag)
1579 cerr << " Analyzing schema group" << endl;
1580 schemaRef = &schema;
1581 if (all)
1582 all->traverse(schema);
1583 else if (choice)
1584 choice->traverse(schema);
1585 else if (sequence)
1586 sequence->traverse(schema);
1587 groupRef = NULL;
1588 if (ref)
1589 { const char *token = qname_token(ref, schema.targetNamespace);
1590 if (token)
1591 { for (vector<xs__group>::iterator i = schema.group.begin(); i != schema.group.end(); ++i)
1592 if (!strcmp((*i).name, token))
1593 { groupRef = &(*i);
1594 if (vflag)
1595 cerr << " Found group '" << (name?name:"") << "' ref '" << (token?token:"") << "'" << endl;
1596 break;
1597 }
1598 }
1599 if (!groupRef)
1600 { for (vector<xs__import>::const_iterator i = schema.import.begin(); i != schema.import.end(); ++i)
1601 { xs__schema *s = (*i).schemaPtr();
1602 if (s)
1603 { token = qname_token(ref, s->targetNamespace);
1604 if (token)
1605 { for (vector<xs__group>::iterator j = s->group.begin(); j != s->group.end(); ++j)
1606 { if (!strcmp((*j).name, token))
1607 { groupRef = &(*j);
1608 if (vflag)
1609 cerr << " Found group '" << (name?name:"") << "' ref '" << (token?token:"") << "'" << endl;
1610 break;
1611 }
1612 }
1613 if (groupRef)
1614 break;
1615 }
1616 }
1617 }
1618 }
1619 if (!groupRef)
1620 if (!Wflag)
1621 cerr << "Warning: could not find group '" << (name?name:"") << "' ref '" << (ref?ref:"") << "' in schema '" << (schema.targetNamespace?schema.targetNamespace:"") << "'" << endl;
1622 }
1623 return SOAP_OK;
1624 }
1625
1626 void xs__group::schemaPtr(xs__schema *schema)
1627 { schemaRef = schema;
1628 }
1629
1630 xs__schema* xs__group::schemaPtr() const
1631 { return schemaRef;
1632 }
1633
1634 void xs__group::groupPtr(xs__group *group)
1635 { groupRef = group;
1636 }
1637
1638 xs__group* xs__group::groupPtr() const
1639 { return groupRef;
1640 }
1641
1642 int xs__enumeration::traverse(xs__schema &schema)
1643 { if (vflag)
1644 cerr << " Analyzing schema enumeration '" << (value?value:"") << "'" << endl;
1645 return SOAP_OK;
1646 }
1647
1648 int xs__pattern::traverse(xs__schema &schema)
1649 { if (vflag)
1650 cerr << " Analyzing schema pattern" << endl;
1651 return SOAP_OK;
1652 }
1653
1654 ////////////////////////////////////////////////////////////////////////////////
1655 //
1656 // I/O
1657 //
1658 ////////////////////////////////////////////////////////////////////////////////
1659
1660 ostream &operator<<(ostream &o, const xs__schema &e)
1661 { if (!e.soap)
1662 { struct soap soap;
1663 soap_init2(&soap, SOAP_IO_DEFAULT, SOAP_XML_TREE | SOAP_C_UTFSTRING);
1664 soap_set_namespaces(&soap, namespaces);
1665 e.soap_serialize(&soap);
1666 soap_begin_send(&soap);
1667 e.soap_out(&soap, "xs:schema", 0, NULL);
1668 soap_end_send(&soap);
1669 soap_end(&soap);
1670 soap_done(&soap);
1671 }
1672 else
1673 { ostream *os = e.soap->os;
1674 e.soap->os = &o;
1675 e.soap_serialize(e.soap);
1676 soap_begin_send(e.soap);
1677 e.soap_out(e.soap, "xs:schema", 0, NULL);
1678 soap_end_send(e.soap);
1679 e.soap->os = os;
1680 }
1681 return o;
1682 }
1683
1684 istream &operator>>(istream &i, xs__schema &e)
1685 { if (!e.soap)
1686 { e.soap = soap_new();
1687 soap_set_namespaces(e.soap, namespaces);
1688 }
1689 istream *is = e.soap->is;
1690 e.soap->is = &i;
1691 if (soap_begin_recv(e.soap)
1692 || !e.soap_in(e.soap, "xs:schema", NULL)
1693 || soap_end_recv(e.soap))
1694 { // handle error? Note: e.soap->error is set and app should check
1695 }
1696 e.soap->is = is;
1697 return i;
1698 }
1699