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

📄 dom++.cpp

📁 linux下简单对象应用协议的开发库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        return soap->error;      if (!prefix)      { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of DOM node '%s'\n", tag + colon));        if (soap_element_end_out(soap, tag + colon))          return soap->error;      }      else      { char *s;        if (strlen(prefix) + strlen(tag + colon) < sizeof(soap->msgbuf))	  s = soap->msgbuf;	else	{ s = (char*)SOAP_MALLOC(soap, strlen(prefix) + strlen(tag + colon) + 2);          if (!s)            return soap->error = SOAP_EOM;	}	sprintf(s, "%s:%s", prefix, tag + colon);        DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of DOM node '%s'\n", s));        if (soap_element_end_out(soap, s))          return soap->error;        if (s != soap->msgbuf)	  SOAP_FREE(soap, s);      }      if (p)        p->level = 0; /* xmlns binding is out of scope */    }  }  return SOAP_OK;}/******************************************************************************/SOAP_FMAC1intSOAP_FMAC2soap_out_xsd__anyAttribute(struct soap *soap, const char *tag, int id, const struct soap_dom_attribute *node, const char *type){ if (!(soap->mode & SOAP_DOM_ASIS))  { const struct soap_dom_attribute *att;    for (att = node; att; att = att->next)    { if (att->name && att->data && !strncmp(att->name, "xmlns:", 6))      { if (!(soap_enter_ns_prefix(soap, att->name + 6, att->data)))          return soap->error = SOAP_EOM;      }      else if (att->name && att->nstr)      { const char *prefix;        if ((prefix = strchr(att->name, ':')))        { size_t colon = prefix - att->name + 1;          if (colon > sizeof(soap->tag))            colon = sizeof(soap->tag);          strncpy(soap->tag, att->name, colon - 1);          soap->tag[colon - 1] = '\0';          if (!(soap_enter_ns_prefix(soap, soap->tag, att->nstr)))            return soap->error = SOAP_EOM;        }      }    }  }  while (node)  { if (node->name)    { if (node->nstr && !(soap->mode & SOAP_DOM_ASIS) && !strchr(node->name, ':'))      { struct soap_ilist *q;        if ((q = soap_lookup_ns_prefix(soap, node->nstr)))        { if (out_attribute(soap, q->id, node->name, node->data, node->wide, 1))            return soap->error;        }        else        { struct Namespace *ns;          for (ns = soap->local_namespaces; ns && ns->id; ns++)          { if (ns->ns == node->nstr || !strcmp(ns->ns, node->nstr))            { /* don't prefix attributes that start with 'xml' */    	      if (out_attribute(soap, strncmp(node->name, "xml", 3) ? ns->id : NULL, node->name, node->data, node->wide, 1))                return soap->error;              break;            }          }          if (!ns || !ns->id)          { sprintf(soap->msgbuf, "xmlns:"SOAP_DOMID_FORMAT, soap->idnum++);            if (soap_set_attr(soap, soap->msgbuf, node->nstr))              return soap->error;            strcat(soap->msgbuf, ":");            strcat(soap->msgbuf, node->name);            if (out_attribute(soap, NULL, soap->msgbuf + 6, node->data, node->wide, 1))              return soap->error;          }        }      }      else      { out_attribute(soap, NULL, node->name, node->data, node->wide, 1);      }    }    node = node->next;  }  return SOAP_OK;}/******************************************************************************/SOAP_FMAC1struct soap_dom_element *SOAP_FMAC2soap_in_xsd__anyType(struct soap *soap, const char *tag, struct soap_dom_element *node, const char *type){ register struct soap_attribute *tp;  register struct soap_dom_attribute **att;  if (soap_peek_element(soap))    return NULL;  if (!node)  { if (!(node = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element))))    { soap->error = SOAP_EOM;      return NULL;    }  }  soap_default_xsd__anyType(soap, node);  node->nstr = soap_current_namespace(soap, soap->tag);  if ((soap->mode & SOAP_DOM_ASIS))    node->name = soap_strdup(soap, soap->tag);  else  { char *s = strchr(soap->tag, ':');    if (s)      node->name = soap_strdup(soap, s+1);    else      node->name = soap_strdup(soap, soap->tag);  }  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node %s in namespace %s\n", node->name, node->nstr?node->nstr:""));  if ((soap->mode & SOAP_DOM_NODE) || (!(soap->mode & SOAP_DOM_TREE) && *soap->id))  { if ((node->node = soap_getelement(soap, &node->type)))    { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node contains type %d from xsi:type\n", node->type));      return node;    }    if (soap->error == SOAP_TAG_MISMATCH)      soap->error = SOAP_OK;    else      return NULL;  }  att = &node->atts;  for (tp = soap->attributes; tp; tp = tp->next)  { if (tp->visible)    { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node attribute='%s'\n", tp->name));      *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));      if (!*att)      { soap->error = SOAP_EOM;        return NULL;      }      (*att)->next = NULL;      (*att)->nstr = soap_current_namespace(soap, tp->name);      if ((soap->mode & SOAP_DOM_ASIS) || !strncmp(tp->name, "xml", 3))        (*att)->name = soap_strdup(soap, tp->name);      else      { char *s = strchr(tp->name, ':');        if (s)          (*att)->name = soap_strdup(soap, s+1);        else          (*att)->name = soap_strdup(soap, tp->name);      }      if (tp->visible == 2)        (*att)->data = soap_strdup(soap, tp->value);      else        (*att)->data = NULL;      (*att)->wide = NULL;      (*att)->soap = soap;      att = &(*att)->next;      tp->visible = 0;    }  }  soap_element_begin_in(soap, NULL, 1, NULL);  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' pulled\n", node->name));  if (soap->body)  { if (!soap_peek_element(soap))    { struct soap_dom_element **elt;      DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' has subelements\n", node->name));      elt = &node->elts;      for (;;)      { if (!(*elt = soap_in_xsd__anyType(soap, NULL, NULL, NULL)))        { if (soap->error == SOAP_NO_TAG)            soap->error = SOAP_OK;          else            return NULL;          break;        }	(*elt)->prnt = node;        elt = &(*elt)->next;      }    }    else if (soap->error == SOAP_NO_TAG)    { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' has cdata\n", node->name));      if ((soap->mode & SOAP_C_UTFSTRING) || (soap->mode & SOAP_C_MBSTRING))      { if (!(node->data = soap_string_in(soap, 1, -1, -1)))          return NULL;      }      else if (!(node->wide = soap_wstring_in(soap, 1, -1, -1)))        return NULL;    }    else      return NULL;    if (soap_element_end_in(soap, node->name))      return NULL;    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of DOM node '%s'\n", node->name));  }  return node;}/******************************************************************************/SOAP_FMAC1struct soap_dom_attribute *SOAP_FMAC2soap_in_xsd__anyAttribute(struct soap *soap, const char *tag, struct soap_dom_attribute *node, const char *type){ register struct soap_attribute *tp;  struct soap_dom_attribute *tmp = node;  struct soap_dom_attribute *att = node;  for (tp = soap->attributes; tp; tp = tp->next)  { if (tp->visible)    { if (!att)      { att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));        if (tmp)	  tmp->next = att;	else	  node = att;        tmp = att;      }      DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node attribute='%s'\n", tp->name));      if (!att)      { soap->error = SOAP_EOM;        return NULL;      }      att->next = NULL;      att->nstr = soap_current_namespace(soap, tp->name);      if ((soap->mode & SOAP_DOM_ASIS) || !strncmp(tp->name, "xml", 3))        att->name = soap_strdup(soap, tp->name);      else      { char *s = strchr(tp->name, ':');        if (s)          att->name = soap_strdup(soap, s+1);	else          att->name = soap_strdup(soap, tp->name);      }      if (tp->visible == 2)        att->data = soap_strdup(soap, tp->value);      else        att->data = NULL;      att->wide = NULL;      att->soap = soap;      att = NULL;    }  }  return node;}/******************************************************************************\ * *	DOM traversing *\******************************************************************************/SOAP_FMAC1struct soap_dom_element *SOAP_FMAC2soap_dom_next_element(struct soap_dom_element *elt){ if (elt->elts)    return elt->elts;  if (elt->next)    return elt->next;  do elt = elt->prnt;  while (elt && !elt->next);  if (elt)    elt = elt->next;  return elt;}/******************************************************************************/struct soap_dom_attribute *soap_dom_next_attribute(struct soap_dom_attribute *att){ return att->next;}/******************************************************************************\ * *	Namespace prefix lookup/store *\******************************************************************************/static struct soap_ilist *soap_lookup_ns_prefix(struct soap *soap, const char *nstr){ register struct soap_ilist *ip;  for (ip = soap->iht[soap_hash(nstr)]; ip; ip = ip->next)    if (!strcmp((char*)ip->ptr, nstr) && ip->level)      return ip;  return NULL;}/******************************************************************************/static struct soap_ilist *soap_enter_ns_prefix(struct soap *soap, const char *prefix, const char *nstr){ size_t h;  register struct soap_ilist *ip;  for (ip = soap->iht[soap_hash(nstr)]; ip; ip = ip->next)  { if (!strcmp((char*)ip->ptr, nstr) && !ip->level)    { strcpy(ip->id, prefix);      ip->level = 1;      return ip;    }  }  ip = (struct soap_ilist*)SOAP_MALLOC(soap, sizeof(struct soap_ilist) + strlen(nstr) + SOAP_TAGLEN);  if (ip)  { h = soap_hash(nstr);    strcpy(ip->id, prefix);    ip->ptr = ip->id + SOAP_TAGLEN;    strcpy((char*)ip->ptr, nstr);    ip->next = soap->iht[h];    soap->iht[h] = ip;    ip->flist = NULL;    ip->copy = NULL;    ip->level = 1;    return ip;  }  return NULL;}#ifdef __cplusplus/******************************************************************************\ * *	soap_dom_element class *\******************************************************************************/soap_dom_element::soap_dom_element(){ soap_default_xsd__anyType(NULL, this);}/******************************************************************************/soap_dom_element::soap_dom_element(struct soap *soap){ soap_default_xsd__anyType(soap, this);}/******************************************************************************/soap_dom_element::soap_dom_element(struct soap *soap, const char *nstr, const char *name){ soap_default_xsd__anyType(soap, this);  this->nstr = soap_strdup(soap, nstr);  this->name = soap_strdup(soap, name);}/******************************************************************************/soap_dom_element::soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data){ soap_default_xsd__anyType(soap, this);  this->nstr = soap_strdup(soap, nstr);  this->name = soap_strdup(soap, name);  this->data = soap_strdup(soap, data);}/******************************************************************************/soap_dom_element::soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type){ soap_default_xsd__anyType(soap, this);  this->nstr = soap_strdup(soap, nstr);  this->name = soap_strdup(soap, name);  this->node = node;  this->type = type;}/******************************************************************************/soap_dom_element::~soap_dom_element(){ }/******************************************************************************/soap_dom_element &soap_dom_element::set(const char *nstr, const char *name){ this->nstr = soap_strdup(soap, nstr);  this->name = soap_strdup(soap, name);  return *this;}/******************************************************************************/soap_dom_element &soap_dom_element::set(const char *data)

⌨️ 快捷键说明

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