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 ++++++------ nanohttp/nanohttp-base64.c | 156 ++++++++++++++++++++++++--------------------- 3 files changed, 160 insertions(+), 153 deletions(-) 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); - } diff --git a/nanohttp/nanohttp-base64.c b/nanohttp/nanohttp-base64.c index f81039c..8abee35 100644 --- a/nanohttp/nanohttp-base64.c +++ b/nanohttp/nanohttp-base64.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-base64.c,v 1.1 2006/02/19 22:22:41 snowdrop Exp $ +* $Id: nanohttp-base64.c,v 1.2 2006/02/25 10:09:29 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -25,6 +25,8 @@ #include #endif +#include "nanohttp-base64.h" + static const char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char cd64[] = "|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; @@ -34,12 +36,13 @@ static const char cd64[] = "|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$ */ static void encodeblock(unsigned char in[3], unsigned char out[4], int len) { - out[0] = cb64[in[0] >> 2]; - out[1] = cb64[((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4)]; - out[2] = (unsigned char)(len > 1 ? cb64[((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)] : '='); - out[3] = (unsigned char)(len > 2 ? cb64[in[2] & 0x3f] : '='); - return; + out[0] = cb64[in[0] >> 2]; + out[1] = cb64[((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4)]; + out[2] = (unsigned char)(len > 1 ? cb64[((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)] : '='); + out[3] = (unsigned char)(len > 2 ? cb64[in[2] & 0x3f] : '='); + + return; } /** @@ -47,28 +50,27 @@ static void encodeblock(unsigned char in[3], unsigned char out[4], int len) */ void base64_encode(const unsigned char *instr, unsigned char *outstr) { - unsigned char in[3], out[4]; - int i, len; - - while (*instr) { - - len = 0; - for (i = 0; i < 3; i++) { - in[i] = (unsigned char)*instr++; - if (*instr) { - len++; - } - else { - in[i] = 0; - } - } - if (len) { - encodeblock(in, out, len); - for (i = 0; i < 4; i++) { - *outstr++ = out[i]; - } - } - } + unsigned char in[3], out[4]; + int i, len; + + while (*instr) + { + len = 0; + for (i = 0; i < 3; i++) + { + if ((in[i] = (unsigned char)*instr)) + { + len++; + instr++; + } + } + if (len) + { + encodeblock(in, out, len); + for (i = 0; i < 4; i++) + *outstr++ = out[i]; + } + } } /** @@ -76,11 +78,11 @@ void base64_encode(const unsigned char *instr, unsigned char *outstr) */ static void decodeblock(unsigned char in[4], unsigned char out[3]) { - out[0] = (unsigned char)(in[0] << 2 | in[1] >> 4); - out[1] = (unsigned char)(in[1] << 4 | in[2] >> 2); - out[2] = (unsigned char)(((in[2] << 6) & 0xc0) | in[3]); + out[0] = (unsigned char)(in[0] << 2 | in[1] >> 4); + out[1] = (unsigned char)(in[1] << 4 | in[2] >> 2); + out[2] = (unsigned char)(((in[2] << 6) & 0xc0) | in[3]); - return; + return; } /** @@ -88,56 +90,66 @@ static void decodeblock(unsigned char in[4], unsigned char out[3]) */ void base64_decode(const unsigned char *instr, unsigned char *outstr) { - unsigned char in[4], out[3], v; - int i, len; - - while (*instr) { - for (len = 0, i = 0; i < 4 && *instr; i++) { - v = 0; - while (*instr && v == 0) { - v = *instr++; - v = (unsigned char)((v < 43 || v > 122) ? 0 : cd64[v - 43]); - if (v) { - v = (unsigned char)((v == '$') ? 0 : v - 61); - } - } - if (*instr) { - len++; - if (v) { - in[i] = (unsigned char)(v - 1); - } - } - else { - in[i] = 0; - } - } - if (len) { - decodeblock(in, out); - for (i = 0; i < len - 1; i++) { - *outstr++ = out[i]; - } - } - } + unsigned char in[4], out[3], v; + int i, len; + + while (*instr) + { + for (len = 0, i = 0; i < 4 && *instr; i++) + { + v = 0; + while (*instr && v == 0) + { + v = *instr++; + v = (unsigned char)((v < 43 || v > 122) ? 0 : cd64[v - 43]); + if (v) + v = (unsigned char)((v == '$') ? 0 : v - 61); + } + if (*instr) + { + len++; + if (v) + in[i] = (unsigned char)(v - 1); + } + else + { + in[i] = 0; + } + } + if (len) + { + decodeblock(in, out); + for (i = 0; i < len - 1; i++) + *outstr++ = out[i]; + } + } } #ifdef BASE64_TEST_CASE_FROM_RFC2617 +#include int main(int argc, char **argv) { + unsigned char *instr = "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="; + unsigned char *result = "Aladdin:open sesame"; + unsigned char instr2[80]; + unsigned char outstr[80]; - unsigned char *instr = "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="; - unsigned char instr2[80]; - unsigned char outstr[80]; - - bzero(outstr, 80); + bzero(outstr, 80); + base64_decode(instr, outstr); - base64_decode(instr, outstr); + printf("\"%s\" => \"%s\"\n", instr, outstr); + if (strcmp(outstr, result)) + printf("base64_decode failed\n"); - printf("\"%s\" => \"%s\"\n", instr, outstr); + strcpy(instr2, outstr); - strcpy(instr2, outstr); + bzero(outstr, 80); + base64_encode(instr2, outstr); - base64_encode(instr2, outstr); + printf("\"%s\" => \"%s\"\n", instr2, outstr); + if (strcmp(outstr, instr)) + printf("base64_encode failed\n"); - return printf("\"%s\" => \"%s\"\n", instr2, outstr); + return 0; } #endif -- cgit v1.1-32-gdbae