From 76c6367d7d0d105aed35c714b45b6883ec8577f7 Mon Sep 17 00:00:00 2001 From: snowdrop Date: Sat, 25 Feb 2006 10:09:28 +0000 Subject: patches by Heiko. See mailinglist (archive 25.02.06) --- libcsoap/soap-client.c | 115 +++++++++++++++++++++++-------------------------- libcsoap/soap-env.c | 42 +++++++++--------- 2 files changed, 76 insertions(+), 81 deletions(-) (limited to 'libcsoap') diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c index f30018d..80f8b3a 100644 --- a/libcsoap/soap-client.c +++ b/libcsoap/soap-client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-client.c,v 1.23 2006/02/18 20:14:36 snowdrop Exp $ +* $Id: soap-client.c,v 1.24 2006/02/25 10:09:28 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -21,24 +21,57 @@ * * Email: ayaz@jprogrammer.net ******************************************************************/ -#include -#include +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_STRING_H #include +#endif + +#ifdef HAVE_STDIO_H +#include +#endif + +#include + +#include "soap-client.h" -/*--------------------------------- */ static int _block_socket = 0; -static herror_t _soap_client_build_result(hresponse_t * res, SoapEnv ** out); -/*--------------------------------- */ + +static herror_t +_soap_client_build_result(hresponse_t * res, SoapEnv ** env) +{ + log_verbose2("Building result (%p)", res); + + if (res == NULL) + return herror_new("_soap_client_build_result", + GENERAL_INVALID_PARAM, "hresponse_t is NULL"); + + + if (res->in == NULL) + return herror_new("_soap_client_build_result", + GENERAL_INVALID_PARAM, "Empty response from server"); + + if (res->errcode != 200) + return herror_new("_soap_client_build_result", + GENERAL_INVALID_PARAM, "HTTP code is not 200 OK"); + + return soap_env_new_from_stream(res->in, env); +} void soap_client_block_socket(int block) { _block_socket = block; + + return; } int -soap_client_get_blockmode() +soap_client_get_blockmode(void) { + return _block_socket; } @@ -47,13 +80,14 @@ soap_client_init_args(int argc, char *argv[]) { return httpc_init(argc, argv); - } void -soap_client_destroy() +soap_client_destroy(void) { httpc_destroy(); + + return; } herror_t @@ -89,8 +123,7 @@ soap_client_invoke(SoapCtx * call, SoapCtx ** response, const char *url, content = (char *) xmlBufferContent(buffer); /* Transport via HTTP */ - conn = httpc_new(); - if (!conn) + if (!(conn = httpc_new())) { return herror_new("soap_client_invoke", SOAP_ERROR_CLIENT_INIT, "Unable to create SOAP client!"); @@ -99,9 +132,9 @@ soap_client_invoke(SoapCtx * call, SoapCtx ** response, const char *url, /* Set soap action */ if (soap_action != NULL) - { httpc_set_header(conn, "SoapAction", soap_action); - } + + httpc_set_header(conn, HEADER_CONNECTION, "Close"); /* check for attachments */ if (!call->attachments) @@ -111,25 +144,22 @@ soap_client_invoke(SoapCtx * call, SoapCtx ** response, const char *url, sprintf(tmp, "%d", (int) strlen(content)); httpc_set_header(conn, HEADER_CONTENT_LENGTH, tmp); - status = httpc_post_begin(conn, url); - if (status != H_OK) + if ((status = httpc_post_begin(conn, url)) != H_OK) { httpc_close_free(conn); xmlBufferFree(buffer); return status; } - status = http_output_stream_write_string(conn->out, content); - if (status != H_OK) + if ((status = http_output_stream_write_string(conn->out, content)) != H_OK) { httpc_close_free(conn); xmlBufferFree(buffer); return status; } - status = httpc_post_end(conn, &res); - if (status != H_OK) + if ((status = httpc_post_end(conn, &res)) != H_OK) { httpc_close_free(conn); xmlBufferFree(buffer); @@ -144,24 +174,21 @@ soap_client_invoke(SoapCtx * call, SoapCtx ** response, const char *url, TRANSFER_ENCODING_CHUNKED); sprintf(start_id, "289247829121218%d", counter++); - status = httpc_mime_begin(conn, url, start_id, "", "text/xml"); - if (status != H_OK) + if ((status = httpc_mime_begin(conn, url, start_id, "", "text/xml")) != H_OK) { httpc_close_free(conn); xmlBufferFree(buffer); return status; } - status = httpc_mime_next(conn, start_id, "text/xml", "binary"); - if (status != H_OK) + if ((status = httpc_mime_next(conn, start_id, "text/xml", "binary")) != H_OK) { httpc_close_free(conn); xmlBufferFree(buffer); return status; } - status = http_output_stream_write(conn->out, content, strlen(content)); - if (status != H_OK) + if ((status = http_output_stream_write(conn->out, content, strlen(content))) != H_OK) { httpc_close_free(conn); xmlBufferFree(buffer); @@ -183,8 +210,7 @@ soap_client_invoke(SoapCtx * call, SoapCtx ** response, const char *url, } } - status = httpc_mime_end(conn, &res); - if (status != H_OK) + if ((status = httpc_mime_end(conn, &res)) != H_OK) { httpc_close_free(conn); xmlBufferFree(buffer); @@ -196,8 +222,7 @@ soap_client_invoke(SoapCtx * call, SoapCtx ** response, const char *url, xmlBufferFree(buffer); /* Build result */ - status = _soap_client_build_result(res, &res_env); - if (status != H_OK) + if ((status = _soap_client_build_result(res, &res_env)) != H_OK) { hresponse_free(res); httpc_close_free(conn); @@ -225,39 +250,9 @@ soap_client_invoke(SoapCtx * call, SoapCtx ** response, const char *url, } } - hresponse_free(res); httpc_close_free(conn); - return H_OK; -} - - -static herror_t -_soap_client_build_result(hresponse_t * res, SoapEnv ** env) -{ - herror_t err; - - log_verbose2("Building result (%p)", res); - - if (res == NULL) - return herror_new("_soap_client_build_result", - GENERAL_INVALID_PARAM, "hresponse_t is NULL"); - - - if (res->in == NULL) - return herror_new("_soap_client_build_result", - GENERAL_INVALID_PARAM, "Empty response from server"); - - if (res->errcode != 200) - return herror_new("_soap_client_build_result", - GENERAL_INVALID_PARAM, "HTTP code is not 200 OK"); - - err = soap_env_new_from_stream(res->in, env); - - if (err != H_OK) - { - return err; - } return H_OK; } + diff --git a/libcsoap/soap-env.c b/libcsoap/soap-env.c index 9da120d..cb55bd2 100644 --- a/libcsoap/soap-env.c +++ b/libcsoap/soap-env.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-env.c,v 1.15 2006/02/04 01:24:10 snowdrop Exp $ +* $Id: soap-env.c,v 1.16 2006/02/25 10:09:28 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -21,10 +21,12 @@ * * Email: ayaz@jprogrammer.net ******************************************************************/ -#include #include +#include #include +#include + #ifdef WIN32 #define USE_XMLSTRING #endif @@ -195,9 +197,9 @@ soap_env_new_with_fault(fault_code_t faultcode, herror_t soap_env_new_with_response(SoapEnv * request, SoapEnv ** out) { + char *method, *res_method; + herror_t ret; char *urn; - char *methodname; - char *methodname2; if (request == NULL) { @@ -212,12 +214,12 @@ soap_env_new_with_response(SoapEnv * request, SoapEnv ** out) "request (first param) has no xml structure"); } - if (!(methodname = soap_env_find_methodname(request))) + if (!(method = soap_env_find_methodname(request))) { return herror_new("soap_env_new_with_response", GENERAL_INVALID_PARAM, "Method name '%s' not found in request", - SAVE_STR(methodname)); + SAVE_STR(method)); } if (!(urn = soap_env_find_urn(request))) @@ -228,9 +230,14 @@ soap_env_new_with_response(SoapEnv * request, SoapEnv ** out) urn = ""; } - methodname2 = malloc(strlen(methodname)+9); - sprintf(methodname2, "%sResponse", methodname); - return soap_env_new_with_method(urn, methodname2, out); + res_method = malloc(strlen(method)+9); + sprintf(res_method, "%sResponse", method); + + ret = soap_env_new_with_method(urn, res_method, out); + + free(res_method); + + return ret; } @@ -506,16 +513,14 @@ soap_env_get_method(SoapEnv * env) xmlNodePtr body; - body = soap_env_get_body(env); - if (body == NULL) + if ((body = soap_env_get_body(env)) == NULL) { log_verbose1("body is NULL"); return NULL; } - /* mehtod is the first child */ + /* method is the first child */ return soap_xml_get_children(body); - } @@ -548,8 +553,7 @@ _soap_env_get_body(SoapEnv * env) return NULL; } - nodeset = xpathobj->nodesetval; - if (!nodeset) + if (!(nodeset = xpathobj->nodesetval)) { log_error1("No Body (nodeset)!"); xmlXPathFreeObject(xpathobj); @@ -576,17 +580,14 @@ soap_env_find_urn(SoapEnv * env) xmlNsPtr ns; xmlNodePtr body, node; - body = soap_env_get_body(env); - if (body == NULL) + if (!(body = soap_env_get_body(env))) { log_verbose1("body is NULL"); return 0; } /* node is the first child */ - node = soap_xml_get_children(body); - - if (node == NULL) + if (!(node = soap_xml_get_children(body))) { log_error1("No namespace found"); return 0; @@ -637,7 +638,6 @@ soap_env_find_methodname(SoapEnv * env) } return((char *) node->name); - } -- cgit v1.1-32-gdbae