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

📄 stdsoap2.c

📁 apache模组的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************/#ifndef PALM_2SOAP_FMAC1intSOAP_FMAC2soap_match_namespace(struct soap *soap, const char *id1, const char *id2, int n1, int n2) { register struct soap_nlist *np = soap->nlist;  while (np && (strncmp(np->id, id1, n1) || np->id[n1]))    np = np->next;  if (np)  { if (np->index < 0 || (np->index >= 0 && soap->local_namespaces[np->index].id && (strncmp(soap->local_namespaces[np->index].id, id2, n2) || soap->local_namespaces[np->index].id[n2])))      return SOAP_NAMESPACE;    return SOAP_OK;  }  if (n1 == 3 && n1 == n2 && !strcmp(id1, "xml") && !strcmp(id1, id2))    return SOAP_OK;  return SOAP_SYNTAX_ERROR; }#endif/******************************************************************************/#ifndef PALM_2SOAP_FMAC1intSOAP_FMAC2soap_tag_cmp(register const char *s, register const char *t){ for (; *s && *s != '"'; s++, t++)    if (tolower(*s) != tolower(*t))      if (*t != '-')      { if (*t != '*')          return 1;        if (*++t)        { register int c = tolower(*t);          for (; *s && *s != '"'; s++)          { if (tolower(*s) == c)              if (!soap_tag_cmp(s + 1, t + 1))                return 0;          }          break;        }        else          return 0;      }  if (*t == '*' && !t[1])    return 0;  return *t;}#endif/******************************************************************************/#ifndef PALM_2SOAP_FMAC1intSOAP_FMAC2soap_match_tag(struct soap *soap, const char *tag1, const char *tag2){ 	register const char *s, *t;  	if (!tag1 || !tag2 || !*tag2)    	return SOAP_OK;  	s = strchr(tag1, ':');  	t = strchr(tag2, ':');  	if (t) { 		if (s) { 			if (SOAP_TAG_CMP(s + 1, t + 1)      			|| (t != tag2 && 				soap_match_namespace(soap, tag1, tag2, s - tag1, t - tag2))) {        		return SOAP_TAG_MISMATCH;        	}    	} else if (SOAP_TAG_CMP(tag1, t + 1)     		|| (t != tag2 && soap_match_namespace(soap, tag1, tag2, 0, t - tag2))) {      		return SOAP_TAG_MISMATCH;		}	    	DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags and (default) namespaces match: '%s' '%s'\n", tag1, tag2));   		return SOAP_OK; 	}  	if (s) {		if ((soap->part != SOAP_IN_HEADER && soap->encodingStyle)				|| SOAP_TAG_CMP(s + 1, tag2)) {     		return SOAP_TAG_MISMATCH;		}  	} else if (SOAP_TAG_CMP(tag1, tag2)) {    	return SOAP_TAG_MISMATCH;	}  	DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags match: '%s' '%s'\n", tag1, tag2));  	return SOAP_OK;}#endif/******************************************************************************/#ifndef PALM_2SOAP_FMAC1intSOAP_FMAC2soap_match_array(struct soap *soap, const char *type){ if (*soap->arrayType)    if (soap_match_tag(soap, soap->arrayType, type)     && soap_match_tag(soap, soap->arrayType, "xsd:anyType")     && soap_match_tag(soap, soap->arrayType, "xsd:ur-type")    )    { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array type mismatch: '%s' '%s'\n", soap->arrayType, type));      return SOAP_TAG_MISMATCH;    }  return SOAP_OK;}#endif/******************************************************************************/#ifdef WITH_OPENSSL/******************************************************************************/#ifndef PALM_1static voidssl_init(){ static int done = 0;  if (!done)  { done = 1;    SSL_library_init();    SSL_load_error_strings();  }}#endif/******************************************************************************/#ifndef PALM_1static const char *ssl_error(struct soap *soap, int ret){ int err = SSL_get_error(soap->ssl, ret);  const struct code_map *map = h_ssl_error_codes;  while (map->code && map->code != err)    map++;  if (map->code)     strcpy(soap->msgbuf, map->string);  else    return ERR_error_string(err, soap->msgbuf);  if (ERR_peek_error())  { unsigned long r;    strcat(soap->msgbuf, "\n");    while ((r = ERR_get_error()))      ERR_error_string_n(r, soap->msgbuf + strlen(soap->msgbuf), sizeof(soap->msgbuf) - strlen(soap->msgbuf));  }   else  { switch (ret)    { case 0:        strcpy(soap->msgbuf, "EOF was observed that violates the protocol. The client probably provided invalid authentication information.");        break;      case -1:        sprintf(soap->msgbuf, "Error observed by underlying BIO: %s", strerror(errno));          break;    }  }  return soap->msgbuf;}#endif/******************************************************************************/#ifndef PALM_1static intfpassword(char *buf, int num, int rwflag, void *userdata){ if (num < (int)strlen((char*)userdata) + 1)    return 0;  return strlen(strcpy(buf, (char*)userdata));}#endif/******************************************************************************/#ifndef PALM_1static intssl_auth_init(struct soap *soap){ ssl_init();  if (!soap->ctx && !(soap->ctx = SSL_CTX_new(SSLv23_method())))    return soap_set_receiver_error(soap, "SSL error", "Can't setup context", SOAP_SSL_ERROR);  if (soap->randfile)  { if (!RAND_load_file(soap->randfile, -1))      return soap_set_receiver_error(soap, "SSL error", "Can't load randomness", SOAP_SSL_ERROR);  }  else  { int r;#ifdef HAVE_RAND_R    unsigned int s = (unsigned int)time(NULL);#endif    RAND_seed(soap->buf, sizeof(soap->buf));    while (!RAND_status())    {#ifdef HAVE_RAND_R      r = rand_r(&s);#else      r = rand();#endif      RAND_seed(&r, sizeof(int));    }  }  if (soap->keyfile)  { if (!SSL_CTX_use_certificate_chain_file(soap->ctx, soap->keyfile))      return soap_set_receiver_error(soap, "SSL error", "Can't read certificate file", SOAP_SSL_ERROR);    if (soap->password)    { SSL_CTX_set_default_passwd_cb_userdata(soap->ctx, (void*)soap->password);      SSL_CTX_set_default_passwd_cb(soap->ctx, fpassword);      if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM))        return soap_set_receiver_error(soap, "SSL error", "Can't read key file", SOAP_SSL_ERROR);    }  }  if (soap->cafile)    if (!SSL_CTX_load_verify_locations(soap->ctx, soap->cafile, 0)     || !SSL_CTX_set_default_verify_paths(soap->ctx))      return soap_set_receiver_error(soap, "SSL error", "Can't read CA list", SOAP_SSL_ERROR);  if (soap->rsa)  { RSA *rsa = RSA_generate_key(512, RSA_F4, NULL, NULL);    if (!SSL_CTX_set_tmp_rsa(soap->ctx, rsa))    { if (rsa)        RSA_free(rsa);      return soap_set_receiver_error(soap, "SSL error", "Can't set RSA key", SOAP_SSL_ERROR);    }    RSA_free(rsa);  }  else if (soap->dhfile)  { DH *dh = 0;    BIO *bio;    bio = BIO_new_file(soap->dhfile, "r");    if (!bio)      return soap_set_receiver_error(soap, "SSL error", "Can't read DH file", SOAP_SSL_ERROR);    dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);    BIO_free(bio);    if (SSL_CTX_set_tmp_dh(soap->ctx, dh) < 0)    { if (dh)        DH_free(dh);      return soap_set_receiver_error(soap, "SSL error", "Can't set DH parameters", SOAP_SSL_ERROR);    }    DH_free(dh);  }#if (OPENSSL_VERSION_NUMBER < 0x00905100L)  SSL_CTX_set_verify_depth(soap->ctx, 1); #endif    return SOAP_OK;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_ssl_accept(struct soap *soap){ int i, r;  if (!soap_valid_socket(soap->socket))    return soap_set_receiver_error(soap, "SSL error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);  soap->ssl = SSL_new(soap->ctx);  if (!soap->ssl)    return soap_set_receiver_error(soap, "SSL error", "SSL_new() failed in soap_ssl_accept()", SOAP_SSL_ERROR);  soap->imode |= SOAP_ENC_SSL;  soap->omode |= SOAP_ENC_SSL;  soap->bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE);  SSL_set_bio(soap->ssl, soap->bio, soap->bio);  i = 1000;  while ((r = SSL_accept(soap->ssl)) < 0)  { int err = SSL_get_error(soap->ssl, r);    if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)    { struct timeval timeout;      fd_set fd;      if (i-- <= 0)        break;      timeout.tv_sec = 0;      timeout.tv_usec = 10000;      FD_ZERO(&fd);      FD_SET((SOAP_SOCKET)soap->socket, &fd);      r = select((SOAP_SOCKET)(soap->socket + 1), &fd, &fd, &fd, &timeout);      if (r < 0 && soap_socket_errno != SOAP_EINTR)      { soap->errnum = soap_socket_errno;        return 0;      }    }    else      break;  }  if (r <= 0)  { soap_set_receiver_error(soap, ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR);    soap_closesock(soap);    return SOAP_SSL_ERROR;  }  return SOAP_OK;}#endif/******************************************************************************/#endif /* WITH_OPENSSL *//******************************************************************************/#ifndef PALM_1static inttcp_init(struct soap *soap){ soap->errmode = 1;#ifdef WIN32  if (tcp_done)    return 0;  tcp_done = 1;  { WSADATA w;    if (WSAStartup(MAKEWORD(1, 1), &w))    { tcp_done = 0;      return -1;    }  }#endif#ifdef PALM  errno = 0;  h_errno = 0;  AppNetRefnum = 0;  NetUInit();  AppNetTimeout = 10000;  NetLibOpen(AppNetRefnum, &h_errno);#endif  return 0;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1voidSOAP_FMAC2soap_done(struct soap *soap){ #ifndef WITH_LEAN  int i;#endif  soap_free(soap);  while (soap->clist)  { struct soap_clist *p = soap->clist->next;    SOAP_FREE(soap->clist);    soap->clist = p;  }  soap->keep_alive = 0; /* to force close the socket */  soap_closesock(soap);#ifdef WITH_COOKIES  soap_free_cookies(soap);#endif  while (soap->plugins)  { register struct soap_plugin *p = soap->plugins->next;    if (!soap->copy)    { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Removing plugin '%s'\n", soap->plugins->id));      soap->plugins->fdelete(soap, soap->plugins);    }    SOAP_FREE(soap->plugins);    soap->plugins = p;  }  soap->fplugin = fplugin;  soap->fpost = http_post;  soap->fposthdr = http_post_header;  soap->fresponse = http_response;  soap->fparse = http_parse;  soap->fparsehdr = http_parse_header;#ifndef MAC_CARBON  soap->faccept = tcp_accept;  soap->fopen = tcp_connect;  soap->fclose = tcp_disconnect;  soap->fsend = fsend;  soap->frecv = frecv;#endif  soap->fprepare = NULL;  soap->fignore = NULL;  if (!soap->copy && soap_valid_socket(soap->master))  { closesocket((SOAP_SOCKET)soap->master);    soap->master = SOAP_INVALID_SOCKET;#ifdef WITH_OPENSSL    if (soap->ctx)    { SSL_CTX_free(soap->ctx);      soap->ctx = NULL;    }#endif  }#ifndef WITH_LEAN  for (i = 0; i < SOAP_MAXLOGS; i++)  { soap_close_logfile(soap, i);    if (soap->logfile[i])    { SOAP_FREE((void*)soap->logfile[i]);      soap->logfile[i] = NULL;    }  }#endif}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1voidSOAP_FMAC2soap_cleanup(struct soap *soap){ soap_done(soap);#ifdef WIN32  if (!tcp_done)    return;  tcp_done = 0;  WSACleanup();#endif}#endif/******************************************************************************/#ifndef PALM_1static const char*tcp_error(struct soap *soap){ register const char *msg = NULL;  switch (soap->errmode)  { case 0:      msg = soap_strerror(soap, soap->errnum);      break;    case 1:      msg = "WSAStartup failed";      break;    case 2:    {#ifndef WITH_LEAN      register const struct code_map *map = h_error_codes;      while (map->code && map->code != soap->errnum)        map++;      if (map->code)        msg = map->string;      else#endif      { sprintf(soap->msgbuf, "TCP error %d", soap->errnum);        msg = soap->msgbuf;      }    }  }  return msg;}#endif/******************************************************************************/#ifndef PALM_1static const char*http_error(struct soap *soap, int status){ register const char *msg = NULL;#ifndef WITH_LEAN  register const struct code_map *map = h_http_error_codes;  while (map->code && map->code != status)    map++;  if (map->code)    msg = map->string;  else#endif  { sprintf(soap->msgbuf, "HTTP error %d", status);    msg = soap->msgbuf;  }  return msg;}#endif/******************************************************************************/#ifndef MAC_CARBON#ifndef PALM_1static intsoap_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr){ unsigned long iadd;  struct hostent hostent, *host = &hostent;  iadd = inet_addr(addr);  if ((int)iadd != -1)  { memcpy(inaddr, &iadd, sizeof(iadd));    return 0;  }#if defined(__GLIBC__)  if (gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &host, &soap->errnum) < 0)    host = NULL;#elif defined(HAVE_GETHOSTBYNAME_R) && !defined(TRU64)  host = gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &soap->errnum);#else  if (!(host = gethostbyname(addr)))    soap->errnum = h_errno;#endif  if (!host)  { DBGLOG(T

⌨️ 快捷键说明

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