📄 stdsoap2.cpp
字号:
return 0;#endif#endif}#endif#endif/******************************************************************************/#ifndef WITH_LEAN#ifndef WITH_NOIO#ifndef PALM_1static size_tfrecv_stop(struct soap *soap, char *s, size_t n){ return 0;}#endif#endif#endif/******************************************************************************/#ifndef WITH_NOHTTP#ifndef PALM_1static soap_wcharsoap_getchunkchar(struct soap *soap){ if (soap->bufidx < soap->buflen) return soap->buf[soap->bufidx++]; soap->bufidx = 0; soap->buflen = soap->chunkbuflen = soap->frecv(soap, soap->buf, SOAP_BUFLEN); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket %d\n", (unsigned int)soap->buflen, soap->socket)); DBGMSG(RECV, soap->buf, soap->buflen); if (soap->buflen) return soap->buf[soap->bufidx++]; return EOF;}#endif#endif/******************************************************************************/#ifndef PALM_1static intsoap_isxdigit(int c){ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_recv_raw(struct soap *soap){ register size_t ret;#ifdef WITH_ZLIB if (soap->mode & SOAP_ENC_ZLIB) { if (soap->d_stream.next_out == Z_NULL) return EOF; if (soap->d_stream.avail_in || !soap->d_stream.avail_out) { register int r; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflating\n")); soap->d_stream.next_out = (Byte*)soap->buf; soap->d_stream.avail_out = SOAP_BUFLEN; r = inflate(&soap->d_stream, Z_NO_FLUSH); if (r == Z_OK || r == Z_STREAM_END) { soap->bufidx = 0; ret = soap->buflen = SOAP_BUFLEN - soap->d_stream.avail_out; if (soap->zlib_in == SOAP_ZLIB_GZIP) soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)ret); if (r == Z_STREAM_END) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out)); soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out; soap->d_stream.next_out = Z_NULL; } if (ret) { soap->count += ret; DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n")); DBGMSG(RECV, soap->buf, ret); return SOAP_OK; } } else if (r != Z_BUF_ERROR) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate error: %s\n", soap->d_stream.msg?soap->d_stream.msg:"")); soap->d_stream.next_out = Z_NULL; soap->error = SOAP_ZLIB_ERROR; return EOF; } }zlib_again: if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK && !soap->chunksize) { memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN); soap->buflen = soap->z_buflen; } DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- compressed ----\n")); }#endif#ifndef WITH_NOHTTP if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) /* read HTTP chunked transfer */ { chunk_again: if (soap->chunksize) { soap->buflen = ret = soap->frecv(soap, soap->buf, soap->chunksize > SOAP_BUFLEN ? SOAP_BUFLEN : soap->chunksize); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk: read %u bytes\n", (unsigned int)ret)); DBGMSG(RECV, soap->buf, ret); soap->bufidx = 0; soap->chunksize -= ret; } else { register soap_wchar c; char *t, tmp[8]; t = tmp; if (!soap->chunkbuflen) { soap->chunkbuflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes (chunked) from socket %d\n", (unsigned int)ret, soap->socket)); DBGMSG(RECV, soap->buf, ret); soap->bufidx = 0; if (!ret) return soap->ahead = EOF; } else soap->bufidx = soap->buflen; soap->buflen = soap->chunkbuflen; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (idx=%u len=%u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen)); while (!soap_isxdigit((int)(c = soap_getchunkchar(soap)))) { if ((int)c == EOF) return soap->ahead = EOF; } do *t++ = (char)c; while (soap_isxdigit((int)(c = soap_getchunkchar(soap))) && t - tmp < 7); while ((int)c != EOF && c != '\n') c = soap_getchunkchar(soap); if ((int)c == EOF) return soap->ahead = EOF; *t = '\0'; soap->chunksize = soap_strtoul(tmp, &t, 16); if (!soap->chunksize) { soap->chunkbuflen = 0; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of chunked message\n")); while ((int)c != EOF && c != '\n') c = soap_getchunkchar(soap); return soap->ahead = EOF; } soap->buflen = soap->bufidx + soap->chunksize; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to idx=%u len=%u (%s)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen, tmp)); if (soap->buflen > soap->chunkbuflen) { soap->buflen = soap->chunkbuflen; soap->chunksize -= soap->buflen - soap->bufidx; soap->chunkbuflen = 0; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Passed end of buffer for chunked HTTP (%u bytes left)\n", (unsigned int)(soap->buflen - soap->bufidx))); } else if (soap->chunkbuflen) soap->chunksize = 0; ret = soap->buflen - soap->bufidx; if (!ret) goto chunk_again; } } else#endif { soap->bufidx = 0; soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket %d\n", (unsigned int)ret, soap->socket)); DBGMSG(RECV, soap->buf, ret); }#ifndef WITH_LEANER if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret))) return soap->error;#endif#ifdef WITH_ZLIB if (soap->mode & SOAP_ENC_ZLIB) { register int r; memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN); soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx); soap->d_stream.avail_in = (unsigned int)ret; soap->d_stream.next_out = (Byte*)soap->buf; soap->d_stream.avail_out = SOAP_BUFLEN; r = inflate(&soap->d_stream, Z_NO_FLUSH); if (r == Z_OK || r == Z_STREAM_END) { soap->bufidx = 0; soap->z_buflen = soap->buflen; soap->buflen = ret = SOAP_BUFLEN - soap->d_stream.avail_out; if (soap->zlib_in == SOAP_ZLIB_GZIP) soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %u bytes\n", (unsigned int)ret)); if (!ret) goto zlib_again; if (r == Z_STREAM_END) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out)); soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out; soap->d_stream.next_out = Z_NULL; } DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n")); DBGMSG(RECV, soap->buf, ret); } else { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to inflate: (%d) %s\n", r, soap->d_stream.msg?soap->d_stream.msg:"")); soap->d_stream.next_out = Z_NULL; soap->error = SOAP_ZLIB_ERROR; return EOF; } }#endif soap->count += ret; return !ret;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_recv(struct soap *soap){ #ifndef WITH_LEANER if (soap->mode & SOAP_ENC_DIME) { if (soap->dime.buflen) { char *s; int i; unsigned char tmp[12]; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME hdr for chunked DIME is in buffer\n")); soap->count += soap->dime.buflen - soap->buflen; soap->buflen = soap->dime.buflen; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Skip padding (%ld bytes)\n", -(long)soap->dime.size&3)); for (i = -(long)soap->dime.size&3; i > 0; i--) { soap->bufidx++; if (soap->bufidx >= soap->buflen) if (soap_recv_raw(soap)) return EOF; } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME hdr for next chunk\n")); s = (char*)tmp; for (i = 12; i > 0; i--) { *s++ = soap->buf[soap->bufidx++]; if (soap->bufidx >= soap->buflen) if (soap_recv_raw(soap)) return EOF; } soap->dime.flags = tmp[0] & 0x7; soap->dime.size = ((size_t)tmp[8] << 24) | ((size_t)tmp[9] << 16) | ((size_t)tmp[10] << 8) | ((size_t)tmp[11]); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME chunk (%u bytes)\n", (unsigned int)soap->dime.size)); if (soap->dime.flags & SOAP_DIME_CF) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "More chunking\n")); soap->dime.chunksize = soap->dime.size; if (soap->buflen - soap->bufidx >= soap->dime.size) { soap->dime.buflen = soap->buflen; soap->buflen = soap->bufidx + soap->dime.chunksize; } else soap->dime.chunksize -= soap->buflen - soap->bufidx; } else { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Last chunk\n")); soap->dime.buflen = 0; soap->dime.chunksize = 0; } soap->count = soap->buflen - soap->bufidx; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%u bytes remaining\n", (unsigned int)soap->count)); return SOAP_OK; } if (soap->dime.chunksize) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get next DIME hdr for chunked DIME (%u bytes chunk)\n", (unsigned int)soap->dime.chunksize)); if (soap_recv_raw(soap)) return EOF; if (soap->buflen - soap->bufidx >= soap->dime.chunksize) { soap->dime.buflen = soap->buflen; soap->count -= soap->buflen - soap->bufidx - soap->dime.chunksize; soap->buflen = soap->bufidx + soap->dime.chunksize; } else soap->dime.chunksize -= soap->buflen - soap->bufidx; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%lu bytes remaining, count=%u\n", (unsigned long)(soap->buflen-soap->bufidx), (unsigned int)soap->count)); return SOAP_OK; } }#endif return soap_recv_raw(soap);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1soap_wcharSOAP_FMAC2soap_getchar(struct soap *soap){ register soap_wchar c; c = soap->ahead; if (c) { if (c != EOF) soap->ahead = 0; return c; } return soap_get1(soap);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1const struct soap_code_map*SOAP_FMAC2soap_code(const struct soap_code_map *map, const char *str){ if (map && str) { while (map->string) { if (!strcmp(str, map->string)) /* case sensitive */ return map; map++; } } return NULL;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1longSOAP_FMAC2soap_code_int(const struct soap_code_map *map, const char *str, long other){ if (map) { while (map->string) { if (!soap_tag_cmp(str, map->string)) /* case insensitive */ return map->code; map++; } } return other;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1const char*SOAP_FMAC2soap_code_str(const struct soap_code_map *map, long code){ if (!map) return NULL; while (map->code != code && map->string) map++; return map->string;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1longSOAP_FMAC2soap_code_bits(const struct soap_code_map *map, const char *str){ register long bits = 0; if (map) { while (str && *str) { const struct soap_code_map *p; for (p = map; p->string; p++) { register size_t n = strlen(p->string); if (!strncmp(p->string, str, n) && soap_blank(str[n])) { bits |= p->code; str += n; while (*str > 0 && *str <= 32) str++; break; } } if (!p->string) return 0; } } return bits;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1const char*SOAP_FMAC2soap_code_list(struct soap *soap, const struct soap_code_map *map, long code){ register char *t = soap->tmpbuf; if (map) { while (map->string) { if (map->code & code) { register const char *s = 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; } 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/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -