summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar m0gg2006-12-01 10:55:59 +0000
committerGravatar m0gg2006-12-01 10:55:59 +0000
commit1e0e97fe7b654ecd7f5315d129df6e57f3e63371 (patch)
treedce178f3f876c04f4e5b1385f388c81fc1b6994c
parent77ce98ff186515cce217814886d9d5b899380c7b (diff)
downloadcsoap-1e0e97fe7b654ecd7f5315d129df6e57f3e63371.tar.gz
csoap-1e0e97fe7b654ecd7f5315d129df6e57f3e63371.tar.bz2
Fix nanoHTTP HTTPS client (still needs port in URL)
-rw-r--r--doc/Doxyfile.source4
-rw-r--r--examples/nanohttp/http_client.c14
-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
10 files changed, 130 insertions, 46 deletions
diff --git a/doc/Doxyfile.source b/doc/Doxyfile.source
index 70b8d10..36bf658 100644
--- a/doc/Doxyfile.source
+++ b/doc/Doxyfile.source
@@ -1005,7 +1005,7 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
-PREDEFINED =
+PREDEFINED = __CSOAP_INTERNAL=1 __NHTTP_INTERNAL=1
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.
@@ -1141,7 +1141,7 @@ INCLUDED_BY_GRAPH = YES
# So in most cases it will be better to enable call graphs for selected
# functions only using the \callgraph command.
-CALL_GRAPH = NO
+CALL_GRAPH = YES
# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
# will graphical hierarchy of all classes instead of a textual one.
diff --git a/examples/nanohttp/http_client.c b/examples/nanohttp/http_client.c
index 7c1b2f0..7deeb03 100644
--- a/examples/nanohttp/http_client.c
+++ b/examples/nanohttp/http_client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: http_client.c,v 1.7 2006/11/30 14:23:59 m0gg Exp $
+* $Id: http_client.c,v 1.8 2006/12/01 10:56:00 m0gg Exp $
*
* CSOAP Project: A http client/server library in C (example)
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -43,7 +43,7 @@ static void show_response(hresponse_t *res)
if (!res)
{
- fprintf(stderr, "hresponse_t is NULL!");
+ fprintf(stderr, "hresponse_t is NULL!\n");
return;
}
@@ -60,7 +60,7 @@ static void show_response(hresponse_t *res)
if (!res->in)
{
- fprintf(stderr, "No input stream!");
+ fprintf(stderr, "No input stream!\n");
return;
}
@@ -109,25 +109,27 @@ int main(int argc, char **argv)
/* Initialize httpc module */
if (httpc_init(argc, argv))
{
- fprintf(stderr, "Cannot inititialize httpc");
+ fprintf(stderr, "Cannot inititialize HTTP client\n");
exit(1);
}
/* Create the client connection object */
if (!(conn = httpc_new()))
{
- fprintf(stderr, "httpc_new failed");
+ fprintf(stderr, "httpc_new failed\n");
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));
+ fprintf(stderr, "httpc_get failed (%s)\n", herror_message(status));
herror_release(status);
exit(1);
}
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;