diff options
author | m0gg | 2006-11-30 14:23:58 +0000 |
---|---|---|
committer | m0gg | 2006-11-30 14:23:58 +0000 |
commit | df58dad240fe368c261263e248d3520d3e0be1a3 (patch) | |
tree | 3fe4e4f6c318aee4bce1b72e0827a8f3300f3b7b | |
parent | cbd1f84a6125931a2f64279aa5da5121a66e3cf1 (diff) | |
download | csoap-df58dad240fe368c261263e248d3520d3e0be1a3.tar.gz csoap-df58dad240fe368c261263e248d3520d3e0be1a3.tar.bz2 |
Code cleanup
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | TODO | 20 | ||||
-rwxr-xr-x | configure | 5 | ||||
-rw-r--r-- | configure.ac | 5 | ||||
-rwxr-xr-x | examples/csoap/echoattachments-client.c | 9 | ||||
-rw-r--r-- | examples/csoap/simpleclient.c | 8 | ||||
-rw-r--r-- | examples/csoap/soapclient.c | 8 | ||||
-rw-r--r-- | examples/nanohttp/client_get.c | 112 | ||||
-rw-r--r-- | examples/nanohttp/http_client.c | 214 | ||||
-rw-r--r-- | examples/nanohttp/http_server.c | 239 | ||||
-rw-r--r-- | libcsoap/Makefile.am | 20 | ||||
-rw-r--r-- | libcsoap/soap-client.h | 10 | ||||
-rw-r--r-- | libcsoap/soap-server.h | 17 | ||||
-rw-r--r-- | nanohttp/Makefile.am | 10 | ||||
-rw-r--r-- | nanohttp/nanohttp-client.c | 8 | ||||
-rw-r--r-- | nanohttp/nanohttp-client.h | 12 | ||||
-rw-r--r-- | nanohttp/nanohttp-server.c | 72 | ||||
-rw-r--r-- | nanohttp/nanohttp-server.h | 14 | ||||
-rw-r--r-- | nanohttp/nanohttp-socket.c | 178 | ||||
-rw-r--r-- | nanohttp/nanohttp-socket.h | 9 | ||||
-rw-r--r-- | nanohttp/nanohttp-ssl.c | 132 | ||||
-rw-r--r-- | nanohttp/nanohttp-ssl.h | 8 | ||||
-rwxr-xr-x | nanohttp/nanohttp-stream.c | 10 |
23 files changed, 518 insertions, 605 deletions
diff --git a/Makefile.am b/Makefile.am index cf6fd8c..b14a16b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,8 +16,7 @@ documentation=doc/Doxyfile.api \ doc/tutorial.xml \ doc/images/logo02.gif -broken_examples=examples/nanohttp/client_get.c \ - examples/nanohttp/client_mime.c \ +broken_examples=examples/nanohttp/client_mime.c \ examples/nanohttp/httpcpost.c \ examples/nanohttp/httppost.c \ examples/nanohttp/postserver.c \ @@ -1,4 +1,4 @@ -$Id: TODO,v 1.8 2006/11/29 13:24:00 m0gg Exp $ +$Id: TODO,v 1.9 2006/11/30 14:23:58 m0gg Exp $ =============================================================================== Things to do _before_ 1.2 release: @@ -6,30 +6,23 @@ Things to do _before_ 1.2 release: nanohttp: --------- -- Get rid of #ifdef HAVE_SSL in nanohttp-socket.c -- Improve API documentation -- remove internal typedefs! -- include neccessary headers in nanohttp-client.h and nanohttp-server.h if - __NANOHTTP_INTERNAL isn't specified -- Check portability to Win32/Linux/MaxOS (only tested on FreeBSD 6.2) -- cleanup circular module dependencies (e.g. hsocket <-> hssl) - improve error handling!!!! - optimize mime API -- cleanup/improve nanohttp request parsing (add GET http://fdqn/service) +- cleanup/improve nanohttp request parsing (add GET http://fdqn/service HTTP/1.1) - Check portability to Win32/Linux/MaxOS (only tested on FreeBSD 6.2) - Elaborate README.ssl (more text and references to csoap API docs, OpenSSL) +- delete or fix broken examples (see Makefile.am) +- Improve API documentation csoap: ------ - move service description documents from router to service (???) +- add examples from http://www.xmethods.org (Google, UDDI) - Check portability to Win32/Linux/MaxOS (only tested on FreeBSD 6.2) - soap-nudp.c needs testing - Improve API documentation - Add reference to http://www.w3.org/TR/SOAP-attachments -- include neccessary headers in soap-client.h and soap-server.h if - __CSOAP_INTERNAL isn't specified -- correct handling of configure flag --with-xmlsec1 -- Write README.xmlsec +- Write README.xmlsec like README.ssl Additional things that could be done: ===================================== @@ -38,6 +31,7 @@ nanohttp: --------- - add DIME attachments - add BASE64 decoding for MIME attachments +- cleanup circular module dependencies (e.g. hsocket <-> hssl) csoap: ------ @@ -21864,9 +21864,6 @@ fi fi; -#--------------------------------------------- -# Check xmlsec1 library -#--------------------------------------------- @@ -22076,7 +22073,7 @@ else fi CFLAGS="$CFLAGS $XMLSEC1_CFLAGS"; - LDFLAGS="$LDFLAGS $XMLSEC1_LIBS" + LDFLAGS="$LDFLAGS $XMLSEC1_LIBS" else echo "$as_me:$LINENO: result: no" >&5 diff --git a/configure.ac b/configure.ac index d52370c..6f30870 100644 --- a/configure.ac +++ b/configure.ac @@ -385,14 +385,11 @@ AM_PATH_SSL(, AM_CONDITIONAL(BUILD_WITH_SSL, false) ) -#--------------------------------------------- -# Check xmlsec1 library -#--------------------------------------------- AM_PATH_XMLSEC1(1.2.10, AC_DEFINE(HAVE_XMLSEC1,1,Define to 1 if you have requested --with-xmlsec1) AM_CONDITIONAL(BUILD_WITH_XMLSEC1, true) CFLAGS="$CFLAGS $XMLSEC1_CFLAGS"; - LDFLAGS="$LDFLAGS $XMLSEC1_LIBS" + LDFLAGS="$LDFLAGS $XMLSEC1_LIBS" , AM_CONDITIONAL(BUILD_WITH_XMLSEC1, false) ) diff --git a/examples/csoap/echoattachments-client.c b/examples/csoap/echoattachments-client.c index 5c22805..fbee05e 100755 --- a/examples/csoap/echoattachments-client.c +++ b/examples/csoap/echoattachments-client.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: echoattachments-client.c,v 1.15 2006/11/25 15:06:57 m0gg Exp $ + * $Id: echoattachments-client.c,v 1.16 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003-2004 Ferhat Ayaz @@ -24,13 +24,8 @@ #include <stdlib.h> #include <libxml/tree.h> +#include <libxml/uri.h> -#include <nanohttp/nanohttp-error.h> -#include <nanohttp/nanohttp-common.h> -#include <nanohttp/nanohttp-logging.h> - -#include <libcsoap/soap-env.h> -#include <libcsoap/soap-ctx.h> #include <libcsoap/soap-client.h> static const char *urn = "urn:examples"; diff --git a/examples/csoap/simpleclient.c b/examples/csoap/simpleclient.c index 757b2cf..eacc886 100644 --- a/examples/csoap/simpleclient.c +++ b/examples/csoap/simpleclient.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: simpleclient.c,v 1.20 2006/11/29 11:04:24 m0gg Exp $ + * $Id: simpleclient.c,v 1.21 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003-2004 Ferhat Ayaz @@ -26,12 +26,6 @@ #include <libxml/tree.h> #include <libxml/uri.h> -#include <nanohttp/nanohttp-error.h> -#include <nanohttp/nanohttp-logging.h> - -#include <libcsoap/soap-ctx.h> -#include <libcsoap/soap-env.h> -#include <libcsoap/soap-addressing.h> #include <libcsoap/soap-client.h> static char *url = "http://localhost:10000/csoapserver"; diff --git a/examples/csoap/soapclient.c b/examples/csoap/soapclient.c index 5b98e91..00ddbbf 100644 --- a/examples/csoap/soapclient.c +++ b/examples/csoap/soapclient.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soapclient.c,v 1.12 2006/11/26 20:13:05 m0gg Exp $ + * $Id: soapclient.c,v 1.13 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003-2006 Adrianus Warmehoven @@ -25,12 +25,8 @@ #include <ctype.h> #include <libxml/tree.h> +#include <libxml/uri.h> -#include <nanohttp/nanohttp-error.h> - -#include <libcsoap/soap-fault.h> -#include <libcsoap/soap-env.h> -#include <libcsoap/soap-ctx.h> #include <libcsoap/soap-client.h> #define MAX_LINE_LENGTH 65535 diff --git a/examples/nanohttp/client_get.c b/examples/nanohttp/client_get.c deleted file mode 100644 index 4015ed2..0000000 --- a/examples/nanohttp/client_get.c +++ /dev/null @@ -1,112 +0,0 @@ -/****************************************************************** -* $Id: client_get.c,v 1.1 2004/10/15 13:42:07 snowdrop Exp $ -* -* CSOAP Project: A http client/server library in C (example) -* Copyright (C) 2003-2004 Ferhat Ayaz -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Library General Public -* License as published by the Free Software Foundation; either -* version 2 of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Library General Public License for more details. -* -* You should have received a copy of the GNU Library General Public -* License along with this library; if not, write to the -* Free Software Foundation, Inc., 59 Temple Place - Suite 330, -* Boston, MA 02111-1307, USA. -* -* Email: ferhatayaz@yahoo.com -******************************************************************/ -#define MEM_DEBUG -#include <stdio.h> -#include <nanohttp/nanohttp-client.h> - -#ifdef MEM_DEBUG -#include <utils/alloc.h> -#endif - -#define MAX_BUFFER_SIZE 1024 - -static -void show_response(hresponse_t *res) -{ - hpair_t *pair; - byte_t buffer[MAX_BUFFER_SIZE+1]; - int read; - - if (res == NULL) - { - log_error1("Response is NULL!"); - return; - } - - log_info2("Status: %d", res->errcode); - log_info2("Desc : '%s'", res->desc); - - pair = res->header; - while (pair != NULL) { - log_debug3("%s: %s", pair->key, pair->value); - pair = pair->next; - } - - if (res->in == NULL) - { - log_warn1("No input stream!"); - return; - } - - - while (http_input_stream_is_ready(res->in)) - { - read = http_input_stream_read(res->in, buffer, MAX_BUFFER_SIZE); - buffer[read] = '\0'; - puts(buffer); - } - -} - -int main(int argc, char *argv[]) -{ - httpc_conn_t *conn; /* Client connection object */ - hresponse_t *res; /* Response object **/ - - /* check usage */ - if (argc < 2) { - fprintf(stderr, "usage %s <url>\n", argv[0]); - exit(1); - } - - /* Set log level to see more information written by the library */ - log_set_level(HLOG_VERBOSE); - - /* Initialize httpc module */ - if (httpc_init(argc, argv)) - { - log_error1("Can not init httpc"); - return 1; - } - - /* Create the client connection object */ - conn = httpc_new(); - - /* Send GET method and receive response */ - res = httpc_get(conn, argv[1]); - - /* Show response */ - show_response(res); - - /* Clean up */ - hresponse_free(res); - httpc_free(conn); - -#ifdef MEM_DEBUG - _mem_report(); -#endif - - return 0; -} - diff --git a/examples/nanohttp/http_client.c b/examples/nanohttp/http_client.c index e320cb9..7c1b2f0 100644 --- a/examples/nanohttp/http_client.c +++ b/examples/nanohttp/http_client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: http_client.c,v 1.6 2006/11/25 15:06:57 m0gg Exp $ +* $Id: http_client.c,v 1.7 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: A http client/server library in C (example) * Copyright (C) 2003-2004 Ferhat Ayaz @@ -25,13 +25,7 @@ #include <stdlib.h> #include <string.h> -#include <nanohttp/nanohttp-error.h> -#include <nanohttp/nanohttp-common.h> -#include <nanohttp/nanohttp-stream.h> -#include <nanohttp/nanohttp-request.h> -#include <nanohttp/nanohttp-response.h> #include <nanohttp/nanohttp-client.h> -#include <nanohttp/nanohttp-logging.h> #define MAX_BUFFER_SIZE 1024 @@ -42,109 +36,109 @@ static int show_content = 1; static char *username = NULL; static char *password = NULL; -static void show_response(hresponse_t *res) { - - unsigned char buffer[MAX_BUFFER_SIZE+1]; - int read; - - if (!res) { - - printf("hresponse_t is NULL!"); - return; - } - - if (res->errcode != 200 || show_http_status_code) - printf("HTTP Status: %d \"%s\"\n", res->errcode, res->desc); - - if (show_headers) { - - hpair_t *pair; - printf("HTTP Headers:\n"); - for (pair = res->header; pair; pair=pair->next) - printf(" %s: %s\n", pair->key, pair->value); - } - - if (!res->in) { - - log_warn1("No input stream!"); - return; - } - - while (http_input_stream_is_ready(res->in)) { - - read = http_input_stream_read(res->in, buffer, MAX_BUFFER_SIZE); - - if (show_content) - fwrite(buffer, read, 1, stdout); - } - return; +static void show_response(hresponse_t *res) +{ + unsigned char buffer[MAX_BUFFER_SIZE+1]; + int read; + + if (!res) + { + fprintf(stderr, "hresponse_t is NULL!"); + return; + } + + if (res->errcode != 200 || show_http_status_code) + printf("HTTP Status: %d \"%s\"\n", res->errcode, res->desc); + + if (show_headers) + { + hpair_t *pair; + printf("HTTP Headers:\n"); + for (pair = res->header; pair; pair=pair->next) + printf(" %s: %s\n", pair->key, pair->value); + } + + if (!res->in) + { + fprintf(stderr, "No input stream!"); + return; + } + + while (http_input_stream_is_ready(res->in)) + { + read = http_input_stream_read(res->in, buffer, MAX_BUFFER_SIZE); + + if (show_content) + fwrite(buffer, read, 1, stdout); + } + return; } -int main(int argc, char **argv) { - - httpc_conn_t *conn; /* Client connection object */ - hresponse_t *res; /* Response object **/ - herror_t status; - int i; - - /* check usage */ - if (argc < 2) { - - fprintf(stderr, "usage: %s [-headers] [-status] [-noout] [-username name] [-password secret] <url>\n", argv[0]); - exit(1); - } - - /* XXX: this is not safe... */ - for (i=0; i<argc; i++) { - - if (!strcmp("-headers", argv[i])) - show_headers = 1; - else if (!strcmp("-status", argv[i])) - show_http_status_code = 1; - else if (!strcmp("-noout", argv[i])) - show_content = 0; - else if (!strcmp("-username", argv[i])) - username = argv[i+1]; - else if (!strcmp("-password", argv[i])) - password = argv[i+1]; - } - - /* Set log level to see more information written by the library */ - hlog_set_level(HLOG_INFO); - - /* Initialize httpc module */ - if (httpc_init(argc, argv)) { - - log_error1("Cannot init httpc"); - exit(1); - } - - /* Create the client connection object */ - if (!(conn = httpc_new())) { - - log_error1("httpc_new failed"); - exit(1); - } - - /* set the credentials, if specified */ - if (username || password) - httpc_set_basic_authorization(conn, username, password); - - /* Send GET method and receive response */ - if ((status = httpc_get(conn, &res, argv[argc-1])) != H_OK) { - - log_error2("httpc_get failed (%s)", herror_message(status)); - herror_release(status); - exit(1); - } - - /* Show response */ - show_response(res); - - /* Clean up */ - hresponse_free(res); - - httpc_free(conn); - - return 0; +int main(int argc, char **argv) +{ + httpc_conn_t *conn; /* Client connection object */ + hresponse_t *res; /* Response object **/ + herror_t status; + int i; + + /* check usage */ + if (argc < 2) + { + fprintf(stderr, "usage: %s [-headers] [-status] [-noout] [-username name] [-password secret] <url>\n", argv[0]); + exit(1); + } + + /* XXX: this is not safe... */ + for (i=0; i<argc; i++) + { + if (!strcmp("-headers", argv[i])) + show_headers = 1; + else if (!strcmp("-status", argv[i])) + show_http_status_code = 1; + else if (!strcmp("-noout", argv[i])) + show_content = 0; + else if (!strcmp("-username", argv[i])) + username = argv[i+1]; + else if (!strcmp("-password", argv[i])) + password = argv[i+1]; + } + + /* Set log level to see more information written by the library */ + hlog_set_level(HLOG_INFO); + + /* Initialize httpc module */ + if (httpc_init(argc, argv)) + { + fprintf(stderr, "Cannot inititialize httpc"); + exit(1); + } + + /* Create the client connection object */ + if (!(conn = httpc_new())) + { + fprintf(stderr, "httpc_new failed"); + exit(1); + } + + /* set the credentials, if specified */ + if (username || password) + httpc_set_basic_authorization(conn, username, password); + + /* Send GET method and receive response */ + if ((status = httpc_get(conn, &res, argv[argc-1])) != H_OK) + { + fprintf(stderr, "httpc_get failed (%s)", herror_message(status)); + herror_release(status); + exit(1); + } + + /* Show response */ + show_response(res); + + /* Clean up */ + hresponse_free(res); + + httpc_free(conn); + + return 0; } diff --git a/examples/nanohttp/http_server.c b/examples/nanohttp/http_server.c index 0e1659a..40443e8 100644 --- a/examples/nanohttp/http_server.c +++ b/examples/nanohttp/http_server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: http_server.c,v 1.9 2006/11/25 16:35:57 m0gg Exp $ +* $Id: http_server.c,v 1.10 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: A http client/server library in C (example) * Copyright (C) 2003 Ferhat Ayaz @@ -24,169 +24,160 @@ #include <stdio.h> #include <string.h> -#include <nanohttp/nanohttp-error.h> -#include <nanohttp/nanohttp-common.h> -#include <nanohttp/nanohttp-stream.h> -#include <nanohttp/nanohttp-request.h> -#include <nanohttp/nanohttp-response.h> #include <nanohttp/nanohttp-server.h> -#include <nanohttp/nanohttp-logging.h> static int simple_authenticator(struct hrequest_t *req, const char *user, const char *password) { + fprintf(stdout, "logging in user=\"%s\" password=\"%s\"", user, password); - log_info3("logging in user=\"%s\" password=\"%s\"", user, password); + if (strcmp(user, "bob")) { - if (strcmp(user, "bob")) { + fprintf(stderr, "user \"%s\" unkown", user); + return 0; + } - log_warn2("user \"%s\" unkown", user); - return 0; - } + if (strcmp(password, "builder")) { - if (strcmp(password, "builder")) { + fprintf(stderr, "wrong password"); + return 0; + } - log_warn1("wrong password"); - return 0; - } - - return 1; + return 1; } static void secure_service(httpd_conn_t *conn, struct hrequest_t *req) { - - httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE); - http_output_stream_write_string(conn->out, - "<html>" - "<head>" - "<title>Secure ressource!</title>" - "</head>" - "<body>" - "<h1>Authenticated access!!!</h1>" - "</body>" - "</html>"); - - return; + httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE); + http_output_stream_write_string(conn->out, + "<html>" + "<head>" + "<title>Secure ressource!</title>" + "</head>" + "<body>" + "<h1>Authenticated access!!!</h1>" + "</body>" + "</html>"); + + return; } static void default_service(httpd_conn_t *conn, struct hrequest_t *req) { - - httpd_send_header(conn, 404, HTTP_STATUS_404_REASON_PHRASE); - http_output_stream_write_string(conn->out, - "<html>" - "<head>" - "<title>Default error page</title>" - "</head>" - "<body>" - "<h1>Default error page</h1>" - "<div>"); - - http_output_stream_write_string(conn->out, req->path); - - http_output_stream_write_string(conn->out, " can not be found" - "</div>" - "</body>" - "</html>"); - - return; -} + httpd_send_header(conn, 404, HTTP_STATUS_404_REASON_PHRASE); + http_output_stream_write_string(conn->out, + "<html>" + "<head>" + "<title>Default error page</title>" + "</head>" + "<body>" + "<h1>Default error page</h1>" + "<div>"); + + http_output_stream_write_string(conn->out, req->path); + + http_output_stream_write_string(conn->out, " can not be found" + "</div>" + "</body>" + "</html>"); + + return; +} static void headers_service(httpd_conn_t *conn, struct hrequest_t *req) { - hpair_t *walker; - - httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE); - http_output_stream_write_string(conn->out, - "<html>" - "<head>" - "<title>Request headers</title>" - "</head>" - "<body>" - "<h1>Request headers</h1>" - "<ul>"); - - for (walker=req->header; walker; walker=walker->next) - { - http_output_stream_write_string(conn->out, "<li>"); - http_output_stream_write_string(conn->out, walker->key); - http_output_stream_write_string(conn->out, " = "); - http_output_stream_write_string(conn->out, walker->value); - http_output_stream_write_string(conn->out, "</li>"); - } - - http_output_stream_write_string(conn->out, - "</ul>" - "</body>" - "</html>"); - - return; + hpair_t *walker; + + httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE); + http_output_stream_write_string(conn->out, + "<html>" + "<head>" + "<title>Request headers</title>" + "</head>" + "<body>" + "<h1>Request headers</h1>" + "<ul>"); + + for (walker=req->header; walker; walker=walker->next) + { + http_output_stream_write_string(conn->out, "<li>"); + http_output_stream_write_string(conn->out, walker->key); + http_output_stream_write_string(conn->out, " = "); + http_output_stream_write_string(conn->out, walker->value); + http_output_stream_write_string(conn->out, "</li>"); + } + + http_output_stream_write_string(conn->out, + "</ul>" + "</body>" + "</html>"); + + return; } static void root_service(httpd_conn_t *conn, struct hrequest_t *req) { - httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE); - http_output_stream_write_string(conn->out, - "<html>" - "<head>" - "<title>nanoHTTP server examples</title>" - "</head>" - "<body>" - "<h1>nanoHTTP server examples</h1>" - "<ul>" - "<li><a href=\"/\">Simple service</a></li>" - "<li><a href=\"/secure\">Secure service</a> (try: bob/builder)</li>" - "<li><a href=\"/headers\">Request headers</a></li>" - "<li><a href=\"/not_existent\">The default service</a></li>" - "<li><a href=\"/nhttp\">Admin page</a> (try -NHTTPDadmin on the command line)</li>" - "</ul>" - "</body>" - "</html>"); - - return; + httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE); + http_output_stream_write_string(conn->out, + "<html>" + "<head>" + "<title>nanoHTTP server examples</title>" + "</head>" + "<body>" + "<h1>nanoHTTP server examples</h1>" + "<ul>" + "<li><a href=\"/\">Simple service</a></li>" + "<li><a href=\"/secure\">Secure service</a> (try: bob/builder)</li>" + "<li><a href=\"/headers\">Request headers</a></li>" + "<li><a href=\"/not_existent\">The default service</a></li>" + "<li><a href=\"/nhttp\">Admin page</a> (try -NHTTPDadmin on the command line)</li>" + "</ul>" + "</body>" + "</html>"); + + return; } int main(int argc, char **argv) { - hlog_set_level(HLOG_INFO); + hlog_set_level(HLOG_INFO); - if (httpd_init(argc, argv)) { + if (httpd_init(argc, argv)) { - fprintf(stderr, "Cannot init httpd"); - return 1; - } + fprintf(stderr, "Cannot init httpd"); + return 1; + } - if (!httpd_register("/", root_service)) { + if (!httpd_register("/", root_service)) { - fprintf(stderr, "Cannot register service"); - return 1; - } + fprintf(stderr, "Cannot register service"); + return 1; + } - if (!httpd_register_secure("/secure", secure_service, simple_authenticator)) { + if (!httpd_register_secure("/secure", secure_service, simple_authenticator)) { - fprintf(stderr, "Cannot register secure service"); - return 1; - } + fprintf(stderr, "Cannot register secure service"); + return 1; + } - if (!httpd_register("/headers", headers_service)) { + if (!httpd_register("/headers", headers_service)) { - fprintf(stderr, "Cannot register headers service"); - return 1; - } + fprintf(stderr, "Cannot register headers service"); + return 1; + } - if (!httpd_register_default("/error", default_service)) { + if (!httpd_register_default("/error", default_service)) { - fprintf(stderr, "Cannot register default service"); - return 1; - } + fprintf(stderr, "Cannot register default service"); + return 1; + } - if (httpd_run()) { + if (httpd_run()) { - fprintf(stderr, "can not run httpd"); - return 1; - } + fprintf(stderr, "can not run httpd"); + return 1; + } - httpd_destroy(); + httpd_destroy(); - return 0; + return 0; } diff --git a/libcsoap/Makefile.am b/libcsoap/Makefile.am index e5518cb..bb00615 100644 --- a/libcsoap/Makefile.am +++ b/libcsoap/Makefile.am @@ -1,17 +1,19 @@ - +# +# $Revision: 1.14 $ +# lib_LTLIBRARIES=libcsoap.la libcsoap_ladir=$(includedir)/libcsoap-@csoap_release@/libcsoap -libcsoap_la_SOURCES=soap-xml.c soap-fault.c soap-env.c soap-service.c \ - soap-router.c soap-client.c soap-server.c soap-ctx.c \ - soap-admin.c soap-addressing.c soap-transport.c \ - soap-nudp.c soap-nhttp.c soap-wsil.c +libcsoap_la_SOURCES=soap-xml.c soap-fault.c soap-env.c soap-service.c \ + soap-router.c soap-client.c soap-server.c soap-ctx.c \ + soap-admin.c soap-addressing.c soap-transport.c \ + soap-nudp.c soap-nhttp.c soap-wsil.c \ -libcsoap_la_HEADERS=soap-xml.h soap-fault.h soap-env.h soap-service.h \ - soap-router.h soap-client.h soap-server.h soap-ctx.h \ - soap-admin.h soap-addressing.h soap-transport.h \ - soap-nudp.h soap-nhttp.h soap-wsil.h +libcsoap_la_HEADERS=soap-fault.h soap-env.h soap-service.h soap-router.h \ + soap-client.h soap-server.h soap-ctx.h soap-addressing.h \ + soap-transport.h soap-admin.h soap-wsil.h soap-nudp.h \ + soap-nhttp.h soap-xml.h if BUILD_WITH_XMLSEC1 libcsoap_la_SOURCES+=soap-xmlsec.c diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h index 30d2f00..e821b9b 100644 --- a/libcsoap/soap-client.h +++ b/libcsoap/soap-client.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-client.h,v 1.15 2006/11/29 11:04:25 m0gg Exp $ + * $Id: soap-client.h,v 1.16 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -24,6 +24,14 @@ #ifndef __csoap_client_h #define __csoap_client_h +#ifndef __CSOAP_INTERNAL +#include <nanohttp/nanohttp-client.h> + +#include <libcsoap/soap-ctx.h> +#include <libcsoap/soap-env.h> +#include <libcsoap/soap-addressing.h> +#endif + #define SOAP_ERROR_CLIENT 5000 #define SOAP_ERROR_CLIENT_GENERIC (SOAP_ERROR_CLIENT + 0) #define SOAP_ERROR_CLIENT_INIT (SOAP_ERROR_CLIENT + 1) diff --git a/libcsoap/soap-server.h b/libcsoap/soap-server.h index afb3a3a..3a9ac32 100644 --- a/libcsoap/soap-server.h +++ b/libcsoap/soap-server.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-server.h,v 1.14 2006/11/29 11:04:25 m0gg Exp $ + * $Id: soap-server.h,v 1.15 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -37,15 +37,22 @@ * @section seq_features Features * * - different transport services - * -- client/server HTTP transport service (with SSL) - * -- client/server UDP transport service (multicast) + * -# client/server HTTP transport service (including SSL) + * -# client/server UDP transport service (multicast) * - attachments via MIME * - message based security (encryption/signation) * - automatic generation of WS-Inspection * - * @author Ferhat Ayaz - * @version $Revision: 1.14 $ + * @author Ferhat Ayaz, + * Michael Rans, + * Matt Campbell, + * Heiko Ronsdorf * + * @version $Revision: 1.15 $ + * + * @see http://www.libxml.org/, + * http://www.openssl.org/, + * http://www.aleksey.com/xmlsec/ */ #ifdef __cplusplus diff --git a/nanohttp/Makefile.am b/nanohttp/Makefile.am index dae7909..f52cce0 100644 --- a/nanohttp/Makefile.am +++ b/nanohttp/Makefile.am @@ -1,3 +1,6 @@ +# +# $Revision: 1.15 $ +# lib_LTLIBRARIES=libnanohttp.la libnanohttp_ladir=$(includedir)/nanohttp-@nanohttp_release@/nanohttp @@ -8,10 +11,9 @@ libnanohttp_la_SOURCES=nanohttp-common.c nanohttp-socket.c nanohttp-client.c nanohttp-logging.c nanohttp-admin.c nanohttp-error.c libnanohttp_la_HEADERS=nanohttp-common.h nanohttp-socket.h nanohttp-client.h \ - nanohttp-server.h nanohttp-stream.h nanohttp-mime.h \ - nanohttp-request.h nanohttp-response.h \ - nanohttp-base64.h nanohttp-logging.h nanohttp-admin.h \ - nanohttp-error.h + nanohttp-server.h nanohttp-stream.h nanohttp-mime.h \ + nanohttp-request.h nanohttp-response.h nanohttp-logging.h \ + nanohttp-error.h nanohttp-base64.h nanohttp-admin.h if BUILD_WITH_SSL libnanohttp_la_SOURCES+=nanohttp-ssl.c diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c index 2392d81..1c4c6d7 100644 --- a/nanohttp/nanohttp-client.c +++ b/nanohttp/nanohttp-client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-client.c,v 1.47 2006/11/28 23:45:57 m0gg Exp $ +* $Id: nanohttp-client.c,v 1.48 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -318,12 +318,12 @@ httpc_send_header(httpc_conn_t * conn) if (walker->key && walker->value) { sprintf(buffer, "%s: %s\r\n", walker->key, walker->value); - if ((status = hsocket_send(conn->sock, buffer)) != H_OK) + if ((status = hsocket_send_string(conn->sock, buffer)) != H_OK) return status; } } - return hsocket_send(conn->sock, "\r\n"); + return hsocket_send_string(conn->sock, "\r\n"); } /*-------------------------------------------------- @@ -429,7 +429,7 @@ _httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn, } log_verbose1("Sending request..."); - if ((status = hsocket_send(conn->sock, buffer)) != H_OK) + if ((status = hsocket_send_string(conn->sock, buffer)) != H_OK) { log_error2("Cannot send request (%s)", herror_message(status)); hsocket_close(conn->sock); diff --git a/nanohttp/nanohttp-client.h b/nanohttp/nanohttp-client.h index b74130d..6e5d4c9 100644 --- a/nanohttp/nanohttp-client.h +++ b/nanohttp/nanohttp-client.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-client.h,v 1.27 2006/11/24 17:28:07 m0gg Exp $ + * $Id: nanohttp-client.h,v 1.28 2006/11/30 14:24:00 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -24,6 +24,16 @@ #ifndef __nanohttp_client_h #define __nanohttp_client_h +/* XXX: Clean up nanohttp to make this unnecessary */ +#ifndef __NHTTP_INTERNAL +#include <nanohttp/nanohttp-error.h> +#include <nanohttp/nanohttp-common.h> +#include <nanohttp/nanohttp-stream.h> +#include <nanohttp/nanohttp-request.h> +#include <nanohttp/nanohttp-response.h> +#include <nanohttp/nanohttp-logging.h> +#endif + typedef struct httpc_conn { struct hsocket_t *sock; diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c index 4c31421..87d740c 100644 --- a/nanohttp/nanohttp-server.c +++ b/nanohttp/nanohttp-server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-server.c,v 1.71 2006/11/28 23:45:57 m0gg Exp $ +* $Id: nanohttp-server.c,v 1.72 2006/11/30 14:24:00 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -122,7 +122,6 @@ static volatile int _httpd_run = 1; static struct hsocket_t _httpd_socket; static int _httpd_port = 10000; static int _httpd_max_connections = 20; -static int _httpd_timeout = 10; static hservice_t *_httpd_services_default = NULL; static hservice_t *_httpd_services_head = NULL; @@ -143,20 +142,36 @@ static sigset_t thrsigset; static pthread_mutex_t _httpd_connection_lock; #endif -/** - * - * Set Sleep function platform depended - * - */ #ifdef WIN32 -static void _sys_sleep(int secs) +BOOL WINAPI +_httpd_term(DWORD sig) +{ + /* log_debug2 ("Got signal %d", sig); */ + if (sig == _httpd_terminate_signal) + _httpd_run = 0; + + return TRUE; +} + +static void _httpd_sys_sleep(int secs) { Sleep(secs*1000); return; } #else -static inline void _sys_sleep(int secs) +static void +_httpd_term(int sig) +{ + log_debug2("Got signal %d", sig); + + if (sig == _httpd_terminate_signal) + _httpd_run = 0; + + return; +} + +static inline void _httpd_sys_sleep(int secs) { sleep(secs); @@ -185,7 +200,7 @@ _httpd_parse_arguments(int argc, char **argv) } else if (!strcmp(argv[i - 1], NHTTPD_ARG_TIMEOUT)) { - _httpd_timeout = atoi(argv[i]); + hsocket_set_timeout(atoi(argv[i])); } } @@ -337,13 +352,13 @@ httpd_get_port(void) int httpd_get_timeout(void) { - return _httpd_timeout; + return hsocket_get_timeout(); } void -httpd_set_timeout(int t) +httpd_set_timeout(int secs) { - _httpd_timeout = t; + hsocket_set_timeout(secs); return; } @@ -447,7 +462,7 @@ httpd_send_header(httpd_conn_t * res, int code, const char *text) strcat(header, "\r\n"); /* send header */ - if ((status = hsocket_nsend(res->sock, header, strlen(header))) != H_OK) + if ((status = hsocket_send(res->sock, header, strlen(header))) != H_OK) return status; res->out = http_output_stream_new(res->sock, res->header); @@ -834,29 +849,6 @@ httpd_add_headers(httpd_conn_t * conn, const hpair_t * values) return; } -#ifdef WIN32 -BOOL WINAPI -httpd_term(DWORD sig) -{ - /* log_debug2 ("Got signal %d", sig); */ - if (sig == _httpd_terminate_signal) - _httpd_run = 0; - - return TRUE; -} -#else -void -httpd_term(int sig) -{ - log_debug2("Got signal %d", sig); - - if (sig == _httpd_terminate_signal) - _httpd_run = 0; - - return; -} -#endif - /* * ----------------------------------------------------- * FUNCTION: _httpd_register_signal_handler @@ -868,13 +860,13 @@ _httpd_register_signal_handler(void) log_verbose2("registering termination signal handler (SIGNAL:%d)", _httpd_terminate_signal); #ifdef WIN32 - if (SetConsoleCtrlHandler((PHANDLER_ROUTINE) httpd_term, TRUE) == FALSE) + if (SetConsoleCtrlHandler((PHANDLER_ROUTINE) _httpd_term, TRUE) == FALSE) { log_error1("Unable to install console event handler!"); } #else - signal(_httpd_terminate_signal, httpd_term); + signal(_httpd_terminate_signal, _httpd_term); #endif return; @@ -905,7 +897,7 @@ _httpd_wait_for_empty_conn(void) if (i >= _httpd_max_connections) { - _sys_sleep(1); + _httpd_sys_sleep(1); i = -1; } else if (_httpd_connection[i].flag == CONNECTION_FREE) diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h index e85c64a..1b74344 100644 --- a/nanohttp/nanohttp-server.h +++ b/nanohttp/nanohttp-server.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-server.h,v 1.25 2006/11/28 23:45:57 m0gg Exp $ + * $Id: nanohttp-server.h,v 1.26 2006/11/30 14:24:00 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -24,6 +24,16 @@ #ifndef __nanohttp_server_h #define __nanohttp_server_h +/* XXX: Clean up nanohttp to make this unnecessary */ +#ifndef __NHTTP_INTERNAL +#include <nanohttp/nanohttp-error.h> +#include <nanohttp/nanohttp-common.h> +#include <nanohttp/nanohttp-stream.h> +#include <nanohttp/nanohttp-request.h> +#include <nanohttp/nanohttp-response.h> +#include <nanohttp/nanohttp-logging.h> +#endif + /** * * nanohttp command line flags @@ -110,7 +120,7 @@ extern "C" extern short httpd_get_port(void); extern int httpd_get_timeout(void); - extern void httpd_set_timeout(int t); + extern void httpd_set_timeout(int secs); extern const char *httpd_get_protocol(void); extern int httpd_get_conncount(void); diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c index 4869cd7..e2ecf3a 100644 --- a/nanohttp/nanohttp-socket.c +++ b/nanohttp/nanohttp-socket.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-socket.c,v 1.66 2006/11/27 12:47:27 m0gg Exp $ +* $Id: nanohttp-socket.c,v 1.68 2006/11/30 14:25:07 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -90,10 +90,51 @@ typedef int ssize_t; #endif #include "nanohttp-ssl.h" #endif -#include "nanohttp-request.h" -#include "nanohttp-server.h" + +static int _hsocket_timeout = 10; #ifdef WIN32 +static herror_t +_hsocket_sys_accept(struct hsocket_t * sock, struct hsocket_t * dest) +{ + struct hsocket_t sockfd; + int asize; + + asize = sizeof(struct sockaddr_in); + while (1) + { + sockfd.sock = accept(sock->sock, (struct sockaddr *) &(dest->addr), &asize); + if (sockfd.sock == INVALID_SOCKET) + { + if (WSAGetLastError() != WSAEWOULDBLOCK) + return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error (%s)", strerror(errno)); + } + else + { + break; + } + } + + dest->sock = sockfd.sock; + + return H_OK; +} + +static void +_hsocket_sys_close(struct hsocket_t * sock) +{ + char junk[10]; + + /* shutdown(sock,SD_RECEIVE); */ + + shutdown(sock->sock, SD_SEND); + while (recv(sock->sock, junk, sizeof(junk), 0) > 0); + /* nothing */ + closesocket(sock->sock); + + return; +} + static void _hsocket_module_sys_init(int argc, char **argv) { @@ -116,11 +157,38 @@ _hsocket_module_sys_init(int argc, char **argv) { return; } + static inline void _hsocket_module_sys_destroy(void) { return; } + +static herror_t +_hsocket_sys_accept(struct hsocket_t * sock, struct hsocket_t * dest) +{ + socklen_t len; + + len = sizeof(struct sockaddr_in); + + if ((dest->sock = accept(sock->sock, (struct sockaddr *) &(dest->addr), &len)) == -1) + { + log_warn2("accept failed (%s)", strerror(errno)); + return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Cannot accept network connection (%s)", strerror(errno)); + } + + return H_OK; +} + +static inline void +_hsocket_sys_close(struct hsocket_t * sock) +{ + shutdown(sock->sock, SHUT_RDWR); + + close(sock->sock); + + return; +} #endif herror_t @@ -246,53 +314,6 @@ hsocket_bind(struct hsocket_t *dsock, unsigned short port) return H_OK; } -#ifdef WIN32 -static herror_t -_hsocket_sys_accept(struct hsocket_t * sock, struct hsocket_t * dest) -{ - int asize; - struct hsocket_t sockfd; - - asize = sizeof(struct sockaddr_in); - while (1) - { - sockfd.sock = accept(sock->sock, (struct sockaddr *) &(dest->addr), &asize); - if (sockfd.sock == INVALID_SOCKET) - { - if (WSAGetLastError() != WSAEWOULDBLOCK) - return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, - "Socket error (%s)", strerror(errno)); - } - else - { - break; - } - } - - dest->sock = sockfd.sock; - - return H_OK; -} -#else -static herror_t -_hsocket_sys_accept(struct hsocket_t * sock, struct hsocket_t * dest) -{ - socklen_t len; - - len = sizeof(struct sockaddr_in); - - if ((dest->sock = accept(sock->sock, (struct sockaddr *) &(dest->addr), &len)) == -1) - { - log_warn2("accept failed (%s)", strerror(errno)); - return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, - "Cannot accept network connection (%s)", - strerror(errno)); - } - - return H_OK; -} -#endif - herror_t hsocket_accept(struct hsocket_t * sock, struct hsocket_t * dest) { @@ -337,34 +358,6 @@ hsocket_listen(struct hsocket_t * sock) return H_OK; } -#ifdef WIN32 -static void -_hsocket_sys_close(struct hsocket_t * sock) -{ - char junk[10]; - - /* shutdown(sock,SD_RECEIVE); */ - - shutdown(sock->sock, SD_SEND); - while (recv(sock->sock, junk, sizeof(junk), 0) > 0); - /* nothing */ - closesocket(sock->sock); - - return; -} -#else -static inline void -_hsocket_sys_close(struct hsocket_t * sock) -{ - - shutdown(sock->sock, SHUT_RDWR); - - close(sock->sock); - - return; -} -#endif - void hsocket_close(struct hsocket_t * sock) { @@ -385,7 +378,7 @@ hsocket_close(struct hsocket_t * sock) } herror_t -hsocket_nsend(struct hsocket_t * sock, const unsigned char * bytes, int n) +hsocket_send(struct hsocket_t * sock, const unsigned char * bytes, int n) { #ifdef HAVE_SSL herror_t status; @@ -393,9 +386,8 @@ hsocket_nsend(struct hsocket_t * sock, const unsigned char * bytes, int n) size_t total = 0; size_t size; - log_verbose2("Starting to send on sock=%p", &sock); if (sock->sock < 0) - return herror_new("hsocket_nsend", HSOCKET_ERROR_NOT_INITIALIZED, + return herror_new("hsocket_send", HSOCKET_ERROR_NOT_INITIALIZED, "hsocket not initialized"); /* log_verbose2( "SENDING %s", bytes ); */ @@ -410,7 +402,7 @@ hsocket_nsend(struct hsocket_t * sock, const unsigned char * bytes, int n) } #else if ((size = send(sock->sock, bytes + total, n, 0)) == -1) - return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "send failed (%s)", strerror(errno)); + return herror_new("hsocket_send", HSOCKET_ERROR_SEND, "send failed (%s)", strerror(errno)); #endif sock->bytes_received += size; @@ -424,9 +416,9 @@ hsocket_nsend(struct hsocket_t * sock, const unsigned char * bytes, int n) } herror_t -hsocket_send(struct hsocket_t * sock, const char *str) +hsocket_send_string(struct hsocket_t * sock, const char *str) { - return hsocket_nsend(sock, str, strlen(str)); + return hsocket_send(sock, str, strlen(str)); } int @@ -438,13 +430,13 @@ hsocket_select_recv(int sock, char *buf, size_t len) FD_ZERO(&fds); FD_SET(sock, &fds); - timeout.tv_sec = httpd_get_timeout(); + timeout.tv_sec = _hsocket_timeout; timeout.tv_usec = 0; if (select(sock + 1, &fds, NULL, NULL, &timeout) == 0) { errno = ETIMEDOUT; - log_verbose2("Socket %d timeout", sock); + log_verbose2("Socket %d timed out", sock); return -1; } @@ -498,3 +490,17 @@ hsocket_read(struct hsocket_t * sock, unsigned char * buffer, int total, int for } while (1); } + +int +hsocket_get_timeout(void) +{ + return _hsocket_timeout; +} + +void +hsocket_set_timeout(int secs) +{ + _hsocket_timeout = secs; + + return; +} diff --git a/nanohttp/nanohttp-socket.h b/nanohttp/nanohttp-socket.h index db2bf31..b71f38d 100644 --- a/nanohttp/nanohttp-socket.h +++ b/nanohttp/nanohttp-socket.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-socket.h,v 1.33 2006/11/26 20:13:06 m0gg Exp $ + * $Id: nanohttp-socket.h,v 1.34 2006/11/30 14:24:00 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -175,7 +175,7 @@ extern herror_t hsocket_accept(struct hsocket_t *sock, struct hsocket_t *dest); * - HSOCKET_ERROR_NOT_INITIALIZED * - HSOCKET_ERROR_SEND */ -extern herror_t hsocket_nsend(struct hsocket_t *sock, const unsigned char *bytes, int size); +extern herror_t hsocket_send(struct hsocket_t *sock, const unsigned char *bytes, int size); /** * @@ -189,7 +189,7 @@ extern herror_t hsocket_nsend(struct hsocket_t *sock, const unsigned char *bytes * - HSOCKET_ERROR_SEND * */ -extern herror_t hsocket_send(struct hsocket_t *sock, const char *str); +extern herror_t hsocket_send_string(struct hsocket_t *sock, const char *str); extern int hsocket_select_recv(int sock, char *buf, size_t len); @@ -210,6 +210,9 @@ extern int hsocket_select_recv(int sock, char *buf, size_t len); */ extern herror_t hsocket_read(struct hsocket_t * sock, unsigned char *buffer, int size, int force, int *readed); +extern int hsocket_get_timeout(void); +extern void hsocket_set_timeout(int secs); + #ifdef __cplusplus } #endif diff --git a/nanohttp/nanohttp-ssl.c b/nanohttp/nanohttp-ssl.c index 8b8fb5d..a5f32e3 100644 --- a/nanohttp/nanohttp-ssl.c +++ b/nanohttp/nanohttp-ssl.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-ssl.c,v 1.33 2006/11/27 12:47:27 m0gg Exp $ +* $Id: nanohttp-ssl.c,v 1.34 2006/11/30 14:24:00 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2001-2005 Rochester Institute of Technology @@ -84,12 +84,11 @@ #include "nanohttp-ssl.h" -static char *certificate = NULL; -static char *certpass = ""; -static char *ca_list = NULL; -static SSL_CTX *context = NULL; - -static int enabled = 0; +static char *_hssl_certificate = NULL; +static char *_hssl_certpass = NULL; +static char *_hssl_ca_list = NULL; +static SSL_CTX *_hssl_context = NULL; +static int _hssl_enabled = 0; static int _hssl_dummy_verify_cert(X509 * cert) @@ -99,7 +98,7 @@ _hssl_dummy_verify_cert(X509 * cert) /* connect to anyone */ - log_verbose1("Validating certificate."); + log_verbose1("_Not_ validating certificate."); return 1; } @@ -176,12 +175,15 @@ _hssl_password_callback(char *buf, int num, int rwflag, void *userdata) { int ret; - ret = strlen(certpass); + if (!_hssl_certpass) + return 0; + + ret = strlen(_hssl_certpass); if (num < ret + 1) return 0; - strcpy(buf, certpass); + strcpy(buf, _hssl_certpass); return ret; } @@ -221,25 +223,34 @@ hssl_set_hssl_verify_cert(int func(X509 * cert)) } void -hssl_set_certificate(char *c) +hssl_set_certificate(const char *filename) { - certificate = c; + if (_hssl_certificate) + free(_hssl_certificate); + + _hssl_certificate = strdup(filename); return; } void -hssl_set_certpass(char *c) +hssl_set_certpass(const char *password) { - certpass = c; + if (_hssl_certpass) + free(_hssl_certpass); + + _hssl_certpass = strdup(password); return; } void -hssl_set_ca(char *c) +hssl_set_ca_list(const char *filename) { - ca_list = c; + if (_hssl_ca_list) + free(_hssl_ca_list); + + _hssl_ca_list = strdup(filename); return; } @@ -247,7 +258,7 @@ hssl_set_ca(char *c) void hssl_enable(void) { - enabled = 1; + _hssl_enabled = 1; return; } @@ -257,23 +268,23 @@ _hssl_parse_arguments(int argc, char **argv) { int i; - for (i = 1; i < argc; i++) + for (i=1; i<argc; i++) { if (!strcmp(argv[i - 1], NHTTP_ARG_CERT)) { - certificate = argv[i]; + hssl_set_certificate(argv[i]); } else if (!strcmp(argv[i - 1], NHTTP_ARG_CERTPASS)) { - certpass = argv[i]; + hssl_set_certpass(argv[i]); } else if (!strcmp(argv[i - 1], NHTTP_ARG_CA)) { - ca_list = argv[i]; + hssl_set_ca_list(argv[i]); } else if (!strcmp(argv[i - 1], NHTTPD_ARG_HTTPS)) { - enabled = 1; + hssl_enabled(); } } @@ -305,57 +316,57 @@ _hssl_library_init(void) static herror_t _hssl_server_context_init(void) { - log_verbose3("enabled=%i, certificate=%p", enabled, certificate); + log_verbose3("enabled=%i, certificate=%p", _hssl_enabled, _hssl_certificate); - if (!enabled || !certificate) + if (!_hssl_enabled || !_hssl_certificate) return H_OK; - if (!(context = SSL_CTX_new(SSLv23_method()))) + if (!(_hssl_context = SSL_CTX_new(SSLv23_method()))) { log_error1("Cannot create SSL context"); return herror_new("_hssl_server_context_init", HSSL_ERROR_CONTEXT, "Unable to create SSL context"); } - if (!(SSL_CTX_use_certificate_file(context, certificate, SSL_FILETYPE_PEM))) + if (!(SSL_CTX_use_certificate_file(_hssl_context, _hssl_certificate, SSL_FILETYPE_PEM))) { - log_error2("Cannot read certificate file: \"%s\"", certificate); - SSL_CTX_free(context); + log_error2("Cannot read certificate file: \"%s\"", _hssl_certificate); + SSL_CTX_free(_hssl_context); return herror_new("_hssl_server_context_init", HSSL_ERROR_CERTIFICATE, - "Unable to use SSL certificate \"%s\"", certificate); + "Unable to use SSL certificate \"%s\"", _hssl_certificate); } - SSL_CTX_set_default_passwd_cb(context, _hssl_password_callback); + SSL_CTX_set_default_passwd_cb(_hssl_context, _hssl_password_callback); - if (!(SSL_CTX_use_PrivateKey_file(context, certificate, SSL_FILETYPE_PEM))) + if (!(SSL_CTX_use_PrivateKey_file(_hssl_context, _hssl_certificate, SSL_FILETYPE_PEM))) { - log_error2("Cannot read key file: \"%s\"", certificate); - SSL_CTX_free(context); + log_error2("Cannot read key file: \"%s\"", _hssl_certificate); + SSL_CTX_free(_hssl_context); return herror_new("_hssl_server_context_init", HSSL_ERROR_PEM, "Unable to use private key"); } - if (ca_list != NULL && *ca_list != '\0') + if (_hssl_ca_list != NULL && *_hssl_ca_list != '\0') { - if (!(SSL_CTX_load_verify_locations(context, ca_list, NULL))) + if (!(SSL_CTX_load_verify_locations(_hssl_context, _hssl_ca_list, NULL))) { - SSL_CTX_free(context); - log_error2("Cannot read CA list: \"%s\"", ca_list); + SSL_CTX_free(_hssl_context); + log_error2("Cannot read CA list: \"%s\"", _hssl_ca_list); return herror_new("_hssl_server_context_init", HSSL_ERROR_CA_LIST, "Unable to read certification authorities \"%s\""); } - SSL_CTX_set_client_CA_list(context, SSL_load_client_CA_file(ca_list)); + SSL_CTX_set_client_CA_list(_hssl_context, SSL_load_client_CA_file(_hssl_ca_list)); log_verbose1("Certification authority contacted"); } - SSL_CTX_set_verify(context, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, + SSL_CTX_set_verify(_hssl_context, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, _hssl_cert_verify_callback); log_verbose1("Certificate verification callback registered"); - SSL_CTX_set_mode(context, SSL_MODE_AUTO_RETRY); + SSL_CTX_set_mode(_hssl_context, SSL_MODE_AUTO_RETRY); - SSL_CTX_set_session_cache_mode(context, SSL_SESS_CACHE_OFF); + SSL_CTX_set_session_cache_mode(_hssl_context, SSL_SESS_CACHE_OFF); _hssl_superseed(); @@ -365,10 +376,10 @@ _hssl_server_context_init(void) static void _hssl_server_context_destroy(void) { - if (context) + if (_hssl_context) { - SSL_CTX_free(context); - context = NULL; + SSL_CTX_free(_hssl_context); + _hssl_context = NULL; } return; } @@ -378,7 +389,7 @@ hssl_module_init(int argc, char **argv) { _hssl_parse_arguments(argc, argv); - if (enabled) + if (_hssl_enabled) { _hssl_library_init(); log_verbose1("SSL enabled"); @@ -396,13 +407,31 @@ hssl_module_destroy(void) { _hssl_server_context_destroy(); + if (_hssl_certpass) + { + free(_hssl_certpass); + _hssl_certpass = NULL; + } + + if (_hssl_ca_list) + { + free(_hssl_ca_list); + _hssl_ca_list = NULL; + } + + if (_hssl_certificate) + { + free(_hssl_certificate); + _hssl_certificate = NULL; + } + return; } int hssl_enabled(void) { - return enabled; + return _hssl_enabled; } herror_t @@ -413,7 +442,7 @@ hssl_client_ssl(struct hsocket_t * sock) log_verbose1("Starting SSL client initialization"); - if (!(ssl = SSL_new(context))) + if (!(ssl = SSL_new(_hssl_context))) { log_error1("Cannot create new SSL object"); return herror_new("hssl_client_ssl", HSSL_ERROR_CLIENT, "SSL_new failed"); @@ -452,7 +481,6 @@ hssl_client_ssl(struct hsocket_t * sock) static int _hssl_bio_read(BIO * b, char *out, int outl) { - return hsocket_select_recv(b->num, out, outl);; } @@ -463,12 +491,12 @@ hssl_server_ssl(struct hsocket_t *sock) int ret; BIO *sbio; - if (!enabled) + if (!_hssl_enabled) return H_OK; log_verbose2("Starting SSL initialization for socket %d", sock->sock); - if (!(ssl = SSL_new(context))) + if (!(ssl = SSL_new(_hssl_context))) { log_warn1("SSL_new failed"); return herror_new("hssl_server_ssl", HSSL_ERROR_SERVER, @@ -530,7 +558,7 @@ hssl_read(struct hsocket_t * sock, char *buf, size_t len, size_t * received) if (sock->ssl) { if ((count = SSL_read(sock->ssl, buf, len)) < 1) - return herror_new("SSL_read", HSOCKET_ERROR_RECEIVE, + return herror_new("hssl_read", HSOCKET_ERROR_RECEIVE, "SSL_read failed (%s)", _hssl_get_error(sock->ssl, count)); } @@ -556,7 +584,7 @@ hssl_write(struct hsocket_t * sock, const char *buf, size_t len, size_t * sent) if (sock->ssl) { if ((count = SSL_write(sock->ssl, buf, len)) == -1) - return herror_new("SSL_write", HSOCKET_ERROR_SEND, + return herror_new("hssl_write", HSOCKET_ERROR_SEND, "SSL_write failed (%s)", _hssl_get_error(sock->ssl, count)); } diff --git a/nanohttp/nanohttp-ssl.h b/nanohttp/nanohttp-ssl.h index 6df53e7..8902ea3 100644 --- a/nanohttp/nanohttp-ssl.h +++ b/nanohttp/nanohttp-ssl.h @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-ssl.h,v 1.22 2006/11/27 12:47:27 m0gg Exp $ +* $Id: nanohttp-ssl.h,v 1.23 2006/11/30 14:24:00 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2001-2005 Rochester Institute of Technology @@ -51,9 +51,9 @@ extern herror_t hssl_module_init(int argc, char **argv); */ extern void hssl_module_destroy(void); -extern void hssl_set_certificate(char *c); -extern void hssl_set_certpass(char *c); -extern void hssl_set_ca(char *c); +extern void hssl_set_certificate(const char *filename); +extern void hssl_set_certpass(const char *password); +extern void hssl_set_ca_list(const char *filename); /** * diff --git a/nanohttp/nanohttp-stream.c b/nanohttp/nanohttp-stream.c index 59888d1..b121e57 100755 --- a/nanohttp/nanohttp-stream.c +++ b/nanohttp/nanohttp-stream.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-stream.c,v 1.17 2006/11/25 15:06:58 m0gg Exp $ +* $Id: nanohttp-stream.c,v 1.18 2006/11/30 14:24:00 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003-2004 Ferhat Ayaz @@ -570,19 +570,19 @@ http_output_stream_write(struct http_output_stream_t * stream, if (stream->type == HTTP_TRANSFER_CHUNKED) { sprintf(chunked, "%x\r\n", size); - if ((status = hsocket_send(stream->sock, chunked)) != H_OK) + if ((status = hsocket_send_string(stream->sock, chunked)) != H_OK) return status; } if (size > 0) { - if ((status = hsocket_nsend(stream->sock, bytes, size)) != H_OK) + if ((status = hsocket_send(stream->sock, bytes, size)) != H_OK) return status; } if (stream->type == HTTP_TRANSFER_CHUNKED) { - if ((status = hsocket_send(stream->sock, "\r\n")) != H_OK) + if ((status = hsocket_send_string(stream->sock, "\r\n")) != H_OK) return status; } @@ -608,7 +608,7 @@ http_output_stream_flush(struct http_output_stream_t * stream) if (stream->type == HTTP_TRANSFER_CHUNKED) { - if ((status = hsocket_send(stream->sock, "0\r\n\r\n")) != H_OK) + if ((status = hsocket_send_string(stream->sock, "0\r\n\r\n")) != H_OK) return status; } |