summaryrefslogtreecommitdiffstats
path: root/nanohttp
diff options
context:
space:
mode:
Diffstat (limited to 'nanohttp')
-rw-r--r--nanohttp/nanohttp-client.c25
-rw-r--r--nanohttp/nanohttp-client.h8
-rw-r--r--nanohttp/nanohttp-socket.c106
3 files changed, 30 insertions, 109 deletions
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c
index de843ab..b55517a 100644
--- a/nanohttp/nanohttp-client.c
+++ b/nanohttp/nanohttp-client.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-client.c,v 1.9 2004/01/06 08:05:43 snowdrop Exp $
+ * $Id: nanohttp-client.c,v 1.10 2004/01/13 12:31:57 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -461,8 +461,10 @@ int httpc_receive_response(httpc_conn_t *conn,
int status;
/* receive header */
+ log_verbose1("receiving header");
res = httpc_receive_header(conn->sock);
if (res == NULL) return 1;
+ log_verbose1("header ok");
/* Invoke callback */
start_cb(conn, userdata, res->header, res->spec,
@@ -850,9 +852,9 @@ int httpc_post_finish_cb(httpc_conn_t *conn,
{
int status;
- status = hsocket_send(conn->sock, "0\r\n");
+ status = hsocket_send(conn->sock, "0\r\n\r\n");
if (status != HSOCKET_OK) return status;
-
+
status = httpc_receive_response(conn, start_cb, cb, userdata);
return status;
}
@@ -861,3 +863,20 @@ int httpc_post_finish_cb(httpc_conn_t *conn,
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nanohttp/nanohttp-client.h b/nanohttp/nanohttp-client.h
index 19ae110..fcb84ea 100644
--- a/nanohttp/nanohttp-client.h
+++ b/nanohttp/nanohttp-client.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-client.h,v 1.4 2004/01/05 10:42:15 snowdrop Exp $
+ * $Id: nanohttp-client.h,v 1.5 2004/01/13 12:31:57 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -75,13 +75,17 @@ int httpc_post_cb(httpc_conn_t *conn, const char *url,
/*
Chunked POST Module
*/
+
+/* Returns 0 if success, >0 otherwise */
+/* do not use this
int httpc_post_open(httpc_conn_t *conn, const char *url);
+
int httpc_post_send(httpc_conn_t *conn, const char* buffer, int bufsize);
hresponse_t *httpc_post_finish(httpc_conn_t *conn);
int httpc_post_finish_cb(httpc_conn_t *conn,
httpc_response_start_callback start_cb,
httpc_response_callback cb, void *userdata);
-
+*/
#endif
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index 18edcb9..b5ada49 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-socket.c,v 1.5 2004/01/05 10:42:15 snowdrop Exp $
+ * $Id: nanohttp-socket.c,v 1.6 2004/01/13 12:31:57 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -150,7 +150,6 @@ int hsocket_nsend(hsocket_t sock, const char* buffer, int n)
int hsocket_send(hsocket_t sock, const char* buffer)
{
int size;
-
size = send((int)sock, buffer, strlen(buffer), 0);
if (size == -1)
return HSOCKET_CAN_NOT_SEND;
@@ -159,98 +158,6 @@ int hsocket_send(hsocket_t sock, const char* buffer)
}
-/*--------------------------------------------------
- FUNCTION: hsocket_recv_limit (DON'T USE!)
-----------------------------------------------------*/
-int hsocket_recv_limit(hsocket_t sock, char** buffer,
- const char* delim, char **rest,
- int *totalBuffer, int *totalRest)
-{
- ssize_t size;
- int chunk=1;
- char tmp[HSOCKET_MAX_BUFSIZE+1];
- int delimlen;
- int fsize;
- int i;
-
- *totalBuffer = 0;
- *totalRest = 0;
- delimlen = strlen(delim);
-
- /* calculate first size for realloc */
- if (*buffer) {
- fsize = strlen(*buffer);
- } else {
- fsize = 0;
- }
-
- do {
-
- log_debug1("recv()");
- size = recv(sock, tmp, HSOCKET_MAX_BUFSIZE, 0);
-
- if (size == -1) {
- log_error1("Error reading from socket\n");
- return HSOCKET_CAN_NOT_RECEIVE;
- }
-
- if (size == 0) {
- break;
- }
-
- puts(tmp);
- /* section 1: find delimiter if exist */
- for (i=0;i<size-delimlen;i++) {
- if (!strncmp(&tmp[i],delim,delimlen)) {
-
- log_debug1("Found delimiter");
- /* ** split to buffer and rest ** */
-
- /* fill buffer until i */
- *totalBuffer += i;
- if (*buffer) {
- *buffer = (char*)realloc(*buffer, *totalBuffer+fsize+1+HSOCKET_MAX_BUFSIZE);
- strncat(*buffer, tmp, i);
- *buffer[*totalBuffer+fsize] = '\0';
- } else {
- *buffer = (char*)realloc(NULL, *totalBuffer+1);
- strncpy(*buffer, tmp, i);
- (*buffer)[*totalBuffer] = '\0';
- }
-
-
- /* fill rest from i to size */
- if (size - (i+delimlen)+1 > 0) {
- *rest = (char*)realloc(NULL, size - (i+delimlen)+1 + HSOCKET_MAX_BUFSIZE);
- strcpy(*rest, &tmp[i+delimlen]);
- *totalRest = size - (i+delimlen);
- (*rest)[*totalRest] = '\0';
- } else {
- *rest = NULL;
- }
-
- return HSOCKET_OK;
- }
- }
-
- /* section 2: no delimiter found. so add tmp to buffer */
- *totalBuffer += size;
- if (*buffer) {
- *buffer = (char*)realloc(*buffer, *totalBuffer+fsize+1);
- strcat(*buffer, tmp);
- } else {
- *buffer = (char*)realloc(NULL, *totalBuffer+1);
- strcpy(*buffer, tmp);
- }
-
- (*buffer)[*totalBuffer] = '\0';
-
- chunk++;
- } while (size > 0);
-
- return HSOCKET_OK;
-}
-
int hsocket_read(hsocket_t sock, char* buffer, int total, int force)
{
int status;
@@ -394,16 +301,7 @@ int hbufsocket_read(hbufsocket_t *bufsock, char *buffer, int size)
size -= tmpsize;
free(bufsock->buffer);
- /*
- status = recv(bufsock->sock, bufsock->buffer, size, 0);
- if (status > 0) {
- bufsock->bufsize = size;
- bufsock->cur = size;
- strncpy(&buffer[tmpsize], bufsock->buffer, size);
- } else {
- return status;
- }
- */
+
status = hsocket_read(bufsock->sock, &buffer[tmpsize], size, 1);
if (status == size) {
bufsock->buffer = (char*)malloc(size+1);