summaryrefslogtreecommitdiffstats
path: root/nanohttp
diff options
context:
space:
mode:
authorGravatar mrcsys2006-01-06 15:16:03 +0000
committerGravatar mrcsys2006-01-06 15:16:03 +0000
commit8a1f6c136a94f322b06dec615df4b0f7cd73a671 (patch)
tree63af13c3f6e406b8aeacf10fcdcdffe64e16349f /nanohttp
parent73327fb2d2a2da4b25e91e34ca121cac6b03fe42 (diff)
downloadcsoap-8a1f6c136a94f322b06dec615df4b0f7cd73a671.tar.gz
csoap-8a1f6c136a94f322b06dec615df4b0f7cd73a671.tar.bz2
Updated to take the HAVE_SSL define and act accordingly
Diffstat (limited to 'nanohttp')
-rw-r--r--nanohttp/nanohttp-client.c4
-rw-r--r--nanohttp/nanohttp-server.c8
-rw-r--r--nanohttp/nanohttp-socket.c26
-rw-r--r--nanohttp/nanohttp-socket.h4
4 files changed, 37 insertions, 5 deletions
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c
index cd13af8..02d6c3c 100644
--- a/nanohttp/nanohttp-client.c
+++ b/nanohttp/nanohttp-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-client.c,v 1.30 2005/12/19 14:18:26 snowdrop Exp $
+* $Id: nanohttp-client.c,v 1.31 2006/01/06 15:16:03 mrcsys Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -319,6 +319,7 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
if (status != H_OK) {
return status;
}
+#ifdef HAVE_SSL
/* TODO XXX XXX this is probably not right -- matt */
if(!&conn->sock.ssl){
status = hsocket_block(conn->sock, conn->block);
@@ -327,6 +328,7 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
return status;
}
}
+#endif
/* check method */
if (method == HTTP_REQUEST_GET) {
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index 38c19cc..0ff7d08 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.36 2005/12/22 21:59:41 mrcsys Exp $
+* $Id: nanohttp-server.c,v 1.37 2006/01/06 15:16:03 mrcsys Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -101,7 +101,9 @@ static void WSAReaper(void *x);
sigset_t thrsigset;
#endif
+#ifdef HAVE_SSL
extern SSL_CTX* SSLctx;
+#endif
/*
@@ -445,6 +447,7 @@ httpd_session_main (void *data)
len = 0;
log_verbose1 ("starting httpd_session_main()");
+#ifdef HAVE_SSL
if( !SSLctx ){
log_verbose1("Using HTTP");
} else {
@@ -455,6 +458,7 @@ httpd_session_main (void *data)
return herror_new("hsocket_accept", SSL_ERROR_INIT, "Unable to initialize SSL");
}
}
+#endif
conn->atime = time ((time_t) 0);
/* call the service */
/* req = hrequest_new_from_buffer (header);*/
@@ -774,7 +778,9 @@ httpd_run ()
if (err != H_OK && herror_code(err) == SSL_ERROR_INIT) {
hsocket_close(conn->sock);
conn->sock.sock = -1;
+#ifdef HAVE_SSL
conn->sock.ssl = NULL;
+#endif
log_error1(herror_message(err));
continue;
} else if (err != H_OK)
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index 62bf287..5fc5523 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.39 2006/01/06 14:09:27 snowdrop Exp $
+* $Id: nanohttp-socket.c,v 1.40 2006/01/06 15:16:03 mrcsys Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -179,13 +179,17 @@ hsocket_open (hsocket_t * dsock, const char *hostname, int port)
if (connect (sock.sock, (struct sockaddr *) &address, sizeof (address)) != 0)
return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Socket error: %d", errno);
+#ifdef HAVE_SSL
if( !SSLctx ){
+#endif
log_verbose1("Using HTTP");
dsock->sock = sock.sock;
+#ifdef HAVE_SSL
} else {
log_verbose1("Using HTTPS");
dsock->ssl = init_ssl(SSLctx, sock.sock, SSL_CLIENT);
}
+#endif
return H_OK;
}
@@ -353,6 +357,7 @@ hsocket_close (hsocket_t sock)
#else
/* XXX m. campbell - It seems like the while loop here needs this */
fcntl( sock.sock, F_SETFL, O_NONBLOCK);
+#ifdef HAVE_SSL
if( sock.ssl ){
log_verbose1("Closing SSL");
ssl_cleanup(sock.ssl);
@@ -360,11 +365,14 @@ hsocket_close (hsocket_t sock)
while (recv(sock.sock, junk, sizeof(junk), 0)>0) { };
close (sock.sock);
}else {
+#endif
shutdown(sock.sock, SHUT_RDWR);
while (recv(sock.sock, junk, sizeof(junk), 0)>0) { };
close (sock.sock);
+#ifdef HAVE_SSL
}
#endif
+#endif
log_verbose1 ("socket closed");
}
@@ -389,7 +397,11 @@ hsocket_nsend (hsocket_t sock, const byte_t *bytes, int n)
int total=0;
log_verbose1( "Starting to send" );
+#ifdef HAVE_SSL
if (sock.sock <= 0 && !sock.ssl)
+#else
+ if (sock.sock <= 0)
+#endif
return herror_new("hsocket_nsend", HSOCKET_ERROR_NOT_INITIALIZED,
"Called hsocket_listen() before initializing!");
@@ -398,11 +410,15 @@ hsocket_nsend (hsocket_t sock, const byte_t *bytes, int n)
/* TODO (#1#): check return value and send again until n bytes sent */
while (1)
{
+#ifdef HAVE_SSL
if(sock.ssl){
size = SSL_write(sock.ssl, bytes + total, n);
} else {
+#endif
size = send((int) sock.sock, bytes + total, n, 0);
+#ifdef HAVE_SSL
}
+#endif
log_verbose2("Sent %d", size );
/* size = _test_send_to_file(filename, bytes, n);*/
#ifdef WIN32
@@ -413,10 +429,12 @@ hsocket_nsend (hsocket_t sock, const byte_t *bytes, int n)
return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
#else
if (size == -1){
+#ifdef HAVE_SSL
if(sock.ssl){
log_error1("Send error");
log_ssl_error(sock.ssl, size);
}
+#endif
return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
}
#endif
@@ -452,6 +470,7 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
log_verbose3("Entering hsocket_read(total=%d,force=%d)", total, force);
*/
do {
+#ifdef HAVE_SSL
if(sock.ssl){
struct timeval timeout;
int i=0;
@@ -496,6 +515,9 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
fcntl( sock.sock, F_SETFL, 0);
#endif
} else {
+#else // HAVE_SSL
+ {
+#endif //HAVE_SSL
status = recv(sock.sock, &buffer[totalRead], total - totalRead, 0);
#ifdef WIN32
@@ -525,6 +547,7 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
}
*/
+#ifdef HAVE_SSL
if( sock.ssl && status < 1 ){
// XXX I'm not sure this err_syscall is right here...
@@ -537,6 +560,7 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
log_ssl_error( sock.ssl, status );
return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "SSL Error");
}
+#endif
if (status == -1)
return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
#endif
diff --git a/nanohttp/nanohttp-socket.h b/nanohttp/nanohttp-socket.h
index 58443f3..7410690 100644
--- a/nanohttp/nanohttp-socket.h
+++ b/nanohttp/nanohttp-socket.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-socket.h,v 1.17 2006/01/06 14:09:27 snowdrop Exp $
+ * $Id: nanohttp-socket.h,v 1.18 2006/01/06 15:16:03 mrcsys Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -47,7 +47,7 @@
typedef int socklen_t;
#else
typedef struct hsocket_t {
-#ifdef HAVA_SSL
+#ifdef HAVE_SSL
SSL *ssl;
#endif
int sock;