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

📄 stdsoap2.cpp

📁 linux下开发的soap协议。建议大家学习学习!
💻 CPP
📖 第 1 页 / 共 5 页
字号:
      if (*t != '-')      { if (*t != '*')	  return 1;	else if (*++t)	{ int c = tolower(*t);	  for (; *s; s++)	  { if (tolower(*s) == c)	      if (!soap_tag_cmp(s+1, t+1))	        return 0;          }	}        else	  return 0;      }  if (*t == '*' && !t[1])    return 0;  return *t;}/******************************************************************************/SOAP_FMAC1wcharSOAP_FMAC2soap_char(struct soap *soap){ int i, c;  char tmp[8], *t = tmp;  for (i = 0; i < 7; i++)  { c = soap_get1(soap);    if (c == ';' || c == EOF)      break;    else      *t++ = c;  }  *t = '\0';  if (*tmp == '#')  { if (tmp[1] == 'x' || tmp[1] == 'X')      return strtol(tmp+2, &t, 16)|0x80000000;    else      return atoi(tmp+1)|0x80000000;  }  if (!soap_tag_cmp(tmp, "lt"))    return '<';  if (!soap_tag_cmp(tmp, "gt"))    return '>';  if (!soap_tag_cmp(tmp, "amp"))    return '&';  if (!soap_tag_cmp(tmp, "quot"))    return '"';  if (!soap_tag_cmp(tmp, "apos"))    return '\'';  return '?';}/******************************************************************************/SOAP_FMAC1wcharSOAP_FMAC2soap_get(struct soap *soap){ register wchar c;  if (soap->ahead1)  { c = soap->ahead1;    soap->ahead1 = 0;    return c;  }  if (soap->ahead2)  { c = soap->ahead2;    soap->ahead2 = 0;    return c;  }redo:  c = soap_get1(soap);  if (soap->cdata)  { if (c == ']')    { c = soap_get1(soap);      if (c == ']')      { soap->cdata = 0;        c = soap_get1(soap); /* skip > */        goto redo;      }      else      { soap->ahead2 = c;        return ']';      }    }    else      return c;  }  switch (c)  { case '<':      do c = soap_get1(soap);      while (blank(c));      if (c == '!' || c == '?' || c == '%')      { if (c == '!')        { c = soap_get1(soap);	  if (c == '[')	  { do c = soap_get1(soap);	    while (c != EOF && c != '[');	    if (c == EOF)	      return EOF;	    soap->cdata = 1;            return soap_get1(soap);	  }	  if (c == '-' && (c = soap_get1(soap)) == '-')	  { do	    { c = soap_get1(soap);	      if (c == '-' && (c = soap_get1(soap)) == '-')	        break;	    } while (c != EOF);	  }	}        while (c != EOF && c != '>')          c = soap_get1(soap);        if (c == '>')          goto redo;        return EOF;      }      if (c == '/')        return TT;      soap->ahead2 = c;      return LT;    case '>':      return GT;    case '"':      return QT;    case '\'':      return AP;    case '&':      c = soap_char(soap);  }  return c;}/******************************************************************************/SOAP_FMAC1wcharSOAP_FMAC2soap_advance(struct soap *soap){ wchar c;  while (((c = soap_get(soap)) != EOF) && c != LT && c != TT)    ;  return c;}/******************************************************************************/SOAP_FMAC1wcharSOAP_FMAC2soap_skip(struct soap *soap){ register wchar c;  do c = soap_get(soap);  while (blank(c));  return c;}/******************************************************************************/SOAP_FMAC1intSOAP_FMAC2soap_move(struct soap *soap, int n){ DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nmoving %d bytes forward", n));  for (; n > 0; n--)    if (soap_get2(soap) == EOF)      return SOAP_EOF;  return SOAP_OK;}/******************************************************************************/SOAP_FMAC1size_tSOAP_FMAC2soap_tell(struct soap *soap){ return soap->count - soap->buflen + soap->bufidx - (soap->ahead1 || soap->ahead2);}/******************************************************************************/SOAP_FMAC1intSOAP_FMAC2soap_pututf8(struct soap *soap, wchar c){ char tmp[16];  if (c < 0x80)  { tmp[0] = (char)c;    tmp[1] = '\0';  }  else    sprintf(tmp, "&#%lu;", (unsigned long)c);  return soap_send(soap, tmp);}/******************************************************************************/SOAP_FMAC1wcharSOAP_FMAC2soap_getutf8(struct soap *soap){ register wchar c;  c = soap_get2(soap);  if (c < 0x80)    return c;  if (c < 0xC0)    return ((wchar)(c&0x1F)<<6)|(wchar)(soap_get1(soap)&0x3F);  if (c < 0xF0)    return ((wchar)(c&0x0F)<<12)|((wchar)(soap_get1(soap)&0x3F)<<6)|(wchar)(soap_get1(soap)&0x3F);  if (c < 0xF8)    return ((wchar)(c&0x07)<<18)|((wchar)(soap_get1(soap)&0x3F)<<12)|((wchar)(soap_get1(soap)&0x3F)<<6)|(wchar)(soap_get1(soap)&0x3F);  if (c < 0xFA)    return ((wchar)(c&0x07)<<24)|((wchar)(soap_get1(soap)&0x3F)<<18)|((wchar)(soap_get1(soap)&0x3F)<<12)|((wchar)(soap_get1(soap)&0x3F)<<6)|(wchar)(soap_get1(soap)&0x3F);  return ((wchar)(c&0x07)<<30)|((wchar)(soap_get1(soap)&0x3F)<<24)|((wchar)(soap_get1(soap)&0x3F)<<18)|((wchar)(soap_get1(soap)&0x3F)<<12)|((wchar)(soap_get1(soap)&0x3F)<<6)|(wchar)(soap_get1(soap)&0x3F);}/******************************************************************************/SOAP_FMAC1intSOAP_FMAC2soap_puthex(struct soap *soap, int n){ char d[3];  d[0] = (n>>4) + (n > 159 ? '7' : '0');  n &= 0x0F;  d[1] = n + (n > 9 ? '7' : '0');  d[2] = '\0';  return soap_send(soap, d);}/******************************************************************************/SOAP_FMAC1intSOAP_FMAC2soap_gethex(struct soap *soap){ wchar c;  char d1, d2;  if ((c = soap_get(soap)) < 0)  { soap_unget(soap, c);    return EOF;  }  d1 = (char)c;  if ((c = soap_get(soap)) < 0)  { soap_unget(soap, c);    return EOF;  }  d2 = (char)c;  return ((d1 >= 'A' ? (d1&0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2&0x7) + 9 : d2 - '0');}/******************************************************************************/SOAP_FMAC1intSOAP_FMAC2soap_putbase64(struct soap *soap, const unsigned char *s, size_t n){ register size_t i;  register unsigned long m;  char d[5];  static const char base64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";  if (!s)    return SOAP_OK;  d[4] = '\0';  for (; n > 2; n -= 3, s += 3)  { m = (s[0]<<16) | (s[1]<<8) | s[2];    for (i = 4; i > 0; m >>= 6)      d[--i] = base64[m&0x3F];    if (soap_send(soap, d))      return soap->error;  }  if (n > 0)  { m = 0;    for (i = 0; i < n; i++)      m = (m<<8) | *s++;    for (; i < 3; i++)      m <<= 8;    for (i++; i > 0; m >>= 6)      d[--i] = base64[m&0x3F];    for (i = 3; i > n; i--)      d[i] = '=';    if (soap_send(soap, d))      return soap->error;  }  return SOAP_OK;}/******************************************************************************/SOAP_FMAC1unsigned char*SOAP_FMAC2soap_getbase64(struct soap *soap, size_t *n, int malloc_flag){ static const char base64[81] = "\76XXX\77\64\65\66\67\70\71\72\73\74\75XXXXXXX\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31XXXXXX\32\33\34\35\36\37\40\41\42\43\44\45\46\47\50\51\52\53\54\55\56\57\60\61\62\63";  register int i, j;  register wchar c;  register unsigned long m;  unsigned char *p;  char *s;  if (soap_new_block(soap))    return NULL;  for (;;)  { s = (char*)soap_push_block(soap, 3*SOAP_BLKLEN);	/* must be multiple of 3 */    for (i = 0; i < SOAP_BLKLEN; i++)    { m = 0;      j = 0;      while (j < 4)      { c = soap_get(soap);        if (c == '=' || c < 0)        { soap->blist->size += 3*(i-SOAP_BLKLEN);	  switch (j)	  { case 2:              *s++ = (char)((m >> 4) & 0xFF);	      soap->blist->size++;	      break;	    case 3:              *s++ = (char)((m >> 10) & 0xFF);              *s++ = (char)((m >> 2) & 0xFF);	      soap->blist->size += 2;          }	  *n = soap->blist->size;	  if (soap->blist->size > 0)	    if (malloc_flag)	      p = (unsigned char*)malloc(soap->blist->size);	    else	      p = (unsigned char*)soap_malloc(soap, soap->blist->size);          else	    p = NULL;	  soap_store_block(soap, (char*)p);	  if (c >= 0)	    c = soap_advance(soap);	  soap_unget(soap, c);	  return p;	}        c -= '+';        if (c >= 0 && c <= 79)        { m = (m << 6) + base64[c];	  j++;        }      }      *s++ = (char)((m >> 16) & 0xFF);      *s++ = (char)((m >> 8) & 0xFF);      *s++ = (char)(m & 0xFF);    }  }}/******************************************************************************/static char*soap_strerror(struct soap *soap, int soaperror){#ifndef UNDER_CE  return strerror(soaperror);#else  FormatMessage(    FORMAT_MESSAGE_FROM_SYSTEM |    FORMAT_MESSAGE_IGNORE_INSERTS,    NULL,    soaperror,    0,    (LPTSTR) &soap->werrorstr,    256,    NULL  );  wcstombs(soap->errorstr, soap->werrorstr, 256);  return soap->errorstr;#endif}/******************************************************************************/static voidsoap_set_error(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail, int soaperror){ *soap_faultcode(soap) = faultcode;  *soap_faultstring(soap) = faultstring;  *soap_faultdetail(soap) = faultdetail;  soap->error = soaperror;}/******************************************************************************/SOAP_FMAC1intSOAP_FMAC2soap_new_block(struct soap *soap){ struct soap_blist *p;  DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nNew block sequence (prev=%p)", soap->blist));  if (!(p = (struct soap_blist*)malloc(sizeof(struct soap_blist))))    return SOAP_EOM;     p->next = soap->blist;   p->ptr = NULL;  p->size = 0;  soap->blist = p;  return SOAP_OK;}/******************************************************************************/SOAP_FMAC1void*SOAP_FMAC2soap_push_block(struct soap *soap, size_t n){ char *p;  DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nPush block %d (%d)", (int)n, soap->blist->size));  if (!(p = (char*)malloc(n + sizeof(char*) + sizeof(size_t))))    return NULL;  *((char**)p) = soap->blist->ptr;  *((size_t*)(p + sizeof(char*))) = n;  soap->blist->ptr = p;  soap->blist->size += n;  return p + sizeof(char*) + sizeof(size_t);}/******************************************************************************/SOAP_FMAC1voidSOAP_FMAC2soap_pop_block(struct soap *soap){ DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nPop block"));  if (!soap->blist->ptr)    return;  soap->blist->size -= *((size_t*)(soap->blist->ptr + sizeof(char*)));}/******************************************************************************/static voidsoap_update_ptrs(struct soap *soap, char *start, char *end, long offset){ int i;  struct soap_ilist *ip;  void *p, **q;  for (i = 0; i < SOAP_IDHASH; i++)    for (ip = soap->iht[i]; ip; ip = ip->next)      { if (ip->ptr && (char*)ip->ptr >= start && (char*)ip->ptr < end)          ip->ptr = (char*)ip->ptr + offset;        DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nTraversing link chain to update %s type %d at level %d", ip->id, ip->type, ip->level));        for (q = &ip->link; q; q = (void**)p)        { p = *q;	  if (p && (char*)p >= start && (char*)p < end)          { DBGLOG(TEST, SOAP_MESSAGE(fdebug,"Link update %p", p));	    *q = (char*)p + offset;          }        }        DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nTraversing copy chain to update %s type %d at level %d", ip->id, ip->type, ip->level));        for (q = &ip->copy; q; q = (void**)p)        { p = *q;          DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nCheck location %p", p));	  if (p && (char*)p >= start && (char*)p < end)          { DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nCopy update %p", p));	    *q = (char*)p + offset;          }        }      }  DBGLOG(TEST, SOAP_MESSAGE(fdebug,"\nPointers updated"));}/******************************************************************************/static voidsoap_resolve_ptr(struct soap_ilist *ip){ void *p, **q;  q = (void**)ip->link;  ip->link = NULL;  while (q)  { p = *q;

⌨️ 快捷键说明

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