summaryrefslogtreecommitdiffstats
path: root/nanohttp
diff options
context:
space:
mode:
Diffstat (limited to 'nanohttp')
-rw-r--r--nanohttp/nanohttp-admin.h32
-rwxr-xr-xnanohttp/nanohttp-request.c6
-rwxr-xr-xnanohttp/nanohttp-response.c4
-rw-r--r--nanohttp/nanohttp-socket.c12
-rw-r--r--nanohttp/nanohttp-socket.h26
-rw-r--r--nanohttp/nanohttp-ssl.c15
-rw-r--r--nanohttp/nanohttp-ssl.h49
-rwxr-xr-xnanohttp/nanohttp-stream.c14
8 files changed, 120 insertions, 38 deletions
diff --git a/nanohttp/nanohttp-admin.h b/nanohttp/nanohttp-admin.h
index 80e4c8e..64550e9 100644
--- a/nanohttp/nanohttp-admin.h
+++ b/nanohttp/nanohttp-admin.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-admin.h,v 1.2 2006/11/24 17:28:07 m0gg Exp $
+ * $Id: nanohttp-admin.h,v 1.3 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -26,7 +26,10 @@
/**
*
- * Commandline argument to enabled the nanoHTTP admin interface.
+ * Commandline argument to enabled the nanoHTTP admin interface. This service
+ * will be reachable via the NHTTPD_ADMIN_CONTEXT.
+ *
+ * @see NHTTPD_ADMIN_CONTEXT
*
*/
#define NHTTPD_ARG_ENABLE_ADMIN "-NHTTPDadmin"
@@ -35,10 +38,35 @@
*
* Context of the nanoHTTP admin interface.
*
+ * Example query:
+ *
+ * http://localhost:10000/nhttp
+ *
+ * @see httpd_register
+ *
*/
#define NHTTPD_ADMIN_CONTEXT "/nhttp"
+/**
+ *
+ * Query parameter for services.
+ *
+ * Example query:
+ *
+ * http://localhost:10000/nhttp?services=list
+ *
+ */
#define NHTTPD_ADMIN_QUERY_SERVICES "services"
+
+/**
+ *
+ * Parameter to query service statistics.
+ *
+ * Example query:
+ *
+ * http://localhost:10000/nhttp?statistics=SERVICE_CONTEXT
+ *
+ */
#define NHTTPD_ADMIN_QUERY_STATISTICS "statistics"
#ifdef __cplusplus
diff --git a/nanohttp/nanohttp-request.c b/nanohttp/nanohttp-request.c
index 4572e2c..f7bd307 100755
--- a/nanohttp/nanohttp-request.c
+++ b/nanohttp/nanohttp-request.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-request.c,v 1.19 2006/11/25 15:06:58 m0gg Exp $
+* $Id: nanohttp-request.c,v 1.20 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -282,9 +282,9 @@ hrequest_new_from_socket(struct hsocket_t *sock, struct hrequest_t ** out)
/* Read header */
for(i=0; i < MAX_HEADER_SIZE; i++)
{
- if ((status = hsocket_read(sock, &(buffer[i]), 1, 1, &readed)) != H_OK)
+ if ((status = hsocket_recv(sock, &(buffer[i]), 1, 1, &readed)) != H_OK)
{
- log_error2("hsocket_read failed (%s)", herror_message(status));
+ log_error2("hsocket_recv failed (%s)", herror_message(status));
return status;
}
diff --git a/nanohttp/nanohttp-response.c b/nanohttp/nanohttp-response.c
index c239eb4..707b07b 100755
--- a/nanohttp/nanohttp-response.c
+++ b/nanohttp/nanohttp-response.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-response.c,v 1.15 2006/11/25 15:06:58 m0gg Exp $
+* $Id: nanohttp-response.c,v 1.16 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -168,7 +168,7 @@ read_header: /* for errorcode: 100 (continue) */
/* Read header */
while (i < MAX_HEADER_SIZE)
{
- if ((status = hsocket_read(sock, &(buffer[i]), 1, 1, &count)) != H_OK)
+ if ((status = hsocket_recv(sock, &(buffer[i]), 1, 1, &count)) != H_OK)
{
log_error1("Socket read error");
return status;
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index 845bfbe..4980b0c 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.67 2006/11/30 14:24:00 m0gg Exp $
+* $Id: nanohttp-socket.c,v 1.69 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -90,8 +90,8 @@ typedef int ssize_t;
#endif
#include "nanohttp-ssl.h"
#endif
-#include "nanohttp-request.h"
-#include "nanohttp-server.h"
+
+#define HSOCKET_FREE -1
static int _hsocket_timeout = 10;
@@ -446,13 +446,13 @@ hsocket_select_recv(int sock, char *buf, size_t len)
}
herror_t
-hsocket_read(struct hsocket_t * sock, unsigned char * buffer, int total, int force, int *received)
+hsocket_recv(struct hsocket_t * sock, unsigned char * buffer, int total, int force, int *received)
{
herror_t status;
size_t totalRead;
size_t count;
-/* log_verbose3("Entering hsocket_read(total=%d,force=%d)", total, force); */
+/* log_verbose3("Entering hsocket_recv(total=%d,force=%d)", total, force); */
totalRead = 0;
do
@@ -466,7 +466,7 @@ hsocket_read(struct hsocket_t * sock, unsigned char * buffer, int total, int for
}
#else
if ((count = hsocket_select_recv(sock->sock, buffer + totalRead, (size_t) total - totalRead)) == -1)
- return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "recv failed (%s)", strerror(errno));
+ return herror_new("hsocket_recv", HSOCKET_ERROR_RECEIVE, "recv failed (%s)", strerror(errno));
#endif
sock->bytes_received += count;
diff --git a/nanohttp/nanohttp-socket.h b/nanohttp/nanohttp-socket.h
index b71f38d..417693a 100644
--- a/nanohttp/nanohttp-socket.h
+++ b/nanohttp/nanohttp-socket.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-socket.h,v 1.34 2006/11/30 14:24:00 m0gg Exp $
+ * $Id: nanohttp-socket.h,v 1.35 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -24,8 +24,6 @@
#ifndef __nanohttp_socket_h
#define __nanohttp_socket_h
-#define HSOCKET_FREE -1
-
/**
*
* Socket definition
@@ -65,6 +63,8 @@ extern herror_t hsocket_module_init(int argc, char **argv);
* Destroys the socket modul. This should be called after finishing an
* application.
*
+ * @see hssl_module_destroy
+ *
*/
extern void hsocket_module_destroy(void);
@@ -77,7 +77,7 @@ extern void hsocket_module_destroy(void);
*
* @returns This function should always return H_OK.
*
- * @see hsocket_init_ssl
+ * @see hssl_module_init
*
*/
extern herror_t hsocket_init(struct hsocket_t * sock);
@@ -110,7 +110,7 @@ extern void hsocket_free(struct hsocket_t * sock);
extern herror_t hsocket_open(struct hsocket_t *sock, const char *host, int port, int ssl);
/**
- *
+ e
* Close a socket connection.
*
* @param sock the socket to close
@@ -118,7 +118,6 @@ extern herror_t hsocket_open(struct hsocket_t *sock, const char *host, int port,
*/
extern void hsocket_close(struct hsocket_t *sock);
-
/**
*
* Binds a socket to a given port number. After bind you can call
@@ -208,9 +207,22 @@ extern int hsocket_select_recv(int sock, char *buf, size_t len);
* the return value is the size of bytes readed from the socket.
*
*/
-extern herror_t hsocket_read(struct hsocket_t * sock, unsigned char *buffer, int size, int force, int *readed);
+extern herror_t hsocket_recv(struct hsocket_t * sock, unsigned char *buffer, int size, int force, int *len);
+/**
+ *
+ * Get the socket read/write timeout.
+ *
+ */
extern int hsocket_get_timeout(void);
+
+/**
+ *
+ * Set the socket read/write timeout.
+ *
+ * @param secs Timeout in seconds.
+ *
+ */
extern void hsocket_set_timeout(int secs);
#ifdef __cplusplus
diff --git a/nanohttp/nanohttp-ssl.c b/nanohttp/nanohttp-ssl.c
index a5f32e3..22aa3d1 100644
--- a/nanohttp/nanohttp-ssl.c
+++ b/nanohttp/nanohttp-ssl.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-ssl.c,v 1.34 2006/11/30 14:24:00 m0gg Exp $
+* $Id: nanohttp-ssl.c,v 1.35 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2001-2005 Rochester Institute of Technology
@@ -284,7 +284,7 @@ _hssl_parse_arguments(int argc, char **argv)
}
else if (!strcmp(argv[i - 1], NHTTPD_ARG_HTTPS))
{
- hssl_enabled();
+ hssl_enable();
}
}
@@ -437,12 +437,21 @@ hssl_enabled(void)
herror_t
hssl_client_ssl(struct hsocket_t * sock)
{
+ SSL_CTX *ctx;
SSL *ssl;
int ret;
log_verbose1("Starting SSL client initialization");
- if (!(ssl = SSL_new(_hssl_context)))
+ _hssl_library_init();
+
+ if (!(ctx = SSL_CTX_new(SSLv23_method())))
+ {
+ log_error2("SSL_CTX_new failed (ctx == %p)", ctx);
+ return herror_new("hssl_client_ssl", HSSL_ERROR_CONTEXT, "Cannot create SSL client context");
+ }
+
+ if (!(ssl = SSL_new(ctx)))
{
log_error1("Cannot create new SSL object");
return herror_new("hssl_client_ssl", HSSL_ERROR_CLIENT, "SSL_new failed");
diff --git a/nanohttp/nanohttp-ssl.h b/nanohttp/nanohttp-ssl.h
index 8902ea3..6dbcad4 100644
--- a/nanohttp/nanohttp-ssl.h
+++ b/nanohttp/nanohttp-ssl.h
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-ssl.h,v 1.23 2006/11/30 14:24:00 m0gg Exp $
+* $Id: nanohttp-ssl.h,v 1.24 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2001-2005 Rochester Institute of Technology
@@ -51,8 +51,27 @@ extern herror_t hssl_module_init(int argc, char **argv);
*/
extern void hssl_module_destroy(void);
+/**
+ *
+ * Sets the SSL certificate to be used.
+ *
+ */
extern void hssl_set_certificate(const char *filename);
+
+/**
+ *
+ * Sets the password for the SSL certificate.
+ *
+ * @see hssl_set_certificate
+ *
+ */
extern void hssl_set_certpass(const char *password);
+
+/**
+ *
+ * Sets the filename for a certification authority list.
+ *
+ */
extern void hssl_set_ca_list(const char *filename);
/**
@@ -99,25 +118,39 @@ extern herror_t hssl_server_ssl(struct hsocket_t * sock);
*/
extern void hssl_cleanup(struct hsocket_t * sock);
-/*
- * Quick function for verifying a portion of the cert
- * nid is any NID_ defined in <openssl/objects.h>
- * returns non-zero if everything went ok
- */
#define CERT_SUBJECT 1
+/**
+ *
+ * Quick function for verifying a portion of the cert nid is any NID_ defined
+ * in <openssl/objects.h> returns non-zero if everything went ok
+ *
+ */
extern int verify_sn(X509 * cert, int who, int nid, char *str);
/**
*
- * Called by framework for verification of client or server supplied
- * certificate.
+ * Called by framework for verification of client or server supplied certificate.
*
*/
extern void hssl_set_user_verify(int func(X509 * cert));
+/**
+ *
+ * Read from a SSL socket.
+ *
+ * @see hsocket_read
+ *
+ */
extern herror_t hssl_read(struct hsocket_t * sock, char *buf, size_t len, size_t * received);
+/**
+ *
+ * Write to a SSL socket.
+ *
+ * @see hsocket_write
+ *
+ */
extern herror_t hssl_write(struct hsocket_t * sock, const char *buf, size_t len, size_t * sent);
#ifdef __cplusplus
diff --git a/nanohttp/nanohttp-stream.c b/nanohttp/nanohttp-stream.c
index b121e57..8899c7e 100755
--- a/nanohttp/nanohttp-stream.c
+++ b/nanohttp/nanohttp-stream.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-stream.c,v 1.18 2006/11/30 14:24:00 m0gg Exp $
+* $Id: nanohttp-stream.c,v 1.19 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -207,7 +207,7 @@ _http_input_stream_content_length_read(struct http_input_stream_t * stream, unsi
size = stream->content_length - stream->received;
/* read from socket */
- if ((status = hsocket_read(stream->sock, dest, size, 1, &read)) != H_OK)
+ if ((status = hsocket_recv(stream->sock, dest, size, 1, &read)) != H_OK)
{
stream->err = status;
return -1;
@@ -227,7 +227,7 @@ _http_input_stream_chunked_read_chunk_size(struct http_input_stream_t * stream)
while (1)
{
- err = hsocket_read(stream->sock, &(chunk[i]), 1, 1, &status);
+ err = hsocket_recv(stream->sock, &(chunk[i]), 1, 1, &status);
if (status != 1)
{
stream->err = herror_new("_http_input_stream_chunked_read_chunk_size",
@@ -296,7 +296,7 @@ _http_input_stream_chunked_read(struct http_input_stream_t * stream, unsigned ch
counter = 100; /* maximum for stop infinity */
while (1)
{
- if ((err = hsocket_read(stream->sock, &ch, 1, 1, &status)) != H_OK)
+ if ((err = hsocket_recv(stream->sock, &ch, 1, 1, &status)) != H_OK)
{
stream->err = err;
return -1;
@@ -338,7 +338,7 @@ _http_input_stream_chunked_read(struct http_input_stream_t * stream, unsigned ch
if (remain < size)
{
/* read from socket */
- if ((err = hsocket_read(stream->sock, &(dest[read]), remain, 1, &status)) != H_OK)
+ if ((err = hsocket_recv(stream->sock, &(dest[read]), remain, 1, &status)) != H_OK)
{
stream->err = err;
return -1;
@@ -355,7 +355,7 @@ _http_input_stream_chunked_read(struct http_input_stream_t * stream, unsigned ch
else
{
/* read from socket */
- err = hsocket_read(stream->sock, &(dest[read]), size, 1, &status);
+ err = hsocket_recv(stream->sock, &(dest[read]), size, 1, &status);
if (status != size)
{
stream->err = herror_new("_http_input_stream_chunked_read",
@@ -387,7 +387,7 @@ _http_input_stream_connection_closed_read(struct http_input_stream_t * stream, u
herror_t err;
/* read from socket */
- if ((err = hsocket_read(stream->sock, dest, size, 0, &status)) != H_OK)
+ if ((err = hsocket_recv(stream->sock, dest, size, 0, &status)) != H_OK)
{
stream->err = err;
return -1;