📄 stdsoap2.cpp
字号:
r = recv(soap->socket, s, (int)n, soap->socket_flags);#ifdef PALM /* CycleSyncDisplay(curStatusMsg); */#endif if (r >= 0) return (size_t)r; r = soap_socket_errno(soap->socket); if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) { soap->errnum = r; return 0; } }#ifndef WITH_LEAN { struct timeval timeout; fd_set fd; if (soap->recv_timeout > 0) { timeout.tv_sec = soap->recv_timeout; timeout.tv_usec = 0; } else if (soap->recv_timeout < 0) { timeout.tv_sec = -soap->recv_timeout/1000000; timeout.tv_usec = -soap->recv_timeout%1000000; } else { timeout.tv_sec = 0; timeout.tv_usec = 10000; }#ifndef WIN32 if ((int)soap->socket >= (int)FD_SETSIZE) { soap->error = SOAP_FD_EXCEEDED; return 0; /* Hint: MUST increase FD_SETSIZE */ }#endif FD_ZERO(&fd); FD_SET(soap->socket, &fd);#ifdef WITH_OPENSSL if (soap->ssl && err == SSL_ERROR_WANT_WRITE) r = select((int)soap->socket + 1, NULL, &fd, &fd, &timeout); else r = select((int)soap->socket + 1, &fd, NULL, &fd, &timeout);#else r = select((int)soap->socket + 1, &fd, NULL, &fd, &timeout);#endif if (r < 0 && (r = soap_socket_errno(soap->socket)) != SOAP_EINTR) { soap->errnum = r; return 0; } if (!r && soap->recv_timeout) { soap->errnum = 0; return 0; } }#endif#ifdef PALM r = soap_socket_errno(soap->socket); if (r != SOAP_EINTR && timeouts-- <= 0) { soap->errnum = r; return 0; }#endif } }#ifdef WITH_FASTCGI return fread(s, 1, n, stdin);#else#ifdef UNDER_CE return fread(s, 1, n, soap->recvfd);#else#ifdef WMW_RPM_IO if (soap->rpmreqid) r = httpBlockRead(soap->rpmreqid, s, n); else#endif r = read(soap->recvfd, s, (unsigned int)n); if (r >= 0) return (size_t)r; soap->errnum = soap_errno; 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); DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n----\n")); 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 *code_map, const char *str){ if (code_map && str) { while (code_map->string) { if (!strcmp(str, code_map->string)) /* case sensitive */ return code_map; code_map++; } } return NULL;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1longSOAP_FMAC2soap_code_int(const struct soap_code_map *code_map, const char *str, long other){ if (code_map) { while (code_map->string) { if (!soap_tag_cmp(str, code_map->string)) /* case insensitive */ return code_map->code; code_map++; } } return other;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1const char*SOAP_FMAC2soap_code_str(const struct soap_code_map *code_map, long code){ if (!code_map) return NULL; while (code_map->code != code && code_map->string) code_map++; return code_map->string;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1longSOAP_FMAC2soap_code_bits(const struct soap_code_map *code_map, const char *str){ register long bits = 0; if (code_map) { while (str && *str) { const struct soap_code_map *p; for (p = code_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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -