Allow compilation against older curl
[libisds.git] / src / soap.c
blobde252a170158b3b01e2974f9e0cd9e68e5b36cfa
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 err = IE_NETWORK;
279 goto leave;
282 isds_log(ILF_HTTP, ILL_DEBUG, _("Sending POST request to %s\n"), url);
283 isds_log(ILF_HTTP, ILL_DEBUG,
284 _("POST body length: %zu, content follows:\n"), request_length);
285 isds_log(ILF_HTTP, ILL_DEBUG, "%.*s\n", request_length, request);
286 isds_log(ILF_HTTP, ILL_DEBUG, _("End of POST body\n"));
287 if ((log_facilities & ILF_HTTP) && (log_level >= ILL_DEBUG) ) {
288 curl_easy_setopt(context->curl, CURLOPT_VERBOSE, 1);
292 /* Do the request */
293 curl_err = curl_easy_perform(context->curl);
295 /* Wipe credentials out of the handler */
296 #if HAVE_DECL_CURLOPT_USERNAME /* Since curl-7.19.1 */
297 if (context->username) {
298 curl_easy_setopt(context->curl, CURLOPT_USERNAME, NULL);
300 if (context->password) {
301 curl_easy_setopt(context->curl, CURLOPT_PASSWORD, NULL);
303 #else
304 if (context->username || context->password) {
305 curl_easy_setopt(context->curl, CURLOPT_USERPWD, NULL);
307 #endif /* not HAVE_DECL_CURLOPT_USERNAME */
309 if (!curl_err)
310 curl_err = curl_easy_getinfo(context->curl, CURLINFO_CONTENT_TYPE,
311 &content_type);
313 if (curl_err) {
314 /* TODO: CURL is not internationalized yet. Collect CURL messages for
315 * I18N. */
316 isds_printf_message(context,
317 _("%s: %s"), url, _(curl_easy_strerror(curl_err)));
318 err = IE_NETWORK;
319 goto leave;
322 isds_log(ILF_HTTP, ILL_DEBUG, _("Final response to %s received\n"), url);
323 isds_log(ILF_HTTP, ILL_DEBUG,
324 _("Response body length: %zu, content follows:\n"),
325 body.length);
326 isds_log(ILF_HTTP, ILL_DEBUG, "%.*s\n", body.length, body.data);
327 isds_log(ILF_HTTP, ILL_DEBUG, _("End of response body\n"));
330 /* Extract MIME type and charset */
331 if (content_type) {
332 char *sep;
333 size_t offset;
335 sep = strchr(content_type, ';');
336 if (sep) offset = (size_t) (sep - content_type);
337 else offset = strlen(content_type);
339 if (mime_type) {
340 *mime_type = malloc(offset + 1);
341 if (!*mime_type) {
342 err = IE_NOMEM;
343 goto leave;
345 memcpy(*mime_type, content_type, offset);
346 (*mime_type)[offset] = '\0';
349 if (charset) {
350 if (!sep) {
351 *charset = NULL;
352 } else {
353 sep = strstr(sep, "charset=");
354 if (!sep) {
355 *charset = NULL;
356 } else {
357 *charset = strdup(sep + 8);
358 if (!*charset) {
359 err = IE_NOMEM;
360 goto leave;
367 /* Get HTTP response code */
368 if (http_code) {
369 curl_err = curl_easy_getinfo(context->curl,
370 CURLINFO_RESPONSE_CODE, http_code);
371 if (curl_err) {
372 err = IE_ERROR;
373 goto leave;
377 leave:
378 curl_slist_free_all(headers);
380 if (err) {
381 free(body.data);
382 body.data = NULL;
383 body.length = 0;
385 if (mime_type) {
386 free(*mime_type);
387 *mime_type = NULL;
389 if (charset) {
390 free(*charset);
391 *charset = NULL;
394 close_connection(context);
397 *response = body.data;
398 *response_length = body.length;
400 return err;
404 /* Do SOAP request.
405 * @context holds the base URL,
406 * @file is a (CGI) file of SOAP URL,
407 * @request is XML node set with SOAP request body.
408 * @file must be NULL, @request should be NULL rather than empty, if they should
409 * not be signaled in the SOAP request.
410 * @reponse is automatically allocated() node set with SOAP response body.
411 * You must xmlFreeNodeList() it. This is literal body, empty (NULL), one node
412 * or more nodes can be returned.
413 * @raw_response is automatically allocated bitstream with response body. Use
414 * NULL if you don't care
415 * @raw_response_length is size of @raw_response in bytes
416 * In case of error the response will be deallocated automatically.
417 * Side effect: message buffer */
418 _hidden isds_error soap(struct isds_ctx *context, const char *file,
419 const xmlNodePtr request, xmlNodePtr *response,
420 void **raw_response, size_t *raw_response_length) {
422 isds_error err = IE_SUCCESS;
423 char *url = NULL;
424 char *mime_type = NULL;
425 long http_code = 0;
426 xmlBufferPtr http_request = NULL;
427 xmlSaveCtxtPtr save_ctx = NULL;
428 xmlDocPtr request_soap_doc = NULL;
429 xmlNodePtr request_soap_envelope = NULL, request_soap_body = NULL;
430 xmlNsPtr soap_ns = NULL;
431 void *http_response = NULL;
432 size_t response_length = 0;
433 xmlDocPtr response_soap_doc = NULL;
434 xmlNodePtr response_root = NULL;
435 xmlXPathContextPtr xpath_ctx = NULL;
436 xmlXPathObjectPtr response_soap_headers = NULL, response_soap_body = NULL,
437 response_soap_fault = NULL;
440 if (!context) return IE_INVALID_CONTEXT;
441 if (!response) return IE_INVAL;
442 if (!raw_response_length && raw_response) return IE_INVAL;
444 xmlFreeNodeList(*response);
445 *response = NULL;
446 if (raw_response) *raw_response = NULL;
448 url = astrcat(context->url, file);
449 if (!url) return IE_NOMEM;
451 /* Build SOAP request envelope */
452 request_soap_doc = xmlNewDoc(BAD_CAST "1.0");
453 if (!request_soap_doc) {
454 isds_log_message(context, _("Could not build SOAP request document"));
455 err = IE_ERROR;
456 goto leave;
458 request_soap_envelope = xmlNewNode(NULL, BAD_CAST "Envelope");
459 if (!request_soap_envelope) {
460 isds_log_message(context, _("Could not build SOAP request envelope"));
461 err = IE_ERROR;
462 goto leave;
464 xmlDocSetRootElement(request_soap_doc, request_soap_envelope);
465 /* Only this way we get namespace definition as @xmlns:soap,
466 * otherwise we get namespace prefix without definition */
467 soap_ns = xmlNewNs(request_soap_envelope, BAD_CAST SOAP_NS, NULL);
468 if(!soap_ns) {
469 isds_log_message(context, _("Could not create SOAP name space"));
470 err = IE_ERROR;
471 goto leave;
473 xmlSetNs(request_soap_envelope, soap_ns);
474 request_soap_body = xmlNewChild(request_soap_envelope, NULL,
475 BAD_CAST "Body", NULL);
476 if (!request_soap_body) {
477 isds_log_message(context,
478 _("Could not add Body to SOAP request envelope"));
479 err = IE_ERROR;
480 goto leave;
483 /* Append request XML node set to SOAP body if request is not empty */
484 /* XXX: Copy of request must be used, otherwise xmlFreeDoc(request_soap_doc)
485 * would destroy this outer structure. */
486 if (request) {
487 xmlNodePtr request_copy = xmlCopyNodeList(request);
488 if (!request_copy) {
489 isds_log_message(context,
490 _("Could not copy request content"));
491 err = IE_ERROR;
492 goto leave;
494 if (!xmlAddChildList(request_soap_body, request_copy)) {
495 xmlFreeNodeList(request_copy);
496 isds_log_message(context,
497 _("Could not add request content to SOAP "
498 "request envelope"));
499 err = IE_ERROR;
500 goto leave;
505 /* Serialize the SOAP request into HTTP request body */
506 http_request = xmlBufferCreate();
507 if (!http_request) {
508 isds_log_message(context,
509 _("Could not create xmlBuffer for HTTP request body"));
510 err = IE_ERROR;
511 goto leave;
513 /* Last argument 1 means format the XML tree. This is pretty but it breaks
514 * digital signatures probably because ISDS abandoned XMLDSig */
515 save_ctx = xmlSaveToBuffer(http_request, "UTF-8", 1);
516 if (!save_ctx) {
517 isds_log_message(context,
518 _("Could not create XML serializer"));
519 err = IE_ERROR;
520 goto leave;
522 /* XXX: According LibXML documentation, this function does not return
523 * meaningfull value yet */
524 xmlSaveDoc(save_ctx, request_soap_doc);
525 if (-1 == xmlSaveFlush(save_ctx)) {
526 isds_log_message(context,
527 _("Could not serialize SOAP request to HTTP request bddy"));
528 err = IE_ERROR;
529 goto leave;
532 isds_log(ILF_SOAP, ILL_DEBUG,
533 _("SOAP request to sent to %s:\n%.*s\nEnd of SOAP request\n"),
534 url, http_request->use, http_request->content);
536 err = http(context, url, http_request->content, http_request->use,
537 &http_response, &response_length,
538 &mime_type, NULL, &http_code);
540 /* TODO: HTTP binding for SOAP prescribes non-200 HTTP return codes
541 * to be processes too. */
543 if (err) {
544 goto leave;
547 /* Check for HTTP return code */
548 isds_log(ILF_SOAP, ILL_DEBUG, _("Server returned %ld HTTP code\n"),
549 http_code);
550 switch (http_code) {
551 /* XXX: We must see which code is used for not permitted ISDS
552 * operation like downloading message without proper user
553 * permissions. In that cat we should keep connection opened. */
554 case 401:
555 err = IE_NOT_LOGGED_IN;
556 isds_log_message(context, _("Authentication failed"));
557 goto leave;
558 break;
559 case 404:
560 err = IE_HTTP;
561 isds_log_message(context,
562 _("Code 404: Document not found on server"));
563 goto leave;
564 break;
565 /* 500 should return standard SOAP message */
568 /* Check for Content-Type: text/xml.
569 * Do it after HTTP code check because 401 Unauthorized returns HTML web
570 * page for browsers. */
571 if (mime_type && strcmp(mime_type, "text/xml")
572 && strcmp(mime_type, "application/soap+xml")
573 && strcmp(mime_type, "application/xml")) {
574 char *mime_type_locale = utf82locale(mime_type);
575 isds_printf_message(context,
576 _("%s: bad MIME type sent by server: %s"), url,
577 mime_type_locale);
578 free(mime_type_locale);
579 err = IE_SOAP;
580 goto leave;
583 /* TODO: Convert returned body into XML default encoding */
585 /* Parse the HTTP body as XML */
586 response_soap_doc = xmlParseMemory(http_response, response_length);
587 if (!response_soap_doc) {
588 err = IE_XML;
589 goto leave;
592 xpath_ctx = xmlXPathNewContext(response_soap_doc);
593 if (!xpath_ctx) {
594 err = IE_ERROR;
595 goto leave;
598 if (register_namespaces(xpath_ctx, MESSAGE_NS_UNSIGNED)) {
599 err = IE_ERROR;
600 goto leave;
603 isds_log(ILF_SOAP, ILL_DEBUG,
604 _("SOAP response received:\n%.*s\nEnd of SOAP response\n"),
605 response_length, http_response);
608 /* Check for SOAP version */
609 response_root = xmlDocGetRootElement(response_soap_doc);
610 if (!response_root) {
611 isds_log_message(context, "SOAP response has no root element");
612 err = IE_SOAP;
613 goto leave;
615 if (xmlStrcmp(response_root->name, BAD_CAST "Envelope") ||
616 xmlStrcmp(response_root->ns->href, BAD_CAST SOAP_NS)) {
617 isds_log_message(context, "SOAP response is not SOAP 1.1 document");
618 err = IE_SOAP;
619 goto leave;
622 /* Check for SOAP Headers */
623 response_soap_headers = xmlXPathEvalExpression(
624 BAD_CAST "/soap:Envelope/soap:Header/"
625 "*[@soap:mustUnderstand/text() = true()]", xpath_ctx);
626 if (!response_soap_headers) {
627 err = IE_ERROR;
628 goto leave;
630 if (!xmlXPathNodeSetIsEmpty(response_soap_headers->nodesetval)) {
631 isds_log_message(context,
632 _("SOAP response requires unsupported feature"));
633 /* TODO: log the headers
634 * xmlChar *fragment = NULL;
635 * fragment = xmlXPathCastNodeSetToSting(response_soap_headers->nodesetval);*/
636 err = IE_NOTSUP;
637 goto leave;
640 /* Get SOAP Body */
641 response_soap_body = xmlXPathEvalExpression(
642 BAD_CAST "/soap:Envelope/soap:Body", xpath_ctx);
643 if (!response_soap_body) {
644 err = IE_ERROR;
645 goto leave;
647 if (xmlXPathNodeSetIsEmpty(response_soap_body->nodesetval)) {
648 isds_log_message(context,
649 _("SOAP response does not contain SOAP Body element"));
650 err = IE_SOAP;
651 goto leave;
653 if (response_soap_body->nodesetval->nodeNr > 1) {
654 isds_log_message(context,
655 _("SOAP response has more than one Body element"));
656 err = IE_SOAP;
657 goto leave;
660 /* Check for SOAP Fault */
661 response_soap_fault = xmlXPathEvalExpression(
662 BAD_CAST "/soap:Envelope/soap:Body/soap:Fault", xpath_ctx);
663 if (!response_soap_fault) {
664 err = IE_ERROR;
665 goto leave;
667 if (!xmlXPathNodeSetIsEmpty(response_soap_fault->nodesetval)) {
668 /* TODO: log the faultcode and faultstring */
669 isds_log_message(context, _("SOAP response signals Fault"));
670 err = IE_SOAP;
671 goto leave;
675 /* Extract XML Tree with ISDS response from SOAP envelope and return it.
676 * XXX: response_soap_body is Body, we need children which may not exist
677 * (i.e. empty Body). */
678 /* TODO: Destroy SOAP response but Body childern. This is more memory
679 * friendly than copying (potentialy) fat body */
680 if (response_soap_body->nodesetval->nodeTab[0]->children) {
681 *response = xmlDocCopyNodeList(response_soap_doc,
682 response_soap_body->nodesetval->nodeTab[0]->children);
683 if (!*response) {
684 err = IE_NOMEM;
685 goto leave;
687 } else *response = NULL;
689 /* Save raw response */
690 if (raw_response) {
691 *raw_response = http_response;
692 *raw_response_length = response_length;
693 http_response = NULL;
697 leave:
698 if (err) {
699 xmlFreeNodeList(*response);
700 *response = NULL;
703 xmlXPathFreeObject(response_soap_fault);
704 xmlXPathFreeObject(response_soap_body);
705 xmlXPathFreeObject(response_soap_headers);
706 xmlXPathFreeContext(xpath_ctx);
707 xmlFreeDoc(response_soap_doc);
708 free(mime_type);
709 free(http_response);
710 xmlSaveClose(save_ctx);
711 xmlBufferFree(http_request);
712 xmlFreeDoc(request_soap_doc); /* recursive, frees request_body, soap_ns*/
713 free(url);
715 return err;
719 /* LibXML functions:
721 * void xmlInitParser(void)
722 * Initialization function for the XML parser. This is not reentrant. Call
723 * once before processing in case of use in multithreaded programs.
725 * int xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
726 * Initialize a parser context
728 * xmlDocPtr xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur,
729 * const * char URL, const char * encoding, int options);
730 * Parse in-memory NULL-terminated document @cur.
732 * xmlDocPtr xmlParseMemory(const char * buffer, int size)
733 * Parse an XML in-memory block and build a tree.
735 * xmlParserCtxtPtr xmlCreateMemoryParserCtxt(const char * buffer, int
736 * size);
737 * Create a parser context for an XML in-memory document.
739 * xmlParserCtxtPtr xmlCreateDocParserCtxt(const xmlChar * cur)
740 * Creates a parser context for an XML in-memory document.
742 * xmlDocPtr xmlCtxtReadMemory(xmlParserCtxtPtr ctxt,
743 * const char * buffer, int size, const char * URL, const char * encoding,
744 * int options)
745 * Parse an XML in-memory document and build a tree. This reuses the existing
746 * @ctxt parser context.
748 * void xmlCleanupParser(void)
749 * Cleanup function for the XML library. It tries to reclaim all parsing
750 * related glob document related memory. Calling this function should not
751 * prevent reusing the libr finished using the library or XML document built
752 * with it.
754 * void xmlClearParserCtxt(xmlParserCtxtPtr ctxt)
755 * Clear (release owned resources) and reinitialize a parser context.
757 * void xmlCtxtReset(xmlParserCtxtPtr ctxt)
758 * Reset a parser context
760 * void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
761 * Free all the memory used by a parser context. However the parsed document
762 * in ctxt->myDoc is not freed.
764 * void xmlFreeDoc(xmlDocPtr cur)
765 * Free up all the structures used by a document, tree included.