summaryrefslogtreecommitdiffstats
path: root/nanohttp
diff options
context:
space:
mode:
Diffstat (limited to 'nanohttp')
-rw-r--r--nanohttp/nanohttp-client.c88
-rw-r--r--nanohttp/nanohttp-client.h320
-rw-r--r--nanohttp/nanohttp-common.c342
-rw-r--r--nanohttp/nanohttp-common.h136
-rwxr-xr-xnanohttp/nanohttp-mime.c70
-rwxr-xr-xnanohttp/nanohttp-mime.h6
-rwxr-xr-xnanohttp/nanohttp-request.c6
-rwxr-xr-xnanohttp/nanohttp-response.c32
-rw-r--r--nanohttp/nanohttp-server.c56
-rw-r--r--nanohttp/nanohttp-server.h4
-rw-r--r--nanohttp/nanohttp-socket.c116
-rw-r--r--nanohttp/nanohttp-socket.h432
-rwxr-xr-xnanohttp/nanohttp-stream.c88
-rwxr-xr-xnanohttp/nanohttp-stream.h10
14 files changed, 853 insertions, 853 deletions
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c
index 814f0b4..2f79bc0 100644
--- a/nanohttp/nanohttp-client.c
+++ b/nanohttp/nanohttp-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-client.c,v 1.25 2004/11/02 22:42:52 snowdrop Exp $
+* $Id: nanohttp-client.c,v 1.26 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -50,22 +50,22 @@ NOTE: This will be called from soap_client_init_args()
----------------------------------------------------*/
herror_t
httpc_init(int argc, char *argv[])
-{
- hoption_init_args(argc, argv);
- hsocket_module_init();
+{
+ hoption_init_args(argc, argv);
+ hsocket_module_init();
return H_OK;
}
-
-
-/*--------------------------------------------------
-FUNCTION: httpc_destroy
-DESC: Destroy the http client module
-----------------------------------------------------*/
-void httpc_destroy()
-{
- hsocket_module_destroy();
-}
-
+
+
+/*--------------------------------------------------
+FUNCTION: httpc_destroy
+DESC: Destroy the http client module
+----------------------------------------------------*/
+void httpc_destroy()
+{
+ hsocket_module_destroy();
+}
+
/*--------------------------------------------------
FUNCTION: httpc_new
@@ -85,7 +85,7 @@ httpc_new()
res->out = NULL;
res->_dime_package_nr = 0;
res->_dime_sent_bytes = 0;
- res->id = counter++;
+ res->id = counter++;
res->block = 0;
return res;
}
@@ -270,16 +270,16 @@ static
herror_t
httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
const char *urlstr)
-{
+{
hurl_t url;
char buffer[4096];
herror_t status;
if (conn == NULL) {
- return herror_new(
- "httpc_talk_to_server",
- GENERAL_INVALID_PARAM,
+ return herror_new(
+ "httpc_talk_to_server",
+ GENERAL_INVALID_PARAM,
"httpc_conn_t param is NULL");
}
/* Build request header */
@@ -323,17 +323,17 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
} else {
log_error1("Unknown method type!");
- return herror_new(
- "httpc_talk_to_server",
- GENERAL_INVALID_PARAM,
- "hreq_method_t must be HTTP_REQUEST_GET or HTTP_REQUEST_POST");
+ return herror_new(
+ "httpc_talk_to_server",
+ GENERAL_INVALID_PARAM,
+ "hreq_method_t must be HTTP_REQUEST_GET or HTTP_REQUEST_POST");
}
status = hsocket_send(conn->sock, buffer);
if (status != H_OK) {
log_error2("Can not send request (status:%d)", status);
hsocket_close(conn->sock);
- return status;
+ return status;
}
/* Send Header */
status = httpc_send_header(conn);
@@ -341,7 +341,7 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
log_error2("Can not send header (status:%d)", status);
hsocket_close(conn->sock);
return status;
- }
+ }
return H_OK;
@@ -368,7 +368,7 @@ httpc_get(httpc_conn_t *conn, hresponse_t** out, const char *urlstr)
{
return status;
}
-
+
return H_OK;
}
@@ -411,10 +411,10 @@ herror_t httpc_post_end(httpc_conn_t *conn, hresponse_t** out)
status = hresponse_new_from_socket(conn->sock, out);
if (status != H_OK)
- {
+ {
return status;
}
-
+
return H_OK;
}
@@ -423,7 +423,7 @@ herror_t httpc_post_end(httpc_conn_t *conn, hresponse_t** out)
/* ---------------------------------------------------
DIME support functions httpc_dime_* function set
-----------------------------------------------------*/
-/*
+/*
int httpc_dime_begin(httpc_conn_t *conn, const char *url)
{
int status;
@@ -595,12 +595,12 @@ herror_t httpc_mime_begin(httpc_conn_t *conn, const char *url,
*/
sprintf(buffer, "multipart/related;");
- /*
- using sprintf instead of snprintf because visual c does not support snprintf
- */
-#ifdef WIN32
-#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
-#endif
+ /*
+ using sprintf instead of snprintf because visual c does not support snprintf
+ */
+#ifdef WIN32
+#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
+#endif
if (related_type) {
snprintf(temp, 75, " type=\"%s\";", related_type);
@@ -691,7 +691,7 @@ herror_t httpc_mime_end(httpc_conn_t *conn, hresponse_t** out)
{
return status;
}
-
+
return H_OK;
}
@@ -713,7 +713,7 @@ httpc_mime_send_file (httpc_conn_t * conn,
size_t size;
if (fd == NULL)
- return herror_new("httpc_mime_send_file", FILE_ERROR_OPEN,
+ return herror_new("httpc_mime_send_file", FILE_ERROR_OPEN,
"Can not open file '%s'", filename);
status =
@@ -730,22 +730,22 @@ httpc_mime_send_file (httpc_conn_t * conn,
if (size == -1)
{
fclose (fd);
- return herror_new("httpc_mime_send_file", FILE_ERROR_READ,
+ return herror_new("httpc_mime_send_file", FILE_ERROR_READ,
"Can not read from file '%s'", filename);
}
-
- if (size>0)
- {
+
+ if (size>0)
+ {
/*DEBUG: fwrite(buffer, 1, size, stdout);*/
status = http_output_stream_write (conn->out, buffer, size);
if (status != H_OK) {
fclose (fd);
return status;
- }
+ }
}
}
- fclose (fd);
+ fclose (fd);
log_verbose1("file sent!");
return H_OK;
}
diff --git a/nanohttp/nanohttp-client.h b/nanohttp/nanohttp-client.h
index 3e3f9c6..06c0fcd 100644
--- a/nanohttp/nanohttp-client.h
+++ b/nanohttp/nanohttp-client.h
@@ -1,160 +1,160 @@
-/******************************************************************
- * $Id: nanohttp-client.h,v 1.13 2004/11/02 22:42:52 snowdrop Exp $
- *
- * CSOAP Project: A http client/server library in C
- * Copyright (C) 2003 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ferhatayaz@yahoo.com
- ******************************************************************/
-#ifndef NANO_HTTP_CLIENT_H
-#define NANO_HTTP_CLIENT_H
-
-
-#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-response.h>
-#include <nanohttp/nanohttp-stream.h>
-
-typedef struct httpc_conn
-{
- hsocket_t sock;
- hpair_t *header;
- hurl_t url;
- http_version_t version;
- /*
- -1 : last dime package
- 0 : no dime connection
- >0 : dime package number
- */
- int _dime_package_nr;
- long _dime_sent_bytes;
- int errcode;
- char errmsg[150];
- http_output_stream_t *out;
- int id; /* uniq id */
- int block;
-}httpc_conn_t;
-
-
-/* --------------------------------------------------------------
- HTTP CLIENT MODULE RELATED FUNCTIONS
- ---------------------------------------------------------------*/
-
-/**
- initialize the httpc_* module
-*/
-herror_t httpc_init(int argc, char *argv[]);
-
-/**
- Destroy the httpc_* module
-*/
-void httpc_destroy();
-
-/**
- Creates a new connection
-*/
-httpc_conn_t* httpc_new();
-
-/**
- Release a connections
-*/
-void httpc_free(httpc_conn_t* conn);
-
-/**
- Set header element (key,value) pair.
-*/
-int httpc_set_header(httpc_conn_t *conn, const char* key, const char* value);
-
-/**
- Invoke a "GET" method request and receive the response
-*/
-herror_t
-httpc_get(httpc_conn_t *conn, hresponse_t** out, const char *urlstr);
-
-/**
- Start a "POST" method request
- Returns: HSOCKET_OK or error flag
-*/
-herror_t httpc_post_begin(httpc_conn_t *conn, const char *url);
-
-/**
- End a "POST" method and receive the response.
- You MUST call httpc_post_end() before!
-*/
-herror_t httpc_post_end(httpc_conn_t *conn, hresponse_t **out);
-
-
-/* --------------------------------------------------------------
- DIME RELATED FUNCTIONS
- ---------------------------------------------------------------*/
-
-/*
- DIME support httpc_dime_* function set
-*/
-/*
-int httpc_dime_begin(httpc_conn_t *conn, const char *url);
-int httpc_dime_next(httpc_conn_t* conn, long content_length,
- const char *content_type, const char *id,
- const char *dime_options, int last);
-hresponse_t* httpc_dime_end(httpc_conn_t *conn);
-*/
-
-/* --------------------------------------------------------------
- MIME RELATED FUNCTIONS
- ---------------------------------------------------------------*/
-/*
- MIME support httpc_mime_* function set
-*/
-
-/**
- Begin MIME multipart/related POST request
- Returns: HSOCKET_OK or error flag
-*/
-herror_t httpc_mime_begin(httpc_conn_t *conn, const char *url,
- const char* related_start,
- const char* related_start_info,
- const char* related_type);
-
-/**
- Send boundary and part header and continue
- with next part
-*/
-herror_t httpc_mime_next(httpc_conn_t *conn,
- const char* content_id,
- const char* content_type,
- const char* transfer_encoding);
-
-/**
- Finish MIME request and get the response
-*/
-herror_t httpc_mime_end(httpc_conn_t *conn, hresponse_t** out);
-
-/**
- Send boundary and part header and continue
- with next part
-*/
-
-herror_t httpc_mime_send_file (httpc_conn_t * conn,
- const char *content_id,
- const char *content_type,
- const char *transfer_encoding,
- const char *filename);
-
-#endif
-
-
+/******************************************************************
+ * $Id: nanohttp-client.h,v 1.14 2004/11/02 23:09:26 snowdrop Exp $
+ *
+ * CSOAP Project: A http client/server library in C
+ * Copyright (C) 2003 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ferhatayaz@yahoo.com
+ ******************************************************************/
+#ifndef NANO_HTTP_CLIENT_H
+#define NANO_HTTP_CLIENT_H
+
+
+#include <nanohttp/nanohttp-common.h>
+#include <nanohttp/nanohttp-socket.h>
+#include <nanohttp/nanohttp-response.h>
+#include <nanohttp/nanohttp-stream.h>
+
+typedef struct httpc_conn
+{
+ hsocket_t sock;
+ hpair_t *header;
+ hurl_t url;
+ http_version_t version;
+ /*
+ -1 : last dime package
+ 0 : no dime connection
+ >0 : dime package number
+ */
+ int _dime_package_nr;
+ long _dime_sent_bytes;
+ int errcode;
+ char errmsg[150];
+ http_output_stream_t *out;
+ int id; /* uniq id */
+ int block;
+}httpc_conn_t;
+
+
+/* --------------------------------------------------------------
+ HTTP CLIENT MODULE RELATED FUNCTIONS
+ ---------------------------------------------------------------*/
+
+/**
+ initialize the httpc_* module
+*/
+herror_t httpc_init(int argc, char *argv[]);
+
+/**
+ Destroy the httpc_* module
+*/
+void httpc_destroy();
+
+/**
+ Creates a new connection
+*/
+httpc_conn_t* httpc_new();
+
+/**
+ Release a connections
+*/
+void httpc_free(httpc_conn_t* conn);
+
+/**
+ Set header element (key,value) pair.
+*/
+int httpc_set_header(httpc_conn_t *conn, const char* key, const char* value);
+
+/**
+ Invoke a "GET" method request and receive the response
+*/
+herror_t
+httpc_get(httpc_conn_t *conn, hresponse_t** out, const char *urlstr);
+
+/**
+ Start a "POST" method request
+ Returns: HSOCKET_OK or error flag
+*/
+herror_t httpc_post_begin(httpc_conn_t *conn, const char *url);
+
+/**
+ End a "POST" method and receive the response.
+ You MUST call httpc_post_end() before!
+*/
+herror_t httpc_post_end(httpc_conn_t *conn, hresponse_t **out);
+
+
+/* --------------------------------------------------------------
+ DIME RELATED FUNCTIONS
+ ---------------------------------------------------------------*/
+
+/*
+ DIME support httpc_dime_* function set
+*/
+/*
+int httpc_dime_begin(httpc_conn_t *conn, const char *url);
+int httpc_dime_next(httpc_conn_t* conn, long content_length,
+ const char *content_type, const char *id,
+ const char *dime_options, int last);
+hresponse_t* httpc_dime_end(httpc_conn_t *conn);
+*/
+
+/* --------------------------------------------------------------
+ MIME RELATED FUNCTIONS
+ ---------------------------------------------------------------*/
+/*
+ MIME support httpc_mime_* function set
+*/
+
+/**
+ Begin MIME multipart/related POST request
+ Returns: HSOCKET_OK or error flag
+*/
+herror_t httpc_mime_begin(httpc_conn_t *conn, const char *url,
+ const char* related_start,
+ const char* related_start_info,
+ const char* related_type);
+
+/**
+ Send boundary and part header and continue
+ with next part
+*/
+herror_t httpc_mime_next(httpc_conn_t *conn,
+ const char* content_id,
+ const char* content_type,
+ const char* transfer_encoding);
+
+/**
+ Finish MIME request and get the response
+*/
+herror_t httpc_mime_end(httpc_conn_t *conn, hresponse_t** out);
+
+/**
+ Send boundary and part header and continue
+ with next part
+*/
+
+herror_t httpc_mime_send_file (httpc_conn_t * conn,
+ const char *content_id,
+ const char *content_type,
+ const char *transfer_encoding,
+ const char *filename);
+
+#endif
+
+
diff --git a/nanohttp/nanohttp-common.c b/nanohttp/nanohttp-common.c
index 67301e3..a6d02e6 100644
--- a/nanohttp/nanohttp-common.c
+++ b/nanohttp/nanohttp-common.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-common.c,v 1.16 2004/10/29 09:27:05 snowdrop Exp $
+* $Id: nanohttp-common.c,v 1.17 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -33,129 +33,129 @@
#ifdef MEM_DEBUG
#include <utils/alloc.h>
#endif
-
-
-#define MAX_OPTION_SIZE 50
-#define MAX_OPTION_VALUE_SIZE 150
-
-static char _hoption_table[MAX_OPTION_SIZE][MAX_OPTION_VALUE_SIZE];
-
-/* option stuff */
-void hoption_set(int opt, const char* value)
-{
- if (opt >= MAX_OPTION_SIZE) {
- log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
- return;
- }
-
- strncpy(_hoption_table[opt], value, MAX_OPTION_VALUE_SIZE);
-}
-
-
-char *hoption_get(int opt)
-{
- if (opt >= MAX_OPTION_SIZE) {
- log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
- return "";
- }
-
- return _hoption_table[opt];
-}
-
-
-void hoption_init_args(int argc, char* argv[])
-{
- int i;
-
- hoption_set(HOPTION_TMP_DIR, "."); /* default value */
-
- /* initialize from arguments */
- for (i = 0; i < argc; i++)
- {
- if (!strcmp (argv[i], NHTTP_ARG_TMPDIR) && i < argc - 1)
- {
- hoption_set(HOPTION_TMP_DIR, argv[i+1]);
- }
- else if (!strcmp (argv[i], NHTTP_ARG_LOGFILE) && i < argc - 1)
- {
- log_set_file(argv[i+1]);
- }
- }
-
-
-}
-
-
-#ifdef WIN32
-#ifndef __MINGW32__
-
-/* not thread safe!*/
-char *VisualC_funcname(const char* file, int line)
-{
- static char buffer[256];
- int i = strlen(file)-1;
- while (i>0 && file[i]!='\\')i--;
- sprintf(buffer, "%s:%d", (file[i]!='\\')?file:(file+i+1), line);
- return buffer;
-}
-
-#endif
-#endif
-
-typedef struct _herror_impl_t
-{
- int errcode;
- char message[250];
- char func[100];
-}herror_impl_t;
-
-
-herror_t herror_new(const char* func, int errcode, const char* format, ...)
-{
- va_list ap;
-
- herror_impl_t *impl = (herror_impl_t*)malloc(sizeof(herror_impl_t));
- impl->errcode = errcode;
- strcpy(impl->func, func);
- va_start(ap, format);
- vsprintf(impl->message, format, ap);
- va_end(ap);
-
- return (herror_t)impl;
-
-}
-
-int herror_code(herror_t err)
-{
- herror_impl_t* impl = (herror_impl_t*)err;
- if (!err) return H_OK;
- return impl->errcode;
-}
-
-char* herror_func(herror_t err)
-{
- herror_impl_t* impl = (herror_impl_t*)err;
- if (!err) return "";
- return impl->func;
-}
-
-char* herror_message(herror_t err)
-{
- herror_impl_t* impl = (herror_impl_t*)err;
- if (!err) return "";
- return impl->message;
-}
-
-void herror_release(herror_t err)
-{
- herror_impl_t* impl = (herror_impl_t*)err;
- if (!err) return;
- free(impl);
-}
-
-
-
-static log_level_t loglevel = HLOG_DEBUG;
+
+
+#define MAX_OPTION_SIZE 50
+#define MAX_OPTION_VALUE_SIZE 150
+
+static char _hoption_table[MAX_OPTION_SIZE][MAX_OPTION_VALUE_SIZE];
+
+/* option stuff */
+void hoption_set(int opt, const char* value)
+{
+ if (opt >= MAX_OPTION_SIZE) {
+ log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
+ return;
+ }
+
+ strncpy(_hoption_table[opt], value, MAX_OPTION_VALUE_SIZE);
+}
+
+
+char *hoption_get(int opt)
+{
+ if (opt >= MAX_OPTION_SIZE) {
+ log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
+ return "";
+ }
+
+ return _hoption_table[opt];
+}
+
+
+void hoption_init_args(int argc, char* argv[])
+{
+ int i;
+
+ hoption_set(HOPTION_TMP_DIR, "."); /* default value */
+
+ /* initialize from arguments */
+ for (i = 0; i < argc; i++)
+ {
+ if (!strcmp (argv[i], NHTTP_ARG_TMPDIR) && i < argc - 1)
+ {
+ hoption_set(HOPTION_TMP_DIR, argv[i+1]);
+ }
+ else if (!strcmp (argv[i], NHTTP_ARG_LOGFILE) && i < argc - 1)
+ {
+ log_set_file(argv[i+1]);
+ }
+ }
+
+
+}
+
+
+#ifdef WIN32
+#ifndef __MINGW32__
+
+/* not thread safe!*/
+char *VisualC_funcname(const char* file, int line)
+{
+ static char buffer[256];
+ int i = strlen(file)-1;
+ while (i>0 && file[i]!='\\')i--;
+ sprintf(buffer, "%s:%d", (file[i]!='\\')?file:(file+i+1), line);
+ return buffer;
+}
+
+#endif
+#endif
+
+typedef struct _herror_impl_t
+{
+ int errcode;
+ char message[250];
+ char func[100];
+}herror_impl_t;
+
+
+herror_t herror_new(const char* func, int errcode, const char* format, ...)
+{
+ va_list ap;
+
+ herror_impl_t *impl = (herror_impl_t*)malloc(sizeof(herror_impl_t));
+ impl->errcode = errcode;
+ strcpy(impl->func, func);
+ va_start(ap, format);
+ vsprintf(impl->message, format, ap);
+ va_end(ap);
+
+ return (herror_t)impl;
+
+}
+
+int herror_code(herror_t err)
+{
+ herror_impl_t* impl = (herror_impl_t*)err;
+ if (!err) return H_OK;
+ return impl->errcode;
+}
+
+char* herror_func(herror_t err)
+{
+ herror_impl_t* impl = (herror_impl_t*)err;
+ if (!err) return "";
+ return impl->func;
+}
+
+char* herror_message(herror_t err)
+{
+ herror_impl_t* impl = (herror_impl_t*)err;
+ if (!err) return "";
+ return impl->message;
+}
+
+void herror_release(herror_t err)
+{
+ herror_impl_t* impl = (herror_impl_t*)err;
+ if (!err) return;
+ free(impl);
+}
+
+
+
+static log_level_t loglevel = HLOG_DEBUG;
static char logfile[75] = {'\0'};
log_level_t
@@ -172,21 +172,21 @@ log_get_level()
{
return loglevel;
}
-
-
-void log_set_file(const char *filename)
-{
- if (filename)
- strncpy(logfile, filename, 75);
- else
- logfile[0] = '\0';
-}
-
-char *log_get_file()
-{
- if (logfile[0] == '\0') return NULL;
- return logfile;
-}
+
+
+void log_set_file(const char *filename)
+{
+ if (filename)
+ strncpy(logfile, filename, 75);
+ else
+ logfile[0] = '\0';
+}
+
+char *log_get_file()
+{
+ if (logfile[0] == '\0') return NULL;
+ return logfile;
+}
static
void
@@ -194,7 +194,7 @@ log_write(log_level_t level, const char *prefix,
const char *func, const char *format, va_list ap)
{
char buffer[1054];
- char buffer2[1054];
+ char buffer2[1054];
FILE *f;
if (level < loglevel)
@@ -203,16 +203,16 @@ log_write(log_level_t level, const char *prefix,
sprintf(buffer, "*%s*: [%s] %s\n", prefix, func, format);
vsprintf(buffer2, buffer, ap);
printf(buffer2);
- fflush(stdout);
-
- if (log_get_file()) {
- f = fopen(log_get_file(), "a");
- if (!f) f = fopen(log_get_file(), "w");
- if (f) {
- fprintf(f, buffer2);
- fflush(f);
- fclose(f);
- }
+ fflush(stdout);
+
+ if (log_get_file()) {
+ f = fopen(log_get_file(), "a");
+ if (!f) f = fopen(log_get_file(), "w");
+ if (f) {
+ fprintf(f, buffer2);
+ fflush(f);
+ fclose(f);
+ }
}
}
@@ -517,13 +517,13 @@ herror_t hurl_parse(hurl_t* url, const char *urlstr)
}
if (iprotocol + 3 >= len) {
log_error1("no host");
- return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
+ return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
}
if (urlstr[iprotocol] != ':'
&& urlstr[iprotocol + 1] != '/'
&& urlstr[iprotocol + 2] != '/') {
log_error1("no protocol");
- return herror_new("hurl_parse", URL_ERROR_NO_PROTOCOL, "No protocol");
+ return herror_new("hurl_parse", URL_ERROR_NO_PROTOCOL, "No protocol");
}
/* find host */
ihost = iprotocol + 3;
@@ -535,7 +535,7 @@ herror_t hurl_parse(hurl_t* url, const char *urlstr)
if (ihost == iprotocol + 1) {
log_error1("no host");
- return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
+ return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
}
/* find port */
iport = ihost;
@@ -556,8 +556,8 @@ herror_t hurl_parse(hurl_t* url, const char *urlstr)
url->protocol = PROTOCOL_HTTPS;
else if (strcmpigcase(protocol, "ftp"))
url->protocol = PROTOCOL_FTP;
- else return herror_new("hurl_parse",
- URL_ERROR_UNKNOWN_PROTOCOL, "Unknown protocol '%s'", protocol);
+ else return herror_new("hurl_parse",
+ URL_ERROR_UNKNOWN_PROTOCOL, "Unknown protocol '%s'", protocol);
/* TODO (#1#): add max of size and URL_MAX_HOST_SIZE */
size = ihost - iprotocol - 3;
@@ -700,7 +700,7 @@ part_t *part_new(const char *id, const char* filename,
{
part_t *part = (part_t*)malloc(sizeof(part_t));
part->header = NULL;
- part->next = next;
+ part->next = next;
part->deleteOnExit = 0;
strcpy(part->id, id);
strcpy(part->filename, filename);
@@ -724,19 +724,19 @@ part_t *part_new(const char *id, const char* filename,
return part;
}
-void part_free(part_t *part)
-{
- if (part == NULL)
- return;
-
- if (part->deleteOnExit) {
- remove(part->filename);
- }
-
- hpairnode_free_deep(part->header);
-
- free(part);
-}
+void part_free(part_t *part)
+{
+ if (part == NULL)
+ return;
+
+ if (part->deleteOnExit) {
+ remove(part->filename);
+ }
+
+ hpairnode_free_deep(part->header);
+
+ free(part);
+}
attachments_t *attachments_new() /* should be used internally */
{
@@ -778,8 +778,8 @@ void attachments_free(attachments_t *message)
part_free(part);
part= tmp;
}
-
- if (message->root_part)
+
+ if (message->root_part)
part_free(message->root_part);
/* TODO (#1#): HERE IS A BUG!!!! */
free(message);
diff --git a/nanohttp/nanohttp-common.h b/nanohttp/nanohttp-common.h
index e633ab4..60cfbeb 100644
--- a/nanohttp/nanohttp-common.h
+++ b/nanohttp/nanohttp-common.h
@@ -1,25 +1,25 @@
-/******************************************************************
- * $Id: nanohttp-common.h,v 1.16 2004/11/01 15:16:26 snowdrop Exp $
- *
- * CSOAP Project: A http client/server library in C
- * Copyright (C) 2003-2004 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ferhatayaz@yahoo.com
+/******************************************************************
+ * $Id: nanohttp-common.h,v 1.17 2004/11/02 23:09:26 snowdrop Exp $
+ *
+ * CSOAP Project: A http client/server library in C
+ * Copyright (C) 2003-2004 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ferhatayaz@yahoo.com
******************************************************************/
#ifndef NANO_HTTP_COMMON_H
#define NANO_HTTP_COMMON_H
@@ -29,8 +29,8 @@
#define HEADER_CONTENT_LENGTH "Content-Length"
#define HEADER_CONTENT_TYPE "Content-Type"
-#define HEADER_CONTENT_ID "Content-Id"
-#define HEADER_CONTENT_LOCATION "Content-Location"
+#define HEADER_CONTENT_ID "Content-Id"
+#define HEADER_CONTENT_LOCATION "Content-Location"
#define HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
#define HEADER_TRANSFER_ENCODING "Transfer-Encoding"
#define HEADER_CONNECTION "Connection"
@@ -38,13 +38,13 @@
#define HEADER_HOST "Host"
#define HEADER_DATE "Date"
#define HEADER_ACCEPT "Accept"
-
-
-#define NHTTPD_ARG_PORT "-NHTTPport"
-#define NHTTPD_ARG_TERMSIG "-NHTTPtsig"
-#define NHTTPD_ARG_MAXCONN "-NHTTPmaxconn"
-#define NHTTP_ARG_LOGFILE "-NHTTPlog"
-#define NHTTP_ARG_TMPDIR "-NHTTPtmpdir"
+
+
+#define NHTTPD_ARG_PORT "-NHTTPport"
+#define NHTTPD_ARG_TERMSIG "-NHTTPtsig"
+#define NHTTPD_ARG_MAXCONN "-NHTTPmaxconn"
+#define NHTTP_ARG_LOGFILE "-NHTTPlog"
+#define NHTTP_ARG_TMPDIR "-NHTTPtmpdir"
#ifndef SAVE_STR
#define SAVE_STR(str) ((str==0)?("(null)"):(str))
@@ -120,18 +120,18 @@
#define MIME_ERROR_NO_ROOT_PART 1304
#define MIME_ERROR_NOT_MIME_MESSAGE 1305
-
-/* General errors */
-#define GENERAL_INVALID_PARAM 1400
-#define GENERAL_HEADER_PARSE_ERROR 1401
-
-/* Thread errors */
-#define THREAD_BEGIN_ERROR 1500
-
-/* XML Errors */
-#define XML_ERROR_EMPTY_DOCUMENT 1600
-#define XML_ERROR_PARSE 1601
-
+
+/* General errors */
+#define GENERAL_INVALID_PARAM 1400
+#define GENERAL_HEADER_PARSE_ERROR 1401
+
+/* Thread errors */
+#define THREAD_BEGIN_ERROR 1500
+
+/* XML Errors */
+#define XML_ERROR_EMPTY_DOCUMENT 1600
+#define XML_ERROR_PARSE 1601
+
/*
Set Sleep function platform depended
*/
@@ -149,8 +149,8 @@ struct tm *localtime_r(const time_t *const timep, struct tm *p_tm);
typedef unsigned char byte_t;
typedef void* herror_t;
-
-
+
+
/**
Indicates the version of the
@@ -171,14 +171,14 @@ typedef enum _hreq_method
HTTP_REQUEST_GET
}hreq_method_t ;
-
-herror_t herror_new(const char* func,
- int errcode, const char* format, ...);
-int herror_code(herror_t err);
-char* herror_func(herror_t err);
-char* herror_message(herror_t err);
-void herror_release(herror_t err);
-
+
+herror_t herror_new(const char* func,
+ int errcode, const char* format, ...);
+int herror_code(herror_t err);
+char* herror_func(herror_t err);
+char* herror_message(herror_t err);
+void herror_release(herror_t err);
+
/*
string function to compare strings ignoring case
@@ -413,22 +413,22 @@ void content_type_free(content_type_t *ct);
*/
typedef struct _part
{
- char id[250];
- char location[250];
+ char id[250];
+ char location[250];
hpair_t *header;
char content_type[128];
char transfer_encoding[128];
char filename[250];
- struct _part *next;
+ struct _part *next;
int deleteOnExit; /* default is 0 */
}part_t;
part_t *part_new(const char *id, const char* filename,
const char* content_type, const char* transfer_encoding, part_t *next);
-void part_free(part_t *part);
-
-
+void part_free(part_t *part);
+
+
/*
@@ -450,13 +450,13 @@ attachments_t *attachments_new(); /* should be used internally */
@see mime_get_attachments
*/
void attachments_free(attachments_t *message);
-void attachments_add_part(attachments_t *attachments, part_t *part);
-
+void attachments_add_part(attachments_t *attachments, part_t *part);
+
-/* tmp directory for multipart/related stuff */
-#define HOPTION_TMP_DIR 2
-void hoption_init_args(int argc, char* argv[]);
-void hoption_set(int opt, const char* value);
+/* tmp directory for multipart/related stuff */
+#define HOPTION_TMP_DIR 2
+void hoption_init_args(int argc, char* argv[]);
+void hoption_set(int opt, const char* value);
char *hoption_get(int opt);
@@ -476,11 +476,11 @@ typedef enum log_level
log_level_t log_set_level(log_level_t level);
log_level_t log_get_level();
-void log_set_file(const char *filename);
-char *log_get_file();
+void log_set_file(const char *filename);
+char *log_get_file();
#ifdef WIN32
- #ifndef __MINGW32__
+ #ifndef __MINGW32__
char *VisualC_funcname(const char* file, int line); /* not thread safe!*/
#define __FUNCTION__ VisualC_funcname(__FILE__, __LINE__)
#endif
diff --git a/nanohttp/nanohttp-mime.c b/nanohttp/nanohttp-mime.c
index 2089348..2cf059c 100755
--- a/nanohttp/nanohttp-mime.c
+++ b/nanohttp/nanohttp-mime.c
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.c,v 1.5 2004/11/01 15:16:26 snowdrop Exp $
+* $Id: nanohttp-mime.c,v 1.6 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -509,18 +509,18 @@ MIME_read_status mime_streamreader_function(void* userdata,
if (!http_input_stream_is_ready(in))
return MIME_READ_EOF;
- readed = http_input_stream_read(in, dest, *size);
- /*
- log_info1("http_input_stream_read() returned 0");
- */
- if (readed == -1) {
- log_error4("[%d] %s():%s ", herror_code(in->err), herror_func(in->err), herror_message(in->err));
- }
+ readed = http_input_stream_read(in, dest, *size);
+ /*
+ log_info1("http_input_stream_read() returned 0");
+ */
+ if (readed == -1) {
+ log_error4("[%d] %s():%s ", herror_code(in->err), herror_func(in->err), herror_message(in->err));
+ }
*size = readed;
- if (*size!=-1) {
+ if (*size!=-1) {
/*
- _log_str("reader.log", dest, *size);
+ _log_str("reader.log", dest, *size);
*/
return MIME_READ_OK;
}
@@ -582,8 +582,8 @@ void _mime_part_begin(void *data)
sprintf(buffer, "%s/mime_%p_%d.part", cbdata->root_dir,
cbdata, cbdata->part_id++);
#endif
-
-/* log_info2("Creating FILE ('%s') deleteOnExit=1", buffer);*/
+
+/* log_info2("Creating FILE ('%s') deleteOnExit=1", buffer);*/
part->deleteOnExit = 1;
cbdata->current_fd = fopen(buffer, "wb");
if (cbdata->current_fd)
@@ -730,23 +730,23 @@ void _mime_received_bytes(void *data, const unsigned char* bytes, int size)
cbdata->current_part->header = _mime_process_header(cbdata->header);
hpairnode_dump_deep(cbdata->current_part->header);
/* set id */
- id = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_ID);
- if (id != NULL)
- {
- strcpy(cbdata->current_part->id, id);
- if (!strcmp(id, cbdata->root_id))
- cbdata->message->root_part = cbdata->current_part;
- }
- location = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_LOCATION);
- if (location != NULL)
- {
- strcpy(cbdata->current_part->location, location);
- }
- type = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_TYPE);
- if (type != NULL)
- {
- strcpy(cbdata->current_part->content_type, type);
- }
+ id = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_ID);
+ if (id != NULL)
+ {
+ strcpy(cbdata->current_part->id, id);
+ if (!strcmp(id, cbdata->root_id))
+ cbdata->message->root_part = cbdata->current_part;
+ }
+ location = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_LOCATION);
+ if (location != NULL)
+ {
+ strcpy(cbdata->current_part->location, location);
+ }
+ type = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_TYPE);
+ if (type != NULL)
+ {
+ strcpy(cbdata->current_part->content_type, type);
+ }
i++;
break;
}
@@ -884,7 +884,7 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
/* Check for MIME message */
if (!(ctype &&
!strcmp(ctype->type, "multipart/related")))
- return herror_new("mime_get_attachments", MIME_ERROR_NOT_MIME_MESSAGE,
+ return herror_new("mime_get_attachments", MIME_ERROR_NOT_MIME_MESSAGE,
"Not a MIME message '%s'", ctype->type);
boundary = hpairnode_get(ctype->params, "boundary");
@@ -893,7 +893,7 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
{
/* TODO (#1#): Handle Error in http form */
log_error1("'boundary' not set for multipart/related");
- return herror_new("mime_get_attachments", MIME_ERROR_NO_BOUNDARY_PARAM,
+ return herror_new("mime_get_attachments", MIME_ERROR_NO_BOUNDARY_PARAM,
"'boundary' not set for multipart/related");
}
@@ -901,8 +901,8 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
{
/* TODO (#1#): Handle Error in http form */
log_error1("'start' not set for multipart/related");
- return herror_new("mime_get_attachments", MIME_ERROR_NO_START_PARAM,
- "'start' not set for multipart/related");
+ return herror_new("mime_get_attachments", MIME_ERROR_NO_START_PARAM,
+ "'start' not set for multipart/related");
}
mimeMessage = mime_message_parse(in, root_id, boundary, hoption_get(HOPTION_TMP_DIR));
@@ -910,7 +910,7 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
{
/* TODO (#1#): Handle Error in http form */
log_error1("MIME Parse Error");
- return herror_new("mime_get_attachments", MIME_ERROR_PARSE_ERROR,
+ return herror_new("mime_get_attachments", MIME_ERROR_PARSE_ERROR,
"MIME Parse Error");
}
@@ -918,7 +918,7 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
if (!mimeMessage->root_part)
{
attachments_free(mimeMessage);
- return herror_new("mime_get_attachments", MIME_ERROR_NO_ROOT_PART,
+ return herror_new("mime_get_attachments", MIME_ERROR_NO_ROOT_PART,
"No root part found!");
}
diff --git a/nanohttp/nanohttp-mime.h b/nanohttp/nanohttp-mime.h
index b51e44d..be2abfa 100755
--- a/nanohttp/nanohttp-mime.h
+++ b/nanohttp/nanohttp-mime.h
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.h,v 1.3 2004/10/28 10:30:46 snowdrop Exp $
+* $Id: nanohttp-mime.h,v 1.4 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -29,8 +29,8 @@
#ifndef NANO_HTTP_MIME_PARSER_H
#define NANO_HTTP_MIME_PARSER_H
-#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-stream.h>
+#include <nanohttp/nanohttp-common.h>
+#include <nanohttp/nanohttp-stream.h>
#include <stdlib.h>
diff --git a/nanohttp/nanohttp-request.c b/nanohttp/nanohttp-request.c
index 7661592..16e74cb 100755
--- a/nanohttp/nanohttp-request.c
+++ b/nanohttp/nanohttp-request.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-request.c,v 1.3 2004/10/28 10:30:46 snowdrop Exp $
+* $Id: nanohttp-request.c,v 1.4 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -44,7 +44,7 @@ hrequest_t *hrequest_new()
req->in = NULL;
req->attachments = NULL;
req->content_type = NULL;
-
+
return req;
}
@@ -220,7 +220,7 @@ hrequest_free(hrequest_t * req)
herror_t
hrequest_new_from_socket(hsocket_t sock, hrequest_t **out)
{
- int i=0, readed;
+ int i=0, readed;
herror_t status;
hrequest_t *req;
char buffer[MAX_HEADER_SIZE+1];
diff --git a/nanohttp/nanohttp-response.c b/nanohttp/nanohttp-response.c
index 3883950..5432898 100755
--- a/nanohttp/nanohttp-response.c
+++ b/nanohttp/nanohttp-response.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-response.c,v 1.3 2004/10/29 09:27:05 snowdrop Exp $
+* $Id: nanohttp-response.c,v 1.4 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -121,11 +121,11 @@ _hresponse_parse_header(const char *buffer)
return res;
}
-
+
herror_t
hresponse_new_from_socket(hsocket_t sock, hresponse_t **out)
{
- int i=0, readed;
+ int i=0, readed;
herror_t status;
hresponse_t *res;
attachments_t *mimeMessage;
@@ -158,7 +158,7 @@ read_header: /* for errorcode: 100 (continue) */
if (res == NULL)
{
log_error1("Header parse error");
- return herror_new("hresponse_new_from_socket",
+ return herror_new("hresponse_new_from_socket",
GENERAL_HEADER_PARSE_ERROR, "Can not parse response header");
}
@@ -186,14 +186,14 @@ read_header: /* for errorcode: 100 (continue) */
}
else
{
- res->attachments = mimeMessage;
+ res->attachments = mimeMessage;
http_input_stream_free(res->in);
- res->in = http_input_stream_new_from_file(mimeMessage->root_part->filename);
- if (!res->in) {
- /* TODO (#1#): Handle error */
-
- } else {
- /*res->in->deleteOnExit = 1;*/
+ res->in = http_input_stream_new_from_file(mimeMessage->root_part->filename);
+ if (!res->in) {
+ /* TODO (#1#): Handle error */
+
+ } else {
+ /*res->in->deleteOnExit = 1;*/
}
}
}
@@ -202,9 +202,9 @@ read_header: /* for errorcode: 100 (continue) */
}
-
-void
-hresponse_free(hresponse_t * res)
+
+void
+hresponse_free(hresponse_t * res)
{
if (res == NULL)
return;
@@ -217,8 +217,8 @@ hresponse_free(hresponse_t * res)
if (res->content_type)
content_type_free(res->content_type);
-
- if (res->attachments)
+
+ if (res->attachments)
attachments_free(res->attachments);
free(res);
}
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index 625bd79..d50c434 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.30 2004/11/02 22:42:52 snowdrop Exp $
+* $Id: nanohttp-server.c,v 1.31 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -32,7 +32,7 @@
#endif
#ifndef WIN32
-
+
/* According to POSIX 1003.1-2001 */
#include <sys/select.h>
@@ -40,11 +40,11 @@
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
-
-#else
-
+
+#else
+
#include <process.h>
-
+
#endif
#ifdef MEM_DEBUG
@@ -97,11 +97,11 @@ static void WSAReaper(void *x);
herror_t
httpd_init (int argc, char *argv[])
{
- int i;
+ int i;
herror_t status;
-
- hoption_init_args(argc, argv);
-
+
+ hoption_init_args(argc, argv);
+
status = hsocket_module_init ();
if (status != H_OK)
return status;
@@ -140,14 +140,14 @@ httpd_init (int argc, char *argv[])
memset ((char *) &_httpd_connection[i], 0, sizeof (_httpd_connection[i]));
}
-#ifdef WIN32
+#ifdef WIN32
/*
if (_beginthread (WSAReaper, 0, NULL) == -1)
{
log_error1 ("Winsock reaper thread failed to start");
- return herror_new("httpd_init", THREAD_BEGIN_ERROR,
+ return herror_new("httpd_init", THREAD_BEGIN_ERROR,
"_beginthread() failed while starting WSAReaper");
- }
+ }
*/
#endif
@@ -298,8 +298,8 @@ httpd_send_header (httpd_conn_t * res, int code, const char *text)
/* send header */
status = hsocket_nsend (res->sock, header, strlen (header));
- if (status != H_OK)
- return status;
+ if (status != H_OK)
+ return status;
res->out = http_output_stream_new (res->sock, res->header);
return H_OK;
@@ -390,11 +390,11 @@ httpd_session_main (void *data)
hrequest_t *req = NULL; /* only for test */
httpd_conn_t *rconn;
hservice_t *service = NULL;
- long content_length = 0;
+ long content_length = 0;
herror_t status;
header[0] = '\0';
- len = 0;
+ len = 0;
@@ -407,7 +407,7 @@ httpd_session_main (void *data)
status = hrequest_new_from_socket (conn->sock, &req);
if (status != H_OK)
{
- httpd_send_internal_error (rconn, herror_message(status)/*"Request parse error!"*/);
+ httpd_send_internal_error (rconn, herror_message(status)/*"Request parse error!"*/);
herror_release(status);
}
else
@@ -706,7 +706,7 @@ void httpd_destroy()
hservice_free(cur);
cur = tmp;
}
-
+
hsocket_module_destroy();
}
@@ -834,12 +834,12 @@ httpd_mime_send_header (httpd_conn_t * conn,
type=..; start=.. ; start-info= ..; boundary=...
*/
- /*
- using sprintf instead of snprintf because visual c does not support snprintf
- */
-#ifdef WIN32
-#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
-#endif
+ /*
+ using sprintf instead of snprintf because visual c does not support snprintf
+ */
+#ifdef WIN32
+#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
+#endif
sprintf (buffer, "multipart/related;");
if (related_type)
@@ -926,7 +926,7 @@ httpd_mime_send_file (httpd_conn_t * conn,
size_t size;
if (fd == NULL)
- return herror_new("httpd_mime_send_file", FILE_ERROR_OPEN,
+ return herror_new("httpd_mime_send_file", FILE_ERROR_OPEN,
"Can not open file '%d'", filename);
status =
@@ -943,8 +943,8 @@ httpd_mime_send_file (httpd_conn_t * conn,
if (size == -1)
{
fclose (fd);
- return herror_new("httpd_mime_send_file", FILE_ERROR_READ,
- "Can not read from file '%d'", filename);
+ return herror_new("httpd_mime_send_file", FILE_ERROR_READ,
+ "Can not read from file '%d'", filename);
}
status = http_output_stream_write (conn->out, buffer, size);
diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h
index e344eba..f0550f8 100644
--- a/nanohttp/nanohttp-server.h
+++ b/nanohttp/nanohttp-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-server.h,v 1.8 2004/10/28 10:30:46 snowdrop Exp $
+ * $Id: nanohttp-server.h,v 1.9 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -74,7 +74,7 @@ herror_t httpd_send_header(httpd_conn_t *res,
int httpd_set_header(httpd_conn_t *conn, const char *key, const char* value);
void httpd_set_headers(httpd_conn_t *conn, hpair_t *header);
-
+
/*
unsigned char *httpd_get_postdata(httpd_conn_t *conn,
hrequest_t *req, long *received, long max);
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index 6d93fe2..869bc40 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.31 2004/10/29 09:27:05 snowdrop Exp $
+* $Id: nanohttp-socket.c,v 1.32 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -67,14 +67,14 @@
#ifdef MEM_DEBUG
#include <utils/alloc.h>
#endif
-
-
-#ifdef WIN32
-#undef errno
-#define errno WSAGetLastError()
-#endif
-
-
+
+
+#ifdef WIN32
+#undef errno
+#define errno WSAGetLastError()
+#endif
+
+
/*--------------------------------------------------
FUNCTION: hsocket_module_init
@@ -141,12 +141,12 @@ hsocket_open (hsocket_t * dsock, const char *hostname, int port)
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock <= 0)
- return herror_new("hsocket_open", HSOCKET_ERROR_CREATE, "Socket error: %d", errno);
+ return herror_new("hsocket_open", HSOCKET_ERROR_CREATE, "Socket error: %d", errno);
/* Get host data */
host = gethostbyname (hostname);
if (host == NULL)
- return herror_new("hsocket_open", HSOCKET_ERROR_GET_HOSTNAME, "Socket error: %d", errno);
+ return herror_new("hsocket_open", HSOCKET_ERROR_GET_HOSTNAME, "Socket error: %d", errno);
ip = inet_ntoa (*(struct in_addr *) *host->h_addr_list);
address.sin_addr.s_addr = inet_addr (ip);
@@ -157,8 +157,8 @@ hsocket_open (hsocket_t * dsock, const char *hostname, int port)
/* connect to the server */
if (connect (sock, (struct sockaddr *) &address, sizeof (address)) != 0)
-/* return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Connect to '%s:%d' failed", hostname, port);*/
- return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Socket error: %d", errno);
+/* return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Connect to '%s:%d' failed", hostname, port);*/
+ return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Socket error: %d", errno);
*dsock = sock;
return H_OK;
@@ -178,7 +178,7 @@ hsocket_bind (hsocket_t * dsock, int port)
if (sock == -1)
{
log_error3 ("Can not create socket: '%s'", "Socket error: %d", errno);
- return herror_new("hsocket_bind", HSOCKET_ERROR_CREATE, "Socket error: %d", errno);
+ return herror_new("hsocket_bind", HSOCKET_ERROR_CREATE, "Socket error: %d", errno);
}
/* bind socket */
addr.sin_family = AF_INET;
@@ -190,7 +190,7 @@ hsocket_bind (hsocket_t * dsock, int port)
if (bind (sock, (struct sockaddr *) &addr, sizeof (struct sockaddr)) == -1)
{
log_error3 ("Can not bind: '%s'", "Socket error: %d", errno);
- return herror_new("hsocket_bind", HSOCKET_ERROR_BIND, "Socket error: %d", errno);
+ return herror_new("hsocket_bind", HSOCKET_ERROR_BIND, "Socket error: %d", errno);
}
*dsock = sock;
return H_OK;
@@ -207,8 +207,8 @@ hsocket_accept (hsocket_t sock, hsocket_t * dest)
struct sockaddr_in addr;
if (sock <= 0)
- return herror_new("hsocket_accept", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_accept", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
asize = sizeof (struct sockaddr_in);
#ifdef WIN32
@@ -217,7 +217,7 @@ hsocket_accept (hsocket_t sock, hsocket_t * dest)
sockfd = accept (sock, (struct sockaddr *) &addr, &asize);
if (sockfd == INVALID_SOCKET) {
if (WSAGetLastError () != WSAEWOULDBLOCK)
- return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error: %d", errno);
+ return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error: %d", errno);
} else {
break;
}
@@ -226,7 +226,7 @@ hsocket_accept (hsocket_t sock, hsocket_t * dest)
/* TODO (#1#): why not a loop like in win32? */
sockfd = accept (sock, (struct sockaddr *) &addr, &asize);
if (sockfd == -1) {
- return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error: %d", errno);
+ return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error: %d", errno);
}
#endif
/* TODO (#1#): Write to access.log file */
@@ -245,13 +245,13 @@ herror_t
hsocket_listen (hsocket_t sock)
{
if (sock <= 0)
- return herror_new("hsocket_listen", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_listen", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
if (listen (sock, 15) == -1)
{
log_error3 ("Can not listen: '%s'", "Socket error: %d", errno);
- return herror_new("hsocket_listen", HSOCKET_ERROR_LISTEN, "Socket error: %d", errno);
+ return herror_new("hsocket_listen", HSOCKET_ERROR_LISTEN, "Socket error: %d", errno);
}
return H_OK;
@@ -304,8 +304,8 @@ hsocket_close (hsocket_t sock)
char junk[10];
/* _hsocket_wait_until_receive(sock);*/
log_verbose1 ("closing socket ...");
-/*
- struct linger _linger;
+/*
+ struct linger _linger;
hsocket_block(sock,1);
_linger.l_onoff =1;
_linger.l_linger = 30000;
@@ -326,17 +326,17 @@ hsocket_close (hsocket_t sock)
#endif
log_verbose1 ("closed");
}
-
-
-static int _test_send_to_file(const char* filename, const byte_t* bytes,int n)
-{
- int size;
- FILE *f = fopen(filename, "ab");
- if (!f) f = fopen(filename, "wb");
- size= fwrite(bytes, 1, n, f);
- fclose(f);
- return size;
-}
+
+
+static int _test_send_to_file(const char* filename, const byte_t* bytes,int n)
+{
+ int size;
+ FILE *f = fopen(filename, "ab");
+ if (!f) f = fopen(filename, "wb");
+ size= fwrite(bytes, 1, n, f);
+ fclose(f);
+ return size;
+}
/*--------------------------------------------------
FUNCTION: hsocket_send
@@ -347,27 +347,27 @@ hsocket_nsend (hsocket_t sock, const byte_t *bytes, int n)
int size;
int total=0;
if (sock <= 0)
- return herror_new("hsocket_nsend", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_nsend", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
/* TODO (#1#): check return value and send again until n bytes sent */
while (1)
{
- size = send((int) sock, bytes + total, n, 0);
+ size = send((int) sock, bytes + total, n, 0);
/* size = _test_send_to_file(filename, bytes, n);*/
#ifdef WIN32
if (size == INVALID_SOCKET)
if (WSAGetLastError () == WSAEWOULDBLOCK)
continue;
else
- return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
+ return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
#else
if (size == -1)
- return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
+ return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
#endif
- n -= size;
+ n -= size;
total += size;
if (n<=0) break;
}
@@ -393,8 +393,8 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
int totalRead;
int wsa_error;
totalRead = 0;
-/*
- log_verbose3("Entering hsocket_read(total=%d,force=%d)", total, force);
+/*
+ log_verbose3("Entering hsocket_read(total=%d,force=%d)", total, force);
*/
do
{
@@ -412,7 +412,7 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
continue;
default:
log_error2("WSAGetLastError()=%d", wsa_error);
- return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
+ return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
}
}
@@ -426,13 +426,13 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
}
*/
if (status == -1)
- return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
+ return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
#endif
- if (!force) {
- *received = status;
- /*
- log_verbose3("Leaving !force (received=%d)(status=%d)", *received, status);
+ if (!force) {
+ *received = status;
+ /*
+ log_verbose3("Leaving !force (received=%d)(status=%d)", *received, status);
*/
return H_OK;
}
@@ -440,11 +440,11 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
totalRead += status;
if (totalRead == total) {
- *received = totalRead;
- /*
- log_verbose4("Leaving totalRead == total (received=%d)(status=%d)(totalRead=%d)", *received, status, totalRead);
- */
- return H_OK;
+ *received = totalRead;
+ /*
+ log_verbose4("Leaving totalRead == total (received=%d)(status=%d)(totalRead=%d)", *received, status, totalRead);
+ */
+ return H_OK;
}
}
while (1);
@@ -459,19 +459,19 @@ hsocket_block(hsocket_t sock, int block)
#endif
if (sock <= 0)
- return herror_new("hsocket_block", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_block", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
#ifdef WIN32
/*#define HSOCKET_BLOCKMODE 0
#define HSOCKET_NONBLOCKMODE 1
-*/
+*/
iMode = (block==0)?1:0; /* Non block mode */
if (ioctlsocket (sock, FIONBIO, (u_long FAR *) & iMode) == INVALID_SOCKET)
{
log_error1 ("ioctlsocket error");
- return herror_new("hsocket_block", HSOCKET_ERROR_IOCTL, "Socket error: %d", errno);
+ return herror_new("hsocket_block", HSOCKET_ERROR_IOCTL, "Socket error: %d", errno);
}
#else /* fcntl(sock, F_SETFL, O_NONBLOCK); */
/* TODO (#1#): check for *nix the non blocking sockets */
diff --git a/nanohttp/nanohttp-socket.h b/nanohttp/nanohttp-socket.h
index 83d8f72..e9a69f6 100644
--- a/nanohttp/nanohttp-socket.h
+++ b/nanohttp/nanohttp-socket.h
@@ -1,216 +1,216 @@
-/******************************************************************
- * $Id: nanohttp-socket.h,v 1.14 2004/10/28 10:30:47 snowdrop Exp $
- *
- * CSOAP Project: A http client/server library in C
- * Copyright (C) 2003 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ayaz@jprogrammer.net
- ******************************************************************/
-#ifndef NANO_HTTP_SOCKET_H
-#define NANO_HTTP_SOCKET_H
-
-#include <nanohttp/nanohttp-common.h>
-
-#include <time.h>
-
-#ifdef WIN32
- #include <winsock2.h>
-#endif
-
-
-#ifdef WIN32
- typedef SOCKET hsocket_t;
- typedef int socklen_t;
-#else
- typedef int hsocket_t;
-#endif
-
-
-
-/**
- Initializes the socket modul. This should be called only
- once for an application.
-
- @returns This function should always return H_OK.
- */
-herror_t hsocket_module_init();
-
-
-/**
- Destroys the socket modul. This should be called after
- finishing an application.
-*/
-void hsocket_module_destroy();
-
-
-/**
- Initializes a given socket object. This function should
- be called for every socket before using it.
-
- @param sock the destination socket to initialize.
-
- @returns This function should always return H_OK.
- */
-herror_t hsocket_init(hsocket_t *sock);
-
-
-/**
- Destroys and releases a given socket.
-
- @param sock the socket to destroy
-*/
-void hsocket_free(hsocket_t sock);
-
-
-/**
- Connects to a given host. The hostname can be an IP number
- or a humen readable hostname.
-
- @param sock the destonation socket object to use
- @param host hostname
- @param port port number to connect to
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_CREATE
- <BR>HSOCKET_ERROR_GET_HOSTNAME
- <BR>HSOCKET_ERROR_CONNECT
- */
-herror_t hsocket_open(hsocket_t *sock, const char* host, int port);
-
-
-/**
- Close a socket connection.
-
- @param sock the socket to close
-*/
-void hsocket_close(hsocket_t sock);
-
-
-/**
- Binds a socket to a given port number. After bind you
- can call hsocket_listen() to listen to the port.
-
- @param sock socket to use.
- @param port port number to bind to
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_CREATE
- <BR>HSOCKET_ERROR_BIND
-
- @see hsocket_listen
- */
-herror_t hsocket_bind(hsocket_t *sock, int port);
-
-
-/**
- Set the socket to the listen mode. You must bind
- the socket to a port with hsocket_bind() before
- you can listen to the port.
-
- @param sock the socket to use
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_LISTEN
-*/
-herror_t hsocket_listen(hsocket_t sock);
-
-
-/**
- Accepts an incoming socket request. Note that this function
- will not return until a socket connection is ready.
-
- @param sock the socket which listents to a port
- @param dest the destination socket which will be created
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_ACCEPT
-*/
-herror_t hsocket_accept(hsocket_t sock, hsocket_t *dest);
-
-
-/**
- Sends data throught the socket.
-
- @param sock the socket to use to send the data
- @param bytes bytes to send
- @param size size of memory to sent pointed by bytes.
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_SEND
-*/
-herror_t hsocket_nsend(hsocket_t sock, const byte_t* bytes, int size);
-
-
-/**
- Sends a string throught the socket
-
- @param sock the socket to use to send the data
- @param str the null terminated string to sent
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_SEND
-*/
-herror_t hsocket_send(hsocket_t sock, const char* str);
-
-
-/**
- Reads data from the socket.
-
- @param sock the socket to read data from
- @param buffer the buffer to use to save the readed bytes
- @param size the maximum size of bytes to read
- @param force if force is 1 then hsocket_read() will wait until
- maximum size of bytes (size parameter) was readed. Otherwise
- this function will not wait and will return with the bytes
- quequed on the socket.
-
- @returns This function will return -1 if an read error was occured.
- Otherwise the return value is the size of bytes readed from
- the socket.
-
-*/
-herror_t hsocket_read(hsocket_t sock, byte_t* buffer, int size, int force, int *readed);
-
-/**
- Sets the goven socket to non-blocking socket mode.
-
- @param sock the socket to set into the non-blocking mode
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_IOCTL
-*/
-herror_t hsocket_block(hsocket_t sock, int block);
-
-
-#endif
-
-
-
-
-
-
-
-
-
-
-
+/******************************************************************
+ * $Id: nanohttp-socket.h,v 1.15 2004/11/02 23:09:27 snowdrop Exp $
+ *
+ * CSOAP Project: A http client/server library in C
+ * Copyright (C) 2003 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ayaz@jprogrammer.net
+ ******************************************************************/
+#ifndef NANO_HTTP_SOCKET_H
+#define NANO_HTTP_SOCKET_H
+
+#include <nanohttp/nanohttp-common.h>
+
+#include <time.h>
+
+#ifdef WIN32
+ #include <winsock2.h>
+#endif
+
+
+#ifdef WIN32
+ typedef SOCKET hsocket_t;
+ typedef int socklen_t;
+#else
+ typedef int hsocket_t;
+#endif
+
+
+
+/**
+ Initializes the socket modul. This should be called only
+ once for an application.
+
+ @returns This function should always return H_OK.
+ */
+herror_t hsocket_module_init();
+
+
+/**
+ Destroys the socket modul. This should be called after
+ finishing an application.
+*/
+void hsocket_module_destroy();
+
+
+/**
+ Initializes a given socket object. This function should
+ be called for every socket before using it.
+
+ @param sock the destination socket to initialize.
+
+ @returns This function should always return H_OK.
+ */
+herror_t hsocket_init(hsocket_t *sock);
+
+
+/**
+ Destroys and releases a given socket.
+
+ @param sock the socket to destroy
+*/
+void hsocket_free(hsocket_t sock);
+
+
+/**
+ Connects to a given host. The hostname can be an IP number
+ or a humen readable hostname.
+
+ @param sock the destonation socket object to use
+ @param host hostname
+ @param port port number to connect to
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_CREATE
+ <BR>HSOCKET_ERROR_GET_HOSTNAME
+ <BR>HSOCKET_ERROR_CONNECT
+ */
+herror_t hsocket_open(hsocket_t *sock, const char* host, int port);
+
+
+/**
+ Close a socket connection.
+
+ @param sock the socket to close
+*/
+void hsocket_close(hsocket_t sock);
+
+
+/**
+ Binds a socket to a given port number. After bind you
+ can call hsocket_listen() to listen to the port.
+
+ @param sock socket to use.
+ @param port port number to bind to
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_CREATE
+ <BR>HSOCKET_ERROR_BIND
+
+ @see hsocket_listen
+ */
+herror_t hsocket_bind(hsocket_t *sock, int port);
+
+
+/**
+ Set the socket to the listen mode. You must bind
+ the socket to a port with hsocket_bind() before
+ you can listen to the port.
+
+ @param sock the socket to use
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_LISTEN
+*/
+herror_t hsocket_listen(hsocket_t sock);
+
+
+/**
+ Accepts an incoming socket request. Note that this function
+ will not return until a socket connection is ready.
+
+ @param sock the socket which listents to a port
+ @param dest the destination socket which will be created
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_ACCEPT
+*/
+herror_t hsocket_accept(hsocket_t sock, hsocket_t *dest);
+
+
+/**
+ Sends data throught the socket.
+
+ @param sock the socket to use to send the data
+ @param bytes bytes to send
+ @param size size of memory to sent pointed by bytes.
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_SEND
+*/
+herror_t hsocket_nsend(hsocket_t sock, const byte_t* bytes, int size);
+
+
+/**
+ Sends a string throught the socket
+
+ @param sock the socket to use to send the data
+ @param str the null terminated string to sent
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_SEND
+*/
+herror_t hsocket_send(hsocket_t sock, const char* str);
+
+
+/**
+ Reads data from the socket.
+
+ @param sock the socket to read data from
+ @param buffer the buffer to use to save the readed bytes
+ @param size the maximum size of bytes to read
+ @param force if force is 1 then hsocket_read() will wait until
+ maximum size of bytes (size parameter) was readed. Otherwise
+ this function will not wait and will return with the bytes
+ quequed on the socket.
+
+ @returns This function will return -1 if an read error was occured.
+ Otherwise the return value is the size of bytes readed from
+ the socket.
+
+*/
+herror_t hsocket_read(hsocket_t sock, byte_t* buffer, int size, int force, int *readed);
+
+/**
+ Sets the goven socket to non-blocking socket mode.
+
+ @param sock the socket to set into the non-blocking mode
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_IOCTL
+*/
+herror_t hsocket_block(hsocket_t sock, int block);
+
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nanohttp/nanohttp-stream.c b/nanohttp/nanohttp-stream.c
index 1951c8a..3f0a9e9 100755
--- a/nanohttp/nanohttp-stream.c
+++ b/nanohttp/nanohttp-stream.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-stream.c,v 1.5 2004/10/29 09:27:05 snowdrop Exp $
+* $Id: nanohttp-stream.c,v 1.6 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -132,7 +132,7 @@ http_input_stream_t *http_input_stream_new_from_file(const char* filename)
result = (http_input_stream_t*)malloc(sizeof(http_input_stream_t));
result->type = HTTP_TRANSFER_FILE;
result->fd = fd;
- result->deleteOnExit = 0;
+ result->deleteOnExit = 0;
strcpy(result->filename, filename);
return result;
}
@@ -142,11 +142,11 @@ http_input_stream_t *http_input_stream_new_from_file(const char* filename)
*/
void http_input_stream_free(http_input_stream_t *stream)
{
- if (stream->type == HTTP_TRANSFER_FILE && stream->fd) {
- fclose(stream->fd);
- if (stream->deleteOnExit)
- log_info2("Removing '%s'", stream->filename);
- /*remove(stream->filename);*/
+ if (stream->type == HTTP_TRANSFER_FILE && stream->fd) {
+ fclose(stream->fd);
+ if (stream->deleteOnExit)
+ log_info2("Removing '%s'", stream->filename);
+ /*remove(stream->filename);*/
}
free(stream);
@@ -185,7 +185,7 @@ static
int _http_input_stream_content_length_read(
http_input_stream_t *stream, byte_t *dest, int size)
{
- herror_t status;
+ herror_t status;
int read;
/* check limit */
@@ -209,20 +209,20 @@ int _http_input_stream_chunked_read_chunk_size(
{
char chunk[25];
int status, i = 0;
- int chunk_size;
+ int chunk_size;
herror_t err;
while (1)
{
- err = hsocket_read(stream->sock, &(chunk[i]), 1, 1, &status);
- if (status != 1) {
- stream->err = herror_new("_http_input_stream_chunked_read_chunk_size",
- GENERAL_INVALID_PARAM, "This should never happens!");
- return -1;
+ err = hsocket_read(stream->sock, &(chunk[i]), 1, 1, &status);
+ if (status != 1) {
+ stream->err = herror_new("_http_input_stream_chunked_read_chunk_size",
+ GENERAL_INVALID_PARAM, "This should never happens!");
+ return -1;
}
- if (err != H_OK) {
- log_error4("[%d] %s(): %s ", herror_code(err), herror_func(err), herror_message(err));
+ if (err != H_OK) {
+ log_error4("[%d] %s(): %s ", herror_code(err), herror_func(err), herror_message(err));
stream->err = err;
return -1;
@@ -235,16 +235,16 @@ int _http_input_stream_chunked_read_chunk_size(
else if (chunk[i] == '\n')
{
chunk[i] = '\0'; /* double check*/
- chunk_size = strtol(chunk, (char **) NULL, 16); /* hex to dec */
+ chunk_size = strtol(chunk, (char **) NULL, 16); /* hex to dec */
/*
- log_verbose3("chunk_size: '%s' as dec: '%d'", chunk, chunk_size);
+ log_verbose3("chunk_size: '%s' as dec: '%d'", chunk, chunk_size);
*/
return chunk_size;
}
if (i == 24) {
- stream->err = herror_new(
- "_http_input_stream_chunked_read_chunk_size", STREAM_ERROR_NO_CHUNK_SIZE,
+ stream->err = herror_new(
+ "_http_input_stream_chunked_read_chunk_size", STREAM_ERROR_NO_CHUNK_SIZE,
"reached max line == %d", i);
return -1;
}
@@ -253,10 +253,10 @@ int _http_input_stream_chunked_read_chunk_size(
}
/* this should never happens */
- stream->err = herror_new(
- "_http_input_stream_chunked_read_chunk_size", STREAM_ERROR_NO_CHUNK_SIZE,
- "reached max line == %d", i);
- return -1;
+ stream->err = herror_new(
+ "_http_input_stream_chunked_read_chunk_size", STREAM_ERROR_NO_CHUNK_SIZE,
+ "reached max line == %d", i);
+ return -1;
}
static
@@ -265,7 +265,7 @@ int _http_input_stream_chunked_read(
{
int status, counter;
int remain, read=0;
- char ch;
+ char ch;
herror_t err;
while (size > 0)
@@ -291,7 +291,7 @@ int _http_input_stream_chunked_read(
break;
}
if (counter-- == 0) {
- stream->err = herror_new("_http_input_stream_chunked_read",
+ stream->err = herror_new("_http_input_stream_chunked_read",
STREAM_ERROR_WRONG_CHUNK_SIZE,"Wrong chunk-size");
return -1;
}
@@ -320,27 +320,27 @@ int _http_input_stream_chunked_read(
/* show remaining chunk size in socket */
if (remain < size)
{
- /* read from socket */
+ /* read from socket */
err = hsocket_read(stream->sock, &(dest[read]), remain, 1, &status);
- if (err != H_OK) {
- stream->err = err;
- return -1;
- }
- if (status != remain) {
- stream->err = herror_new("_http_input_stream_chunked_read",
- GENERAL_INVALID_PARAM, "This should never happens(remain=%d)(status=%d)!", remain, status);
- return -1;
- }
+ if (err != H_OK) {
+ stream->err = err;
+ return -1;
+ }
+ if (status != remain) {
+ stream->err = herror_new("_http_input_stream_chunked_read",
+ GENERAL_INVALID_PARAM, "This should never happens(remain=%d)(status=%d)!", remain, status);
+ return -1;
+ }
}
else
{
/* read from socket */
err = hsocket_read(stream->sock, &(dest[read]), size, 1, &status);
- if (status != size) {
- stream->err = herror_new("_http_input_stream_chunked_read",
- GENERAL_INVALID_PARAM, "This should never happens(size=%d)(status=%d)!", size, status);
- return -1;
- }
+ if (status != size) {
+ stream->err = herror_new("_http_input_stream_chunked_read",
+ GENERAL_INVALID_PARAM, "This should never happens(size=%d)(status=%d)!", size, status);
+ return -1;
+ }
if (err != H_OK) {
stream->err = err;
return -1;
@@ -361,7 +361,7 @@ int _http_input_stream_connection_closed_read(
http_input_stream_t *stream, byte_t *dest, int size)
{
int status;
- herror_t err;
+ herror_t err;
/* read from socket */
err = hsocket_read(stream->sock, dest, size, 0, &status );
@@ -386,7 +386,7 @@ int _http_input_stream_file_read(
readed = fread(dest, 1, size, stream->fd);
if (readed == -1) {
- stream->err = herror_new("_http_input_stream_file_read",
+ stream->err = herror_new("_http_input_stream_file_read",
HSOCKET_ERROR_RECEIVE, "fread() returned -1");
return -1;
}
@@ -453,7 +453,7 @@ int http_input_stream_read(http_input_stream_t *stream,
readed=_http_input_stream_file_read(stream, dest, size);
break;
default:
- stream->err = herror_new("http_input_stream_read",
+ stream->err = herror_new("http_input_stream_read",
STREAM_ERROR_INVALID_TYPE, "%d is invalid stream type", stream->type);
return -1;
}
diff --git a/nanohttp/nanohttp-stream.h b/nanohttp/nanohttp-stream.h
index b8b345c..d0a234a 100755
--- a/nanohttp/nanohttp-stream.h
+++ b/nanohttp/nanohttp-stream.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-stream.h,v 1.4 2004/10/29 09:27:05 snowdrop Exp $
+ * $Id: nanohttp-stream.h,v 1.5 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -93,11 +93,11 @@ typedef struct http_input_stream
int received;
int content_length;
int chunk_size;
- byte_t connection_closed;
-
+ byte_t connection_closed;
+
/* file handling */
- FILE *fd;
- char filename[255];
+ FILE *fd;
+ char filename[255];
int deleteOnExit; /* default is 0 */
}http_input_stream_t;