📄 stdsoap2.c
字号:
/* stdsoap2.c[pp] 2.3 rev 4The contents of this file are subject to the gSOAP Public License Version 1.3(the "License"); you may not use this file except in compliance with theLicense. You may obtain a copy of the License athttp://www.cs.fsu.edu/~engelen/soaplicense.htmlSoftware distributed under the License is distributed on an "AS IS" basis,WITHOUT WARRANTY OF ANY KIND, either express or implied. See the Licensefor the specific language governing rights and limitations under the License.The Initial Developer of the Original Code is Robert A. van Engelen.Copyright (C) 2000-2003 Robert A. van Engelen, Genivia inc. All Rights Reserved.Note:Win32 build needs winsock.dll (Visual C++ "wsock32.lib")To do this in Visual C++ 6.0, go to "Project", "settings", select the "Link"tab (the project file needs to be selected in the file view) and add"wsock32.lib" to the "Object/library modules" entry*/#include "stdsoap2.h"#ifdef __cplusplusSOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.3 2003-08-01 12:00:00 GMT")extern "C" {#elseSOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.3 2003-08-01 12:00:00 GMT")#endif/* EOF=-1 */#define LT (-2) /* XML character '<' */#define TT (-3) /* XML character '</' */#define GT (-4) /* XML character '>' */#define QT (-5) /* XML character '"' */#define AP (-6) /* XML character ''' */#define blank(c) ((c) >= 0 && (c) <= 32)#define notblank(c) ((c) > 32)#define hash_ptr(p) (((unsigned long)(p) >> 3) & (SOAP_PTRHASH - 1))static wchar soap_char(struct soap*);static wchar soap_getchunkchar(struct soap*);static void soap_update_ptrs(struct soap*, char*, char*, long);static int soap_has_copies(struct soap*, char*, char*);static int soap_puthttphdr(struct soap*, int, size_t);static struct soap_ilist *soap_hlookup(struct soap*, const char*);static void soap_init_iht(struct soap*);static void soap_free_iht(struct soap*);static void soap_init_pht(struct soap*);static void soap_free_pht(struct soap*);static int soap_set_error(struct soap*, const char*, const char*, const char*, int);static int soap_copy_fault(struct soap*, const char*, const char*, const char*);static int soap_getattrval(struct soap*, char*, size_t, wchar);static void soap_set_local_namespaces(struct soap*);static size_t soap_begin_dime(struct soap*);static int soap_isnumeric(struct soap*, const char*);static void *fplugin(struct soap*, const char*);#ifndef WITH_LEANstatic time_t soap_timegm(struct tm*);static void soap_init_logs(struct soap*);static void soap_close_logfile(struct soap*, int);static void soap_set_logfile(struct soap*, int, const char*);#endif#ifndef WITH_LEANERstatic int soap_putdimefield(struct soap*, const char*, size_t);static char *soap_getdimefield(struct soap*, size_t);#endif#ifdef WITH_GZIPstatic int soap_getgzipheader(struct soap*);#endifstatic char *soap_strerror(struct soap*, int);static const char *tcp_error(struct soap*);static const char *http_error(struct soap*, int);static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, size_t);static int http_post_header(struct soap*, const char*, const char*);static int http_response(struct soap*, int, size_t);static int http_parse(struct soap*);static int http_parse_header(struct soap*, const char*, const char*);static int tcp_connect(struct soap*, const char*, const char*, int);static int tcp_accept(struct soap*, int, struct sockaddr*, int*);static int tcp_disconnect(struct soap*);static int fsend(struct soap*, const char*, size_t);static size_t frecv(struct soap*, char*, size_t);#ifndef PALM_2static const char soap_env1[42] = "http://schemas.xmlsoap.org/soap/envelope/";static const char soap_enc1[42] = "http://schemas.xmlsoap.org/soap/encoding/";static const char soap_env2[40] = "http://www.w3.org/2002/12/soap-envelope";static const char soap_enc2[40] = "http://www.w3.org/2002/12/soap-encoding";static const char soap_rpc[35] = "http://www.w3.org/2002/12/soap-rpc";#endif#ifndef PALM_1const struct soap_double_nan soap_double_nan = {0xFFFFFFFF, 0xFFFFFFFF};static const char soap_base64o[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";static const char soap_base64i[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";#endifstatic const char soap_padding[3] = "\0\0";#define SOAP_STR_PADDING (soap_padding)#define SOAP_STR_EOS (soap_padding)struct code_map{ int code; const char *string;};#ifndef WITH_LEANstatic const struct code_map html_entity_codes[] = /* entities for XHTML parsing */{ { 160, "nbsp" }, { 161, "iexcl" }, { 162, "cent" }, { 163, "pound" }, { 164, "curren" }, { 165, "yen" }, { 166, "brvbar" }, { 167, "sect" }, { 168, "uml" }, { 169, "copy" }, { 170, "ordf" }, { 171, "laquo" }, { 172, "not" }, { 173, "shy" }, { 174, "reg" }, { 175, "macr" }, { 176, "deg" }, { 177, "plusmn" }, { 178, "sup2" }, { 179, "sup3" }, { 180, "acute" }, { 181, "micro" }, { 182, "para" }, { 183, "middot" }, { 184, "cedil" }, { 185, "sup1" }, { 186, "ordm" }, { 187, "raquo" }, { 188, "frac14" }, { 189, "frac12" }, { 190, "frac34" }, { 191, "iquest" }, { 192, "Agrave" }, { 193, "Aacute" }, { 194, "Acirc" }, { 195, "Atilde" }, { 196, "Auml" }, { 197, "Aring" }, { 198, "AElig" }, { 199, "Ccedil" }, { 200, "Egrave" }, { 201, "Eacute" }, { 202, "Ecirc" }, { 203, "Euml" }, { 204, "Igrave" }, { 205, "Iacute" }, { 206, "Icirc" }, { 207, "Iuml" }, { 208, "ETH" }, { 209, "Ntilde" }, { 210, "Ograve" }, { 211, "Oacute" }, { 212, "Ocirc" }, { 213, "Otilde" }, { 214, "Ouml" }, { 215, "times" }, { 216, "Oslash" }, { 217, "Ugrave" }, { 218, "Uacute" }, { 219, "Ucirc" }, { 220, "Uuml" }, { 221, "Yacute" }, { 222, "THORN" }, { 223, "szlig" }, { 224, "agrave" }, { 225, "aacute" }, { 226, "acirc" }, { 227, "atilde" }, { 228, "auml" }, { 229, "aring" }, { 230, "aelig" }, { 231, "ccedil" }, { 232, "egrave" }, { 233, "eacute" }, { 234, "ecirc" }, { 235, "euml" }, { 236, "igrave" }, { 237, "iacute" }, { 238, "icirc" }, { 239, "iuml" }, { 240, "eth" }, { 241, "ntilde" }, { 242, "ograve" }, { 243, "oacute" }, { 244, "ocirc" }, { 245, "otilde" }, { 246, "ouml" }, { 247, "divide" }, { 248, "oslash" }, { 249, "ugrave" }, { 250, "uacute" }, { 251, "ucirc" }, { 252, "uuml" }, { 253, "yacute" }, { 254, "thorn" }, { 255, "yuml" }, { 0, NULL }};#endif#ifndef WITH_LEANstatic const struct code_map h_error_codes[] ={#ifdef HOST_NOT_FOUND { HOST_NOT_FOUND, "Host not found" },#endif#ifdef TRY_AGAIN { TRY_AGAIN, "Try Again" },#endif#ifdef NO_RECOVERY { NO_RECOVERY, "No Recovery" },#endif#ifdef NO_DATA { NO_DATA, "No Data" },#endif#ifdef NO_ADDRESS { NO_ADDRESS, "No Address" },#endif { 0, NULL }};#endif#ifndef WITH_LEANstatic const struct code_map h_http_error_codes[] ={ { 201, "Created" }, { 202, "Accepted" }, { 203, "Non-Authoritative Information" }, { 204, "No Content" }, { 205, "Reset Content" }, { 206, "Partial Content" }, { 300, "Multiple Choices" }, { 301, "Moved Permanently" }, { 302, "Found" }, { 303, "See Other" }, { 304, "Not Modified" }, { 305, "Use Proxy" }, { 307, "Temporary Redirect" }, { 400, "Bad Request" }, { 401, "Unauthorized" }, { 402, "Payment Required" }, { 403, "Forbidden" }, { 404, "Not Found" }, { 405, "Method Not Allowed" }, { 406, "Not Acceptable" }, { 407, "Proxy Authentication Required" }, { 408, "Request Time-out" }, { 409, "Conflict" }, { 410, "Gone" }, { 411, "Length Required" }, { 412, "Precondition Failed" }, { 413, "Request Entity Too Large" }, { 414, "Request-URI Too Large" }, { 415, "Unsupported Media Type" }, { 416, "Requested range not satisfiable" }, { 417, "Expectation Failed" }, { 500, "Internal Server Error" }, { 501, "Not Implemented" }, { 502, "Bad Gateway" }, { 503, "Service Unavailable" }, { 504, "Gateway Time-out" }, { 505, "HTTP Version not supported" }, { 0, NULL }};#endif#ifdef WITH_OPENSSLstatic const struct code_map h_ssl_error_codes[] ={#define _SSL_ERROR(e) { e, #e } _SSL_ERROR(SSL_ERROR_SSL), _SSL_ERROR(SSL_ERROR_ZERO_RETURN), _SSL_ERROR(SSL_ERROR_WANT_READ), _SSL_ERROR(SSL_ERROR_WANT_WRITE), _SSL_ERROR(SSL_ERROR_WANT_CONNECT), _SSL_ERROR(SSL_ERROR_WANT_X509_LOOKUP), _SSL_ERROR(SSL_ERROR_SYSCALL), { 0, NULL }};#endif#ifdef WIN32static int tcp_done = 0;#endif/******************************************************************************/#ifndef MAC_CARBON#ifndef PALM_1static intfsend(struct soap *soap, const char *s, size_t n){ register int nwritten;#if defined(__cplusplus) && !defined(UNDER_CE) if (soap->os) { soap->os->write(s, n); if (soap->os->good()) return SOAP_OK; return SOAP_EOF; }#endif while (n) { if (soap_valid_socket(soap->socket)) { #ifndef WITH_LEAN if (soap->send_timeout) { struct timeval timeout; fd_set fd; if (soap->send_timeout > 0) { timeout.tv_sec = soap->send_timeout; timeout.tv_usec = 0; } else { timeout.tv_sec = -soap->send_timeout/1000000; timeout.tv_usec = -soap->send_timeout%1000000; } FD_ZERO(&fd); FD_SET((SOAP_SOCKET)soap->socket, &fd); for (;;) { register int r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); if (r > 0) break; if (!r) { soap->errnum = 0; return SOAP_EOF; } if (soap_socket_errno != SOAP_EINTR) { soap->errnum = soap_socket_errno; return SOAP_EOF; } } }#endif#ifdef WITH_OPENSSL if (soap->ssl) nwritten = SSL_write(soap->ssl, s, n); else#endif#ifndef PALM nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);#else nwritten = send((SOAP_SOCKET)soap->socket, (void*)s, n, soap->socket_flags);#endif if (nwritten <= 0) {#ifdef WITH_OPENSSL if (soap->ssl && SSL_get_error(soap->ssl, nwritten) != SSL_ERROR_NONE) return SOAP_EOF;#endif if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EWOULDBLOCK && soap_socket_errno != SOAP_EAGAIN) { soap->errnum = soap_socket_errno; return SOAP_EOF; } nwritten = 0; /* and call write() again */ } } else {#ifdef WITH_FASTCGI nwritten = fwrite(s, 1, n, stdout); fflush(stdout);#else#ifdef UNDER_CE nwritten = fwrite(s, 1, n, soap->sendfd);#else nwritten = write((SOAP_SOCKET)soap->sendfd, s, n);#endif#endif if (nwritten <= 0) { if (soap_errno != SOAP_EINTR && soap_errno != SOAP_EWOULDBLOCK && soap_errno != SOAP_EAGAIN) { soap->errnum = soap_errno; return SOAP_EOF; } nwritten = 0; /* and call write() again */ } } n -= nwritten; s += nwritten; } return SOAP_OK;}#endif#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_flush_raw(struct soap *soap, const char *s, size_t n){ #ifndef WITH_LEAN if ((soap->mode & SOAP_IO) == SOAP_IO_STORE) { char *t; if (!(t = (char*)soap_push_block(soap, n))) return soap->error = SOAP_EOM; memcpy(t, s, n); return SOAP_OK; } if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) { char t[16]; sprintf(t, "\r\n%lX\r\n" + (soap->chunksize ? 0 : 2), (unsigned long)n); DBGMSG(SENT, t, strlen(t)); if ((soap->error = soap->fsend(soap, t, strlen(t)))) return soap->error; soap->chunksize += n; }#endif DBGMSG(SENT, s, n); return soap->error = soap->fsend(soap, s, n);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_flush(struct soap *soap){ if (soap->bufidx) {#ifdef WITH_ZLIB if (soap->mode & SOAP_ENC_ZLIB) { soap->d_stream.next_in = (Byte*)soap->buf; soap->d_stream.avail_in = (unsigned int)soap->bufidx;#ifdef WITH_GZIP soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->bufidx);#endif do { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating %u bytes\n", soap->d_stream.avail_in)); if (deflate(&soap->d_stream, Z_NO_FLUSH) != Z_OK) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:"")); return soap->error = SOAP_ZLIB_ERROR; } if (!soap->d_stream.avail_out) { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN)) return soap->error; soap->d_stream.next_out = (Byte*)soap->z_buf; soap->d_stream.avail_out = SOAP_BUFLEN; } } while (soap->d_stream.avail_in); } else#endif if (soap_flush_raw(soap, soap->buf, soap->bufidx)) return soap->error; soap->bufidx = 0; } return SOAP_OK;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_send_raw(struct soap *soap, const char *s, size_t n){ if (!n) return SOAP_OK; if (soap->mode & SOAP_IO_LENGTH)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -