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

📄 wsaapi.c

📁 一款开源的soap库
💻 C
📖 第 1 页 / 共 3 页
字号:
 * Server-side SOAP Fault *\******************************************************************************//**@fn int soap_wsa_fault_subcode(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail)@brief Sets sender/receiver SOAP Fault (sub)code for server fault response.@param soap context@param[in] flag 0=receiver, 1=sender@param[in] faultsubcode sub code string@param[in] faultstring fault string@param[in] faultdetail detail string@return SOAP_FAULT*/static intsoap_wsa_fault_subcode(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail){ struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);  struct SOAP_ENV__Header *header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));  DBGFUN2("soap_wsa_fault_subcode", "faultsubcode=%s", faultsubcode?faultsubcode:"", "faultstring=%s", faultstring?faultstring:"");  if (!data)    return SOAP_PLUGIN_ERROR;  soap_default_SOAP_ENV__Header(soap, header);  soap_wsa_alloc_header(soap);  if (soap->header->wsa__MessageID)  { header->wsa__RelatesTo = (struct wsa__Relationship*)soap_malloc(soap, sizeof(struct wsa__Relationship));    soap_default_wsa__Relationship(soap, header->wsa__RelatesTo);    header->wsa__RelatesTo->__item = soap->header->wsa__MessageID;  }  /* header->wsa__MessageID = "..."; */  header->wsa__Action = (char*)soap_wsa_faultAction;  if (soap->header && soap->header->wsa__FaultTo && soap->header->wsa__FaultTo->Address && strcmp(soap->header->wsa__FaultTo->Address, soap_wsa_anonymousURI))  { header->wsa__To = soap->header->wsa__FaultTo->Address;    /* (re)connect to fault endpoint if To != FaultTo */    if (!soap->header->wsa__From || !soap->header->wsa__From->Address || strcmp(soap->header->wsa__From->Address, soap->header->wsa__ReplyTo->Address))    { soap->keep_alive = 0;      soap_send_empty_response(soap, SOAP_OK);	/* HTTP ACCEPTED */      if (soap_connect(soap, header->wsa__To, header->wsa__Action))        return SOAP_STOP;	/* nowhere to go */      soap_set_endpoint(soap, header->wsa__To);      soap->action = header->wsa__Action;      data->fresponse = soap->fresponse;      soap->fresponse = soap_wsa_response;	/* response will be a POST */    }  }  else if (soap->header->wsa__From)    header->wsa__To = soap->header->wsa__From->Address;  else    header->wsa__To = (char*)soap_wsa_anonymousURI;  soap->header = header;  if (flag)    return soap_sender_fault_subcode(soap, faultsubcode, faultstring, faultdetail);  return soap_receiver_fault_subcode(soap, faultsubcode, faultstring, faultdetail);}/**@fn int soap_wsa_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)@brief Sets sender SOAP Fault (sub)code for server fault response.@param soap context@param[in] faultsubcode sub code string@param[in] faultstring fault string@param[in] faultdetail detail string@return SOAP_FAULT*/intsoap_wsa_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail){ return soap_wsa_fault_subcode(soap, 1, faultsubcode, faultstring, faultdetail);}/**@fn int soap_wsa_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)@brief Sets receiver SOAP Fault (sub)code for server fault response.@param soap context@param[in] faultsubcode sub code string@param[in] faultstring fault string@param[in] faultdetail detail string@return SOAP_FAULT*/intsoap_wsa_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail){ return soap_wsa_fault_subcode(soap, 0, faultsubcode, faultstring, faultdetail);}/**@fn int soap_wsa_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)@brief Sets sender SOAP Fault for server fault response.@param soap context@param[in] faultstring fault string@param[in] faultdetail detail string@return SOAP_FAULT*/intsoap_wsa_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail){ return soap_wsa_fault_subcode(soap, 1, NULL, faultstring, faultdetail);}/**@fn int soap_wsa_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)@brief Sets receiver SOAP Fault for server fault response.@param soap context@param[in] faultstring fault string@param[in] faultdetail detail string@return SOAP_FAULT*/intsoap_wsa_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail){ return soap_wsa_fault_subcode(soap, 0, NULL, faultstring, faultdetail);}/******************************************************************************\ * * Server-side WS-Addressing Fault *\******************************************************************************//**@fn int soap_wsa_error(struct soap *soap, wsa__FaultSubcodeValues fault)@brief Sets SOAP Fault (sub)code for server WS-Addressing fault response.@param soap context@param[in] fault is one of wsa:FaultSubcodeValues@return SOAP_FAULT*/intsoap_wsa_error(struct soap *soap, wsa__FaultSubcodeValues fault){ const char *code = soap_wsa__FaultSubcodeValues2s(soap, fault);  /* populate the SOAP Fault as per WS-Addressing spec */  switch (fault)  { case wsa__InvalidMessageInformationHeader:      return soap_wsa_sender_fault_subcode(soap, code, "A message information header is not valid and the message cannot be processed. The validity failure can be either structural or semantic, e.g. a [destination] that is not a URI or a [relationship] to a [message id] that was never issued.", "Invalid header");    case wsa__MessageInformationHeaderRequired:      return soap_wsa_sender_fault_subcode(soap, code, "A required message information header, To, MessageID, or Action, is not present.", "Missing Header QName");    case wsa__DestinationUnreachable:      return soap_wsa_sender_fault_subcode(soap, code, "No route can be determined to reach the destination role defined by the WS-Addressing To.", NULL);    case wsa__ActionNotSupported:      return soap_wsa_sender_fault_subcode(soap, code, "The [action] cannot be processed at the receiver.", soap->action);    case wsa__EndpointUnavailable:      return soap_wsa_receiver_fault_subcode(soap, code, "The endpoint is unable to process the message at this time.", NULL);  }  return SOAP_FAULT;}/******************************************************************************\ * * Plugin registry functions *\******************************************************************************//**@fn int soap_wsa(struct soap *soap, struct soap_plugin *p, void *arg)@brief Plugin registry function, used with soap_register_plugin.@param soap context@param[in,out] p plugin created in registry@param[in] arg passed from soap_register_plugin_arg@return SOAP_OK*/intsoap_wsa(struct soap *soap, struct soap_plugin *p, void *arg){ DBGFUN("soap_wsa");  p->id = soap_wsa_id;  p->data = (void*)SOAP_MALLOC(soap, sizeof(struct soap_wsa_data));  p->fcopy = NULL;  p->fdelete = soap_wsa_delete;  if (p->data)  { if (soap_wsa_init(soap, (struct soap_wsa_data*)p->data))    { SOAP_FREE(soap, p->data);      return SOAP_EOM;    }  }  return SOAP_OK;}/**@fn int soap_wsa_init(struct soap *soap, struct soap_wsa_data *data)@brief Initializes plugin data.@param soap context@param[in,out] data plugin data@return SOAP_OK*/static intsoap_wsa_init(struct soap *soap, struct soap_wsa_data *data){ DBGFUN("soap_wsa_init");  data->fheader = soap->fheader;  data->fseterror = soap->fseterror;  soap->fheader = soap_wsa_header;  soap->fseterror = soap_wsa_set_error;  return SOAP_OK;}/**@fn void soap_wsa_delete(struct soap *soap, struct soap_plugin *p)@brief Deletes plugin data.@param soap context@param[in,out] p plugin@return SOAP_OK*/static voidsoap_wsa_delete(struct soap *soap, struct soap_plugin *p){ DBGFUN("soap_wsa_delete");  SOAP_FREE(soap, p->data);}/******************************************************************************\ * * Callbacks registered by plugin *\******************************************************************************//**@fn int soap_wsa_header(struct soap *soap)@brief Copies WS-Addressing action to SOAP action@param soap context@return SOAP_OK or faultThis callback is invoked to copy the WS-Addressing action to the SOAP actionbefore invoking the service operation.*/static intsoap_wsa_header(struct soap *soap){ struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);  DBGFUN("soap_wsa_header");  if (!data)    return SOAP_PLUGIN_ERROR;  if (data->fheader && data->fheader(soap))    return soap->error;  if (soap->header && soap->header->wsa__Action)    soap->action = soap->header->wsa__Action;  return SOAP_OK;}/**@fn void soap_wsa_set_error(struct soap *soap, const char **c, const char **s)@brief Copies WS-Addressing action to SOAP action@param soap context@param c fault code@param s fault string*/static voidsoap_wsa_set_error(struct soap *soap, const char **c, const char **s){ struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);  DBGFUN("soap_wsa_set_error");  if (!data)    return;  if (data->fseterror)    data->fseterror(soap, c, s);  if (soap->error == SOAP_NO_METHOD)    soap->error = soap_wsa_error(soap, wsa__ActionNotSupported);}/**@fn int soap_wsa_response(struct soap *soap, int status, size_t count)@brief Overrides the HTTP response operations to send an HTTP POST@param soap context@param status code@param count message length (if non-chunked)*/static intsoap_wsa_response(struct soap *soap, int status, size_t count){ struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);  DBGFUN2("soap_wsa_response", "status=%d", status, "count=%lu", (unsigned long)count);  if (!data)    return SOAP_PLUGIN_ERROR;  soap->fresponse = data->fresponse;	/* reset (HTTP response) */  return soap->fpost(soap, soap_strdup(soap, soap->endpoint), soap->host, soap->port, soap->path, soap->action, count);}/******************************************************************************\ * * Misc. *\******************************************************************************//**@fn int soap_wsa_alloc_header(struct soap *soap)@brief Adds SOAP Header if not present.@param soap context@return SOAP_OK*/static intsoap_wsa_alloc_header(struct soap *soap){ if (!soap->header)    soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));  return SOAP_OK;}

⌨️ 快捷键说明

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