summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xexamples/csoap/echoattachments-client.c120
-rwxr-xr-xexamples/csoap/echoattachments-server.c36
-rw-r--r--examples/csoap/simpleclient.c42
-rw-r--r--examples/csoap/simpleserver.c43
-rw-r--r--examples/csoap/soapclient.c101
-rw-r--r--libcsoap/soap-client.c146
-rw-r--r--libcsoap/soap-client.h14
-rwxr-xr-xlibcsoap/soap-ctx.c62
-rwxr-xr-xlibcsoap/soap-ctx.h18
-rw-r--r--libcsoap/soap-env.c315
-rw-r--r--libcsoap/soap-env.h66
-rw-r--r--libcsoap/soap-fault.c42
-rw-r--r--libcsoap/soap-fault.h8
-rw-r--r--libcsoap/soap-router.c38
-rw-r--r--libcsoap/soap-router.h16
-rw-r--r--libcsoap/soap-server.c261
-rw-r--r--libcsoap/soap-server.h10
-rw-r--r--libcsoap/soap-service.c38
-rw-r--r--libcsoap/soap-service.h14
-rw-r--r--libcsoap/soap-xml.c48
-rw-r--r--libcsoap/soap-xml.h16
-rw-r--r--nanohttp/nanohttp-client.c266
-rw-r--r--nanohttp/nanohttp-client.h51
-rw-r--r--nanohttp/nanohttp-common.c382
-rw-r--r--nanohttp/nanohttp-common.h84
-rwxr-xr-xnanohttp/nanohttp-mime.c334
-rwxr-xr-xnanohttp/nanohttp-mime.h8
-rwxr-xr-xnanohttp/nanohttp-request.c84
-rwxr-xr-xnanohttp/nanohttp-request.h6
-rwxr-xr-xnanohttp/nanohttp-response.c88
-rwxr-xr-xnanohttp/nanohttp-response.h6
-rw-r--r--nanohttp/nanohttp-server.c495
-rw-r--r--nanohttp/nanohttp-server.h49
-rw-r--r--nanohttp/nanohttp-socket.c278
-rw-r--r--nanohttp/nanohttp-socket.h30
-rw-r--r--nanohttp/nanohttp-ssl.c192
-rw-r--r--nanohttp/nanohttp-ssl.h10
-rwxr-xr-xnanohttp/nanohttp-stream.c217
-rwxr-xr-xnanohttp/nanohttp-stream.h32
39 files changed, 2016 insertions, 2050 deletions
diff --git a/examples/csoap/echoattachments-client.c b/examples/csoap/echoattachments-client.c
index 353e1d2..b3dd3f8 100755
--- a/examples/csoap/echoattachments-client.c
+++ b/examples/csoap/echoattachments-client.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: echoattachments-client.c,v 1.9 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: echoattachments-client.c,v 1.10 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -32,78 +32,78 @@ static const char *method = "echo";
void
-compareFiles (const char *received, const char *sent)
+compareFiles(const char *received, const char *sent)
{
FILE *f1, *f2;
char c1, c2;
long s1, s2;
- printf ("Opening received file to compare: '%s'\n", received);
- f1 = fopen (received, "r");
+ printf("Opening received file to compare: '%s'\n", received);
+ f1 = fopen(received, "r");
if (!f1)
{
- fprintf (stderr, "Can not open '%s'\n", received);
+ fprintf(stderr, "Can not open '%s'\n", received);
return;
}
- printf ("Opening sent file to compare: '%s'\n", sent);
- f2 = fopen (sent, "r");
+ printf("Opening sent file to compare: '%s'\n", sent);
+ f2 = fopen(sent, "r");
if (!f2)
{
- fprintf (stderr, "Can not open '%s'\n", sent);
- fclose (f1);
+ fprintf(stderr, "Can not open '%s'\n", sent);
+ fclose(f1);
return;
}
- fseek (f1, 0, SEEK_END);
- fseek (f2, 0, SEEK_END);
+ fseek(f1, 0, SEEK_END);
+ fseek(f2, 0, SEEK_END);
- s1 = ftell (f1);
- s2 = ftell (f2);
+ s1 = ftell(f1);
+ s2 = ftell(f2);
- fseek (f1, 0, SEEK_SET);
- fseek (f2, 0, SEEK_SET);
+ fseek(f1, 0, SEEK_SET);
+ fseek(f2, 0, SEEK_SET);
if (s1 > s2)
{
- printf ("ERROR: files are not equal! Received file is bigger\n");
- fclose (f1);
- fclose (f2);
+ printf("ERROR: files are not equal! Received file is bigger\n");
+ fclose(f1);
+ fclose(f2);
return;
}
else if (s2 > s1)
{
- printf ("ERROR: files are not equal! Sent file is bigger\n");
- fclose (f1);
- fclose (f2);
+ printf("ERROR: files are not equal! Sent file is bigger\n");
+ fclose(f1);
+ fclose(f2);
return;
}
- while (feof (f1))
+ while (feof(f1))
{
- c1 = fgetc (f1);
- c2 = fgetc (f2);
+ c1 = fgetc(f1);
+ c2 = fgetc(f2);
if (c1 != c2)
{
- printf ("ERROR: files are not equal! Byte compare failed\n");
- fclose (f1);
- fclose (f2);
+ printf("ERROR: files are not equal! Byte compare failed\n");
+ fclose(f1);
+ fclose(f2);
break;
}
}
- printf ("OK: files are equal!\n");
- fclose (f1);
- fclose (f2);
+ printf("OK: files are equal!\n");
+ fclose(f1);
+ fclose(f2);
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
SoapCtx *ctx, *ctx2;
char href[MAX_HREF_SIZE];
@@ -113,86 +113,86 @@ main (int argc, char *argv[])
if (argc < 2)
{
- fprintf (stderr, "usage: %s <filename> [url]\n", argv[0]);
- exit (1);
+ fprintf(stderr, "usage: %s <filename> [url]\n", argv[0]);
+ exit(1);
}
/*
Initialize soap client */
- err = soap_client_init_args (argc, argv);
+ err = soap_client_init_args(argc, argv);
if (err != H_OK)
{
- log_error4 ("[%d] %s():%s ", herror_code (err), herror_func (err),
- herror_message (err));
- herror_release (err);
+ log_error4("[%d] %s():%s ", herror_code(err), herror_func(err),
+ herror_message(err));
+ herror_release(err);
return 1;
}
/*
Create a context object */
- err = soap_ctx_new_with_method (urn, method, &ctx);
+ err = soap_ctx_new_with_method(urn, method, &ctx);
if (err != H_OK)
{
- log_error4 ("[%d] %s():%s ", herror_code (err), herror_func (err),
- herror_message (err));
- herror_release (err);
+ log_error4("[%d] %s():%s ", herror_code(err), herror_func(err),
+ herror_message(err));
+ herror_release(err);
return 1;
}
/*
Add file to the context */
- err = soap_ctx_add_file (ctx, argv[1], "application/octet-stream", href);
+ err = soap_ctx_add_file(ctx, argv[1], "application/octet-stream", href);
if (err != H_OK)
{
- log_error4 ("%s():%s [%d]", herror_func (err), herror_message (err),
- herror_code (err));
- herror_release (err);
+ log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
+ herror_code(err));
+ herror_release(err);
return 1;
}
/*
Add file reference to the envelope */
- soap_env_add_attachment (ctx->env, "source", href);
+ soap_env_add_attachment(ctx->env, "source", href);
/*
Send soap request to the server */
- printf ("sending request ...\n");
+ printf("sending request ...\n");
if (argc > 2)
- err = soap_client_invoke (ctx, &ctx2, argv[2], "");
+ err = soap_client_invoke(ctx, &ctx2, argv[2], "");
else
- err = soap_client_invoke (ctx, &ctx2, url, "");
+ err = soap_client_invoke(ctx, &ctx2, url, "");
if (err != H_OK)
{
- log_error4 ("%s():%s [%d]", herror_func (err), herror_message (err),
- herror_code (err));
- herror_release (err);
+ log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
+ herror_code(err));
+ herror_release(err);
return 1;
}
/*
Handle response (just print to the screen) */
- fault = soap_env_get_fault (ctx2->env);
+ fault = soap_env_get_fault(ctx2->env);
if (fault)
{
- soap_xml_doc_print (ctx2->env->root->doc);
+ soap_xml_doc_print(ctx2->env->root->doc);
}
else if (ctx2->attachments)
{
- compareFiles (ctx2->attachments->parts->filename, argv[1]);
+ compareFiles(ctx2->attachments->parts->filename, argv[1]);
}
else
{
- printf ("No attachments!");
- soap_xml_doc_print (ctx2->env->root->doc);
+ printf("No attachments!");
+ soap_xml_doc_print(ctx2->env->root->doc);
}
/*
Clean up */
- soap_ctx_free (ctx2);
- soap_ctx_free (ctx);
+ soap_ctx_free(ctx2);
+ soap_ctx_free(ctx);
- soap_client_destroy ();
+ soap_client_destroy();
return 0;
}
diff --git a/examples/csoap/echoattachments-server.c b/examples/csoap/echoattachments-server.c
index 151d020..4b37aa8 100755
--- a/examples/csoap/echoattachments-server.c
+++ b/examples/csoap/echoattachments-server.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: echoattachments-server.c,v 1.6 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: echoattachments-server.c,v 1.7 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -32,14 +32,14 @@ static const char *method = "echo";
herror_t
-echo_attachments (SoapCtx * req, SoapCtx * res)
+echo_attachments(SoapCtx * req, SoapCtx * res)
{
herror_t err;
part_t *part;
char href[MAX_HREF_SIZE];
- err = soap_env_new_with_response (req->env, &res->env);
+ err = soap_env_new_with_response(req->env, &res->env);
if (err != H_OK)
{
return err;
@@ -49,8 +49,8 @@ echo_attachments (SoapCtx * req, SoapCtx * res)
{
for (part = req->attachments->parts; part != NULL; part = part->next)
{
- soap_ctx_add_file (res, part->filename, part->content_type, href);
- soap_env_add_attachment (res->env, "echoFile", href);
+ soap_ctx_add_file(res, part->filename, part->content_type, href);
+ soap_env_add_attachment(res->env, "echoFile", href);
}
}
@@ -59,31 +59,31 @@ echo_attachments (SoapCtx * req, SoapCtx * res)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
herror_t err;
SoapRouter *router;
- log_set_level (HLOG_VERBOSE);
+ log_set_level(HLOG_VERBOSE);
- err = soap_server_init_args (argc, argv);
+ err = soap_server_init_args(argc, argv);
if (err != H_OK)
{
- log_error4 ("%s():%s [%d]", herror_func (err), herror_message (err),
- herror_code (err));
- herror_release (err);
+ log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
+ herror_code(err));
+ herror_release(err);
return 1;
}
- router = soap_router_new ();
- soap_router_register_service (router, echo_attachments, method, urn);
- soap_server_register_router (router, url);
+ router = soap_router_new();
+ soap_router_register_service(router, echo_attachments, method, urn);
+ soap_server_register_router(router, url);
- log_info1 ("send SIGTERM to shutdown");
- soap_server_run ();
+ log_info1("send SIGTERM to shutdown");
+ soap_server_run();
- log_info1 ("shutting down\n");
- soap_server_destroy ();
+ log_info1("shutting down\n");
+ soap_server_destroy();
return 0;
}
diff --git a/examples/csoap/simpleclient.c b/examples/csoap/simpleclient.c
index 4e0e843..6ae206b 100644
--- a/examples/csoap/simpleclient.c
+++ b/examples/csoap/simpleclient.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: simpleclient.c,v 1.10 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: simpleclient.c,v 1.11 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -30,50 +30,50 @@ static const char *method = "sayHello";
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
SoapCtx *ctx, *ctx2;
herror_t err;
/* log_set_level(HLOG_VERBOSE); */
- err = soap_client_init_args (argc, argv);
+ err = soap_client_init_args(argc, argv);
if (err != H_OK)
{
- log_error4 ("%s():%s [%d]", herror_func (err), herror_message (err),
- herror_code (err));
- herror_release (err);
+ log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
+ herror_code(err));
+ herror_release(err);
return 1;
}
- err = soap_ctx_new_with_method (urn, method, &ctx);
+ err = soap_ctx_new_with_method(urn, method, &ctx);
if (err != H_OK)
{
- log_error4 ("%s():%s [%d]", herror_func (err), herror_message (err),
- herror_code (err));
- herror_release (err);
+ log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
+ herror_code(err));
+ herror_release(err);
return 1;
}
- soap_env_add_item (ctx->env, "xsd:string", "name", "Jonny B. Good");
+ soap_env_add_item(ctx->env, "xsd:string", "name", "Jonny B. Good");
if (argc > 1)
- err = soap_client_invoke (ctx, &ctx2, argv[1], "");
+ err = soap_client_invoke(ctx, &ctx2, argv[1], "");
else
- err = soap_client_invoke (ctx, &ctx2, url, "");
+ err = soap_client_invoke(ctx, &ctx2, url, "");
if (err != H_OK)
{
- log_error4 ("[%d] %s(): %s ", herror_code (err), herror_func (err),
- herror_message (err));
- herror_release (err);
- soap_ctx_free (ctx);
+ log_error4("[%d] %s(): %s ", herror_code(err), herror_func(err),
+ herror_message(err));
+ herror_release(err);
+ soap_ctx_free(ctx);
return 1;
}
- soap_xml_doc_print (ctx2->env->root->doc);
- soap_ctx_free (ctx2);
- soap_ctx_free (ctx);
+ soap_xml_doc_print(ctx2->env->root->doc);
+ soap_ctx_free(ctx2);
+ soap_ctx_free(ctx);
- soap_client_destroy ();
+ soap_client_destroy();
return 0;
}
diff --git a/examples/csoap/simpleserver.c b/examples/csoap/simpleserver.c
index b0d37f9..9edd86f 100644
--- a/examples/csoap/simpleserver.c
+++ b/examples/csoap/simpleserver.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: simpleserver.c,v 1.15 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: simpleserver.c,v 1.16 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -30,7 +30,7 @@ static const char *method = "sayHello";
herror_t
-say_hello (SoapCtx * req, SoapCtx * res)
+say_hello(SoapCtx * req, SoapCtx * res)
{
herror_t err;
@@ -38,21 +38,20 @@ say_hello (SoapCtx * req, SoapCtx * res)
xmlNodePtr method, node;
- err = soap_env_new_with_response (req->env, &res->env);
+ err = soap_env_new_with_response(req->env, &res->env);
if (err != H_OK)
{
return err;
}
- method = soap_env_get_method (req->env);
- node = soap_xml_get_children (method);
+ method = soap_env_get_method(req->env);
+ node = soap_xml_get_children(method);
while (node)
{
- name =
- (char *) xmlNodeListGetString (node->doc, node->xmlChildrenNode, 1);
- soap_env_add_itemf (res->env, "xsd:string", "echo", "Hello '%s'", name);
- node = soap_xml_get_next (node);
+ name = (char *) xmlNodeListGetString(node->doc, node->xmlChildrenNode, 1);
+ soap_env_add_itemf(res->env, "xsd:string", "echo", "Hello '%s'", name);
+ node = soap_xml_get_next(node);
}
return H_OK;
@@ -60,32 +59,32 @@ say_hello (SoapCtx * req, SoapCtx * res)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
herror_t err;
SoapRouter *router;
- log_set_level (HLOG_INFO);
+ log_set_level(HLOG_INFO);
- err = soap_server_init_args (argc, argv);
+ err = soap_server_init_args(argc, argv);
if (err != H_OK)
{
- log_error4 ("%s():%s [%d]", herror_func (err), herror_message (err),
- herror_code (err));
- herror_release (err);
+ log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
+ herror_code(err));
+ herror_release(err);
return 1;
}
- router = soap_router_new ();
- soap_router_register_service (router, say_hello, method, urn);
- soap_server_register_router (router, url);
+ router = soap_router_new();
+ soap_router_register_service(router, say_hello, method, urn);
+ soap_server_register_router(router, url);
- log_info1 ("send SIGTERM to shutdown");
- soap_server_run ();
+ log_info1("send SIGTERM to shutdown");
+ soap_server_run();
- log_info1 ("shutting down\n");
- soap_server_destroy ();
+ log_info1("shutting down\n");
+ soap_server_destroy();
return 0;
}
diff --git a/examples/csoap/soapclient.c b/examples/csoap/soapclient.c
index 826d518..7f96364 100644
--- a/examples/csoap/soapclient.c
+++ b/examples/csoap/soapclient.c
@@ -11,7 +11,7 @@
// stripcslashes - unescapes the string
void
-stripcslashes (char *str, int *len)
+stripcslashes(char *str, int *len)
{
char *source, *target, *end;
int nlen = *len, i;
@@ -57,10 +57,10 @@ stripcslashes (char *str, int *len)
nlen--;
break;
case 'x':
- if (source + 1 < end && isxdigit ((int) (*(source + 1))))
+ if (source + 1 < end && isxdigit((int) (*(source + 1))))
{
numtmp[0] = *++source;
- if (source + 1 < end && isxdigit ((int) (*(source + 1))))
+ if (source + 1 < end && isxdigit((int) (*(source + 1))))
{
numtmp[1] = *++source;
numtmp[2] = '\0';
@@ -71,7 +71,7 @@ stripcslashes (char *str, int *len)
numtmp[1] = '\0';
nlen -= 2;
}
- *target++ = (char) strtol (numtmp, NULL, 16);
+ *target++ = (char) strtol(numtmp, NULL, 16);
break;
}
default:
@@ -83,7 +83,7 @@ stripcslashes (char *str, int *len)
if (i)
{
numtmp[i] = '\0';
- *target++ = (char) strtol (numtmp, NULL, 8);
+ *target++ = (char) strtol(numtmp, NULL, 8);
nlen -= i;
source--;
}
@@ -108,24 +108,24 @@ stripcslashes (char *str, int *len)
// ParseLine - gets a line, finds the commas, unescapes the value and adds it
// to the SOAP request
void
-ParseLine (SoapCtx * ctx, char *Buffer, int LineLen)
+ParseLine(SoapCtx * ctx, char *Buffer, int LineLen)
{
// if wrong line length, return
if (LineLen <= 0)
return;
// alloc buffer for the line, copy it
- char *Line = (char *) malloc (LineLen + 1);
- memcpy (Line, Buffer, LineLen);
+ char *Line = (char *) malloc(LineLen + 1);
+ memcpy(Line, Buffer, LineLen);
Line[LineLen] = '\0';
// find first comma
- char *FirstCommaPos = strchr (Line, ',');
+ char *FirstCommaPos = strchr(Line, ',');
if (!FirstCommaPos)
return;
// find second comma
- char *SecondCommaPos = strchr (FirstCommaPos + 1, ',');
+ char *SecondCommaPos = strchr(FirstCommaPos + 1, ',');
if (!SecondCommaPos)
return;
@@ -134,29 +134,29 @@ ParseLine (SoapCtx * ctx, char *Buffer, int LineLen)
SecondCommaPos[0] = '\0';
// unescape
- int len = strlen (SecondCommaPos + 1);
- stripcslashes (SecondCommaPos + 1, &len);
+ int len = strlen(SecondCommaPos + 1);
+ stripcslashes(SecondCommaPos + 1, &len);
// add to the request
- soap_env_add_item (ctx->env, Line, FirstCommaPos + 1, SecondCommaPos + 1);
+ soap_env_add_item(ctx->env, Line, FirstCommaPos + 1, SecondCommaPos + 1);
// free the buffer
- free (Line);
+ free(Line);
}
void
-printusage (char *FileName)
+printusage(char *FileName)
{
- printf ("Usage: %s [URL] [URN] [SOAPMETHOD]\n\n", FileName);
- printf ("- [URL] is the url of the SOAP server.\n");
- printf ("- [URN] is the namespace for the method/webservice.\n");
- printf ("- [SOAPMETHOD] is the method to call.\n\n");
- printf ("All commandline paramaters are mandatory.\n\n");
+ printf("Usage: %s [URL] [URN] [SOAPMETHOD]\n\n", FileName);
+ printf("- [URL] is the url of the SOAP server.\n");
+ printf("- [URN] is the namespace for the method/webservice.\n");
+ printf("- [SOAPMETHOD] is the method to call.\n\n");
+ printf("All commandline paramaters are mandatory.\n\n");
printf
("%s reads the parameters for the SOAPMETHOD from STDIN as a comma-separated list\n\n",
FileName);
- printf ("Each line is one parameter and has the following form:\n\n");
- printf ("xsd:[TYPE],[PARAMETERNAME],[PARAMETERVALUE]\n\n");
+ printf("Each line is one parameter and has the following form:\n\n");
+ printf("xsd:[TYPE],[PARAMETERNAME],[PARAMETERVALUE]\n\n");
printf
("- [TYPE] is a basic type for SOAP or a complex type defined by the WSDL.\n");
printf
@@ -166,7 +166,7 @@ printusage (char *FileName)
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
SoapCtx *ctx, *ctx2;
herror_t err;
@@ -174,27 +174,27 @@ main (int argc, char *argv[])
// check the parameter count
if (argc != 4)
{
- printusage (argv[0]);
+ printusage(argv[0]);
return 1;
}
// init cSOAP client
- err = soap_client_init_args (argc, argv);
+ err = soap_client_init_args(argc, argv);
if (err != H_OK)
{
- log_error4 ("%s():%s [%d]", herror_func (err),
- herror_message (err), herror_code (err));
- herror_release (err);
+ log_error4("%s():%s [%d]", herror_func(err),
+ herror_message(err), herror_code(err));
+ herror_release(err);
return 1;
}
// create a SoapCtx object
- err = soap_ctx_new_with_method (argv[2], argv[3], &ctx);
+ err = soap_ctx_new_with_method(argv[2], argv[3], &ctx);
if (err != H_OK)
{
- log_error4 ("%s():%s [%d]", herror_func (err),
- herror_message (err), herror_code (err));
- herror_release (err);
+ log_error4("%s():%s [%d]", herror_func(err),
+ herror_message(err), herror_code(err));
+ herror_release(err);
return 1;
}
@@ -203,51 +203,50 @@ main (int argc, char *argv[])
int bytes_read, bytes_left;
// read from stdin until EOF
- while (!feof (stdin))
+ while (!feof(stdin))
{
- bytes_read = fread (Buffer, 1, MAX_LINE_LENGTH, stdin);
+ bytes_read = fread(Buffer, 1, MAX_LINE_LENGTH, stdin);
// pass each line into ParseLine
char *EndLinePos;
- while (EndLinePos = strchr (Buffer, '\n'))
+ while (EndLinePos = strchr(Buffer, '\n'))
{
- ParseLine (ctx, Buffer, EndLinePos - Buffer);
- memmove (Buffer, EndLinePos + 1, bytes_read - (EndLinePos -
- Buffer + 1));
+ ParseLine(ctx, Buffer, EndLinePos - Buffer);
+ memmove(Buffer, EndLinePos + 1, bytes_read - (EndLinePos - Buffer + 1));
Buffer[bytes_read - (EndLinePos - Buffer + 1)] = '\0';
}
// no '\n' found in the whole Buffer, that means line's too
- long bytes_left = strlen (Buffer);
+ long bytes_left = strlen(Buffer);
if (bytes_left == MAX_LINE_LENGTH)
{
- log_error1 ("The parameter line is too long.");
- herror_release (err);
- soap_ctx_free (ctx);
+ log_error1("The parameter line is too long.");
+ herror_release(err);
+ soap_ctx_free(ctx);
return 1;
}
}
// invoke
- err = soap_client_invoke (ctx, &ctx2, argv[1], "");
+ err = soap_client_invoke(ctx, &ctx2, argv[1], "");
if (err != H_OK)
{
- log_error4 ("[%d] %s(): %s ", herror_code (err),
- herror_func (err), herror_message (err));
- herror_release (err);
- soap_ctx_free (ctx);
+ log_error4("[%d] %s(): %s ", herror_code(err),
+ herror_func(err), herror_message(err));
+ herror_release(err);
+ soap_ctx_free(ctx);
return 1;
}
// print the result
- soap_xml_doc_print (ctx2->env->root->doc);
+ soap_xml_doc_print(ctx2->env->root->doc);
// free the objects
- soap_ctx_free (ctx2);
- soap_ctx_free (ctx);
+ soap_ctx_free(ctx2);
+ soap_ctx_free(ctx);
// destroy the cSOAP client
- soap_client_destroy ();
+ soap_client_destroy();
return 0;
}
diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c
index d1599bd..f7c38c2 100644
--- a/libcsoap/soap-client.c
+++ b/libcsoap/soap-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-client.c,v 1.20 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: soap-client.c,v 1.21 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -27,17 +27,17 @@
/*--------------------------------- */
static int _block_socket = 0;
-static herror_t _soap_client_build_result (hresponse_t * res, SoapEnv ** out);
+static herror_t _soap_client_build_result(hresponse_t * res, SoapEnv ** out);
/*--------------------------------- */
void
-soap_client_block_socket (int block)
+soap_client_block_socket(int block)
{
_block_socket = block;
}
int
-soap_client_get_blockmode ()
+soap_client_get_blockmode()
{
return _block_socket;
}
@@ -45,38 +45,38 @@ soap_client_get_blockmode ()
herror_t
-soap_client_init_args (int argc, char *argv[])
+soap_client_init_args(int argc, char *argv[])
{
- return httpc_init (argc, argv);
+ return httpc_init(argc, argv);
}
void
-soap_client_destroy ()
+soap_client_destroy()
{
- httpc_destroy ();
+ httpc_destroy();
}
static long
-_file_get_size (const char *filename)
+_file_get_size(const char *filename)
{
- FILE *f = fopen (filename, "r");
+ FILE *f = fopen(filename, "r");
long size;
if (!f)
return -1;
- fseek (f, 0, SEEK_END);
- size = ftell (f);
- fclose (f);
+ fseek(f, 0, SEEK_END);
+ size = ftell(f);
+ fclose(f);
return size;
}
herror_t
-soap_client_invoke (SoapCtx * call, SoapCtx ** response, const char *url,
- const char *soap_action)
+soap_client_invoke(SoapCtx * call, SoapCtx ** response, const char *url,
+ const char *soap_action)
{
/* Status */
herror_t status;
@@ -102,55 +102,55 @@ soap_client_invoke (SoapCtx * call, SoapCtx ** response, const char *url,
char href[MAX_HREF_SIZE];
/* Create buffer */
- buffer = xmlBufferCreate ();
- xmlNodeDump (buffer, call->env->root->doc, call->env->root, 1, 0);
- content = (char *) xmlBufferContent (buffer);
+ buffer = xmlBufferCreate();
+ xmlNodeDump(buffer, call->env->root->doc, call->env->root, 1, 0);
+ content = (char *) xmlBufferContent(buffer);
/* Transport via HTTP */
- conn = httpc_new ();
+ conn = httpc_new();
if (!conn)
{
- return herror_new ("soap_client_invoke", SOAP_ERROR_CLIENT_INIT,
- "Unable to create SOAP client!");
+ return herror_new("soap_client_invoke", SOAP_ERROR_CLIENT_INIT,
+ "Unable to create SOAP client!");
}
- conn->block = soap_client_get_blockmode ();
+ conn->block = soap_client_get_blockmode();
/* Set soap action */
if (soap_action != NULL)
{
- httpc_set_header (conn, "SoapAction", soap_action);
+ httpc_set_header(conn, "SoapAction", soap_action);
}
/* check for attachments */
if (!call->attachments)
{
/* content-type is always 'text/xml' */
- httpc_set_header (conn, HEADER_CONTENT_TYPE, "text/xml");
+ httpc_set_header(conn, HEADER_CONTENT_TYPE, "text/xml");
- sprintf (tmp, "%d", (int) strlen (content));
- httpc_set_header (conn, HEADER_CONTENT_LENGTH, tmp);
- status = httpc_post_begin (conn, url);
+ sprintf(tmp, "%d", (int) strlen(content));
+ httpc_set_header(conn, HEADER_CONTENT_LENGTH, tmp);
+ status = httpc_post_begin(conn, url);
if (status != H_OK)
{
- httpc_close_free (conn);
- xmlBufferFree (buffer);
+ httpc_close_free(conn);
+ xmlBufferFree(buffer);
return status;
}
- status = http_output_stream_write_string (conn->out, content);
+ status = http_output_stream_write_string(conn->out, content);
if (status != H_OK)
{
- httpc_close_free (conn);
- xmlBufferFree (buffer);
+ httpc_close_free(conn);
+ xmlBufferFree(buffer);
return status;
}
- status = httpc_post_end (conn, &res);
+ status = httpc_post_end(conn, &res);
if (status != H_OK)
{
- httpc_close_free (conn);
- xmlBufferFree (buffer);
+ httpc_close_free(conn);
+ xmlBufferFree(buffer);
return status;
}
}
@@ -158,72 +158,72 @@ soap_client_invoke (SoapCtx * call, SoapCtx ** response, const char *url,
{
/* Use chunked transport */
- httpc_set_header (conn, HEADER_TRANSFER_ENCODING,
- TRANSFER_ENCODING_CHUNKED);
+ httpc_set_header(conn, HEADER_TRANSFER_ENCODING,
+ TRANSFER_ENCODING_CHUNKED);
- sprintf (start_id, "289247829121218%d", counter++);
- status = httpc_mime_begin (conn, url, start_id, "", "text/xml");
+ sprintf(start_id, "289247829121218%d", counter++);
+ status = httpc_mime_begin(conn, url, start_id, "", "text/xml");
if (status != H_OK)
{
- httpc_close_free (conn);
- xmlBufferFree (buffer);
+ httpc_close_free(conn);
+ xmlBufferFree(buffer);
return status;
}
- status = httpc_mime_next (conn, start_id, "text/xml", "binary");
+ status = httpc_mime_next(conn, start_id, "text/xml", "binary");
if (status != H_OK)
{
- httpc_close_free (conn);
- xmlBufferFree (buffer);
+ httpc_close_free(conn);
+ xmlBufferFree(buffer);
return status;
}
- status = http_output_stream_write (conn->out, content, strlen (content));
+ status = http_output_stream_write(conn->out, content, strlen(content));
if (status != H_OK)
{
- httpc_close_free (conn);
- xmlBufferFree (buffer);
+ httpc_close_free(conn);
+ xmlBufferFree(buffer);
return status;
}
for (part = call->attachments->parts; part; part = part->next)
{
- status = httpc_mime_send_file (conn, part->id,
- part->content_type,
- part->transfer_encoding, part->filename);
+ status = httpc_mime_send_file(conn, part->id,
+ part->content_type,
+ part->transfer_encoding, part->filename);
if (status != H_OK)
{
- log_error2 ("Send file failed. Status:%d", status);
- httpc_close_free (conn);
- xmlBufferFree (buffer);
+ log_error2("Send file failed. Status:%d", status);
+ httpc_close_free(conn);
+ xmlBufferFree(buffer);
return status;
}
}
- status = httpc_mime_end (conn, &res);
+ status = httpc_mime_end(conn, &res);
if (status != H_OK)
{
- httpc_close_free (conn);
- xmlBufferFree (buffer);
+ httpc_close_free(conn);
+ xmlBufferFree(buffer);
return status;
}
}
/* Free buffer */
- xmlBufferFree (buffer);
+ xmlBufferFree(buffer);
/* Build result */
- status = _soap_client_build_result (res, &res_env);
+ status = _soap_client_build_result(res, &res_env);
if (status != H_OK)
{
- hresponse_free (res);
- httpc_close_free (conn);
+ hresponse_free(res);
+ httpc_close_free(conn);
return status;
}
/* Create Context */
- *response = soap_ctx_new (res_env);
+ *response = soap_ctx_new(res_env);
/* soap_ctx_add_files(*response, res->attachments);*/
if (res->attachments != NULL)
@@ -231,7 +231,7 @@ soap_client_invoke (SoapCtx * call, SoapCtx ** response, const char *url,
part = res->attachments->parts;
while (part)
{
- soap_ctx_add_file (*response, part->filename, part->content_type, href);
+ soap_ctx_add_file(*response, part->filename, part->content_type, href);
part->deleteOnExit = 0;
part = part->next;
}
@@ -244,33 +244,33 @@ soap_client_invoke (SoapCtx * call, SoapCtx ** response, const char *url,
}
- hresponse_free (res);
- httpc_close_free (conn);
+ hresponse_free(res);
+ httpc_close_free(conn);
return H_OK;
}
static herror_t
-_soap_client_build_result (hresponse_t * res, SoapEnv ** env)
+_soap_client_build_result(hresponse_t * res, SoapEnv ** env)
{
herror_t err;
- log_verbose2 ("Building result (%p)", res);
+ log_verbose2("Building result (%p)", res);
if (res == NULL)
- return herror_new ("_soap_client_build_result",
- GENERAL_INVALID_PARAM, "hresponse_t is NULL");
+ return herror_new("_soap_client_build_result",
+ GENERAL_INVALID_PARAM, "hresponse_t is NULL");
if (res->in == NULL)
- return herror_new ("_soap_client_build_result",
- GENERAL_INVALID_PARAM, "Empty response from server");
+ return herror_new("_soap_client_build_result",
+ GENERAL_INVALID_PARAM, "Empty response from server");
if (res->errcode != 200)
- return herror_new ("_soap_client_build_result",
- GENERAL_INVALID_PARAM, "HTTP code is not 200 OK");
+ return herror_new("_soap_client_build_result",
+ GENERAL_INVALID_PARAM, "HTTP code is not 200 OK");
- err = soap_env_new_from_stream (res->in, env);
+ err = soap_env_new_from_stream(res->in, env);
if (err != H_OK)
{
diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h
index 0795a29..43d1359 100644
--- a/libcsoap/soap-client.h
+++ b/libcsoap/soap-client.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-client.h,v 1.11 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-client.h,v 1.12 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -32,13 +32,13 @@
/**
Initializes the client side soap engine
*/
-herror_t soap_client_init_args (int argc, char *argv[]);
+herror_t soap_client_init_args(int argc, char *argv[]);
/**
Destroy the soap client module
*/
-void soap_client_destroy ();
+void soap_client_destroy();
/**
@@ -53,8 +53,8 @@ void soap_client_destroy ();
@returns H_OK if success
*/
-herror_t soap_client_invoke (SoapCtx * ctx, SoapCtx ** response,
- const char *url, const char *soap_action);
+herror_t soap_client_invoke(SoapCtx * ctx, SoapCtx ** response,
+ const char *url, const char *soap_action);
@@ -66,7 +66,7 @@ herror_t soap_client_invoke (SoapCtx * ctx, SoapCtx ** response,
@param block 1 to creat blocked sockets, 0 to create non
blocking sockets.
*/
-void soap_client_block_socket (int block);
-int soap_client_get_blockmode ();
+void soap_client_block_socket(int block);
+int soap_client_get_blockmode();
#endif
diff --git a/libcsoap/soap-ctx.c b/libcsoap/soap-ctx.c
index b2d1db2..7edefc3 100755
--- a/libcsoap/soap-ctx.c
+++ b/libcsoap/soap-ctx.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-ctx.c,v 1.6 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-ctx.c,v 1.7 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -26,9 +26,9 @@
#include <string.h>
SoapCtx *
-soap_ctx_new (SoapEnv * env) /* should only be used internally */
+soap_ctx_new(SoapEnv * env) /* should only be used internally */
{
- SoapCtx *ctx = (SoapCtx *) malloc (sizeof (SoapCtx));
+ SoapCtx *ctx = (SoapCtx *) malloc(sizeof(SoapCtx));
ctx->env = env;
ctx->attachments = NULL;
@@ -37,7 +37,7 @@ soap_ctx_new (SoapEnv * env) /* should only be used internally */
void
-soap_ctx_add_files (SoapCtx * ctx, attachments_t * attachments)
+soap_ctx_add_files(SoapCtx * ctx, attachments_t * attachments)
{
part_t *part;
char href[MAX_HREF_SIZE];
@@ -48,43 +48,43 @@ soap_ctx_add_files (SoapCtx * ctx, attachments_t * attachments)
part = attachments->parts;
while (part)
{
- soap_ctx_add_file (ctx, part->filename, part->content_type, href);
+ soap_ctx_add_file(ctx, part->filename, part->content_type, href);
part = part->next;
}
}
herror_t
-soap_ctx_add_file (SoapCtx * ctx, const char *filename,
- const char *content_type, char *dest_href)
+soap_ctx_add_file(SoapCtx * ctx, const char *filename,
+ const char *content_type, char *dest_href)
{
char cid[250];
char id[250];
part_t *part;
static int counter = 1;
- FILE *test = fopen (filename, "r");
+ FILE *test = fopen(filename, "r");
if (!test)
- return herror_new ("soap_ctx_add_file", FILE_ERROR_OPEN,
- "Can not open file '%s'", filename);
+ return herror_new("soap_ctx_add_file", FILE_ERROR_OPEN,
+ "Can not open file '%s'", filename);
- fclose (test);
+ fclose(test);
/* generate an id */
- sprintf (id, "005512345894583%d", counter++);
- sprintf (dest_href, "cid:%s", id);
- sprintf (cid, "<%s>", id);
+ sprintf(id, "005512345894583%d", counter++);
+ sprintf(dest_href, "cid:%s", id);
+ sprintf(cid, "<%s>", id);
/* add part to context */
- part = part_new (cid, filename, content_type, NULL, NULL);
+ part = part_new(cid, filename, content_type, NULL, NULL);
if (!ctx->attachments)
- ctx->attachments = attachments_new ();
- attachments_add_part (ctx->attachments, part);
+ ctx->attachments = attachments_new();
+ attachments_add_part(ctx->attachments, part);
return H_OK;
}
part_t *
-soap_ctx_get_file (SoapCtx * ctx, xmlNodePtr node)
+soap_ctx_get_file(SoapCtx * ctx, xmlNodePtr node)
{
xmlChar *prop;
char href[MAX_HREF_SIZE];
@@ -94,18 +94,18 @@ soap_ctx_get_file (SoapCtx * ctx, xmlNodePtr node)
if (!ctx->attachments)
return NULL;
- prop = xmlGetProp (node, "href");
+ prop = xmlGetProp(node, "href");
if (!prop)
return NULL;
- strcpy (href, (const char *) prop);
- if (!strncmp (href, "cid:", 4))
+ strcpy(href, (const char *) prop);
+ if (!strncmp(href, "cid:", 4))
{
for (part = ctx->attachments->parts; part; part = part->next)
{
- sprintf (buffer, "<%s>", href + 4);
- if (!strcmp (part->id, buffer))
+ sprintf(buffer, "<%s>", href + 4);
+ if (!strcmp(part->id, buffer))
return part;
}
@@ -114,7 +114,7 @@ soap_ctx_get_file (SoapCtx * ctx, xmlNodePtr node)
{
for (part = ctx->attachments->parts; part; part = part->next)
{
- if (!strcmp (part->location, href))
+ if (!strcmp(part->location, href))
return part;
}
@@ -124,29 +124,29 @@ soap_ctx_get_file (SoapCtx * ctx, xmlNodePtr node)
}
void
-soap_ctx_free (SoapCtx * ctx)
+soap_ctx_free(SoapCtx * ctx)
{
if (!ctx)
return;
if (ctx->attachments)
- attachments_free (ctx->attachments);
+ attachments_free(ctx->attachments);
if (ctx->env)
- soap_env_free (ctx->env);
+ soap_env_free(ctx->env);
- free (ctx);
+ free(ctx);
}
herror_t
-soap_ctx_new_with_method (const char *urn, const char *method, SoapCtx ** out)
+soap_ctx_new_with_method(const char *urn, const char *method, SoapCtx ** out)
{
SoapEnv *env;
herror_t err;
- err = soap_env_new_with_method (urn, method, &env);
+ err = soap_env_new_with_method(urn, method, &env);
if (err != H_OK)
return err;
- *out = soap_ctx_new (env);
+ *out = soap_ctx_new(env);
return H_OK;
}
diff --git a/libcsoap/soap-ctx.h b/libcsoap/soap-ctx.h
index 2df74b9..1baabba 100755
--- a/libcsoap/soap-ctx.h
+++ b/libcsoap/soap-ctx.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-ctx.h,v 1.6 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-ctx.h,v 1.7 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -41,7 +41,7 @@ typedef struct _SoapCtx
} SoapCtx;
-SoapCtx *soap_ctx_new (SoapEnv * env); /* should only be used internally */
+SoapCtx *soap_ctx_new(SoapEnv * env); /* should only be used internally */
/**
Returns the attached file if any found.
@@ -51,22 +51,22 @@ SoapCtx *soap_ctx_new (SoapEnv * env); /* should only be used internally */
@returns a part_t object of attachment was found, NULL otherwise.
*/
-part_t *soap_ctx_get_file (SoapCtx * ctx, xmlNodePtr node);
+part_t *soap_ctx_get_file(SoapCtx * ctx, xmlNodePtr node);
/**
Creates a new soap context object.
*/
-herror_t soap_ctx_new_with_method (const char *urn, const char *method,
- SoapCtx ** out);
+herror_t soap_ctx_new_with_method(const char *urn, const char *method,
+ SoapCtx ** out);
/* Size of destination dest_href should be MAX_HREF_SIZE */
-herror_t soap_ctx_add_file (SoapCtx * ctx, const char *filename,
- const char *content_type, char *dest_href);
+herror_t soap_ctx_add_file(SoapCtx * ctx, const char *filename,
+ const char *content_type, char *dest_href);
/*
Used internally. Will switch the deleteOnExit flag from the
given one to the added part.
*/
-void soap_ctx_add_files (SoapCtx * ctx, attachments_t * attachments);
-void soap_ctx_free (SoapCtx * ctx);
+void soap_ctx_add_files(SoapCtx * ctx, attachments_t * attachments);
+void soap_ctx_free(SoapCtx * ctx);
#endif
diff --git a/libcsoap/soap-env.c b/libcsoap/soap-env.c
index ec27137..5859dbc 100644
--- a/libcsoap/soap-env.c
+++ b/libcsoap/soap-env.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-env.c,v 1.11 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: soap-env.c,v 1.12 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -89,52 +89,52 @@ struct XmlNodeHolder
};
static
- void xmlbuilder_start_element (const xmlChar * element_name, int attr_count,
- xmlChar ** keys, xmlChar ** values,
- void *userData);
+ void xmlbuilder_start_element(const xmlChar * element_name, int attr_count,
+ xmlChar ** keys, xmlChar ** values,
+ void *userData);
static
- void xmlbuilder_characters (const xmlChar * element_name,
- const xmlChar * chars, void *userData);
+ void xmlbuilder_characters(const xmlChar * element_name,
+ const xmlChar * chars, void *userData);
static
- void xmlbuilder_end_element (const xmlChar * element_name, void *userData);
+ void xmlbuilder_end_element(const xmlChar * element_name, void *userData);
/* ---------------------------------------------------------------------------- */
herror_t
-soap_env_new_from_doc (xmlDocPtr doc, SoapEnv ** out)
+soap_env_new_from_doc(xmlDocPtr doc, SoapEnv ** out)
{
xmlNodePtr node;
SoapEnv *env;
if (doc == NULL)
{
- log_error1 ("Can not create xml document!");
- return herror_new ("soap_env_new_from_doc",
- GENERAL_INVALID_PARAM,
- "XML Document (xmlDocPtr) is NULL");
+ log_error1("Can not create xml document!");
+ return herror_new("soap_env_new_from_doc",
+ GENERAL_INVALID_PARAM,
+ "XML Document (xmlDocPtr) is NULL");
}
- node = xmlDocGetRootElement (doc);
+ node = xmlDocGetRootElement(doc);
if (node == NULL)
{
- log_error1 ("xml document is empty!");
- return herror_new ("soap_env_new_from_doc",
- XML_ERROR_EMPTY_DOCUMENT, "XML Document is empty!");
+ log_error1("xml document is empty!");
+ return herror_new("soap_env_new_from_doc",
+ XML_ERROR_EMPTY_DOCUMENT, "XML Document is empty!");
}
- env = (SoapEnv *) malloc (sizeof (SoapEnv));
+ env = (SoapEnv *) malloc(sizeof(SoapEnv));
/* set root */
env->root = node;
/* set method root set call->cur (current node) to <method>. xpath:
//Envelope/Body/ */
- node = soap_xml_get_children (env->root); /* Check for NULL ! */
- env->cur = soap_xml_get_children (node); /* Check for NULL ! */
+ node = soap_xml_get_children(env->root); /* Check for NULL ! */
+ env->cur = soap_xml_get_children(node); /* Check for NULL ! */
*out = env;
return H_OK;
@@ -144,24 +144,24 @@ soap_env_new_from_doc (xmlDocPtr doc, SoapEnv ** out)
herror_t
-soap_env_new_from_buffer (const char *buffer, SoapEnv ** out)
+soap_env_new_from_buffer(const char *buffer, SoapEnv ** out)
{
xmlDocPtr doc;
herror_t err;
if (buffer == NULL)
- return herror_new ("soap_env_new_from_buffer",
- GENERAL_INVALID_PARAM, "buffer (first param) is NULL");
+ return herror_new("soap_env_new_from_buffer",
+ GENERAL_INVALID_PARAM, "buffer (first param) is NULL");
- doc = xmlParseDoc (BAD_CAST buffer);
+ doc = xmlParseDoc(BAD_CAST buffer);
if (doc == NULL)
- return herror_new ("soap_env_new_from_buffer",
- XML_ERROR_PARSE, "Can not parse xml");
+ return herror_new("soap_env_new_from_buffer",
+ XML_ERROR_PARSE, "Can not parse xml");
- err = soap_env_new_from_doc (doc, out);
+ err = soap_env_new_from_doc(doc, out);
if (err != H_OK)
{
- xmlFreeDoc (doc);
+ xmlFreeDoc(doc);
}
return err;
@@ -169,23 +169,23 @@ soap_env_new_from_buffer (const char *buffer, SoapEnv ** out)
herror_t
-soap_env_new_with_fault (fault_code_t faultcode,
- const char *faultstring,
- const char *faultactor, const char *detail,
- SoapEnv ** out)
+soap_env_new_with_fault(fault_code_t faultcode,
+ const char *faultstring,
+ const char *faultactor, const char *detail,
+ SoapEnv ** out)
{
xmlDocPtr doc;
herror_t err;
- doc = soap_fault_build (faultcode, faultstring, faultactor, detail);
+ doc = soap_fault_build(faultcode, faultstring, faultactor, detail);
if (doc == NULL)
- return herror_new ("soap_env_new_with_fault",
- XML_ERROR_PARSE, "Can not parse fault xml");
+ return herror_new("soap_env_new_with_fault",
+ XML_ERROR_PARSE, "Can not parse fault xml");
- err = soap_env_new_from_doc (doc, out);
+ err = soap_env_new_from_doc(doc, out);
if (err != H_OK)
{
- xmlFreeDoc (doc);
+ xmlFreeDoc(doc);
}
return err;
@@ -193,7 +193,7 @@ soap_env_new_with_fault (fault_code_t faultcode,
herror_t
-soap_env_new_with_response (SoapEnv * request, SoapEnv ** out)
+soap_env_new_with_response(SoapEnv * request, SoapEnv ** out)
{
char urn[100];
char methodname[150];
@@ -201,27 +201,26 @@ soap_env_new_with_response (SoapEnv * request, SoapEnv ** out)
if (request == NULL)
{
- return herror_new ("soap_env_new_with_response",
- GENERAL_INVALID_PARAM,
- "request (first param) is NULL");
+ return herror_new("soap_env_new_with_response",
+ GENERAL_INVALID_PARAM, "request (first param) is NULL");
}
if (request->root == NULL)
{
- return herror_new ("soap_env_new_with_response",
- GENERAL_INVALID_PARAM,
- "request (first param) has no xml structure");
+ return herror_new("soap_env_new_with_response",
+ GENERAL_INVALID_PARAM,
+ "request (first param) has no xml structure");
}
- if (!soap_env_find_methodname (request, methodname))
+ if (!soap_env_find_methodname(request, methodname))
{
- return herror_new ("soap_env_new_with_response",
- GENERAL_INVALID_PARAM,
- "Method name '%s' not found in request",
- SAVE_STR (methodname));
+ return herror_new("soap_env_new_with_response",
+ GENERAL_INVALID_PARAM,
+ "Method name '%s' not found in request",
+ SAVE_STR(methodname));
}
- if (!soap_env_find_urn (request, urn))
+ if (!soap_env_find_urn(request, urn))
{
/* here we have no chance to find out the namespace */
@@ -229,76 +228,74 @@ soap_env_new_with_response (SoapEnv * request, SoapEnv ** out)
urn[0] = '\0';
}
- sprintf (methodname2, "%sResponse", methodname);
- return soap_env_new_with_method (urn, methodname2, out);
+ sprintf(methodname2, "%sResponse", methodname);
+ return soap_env_new_with_method(urn, methodname2, out);
}
herror_t
-soap_env_new_with_method (const char *urn, const char *method, SoapEnv ** out)
+soap_env_new_with_method(const char *urn, const char *method, SoapEnv ** out)
{
xmlDocPtr env;
xmlChar buffer[1054];
- log_verbose2 ("URN = '%s'", urn);
- log_verbose2 ("Method = '%s'", method);
+ log_verbose2("URN = '%s'", urn);
+ log_verbose2("Method = '%s'", method);
- if (!strcmp (urn, ""))
+ if (!strcmp(urn, ""))
{
#ifdef USE_XMLSTRING
- xmlStrPrintf (buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_EMPTY_TARGET_,
- soap_env_ns, soap_env_enc, soap_xsi_ns,
- soap_xsd_ns, BAD_CAST method, BAD_CAST urn,
- BAD_CAST method);
+ xmlStrPrintf(buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_EMPTY_TARGET_,
+ soap_env_ns, soap_env_enc, soap_xsi_ns,
+ soap_xsd_ns, BAD_CAST method, BAD_CAST urn, BAD_CAST method);
#else
- sprintf (buffer, _SOAP_MSG_TEMPLATE_EMPTY_TARGET_,
- soap_env_ns, soap_env_enc, soap_xsi_ns,
- soap_xsd_ns, method, urn, method);
+ sprintf(buffer, _SOAP_MSG_TEMPLATE_EMPTY_TARGET_,
+ soap_env_ns, soap_env_enc, soap_xsi_ns,
+ soap_xsd_ns, method, urn, method);
#endif
}
else
{
#ifdef USE_XMLSTRING
- xmlStrPrintf (buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_,
- soap_env_ns, soap_env_enc, soap_xsi_ns,
- soap_xsd_ns, BAD_CAST method, BAD_CAST urn,
- BAD_CAST method);
+ xmlStrPrintf(buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_,
+ soap_env_ns, soap_env_enc, soap_xsi_ns,
+ soap_xsd_ns, BAD_CAST method, BAD_CAST urn, BAD_CAST method);
#else
- sprintf (buffer, _SOAP_MSG_TEMPLATE_,
- soap_env_ns, soap_env_enc, soap_xsi_ns,
- soap_xsd_ns, method, urn, method);
+ sprintf(buffer, _SOAP_MSG_TEMPLATE_,
+ soap_env_ns, soap_env_enc, soap_xsi_ns,
+ soap_xsd_ns, method, urn, method);
#endif
}
- env = xmlParseDoc (buffer);
+ env = xmlParseDoc(buffer);
if (!env)
- return herror_new ("soap_env_new_with_method",
- XML_ERROR_PARSE, "Can not parse xml");
+ return herror_new("soap_env_new_with_method",
+ XML_ERROR_PARSE, "Can not parse xml");
- return soap_env_new_from_doc (env, out);
+ return soap_env_new_from_doc(env, out);
}
static int
-_soap_env_xml_io_read (void *ctx, char *buffer, int len)
+_soap_env_xml_io_read(void *ctx, char *buffer, int len)
{
int readed;
http_input_stream_t *in = (http_input_stream_t *) ctx;
- if (!http_input_stream_is_ready (in))
+ if (!http_input_stream_is_ready(in))
return 0;
- readed = http_input_stream_read (in, buffer, len);
+ readed = http_input_stream_read(in, buffer, len);
if (readed == -1)
return 0;
return readed;
}
static int
-_soap_env_xml_io_close (void *ctx)
+_soap_env_xml_io_close(void *ctx)
{
/* do nothing */
return 0;
@@ -306,44 +303,44 @@ _soap_env_xml_io_close (void *ctx)
herror_t
-soap_env_new_from_stream (http_input_stream_t * in, SoapEnv ** out)
+soap_env_new_from_stream(http_input_stream_t * in, SoapEnv ** out)
{
xmlDocPtr doc;
herror_t err;
- doc = xmlReadIO (_soap_env_xml_io_read,
- _soap_env_xml_io_close, in, "", NULL, 0);
+ doc = xmlReadIO(_soap_env_xml_io_read,
+ _soap_env_xml_io_close, in, "", NULL, 0);
if (in->err != H_OK)
return in->err;
if (doc == NULL)
- return herror_new ("soap_env_new_from_stream",
- XML_ERROR_PARSE, "Trying to parse not valid xml");
- err = soap_env_new_from_doc (doc, out);
+ return herror_new("soap_env_new_from_stream",
+ XML_ERROR_PARSE, "Trying to parse not valid xml");
+ err = soap_env_new_from_doc(doc, out);
return err;
}
xmlNodePtr
-soap_env_add_item (SoapEnv * call, const char *type,
- const char *name, const char *value)
+soap_env_add_item(SoapEnv * call, const char *type,
+ const char *name, const char *value)
{
xmlNodePtr newnode;
- newnode = xmlNewTextChild (call->cur, NULL, BAD_CAST name, BAD_CAST value);
+ newnode = xmlNewTextChild(call->cur, NULL, BAD_CAST name, BAD_CAST value);
if (newnode == NULL)
{
- log_error1 ("Can not create new xml node");
+ log_error1("Can not create new xml node");
return NULL;
}
if (type)
{
- if (!xmlNewProp (newnode, BAD_CAST "xsi:type", BAD_CAST type))
+ if (!xmlNewProp(newnode, BAD_CAST "xsi:type", BAD_CAST type))
{
- log_error1 ("Can not create new xml attribute");
+ log_error1("Can not create new xml attribute");
return NULL;
}
}
@@ -354,41 +351,41 @@ soap_env_add_item (SoapEnv * call, const char *type,
xmlNodePtr
-soap_env_add_itemf (SoapEnv * call, const char *type,
- const char *name, const char *format, ...)
+soap_env_add_itemf(SoapEnv * call, const char *type,
+ const char *name, const char *format, ...)
{
va_list ap;
char buffer[1054];
- va_start (ap, format);
- vsprintf (buffer, format, ap);
- va_end (ap);
+ va_start(ap, format);
+ vsprintf(buffer, format, ap);
+ va_end(ap);
- return soap_env_add_item (call, type, name, buffer);
+ return soap_env_add_item(call, type, name, buffer);
}
xmlNodePtr
-soap_env_add_attachment (SoapEnv * call, const char *name, const char *href)
+soap_env_add_attachment(SoapEnv * call, const char *name, const char *href)
{
xmlNodePtr newnode;
- newnode = xmlNewTextChild (call->cur, NULL, BAD_CAST name, BAD_CAST "");
+ newnode = xmlNewTextChild(call->cur, NULL, BAD_CAST name, BAD_CAST "");
if (newnode == NULL)
{
- log_error1 ("Can not create new xml node");
+ log_error1("Can not create new xml node");
return NULL;
}
if (href)
{
- if (!xmlNewProp (newnode, BAD_CAST "href", BAD_CAST href))
+ if (!xmlNewProp(newnode, BAD_CAST "href", BAD_CAST href))
{
- log_error1 ("Can not create new xml attribute");
+ log_error1("Can not create new xml attribute");
return NULL;
}
}
@@ -397,27 +394,27 @@ soap_env_add_attachment (SoapEnv * call, const char *name, const char *href)
}
void
-soap_env_add_custom (SoapEnv * call, void *obj, XmlSerializerCallback cb,
- const char *type, const char *name)
+soap_env_add_custom(SoapEnv * call, void *obj, XmlSerializerCallback cb,
+ const char *type, const char *name)
{
struct XmlNodeHolder holder;
- holder.node = soap_env_get_method (call);
+ holder.node = soap_env_get_method(call);
- cb (obj, BAD_CAST name,
- xmlbuilder_start_element,
- xmlbuilder_characters, xmlbuilder_end_element, &holder);
+ cb(obj, BAD_CAST name,
+ xmlbuilder_start_element,
+ xmlbuilder_characters, xmlbuilder_end_element, &holder);
}
xmlNodePtr
-soap_env_push_item (SoapEnv * call, const char *type, const char *name)
+soap_env_push_item(SoapEnv * call, const char *type, const char *name)
{
xmlNodePtr node;
- node = soap_env_add_item (call, type, name, "");
+ node = soap_env_add_item(call, type, name, "");
if (node)
{
@@ -429,72 +426,72 @@ soap_env_push_item (SoapEnv * call, const char *type, const char *name)
void
-soap_env_pop_item (SoapEnv * call)
+soap_env_pop_item(SoapEnv * call)
{
call->cur = call->cur->parent;
}
void
-soap_env_free (SoapEnv * env)
+soap_env_free(SoapEnv * env)
{
if (env)
{
if (env->root)
{
- xmlFreeDoc (env->root->doc);
+ xmlFreeDoc(env->root->doc);
}
- free (env);
+ free(env);
}
}
xmlNodePtr
-soap_env_get_body (SoapEnv * env)
+soap_env_get_body(SoapEnv * env)
{
xmlNodePtr node;
if (env == NULL)
{
- log_error1 ("env object is NULL");
+ log_error1("env object is NULL");
return NULL;
}
if (env->root == NULL)
{
- log_error1 ("env has no xml");
+ log_error1("env has no xml");
return NULL;
}
- node = soap_xml_get_children (env->root);
+ node = soap_xml_get_children(env->root);
while (node != NULL)
{
- if (!xmlStrcmp (node->name, BAD_CAST "Body"))
+ if (!xmlStrcmp(node->name, BAD_CAST "Body"))
return node;
- node = soap_xml_get_next (node);
+ node = soap_xml_get_next(node);
}
- log_error1 ("Node Body tag found!");
+ log_error1("Node Body tag found!");
return NULL;
}
xmlNodePtr
-soap_env_get_fault (SoapEnv * env)
+soap_env_get_fault(SoapEnv * env)
{
xmlNodePtr node;
- node = soap_env_get_body (env);
+ node = soap_env_get_body(env);
if (!node)
return NULL;
while (node != NULL)
{
- if (!xmlStrcmp (node->name, BAD_CAST "Fault"))
+ if (!xmlStrcmp(node->name, BAD_CAST "Fault"))
return node;
- node = soap_xml_get_next (node);
+ node = soap_xml_get_next(node);
}
/* log_warn1 ("Node Fault tag found!");*/
@@ -503,26 +500,26 @@ soap_env_get_fault (SoapEnv * env)
xmlNodePtr
-soap_env_get_method (SoapEnv * env)
+soap_env_get_method(SoapEnv * env)
{
xmlNodePtr body;
- body = soap_env_get_body (env);
+ body = soap_env_get_body(env);
if (body == NULL)
{
- log_verbose1 ("body is NULL");
+ log_verbose1("body is NULL");
return NULL;
}
/* mehtod is the first child */
- return soap_xml_get_children (body);
+ return soap_xml_get_children(body);
}
xmlNodePtr
-_soap_env_get_body (SoapEnv * env)
+_soap_env_get_body(SoapEnv * env)
{
xmlNodePtr body;
xmlNodeSetPtr nodeset;
@@ -530,83 +527,83 @@ _soap_env_get_body (SoapEnv * env)
if (env == NULL)
{
- log_error1 ("env object is NULL");
+ log_error1("env object is NULL");
return NULL;
}
if (env->root == NULL)
{
- log_error1 ("env has no xml");
+ log_error1("env has no xml");
return NULL;
}
/*
find <Body> tag find out namespace xpath: //Envelope/Body/ */
- xpathobj = soap_xpath_eval (env->root->doc, "//Envelope/Body");
+ xpathobj = soap_xpath_eval(env->root->doc, "//Envelope/Body");
if (!xpathobj)
{
- log_error1 ("No Body (xpathobj)!");
+ log_error1("No Body (xpathobj)!");
return NULL;
}
nodeset = xpathobj->nodesetval;
if (!nodeset)
{
- log_error1 ("No Body (nodeset)!");
- xmlXPathFreeObject (xpathobj);
+ log_error1("No Body (nodeset)!");
+ xmlXPathFreeObject(xpathobj);
return NULL;
}
if (nodeset->nodeNr < 1)
{
- log_error1 ("No Body (nodeNr)!");
- xmlXPathFreeObject (xpathobj);
+ log_error1("No Body (nodeNr)!");
+ xmlXPathFreeObject(xpathobj);
return NULL;
}
body = nodeset->nodeTab[0]; /* body is <Body> */
- xmlXPathFreeObject (xpathobj);
+ xmlXPathFreeObject(xpathobj);
return body;
}
int
-soap_env_find_urn (SoapEnv * env, char *urn)
+soap_env_find_urn(SoapEnv * env, char *urn)
{
xmlNsPtr ns;
xmlNodePtr body, node;
- body = soap_env_get_body (env);
+ body = soap_env_get_body(env);
if (body == NULL)
{
- log_verbose1 ("body is NULL");
+ log_verbose1("body is NULL");
return 0;
}
/* node is the first child */
- node = soap_xml_get_children (body);
+ node = soap_xml_get_children(body);
if (node == NULL)
{
- log_error1 ("No namespace found");
+ log_error1("No namespace found");
return 0;
}
if (node->ns && node->ns->prefix)
{
- ns = xmlSearchNs (body->doc, node, node->ns->prefix);
+ ns = xmlSearchNs(body->doc, node, node->ns->prefix);
if (ns != NULL)
{
- strcpy (urn, (char *) ns->href);
+ strcpy(urn, (char *) ns->href);
return 1; /* namespace found! */
}
}
else
{
- strcpy (urn, "");
- log_warn1 ("No namespace found");
+ strcpy(urn, "");
+ log_warn1("No namespace found");
return 1;
}
@@ -615,30 +612,30 @@ soap_env_find_urn (SoapEnv * env, char *urn)
int
-soap_env_find_methodname (SoapEnv * env, char *method)
+soap_env_find_methodname(SoapEnv * env, char *method)
{
xmlNodePtr body, node;
- body = soap_env_get_body (env);
+ body = soap_env_get_body(env);
if (body == NULL)
return 0;
- node = soap_xml_get_children (body); /* node is the first child */
+ node = soap_xml_get_children(body); /* node is the first child */
if (node == NULL)
{
- log_error1 ("No method found");
+ log_error1("No method found");
return 0;
}
if (node->name == NULL)
{
- log_error1 ("No methodname found");
+ log_error1("No methodname found");
return 0;
}
- strcpy (method, (const char *) node->name);
+ strcpy(method, (const char *) node->name);
return 1;
}
@@ -651,8 +648,8 @@ soap_env_find_methodname (SoapEnv * env, char *method)
static void
-xmlbuilder_start_element (const xmlChar * element_name, int attr_count,
- xmlChar ** keys, xmlChar ** values, void *userData)
+xmlbuilder_start_element(const xmlChar * element_name, int attr_count,
+ xmlChar ** keys, xmlChar ** values, void *userData)
{
struct XmlNodeHolder *holder = (struct XmlNodeHolder *) userData;
xmlNodePtr parent = NULL;
@@ -663,13 +660,13 @@ xmlbuilder_start_element (const xmlChar * element_name, int attr_count,
if (parent == NULL)
return;
- holder->node = xmlNewChild (parent, NULL, element_name, NULL);
+ holder->node = xmlNewChild(parent, NULL, element_name, NULL);
}
static void
-xmlbuilder_characters (const xmlChar * element_name, const xmlChar * chars,
- void *userData)
+xmlbuilder_characters(const xmlChar * element_name, const xmlChar * chars,
+ void *userData)
{
struct XmlNodeHolder *holder = (struct XmlNodeHolder *) userData;
xmlNodePtr parent = NULL;
@@ -680,11 +677,11 @@ xmlbuilder_characters (const xmlChar * element_name, const xmlChar * chars,
if (parent == NULL)
return;
- xmlNewTextChild (parent, NULL, element_name, chars);
+ xmlNewTextChild(parent, NULL, element_name, chars);
}
static void
-xmlbuilder_end_element (const xmlChar * element_name, void *userData)
+xmlbuilder_end_element(const xmlChar * element_name, void *userData)
{
struct XmlNodeHolder *holder = (struct XmlNodeHolder *) userData;
diff --git a/libcsoap/soap-env.h b/libcsoap/soap-env.h
index 6a3d909..72dd999 100644
--- a/libcsoap/soap-env.h
+++ b/libcsoap/soap-env.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-env.h,v 1.10 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-env.h,v 1.11 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -73,10 +73,10 @@ typedef struct _SoapEnv
*/
herror_t
-soap_env_new_with_fault (fault_code_t faultcode,
- const char *faultstring,
- const char *faultactor,
- const char *detail, SoapEnv ** out);
+soap_env_new_with_fault(fault_code_t faultcode,
+ const char *faultstring,
+ const char *faultactor,
+ const char *detail, SoapEnv ** out);
/**
Creates an envelope with a method to invoke a soap service.
@@ -104,8 +104,7 @@ soap_env_new_with_fault (fault_code_t faultcode,
*/
herror_t
-soap_env_new_with_method (const char *urn, const char *method,
- SoapEnv ** out);
+soap_env_new_with_method(const char *urn, const char *method, SoapEnv ** out);
/**
@@ -138,7 +137,7 @@ soap_env_new_with_method (const char *urn, const char *method,
*/
-herror_t soap_env_new_with_response (SoapEnv * req, SoapEnv ** out);
+herror_t soap_env_new_with_response(SoapEnv * req, SoapEnv ** out);
/**
@@ -150,7 +149,7 @@ herror_t soap_env_new_with_response (SoapEnv * req, SoapEnv ** out);
@returns H_OK if success
*/
-herror_t soap_env_new_from_doc (xmlDocPtr doc, SoapEnv ** out);
+herror_t soap_env_new_from_doc(xmlDocPtr doc, SoapEnv ** out);
/**
@@ -161,7 +160,7 @@ herror_t soap_env_new_from_doc (xmlDocPtr doc, SoapEnv ** out);
@param out the output envelope object
@returns H_OK if success
*/
-herror_t soap_env_new_from_buffer (const char *buffer, SoapEnv ** out);
+herror_t soap_env_new_from_buffer(const char *buffer, SoapEnv ** out);
/**
@@ -171,21 +170,16 @@ herror_t soap_env_new_from_buffer (const char *buffer, SoapEnv ** out);
@param out the output envelope object
@returns H_OK if success
*/
-herror_t soap_env_new_from_stream (http_input_stream_t * in, SoapEnv ** out);
+herror_t soap_env_new_from_stream(http_input_stream_t * in, SoapEnv ** out);
/* --------------------------------------------------- */
/* XML Serializer functions and typedefs */
/* --------------------------------------------------- */
-typedef void (*XmlSerializerCallback)
- (void * /* obj */ , const xmlChar * /* root_element_name */ ,
- void (*OnStartElement) (const xmlChar * element_name, int attr_count,
- xmlChar ** keys, xmlChar ** values,
- void *userData),
- void (*OnCharacters) (const xmlChar * element_name, const xmlChar * chars,
- void *userData),
- void (*OnEndElement) (const xmlChar * element_name, void *userData),
- void * /* userdata */ );
+typedef void (*XmlSerializerCallback) (void * /* obj */ , const xmlChar * /* root_element_name
+ */ ,
+ void (*OnStartElement) (const xmlChar * element_name, int attr_count, xmlChar ** keys, xmlChar ** values, void *userData), void (*OnCharacters) (const xmlChar * element_name, const xmlChar * chars, void *userData), void (*OnEndElement) (const xmlChar * element_name, void *userData), void * /* userdata
+ */ );
/* ------------------------------------------------------ */
@@ -211,8 +205,8 @@ typedef void (*XmlSerializerCallback)
@see tutorial
*/
xmlNodePtr
-soap_env_add_item (SoapEnv * env, const char *type,
- const char *name, const char *value);
+soap_env_add_item(SoapEnv * env, const char *type,
+ const char *name, const char *value);
/**
@@ -232,7 +226,7 @@ soap_env_add_item (SoapEnv * env, const char *type,
@see soap_ctx_add_file tutorial
*/
xmlNodePtr
-soap_env_add_attachment (SoapEnv * env, const char *name, const char *href);
+soap_env_add_attachment(SoapEnv * env, const char *name, const char *href);
/**
@@ -243,8 +237,8 @@ soap_env_add_attachment (SoapEnv * env, const char *name, const char *href);
*/
void
-soap_env_add_custom (SoapEnv * env, void *obj, XmlSerializerCallback cb,
- const char *type, const char *name);
+soap_env_add_custom(SoapEnv * env, void *obj, XmlSerializerCallback cb,
+ const char *type, const char *name);
/**
Same as soap_env_add_item() with c style arguments
@@ -256,8 +250,8 @@ soap_env_add_custom (SoapEnv * env, void *obj, XmlSerializerCallback cb,
@see soap_env_add_item
*/
xmlNodePtr
-soap_env_add_itemf (SoapEnv * env, const char *type,
- const char *name, const char *value, ...);
+soap_env_add_itemf(SoapEnv * env, const char *type,
+ const char *name, const char *value, ...);
/**
@@ -285,7 +279,7 @@ soap_env_add_itemf (SoapEnv * env, const char *type,
@see tutorial
*/
xmlNodePtr
-soap_env_push_item (SoapEnv * env, const char *type, const char *name);
+soap_env_push_item(SoapEnv * env, const char *type, const char *name);
/**
Sets the xml pointer 1 level higher.
@@ -293,14 +287,14 @@ soap_env_push_item (SoapEnv * env, const char *type, const char *name);
@param env The envelope object
@see soap_env_push_item
*/
-void soap_env_pop_item (SoapEnv * env);
+void soap_env_pop_item(SoapEnv * env);
/**
Free the envelope.
@param env The envelope object
*/
-void soap_env_free (SoapEnv * env);
+void soap_env_free(SoapEnv * env);
/* --------------------------------------------------- */
@@ -311,29 +305,29 @@ void soap_env_free (SoapEnv * env);
/**
Gets the xml node pointing to SOAP Body.
*/
-xmlNodePtr soap_env_get_body (SoapEnv * env);
+xmlNodePtr soap_env_get_body(SoapEnv * env);
/**
Get the xml node pointing to SOAP method (call)
*/
-xmlNodePtr soap_env_get_method (SoapEnv * env);
+xmlNodePtr soap_env_get_method(SoapEnv * env);
/**
Get the xml node pointing to SOAP Fault
*/
-xmlNodePtr soap_env_get_fault (SoapEnv * env);
+xmlNodePtr soap_env_get_fault(SoapEnv * env);
/**
Get the xml node pointing to SOAP Header
*/
-xmlNodePtr soap_env_get_header (SoapEnv * env);
+xmlNodePtr soap_env_get_header(SoapEnv * env);
-int soap_env_find_urn (SoapEnv * env, char *urn);
-int soap_env_find_methodname (SoapEnv * env, char *methodname);
+int soap_env_find_urn(SoapEnv * env, char *urn);
+int soap_env_find_methodname(SoapEnv * env, char *methodname);
diff --git a/libcsoap/soap-fault.c b/libcsoap/soap-fault.c
index 3c8f5c1..1e6cae8 100644
--- a/libcsoap/soap-fault.c
+++ b/libcsoap/soap-fault.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-fault.c,v 1.7 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: soap-fault.c,v 1.8 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -63,9 +63,9 @@ static char *fault_client = "Client";
static char *fault_server = "Server";
xmlDocPtr
-soap_fault_build (fault_code_t fcode,
- const char *faultstring,
- const char *faultactor, const char *detail)
+soap_fault_build(fault_code_t fcode,
+ const char *faultstring,
+ const char *faultactor, const char *detail)
{
/* variables */
@@ -74,7 +74,7 @@ soap_fault_build (fault_code_t fcode,
char *buffer;
xmlDocPtr fault; /* result */
- log_verbose1 ("Build fault");
+ log_verbose1("Build fault");
switch (fcode)
{
@@ -96,33 +96,33 @@ soap_fault_build (fault_code_t fcode,
/* calculate buffer length */
if (faultstring)
- bufferlen += strlen (faultstring);
+ bufferlen += strlen(faultstring);
if (faultactor)
- bufferlen += strlen (faultactor);
+ bufferlen += strlen(faultactor);
if (detail)
- bufferlen += strlen (detail);
+ bufferlen += strlen(detail);
- log_verbose2 ("Creating buffer with %d bytes", bufferlen);
- buffer = (char *) malloc (bufferlen);
+ log_verbose2("Creating buffer with %d bytes", bufferlen);
+ buffer = (char *) malloc(bufferlen);
- sprintf (buffer, _SOAP_FAULT_TEMPLATE_,
- soap_env_ns, soap_env_enc, soap_xsi_ns,
- soap_xsd_ns, faultcode,
- faultstring ? faultstring : "error",
- faultactor ? faultactor : "", detail ? detail : "");
+ sprintf(buffer, _SOAP_FAULT_TEMPLATE_,
+ soap_env_ns, soap_env_enc, soap_xsi_ns,
+ soap_xsd_ns, faultcode,
+ faultstring ? faultstring : "error",
+ faultactor ? faultactor : "", detail ? detail : "");
- fault = xmlParseDoc (BAD_CAST buffer);
- free (buffer);
+ fault = xmlParseDoc(BAD_CAST buffer);
+ free(buffer);
if (fault == NULL)
{
- log_error1 ("Can not create xml document!");
+ log_error1("Can not create xml document!");
- return soap_fault_build (fcode, "Can not create fault object in xml",
- "soap_fault_build()", NULL);
+ return soap_fault_build(fcode, "Can not create fault object in xml",
+ "soap_fault_build()", NULL);
}
- log_verbose2 ("Returning fault (%p)", fault);
+ log_verbose2("Returning fault (%p)", fault);
return fault;
}
diff --git a/libcsoap/soap-fault.h b/libcsoap/soap-fault.h
index 46471a0..7f01e9f 100644
--- a/libcsoap/soap-fault.h
+++ b/libcsoap/soap-fault.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-fault.h,v 1.3 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-fault.h,v 1.4 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -37,9 +37,9 @@ typedef enum _fault_code
} fault_code_t;
-xmlDocPtr soap_fault_build (fault_code_t faultcode,
- const char *faultstring,
- const char *faultactor, const char *detail);
+xmlDocPtr soap_fault_build(fault_code_t faultcode,
+ const char *faultstring,
+ const char *faultactor, const char *detail);
#endif
diff --git a/libcsoap/soap-router.c b/libcsoap/soap-router.c
index 74c53be..1e57850 100644
--- a/libcsoap/soap-router.c
+++ b/libcsoap/soap-router.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-router.c,v 1.4 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: soap-router.c,v 1.5 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -25,11 +25,11 @@
#include <string.h>
SoapRouter *
-soap_router_new ()
+soap_router_new()
{
SoapRouter *router;
- router = (SoapRouter *) malloc (sizeof (SoapRouter));
+ router = (SoapRouter *) malloc(sizeof(SoapRouter));
router->service_head = NULL;
router->service_tail = NULL;
@@ -38,30 +38,30 @@ soap_router_new ()
void
-soap_router_register_service (SoapRouter * router,
- SoapServiceFunc func,
- const char *method, const char *urn)
+soap_router_register_service(SoapRouter * router,
+ SoapServiceFunc func,
+ const char *method, const char *urn)
{
SoapService *service;
- service = soap_service_new (urn, method, func);
+ service = soap_service_new(urn, method, func);
if (router->service_tail == NULL)
{
router->service_head =
- router->service_tail = soap_service_node_new (service, NULL);
+ router->service_tail = soap_service_node_new(service, NULL);
}
else
{
- router->service_tail->next = soap_service_node_new (service, NULL);
+ router->service_tail->next = soap_service_node_new(service, NULL);
router->service_tail = router->service_tail->next;
}
}
SoapService *
-soap_router_find_service (SoapRouter * router,
- const char *urn, const char *method)
+soap_router_find_service(SoapRouter * router,
+ const char *urn, const char *method)
{
SoapServiceNode *node;
@@ -75,8 +75,8 @@ soap_router_find_service (SoapRouter * router,
if (node->service && node->service->urn && node->service->method)
{
- if (!strcmp (node->service->urn, urn)
- && !strcmp (node->service->method, method))
+ if (!strcmp(node->service->urn, urn)
+ && !strcmp(node->service->method, method))
return node->service;
}
@@ -89,10 +89,10 @@ soap_router_find_service (SoapRouter * router,
void
-soap_router_free (SoapRouter * router)
+soap_router_free(SoapRouter * router)
{
SoapServiceNode *node;
- log_verbose2 ("enter: router=%p", router);
+ log_verbose2("enter: router=%p", router);
if (router == NULL)
return;
@@ -101,11 +101,11 @@ soap_router_free (SoapRouter * router)
node = router->service_head->next;
/* log_verbose2("soap_service_free(%p)\n",
router->service_head->service); */
- soap_service_free (router->service_head->service);
- free (router->service_head);
+ soap_service_free(router->service_head->service);
+ free(router->service_head);
router->service_head = node;
}
- free (router);
- log_verbose1 ("leave with success");
+ free(router);
+ log_verbose1("leave with success");
}
diff --git a/libcsoap/soap-router.h b/libcsoap/soap-router.h
index f82d43c..5b0c7ab 100644
--- a/libcsoap/soap-router.h
+++ b/libcsoap/soap-router.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-router.h,v 1.3 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-router.h,v 1.4 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -47,7 +47,7 @@ typedef struct _SoapRouter
@returns Soap router
@see soap_router_free
*/
-SoapRouter *soap_router_new ();
+SoapRouter *soap_router_new();
/**
@@ -60,9 +60,9 @@ SoapRouter *soap_router_new ();
the client side.
@param urn The urn for this service
*/
-void soap_router_register_service (SoapRouter * router,
- SoapServiceFunc func,
- const char *method, const char *urn);
+void soap_router_register_service(SoapRouter * router,
+ SoapServiceFunc func,
+ const char *method, const char *urn);
/**
@@ -74,8 +74,8 @@ void soap_router_register_service (SoapRouter * router,
@return The service if found, NULL otherwise.
*/
-SoapService *soap_router_find_service (SoapRouter * router,
- const char *urn, const char *method);
+SoapService *soap_router_find_service(SoapRouter * router,
+ const char *urn, const char *method);
/**
@@ -83,6 +83,6 @@ SoapService *soap_router_find_service (SoapRouter * router,
@param router The router object to free
*/
-void soap_router_free (SoapRouter * router);
+void soap_router_free(SoapRouter * router);
#endif
diff --git a/libcsoap/soap-server.c b/libcsoap/soap-server.c
index 9daf639..74ff251 100644
--- a/libcsoap/soap-server.c
+++ b/libcsoap/soap-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-server.c,v 1.13 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: soap-server.c,v 1.14 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -38,46 +38,45 @@ SoapRouterNode *head = NULL;
SoapRouterNode *tail = NULL;
static
- SoapRouterNode *router_node_new (SoapRouter * router,
- const char *context,
- SoapRouterNode * next);
+ SoapRouterNode *router_node_new(SoapRouter * router,
+ const char *context, SoapRouterNode * next);
-static SoapRouter *router_find (const char *context);
+static SoapRouter *router_find(const char *context);
-static void _soap_server_send_ctx (httpd_conn_t * conn, SoapCtx * ctxres);
+static void _soap_server_send_ctx(httpd_conn_t * conn, SoapCtx * ctxres);
/*---------------------------------*/
-void soap_server_entry (httpd_conn_t * conn, hrequest_t * req);
-static void _soap_server_send_env (http_output_stream_t * out, SoapEnv * env);
+void soap_server_entry(httpd_conn_t * conn, hrequest_t * req);
+static void _soap_server_send_env(http_output_stream_t * out, SoapEnv * env);
static
- void _soap_server_send_fault (httpd_conn_t * conn, hpair_t * header,
- const char *errmsg);
+ void _soap_server_send_fault(httpd_conn_t * conn, hpair_t * header,
+ const char *errmsg);
/*---------------------------------*/
herror_t
-soap_server_init_args (int argc, char *argv[])
+soap_server_init_args(int argc, char *argv[])
{
- return httpd_init (argc, argv);
+ return httpd_init(argc, argv);
}
int
-soap_server_register_router (SoapRouter * router, const char *context)
+soap_server_register_router(SoapRouter * router, const char *context)
{
- if (!httpd_register (context, soap_server_entry))
+ if (!httpd_register(context, soap_server_entry))
{
return 0;
}
if (tail == NULL)
{
- head = tail = router_node_new (router, context, NULL);
+ head = tail = router_node_new(router, context, NULL);
}
else
{
- tail->next = router_node_new (router, context, NULL);
+ tail->next = router_node_new(router, context, NULL);
tail = tail->next;
}
@@ -86,14 +85,14 @@ soap_server_register_router (SoapRouter * router, const char *context)
herror_t
-soap_server_run ()
+soap_server_run()
{
- return httpd_run ();
+ return httpd_run();
}
void
-soap_server_destroy ()
+soap_server_destroy()
{
SoapRouterNode *node = head;
SoapRouterNode *tmp;
@@ -101,18 +100,18 @@ soap_server_destroy ()
while (node != NULL)
{
tmp = node->next;
- log_verbose2 ("soap_router_free(%p)", node->router);
- soap_router_free (node->router);
- free (node->context);
- free (node);
+ log_verbose2("soap_router_free(%p)", node->router);
+ soap_router_free(node->router);
+ free(node->context);
+ free(node);
node = tmp;
}
- httpd_destroy ();
+ httpd_destroy();
}
void
-soap_server_entry (httpd_conn_t * conn, hrequest_t * req)
+soap_server_entry(httpd_conn_t * conn, hrequest_t * req)
{
hpair_t *header = NULL;
char buffer[1054];
@@ -127,23 +126,23 @@ soap_server_entry (httpd_conn_t * conn, hrequest_t * req)
if (req->method != HTTP_REQUEST_POST)
{
- httpd_send_header (conn, 200, "OK");
- http_output_stream_write_string (conn->out, "<html><head></head><body>");
- http_output_stream_write_string (conn->out, "<h1>Sorry! </h1><hr>");
- http_output_stream_write_string (conn->out,
- "I only speak with 'POST' method");
- http_output_stream_write_string (conn->out, "</body></html>");
+ httpd_send_header(conn, 200, "OK");
+ http_output_stream_write_string(conn->out, "<html><head></head><body>");
+ http_output_stream_write_string(conn->out, "<h1>Sorry! </h1><hr>");
+ http_output_stream_write_string(conn->out,
+ "I only speak with 'POST' method");
+ http_output_stream_write_string(conn->out, "</body></html>");
return;
}
- header = hpairnode_new (HEADER_CONTENT_TYPE, "text/xml", NULL);
+ header = hpairnode_new(HEADER_CONTENT_TYPE, "text/xml", NULL);
- err = soap_env_new_from_stream (req->in, &env);
+ err = soap_env_new_from_stream(req->in, &env);
if (err != H_OK)
{
- _soap_server_send_fault (conn, header, herror_message (err));
- herror_release (err);
+ _soap_server_send_fault(conn, header, herror_message(err));
+ herror_release(err);
return;
}
@@ -151,19 +150,19 @@ soap_server_entry (httpd_conn_t * conn, hrequest_t * req)
if (env == NULL)
{
- _soap_server_send_fault (conn, header, "Can not receive POST data!");
+ _soap_server_send_fault(conn, header, "Can not receive POST data!");
}
else
{
- ctx = soap_ctx_new (env);
- soap_ctx_add_files (ctx, req->attachments);
+ ctx = soap_ctx_new(env);
+ soap_ctx_add_files(ctx, req->attachments);
if (ctx->env == NULL)
{
- _soap_server_send_fault (conn, header, "Can not parse POST data!");
+ _soap_server_send_fault(conn, header, "Can not parse POST data!");
}
else
@@ -171,76 +170,76 @@ soap_server_entry (httpd_conn_t * conn, hrequest_t * req)
/* soap_xml_doc_print(env->root->doc); */
- router = router_find (req->path);
+ router = router_find(req->path);
if (router == NULL)
{
- _soap_server_send_fault (conn, header, "Can not find router!");
+ _soap_server_send_fault(conn, header, "Can not find router!");
}
else
{
- if (!soap_env_find_urn (ctx->env, urn))
+ if (!soap_env_find_urn(ctx->env, urn))
{
- _soap_server_send_fault (conn, header, "No URN found!");
- soap_ctx_free (ctx);
+ _soap_server_send_fault(conn, header, "No URN found!");
+ soap_ctx_free(ctx);
return;
}
else
{
- log_verbose2 ("urn: '%s'", urn);
+ log_verbose2("urn: '%s'", urn);
}
- if (!soap_env_find_methodname (ctx->env, method))
+ if (!soap_env_find_methodname(ctx->env, method))
{
- _soap_server_send_fault (conn, header, "No method found!");
- soap_ctx_free (ctx);
+ _soap_server_send_fault(conn, header, "No method found!");
+ soap_ctx_free(ctx);
return;
}
else
{
- log_verbose2 ("method: '%s'", method);
+ log_verbose2("method: '%s'", method);
}
- service = soap_router_find_service (router, urn, method);
+ service = soap_router_find_service(router, urn, method);
if (service == NULL)
{
- sprintf (buffer, "URN '%s' not found", urn);
- _soap_server_send_fault (conn, header, buffer);
- soap_ctx_free (ctx);
+ sprintf(buffer, "URN '%s' not found", urn);
+ _soap_server_send_fault(conn, header, buffer);
+ soap_ctx_free(ctx);
return;
}
else
{
- log_verbose2 ("func: %p", service->func);
- ctxres = soap_ctx_new (NULL);
+ log_verbose2("func: %p", service->func);
+ ctxres = soap_ctx_new(NULL);
/* ===================================== */
/* CALL SERVICE FUNCTION */
/* ===================================== */
- err = service->func (ctx, ctxres);
+ err = service->func(ctx, ctxres);
if (err != H_OK)
{
- sprintf (buffer, "Service returned following error message: '%s'",
- herror_message (err));
- herror_release (err);
- _soap_server_send_fault (conn, header, buffer);
- soap_ctx_free (ctx);
+ sprintf(buffer, "Service returned following error message: '%s'",
+ herror_message(err));
+ herror_release(err);
+ _soap_server_send_fault(conn, header, buffer);
+ soap_ctx_free(ctx);
return;
}
if (ctxres->env == NULL)
{
- sprintf (buffer, "Service '%s' returned no envelope", urn);
- _soap_server_send_fault (conn, header, buffer);
- soap_ctx_free (ctx);
+ sprintf(buffer, "Service '%s' returned no envelope", urn);
+ _soap_server_send_fault(conn, header, buffer);
+ soap_ctx_free(ctx);
return;
}
@@ -250,22 +249,22 @@ soap_server_entry (httpd_conn_t * conn, hrequest_t * req)
/* httpd_send_header(conn, 200, "OK");
_soap_server_send_env(conn->out, ctxres->env);
*/
- _soap_server_send_ctx (conn, ctxres);
+ _soap_server_send_ctx(conn, ctxres);
/* free envctx */
- soap_ctx_free (ctxres);
+ soap_ctx_free(ctxres);
}
}
}
}
- soap_ctx_free (ctx);
+ soap_ctx_free(ctx);
}
}
static void
-_soap_server_send_ctx (httpd_conn_t * conn, SoapCtx * ctx)
+_soap_server_send_ctx(httpd_conn_t * conn, SoapCtx * ctx)
{
xmlBufferPtr buffer;
static int counter = 1;
@@ -275,118 +274,116 @@ _soap_server_send_ctx (httpd_conn_t * conn, SoapCtx * ctx)
if (ctx->env == NULL || ctx->env->root == NULL)
return;
- buffer = xmlBufferCreate ();
+ buffer = xmlBufferCreate();
/* xmlIndentTreeOutput = 1;*/
- xmlThrDefIndentTreeOutput (1);
+ xmlThrDefIndentTreeOutput(1);
/* xmlKeepBlanksDefault(0);*/
- xmlNodeDump (buffer, ctx->env->root->doc, ctx->env->root, 1, 1);
+ xmlNodeDump(buffer, ctx->env->root->doc, ctx->env->root, 1, 1);
if (ctx->attachments)
{
- sprintf (strbuffer, "000128590350940924234%d", counter++);
- httpd_mime_send_header (conn, strbuffer, "", "text/xml", 200, "OK");
- httpd_mime_next (conn, strbuffer, "text/xml", "binary");
- http_output_stream_write_string (conn->out,
- (const char *)
- xmlBufferContent (buffer));
+ sprintf(strbuffer, "000128590350940924234%d", counter++);
+ httpd_mime_send_header(conn, strbuffer, "", "text/xml", 200, "OK");
+ httpd_mime_next(conn, strbuffer, "text/xml", "binary");
+ http_output_stream_write_string(conn->out,
+ (const char *) xmlBufferContent(buffer));
part = ctx->attachments->parts;
while (part)
{
- httpd_mime_send_file (conn, part->id, part->content_type,
- part->transfer_encoding, part->filename);
+ httpd_mime_send_file(conn, part->id, part->content_type,
+ part->transfer_encoding, part->filename);
part = part->next;
}
- httpd_mime_end (conn);
+ httpd_mime_end(conn);
}
else
{
char buflen[100];
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;
- xpathCtx = xmlXPathNewContext (ctx->env->root->doc);
- xpathObj = xmlXPathEvalExpression ("//Fault", xpathCtx);
+ xpathCtx = xmlXPathNewContext(ctx->env->root->doc);
+ xpathObj = xmlXPathEvalExpression("//Fault", xpathCtx);
#ifdef WIN32
#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
#endif
- snprintf (buflen, 100, "%d",
- strlen ((const char *) xmlBufferContent (buffer)));
- httpd_set_header (conn, HEADER_CONTENT_LENGTH, buflen);
+ snprintf(buflen, 100, "%d",
+ strlen((const char *) xmlBufferContent(buffer)));
+ httpd_set_header(conn, HEADER_CONTENT_LENGTH, buflen);
if ((xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0)
{
- httpd_send_header (conn, 500, "FAILED");
+ httpd_send_header(conn, 500, "FAILED");
}
else
{
- httpd_send_header (conn, 200, "OK");
+ httpd_send_header(conn, 200, "OK");
}
- http_output_stream_write_string (conn->out,
- (const char *)
- xmlBufferContent (buffer));
- xmlXPathFreeObject (xpathObj);
- xmlXPathFreeContext (xpathCtx);
+ http_output_stream_write_string(conn->out,
+ (const char *) xmlBufferContent(buffer));
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
}
- xmlBufferFree (buffer);
+ xmlBufferFree(buffer);
}
static void
-_soap_server_send_env (http_output_stream_t * out, SoapEnv * env)
+_soap_server_send_env(http_output_stream_t * out, SoapEnv * env)
{
xmlBufferPtr buffer;
if (env == NULL || env->root == NULL)
return;
- buffer = xmlBufferCreate ();
- xmlNodeDump (buffer, env->root->doc, env->root, 1, 1);
- http_output_stream_write_string (out,
- (const char *) xmlBufferContent (buffer));
- xmlBufferFree (buffer);
+ buffer = xmlBufferCreate();
+ xmlNodeDump(buffer, env->root->doc, env->root, 1, 1);
+ http_output_stream_write_string(out,
+ (const char *) xmlBufferContent(buffer));
+ xmlBufferFree(buffer);
}
static void
-_soap_server_send_fault (httpd_conn_t * conn, hpair_t * header,
- const char *errmsg)
+_soap_server_send_fault(httpd_conn_t * conn, hpair_t * header,
+ const char *errmsg)
{
SoapEnv *envres;
herror_t err;
char buffer[45];
- httpd_set_headers (conn, header);
- err = httpd_send_header (conn, 500, "FAILED");
+ httpd_set_headers(conn, header);
+ err = httpd_send_header(conn, 500, "FAILED");
if (err != H_OK)
{
/* WARNING: unhandled exception ! */
- log_error4 ("%s():%s [%d]", herror_func (err), herror_message (err),
- herror_code (err));
+ log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
+ herror_code(err));
return;
}
- err = soap_env_new_with_fault (Fault_Server,
- errmsg ? errmsg : "General error",
- "cSOAP_Server", NULL, &envres);
+ err = soap_env_new_with_fault(Fault_Server,
+ errmsg ? errmsg : "General error",
+ "cSOAP_Server", NULL, &envres);
if (err != H_OK)
{
- log_error1 (herror_message (err));
- http_output_stream_write_string (conn->out, "<html><head></head><body>");
- http_output_stream_write_string (conn->out, "<h1>Error</h1><hr>");
- http_output_stream_write_string (conn->out,
- "Error while sending fault object:<br>Message: ");
- http_output_stream_write_string (conn->out, herror_message (err));
- http_output_stream_write_string (conn->out, "<br>Function: ");
- http_output_stream_write_string (conn->out, herror_func (err));
- http_output_stream_write_string (conn->out, "<br>Error code: ");
- sprintf (buffer, "%d", herror_code (err));
- http_output_stream_write_string (conn->out, buffer);
- http_output_stream_write_string (conn->out, "</body></html>");
+ log_error1(herror_message(err));
+ http_output_stream_write_string(conn->out, "<html><head></head><body>");
+ http_output_stream_write_string(conn->out, "<h1>Error</h1><hr>");
+ http_output_stream_write_string(conn->out,
+ "Error while sending fault object:<br>Message: ");
+ http_output_stream_write_string(conn->out, herror_message(err));
+ http_output_stream_write_string(conn->out, "<br>Function: ");
+ http_output_stream_write_string(conn->out, herror_func(err));
+ http_output_stream_write_string(conn->out, "<br>Error code: ");
+ sprintf(buffer, "%d", herror_code(err));
+ http_output_stream_write_string(conn->out, buffer);
+ http_output_stream_write_string(conn->out, "</body></html>");
return;
- herror_release (err);
+ herror_release(err);
}
else
{
- _soap_server_send_env (conn->out, envres);
+ _soap_server_send_env(conn->out, envres);
}
}
@@ -394,23 +391,23 @@ _soap_server_send_fault (httpd_conn_t * conn, hpair_t * header,
static SoapRouterNode *
-router_node_new (SoapRouter * router,
- const char *context, SoapRouterNode * next)
+router_node_new(SoapRouter * router,
+ const char *context, SoapRouterNode * next)
{
SoapRouterNode *node;
const char *noname = "/lost_found";
- node = (SoapRouterNode *) malloc (sizeof (SoapRouterNode));
+ node = (SoapRouterNode *) malloc(sizeof(SoapRouterNode));
if (context)
{
- node->context = (char *) malloc (strlen (context) + 1);
- strcpy (node->context, context);
+ node->context = (char *) malloc(strlen(context) + 1);
+ strcpy(node->context, context);
}
else
{
- log_warn2 ("context is null. Using '%s'", noname);
- node->context = (char *) malloc (strlen (noname) + 1);
- strcpy (node->context, noname);
+ log_warn2("context is null. Using '%s'", noname);
+ node->context = (char *) malloc(strlen(noname) + 1);
+ strcpy(node->context, noname);
}
node->router = router;
@@ -421,13 +418,13 @@ router_node_new (SoapRouter * router,
static SoapRouter *
-router_find (const char *context)
+router_find(const char *context)
{
SoapRouterNode *node = head;
while (node != NULL)
{
- if (!strcmp (node->context, context))
+ if (!strcmp(node->context, context))
return node->router;
node = node->next;
}
diff --git a/libcsoap/soap-server.h b/libcsoap/soap-server.h
index b829909..9306f1a 100644
--- a/libcsoap/soap-server.h
+++ b/libcsoap/soap-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-server.h,v 1.6 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-server.h,v 1.7 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -44,7 +44,7 @@
@returns 1 if success, 0 otherwise
*/
-herror_t soap_server_init_args (int argc, char *argv[]);
+herror_t soap_server_init_args(int argc, char *argv[]);
/**
@@ -61,20 +61,20 @@ herror_t soap_server_init_args (int argc, char *argv[]);
@see soap_router_register_service
*/
-int soap_server_register_router (SoapRouter * router, const char *context);
+int soap_server_register_router(SoapRouter * router, const char *context);
/**
Enters the server loop and starts to listen to
http requests.
*/
-herror_t soap_server_run ();
+herror_t soap_server_run();
/**
Frees the soap server.
*/
-void soap_server_destroy ();
+void soap_server_destroy();
#endif
diff --git a/libcsoap/soap-service.c b/libcsoap/soap-service.c
index 91be66e..376daa7 100644
--- a/libcsoap/soap-service.c
+++ b/libcsoap/soap-service.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-service.c,v 1.5 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: soap-service.c,v 1.6 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -26,11 +26,11 @@
#include <string.h>
SoapServiceNode *
-soap_service_node_new (SoapService * service, SoapServiceNode * next)
+soap_service_node_new(SoapService * service, SoapServiceNode * next)
{
SoapServiceNode *node;
- node = (SoapServiceNode *) malloc (sizeof (SoapServiceNode));
+ node = (SoapServiceNode *) malloc(sizeof(SoapServiceNode));
node->service = service;
node->next = next;
@@ -41,33 +41,33 @@ soap_service_node_new (SoapService * service, SoapServiceNode * next)
SoapService *
-soap_service_new (const char *urn, const char *method, SoapServiceFunc f)
+soap_service_new(const char *urn, const char *method, SoapServiceFunc f)
{
SoapService *service;
- service = (SoapService *) malloc (sizeof (SoapService));
+ service = (SoapService *) malloc(sizeof(SoapService));
service->func = f;
if (urn != NULL)
{
- service->urn = (char *) malloc (strlen (urn) + 1);
- strcpy (service->urn, urn);
+ service->urn = (char *) malloc(strlen(urn) + 1);
+ strcpy(service->urn, urn);
}
else
{
- log_warn1 ("urn is NULL");
+ log_warn1("urn is NULL");
service->urn = "";
}
if (method != NULL)
{
- service->method = (char *) malloc (strlen (method) + 1);
- strcpy (service->method, method);
+ service->method = (char *) malloc(strlen(method) + 1);
+ strcpy(service->method, method);
}
else
{
- log_warn1 ("method is NULL");
+ log_warn1("method is NULL");
service->method = "";
}
@@ -77,19 +77,19 @@ soap_service_new (const char *urn, const char *method, SoapServiceFunc f)
void
-soap_service_free (SoapService * service)
+soap_service_free(SoapService * service)
{
- log_verbose2 ("enter: service=%p", service);
+ log_verbose2("enter: service=%p", service);
if (service == NULL)
return;
- if (strcmp (service->urn, ""))
- free (service->urn);
+ if (strcmp(service->urn, ""))
+ free(service->urn);
- if (strcmp (service->method, ""))
- free (service->method);
+ if (strcmp(service->method, ""))
+ free(service->method);
- free (service);
- log_verbose1 ("leave with success");
+ free(service);
+ log_verbose1("leave with success");
}
diff --git a/libcsoap/soap-service.h b/libcsoap/soap-service.h
index 497e77b..798f842 100644
--- a/libcsoap/soap-service.h
+++ b/libcsoap/soap-service.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-service.h,v 1.4 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-service.h,v 1.5 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -28,7 +28,7 @@
#include <libcsoap/soap-env.h>
#include <libcsoap/soap-ctx.h>
-typedef herror_t (*SoapServiceFunc) (SoapCtx *, SoapCtx *);
+typedef herror_t(*SoapServiceFunc) (SoapCtx *, SoapCtx *);
typedef struct _SoapService
@@ -45,12 +45,12 @@ typedef struct _SoapServiceNode
struct _SoapServiceNode *next;
} SoapServiceNode;
-SoapServiceNode *soap_service_node_new (SoapService * service,
- SoapServiceNode * next);
+SoapServiceNode *soap_service_node_new(SoapService * service,
+ SoapServiceNode * next);
-SoapService *soap_service_new (const char *urn, const char *method,
- SoapServiceFunc f);
-void soap_service_free (SoapService * service);
+SoapService *soap_service_new(const char *urn, const char *method,
+ SoapServiceFunc f);
+void soap_service_free(SoapService * service);
diff --git a/libcsoap/soap-xml.c b/libcsoap/soap-xml.c
index 288e5ff..7b6ba87 100644
--- a/libcsoap/soap-xml.c
+++ b/libcsoap/soap-xml.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-xml.c,v 1.7 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: soap-xml.c,v 1.8 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -26,13 +26,13 @@
static const char *soap_env_ns = "http://schemas.xmlsoap.org/soap/envelope/";
xmlNodePtr
-soap_xml_get_children (xmlNodePtr param)
+soap_xml_get_children(xmlNodePtr param)
{
xmlNodePtr children;
if (param == NULL)
{
- log_error1 ("Invalid parameter 'param' (null)");
+ log_error1("Invalid parameter 'param' (null)");
return NULL;
}
@@ -49,7 +49,7 @@ soap_xml_get_children (xmlNodePtr param)
}
xmlNodePtr
-soap_xml_get_next (xmlNodePtr param)
+soap_xml_get_next(xmlNodePtr param)
{
xmlNodePtr node = param->next;
@@ -67,33 +67,33 @@ soap_xml_get_next (xmlNodePtr param)
xmlXPathObjectPtr
-soap_xpath_eval (xmlDocPtr doc, const char *xpath)
+soap_xpath_eval(xmlDocPtr doc, const char *xpath)
{
xmlXPathContextPtr context;
xmlXPathObjectPtr result;
- context = xmlXPathNewContext (doc);
- result = xmlXPathEvalExpression (BAD_CAST xpath, context);
- if (xmlXPathNodeSetIsEmpty (result->nodesetval))
+ context = xmlXPathNewContext(doc);
+ result = xmlXPathEvalExpression(BAD_CAST xpath, context);
+ if (xmlXPathNodeSetIsEmpty(result->nodesetval))
{
/* no result */
return NULL;
}
- xmlXPathFreeContext (context);
+ xmlXPathFreeContext(context);
return result;
}
int
-soap_xpath_foreach (xmlDocPtr doc, const char *xpath,
- soap_xmlnode_callback cb, void *userdata)
+soap_xpath_foreach(xmlDocPtr doc, const char *xpath,
+ soap_xmlnode_callback cb, void *userdata)
{
int i = 0;
xmlNodeSetPtr nodeset;
xmlXPathObjectPtr xpathobj;
- xpathobj = soap_xpath_eval (doc, xpath);
+ xpathobj = soap_xpath_eval(doc, xpath);
if (!xpathobj)
return 0;
@@ -104,44 +104,44 @@ soap_xpath_foreach (xmlDocPtr doc, const char *xpath,
for (i = 0; i < nodeset->nodeNr; i++)
{
- if (!cb (nodeset->nodeTab[i], userdata))
+ if (!cb(nodeset->nodeTab[i], userdata))
break;
}
- xmlXPathFreeObject ((xmlXPathObjectPtr) nodeset);
+ xmlXPathFreeObject((xmlXPathObjectPtr) nodeset);
return i;
}
void
-soap_xml_doc_print (xmlDocPtr doc)
+soap_xml_doc_print(xmlDocPtr doc)
{
xmlBufferPtr buffer;
xmlNodePtr root;
if (doc == NULL)
{
- puts ("xmlDocPtr is NULL!");
+ puts("xmlDocPtr is NULL!");
return;
}
- root = xmlDocGetRootElement (doc);
+ root = xmlDocGetRootElement(doc);
if (root == NULL)
{
- puts ("Empty document!");
+ puts("Empty document!");
return;
}
- buffer = xmlBufferCreate ();
- xmlNodeDump (buffer, doc, root, 1, 0);
- puts ((const char *) xmlBufferContent (buffer));
- xmlBufferFree (buffer);
+ buffer = xmlBufferCreate();
+ xmlNodeDump(buffer, doc, root, 1, 0);
+ puts((const char *) xmlBufferContent(buffer));
+ xmlBufferFree(buffer);
}
char *
-soap_xml_get_text (xmlNodePtr node)
+soap_xml_get_text(xmlNodePtr node)
{
- return (char *) xmlNodeListGetString (node->doc, node->xmlChildrenNode, 1);
+ return (char *) xmlNodeListGetString(node->doc, node->xmlChildrenNode, 1);
}
diff --git a/libcsoap/soap-xml.h b/libcsoap/soap-xml.h
index de11e2d..9ab07ea 100644
--- a/libcsoap/soap-xml.h
+++ b/libcsoap/soap-xml.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-xml.h,v 1.6 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: soap-xml.h,v 1.7 2006/01/10 11:29:04 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -32,17 +32,17 @@
typedef int (*soap_xmlnode_callback) (xmlNodePtr, void *);
-xmlNodePtr soap_xml_get_children (xmlNodePtr param);
-xmlNodePtr soap_xml_get_next (xmlNodePtr param);
+xmlNodePtr soap_xml_get_children(xmlNodePtr param);
+xmlNodePtr soap_xml_get_next(xmlNodePtr param);
-xmlXPathObjectPtr soap_xpath_eval (xmlDocPtr doc, const char *xpath);
+xmlXPathObjectPtr soap_xpath_eval(xmlDocPtr doc, const char *xpath);
int
-soap_xpath_foreach (xmlDocPtr doc, const char *xpath,
- soap_xmlnode_callback cb, void *userdata);
+soap_xpath_foreach(xmlDocPtr doc, const char *xpath,
+ soap_xmlnode_callback cb, void *userdata);
-void soap_xml_doc_print (xmlDocPtr doc);
-char *soap_xml_get_text (xmlNodePtr node);
+void soap_xml_doc_print(xmlDocPtr doc);
+char *soap_xml_get_text(xmlNodePtr node);
#endif
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c
index b5a3fd0..e61e5af 100644
--- a/nanohttp/nanohttp-client.c
+++ b/nanohttp/nanohttp-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-client.c,v 1.32 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-client.c,v 1.33 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -40,7 +40,7 @@
#if 0
static int
-httpc_send_data (httpc_conn_t * conn, const unsigned char *data, size_t size)
+httpc_send_data(httpc_conn_t * conn, const unsigned char *data, size_t size)
{
return -1;
}
@@ -51,10 +51,10 @@ DESC: Initialize http client connection
NOTE: This will be called from soap_client_init_args()
----------------------------------------------------*/
herror_t
-httpc_init (int argc, char *argv[])
+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;
}
@@ -64,9 +64,9 @@ FUNCTION: httpc_destroy
DESC: Destroy the http client module
----------------------------------------------------*/
void
-httpc_destroy ()
+httpc_destroy()
{
- hsocket_module_destroy ();
+ hsocket_module_destroy();
}
@@ -77,12 +77,12 @@ You need to create at least 1 http client connection
to communicate via http.
----------------------------------------------------*/
httpc_conn_t *
-httpc_new ()
+httpc_new()
{
static int counter = 10000;
- httpc_conn_t *res = (httpc_conn_t *) malloc (sizeof (httpc_conn_t));
+ httpc_conn_t *res = (httpc_conn_t *) malloc(sizeof(httpc_conn_t));
- if (hsocket_init (&res->sock) != H_OK)
+ if (hsocket_init(&res->sock) != H_OK)
{
return NULL;
}
@@ -102,7 +102,7 @@ FUNCTION: httpc_free
DESC: Free the given http client object.
----------------------------------------------------*/
void
-httpc_free (httpc_conn_t * conn)
+httpc_free(httpc_conn_t * conn)
{
hpair_t *tmp;
@@ -114,17 +114,17 @@ httpc_free (httpc_conn_t * conn)
{
tmp = conn->header;
conn->header = conn->header->next;
- hpairnode_free (tmp);
+ hpairnode_free(tmp);
}
if (conn->out != NULL)
{
- http_output_stream_free (conn->out);
+ http_output_stream_free(conn->out);
conn->out = NULL;
}
- hsocket_free (conn->sock);
- free (conn);
+ hsocket_free(conn->sock);
+ free(conn);
}
@@ -133,13 +133,13 @@ httpc_free (httpc_conn_t * conn)
DESC: Close and free the given http client object.
----------------------------------------------------*/
void
-httpc_close_free (httpc_conn_t * conn)
+httpc_close_free(httpc_conn_t * conn)
{
if (conn == NULL)
return;
- hsocket_close (conn->sock);
- httpc_free (conn);
+ hsocket_close(conn->sock);
+ httpc_free(conn);
}
@@ -150,13 +150,13 @@ or modifies the old pair if this function will
finds another pair with the same 'key' value.
----------------------------------------------------*/
int
-httpc_set_header (httpc_conn_t * conn, const char *key, const char *value)
+httpc_set_header(httpc_conn_t * conn, const char *key, const char *value)
{
hpair_t *p;
if (conn == NULL)
{
- log_warn1 ("Connection object is NULL");
+ log_warn1("Connection object is NULL");
return 0;
}
p = conn->header;
@@ -164,18 +164,18 @@ httpc_set_header (httpc_conn_t * conn, const char *key, const char *value)
{
if (p->key != NULL)
{
- if (!strcmp (p->key, key))
+ if (!strcmp(p->key, key))
{
- free (p->value);
- p->value = (char *) malloc (strlen (value) + 1);
- strcpy (p->value, value);
+ free(p->value);
+ p->value = (char *) malloc(strlen(value) + 1);
+ strcpy(p->value, value);
return 1;
}
}
p = p->next;
}
- conn->header = hpairnode_new (key, value, conn->header);
+ conn->header = hpairnode_new(key, value, conn->header);
return 0;
}
@@ -185,15 +185,15 @@ FUNCTION: httpc_header_add_date
DESC: Adds the current date to the header.
----------------------------------------------------*/
static void
-_httpc_set_error (httpc_conn_t * conn, int errcode, const char *format, ...)
+_httpc_set_error(httpc_conn_t * conn, int errcode, const char *format, ...)
{
va_list ap;
conn->errcode = errcode;
- va_start (ap, format);
- vsprintf (conn->errmsg, format, ap);
- va_end (ap);
+ va_start(ap, format);
+ vsprintf(conn->errmsg, format, ap);
+ va_end(ap);
}
/*--------------------------------------------------
@@ -201,17 +201,17 @@ FUNCTION: httpc_header_add_date
DESC: Adds the current date to the header.
----------------------------------------------------*/
static void
-httpc_header_add_date (httpc_conn_t * conn)
+httpc_header_add_date(httpc_conn_t * conn)
{
char buffer[255];
time_t nw;
struct tm stm;
/* Set date */
- nw = time (NULL);
- localtime_r (&nw, &stm);
- strftime (buffer, 255, "%a, %d %b %Y %T GMT", &stm);
- httpc_set_header (conn, HEADER_DATE, buffer);
+ nw = time(NULL);
+ localtime_r(&nw, &stm);
+ strftime(buffer, 255, "%a, %d %b %Y %T GMT", &stm);
+ httpc_set_header(conn, HEADER_DATE, buffer);
}
@@ -222,7 +222,7 @@ DESC: Sends the current header information stored
in conn through conn->sock.
----------------------------------------------------*/
herror_t
-httpc_send_header (httpc_conn_t * conn)
+httpc_send_header(httpc_conn_t * conn)
{
hpair_t *p;
herror_t status;
@@ -233,15 +233,15 @@ httpc_send_header (httpc_conn_t * conn)
{
if (p->key && p->value)
{
- sprintf (buffer, "%s: %s\r\n", p->key, p->value);
- status = hsocket_send (conn->sock, buffer);
+ sprintf(buffer, "%s: %s\r\n", p->key, p->value);
+ status = hsocket_send(conn->sock, buffer);
if (status != H_OK)
return status;
}
p = p->next;
}
- status = hsocket_send (conn->sock, "\r\n");
+ status = hsocket_send(conn->sock, "\r\n");
return status;
}
@@ -291,8 +291,8 @@ If success, this function will return 0.
>0 otherwise.
----------------------------------------------------*/
static herror_t
-httpc_talk_to_server (hreq_method_t method, httpc_conn_t * conn,
- const char *urlstr)
+httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
+ const char *urlstr)
{
hurl_t url;
@@ -301,26 +301,26 @@ httpc_talk_to_server (hreq_method_t method, httpc_conn_t * conn,
if (conn == NULL)
{
- return herror_new ("httpc_talk_to_server",
- GENERAL_INVALID_PARAM, "httpc_conn_t param is NULL");
+ return herror_new("httpc_talk_to_server",
+ GENERAL_INVALID_PARAM, "httpc_conn_t param is NULL");
}
/* Build request header */
- httpc_header_add_date (conn);
+ httpc_header_add_date(conn);
/* Create url */
- status = hurl_parse (&url, urlstr);
+ status = hurl_parse(&url, urlstr);
if (status != H_OK)
{
- log_error2 ("Can not parse URL '%s'", SAVE_STR (urlstr));
+ log_error2("Can not parse URL '%s'", SAVE_STR(urlstr));
return status;
}
/* TODO (#1#): Check for HTTP protocol in URL */
/* Set hostname */
- httpc_set_header (conn, HEADER_HOST, url.host);
+ httpc_set_header(conn, HEADER_HOST, url.host);
/* Open connection */
- status = hsocket_open (&conn->sock, url.host, url.port);
+ status = hsocket_open(&conn->sock, url.host, url.port);
if (status != H_OK)
{
return status;
@@ -329,10 +329,10 @@ httpc_talk_to_server (hreq_method_t method, httpc_conn_t * conn,
/* TODO XXX XXX this is probably not right -- matt */
if (!&conn->sock.ssl)
{
- status = hsocket_block (conn->sock, conn->block);
+ status = hsocket_block(conn->sock, conn->block);
if (status != H_OK)
{
- log_error1 ("Cannot make socket non-blocking");
+ log_error1("Cannot make socket non-blocking");
return status;
}
}
@@ -342,42 +342,42 @@ httpc_talk_to_server (hreq_method_t method, httpc_conn_t * conn,
{
/* Set GET Header */
- sprintf (buffer, "GET %s HTTP/%s\r\n",
- (url.context[0] != '\0') ? url.context : ("/"),
- (conn->version == HTTP_1_0) ? "1.0" : "1.1");
+ sprintf(buffer, "GET %s HTTP/%s\r\n",
+ (url.context[0] != '\0') ? url.context : ("/"),
+ (conn->version == HTTP_1_0) ? "1.0" : "1.1");
}
else if (method == HTTP_REQUEST_POST)
{
/* Set POST Header */
- sprintf (buffer, "POST %s HTTP/%s\r\n",
- (url.context[0] != '\0') ? url.context : ("/"),
- (conn->version == HTTP_1_0) ? "1.0" : "1.1");
+ sprintf(buffer, "POST %s HTTP/%s\r\n",
+ (url.context[0] != '\0') ? url.context : ("/"),
+ (conn->version == HTTP_1_0) ? "1.0" : "1.1");
}
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");
+ 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");
}
- log_verbose1 ("Sending header...");
- status = hsocket_send (conn->sock, buffer);
+ log_verbose1("Sending header...");
+ status = hsocket_send(conn->sock, buffer);
if (status != H_OK)
{
- log_error2 ("Can not send request (status:%d)", status);
- hsocket_close (conn->sock);
+ log_error2("Can not send request (status:%d)", status);
+ hsocket_close(conn->sock);
return status;
}
/* Send Header */
- status = httpc_send_header (conn);
+ status = httpc_send_header(conn);
if (status != H_OK)
{
- log_error2 ("Can not send header (status:%d)", status);
- hsocket_close (conn->sock);
+ log_error2("Can not send header (status:%d)", status);
+ hsocket_close(conn->sock);
return status;
}
@@ -390,18 +390,18 @@ FUNCTION: httpc_get
DESC:
----------------------------------------------------*/
herror_t
-httpc_get (httpc_conn_t * conn, hresponse_t ** out, const char *urlstr)
+httpc_get(httpc_conn_t * conn, hresponse_t ** out, const char *urlstr)
{
herror_t status;
- status = httpc_talk_to_server (HTTP_REQUEST_GET, conn, urlstr);
+ status = httpc_talk_to_server(HTTP_REQUEST_GET, conn, urlstr);
if (status != H_OK)
{
return status;
}
- status = hresponse_new_from_socket (conn->sock, out);
+ status = hresponse_new_from_socket(conn->sock, out);
if (status != H_OK)
{
return status;
@@ -417,16 +417,16 @@ FUNCTION: httpc_post_begin
DESC: Returns H_OK if success
----------------------------------------------------*/
herror_t
-httpc_post_begin (httpc_conn_t * conn, const char *url)
+httpc_post_begin(httpc_conn_t * conn, const char *url)
{
herror_t status;
- status = httpc_talk_to_server (HTTP_REQUEST_POST, conn, url);
+ status = httpc_talk_to_server(HTTP_REQUEST_POST, conn, url);
if (status != H_OK)
return status;
- conn->out = http_output_stream_new (conn->sock, conn->header);
+ conn->out = http_output_stream_new(conn->sock, conn->header);
return H_OK;
}
@@ -438,18 +438,18 @@ DESC: 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)
+httpc_post_end(httpc_conn_t * conn, hresponse_t ** out)
{
herror_t status;
- status = http_output_stream_flush (conn->out);
+ status = http_output_stream_flush(conn->out);
if (status != H_OK)
{
return status;
}
- status = hresponse_new_from_socket (conn->sock, out);
+ status = hresponse_new_from_socket(conn->sock, out);
if (status != H_OK)
{
return status;
@@ -612,16 +612,16 @@ hresponse_t* httpc_dime_end(httpc_conn_t *conn)
-----------------------------------------------------*/
static void
-_httpc_mime_get_boundary (httpc_conn_t * conn, char *dest)
+_httpc_mime_get_boundary(httpc_conn_t * conn, char *dest)
{
- sprintf (dest, "---=.Part_NH_%d", conn->id);
- log_verbose2 ("boundary= \"%s\"", dest);
+ sprintf(dest, "---=.Part_NH_%d", conn->id);
+ log_verbose2("boundary= \"%s\"", dest);
}
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)
+httpc_mime_begin(httpc_conn_t * conn, const char *url,
+ const char *related_start,
+ const char *related_start_info, const char *related_type)
{
herror_t status;
char buffer[300];
@@ -633,7 +633,7 @@ httpc_mime_begin (httpc_conn_t * conn, const char *url,
start-info= ..; boundary=...
*/
- sprintf (buffer, "multipart/related;");
+ sprintf(buffer, "multipart/related;");
/*
using sprintf instead of snprintf because visual c does not support
snprintf */
@@ -643,96 +643,93 @@ httpc_mime_begin (httpc_conn_t * conn, const char *url,
if (related_type)
{
- snprintf (temp, 75, " type=\"%s\";", related_type);
- strcat (buffer, temp);
+ snprintf(temp, 75, " type=\"%s\";", related_type);
+ strcat(buffer, temp);
}
if (related_start)
{
- snprintf (temp, 75, " start=\"%s\";", related_start);
- strcat (buffer, temp);
+ snprintf(temp, 75, " start=\"%s\";", related_start);
+ strcat(buffer, temp);
}
if (related_start_info)
{
- snprintf (temp, 75, " start-info=\"%s\";", related_start_info);
- strcat (buffer, temp);
+ snprintf(temp, 75, " start-info=\"%s\";", related_start_info);
+ strcat(buffer, temp);
}
- _httpc_mime_get_boundary (conn, boundary);
- snprintf (temp, 75, " boundary=\"%s\"", boundary);
- strcat (buffer, temp);
+ _httpc_mime_get_boundary(conn, boundary);
+ snprintf(temp, 75, " boundary=\"%s\"", boundary);
+ strcat(buffer, temp);
- httpc_set_header (conn, HEADER_CONTENT_TYPE, buffer);
+ httpc_set_header(conn, HEADER_CONTENT_TYPE, buffer);
- status = httpc_post_begin (conn, url);
+ status = httpc_post_begin(conn, url);
return status;
}
herror_t
-httpc_mime_next (httpc_conn_t * conn,
- const char *content_id,
- const char *content_type, const char *transfer_encoding)
+httpc_mime_next(httpc_conn_t * conn,
+ const char *content_id,
+ const char *content_type, const char *transfer_encoding)
{
herror_t status;
char buffer[512];
char boundary[75];
/* Get the boundary string */
- _httpc_mime_get_boundary (conn, boundary);
- sprintf (buffer, "\r\n--%s\r\n", boundary);
+ _httpc_mime_get_boundary(conn, boundary);
+ sprintf(buffer, "\r\n--%s\r\n", boundary);
/* Send boundary */
- status = http_output_stream_write (conn->out,
- (const byte_t *) buffer,
- strlen (buffer));
+ status = http_output_stream_write(conn->out,
+ (const byte_t *) buffer, strlen(buffer));
if (status != H_OK)
return status;
/* Send Content header */
- sprintf (buffer, "%s: %s\r\n%s: %s\r\n%s: %s\r\n\r\n",
- HEADER_CONTENT_TYPE, content_type,
- HEADER_CONTENT_TRANSFER_ENCODING, transfer_encoding,
- HEADER_CONTENT_ID, content_id);
+ sprintf(buffer, "%s: %s\r\n%s: %s\r\n%s: %s\r\n\r\n",
+ HEADER_CONTENT_TYPE, content_type,
+ HEADER_CONTENT_TRANSFER_ENCODING, transfer_encoding,
+ HEADER_CONTENT_ID, content_id);
- status = http_output_stream_write (conn->out,
- (const byte_t *) buffer,
- strlen (buffer));
+ status = http_output_stream_write(conn->out,
+ (const byte_t *) buffer, strlen(buffer));
return status;
}
herror_t
-httpc_mime_end (httpc_conn_t * conn, hresponse_t ** out)
+httpc_mime_end(httpc_conn_t * conn, hresponse_t ** out)
{
herror_t status;
char buffer[512];
char boundary[75];
/* Get the boundary string */
- _httpc_mime_get_boundary (conn, boundary);
- sprintf (buffer, "\r\n--%s--\r\n\r\n", boundary);
+ _httpc_mime_get_boundary(conn, boundary);
+ sprintf(buffer, "\r\n--%s--\r\n\r\n", boundary);
/* Send boundary */
- status = http_output_stream_write (conn->out,
- (const byte_t *) buffer,
- strlen (buffer));
+ status = http_output_stream_write(conn->out,
+ (const byte_t *) buffer, strlen(buffer));
if (status != H_OK)
return status;
/* Flush put stream */
- status = http_output_stream_flush (conn->out);
+ status = http_output_stream_flush(conn->out);
if (status != H_OK)
{
return status;
}
- status = hresponse_new_from_socket (conn->sock, out);
+ status = hresponse_new_from_socket(conn->sock, out);
if (status != H_OK)
{
return status;
@@ -748,51 +745,50 @@ httpc_mime_end (httpc_conn_t * conn, hresponse_t ** out)
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)
+httpc_mime_send_file(httpc_conn_t * conn,
+ const char *content_id,
+ const char *content_type,
+ const char *transfer_encoding, const char *filename)
{
herror_t status;
- FILE *fd = fopen (filename, "rb");
+ FILE *fd = fopen(filename, "rb");
byte_t buffer[MAX_FILE_BUFFER_SIZE];
size_t size;
if (fd == NULL)
- return herror_new ("httpc_mime_send_file", FILE_ERROR_OPEN,
- "Can not open file '%s'", filename);
+ return herror_new("httpc_mime_send_file", FILE_ERROR_OPEN,
+ "Can not open file '%s'", filename);
- status =
- httpc_mime_next (conn, content_id, content_type, transfer_encoding);
+ status = httpc_mime_next(conn, content_id, content_type, transfer_encoding);
if (status != H_OK)
{
- fclose (fd);
+ fclose(fd);
return status;
}
- while (!feof (fd))
+ while (!feof(fd))
{
- size = fread (buffer, 1, MAX_FILE_BUFFER_SIZE, fd);
+ size = fread(buffer, 1, MAX_FILE_BUFFER_SIZE, fd);
if (size == -1)
{
- fclose (fd);
- return herror_new ("httpc_mime_send_file", FILE_ERROR_READ,
- "Can not read from file '%s'", filename);
+ fclose(fd);
+ return herror_new("httpc_mime_send_file", FILE_ERROR_READ,
+ "Can not read from file '%s'", filename);
}
if (size > 0)
{
/* DEBUG: fwrite(buffer, 1, size, stdout); */
- status = http_output_stream_write (conn->out, buffer, size);
+ status = http_output_stream_write(conn->out, buffer, size);
if (status != H_OK)
{
- fclose (fd);
+ fclose(fd);
return status;
}
}
}
- fclose (fd);
- log_verbose1 ("file sent!");
+ fclose(fd);
+ log_verbose1("file sent!");
return H_OK;
}
diff --git a/nanohttp/nanohttp-client.h b/nanohttp/nanohttp-client.h
index 77c8e8e..2b93617 100644
--- a/nanohttp/nanohttp-client.h
+++ b/nanohttp/nanohttp-client.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-client.h,v 1.17 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: nanohttp-client.h,v 1.18 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -55,57 +55,56 @@ typedef struct httpc_conn
/**
initialize the httpc_* module
*/
-herror_t httpc_init (int argc, char *argv[]);
+herror_t httpc_init(int argc, char *argv[]);
/**
Destroy the httpc_* module
*/
-void httpc_destroy ();
+void httpc_destroy();
/**
Creates a new connection
*/
-httpc_conn_t *httpc_new ();
+httpc_conn_t *httpc_new();
/**
Close and release a connection
*/
-void httpc_close_free (httpc_conn_t * conn);
+void httpc_close_free(httpc_conn_t * conn);
/**
Release a connection
(use httpc_close_free() instead)
*/
-void httpc_free (httpc_conn_t * conn);
+void httpc_free(httpc_conn_t * conn);
/**
* Close and release a connection
*/
-void httpc_close_free (httpc_conn_t * conn);
+void httpc_close_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);
+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);
+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);
+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);
+herror_t httpc_post_end(httpc_conn_t * conn, hresponse_t ** out);
/* --------------------------------------------------------------
@@ -134,34 +133,34 @@ hresponse_t* httpc_dime_end(httpc_conn_t *conn);
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);
+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);
+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);
+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);
+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 7d7b141..3dcee6b 100644
--- a/nanohttp/nanohttp-common.c
+++ b/nanohttp/nanohttp-common.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-common.c,v 1.21 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-common.c,v 1.22 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -50,24 +50,24 @@ extern int SSLCertLess;
/* option stuff */
void
-hoption_set (int opt, const char *value)
+hoption_set(int opt, const char *value)
{
if (opt >= MAX_OPTION_SIZE)
{
- log_warn3 ("Option to high (%d >= %d)", 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);
+ strncpy(_hoption_table[opt], value, MAX_OPTION_VALUE_SIZE);
}
char *
-hoption_get (int opt)
+hoption_get(int opt)
{
if (opt >= MAX_OPTION_SIZE)
{
- log_warn3 ("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
+ log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
return "";
}
@@ -76,59 +76,59 @@ hoption_get (int opt)
void
-hoption_init_args (int argc, char *argv[])
+hoption_init_args(int argc, char *argv[])
{
int i;
- hoption_set (HOPTION_TMP_DIR, "."); /* default value */
+ 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)
+ if (!strcmp(argv[i], NHTTP_ARG_TMPDIR) && i < argc - 1)
{
- hoption_set (HOPTION_TMP_DIR, argv[i + 1]);
+ hoption_set(HOPTION_TMP_DIR, argv[i + 1]);
}
- else if (!strcmp (argv[i], NHTTP_ARG_LOGFILE) && i < argc - 1)
+ else if (!strcmp(argv[i], NHTTP_ARG_LOGFILE) && i < argc - 1)
{
- log_set_file (argv[i + 1]);
+ log_set_file(argv[i + 1]);
}
- else if (!strcmp (argv[i], NHTTP_ARG_CERT) && i < argc - 1)
+ else if (!strcmp(argv[i], NHTTP_ARG_CERT) && i < argc - 1)
{
#ifndef HAVE_SSL
- fprintf (stderr,
- "WARNING: csoap compiled without '--with-ssl' flag. Parameter '%s' is disabled",
- NHTTP_ARG_CERT);
+ fprintf(stderr,
+ "WARNING: csoap compiled without '--with-ssl' flag. Parameter '%s' is disabled",
+ NHTTP_ARG_CERT);
#else
SSLCert = argv[i + 1];
#endif
}
- else if (!strcmp (argv[i], NHTTP_ARG_CERTPASS) && i < argc - 1)
+ else if (!strcmp(argv[i], NHTTP_ARG_CERTPASS) && i < argc - 1)
{
#ifndef HAVE_SSL
- fprintf (stderr,
- "WARNING: csoap compiled without '--with-ssl' flag. Parameter '%s' is disabled",
- NHTTP_ARG_CERTPASS);
+ fprintf(stderr,
+ "WARNING: csoap compiled without '--with-ssl' flag. Parameter '%s' is disabled",
+ NHTTP_ARG_CERTPASS);
#else
SSLPass = argv[i + 1];
#endif
}
- else if (!strcmp (argv[i], NHTTP_ARG_CA) && i < argc - 1)
+ else if (!strcmp(argv[i], NHTTP_ARG_CA) && i < argc - 1)
{
#ifndef HAVE_SSL
- fprintf (stderr,
- "WARNING: csoap compiled without '--with-ssl' flag. Parameter '%s' is disabled",
- NHTTP_ARG_CA);
+ fprintf(stderr,
+ "WARNING: csoap compiled without '--with-ssl' flag. Parameter '%s' is disabled",
+ NHTTP_ARG_CA);
#else
SSLCA = argv[i + 1];
#endif
}
- else if (!strcmp (argv[i], NHTTP_ARG_HTTPS))
+ else if (!strcmp(argv[i], NHTTP_ARG_HTTPS))
{
#ifndef HAVE_SSL
- fprintf (stderr,
- "WARNING: csoap compiled without '--with-ssl' flag. Parameter '%s' is disabled",
- NHTTP_ARG_HTTPS);
+ fprintf(stderr,
+ "WARNING: csoap compiled without '--with-ssl' flag. Parameter '%s' is disabled",
+ NHTTP_ARG_HTTPS);
#else
SSLCertLess = 1;
#endif
@@ -144,13 +144,13 @@ hoption_init_args (int argc, char *argv[])
/* not thread safe!*/
char *
-VisualC_funcname (const char *file, int line)
+VisualC_funcname(const char *file, int line)
{
static char buffer[256];
- int i = strlen (file) - 1;
+ int i = strlen(file) - 1;
while (i > 0 && file[i] != '\\')
i--;
- sprintf (buffer, "%s:%d", (file[i] != '\\') ? file : (file + i + 1), line);
+ sprintf(buffer, "%s:%d", (file[i] != '\\') ? file : (file + i + 1), line);
return buffer;
}
@@ -166,23 +166,23 @@ typedef struct _herror_impl_t
herror_t
-herror_new (const char *func, int errcode, const char *format, ...)
+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));
+ 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);
+ 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_code(herror_t err)
{
herror_impl_t *impl = (herror_impl_t *) err;
if (!err)
@@ -191,7 +191,7 @@ herror_code (herror_t err)
}
char *
-herror_func (herror_t err)
+herror_func(herror_t err)
{
herror_impl_t *impl = (herror_impl_t *) err;
if (!err)
@@ -200,7 +200,7 @@ herror_func (herror_t err)
}
char *
-herror_message (herror_t err)
+herror_message(herror_t err)
{
herror_impl_t *impl = (herror_impl_t *) err;
if (!err)
@@ -209,12 +209,12 @@ herror_message (herror_t err)
}
void
-herror_release (herror_t err)
+herror_release(herror_t err)
{
herror_impl_t *impl = (herror_impl_t *) err;
if (!err)
return;
- free (impl);
+ free(impl);
}
@@ -224,7 +224,7 @@ static char logfile[75] = { '\0' };
static int log_background = 0;
log_level_t
-log_set_level (log_level_t level)
+log_set_level(log_level_t level)
{
log_level_t old = loglevel;
loglevel = level;
@@ -233,29 +233,29 @@ log_set_level (log_level_t level)
log_level_t
-log_get_level ()
+log_get_level()
{
return loglevel;
}
void
-log_set_file (const char *filename)
+log_set_file(const char *filename)
{
if (filename)
- strncpy (logfile, filename, 75);
+ strncpy(logfile, filename, 75);
else
logfile[0] = '\0';
}
void
-log_set_background (int state)
+log_set_background(int state)
{
log_background = state;
}
char *
-log_get_file ()
+log_get_file()
{
if (logfile[0] == '\0')
return NULL;
@@ -263,8 +263,8 @@ log_get_file ()
}
static void
-log_write (log_level_t level, const char *prefix,
- const char *func, const char *format, va_list ap)
+log_write(log_level_t level, const char *prefix,
+ const char *func, const char *format, va_list ap)
{
char buffer[1054];
char buffer2[1054];
@@ -273,84 +273,84 @@ log_write (log_level_t level, const char *prefix,
if (level < loglevel)
return;
- if (!log_background || log_get_file ())
+ if (!log_background || log_get_file())
{
#ifdef WIN32
- sprintf (buffer, "*%s*: [%s] %s\n", prefix, func, format);
+ sprintf(buffer, "*%s*: [%s] %s\n", prefix, func, format);
#else
- sprintf (buffer, "*%s*:(%d) [%s] %s\n",
- prefix, pthread_self (), func, format);
+ sprintf(buffer, "*%s*:(%d) [%s] %s\n",
+ prefix, pthread_self(), func, format);
#endif
- vsprintf (buffer2, buffer, ap);
+ vsprintf(buffer2, buffer, ap);
if (!log_background)
{
- printf (buffer2);
- fflush (stdout);
+ printf(buffer2);
+ fflush(stdout);
}
- if (log_get_file ())
+ if (log_get_file())
{
- f = fopen (log_get_file (), "a");
+ f = fopen(log_get_file(), "a");
if (!f)
- f = fopen (log_get_file (), "w");
+ f = fopen(log_get_file(), "w");
if (f)
{
- fprintf (f, buffer2);
- fflush (f);
- fclose (f);
+ fprintf(f, buffer2);
+ fflush(f);
+ fclose(f);
}
}
}
}
void
-log_verbose (const char *FUNC, const char *format, ...)
+log_verbose(const char *FUNC, const char *format, ...)
{
va_list ap;
- va_start (ap, format);
- log_write (HLOG_VERBOSE, "VERBOSE", FUNC, format, ap);
- va_end (ap);
+ va_start(ap, format);
+ log_write(HLOG_VERBOSE, "VERBOSE", FUNC, format, ap);
+ va_end(ap);
}
void
-log_debug (const char *FUNC, const char *format, ...)
+log_debug(const char *FUNC, const char *format, ...)
{
va_list ap;
- va_start (ap, format);
- log_write (HLOG_DEBUG, "DEBUG", FUNC, format, ap);
- va_end (ap);
+ va_start(ap, format);
+ log_write(HLOG_DEBUG, "DEBUG", FUNC, format, ap);
+ va_end(ap);
}
void
-log_info (const char *FUNC, const char *format, ...)
+log_info(const char *FUNC, const char *format, ...)
{
va_list ap;
- va_start (ap, format);
- log_write (HLOG_INFO, "INFO", FUNC, format, ap);
- va_end (ap);
+ va_start(ap, format);
+ log_write(HLOG_INFO, "INFO", FUNC, format, ap);
+ va_end(ap);
}
void
-log_warn (const char *FUNC, const char *format, ...)
+log_warn(const char *FUNC, const char *format, ...)
{
va_list ap;
- va_start (ap, format);
- log_write (HLOG_WARN, "WARN", FUNC, format, ap);
- va_end (ap);
+ va_start(ap, format);
+ log_write(HLOG_WARN, "WARN", FUNC, format, ap);
+ va_end(ap);
}
void
-log_error (const char *FUNC, const char *format, ...)
+log_error(const char *FUNC, const char *format, ...)
{
va_list ap;
- va_start (ap, format);
- log_write (HLOG_ERROR, "ERROR", FUNC, format, ap);
- va_end (ap);
+ va_start(ap, format);
+ log_write(HLOG_ERROR, "ERROR", FUNC, format, ap);
+ va_end(ap);
}
@@ -358,7 +358,7 @@ log_error (const char *FUNC, const char *format, ...)
FUNCTION: strcmpigcase
------------------------------------------*/
int
-strcmpigcase (const char *s1, const char *s2)
+strcmpigcase(const char *s1, const char *s2)
{
int l1, l2, i;
@@ -367,14 +367,14 @@ strcmpigcase (const char *s1, const char *s2)
if (s1 == NULL || s2 == NULL)
return 0;
- l1 = strlen (s1);
- l2 = strlen (s2);
+ l1 = strlen(s1);
+ l2 = strlen(s2);
if (l1 != l2)
return 0;
for (i = 0; i < l1; i++)
- if (toupper (s1[i]) != toupper (s2[i]))
+ if (toupper(s1[i]) != toupper(s2[i]))
return 0;
return 1;
@@ -382,17 +382,17 @@ strcmpigcase (const char *s1, const char *s2)
hpair_t *
-hpairnode_new (const char *key, const char *value, hpair_t * next)
+hpairnode_new(const char *key, const char *value, hpair_t * next)
{
hpair_t *pair;
- log_verbose3 ("new pair ('%s','%s')", SAVE_STR (key), SAVE_STR (value));
- pair = (hpair_t *) malloc (sizeof (hpair_t));
+ log_verbose3("new pair ('%s','%s')", SAVE_STR(key), SAVE_STR(value));
+ pair = (hpair_t *) malloc(sizeof(hpair_t));
if (key != NULL)
{
- pair->key = (char *) malloc (strlen (key) + 1);
- strcpy (pair->key, key);
+ pair->key = (char *) malloc(strlen(key) + 1);
+ strcpy(pair->key, key);
}
else
{
@@ -401,8 +401,8 @@ hpairnode_new (const char *key, const char *value, hpair_t * next)
if (value != NULL)
{
- pair->value = (char *) malloc (strlen (value) + 1);
- strcpy (pair->value, value);
+ pair->value = (char *) malloc(strlen(value) + 1);
+ strcpy(pair->value, value);
}
else
{
@@ -415,63 +415,63 @@ hpairnode_new (const char *key, const char *value, hpair_t * next)
}
hpair_t *
-hpairnode_parse (const char *str, const char *delim, hpair_t * next)
+hpairnode_parse(const char *str, const char *delim, hpair_t * next)
{
hpair_t *pair;
char *key, *value;
int c;
- pair = (hpair_t *) malloc (sizeof (hpair_t));
+ pair = (hpair_t *) malloc(sizeof(hpair_t));
pair->key = "";
pair->value = "";
pair->next = next;
- key = strtok_r ((char *) str, delim, &value);
+ key = strtok_r((char *) str, delim, &value);
if (key != NULL)
{
- pair->key = (char *) malloc (strlen (key) + 1);
- strcpy (pair->key, key);
+ pair->key = (char *) malloc(strlen(key) + 1);
+ strcpy(pair->key, key);
}
if (value != NULL)
{
for (c = 0; value[c] == ' '; c++); /* skip white space */
- pair->value = (char *) malloc (strlen (&value[c]) + 1);
- strcpy (pair->value, &value[c]);
+ pair->value = (char *) malloc(strlen(&value[c]) + 1);
+ strcpy(pair->value, &value[c]);
}
return pair;
}
hpair_t *
-hpairnode_copy (const hpair_t * src)
+hpairnode_copy(const hpair_t * src)
{
hpair_t *pair;
if (src == NULL)
return NULL;
- pair = hpairnode_new (src->key, src->value, NULL);
+ pair = hpairnode_new(src->key, src->value, NULL);
return pair;
}
hpair_t *
-hpairnode_copy_deep (const hpair_t * src)
+hpairnode_copy_deep(const hpair_t * src)
{
hpair_t *pair, *result, *next;
if (src == NULL)
return NULL;
- result = hpairnode_copy (src);
+ result = hpairnode_copy(src);
next = src->next;
pair = result;
while (next != NULL)
{
- pair->next = hpairnode_copy (next);
+ pair->next = hpairnode_copy(next);
pair = pair->next;
next = next->next;
}
@@ -481,75 +481,75 @@ hpairnode_copy_deep (const hpair_t * src)
void
-hpairnode_dump (hpair_t * pair)
+hpairnode_dump(hpair_t * pair)
{
if (pair == NULL)
{
- log_verbose1 ("(NULL)[]");
+ log_verbose1("(NULL)[]");
return;
}
- log_verbose5 ("(%p)['%s','%s','%p']", pair,
- SAVE_STR (pair->key), SAVE_STR (pair->value), pair->next);
+ log_verbose5("(%p)['%s','%s','%p']", pair,
+ SAVE_STR(pair->key), SAVE_STR(pair->value), pair->next);
}
void
-hpairnode_dump_deep (hpair_t * pair)
+hpairnode_dump_deep(hpair_t * pair)
{
hpair_t *p;
p = pair;
- log_verbose1 ("-- BEGIN dump hpairnode_t --");
+ log_verbose1("-- BEGIN dump hpairnode_t --");
while (p != NULL)
{
- hpairnode_dump (p);
+ hpairnode_dump(p);
p = p->next;
}
- log_verbose1 ("-- END dump hpairnode_t --\n");
+ log_verbose1("-- END dump hpairnode_t --\n");
}
void
-hpairnode_free (hpair_t * pair)
+hpairnode_free(hpair_t * pair)
{
if (pair == NULL)
return;
- free (pair->key);
- free (pair->value);
+ free(pair->key);
+ free(pair->value);
- free (pair);
+ free(pair);
}
void
-hpairnode_free_deep (hpair_t * pair)
+hpairnode_free_deep(hpair_t * pair)
{
hpair_t *tmp;
while (pair != NULL)
{
tmp = pair->next;
- hpairnode_free (pair);
+ hpairnode_free(pair);
pair = tmp;
}
}
char *
-hpairnode_get_ignore_case (hpair_t * pair, const char *key)
+hpairnode_get_ignore_case(hpair_t * pair, const char *key)
{
if (key == NULL)
{
- log_error1 ("key is NULL");
+ log_error1("key is NULL");
return NULL;
}
while (pair != NULL)
{
if (pair->key != NULL)
{
- if (strcmpigcase (pair->key, key))
+ if (strcmpigcase(pair->key, key))
{
return pair->value;
}
@@ -561,18 +561,18 @@ hpairnode_get_ignore_case (hpair_t * pair, const char *key)
}
char *
-hpairnode_get (hpair_t * pair, const char *key)
+hpairnode_get(hpair_t * pair, const char *key)
{
if (key == NULL)
{
- log_error1 ("key is NULL");
+ log_error1("key is NULL");
return NULL;
}
while (pair != NULL)
{
if (pair->key != NULL)
{
- if (!strcmp (pair->key, key))
+ if (!strcmp(pair->key, key))
{
return pair->value;
}
@@ -584,23 +584,23 @@ hpairnode_get (hpair_t * pair, const char *key)
}
static void
-hurl_dump (const hurl_t * url)
+hurl_dump(const hurl_t * url)
{
if (url == NULL)
{
- log_error1 ("url is NULL!");
+ log_error1("url is NULL!");
return;
}
- log_verbose2 ("PROTOCOL : %d", url->protocol);
- log_verbose2 (" HOST : %s", url->host);
- log_verbose2 (" PORT : %d", url->port);
- log_verbose2 (" CONTEXT : %s", url->context);
+ log_verbose2("PROTOCOL : %d", url->protocol);
+ log_verbose2(" HOST : %s", url->host);
+ log_verbose2(" PORT : %d", url->port);
+ log_verbose2(" CONTEXT : %s", url->context);
}
herror_t
-hurl_parse (hurl_t * url, const char *urlstr)
+hurl_parse(hurl_t * url, const char *urlstr)
{
int iprotocol;
int ihost;
@@ -611,7 +611,7 @@ hurl_parse (hurl_t * url, const char *urlstr)
char protocol[1024];
iprotocol = 0;
- len = strlen (urlstr);
+ len = strlen(urlstr);
/* find protocol */
while (urlstr[iprotocol] != ':' && urlstr[iprotocol] != '\0')
@@ -621,19 +621,19 @@ hurl_parse (hurl_t * url, const char *urlstr)
if (iprotocol == 0)
{
- log_error1 ("no protocol");
- return herror_new ("hurl_parse", URL_ERROR_NO_PROTOCOL, "No protocol");
+ log_error1("no protocol");
+ return herror_new("hurl_parse", URL_ERROR_NO_PROTOCOL, "No protocol");
}
if (iprotocol + 3 >= len)
{
- log_error1 ("no host");
- return herror_new ("hurl_parse", URL_ERROR_NO_HOST, "No host");
+ log_error1("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");
+ log_error1("no protocol");
+ return herror_new("hurl_parse", URL_ERROR_NO_PROTOCOL, "No protocol");
}
/* find host */
ihost = iprotocol + 3;
@@ -645,8 +645,8 @@ 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");
+ log_error1("no host");
+ return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
}
/* find port */
iport = ihost;
@@ -662,29 +662,29 @@ hurl_parse (hurl_t * url, const char *urlstr)
}
/* find protocol */
- strncpy (protocol, urlstr, iprotocol);
+ strncpy(protocol, urlstr, iprotocol);
protocol[iprotocol] = '\0';
- if (strcmpigcase (protocol, "http"))
+ if (strcmpigcase(protocol, "http"))
url->protocol = PROTOCOL_HTTP;
- else if (strcmpigcase (protocol, "https"))
+ else if (strcmpigcase(protocol, "https"))
url->protocol = PROTOCOL_HTTPS;
- else if (strcmpigcase (protocol, "ftp"))
+ else if (strcmpigcase(protocol, "ftp"))
url->protocol = PROTOCOL_FTP;
else
- return herror_new ("hurl_parse",
- URL_ERROR_UNKNOWN_PROTOCOL, "Unknown protocol '%s'",
- protocol);
+ 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;
- strncpy (url->host, &urlstr[iprotocol + 3], size);
+ strncpy(url->host, &urlstr[iprotocol + 3], size);
url->host[size] = '\0';
if (iport > ihost)
{
size = iport - ihost;
- strncpy (tmp, &urlstr[ihost + 1], size);
- url->port = atoi (tmp);
+ strncpy(tmp, &urlstr[ihost + 1], size);
+ url->port = atoi(tmp);
}
else
{
@@ -702,12 +702,12 @@ hurl_parse (hurl_t * url, const char *urlstr)
}
}
- len = strlen (urlstr);
+ len = strlen(urlstr);
if (len > iport)
{
/* TODO (#1#): find max of size and URL_MAX_CONTEXT_SIZE */
size = len - iport;
- strncpy (url->context, &urlstr[iport], size);
+ strncpy(url->context, &urlstr[iport], size);
url->context[size] = '\0';
}
else
@@ -715,7 +715,7 @@ hurl_parse (hurl_t * url, const char *urlstr)
url->context[0] = '\0';
}
- hurl_dump (url);
+ hurl_dump(url);
return H_OK;
}
@@ -724,7 +724,7 @@ hurl_parse (hurl_t * url, const char *urlstr)
/* Content-type stuff */
content_type_t *
-content_type_new (const char *content_type_str)
+content_type_new(const char *content_type_str)
{
hpair_t *pair = NULL, *last = NULL;
content_type_t *ct;
@@ -735,10 +735,10 @@ content_type_new (const char *content_type_str)
/* Create object */
- ct = (content_type_t *) malloc (sizeof (content_type_t));
+ ct = (content_type_t *) malloc(sizeof(content_type_t));
ct->params = NULL;
- len = strlen (content_type_str);
+ len = strlen(content_type_str);
while (i <= len)
{
if (i != len)
@@ -784,7 +784,7 @@ content_type_new (const char *content_type_str)
{
value[c] = '\0';
- pair = hpairnode_new (key, value, NULL);
+ pair = hpairnode_new(key, value, NULL);
if (ct->params == NULL)
ct->params = pair;
else
@@ -810,43 +810,43 @@ content_type_new (const char *content_type_str)
void
-content_type_free (content_type_t * ct)
+content_type_free(content_type_t * ct)
{
if (!ct)
return;
- hpairnode_free_deep (ct->params);
- free (ct);
+ hpairnode_free_deep(ct->params);
+ free(ct);
}
part_t *
-part_new (const char *id, const char *filename,
- const char *content_type, const char *transfer_encoding,
- part_t * next)
+part_new(const char *id, const char *filename,
+ const char *content_type, const char *transfer_encoding,
+ part_t * next)
{
- part_t *part = (part_t *) malloc (sizeof (part_t));
+ part_t *part = (part_t *) malloc(sizeof(part_t));
part->header = NULL;
part->next = next;
part->deleteOnExit = 0;
- strcpy (part->id, id);
- strcpy (part->filename, filename);
+ strcpy(part->id, id);
+ strcpy(part->filename, filename);
if (content_type)
- strcpy (part->content_type, content_type);
+ strcpy(part->content_type, content_type);
else
part->content_type[0] = '\0';
- part->header = hpairnode_new (HEADER_CONTENT_ID, id, part->header);
+ part->header = hpairnode_new(HEADER_CONTENT_ID, id, part->header);
/* TODO (#1#): encoding is always binary. implement also others! */
/* part->header = hpairnode_new(HEADER_CONTENT_TRANSFER_ENCODING, "binary", part->header);*/
- strcpy (part->transfer_encoding,
- transfer_encoding ? transfer_encoding : "binary");
+ strcpy(part->transfer_encoding,
+ transfer_encoding ? transfer_encoding : "binary");
if (content_type)
{
part->header =
- hpairnode_new (HEADER_CONTENT_TYPE, content_type, part->header);
+ hpairnode_new(HEADER_CONTENT_TYPE, content_type, part->header);
}
else
{
@@ -857,26 +857,26 @@ part_new (const char *id, const char *filename,
}
void
-part_free (part_t * part)
+part_free(part_t * part)
{
if (part == NULL)
return;
if (part->deleteOnExit)
{
- remove (part->filename);
+ remove(part->filename);
}
- hpairnode_free_deep (part->header);
+ hpairnode_free_deep(part->header);
- free (part);
+ free(part);
}
attachments_t *
-attachments_new () /* should be used internally */
+attachments_new() /* should be used internally */
{
attachments_t *attachments =
- (attachments_t *) malloc (sizeof (attachments_t));
+ (attachments_t *) malloc(sizeof(attachments_t));
attachments->parts = NULL;
attachments->last = NULL;
attachments->root_part = NULL;
@@ -885,7 +885,7 @@ attachments_new () /* should be used internally */
}
void
-attachments_add_part (attachments_t * attachments, part_t * part)
+attachments_add_part(attachments_t * attachments, part_t * part)
{
/* paranoya check */
if (!attachments)
@@ -903,7 +903,7 @@ attachments_add_part (attachments_t * attachments, part_t * part)
Free a mime message
*/
void
-attachments_free (attachments_t * message)
+attachments_free(attachments_t * message)
{
part_t *tmp, *part;
@@ -914,14 +914,14 @@ attachments_free (attachments_t * message)
while (part)
{
tmp = part->next;
- part_free (part);
+ part_free(part);
part = tmp;
}
if (message->root_part)
- part_free (message->root_part);
+ part_free(message->root_part);
/* TODO (#1#): HERE IS A BUG!!!! */
- free (message);
+ free(message);
}
@@ -929,7 +929,7 @@ attachments_free (attachments_t * message)
/* strtok_r() */
char *
-strtok_r (char *s, const char *delim, char **save_ptr)
+strtok_r(char *s, const char *delim, char **save_ptr)
{
char *token;
@@ -937,16 +937,16 @@ strtok_r (char *s, const char *delim, char **save_ptr)
s = *save_ptr;
/* Scan leading delimiters. */
- s += strspn (s, delim);
+ s += strspn(s, delim);
if (*s == '\0')
return NULL;
/* Find the end of the token. */
token = s;
- s = strpbrk (token, delim);
+ s = strpbrk(token, delim);
if (s == NULL)
/* This token finishes the string. */
- *save_ptr = strchr (token, '\0');
+ *save_ptr = strchr(token, '\0');
else
{
/* Terminate the token and make *SAVE_PTR point past it. */
@@ -958,13 +958,13 @@ strtok_r (char *s, const char *delim, char **save_ptr)
/* localtime_r() */
struct tm *
-localtime_r (const time_t * const timep, struct tm *p_tm)
+localtime_r(const time_t * const timep, struct tm *p_tm)
{
static struct tm *tmp;
- tmp = localtime (timep);
+ tmp = localtime(timep);
if (tmp)
{
- memcpy (p_tm, tmp, sizeof (struct tm));
+ memcpy(p_tm, tmp, sizeof(struct tm));
tmp = p_tm;
}
return tmp;
diff --git a/nanohttp/nanohttp-common.h b/nanohttp/nanohttp-common.h
index 36136b5..7a957ce 100644
--- a/nanohttp/nanohttp-common.h
+++ b/nanohttp/nanohttp-common.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-common.h,v 1.21 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: nanohttp-common.h,v 1.22 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -152,8 +152,8 @@ Set Sleep function platform depended
#ifdef WIN32
#include <string.h>
-char *strtok_r (char *s, const char *delim, char **save_ptr);
-struct tm *localtime_r (const time_t * const timep, struct tm *p_tm);
+char *strtok_r(char *s, const char *delim, char **save_ptr);
+struct tm *localtime_r(const time_t * const timep, struct tm *p_tm);
#endif
typedef unsigned char byte_t;
@@ -182,18 +182,18 @@ typedef enum _hreq_method
} 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
Returns 1 if s1 equals s2 and 0 otherwise.
*/
-int strcmpigcase (const char *s1, const char *s2);
+int strcmpigcase(const char *s1, const char *s2);
@@ -221,7 +221,7 @@ struct hpair
@returns A newly crated hpair_t object. Use hpair_free()
or hpair_free_deep() to free the pair.
*/
-hpair_t *hpairnode_new (const char *key, const char *value, hpair_t * next);
+hpair_t *hpairnode_new(const char *key, const char *value, hpair_t * next);
/**
@@ -239,7 +239,7 @@ hpair_t *hpairnode_new (const char *key, const char *value, hpair_t * next);
@returns A newly crated hpair_t object. Use hpair_free()
or hpair_free_deep() to free the pair.
*/
-hpair_t *hpairnode_parse (const char *str, const char *delim, hpair_t * next);
+hpair_t *hpairnode_parse(const char *str, const char *delim, hpair_t * next);
/**
@@ -247,7 +247,7 @@ hpair_t *hpairnode_parse (const char *str, const char *delim, hpair_t * next);
@param pair the pair to free
*/
-void hpairnode_free (hpair_t * pair);
+void hpairnode_free(hpair_t * pair);
/**
@@ -257,7 +257,7 @@ void hpairnode_free (hpair_t * pair);
@param pair the pair to start to free the linked list
*/
-void hpairnode_free_deep (hpair_t * pair);
+void hpairnode_free_deep(hpair_t * pair);
/**
@@ -270,7 +270,7 @@ void hpairnode_free_deep (hpair_t * pair);
return the value (do not free this string) or NULL
if no pair was found with the key 'key'.
*/
-char *hpairnode_get (hpair_t * pair, const char *key);
+char *hpairnode_get(hpair_t * pair, const char *key);
/**
@@ -284,7 +284,7 @@ char *hpairnode_get (hpair_t * pair, const char *key);
return the value (do not free this string) or NULL
if no pair was found with the key 'key'.
*/
-char *hpairnode_get_ignore_case (hpair_t * pair, const char *key);
+char *hpairnode_get_ignore_case(hpair_t * pair, const char *key);
/**
@@ -300,7 +300,7 @@ char *hpairnode_get_ignore_case (hpair_t * pair, const char *key);
@see hpairnode_copy_deep
*/
-hpair_t *hpairnode_copy (const hpair_t * src);
+hpair_t *hpairnode_copy(const hpair_t * src);
/**
@@ -312,11 +312,11 @@ hpair_t *hpairnode_copy (const hpair_t * src);
@see hpairnode_copy
*/
-hpair_t *hpairnode_copy_deep (const hpair_t * src);
+hpair_t *hpairnode_copy_deep(const hpair_t * src);
/* Debug functions */
-void hpairnode_dump_deep (hpair_t * pair);
-void hpairnode_dump (hpair_t * pair);
+void hpairnode_dump_deep(hpair_t * pair);
+void hpairnode_dump(hpair_t * pair);
/**
The protocol types in enumeration
@@ -378,7 +378,7 @@ typedef struct _hurl
URL_ERROR_NO_PROTOCOL
URL_ERROR_NO_HOST
*/
-herror_t hurl_parse (hurl_t * obj, const char *url);
+herror_t hurl_parse(hurl_t * obj, const char *url);
/*
Object representation of the content-type field
@@ -407,13 +407,13 @@ typedef struct _content_type
@see content_type_free
*/
-content_type_t *content_type_new (const char *content_type_str);
+content_type_t *content_type_new(const char *content_type_str);
/**
Frees the given content_type_t object
*/
-void content_type_free (content_type_t * ct);
+void content_type_free(content_type_t * ct);
@@ -433,10 +433,10 @@ typedef struct _part
} 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);
+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);
@@ -451,7 +451,7 @@ typedef struct _attachments
part_t *root_part;
} attachments_t;
-attachments_t *attachments_new (); /* should be used internally */
+attachments_t *attachments_new(); /* should be used internally */
/*
Free a attachment. Create attachments with MIME
@@ -459,15 +459,15 @@ 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_free(attachments_t * message);
+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);
-char *hoption_get (int opt);
+void hoption_init_args(int argc, char *argv[]);
+void hoption_set(int opt, const char *value);
+char *hoption_get(int opt);
/* logging stuff */
typedef enum log_level
@@ -482,15 +482,15 @@ typedef enum log_level
-log_level_t log_set_level (log_level_t level);
-log_level_t log_get_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
#if defined(_MSC_VER) && _MSC_VER <= 1200
-char *VisualC_funcname (const char *file, int line); /* not thread safe! */
+char *VisualC_funcname(const char *file, int line); /* not thread safe! */
#define __FUNCTION__ VisualC_funcname(__FILE__, __LINE__)
#endif
#endif
@@ -525,11 +525,11 @@ char *VisualC_funcname (const char *file, int line); /* not thread safe! */
#define log_error4(a1,a2,a3,a4) log_error(__FUNCTION__, a1,a2,a3,a4)
#define log_error5(a1,a2,a3,a4,a5) log_error(__FUNCTION__, a1,a2,a3,a4,a5)
-void log_verbose (const char *FUNC, const char *format, ...);
-void log_debug (const char *FUNC, const char *format, ...);
-void log_info (const char *FUNC, const char *format, ...);
-void log_warn (const char *FUNC, const char *format, ...);
-void log_error (const char *FUNC, const char *format, ...);
+void log_verbose(const char *FUNC, const char *format, ...);
+void log_debug(const char *FUNC, const char *format, ...);
+void log_info(const char *FUNC, const char *format, ...);
+void log_warn(const char *FUNC, const char *format, ...);
+void log_error(const char *FUNC, const char *format, ...);
diff --git a/nanohttp/nanohttp-mime.c b/nanohttp/nanohttp-mime.c
index 3f17d38..5ca7df9 100755
--- a/nanohttp/nanohttp-mime.c
+++ b/nanohttp/nanohttp-mime.c
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.c,v 1.8 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-mime.c,v 1.9 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -69,8 +69,8 @@ typedef enum _MIME_read_status
#define MIME_PARSER_BUFFER_SIZE 1054
-typedef MIME_read_status (*MIME_read_function) (void *, unsigned char *,
- int *);
+typedef MIME_read_status(*MIME_read_function) (void *, unsigned char *,
+ int *);
/**
@@ -88,8 +88,8 @@ typedef struct _MIME_reader
} MIME_reader;
-MIME_read_status MIME_filereader_function (void *userdata,
- unsigned char *dest, int *size);
+MIME_read_status MIME_filereader_function(void *userdata,
+ unsigned char *dest, int *size);
typedef struct _MIME_callbacks
{
@@ -101,19 +101,19 @@ typedef struct _MIME_callbacks
} MIME_callbacks;
-MIME_parser_status MIME_parse (MIME_read_function reader_function,
- void *reader_userdata,
- const char *user_boundary,
- const MIME_callbacks * callbacks,
- void *callbacks_userdata);
+MIME_parser_status MIME_parse(MIME_read_function reader_function,
+ void *reader_userdata,
+ const char *user_boundary,
+ const MIME_callbacks * callbacks,
+ void *callbacks_userdata);
/**
Initialize a reader
*/
void
-MIME_reader_init (MIME_reader * reader,
- MIME_read_function reader_function, void *userdata)
+MIME_reader_init(MIME_reader * reader,
+ MIME_read_function reader_function, void *userdata)
{
reader->size = 0;
reader->marker = -1;
@@ -127,7 +127,7 @@ MIME_reader_init (MIME_reader * reader,
Read data from a reader source.
*/
MIME_read_status
-MIME_reader_read (MIME_reader * reader, unsigned char *buffer, int size)
+MIME_reader_read(MIME_reader * reader, unsigned char *buffer, int size)
{
MIME_read_status status;
int readed_size;
@@ -144,14 +144,14 @@ MIME_reader_read (MIME_reader * reader, unsigned char *buffer, int size)
{
if (reader->marker != 0)
{
- memcpy (tempBuffer, reader->buffer + reader->marker,
- reader->size - reader->marker);
- memcpy (reader->buffer, tempBuffer, reader->size - reader->marker);
+ memcpy(tempBuffer, reader->buffer + reader->marker,
+ reader->size - reader->marker);
+ memcpy(reader->buffer, tempBuffer, reader->size - reader->marker);
reader->current = reader->size - reader->marker;
}
else if (reader->current == MIME_READER_MAX_BUFFER_SIZE - 1)
{
- fprintf (stderr, "Marker error");
+ fprintf(stderr, "Marker error");
return MIME_READ_ERROR;
}
reader->marker = 0;
@@ -160,9 +160,9 @@ MIME_reader_read (MIME_reader * reader, unsigned char *buffer, int size)
reader->current = 0;
readed_size = MIME_READER_MAX_BUFFER_SIZE - reader->current - 1;
- status = reader->read_function (reader->userdata,
- reader->buffer + reader->current,
- &readed_size);
+ status = reader->read_function(reader->userdata,
+ reader->buffer + reader->current,
+ &readed_size);
if (status == MIME_READ_OK)
{
@@ -174,7 +174,7 @@ MIME_reader_read (MIME_reader * reader, unsigned char *buffer, int size)
if (size <= reader->size - reader->current)
{
- memcpy (buffer, reader->buffer + reader->current, size);
+ memcpy(buffer, reader->buffer + reader->current, size);
reader->current += size;
return MIME_READ_OK;
}
@@ -182,28 +182,28 @@ MIME_reader_read (MIME_reader * reader, unsigned char *buffer, int size)
{
/* Fill rest data */
rest_size = reader->size - reader->current;
- memcpy (buffer, reader->buffer + reader->current, rest_size);
+ memcpy(buffer, reader->buffer + reader->current, rest_size);
reader->current = reader->size;
- return MIME_reader_read (reader, buffer + rest_size, size - rest_size);
+ return MIME_reader_read(reader, buffer + rest_size, size - rest_size);
}
}
void
-MIME_reader_set_marker (MIME_reader * reader)
+MIME_reader_set_marker(MIME_reader * reader)
{
reader->marker = reader->current;
}
void
-MIME_reader_unset_marker (MIME_reader * reader)
+MIME_reader_unset_marker(MIME_reader * reader)
{
reader->marker = -1;
}
void
-MIME_reader_jump_marker (MIME_reader * reader)
+MIME_reader_jump_marker(MIME_reader * reader)
{
reader->current = reader->marker;
}
@@ -218,48 +218,48 @@ typedef struct _MIME_buffer
void
-MIME_buffer_init (MIME_buffer * buffer)
+MIME_buffer_init(MIME_buffer * buffer)
{
buffer->size = 0;
}
void
-MIME_buffer_add (MIME_buffer * buffer, unsigned char ch)
+MIME_buffer_add(MIME_buffer * buffer, unsigned char ch)
{
buffer->data[buffer->size++] = ch;
}
void
-MIME_buffer_add_bytes (MIME_buffer * buffer, unsigned char *bytes, int size)
+MIME_buffer_add_bytes(MIME_buffer * buffer, unsigned char *bytes, int size)
{
- memcpy (buffer->data, bytes, size);
+ memcpy(buffer->data, bytes, size);
buffer->size += size;
}
int
-MIME_buffer_is_full (MIME_buffer * buffer)
+MIME_buffer_is_full(MIME_buffer * buffer)
{
return buffer->size + 150 >= MIME_PARSER_BUFFER_SIZE;
}
int
-MIME_buffer_is_empty (MIME_buffer * buffer)
+MIME_buffer_is_empty(MIME_buffer * buffer)
{
return buffer->size == 0;
}
void
-MIME_buffer_clear (MIME_buffer * buffer)
+MIME_buffer_clear(MIME_buffer * buffer)
{
buffer->size = 0;
}
MIME_parser_status
-MIME_parse (MIME_read_function reader_function,
- void *reader_userdata,
- const char *user_boundary,
- const MIME_callbacks * callbacks, void *callbacks_userdata)
+MIME_parse(MIME_read_function reader_function,
+ void *reader_userdata,
+ const char *user_boundary,
+ const MIME_callbacks * callbacks, void *callbacks_userdata)
{
char boundary[150];
unsigned char ch[153];
@@ -269,30 +269,30 @@ MIME_parse (MIME_read_function reader_function,
MIME_read_status status;
/* Init reader */
- MIME_reader_init (&reader, reader_function, reader_userdata);
+ MIME_reader_init(&reader, reader_function, reader_userdata);
/* Init buffer */
- MIME_buffer_init (&buffer);
+ MIME_buffer_init(&buffer);
/* Set boundary related stuff */
- sprintf (boundary, "\n--%s", user_boundary);
- boundary_length = strlen (boundary);
+ sprintf(boundary, "\n--%s", user_boundary);
+ boundary_length = strlen(boundary);
/* Call parse begin callback */
- callbacks->parse_begin_cb (callbacks_userdata);
+ callbacks->parse_begin_cb(callbacks_userdata);
while (1)
{
set_marker:
/* Set marker */
- MIME_reader_set_marker (&reader);
+ MIME_reader_set_marker(&reader);
read_byte:
/* Read 1 byte */
- status = MIME_reader_read (&reader, ch, 1);
- _log_str ("buffer.log", ch, 1);
+ status = MIME_reader_read(&reader, ch, 1);
+ _log_str("buffer.log", ch, 1);
if (status == MIME_READ_EOF)
return MIME_PARSER_INCOMPLETE_MESSAGE;
else if (status == MIME_READ_ERROR)
@@ -304,8 +304,8 @@ MIME_parse (MIME_read_function reader_function,
while (n < boundary_length)
{
/* Read 1 byte */
- status = MIME_reader_read (&reader, ch, 1);
- _log_str ("buffer.log", ch, 1);
+ status = MIME_reader_read(&reader, ch, 1);
+ _log_str("buffer.log", ch, 1);
if (status == MIME_READ_EOF)
return MIME_PARSER_INCOMPLETE_MESSAGE;
else if (status == MIME_READ_ERROR)
@@ -319,7 +319,7 @@ MIME_parse (MIME_read_function reader_function,
}
else
{
- MIME_reader_jump_marker (&reader);
+ MIME_reader_jump_marker(&reader);
ignore = 1;
goto read_byte;
}
@@ -327,8 +327,8 @@ MIME_parse (MIME_read_function reader_function,
} /* while n < boundary_length */
/* Read 1 byte */
- status = MIME_reader_read (&reader, ch, 1);
- _log_str ("buffer.log", ch, 1);
+ status = MIME_reader_read(&reader, ch, 1);
+ _log_str("buffer.log", ch, 1);
if (status == MIME_READ_EOF)
@@ -340,8 +340,8 @@ MIME_parse (MIME_read_function reader_function,
if (ch[0] == '\r')
{
/* Read 1 byte */
- status = MIME_reader_read (&reader, ch, 1);
- _log_str ("buffer.log", ch, 1);
+ status = MIME_reader_read(&reader, ch, 1);
+ _log_str("buffer.log", ch, 1);
if (status == MIME_READ_EOF)
@@ -352,42 +352,42 @@ MIME_parse (MIME_read_function reader_function,
/* Check if byte is '\n' */
if (ch[0] == '\n')
{
- if (!MIME_buffer_is_empty (&buffer))
+ if (!MIME_buffer_is_empty(&buffer))
{
/* Invoke callback */
- callbacks->received_bytes_cb (callbacks_userdata, buffer.data,
- buffer.size);
+ callbacks->received_bytes_cb(callbacks_userdata, buffer.data,
+ buffer.size);
/* Empty the buffer */
- MIME_buffer_clear (&buffer);
+ MIME_buffer_clear(&buffer);
/* Invoke End Part */
- callbacks->part_end_cb (callbacks_userdata);
+ callbacks->part_end_cb(callbacks_userdata);
}
/* Invoke start new Part */
- callbacks->part_begin_cb (callbacks_userdata);
+ callbacks->part_begin_cb(callbacks_userdata);
goto set_marker;
} /* if (ch[0] == '\n') */
else
{
/* Jump to marker and read bytes */
- MIME_reader_jump_marker (&reader);
- MIME_reader_read (&reader, ch, boundary_length + 2);
- _log_str ("buffer.log", ch, 1);
+ MIME_reader_jump_marker(&reader);
+ MIME_reader_read(&reader, ch, boundary_length + 2);
+ _log_str("buffer.log", ch, 1);
- MIME_buffer_add_bytes (&buffer, ch, boundary_length + 2);
+ MIME_buffer_add_bytes(&buffer, ch, boundary_length + 2);
- if (MIME_buffer_is_full (&buffer))
+ if (MIME_buffer_is_full(&buffer))
{
/* Invoke callback */
- callbacks->received_bytes_cb (callbacks_userdata, buffer.data,
- buffer.size);
+ callbacks->received_bytes_cb(callbacks_userdata, buffer.data,
+ buffer.size);
/* Empty the buffer */
- MIME_buffer_clear (&buffer);
+ MIME_buffer_clear(&buffer);
}
} /* else of if (ch[0] == '\n') */
@@ -397,8 +397,8 @@ MIME_parse (MIME_read_function reader_function,
if (ch[0] == '-')
{
/* Read 1 byte */
- status = MIME_reader_read (&reader, ch, 1);
- _log_str ("buffer.log", ch, 1);
+ status = MIME_reader_read(&reader, ch, 1);
+ _log_str("buffer.log", ch, 1);
if (status == MIME_READ_EOF)
return MIME_PARSER_INCOMPLETE_MESSAGE;
@@ -407,21 +407,21 @@ MIME_parse (MIME_read_function reader_function,
if (ch[0] == '-')
{
- if (!MIME_buffer_is_empty (&buffer))
+ if (!MIME_buffer_is_empty(&buffer))
{
/* Invoke callback */
- callbacks->received_bytes_cb (callbacks_userdata, buffer.data,
- buffer.size);
+ callbacks->received_bytes_cb(callbacks_userdata, buffer.data,
+ buffer.size);
/* Empty the buffer */
- MIME_buffer_clear (&buffer);
+ MIME_buffer_clear(&buffer);
/* Invoke End Part */
- callbacks->part_end_cb (callbacks_userdata);
+ callbacks->part_end_cb(callbacks_userdata);
}
/* Invoke start new Part */
- callbacks->parse_end_cb (callbacks_userdata);
+ callbacks->parse_end_cb(callbacks_userdata);
/* Finish parsing */
/* TODO (#1#): We assume that after -- comes \r\n This is not
@@ -432,7 +432,7 @@ MIME_parse (MIME_read_function reader_function,
} /* if (ch[0] == '-') */
else
{
- MIME_reader_jump_marker (&reader);
+ MIME_reader_jump_marker(&reader);
ignore = 1;
goto read_byte;
} /* else of if (ch[0] == '-') */
@@ -440,7 +440,7 @@ MIME_parse (MIME_read_function reader_function,
} /* if (ch[0] == '-') */
else
{
- MIME_reader_jump_marker (&reader);
+ MIME_reader_jump_marker(&reader);
ignore = 1;
goto read_byte;
} /* else of if (ch[0] == '-') */
@@ -451,17 +451,17 @@ MIME_parse (MIME_read_function reader_function,
else
{
ignore = 0;
- MIME_buffer_add (&buffer, ch[0]);
+ MIME_buffer_add(&buffer, ch[0]);
/* Chec if buffer is full */
- if (MIME_buffer_is_full (&buffer))
+ if (MIME_buffer_is_full(&buffer))
{
/* Invoke callback */
- callbacks->received_bytes_cb (callbacks_userdata, buffer.data,
- buffer.size);
+ callbacks->received_bytes_cb(callbacks_userdata, buffer.data,
+ buffer.size);
/* Empty the buffer */
- MIME_buffer_clear (&buffer);
+ MIME_buffer_clear(&buffer);
}
} /* else of if ch[0] == '\r' && !ignore */
} /* while (1) */
@@ -471,14 +471,14 @@ MIME_parse (MIME_read_function reader_function,
MIME_read_status
-MIME_filereader_function (void *userdata, unsigned char *dest, int *size)
+MIME_filereader_function(void *userdata, unsigned char *dest, int *size)
{
FILE *f = (FILE *) userdata;
- if (feof (f))
+ if (feof(f))
return MIME_READ_EOF;
- *size = fread (dest, 1, *size, f);
+ *size = fread(dest, 1, *size, f);
return MIME_READ_OK;
}
@@ -507,21 +507,21 @@ typedef struct _mime_callback_data
MIME_read_status
-mime_streamreader_function (void *userdata, unsigned char *dest, int *size)
+mime_streamreader_function(void *userdata, unsigned char *dest, int *size)
{
int readed = 0;
http_input_stream_t *in = (http_input_stream_t *) userdata;
- if (!http_input_stream_is_ready (in))
+ if (!http_input_stream_is_ready(in))
return MIME_READ_EOF;
- readed = http_input_stream_read (in, dest, *size);
+ 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));
+ log_error4("[%d] %s():%s ", herror_code(in->err), herror_func(in->err),
+ herror_message(in->err));
}
*size = readed;
@@ -539,34 +539,34 @@ mime_streamreader_function (void *userdata, unsigned char *dest, int *size)
Start Callback functions
*/
static void
-_mime_parse_begin (void *data)
+_mime_parse_begin(void *data)
{
/* Nothing to do
mime_callback_data_t *cbdata = (mime_callback_data_t)data;
*/
- log_verbose2 ("Begin parse (%p)", data);
+ log_verbose2("Begin parse (%p)", data);
}
static void
-_mime_parse_end (void *data)
+_mime_parse_end(void *data)
{
/* Nothing to do
mime_callback_data_t *cbdata = (mime_callback_data_t)data;
*/
- log_verbose2 ("End parse (%p)", data);
+ log_verbose2("End parse (%p)", data);
}
static void
-_mime_part_begin (void *data)
+_mime_part_begin(void *data)
{
char buffer[1054];
mime_callback_data_t *cbdata = (mime_callback_data_t *) data;
part_t *part;
- log_verbose2 ("Begin Part (%p)", data);
- part = (part_t *) malloc (sizeof (part_t));
+ log_verbose2("Begin Part (%p)", data);
+ part = (part_t *) malloc(sizeof(part_t));
part->next = NULL;
@@ -583,38 +583,38 @@ _mime_part_begin (void *data)
cbdata->header_search = 0;
#ifdef WIN32
- sprintf (buffer, "%s\\mime_%p_%d.part", cbdata->root_dir,
- cbdata, cbdata->part_id++);
+ sprintf(buffer, "%s\\mime_%p_%d.part", cbdata->root_dir,
+ cbdata, cbdata->part_id++);
#else
- sprintf (buffer, "%s/mime_%p_%d.part", cbdata->root_dir,
- cbdata, cbdata->part_id++);
+ sprintf(buffer, "%s/mime_%p_%d.part", cbdata->root_dir,
+ cbdata, cbdata->part_id++);
#endif
/* log_info2("Creating FILE ('%s') deleteOnExit=1", buffer);*/
part->deleteOnExit = 1;
- cbdata->current_fd = fopen (buffer, "wb");
+ cbdata->current_fd = fopen(buffer, "wb");
if (cbdata->current_fd)
- strcpy (cbdata->current_part->filename, buffer);
+ strcpy(cbdata->current_part->filename, buffer);
else
- log_error2 ("Can not open file for write '%s'", buffer);
+ log_error2("Can not open file for write '%s'", buffer);
}
static void
-_mime_part_end (void *data)
+_mime_part_end(void *data)
{
mime_callback_data_t *cbdata = (mime_callback_data_t *) data;
- log_verbose2 ("End Part (%p)", data);
+ log_verbose2("End Part (%p)", data);
if (cbdata->current_fd)
{
- fclose (cbdata->current_fd);
+ fclose(cbdata->current_fd);
cbdata->current_fd = NULL;
}
}
static hpair_t *
-_mime_process_header (char *buffer)
+_mime_process_header(char *buffer)
{
int i = 0, c = 0, proc_key, begin = 0;
hpair_t *first = NULL, *last = NULL;
@@ -631,12 +631,12 @@ _mime_process_header (char *buffer)
value[c] = '\0';
if (last)
{
- last->next = hpairnode_new (key, value, NULL);
+ last->next = hpairnode_new(key, value, NULL);
last = last->next;
}
else
{
- first = last = hpairnode_new (key, value, NULL);
+ first = last = hpairnode_new(key, value, NULL);
}
proc_key = 1;
c = 0;
@@ -668,7 +668,7 @@ _mime_process_header (char *buffer)
static void
-_mime_received_bytes (void *data, const unsigned char *bytes, int size)
+_mime_received_bytes(void *data, const unsigned char *bytes, int size)
{
int i = 0;
char *id, *type, *location;
@@ -738,30 +738,28 @@ _mime_received_bytes (void *data, const unsigned char *bytes, int size)
cbdata->header[cbdata->header_index++] = '\n';
cbdata->header[cbdata->header_index++] = '\0';
cbdata->header_search = 4;
- cbdata->current_part->header =
- _mime_process_header (cbdata->header);
- hpairnode_dump_deep (cbdata->current_part->header);
+ 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);
+ 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))
+ 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);
+ hpairnode_get(cbdata->current_part->header,
+ HEADER_CONTENT_LOCATION);
if (location != NULL)
{
- strcpy (cbdata->current_part->location, location);
+ strcpy(cbdata->current_part->location, location);
}
type =
- hpairnode_get (cbdata->current_part->header, HEADER_CONTENT_TYPE);
+ hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_TYPE);
if (type != NULL)
{
- strcpy (cbdata->current_part->content_type, type);
+ strcpy(cbdata->current_part->content_type, type);
}
i++;
break;
@@ -786,7 +784,7 @@ _mime_received_bytes (void *data, const unsigned char *bytes, int size)
/* Write remaining bytes into the file or buffer (if root) (buffer is
disabled in this version) */
if (cbdata->current_fd)
- fwrite (&(bytes[i]), 1, size - i, cbdata->current_fd);
+ fwrite(&(bytes[i]), 1, size - i, cbdata->current_fd);
}
@@ -795,15 +793,15 @@ _mime_received_bytes (void *data, const unsigned char *bytes, int size)
*/
attachments_t *
-mime_message_parse (http_input_stream_t * in, const char *root_id,
- const char *boundary, const char *dest_dir)
+mime_message_parse(http_input_stream_t * in, const char *root_id,
+ const char *boundary, const char *dest_dir)
{
MIME_parser_status status;
MIME_callbacks callbacks;
attachments_t *message;
mime_callback_data_t *cbdata = (mime_callback_data_t *)
- malloc (sizeof (mime_callback_data_t));
+ malloc(sizeof(mime_callback_data_t));
cbdata->part_id = 100;
cbdata->buffer_capacity = 0;
@@ -811,9 +809,9 @@ mime_message_parse (http_input_stream_t * in, const char *root_id,
cbdata->current_part = NULL;
cbdata->header_index = 0;
cbdata->header_search = 0;
- strcpy (cbdata->root_id, root_id);
- strcpy (cbdata->root_dir, dest_dir);
- message = (attachments_t *) malloc (sizeof (attachments_t));
+ strcpy(cbdata->root_id, root_id);
+ strcpy(cbdata->root_dir, dest_dir);
+ message = (attachments_t *) malloc(sizeof(attachments_t));
cbdata->message = message;
cbdata->message->parts = NULL;
cbdata->message->root_part = NULL;
@@ -824,33 +822,33 @@ mime_message_parse (http_input_stream_t * in, const char *root_id,
callbacks.part_end_cb = _mime_part_end;
callbacks.received_bytes_cb = _mime_received_bytes;
- status = MIME_parse (mime_streamreader_function,
- in, boundary, &callbacks, cbdata);
+ status = MIME_parse(mime_streamreader_function,
+ in, boundary, &callbacks, cbdata);
if (status == MIME_PARSER_OK)
{
- free (cbdata);
+ free(cbdata);
return message;
}
else
{
- log_error2 ("MIME parser error '%s'!",
- status ==
- MIME_PARSER_READ_ERROR ? "read error" : "Incomplete message");
+ log_error2("MIME parser error '%s'!",
+ status ==
+ MIME_PARSER_READ_ERROR ? "read error" : "Incomplete message");
return NULL;
}
}
attachments_t *
-mime_message_parse_from_file (FILE * in, const char *root_id,
- const char *boundary, const char *dest_dir)
+mime_message_parse_from_file(FILE * in, const char *root_id,
+ const char *boundary, const char *dest_dir)
{
MIME_parser_status status;
MIME_callbacks callbacks;
attachments_t *message;
mime_callback_data_t *cbdata = (mime_callback_data_t *)
- malloc (sizeof (mime_callback_data_t));
+ malloc(sizeof(mime_callback_data_t));
cbdata->part_id = 100;
cbdata->buffer_capacity = 0;
@@ -858,9 +856,9 @@ mime_message_parse_from_file (FILE * in, const char *root_id,
cbdata->current_part = NULL;
cbdata->header_index = 0;
cbdata->header_search = 0;
- strcpy (cbdata->root_id, root_id);
- strcpy (cbdata->root_dir, dest_dir);
- message = (attachments_t *) malloc (sizeof (attachments_t));
+ strcpy(cbdata->root_id, root_id);
+ strcpy(cbdata->root_dir, dest_dir);
+ message = (attachments_t *) malloc(sizeof(attachments_t));
cbdata->message = message;
cbdata->message->parts = NULL;
cbdata->message->root_part = NULL;
@@ -871,22 +869,22 @@ mime_message_parse_from_file (FILE * in, const char *root_id,
callbacks.part_end_cb = _mime_part_end;
callbacks.received_bytes_cb = _mime_received_bytes;
- status = MIME_parse (MIME_filereader_function,
- in, boundary, &callbacks, cbdata);
+ status = MIME_parse(MIME_filereader_function,
+ in, boundary, &callbacks, cbdata);
if (status == MIME_PARSER_OK)
{
- free (cbdata);
+ free(cbdata);
return message;
}
else
{
/* TODO (#1#): Free objects */
- log_error2 ("MIME parser error '%s'!",
- status ==
- MIME_PARSER_READ_ERROR ? "general error" :
- "Incomplete message");
+ log_error2("MIME parser error '%s'!",
+ status ==
+ MIME_PARSER_READ_ERROR ? "general error" :
+ "Incomplete message");
return NULL;
}
}
@@ -894,8 +892,8 @@ mime_message_parse_from_file (FILE * in, const char *root_id,
herror_t
-mime_get_attachments (content_type_t * ctype, http_input_stream_t * in,
- attachments_t ** dest)
+mime_get_attachments(content_type_t * ctype, http_input_stream_t * in,
+ attachments_t ** dest)
{
/* MIME variables */
attachments_t *mimeMessage;
@@ -903,44 +901,44 @@ mime_get_attachments (content_type_t * ctype, http_input_stream_t * in,
char *boundary, *root_id;
/* Check for MIME message */
- if (!(ctype && !strcmp (ctype->type, "multipart/related")))
- return herror_new ("mime_get_attachments", MIME_ERROR_NOT_MIME_MESSAGE,
- "Not a MIME message '%s'", ctype->type);
+ if (!(ctype && !strcmp(ctype->type, "multipart/related")))
+ return herror_new("mime_get_attachments", MIME_ERROR_NOT_MIME_MESSAGE,
+ "Not a MIME message '%s'", ctype->type);
- boundary = hpairnode_get (ctype->params, "boundary");
- root_id = hpairnode_get (ctype->params, "start");
+ boundary = hpairnode_get(ctype->params, "boundary");
+ root_id = hpairnode_get(ctype->params, "start");
if (boundary == NULL)
{
/* 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,
- "'boundary' not set for multipart/related");
+ log_error1("'boundary' not set for multipart/related");
+ return herror_new("mime_get_attachments", MIME_ERROR_NO_BOUNDARY_PARAM,
+ "'boundary' not set for multipart/related");
}
if (root_id == NULL)
{
/* 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");
+ 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");
}
mimeMessage =
- mime_message_parse (in, root_id, boundary, hoption_get (HOPTION_TMP_DIR));
+ mime_message_parse(in, root_id, boundary, hoption_get(HOPTION_TMP_DIR));
if (mimeMessage == NULL)
{
/* TODO (#1#): Handle Error in http form */
- log_error1 ("MIME Parse Error");
- return herror_new ("mime_get_attachments", MIME_ERROR_PARSE_ERROR,
- "MIME Parse Error");
+ log_error1("MIME Parse Error");
+ return herror_new("mime_get_attachments", MIME_ERROR_PARSE_ERROR,
+ "MIME Parse Error");
}
/* Find root */
if (!mimeMessage->root_part)
{
- attachments_free (mimeMessage);
- return herror_new ("mime_get_attachments", MIME_ERROR_NO_ROOT_PART,
- "No root part found!");
+ attachments_free(mimeMessage);
+ return herror_new("mime_get_attachments", MIME_ERROR_NO_ROOT_PART,
+ "No root part found!");
}
/* delete root_part from list */
diff --git a/nanohttp/nanohttp-mime.h b/nanohttp/nanohttp-mime.h
index 6b160ab..7ee04b0 100755
--- a/nanohttp/nanohttp-mime.h
+++ b/nanohttp/nanohttp-mime.h
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.h,v 1.5 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-mime.h,v 1.6 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -40,9 +40,9 @@
-herror_t mime_get_attachments (content_type_t * ctype,
- http_input_stream_t * in,
- attachments_t ** dest);
+herror_t mime_get_attachments(content_type_t * ctype,
+ http_input_stream_t * in,
+ attachments_t ** dest);
#endif
diff --git a/nanohttp/nanohttp-request.c b/nanohttp/nanohttp-request.c
index 5f15e93..930c609 100755
--- a/nanohttp/nanohttp-request.c
+++ b/nanohttp/nanohttp-request.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-request.c,v 1.7 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-request.c,v 1.8 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -35,9 +35,9 @@
static hrequest_t *
-hrequest_new ()
+hrequest_new()
{
- hrequest_t *req = (hrequest_t *) malloc (sizeof (hrequest_t));
+ hrequest_t *req = (hrequest_t *) malloc(sizeof(hrequest_t));
req->method = HTTP_REQUEST_GET;
req->version = HTTP_1_1;
@@ -51,7 +51,7 @@ hrequest_new ()
}
static hrequest_t *
-_hrequest_parse_header (char *data)
+_hrequest_parse_header(char *data)
{
hrequest_t *req;
hpair_t *hpair = NULL, *qpair = NULL, *tmppair = NULL;
@@ -67,12 +67,12 @@ _hrequest_parse_header (char *data)
char *opt_value;
int firstline = 1;
- req = hrequest_new ();
+ req = hrequest_new();
tmp = data;
for (;;)
{
- result = (char *) strtok_r (tmp, "\r\n", &saveptr);
+ result = (char *) strtok_r(tmp, "\r\n", &saveptr);
tmp = saveptr;
if (result == NULL)
@@ -84,19 +84,19 @@ _hrequest_parse_header (char *data)
tmp2 = result;
/* parse [GET|POST] [PATH] [SPEC] */
- key = (char *) strtok_r (tmp2, " ", &saveptr2);
+ key = (char *) strtok_r(tmp2, " ", &saveptr2);
/* save method (get or post) */
tmp2 = saveptr2;
if (key != NULL)
{
- if (!strcmp (key, "POST"))
+ if (!strcmp(key, "POST"))
req->method = HTTP_REQUEST_POST;
else
req->method = HTTP_REQUEST_GET;
}
/* below is key the path and tmp2 the spec */
- key = (char *) strtok_r (tmp2, " ", &saveptr2);
+ key = (char *) strtok_r(tmp2, " ", &saveptr2);
/* save version */
tmp2 = saveptr2;
@@ -104,7 +104,7 @@ _hrequest_parse_header (char *data)
{
/* req->spec = (char *) malloc(strlen(tmp2) + 1); strcpy(req->spec,
tmp2); */
- if (!strcmp (tmp2, "HTTP/1.0"))
+ if (!strcmp(tmp2, "HTTP/1.0"))
req->version = HTTP_1_0;
else
req->version = HTTP_1_1;
@@ -117,23 +117,23 @@ _hrequest_parse_header (char *data)
if (key != NULL)
{
tmp2 = key;
- key = (char *) strtok_r (tmp2, "?", &saveptr2);
+ key = (char *) strtok_r(tmp2, "?", &saveptr2);
tmp2 = saveptr2;
/* save path */
/* req->path = (char *) malloc(strlen(key) + 1); */
- strncpy (req->path, key, REQUEST_MAX_PATH_SIZE);
+ strncpy(req->path, key, REQUEST_MAX_PATH_SIZE);
/* parse options */
for (;;)
{
- key = (char *) strtok_r (tmp2, "&", &saveptr2);
+ key = (char *) strtok_r(tmp2, "&", &saveptr2);
tmp2 = saveptr2;
if (key == NULL)
break;
- opt_key = (char *) strtok_r (key, "=", &saveptr3);
+ opt_key = (char *) strtok_r(key, "=", &saveptr3);
opt_value = saveptr3;
if (opt_value == NULL)
@@ -142,7 +142,7 @@ _hrequest_parse_header (char *data)
/* create option pair */
if (opt_key != NULL)
{
- tmppair = (hpair_t *) malloc (sizeof (hpair_t));
+ tmppair = (hpair_t *) malloc(sizeof(hpair_t));
if (req->query == NULL)
{
@@ -156,11 +156,11 @@ _hrequest_parse_header (char *data)
/* fill hpairnode_t struct */
qpair->next = NULL;
- qpair->key = (char *) malloc (strlen (opt_key) + 1);
- qpair->value = (char *) malloc (strlen (opt_value) + 1);
+ qpair->key = (char *) malloc(strlen(opt_key) + 1);
+ qpair->value = (char *) malloc(strlen(opt_value) + 1);
- strcpy (qpair->key, opt_key);
- strcpy (qpair->value, opt_value);
+ strcpy(qpair->key, opt_key);
+ strcpy(qpair->value, opt_value);
}
}
@@ -175,7 +175,7 @@ _hrequest_parse_header (char *data)
/* create pair */
/* tmppair = (hpair_t *) malloc(sizeof(hpair_t));*/
- tmppair = hpairnode_parse (result, ":", NULL);
+ tmppair = hpairnode_parse(result, ":", NULL);
if (req->header == NULL)
{
@@ -197,39 +197,39 @@ _hrequest_parse_header (char *data)
}
/* Check Content-type */
- tmp = hpairnode_get (req->header, HEADER_CONTENT_TYPE);
+ tmp = hpairnode_get(req->header, HEADER_CONTENT_TYPE);
if (tmp != NULL)
- req->content_type = content_type_new (tmp);
+ req->content_type = content_type_new(tmp);
return req;
}
void
-hrequest_free (hrequest_t * req)
+hrequest_free(hrequest_t * req)
{
if (req == NULL)
return;
- hpairnode_free_deep (req->header);
- hpairnode_free_deep (req->query);
+ hpairnode_free_deep(req->header);
+ hpairnode_free_deep(req->query);
if (req->in)
- http_input_stream_free (req->in);
+ http_input_stream_free(req->in);
if (req->content_type)
- content_type_free (req->content_type);
+ content_type_free(req->content_type);
if (req->attachments)
- attachments_free (req->attachments);
+ attachments_free(req->attachments);
- free (req);
+ free(req);
}
herror_t
-hrequest_new_from_socket (hsocket_t sock, hrequest_t ** out)
+hrequest_new_from_socket(hsocket_t sock, hrequest_t ** out)
{
int i = 0, readed;
herror_t status;
@@ -237,16 +237,16 @@ hrequest_new_from_socket (hsocket_t sock, hrequest_t ** out)
char buffer[MAX_HEADER_SIZE + 1];
attachments_t *mimeMessage;
- memset (buffer, 0, MAX_HEADER_SIZE);
+ memset(buffer, 0, MAX_HEADER_SIZE);
/* Read header */
while (i < MAX_HEADER_SIZE)
{
- status = hsocket_read (sock, &(buffer[i]), 1, 1, &readed);
+ status = hsocket_read(sock, &(buffer[i]), 1, 1, &readed);
if (status != H_OK)
{
- if (herror_code (status) != HSOCKET_SSL_CLOSE)
+ if (herror_code(status) != HSOCKET_SSL_CLOSE)
{
- log_error1 ("Socket read error");
+ log_error1("Socket read error");
}
return status;
}
@@ -255,36 +255,36 @@ hrequest_new_from_socket (hsocket_t sock, hrequest_t ** out)
if (i > 3)
{
- if (!strcmp (&(buffer[i - 1]), "\n\n") ||
- !strcmp (&(buffer[i - 2]), "\n\r\n"))
+ if (!strcmp(&(buffer[i - 1]), "\n\n") ||
+ !strcmp(&(buffer[i - 2]), "\n\r\n"))
break;
}
i++;
}
/* Create response */
- req = _hrequest_parse_header (buffer);
+ req = _hrequest_parse_header(buffer);
/* Create input stream */
- req->in = http_input_stream_new (sock, req->header);
+ req->in = http_input_stream_new(sock, req->header);
/* Check for MIME message */
if ((req->content_type &&
- !strcmp (req->content_type->type, "multipart/related")))
+ !strcmp(req->content_type->type, "multipart/related")))
{
- status = mime_get_attachments (req->content_type, req->in, &mimeMessage);
+ status = mime_get_attachments(req->content_type, req->in, &mimeMessage);
if (status != H_OK)
{
/* TODO (#1#): Handle error */
- hrequest_free (req);
+ hrequest_free(req);
return status;
}
else
{
req->attachments = mimeMessage;
req->in =
- http_input_stream_new_from_file (mimeMessage->root_part->filename);
+ http_input_stream_new_from_file(mimeMessage->root_part->filename);
}
}
diff --git a/nanohttp/nanohttp-request.h b/nanohttp/nanohttp-request.h
index e7b7b3e..537cf08 100755
--- a/nanohttp/nanohttp-request.h
+++ b/nanohttp/nanohttp-request.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-request.h,v 1.3 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: nanohttp-request.h,v 1.4 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -45,7 +45,7 @@ typedef struct hrequest
char root_part_id[150];
} hrequest_t;
-herror_t hrequest_new_from_socket (hsocket_t sock, hrequest_t ** out);
-void hrequest_free (hrequest_t * req);
+herror_t hrequest_new_from_socket(hsocket_t sock, hrequest_t ** out);
+void hrequest_free(hrequest_t * req);
#endif
diff --git a/nanohttp/nanohttp-response.c b/nanohttp/nanohttp-response.c
index ee9e762..2253640 100755
--- a/nanohttp/nanohttp-response.c
+++ b/nanohttp/nanohttp-response.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-response.c,v 1.6 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-response.c,v 1.7 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -32,12 +32,12 @@
#endif
static hresponse_t *
-hresponse_new ()
+hresponse_new()
{
hresponse_t *res;
/* create response object */
- res = (hresponse_t *) malloc (sizeof (hresponse_t));
+ res = (hresponse_t *) malloc(sizeof(hresponse_t));
res->version = HTTP_1_1;
res->errcode = -1;
res->desc[0] = '\0';
@@ -49,58 +49,58 @@ hresponse_new ()
}
static hresponse_t *
-_hresponse_parse_header (const char *buffer)
+_hresponse_parse_header(const char *buffer)
{
hresponse_t *res;
char *s1, *s2, *str;
/* create response object */
- res = hresponse_new ();
+ res = hresponse_new();
/* *** parse spec *** */
/* [HTTP/1.1 | 1.2] [CODE] [DESC] */
/* stage 1: HTTP spec */
- str = (char *) strtok_r ((char *) buffer, " ", &s2);
+ str = (char *) strtok_r((char *) buffer, " ", &s2);
s1 = s2;
if (str == NULL)
{
- log_error1 ("Parse error reading HTTP spec");
+ log_error1("Parse error reading HTTP spec");
return NULL;
}
- if (!strcmp (str, "HTTP/1.0"))
+ if (!strcmp(str, "HTTP/1.0"))
res->version = HTTP_1_0;
else
res->version = HTTP_1_1;
/* stage 2: http code */
- str = (char *) strtok_r (s1, " ", &s2);
+ str = (char *) strtok_r(s1, " ", &s2);
s1 = s2;
if (str == NULL)
{
- log_error1 ("Parse error reading HTTP code");
+ log_error1("Parse error reading HTTP code");
return NULL;
}
- res->errcode = atoi (str);
+ res->errcode = atoi(str);
/* stage 3: description text */
- str = (char *) strtok_r (s1, "\r\n", &s2);
+ str = (char *) strtok_r(s1, "\r\n", &s2);
s1 = s2;
if (str == NULL)
{
- log_error1 ("Parse error reading HTTP description");
+ log_error1("Parse error reading HTTP description");
return NULL;
}
/* res->desc = (char *) malloc(strlen(str) + 1);*/
- strncpy (res->desc, str, RESPONSE_MAX_DESC_SIZE);
- res->desc[strlen (str)] = '\0';
+ strncpy(res->desc, str, RESPONSE_MAX_DESC_SIZE);
+ res->desc[strlen(str)] = '\0';
/* *** parse header *** */
/* [key]: [value] */
for (;;)
{
- str = strtok_r (s1, "\n", &s2);
+ str = strtok_r(s1, "\n", &s2);
s1 = s2;
/* check if header ends without body */
@@ -109,18 +109,18 @@ _hresponse_parse_header (const char *buffer)
return res;
}
/* check also for end of header */
- if (!strcmp (str, "\r"))
+ if (!strcmp(str, "\r"))
{
break;
}
- str[strlen (str) - 1] = '\0';
- res->header = hpairnode_parse (str, ":", res->header);
+ str[strlen(str) - 1] = '\0';
+ res->header = hpairnode_parse(str, ":", res->header);
}
/* Check Content-type */
- str = hpairnode_get (res->header, HEADER_CONTENT_TYPE);
+ str = hpairnode_get(res->header, HEADER_CONTENT_TYPE);
if (str != NULL)
- res->content_type = content_type_new (str);
+ res->content_type = content_type_new(str);
/* return response object */
return res;
@@ -128,7 +128,7 @@ _hresponse_parse_header (const char *buffer)
herror_t
-hresponse_new_from_socket (hsocket_t sock, hresponse_t ** out)
+hresponse_new_from_socket(hsocket_t sock, hresponse_t ** out)
{
int i = 0, readed;
herror_t status;
@@ -140,10 +140,10 @@ read_header: /* for errorcode: 100 (continue) */
/* Read header */
while (i < MAX_HEADER_SIZE)
{
- status = hsocket_read (sock, &(buffer[i]), 1, 1, &readed);
+ status = hsocket_read(sock, &(buffer[i]), 1, 1, &readed);
if (status != H_OK)
{
- log_error1 ("Socket read error");
+ log_error1("Socket read error");
return status;
}
@@ -151,52 +151,52 @@ read_header: /* for errorcode: 100 (continue) */
if (i > 3)
{
- if (!strcmp (&(buffer[i - 1]), "\n\n") ||
- !strcmp (&(buffer[i - 2]), "\n\r\n"))
+ if (!strcmp(&(buffer[i - 1]), "\n\n") ||
+ !strcmp(&(buffer[i - 2]), "\n\r\n"))
break;
}
i++;
}
/* Create response */
- res = _hresponse_parse_header (buffer);
+ res = _hresponse_parse_header(buffer);
if (res == NULL)
{
- log_error1 ("Header parse error");
- return herror_new ("hresponse_new_from_socket",
- GENERAL_HEADER_PARSE_ERROR,
- "Can not parse response header");
+ log_error1("Header parse error");
+ return herror_new("hresponse_new_from_socket",
+ GENERAL_HEADER_PARSE_ERROR,
+ "Can not parse response header");
}
/* Chec for Errorcode: 100 (continue) */
if (res->errcode == 100)
{
- hresponse_free (res);
+ hresponse_free(res);
i = 0;
goto read_header;
}
/* Create input stream */
- res->in = http_input_stream_new (sock, res->header);
+ res->in = http_input_stream_new(sock, res->header);
/* Check for MIME message */
if ((res->content_type &&
- !strcmp (res->content_type->type, "multipart/related")))
+ !strcmp(res->content_type->type, "multipart/related")))
{
- status = mime_get_attachments (res->content_type, res->in, &mimeMessage);
+ status = mime_get_attachments(res->content_type, res->in, &mimeMessage);
if (status != H_OK)
{
/* TODO (#1#): Handle error */
- hresponse_free (res);
+ hresponse_free(res);
return status;
}
else
{
res->attachments = mimeMessage;
- http_input_stream_free (res->in);
+ http_input_stream_free(res->in);
res->in =
- http_input_stream_new_from_file (mimeMessage->root_part->filename);
+ http_input_stream_new_from_file(mimeMessage->root_part->filename);
if (!res->in)
{
/* TODO (#1#): Handle error */
@@ -215,21 +215,21 @@ read_header: /* for errorcode: 100 (continue) */
void
-hresponse_free (hresponse_t * res)
+hresponse_free(hresponse_t * res)
{
if (res == NULL)
return;
if (res->header)
- hpairnode_free_deep (res->header);
+ hpairnode_free_deep(res->header);
if (res->in)
- http_input_stream_free (res->in);
+ http_input_stream_free(res->in);
if (res->content_type)
- content_type_free (res->content_type);
+ content_type_free(res->content_type);
if (res->attachments)
- attachments_free (res->attachments);
- free (res);
+ attachments_free(res->attachments);
+ free(res);
}
diff --git a/nanohttp/nanohttp-response.h b/nanohttp/nanohttp-response.h
index 70e5348..c91c56b 100755
--- a/nanohttp/nanohttp-response.h
+++ b/nanohttp/nanohttp-response.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-response.h,v 1.3 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: nanohttp-response.h,v 1.4 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -43,8 +43,8 @@ typedef struct hresponse
char root_part_id[150];
} hresponse_t;
-herror_t hresponse_new_from_socket (hsocket_t sock, hresponse_t ** out);
-void hresponse_free (hresponse_t * res);
+herror_t hresponse_new_from_socket(hsocket_t sock, hresponse_t ** out);
+void hresponse_free(hresponse_t * res);
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index 102c62a..d09d5df 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.38 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-server.c,v 1.39 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -96,7 +96,7 @@ static conndata_t *_httpd_connection;
#ifdef WIN32
-static void WSAReaper (void *x);
+static void WSAReaper(void *x);
#else
sigset_t thrsigset;
#endif
@@ -113,66 +113,66 @@ extern SSL_CTX *SSLctx;
* -----------------------------------------------------
*/
herror_t
-httpd_init (int argc, char *argv[])
+httpd_init(int argc, char *argv[])
{
int i;
herror_t status;
- hoption_init_args (argc, argv);
+ hoption_init_args(argc, argv);
- status = hsocket_module_init ();
+ status = hsocket_module_init();
if (status != H_OK)
return status;
/* write argument information */
- log_verbose1 ("Arguments:");
+ log_verbose1("Arguments:");
for (i = 0; i < argc; i++)
- log_verbose3 ("argv[%i] = '%s'", i, SAVE_STR (argv[i]));
+ log_verbose3("argv[%i] = '%s'", i, SAVE_STR(argv[i]));
/* initialize from arguments */
for (i = 0; i < argc; i++)
{
- if (!strcmp (argv[i], NHTTPD_ARG_PORT) && i < argc - 1)
+ if (!strcmp(argv[i], NHTTPD_ARG_PORT) && i < argc - 1)
{
- _httpd_port = atoi (argv[i + 1]);
+ _httpd_port = atoi(argv[i + 1]);
}
- else if (!strcmp (argv[i], NHTTPD_ARG_TERMSIG) && i < argc - 1)
+ else if (!strcmp(argv[i], NHTTPD_ARG_TERMSIG) && i < argc - 1)
{
- _httpd_terminate_signal = atoi (argv[i + 1]);
+ _httpd_terminate_signal = atoi(argv[i + 1]);
}
- else if (!strcmp (argv[i], NHTTPD_ARG_MAXCONN) && i < argc - 1)
+ else if (!strcmp(argv[i], NHTTPD_ARG_MAXCONN) && i < argc - 1)
{
- _httpd_max_connections = atoi (argv[i + 1]);
+ _httpd_max_connections = atoi(argv[i + 1]);
}
}
- log_verbose2 ("socket bind to port '%d'", _httpd_port);
+ log_verbose2("socket bind to port '%d'", _httpd_port);
/* init built-in services */
/* httpd_register("/httpd/list", service_list); */
- _httpd_connection = calloc (_httpd_max_connections, sizeof (conndata_t));
+ _httpd_connection = calloc(_httpd_max_connections, sizeof(conndata_t));
for (i = 0; i < _httpd_max_connections; i++)
{
- memset ((char *) &_httpd_connection[i], 0, sizeof (_httpd_connection[i]));
+ memset((char *) &_httpd_connection[i], 0, sizeof(_httpd_connection[i]));
}
#ifdef WIN32
/*
if (_beginthread (WSAReaper, 0, NULL) == -1) { log_error1 ("Winsock
reaper thread failed to start"); return herror_new("httpd_init",
- THREAD_BEGIN_ERROR, "_beginthread() failed while starting WSAReaper");
- } */
+ THREAD_BEGIN_ERROR, "_beginthread() failed while starting WSAReaper"); }
+ */
#endif
/* create socket */
- status = hsocket_init (&_httpd_socket);
+ status = hsocket_init(&_httpd_socket);
if (status != H_OK)
{
return status;
}
- status = hsocket_bind (&_httpd_socket, _httpd_port);
+ status = hsocket_bind(&_httpd_socket, _httpd_port);
return status;
}
@@ -184,16 +184,16 @@ httpd_init (int argc, char *argv[])
*/
int
-httpd_register (const char *ctx, httpd_service func)
+httpd_register(const char *ctx, httpd_service func)
{
hservice_t *service;
- service = (hservice_t *) malloc (sizeof (hservice_t));
+ service = (hservice_t *) malloc(sizeof(hservice_t));
service->next = NULL;
service->func = func;
- strcpy (service->ctx, ctx);
+ strcpy(service->ctx, ctx);
- log_verbose3 ("register service:t(%p):%s", service, SAVE_STR (ctx));
+ log_verbose3("register service:t(%p):%s", service, SAVE_STR(ctx));
if (_httpd_services_head == NULL)
{
_httpd_services_head = _httpd_services_tail = service;
@@ -214,7 +214,7 @@ httpd_register (const char *ctx, httpd_service func)
* -----------------------------------------------------
*/
hservice_t *
-httpd_services ()
+httpd_services()
{
return _httpd_services_head;
}
@@ -225,9 +225,9 @@ httpd_services ()
* -----------------------------------------------------
*/
static void
-hservice_free (hservice_t * service)
+hservice_free(hservice_t * service)
{
- free (service);
+ free(service);
}
/*
@@ -236,13 +236,13 @@ hservice_free (hservice_t * service)
* -----------------------------------------------------
*/
static hservice_t *
-httpd_find_service (const char *ctx)
+httpd_find_service(const char *ctx)
{
hservice_t *cur = _httpd_services_head;
while (cur != NULL)
{
- if (!strcmp (cur->ctx, ctx))
+ if (!strcmp(cur->ctx, ctx))
{
return cur;
}
@@ -259,9 +259,9 @@ httpd_find_service (const char *ctx)
* -----------------------------------------------------
*/
void
-httpd_response_set_content_type (httpd_conn_t * res, const char *content_type)
+httpd_response_set_content_type(httpd_conn_t * res, const char *content_type)
{
- strncpy (res->content_type, content_type, 25);
+ strncpy(res->content_type, content_type, 25);
}
@@ -271,7 +271,7 @@ httpd_response_set_content_type (httpd_conn_t * res, const char *content_type)
* -----------------------------------------------------
*/
herror_t
-httpd_send_header (httpd_conn_t * res, int code, const char *text)
+httpd_send_header(httpd_conn_t * res, int code, const char *text)
{
struct tm stm;
time_t nw;
@@ -281,14 +281,14 @@ httpd_send_header (httpd_conn_t * res, int code, const char *text)
herror_t status;
/* set status code */
- sprintf (header, "HTTP/1.1 %d %s\r\n", code, text);
+ sprintf(header, "HTTP/1.1 %d %s\r\n", code, text);
/* set date */
- nw = time (NULL);
- localtime_r (&nw, &stm);
- strftime (buffer, 255, "Date: %a, %d %b %Y %T GMT", &stm);
- strcat (header, buffer);
- strcat (header, "\r\n");
+ nw = time(NULL);
+ localtime_r(&nw, &stm);
+ strftime(buffer, 255, "Date: %a, %d %b %Y %T GMT", &stm);
+ strcat(header, buffer);
+ strcat(header, "\r\n");
/* set content-type */
/*
@@ -298,7 +298,7 @@ httpd_send_header (httpd_conn_t * res, int code, const char *text)
*/
/* set server name */
- strcat (header, "Server: Nano HTTPD library\r\n");
+ strcat(header, "Server: Nano HTTPD library\r\n");
/* set _httpd_connection status */
// strcat (header, "Connection: close\r\n");
@@ -307,40 +307,40 @@ httpd_send_header (httpd_conn_t * res, int code, const char *text)
cur = res->header;
while (cur != NULL)
{
- sprintf (buffer, "%s: %s\r\n", cur->key, cur->value);
- strcat (header, buffer);
+ sprintf(buffer, "%s: %s\r\n", cur->key, cur->value);
+ strcat(header, buffer);
cur = cur->next;
}
/* set end of header */
- strcat (header, "\r\n");
+ strcat(header, "\r\n");
/* send header */
- status = hsocket_nsend (res->sock, header, strlen (header));
+ status = hsocket_nsend(res->sock, header, strlen(header));
if (status != H_OK)
return status;
- res->out = http_output_stream_new (res->sock, res->header);
+ res->out = http_output_stream_new(res->sock, res->header);
return H_OK;
}
int
-httpd_send_internal_error (httpd_conn_t * conn, const char *errmsg)
+httpd_send_internal_error(httpd_conn_t * conn, const char *errmsg)
{
const char *template1 =
"<html><body><h3>Error!</h3><hr> Message: '%s' </body></html>\r\n";
char buffer[4064];
char buflen[5];
- sprintf (buffer, template1, errmsg);
+ sprintf(buffer, template1, errmsg);
#ifdef WIN32
#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
#endif
- snprintf (buflen, 5, "%d", strlen (buffer));
- httpd_set_header (conn, HEADER_CONTENT_LENGTH, buflen);
- httpd_send_header (conn, 500, "INTERNAL");
- return hsocket_nsend (conn->sock, buffer, strlen (buffer));
+ snprintf(buflen, 5, "%d", strlen(buffer));
+ httpd_set_header(conn, HEADER_CONTENT_LENGTH, buflen);
+ httpd_send_header(conn, 500, "INTERNAL");
+ return hsocket_nsend(conn->sock, buffer, strlen(buffer));
}
/*
@@ -349,40 +349,40 @@ httpd_send_internal_error (httpd_conn_t * conn, const char *errmsg)
* -----------------------------------------------------
*/
static void
-httpd_request_print (hrequest_t * req)
+httpd_request_print(hrequest_t * req)
{
hpair_t *pair;
- log_verbose1 ("++++++ Request +++++++++");
- log_verbose2 (" Method : '%s'",
- (req->method == HTTP_REQUEST_POST) ? "POST" : "GET");
- log_verbose2 (" Path : '%s'", req->path);
- log_verbose2 (" Spec : '%s'",
- (req->version == HTTP_1_0) ? "HTTP/1.0" : "HTTP/1.1");
- log_verbose1 (" Parsed query string :");
+ log_verbose1("++++++ Request +++++++++");
+ log_verbose2(" Method : '%s'",
+ (req->method == HTTP_REQUEST_POST) ? "POST" : "GET");
+ log_verbose2(" Path : '%s'", req->path);
+ log_verbose2(" Spec : '%s'",
+ (req->version == HTTP_1_0) ? "HTTP/1.0" : "HTTP/1.1");
+ log_verbose1(" Parsed query string :");
pair = req->query;
while (pair != NULL)
{
- log_verbose3 (" %s = '%s'", pair->key, pair->value);
+ log_verbose3(" %s = '%s'", pair->key, pair->value);
pair = pair->next;
}
- log_verbose1 (" Parsed header :");
+ log_verbose1(" Parsed header :");
pair = req->header;
while (pair != NULL)
{
- log_verbose3 (" %s = '%s'", pair->key, pair->value);
+ log_verbose3(" %s = '%s'", pair->key, pair->value);
pair = pair->next;
}
- log_verbose1 ("++++++++++++++++++++++++");
+ log_verbose1("++++++++++++++++++++++++");
}
httpd_conn_t *
-httpd_new (hsocket_t sock)
+httpd_new(hsocket_t sock)
{
- httpd_conn_t *conn = (httpd_conn_t *) malloc (sizeof (httpd_conn_t));
+ httpd_conn_t *conn = (httpd_conn_t *) malloc(sizeof(httpd_conn_t));
conn->sock = sock;
conn->out = NULL;
conn->content_type[0] = '\0';
@@ -393,19 +393,19 @@ httpd_new (hsocket_t sock)
void
-httpd_free (httpd_conn_t * conn)
+httpd_free(httpd_conn_t * conn)
{
if (conn->out != NULL)
- http_output_stream_free (conn->out);
+ http_output_stream_free(conn->out);
if (conn->header != NULL)
- hpairnode_free_deep (conn->header);
+ hpairnode_free_deep(conn->header);
- free (conn);
+ free(conn);
}
void
-do_req_timeout (int signum)
+do_req_timeout(int signum)
{
/*
struct sigaction req_timeout;
@@ -415,11 +415,11 @@ do_req_timeout (int signum)
*/
// XXX this is not real pretty, is there a better way?
- log_verbose1 ("Thread timeout.");
+ log_verbose1("Thread timeout.");
#ifdef WIN32
- _endthread ();
+ _endthread();
#else
- pthread_exit (0);
+ pthread_exit(0);
#endif
}
@@ -430,15 +430,15 @@ do_req_timeout (int signum)
*/
#ifdef WIN32
static unsigned _stdcall
-httpd_session_main (void *data)
+httpd_session_main(void *data)
#else
static void *
-httpd_session_main (void *data)
+httpd_session_main(void *data)
#endif
{
conndata_t *conn = (conndata_t *) data;
const char *msg = "SESSION 1.0\n";
- int len = strlen (msg);
+ int len = strlen(msg);
int done = 0;
char buffer[256]; /* temp buffer for recv() */
char header[4064]; /* received header */
@@ -450,54 +450,54 @@ httpd_session_main (void *data)
header[0] = '\0';
len = 0;
- log_verbose1 ("starting httpd_session_main()");
+ log_verbose1("starting httpd_session_main()");
#ifdef HAVE_SSL
if (!SSLctx)
{
- log_verbose1 ("Using HTTP");
+ log_verbose1("Using HTTP");
}
else
{
- log_verbose1 ("Using HTTPS");
- conn->sock.ssl = init_ssl (SSLctx, conn->sock.sock, SSL_SERVER);
- hsocket_block (conn->sock, 0);
+ log_verbose1("Using HTTPS");
+ conn->sock.ssl = init_ssl(SSLctx, conn->sock.sock, SSL_SERVER);
+ hsocket_block(conn->sock, 0);
if (conn->sock.ssl == NULL)
{
- return herror_new ("hsocket_accept", SSL_ERROR_INIT,
- "Unable to initialize SSL");
+ return herror_new("hsocket_accept", SSL_ERROR_INIT,
+ "Unable to initialize SSL");
}
}
#endif
- conn->atime = time ((time_t) 0);
+ conn->atime = time((time_t) 0);
/* call the service */
/* req = hrequest_new_from_buffer (header);*/
do
{
- log_verbose1 ("starting HTTP request");
- rconn = httpd_new (conn->sock);
+ log_verbose1("starting HTTP request");
+ rconn = httpd_new(conn->sock);
- status = hrequest_new_from_socket (conn->sock, &req);
+ status = hrequest_new_from_socket(conn->sock, &req);
if (status != H_OK)
{
- if (herror_code (status) != HSOCKET_SSL_CLOSE)
+ if (herror_code(status) != HSOCKET_SSL_CLOSE)
{
- httpd_send_internal_error (rconn, herror_message (status) /* "Request
- parse
- error!" */ );
- herror_release (status);
+ httpd_send_internal_error(rconn, herror_message(status) /* "Request
+ parse
+ error!" */ );
+ herror_release(status);
}
done = 1;
}
else
{
char *conn_str =
- hpairnode_get_ignore_case (req->header, HEADER_CONNECTION);
+ hpairnode_get_ignore_case(req->header, HEADER_CONNECTION);
#ifdef WIN32
#define strncasecmp(s1, s2, num) strncmp(s1, s2, num)
#endif
- if (conn_str && strncasecmp (conn_str, "close", 5) == 0)
+ if (conn_str && strncasecmp(conn_str, "close", 5) == 0)
{
done = 1;
}
@@ -505,31 +505,31 @@ httpd_session_main (void *data)
{
done = req->version == HTTP_1_0 ? 1 : 0;
}
- httpd_request_print (req);
+ httpd_request_print(req);
- service = httpd_find_service (req->path);
+ service = httpd_find_service(req->path);
if (service != NULL)
{
- log_verbose2 ("service '%s' found", req->path);
+ log_verbose2("service '%s' found", req->path);
if (service->func != NULL)
{
- service->func (rconn, req);
+ service->func(rconn, req);
}
else
{
- sprintf (buffer,
- "service '%s' not registered properly (func == NULL)",
- req->path);
- log_verbose1 (buffer);
- httpd_send_internal_error (rconn, buffer);
+ sprintf(buffer,
+ "service '%s' not registered properly (func == NULL)",
+ req->path);
+ log_verbose1(buffer);
+ httpd_send_internal_error(rconn, buffer);
}
}
else
{
- sprintf (buffer, "service '%s' not found", req->path);
- log_verbose1 (buffer);
- httpd_send_internal_error (rconn, buffer);
+ sprintf(buffer, "service '%s' not found", req->path);
+ log_verbose1(buffer);
+ httpd_send_internal_error(rconn, buffer);
}
/* httpd_response_free(res); */
@@ -538,29 +538,29 @@ httpd_session_main (void *data)
}
while (!done);
- hsocket_close (conn->sock);
- log_verbose1 ("Marking connection as available");
+ hsocket_close(conn->sock);
+ log_verbose1("Marking connection as available");
conn->sock.sock = 0;
- hrequest_free (req);
- httpd_free (rconn);
+ hrequest_free(req);
+ httpd_free(rconn);
#ifdef WIN32
- CloseHandle ((HANDLE) conn->tid);
- _endthread ();
+ CloseHandle((HANDLE) conn->tid);
+ _endthread();
return 0;
#else
- pthread_exit (NULL);
+ pthread_exit(NULL);
return service;
#endif
}
int
-httpd_set_header (httpd_conn_t * conn, const char *key, const char *value)
+httpd_set_header(httpd_conn_t * conn, const char *key, const char *value)
{
hpair_t *p;
if (conn == NULL)
{
- log_warn1 ("Connection object is NULL");
+ log_warn1("Connection object is NULL");
return 0;
}
p = conn->header;
@@ -568,28 +568,28 @@ httpd_set_header (httpd_conn_t * conn, const char *key, const char *value)
{
if (p->key != NULL)
{
- if (!strcmp (p->key, key))
+ if (!strcmp(p->key, key))
{
- free (p->value);
- p->value = (char *) malloc (strlen (value) + 1);
- strcpy (p->value, value);
+ free(p->value);
+ p->value = (char *) malloc(strlen(value) + 1);
+ strcpy(p->value, value);
return 1;
}
}
p = p->next;
}
- conn->header = hpairnode_new (key, value, conn->header);
+ conn->header = hpairnode_new(key, value, conn->header);
return 0;
}
void
-httpd_set_headers (httpd_conn_t * conn, hpair_t * header)
+httpd_set_headers(httpd_conn_t * conn, hpair_t * header)
{
while (header)
{
- httpd_set_header (conn, header->key, header->value);
+ httpd_set_header(conn, header->key, header->value);
header = header->next;
}
}
@@ -601,7 +601,7 @@ httpd_set_headers (httpd_conn_t * conn, hpair_t * header)
*/
#ifdef WIN32
BOOL WINAPI
-httpd_term (DWORD sig)
+httpd_term(DWORD sig)
{
// log_debug2 ("Got signal %d", sig);
if (sig == _httpd_terminate_signal)
@@ -612,9 +612,9 @@ httpd_term (DWORD sig)
#else
void
-httpd_term (int sig)
+httpd_term(int sig)
{
- log_debug2 ("Got signal %d", sig);
+ log_debug2("Got signal %d", sig);
if (sig == _httpd_terminate_signal)
_httpd_run = 0;
}
@@ -628,18 +628,18 @@ httpd_term (int sig)
* -----------------------------------------------------
*/
static void
-_httpd_register_signal_handler ()
+_httpd_register_signal_handler()
{
- log_verbose2 ("registering termination signal handler (SIGNAL:%d)",
- _httpd_terminate_signal);
+ log_verbose2("registering termination signal handler (SIGNAL:%d)",
+ _httpd_terminate_signal);
#ifdef WIN32
- if (SetConsoleCtrlHandler ((PHANDLER_ROUTINE) httpd_term, TRUE) == FALSE)
+ if (SetConsoleCtrlHandler((PHANDLER_ROUTINE) httpd_term, TRUE) == FALSE)
{
- log_error1 ("Unable to install console event handler!");
+ log_error1("Unable to install console event handler!");
}
#else
- signal (_httpd_terminate_signal, httpd_term);
+ signal(_httpd_terminate_signal, httpd_term);
#endif
}
@@ -650,7 +650,7 @@ _httpd_register_signal_handler ()
FUNCTION: _httpd_wait_for_empty_conn
----------------------------------------------------*/
static conndata_t *
-_httpd_wait_for_empty_conn ()
+_httpd_wait_for_empty_conn()
{
int i;
for (i = 0;; i++)
@@ -660,7 +660,7 @@ _httpd_wait_for_empty_conn ()
if (i >= _httpd_max_connections)
{
- system_sleep (1);
+ system_sleep(1);
i = 0;
}
else if (_httpd_connection[i].sock.sock == 0)
@@ -678,24 +678,23 @@ _httpd_wait_for_empty_conn ()
* -----------------------------------------------------
*/
static void
-_httpd_start_thread (conndata_t * conn)
+_httpd_start_thread(conndata_t * conn)
{
int err;
#ifdef WIN32
conn->tid =
- (HANDLE) _beginthreadex (NULL, 65535, httpd_session_main, conn, 0, &err);
+ (HANDLE) _beginthreadex(NULL, 65535, httpd_session_main, conn, 0, &err);
#else
- pthread_attr_init (&(conn->attr));
+ pthread_attr_init(&(conn->attr));
#ifdef PTHREAD_CREATE_DETACHED
- pthread_attr_setdetachstate (&(conn->attr), PTHREAD_CREATE_DETACHED);
+ pthread_attr_setdetachstate(&(conn->attr), PTHREAD_CREATE_DETACHED);
#endif
- pthread_sigmask (SIG_BLOCK, &thrsigset, NULL);
- err = pthread_create (&(conn->tid), &(conn->attr), httpd_session_main,
- conn);
+ pthread_sigmask(SIG_BLOCK, &thrsigset, NULL);
+ err = pthread_create(&(conn->tid), &(conn->attr), httpd_session_main, conn);
if (err)
{
- log_error2 ("Error creating thread: ('%d')", err);
+ log_error2("Error creating thread: ('%d')", err);
}
#endif
}
@@ -709,7 +708,7 @@ _httpd_start_thread (conndata_t * conn)
*/
herror_t
-httpd_run ()
+httpd_run()
{
herror_t err;
conndata_t *conn;
@@ -717,34 +716,34 @@ httpd_run ()
struct timeval timeout;
- log_verbose1 ("starting run routine");
+ log_verbose1("starting run routine");
timeout.tv_sec = 1;
timeout.tv_usec = 0;
#ifdef WIN32
#else
- sigemptyset (&thrsigset);
- sigaddset (&thrsigset, SIGALRM);
+ sigemptyset(&thrsigset);
+ sigaddset(&thrsigset, SIGALRM);
#endif
/* listen to port */
- err = hsocket_listen (_httpd_socket);
+ err = hsocket_listen(_httpd_socket);
if (err != H_OK)
{
- log_error2 ("httpd_run(): '%d'", herror_message (err));
+ log_error2("httpd_run(): '%d'", herror_message(err));
return err;
}
- log_verbose2 ("listening to port '%d'", _httpd_port);
+ log_verbose2("listening to port '%d'", _httpd_port);
/* register signal handler */
- _httpd_register_signal_handler ();
+ _httpd_register_signal_handler();
/* make the socket non blocking */
- err = hsocket_block (_httpd_socket, 0);
+ err = hsocket_block(_httpd_socket, 0);
if (err != H_OK)
{
- log_error2 ("httpd_run(): '%s'", herror_message (err));
+ log_error2("httpd_run(): '%s'", herror_message(err));
return err;
}
@@ -752,7 +751,7 @@ httpd_run ()
while (_httpd_run)
{
/* Get an empty connection struct */
- conn = _httpd_wait_for_empty_conn ();
+ conn = _httpd_wait_for_empty_conn();
if (!_httpd_run)
break;
@@ -766,11 +765,11 @@ httpd_run ()
timeout.tv_usec = 0;
/* zero and set file descriptior */
- FD_ZERO (&fds);
- FD_SET (_httpd_socket.sock, &fds);
+ FD_ZERO(&fds);
+ FD_SET(_httpd_socket.sock, &fds);
/* select socket descriptor */
- switch (select (_httpd_socket.sock + 1, &fds, NULL, NULL, &timeout))
+ switch (select(_httpd_socket.sock + 1, &fds, NULL, NULL, &timeout))
{
case 0:
/* descriptor is not ready */
@@ -782,7 +781,7 @@ httpd_run ()
/* no nothing */
break;
}
- if (FD_ISSET (_httpd_socket.sock, &fds))
+ if (FD_ISSET(_httpd_socket.sock, &fds))
{
break;
}
@@ -793,49 +792,49 @@ httpd_run ()
break;
/* Accept a socket */
- err = hsocket_accept (_httpd_socket, &(conn->sock));
- if (err != H_OK && herror_code (err) == SSL_ERROR_INIT)
+ err = hsocket_accept(_httpd_socket, &(conn->sock));
+ if (err != H_OK && herror_code(err) == SSL_ERROR_INIT)
{
- hsocket_close (conn->sock);
+ hsocket_close(conn->sock);
conn->sock.sock = -1;
#ifdef HAVE_SSL
conn->sock.ssl = NULL;
#endif
- log_error1 (herror_message (err));
+ log_error1(herror_message(err));
continue;
}
else if (err != H_OK)
{
- log_error2 ("Can not accept socket: %s", herror_message (err));
+ log_error2("Can not accept socket: %s", herror_message(err));
return err; /* this is hard core! */
}
/* Now start a thread */
- _httpd_start_thread (conn);
+ _httpd_start_thread(conn);
}
- free (_httpd_connection);
+ free(_httpd_connection);
return 0;
}
void
-httpd_destroy ()
+httpd_destroy()
{
hservice_t *tmp, *cur = _httpd_services_head;
while (cur != NULL)
{
tmp = cur->next;
- hservice_free (cur);
+ hservice_free(cur);
cur = tmp;
}
- hsocket_module_destroy ();
+ hsocket_module_destroy();
}
#ifdef WIN32
static void
-WSAReaper (void *x)
+WSAReaper(void *x)
{
short int connections;
short int i;
@@ -846,34 +845,32 @@ WSAReaper (void *x)
for (;;)
{
connections = 0;
- ctime = time ((time_t) 0);
+ ctime = time((time_t) 0);
for (i = 0; i < _httpd_max_connections; i++)
{
if (_httpd_connection[i].tid == 0)
continue;
- GetExitCodeThread ((HANDLE) _httpd_connection[i].tid, (PDWORD) & rc);
+ GetExitCodeThread((HANDLE) _httpd_connection[i].tid, (PDWORD) & rc);
if (rc != STILL_ACTIVE)
continue;
connections++;
if ((ctime - _httpd_connection[i].atime < _httpd_max_idle) ||
(_httpd_connection[i].atime == 0))
continue;
- log_verbose3 ("Reaping socket %u from (runtime ~= %d seconds)",
- _httpd_connection[i].sock,
- ctime - _httpd_connection[i].atime);
- shutdown (_httpd_connection[i].sock.sock, 2);
- while (recv (_httpd_connection[i].sock.sock, junk, sizeof (junk), 0) >
- 0)
+ log_verbose3("Reaping socket %u from (runtime ~= %d seconds)",
+ _httpd_connection[i].sock,
+ ctime - _httpd_connection[i].atime);
+ shutdown(_httpd_connection[i].sock.sock, 2);
+ while (recv(_httpd_connection[i].sock.sock, junk, sizeof(junk), 0) > 0)
{
};
- closesocket (_httpd_connection[i].sock.sock);
+ closesocket(_httpd_connection[i].sock.sock);
_httpd_connection[i].sock.sock = 0;
- TerminateThread (_httpd_connection[i].tid, (DWORD) & rc);
- CloseHandle (_httpd_connection[i].tid);
- memset ((char *) &_httpd_connection[i], 0,
- sizeof (_httpd_connection[i]));
+ TerminateThread(_httpd_connection[i].tid, (DWORD) & rc);
+ CloseHandle(_httpd_connection[i].tid);
+ memset((char *) &_httpd_connection[i], 0, sizeof(_httpd_connection[i]));
}
- Sleep (100);
+ Sleep(100);
}
return;
}
@@ -881,8 +878,8 @@ WSAReaper (void *x)
#endif
unsigned char *
-httpd_get_postdata (httpd_conn_t * conn, hrequest_t * req, long *received,
- long max)
+httpd_get_postdata(httpd_conn_t * conn, hrequest_t * req, long *received,
+ long max)
{
char *content_length_str;
long content_length = 0;
@@ -892,15 +889,15 @@ httpd_get_postdata (httpd_conn_t * conn, hrequest_t * req, long *received,
{
content_length_str =
- hpairnode_get_ignore_case (req->header, HEADER_CONTENT_LENGTH);
+ hpairnode_get_ignore_case(req->header, HEADER_CONTENT_LENGTH);
if (content_length_str != NULL)
- content_length = atol (content_length_str);
+ content_length = atol(content_length_str);
}
else
{
- log_warn1 ("Not a POST method");
+ log_warn1("Not a POST method");
return NULL;
}
@@ -910,23 +907,23 @@ httpd_get_postdata (httpd_conn_t * conn, hrequest_t * req, long *received,
if (content_length == 0)
{
*received = 0;
- postdata = (char *) malloc (1);
+ postdata = (char *) malloc(1);
postdata[0] = '\0';
return postdata;
}
- postdata = (unsigned char *) malloc (content_length + 1);
+ postdata = (unsigned char *) malloc(content_length + 1);
if (postdata == NULL)
{
- log_error1 ("Not enough memory");
+ log_error1("Not enough memory");
return NULL;
}
- if (http_input_stream_read (req->in, postdata, (int) content_length) > 0)
+ if (http_input_stream_read(req->in, postdata, (int) content_length) > 0)
{
*received = content_length;
postdata[content_length] = '\0';
return postdata;
}
- free (postdata);
+ free(postdata);
return NULL;
}
@@ -938,10 +935,10 @@ httpd_get_postdata (httpd_conn_t * conn, hrequest_t * req, long *received,
*/
static void
-_httpd_mime_get_boundary (httpd_conn_t * conn, char *dest)
+_httpd_mime_get_boundary(httpd_conn_t * conn, char *dest)
{
- sprintf (dest, "---=.Part_NH_%p", conn);
- log_verbose2 ("boundary= \"%s\"", dest);
+ sprintf(dest, "---=.Part_NH_%p", conn);
+ log_verbose2("boundary= \"%s\"", dest);
}
@@ -950,10 +947,10 @@ _httpd_mime_get_boundary (httpd_conn_t * conn, char *dest)
Returns: H_OK or error flag
*/
herror_t
-httpd_mime_send_header (httpd_conn_t * conn,
- const char *related_start,
- const char *related_start_info,
- const char *related_type, int code, const char *text)
+httpd_mime_send_header(httpd_conn_t * conn,
+ const char *related_start,
+ const char *related_start_info,
+ const char *related_type, int code, const char *text)
{
char buffer[300];
char temp[250];
@@ -968,33 +965,33 @@ httpd_mime_send_header (httpd_conn_t * conn,
using sprintf instead of snprintf because visual c does not support
snprintf */
- sprintf (buffer, "multipart/related;");
+ sprintf(buffer, "multipart/related;");
if (related_type)
{
- snprintf (temp, 75, " type=\"%s\";", related_type);
- strcat (buffer, temp);
+ snprintf(temp, 75, " type=\"%s\";", related_type);
+ strcat(buffer, temp);
}
if (related_start)
{
- snprintf (temp, 250, " start=\"%s\";", related_start);
- strcat (buffer, temp);
+ snprintf(temp, 250, " start=\"%s\";", related_start);
+ strcat(buffer, temp);
}
if (related_start_info)
{
- snprintf (temp, 250, " start-info=\"%s\";", related_start_info);
- strcat (buffer, temp);
+ snprintf(temp, 250, " start-info=\"%s\";", related_start_info);
+ strcat(buffer, temp);
}
- _httpd_mime_get_boundary (conn, boundary);
- snprintf (temp, 250, " boundary=\"%s\"", boundary);
- strcat (buffer, temp);
+ _httpd_mime_get_boundary(conn, boundary);
+ snprintf(temp, 250, " boundary=\"%s\"", boundary);
+ strcat(buffer, temp);
- httpd_set_header (conn, HEADER_CONTENT_TYPE, buffer);
+ httpd_set_header(conn, HEADER_CONTENT_TYPE, buffer);
- return httpd_send_header (conn, code, text);
+ return httpd_send_header(conn, code, text);
}
@@ -1003,37 +1000,35 @@ httpd_mime_send_header (httpd_conn_t * conn,
with next part
*/
herror_t
-httpd_mime_next (httpd_conn_t * conn,
- const char *content_id,
- const char *content_type, const char *transfer_encoding)
+httpd_mime_next(httpd_conn_t * conn,
+ const char *content_id,
+ const char *content_type, const char *transfer_encoding)
{
herror_t status;
char buffer[512];
char boundary[75];
/* Get the boundary string */
- _httpd_mime_get_boundary (conn, boundary);
- sprintf (buffer, "\r\n--%s\r\n", boundary);
+ _httpd_mime_get_boundary(conn, boundary);
+ sprintf(buffer, "\r\n--%s\r\n", boundary);
/* Send boundary */
- status = http_output_stream_write (conn->out,
- (const byte_t *) buffer,
- strlen (buffer));
+ status = http_output_stream_write(conn->out,
+ (const byte_t *) buffer, strlen(buffer));
if (status != H_OK)
return status;
/* Send Content header */
- sprintf (buffer, "%s: %s\r\n%s: %s\r\n%s: %s\r\n\r\n",
- HEADER_CONTENT_TYPE, content_type ? content_type : "text/plain",
- HEADER_CONTENT_TRANSFER_ENCODING,
- transfer_encoding ? transfer_encoding : "binary",
- HEADER_CONTENT_ID,
- content_id ? content_id : "<content-id-not-set>");
+ sprintf(buffer, "%s: %s\r\n%s: %s\r\n%s: %s\r\n\r\n",
+ HEADER_CONTENT_TYPE, content_type ? content_type : "text/plain",
+ HEADER_CONTENT_TRANSFER_ENCODING,
+ transfer_encoding ? transfer_encoding : "binary",
+ HEADER_CONTENT_ID,
+ content_id ? content_id : "<content-id-not-set>");
- status = http_output_stream_write (conn->out,
- (const byte_t *) buffer,
- strlen (buffer));
+ status = http_output_stream_write(conn->out,
+ (const byte_t *) buffer, strlen(buffer));
return status;
}
@@ -1043,47 +1038,46 @@ httpd_mime_next (httpd_conn_t * conn,
with next part
*/
herror_t
-httpd_mime_send_file (httpd_conn_t * conn,
- const char *content_id,
- const char *content_type,
- const char *transfer_encoding, const char *filename)
+httpd_mime_send_file(httpd_conn_t * conn,
+ const char *content_id,
+ const char *content_type,
+ const char *transfer_encoding, const char *filename)
{
herror_t status;
- FILE *fd = fopen (filename, "rb");
+ FILE *fd = fopen(filename, "rb");
byte_t buffer[MAX_FILE_BUFFER_SIZE];
size_t size;
if (fd == NULL)
- return herror_new ("httpd_mime_send_file", FILE_ERROR_OPEN,
- "Can not open file '%d'", filename);
+ return herror_new("httpd_mime_send_file", FILE_ERROR_OPEN,
+ "Can not open file '%d'", filename);
- status =
- httpd_mime_next (conn, content_id, content_type, transfer_encoding);
+ status = httpd_mime_next(conn, content_id, content_type, transfer_encoding);
if (status != H_OK)
{
- fclose (fd);
+ fclose(fd);
return status;
}
- while (!feof (fd))
+ while (!feof(fd))
{
- size = fread (buffer, 1, MAX_FILE_BUFFER_SIZE, fd);
+ size = fread(buffer, 1, MAX_FILE_BUFFER_SIZE, fd);
if (size == -1)
{
- fclose (fd);
- return herror_new ("httpd_mime_send_file", FILE_ERROR_READ,
- "Can not read from file '%d'", filename);
+ fclose(fd);
+ 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);
+ status = http_output_stream_write(conn->out, buffer, size);
if (status != H_OK)
{
- fclose (fd);
+ fclose(fd);
return status;
}
}
- fclose (fd);
+ fclose(fd);
return H_OK;
}
@@ -1092,26 +1086,25 @@ httpd_mime_send_file (httpd_conn_t * conn,
Returns: H_OK or error flag
*/
herror_t
-httpd_mime_end (httpd_conn_t * conn)
+httpd_mime_end(httpd_conn_t * conn)
{
herror_t status;
char buffer[512];
char boundary[75];
/* Get the boundary string */
- _httpd_mime_get_boundary (conn, boundary);
- sprintf (buffer, "\r\n--%s--\r\n\r\n", boundary);
+ _httpd_mime_get_boundary(conn, boundary);
+ sprintf(buffer, "\r\n--%s--\r\n\r\n", boundary);
/* Send boundary */
- status = http_output_stream_write (conn->out,
- (const byte_t *) buffer,
- strlen (buffer));
+ status = http_output_stream_write(conn->out,
+ (const byte_t *) buffer, strlen(buffer));
if (status != H_OK)
return status;
/* Flush put stream */
- status = http_output_stream_flush (conn->out);
+ status = http_output_stream_flush(conn->out);
return status;
}
diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h
index 101a4b7..383b7be 100644
--- a/nanohttp/nanohttp-server.h
+++ b/nanohttp/nanohttp-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-server.h,v 1.10 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: nanohttp-server.h,v 1.11 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -62,18 +62,17 @@ typedef struct tag_hservice
/*
Begin httpd_* function set
*/
-herror_t httpd_init (int argc, char *argv[]);
-int httpd_register (const char *ctx, httpd_service service);
-herror_t httpd_run ();
-void httpd_destroy ();
+herror_t httpd_init(int argc, char *argv[]);
+int httpd_register(const char *ctx, httpd_service service);
+herror_t httpd_run();
+void httpd_destroy();
-hservice_t *httpd_services ();
+hservice_t *httpd_services();
-herror_t httpd_send_header (httpd_conn_t * res, int code, const char *text);
+herror_t httpd_send_header(httpd_conn_t * res, int code, const char *text);
-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);
+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,
@@ -90,36 +89,36 @@ unsigned char *httpd_get_postdata(httpd_conn_t *conn,
Begin MIME multipart/related POST
Returns: HSOCKET_OK or error flag
*/
-herror_t httpd_mime_send_header (httpd_conn_t * conn,
- const char *related_start,
- const char *related_start_info,
- const char *related_type, int code,
- const char *text);
+herror_t httpd_mime_send_header(httpd_conn_t * conn,
+ const char *related_start,
+ const char *related_start_info,
+ const char *related_type, int code,
+ const char *text);
/**
Send boundary and part header and continue
with next part
*/
-herror_t httpd_mime_next (httpd_conn_t * conn,
- const char *content_id,
- const char *content_type,
- const char *transfer_encoding);
+herror_t httpd_mime_next(httpd_conn_t * conn,
+ const char *content_id,
+ const char *content_type,
+ const char *transfer_encoding);
/**
Send boundary and part header and continue
with next part
*/
-herror_t httpd_mime_send_file (httpd_conn_t * conn,
- const char *content_id,
- const char *content_type,
- const char *transfer_encoding,
- const char *filename);
+herror_t httpd_mime_send_file(httpd_conn_t * conn,
+ const char *content_id,
+ const char *content_type,
+ const char *transfer_encoding,
+ const char *filename);
/**
Finish MIME request
Returns: HSOCKET_OK or error flag
*/
-herror_t httpd_mime_end (httpd_conn_t * conn);
+herror_t httpd_mime_end(httpd_conn_t * conn);
#endif
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index ee69561..018f42d 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.42 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-socket.c,v 1.43 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -91,11 +91,11 @@ NOTE: This will be called from httpd_init()
for server and from httpc_init() for client
----------------------------------------------------*/
herror_t
-hsocket_module_init ()
+hsocket_module_init()
{
#ifdef WIN32
struct WSAData info;
- WSAStartup (MAKEWORD (2, 2), &info);
+ WSAStartup(MAKEWORD(2, 2), &info);
#else /* */
/* nothing to init for unix sockets */
@@ -107,10 +107,10 @@ hsocket_module_init ()
FUNCTION: hsocket_module_destroy
----------------------------------------------------*/
void
-hsocket_module_destroy ()
+hsocket_module_destroy()
{
#ifdef WIN32
- WSACleanup ();
+ WSACleanup();
#else /* */
/* nothing to destroy for unix sockets */
@@ -121,21 +121,21 @@ hsocket_module_destroy ()
FUNCTION: hsocket_init
----------------------------------------------------*/
herror_t
-hsocket_init (hsocket_t * sock)
+hsocket_init(hsocket_t * sock)
{
- log_verbose1 ("Starting hsocket init");
+ log_verbose1("Starting hsocket init");
/* just set the descriptor to -1 */
sock->sock = -1;
#ifdef HAVE_SSL
sock->ssl = NULL;
if (SSLCert || SSLCertLess)
{
- log_verbose1 ("calling init ctx");
- SSLctx = initialize_ctx (SSLCert, SSLPass, SSLCA);
+ log_verbose1("calling init ctx");
+ SSLctx = initialize_ctx(SSLCert, SSLPass, SSLCA);
if (SSLctx == NULL)
{
- return herror_new ("hsocket_init", HSOCKET_ERROR_CONNECT,
- "Unable to initialize SSL CTX");
+ return herror_new("hsocket_init", HSOCKET_ERROR_CONNECT,
+ "Unable to initialize SSL CTX");
}
}
#endif
@@ -146,7 +146,7 @@ hsocket_init (hsocket_t * sock)
FUNCTION: hsocket_free
----------------------------------------------------*/
void
-hsocket_free (hsocket_t sock)
+hsocket_free(hsocket_t sock)
{
/* nothing to free for unix sockets */
}
@@ -155,49 +155,48 @@ hsocket_free (hsocket_t sock)
FUNCTION: hsocket_open
----------------------------------------------------*/
herror_t
-hsocket_open (hsocket_t * dsock, const char *hostname, int port)
+hsocket_open(hsocket_t * dsock, const char *hostname, int port)
{
hsocket_t sock;
char *ip;
struct sockaddr_in address;
struct hostent *host;
- sock.sock = socket (AF_INET, SOCK_STREAM, 0);
+ sock.sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock.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);
+ 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);
+ ip = inet_ntoa(*(struct in_addr *) *host->h_addr_list);
+ address.sin_addr.s_addr = inet_addr(ip);
/* set server addresss */
address.sin_family = host->h_addrtype;
- address.sin_port = htons ((unsigned short) port);
+ address.sin_port = htons((unsigned short) port);
/* connect to the server */
- if (connect (sock.sock, (struct sockaddr *) &address, sizeof (address)) !=
- 0)
- return herror_new ("hsocket_open", HSOCKET_ERROR_CONNECT,
- "Socket error: %d", errno);
+ if (connect(sock.sock, (struct sockaddr *) &address, sizeof(address)) != 0)
+ return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT,
+ "Socket error: %d", errno);
#ifdef HAVE_SSL
if (!SSLctx)
{
#endif
- log_verbose1 ("Using HTTP");
+ log_verbose1("Using HTTP");
dsock->sock = sock.sock;
#ifdef HAVE_SSL
}
else
{
- log_verbose1 ("Using HTTPS");
- dsock->ssl = init_ssl (SSLctx, sock.sock, SSL_CLIENT);
+ log_verbose1("Using HTTPS");
+ dsock->ssl = init_ssl(SSLctx, sock.sock, SSL_CLIENT);
}
#endif
return H_OK;
@@ -207,35 +206,34 @@ hsocket_open (hsocket_t * dsock, const char *hostname, int port)
FUNCTION: hsocket_bind
----------------------------------------------------*/
herror_t
-hsocket_bind (hsocket_t * dsock, int port)
+hsocket_bind(hsocket_t * dsock, int port)
{
hsocket_t sock;
struct sockaddr_in addr;
int opt = 1;
/* create socket */
- sock.sock = socket (AF_INET, SOCK_STREAM, 0);
+ sock.sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock.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);
+ log_error3("Can not create socket: '%s'", "Socket error: %d", errno);
+ return herror_new("hsocket_bind", HSOCKET_ERROR_CREATE,
+ "Socket error: %d", errno);
}
- setsockopt (sock.sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt));
+ setsockopt(sock.sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
/* bind socket */
addr.sin_family = AF_INET;
- addr.sin_port = htons ((unsigned short) port); /* short, network
- byte order */
+ addr.sin_port = htons((unsigned short) port); /* short, network byte order */
addr.sin_addr.s_addr = INADDR_ANY;
- memset (&(addr.sin_zero), '\0', 8); /* zero the rest of the struct */
+ memset(&(addr.sin_zero), '\0', 8); /* zero the rest of the struct */
- if (bind (sock.sock, (struct sockaddr *) &addr, sizeof (struct sockaddr)) ==
+ if (bind(sock.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);
+ log_error3("Can not bind: '%s'", "Socket error: %d", errno);
+ return herror_new("hsocket_bind", HSOCKET_ERROR_BIND, "Socket error: %d",
+ errno);
}
dsock->sock = sock.sock;
return H_OK;
@@ -245,26 +243,26 @@ hsocket_bind (hsocket_t * dsock, int port)
FUNCTION: hsocket_accept
----------------------------------------------------------*/
herror_t
-hsocket_accept (hsocket_t sock, hsocket_t * dest)
+hsocket_accept(hsocket_t sock, hsocket_t * dest)
{
socklen_t asize;
hsocket_t sockfd;
struct sockaddr_in addr;
if (sock.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);
+ asize = sizeof(struct sockaddr_in);
#ifdef WIN32
while (1)
{
- sockfd.sock = accept (sock.sock, (struct sockaddr *) &addr, &asize);
+ sockfd.sock = accept(sock.sock, (struct sockaddr *) &addr, &asize);
if (sockfd.sock == INVALID_SOCKET)
{
- if (WSAGetLastError () != WSAEWOULDBLOCK)
- return herror_new ("hsocket_accept", HSOCKET_ERROR_ACCEPT,
- "Socket error: %d", errno);
+ if (WSAGetLastError() != WSAEWOULDBLOCK)
+ return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT,
+ "Socket error: %d", errno);
}
else
{
@@ -273,17 +271,17 @@ hsocket_accept (hsocket_t sock, hsocket_t * dest)
}
#else
/* TODO (#1#): why not a loop like in win32? */
- sockfd.sock = accept (sock.sock, (struct sockaddr *) &addr, &asize);
+ sockfd.sock = accept(sock.sock, (struct sockaddr *) &addr, &asize);
if (sockfd.sock == -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 */
- log_verbose3 ("accept new socket (%d) from '%s'", sockfd.sock,
- SAVE_STR (((char *) inet_ntoa (addr.sin_addr))));
+ log_verbose3("accept new socket (%d) from '%s'", sockfd.sock,
+ SAVE_STR(((char *) inet_ntoa(addr.sin_addr))));
dest->sock = sockfd.sock;
return H_OK;
@@ -293,17 +291,17 @@ hsocket_accept (hsocket_t sock, hsocket_t * dest)
FUNCTION: hsocket_listen
----------------------------------------------------*/
herror_t
-hsocket_listen (hsocket_t sock)
+hsocket_listen(hsocket_t sock)
{
if (sock.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.sock, 15) == -1)
+ if (listen(sock.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);
+ log_error3("Can not listen: '%s'", "Socket error: %d", errno);
+ return herror_new("hsocket_listen", HSOCKET_ERROR_LISTEN,
+ "Socket error: %d", errno);
}
return H_OK;
@@ -311,7 +309,7 @@ hsocket_listen (hsocket_t sock)
#if 0
static void
-_hsocket_wait_until_receive (hsocket_t sock)
+_hsocket_wait_until_receive(hsocket_t sock)
{
fd_set fds;
struct timeval timeout;
@@ -322,13 +320,13 @@ _hsocket_wait_until_receive (hsocket_t sock)
while (1)
{
- log_verbose1 ("waiting until receive mode");
+ log_verbose1("waiting until receive mode");
/* zero and set file descriptior */
- FD_ZERO (&fds);
- FD_SET (sock, &fds);
+ FD_ZERO(&fds);
+ FD_SET(sock, &fds);
/* select socket descriptor */
- switch (select (sock + 1, &fds, NULL, NULL, &timeout))
+ switch (select(sock + 1, &fds, NULL, NULL, &timeout))
{
case 0:
/* descriptor is not ready */
@@ -340,7 +338,7 @@ _hsocket_wait_until_receive (hsocket_t sock)
/* no nothing */
break;
}
- if (FD_ISSET (sock, &fds))
+ if (FD_ISSET(sock, &fds))
{
break;
}
@@ -352,11 +350,11 @@ _hsocket_wait_until_receive (hsocket_t sock)
FUNCTION: hsocket_close
----------------------------------------------------*/
void
-hsocket_close (hsocket_t sock)
+hsocket_close(hsocket_t sock)
{
char junk[10];
/* _hsocket_wait_until_receive(sock);*/
- log_verbose2 ("closing socket %d...", sock.sock);
+ log_verbose2("closing socket %d...", sock.sock);
/*
struct linger _linger;
hsocket_block(sock,1);
@@ -370,51 +368,51 @@ hsocket_close (hsocket_t sock)
/* shutdown(sock,SD_RECEIVE); */
- shutdown (sock.sock, SD_SEND);
- while (recv (sock.sock, junk, sizeof (junk), 0) > 0)
+ shutdown(sock.sock, SD_SEND);
+ while (recv(sock.sock, junk, sizeof(junk), 0) > 0)
{
};
- closesocket (sock.sock);
+ closesocket(sock.sock);
#else
/* XXX m. campbell - It seems like the while loop here needs this */
- fcntl (sock.sock, F_SETFL, O_NONBLOCK);
+ fcntl(sock.sock, F_SETFL, O_NONBLOCK);
#ifdef HAVE_SSL
if (sock.ssl)
{
- log_verbose1 ("Closing SSL");
- ssl_cleanup (sock.ssl);
- shutdown (sock.sock, SHUT_RDWR);
- while (recv (sock.sock, junk, sizeof (junk), 0) > 0)
+ log_verbose1("Closing SSL");
+ ssl_cleanup(sock.ssl);
+ shutdown(sock.sock, SHUT_RDWR);
+ while (recv(sock.sock, junk, sizeof(junk), 0) > 0)
{
};
- close (sock.sock);
+ close(sock.sock);
}
else
{
#endif
- shutdown (sock.sock, SHUT_RDWR);
- while (recv (sock.sock, junk, sizeof (junk), 0) > 0)
+ shutdown(sock.sock, SHUT_RDWR);
+ while (recv(sock.sock, junk, sizeof(junk), 0) > 0)
{
};
- close (sock.sock);
+ close(sock.sock);
#ifdef HAVE_SSL
}
#endif
#endif
- log_verbose1 ("socket closed");
+ log_verbose1("socket closed");
}
#if 0
static int
-_test_send_to_file (const char *filename, const byte_t * bytes, int n)
+_test_send_to_file(const char *filename, const byte_t * bytes, int n)
{
int size;
- FILE *f = fopen (filename, "ab");
+ FILE *f = fopen(filename, "ab");
if (!f)
- f = fopen (filename, "wb");
- size = fwrite (bytes, 1, n, f);
- fclose (f);
+ f = fopen(filename, "wb");
+ size = fwrite(bytes, 1, n, f);
+ fclose(f);
return size;
}
#endif
@@ -422,19 +420,19 @@ _test_send_to_file (const char *filename, const byte_t * bytes, int n)
FUNCTION: hsocket_send
----------------------------------------------------*/
herror_t
-hsocket_nsend (hsocket_t sock, const byte_t * bytes, int n)
+hsocket_nsend(hsocket_t sock, const byte_t * bytes, int n)
{
int size;
int total = 0;
- log_verbose1 ("Starting to send");
+ log_verbose1("Starting to send");
#ifdef HAVE_SSL
if (sock.sock <= 0 && !sock.ssl)
#else
if (sock.sock <= 0)
#endif
- return herror_new ("hsocket_nsend", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_nsend", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
// log_verbose2( "SENDING %s", bytes );
@@ -444,36 +442,36 @@ hsocket_nsend (hsocket_t sock, const byte_t * bytes, int n)
#ifdef HAVE_SSL
if (sock.ssl)
{
- size = SSL_write (sock.ssl, bytes + total, n);
+ size = SSL_write(sock.ssl, bytes + total, n);
}
else
{
#endif
- size = send ((int) sock.sock, bytes + total, n, 0);
+ size = send((int) sock.sock, bytes + total, n, 0);
#ifdef HAVE_SSL
}
#endif
- log_verbose2 ("Sent %d", size);
+ log_verbose2("Sent %d", size);
/* size = _test_send_to_file(filename, bytes, n); */
#ifdef WIN32
if (size == INVALID_SOCKET)
- if (WSAGetLastError () == WSAEWOULDBLOCK)
+ 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)
{
#ifdef HAVE_SSL
if (sock.ssl)
{
- log_error1 ("Send error");
- log_ssl_error (sock.ssl, size);
+ log_error1("Send error");
+ log_ssl_error(sock.ssl, size);
}
#endif
- 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;
@@ -488,17 +486,17 @@ hsocket_nsend (hsocket_t sock, const byte_t * bytes, int n)
FUNCTION: hsocket_send
----------------------------------------------------*/
herror_t
-hsocket_send (hsocket_t sock, const char *str)
+hsocket_send(hsocket_t sock, const char *str)
{
- return hsocket_nsend (sock, str, strlen (str));
+ return hsocket_nsend(sock, str, strlen(str));
}
/*
return: -1 is error. read bytes otherwise
*/
herror_t
-hsocket_read (hsocket_t sock, byte_t * buffer, int total, int force,
- int *received)
+hsocket_read(hsocket_t sock, byte_t * buffer, int total, int force,
+ int *received)
{
int status;
int totalRead;
@@ -517,41 +515,41 @@ hsocket_read (hsocket_t sock, byte_t * buffer, int total, int force,
struct timeval timeout;
int i = 0;
fd_set fds;
- FD_ZERO (&fds);
- FD_SET (sock.sock, &fds);
+ FD_ZERO(&fds);
+ FD_SET(sock.sock, &fds);
timeout.tv_sec = 10;
timeout.tv_usec = 0;
#ifdef WIN32
#else
- fcntl (sock.sock, F_SETFL, O_NONBLOCK);
+ fcntl(sock.sock, F_SETFL, O_NONBLOCK);
#endif
// log_verbose1("START READ LOOP");
// do{
// log_verbose2("DEBUG A %d",i);
- status = SSL_read (sock.ssl, &buffer[totalRead], total - totalRead);
+ status = SSL_read(sock.ssl, &buffer[totalRead], total - totalRead);
if (status < 1)
{
- int ret = select (sock.sock + 1, &fds, NULL, NULL, &timeout);
+ int ret = select(sock.sock + 1, &fds, NULL, NULL, &timeout);
// log_verbose2("DEBUG %d",ret);
#ifdef WIN32
if (ret == SOCKET_ERROR)
{
- wsa_error = WSAGetLastError ();
- log_error2 ("WSAGetLastError()=%d", wsa_error);
- return herror_new ("hsocket_read", HSOCKET_ERROR_RECEIVE,
- "Socket error: %d", errno);
+ wsa_error = WSAGetLastError();
+ log_error2("WSAGetLastError()=%d", wsa_error);
+ return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE,
+ "Socket error: %d", errno);
}
#endif
if (ret == 0)
{
- log_verbose1 ("Socket timeout");
- return herror_new ("hsocket_read", HSOCKET_SSL_CLOSE, "Timeout");
+ log_verbose1("Socket timeout");
+ return herror_new("hsocket_read", HSOCKET_SSL_CLOSE, "Timeout");
}
else
{
// log_verbose1("DEBUG C");
- status = SSL_read (sock.ssl, &buffer[totalRead], total - totalRead);
+ status = SSL_read(sock.ssl, &buffer[totalRead], total - totalRead);
}
// log_verbose3("DEBUG D char: %d status: %d",
// buffer[totalRead], SSL_get_error(sock.ssl, status));
@@ -559,7 +557,7 @@ hsocket_read (hsocket_t sock, byte_t * buffer, int total, int force,
// } while( SSL_get_error(sock.ssl, status) == SSL_ERROR_WANT_READ);
#ifdef WIN32
#else
- fcntl (sock.sock, F_SETFL, 0);
+ fcntl(sock.sock, F_SETFL, 0);
#endif
}
else
@@ -567,21 +565,21 @@ hsocket_read (hsocket_t sock, byte_t * buffer, int total, int force,
#else // HAVE_SSL
{
#endif // HAVE_SSL
- status = recv (sock.sock, &buffer[totalRead], total - totalRead, 0);
+ status = recv(sock.sock, &buffer[totalRead], total - totalRead, 0);
#ifdef WIN32
if (status == INVALID_SOCKET)
{
- wsa_error = WSAGetLastError ();
+ wsa_error = WSAGetLastError();
switch (wsa_error)
{
case WSAEWOULDBLOCK:
/* case WSAEALREADY: case WSAEINPROGRESS: */
continue;
default:
- log_error2 ("WSAGetLastError()=%d", wsa_error);
- return herror_new ("hsocket_read", HSOCKET_ERROR_RECEIVE,
- "Socket error: %d", errno);
+ log_error2("WSAGetLastError()=%d", wsa_error);
+ return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE,
+ "Socket error: %d", errno);
}
}
}
@@ -601,20 +599,20 @@ hsocket_read (hsocket_t sock, byte_t * buffer, int total, int force,
{
// XXX I'm not sure this err_syscall is right here...
- if (SSL_get_shutdown (sock.ssl) == SSL_RECEIVED_SHUTDOWN ||
- SSL_get_error (sock.ssl, status) == SSL_ERROR_SYSCALL)
+ if (SSL_get_shutdown(sock.ssl) == SSL_RECEIVED_SHUTDOWN ||
+ SSL_get_error(sock.ssl, status) == SSL_ERROR_SYSCALL)
{
*received = NULL;;
- return herror_new ("hsocket_read", HSOCKET_SSL_CLOSE, "SSL Closed");
+ return herror_new("hsocket_read", HSOCKET_SSL_CLOSE, "SSL Closed");
}
- log_error2 ("Read error (%d)", status);
- log_ssl_error (sock.ssl, status);
- return herror_new ("hsocket_read", HSOCKET_ERROR_RECEIVE, "SSL Error");
+ log_error2("Read error (%d)", status);
+ log_ssl_error(sock.ssl, status);
+ return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "SSL Error");
}
#endif
if (status == -1)
- return herror_new ("hsocket_read", HSOCKET_ERROR_RECEIVE,
- "Socket error: %d", errno);
+ return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE,
+ "Socket error: %d", errno);
#endif
if (!force)
@@ -643,15 +641,15 @@ hsocket_read (hsocket_t sock, byte_t * buffer, int total, int force,
herror_t
-hsocket_block (hsocket_t sock, int block)
+hsocket_block(hsocket_t sock, int block)
{
#ifdef WIN32
unsigned long iMode;
#endif
if (sock.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
@@ -659,13 +657,13 @@ hsocket_block (hsocket_t sock, int block)
*/
iMode = (block == 0) ? 1 : 0; /* Non block mode */
- if (ioctlsocket (sock.sock, FIONBIO, (u_long FAR *) & iMode) ==
+ if (ioctlsocket(sock.sock, FIONBIO, (u_long FAR *) & iMode) ==
INVALID_SOCKET)
{
- int err = WSAGetLastError ();
- log_error2 ("ioctlsocket error %d", err);
- return herror_new ("hsocket_block", HSOCKET_ERROR_IOCTL,
- "Socket error: %d", err);
+ int err = WSAGetLastError();
+ log_error2("ioctlsocket error %d", err);
+ return herror_new("hsocket_block", HSOCKET_ERROR_IOCTL,
+ "Socket error: %d", err);
}
#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 68f6c5b..b75a637 100644
--- a/nanohttp/nanohttp-socket.h
+++ b/nanohttp/nanohttp-socket.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-socket.h,v 1.19 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: nanohttp-socket.h,v 1.20 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -64,14 +64,14 @@ typedef struct hsocket_t
@returns This function should always return H_OK.
*/
-herror_t hsocket_module_init ();
+herror_t hsocket_module_init();
/**
Destroys the socket modul. This should be called after
finishing an application.
*/
-void hsocket_module_destroy ();
+void hsocket_module_destroy();
/**
@@ -82,7 +82,7 @@ void hsocket_module_destroy ();
@returns This function should always return H_OK.
*/
-herror_t hsocket_init (hsocket_t * sock);
+herror_t hsocket_init(hsocket_t * sock);
/**
@@ -90,7 +90,7 @@ herror_t hsocket_init (hsocket_t * sock);
@param sock the socket to destroy
*/
-void hsocket_free (hsocket_t sock);
+void hsocket_free(hsocket_t sock);
/**
@@ -106,7 +106,7 @@ void hsocket_free (hsocket_t sock);
<BR>HSOCKET_ERROR_GET_HOSTNAME
<BR>HSOCKET_ERROR_CONNECT
*/
-herror_t hsocket_open (hsocket_t * sock, const char *host, int port);
+herror_t hsocket_open(hsocket_t * sock, const char *host, int port);
/**
@@ -114,7 +114,7 @@ herror_t hsocket_open (hsocket_t * sock, const char *host, int port);
@param sock the socket to close
*/
-void hsocket_close (hsocket_t sock);
+void hsocket_close(hsocket_t sock);
/**
@@ -130,7 +130,7 @@ void hsocket_close (hsocket_t sock);
@see hsocket_listen
*/
-herror_t hsocket_bind (hsocket_t * sock, int port);
+herror_t hsocket_bind(hsocket_t * sock, int port);
/**
@@ -144,7 +144,7 @@ herror_t hsocket_bind (hsocket_t * sock, int port);
<BR>HSOCKET_ERROR_NOT_INITIALIZED
<BR>HSOCKET_ERROR_LISTEN
*/
-herror_t hsocket_listen (hsocket_t sock);
+herror_t hsocket_listen(hsocket_t sock);
/**
@@ -158,7 +158,7 @@ herror_t hsocket_listen (hsocket_t sock);
<BR>HSOCKET_ERROR_NOT_INITIALIZED
<BR>HSOCKET_ERROR_ACCEPT
*/
-herror_t hsocket_accept (hsocket_t sock, hsocket_t * dest);
+herror_t hsocket_accept(hsocket_t sock, hsocket_t * dest);
/**
@@ -172,7 +172,7 @@ herror_t hsocket_accept (hsocket_t sock, hsocket_t * dest);
<BR>HSOCKET_ERROR_NOT_INITIALIZED
<BR>HSOCKET_ERROR_SEND
*/
-herror_t hsocket_nsend (hsocket_t sock, const byte_t * bytes, int size);
+herror_t hsocket_nsend(hsocket_t sock, const byte_t * bytes, int size);
/**
@@ -185,7 +185,7 @@ herror_t hsocket_nsend (hsocket_t sock, const byte_t * bytes, int size);
<BR>HSOCKET_ERROR_NOT_INITIALIZED
<BR>HSOCKET_ERROR_SEND
*/
-herror_t hsocket_send (hsocket_t sock, const char *str);
+herror_t hsocket_send(hsocket_t sock, const char *str);
/**
@@ -204,8 +204,8 @@ herror_t hsocket_send (hsocket_t sock, const char *str);
the socket.
*/
-herror_t hsocket_read (hsocket_t sock, byte_t * buffer, int size, int force,
- int *readed);
+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.
@@ -216,7 +216,7 @@ herror_t hsocket_read (hsocket_t sock, byte_t * buffer, int size, int force,
<BR>HSOCKET_ERROR_NOT_INITIALIZED
<BR>HSOCKET_ERROR_IOCTL
*/
-herror_t hsocket_block (hsocket_t sock, int block);
+herror_t hsocket_block(hsocket_t sock, int block);
#endif
diff --git a/nanohttp/nanohttp-ssl.c b/nanohttp/nanohttp-ssl.c
index 38b3595..e1195c7 100644
--- a/nanohttp/nanohttp-ssl.c
+++ b/nanohttp/nanohttp-ssl.c
@@ -70,53 +70,53 @@ static char *pass;
*/
void
-superseed ()
+superseed()
{
int buf[256], i;
- srand (time (NULL));
+ srand(time(NULL));
for (i = 0; i < 256; i++)
{
- buf[i] = rand ();
+ buf[i] = rand();
}
- RAND_seed ((unsigned char *) buf, sizeof (buf));
+ RAND_seed((unsigned char *) buf, sizeof(buf));
}
static int
-pw_cb (char *buf, int num, int rwflag, void *userdata)
+pw_cb(char *buf, int num, int rwflag, void *userdata)
{
- if (num < (int) strlen (pass) + 1)
+ if (num < (int) strlen(pass) + 1)
return (0);
- strcpy (buf, pass);
- return strlen (pass);
+ strcpy(buf, pass);
+ return strlen(pass);
}
int
-verify_sn (X509 * cert, int who, int nid, char *str)
+verify_sn(X509 * cert, int who, int nid, char *str)
{
char name[256];
char buf[256];
- memset (name, '\0', 256);
- memset (buf, '\0', 256);
+ memset(name, '\0', 256);
+ memset(buf, '\0', 256);
if (who == CERT_SUBJECT)
{
- X509_NAME_oneline (X509_get_subject_name (cert), name, 256);
+ X509_NAME_oneline(X509_get_subject_name(cert), name, 256);
}
else
{
- X509_NAME_oneline (X509_get_issuer_name (cert), name, 256);
+ X509_NAME_oneline(X509_get_issuer_name(cert), name, 256);
}
buf[0] = '/';
- strcat (buf, OBJ_nid2sn (nid));
- strcat (buf, "=");
- strcat (buf, str);
+ strcat(buf, OBJ_nid2sn(nid));
+ strcat(buf, "=");
+ strcat(buf, str);
- if (strstr (name, buf))
+ if (strstr(name, buf))
{
return 1;
}
@@ -127,11 +127,11 @@ verify_sn (X509 * cert, int who, int nid, char *str)
}
static int
-verify_cb (int prev_ok, X509_STORE_CTX * ctx)
+verify_cb(int prev_ok, X509_STORE_CTX * ctx)
{
- X509 *cert = X509_STORE_CTX_get_current_cert (ctx);
- int depth = X509_STORE_CTX_get_error_depth (ctx);
- int err = X509_STORE_CTX_get_error (ctx);
+ X509 *cert = X509_STORE_CTX_get_current_cert(ctx);
+ int depth = X509_STORE_CTX_get_error_depth(ctx);
+ int err = X509_STORE_CTX_get_error(ctx);
/*
if( err = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ){
log_verbose1("Self signed cert in chain");
@@ -142,12 +142,12 @@ verify_cb (int prev_ok, X509_STORE_CTX * ctx)
unresolved reference while compiling */
if (depth == 0)
{
- return user_verify (cert);
+ return user_verify(cert);
}
else
{
#endif
- log_verbose1 ("Cert ok (prev)");
+ log_verbose1("Cert ok (prev)");
return prev_ok;
#ifdef NOUSER_VERIFY
}
@@ -156,18 +156,18 @@ verify_cb (int prev_ok, X509_STORE_CTX * ctx)
#ifdef NOUSER_VERIFY
int
-user_verify (X509 * cert)
+user_verify(X509 * cert)
{
// TODO: Make sure that the client is providing a client cert,
// or that the Module is providing the Module cert
/* connect to anyone */
- log_verbose1 ("Validating certificate.");
+ log_verbose1("Validating certificate.");
return 1;
}
#endif
SSL_CTX *
-initialize_ctx (char *keyfile, char *password, char *calist)
+initialize_ctx(char *keyfile, char *password, char *calist)
{
SSL_CTX *ctx = NULL;
@@ -176,139 +176,139 @@ initialize_ctx (char *keyfile, char *password, char *calist)
/* Global system initialization */
- log_verbose1 ("Initializing library");
- SSL_library_init ();
- SSL_load_error_strings ();
- ERR_load_crypto_strings ();
- OpenSSL_add_ssl_algorithms ();
+ log_verbose1("Initializing library");
+ SSL_library_init();
+ SSL_load_error_strings();
+ ERR_load_crypto_strings();
+ OpenSSL_add_ssl_algorithms();
/* Create our context */
- ctx = SSL_CTX_new (SSLv23_method ());
+ ctx = SSL_CTX_new(SSLv23_method());
if (ctx == NULL)
{
- log_error1 ("Cannot create SSL context");
+ log_error1("Cannot create SSL context");
return NULL;
}
- log_verbose1 ("SSL context created ok");
+ log_verbose1("SSL context created ok");
/* Load our keys and certificates */
if (keyfile != NULL && password != NULL)
{
- if (!(SSL_CTX_use_certificate_file (ctx, keyfile, SSL_FILETYPE_PEM)))
+ if (!(SSL_CTX_use_certificate_file(ctx, keyfile, SSL_FILETYPE_PEM)))
{
- log_error2 ("Couldn't read certificate file: %s", keyfile);
- SSL_CTX_free (ctx);
+ log_error2("Couldn't read certificate file: %s", keyfile);
+ SSL_CTX_free(ctx);
return ctx = NULL;
}
- log_verbose1 ("Certificate file read ok");
+ log_verbose1("Certificate file read ok");
pass = password;
- SSL_CTX_set_default_passwd_cb (ctx, pw_cb);
+ SSL_CTX_set_default_passwd_cb(ctx, pw_cb);
- if (!(SSL_CTX_use_PrivateKey_file (ctx, keyfile, SSL_FILETYPE_PEM)))
+ if (!(SSL_CTX_use_PrivateKey_file(ctx, keyfile, SSL_FILETYPE_PEM)))
{
- log_error2 ("Couldn't read key file: %s", keyfile);
- SSL_CTX_free (ctx);
+ log_error2("Couldn't read key file: %s", keyfile);
+ SSL_CTX_free(ctx);
return ctx = NULL;
}
- log_verbose1 ("Keyfile read ok");
+ log_verbose1("Keyfile read ok");
}
if (calist != NULL)
{
/* Load the CAs we trust */
- if (!(SSL_CTX_load_verify_locations (ctx, calist, NULL)))
+ if (!(SSL_CTX_load_verify_locations(ctx, calist, NULL)))
{
- log_error2 ("Couldn't read CA list: %s", calist);
- SSL_CTX_free (ctx);
+ log_error2("Couldn't read CA list: %s", calist);
+ SSL_CTX_free(ctx);
return ctx = NULL;
}
- SSL_CTX_set_client_CA_list (ctx, SSL_load_client_CA_file (calist));
- log_verbose1 ("Certificate Authority contacted");
+ SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(calist));
+ log_verbose1("Certificate Authority contacted");
}
- SSL_CTX_set_verify (ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE,
- verify_cb);
- log_verbose1 ("Verify callback registered");
+ SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE,
+ verify_cb);
+ log_verbose1("Verify callback registered");
- SSL_CTX_set_session_cache_mode (ctx, SSL_SESS_CACHE_OFF);
+ SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
/* Load randomness */
- superseed ();
+ superseed();
return ctx;
}
void
-log_ssl_error (SSL * ssl, int ret)
+log_ssl_error(SSL * ssl, int ret)
{
int errqueue;
char errorbuf[256] = "Error: ";
if (ret == 0)
{
- log_error1 ("SSL handshake was not successful, contolled shutdown");
+ log_error1("SSL handshake was not successful, contolled shutdown");
}
else if (ret == -1)
{
- log_error1 ("SSL handshake was not successful, fatal error at protocol");
+ log_error1("SSL handshake was not successful, fatal error at protocol");
}
- errqueue = SSL_get_error (ssl, ret);
+ errqueue = SSL_get_error(ssl, ret);
switch (errqueue)
{
case SSL_ERROR_NONE:
- strcat (errorbuf, "None");
+ strcat(errorbuf, "None");
break;
case SSL_ERROR_ZERO_RETURN:
- strcat (errorbuf, "Zero return");
+ strcat(errorbuf, "Zero return");
break;
case SSL_ERROR_WANT_READ:
- strcat (errorbuf, "Want read");
+ strcat(errorbuf, "Want read");
break;
case SSL_ERROR_WANT_WRITE:
- strcat (errorbuf, "Want write");
+ strcat(errorbuf, "Want write");
break;
case SSL_ERROR_WANT_X509_LOOKUP:
- strcat (errorbuf, "Want x509 lookup");
+ strcat(errorbuf, "Want x509 lookup");
break;
case SSL_ERROR_SYSCALL:
- strcat (errorbuf, "Syscall:");
+ strcat(errorbuf, "Syscall:");
if (ret == 0)
{
- strcat (errorbuf, "Protocol violation");
+ strcat(errorbuf, "Protocol violation");
}
else if (ret == -1)
{
- strcat (errorbuf, "BIO reported an I/O error");
+ strcat(errorbuf, "BIO reported an I/O error");
}
else
{
- strcat (errorbuf, "Unknown syscall error");
+ strcat(errorbuf, "Unknown syscall error");
} /* if */
break;
case SSL_ERROR_SSL:
- strcat (errorbuf, "SSL library");
- while (errqueue = ERR_get_error ())
+ strcat(errorbuf, "SSL library");
+ while (errqueue = ERR_get_error())
{
- log_error2 ("SSL %s", ERR_error_string (errqueue, NULL));
+ log_error2("SSL %s", ERR_error_string(errqueue, NULL));
}
break;
} /* switch code */
- log_error1 (errorbuf);
+ log_error1(errorbuf);
}
SSL *
-init_ssl (SSL_CTX * ctx, int sock, int type)
+init_ssl(SSL_CTX * ctx, int sock, int type)
{
int ret;
int status;
@@ -322,63 +322,63 @@ init_ssl (SSL_CTX * ctx, int sock, int type)
#endif
#endif
- log_verbose1 ("Starting SSL Initialization");
+ log_verbose1("Starting SSL Initialization");
- ssl = SSL_new (ctx);
+ ssl = SSL_new(ctx);
if (ssl == NULL)
{
- log_error1 ("Cannot create new ssl object");
+ log_error1("Cannot create new ssl object");
return NULL;
}
#if 0
#ifdef WIN32
- log_error1 ("Setting up BIO with socket");
- rbio = BIO_new_socket (sock, BIO_NOCLOSE);
+ log_error1("Setting up BIO with socket");
+ rbio = BIO_new_socket(sock, BIO_NOCLOSE);
if (rbio == NULL)
{
- log_error1 ("BIO_new_socket failed");
+ log_error1("BIO_new_socket failed");
return NULL;
}
- SSL_set_bio (ssl, rbio, rbio);
+ SSL_set_bio(ssl, rbio, rbio);
#else
- sbio = BIO_new_socket (sock, BIO_NOCLOSE);
+ sbio = BIO_new_socket(sock, BIO_NOCLOSE);
if (sbio == NULL)
{
- log_error1 ("BIO_new_socket failed");
+ log_error1("BIO_new_socket failed");
return NULL;
}
- SSL_set_bio (ssl, sbio, sbio);
+ SSL_set_bio(ssl, sbio, sbio);
#endif
#endif
- SSL_set_fd (ssl, sock);
+ SSL_set_fd(ssl, sock);
if (type == SSL_SERVER)
{
hsocket_t sock_t;
sock_t.sock = sock;
- hsocket_block (sock_t, 1);
- ret = SSL_accept (ssl);
- hsocket_block (sock_t, 0);
+ hsocket_block(sock_t, 1);
+ ret = SSL_accept(ssl);
+ hsocket_block(sock_t, 0);
if (ret <= 0)
{
- log_error1 ("SSL accept error");
- log_ssl_error (ssl, ret);
- SSL_free (ssl);
+ log_error1("SSL accept error");
+ log_ssl_error(ssl, ret);
+ SSL_free(ssl);
return ssl = NULL;
} /* if error */
}
else
{ /* client */
- ret = SSL_connect (ssl);
+ ret = SSL_connect(ssl);
if (ret <= 0)
{
- log_error1 ("SSL connect error");
- log_ssl_error (ssl, ret);
- SSL_free (ssl);
+ log_error1("SSL connect error");
+ log_ssl_error(ssl, ret);
+ SSL_free(ssl);
return ssl = NULL;
} /* if error */
/* SSL_connect should take care of this for us.
@@ -388,21 +388,21 @@ init_ssl (SSL_CTX * ctx, int sock, int type)
did not verify"); SSL_free(ssl); return ssl = NULL; } */
}
- log_verbose1 ("Completed SSL Initialization");
+ log_verbose1("Completed SSL Initialization");
return ssl;
}
void
-ssl_cleanup (SSL * ssl)
+ssl_cleanup(SSL * ssl)
{
/* does nothing to context */
if (ssl != NULL)
{
- SSL_shutdown (ssl);
+ SSL_shutdown(ssl);
// SSL_clear(ssl);
- SSL_free (ssl);
+ SSL_free(ssl);
ssl = NULL;
}
}
diff --git a/nanohttp/nanohttp-ssl.h b/nanohttp/nanohttp-ssl.h
index 449c78c..f4ec7ef 100644
--- a/nanohttp/nanohttp-ssl.h
+++ b/nanohttp/nanohttp-ssl.h
@@ -63,7 +63,7 @@ typedef struct Con
* Initialize the context
*/
-SSL_CTX *initialize_ctx (char *keyfile, char *password, char *calist);
+SSL_CTX *initialize_ctx(char *keyfile, char *password, char *calist);
/*
* Quick function for verifying a portion of the cert
@@ -71,7 +71,7 @@ SSL_CTX *initialize_ctx (char *keyfile, char *password, char *calist);
* returns non-zero if everything went ok
*/
-int verify_sn (X509 * cert, int who, int nid, char *str);
+int verify_sn(X509 * cert, int who, int nid, char *str);
/*
* Called by framework for verify
@@ -83,20 +83,20 @@ int verify_sn (X509 * cert, int who, int nid, char *str);
* This function MUST be implemented by user client/server code somewhere
*/
-int user_verify (X509 * cert);
+int user_verify(X509 * cert);
/*
* Create the ssl socket and return it
* pass in the context and an open socket
*/
-SSL *init_ssl (SSL_CTX * ctx, int sock, int type);
+SSL *init_ssl(SSL_CTX * ctx, int sock, int type);
/*
* Close the ssl connection (socket is still left open)
*/
-void ssl_cleanup ();
+void ssl_cleanup();
#endif
diff --git a/nanohttp/nanohttp-stream.c b/nanohttp/nanohttp-stream.c
index 7700867..c8ba216 100755
--- a/nanohttp/nanohttp-stream.c
+++ b/nanohttp/nanohttp-stream.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-stream.c,v 1.8 2006/01/10 11:21:55 snowdrop Exp $
+* $Id: nanohttp-stream.c,v 1.9 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -30,7 +30,7 @@
#include <utils/alloc.h>
#endif
void
-_log_str (char *fn, char *str, int size)
+_log_str(char *fn, char *str, int size)
{
/* FILE *f = fopen(fn, "ab");
if (!f) f=fopen(fn,"wb");
@@ -49,19 +49,19 @@ HTTP INPUT STREAM
*/
static int
-_http_stream_is_content_length (hpair_t * header)
+_http_stream_is_content_length(hpair_t * header)
{
- return hpairnode_get_ignore_case (header, HEADER_CONTENT_LENGTH) != NULL;
+ return hpairnode_get_ignore_case(header, HEADER_CONTENT_LENGTH) != NULL;
}
static int
-_http_stream_is_chunked (hpair_t * header)
+_http_stream_is_chunked(hpair_t * header)
{
char *chunked;
- chunked = hpairnode_get_ignore_case (header, HEADER_TRANSFER_ENCODING);
+ chunked = hpairnode_get_ignore_case(header, HEADER_TRANSFER_ENCODING);
if (chunked != NULL)
{
- if (!strcmp (chunked, TRANSFER_ENCODING_CHUNKED))
+ if (!strcmp(chunked, TRANSFER_ENCODING_CHUNKED))
{
return 1;
}
@@ -74,7 +74,7 @@ _http_stream_is_chunked (hpair_t * header)
Creates a new input stream.
*/
http_input_stream_t *
-http_input_stream_new (hsocket_t sock, hpair_t * header)
+http_input_stream_new(hsocket_t sock, hpair_t * header)
{
http_input_stream_t *result;
char *content_length;
@@ -82,26 +82,25 @@ http_input_stream_new (hsocket_t sock, hpair_t * header)
/* Paranoya check */
/* if (header == NULL) return NULL; */
/* Create object */
- result = (http_input_stream_t *) malloc (sizeof (http_input_stream_t));
+ result = (http_input_stream_t *) malloc(sizeof(http_input_stream_t));
result->sock = sock;
result->err = H_OK;
/* Find connection type */
- hpairnode_dump_deep (header);
+ hpairnode_dump_deep(header);
/* Check if Content-type */
- if (_http_stream_is_content_length (header))
+ if (_http_stream_is_content_length(header))
{
- log_verbose1 ("Stream transfer with 'Content-length'");
- content_length =
- hpairnode_get_ignore_case (header, HEADER_CONTENT_LENGTH);
- result->content_length = atoi (content_length);
+ log_verbose1("Stream transfer with 'Content-length'");
+ content_length = hpairnode_get_ignore_case(header, HEADER_CONTENT_LENGTH);
+ result->content_length = atoi(content_length);
result->received = 0;
result->type = HTTP_TRANSFER_CONTENT_LENGTH;
}
/* Check if Chunked */
- else if (_http_stream_is_chunked (header))
+ else if (_http_stream_is_chunked(header))
{
- log_verbose1 ("Stream transfer with 'chunked'");
+ log_verbose1("Stream transfer with 'chunked'");
result->type = HTTP_TRANSFER_CHUNKED;
result->chunk_size = -1;
result->received = -1;
@@ -109,7 +108,7 @@ http_input_stream_new (hsocket_t sock, hpair_t * header)
/* Assume connection close */
else
{
- log_verbose1 ("Stream transfer with 'Connection: close'");
+ log_verbose1("Stream transfer with 'Connection: close'");
result->type = HTTP_TRANSFER_CONNECTION_CLOSE;
result->connection_closed = 0;
result->received = 0;
@@ -123,20 +122,20 @@ http_input_stream_new (hsocket_t sock, hpair_t * header)
and for debugging.
*/
http_input_stream_t *
-http_input_stream_new_from_file (const char *filename)
+http_input_stream_new_from_file(const char *filename)
{
http_input_stream_t *result;
- FILE *fd = fopen (filename, "rb");
+ FILE *fd = fopen(filename, "rb");
if (fd == NULL)
return NULL;
/* Create object */
- result = (http_input_stream_t *) malloc (sizeof (http_input_stream_t));
+ result = (http_input_stream_t *) malloc(sizeof(http_input_stream_t));
result->type = HTTP_TRANSFER_FILE;
result->fd = fd;
result->deleteOnExit = 0;
- strcpy (result->filename, filename);
+ strcpy(result->filename, filename);
return result;
}
@@ -144,47 +143,47 @@ http_input_stream_new_from_file (const char *filename)
Free input stream
*/
void
-http_input_stream_free (http_input_stream_t * stream)
+http_input_stream_free(http_input_stream_t * stream)
{
if (stream->type == HTTP_TRANSFER_FILE && stream->fd)
{
- fclose (stream->fd);
+ fclose(stream->fd);
if (stream->deleteOnExit)
- log_info2 ("Removing '%s'", stream->filename);
+ log_info2("Removing '%s'", stream->filename);
/* remove(stream->filename); */
}
- free (stream);
+ free(stream);
}
static int
-_http_input_stream_is_content_length_ready (http_input_stream_t * stream)
+_http_input_stream_is_content_length_ready(http_input_stream_t * stream)
{
return (stream->content_length > stream->received);
}
static int
-_http_input_stream_is_chunked_ready (http_input_stream_t * stream)
+_http_input_stream_is_chunked_ready(http_input_stream_t * stream)
{
return stream->chunk_size != 0;
}
static int
-_http_input_stream_is_connection_closed_ready (http_input_stream_t * stream)
+_http_input_stream_is_connection_closed_ready(http_input_stream_t * stream)
{
return !stream->connection_closed;
}
static int
-_http_input_stream_is_file_ready (http_input_stream_t * stream)
+_http_input_stream_is_file_ready(http_input_stream_t * stream)
{
- return !feof (stream->fd);
+ return !feof(stream->fd);
}
static int
-_http_input_stream_content_length_read (http_input_stream_t * stream,
- byte_t * dest, int size)
+_http_input_stream_content_length_read(http_input_stream_t * stream,
+ byte_t * dest, int size)
{
herror_t status;
int read;
@@ -194,7 +193,7 @@ _http_input_stream_content_length_read (http_input_stream_t * stream,
size = stream->content_length - stream->received;
/* read from socket */
- status = hsocket_read (stream->sock, dest, size, 1, &read);
+ status = hsocket_read(stream->sock, dest, size, 1, &read);
if (status != H_OK)
{
stream->err = status;
@@ -206,7 +205,7 @@ _http_input_stream_content_length_read (http_input_stream_t * stream,
}
static int
-_http_input_stream_chunked_read_chunk_size (http_input_stream_t * stream)
+_http_input_stream_chunked_read_chunk_size(http_input_stream_t * stream)
{
char chunk[25];
int status, i = 0;
@@ -215,19 +214,19 @@ _http_input_stream_chunked_read_chunk_size (http_input_stream_t * stream)
while (1)
{
- err = hsocket_read (stream->sock, &(chunk[i]), 1, 1, &status);
+ 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!");
+ 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));
+ log_error4("[%d] %s(): %s ", herror_code(err), herror_func(err),
+ herror_message(err));
stream->err = err;
return -1;
@@ -240,7 +239,7 @@ _http_input_stream_chunked_read_chunk_size (http_input_stream_t * stream)
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); */
return chunk_size;
@@ -249,8 +248,8 @@ _http_input_stream_chunked_read_chunk_size (http_input_stream_t * stream)
if (i == 24)
{
stream->err =
- herror_new ("_http_input_stream_chunked_read_chunk_size",
- STREAM_ERROR_NO_CHUNK_SIZE, "reached max line == %d", i);
+ herror_new("_http_input_stream_chunked_read_chunk_size",
+ STREAM_ERROR_NO_CHUNK_SIZE, "reached max line == %d", i);
return -1;
}
else
@@ -259,14 +258,14 @@ _http_input_stream_chunked_read_chunk_size (http_input_stream_t * stream)
/* 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);
+ herror_new("_http_input_stream_chunked_read_chunk_size",
+ STREAM_ERROR_NO_CHUNK_SIZE, "reached max line == %d", i);
return -1;
}
static int
-_http_input_stream_chunked_read (http_input_stream_t * stream, byte_t * dest,
- int size)
+_http_input_stream_chunked_read(http_input_stream_t * stream, byte_t * dest,
+ int size)
{
int status, counter;
int remain, read = 0;
@@ -284,7 +283,7 @@ _http_input_stream_chunked_read (http_input_stream_t * stream, byte_t * dest,
counter = 100; /* maximum for stop infinity */
while (1)
{
- err = hsocket_read (stream->sock, &ch, 1, 1, &status);
+ err = hsocket_read(stream->sock, &ch, 1, 1, &status);
if (err != H_OK)
{
@@ -298,9 +297,9 @@ _http_input_stream_chunked_read (http_input_stream_t * stream, byte_t * dest,
}
if (counter-- == 0)
{
- stream->err = herror_new ("_http_input_stream_chunked_read",
- STREAM_ERROR_WRONG_CHUNK_SIZE,
- "Wrong chunk-size");
+ stream->err = herror_new("_http_input_stream_chunked_read",
+ STREAM_ERROR_WRONG_CHUNK_SIZE,
+ "Wrong chunk-size");
return -1;
}
}
@@ -309,8 +308,7 @@ _http_input_stream_chunked_read (http_input_stream_t * stream, byte_t * dest,
if (remain == 0)
{
/* receive new chunk size */
- stream->chunk_size =
- _http_input_stream_chunked_read_chunk_size (stream);
+ stream->chunk_size = _http_input_stream_chunked_read_chunk_size(stream);
stream->received = 0;
if (stream->chunk_size < 0)
@@ -329,7 +327,7 @@ _http_input_stream_chunked_read (http_input_stream_t * stream, byte_t * dest,
if (remain < size)
{
/* read from socket */
- err = hsocket_read (stream->sock, &(dest[read]), remain, 1, &status);
+ err = hsocket_read(stream->sock, &(dest[read]), remain, 1, &status);
if (err != H_OK)
{
stream->err = err;
@@ -337,23 +335,23 @@ _http_input_stream_chunked_read (http_input_stream_t * stream, byte_t * dest,
}
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);
+ 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);
+ 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);
+ 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)
@@ -373,14 +371,14 @@ _http_input_stream_chunked_read (http_input_stream_t * stream, byte_t * dest,
static int
-_http_input_stream_connection_closed_read (http_input_stream_t * stream,
- byte_t * dest, int size)
+_http_input_stream_connection_closed_read(http_input_stream_t * stream,
+ byte_t * dest, int size)
{
int status;
herror_t err;
/* read from socket */
- err = hsocket_read (stream->sock, dest, size, 0, &status);
+ err = hsocket_read(stream->sock, dest, size, 0, &status);
if (err != H_OK)
{
stream->err = err;
@@ -391,21 +389,21 @@ _http_input_stream_connection_closed_read (http_input_stream_t * stream,
stream->connection_closed = 1;
stream->received += status;
- _log_str ("stream.in", dest, size);
+ _log_str("stream.in", dest, size);
return status;
}
static int
-_http_input_stream_file_read (http_input_stream_t * stream, byte_t * dest,
- int size)
+_http_input_stream_file_read(http_input_stream_t * stream, byte_t * dest,
+ int size)
{
int readed;
- readed = fread (dest, 1, size, stream->fd);
+ readed = fread(dest, 1, size, stream->fd);
if (readed == -1)
{
- stream->err = herror_new ("_http_input_stream_file_read",
- HSOCKET_ERROR_RECEIVE, "fread() returned -1");
+ stream->err = herror_new("_http_input_stream_file_read",
+ HSOCKET_ERROR_RECEIVE, "fread() returned -1");
return -1;
}
@@ -416,7 +414,7 @@ _http_input_stream_file_read (http_input_stream_t * stream, byte_t * dest,
Returns the actual status of the stream.
*/
int
-http_input_stream_is_ready (http_input_stream_t * stream)
+http_input_stream_is_ready(http_input_stream_t * stream)
{
/* paranoya check */
if (stream == NULL)
@@ -428,13 +426,13 @@ http_input_stream_is_ready (http_input_stream_t * stream)
switch (stream->type)
{
case HTTP_TRANSFER_CONTENT_LENGTH:
- return _http_input_stream_is_content_length_ready (stream);
+ return _http_input_stream_is_content_length_ready(stream);
case HTTP_TRANSFER_CHUNKED:
- return _http_input_stream_is_chunked_ready (stream);
+ return _http_input_stream_is_chunked_ready(stream);
case HTTP_TRANSFER_CONNECTION_CLOSE:
- return _http_input_stream_is_connection_closed_ready (stream);
+ return _http_input_stream_is_connection_closed_ready(stream);
case HTTP_TRANSFER_FILE:
- return _http_input_stream_is_file_ready (stream);
+ return _http_input_stream_is_file_ready(stream);
default:
return 0;
}
@@ -446,7 +444,7 @@ http_input_stream_is_ready (http_input_stream_t * stream)
<0 on error
*/
int
-http_input_stream_read (http_input_stream_t * stream, byte_t * dest, int size)
+http_input_stream_read(http_input_stream_t * stream, byte_t * dest, int size)
{
int readed = 0;
/* paranoya check */
@@ -461,21 +459,21 @@ http_input_stream_read (http_input_stream_t * stream, byte_t * dest, int size)
switch (stream->type)
{
case HTTP_TRANSFER_CONTENT_LENGTH:
- readed = _http_input_stream_content_length_read (stream, dest, size);
+ readed = _http_input_stream_content_length_read(stream, dest, size);
break;
case HTTP_TRANSFER_CHUNKED:
- readed = _http_input_stream_chunked_read (stream, dest, size);
+ readed = _http_input_stream_chunked_read(stream, dest, size);
break;
case HTTP_TRANSFER_CONNECTION_CLOSE:
- readed = _http_input_stream_connection_closed_read (stream, dest, size);
+ readed = _http_input_stream_connection_closed_read(stream, dest, size);
break;
case HTTP_TRANSFER_FILE:
- readed = _http_input_stream_file_read (stream, dest, size);
+ readed = _http_input_stream_file_read(stream, dest, size);
break;
default:
- stream->err = herror_new ("http_input_stream_read",
- STREAM_ERROR_INVALID_TYPE,
- "%d is invalid stream type", stream->type);
+ stream->err = herror_new("http_input_stream_read",
+ STREAM_ERROR_INVALID_TYPE,
+ "%d is invalid stream type", stream->type);
return -1;
}
@@ -497,7 +495,7 @@ HTTP OUTPUT STREAM
Creates a new output stream. Transfer code will be found from header.
*/
http_output_stream_t *
-http_output_stream_new (hsocket_t sock, hpair_t * header)
+http_output_stream_new(hsocket_t sock, hpair_t * header)
{
http_output_stream_t *result;
char *content_length;
@@ -507,31 +505,30 @@ http_output_stream_new (hsocket_t sock, hpair_t * header)
return NULL;
*/
/* Create object */
- result = (http_output_stream_t *) malloc (sizeof (http_output_stream_t));
+ result = (http_output_stream_t *) malloc(sizeof(http_output_stream_t));
result->sock = sock;
result->sent = 0;
/* Find connection type */
/* Check if Content-type */
- if (_http_stream_is_content_length (header))
+ if (_http_stream_is_content_length(header))
{
- log_verbose1 ("Stream transfer with 'Content-length'");
- content_length =
- hpairnode_get_ignore_case (header, HEADER_CONTENT_LENGTH);
- result->content_length = atoi (content_length);
+ log_verbose1("Stream transfer with 'Content-length'");
+ content_length = hpairnode_get_ignore_case(header, HEADER_CONTENT_LENGTH);
+ result->content_length = atoi(content_length);
result->type = HTTP_TRANSFER_CONTENT_LENGTH;
}
/* Check if Chunked */
- else if (_http_stream_is_chunked (header))
+ else if (_http_stream_is_chunked(header))
{
- log_verbose1 ("Stream transfer with 'chunked'");
+ log_verbose1("Stream transfer with 'chunked'");
result->type = HTTP_TRANSFER_CHUNKED;
}
/* Assume connection close */
else
{
- log_verbose1 ("Stream transfer with 'Connection: close'");
+ log_verbose1("Stream transfer with 'Connection: close'");
result->type = HTTP_TRANSFER_CONNECTION_CLOSE;
}
@@ -542,9 +539,9 @@ http_output_stream_new (hsocket_t sock, hpair_t * header)
Free output stream
*/
void
-http_output_stream_free (http_output_stream_t * stream)
+http_output_stream_free(http_output_stream_t * stream)
{
- free (stream);
+ free(stream);
}
/**
@@ -552,31 +549,31 @@ http_output_stream_free (http_output_stream_t * stream)
Returns socket error flags or H_OK.
*/
herror_t
-http_output_stream_write (http_output_stream_t * stream,
- const byte_t * bytes, int size)
+http_output_stream_write(http_output_stream_t * stream,
+ const byte_t * bytes, int size)
{
herror_t status;
char chunked[15];
if (stream->type == HTTP_TRANSFER_CHUNKED)
{
- sprintf (chunked, "%x\r\n", size);
- status = hsocket_send (stream->sock, chunked);
+ sprintf(chunked, "%x\r\n", size);
+ status = hsocket_send(stream->sock, chunked);
if (status != H_OK)
return status;
}
if (size > 0)
{
- _log_str ("stream.out", (char *) bytes, size);
- status = hsocket_nsend (stream->sock, bytes, size);
+ _log_str("stream.out", (char *) bytes, size);
+ status = hsocket_nsend(stream->sock, bytes, size);
if (status != H_OK)
return status;
}
if (stream->type == HTTP_TRANSFER_CHUNKED)
{
- status = hsocket_send (stream->sock, "\r\n");
+ status = hsocket_send(stream->sock, "\r\n");
if (status != H_OK)
return status;
}
@@ -589,21 +586,21 @@ http_output_stream_write (http_output_stream_t * stream,
Returns socket error flags or H_OK.
*/
herror_t
-http_output_stream_write_string (http_output_stream_t * stream,
- const char *str)
+http_output_stream_write_string(http_output_stream_t * stream,
+ const char *str)
{
- return http_output_stream_write (stream, str, strlen (str));
+ return http_output_stream_write(stream, str, strlen(str));
}
herror_t
-http_output_stream_flush (http_output_stream_t * stream)
+http_output_stream_flush(http_output_stream_t * stream)
{
herror_t status;
if (stream->type == HTTP_TRANSFER_CHUNKED)
{
- status = hsocket_send (stream->sock, "0\r\n\r\n");
+ status = hsocket_send(stream->sock, "0\r\n\r\n");
if (status != H_OK)
return status;
}
diff --git a/nanohttp/nanohttp-stream.h b/nanohttp/nanohttp-stream.h
index 2ef12a2..20ced17 100755
--- a/nanohttp/nanohttp-stream.h
+++ b/nanohttp/nanohttp-stream.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-stream.h,v 1.6 2006/01/10 11:21:55 snowdrop Exp $
+ * $Id: nanohttp-stream.h,v 1.7 2006/01/10 11:29:05 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -25,7 +25,7 @@
#define NANO_HTTP_STREAM_H
#include <stdio.h>
-void _log_str (char *fn, char *str, int size);
+void _log_str(char *fn, char *str, int size);
/*
HTTP Stream modul:
@@ -134,7 +134,7 @@ typedef struct http_output_stream
@see http_input_stream_free
*/
-http_input_stream_t *http_input_stream_new (hsocket_t sock, hpair_t * header);
+http_input_stream_t *http_input_stream_new(hsocket_t sock, hpair_t * header);
/**
@@ -150,7 +150,7 @@ http_input_stream_t *http_input_stream_new (hsocket_t sock, hpair_t * header);
@see http_input_stream_free
*/
-http_input_stream_t *http_input_stream_new_from_file (const char *filename);
+http_input_stream_t *http_input_stream_new_from_file(const char *filename);
/**
@@ -159,7 +159,7 @@ http_input_stream_t *http_input_stream_new_from_file (const char *filename);
@param stream the input stream to free.
*/
-void http_input_stream_free (http_input_stream_t * stream);
+void http_input_stream_free(http_input_stream_t * stream);
/**
@@ -169,7 +169,7 @@ void http_input_stream_free (http_input_stream_t * stream);
@returns <br>1 if there are still data to read.
<br>0 if no more data exists.
*/
-int http_input_stream_is_ready (http_input_stream_t * stream);
+int http_input_stream_is_ready(http_input_stream_t * stream);
/**
@@ -193,8 +193,8 @@ int http_input_stream_is_ready (http_input_stream_t * stream);
@returns the actual readed bytes or -1 on error.
*/
-int http_input_stream_read (http_input_stream_t * stream,
- byte_t * dest, int size);
+int http_input_stream_read(http_input_stream_t * stream,
+ byte_t * dest, int size);
/*
@@ -216,8 +216,8 @@ int http_input_stream_read (http_input_stream_t * stream,
@see http_output_stream_free
*/
-http_output_stream_t *http_output_stream_new (hsocket_t sock,
- hpair_t * header);
+http_output_stream_t *http_output_stream_new(hsocket_t sock,
+ hpair_t * header);
/**
@@ -226,7 +226,7 @@ http_output_stream_t *http_output_stream_new (hsocket_t sock,
@param stream the stream to free.
*/
-void http_output_stream_free (http_output_stream_t * stream);
+void http_output_stream_free(http_output_stream_t * stream);
/**
@@ -240,8 +240,8 @@ void http_output_stream_free (http_output_stream_t * stream);
<BR>HSOCKET_ERROR_NOT_INITIALIZED
<BR>HSOCKET_ERROR_SEND
*/
-herror_t http_output_stream_write (http_output_stream_t * stream,
- const byte_t * bytes, int size);
+herror_t http_output_stream_write(http_output_stream_t * stream,
+ const byte_t * bytes, int size);
/**
Writes a null terminated string to the stream.
@@ -253,8 +253,8 @@ herror_t http_output_stream_write (http_output_stream_t * stream,
<BR>HSOCKET_ERROR_NOT_INITIALIZED
<BR>HSOCKET_ERROR_SEND
*/
-herror_t http_output_stream_write_string (http_output_stream_t * stream,
- const char *str);
+herror_t http_output_stream_write_string(http_output_stream_t * stream,
+ const char *str);
/**
@@ -267,6 +267,6 @@ herror_t http_output_stream_write_string (http_output_stream_t * stream,
<BR>HSOCKET_ERROR_NOT_INITIALIZED
<BR>HSOCKET_ERROR_SEND
*/
-herror_t http_output_stream_flush (http_output_stream_t * stream);
+herror_t http_output_stream_flush(http_output_stream_t * stream);
#endif