From c4286ea5287279836c5ef49a06153db95429bfe6 Mon Sep 17 00:00:00 2001 From: snowdrop Date: Wed, 8 Feb 2006 11:13:13 +0000 Subject: the attached patches address the following issues: * query the port the server is listening on {soap_server,httpd}_get_port * the possibility to add a default service via httpd_register_default * remove some compiler warnings (on FreeBSD pthread_t is a pointer to a struct pthread, on Linux it is a (unsigned?) long int) tschuess, Heiko --- nanohttp/nanohttp-server.c | 57 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'nanohttp/nanohttp-server.c') diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c index 24a8333..e063045 100644 --- a/nanohttp/nanohttp-server.c +++ b/nanohttp/nanohttp-server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-server.c,v 1.47 2006/01/25 19:15:18 mrcsys Exp $ +* $Id: nanohttp-server.c,v 1.48 2006/02/08 11:13:14 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -85,6 +85,7 @@ static int _httpd_max_connections = 20; static int _httpd_max_idle = 120; #endif static hsocket_t _httpd_socket; +static hservice_t *_httpd_services_default = NULL; static hservice_t *_httpd_services_head = NULL; static hservice_t *_httpd_services_tail = NULL; static int _httpd_run = 1; @@ -180,7 +181,7 @@ httpd_init (int argc, char *argv[]) SSLPass = hoption_get(HOPTION_SSL_PASS); SSLCA = hoption_get(HOPTION_SSL_CA); log_verbose3("SSL: %s %s", SSLCert, SSLCA); - if(SSLCert[0] != NULL){ + if(SSLCert[0] != '\0'){ status = hsocket_init_ssl(&_httpd_socket, SSLCert, SSLPass, SSLCA); } else #endif @@ -227,6 +228,24 @@ httpd_register (const char *ctx, httpd_service func) return 1; } +int +httpd_register_default (const char *ctx, httpd_service func) +{ + int ret; + + ret = httpd_register(ctx, func); + + /* this is broken, but working */ + _httpd_services_default = _httpd_services_tail; + + return ret; +} + +int +httpd_get_port(void) +{ + return _httpd_port; +} /* * ----------------------------------------------------- @@ -269,7 +288,7 @@ httpd_find_service (const char *ctx) cur = cur->next; } - return NULL; + return _httpd_services_default; } @@ -609,7 +628,6 @@ httpd_set_header (httpd_conn_t * conn, const char *key, const char *value) return 0; } - void httpd_set_headers (httpd_conn_t * conn, hpair_t * header) { @@ -620,6 +638,37 @@ httpd_set_headers (httpd_conn_t * conn, hpair_t * header) } } +int +httpd_add_header (httpd_conn_t *conn, const char *key, const char *value) +{ + if (!conn) + { + log_warn1("Connection object is NULL"); + return 0; + } + + conn->header = hpairnode_new(key, value, conn->header); + + return 1; +} + +void +httpd_add_headers (httpd_conn_t *conn, const hpair_t *values) +{ + if (!conn) + { + log_warn1("Connection object is NULL"); + return; + } + + while (values) + { + httpd_add_header(conn, values->key, values->value); + values = values->next; + } + return; +} + /* * ----------------------------------------------------- * FUNCTION: httpd_term -- cgit v1.1-32-gdbae