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

📄 schema.cpp

📁 linux下简单对象应用协议的开发库
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*schema.cppXSD binding schema implementation--------------------------------------------------------------------------------gSOAP XML Web services toolsCopyright (C) 2001-2007, Robert van Engelen, Genivia Inc. All Rights Reserved.This software is released under one of the following two licenses:GPL or Genivia's license for commercial use.--------------------------------------------------------------------------------GPL license.This program is free software; you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the Free SoftwareFoundation; either version 2 of the License, or (at your option) any laterversion.This program is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along withthis program; if not, write to the Free Software Foundation, Inc., 59 TemplePlace, Suite 330, Boston, MA 02111-1307 USAAuthor contact information:engelen@genivia.com / engelen@acm.org--------------------------------------------------------------------------------A commercial use license is available from Genivia, Inc., contact@genivia.com--------------------------------------------------------------------------------*/#include "wsdlH.h"		// cannot include "schemaH.h"#include "includes.h"extern struct Namespace namespaces[];extern int warn_ignore(struct soap*, const char*);extern const char *qname_token(const char*, const char*);extern int is_builtin_qname(const char*);////////////////////////////////////////////////////////////////////////////////////	schema//////////////////////////////////////////////////////////////////////////////////xs__schema::xs__schema(){ soap = soap_new1(SOAP_XML_TREE | SOAP_C_UTFSTRING);#ifdef WITH_OPENSSL  soap_ssl_client_context(soap, SOAP_SSL_NO_AUTHENTICATION, NULL, NULL, NULL, NULL, NULL);#endif  soap_set_namespaces(soap, namespaces);  soap_default(soap);  soap->fignore = warn_ignore;  soap->encodingStyle = NULL;  soap->proxy_host = proxy_host;  soap->proxy_port = proxy_port;  targetNamespace = NULL;  version = NULL;  updated = false;  location = NULL;  redirs = 0;}xs__schema::xs__schema(struct soap *copy){ soap = soap_copy(copy);  soap_default(soap);  soap->fignore = warn_ignore;  soap->encodingStyle = NULL;  targetNamespace = NULL;  version = NULL;  updated = false;  location = NULL;  redirs = 0;}xs__schema::xs__schema(struct soap *copy, const char *cwd, const char *loc){ soap = soap_copy(copy);  soap->socket = SOAP_INVALID_SOCKET;  soap->recvfd = 0;  soap->sendfd = 1;  /* no longer required, since we keep the host name:  strcpy(soap->host, copy->host);  */  soap_default(soap);  soap->fignore = warn_ignore;  soap->encodingStyle = NULL;  targetNamespace = NULL;  version = NULL;  updated = false;  location = NULL;  redirs = 0;  read(cwd, loc);}xs__schema::~xs__schema(){ }int xs__schema::get(struct soap *soap){ return preprocess();}int xs__schema::preprocess(){ // process xs:include recursively, but should check if not already included?  // NOTE: includes are context sensitive (take context info), so keep including  for (vector<xs__include>::iterator in = include.begin(); in != include.end(); ++in)  { (*in).preprocess(*this); // read schema and recurse over <include>    if ((*in).schemaPtr())      insert(*(*in).schemaPtr());  }  for (vector<xs__redefine>::iterator re = redefine.begin(); re != redefine.end(); ++re)  { (*re).preprocess(*this); // read schema and recurse over <redefine>    if ((*re).schemaPtr())      insert(*(*re).schemaPtr());  }  return SOAP_OK;}int xs__schema::insert(xs__schema& schema){ bool found;  if (targetNamespace && schema.targetNamespace && strcmp(targetNamespace, schema.targetNamespace))    fprintf(stderr, "Warning: attempt to include schema with mismatching targetNamespace '%s' in schema '%s'\n", schema.targetNamespace, targetNamespace);  if (elementFormDefault != schema.elementFormDefault)    fprintf(stderr, "Warning: attempt to include schema with mismatching elementFormDefault in schema '%s'\n", targetNamespace?targetNamespace:"");  if (attributeFormDefault != schema.attributeFormDefault)    fprintf(stderr, "Warning: attempt to include schema with mismatching attributeFormDefault in schema '%s'\n", targetNamespace?targetNamespace:"");  // insert imports, but only add imports with new namespace  for (vector<xs__import>::const_iterator im = schema.import.begin(); im != schema.import.end(); ++im)  { found = false;    if ((*im).namespace_)    { for (vector<xs__import>::const_iterator i = import.begin(); i != import.end(); ++i)      { if ((*i).namespace_ && !strcmp((*im).namespace_, (*i).namespace_))        { found = true;          break;        }      }    }    if (!found)      import.push_back(*im);  }  // insert attributes, but only add attributes with new name (limited conflict check)  for (vector<xs__attribute>::const_iterator at = schema.attribute.begin(); at != schema.attribute.end(); ++at)  { found = false;    if ((*at).name)    { for (vector<xs__attribute>::const_iterator a = attribute.begin(); a != attribute.end(); ++a)      { if ((*a).name && !strcmp((*at).name, (*a).name))        { found = true;          if ((*at).type && (*a).type && strcmp((*at).type, (*a).type))            fprintf(stderr, "Warning: attempt to redefine attribute '%s' with type '%s' in schema '%s'\n", (*at).name, (*at).type, targetNamespace?targetNamespace:"");          break;        }      }    }    if (!found)    { attribute.push_back(*at);      attribute.back().schemaPtr(this);    }  }  // insert elements, but only add elements with new name (limited conflict check)  for (vector<xs__element>::const_iterator el = schema.element.begin(); el != schema.element.end(); ++el)  { found = false;    if ((*el).name)    { for (vector<xs__element>::const_iterator e = element.begin(); e != element.end(); ++e)      { if ((*e).name && !strcmp((*el).name, (*e).name))        { found = true;          if ((*el).type && (*e).type && strcmp((*el).type, (*e).type))            fprintf(stderr, "Warning: attempt to redefine element '%s' with type '%s' in schema '%s'\n", (*el).name, (*el).type, targetNamespace?targetNamespace:"");          break;        }      }    }    if (!found)    { element.push_back(*el);      element.back().schemaPtr(this);    }  }  // insert groups, but only add groups with new name (no conflict check)  for (vector<xs__group>::const_iterator gp = schema.group.begin(); gp != schema.group.end(); ++gp)  { found = false;    if ((*gp).name)    { for (vector<xs__group>::const_iterator g = group.begin(); g != group.end(); ++g)      { if ((*g).name && !strcmp((*gp).name, (*g).name))        { found = true;          break;        }      }    }    if (!found)    { group.push_back(*gp);      group.back().schemaPtr(this);    }  }  // insert attributeGroups, but only add attributeGroups with new name (no conflict check)  for (vector<xs__attributeGroup>::const_iterator ag = schema.attributeGroup.begin(); ag != schema.attributeGroup.end(); ++ag)  { found = false;    if ((*ag).name)    { for (vector<xs__attributeGroup>::const_iterator g = attributeGroup.begin(); g != attributeGroup.end(); ++g)      { if ((*g).name && !strcmp((*ag).name, (*g).name))        { found = true;          break;        }      }    }    if (!found)    { attributeGroup.push_back(*ag);      attributeGroup.back().schemaPtr(this);    }  }  // insert simpleTypes, but only add simpleTypes with new name (no conflict check)  for (vector<xs__simpleType>::const_iterator st = schema.simpleType.begin(); st != schema.simpleType.end(); ++st)  { found = false;    if ((*st).name)    { for (vector<xs__simpleType>::const_iterator s = simpleType.begin(); s != simpleType.end(); ++s)      { if ((*s).name && !strcmp((*st).name, (*s).name))        { found = true;          break;        }      }    }    if (!found)    { simpleType.push_back(*st);      simpleType.back().schemaPtr(this);    }  }  // insert complexTypes, but only add complexTypes with new name (no conflict check)  for (vector<xs__complexType>::const_iterator ct = schema.complexType.begin(); ct != schema.complexType.end(); ++ct)  { found = false;    if ((*ct).name)    { for (vector<xs__complexType>::const_iterator c = complexType.begin(); c != complexType.end(); ++c)      { if ((*c).name && !strcmp((*ct).name, (*c).name))        { found = true;          break;        }      }    }    if (!found)    { complexType.push_back(*ct);      complexType.back().schemaPtr(this);    }  }  return SOAP_OK;}int xs__schema::traverse(){ if (vflag)    cerr << "Analyzing schema " << (targetNamespace?targetNamespace:"") << endl;  if (updated)    return SOAP_OK;  updated = true;  if (!targetNamespace)  { if (vflag)      fprintf(stderr, "Warning: Schema has no targetNamespace\n");    targetNamespace = "";  }  else if (exturis.find(targetNamespace) != exturis.end())  { if (vflag)      fprintf(stderr, "Warning: Built-in schema '%s' content encountered\n", targetNamespace);  }  // process import  for (vector<xs__import>::iterator im = import.begin(); im != import.end(); ++im)    (*im).traverse(*this);  // process attributes  for (vector<xs__attribute>::iterator at = attribute.begin(); at != attribute.end(); ++at)    (*at).traverse(*this);  // process elements  for (vector<xs__element>::iterator el = element.begin(); el != element.end(); ++el)    (*el).traverse(*this);  // process simpleTypes, check conflicts with complexTypes  for (vector<xs__simpleType>::iterator st = simpleType.begin(); st != simpleType.end(); ++st)  { (*st).traverse(*this);    if ((*st).name)    { for (vector<xs__complexType>::iterator ct = complexType.begin(); ct != complexType.end(); ++ct)        if ((*ct).name && !strcmp((*st).name, (*ct).name))          fprintf(stderr, "Warning: top-level simpleType name and complexType name '%s' clash in schema '%s'\n", (*st).name, targetNamespace?targetNamespace:"");    }  }  // process complexTypes  for (vector<xs__complexType>::iterator ct = complexType.begin(); ct != complexType.end(); ++ct)    (*ct).traverse(*this);  // process groups  for (vector<xs__group>::iterator gp = group.begin(); gp != group.end(); ++gp)    (*gp).traverse(*this);  // process attributeGroups  for (vector<xs__attributeGroup>::iterator ag = attributeGroup.begin(); ag != attributeGroup.end(); ++ag)    (*ag).traverse(*this);  if (vflag)    cerr << "End of schema " << (targetNamespace?targetNamespace:"") << endl;  return SOAP_OK;}int xs__schema::read(const char *cwd, const char *loc){ const char *cwd_temp;  if (!cwd)    cwd = cwd_path;  if (vflag)    fprintf(stderr, "Opening schema '%s' from '%s'\n", loc?loc:"", cwd?cwd:"");  if (loc)  {#ifdef WITH_OPENSSL    if (!strncmp(loc, "http://", 7) || !strncmp(loc, "https://", 8))#else    if (!strncmp(loc, "https://", 8))    { fprintf(stderr, "Cannot connect to https site: no SSL support, please rebuild with 'make secure' or download the files and rerun wsdl2h\n");      exit(1);    }    else if (!strncmp(loc, "http://", 7))#endif    { fprintf(stderr, "Connecting to '%s' to retrieve schema... ", loc);      location = soap_strdup(soap, loc);      if (soap_connect_command(soap, SOAP_GET, location, NULL))      { fprintf(stderr, "connection failed\n");        exit(1);      }      fprintf(stderr, "connected, receiving...\n");    }    else if (cwd && (!strncmp(cwd, "http://", 7) || !strncmp(cwd, "https://", 8)))    { char *s;      location = (char*)soap_malloc(soap, strlen(cwd) + strlen(loc) + 2);      strcpy(location, cwd);      s = strrchr(location, '/');      if (s)        *s = '\0';      strcat(location, "/");      strcat(location, loc);      fprintf(stderr, "Connecting to '%s' to retrieve relative '%s' schema... ", location, loc);      if (soap_connect_command(soap, SOAP_GET, location, NULL))      { fprintf(stderr, "connection failed\n");        exit(1);      }      fprintf(stderr, "connected, receiving...\n");    }    else    { soap->recvfd = open(loc, O_RDONLY, 0);      if (soap->recvfd < 0)      { if (cwd)        { char *s;          location = (char*)soap_malloc(soap, strlen(cwd) + strlen(loc) + 2);          strcpy(location, cwd);          s = strrchr(location, '/');          if (s)            *s = '\0';          strcat(location, "/");          strcat(location, loc);          soap->recvfd = open(location, O_RDONLY, 0);        }        if (soap->recvfd < 0 && import_path)        { location = (char*)soap_malloc(soap, strlen(import_path) + strlen(loc) + 2);          strcpy(location, import_path);          strcat(location, "/");          strcat(location, loc);          soap->recvfd = open(location, O_RDONLY, 0);        }        if (soap->recvfd < 0)        { fprintf(stderr, "Cannot open '%s' to retrieve schema\n", loc);          exit(1);        }      }      else        location = soap_strdup(soap, loc);      fprintf(stderr, "Reading schema file '%s'\n", location);    }  }  cwd_temp = cwd_path;  cwd_path = location;  if (!soap_begin_recv(soap))    this->soap_in(soap, "xs:schema", NULL);  if ((soap->error >= 301 && soap->error <= 303) || soap->error == 307) // HTTP redirect, socket was closed  { int r = SOAP_ERR;    fprintf(stderr, "Redirected to '%s'\n", soap->endpoint);    if (redirs++ < 10)      r = read(cwd, soap->endpoint);    else      fprintf(stderr, "Max redirects exceeded\n");    redirs--;    return r;  }  if (soap->error)  { fprintf(stderr, "An error occurred while parsing schema from '%s'\n", loc?loc:"");    soap_print_fault(soap, stderr);    soap_print_fault_location(soap, stderr);    exit(1);  }  soap_end_recv(soap);  if (soap->recvfd > 2)  { close(soap->recvfd);    soap->recvfd = -1;  }  else    soap_closesock(soap);  cwd_path = cwd_temp;  return SOAP_OK;

⌨️ 快捷键说明

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