From 5502aff768e5cbc3bbd05e067bc0dfc456770f86 Mon Sep 17 00:00:00 2001 From: m0gg Date: Mon, 1 Jan 2007 22:54:46 +0000 Subject: Header parsing error solved --- TODO | 14 +++++++------- examples/csoap/echoattachments-client.c | 13 +++++++------ examples/csoap/echoattachments-server.c | 9 +++++---- examples/nanohttp/http_server.c | 31 ++++++++++--------------------- nanohttp/nanohttp-admin.c | 12 +++++++----- nanohttp/nanohttp-client.c | 4 ++-- nanohttp/nanohttp-common.c | 20 ++++++++------------ nanohttp/nanohttp-server.c | 32 +++++++++++++++++++------------- nanohttp/nanohttp-server.h | 33 +++++++++++++++++++++------------ 9 files changed, 86 insertions(+), 82 deletions(-) diff --git a/TODO b/TODO index 0e1933d..3b50e5e 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -$Id: TODO,v 1.15 2007/01/01 18:58:05 m0gg Exp $ +$Id: TODO,v 1.16 2007/01/01 22:54:46 m0gg Exp $ =============================================================================== Things to do _before_ 1.2 release: @@ -9,7 +9,6 @@ nanohttp: - improve error handling!!!! - cleanup/improve nanohttp request parsing - "GET http://fdqn/service HTTP/1.1" segfaults - - other HTTP methods (OPTIONS, CONNECT) should return HTTP 501 - Check portability to Win32/MaxOS (only tested on FreeBSD/Solaris/Linux) - remove CFLAGS="-D_XOPEN_SOURCE=600" ./configure on Linux - Elaborate README.ssl (more text and references to csoap API docs, OpenSSL) @@ -19,6 +18,8 @@ nanohttp: csoap: ------ +- MIME functions are broken (example only?) + - optimize mime API - Check portability to Win32/Linux/MaxOS (only tested on FreeBSD 6.2) - Improve API documentation - Add reference to http://www.w3.org/TR/SOAP-attachments @@ -36,18 +37,17 @@ Additional things that could be done: nanohttp: --------- -- optimize mime API -- add DIME attachments -- add BASE64 decoding for MIME attachments +- add DIME attachments (SOAP MTOM) +- add BASE64 decoding for MIME attachments (?) - cleanup circular module dependencies - e.g. nanohttp-stream should hide hsocket, hssl + - e.g. nanohttp-stream should hide hsocket, hssl csoap: ------ - add examples from http://www.xmethods.org (Google, UDDI) - soap-nudp.c one thread per request (see soap_nudp_server_run) - http://www.ws-i.org/Profiles/BasicProfile-1.0.html conformance testing - create an automated testsuite (?) + - create an automated testsuite (?) - http://www.w3.org/Submission/WS-Enumeration/ - soap-nudp message re-transmission - WS-Reliability support (?) diff --git a/examples/csoap/echoattachments-client.c b/examples/csoap/echoattachments-client.c index fbee05e..4ad908e 100755 --- a/examples/csoap/echoattachments-client.c +++ b/examples/csoap/echoattachments-client.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: echoattachments-client.c,v 1.16 2006/11/30 14:23:59 m0gg Exp $ + * $Id: echoattachments-client.c,v 1.17 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003-2004 Ferhat Ayaz @@ -101,6 +101,7 @@ compareFiles(const char *received, const char *sent) fclose(f1); fclose(f2); + return; } int @@ -122,7 +123,7 @@ main(int argc, char **argv) err = soap_client_init_args(argc, argv); if (err != H_OK) { - printf("[%d] %s():%s ", herror_code(err), herror_func(err), herror_message(err)); + printf("[%d] %s():%s \n", herror_code(err), herror_func(err), herror_message(err)); herror_release(err); return 1; } @@ -132,7 +133,7 @@ main(int argc, char **argv) err = soap_ctx_new_with_method(urn, method, &ctx); if (err != H_OK) { - printf("[%d] %s():%s ", herror_code(err), herror_func(err), herror_message(err)); + printf("[%d] %s():%s \n", herror_code(err), herror_func(err), herror_message(err)); herror_release(err); return 1; } @@ -142,7 +143,7 @@ main(int argc, char **argv) err = soap_ctx_add_file(ctx, argv[1], "application/octet-stream", href); if (err != H_OK) { - printf("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err)); + printf("%s():%s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); herror_release(err); return 1; } @@ -161,7 +162,7 @@ main(int argc, char **argv) if (err != H_OK) { - printf("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err)); + printf("%s():%s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); herror_release(err); return 1; } @@ -179,7 +180,7 @@ main(int argc, char **argv) } else { - printf("No attachments!"); + printf("No attachments!\n"); xmlDocDump(stdout, ctx2->env->root->doc); } diff --git a/examples/csoap/echoattachments-server.c b/examples/csoap/echoattachments-server.c index ea45aa8..e6b4872 100755 --- a/examples/csoap/echoattachments-server.c +++ b/examples/csoap/echoattachments-server.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: echoattachments-server.c,v 1.12 2006/11/25 15:06:57 m0gg Exp $ + * $Id: echoattachments-server.c,v 1.13 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003-2004 Ferhat Ayaz @@ -57,6 +57,7 @@ echo_attachments(struct SoapCtx * req, struct SoapCtx * res) { for (part = req->attachments->parts; part != NULL; part = part->next) { + printf("attaching \"%s\"\n", part->filename); soap_ctx_add_file(res, part->filename, part->content_type, href); soap_env_add_attachment(res->env, "echoFile", href); } @@ -76,7 +77,7 @@ main(int argc, char **argv) err = soap_server_init_args(argc, argv); if (err != H_OK) { - printf("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err)); + printf("%s():%s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); herror_release(err); return 1; } @@ -85,10 +86,10 @@ main(int argc, char **argv) soap_router_register_service(router, echo_attachments, method, urn); soap_server_register_router(router, url); - log_info1("send SIGTERM to shutdown"); + printf("send SIGTERM to shutdown"); soap_server_run(); - log_info1("shutting down\n"); + printf("shutting down\n"); soap_server_destroy(); return 0; diff --git a/examples/nanohttp/http_server.c b/examples/nanohttp/http_server.c index a00c982..052aec1 100644 --- a/examples/nanohttp/http_server.c +++ b/examples/nanohttp/http_server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: http_server.c,v 1.12 2006/12/10 12:23:45 m0gg Exp $ +* $Id: http_server.c,v 1.13 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: A http client/server library in C (example) * Copyright (C) 2003 Ferhat Ayaz @@ -22,6 +22,7 @@ * Email: hero@persua.de ******************************************************************/ #include +#include #include #include @@ -63,29 +64,20 @@ static void secure_service(httpd_conn_t *conn, struct hrequest_t *req) 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, - "" - "" - "Default error page" - "" - "" - "

Default error page

" - "
"); + char buf[512]; - http_output_stream_write_string(conn->out, req->path); + snprintf(buf, 512, "Resource \"%s\" not found", req->path); - http_output_stream_write_string(conn->out, " cannot be found" - "
" - "" - ""); + httpd_send_not_found(conn, buf); return; -} +} static void headers_service(httpd_conn_t *conn, struct hrequest_t *req) { hpair_t *walker; + char buf[512]; + int len; httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE); http_output_stream_write_string(conn->out, @@ -99,11 +91,8 @@ static void headers_service(httpd_conn_t *conn, struct hrequest_t *req) for (walker=req->header; walker; walker=walker->next) { - http_output_stream_write_string(conn->out, "
  • "); - 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, "
  • "); + len = snprintf(buf, 512, "
  • %s: %s
  • ", walker->key, walker->value); + http_output_stream_write(conn->out, buf, len); } http_output_stream_write_string(conn->out, diff --git a/nanohttp/nanohttp-admin.c b/nanohttp/nanohttp-admin.c index 3dbdbd6..060cbb8 100644 --- a/nanohttp/nanohttp-admin.c +++ b/nanohttp/nanohttp-admin.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-admin.c,v 1.11 2006/12/31 17:24:22 m0gg Exp $ +* $Id: nanohttp-admin.c,v 1.12 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -68,9 +68,9 @@ _httpd_admin_send_title(httpd_conn_t *conn, const char *title) ""); http_output_stream_write_string(conn->out, - "" - "" - "nhttpd "); + "" + "" + "nhttpd "); http_output_stream_write_string(conn->out, title); http_output_stream_write_string(conn->out, "
    "); @@ -80,7 +80,9 @@ _httpd_admin_send_title(httpd_conn_t *conn, const char *title) static inline void _httpd_admin_send_footer(httpd_conn_t *conn) { - http_output_stream_write_string(conn->out, ""); + http_output_stream_write_string(conn->out, + "" + ""); return; } diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c index 00bf7c7..472c58f 100644 --- a/nanohttp/nanohttp-client.c +++ b/nanohttp/nanohttp-client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-client.c,v 1.52 2007/01/01 15:29:48 m0gg Exp $ +* $Id: nanohttp-client.c,v 1.53 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -390,7 +390,7 @@ _httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn, const char *url httpc_set_header(conn, HEADER_HOST, conn->url->host); ssl = conn->url->protocol == PROTOCOL_HTTPS ? 1 : 0; - log_error4("ssl = %i (%i %i)", ssl, conn->url->protocol, PROTOCOL_HTTPS); + log_verbose4("ssl = %i (%i %i)", ssl, conn->url->protocol, PROTOCOL_HTTPS); /* Open connection */ if ((status = hsocket_open(conn->sock, conn->url->host, conn->url->port, ssl)) != H_OK) diff --git a/nanohttp/nanohttp-common.c b/nanohttp/nanohttp-common.c index 9b5015e..de17bfe 100644 --- a/nanohttp/nanohttp-common.c +++ b/nanohttp/nanohttp-common.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-common.c,v 1.37 2006/12/16 15:55:24 m0gg Exp $ +* $Id: nanohttp-common.c,v 1.38 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -71,8 +71,7 @@ hpairnode_new(const char *key, const char *value, hpair_t * next) if (key != NULL) { - pair->key = (char *) malloc(strlen(key) + 1); - strcpy(pair->key, key); + pair->key = strdup(key); } else { @@ -81,8 +80,7 @@ hpairnode_new(const char *key, const char *value, hpair_t * next) if (value != NULL) { - pair->value = (char *) malloc(strlen(value) + 1); - strcpy(pair->value, value); + pair->value = strdup(value); } else { @@ -99,7 +97,6 @@ hpairnode_parse(const char *str, const char *delim, hpair_t * next) { hpair_t *pair; char *key, *value; - int c; pair = (hpair_t *) malloc(sizeof(hpair_t)); pair->key = ""; @@ -110,19 +107,18 @@ hpairnode_parse(const char *str, const char *delim, hpair_t * next) if (key != NULL) { - pair->key = (char *) malloc(strlen(key) + 1); - strcpy(pair->key, key); + pair->key = strdup(key); } if (value != NULL) { - for (c = 0; value[c] == ' '; c++); /* skip white space */ - pair->value = (char *) malloc(strlen(&value[c]) + 1); - strcpy(pair->value, &value[c]); + /* skip white space */ + for (; *value == ' '; value++) ; + + pair->value = strdup(value); } return pair; } - hpair_t * hpairnode_copy(const hpair_t * src) { diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c index 9e2af45..e7fe6d6 100644 --- a/nanohttp/nanohttp-server.c +++ b/nanohttp/nanohttp-server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-server.c,v 1.79 2007/01/01 15:29:48 m0gg Exp $ +* $Id: nanohttp-server.c,v 1.80 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -548,18 +548,6 @@ _httpd_send_html_message(httpd_conn_t *conn, int reason, const char *phrase, con return http_output_stream_write(conn->out, buf, len); } -herror_t -httpd_send_internal_error(httpd_conn_t * conn, const char *msg) -{ - return _httpd_send_html_message(conn, 500, HTTP_STATUS_500_REASON_PHRASE, msg); -} - -herror_t -httpd_send_not_implemented(httpd_conn_t *conn, const char *msg) -{ - return _httpd_send_html_message(conn, 501, HTTP_STATUS_501_REASON_PHRASE, msg); -} - herror_t httpd_send_bad_request(httpd_conn_t *conn, const char *msg) { @@ -577,6 +565,24 @@ httpd_send_unauthorized(httpd_conn_t *conn, const char *realm) return _httpd_send_html_message(conn, 401, HTTP_STATUS_401_REASON_PHRASE, "Unauthorized request logged"); } +herror_t +httpd_send_not_found(httpd_conn_t *conn, const char *msg) +{ + return _httpd_send_html_message(conn, 404, HTTP_STATUS_404_REASON_PHRASE, msg); +} + +herror_t +httpd_send_internal_error(httpd_conn_t *conn, const char *msg) +{ + return _httpd_send_html_message(conn, 500, HTTP_STATUS_500_REASON_PHRASE, msg); +} + +herror_t +httpd_send_not_implemented(httpd_conn_t *conn, const char *msg) +{ + return _httpd_send_html_message(conn, 501, HTTP_STATUS_501_REASON_PHRASE, msg); +} + static void _httpd_request_print(struct hrequest_t * req) { diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h index 53eb4a8..71c0370 100644 --- a/nanohttp/nanohttp-server.h +++ b/nanohttp/nanohttp-server.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-server.h,v 1.35 2007/01/01 18:58:05 m0gg Exp $ + * $Id: nanohttp-server.h,v 1.36 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -360,39 +360,48 @@ extern herror_t httpd_mime_end(httpd_conn_t * conn); /** * - * Send a minimalistic HTML error document with HTTP status 500. + * Send a minimalistic HTML error document with HTTP status 400. * - * @see HTTP_STATUS_500_REASON_PHRASE + * @see HTTP_STATUS_400_REASON_PHRASE * */ -extern herror_t httpd_send_internal_error(httpd_conn_t * conn, const char *msg); +extern herror_t httpd_send_bad_request(httpd_conn_t *conn, const char *msg); /** * - * Send a minimalistic HTML error document with HTTP status 501. + * Send a minimalistc HTML error document with HTTP status 401. * - * @see HTTP_STATUS_501_REASON_PHRASE + * @see HTTP_STATUS_401_REASON_PHRASE * */ -extern herror_t httpd_send_not_implemented(httpd_conn_t *conn, const char *msg); +extern herror_t httpd_send_unauthorized(httpd_conn_t *conn, const char *realm); /** * * Send a minimalistic HTML error document with HTTP status 404. * - * @see HTTP_STATUS_401_REASON_PHRASE + * @see HTTP_STATUS_404_REASON_PHRASE * */ -extern herror_t httpd_send_bad_request(httpd_conn_t *conn, const char *msg); +extern herror_t httpd_send_not_found(httpd_conn_t *conn, const char *msg); /** * - * Send a minimalistc HTML error document with HTTP status 401. + * Send a minimalistic HTML error document with HTTP status 500. * - * @see HTTP_STATUS_404_REASON_PHRASE + * @see HTTP_STATUS_500_REASON_PHRASE * */ -extern herror_t httpd_send_unauthorized(httpd_conn_t *conn, const char *realm); +extern herror_t httpd_send_internal_error(httpd_conn_t * conn, const char *msg); + +/** + * + * Send a minimalistic HTML error document with HTTP status 501. + * + * @see HTTP_STATUS_501_REASON_PHRASE + * + */ +extern herror_t httpd_send_not_implemented(httpd_conn_t *conn, const char *msg); #ifdef __cplusplus } -- cgit v1.1-32-gdbae