summaryrefslogtreecommitdiffstats
path: root/nanohttp/nanohttp-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'nanohttp/nanohttp-common.c')
-rw-r--r--nanohttp/nanohttp-common.c342
1 files changed, 171 insertions, 171 deletions
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);