summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar snowdrop2004-11-02 23:09:19 +0000
committerGravatar snowdrop2004-11-02 23:09:19 +0000
commit402e8748593a42cf6d42fda772f207e3e9300a3e (patch)
tree8c87ecde3498891a6de178f2a77dc4d9cf20fe57
parent15b392f1e21d3dae8f83da401199959e9f0b0db6 (diff)
downloadcsoap-402e8748593a42cf6d42fda772f207e3e9300a3e.tar.gz
csoap-402e8748593a42cf6d42fda772f207e3e9300a3e.tar.bz2
dos2unix
-rwxr-xr-xexamples/csoap/echoattachments-client.c366
-rwxr-xr-xexamples/csoap/echoattachments-server.c170
-rw-r--r--examples/csoap/simpleclient.c48
-rw-r--r--examples/csoap/simpleserver.c170
-rw-r--r--libcsoap/soap-client.c116
-rw-r--r--libcsoap/soap-client.h146
-rwxr-xr-xlibcsoap/soap-ctx.c270
-rwxr-xr-xlibcsoap/soap-ctx.h142
-rw-r--r--libcsoap/soap-env.c212
-rw-r--r--libcsoap/soap-env.h28
-rw-r--r--libcsoap/soap-server.c94
-rw-r--r--libcsoap/soap-server.h8
-rw-r--r--nanohttp/nanohttp-client.c88
-rw-r--r--nanohttp/nanohttp-client.h320
-rw-r--r--nanohttp/nanohttp-common.c342
-rw-r--r--nanohttp/nanohttp-common.h136
-rwxr-xr-xnanohttp/nanohttp-mime.c70
-rwxr-xr-xnanohttp/nanohttp-mime.h6
-rwxr-xr-xnanohttp/nanohttp-request.c6
-rwxr-xr-xnanohttp/nanohttp-response.c32
-rw-r--r--nanohttp/nanohttp-server.c56
-rw-r--r--nanohttp/nanohttp-server.h4
-rw-r--r--nanohttp/nanohttp-socket.c116
-rw-r--r--nanohttp/nanohttp-socket.h432
-rwxr-xr-xnanohttp/nanohttp-stream.c88
-rwxr-xr-xnanohttp/nanohttp-stream.h10
26 files changed, 1738 insertions, 1738 deletions
diff --git a/examples/csoap/echoattachments-client.c b/examples/csoap/echoattachments-client.c
index 0f57b6b..0d8e9dc 100755
--- a/examples/csoap/echoattachments-client.c
+++ b/examples/csoap/echoattachments-client.c
@@ -1,183 +1,183 @@
-/******************************************************************
- * $Id: echoattachments-client.c,v 1.7 2004/11/02 22:42:52 snowdrop Exp $
- *
- * CSOAP Project: CSOAP examples project
- * Copyright (C) 2003-2004 Ferhat Ayaz
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
- *
- * Email: ferhatayaz@yahoo.com
- ******************************************************************/
-
-#include <libcsoap/soap-client.h>
-
-
-
-
-static const char *urn = "urn:examples";
-static const char *url = "http://localhost:10000/echoattachments";
-static const char *method = "echo";
-
-
-void 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");
- if (!f1) {
- fprintf(stderr, "Can not open '%s'\n", received);
- return;
- }
-
- 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);
- return;
- }
-
- fseek(f1, 0, SEEK_END);
- fseek(f2, 0, SEEK_END);
-
- s1 = ftell(f1);
- s2 = ftell(f2);
-
- 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);
- return;
-
- } else if (s2 > s1) {
-
- printf("ERROR: files are not equal! Sent file is bigger\n");
- fclose(f1); fclose(f2);
- return;
- }
-
- while (feof(f1)) {
-
- c1= fgetc(f1);
- c2= fgetc(f2);
- if (c1 != c2){
- 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);
-
-}
-
-int main(int argc, char *argv[])
-{
- SoapCtx *ctx, *ctx2;
- char href[MAX_HREF_SIZE];
- xmlNodePtr fault;
- herror_t err;
-
-
- if (argc < 2) {
- fprintf(stderr, "usage: %s <filename> [url]\n", argv[0]);
- exit(1);
- }
-
- /*
- Initialize soap client
- */
- 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);
- return 1;
- }
-
- /*
- Create a context object
- */
- 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);
- return 1;
- }
-
- /*
- Add file to the context
- */
- 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);
- return 1;
- }
-
- /*
- Add file reference to the envelope
- */
- soap_env_add_attachment(ctx->env,"source", href);
-
- /*
- Send soap request to the server
- */
- printf("sending request ...\n");
- if (argc > 2)
- err = soap_client_invoke(ctx, &ctx2, argv[2], "");
- else
- 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);
- return 1;
- }
-
- /*
- Handle response (just print to the screen)
- */
- fault = soap_env_get_fault(ctx2->env);
- if (fault) {
- soap_xml_doc_print(ctx2->env->root->doc);
- } else if (ctx2->attachments) {
- compareFiles(ctx2->attachments->parts->filename, argv[1]);
- } else {
- printf("No attachments!");
- soap_xml_doc_print(ctx2->env->root->doc);
- }
-
- /*
- Clean up
- */
- soap_ctx_free(ctx2);
- soap_ctx_free(ctx);
-
- soap_client_destroy();
-
- return 0;
-}
-
-
-
-
-
+/******************************************************************
+ * $Id: echoattachments-client.c,v 1.8 2004/11/02 23:09:19 snowdrop Exp $
+ *
+ * CSOAP Project: CSOAP examples project
+ * Copyright (C) 2003-2004 Ferhat Ayaz
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
+ *
+ * Email: ferhatayaz@yahoo.com
+ ******************************************************************/
+
+#include <libcsoap/soap-client.h>
+
+
+
+
+static const char *urn = "urn:examples";
+static const char *url = "http://localhost:10000/echoattachments";
+static const char *method = "echo";
+
+
+void 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");
+ if (!f1) {
+ fprintf(stderr, "Can not open '%s'\n", received);
+ return;
+ }
+
+ 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);
+ return;
+ }
+
+ fseek(f1, 0, SEEK_END);
+ fseek(f2, 0, SEEK_END);
+
+ s1 = ftell(f1);
+ s2 = ftell(f2);
+
+ 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);
+ return;
+
+ } else if (s2 > s1) {
+
+ printf("ERROR: files are not equal! Sent file is bigger\n");
+ fclose(f1); fclose(f2);
+ return;
+ }
+
+ while (feof(f1)) {
+
+ c1= fgetc(f1);
+ c2= fgetc(f2);
+ if (c1 != c2){
+ 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);
+
+}
+
+int main(int argc, char *argv[])
+{
+ SoapCtx *ctx, *ctx2;
+ char href[MAX_HREF_SIZE];
+ xmlNodePtr fault;
+ herror_t err;
+
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <filename> [url]\n", argv[0]);
+ exit(1);
+ }
+
+ /*
+ Initialize soap client
+ */
+ 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);
+ return 1;
+ }
+
+ /*
+ Create a context object
+ */
+ 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);
+ return 1;
+ }
+
+ /*
+ Add file to the context
+ */
+ 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);
+ return 1;
+ }
+
+ /*
+ Add file reference to the envelope
+ */
+ soap_env_add_attachment(ctx->env,"source", href);
+
+ /*
+ Send soap request to the server
+ */
+ printf("sending request ...\n");
+ if (argc > 2)
+ err = soap_client_invoke(ctx, &ctx2, argv[2], "");
+ else
+ 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);
+ return 1;
+ }
+
+ /*
+ Handle response (just print to the screen)
+ */
+ fault = soap_env_get_fault(ctx2->env);
+ if (fault) {
+ soap_xml_doc_print(ctx2->env->root->doc);
+ } else if (ctx2->attachments) {
+ compareFiles(ctx2->attachments->parts->filename, argv[1]);
+ } else {
+ printf("No attachments!");
+ soap_xml_doc_print(ctx2->env->root->doc);
+ }
+
+ /*
+ Clean up
+ */
+ soap_ctx_free(ctx2);
+ soap_ctx_free(ctx);
+
+ soap_client_destroy();
+
+ return 0;
+}
+
+
+
+
+
diff --git a/examples/csoap/echoattachments-server.c b/examples/csoap/echoattachments-server.c
index 22b5fb2..01299b4 100755
--- a/examples/csoap/echoattachments-server.c
+++ b/examples/csoap/echoattachments-server.c
@@ -1,85 +1,85 @@
-/******************************************************************
- * $Id: echoattachments-server.c,v 1.4 2004/11/01 15:16:22 snowdrop Exp $
- *
- * CSOAP Project: CSOAP examples project
- * Copyright (C) 2003-2004 Ferhat Ayaz
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
- *
- * Email: ferhatayaz@yahoo.com
- ******************************************************************/
-
-#include <libcsoap/soap-server.h>
-
-
-static const char *url = "/echoattachments";
-static const char *urn = "urn:examples";
-static const char *method = "echo";
-
-
-
-
-herror_t 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);
- if (err != H_OK) {
- return err;
- }
-
- if (req->attachments)
- {
- 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);
- }
- }
-
- return H_OK;
-}
-
-
-int main(int argc, char *argv[])
-{
- herror_t err;
- SoapRouter *router;
-
- log_set_level(HLOG_VERBOSE);
-
- 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);
- return 1;
- }
-
- 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("shutting down\n");
- soap_server_destroy();
-
- return 0;
-}
-
+/******************************************************************
+ * $Id: echoattachments-server.c,v 1.5 2004/11/02 23:09:19 snowdrop Exp $
+ *
+ * CSOAP Project: CSOAP examples project
+ * Copyright (C) 2003-2004 Ferhat Ayaz
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
+ *
+ * Email: ferhatayaz@yahoo.com
+ ******************************************************************/
+
+#include <libcsoap/soap-server.h>
+
+
+static const char *url = "/echoattachments";
+static const char *urn = "urn:examples";
+static const char *method = "echo";
+
+
+
+
+herror_t 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);
+ if (err != H_OK) {
+ return err;
+ }
+
+ if (req->attachments)
+ {
+ 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);
+ }
+ }
+
+ return H_OK;
+}
+
+
+int main(int argc, char *argv[])
+{
+ herror_t err;
+ SoapRouter *router;
+
+ log_set_level(HLOG_VERBOSE);
+
+ 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);
+ return 1;
+ }
+
+ 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("shutting down\n");
+ soap_server_destroy();
+
+ return 0;
+}
+
diff --git a/examples/csoap/simpleclient.c b/examples/csoap/simpleclient.c
index 8c10d5f..29c4c1e 100644
--- a/examples/csoap/simpleclient.c
+++ b/examples/csoap/simpleclient.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: simpleclient.c,v 1.8 2004/11/02 22:42:52 snowdrop Exp $
+ * $Id: simpleclient.c,v 1.9 2004/11/02 23:09:19 snowdrop Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -31,23 +31,23 @@ static const char *method = "sayHello";
int main(int argc, char *argv[])
{
- SoapCtx *ctx, *ctx2;
+ SoapCtx *ctx, *ctx2;
herror_t err;
- /*log_set_level(HLOG_VERBOSE);*/
+ /*log_set_level(HLOG_VERBOSE);*/
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);
- return 1;
- }
+ if (err != H_OK) {
+ 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);
- if (err != H_OK) {
- 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);
+ if (err != H_OK) {
+ 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");
@@ -55,18 +55,18 @@ int main(int argc, char *argv[])
err = soap_client_invoke(ctx, &ctx2, argv[1], "");
else
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);
- return 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);
+ return 1;
+ }
soap_xml_doc_print(ctx2->env->root->doc);
soap_ctx_free(ctx2);
- soap_ctx_free(ctx);
-
- soap_client_destroy();
+ soap_ctx_free(ctx);
+
+ soap_client_destroy();
return 0;
}
diff --git a/examples/csoap/simpleserver.c b/examples/csoap/simpleserver.c
index a165cfc..fef16f0 100644
--- a/examples/csoap/simpleserver.c
+++ b/examples/csoap/simpleserver.c
@@ -1,85 +1,85 @@
-/******************************************************************
- * $Id: simpleserver.c,v 1.11 2004/10/28 10:30:42 snowdrop Exp $
- *
- * CSOAP Project: CSOAP examples project
- * Copyright (C) 2003-2004 Ferhat Ayaz
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
- *
- * Email: ferhatayaz@yahoo.com
- ******************************************************************/
-
-#include <libcsoap/soap-server.h>
-
-
-static const char *url = "/csoapserver";
-static const char *urn = "urn:examples";
-static const char *method = "sayHello";
-
-
-herror_t say_hello(SoapCtx *req, SoapCtx* res)
-{
-
- herror_t err;
- char *name;
-
- xmlNodePtr method, node;
-
- 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);
-
- while (node) {
- name = (char*)xmlNodeListGetString(node->doc, node->xmlChildrenNode, 1);
- soap_env_add_itemf(req->env,"xsd:string", "echo", "Hello '%s'", name);
- node = soap_xml_get_next(node);
- }
-
- return H_OK;
-}
-
-
-int main(int argc, char *argv[])
-{
-
- herror_t err;
- SoapRouter *router;
-
- log_set_level(HLOG_VERBOSE);
-
- 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);
- return 1;
- }
-
- 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("shutting down\n");
- soap_server_destroy();
-
- return 0;
-}
-
+/******************************************************************
+ * $Id: simpleserver.c,v 1.12 2004/11/02 23:09:19 snowdrop Exp $
+ *
+ * CSOAP Project: CSOAP examples project
+ * Copyright (C) 2003-2004 Ferhat Ayaz
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
+ *
+ * Email: ferhatayaz@yahoo.com
+ ******************************************************************/
+
+#include <libcsoap/soap-server.h>
+
+
+static const char *url = "/csoapserver";
+static const char *urn = "urn:examples";
+static const char *method = "sayHello";
+
+
+herror_t say_hello(SoapCtx *req, SoapCtx* res)
+{
+
+ herror_t err;
+ char *name;
+
+ xmlNodePtr method, node;
+
+ 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);
+
+ while (node) {
+ name = (char*)xmlNodeListGetString(node->doc, node->xmlChildrenNode, 1);
+ soap_env_add_itemf(req->env,"xsd:string", "echo", "Hello '%s'", name);
+ node = soap_xml_get_next(node);
+ }
+
+ return H_OK;
+}
+
+
+int main(int argc, char *argv[])
+{
+
+ herror_t err;
+ SoapRouter *router;
+
+ log_set_level(HLOG_VERBOSE);
+
+ 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);
+ return 1;
+ }
+
+ 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("shutting down\n");
+ soap_server_destroy();
+
+ return 0;
+}
+
diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c
index bec9044..fa65864 100644
--- a/libcsoap/soap-client.c
+++ b/libcsoap/soap-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-client.c,v 1.13 2004/11/02 22:42:52 snowdrop Exp $
+* $Id: soap-client.c,v 1.14 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -25,21 +25,21 @@
#include <nanohttp/nanohttp-client.h>
#include <string.h>
-/*--------------------------------- */
+/*--------------------------------- */
static int _block_socket = 0;
static herror_t _soap_client_build_result(hresponse_t *res, SoapEnv **out);
/*--------------------------------- */
-
-void soap_client_block_socket(int block)
-{
- _block_socket = block;
-}
-
-int soap_client_get_blockmode()
-{
- return _block_socket;
-}
-
+
+void soap_client_block_socket(int block)
+{
+ _block_socket = block;
+}
+
+int soap_client_get_blockmode()
+{
+ return _block_socket;
+}
+
herror_t soap_client_init_args(int argc, char *argv[])
@@ -50,10 +50,10 @@ herror_t soap_client_init_args(int argc, char *argv[])
}
-void soap_client_destroy()
-{
- httpc_destroy();
-}
+void soap_client_destroy()
+{
+ httpc_destroy();
+}
static
long _file_get_size(const char* filename)
@@ -69,7 +69,7 @@ long _file_get_size(const char* filename)
return size;
}
-
+
herror_t
soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const char *soap_action)
{
@@ -93,17 +93,17 @@ soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const cha
static int counter=1;
part_t *part;
int file_count=0;
-
+
/* for copy attachments */
- char href[MAX_HREF_SIZE];
-
+ char href[MAX_HREF_SIZE];
+
/* Create 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();
conn->block = soap_client_get_blockmode();
/* Set soap action */
@@ -123,7 +123,7 @@ soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const cha
if (status != H_OK) {
httpc_free(conn);
- xmlBufferFree(buffer);
+ xmlBufferFree(buffer);
return status;
}
@@ -131,14 +131,14 @@ soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const cha
if (status != H_OK) {
httpc_free(conn);
xmlBufferFree(buffer);
- return status;
+ return status;
}
status = httpc_post_end(conn, &res);
if (status != H_OK) {
httpc_free(conn);
xmlBufferFree(buffer);
- return status;
+ return status;
}
}
else
@@ -152,21 +152,21 @@ soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const cha
if (status != H_OK) {
httpc_free(conn);
xmlBufferFree(buffer);
- return status;
+ return status;
}
status = httpc_mime_next(conn, start_id, "text/xml", "binary");
if (status != H_OK) {
httpc_free(conn);
xmlBufferFree(buffer);
- return status;
+ return status;
}
status = http_output_stream_write(conn->out, content, strlen(content));
if (status != H_OK) {
httpc_free(conn);
xmlBufferFree(buffer);
- return status;
+ return status;
}
@@ -178,7 +178,7 @@ soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const cha
log_error2("Send file failed. Status:%d", status);
httpc_free(conn);
xmlBufferFree(buffer);
- return status;
+ return status;
}
}
@@ -187,7 +187,7 @@ soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const cha
{
httpc_free(conn);
xmlBufferFree(buffer);
- return status;
+ return status;
}
}
@@ -196,58 +196,58 @@ soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const cha
/* Build result */
status = _soap_client_build_result(res, &res_env);
- if (status != H_OK) {
- hresponse_free(res);
- httpc_free(conn);
- return status;
- }
+ if (status != H_OK) {
+ hresponse_free(res);
+ httpc_free(conn);
+ return status;
+ }
/* Create Context */
*response = soap_ctx_new(res_env);
-/* soap_ctx_add_files(*response, res->attachments);*/
-
- if (res->attachments!=NULL) {
- part = res->attachments->parts;
- while (part) {
- soap_ctx_add_file(*response, part->filename, part->content_type, href);
- part->deleteOnExit = 0;
- part = part->next;
- }
- part = (*response)->attachments->parts;
- while (part) {
- part->deleteOnExit = 1;
- part = part->next;
- }
- }
-
-
+/* soap_ctx_add_files(*response, res->attachments);*/
+
+ if (res->attachments!=NULL) {
+ part = res->attachments->parts;
+ while (part) {
+ soap_ctx_add_file(*response, part->filename, part->content_type, href);
+ part->deleteOnExit = 0;
+ part = part->next;
+ }
+ part = (*response)->attachments->parts;
+ while (part) {
+ part->deleteOnExit = 1;
+ part = part->next;
+ }
+ }
+
+
hresponse_free(res);
- httpc_free(conn);
+ httpc_free(conn);
return H_OK;
}
-static
+static
herror_t
_soap_client_build_result(hresponse_t *res, SoapEnv** env)
-{
+{
herror_t err;
log_verbose2("Building result (%p)", res);
if (res == NULL)
- return herror_new("_soap_client_build_result",
+ 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",
+ return herror_new("_soap_client_build_result",
GENERAL_INVALID_PARAM, "Empty response from server");
err = soap_env_new_from_stream(res->in, env);
- if (err != H_OK) {
+ if (err != H_OK) {
return err;
}
diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h
index 7042aad..e0f79bf 100644
--- a/libcsoap/soap-client.h
+++ b/libcsoap/soap-client.h
@@ -1,73 +1,73 @@
-/******************************************************************
- * $Id: soap-client.h,v 1.8 2004/11/02 22:42:52 snowdrop Exp $
- *
- * CSOAP Project: A SOAP client/server library in C
- * Copyright (C) 2003 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ayaz@jprogrammer.net
- ******************************************************************/
-#ifndef cSOAP_CLIENT_H
-#define cSOAP_CLIENT_H
-
-#include <libcsoap/soap-env.h>
-#include <libcsoap/soap-ctx.h>
-
-/**
- Initializes the client side soap engine
-*/
-herror_t soap_client_init_args(int argc, char *argv[]);
-
-
-/**
- Destroy the soap client module
-*/
-void soap_client_destroy();
-
-
-/**
- Establish connection to the soap server and send
- the given envelope.
-
- @param env envelope to send
- @param response the result envelope
- @param url url to the soap server
- @soap_action value for "SoapAction:" in the
- HTTP request header.
-
- @returns H_OK if success
- */
-herror_t soap_client_invoke(SoapCtx *ctx, SoapCtx** response,
- const char *url,
- const char *soap_action);
-
-
-
-/**
- Sets the underlaying socket to use while connecting
- into block mode or not block mode.
- The default mode is always non-blocking mode.
-
- @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();
-
-#endif
-
-
+/******************************************************************
+ * $Id: soap-client.h,v 1.9 2004/11/02 23:09:26 snowdrop Exp $
+ *
+ * CSOAP Project: A SOAP client/server library in C
+ * Copyright (C) 2003 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ayaz@jprogrammer.net
+ ******************************************************************/
+#ifndef cSOAP_CLIENT_H
+#define cSOAP_CLIENT_H
+
+#include <libcsoap/soap-env.h>
+#include <libcsoap/soap-ctx.h>
+
+/**
+ Initializes the client side soap engine
+*/
+herror_t soap_client_init_args(int argc, char *argv[]);
+
+
+/**
+ Destroy the soap client module
+*/
+void soap_client_destroy();
+
+
+/**
+ Establish connection to the soap server and send
+ the given envelope.
+
+ @param env envelope to send
+ @param response the result envelope
+ @param url url to the soap server
+ @soap_action value for "SoapAction:" in the
+ HTTP request header.
+
+ @returns H_OK if success
+ */
+herror_t soap_client_invoke(SoapCtx *ctx, SoapCtx** response,
+ const char *url,
+ const char *soap_action);
+
+
+
+/**
+ Sets the underlaying socket to use while connecting
+ into block mode or not block mode.
+ The default mode is always non-blocking mode.
+
+ @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();
+
+#endif
+
+
diff --git a/libcsoap/soap-ctx.c b/libcsoap/soap-ctx.c
index 423bcfe..5fe0685 100755
--- a/libcsoap/soap-ctx.c
+++ b/libcsoap/soap-ctx.c
@@ -1,135 +1,135 @@
-/******************************************************************
- * $Id: soap-ctx.c,v 1.3 2004/11/01 15:16:26 snowdrop Exp $
- *
- * CSOAP Project: A SOAP client/server library in C
- * Copyright (C) 2003-2004 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ferhatayaz@jprogrammer.net
- ******************************************************************/
-#include <libcsoap/soap-ctx.h>
-
-
-SoapCtx* soap_ctx_new(SoapEnv *env) /* should only be used internally */
-{
- SoapCtx* ctx = (SoapCtx*)malloc(sizeof(SoapCtx));
- ctx->env = env;
- ctx->attachments = NULL;
-
- return ctx;
-}
-
-
-void soap_ctx_add_files(SoapCtx* ctx, attachments_t *attachments)
-{
- part_t *part;
- char href[MAX_HREF_SIZE];
-
- if (attachments==NULL) return;
-
- part = attachments->parts;
- while (part) {
- 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)
-{
- char cid[250];
- char id[250];
- part_t *part;
- static int counter = 1;
- FILE *test = fopen(filename, "r");
- if (!test)
- return herror_new("soap_ctx_add_file", FILE_ERROR_OPEN,
- "Can not open file '%s'", filename);
-
- fclose(test);
-
- /* generate an 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);
- if (!ctx->attachments) ctx->attachments = attachments_new();
- attachments_add_part(ctx->attachments, part);
-
- return H_OK;
-}
-
-part_t *soap_ctx_get_file(SoapCtx* ctx, xmlNodePtr node)
-{
- xmlChar *prop;
- char href[MAX_HREF_SIZE];
- char buffer[MAX_HREF_SIZE];
- part_t *part;
-
- if (!ctx->attachments) return NULL;
-
- prop = xmlGetProp(node, "href");
-
- if (!prop) NULL;
-
- 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))
- return part;
-
- }
- } else {
- for (part = ctx->attachments->parts; part; part=part->next)
- {
- if (!strcmp(part->location, href))
- return part;
-
- }
- }
-
- return NULL;
-}
-
-void soap_ctx_free(SoapCtx* ctx)
-{
- if (!ctx) return;
-
- if (ctx->attachments)
- attachments_free(ctx->attachments);
- if (ctx->env)
- soap_env_free(ctx->env);
-
- free(ctx);
-}
-
-
-herror_t 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);
- if (err != H_OK) return err;
- *out = soap_ctx_new(env);
-
- return H_OK;
-}
-
+/******************************************************************
+ * $Id: soap-ctx.c,v 1.4 2004/11/02 23:09:26 snowdrop Exp $
+ *
+ * CSOAP Project: A SOAP client/server library in C
+ * Copyright (C) 2003-2004 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ferhatayaz@jprogrammer.net
+ ******************************************************************/
+#include <libcsoap/soap-ctx.h>
+
+
+SoapCtx* soap_ctx_new(SoapEnv *env) /* should only be used internally */
+{
+ SoapCtx* ctx = (SoapCtx*)malloc(sizeof(SoapCtx));
+ ctx->env = env;
+ ctx->attachments = NULL;
+
+ return ctx;
+}
+
+
+void soap_ctx_add_files(SoapCtx* ctx, attachments_t *attachments)
+{
+ part_t *part;
+ char href[MAX_HREF_SIZE];
+
+ if (attachments==NULL) return;
+
+ part = attachments->parts;
+ while (part) {
+ 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)
+{
+ char cid[250];
+ char id[250];
+ part_t *part;
+ static int counter = 1;
+ FILE *test = fopen(filename, "r");
+ if (!test)
+ return herror_new("soap_ctx_add_file", FILE_ERROR_OPEN,
+ "Can not open file '%s'", filename);
+
+ fclose(test);
+
+ /* generate an 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);
+ if (!ctx->attachments) ctx->attachments = attachments_new();
+ attachments_add_part(ctx->attachments, part);
+
+ return H_OK;
+}
+
+part_t *soap_ctx_get_file(SoapCtx* ctx, xmlNodePtr node)
+{
+ xmlChar *prop;
+ char href[MAX_HREF_SIZE];
+ char buffer[MAX_HREF_SIZE];
+ part_t *part;
+
+ if (!ctx->attachments) return NULL;
+
+ prop = xmlGetProp(node, "href");
+
+ if (!prop) NULL;
+
+ 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))
+ return part;
+
+ }
+ } else {
+ for (part = ctx->attachments->parts; part; part=part->next)
+ {
+ if (!strcmp(part->location, href))
+ return part;
+
+ }
+ }
+
+ return NULL;
+}
+
+void soap_ctx_free(SoapCtx* ctx)
+{
+ if (!ctx) return;
+
+ if (ctx->attachments)
+ attachments_free(ctx->attachments);
+ if (ctx->env)
+ soap_env_free(ctx->env);
+
+ free(ctx);
+}
+
+
+herror_t 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);
+ if (err != H_OK) return err;
+ *out = soap_ctx_new(env);
+
+ return H_OK;
+}
+
diff --git a/libcsoap/soap-ctx.h b/libcsoap/soap-ctx.h
index a55f18f..a8a8337 100755
--- a/libcsoap/soap-ctx.h
+++ b/libcsoap/soap-ctx.h
@@ -1,71 +1,71 @@
-/******************************************************************
- * $Id: soap-ctx.h,v 1.4 2004/11/01 15:16:26 snowdrop Exp $
- *
- * CSOAP Project: A SOAP client/server library in C
- * Copyright (C) 2003-2004 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ferhatayaz@jprogrammer.net
- ******************************************************************/
-#ifndef cSOAP_CTX_H
-#define cSOAP_CTX_H
-
-
-#include <libcsoap/soap-env.h>
-#include <nanohttp/nanohttp-common.h>
-
-
-#define SOAP_ERROR_NO_FILE_ATTACHED 4001
-#define SOAP_ERROR_EMPTY_ATTACHMENT 4002
-
-#define MAX_HREF_SIZE 150
-
-typedef struct _SoapCtx
-{
- SoapEnv *env;
- attachments_t *attachments;
-}SoapCtx;
-
-
-SoapCtx* soap_ctx_new(SoapEnv *env); /* should only be used internally */
-
-/**
- Returns the attached file if any found.
- @param ctx the SoapCtx object which should contain the part
- @param node the xml node which points to a file via the "href" xml attribute
-
- @returns a part_t object of attachment was found, NULL otherwise.
-
-*/
-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);
-
-/* 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);
-/*
-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);
-
-#endif
-
+/******************************************************************
+ * $Id: soap-ctx.h,v 1.5 2004/11/02 23:09:26 snowdrop Exp $
+ *
+ * CSOAP Project: A SOAP client/server library in C
+ * Copyright (C) 2003-2004 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ferhatayaz@jprogrammer.net
+ ******************************************************************/
+#ifndef cSOAP_CTX_H
+#define cSOAP_CTX_H
+
+
+#include <libcsoap/soap-env.h>
+#include <nanohttp/nanohttp-common.h>
+
+
+#define SOAP_ERROR_NO_FILE_ATTACHED 4001
+#define SOAP_ERROR_EMPTY_ATTACHMENT 4002
+
+#define MAX_HREF_SIZE 150
+
+typedef struct _SoapCtx
+{
+ SoapEnv *env;
+ attachments_t *attachments;
+}SoapCtx;
+
+
+SoapCtx* soap_ctx_new(SoapEnv *env); /* should only be used internally */
+
+/**
+ Returns the attached file if any found.
+ @param ctx the SoapCtx object which should contain the part
+ @param node the xml node which points to a file via the "href" xml attribute
+
+ @returns a part_t object of attachment was found, NULL otherwise.
+
+*/
+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);
+
+/* 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);
+/*
+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);
+
+#endif
+
diff --git a/libcsoap/soap-env.c b/libcsoap/soap-env.c
index 6527028..2018b3d 100644
--- a/libcsoap/soap-env.c
+++ b/libcsoap/soap-env.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-env.c,v 1.9 2004/10/28 10:30:46 snowdrop Exp $
+* $Id: soap-env.c,v 1.10 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -102,91 +102,91 @@ static
/* ---------------------------------------------------------------------------- */
-
-
-herror_t
-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");
- }
-
- 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!");
- }
-
- 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 ! */
-
- *out = env;
- return H_OK;
-}
-
-
-
-
-herror_t
-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");
-
- doc = xmlParseDoc (BAD_CAST buffer);
- if (doc == NULL)
- return herror_new("soap_env_new_from_buffer",
- XML_ERROR_PARSE, "Can not parse xml");
-
- err = soap_env_new_from_doc (doc, out);
- if (err != H_OK) {
- xmlFreeDoc (doc);
- }
-
- return err;
-}
-
-
+
+
+herror_t
+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");
+ }
+
+ 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!");
+ }
+
+ 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 ! */
+
+ *out = env;
+ return H_OK;
+}
+
+
+
+
+herror_t
+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");
+
+ doc = xmlParseDoc (BAD_CAST buffer);
+ if (doc == NULL)
+ return herror_new("soap_env_new_from_buffer",
+ XML_ERROR_PARSE, "Can not parse xml");
+
+ err = soap_env_new_from_doc (doc, out);
+ if (err != H_OK) {
+ xmlFreeDoc (doc);
+ }
+
+ return err;
+}
+
+
herror_t
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;
-
+ herror_t err;
+
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");
-
- err = soap_env_new_from_doc (doc, out);
- if (err != H_OK) {
- xmlFreeDoc (doc);
- }
-
- return err;
+ return herror_new("soap_env_new_with_fault",
+ XML_ERROR_PARSE, "Can not parse fault xml");
+
+ err = soap_env_new_from_doc (doc, out);
+ if (err != H_OK) {
+ xmlFreeDoc (doc);
+ }
+
+ return err;
}
@@ -199,20 +199,20 @@ 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))
{
- 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))
@@ -263,29 +263,29 @@ soap_env_new_with_method (const char *urn, const char *method, SoapEnv **out)
#endif
}
-
- env = xmlParseDoc (buffer);
- if (!env)
- return herror_new("soap_env_new_with_method",
- XML_ERROR_PARSE, "Can not parse xml");
+
+ env = xmlParseDoc (buffer);
+ if (!env)
+ return herror_new("soap_env_new_with_method",
+ XML_ERROR_PARSE, "Can not parse xml");
return soap_env_new_from_doc (env, out);
}
-
-
+
+
static
int _soap_env_xml_io_read(void* ctx, char *buffer, int len)
-{
+{
int readed;
- http_input_stream_t *in = (http_input_stream_t*)ctx;
+ http_input_stream_t *in = (http_input_stream_t*)ctx;
if(!http_input_stream_is_ready(in))
- return 0;
-
- readed = http_input_stream_read(in, buffer, len);
- if (readed == -1)
- return 0;
+ return 0;
+
+ readed = http_input_stream_read(in, buffer, len);
+ if (readed == -1)
+ return 0;
return readed;
}
@@ -296,21 +296,21 @@ int _soap_env_xml_io_close(void *ctx)
return 0;
}
-
+
herror_t
soap_env_new_from_stream(http_input_stream_t *in, SoapEnv **out)
{
- xmlDocPtr doc;
+ xmlDocPtr doc;
herror_t err;
-
+
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",
+
+ 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 err;
+ err = soap_env_new_from_doc (doc, out);
+ return err;
}
diff --git a/libcsoap/soap-env.h b/libcsoap/soap-env.h
index 58af136..523438d 100644
--- a/libcsoap/soap-env.h
+++ b/libcsoap/soap-env.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-env.h,v 1.8 2004/10/28 10:30:46 snowdrop Exp $
+ * $Id: soap-env.h,v 1.9 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -71,7 +71,7 @@ typedef struct _SoapEnv
</pre>
- */
+ */
herror_t
soap_env_new_with_fault(fault_code_t faultcode,
const char *faultstring,
@@ -85,8 +85,8 @@ soap_env_new_with_fault(fault_code_t faultcode,
@param urn The urn of the soap service to invoke
@param method The method name of the soap service
- @param out the result envelope out parameter like follows
- @returns H_OK if success
+ @param out the result envelope out parameter like follows
+ @returns H_OK if success
<pre>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
@@ -103,7 +103,7 @@ soap_env_new_with_fault(fault_code_t faultcode,
</pre>
*/
-herror_t
+herror_t
soap_env_new_with_method(const char *urn, const char *method, SoapEnv **out);
@@ -118,8 +118,8 @@ soap_env_new_with_method(const char *urn, const char *method, SoapEnv **out);
@param req The request object. A response object will be created
to this request.
- @param out the result envelope out paramter like follows
- @returns H_OK if success
+ @param out the result envelope out paramter like follows
+ @returns H_OK if success
<pre>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
@@ -144,8 +144,8 @@ herror_t soap_env_new_with_response(SoapEnv *req,SoapEnv **out);
Creates an envelope from a given libxml2 xmlDoc
pointer.
- @param doc the xml document pointer
- @param out the output envelope object
+ @param doc the xml document pointer
+ @param out the output envelope object
@returns H_OK if success
*/
@@ -157,18 +157,18 @@ herror_t soap_env_new_from_doc(xmlDocPtr doc, SoapEnv **out);
The string must be in xml format.
@param buffer The string to parse into a envelope.
- @param out the output envelope object
+ @param out the output envelope object
@returns H_OK if success
*/
herror_t soap_env_new_from_buffer(const char* buffer,SoapEnv **out);
/**
- Create an envelope from input stream
+ Create an envelope from input stream
- @param in the input stream object to read from
- @param out the output envelope object
- @returns H_OK if success
+ @param in the input stream object to read from
+ @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);
diff --git a/libcsoap/soap-server.c b/libcsoap/soap-server.c
index 8313eb8..2ebefef 100644
--- a/libcsoap/soap-server.c
+++ b/libcsoap/soap-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-server.c,v 1.8 2004/11/02 22:42:52 snowdrop Exp $
+* $Id: soap-server.c,v 1.9 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -100,7 +100,7 @@ void soap_server_destroy()
free(node->context);
free(node);
node = tmp;
- }
+ }
httpd_destroy();
}
@@ -114,7 +114,7 @@ void soap_server_entry(httpd_conn_t *conn, hrequest_t *req)
SoapCtx *ctx, *ctxres;
SoapRouter *router;
SoapService *service;
- SoapEnv *env;
+ SoapEnv *env;
herror_t err;
if (req->method != HTTP_REQUEST_POST) {
@@ -128,15 +128,15 @@ void soap_server_entry(httpd_conn_t *conn, hrequest_t *req)
}
- header = hpairnode_new(HEADER_CONTENT_TYPE, "text/xml", NULL);
-
- 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);
- return;
- }
+ header = hpairnode_new(HEADER_CONTENT_TYPE, "text/xml", NULL);
+
+ 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);
+ return;
+ }
if (env == NULL) {
@@ -192,20 +192,20 @@ void soap_server_entry(httpd_conn_t *conn, hrequest_t *req)
return;
} else {
- log_verbose2("func: %p", service->func);
+ log_verbose2("func: %p", service->func);
ctxres = soap_ctx_new(NULL);
/* ===================================== */
/* CALL SERVICE FUNCTION */
/* ===================================== */
- 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);
- return;
- }
+ 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);
+ return;
+ }
if (ctxres->env == NULL) {
@@ -289,37 +289,37 @@ static
void _soap_server_send_fault(httpd_conn_t *conn, hpair_t *header,
const char* errmsg)
{
- SoapEnv *envres;
- herror_t err;
+ SoapEnv *envres;
+ herror_t err;
char buffer[45];
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));
- return;
- }
+ 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));
+ return;
+ }
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>");
- return;
-
- herror_release(err);
+ "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>");
+ return;
+
+ herror_release(err);
} else {
- _soap_server_send_env(conn->out, envres);
+ _soap_server_send_env(conn->out, envres);
}
}
diff --git a/libcsoap/soap-server.h b/libcsoap/soap-server.h
index 62d136c..5290642 100644
--- a/libcsoap/soap-server.h
+++ b/libcsoap/soap-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-server.h,v 1.4 2004/10/28 10:30:46 snowdrop Exp $
+ * $Id: soap-server.h,v 1.5 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -34,9 +34,9 @@
<TABLE border=1>
<TR><TH>Argument</TH><TH>Description</TH></TR>
- <TR><TD>-NHTTPport [port]</TD><TD>Port to listen (default: 10000)</TD></TR>
- <TR><TD>-NHTTPmaxconn [num]</TD><TD>Maximum thread connections</TD></TR>
- <TR><TD>-NHTTPlog [logfilename]</TD><TD>logfile</TD></TR>
+ <TR><TD>-NHTTPport [port]</TD><TD>Port to listen (default: 10000)</TD></TR>
+ <TR><TD>-NHTTPmaxconn [num]</TD><TD>Maximum thread connections</TD></TR>
+ <TR><TD>-NHTTPlog [logfilename]</TD><TD>logfile</TD></TR>
</TABLE>
@param argc commandline arg count
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c
index 814f0b4..2f79bc0 100644
--- a/nanohttp/nanohttp-client.c
+++ b/nanohttp/nanohttp-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-client.c,v 1.25 2004/11/02 22:42:52 snowdrop Exp $
+* $Id: nanohttp-client.c,v 1.26 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -50,22 +50,22 @@ NOTE: This will be called from soap_client_init_args()
----------------------------------------------------*/
herror_t
httpc_init(int argc, char *argv[])
-{
- hoption_init_args(argc, argv);
- hsocket_module_init();
+{
+ hoption_init_args(argc, argv);
+ hsocket_module_init();
return H_OK;
}
-
-
-/*--------------------------------------------------
-FUNCTION: httpc_destroy
-DESC: Destroy the http client module
-----------------------------------------------------*/
-void httpc_destroy()
-{
- hsocket_module_destroy();
-}
-
+
+
+/*--------------------------------------------------
+FUNCTION: httpc_destroy
+DESC: Destroy the http client module
+----------------------------------------------------*/
+void httpc_destroy()
+{
+ hsocket_module_destroy();
+}
+
/*--------------------------------------------------
FUNCTION: httpc_new
@@ -85,7 +85,7 @@ httpc_new()
res->out = NULL;
res->_dime_package_nr = 0;
res->_dime_sent_bytes = 0;
- res->id = counter++;
+ res->id = counter++;
res->block = 0;
return res;
}
@@ -270,16 +270,16 @@ static
herror_t
httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
const char *urlstr)
-{
+{
hurl_t url;
char buffer[4096];
herror_t status;
if (conn == NULL) {
- return herror_new(
- "httpc_talk_to_server",
- GENERAL_INVALID_PARAM,
+ return herror_new(
+ "httpc_talk_to_server",
+ GENERAL_INVALID_PARAM,
"httpc_conn_t param is NULL");
}
/* Build request header */
@@ -323,17 +323,17 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
} else {
log_error1("Unknown method type!");
- return herror_new(
- "httpc_talk_to_server",
- GENERAL_INVALID_PARAM,
- "hreq_method_t must be HTTP_REQUEST_GET or HTTP_REQUEST_POST");
+ return herror_new(
+ "httpc_talk_to_server",
+ GENERAL_INVALID_PARAM,
+ "hreq_method_t must be HTTP_REQUEST_GET or HTTP_REQUEST_POST");
}
status = hsocket_send(conn->sock, buffer);
if (status != H_OK) {
log_error2("Can not send request (status:%d)", status);
hsocket_close(conn->sock);
- return status;
+ return status;
}
/* Send Header */
status = httpc_send_header(conn);
@@ -341,7 +341,7 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
log_error2("Can not send header (status:%d)", status);
hsocket_close(conn->sock);
return status;
- }
+ }
return H_OK;
@@ -368,7 +368,7 @@ httpc_get(httpc_conn_t *conn, hresponse_t** out, const char *urlstr)
{
return status;
}
-
+
return H_OK;
}
@@ -411,10 +411,10 @@ herror_t httpc_post_end(httpc_conn_t *conn, hresponse_t** out)
status = hresponse_new_from_socket(conn->sock, out);
if (status != H_OK)
- {
+ {
return status;
}
-
+
return H_OK;
}
@@ -423,7 +423,7 @@ herror_t httpc_post_end(httpc_conn_t *conn, hresponse_t** out)
/* ---------------------------------------------------
DIME support functions httpc_dime_* function set
-----------------------------------------------------*/
-/*
+/*
int httpc_dime_begin(httpc_conn_t *conn, const char *url)
{
int status;
@@ -595,12 +595,12 @@ herror_t httpc_mime_begin(httpc_conn_t *conn, const char *url,
*/
sprintf(buffer, "multipart/related;");
- /*
- using sprintf instead of snprintf because visual c does not support snprintf
- */
-#ifdef WIN32
-#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
-#endif
+ /*
+ using sprintf instead of snprintf because visual c does not support snprintf
+ */
+#ifdef WIN32
+#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
+#endif
if (related_type) {
snprintf(temp, 75, " type=\"%s\";", related_type);
@@ -691,7 +691,7 @@ herror_t httpc_mime_end(httpc_conn_t *conn, hresponse_t** out)
{
return status;
}
-
+
return H_OK;
}
@@ -713,7 +713,7 @@ httpc_mime_send_file (httpc_conn_t * conn,
size_t size;
if (fd == NULL)
- return herror_new("httpc_mime_send_file", FILE_ERROR_OPEN,
+ return herror_new("httpc_mime_send_file", FILE_ERROR_OPEN,
"Can not open file '%s'", filename);
status =
@@ -730,22 +730,22 @@ httpc_mime_send_file (httpc_conn_t * conn,
if (size == -1)
{
fclose (fd);
- return herror_new("httpc_mime_send_file", FILE_ERROR_READ,
+ return herror_new("httpc_mime_send_file", FILE_ERROR_READ,
"Can not read from file '%s'", filename);
}
-
- if (size>0)
- {
+
+ if (size>0)
+ {
/*DEBUG: fwrite(buffer, 1, size, stdout);*/
status = http_output_stream_write (conn->out, buffer, size);
if (status != H_OK) {
fclose (fd);
return status;
- }
+ }
}
}
- fclose (fd);
+ fclose (fd);
log_verbose1("file sent!");
return H_OK;
}
diff --git a/nanohttp/nanohttp-client.h b/nanohttp/nanohttp-client.h
index 3e3f9c6..06c0fcd 100644
--- a/nanohttp/nanohttp-client.h
+++ b/nanohttp/nanohttp-client.h
@@ -1,160 +1,160 @@
-/******************************************************************
- * $Id: nanohttp-client.h,v 1.13 2004/11/02 22:42:52 snowdrop Exp $
- *
- * CSOAP Project: A http client/server library in C
- * Copyright (C) 2003 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ferhatayaz@yahoo.com
- ******************************************************************/
-#ifndef NANO_HTTP_CLIENT_H
-#define NANO_HTTP_CLIENT_H
-
-
-#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-response.h>
-#include <nanohttp/nanohttp-stream.h>
-
-typedef struct httpc_conn
-{
- hsocket_t sock;
- hpair_t *header;
- hurl_t url;
- http_version_t version;
- /*
- -1 : last dime package
- 0 : no dime connection
- >0 : dime package number
- */
- int _dime_package_nr;
- long _dime_sent_bytes;
- int errcode;
- char errmsg[150];
- http_output_stream_t *out;
- int id; /* uniq id */
- int block;
-}httpc_conn_t;
-
-
-/* --------------------------------------------------------------
- HTTP CLIENT MODULE RELATED FUNCTIONS
- ---------------------------------------------------------------*/
-
-/**
- initialize the httpc_* module
-*/
-herror_t httpc_init(int argc, char *argv[]);
-
-/**
- Destroy the httpc_* module
-*/
-void httpc_destroy();
-
-/**
- Creates a new connection
-*/
-httpc_conn_t* httpc_new();
-
-/**
- Release a connections
-*/
-void httpc_free(httpc_conn_t* conn);
-
-/**
- Set header element (key,value) pair.
-*/
-int httpc_set_header(httpc_conn_t *conn, const char* key, const char* value);
-
-/**
- Invoke a "GET" method request and receive the response
-*/
-herror_t
-httpc_get(httpc_conn_t *conn, hresponse_t** out, const char *urlstr);
-
-/**
- Start a "POST" method request
- Returns: HSOCKET_OK or error flag
-*/
-herror_t httpc_post_begin(httpc_conn_t *conn, const char *url);
-
-/**
- End a "POST" method and receive the response.
- You MUST call httpc_post_end() before!
-*/
-herror_t httpc_post_end(httpc_conn_t *conn, hresponse_t **out);
-
-
-/* --------------------------------------------------------------
- DIME RELATED FUNCTIONS
- ---------------------------------------------------------------*/
-
-/*
- DIME support httpc_dime_* function set
-*/
-/*
-int httpc_dime_begin(httpc_conn_t *conn, const char *url);
-int httpc_dime_next(httpc_conn_t* conn, long content_length,
- const char *content_type, const char *id,
- const char *dime_options, int last);
-hresponse_t* httpc_dime_end(httpc_conn_t *conn);
-*/
-
-/* --------------------------------------------------------------
- MIME RELATED FUNCTIONS
- ---------------------------------------------------------------*/
-/*
- MIME support httpc_mime_* function set
-*/
-
-/**
- Begin MIME multipart/related POST request
- Returns: HSOCKET_OK or error flag
-*/
-herror_t httpc_mime_begin(httpc_conn_t *conn, const char *url,
- const char* related_start,
- const char* related_start_info,
- const char* related_type);
-
-/**
- Send boundary and part header and continue
- with next part
-*/
-herror_t httpc_mime_next(httpc_conn_t *conn,
- const char* content_id,
- const char* content_type,
- const char* transfer_encoding);
-
-/**
- Finish MIME request and get the response
-*/
-herror_t httpc_mime_end(httpc_conn_t *conn, hresponse_t** out);
-
-/**
- Send boundary and part header and continue
- with next part
-*/
-
-herror_t httpc_mime_send_file (httpc_conn_t * conn,
- const char *content_id,
- const char *content_type,
- const char *transfer_encoding,
- const char *filename);
-
-#endif
-
-
+/******************************************************************
+ * $Id: nanohttp-client.h,v 1.14 2004/11/02 23:09:26 snowdrop Exp $
+ *
+ * CSOAP Project: A http client/server library in C
+ * Copyright (C) 2003 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ferhatayaz@yahoo.com
+ ******************************************************************/
+#ifndef NANO_HTTP_CLIENT_H
+#define NANO_HTTP_CLIENT_H
+
+
+#include <nanohttp/nanohttp-common.h>
+#include <nanohttp/nanohttp-socket.h>
+#include <nanohttp/nanohttp-response.h>
+#include <nanohttp/nanohttp-stream.h>
+
+typedef struct httpc_conn
+{
+ hsocket_t sock;
+ hpair_t *header;
+ hurl_t url;
+ http_version_t version;
+ /*
+ -1 : last dime package
+ 0 : no dime connection
+ >0 : dime package number
+ */
+ int _dime_package_nr;
+ long _dime_sent_bytes;
+ int errcode;
+ char errmsg[150];
+ http_output_stream_t *out;
+ int id; /* uniq id */
+ int block;
+}httpc_conn_t;
+
+
+/* --------------------------------------------------------------
+ HTTP CLIENT MODULE RELATED FUNCTIONS
+ ---------------------------------------------------------------*/
+
+/**
+ initialize the httpc_* module
+*/
+herror_t httpc_init(int argc, char *argv[]);
+
+/**
+ Destroy the httpc_* module
+*/
+void httpc_destroy();
+
+/**
+ Creates a new connection
+*/
+httpc_conn_t* httpc_new();
+
+/**
+ Release a connections
+*/
+void httpc_free(httpc_conn_t* conn);
+
+/**
+ Set header element (key,value) pair.
+*/
+int httpc_set_header(httpc_conn_t *conn, const char* key, const char* value);
+
+/**
+ Invoke a "GET" method request and receive the response
+*/
+herror_t
+httpc_get(httpc_conn_t *conn, hresponse_t** out, const char *urlstr);
+
+/**
+ Start a "POST" method request
+ Returns: HSOCKET_OK or error flag
+*/
+herror_t httpc_post_begin(httpc_conn_t *conn, const char *url);
+
+/**
+ End a "POST" method and receive the response.
+ You MUST call httpc_post_end() before!
+*/
+herror_t httpc_post_end(httpc_conn_t *conn, hresponse_t **out);
+
+
+/* --------------------------------------------------------------
+ DIME RELATED FUNCTIONS
+ ---------------------------------------------------------------*/
+
+/*
+ DIME support httpc_dime_* function set
+*/
+/*
+int httpc_dime_begin(httpc_conn_t *conn, const char *url);
+int httpc_dime_next(httpc_conn_t* conn, long content_length,
+ const char *content_type, const char *id,
+ const char *dime_options, int last);
+hresponse_t* httpc_dime_end(httpc_conn_t *conn);
+*/
+
+/* --------------------------------------------------------------
+ MIME RELATED FUNCTIONS
+ ---------------------------------------------------------------*/
+/*
+ MIME support httpc_mime_* function set
+*/
+
+/**
+ Begin MIME multipart/related POST request
+ Returns: HSOCKET_OK or error flag
+*/
+herror_t httpc_mime_begin(httpc_conn_t *conn, const char *url,
+ const char* related_start,
+ const char* related_start_info,
+ const char* related_type);
+
+/**
+ Send boundary and part header and continue
+ with next part
+*/
+herror_t httpc_mime_next(httpc_conn_t *conn,
+ const char* content_id,
+ const char* content_type,
+ const char* transfer_encoding);
+
+/**
+ Finish MIME request and get the response
+*/
+herror_t httpc_mime_end(httpc_conn_t *conn, hresponse_t** out);
+
+/**
+ Send boundary and part header and continue
+ with next part
+*/
+
+herror_t httpc_mime_send_file (httpc_conn_t * conn,
+ const char *content_id,
+ const char *content_type,
+ const char *transfer_encoding,
+ const char *filename);
+
+#endif
+
+
diff --git a/nanohttp/nanohttp-common.c b/nanohttp/nanohttp-common.c
index 67301e3..a6d02e6 100644
--- a/nanohttp/nanohttp-common.c
+++ b/nanohttp/nanohttp-common.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-common.c,v 1.16 2004/10/29 09:27:05 snowdrop Exp $
+* $Id: nanohttp-common.c,v 1.17 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -33,129 +33,129 @@
#ifdef MEM_DEBUG
#include <utils/alloc.h>
#endif
-
-
-#define MAX_OPTION_SIZE 50
-#define MAX_OPTION_VALUE_SIZE 150
-
-static char _hoption_table[MAX_OPTION_SIZE][MAX_OPTION_VALUE_SIZE];
-
-/* option stuff */
-void hoption_set(int opt, const char* value)
-{
- if (opt >= MAX_OPTION_SIZE) {
- log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
- return;
- }
-
- strncpy(_hoption_table[opt], value, MAX_OPTION_VALUE_SIZE);
-}
-
-
-char *hoption_get(int opt)
-{
- if (opt >= MAX_OPTION_SIZE) {
- log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
- return "";
- }
-
- return _hoption_table[opt];
-}
-
-
-void hoption_init_args(int argc, char* argv[])
-{
- int i;
-
- hoption_set(HOPTION_TMP_DIR, "."); /* default value */
-
- /* initialize from arguments */
- for (i = 0; i < argc; i++)
- {
- if (!strcmp (argv[i], NHTTP_ARG_TMPDIR) && i < argc - 1)
- {
- hoption_set(HOPTION_TMP_DIR, argv[i+1]);
- }
- else if (!strcmp (argv[i], NHTTP_ARG_LOGFILE) && i < argc - 1)
- {
- log_set_file(argv[i+1]);
- }
- }
-
-
-}
-
-
-#ifdef WIN32
-#ifndef __MINGW32__
-
-/* not thread safe!*/
-char *VisualC_funcname(const char* file, int line)
-{
- static char buffer[256];
- int i = strlen(file)-1;
- while (i>0 && file[i]!='\\')i--;
- sprintf(buffer, "%s:%d", (file[i]!='\\')?file:(file+i+1), line);
- return buffer;
-}
-
-#endif
-#endif
-
-typedef struct _herror_impl_t
-{
- int errcode;
- char message[250];
- char func[100];
-}herror_impl_t;
-
-
-herror_t herror_new(const char* func, int errcode, const char* format, ...)
-{
- va_list ap;
-
- herror_impl_t *impl = (herror_impl_t*)malloc(sizeof(herror_impl_t));
- impl->errcode = errcode;
- strcpy(impl->func, func);
- va_start(ap, format);
- vsprintf(impl->message, format, ap);
- va_end(ap);
-
- return (herror_t)impl;
-
-}
-
-int herror_code(herror_t err)
-{
- herror_impl_t* impl = (herror_impl_t*)err;
- if (!err) return H_OK;
- return impl->errcode;
-}
-
-char* herror_func(herror_t err)
-{
- herror_impl_t* impl = (herror_impl_t*)err;
- if (!err) return "";
- return impl->func;
-}
-
-char* herror_message(herror_t err)
-{
- herror_impl_t* impl = (herror_impl_t*)err;
- if (!err) return "";
- return impl->message;
-}
-
-void herror_release(herror_t err)
-{
- herror_impl_t* impl = (herror_impl_t*)err;
- if (!err) return;
- free(impl);
-}
-
-
-
-static log_level_t loglevel = HLOG_DEBUG;
+
+
+#define MAX_OPTION_SIZE 50
+#define MAX_OPTION_VALUE_SIZE 150
+
+static char _hoption_table[MAX_OPTION_SIZE][MAX_OPTION_VALUE_SIZE];
+
+/* option stuff */
+void hoption_set(int opt, const char* value)
+{
+ if (opt >= MAX_OPTION_SIZE) {
+ log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
+ return;
+ }
+
+ strncpy(_hoption_table[opt], value, MAX_OPTION_VALUE_SIZE);
+}
+
+
+char *hoption_get(int opt)
+{
+ if (opt >= MAX_OPTION_SIZE) {
+ log_warn3("Option to high (%d >= %d)", opt, MAX_OPTION_SIZE);
+ return "";
+ }
+
+ return _hoption_table[opt];
+}
+
+
+void hoption_init_args(int argc, char* argv[])
+{
+ int i;
+
+ hoption_set(HOPTION_TMP_DIR, "."); /* default value */
+
+ /* initialize from arguments */
+ for (i = 0; i < argc; i++)
+ {
+ if (!strcmp (argv[i], NHTTP_ARG_TMPDIR) && i < argc - 1)
+ {
+ hoption_set(HOPTION_TMP_DIR, argv[i+1]);
+ }
+ else if (!strcmp (argv[i], NHTTP_ARG_LOGFILE) && i < argc - 1)
+ {
+ log_set_file(argv[i+1]);
+ }
+ }
+
+
+}
+
+
+#ifdef WIN32
+#ifndef __MINGW32__
+
+/* not thread safe!*/
+char *VisualC_funcname(const char* file, int line)
+{
+ static char buffer[256];
+ int i = strlen(file)-1;
+ while (i>0 && file[i]!='\\')i--;
+ sprintf(buffer, "%s:%d", (file[i]!='\\')?file:(file+i+1), line);
+ return buffer;
+}
+
+#endif
+#endif
+
+typedef struct _herror_impl_t
+{
+ int errcode;
+ char message[250];
+ char func[100];
+}herror_impl_t;
+
+
+herror_t herror_new(const char* func, int errcode, const char* format, ...)
+{
+ va_list ap;
+
+ herror_impl_t *impl = (herror_impl_t*)malloc(sizeof(herror_impl_t));
+ impl->errcode = errcode;
+ strcpy(impl->func, func);
+ va_start(ap, format);
+ vsprintf(impl->message, format, ap);
+ va_end(ap);
+
+ return (herror_t)impl;
+
+}
+
+int herror_code(herror_t err)
+{
+ herror_impl_t* impl = (herror_impl_t*)err;
+ if (!err) return H_OK;
+ return impl->errcode;
+}
+
+char* herror_func(herror_t err)
+{
+ herror_impl_t* impl = (herror_impl_t*)err;
+ if (!err) return "";
+ return impl->func;
+}
+
+char* herror_message(herror_t err)
+{
+ herror_impl_t* impl = (herror_impl_t*)err;
+ if (!err) return "";
+ return impl->message;
+}
+
+void herror_release(herror_t err)
+{
+ herror_impl_t* impl = (herror_impl_t*)err;
+ if (!err) return;
+ free(impl);
+}
+
+
+
+static log_level_t loglevel = HLOG_DEBUG;
static char logfile[75] = {'\0'};
log_level_t
@@ -172,21 +172,21 @@ log_get_level()
{
return loglevel;
}
-
-
-void log_set_file(const char *filename)
-{
- if (filename)
- strncpy(logfile, filename, 75);
- else
- logfile[0] = '\0';
-}
-
-char *log_get_file()
-{
- if (logfile[0] == '\0') return NULL;
- return logfile;
-}
+
+
+void log_set_file(const char *filename)
+{
+ if (filename)
+ strncpy(logfile, filename, 75);
+ else
+ logfile[0] = '\0';
+}
+
+char *log_get_file()
+{
+ if (logfile[0] == '\0') return NULL;
+ return logfile;
+}
static
void
@@ -194,7 +194,7 @@ log_write(log_level_t level, const char *prefix,
const char *func, const char *format, va_list ap)
{
char buffer[1054];
- char buffer2[1054];
+ char buffer2[1054];
FILE *f;
if (level < loglevel)
@@ -203,16 +203,16 @@ log_write(log_level_t level, const char *prefix,
sprintf(buffer, "*%s*: [%s] %s\n", prefix, func, format);
vsprintf(buffer2, buffer, ap);
printf(buffer2);
- fflush(stdout);
-
- if (log_get_file()) {
- f = fopen(log_get_file(), "a");
- if (!f) f = fopen(log_get_file(), "w");
- if (f) {
- fprintf(f, buffer2);
- fflush(f);
- fclose(f);
- }
+ fflush(stdout);
+
+ if (log_get_file()) {
+ f = fopen(log_get_file(), "a");
+ if (!f) f = fopen(log_get_file(), "w");
+ if (f) {
+ fprintf(f, buffer2);
+ fflush(f);
+ fclose(f);
+ }
}
}
@@ -517,13 +517,13 @@ herror_t hurl_parse(hurl_t* url, const char *urlstr)
}
if (iprotocol + 3 >= len) {
log_error1("no host");
- return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
+ return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
}
if (urlstr[iprotocol] != ':'
&& urlstr[iprotocol + 1] != '/'
&& urlstr[iprotocol + 2] != '/') {
log_error1("no protocol");
- return herror_new("hurl_parse", URL_ERROR_NO_PROTOCOL, "No protocol");
+ return herror_new("hurl_parse", URL_ERROR_NO_PROTOCOL, "No protocol");
}
/* find host */
ihost = iprotocol + 3;
@@ -535,7 +535,7 @@ herror_t hurl_parse(hurl_t* url, const char *urlstr)
if (ihost == iprotocol + 1) {
log_error1("no host");
- return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
+ return herror_new("hurl_parse", URL_ERROR_NO_HOST, "No host");
}
/* find port */
iport = ihost;
@@ -556,8 +556,8 @@ herror_t hurl_parse(hurl_t* url, const char *urlstr)
url->protocol = PROTOCOL_HTTPS;
else if (strcmpigcase(protocol, "ftp"))
url->protocol = PROTOCOL_FTP;
- else return herror_new("hurl_parse",
- URL_ERROR_UNKNOWN_PROTOCOL, "Unknown protocol '%s'", protocol);
+ else return herror_new("hurl_parse",
+ URL_ERROR_UNKNOWN_PROTOCOL, "Unknown protocol '%s'", protocol);
/* TODO (#1#): add max of size and URL_MAX_HOST_SIZE */
size = ihost - iprotocol - 3;
@@ -700,7 +700,7 @@ part_t *part_new(const char *id, const char* filename,
{
part_t *part = (part_t*)malloc(sizeof(part_t));
part->header = NULL;
- part->next = next;
+ part->next = next;
part->deleteOnExit = 0;
strcpy(part->id, id);
strcpy(part->filename, filename);
@@ -724,19 +724,19 @@ part_t *part_new(const char *id, const char* filename,
return part;
}
-void part_free(part_t *part)
-{
- if (part == NULL)
- return;
-
- if (part->deleteOnExit) {
- remove(part->filename);
- }
-
- hpairnode_free_deep(part->header);
-
- free(part);
-}
+void part_free(part_t *part)
+{
+ if (part == NULL)
+ return;
+
+ if (part->deleteOnExit) {
+ remove(part->filename);
+ }
+
+ hpairnode_free_deep(part->header);
+
+ free(part);
+}
attachments_t *attachments_new() /* should be used internally */
{
@@ -778,8 +778,8 @@ void attachments_free(attachments_t *message)
part_free(part);
part= tmp;
}
-
- if (message->root_part)
+
+ if (message->root_part)
part_free(message->root_part);
/* TODO (#1#): HERE IS A BUG!!!! */
free(message);
diff --git a/nanohttp/nanohttp-common.h b/nanohttp/nanohttp-common.h
index e633ab4..60cfbeb 100644
--- a/nanohttp/nanohttp-common.h
+++ b/nanohttp/nanohttp-common.h
@@ -1,25 +1,25 @@
-/******************************************************************
- * $Id: nanohttp-common.h,v 1.16 2004/11/01 15:16:26 snowdrop Exp $
- *
- * CSOAP Project: A http client/server library in C
- * Copyright (C) 2003-2004 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ferhatayaz@yahoo.com
+/******************************************************************
+ * $Id: nanohttp-common.h,v 1.17 2004/11/02 23:09:26 snowdrop Exp $
+ *
+ * CSOAP Project: A http client/server library in C
+ * Copyright (C) 2003-2004 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ferhatayaz@yahoo.com
******************************************************************/
#ifndef NANO_HTTP_COMMON_H
#define NANO_HTTP_COMMON_H
@@ -29,8 +29,8 @@
#define HEADER_CONTENT_LENGTH "Content-Length"
#define HEADER_CONTENT_TYPE "Content-Type"
-#define HEADER_CONTENT_ID "Content-Id"
-#define HEADER_CONTENT_LOCATION "Content-Location"
+#define HEADER_CONTENT_ID "Content-Id"
+#define HEADER_CONTENT_LOCATION "Content-Location"
#define HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
#define HEADER_TRANSFER_ENCODING "Transfer-Encoding"
#define HEADER_CONNECTION "Connection"
@@ -38,13 +38,13 @@
#define HEADER_HOST "Host"
#define HEADER_DATE "Date"
#define HEADER_ACCEPT "Accept"
-
-
-#define NHTTPD_ARG_PORT "-NHTTPport"
-#define NHTTPD_ARG_TERMSIG "-NHTTPtsig"
-#define NHTTPD_ARG_MAXCONN "-NHTTPmaxconn"
-#define NHTTP_ARG_LOGFILE "-NHTTPlog"
-#define NHTTP_ARG_TMPDIR "-NHTTPtmpdir"
+
+
+#define NHTTPD_ARG_PORT "-NHTTPport"
+#define NHTTPD_ARG_TERMSIG "-NHTTPtsig"
+#define NHTTPD_ARG_MAXCONN "-NHTTPmaxconn"
+#define NHTTP_ARG_LOGFILE "-NHTTPlog"
+#define NHTTP_ARG_TMPDIR "-NHTTPtmpdir"
#ifndef SAVE_STR
#define SAVE_STR(str) ((str==0)?("(null)"):(str))
@@ -120,18 +120,18 @@
#define MIME_ERROR_NO_ROOT_PART 1304
#define MIME_ERROR_NOT_MIME_MESSAGE 1305
-
-/* General errors */
-#define GENERAL_INVALID_PARAM 1400
-#define GENERAL_HEADER_PARSE_ERROR 1401
-
-/* Thread errors */
-#define THREAD_BEGIN_ERROR 1500
-
-/* XML Errors */
-#define XML_ERROR_EMPTY_DOCUMENT 1600
-#define XML_ERROR_PARSE 1601
-
+
+/* General errors */
+#define GENERAL_INVALID_PARAM 1400
+#define GENERAL_HEADER_PARSE_ERROR 1401
+
+/* Thread errors */
+#define THREAD_BEGIN_ERROR 1500
+
+/* XML Errors */
+#define XML_ERROR_EMPTY_DOCUMENT 1600
+#define XML_ERROR_PARSE 1601
+
/*
Set Sleep function platform depended
*/
@@ -149,8 +149,8 @@ struct tm *localtime_r(const time_t *const timep, struct tm *p_tm);
typedef unsigned char byte_t;
typedef void* herror_t;
-
-
+
+
/**
Indicates the version of the
@@ -171,14 +171,14 @@ typedef enum _hreq_method
HTTP_REQUEST_GET
}hreq_method_t ;
-
-herror_t herror_new(const char* func,
- int errcode, const char* format, ...);
-int herror_code(herror_t err);
-char* herror_func(herror_t err);
-char* herror_message(herror_t err);
-void herror_release(herror_t err);
-
+
+herror_t herror_new(const char* func,
+ int errcode, const char* format, ...);
+int herror_code(herror_t err);
+char* herror_func(herror_t err);
+char* herror_message(herror_t err);
+void herror_release(herror_t err);
+
/*
string function to compare strings ignoring case
@@ -413,22 +413,22 @@ void content_type_free(content_type_t *ct);
*/
typedef struct _part
{
- char id[250];
- char location[250];
+ char id[250];
+ char location[250];
hpair_t *header;
char content_type[128];
char transfer_encoding[128];
char filename[250];
- struct _part *next;
+ struct _part *next;
int deleteOnExit; /* default is 0 */
}part_t;
part_t *part_new(const char *id, const char* filename,
const char* content_type, const char* transfer_encoding, part_t *next);
-void part_free(part_t *part);
-
-
+void part_free(part_t *part);
+
+
/*
@@ -450,13 +450,13 @@ attachments_t *attachments_new(); /* should be used internally */
@see mime_get_attachments
*/
void attachments_free(attachments_t *message);
-void attachments_add_part(attachments_t *attachments, part_t *part);
-
+void attachments_add_part(attachments_t *attachments, part_t *part);
+
-/* tmp directory for multipart/related stuff */
-#define HOPTION_TMP_DIR 2
-void hoption_init_args(int argc, char* argv[]);
-void hoption_set(int opt, const char* value);
+/* tmp directory for multipart/related stuff */
+#define HOPTION_TMP_DIR 2
+void hoption_init_args(int argc, char* argv[]);
+void hoption_set(int opt, const char* value);
char *hoption_get(int opt);
@@ -476,11 +476,11 @@ typedef enum log_level
log_level_t log_set_level(log_level_t level);
log_level_t log_get_level();
-void log_set_file(const char *filename);
-char *log_get_file();
+void log_set_file(const char *filename);
+char *log_get_file();
#ifdef WIN32
- #ifndef __MINGW32__
+ #ifndef __MINGW32__
char *VisualC_funcname(const char* file, int line); /* not thread safe!*/
#define __FUNCTION__ VisualC_funcname(__FILE__, __LINE__)
#endif
diff --git a/nanohttp/nanohttp-mime.c b/nanohttp/nanohttp-mime.c
index 2089348..2cf059c 100755
--- a/nanohttp/nanohttp-mime.c
+++ b/nanohttp/nanohttp-mime.c
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.c,v 1.5 2004/11/01 15:16:26 snowdrop Exp $
+* $Id: nanohttp-mime.c,v 1.6 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -509,18 +509,18 @@ MIME_read_status mime_streamreader_function(void* userdata,
if (!http_input_stream_is_ready(in))
return MIME_READ_EOF;
- readed = http_input_stream_read(in, dest, *size);
- /*
- log_info1("http_input_stream_read() returned 0");
- */
- if (readed == -1) {
- log_error4("[%d] %s():%s ", herror_code(in->err), herror_func(in->err), herror_message(in->err));
- }
+ readed = http_input_stream_read(in, dest, *size);
+ /*
+ log_info1("http_input_stream_read() returned 0");
+ */
+ if (readed == -1) {
+ log_error4("[%d] %s():%s ", herror_code(in->err), herror_func(in->err), herror_message(in->err));
+ }
*size = readed;
- if (*size!=-1) {
+ if (*size!=-1) {
/*
- _log_str("reader.log", dest, *size);
+ _log_str("reader.log", dest, *size);
*/
return MIME_READ_OK;
}
@@ -582,8 +582,8 @@ void _mime_part_begin(void *data)
sprintf(buffer, "%s/mime_%p_%d.part", cbdata->root_dir,
cbdata, cbdata->part_id++);
#endif
-
-/* log_info2("Creating FILE ('%s') deleteOnExit=1", buffer);*/
+
+/* log_info2("Creating FILE ('%s') deleteOnExit=1", buffer);*/
part->deleteOnExit = 1;
cbdata->current_fd = fopen(buffer, "wb");
if (cbdata->current_fd)
@@ -730,23 +730,23 @@ void _mime_received_bytes(void *data, const unsigned char* bytes, int size)
cbdata->current_part->header = _mime_process_header(cbdata->header);
hpairnode_dump_deep(cbdata->current_part->header);
/* set id */
- id = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_ID);
- if (id != NULL)
- {
- strcpy(cbdata->current_part->id, id);
- if (!strcmp(id, cbdata->root_id))
- cbdata->message->root_part = cbdata->current_part;
- }
- location = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_LOCATION);
- if (location != NULL)
- {
- strcpy(cbdata->current_part->location, location);
- }
- type = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_TYPE);
- if (type != NULL)
- {
- strcpy(cbdata->current_part->content_type, type);
- }
+ id = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_ID);
+ if (id != NULL)
+ {
+ strcpy(cbdata->current_part->id, id);
+ if (!strcmp(id, cbdata->root_id))
+ cbdata->message->root_part = cbdata->current_part;
+ }
+ location = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_LOCATION);
+ if (location != NULL)
+ {
+ strcpy(cbdata->current_part->location, location);
+ }
+ type = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_TYPE);
+ if (type != NULL)
+ {
+ strcpy(cbdata->current_part->content_type, type);
+ }
i++;
break;
}
@@ -884,7 +884,7 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
/* Check for MIME message */
if (!(ctype &&
!strcmp(ctype->type, "multipart/related")))
- return herror_new("mime_get_attachments", MIME_ERROR_NOT_MIME_MESSAGE,
+ return herror_new("mime_get_attachments", MIME_ERROR_NOT_MIME_MESSAGE,
"Not a MIME message '%s'", ctype->type);
boundary = hpairnode_get(ctype->params, "boundary");
@@ -893,7 +893,7 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
{
/* TODO (#1#): Handle Error in http form */
log_error1("'boundary' not set for multipart/related");
- return herror_new("mime_get_attachments", MIME_ERROR_NO_BOUNDARY_PARAM,
+ return herror_new("mime_get_attachments", MIME_ERROR_NO_BOUNDARY_PARAM,
"'boundary' not set for multipart/related");
}
@@ -901,8 +901,8 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
{
/* TODO (#1#): Handle Error in http form */
log_error1("'start' not set for multipart/related");
- return herror_new("mime_get_attachments", MIME_ERROR_NO_START_PARAM,
- "'start' not set for multipart/related");
+ return herror_new("mime_get_attachments", MIME_ERROR_NO_START_PARAM,
+ "'start' not set for multipart/related");
}
mimeMessage = mime_message_parse(in, root_id, boundary, hoption_get(HOPTION_TMP_DIR));
@@ -910,7 +910,7 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
{
/* TODO (#1#): Handle Error in http form */
log_error1("MIME Parse Error");
- return herror_new("mime_get_attachments", MIME_ERROR_PARSE_ERROR,
+ return herror_new("mime_get_attachments", MIME_ERROR_PARSE_ERROR,
"MIME Parse Error");
}
@@ -918,7 +918,7 @@ herror_t mime_get_attachments(content_type_t *ctype, http_input_stream_t *in, at
if (!mimeMessage->root_part)
{
attachments_free(mimeMessage);
- return herror_new("mime_get_attachments", MIME_ERROR_NO_ROOT_PART,
+ return herror_new("mime_get_attachments", MIME_ERROR_NO_ROOT_PART,
"No root part found!");
}
diff --git a/nanohttp/nanohttp-mime.h b/nanohttp/nanohttp-mime.h
index b51e44d..be2abfa 100755
--- a/nanohttp/nanohttp-mime.h
+++ b/nanohttp/nanohttp-mime.h
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.h,v 1.3 2004/10/28 10:30:46 snowdrop Exp $
+* $Id: nanohttp-mime.h,v 1.4 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -29,8 +29,8 @@
#ifndef NANO_HTTP_MIME_PARSER_H
#define NANO_HTTP_MIME_PARSER_H
-#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-stream.h>
+#include <nanohttp/nanohttp-common.h>
+#include <nanohttp/nanohttp-stream.h>
#include <stdlib.h>
diff --git a/nanohttp/nanohttp-request.c b/nanohttp/nanohttp-request.c
index 7661592..16e74cb 100755
--- a/nanohttp/nanohttp-request.c
+++ b/nanohttp/nanohttp-request.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-request.c,v 1.3 2004/10/28 10:30:46 snowdrop Exp $
+* $Id: nanohttp-request.c,v 1.4 2004/11/02 23:09:26 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -44,7 +44,7 @@ hrequest_t *hrequest_new()
req->in = NULL;
req->attachments = NULL;
req->content_type = NULL;
-
+
return req;
}
@@ -220,7 +220,7 @@ hrequest_free(hrequest_t * req)
herror_t
hrequest_new_from_socket(hsocket_t sock, hrequest_t **out)
{
- int i=0, readed;
+ int i=0, readed;
herror_t status;
hrequest_t *req;
char buffer[MAX_HEADER_SIZE+1];
diff --git a/nanohttp/nanohttp-response.c b/nanohttp/nanohttp-response.c
index 3883950..5432898 100755
--- a/nanohttp/nanohttp-response.c
+++ b/nanohttp/nanohttp-response.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-response.c,v 1.3 2004/10/29 09:27:05 snowdrop Exp $
+* $Id: nanohttp-response.c,v 1.4 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -121,11 +121,11 @@ _hresponse_parse_header(const char *buffer)
return res;
}
-
+
herror_t
hresponse_new_from_socket(hsocket_t sock, hresponse_t **out)
{
- int i=0, readed;
+ int i=0, readed;
herror_t status;
hresponse_t *res;
attachments_t *mimeMessage;
@@ -158,7 +158,7 @@ read_header: /* for errorcode: 100 (continue) */
if (res == NULL)
{
log_error1("Header parse error");
- return herror_new("hresponse_new_from_socket",
+ return herror_new("hresponse_new_from_socket",
GENERAL_HEADER_PARSE_ERROR, "Can not parse response header");
}
@@ -186,14 +186,14 @@ read_header: /* for errorcode: 100 (continue) */
}
else
{
- res->attachments = mimeMessage;
+ res->attachments = mimeMessage;
http_input_stream_free(res->in);
- res->in = http_input_stream_new_from_file(mimeMessage->root_part->filename);
- if (!res->in) {
- /* TODO (#1#): Handle error */
-
- } else {
- /*res->in->deleteOnExit = 1;*/
+ res->in = http_input_stream_new_from_file(mimeMessage->root_part->filename);
+ if (!res->in) {
+ /* TODO (#1#): Handle error */
+
+ } else {
+ /*res->in->deleteOnExit = 1;*/
}
}
}
@@ -202,9 +202,9 @@ read_header: /* for errorcode: 100 (continue) */
}
-
-void
-hresponse_free(hresponse_t * res)
+
+void
+hresponse_free(hresponse_t * res)
{
if (res == NULL)
return;
@@ -217,8 +217,8 @@ hresponse_free(hresponse_t * res)
if (res->content_type)
content_type_free(res->content_type);
-
- if (res->attachments)
+
+ if (res->attachments)
attachments_free(res->attachments);
free(res);
}
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index 625bd79..d50c434 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.30 2004/11/02 22:42:52 snowdrop Exp $
+* $Id: nanohttp-server.c,v 1.31 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -32,7 +32,7 @@
#endif
#ifndef WIN32
-
+
/* According to POSIX 1003.1-2001 */
#include <sys/select.h>
@@ -40,11 +40,11 @@
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
-
-#else
-
+
+#else
+
#include <process.h>
-
+
#endif
#ifdef MEM_DEBUG
@@ -97,11 +97,11 @@ static void WSAReaper(void *x);
herror_t
httpd_init (int argc, char *argv[])
{
- int i;
+ int i;
herror_t status;
-
- hoption_init_args(argc, argv);
-
+
+ hoption_init_args(argc, argv);
+
status = hsocket_module_init ();
if (status != H_OK)
return status;
@@ -140,14 +140,14 @@ httpd_init (int argc, char *argv[])
memset ((char *) &_httpd_connection[i], 0, sizeof (_httpd_connection[i]));
}
-#ifdef WIN32
+#ifdef WIN32
/*
if (_beginthread (WSAReaper, 0, NULL) == -1)
{
log_error1 ("Winsock reaper thread failed to start");
- return herror_new("httpd_init", THREAD_BEGIN_ERROR,
+ return herror_new("httpd_init", THREAD_BEGIN_ERROR,
"_beginthread() failed while starting WSAReaper");
- }
+ }
*/
#endif
@@ -298,8 +298,8 @@ httpd_send_header (httpd_conn_t * res, int code, const char *text)
/* send header */
status = hsocket_nsend (res->sock, header, strlen (header));
- if (status != H_OK)
- return status;
+ if (status != H_OK)
+ return status;
res->out = http_output_stream_new (res->sock, res->header);
return H_OK;
@@ -390,11 +390,11 @@ httpd_session_main (void *data)
hrequest_t *req = NULL; /* only for test */
httpd_conn_t *rconn;
hservice_t *service = NULL;
- long content_length = 0;
+ long content_length = 0;
herror_t status;
header[0] = '\0';
- len = 0;
+ len = 0;
@@ -407,7 +407,7 @@ httpd_session_main (void *data)
status = hrequest_new_from_socket (conn->sock, &req);
if (status != H_OK)
{
- httpd_send_internal_error (rconn, herror_message(status)/*"Request parse error!"*/);
+ httpd_send_internal_error (rconn, herror_message(status)/*"Request parse error!"*/);
herror_release(status);
}
else
@@ -706,7 +706,7 @@ void httpd_destroy()
hservice_free(cur);
cur = tmp;
}
-
+
hsocket_module_destroy();
}
@@ -834,12 +834,12 @@ httpd_mime_send_header (httpd_conn_t * conn,
type=..; start=.. ; start-info= ..; boundary=...
*/
- /*
- using sprintf instead of snprintf because visual c does not support snprintf
- */
-#ifdef WIN32
-#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
-#endif
+ /*
+ using sprintf instead of snprintf because visual c does not support snprintf
+ */
+#ifdef WIN32
+#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
+#endif
sprintf (buffer, "multipart/related;");
if (related_type)
@@ -926,7 +926,7 @@ httpd_mime_send_file (httpd_conn_t * conn,
size_t size;
if (fd == NULL)
- return herror_new("httpd_mime_send_file", FILE_ERROR_OPEN,
+ return herror_new("httpd_mime_send_file", FILE_ERROR_OPEN,
"Can not open file '%d'", filename);
status =
@@ -943,8 +943,8 @@ httpd_mime_send_file (httpd_conn_t * conn,
if (size == -1)
{
fclose (fd);
- return herror_new("httpd_mime_send_file", FILE_ERROR_READ,
- "Can not read from file '%d'", filename);
+ return herror_new("httpd_mime_send_file", FILE_ERROR_READ,
+ "Can not read from file '%d'", filename);
}
status = http_output_stream_write (conn->out, buffer, size);
diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h
index e344eba..f0550f8 100644
--- a/nanohttp/nanohttp-server.h
+++ b/nanohttp/nanohttp-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-server.h,v 1.8 2004/10/28 10:30:46 snowdrop Exp $
+ * $Id: nanohttp-server.h,v 1.9 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -74,7 +74,7 @@ herror_t httpd_send_header(httpd_conn_t *res,
int httpd_set_header(httpd_conn_t *conn, const char *key, const char* value);
void httpd_set_headers(httpd_conn_t *conn, hpair_t *header);
-
+
/*
unsigned char *httpd_get_postdata(httpd_conn_t *conn,
hrequest_t *req, long *received, long max);
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index 6d93fe2..869bc40 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.31 2004/10/29 09:27:05 snowdrop Exp $
+* $Id: nanohttp-socket.c,v 1.32 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -67,14 +67,14 @@
#ifdef MEM_DEBUG
#include <utils/alloc.h>
#endif
-
-
-#ifdef WIN32
-#undef errno
-#define errno WSAGetLastError()
-#endif
-
-
+
+
+#ifdef WIN32
+#undef errno
+#define errno WSAGetLastError()
+#endif
+
+
/*--------------------------------------------------
FUNCTION: hsocket_module_init
@@ -141,12 +141,12 @@ hsocket_open (hsocket_t * dsock, const char *hostname, int port)
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock <= 0)
- return herror_new("hsocket_open", HSOCKET_ERROR_CREATE, "Socket error: %d", errno);
+ return herror_new("hsocket_open", HSOCKET_ERROR_CREATE, "Socket error: %d", errno);
/* Get host data */
host = gethostbyname (hostname);
if (host == NULL)
- return herror_new("hsocket_open", HSOCKET_ERROR_GET_HOSTNAME, "Socket error: %d", errno);
+ return herror_new("hsocket_open", HSOCKET_ERROR_GET_HOSTNAME, "Socket error: %d", errno);
ip = inet_ntoa (*(struct in_addr *) *host->h_addr_list);
address.sin_addr.s_addr = inet_addr (ip);
@@ -157,8 +157,8 @@ hsocket_open (hsocket_t * dsock, const char *hostname, int port)
/* connect to the server */
if (connect (sock, (struct sockaddr *) &address, sizeof (address)) != 0)
-/* return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Connect to '%s:%d' failed", hostname, port);*/
- return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Socket error: %d", errno);
+/* return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Connect to '%s:%d' failed", hostname, port);*/
+ return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Socket error: %d", errno);
*dsock = sock;
return H_OK;
@@ -178,7 +178,7 @@ hsocket_bind (hsocket_t * dsock, int port)
if (sock == -1)
{
log_error3 ("Can not create socket: '%s'", "Socket error: %d", errno);
- return herror_new("hsocket_bind", HSOCKET_ERROR_CREATE, "Socket error: %d", errno);
+ return herror_new("hsocket_bind", HSOCKET_ERROR_CREATE, "Socket error: %d", errno);
}
/* bind socket */
addr.sin_family = AF_INET;
@@ -190,7 +190,7 @@ hsocket_bind (hsocket_t * dsock, int port)
if (bind (sock, (struct sockaddr *) &addr, sizeof (struct sockaddr)) == -1)
{
log_error3 ("Can not bind: '%s'", "Socket error: %d", errno);
- return herror_new("hsocket_bind", HSOCKET_ERROR_BIND, "Socket error: %d", errno);
+ return herror_new("hsocket_bind", HSOCKET_ERROR_BIND, "Socket error: %d", errno);
}
*dsock = sock;
return H_OK;
@@ -207,8 +207,8 @@ hsocket_accept (hsocket_t sock, hsocket_t * dest)
struct sockaddr_in addr;
if (sock <= 0)
- return herror_new("hsocket_accept", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_accept", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
asize = sizeof (struct sockaddr_in);
#ifdef WIN32
@@ -217,7 +217,7 @@ hsocket_accept (hsocket_t sock, hsocket_t * dest)
sockfd = accept (sock, (struct sockaddr *) &addr, &asize);
if (sockfd == INVALID_SOCKET) {
if (WSAGetLastError () != WSAEWOULDBLOCK)
- return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error: %d", errno);
+ return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error: %d", errno);
} else {
break;
}
@@ -226,7 +226,7 @@ hsocket_accept (hsocket_t sock, hsocket_t * dest)
/* TODO (#1#): why not a loop like in win32? */
sockfd = accept (sock, (struct sockaddr *) &addr, &asize);
if (sockfd == -1) {
- return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error: %d", errno);
+ return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT, "Socket error: %d", errno);
}
#endif
/* TODO (#1#): Write to access.log file */
@@ -245,13 +245,13 @@ herror_t
hsocket_listen (hsocket_t sock)
{
if (sock <= 0)
- return herror_new("hsocket_listen", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_listen", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
if (listen (sock, 15) == -1)
{
log_error3 ("Can not listen: '%s'", "Socket error: %d", errno);
- return herror_new("hsocket_listen", HSOCKET_ERROR_LISTEN, "Socket error: %d", errno);
+ return herror_new("hsocket_listen", HSOCKET_ERROR_LISTEN, "Socket error: %d", errno);
}
return H_OK;
@@ -304,8 +304,8 @@ hsocket_close (hsocket_t sock)
char junk[10];
/* _hsocket_wait_until_receive(sock);*/
log_verbose1 ("closing socket ...");
-/*
- struct linger _linger;
+/*
+ struct linger _linger;
hsocket_block(sock,1);
_linger.l_onoff =1;
_linger.l_linger = 30000;
@@ -326,17 +326,17 @@ hsocket_close (hsocket_t sock)
#endif
log_verbose1 ("closed");
}
-
-
-static int _test_send_to_file(const char* filename, const byte_t* bytes,int n)
-{
- int size;
- FILE *f = fopen(filename, "ab");
- if (!f) f = fopen(filename, "wb");
- size= fwrite(bytes, 1, n, f);
- fclose(f);
- return size;
-}
+
+
+static int _test_send_to_file(const char* filename, const byte_t* bytes,int n)
+{
+ int size;
+ FILE *f = fopen(filename, "ab");
+ if (!f) f = fopen(filename, "wb");
+ size= fwrite(bytes, 1, n, f);
+ fclose(f);
+ return size;
+}
/*--------------------------------------------------
FUNCTION: hsocket_send
@@ -347,27 +347,27 @@ hsocket_nsend (hsocket_t sock, const byte_t *bytes, int n)
int size;
int total=0;
if (sock <= 0)
- return herror_new("hsocket_nsend", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_nsend", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
/* TODO (#1#): check return value and send again until n bytes sent */
while (1)
{
- size = send((int) sock, bytes + total, n, 0);
+ size = send((int) sock, bytes + total, n, 0);
/* size = _test_send_to_file(filename, bytes, n);*/
#ifdef WIN32
if (size == INVALID_SOCKET)
if (WSAGetLastError () == WSAEWOULDBLOCK)
continue;
else
- return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
+ return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
#else
if (size == -1)
- return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
+ return herror_new("hsocket_nsend", HSOCKET_ERROR_SEND, "Socket error: %d", errno);
#endif
- n -= size;
+ n -= size;
total += size;
if (n<=0) break;
}
@@ -393,8 +393,8 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
int totalRead;
int wsa_error;
totalRead = 0;
-/*
- log_verbose3("Entering hsocket_read(total=%d,force=%d)", total, force);
+/*
+ log_verbose3("Entering hsocket_read(total=%d,force=%d)", total, force);
*/
do
{
@@ -412,7 +412,7 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
continue;
default:
log_error2("WSAGetLastError()=%d", wsa_error);
- return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
+ return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
}
}
@@ -426,13 +426,13 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
}
*/
if (status == -1)
- return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
+ return herror_new("hsocket_read", HSOCKET_ERROR_RECEIVE, "Socket error: %d", errno);
#endif
- if (!force) {
- *received = status;
- /*
- log_verbose3("Leaving !force (received=%d)(status=%d)", *received, status);
+ if (!force) {
+ *received = status;
+ /*
+ log_verbose3("Leaving !force (received=%d)(status=%d)", *received, status);
*/
return H_OK;
}
@@ -440,11 +440,11 @@ hsocket_read (hsocket_t sock, byte_t *buffer, int total, int force, int *receive
totalRead += status;
if (totalRead == total) {
- *received = totalRead;
- /*
- log_verbose4("Leaving totalRead == total (received=%d)(status=%d)(totalRead=%d)", *received, status, totalRead);
- */
- return H_OK;
+ *received = totalRead;
+ /*
+ log_verbose4("Leaving totalRead == total (received=%d)(status=%d)(totalRead=%d)", *received, status, totalRead);
+ */
+ return H_OK;
}
}
while (1);
@@ -459,19 +459,19 @@ hsocket_block(hsocket_t sock, int block)
#endif
if (sock <= 0)
- return herror_new("hsocket_block", HSOCKET_ERROR_NOT_INITIALIZED,
- "Called hsocket_listen() before initializing!");
+ return herror_new("hsocket_block", HSOCKET_ERROR_NOT_INITIALIZED,
+ "Called hsocket_listen() before initializing!");
#ifdef WIN32
/*#define HSOCKET_BLOCKMODE 0
#define HSOCKET_NONBLOCKMODE 1
-*/
+*/
iMode = (block==0)?1:0; /* Non block mode */
if (ioctlsocket (sock, FIONBIO, (u_long FAR *) & iMode) == INVALID_SOCKET)
{
log_error1 ("ioctlsocket error");
- return herror_new("hsocket_block", HSOCKET_ERROR_IOCTL, "Socket error: %d", errno);
+ return herror_new("hsocket_block", HSOCKET_ERROR_IOCTL, "Socket error: %d", errno);
}
#else /* fcntl(sock, F_SETFL, O_NONBLOCK); */
/* TODO (#1#): check for *nix the non blocking sockets */
diff --git a/nanohttp/nanohttp-socket.h b/nanohttp/nanohttp-socket.h
index 83d8f72..e9a69f6 100644
--- a/nanohttp/nanohttp-socket.h
+++ b/nanohttp/nanohttp-socket.h
@@ -1,216 +1,216 @@
-/******************************************************************
- * $Id: nanohttp-socket.h,v 1.14 2004/10/28 10:30:47 snowdrop Exp $
- *
- * CSOAP Project: A http client/server library in C
- * Copyright (C) 2003 Ferhat Ayaz
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Email: ayaz@jprogrammer.net
- ******************************************************************/
-#ifndef NANO_HTTP_SOCKET_H
-#define NANO_HTTP_SOCKET_H
-
-#include <nanohttp/nanohttp-common.h>
-
-#include <time.h>
-
-#ifdef WIN32
- #include <winsock2.h>
-#endif
-
-
-#ifdef WIN32
- typedef SOCKET hsocket_t;
- typedef int socklen_t;
-#else
- typedef int hsocket_t;
-#endif
-
-
-
-/**
- Initializes the socket modul. This should be called only
- once for an application.
-
- @returns This function should always return H_OK.
- */
-herror_t hsocket_module_init();
-
-
-/**
- Destroys the socket modul. This should be called after
- finishing an application.
-*/
-void hsocket_module_destroy();
-
-
-/**
- Initializes a given socket object. This function should
- be called for every socket before using it.
-
- @param sock the destination socket to initialize.
-
- @returns This function should always return H_OK.
- */
-herror_t hsocket_init(hsocket_t *sock);
-
-
-/**
- Destroys and releases a given socket.
-
- @param sock the socket to destroy
-*/
-void hsocket_free(hsocket_t sock);
-
-
-/**
- Connects to a given host. The hostname can be an IP number
- or a humen readable hostname.
-
- @param sock the destonation socket object to use
- @param host hostname
- @param port port number to connect to
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_CREATE
- <BR>HSOCKET_ERROR_GET_HOSTNAME
- <BR>HSOCKET_ERROR_CONNECT
- */
-herror_t hsocket_open(hsocket_t *sock, const char* host, int port);
-
-
-/**
- Close a socket connection.
-
- @param sock the socket to close
-*/
-void hsocket_close(hsocket_t sock);
-
-
-/**
- Binds a socket to a given port number. After bind you
- can call hsocket_listen() to listen to the port.
-
- @param sock socket to use.
- @param port port number to bind to
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_CREATE
- <BR>HSOCKET_ERROR_BIND
-
- @see hsocket_listen
- */
-herror_t hsocket_bind(hsocket_t *sock, int port);
-
-
-/**
- Set the socket to the listen mode. You must bind
- the socket to a port with hsocket_bind() before
- you can listen to the port.
-
- @param sock the socket to use
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_LISTEN
-*/
-herror_t hsocket_listen(hsocket_t sock);
-
-
-/**
- Accepts an incoming socket request. Note that this function
- will not return until a socket connection is ready.
-
- @param sock the socket which listents to a port
- @param dest the destination socket which will be created
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_ACCEPT
-*/
-herror_t hsocket_accept(hsocket_t sock, hsocket_t *dest);
-
-
-/**
- Sends data throught the socket.
-
- @param sock the socket to use to send the data
- @param bytes bytes to send
- @param size size of memory to sent pointed by bytes.
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_SEND
-*/
-herror_t hsocket_nsend(hsocket_t sock, const byte_t* bytes, int size);
-
-
-/**
- Sends a string throught the socket
-
- @param sock the socket to use to send the data
- @param str the null terminated string to sent
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_SEND
-*/
-herror_t hsocket_send(hsocket_t sock, const char* str);
-
-
-/**
- Reads data from the socket.
-
- @param sock the socket to read data from
- @param buffer the buffer to use to save the readed bytes
- @param size the maximum size of bytes to read
- @param force if force is 1 then hsocket_read() will wait until
- maximum size of bytes (size parameter) was readed. Otherwise
- this function will not wait and will return with the bytes
- quequed on the socket.
-
- @returns This function will return -1 if an read error was occured.
- Otherwise the return value is the size of bytes readed from
- the socket.
-
-*/
-herror_t hsocket_read(hsocket_t sock, byte_t* buffer, int size, int force, int *readed);
-
-/**
- Sets the goven socket to non-blocking socket mode.
-
- @param sock the socket to set into the non-blocking mode
-
- @returns H_OK if success. One of the followings if fails:<P>
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_IOCTL
-*/
-herror_t hsocket_block(hsocket_t sock, int block);
-
-
-#endif
-
-
-
-
-
-
-
-
-
-
-
+/******************************************************************
+ * $Id: nanohttp-socket.h,v 1.15 2004/11/02 23:09:27 snowdrop Exp $
+ *
+ * CSOAP Project: A http client/server library in C
+ * Copyright (C) 2003 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ayaz@jprogrammer.net
+ ******************************************************************/
+#ifndef NANO_HTTP_SOCKET_H
+#define NANO_HTTP_SOCKET_H
+
+#include <nanohttp/nanohttp-common.h>
+
+#include <time.h>
+
+#ifdef WIN32
+ #include <winsock2.h>
+#endif
+
+
+#ifdef WIN32
+ typedef SOCKET hsocket_t;
+ typedef int socklen_t;
+#else
+ typedef int hsocket_t;
+#endif
+
+
+
+/**
+ Initializes the socket modul. This should be called only
+ once for an application.
+
+ @returns This function should always return H_OK.
+ */
+herror_t hsocket_module_init();
+
+
+/**
+ Destroys the socket modul. This should be called after
+ finishing an application.
+*/
+void hsocket_module_destroy();
+
+
+/**
+ Initializes a given socket object. This function should
+ be called for every socket before using it.
+
+ @param sock the destination socket to initialize.
+
+ @returns This function should always return H_OK.
+ */
+herror_t hsocket_init(hsocket_t *sock);
+
+
+/**
+ Destroys and releases a given socket.
+
+ @param sock the socket to destroy
+*/
+void hsocket_free(hsocket_t sock);
+
+
+/**
+ Connects to a given host. The hostname can be an IP number
+ or a humen readable hostname.
+
+ @param sock the destonation socket object to use
+ @param host hostname
+ @param port port number to connect to
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_CREATE
+ <BR>HSOCKET_ERROR_GET_HOSTNAME
+ <BR>HSOCKET_ERROR_CONNECT
+ */
+herror_t hsocket_open(hsocket_t *sock, const char* host, int port);
+
+
+/**
+ Close a socket connection.
+
+ @param sock the socket to close
+*/
+void hsocket_close(hsocket_t sock);
+
+
+/**
+ Binds a socket to a given port number. After bind you
+ can call hsocket_listen() to listen to the port.
+
+ @param sock socket to use.
+ @param port port number to bind to
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_CREATE
+ <BR>HSOCKET_ERROR_BIND
+
+ @see hsocket_listen
+ */
+herror_t hsocket_bind(hsocket_t *sock, int port);
+
+
+/**
+ Set the socket to the listen mode. You must bind
+ the socket to a port with hsocket_bind() before
+ you can listen to the port.
+
+ @param sock the socket to use
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_LISTEN
+*/
+herror_t hsocket_listen(hsocket_t sock);
+
+
+/**
+ Accepts an incoming socket request. Note that this function
+ will not return until a socket connection is ready.
+
+ @param sock the socket which listents to a port
+ @param dest the destination socket which will be created
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_ACCEPT
+*/
+herror_t hsocket_accept(hsocket_t sock, hsocket_t *dest);
+
+
+/**
+ Sends data throught the socket.
+
+ @param sock the socket to use to send the data
+ @param bytes bytes to send
+ @param size size of memory to sent pointed by bytes.
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_SEND
+*/
+herror_t hsocket_nsend(hsocket_t sock, const byte_t* bytes, int size);
+
+
+/**
+ Sends a string throught the socket
+
+ @param sock the socket to use to send the data
+ @param str the null terminated string to sent
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_SEND
+*/
+herror_t hsocket_send(hsocket_t sock, const char* str);
+
+
+/**
+ Reads data from the socket.
+
+ @param sock the socket to read data from
+ @param buffer the buffer to use to save the readed bytes
+ @param size the maximum size of bytes to read
+ @param force if force is 1 then hsocket_read() will wait until
+ maximum size of bytes (size parameter) was readed. Otherwise
+ this function will not wait and will return with the bytes
+ quequed on the socket.
+
+ @returns This function will return -1 if an read error was occured.
+ Otherwise the return value is the size of bytes readed from
+ the socket.
+
+*/
+herror_t hsocket_read(hsocket_t sock, byte_t* buffer, int size, int force, int *readed);
+
+/**
+ Sets the goven socket to non-blocking socket mode.
+
+ @param sock the socket to set into the non-blocking mode
+
+ @returns H_OK if success. One of the followings if fails:<P>
+ <BR>HSOCKET_ERROR_NOT_INITIALIZED
+ <BR>HSOCKET_ERROR_IOCTL
+*/
+herror_t hsocket_block(hsocket_t sock, int block);
+
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nanohttp/nanohttp-stream.c b/nanohttp/nanohttp-stream.c
index 1951c8a..3f0a9e9 100755
--- a/nanohttp/nanohttp-stream.c
+++ b/nanohttp/nanohttp-stream.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-stream.c,v 1.5 2004/10/29 09:27:05 snowdrop Exp $
+* $Id: nanohttp-stream.c,v 1.6 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -132,7 +132,7 @@ http_input_stream_t *http_input_stream_new_from_file(const char* filename)
result = (http_input_stream_t*)malloc(sizeof(http_input_stream_t));
result->type = HTTP_TRANSFER_FILE;
result->fd = fd;
- result->deleteOnExit = 0;
+ result->deleteOnExit = 0;
strcpy(result->filename, filename);
return result;
}
@@ -142,11 +142,11 @@ http_input_stream_t *http_input_stream_new_from_file(const char* filename)
*/
void http_input_stream_free(http_input_stream_t *stream)
{
- if (stream->type == HTTP_TRANSFER_FILE && stream->fd) {
- fclose(stream->fd);
- if (stream->deleteOnExit)
- log_info2("Removing '%s'", stream->filename);
- /*remove(stream->filename);*/
+ if (stream->type == HTTP_TRANSFER_FILE && stream->fd) {
+ fclose(stream->fd);
+ if (stream->deleteOnExit)
+ log_info2("Removing '%s'", stream->filename);
+ /*remove(stream->filename);*/
}
free(stream);
@@ -185,7 +185,7 @@ static
int _http_input_stream_content_length_read(
http_input_stream_t *stream, byte_t *dest, int size)
{
- herror_t status;
+ herror_t status;
int read;
/* check limit */
@@ -209,20 +209,20 @@ int _http_input_stream_chunked_read_chunk_size(
{
char chunk[25];
int status, i = 0;
- int chunk_size;
+ int chunk_size;
herror_t err;
while (1)
{
- err = hsocket_read(stream->sock, &(chunk[i]), 1, 1, &status);
- if (status != 1) {
- stream->err = herror_new("_http_input_stream_chunked_read_chunk_size",
- GENERAL_INVALID_PARAM, "This should never happens!");
- return -1;
+ err = hsocket_read(stream->sock, &(chunk[i]), 1, 1, &status);
+ if (status != 1) {
+ stream->err = herror_new("_http_input_stream_chunked_read_chunk_size",
+ GENERAL_INVALID_PARAM, "This should never happens!");
+ return -1;
}
- if (err != H_OK) {
- log_error4("[%d] %s(): %s ", herror_code(err), herror_func(err), herror_message(err));
+ if (err != H_OK) {
+ log_error4("[%d] %s(): %s ", herror_code(err), herror_func(err), herror_message(err));
stream->err = err;
return -1;
@@ -235,16 +235,16 @@ int _http_input_stream_chunked_read_chunk_size(
else if (chunk[i] == '\n')
{
chunk[i] = '\0'; /* double check*/
- chunk_size = strtol(chunk, (char **) NULL, 16); /* hex to dec */
+ chunk_size = strtol(chunk, (char **) NULL, 16); /* hex to dec */
/*
- log_verbose3("chunk_size: '%s' as dec: '%d'", chunk, chunk_size);
+ log_verbose3("chunk_size: '%s' as dec: '%d'", chunk, chunk_size);
*/
return chunk_size;
}
if (i == 24) {
- stream->err = herror_new(
- "_http_input_stream_chunked_read_chunk_size", STREAM_ERROR_NO_CHUNK_SIZE,
+ stream->err = herror_new(
+ "_http_input_stream_chunked_read_chunk_size", STREAM_ERROR_NO_CHUNK_SIZE,
"reached max line == %d", i);
return -1;
}
@@ -253,10 +253,10 @@ int _http_input_stream_chunked_read_chunk_size(
}
/* this should never happens */
- stream->err = herror_new(
- "_http_input_stream_chunked_read_chunk_size", STREAM_ERROR_NO_CHUNK_SIZE,
- "reached max line == %d", i);
- return -1;
+ stream->err = herror_new(
+ "_http_input_stream_chunked_read_chunk_size", STREAM_ERROR_NO_CHUNK_SIZE,
+ "reached max line == %d", i);
+ return -1;
}
static
@@ -265,7 +265,7 @@ int _http_input_stream_chunked_read(
{
int status, counter;
int remain, read=0;
- char ch;
+ char ch;
herror_t err;
while (size > 0)
@@ -291,7 +291,7 @@ int _http_input_stream_chunked_read(
break;
}
if (counter-- == 0) {
- stream->err = herror_new("_http_input_stream_chunked_read",
+ stream->err = herror_new("_http_input_stream_chunked_read",
STREAM_ERROR_WRONG_CHUNK_SIZE,"Wrong chunk-size");
return -1;
}
@@ -320,27 +320,27 @@ int _http_input_stream_chunked_read(
/* show remaining chunk size in socket */
if (remain < size)
{
- /* read from socket */
+ /* read from socket */
err = hsocket_read(stream->sock, &(dest[read]), remain, 1, &status);
- if (err != H_OK) {
- stream->err = err;
- return -1;
- }
- if (status != remain) {
- stream->err = herror_new("_http_input_stream_chunked_read",
- GENERAL_INVALID_PARAM, "This should never happens(remain=%d)(status=%d)!", remain, status);
- return -1;
- }
+ if (err != H_OK) {
+ stream->err = err;
+ return -1;
+ }
+ if (status != remain) {
+ stream->err = herror_new("_http_input_stream_chunked_read",
+ GENERAL_INVALID_PARAM, "This should never happens(remain=%d)(status=%d)!", remain, status);
+ return -1;
+ }
}
else
{
/* read from socket */
err = hsocket_read(stream->sock, &(dest[read]), size, 1, &status);
- if (status != size) {
- stream->err = herror_new("_http_input_stream_chunked_read",
- GENERAL_INVALID_PARAM, "This should never happens(size=%d)(status=%d)!", size, status);
- return -1;
- }
+ if (status != size) {
+ stream->err = herror_new("_http_input_stream_chunked_read",
+ GENERAL_INVALID_PARAM, "This should never happens(size=%d)(status=%d)!", size, status);
+ return -1;
+ }
if (err != H_OK) {
stream->err = err;
return -1;
@@ -361,7 +361,7 @@ int _http_input_stream_connection_closed_read(
http_input_stream_t *stream, byte_t *dest, int size)
{
int status;
- herror_t err;
+ herror_t err;
/* read from socket */
err = hsocket_read(stream->sock, dest, size, 0, &status );
@@ -386,7 +386,7 @@ int _http_input_stream_file_read(
readed = fread(dest, 1, size, stream->fd);
if (readed == -1) {
- stream->err = herror_new("_http_input_stream_file_read",
+ stream->err = herror_new("_http_input_stream_file_read",
HSOCKET_ERROR_RECEIVE, "fread() returned -1");
return -1;
}
@@ -453,7 +453,7 @@ int http_input_stream_read(http_input_stream_t *stream,
readed=_http_input_stream_file_read(stream, dest, size);
break;
default:
- stream->err = herror_new("http_input_stream_read",
+ stream->err = herror_new("http_input_stream_read",
STREAM_ERROR_INVALID_TYPE, "%d is invalid stream type", stream->type);
return -1;
}
diff --git a/nanohttp/nanohttp-stream.h b/nanohttp/nanohttp-stream.h
index b8b345c..d0a234a 100755
--- a/nanohttp/nanohttp-stream.h
+++ b/nanohttp/nanohttp-stream.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-stream.h,v 1.4 2004/10/29 09:27:05 snowdrop Exp $
+ * $Id: nanohttp-stream.h,v 1.5 2004/11/02 23:09:27 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -93,11 +93,11 @@ typedef struct http_input_stream
int received;
int content_length;
int chunk_size;
- byte_t connection_closed;
-
+ byte_t connection_closed;
+
/* file handling */
- FILE *fd;
- char filename[255];
+ FILE *fd;
+ char filename[255];
int deleteOnExit; /* default is 0 */
}http_input_stream_t;