summaryrefslogtreecommitdiffstats
path: root/nanohttp
diff options
context:
space:
mode:
authorGravatar snowdrop2004-02-03 08:59:22 +0000
committerGravatar snowdrop2004-02-03 08:59:22 +0000
commit889a90340eec29e63cb7b8b8095442d5858ad7ce (patch)
tree041a9fd7635c6da7827e4c55c1fece2ed03b6281 /nanohttp
parentb3ecb22603e9187725810d1e1616fec01c5c063b (diff)
downloadcsoap-889a90340eec29e63cb7b8b8095442d5858ad7ce.tar.gz
csoap-889a90340eec29e63cb7b8b8095442d5858ad7ce.tar.bz2
develop
Diffstat (limited to 'nanohttp')
-rw-r--r--nanohttp/nanohttp-common.c23
-rw-r--r--nanohttp/nanohttp-server.c39
-rw-r--r--nanohttp/nanohttp-socket.c23
3 files changed, 52 insertions, 33 deletions
diff --git a/nanohttp/nanohttp-common.c b/nanohttp/nanohttp-common.c
index 55a9f7f..1d00d42 100644
--- a/nanohttp/nanohttp-common.c
+++ b/nanohttp/nanohttp-common.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-common.c,v 1.7 2004/01/21 12:28:20 snowdrop Exp $
+ * $Id: nanohttp-common.c,v 1.8 2004/02/03 08:59:23 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -255,6 +255,17 @@ void hpairnode_free(hpair_t *pair)
}
+void hpairnode_free_deep(hpair_t *pair)
+{
+ hpair_t *tmp;
+
+ while (pair != NULL) {
+ tmp = pair->next;
+ hpairnode_free(pair);
+ pair=tmp;
+ }
+}
+
char *hpairnode_get_ignore_case(hpair_t *pair, const char* key)
{
if (key == NULL) {
@@ -565,7 +576,15 @@ hrequest_t *hrequest_new_from_buffer(char *data)
void hrequest_free(hrequest_t *req)
{
- log_warn1("hrequest_free() not implemented!");
+ if (req == NULL) return;
+
+ free(req->method);
+ free(req->path);
+ free(req->spec);
+
+ hpairnode_free_deep(req->header);
+ hpairnode_free_deep(req->query);
+
}
/* response stuff */
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index b3bd1dc..d3a96e3 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-server.c,v 1.3 2004/01/30 16:37:50 snowdrop Exp $
+ * $Id: nanohttp-server.c,v 1.4 2004/02/03 08:59:23 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -57,7 +57,7 @@ int httpd_init(int argc, char *argv[])
/* write argument information */
log_verbose1("Arguments:");
for (i=0;i<argc;i++)
- log_verbose3("argv[%i] = '%s'\n", i, SAVE_STR(argv[i]));
+ log_verbose3("argv[%i] = '%s'", i, SAVE_STR(argv[i]));
/* initialize from arguments */
for (i=0;i<argc;i++) {
@@ -66,7 +66,7 @@ int httpd_init(int argc, char *argv[])
}
}
- log_debug2("socket bind to port '%d'\n", _httpd_port);
+ log_verbose2("socket bind to port '%d'", _httpd_port);
/* init built-in services */
/*
@@ -87,7 +87,7 @@ int httpd_init(int argc, char *argv[])
int httpd_register(const char* ctx, httpd_service func)
{
hservice_t* service;
- log_debug3("register service:t(%p):%s", service, SAVE_STR(ctx));
+ log_verbose3("register service:t(%p):%s", service, SAVE_STR(ctx));
service = (hservice_t*)malloc(sizeof(hservice_t));
service->next = NULL;
@@ -167,12 +167,14 @@ int httpd_send_header(httpd_conn_t *res,
strcat(header, "\r\n");
/* set content-type */
+ /*
if (res->content_type[0] == '\0') {
strcat(header, "Content-Type: text/html\r\n");
} else {
sprintf(buffer, "Content-Type: %s\r\n", res->content_type);
strcat(header, buffer);
}
+ */
/* set server name */
strcat(header, "Server: Nano HTTPD library\r\n");
@@ -216,18 +218,18 @@ static void httpd_request_print(hrequest_t *req)
{
hpair_t *pair;
- printf("++++++ Request +++++++++\n");
- printf(" Method : '%s'\n", req->method);
- printf(" Path : '%s'\n", req->path);
- printf(" Spec : '%s'\n", req->spec);
- printf(" Parsed query string :\n");
+ log_verbose1("++++++ Request +++++++++");
+ log_verbose2(" Method : '%s'", req->method);
+ log_verbose2(" Path : '%s'", req->path);
+ log_verbose2(" Spec : '%s'", req->spec);
+ log_verbose1(" Parsed query string :");
pair = req->query;
while (pair != NULL) {
- printf(" %s = '%s'\n", pair->key, pair->value);
+ log_verbose3(" %s = '%s'", pair->key, pair->value);
pair = pair->next;
}
- printf("++++++++++++++++++++++++\n");
+ log_verbose1("++++++++++++++++++++++++");
}
@@ -255,7 +257,7 @@ static void* httpd_session_main(void *data)
len = 0;
- log_debug1("starting httpd_session_main()\n");
+ log_verbose1("starting httpd_session_main()");
while (len < 4064) {
/*printf("receiving ...\n");*/
@@ -271,7 +273,7 @@ static void* httpd_session_main(void *data)
}
}
- printf("=== HEADER ===\n%s\n============\n", header);
+ /* log_verbose2("=== HEADER ===\n%s\n============\n", header);*/
/* call the service */
req = hrequest_new_from_buffer(header);
httpd_request_print(req);
@@ -283,7 +285,7 @@ static void* httpd_session_main(void *data)
service = httpd_find_service(req->path);
if (service != NULL) {
- log_verbose2("service '%s' found\n", req->path);
+ log_verbose2("service '%s' found", req->path);
if (service->func != NULL) {
service->func(rconn, req);
} else {
@@ -321,7 +323,7 @@ int httpd_run()
fd_set fds;
/*struct timeval timeout;*/
- log_debug1("starting run routine\n");
+ log_verbose1("starting run routine");
/*
timeout.tv_sec = 1;
timeout.tv_usec = 0;
@@ -329,12 +331,12 @@ int httpd_run()
/* listen to port */
err = hsocket_listen(_httpd_socket,15);
if (err != HSOCKET_OK) {
- log_error2("httpd_run(): '%d'\n", err);
+ log_error2("httpd_run(): '%d'", err);
return err;
}
- log_debug2("listening to port '%d'\n", _httpd_port);
+ log_verbose2("listening to port '%d'", _httpd_port);
/* fcntl(_httpd_socket, F_SETFL, O_NONBLOCK);*/
@@ -361,7 +363,7 @@ int httpd_run()
err = pthread_create(&tid, NULL, httpd_session_main, conn);
if (err) {
- printf("Error creating thread: ('%d')\n", err);
+ log_error2("Error creating thread: ('%d')", err);
}
}
@@ -411,6 +413,7 @@ char *httpd_get_postdata(httpd_conn_t *conn, hrequest_t *req, long *received, lo
if (hsocket_read(conn->sock, postdata,
(int)content_length, 1) == HSOCKET_OK) {
*received = content_length;
+ postdata[content_length] = '\0';
return postdata;
}
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index e828992..a555a7f 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-socket.c,v 1.7 2004/01/21 12:28:20 snowdrop Exp $
+ * $Id: nanohttp-socket.c,v 1.8 2004/02/03 08:59:23 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -132,7 +132,7 @@ int hsocket_bind(hsocket_t *dsock, int port)
/* create socket */
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1) {
- log_error2("Can not create socket: '%s'\n", strerror(errno));
+ log_error2("Can not create socket: '%s'", strerror(errno));
return HSOCKET_CAN_NOT_CREATE;
}
@@ -144,7 +144,7 @@ int hsocket_bind(hsocket_t *dsock, int port)
if (bind(sock, (struct sockaddr *)&addr,
sizeof(struct sockaddr)) == -1) {
- log_error2("Can not bind: '%s'\n", strerror(errno));
+ log_error2("Can not bind: '%s'", strerror(errno));
return HSOCKET_CAN_NOT_BIND;
}
@@ -158,7 +158,7 @@ int hsocket_bind(hsocket_t *dsock, int port)
int hsocket_listen(hsocket_t sock, int n)
{
if (listen(sock, n) == -1) {
- log_error2("Can not listen: '%s'\n", strerror(errno));
+ log_error2("Can not listen: '%s'", strerror(errno));
return HSOCKET_CAN_NOT_LISTEN;
}
return HSOCKET_OK;
@@ -182,7 +182,7 @@ int hsocket_accept(hsocket_t sock, hsocket_t *dest)
return HSOCKET_CAN_NOT_ACCEPT;
}
- log_debug3("accept new socket (%d) from '%s'\n", sockfd,
+ log_verbose3("accept new socket (%d) from '%s'", sockfd,
SAVE_STR(((char*)inet_ntoa(addr.sin_addr))) );
*dest = sockfd;
@@ -279,7 +279,7 @@ int hsocket_recv(hsocket_t sock, char** buffer, int *totalSize)
bufSize = HSOCKET_MAX_BUFSIZE;
if (size == -1) {
- log_error1("Error reading from socket\n");
+ log_error1("Error reading from socket");
return HSOCKET_CAN_NOT_RECEIVE;
}
@@ -289,22 +289,19 @@ int hsocket_recv(hsocket_t sock, char** buffer, int *totalSize)
*totalSize += size;
if (*buffer) {
- log_debug2("reallocation %d bytes",*totalSize+fsize+1);
+ log_verbose2("reallocation %d bytes",*totalSize+fsize+1);
*buffer = (char*)realloc((char*)*buffer,
(*totalSize)+fsize+HSOCKET_MAX_BUFSIZE);
strcat(*buffer, tmp);
} else {
- log_debug1("Allocating");
*buffer = (char*)realloc(NULL, *totalSize+1);
strcpy(*buffer, tmp);
}
- log_debug1("Assigning");
(*buffer)[*totalSize+fsize] = '\0';
chunk++;
} while (size > 0);
- log_debug1("Returning");
return HSOCKET_OK;
}
@@ -324,7 +321,7 @@ int hsocket_recv_cb(hsocket_t sock,
size = recv(sock, tmp, HSOCKET_MAX_BUFSIZE, 0);
if (size == -1) {
- log_error1("Error reading from socket\n");
+ log_error1("Error reading from socket");
return HSOCKET_CAN_NOT_RECEIVE;
}
@@ -354,7 +351,7 @@ int hbufsocket_read(hbufsocket_t *bufsock, char *buffer, int size)
if (bufsock->bufsize - bufsock->cur >= size) {
- log_debug1("no need to read from socket");
+ log_verbose1("no need to read from socket");
strncpy(buffer, &(bufsock->buffer[bufsock->cur]), size);
bufsock->cur += size;
return HSOCKET_OK;
@@ -362,7 +359,7 @@ int hbufsocket_read(hbufsocket_t *bufsock, char *buffer, int size)
} else {
tmpsize = bufsock->bufsize - bufsock->cur;
- log_debug2("tmpsize = %d", tmpsize);
+ log_verbose2("tmpsize = %d", tmpsize);
if (tmpsize > 0)
strncpy(buffer, &(bufsock->buffer[bufsock->cur]), tmpsize);