1 #define _XOPEN_SOURCE 500 /* strdup from string.h */
8 /* Private structure for write_body() call back */
15 /* Close connection to server and destroy CURL handle associated
17 _hidden isds_error
close_connection(struct isds_ctx
*context
) {
18 if (!context
) return IE_INVALID_CONTEXT
;
21 curl_easy_cleanup(context
->curl
);
23 isds_log(ILF_HTTP
, ILL_DEBUG
, _("Connection to server %s closed\n"),
27 return IE_CONNECTION_CLOSED
;
32 /* CURL call back function called when chunk of HTTP reponse body is available.
33 * @buffer points to new data
34 * @size * @nmemb is length of the chunk in bytes. Zero means empty body.
35 * @userp is private structure.
36 * Must reuturn the length of the chunk, otherwise CURL will signal
37 * CURL_WRITE_ERROR. */
38 static size_t write_body(void *buffer
, size_t size
, size_t nmemb
, void *userp
) {
39 struct soap_body
*body
= (struct soap_body
*) userp
;
42 /* FIXME: Check for (size * nmemb + body->lengt) !> SIZE_T_MAX.
43 * Precompute the product then. */
45 if (!body
) return 0; /* This should never happen */
46 if (0 == (size
* nmemb
)) return 0; /* Empty body */
48 new_data
= realloc(body
->data
, body
->length
+ size
* nmemb
);
49 if (!new_data
) return 0;
51 memcpy(new_data
+ body
->length
, buffer
, size
* nmemb
);
53 body
->data
= new_data
;
54 body
->length
+= size
* nmemb
;
56 return (size
* nmemb
);
60 /* CURL progress callback proxy to rearrange arguments.
61 * @curl_data is session context */
62 static int progress_proxy(void *curl_data
, double download_total
,
63 double download_current
, double upload_total
, double upload_current
) {
64 struct isds_ctx
*context
= (struct isds_ctx
*) curl_data
;
67 if (context
&& context
->progress_callback
) {
68 abort
= context
->progress_callback(
69 upload_total
, upload_current
,
70 download_total
, download_current
,
71 context
->progress_callback_data
);
73 isds_log(ILF_HTTP
, ILL_INFO
,
74 _("Application aborted HTTP transfer"));
83 * @context holds the base URL,
84 * @url is a (CGI) file of SOAP URL,
85 * @request is body for POST request
86 * @request_length is length of @request in bytes
87 * @reponse is automatically reallocated() buffer to fit HTTP response with
88 * @response_length (does not need to match allocatef memory exactly). You must
89 * free() the @response.
90 * @mime_type is automatically allocated MIME type send by server (*NULL if not
91 * sent). Set NULL if you don't care.
92 * @charset is charset of the body signaled by server. The same constrains
93 * like on @mime_type apply.
94 * @http_code is final HTTP code returned by server. This can be 200, 401, 500
95 * or any other one. Pass NULL if you don't interrest.
96 * In case of error, the response memory, MIME type, charset and lenght will be
97 * deallocated and zerod automatically. Thus be sure they are preallocated or
98 * they points to NULL.
99 * Be ware that successful return value does not mean the HTTP request has
100 * been accepted by the server. You must cosult @http_code. OTOH, failure
101 * return value means the request could not been sent (e.g. SSL error).
102 * Side effect: message buffer */
103 static isds_error
http(struct isds_ctx
*context
, const char *url
,
104 const void *request
, const size_t request_length
,
105 void **response
, size_t *response_length
,
106 char **mime_type
, char **charset
, long *http_code
) {
109 isds_error err
= IE_SUCCESS
;
110 struct soap_body body
;
112 struct curl_slist
*headers
= NULL
;
115 if (!context
) return IE_INVALID_CONTEXT
;
116 if (!url
) return IE_INVAL
;
117 if (request_length
> 0 && !request
) return IE_INVAL
;
118 if (!response
|| !response_length
) return IE_INVAL
;
120 /* Set the body here to allow deallocatation in leave block */
121 body
.data
= *response
;
124 /* Set Request-URI */
125 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_URL
, url
);
127 /* Set TLS options */
128 if (!curl_err
&& context
->tls_verify_server
) {
129 if (!*context
->tls_verify_server
)
130 isds_log(ILF_SEC
, ILL_WARNING
,
131 _("Disabling server identity verification. "
132 "That was your decision.\n"));
133 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSL_VERIFYPEER
,
134 (*context
->tls_verify_server
)? 1L : 0L);
136 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSL_VERIFYHOST
,
137 (*context
->tls_verify_server
)? 2L : 0L);
140 if (!curl_err
&& context
->tls_ca_file
) {
141 isds_log(ILF_SEC
, ILL_INFO
,
142 _("CA certificates will be searched in `%s' file since now\n"),
143 context
->tls_ca_file
);
144 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_CAINFO
,
145 context
->tls_ca_file
);
147 if (!curl_err
&& context
->tls_ca_dir
) {
148 isds_log(ILF_SEC
, ILL_INFO
,
149 _("CA certificates will be searched in `%s' directory "
150 "since now\n"), context
->tls_ca_dir
);
151 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_CAPATH
,
152 context
->tls_ca_dir
);
156 /* Set credentials */
157 #if HAVE_DECL_CURLOPT_USERNAME /* Since curl-7.19.1 */
158 if (!curl_err
&& context
->username
) {
159 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_USERNAME
,
162 if (!curl_err
&& context
->password
) {
163 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_PASSWORD
,
167 if (!curl_err
&& (context
->username
|| context
->password
)) {
168 char *userpwd
= astrcat3(context
->username
, ":", context
->password
);
170 isds_log_message(context
, _("Could not pass credentials to CURL"));
174 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_USERPWD
, userpwd
);
177 #endif /* not HAVE_DECL_CURLOPT_USERNAME */
179 /* Set PKI credentials */
180 if (!curl_err
&& (context
->pki_credentials
)) {
181 if (context
->pki_credentials
->engine
) {
182 /* Select SSL engine */
183 isds_log(ILF_SEC
, ILL_INFO
,
184 _("Cryptograhic engine `%s' will be used for "
185 "key or certificate\n"),
186 context
->pki_credentials
->engine
);
187 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSLENGINE
,
188 context
->pki_credentials
->engine
);
192 /* Select certificate format */
193 #if HAVE_DECL_CURLOPT_SSLCERTTYPE /* since curl-7.9.3 */
194 if (context
->pki_credentials
->certificate_format
==
196 /* XXX: It's valid to have certificate in engine without name.
197 * Engines can select certificate according private key and
199 if (context
->pki_credentials
->certificate
)
200 isds_log(ILF_SEC
, ILL_INFO
, _("Client `%s' certificate "
201 "will be read from `%s' engine\n"),
202 context
->pki_credentials
->certificate
,
203 context
->pki_credentials
->engine
);
205 isds_log(ILF_SEC
, ILL_INFO
, _("Client certificate "
206 "will be read from `%s' engine\n"),
207 context
->pki_credentials
->engine
);
208 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSLCERTTYPE
,
210 } else if (context
->pki_credentials
->certificate
) {
211 isds_log(ILF_SEC
, ILL_INFO
, _("Client %s certificate "
212 "will be read from `%s' file\n"),
213 (context
->pki_credentials
->certificate_format
==
214 PKI_FORMAT_DER
) ? _("DER") : _("PEM"),
215 context
->pki_credentials
->certificate
);
216 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSLCERTTYPE
,
217 (context
->pki_credentials
->certificate_format
==
218 PKI_FORMAT_DER
) ? "DER" : "PEM");
221 if ((context
->pki_credentials
->certificate_format
==
223 context
->pki_credentials
->certificate
))
224 isds_log(ILF_SEC
, ILL_WARNING
,
225 _("Your curl library cannot distinguish certifcate "
226 "formats. Make sure your cryptographic library\n"
227 "understands your certificate file by default, "
228 "or upgrade curl.\n"));
229 #endif /* not HAVE_DECL_CURLOPT_SSLCERTTYPE */
232 if (!curl_err
&& context
->pki_credentials
->certificate
) {
233 /* Select certificate */
235 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSLCERT
,
236 context
->pki_credentials
->certificate
);
240 /* Select key format */
241 if (context
->pki_credentials
->key_format
== PKI_FORMAT_ENG
) {
242 if (context
->pki_credentials
->key
)
243 isds_log(ILF_SEC
, ILL_INFO
, _("Client private key `%s' "
244 "from `%s' engine will be used\n"),
245 context
->pki_credentials
->key
,
246 context
->pki_credentials
->engine
);
248 isds_log(ILF_SEC
, ILL_INFO
, _("Client private key "
249 "from `%s' engine will be used\n"),
250 context
->pki_credentials
->engine
);
251 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSLKEYTYPE
,
253 } else if (context
->pki_credentials
->key
) {
254 isds_log(ILF_SEC
, ILL_INFO
, _("Client %s private key will be "
255 "read from `%s' file\n"),
256 (context
->pki_credentials
->key_format
==
257 PKI_FORMAT_DER
) ? _("DER") : _("PEM"),
258 context
->pki_credentials
->key
);
259 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSLKEYTYPE
,
260 (context
->pki_credentials
->key_format
==
261 PKI_FORMAT_DER
) ? "DER" : "PEM");
266 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_SSLKEY
,
267 context
->pki_credentials
->key
);
270 /* Pass key passphrase */
271 #if HAVE_DECL_CURLOPT_KEYPASSWD /* since curl-7.16.5 */
272 curl_err
= curl_easy_setopt(context
->curl
,
274 context
->pki_credentials
->passphrase
);
275 #elif HAVE_DECL_CURLOPT_SSLKEYPASSWD /* up to curl-7.16.4 */
276 curl_err
= curl_easy_setopt(context
->curl
,
277 CURLOPT_SSLKEYPASSWD
,
278 context
->pki_credentials
->passphrase
);
279 #else /* up to curl-7.9.2 */
280 curl_err
= curl_easy_setopt(context
->curl
,
281 CURLOPT_SSLCERTPASSWD
,
282 context
->pki_credentials
->passphrase
);
290 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_NOSIGNAL
, 1);
292 if (!curl_err
&& context
->timeout
) {
293 #if HAVE_DECL_CURLOPT_TIMEOUT_MS /* Since curl-7.16.2 */
294 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_TIMEOUT_MS
,
297 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_TIMEOUT
,
298 context
->timeout
/ 1000);
299 #endif /* not HAVE_DECL_CURLOPT_TIMEOUT_MS */
302 /* Register callback */
303 if (context
->progress_callback
) {
305 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_NOPROGRESS
, 0);
308 curl_err
= curl_easy_setopt(context
->curl
,
309 CURLOPT_PROGRESSFUNCTION
, progress_proxy
);
312 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_PROGRESSDATA
,
317 /* Set other CURL features */
319 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_FAILONERROR
, 0);
322 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_FOLLOWLOCATION
, 1);
325 /* TODO: Make the redirect depth configurable */
326 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_MAXREDIRS
, 8);
329 curl_err
= curl_easy_setopt(context
->curl
,
330 CURLOPT_UNRESTRICTED_AUTH
, 1);
333 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_COOKIEFILE
, "");
336 /* Set get-response function */
338 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_WRITEFUNCTION
,
342 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_WRITEDATA
, &body
);
345 /* Set MIME types and headers requires by SOAP 1.1.
346 * SOAP 1.1 requires text/xml, SOAP 1.2 requires application/soap+xml */
348 headers
= curl_slist_append(headers
,
349 "Accept: application/soap+xml,application/xml,text/xml");
354 headers
= curl_slist_append(headers
, "Content-Type: text/xml");
359 headers
= curl_slist_append(headers
, "SOAPAction: ");
364 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_HTTPHEADER
, headers
);
367 /* Set user agent identification */
368 /* TODO: Present library version, curl etc. in User-Agent */
369 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_USERAGENT
, "libisds");
372 /* Set POST request body */
374 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_POST
, 1);
377 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_POSTFIELDS
, request
);
380 curl_err
= curl_easy_setopt(context
->curl
, CURLOPT_POSTFIELDSIZE
,
384 /* Check for errors so far */
386 isds_log_message(context
, curl_easy_strerror(curl_err
));
391 isds_log(ILF_HTTP
, ILL_DEBUG
, _("Sending POST request to %s\n"), url
);
392 isds_log(ILF_HTTP
, ILL_DEBUG
,
393 _("POST body length: %zu, content follows:\n"), request_length
);
394 isds_log(ILF_HTTP
, ILL_DEBUG
, "%.*s\n", request_length
, request
);
395 isds_log(ILF_HTTP
, ILL_DEBUG
, _("End of POST body\n"));
396 if ((log_facilities
& ILF_HTTP
) && (log_level
>= ILL_DEBUG
) ) {
397 curl_easy_setopt(context
->curl
, CURLOPT_VERBOSE
, 1);
402 curl_err
= curl_easy_perform(context
->curl
);
404 /* Wipe credentials out of the handler */
405 #if HAVE_DECL_CURLOPT_USERNAME /* Since curl-7.19.1 */
406 if (context
->username
) {
407 curl_easy_setopt(context
->curl
, CURLOPT_USERNAME
, NULL
);
409 if (context
->password
) {
410 curl_easy_setopt(context
->curl
, CURLOPT_PASSWORD
, NULL
);
413 if (context
->username
|| context
->password
) {
414 curl_easy_setopt(context
->curl
, CURLOPT_USERPWD
, NULL
);
416 #endif /* not HAVE_DECL_CURLOPT_USERNAME */
419 curl_err
= curl_easy_getinfo(context
->curl
, CURLINFO_CONTENT_TYPE
,
423 /* TODO: CURL is not internationalized yet. Collect CURL messages for
425 isds_printf_message(context
,
426 _("%s: %s"), url
, _(curl_easy_strerror(curl_err
)));
427 if (curl_err
== CURLE_ABORTED_BY_CALLBACK
)
434 isds_log(ILF_HTTP
, ILL_DEBUG
, _("Final response to %s received\n"), url
);
435 isds_log(ILF_HTTP
, ILL_DEBUG
,
436 _("Response body length: %zu, content follows:\n"),
438 isds_log(ILF_HTTP
, ILL_DEBUG
, "%.*s\n", body
.length
, body
.data
);
439 isds_log(ILF_HTTP
, ILL_DEBUG
, _("End of response body\n"));
442 /* Extract MIME type and charset */
447 sep
= strchr(content_type
, ';');
448 if (sep
) offset
= (size_t) (sep
- content_type
);
449 else offset
= strlen(content_type
);
452 *mime_type
= malloc(offset
+ 1);
457 memcpy(*mime_type
, content_type
, offset
);
458 (*mime_type
)[offset
] = '\0';
465 sep
= strstr(sep
, "charset=");
469 *charset
= strdup(sep
+ 8);
479 /* Get HTTP response code */
481 curl_err
= curl_easy_getinfo(context
->curl
,
482 CURLINFO_RESPONSE_CODE
, http_code
);
490 curl_slist_free_all(headers
);
506 if (err
!= IE_ABORTED
) close_connection(context
);
509 *response
= body
.data
;
510 *response_length
= body
.length
;
517 * @context holds the base URL,
518 * @file is a (CGI) file of SOAP URL,
519 * @request is XML node set with SOAP request body.
520 * @file must be NULL, @request should be NULL rather than empty, if they should
521 * not be signaled in the SOAP request.
522 * @reponse is automatically allocated() node set with SOAP response body.
523 * You must xmlFreeNodeList() it. This is literal body, empty (NULL), one node
524 * or more nodes can be returned.
525 * @raw_response is automatically allocated bitstream with response body. Use
526 * NULL if you don't care
527 * @raw_response_length is size of @raw_response in bytes
528 * In case of error the response will be deallocated automatically.
529 * Side effect: message buffer */
530 _hidden isds_error
soap(struct isds_ctx
*context
, const char *file
,
531 const xmlNodePtr request
, xmlNodePtr
*response
,
532 void **raw_response
, size_t *raw_response_length
) {
534 isds_error err
= IE_SUCCESS
;
536 char *mime_type
= NULL
;
538 xmlBufferPtr http_request
= NULL
;
539 xmlSaveCtxtPtr save_ctx
= NULL
;
540 xmlDocPtr request_soap_doc
= NULL
;
541 xmlNodePtr request_soap_envelope
= NULL
, request_soap_body
= NULL
;
542 xmlNsPtr soap_ns
= NULL
;
543 void *http_response
= NULL
;
544 size_t response_length
= 0;
545 xmlDocPtr response_soap_doc
= NULL
;
546 xmlNodePtr response_root
= NULL
;
547 xmlXPathContextPtr xpath_ctx
= NULL
;
548 xmlXPathObjectPtr response_soap_headers
= NULL
, response_soap_body
= NULL
,
549 response_soap_fault
= NULL
;
552 if (!context
) return IE_INVALID_CONTEXT
;
553 if (!response
) return IE_INVAL
;
554 if (!raw_response_length
&& raw_response
) return IE_INVAL
;
556 xmlFreeNodeList(*response
);
558 if (raw_response
) *raw_response
= NULL
;
560 url
= astrcat(context
->url
, file
);
561 if (!url
) return IE_NOMEM
;
563 /* Build SOAP request envelope */
564 request_soap_doc
= xmlNewDoc(BAD_CAST
"1.0");
565 if (!request_soap_doc
) {
566 isds_log_message(context
, _("Could not build SOAP request document"));
570 request_soap_envelope
= xmlNewNode(NULL
, BAD_CAST
"Envelope");
571 if (!request_soap_envelope
) {
572 isds_log_message(context
, _("Could not build SOAP request envelope"));
576 xmlDocSetRootElement(request_soap_doc
, request_soap_envelope
);
577 /* Only this way we get namespace definition as @xmlns:soap,
578 * otherwise we get namespace prefix without definition */
579 soap_ns
= xmlNewNs(request_soap_envelope
, BAD_CAST SOAP_NS
, NULL
);
581 isds_log_message(context
, _("Could not create SOAP name space"));
585 xmlSetNs(request_soap_envelope
, soap_ns
);
586 request_soap_body
= xmlNewChild(request_soap_envelope
, NULL
,
587 BAD_CAST
"Body", NULL
);
588 if (!request_soap_body
) {
589 isds_log_message(context
,
590 _("Could not add Body to SOAP request envelope"));
595 /* Append request XML node set to SOAP body if request is not empty */
596 /* XXX: Copy of request must be used, otherwise xmlFreeDoc(request_soap_doc)
597 * would destroy this outer structure. */
599 xmlNodePtr request_copy
= xmlCopyNodeList(request
);
601 isds_log_message(context
,
602 _("Could not copy request content"));
606 if (!xmlAddChildList(request_soap_body
, request_copy
)) {
607 xmlFreeNodeList(request_copy
);
608 isds_log_message(context
,
609 _("Could not add request content to SOAP "
610 "request envelope"));
617 /* Serialize the SOAP request into HTTP request body */
618 http_request
= xmlBufferCreate();
620 isds_log_message(context
,
621 _("Could not create xmlBuffer for HTTP request body"));
625 /* Last argument 1 means format the XML tree. This is pretty but it breaks
626 * digital signatures probably because ISDS abandoned XMLDSig */
627 save_ctx
= xmlSaveToBuffer(http_request
, "UTF-8", 1);
629 isds_log_message(context
,
630 _("Could not create XML serializer"));
634 /* XXX: According LibXML documentation, this function does not return
635 * meaningfull value yet */
636 xmlSaveDoc(save_ctx
, request_soap_doc
);
637 if (-1 == xmlSaveFlush(save_ctx
)) {
638 isds_log_message(context
,
639 _("Could not serialize SOAP request to HTTP request bddy"));
644 isds_log(ILF_SOAP
, ILL_DEBUG
,
645 _("SOAP request to sent to %s:\n%.*s\nEnd of SOAP request\n"),
646 url
, http_request
->use
, http_request
->content
);
648 err
= http(context
, url
, http_request
->content
, http_request
->use
,
649 &http_response
, &response_length
,
650 &mime_type
, NULL
, &http_code
);
652 /* TODO: HTTP binding for SOAP prescribes non-200 HTTP return codes
653 * to be processes too. */
659 /* Check for HTTP return code */
660 isds_log(ILF_SOAP
, ILL_DEBUG
, _("Server returned %ld HTTP code\n"),
663 /* XXX: We must see which code is used for not permitted ISDS
664 * operation like downloading message without proper user
665 * permissions. In that cat we should keep connection opened. */
667 err
= IE_NOT_LOGGED_IN
;
668 isds_log_message(context
, _("Authentication failed"));
673 isds_printf_message(context
,
674 _("Code 404: Document (%s) not found on server"), url
);
677 /* 500 should return standard SOAP message */
680 /* Check for Content-Type: text/xml.
681 * Do it after HTTP code check because 401 Unauthorized returns HTML web
682 * page for browsers. */
683 if (mime_type
&& strcmp(mime_type
, "text/xml")
684 && strcmp(mime_type
, "application/soap+xml")
685 && strcmp(mime_type
, "application/xml")) {
686 char *mime_type_locale
= utf82locale(mime_type
);
687 isds_printf_message(context
,
688 _("%s: bad MIME type sent by server: %s"), url
,
690 free(mime_type_locale
);
695 /* TODO: Convert returned body into XML default encoding */
697 /* Parse the HTTP body as XML */
698 response_soap_doc
= xmlParseMemory(http_response
, response_length
);
699 if (!response_soap_doc
) {
704 xpath_ctx
= xmlXPathNewContext(response_soap_doc
);
710 if (register_namespaces(xpath_ctx
, MESSAGE_NS_UNSIGNED
)) {
715 isds_log(ILF_SOAP
, ILL_DEBUG
,
716 _("SOAP response received:\n%.*s\nEnd of SOAP response\n"),
717 response_length
, http_response
);
720 /* Check for SOAP version */
721 response_root
= xmlDocGetRootElement(response_soap_doc
);
722 if (!response_root
) {
723 isds_log_message(context
, "SOAP response has no root element");
727 if (xmlStrcmp(response_root
->name
, BAD_CAST
"Envelope") ||
728 xmlStrcmp(response_root
->ns
->href
, BAD_CAST SOAP_NS
)) {
729 isds_log_message(context
, "SOAP response is not SOAP 1.1 document");
734 /* Check for SOAP Headers */
735 response_soap_headers
= xmlXPathEvalExpression(
736 BAD_CAST
"/soap:Envelope/soap:Header/"
737 "*[@soap:mustUnderstand/text() = true()]", xpath_ctx
);
738 if (!response_soap_headers
) {
742 if (!xmlXPathNodeSetIsEmpty(response_soap_headers
->nodesetval
)) {
743 isds_log_message(context
,
744 _("SOAP response requires unsupported feature"));
745 /* TODO: log the headers
746 * xmlChar *fragment = NULL;
747 * fragment = xmlXPathCastNodeSetToSting(response_soap_headers->nodesetval);*/
753 response_soap_body
= xmlXPathEvalExpression(
754 BAD_CAST
"/soap:Envelope/soap:Body", xpath_ctx
);
755 if (!response_soap_body
) {
759 if (xmlXPathNodeSetIsEmpty(response_soap_body
->nodesetval
)) {
760 isds_log_message(context
,
761 _("SOAP response does not contain SOAP Body element"));
765 if (response_soap_body
->nodesetval
->nodeNr
> 1) {
766 isds_log_message(context
,
767 _("SOAP response has more than one Body element"));
772 /* Check for SOAP Fault */
773 response_soap_fault
= xmlXPathEvalExpression(
774 BAD_CAST
"/soap:Envelope/soap:Body/soap:Fault", xpath_ctx
);
775 if (!response_soap_fault
) {
779 if (!xmlXPathNodeSetIsEmpty(response_soap_fault
->nodesetval
)) {
780 /* TODO: log the faultcode and faultstring */
781 isds_log_message(context
, _("SOAP response signals Fault"));
787 /* Extract XML Tree with ISDS response from SOAP envelope and return it.
788 * XXX: response_soap_body is Body, we need children which may not exist
789 * (i.e. empty Body). */
790 /* TODO: Destroy SOAP response but Body childern. This is more memory
791 * friendly than copying (potentialy) fat body */
792 if (response_soap_body
->nodesetval
->nodeTab
[0]->children
) {
793 *response
= xmlDocCopyNodeList(response_soap_doc
,
794 response_soap_body
->nodesetval
->nodeTab
[0]->children
);
799 } else *response
= NULL
;
801 /* Save raw response */
803 *raw_response
= http_response
;
804 *raw_response_length
= response_length
;
805 http_response
= NULL
;
811 xmlFreeNodeList(*response
);
815 xmlXPathFreeObject(response_soap_fault
);
816 xmlXPathFreeObject(response_soap_body
);
817 xmlXPathFreeObject(response_soap_headers
);
818 xmlXPathFreeContext(xpath_ctx
);
819 xmlFreeDoc(response_soap_doc
);
822 xmlSaveClose(save_ctx
);
823 xmlBufferFree(http_request
);
824 xmlFreeDoc(request_soap_doc
); /* recursive, frees request_body, soap_ns*/
833 * void xmlInitParser(void)
834 * Initialization function for the XML parser. This is not reentrant. Call
835 * once before processing in case of use in multithreaded programs.
837 * int xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
838 * Initialize a parser context
840 * xmlDocPtr xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur,
841 * const * char URL, const char * encoding, int options);
842 * Parse in-memory NULL-terminated document @cur.
844 * xmlDocPtr xmlParseMemory(const char * buffer, int size)
845 * Parse an XML in-memory block and build a tree.
847 * xmlParserCtxtPtr xmlCreateMemoryParserCtxt(const char * buffer, int
849 * Create a parser context for an XML in-memory document.
851 * xmlParserCtxtPtr xmlCreateDocParserCtxt(const xmlChar * cur)
852 * Creates a parser context for an XML in-memory document.
854 * xmlDocPtr xmlCtxtReadMemory(xmlParserCtxtPtr ctxt,
855 * const char * buffer, int size, const char * URL, const char * encoding,
857 * Parse an XML in-memory document and build a tree. This reuses the existing
858 * @ctxt parser context.
860 * void xmlCleanupParser(void)
861 * Cleanup function for the XML library. It tries to reclaim all parsing
862 * related glob document related memory. Calling this function should not
863 * prevent reusing the libr finished using the library or XML document built
866 * void xmlClearParserCtxt(xmlParserCtxtPtr ctxt)
867 * Clear (release owned resources) and reinitialize a parser context.
869 * void xmlCtxtReset(xmlParserCtxtPtr ctxt)
870 * Reset a parser context
872 * void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
873 * Free all the memory used by a parser context. However the parsed document
874 * in ctxt->myDoc is not freed.
876 * void xmlFreeDoc(xmlDocPtr cur)
877 * Free up all the structures used by a document, tree included.