summaryrefslogtreecommitdiffstats
path: root/nanohttp
diff options
context:
space:
mode:
authorGravatar snowdrop2006-02-08 11:13:13 +0000
committerGravatar snowdrop2006-02-08 11:13:13 +0000
commitc4286ea5287279836c5ef49a06153db95429bfe6 (patch)
tree1ace3f15224374a6350b028b2fe50d34072f5f87 /nanohttp
parent1340ec27d42648e84878abe2d2f0b6f23ca24d82 (diff)
downloadcsoap-c4286ea5287279836c5ef49a06153db95429bfe6.tar.gz
csoap-c4286ea5287279836c5ef49a06153db95429bfe6.tar.bz2
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
Diffstat (limited to 'nanohttp')
-rw-r--r--nanohttp/nanohttp-client.c37
-rw-r--r--nanohttp/nanohttp-client.h8
-rw-r--r--nanohttp/nanohttp-common.c6
-rw-r--r--nanohttp/nanohttp-server.c57
-rw-r--r--nanohttp/nanohttp-server.h7
-rw-r--r--nanohttp/nanohttp-socket.c4
-rw-r--r--nanohttp/nanohttp-ssl.c15
7 files changed, 108 insertions, 26 deletions
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c
index bf01fbe..44ba815 100644
--- a/nanohttp/nanohttp-client.c
+++ b/nanohttp/nanohttp-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-client.c,v 1.36 2006/01/25 19:18:42 mrcsys Exp $
+* $Id: nanohttp-client.c,v 1.37 2006/02/08 11:13:14 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -145,7 +145,35 @@ httpc_close_free(httpc_conn_t * conn)
httpc_free(conn);
}
+int
+httpc_add_header(httpc_conn_t *conn, const char *key, const char *value)
+{
+ if (!conn)
+ {
+ log_warn1("Connection object is NULL");
+ return -1;
+ }
+
+ conn->header = hpairnode_new(key, value, conn->header);
+
+ return 0;
+}
+void
+httpc_add_headers(httpc_conn_t *conn, const hpair_t *values)
+{
+ if (conn == NULL)
+ {
+ log_warn1("Connection object is NULL");
+ return;
+ }
+
+ for(;values; values=values->next)
+ httpc_add_header(conn, values->key, values->value);
+
+ return;
+}
+
/*--------------------------------------------------
FUNCTION: httpc_set_header
DESC: Adds a new (key, value) pair to the header
@@ -153,7 +181,7 @@ or modifies the old pair if this function will
finds another pair with the same 'key' value.
----------------------------------------------------*/
int
-httpc_set_header(httpc_conn_t * conn, const char *key, const char *value)
+httpc_set_header(httpc_conn_t *conn, const char *key, const char *value)
{
hpair_t *p;
@@ -182,12 +210,11 @@ httpc_set_header(httpc_conn_t * conn, const char *key, const char *value)
return 0;
}
-
/*--------------------------------------------------
FUNCTION: httpc_header_add_date
DESC: Adds the current date to the header.
----------------------------------------------------*/
-static void
+/* static void
_httpc_set_error(httpc_conn_t * conn, int errcode, const char *format, ...)
{
va_list ap;
@@ -197,7 +224,7 @@ _httpc_set_error(httpc_conn_t * conn, int errcode, const char *format, ...)
va_start(ap, format);
vsprintf(conn->errmsg, format, ap);
va_end(ap);
-}
+} */
/*--------------------------------------------------
FUNCTION: httpc_header_add_date
diff --git a/nanohttp/nanohttp-client.h b/nanohttp/nanohttp-client.h
index 2b93617..03e1e16 100644
--- a/nanohttp/nanohttp-client.h
+++ b/nanohttp/nanohttp-client.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-client.h,v 1.18 2006/01/10 11:29:05 snowdrop Exp $
+ * $Id: nanohttp-client.h,v 1.19 2006/02/08 11:13:14 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -88,11 +88,13 @@ void httpc_close_free(httpc_conn_t * conn);
*/
int httpc_set_header(httpc_conn_t * conn, const char *key, const char *value);
+int httpc_add_header(httpc_conn_t *conn, const char *key, const char *value);
+void httpc_add_headers(httpc_conn_t *conn, const hpair_t *values);
+
/**
Invoke a "GET" method request and receive the response
*/
-herror_t
-httpc_get(httpc_conn_t * conn, hresponse_t ** out, const char *urlstr);
+herror_t httpc_get(httpc_conn_t * conn, hresponse_t ** out, const char *urlstr);
/**
Start a "POST" method request
diff --git a/nanohttp/nanohttp-common.c b/nanohttp/nanohttp-common.c
index 062c66c..adead8c 100644
--- a/nanohttp/nanohttp-common.c
+++ b/nanohttp/nanohttp-common.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-common.c,v 1.24 2006/01/18 16:28:24 mrcsys Exp $
+* $Id: nanohttp-common.c,v 1.25 2006/02/08 11:13:14 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -31,6 +31,8 @@
#include <string.h>
#include <ctype.h>
+#include <pthread.h>
+
#ifdef MEM_DEBUG
#include <utils/alloc.h>
#endif
@@ -283,7 +285,7 @@ log_write(log_level_t level, const char *prefix,
#ifdef WIN32
sprintf(buffer, "*%s*: [%s] %s\n", prefix, func, format);
#else
- sprintf(buffer, "*%s*:(%d) [%s] %s\n",
+ sprintf(buffer, "*%s*:(%ld) [%s] %s\n",
prefix, pthread_self(), func, format);
#endif
vsprintf(buffer2, buffer, ap);
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
diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h
index 383b7be..ccafe8f 100644
--- a/nanohttp/nanohttp-server.h
+++ b/nanohttp/nanohttp-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-server.h,v 1.11 2006/01/10 11:29:05 snowdrop Exp $
+ * $Id: nanohttp-server.h,v 1.12 2006/02/08 11:13:14 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -67,6 +67,8 @@ int httpd_register(const char *ctx, httpd_service service);
herror_t httpd_run();
void httpd_destroy();
+int httpd_get_port(void);
+
hservice_t *httpd_services();
herror_t httpd_send_header(httpd_conn_t * res, int code, const char *text);
@@ -74,6 +76,9 @@ herror_t httpd_send_header(httpd_conn_t * res, int code, const char *text);
int httpd_set_header(httpd_conn_t * conn, const char *key, const char *value);
void httpd_set_headers(httpd_conn_t * conn, hpair_t * header);
+int httpd_add_header(httpd_conn_t * conn, const char *key, const char *value);
+void httpd_add_headers(httpd_conn_t * conn, const hpair_t *values);
+
/*
unsigned char *httpd_get_postdata(httpd_conn_t *conn,
hrequest_t *req, long *received, long max);
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index 0c2c5ae..f880b74 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.46 2006/02/04 01:25:13 snowdrop Exp $
+* $Id: nanohttp-socket.c,v 1.47 2006/02/08 11:13:14 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -631,7 +631,7 @@ hsocket_read(hsocket_t sock, byte_t * buffer, int total, int force,
if (SSL_get_shutdown(sock.ssl) == SSL_RECEIVED_SHUTDOWN ||
SSL_get_error(sock.ssl, status) == SSL_ERROR_SYSCALL)
{
- *received = NULL;;
+ *received = 0;
return herror_new("hsocket_read", HSOCKET_ERROR_SSLCLOSE, "SSL Closed");
}
log_error2("Read error (%d)", status);
diff --git a/nanohttp/nanohttp-ssl.c b/nanohttp/nanohttp-ssl.c
index e1139ac..b0f3aa2 100644
--- a/nanohttp/nanohttp-ssl.c
+++ b/nanohttp/nanohttp-ssl.c
@@ -129,20 +129,18 @@ verify_sn (X509 * cert, int who, int nid, char *str)
static int
verify_cb (int prev_ok, X509_STORE_CTX * ctx)
{
- X509 *cert = X509_STORE_CTX_get_current_cert (ctx);
- int depth = X509_STORE_CTX_get_error_depth (ctx);
- int err = X509_STORE_CTX_get_error (ctx);
/*
- if( err = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ){
+ if ((X509_STORE_CTX_get_error(ctx) = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN))
+ {
log_verbose1("Self signed cert in chain");
return 1;
}
*/
#ifdef NOUSER_VERIFY /* ifdef's added by Ferhat. because of
unresolved reference while compiling */
- if (depth == 0)
+ if (X509_STORE_CTX_get_error_depth(ctx) == 0)
{
- return user_verify (cert);
+ return user_verify (X509_STORE_CTX_get_current_cert(ctx));
}
else
{
@@ -207,7 +205,7 @@ initialize_ctx (const char *keyfile, const char *password, const char *calist)
log_verbose1 ("Certificate file read ok");
- pass = password;
+ pass = strdup(password);
SSL_CTX_set_default_passwd_cb (ctx, pw_cb);
if (!(SSL_CTX_use_PrivateKey_file (ctx, keyfile, SSL_FILETYPE_PEM)))
@@ -299,7 +297,7 @@ log_ssl_error (SSL * ssl, int ret)
break;
case SSL_ERROR_SSL:
strcat (errorbuf, "SSL library");
- while (errqueue = ERR_get_error ())
+ while ((errqueue = ERR_get_error()))
{
log_error2 ("SSL %s", ERR_error_string (errqueue, NULL));
}
@@ -313,7 +311,6 @@ SSL *
init_ssl (SSL_CTX * ctx, int sock, int type)
{
int ret;
- int status;
SSL *ssl;
#if 0
#ifdef WIN32