Aborted transfer does not close connection
[libisds.git] / src / soap.c
blobe8f9b81041175d5764e1c494e547c22ab2ccf41c
1 #define _XOPEN_SOURCE 500 /* strdup from string.h */
2 #include "isds_priv.h"
3 #include "soap.h"
4 #include "utils.h"
5 #include <stdlib.h>
6 #include <string.h>
8 /* Private structure for write_body() call back */
9 struct soap_body {
10 void *data;
11 size_t length;
15 /* Close connection to server and destroy CURL handle associated
16 * with @context */
17 _hidden isds_error close_connection(struct isds_ctx *context) {
18 if (!context) return IE_INVALID_CONTEXT;
20 if (context->curl) {
21 curl_easy_cleanup(context->curl);
22 context->curl = NULL;
23 isds_log(ILF_HTTP, ILL_DEBUG, _("Connection to server %s closed\n"),
24 context->url);
25 return IE_SUCCESS;
26 } else {
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;
40 void *new_data;
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;
65 int abort = 0;
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);
72 if (abort) {
73 isds_log(ILF_HTTP, ILL_INFO,
74 _("Application aborted HTTP transfer"));
78 return abort;
82 /* Do HTTP request.
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) {
108 CURLcode curl_err;
109 isds_error err = IE_SUCCESS;
110 struct soap_body body;
111 char *content_type;
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 deallocataion in leave block */
121 body.data = *response;
122 body.length = 0;
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);
135 if (!curl_err) {
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_file);
151 curl_err = curl_easy_setopt(context->curl, CURLOPT_CAINFO,
152 context->tls_ca_file);
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,
160 context->username);
162 if (!curl_err && context->password) {
163 curl_err = curl_easy_setopt(context->curl, CURLOPT_PASSWORD,
164 context->password);
166 #else
167 if (!curl_err && (context->username || context->password)) {
168 char *userpwd = astrcat3(context->username, ":", context->password);
169 if (!userpwd) {
170 isds_log_message(context, _("Could not pass credentials to CURL"));
171 err = IE_NOMEM;
172 goto leave;
174 curl_err = curl_easy_setopt(context->curl, CURLOPT_USERPWD, userpwd);
175 free(userpwd);
177 #endif /* not HAVE_DECL_CURLOPT_USERNAME */
179 /* Set timeout */
180 if (!curl_err) {
181 curl_err = curl_easy_setopt(context->curl, CURLOPT_NOSIGNAL, 1);
183 if (!curl_err && context->timeout) {
184 #if HAVE_DECL_CURLOPT_TIMEOUT_MS /* Since curl-7.16.2 */
185 curl_err = curl_easy_setopt(context->curl, CURLOPT_TIMEOUT_MS,
186 context->timeout);
187 #else
188 curl_err = curl_easy_setopt(context->curl, CURLOPT_TIMEOUT,
189 context->timeout / 1000);
190 #endif /* not HAVE_DECL_CURLOPT_TIMEOUT_MS */
193 /* Register callback */
194 if (context->progress_callback) {
195 if (!curl_err) {
196 curl_err = curl_easy_setopt(context->curl, CURLOPT_NOPROGRESS, 0);
198 if (!curl_err) {
199 curl_err = curl_easy_setopt(context->curl,
200 CURLOPT_PROGRESSFUNCTION, progress_proxy);
202 if (!curl_err) {
203 curl_err = curl_easy_setopt(context->curl, CURLOPT_PROGRESSDATA,
204 context);
208 /* Set other CURL features */
209 if (!curl_err) {
210 curl_err = curl_easy_setopt(context->curl, CURLOPT_FAILONERROR, 0);
212 if (!curl_err) {
213 curl_err = curl_easy_setopt(context->curl, CURLOPT_FOLLOWLOCATION, 1);
215 if (!curl_err) {
216 /* TODO: Make the redirect depth configurable */
217 curl_err = curl_easy_setopt(context->curl, CURLOPT_MAXREDIRS, 8);
219 if (!curl_err) {
220 curl_err = curl_easy_setopt(context->curl,
221 CURLOPT_UNRESTRICTED_AUTH, 1);
223 if (!curl_err) {
224 curl_err = curl_easy_setopt(context->curl, CURLOPT_COOKIEFILE, "");
227 /* Set get-response function */
228 if (!curl_err) {
229 curl_err = curl_easy_setopt(context->curl, CURLOPT_WRITEFUNCTION,
230 write_body);
232 if (!curl_err) {
233 curl_err = curl_easy_setopt(context->curl, CURLOPT_WRITEDATA, &body);
236 /* Set MIME types and headers requires by SOAP 1.1.
237 * SOAP 1.1 requires text/xml, SOAP 1.2 requires application/soap+xml */
238 if (!curl_err) {
239 headers = curl_slist_append(headers,
240 "Accept: application/soap+xml,application/xml,text/xml");
241 if (!headers) {
242 err = IE_NOMEM;
243 goto leave;
245 headers = curl_slist_append(headers, "Content-Type: text/xml");
246 if (!headers) {
247 err = IE_NOMEM;
248 goto leave;
250 headers = curl_slist_append(headers, "SOAPAction: ");
251 if (!headers) {
252 err = IE_NOMEM;
253 goto leave;
255 curl_err = curl_easy_setopt(context->curl, CURLOPT_HTTPHEADER, headers);
257 if (!curl_err) {
258 /* Set user agent identification */
259 /* TODO: Present library version, curl etc. in User-Agent */
260 curl_err = curl_easy_setopt(context->curl, CURLOPT_USERAGENT, "libisds");
263 /* Set POST request body */
264 if (!curl_err) {
265 curl_err = curl_easy_setopt(context->curl, CURLOPT_POST, 1);
267 if (!curl_err) {
268 curl_err = curl_easy_setopt(context->curl, CURLOPT_POSTFIELDS, request);
270 if (!curl_err) {
271 curl_err = curl_easy_setopt(context->curl, CURLOPT_POSTFIELDSIZE,
272 request_length);
275 /* Check for errors so far */
276 if (curl_err) {
277 isds_log_message(context, curl_easy_strerror(curl_err));
278 if (curl_err == CURLE_ABORTED_BY_CALLBACK)
279 err = IE_ABORTED;
280 else
281 err = IE_NETWORK;
282 goto leave;
285 isds_log(ILF_HTTP, ILL_DEBUG, _("Sending POST request to %s\n"), url);
286 isds_log(ILF_HTTP, ILL_DEBUG,
287 _("POST body length: %zu, content follows:\n"), request_length);
288 isds_log(ILF_HTTP, ILL_DEBUG, "%.*s\n", request_length, request);
289 isds_log(ILF_HTTP, ILL_DEBUG, _("End of POST body\n"));
290 if ((log_facilities & ILF_HTTP) && (log_level >= ILL_DEBUG) ) {
291 curl_easy_setopt(context->curl, CURLOPT_VERBOSE, 1);
295 /* Do the request */
296 curl_err = curl_easy_perform(context->curl);
298 /* Wipe credentials out of the handler */
299 #if HAVE_DECL_CURLOPT_USERNAME /* Since curl-7.19.1 */
300 if (context->username) {
301 curl_easy_setopt(context->curl, CURLOPT_USERNAME, NULL);
303 if (context->password) {
304 curl_easy_setopt(context->curl, CURLOPT_PASSWORD, NULL);
306 #else
307 if (context->username || context->password) {
308 curl_easy_setopt(context->curl, CURLOPT_USERPWD, NULL);
310 #endif /* not HAVE_DECL_CURLOPT_USERNAME */
312 if (!curl_err)
313 curl_err = curl_easy_getinfo(context->curl, CURLINFO_CONTENT_TYPE,
314 &content_type);
316 if (curl_err) {
317 /* TODO: CURL is not internationalized yet. Collect CURL messages for
318 * I18N. */
319 isds_printf_message(context,
320 _("%s: %s"), url, _(curl_easy_strerror(curl_err)));
321 err = IE_NETWORK;
322 goto leave;
325 isds_log(ILF_HTTP, ILL_DEBUG, _("Final response to %s received\n"), url);
326 isds_log(ILF_HTTP, ILL_DEBUG,
327 _("Response body length: %zu, content follows:\n"),
328 body.length);
329 isds_log(ILF_HTTP, ILL_DEBUG, "%.*s\n", body.length, body.data);
330 isds_log(ILF_HTTP, ILL_DEBUG, _("End of response body\n"));
333 /* Extract MIME type and charset */
334 if (content_type) {
335 char *sep;
336 size_t offset;
338 sep = strchr(content_type, ';');
339 if (sep) offset = (size_t) (sep - content_type);
340 else offset = strlen(content_type);
342 if (mime_type) {
343 *mime_type = malloc(offset + 1);
344 if (!*mime_type) {
345 err = IE_NOMEM;
346 goto leave;
348 memcpy(*mime_type, content_type, offset);
349 (*mime_type)[offset] = '\0';
352 if (charset) {
353 if (!sep) {
354 *charset = NULL;
355 } else {
356 sep = strstr(sep, "charset=");
357 if (!sep) {
358 *charset = NULL;
359 } else {
360 *charset = strdup(sep + 8);
361 if (!*charset) {
362 err = IE_NOMEM;
363 goto leave;
370 /* Get HTTP response code */
371 if (http_code) {
372 curl_err = curl_easy_getinfo(context->curl,
373 CURLINFO_RESPONSE_CODE, http_code);
374 if (curl_err) {
375 err = IE_ERROR;
376 goto leave;
380 leave:
381 curl_slist_free_all(headers);
383 if (err) {
384 free(body.data);
385 body.data = NULL;
386 body.length = 0;
388 if (mime_type) {
389 free(*mime_type);
390 *mime_type = NULL;
392 if (charset) {
393 free(*charset);
394 *charset = NULL;
397 if (err != IE_ABORTED) close_connection(context);
400 *response = body.data;
401 *response_length = body.length;
403 return err;
407 /* Do SOAP request.
408 * @context holds the base URL,
409 * @file is a (CGI) file of SOAP URL,
410 * @request is XML node set with SOAP request body.
411 * @file must be NULL, @request should be NULL rather than empty, if they should
412 * not be signaled in the SOAP request.
413 * @reponse is automatically allocated() node set with SOAP response body.
414 * You must xmlFreeNodeList() it. This is literal body, empty (NULL), one node
415 * or more nodes can be returned.
416 * @raw_response is automatically allocated bitstream with response body. Use
417 * NULL if you don't care
418 * @raw_response_length is size of @raw_response in bytes
419 * In case of error the response will be deallocated automatically.
420 * Side effect: message buffer */
421 _hidden isds_error soap(struct isds_ctx *context, const char *file,
422 const xmlNodePtr request, xmlNodePtr *response,
423 void **raw_response, size_t *raw_response_length) {
425 isds_error err = IE_SUCCESS;
426 char *url = NULL;
427 char *mime_type = NULL;
428 long http_code = 0;
429 xmlBufferPtr http_request = NULL;
430 xmlSaveCtxtPtr save_ctx = NULL;
431 xmlDocPtr request_soap_doc = NULL;
432 xmlNodePtr request_soap_envelope = NULL, request_soap_body = NULL;
433 xmlNsPtr soap_ns = NULL;
434 void *http_response = NULL;
435 size_t response_length = 0;
436 xmlDocPtr response_soap_doc = NULL;
437 xmlNodePtr response_root = NULL;
438 xmlXPathContextPtr xpath_ctx = NULL;
439 xmlXPathObjectPtr response_soap_headers = NULL, response_soap_body = NULL,
440 response_soap_fault = NULL;
443 if (!context) return IE_INVALID_CONTEXT;
444 if (!response) return IE_INVAL;
445 if (!raw_response_length && raw_response) return IE_INVAL;
447 xmlFreeNodeList(*response);
448 *response = NULL;
449 if (raw_response) *raw_response = NULL;
451 url = astrcat(context->url, file);
452 if (!url) return IE_NOMEM;
454 /* Build SOAP request envelope */
455 request_soap_doc = xmlNewDoc(BAD_CAST "1.0");
456 if (!request_soap_doc) {
457 isds_log_message(context, _("Could not build SOAP request document"));
458 err = IE_ERROR;
459 goto leave;
461 request_soap_envelope = xmlNewNode(NULL, BAD_CAST "Envelope");
462 if (!request_soap_envelope) {
463 isds_log_message(context, _("Could not build SOAP request envelope"));
464 err = IE_ERROR;
465 goto leave;
467 xmlDocSetRootElement(request_soap_doc, request_soap_envelope);
468 /* Only this way we get namespace definition as @xmlns:soap,
469 * otherwise we get namespace prefix without definition */
470 soap_ns = xmlNewNs(request_soap_envelope, BAD_CAST SOAP_NS, NULL);
471 if(!soap_ns) {
472 isds_log_message(context, _("Could not create SOAP name space"));
473 err = IE_ERROR;
474 goto leave;
476 xmlSetNs(request_soap_envelope, soap_ns);
477 request_soap_body = xmlNewChild(request_soap_envelope, NULL,
478 BAD_CAST "Body", NULL);
479 if (!request_soap_body) {
480 isds_log_message(context,
481 _("Could not add Body to SOAP request envelope"));
482 err = IE_ERROR;
483 goto leave;
486 /* Append request XML node set to SOAP body if request is not empty */
487 /* XXX: Copy of request must be used, otherwise xmlFreeDoc(request_soap_doc)
488 * would destroy this outer structure. */
489 if (request) {
490 xmlNodePtr request_copy = xmlCopyNodeList(request);
491 if (!request_copy) {
492 isds_log_message(context,
493 _("Could not copy request content"));
494 err = IE_ERROR;
495 goto leave;
497 if (!xmlAddChildList(request_soap_body, request_copy)) {
498 xmlFreeNodeList(request_copy);
499 isds_log_message(context,
500 _("Could not add request content to SOAP "
501 "request envelope"));
502 err = IE_ERROR;
503 goto leave;
508 /* Serialize the SOAP request into HTTP request body */
509 http_request = xmlBufferCreate();
510 if (!http_request) {
511 isds_log_message(context,
512 _("Could not create xmlBuffer for HTTP request body"));
513 err = IE_ERROR;
514 goto leave;
516 /* Last argument 1 means format the XML tree. This is pretty but it breaks
517 * digital signatures probably because ISDS abandoned XMLDSig */
518 save_ctx = xmlSaveToBuffer(http_request, "UTF-8", 1);
519 if (!save_ctx) {
520 isds_log_message(context,
521 _("Could not create XML serializer"));
522 err = IE_ERROR;
523 goto leave;
525 /* XXX: According LibXML documentation, this function does not return
526 * meaningfull value yet */
527 xmlSaveDoc(save_ctx, request_soap_doc);
528 if (-1 == xmlSaveFlush(save_ctx)) {
529 isds_log_message(context,
530 _("Could not serialize SOAP request to HTTP request bddy"));
531 err = IE_ERROR;
532 goto leave;
535 isds_log(ILF_SOAP, ILL_DEBUG,
536 _("SOAP request to sent to %s:\n%.*s\nEnd of SOAP request\n"),
537 url, http_request->use, http_request->content);
539 err = http(context, url, http_request->content, http_request->use,
540 &http_response, &response_length,
541 &mime_type, NULL, &http_code);
543 /* TODO: HTTP binding for SOAP prescribes non-200 HTTP return codes
544 * to be processes too. */
546 if (err) {
547 goto leave;
550 /* Check for HTTP return code */
551 isds_log(ILF_SOAP, ILL_DEBUG, _("Server returned %ld HTTP code\n"),
552 http_code);
553 switch (http_code) {
554 /* XXX: We must see which code is used for not permitted ISDS
555 * operation like downloading message without proper user
556 * permissions. In that cat we should keep connection opened. */
557 case 401:
558 err = IE_NOT_LOGGED_IN;
559 isds_log_message(context, _("Authentication failed"));
560 goto leave;
561 break;
562 case 404:
563 err = IE_HTTP;
564 isds_log_message(context,
565 _("Code 404: Document not found on server"));
566 goto leave;
567 break;
568 /* 500 should return standard SOAP message */
571 /* Check for Content-Type: text/xml.
572 * Do it after HTTP code check because 401 Unauthorized returns HTML web
573 * page for browsers. */
574 if (mime_type && strcmp(mime_type, "text/xml")
575 && strcmp(mime_type, "application/soap+xml")
576 && strcmp(mime_type, "application/xml")) {
577 char *mime_type_locale = utf82locale(mime_type);
578 isds_printf_message(context,
579 _("%s: bad MIME type sent by server: %s"), url,
580 mime_type_locale);
581 free(mime_type_locale);
582 err = IE_SOAP;
583 goto leave;
586 /* TODO: Convert returned body into XML default encoding */
588 /* Parse the HTTP body as XML */
589 response_soap_doc = xmlParseMemory(http_response, response_length);
590 if (!response_soap_doc) {
591 err = IE_XML;
592 goto leave;
595 xpath_ctx = xmlXPathNewContext(response_soap_doc);
596 if (!xpath_ctx) {
597 err = IE_ERROR;
598 goto leave;
601 if (register_namespaces(xpath_ctx, MESSAGE_NS_UNSIGNED)) {
602 err = IE_ERROR;
603 goto leave;
606 isds_log(ILF_SOAP, ILL_DEBUG,
607 _("SOAP response received:\n%.*s\nEnd of SOAP response\n"),
608 response_length, http_response);
611 /* Check for SOAP version */
612 response_root = xmlDocGetRootElement(response_soap_doc);
613 if (!response_root) {
614 isds_log_message(context, "SOAP response has no root element");
615 err = IE_SOAP;
616 goto leave;
618 if (xmlStrcmp(response_root->name, BAD_CAST "Envelope") ||
619 xmlStrcmp(response_root->ns->href, BAD_CAST SOAP_NS)) {
620 isds_log_message(context, "SOAP response is not SOAP 1.1 document");
621 err = IE_SOAP;
622 goto leave;
625 /* Check for SOAP Headers */
626 response_soap_headers = xmlXPathEvalExpression(
627 BAD_CAST "/soap:Envelope/soap:Header/"
628 "*[@soap:mustUnderstand/text() = true()]", xpath_ctx);
629 if (!response_soap_headers) {
630 err = IE_ERROR;
631 goto leave;
633 if (!xmlXPathNodeSetIsEmpty(response_soap_headers->nodesetval)) {
634 isds_log_message(context,
635 _("SOAP response requires unsupported feature"));
636 /* TODO: log the headers
637 * xmlChar *fragment = NULL;
638 * fragment = xmlXPathCastNodeSetToSting(response_soap_headers->nodesetval);*/
639 err = IE_NOTSUP;
640 goto leave;
643 /* Get SOAP Body */
644 response_soap_body = xmlXPathEvalExpression(
645 BAD_CAST "/soap:Envelope/soap:Body", xpath_ctx);
646 if (!response_soap_body) {
647 err = IE_ERROR;
648 goto leave;
650 if (xmlXPathNodeSetIsEmpty(response_soap_body->nodesetval)) {
651 isds_log_message(context,
652 _("SOAP response does not contain SOAP Body element"));
653 err = IE_SOAP;
654 goto leave;
656 if (response_soap_body->nodesetval->nodeNr > 1) {
657 isds_log_message(context,
658 _("SOAP response has more than one Body element"));
659 err = IE_SOAP;
660 goto leave;
663 /* Check for SOAP Fault */
664 response_soap_fault = xmlXPathEvalExpression(
665 BAD_CAST "/soap:Envelope/soap:Body/soap:Fault", xpath_ctx);
666 if (!response_soap_fault) {
667 err = IE_ERROR;
668 goto leave;
670 if (!xmlXPathNodeSetIsEmpty(response_soap_fault->nodesetval)) {
671 /* TODO: log the faultcode and faultstring */
672 isds_log_message(context, _("SOAP response signals Fault"));
673 err = IE_SOAP;
674 goto leave;
678 /* Extract XML Tree with ISDS response from SOAP envelope and return it.
679 * XXX: response_soap_body is Body, we need children which may not exist
680 * (i.e. empty Body). */
681 /* TODO: Destroy SOAP response but Body childern. This is more memory
682 * friendly than copying (potentialy) fat body */
683 if (response_soap_body->nodesetval->nodeTab[0]->children) {
684 *response = xmlDocCopyNodeList(response_soap_doc,
685 response_soap_body->nodesetval->nodeTab[0]->children);
686 if (!*response) {
687 err = IE_NOMEM;
688 goto leave;
690 } else *response = NULL;
692 /* Save raw response */
693 if (raw_response) {
694 *raw_response = http_response;
695 *raw_response_length = response_length;
696 http_response = NULL;
700 leave:
701 if (err) {
702 xmlFreeNodeList(*response);
703 *response = NULL;
706 xmlXPathFreeObject(response_soap_fault);
707 xmlXPathFreeObject(response_soap_body);
708 xmlXPathFreeObject(response_soap_headers);
709 xmlXPathFreeContext(xpath_ctx);
710 xmlFreeDoc(response_soap_doc);
711 free(mime_type);
712 free(http_response);
713 xmlSaveClose(save_ctx);
714 xmlBufferFree(http_request);
715 xmlFreeDoc(request_soap_doc); /* recursive, frees request_body, soap_ns*/
716 free(url);
718 return err;
722 /* LibXML functions:
724 * void xmlInitParser(void)
725 * Initialization function for the XML parser. This is not reentrant. Call
726 * once before processing in case of use in multithreaded programs.
728 * int xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
729 * Initialize a parser context
731 * xmlDocPtr xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur,
732 * const * char URL, const char * encoding, int options);
733 * Parse in-memory NULL-terminated document @cur.
735 * xmlDocPtr xmlParseMemory(const char * buffer, int size)
736 * Parse an XML in-memory block and build a tree.
738 * xmlParserCtxtPtr xmlCreateMemoryParserCtxt(const char * buffer, int
739 * size);
740 * Create a parser context for an XML in-memory document.
742 * xmlParserCtxtPtr xmlCreateDocParserCtxt(const xmlChar * cur)
743 * Creates a parser context for an XML in-memory document.
745 * xmlDocPtr xmlCtxtReadMemory(xmlParserCtxtPtr ctxt,
746 * const char * buffer, int size, const char * URL, const char * encoding,
747 * int options)
748 * Parse an XML in-memory document and build a tree. This reuses the existing
749 * @ctxt parser context.
751 * void xmlCleanupParser(void)
752 * Cleanup function for the XML library. It tries to reclaim all parsing
753 * related glob document related memory. Calling this function should not
754 * prevent reusing the libr finished using the library or XML document built
755 * with it.
757 * void xmlClearParserCtxt(xmlParserCtxtPtr ctxt)
758 * Clear (release owned resources) and reinitialize a parser context.
760 * void xmlCtxtReset(xmlParserCtxtPtr ctxt)
761 * Reset a parser context
763 * void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
764 * Free all the memory used by a parser context. However the parsed document
765 * in ctxt->myDoc is not freed.
767 * void xmlFreeDoc(xmlDocPtr cur)
768 * Free up all the structures used by a document, tree included.