⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsdl.cpp

📁 一款开源的soap库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    }  }  if (!messageRef)    cerr << "Warning: no fault '" << (name?name:"") << "' message '" << (message?message:"") << "' in WSDL definitions '" << (definitions.name?definitions.name:"") << "' namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;  return SOAP_OK;}void wsdl__fault::messagePtr(wsdl__message *message){ messageRef = message;}wsdl__message *wsdl__fault::messagePtr() const{ return messageRef;}int wsdl__message::traverse(wsdl__definitions& definitions){ if (vflag)    cerr << "Analyzing wsdl message" << endl;  for (vector<wsdl__part>::iterator i = part.begin(); i != part.end(); ++i)    (*i).traverse(definitions);  return SOAP_OK;}wsdl__part::wsdl__part(){ elementRef = NULL;  simpleTypeRef = NULL;  complexTypeRef = NULL;}int wsdl__part::traverse(wsdl__definitions& definitions){ if (vflag)    cerr << "Analyzing wsdl part" << endl;  elementRef = NULL;  simpleTypeRef = NULL;  complexTypeRef = NULL;  if (definitions.types)  { for (vector<xs__schema*>::iterator schema = definitions.types->xs__schema_.begin(); schema != definitions.types->xs__schema_.end(); ++schema)    { const char *token = qname_token(element, (*schema)->targetNamespace);      if (token)      { for (vector<xs__element>::iterator element = (*schema)->element.begin(); element != (*schema)->element.end(); ++element)        { if ((*element).name && !strcmp((*element).name, token))          { elementRef = &(*element);            if (vflag)	      cerr << "Found part " << (name?name:"") << " element " << (token?token:"") << endl;            break;          }        }      }      token = qname_token(type, (*schema)->targetNamespace);      if (token)      { for (vector<xs__simpleType>::iterator simpleType = (*schema)->simpleType.begin(); simpleType != (*schema)->simpleType.end(); ++simpleType)        { if ((*simpleType).name && !strcmp((*simpleType).name, token))          { simpleTypeRef = &(*simpleType);            if (vflag)              cerr << "Found part " << (name?name:"") << " simpleType " << (token?token:"") << endl;            break;          }        }      }      token = qname_token(type, (*schema)->targetNamespace);      if (token)      { for (vector<xs__complexType>::iterator complexType = (*schema)->complexType.begin(); complexType != (*schema)->complexType.end(); ++complexType)        { if ((*complexType).name && !strcmp((*complexType).name, token))          { complexTypeRef = &(*complexType);            if (vflag)	      cerr << "Found part " << (name?name:"") << " complexType " << (token?token:"") << endl;            break;          }        }      }    }  }  if (!elementRef && !simpleTypeRef && !complexTypeRef)  { if (element)    { if (is_builtin_qname(element))	definitions.builtinElement(element);      else        cerr << "Warning: no part '" << (name?name:"") << "' element '" << element << "' in WSDL definitions '" << (definitions.name?definitions.name:"") << "' namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;    }    else if (type)    { if (is_builtin_qname(type))	definitions.builtinType(type);      else        cerr << "Warning: no part '" << (name?name:"") << "' type '" << type << "' in WSDL definitions '" << (definitions.name?definitions.name:"") << "' namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;    }    else      cerr << "Warning: no part '" << (name?name:"") << "' element or type in WSDL definitions '" << (definitions.name?definitions.name:"") << "' namespace " << (definitions.targetNamespace?definitions.targetNamespace:"") << endl;  }  return SOAP_OK;}void wsdl__part::elementPtr(xs__element *element){ elementRef = element;}void wsdl__part::simpleTypePtr(xs__simpleType *simpleType){ simpleTypeRef = simpleType;}void wsdl__part::complexTypePtr(xs__complexType *complexType){ complexTypeRef = complexType;}xs__element *wsdl__part::elementPtr() const{ return elementRef;}xs__simpleType *wsdl__part::simpleTypePtr() const{ return simpleTypeRef;}xs__complexType *wsdl__part::complexTypePtr() const{ return complexTypeRef;}int wsdl__types::preprocess(wsdl__definitions& definitions){ if (vflag)    cerr << "Preprocessing wsdl types" << endl;  // set the location of each schema in <types> to the WSDL's location  for (vector<xs__schema*>::iterator schema0 = xs__schema_.begin(); schema0 != xs__schema_.end(); ++schema0)  { if (!(*schema0)->sourceLocation())      (*schema0)->sourceLocation(definitions.sourceLocation());  }again:  // link imported schemas, need to repeat when <types> is extended with new imported schema (from inside another schema, etc.)  for (vector<xs__schema*>::iterator schema1 = xs__schema_.begin(); schema1 != xs__schema_.end(); ++schema1)  { for (vector<xs__import>::iterator import = (*schema1)->import.begin(); import != (*schema1)->import.end(); ++import)    { if ((*import).namespace_ && !(*import).schemaPtr())      { for (vector<xs__schema*>::const_iterator schema2 = xs__schema_.begin(); schema2 != xs__schema_.end(); ++schema2)        { if ((*schema2)->targetNamespace && !strcmp((*import).namespace_, (*schema2)->targetNamespace))          { (*import).schemaPtr(*schema2);	    break;	  }	}      }    }  }  // if a schema is imported but not in <types> then get it  for (vector<xs__schema*>::iterator schema2 = xs__schema_.begin(); schema2 != xs__schema_.end(); ++schema2)  { for (vector<xs__import>::iterator import = (*schema2)->import.begin(); import != (*schema2)->import.end(); ++import)    { bool found = false;      if ((*import).schemaPtr())        found = true;      if (vflag)        fprintf(stderr, "Preprocessing schema %s import %s\n", (*schema2)->targetNamespace, (*import).namespace_?(*import).namespace_:"");      if (!found && (*import).namespace_)      { if ((*import).schemaPtr())	  found = true;        else	{ for (vector<xs__schema*>::const_iterator schema3 = xs__schema_.begin(); schema3 != xs__schema_.end(); ++schema3)          { if ((*schema3)->targetNamespace && !strcmp((*import).namespace_, (*schema3)->targetNamespace))            { found = true;	      break;	    }	  }	}	if (!found)	{ for (SetOfString::const_iterator i = exturis.begin(); i != exturis.end(); ++i)	  { if (!soap_tag_cmp((*import).namespace_, *i))            { found = true;	      break;            }          }        }      }      if (!found && !iflag) // don't import any of the schemas in the .nsmap table (or when -i option is used)      { xs__schema *importschema;        importschema = (*import).schemaPtr();	if (!importschema)        { const char *s = (*import).schemaLocation;	  if (!s)	    s = (*import).namespace_;	  if (!s)	    continue;	  importschema = new xs__schema(definitions.soap, (*schema2)->sourceLocation(), s);	  if (!(*import).namespace_)	  { if ((*schema2)->targetNamespace)	      (*import).namespace_ = (*schema2)->targetNamespace;	    else if (importschema->targetNamespace)	      (*import).namespace_ = importschema->targetNamespace;	    else	      (*import).namespace_ = "";	  }	  if (!importschema->targetNamespace || !*importschema->targetNamespace)	    importschema->targetNamespace = (*import).namespace_;	  else if ((*import).namespace_ && strcmp(importschema->targetNamespace, (*import).namespace_))	    cerr << "Schema import namespace " << ((*import).namespace_?(*import).namespace_:"") << " does not correspond to imported targetNamespace " << importschema->targetNamespace << endl;	}        for (vector<xs__schema*>::const_iterator schema3 = xs__schema_.begin(); schema3 != xs__schema_.end(); ++schema3)        { if (schema3 != schema2 && (*schema3)->targetNamespace && !strcmp((*import).namespace_, (*schema3)->targetNamespace))          { found = true;	    (*import).schemaPtr(*schema3);	    break;	  }	}	if (!found)	{ (*import).schemaPtr(importschema);	  xs__schema_.push_back(importschema);          if (vflag)            fprintf(stderr, "Adding schema %s\n", importschema->targetNamespace);	  goto again;	}      }    }  }  return SOAP_OK;}int wsdl__types::traverse(wsdl__definitions& definitions){ if (vflag)    cerr << "Analyzing wsdl types" << endl;  for (vector<xs__schema*>::iterator schema3 = xs__schema_.begin(); schema3 != xs__schema_.end(); ++schema3)  { // artificially extend the <import> of each schema to include others so when we traverse schemas we can resolve references    for (vector<xs__schema*>::iterator importschema = xs__schema_.begin(); importschema != xs__schema_.end(); ++importschema)    { if (schema3 != importschema && (*importschema)->targetNamespace)      { xs__import *import = soap_new_xs__import(definitions.soap, -1);        import->namespace_ = (*importschema)->targetNamespace;        import->schemaPtr(*importschema);        (*schema3)->import.push_back(*import);      }    }    // check and report    for (vector<xs__import>::iterator import = (*schema3)->import.begin(); import != (*schema3)->import.end(); ++import)    { if ((*import).namespace_)      { bool found = false;        for (vector<xs__schema*>::const_iterator importschema = xs__schema_.begin(); importschema != xs__schema_.end(); ++importschema)	{ if ((*importschema)->targetNamespace && !strcmp((*import).namespace_, (*importschema)->targetNamespace))          { found = true;	    break;	  }        }	if (!found && vflag)	  cerr << "Schema import namespace " << (*import).namespace_ << " refers to a known external Schema" << endl;      }      else        cerr << "Warning: Schema import " << ((*import).schemaLocation ? (*import).schemaLocation : "") << " has no namespace" << endl;    }  }  // traverse the schemas  for (vector<xs__schema*>::iterator schema4 = xs__schema_.begin(); schema4 != xs__schema_.end(); ++schema4)    (*schema4)->traverse();  // find all built-in types, elements, and attributes  for (vector<xs__schema*>::iterator schema5 = xs__schema_.begin(); schema5 != xs__schema_.end(); ++schema5)  { if (vflag)      for (SetOfString::const_iterator i = (*schema5)->builtinTypes().begin(); i != (*schema5)->builtinTypes().end(); ++i)        cerr << "Found built-in schema type: " << (*i) << endl;    definitions.builtinTypes((*schema5)->builtinTypes());    definitions.builtinElements((*schema5)->builtinElements());    definitions.builtinAttributes((*schema5)->builtinAttributes());  }  return SOAP_OK;}int wsdl__import::preprocess(wsdl__definitions& definitions){ bool found = false;  if (vflag)    cerr << "Preprocess wsdl import " << (location?location:"") << endl;  definitionsRef = NULL;  if (namespace_)  { for (SetOfString::const_iterator i = exturis.begin(); i != exturis.end(); ++i)    { if (!soap_tag_cmp(namespace_, *i))      { found = true;        break;      }    }  }  if (!found && location)  { // parse imported definitions    definitionsRef = new wsdl__definitions(definitions.soap, definitions.sourceLocation(), location);    if (!definitionsRef)      return SOAP_EOF;    if (!namespace_)      namespace_ = definitionsRef->targetNamespace;    else if (!definitionsRef->targetNamespace || !*definitionsRef->targetNamespace)      definitionsRef->targetNamespace = namespace_;    else if (strcmp(namespace_, definitionsRef->targetNamespace))      cerr << "Error: WSDL definitions/import " << location << " namespace " << namespace_ << " does not match imported targetNamespace " << definitionsRef->targetNamespace << endl;  }  else if (!found)    cerr << "WSDL definitions/import has no location attribute" << endl;  return SOAP_OK;}int wsdl__import::traverse(wsdl__definitions& definitions){ if (vflag)    cerr << "Analyzing wsdl import " << (location?location:"") << endl;  if (definitionsRef)  { for (vector<wsdl__message>::iterator mg = definitionsRef->message.begin(); mg != definitionsRef->message.end(); ++mg)      (*mg).traverse(definitions);    // process portTypes before bindings    for (vector<wsdl__portType>::iterator pt = definitionsRef->portType.begin(); pt != definitionsRef->portType.end(); ++pt)      (*pt).traverse(definitions);    // process bindings    for (vector<wsdl__binding>::iterator bg = definitionsRef->binding.begin(); bg != definitionsRef->binding.end(); ++bg)      (*bg).traverse(definitions);    // process services    for (vector<wsdl__service>::iterator sv = definitionsRef->service.begin(); sv != definitionsRef->service.end(); ++sv)      (*sv).traverse(definitions);  }  return SOAP_OK;}void wsdl__import::definitionsPtr(wsdl__definitions *definitions){ definitionsRef = definitions;}wsdl__definitions *wsdl__import::definitionsPtr() const{ return definitionsRef;}wsdl__import::wsdl__import(){ definitionsRef = NULL;}////////////////////////////////////////////////////////////////////////////////////	streams//////////////////////////////////////////////////////////////////////////////////ostream &operator<<(ostream &o, const wsdl__definitions &e){ if (!e.soap)  { struct soap soap;    soap_init2(&soap, SOAP_IO_DEFAULT, SOAP_XML_TREE | SOAP_C_UTFSTRING);#ifdef WITH_NONAMESPACES    soap_set_namespaces(&soap, namespaces);#endif    e.soap_serialize(&soap);    soap_begin_send(&soap);    e.soap_out(&soap, "wsdl:definitions", 0, NULL);    soap_end_send(&soap);    soap_destroy(&soap);    soap_end(&soap);    soap_done(&soap);  }  else  { ostream *os = e.soap->os;    e.soap->os = &o;    e.soap_serialize(e.soap);    soap_begin_send(e.soap);    e.soap_out(e.soap, "wsdl:definitions", 0, NULL);    soap_end_send(e.soap);    e.soap->os = os;  }  return o;}istream &operator>>(istream &i, wsdl__definitions &e){ if (!e.soap)  { e.soap = soap_new1(SOAP_XML_TREE | SOAP_C_UTFSTRING);    soap_set_namespaces(e.soap, namespaces);  }  istream *is = e.soap->is;  e.soap->is = &i;  if (soap_begin_recv(e.soap)   || !e.soap_in(e.soap, "wsdl:definitions", NULL)   || soap_end_recv(e.soap))  { // handle error? Note: e.soap->error is set and app should check  }  e.soap->is = is;  return i;}////////////////////////////////////////////////////////////////////////////////////	Miscellaneous//////////////////////////////////////////////////////////////////////////////////int warn_ignore(struct soap *soap, const char *tag){ // We don't warn if the omitted element was an annotation or a documentation in an unexpected place  if (soap_match_tag(soap, tag, "xs:annotation")   && soap_match_tag(soap, tag, "xs:documentation")   && soap_match_tag(soap, tag, "xs:appinfo"))    fprintf(stderr, "Warning: element '%s' at level %d was not recognized and will be ignored\n", tag, soap->level);  if (!soap_string_in(soap, 0, -1, -1))    return soap->error;  return SOAP_OK;}int show_ignore(struct soap *soap, const char *tag){ warn_ignore(soap, tag);  soap_print_fault_location(soap, stderr);  return SOAP_OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -