00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028 #ifdef HAVE_STRING_H
00029 #include <string.h>
00030 #endif
00031
00032 #ifdef HAVE_ERRNO_H
00033 #include <errno.h>
00034 #endif
00035
00036 #include <libxml/xpath.h>
00037
00038 #include <nanohttp/nanohttp-error.h>
00039 #include <nanohttp/nanohttp-logging.h>
00040
00041 #include "soap-xml.h"
00042 #include "soap-env.h"
00043 #include "soap-ctx.h"
00044 #include "soap-service.h"
00045 #include "soap-router.h"
00046 #include "soap-server.h"
00047 #include "soap-fault.h"
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #define _SOAP_FAULT_TEMPLATE_ \
00061 "<SOAP-ENV:Envelope" \
00062 " xmlns:SOAP-ENV=\"%s\"" \
00063 " SOAP-ENV:encoding=\"%s\"" \
00064 " xmlns:xsi=\"%s\"" \
00065 " xmlns:xsd=\"%s\">" \
00066 "<SOAP-ENV:Header />" \
00067 "<SOAP-ENV:Body>" \
00068 "<SOAP-ENV:Fault>"\
00069 "<faultcode>%s</faultcode>"\
00070 "<faultstring>%s</faultstring>"\
00071 "<faultactor>%s</faultactor>"\
00072 "<detail>%s</detail>"\
00073 "</SOAP-ENV:Fault>" \
00074 "</SOAP-ENV:Body>"\
00075 "</SOAP-ENV:Envelope>"
00076
00077
00078 static const char const *fault_vm = "VersionMismatch";
00079 static const char const *fault_mu = "MustUnderstand";
00080 static const char const *fault_deu = "DataEncodingUnkown";
00081 static const char const *fault_client = "Client";
00082 static const char const *fault_server = "Server";
00083
00084 xmlDocPtr
00085 soap_fault_build(int fault_code, const char *fault_string, const char *fault_actor, const char *detail)
00086 {
00087
00088
00089 const char *faultcode;
00090 int bufferlen = 2000;
00091 char *buffer;
00092 xmlDocPtr fault;
00093
00094 log_verbose1("Build fault");
00095
00096 switch (fault_code)
00097 {
00098 case SOAP_FAULT_VERSION_MISMATCH:
00099 faultcode = fault_vm;
00100 break;
00101 case SOAP_FAULT_MUST_UNDERSTAND:
00102 faultcode = fault_mu;
00103 break;
00104 case SOAP_FAULT_DATA_ENCODING_UNKOWN:
00105 faultcode = fault_deu;
00106 break;
00107 case SOAP_FAULT_RECEIVER:
00108 faultcode = fault_server;
00109 break;
00110 case SOAP_FAULT_SENDER:
00111 default:
00112 faultcode = fault_client;
00113 break;
00114 }
00115
00116
00117 if (fault_string)
00118 bufferlen += strlen(fault_string);
00119 if (fault_actor)
00120 bufferlen += strlen(fault_actor);
00121 if (detail)
00122 bufferlen += strlen(detail);
00123
00124 log_verbose2("Creating buffer with %d bytes", bufferlen);
00125 if (!(buffer = (char *) malloc(bufferlen)))
00126 {
00127 log_error2("malloc failed (%s)", errno);
00128 return NULL;
00129 }
00130
00131 sprintf(buffer, _SOAP_FAULT_TEMPLATE_,
00132 soap_env_ns, soap_env_enc, soap_xsi_ns,
00133 soap_xsd_ns, faultcode,
00134 fault_string ? fault_string : "error",
00135 fault_actor ? fault_actor : "", detail ? detail : "");
00136
00137 fault = xmlParseDoc(BAD_CAST buffer);
00138 free(buffer);
00139
00140 if (fault == NULL)
00141 {
00142 log_error1("Cannot create XML document!");
00143
00144 return soap_fault_build(fault_code, "Cannot create fault object in XML", soap_server_get_name(), NULL);
00145 }
00146
00147 log_verbose2("Returning fault (%p)", fault);
00148 return fault;
00149 }