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

📄 stdsoap2.cpp

📁 linux下简单对象应用协议的开发库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************/#ifndef PALM_1SOAP_FMAC1const char*SOAP_FMAC2soap_code_list(struct soap *soap, const struct soap_code_map *code_map, long code){ register char *t = soap->tmpbuf;  if (code_map)  { while (code_map->string)    { if (code_map->code & code)      { register const char *s = code_map->string;        if (t != soap->tmpbuf)          *t++ = ' ';        while (*s && t < soap->tmpbuf + sizeof(soap->tmpbuf) - 1)          *t++ = *s++;        if (t == soap->tmpbuf + sizeof(soap->tmpbuf) - 1)          break;      }      code_map++;    }  }  *t = '\0';  return soap->tmpbuf;}#endif/******************************************************************************/#ifndef PALM_1static soap_wcharsoap_char(struct soap *soap){ char tmp[8];  register int i;  register soap_wchar c;  register char *s = tmp;  for (i = 0; i < 7; i++)  { c = soap_get1(soap);    if (c == ';' || (int)c == EOF)      break;    *s++ = (char)c;  }  *s = '\0';  if (*tmp == '#')  { if (tmp[1] == 'x' || tmp[1] == 'X')      return soap_strtol(tmp + 2, NULL, 16);    return atol(tmp + 1);  }  if (!strcmp(tmp, "lt"))    return '<';  if (!strcmp(tmp, "gt"))    return '>';  if (!strcmp(tmp, "amp"))    return '&';  if (!strcmp(tmp, "quot"))    return '"';  if (!strcmp(tmp, "apos"))    return '\'';#ifndef WITH_LEAN  return (soap_wchar)soap_code_int(html_entity_codes, tmp, SOAP_UNKNOWN_CHAR);#else  return SOAP_UNKNOWN_CHAR; /* use this to represent unknown code */#endif}#endif/******************************************************************************/#ifdef WITH_LEAN#ifndef PALM_1soap_wcharsoap_get0(struct soap *soap){ if (soap->bufidx >= soap->buflen && soap_recv(soap))    return EOF;  return (unsigned char)soap->buf[soap->bufidx];}#endif#endif/******************************************************************************/#ifdef WITH_LEAN#ifndef PALM_1soap_wcharsoap_get1(struct soap *soap){ if (soap->bufidx >= soap->buflen && soap_recv(soap))    return EOF;  return (unsigned char)soap->buf[soap->bufidx++];}#endif#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1soap_wcharSOAP_FMAC2soap_get(struct soap *soap){ register soap_wchar c;  c = soap->ahead;  if (c)  { if ((int)c != EOF)      soap->ahead = 0;  }  else    c = soap_get1(soap);  while ((int)c != EOF)  { if (soap->cdata)    { if (c == ']')      { c = soap_get1(soap);        if (c == ']')        { c = soap_get0(soap);          if (c == '>')          { soap->cdata = 0;            soap_get1(soap);            c = soap_get1(soap);          }          else          { soap_unget(soap, ']');            return ']';          }        }        else        { soap_revget1(soap);          return ']';        }      }      else        return c;    }    switch (c)    { case '<':        do c = soap_get1(soap);        while (soap_blank(c));        if (c == '!' || c == '?' || c == '%')        { register int k = 1;          if (c == '!')          { c = soap_get1(soap);            if (c == '[')            { do c = soap_get1(soap);              while ((int)c != EOF && c != '[');              if ((int)c == EOF)                break;              soap->cdata = 1;              c = soap_get1(soap);              continue;            }            if (c == '-' && (c = soap_get1(soap)) == '-')            { do              { c = soap_get1(soap);                if (c == '-' && (c = soap_get1(soap)) == '-')                  break;              } while ((int)c != EOF);            }          }          else if (c == '?')            c = soap_get_pi(soap);          while ((int)c != EOF)          { if (c == '<')              k++;            else if (c == '>')            { if (--k <= 0)                break;            }            c = soap_get1(soap);          }          if ((int)c == EOF)            break;          c = soap_get1(soap);          continue;        }        if (c == '/')          return SOAP_TT;        soap_revget1(soap);        return SOAP_LT;      case '>':        return SOAP_GT;      case '"':        return SOAP_QT;      case '\'':        return SOAP_AP;      case '&':        return soap_char(soap) | 0x80000000;    }    break;  }  return c;}#endif/******************************************************************************/#ifndef PALM_1static soap_wcharsoap_get_pi(struct soap *soap){ char buf[64];  register char *s = buf;  register int i = sizeof(buf);  register soap_wchar c = soap_getchar(soap);  /* This is a quick way to parse XML PI and we could use a callback instead to   * enable applications to intercept processing instructions */  while ((int)c != EOF && c != '?')  { if (--i > 0)    { if (soap_blank(c))        c = ' ';      *s++ = (char)c;    }    c = soap_getchar(soap);  }  *s = '\0';  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI <?%s?>\n", buf));  if (!strncmp(buf, "xml ", 4))  { s = strstr(buf, " encoding=");    if (s && s[10])    { if (!soap_tag_cmp(s + 11, "iso-8859-1*")       || !soap_tag_cmp(s + 11, "latin1*"))      { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to latin1 encoding\n"));        soap->mode |= SOAP_ENC_LATIN;      }      else if (!soap_tag_cmp(s + 11, "utf-8*"))      { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to utf-8 encoding\n"));        soap->mode &= ~SOAP_ENC_LATIN;      }    }  }  if ((int)c != EOF)    c = soap_getchar(soap);  return c;}#endif/******************************************************************************/#ifndef WITH_LEANER#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_move(struct soap *soap, long n){ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %ld bytes forward\n", (long)n));  for (; n > 0; n--)    if ((int)soap_getchar(soap) == EOF)      return SOAP_EOF;  return SOAP_OK;}#endif#endif/******************************************************************************/#ifndef WITH_LEANER#ifndef PALM_1SOAP_FMAC1size_tSOAP_FMAC2soap_tell(struct soap *soap){ return soap->count - soap->buflen + soap->bufidx - (soap->ahead != 0);}#endif#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_pututf8(struct soap *soap, register unsigned long c){ char tmp[16];  if (c < 0x80 && c >= 0x20)  { *tmp = (char)c;    return soap_send_raw(soap, tmp, 1);  }#ifndef WITH_LEAN  if (c >= 0x80 && (soap->mode & SOAP_XML_CANONICAL))  { register char *t = tmp;    if (c < 0x0800)      *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));    else    { if (c < 0x010000)        *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));      else      { if (c < 0x200000)          *t++ = (char)(0xF0 | ((c >> 18) & 0x07));        else        { if (c < 0x04000000)            *t++ = (char)(0xF8 | ((c >> 24) & 0x03));          else          { *t++ = (char)(0xFC | ((c >> 30) & 0x01));            *t++ = (char)(0x80 | ((c >> 24) & 0x3F));          }          *t++ = (char)(0x80 | ((c >> 18) & 0x3F));        }             *t++ = (char)(0x80 | ((c >> 12) & 0x3F));      }      *t++ = (char)(0x80 | ((c >> 6) & 0x3F));    }    *t++ = (char)(0x80 | (c & 0x3F));    *t = '\0';  }  else#endif    sprintf(tmp, "&#%lu;", c);  return soap_send(soap, tmp);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1soap_wcharSOAP_FMAC2soap_getutf8(struct soap *soap){ register soap_wchar c, c1, c2, c3, c4;  c = soap->ahead;  if (c > 0xFF)  { soap->ahead = 0;    return c;  }again:  c = soap_get(soap);  if (c < 0x80 || (soap->mode & SOAP_ENC_LATIN))    return c;  c1 = soap_get1(soap);  if (c1 < 0x80)  { soap_revget1(soap); /* doesn't look like this is UTF8 */    return c;  }  c1 &= 0x3F;  if (c < 0xE0)    return ((soap_wchar)(c & 0x1F) << 6) | c1;  c2 = (soap_wchar)soap_get1(soap) & 0x3F;  if (c == 0xEF && c1 == 0x3B && c2 == 0x3F)	/* ignore UTF-8 BOM */    goto again;  if (c < 0xF0)    return ((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2;  c3 = (soap_wchar)soap_get1(soap) & 0x3F;  if (c < 0xF8)    return ((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;  c4 = (soap_wchar)soap_get1(soap) & 0x3F;  if (c < 0xFC)    return ((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4;  return ((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(soap_get1(soap) & 0x3F);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_puthex(struct soap *soap, const unsigned char *s, int n){ char d[2];  register int i;#ifdef WITH_DOM  if ((soap->mode & SOAP_XML_DOM) && soap->dom)  { if (!(soap->dom->data = soap_s2hex(soap, s, NULL, n)))      return soap->error;    return SOAP_OK;  }#endif  for (i = 0; i < n; i++)  { register int m = *s++;    d[0] = (char)((m >> 4) + (m > 159 ? '7' : '0'));    m &= 0x0F;    d[1] = (char)(m + (m > 9 ? '7' : '0'));    if (soap_send_raw(soap, d, 2))      return soap->error;  }  return SOAP_OK;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1unsigned char*SOAP_FMAC2soap_gethex(struct soap *soap, int *n){#ifdef WITH_DOM  if ((soap->mode & SOAP_XML_DOM) && soap->dom)  { soap->dom->data = soap_string_in(soap, 0, -1, -1);    return (unsigned char*)soap_hex2s(soap, soap->dom->data, NULL, 0, n);  }#endif#ifdef WITH_FAST  soap->labidx = 0;  for (;;)  { register char *s;    register size_t i, k;    if (soap_append_lab(soap, NULL, 0))      return NULL;    s = soap->labbuf + soap->labidx;    k = soap->lablen - soap->labidx;    soap->labidx = soap->lablen;    for (i = 0; i < k; i++)    { register char d1, d2;      register soap_wchar c;      c = soap_get(soap);      if (soap_isxdigit(c))      { d1 = (char)c;        c = soap_get(soap);         if (soap_isxdigit(c))          d2 = (char)c;        else         { soap->error = SOAP_TYPE;          return NULL;        }      }      else      { unsigned char *p;        soap_unget(soap, c);        if (n)          *n = (int)(soap->lablen + i - k);        p = (unsigned char*)soap_malloc(soap, soap->lablen + i - k);        if (p)          memcpy(p, soap->labbuf, soap->lablen + i - k);        return p;      }      *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');    }  }#else  if (soap_new_block(soap))    return NULL;  for (;;)  { register int i;    register char *s = (char*)soap_push_block(soap, SOAP_BLKLEN);    if (!s)    { soap_end_block(soap);      return NULL;    }    for (i = 0; i < SOAP_BLKLEN; i++)    { register char d1, d2;      register soap_wchar c = soap_get(soap);      if (soap_isxdigit(c))      { d1 = (char)c;        c = soap_get(soap);         if (soap_isxdigit(c))          d2 = (char)c;        else         { soap_end_block(soap);          soap->error = SOAP_TYPE;          return NULL;        }      }      else      { unsigned char *p;        soap_unget(soap, c);        if (n)          *n = (int)soap_size_block(soap, i);        p = (unsigned char*)soap_save_block(soap, NULL, 0);        return p;      }      *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');

⌨️ 快捷键说明

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