summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO7
-rw-r--r--configure.ac4
-rwxr-xr-xexamples/csoap/echoattachments-client.c33
-rwxr-xr-xexamples/csoap/echoattachments-server.c18
-rw-r--r--examples/csoap/simpleclient.c20
-rw-r--r--examples/csoap/simpleserver.c15
-rw-r--r--examples/csoap/soapclient.c24
-rw-r--r--examples/nanohttp/http_client.c4
-rw-r--r--examples/nanohttp/http_server.c40
-rw-r--r--libcsoap/Makefile.am4
-rw-r--r--libcsoap/soap-addressing.c93
-rw-r--r--libcsoap/soap-addressing.h60
-rw-r--r--libcsoap/soap-admin.c15
-rw-r--r--libcsoap/soap-admin.h22
-rw-r--r--libcsoap/soap-client.c17
-rw-r--r--libcsoap/soap-client.h63
-rwxr-xr-xlibcsoap/soap-ctx.c22
-rwxr-xr-xlibcsoap/soap-ctx.h21
-rw-r--r--libcsoap/soap-env.c118
-rw-r--r--libcsoap/soap-env.h470
-rw-r--r--libcsoap/soap-fault.c10
-rw-r--r--libcsoap/soap-nhttp.c75
-rw-r--r--libcsoap/soap-nhttp.h6
-rw-r--r--libcsoap/soap-nudp.c14
-rw-r--r--libcsoap/soap-nudp.h6
-rw-r--r--libcsoap/soap-router.c41
-rw-r--r--libcsoap/soap-router.h117
-rw-r--r--libcsoap/soap-server.c54
-rw-r--r--libcsoap/soap-server.h17
-rw-r--r--libcsoap/soap-service.c3
-rw-r--r--libcsoap/soap-service.h11
-rw-r--r--libcsoap/soap-transport.c61
-rw-r--r--libcsoap/soap-transport.h12
-rw-r--r--libcsoap/soap-wsil.c43
-rw-r--r--libcsoap/soap-xml.c62
-rw-r--r--libcsoap/soap-xml.h27
-rw-r--r--nanohttp/nanohttp-admin.c17
-rw-r--r--nanohttp/nanohttp-client.c44
-rw-r--r--nanohttp/nanohttp-client.h8
-rw-r--r--nanohttp/nanohttp-common.h106
-rw-r--r--nanohttp/nanohttp-logging.h4
-rwxr-xr-xnanohttp/nanohttp-mime.c8
-rwxr-xr-xnanohttp/nanohttp-mime.h8
-rwxr-xr-xnanohttp/nanohttp-request.c43
-rwxr-xr-xnanohttp/nanohttp-request.h48
-rwxr-xr-xnanohttp/nanohttp-response.c4
-rwxr-xr-xnanohttp/nanohttp-response.h30
-rw-r--r--nanohttp/nanohttp-server.c257
-rw-r--r--nanohttp/nanohttp-server.h98
-rw-r--r--nanohttp/nanohttp-socket.c88
-rw-r--r--nanohttp/nanohttp-socket.h258
-rw-r--r--nanohttp/nanohttp-ssl.c111
-rw-r--r--nanohttp/nanohttp-ssl.h46
-rwxr-xr-xnanohttp/nanohttp-stream.c57
-rwxr-xr-xnanohttp/nanohttp-stream.h356
55 files changed, 1511 insertions, 1709 deletions
diff --git a/TODO b/TODO
index 7d6c516..152d4f0 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,7 @@
+remove most of the typedefs!
------------------------------------------------------------
-ERROR HANDLING !!!!
-------------------------------------------------------------
+improve error handling!!!!
mime_message_t *
@@ -11,6 +11,3 @@ mime_message_parse(http_input_stream_t *in,
and try to optimize mime API
-------------------------------------------------------------
-check socket API again
-
diff --git a/configure.ac b/configure.ac
index 3f49a2d..6bcfcc9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,6 @@
-
+dnl
+dnl package version
+dnl
AC_INIT(csoap, 1.2.0)
AC_CONFIG_SRCDIR([nanohttp/nanohttp-server.c])
diff --git a/examples/csoap/echoattachments-client.c b/examples/csoap/echoattachments-client.c
index b128563..26c65ff 100755
--- a/examples/csoap/echoattachments-client.c
+++ b/examples/csoap/echoattachments-client.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: echoattachments-client.c,v 1.13 2006/11/21 20:58:59 m0gg Exp $
+ * $Id: echoattachments-client.c,v 1.14 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -20,30 +20,22 @@
*
* Email: ferhatayaz@yahoo.com
******************************************************************/
-#include <sys/time.h>
#include <stdio.h>
-#include <netinet/in.h>
+#include <stdlib.h>
#include <libxml/tree.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
-#include <nanohttp/nanohttp-request.h>
-#include <nanohttp/nanohttp-response.h>
-#include <nanohttp/nanohttp-client.h>
#include <nanohttp/nanohttp-logging.h>
#include <libcsoap/soap-env.h>
#include <libcsoap/soap-ctx.h>
#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)
{
@@ -116,14 +108,13 @@ compareFiles(const char *received, const char *sent)
}
int
-main(int argc, char *argv[])
+main(int argc, char **argv)
{
- SoapCtx *ctx, *ctx2;
+ struct 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]);
@@ -135,8 +126,7 @@ main(int argc, char *argv[])
err = soap_client_init_args(argc, argv);
if (err != H_OK)
{
- log_error4("[%d] %s():%s ", herror_code(err), herror_func(err),
- herror_message(err));
+ printf("[%d] %s():%s ", herror_code(err), herror_func(err), herror_message(err));
herror_release(err);
return 1;
}
@@ -146,8 +136,7 @@ main(int argc, char *argv[])
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));
+ printf("[%d] %s():%s ", herror_code(err), herror_func(err), herror_message(err));
herror_release(err);
return 1;
}
@@ -157,8 +146,7 @@ main(int argc, char *argv[])
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));
+ printf("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err));
herror_release(err);
return 1;
}
@@ -177,8 +165,7 @@ main(int argc, char *argv[])
if (err != H_OK)
{
- log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
- herror_code(err));
+ printf("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err));
herror_release(err);
return 1;
}
@@ -188,7 +175,7 @@ main(int argc, char *argv[])
fault = soap_env_get_fault(ctx2->env);
if (fault)
{
- soap_xml_doc_print(ctx2->env->root->doc);
+ xmlDocDump(stdout, ctx2->env->root->doc);
}
else if (ctx2->attachments)
{
@@ -197,7 +184,7 @@ main(int argc, char *argv[])
else
{
printf("No attachments!");
- soap_xml_doc_print(ctx2->env->root->doc);
+ xmlDocDump(stdout, ctx2->env->root->doc);
}
/*
diff --git a/examples/csoap/echoattachments-server.c b/examples/csoap/echoattachments-server.c
index a065cc5..abfb7ec 100755
--- a/examples/csoap/echoattachments-server.c
+++ b/examples/csoap/echoattachments-server.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: echoattachments-server.c,v 1.10 2006/11/21 20:58:59 m0gg Exp $
+ * $Id: echoattachments-server.c,v 1.11 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -22,16 +22,10 @@
******************************************************************/
#include <stdio.h>
#include <stdlib.h>
-#include <netinet/in.h>
#include <libxml/tree.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
-#include <nanohttp/nanohttp-request.h>
-#include <nanohttp/nanohttp-response.h>
-#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-logging.h>
#include <libcsoap/soap-env.h>
@@ -45,7 +39,7 @@ static const char *urn = "urn:examples";
static const char *method = "echo";
herror_t
-echo_attachments(SoapCtx * req, SoapCtx * res)
+echo_attachments(struct SoapCtx * req, struct SoapCtx * res)
{
herror_t err;
@@ -70,20 +64,18 @@ echo_attachments(SoapCtx * req, SoapCtx * res)
return H_OK;
}
-
int
-main(int argc, char *argv[])
+main(int argc, char **argv)
{
herror_t err;
- SoapRouter *router;
+ struct SoapRouter *router;
hlog_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));
+ printf("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err));
herror_release(err);
return 1;
}
diff --git a/examples/csoap/simpleclient.c b/examples/csoap/simpleclient.c
index 6a4451e..1e3b3ff 100644
--- a/examples/csoap/simpleclient.c
+++ b/examples/csoap/simpleclient.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: simpleclient.c,v 1.14 2006/11/21 20:58:59 m0gg Exp $
+ * $Id: simpleclient.c,v 1.15 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -22,18 +22,14 @@
******************************************************************/
#include <stdio.h>
#include <stdlib.h>
-#include <netinet/in.h>
#include <libxml/tree.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
-#include <nanohttp/nanohttp-request.h>
-#include <nanohttp/nanohttp-response.h>
-#include <nanohttp/nanohttp-client.h>
#include <nanohttp/nanohttp-logging.h>
+#include <libcsoap/soap-ctx.h>
+#include <libcsoap/soap-env.h>
#include <libcsoap/soap-client.h>
static char *url = "http://localhost:10000/csoapserver";
@@ -41,12 +37,12 @@ static char *urn = "urn:examples";
static char *method = "sayHello";
int
-main(int argc, char *argv[])
+main(int argc, char **argv)
{
- SoapCtx *ctx, *ctx2;
+ struct SoapCtx *ctx, *ctx2;
herror_t err;
- // hlog_set_level(HLOG_VERBOSE);
+ hlog_set_level(HLOG_VERBOSE);
err = soap_client_init_args(argc, argv);
if (err != H_OK)
@@ -67,7 +63,7 @@ main(int argc, char *argv[])
soap_env_add_item(ctx->env, "xsd:string", "name", "Jonny B. Good");
printf("**** sending ****\n");
- soap_xml_doc_print(ctx->env->root->doc);
+ xmlDocDump(stderr, ctx->env->root->doc);
if (argc > 1)
url = argv[1];
@@ -82,7 +78,7 @@ main(int argc, char *argv[])
}
printf("**** received ****\n");
- soap_xml_doc_print(ctx2->env->root->doc);
+ xmlDocDump(stdout, ctx2->env->root->doc);
soap_ctx_free(ctx2);
soap_ctx_free(ctx);
diff --git a/examples/csoap/simpleserver.c b/examples/csoap/simpleserver.c
index a433783..c67d0e5 100644
--- a/examples/csoap/simpleserver.c
+++ b/examples/csoap/simpleserver.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: simpleserver.c,v 1.21 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: simpleserver.c,v 1.22 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -22,16 +22,11 @@
******************************************************************/
#include <stdio.h>
#include <stdlib.h>
-#include <netinet/in.h>
#include <libxml/tree.h>
+#include <libxml/xpath.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
-#include <nanohttp/nanohttp-request.h>
-#include <nanohttp/nanohttp-response.h>
-#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-logging.h>
#include <libcsoap/soap-xml.h>
@@ -46,7 +41,7 @@ static const char const *urn = "urn:examples";
static const char const *method = "sayHello";
herror_t
-say_hello(SoapCtx * req, SoapCtx * res)
+say_hello(struct SoapCtx *req, struct SoapCtx *res)
{
herror_t err;
char *name;
@@ -76,11 +71,11 @@ say_hello(SoapCtx * req, SoapCtx * res)
}
int
-main(int argc, char *argv[])
+main(int argc, char **argv)
{
herror_t err;
- SoapRouter *router;
+ struct SoapRouter *router;
// hlog_set_level(HLOG_VERBOSE);
diff --git a/examples/csoap/soapclient.c b/examples/csoap/soapclient.c
index c7d55f3..ea7d05f 100644
--- a/examples/csoap/soapclient.c
+++ b/examples/csoap/soapclient.c
@@ -7,19 +7,15 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
-#include <netinet/in.h>
#include <libxml/tree.h>
#include <libxml/uri.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
-#include <nanohttp/nanohttp-request.h>
-#include <nanohttp/nanohttp-response.h>
-#include <nanohttp/nanohttp-client.h>
-#include <nanohttp/nanohttp-logging.h>
+// #include <nanohttp/nanohttp-request.h>
+// #include <nanohttp/nanohttp-response.h>
+// #include <nanohttp/nanohttp-client.h>
#include <libcsoap/soap-fault.h>
#include <libcsoap/soap-env.h>
@@ -128,7 +124,7 @@ stripcslashes(char *str, int *len)
// to the SOAP request
*/
void
-ParseLine(SoapCtx * ctx, char *Buffer, int LineLen)
+ParseLine(struct SoapCtx * ctx, char *Buffer, int LineLen)
{
char *Line, *FirstCommaPos, *SecondCommaPos;
int len;
@@ -191,7 +187,7 @@ printusage(char *FileName)
int
main(int argc, char *argv[])
{
- SoapCtx *ctx, *ctx2;
+ struct SoapCtx *ctx, *ctx2;
herror_t err;
/* create buffer */
@@ -211,7 +207,7 @@ main(int argc, char *argv[])
err = soap_client_init_args(argc, argv);
if (err != H_OK)
{
- log_error4("%s():%s [%d]", herror_func(err),
+ printf("%s():%s [%d]", herror_func(err),
herror_message(err), herror_code(err));
herror_release(err);
return 1;
@@ -221,7 +217,7 @@ main(int argc, char *argv[])
err = soap_ctx_new_with_method(argv[2], argv[3], &ctx);
if (err != H_OK)
{
- log_error4("%s():%s [%d]", herror_func(err),
+ printf("%s():%s [%d]", herror_func(err),
herror_message(err), herror_code(err));
herror_release(err);
return 1;
@@ -244,7 +240,7 @@ main(int argc, char *argv[])
bytes_left = strlen(Buffer);
if (bytes_left == MAX_LINE_LENGTH)
{
- log_error1("The parameter line is too long.");
+ printf("The parameter line is too long.");
herror_release(err);
soap_ctx_free(ctx);
return 1;
@@ -255,7 +251,7 @@ main(int argc, char *argv[])
err = soap_client_invoke(ctx, &ctx2, argv[1], "");
if (err != H_OK)
{
- log_error4("[%d] %s(): %s ", herror_code(err),
+ printf("[%d] %s(): %s ", herror_code(err),
herror_func(err), herror_message(err));
herror_release(err);
soap_ctx_free(ctx);
@@ -263,7 +259,7 @@ main(int argc, char *argv[])
}
/* print the result */
- soap_xml_doc_print(ctx2->env->root->doc);
+ xmlDocDump(stdout, ctx2->env->root->doc);
/* free the objects */
soap_ctx_free(ctx2);
diff --git a/examples/nanohttp/http_client.c b/examples/nanohttp/http_client.c
index 4fa5bed..f871739 100644
--- a/examples/nanohttp/http_client.c
+++ b/examples/nanohttp/http_client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: http_client.c,v 1.4 2006/11/21 20:59:02 m0gg Exp $
+* $Id: http_client.c,v 1.5 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C (example)
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -24,10 +24,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <netinet/in.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
#include <nanohttp/nanohttp-stream.h>
#include <nanohttp/nanohttp-request.h>
#include <nanohttp/nanohttp-response.h>
diff --git a/examples/nanohttp/http_server.c b/examples/nanohttp/http_server.c
index 420c32f..950a717 100644
--- a/examples/nanohttp/http_server.c
+++ b/examples/nanohttp/http_server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: http_server.c,v 1.6 2006/11/21 20:59:02 m0gg Exp $
+* $Id: http_server.c,v 1.7 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C (example)
* Copyright (C) 2003 Ferhat Ayaz
@@ -23,17 +23,15 @@
******************************************************************/
#include <stdio.h>
#include <string.h>
-#include <netinet/in.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
#include <nanohttp/nanohttp-stream.h>
#include <nanohttp/nanohttp-request.h>
#include <nanohttp/nanohttp-response.h>
#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-logging.h>
-static int simple_authenticator(hrequest_t *req, const char *user, const char *password)
+static int simple_authenticator(struct hrequest_t *req, const char *user, const char *password)
{
log_info3("logging in user=\"%s\" password=\"%s\"", user, password);
@@ -53,11 +51,11 @@ static int simple_authenticator(hrequest_t *req, const char *user, const char *p
return 1;
}
-static void secure_service(httpd_conn_t *conn, hrequest_t *req)
+static void secure_service(httpd_conn_t *conn, struct hrequest_t *req)
{
httpd_send_header(conn, 200, "OK");
- hsocket_send(conn->sock,
+ http_output_stream_write_string(conn->out,
"<html>"
"<head>"
"<title>Secure ressource!</title>"
@@ -70,11 +68,11 @@ static void secure_service(httpd_conn_t *conn, hrequest_t *req)
return;
}
-static void default_service(httpd_conn_t *conn, hrequest_t *req)
+static void default_service(httpd_conn_t *conn, struct hrequest_t *req)
{
httpd_send_header(conn, 404, "Not found");
- hsocket_send(conn->sock,
+ http_output_stream_write_string(conn->out,
"<html>"
"<head>"
"<title>Default error page</title>"
@@ -83,9 +81,9 @@ static void default_service(httpd_conn_t *conn, hrequest_t *req)
"<h1>Default error page</h1>"
"<div>");
- hsocket_send(conn->sock, req->path);
+ http_output_stream_write_string(conn->out, req->path);
- hsocket_send(conn->sock, " can not be found"
+ http_output_stream_write_string(conn->out, " can not be found"
"</div>"
"</body>"
"</html>");
@@ -93,12 +91,12 @@ static void default_service(httpd_conn_t *conn, hrequest_t *req)
return;
}
-static void headers_service(httpd_conn_t *conn, hrequest_t *req)
+static void headers_service(httpd_conn_t *conn, struct hrequest_t *req)
{
hpair_t *walker;
httpd_send_header(conn, 200, "OK");
- hsocket_send(conn->sock,
+ http_output_stream_write_string(conn->out,
"<html>"
"<head>"
"<title>Request headers</title>"
@@ -109,14 +107,14 @@ static void headers_service(httpd_conn_t *conn, hrequest_t *req)
for (walker=req->header; walker; walker=walker->next)
{
- hsocket_send(conn->sock, "<li>");
- hsocket_send(conn->sock, walker->key);
- hsocket_send(conn->sock, " = ");
- hsocket_send(conn->sock, walker->value);
- hsocket_send(conn->sock, "</li>");
+ http_output_stream_write_string(conn->out, "<li>");
+ http_output_stream_write_string(conn->out, walker->key);
+ http_output_stream_write_string(conn->out, " = ");
+ http_output_stream_write_string(conn->out, walker->value);
+ http_output_stream_write_string(conn->out, "</li>");
}
- hsocket_send(conn->sock,
+ http_output_stream_write_string(conn->out,
"</ul>"
"</body>"
"</html>");
@@ -124,10 +122,10 @@ static void headers_service(httpd_conn_t *conn, hrequest_t *req)
return;
}
-static void root_service(httpd_conn_t *conn, hrequest_t *req)
+static void root_service(httpd_conn_t *conn, struct hrequest_t *req)
{
httpd_send_header(conn, 200, "OK");
- hsocket_send(conn->sock,
+ http_output_stream_write_string(conn->out,
"<html>"
"<head>"
"<title>nanoHTTP server examples</title>"
@@ -147,7 +145,7 @@ static void root_service(httpd_conn_t *conn, hrequest_t *req)
return;
}
-int main(int argc, char *argv[])
+int main(int argc, char **argv)
{
hlog_set_level(HLOG_INFO);
diff --git a/libcsoap/Makefile.am b/libcsoap/Makefile.am
index b2c73f5..a0dc62e 100644
--- a/libcsoap/Makefile.am
+++ b/libcsoap/Makefile.am
@@ -6,12 +6,12 @@ libcsoap_ladir=$(includedir)/libcsoap-@csoap_release@/libcsoap
libcsoap_la_SOURCES=soap-xml.c soap-fault.c soap-env.c soap-service.c \
soap-router.c soap-client.c soap-server.c soap-ctx.c \
soap-admin.c soap-addressing.c soap-transport.c \
- soap-nudp.c soap-nhttp.c
+ soap-nudp.c soap-nhttp.c soap-wsil.c
libcsoap_la_HEADERS=soap-xml.h soap-fault.h soap-env.h soap-service.h \
soap-router.h soap-client.h soap-server.h soap-ctx.h \
soap-admin.h soap-addressing.h soap-transport.h \
- soap-nudp.h soap-nhttp.c
+ soap-nudp.h soap-nhttp.h soap-wsil.h
libcsoap_la_LDFLAGS= -version-info @csoap_version@ -release @csoap_release@
libcsoap_la_CFLAGS=-I${top_srcdir} -D__CSOAP_INTERNAL=1
diff --git a/libcsoap/soap-addressing.c b/libcsoap/soap-addressing.c
index b1b9d30..dc75d18 100644
--- a/libcsoap/soap-addressing.c
+++ b/libcsoap/soap-addressing.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-addressing.c,v 1.2 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-addressing.c,v 1.3 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2006 Heiko Ronsdorf
@@ -61,7 +61,7 @@
#include "soap-env.h"
#include "soap-addressing.h"
-static const char *
+static const xmlChar *
_soap_addressing_uuid_error(uint32_t status)
{
switch(status)
@@ -261,7 +261,7 @@ soap_addressing_set_metadata(xmlNodePtr endpoint_reference, xmlNodePtr metadata)
}
xmlURI *
-soap_addressing_get_message_id(SoapEnv *envelope)
+soap_addressing_get_message_id(struct SoapEnv *envelope)
{
xmlNodePtr id;
@@ -273,7 +273,7 @@ soap_addressing_get_message_id(SoapEnv *envelope)
}
xmlNodePtr
-soap_addressing_set_message_id(SoapEnv *envelope, xmlURI *id)
+soap_addressing_set_message_id(struct SoapEnv *envelope, xmlURI *id)
{
xmlNodePtr node;
@@ -285,13 +285,50 @@ soap_addressing_set_message_id(SoapEnv *envelope, xmlURI *id)
}
xmlNodePtr
-soap_addressing_get_relates_to(SoapEnv *envelope)
+soap_addressing_set_message_id_string(struct SoapEnv *envelope, xmlChar *id)
+{
+ xmlNodePtr node;
+ xmlChar *tmp;
+
+ if (id == NULL)
+ tmp = _soap_addressing_generate_id();
+ else
+ tmp = id;
+
+ node = _soap_addressing_get_child_element(envelope->header, WSA_MESSAGE_ID);
+ if (node == NULL)
+ node = _soap_addressing_add_node(envelope->header, WSA_MESSAGE_ID, tmp);
+ else
+ xmlNodeSetContent(node, tmp);
+
+ if (id == NULL)
+ xmlFree(tmp);
+
+ return node;
+}
+
+xmlChar *soap_addressing_get_message_id_string(struct SoapEnv *envelope)
+{
+ xmlURI *uri;
+ xmlChar *ret;
+
+ if (!(uri = soap_addressing_get_message_id(envelope)))
+ return NULL;
+
+ ret = xmlSaveUri(uri);
+ xmlFreeURI(uri);
+
+ return ret;
+}
+
+xmlNodePtr
+soap_addressing_get_relates_to(struct SoapEnv *envelope)
{
return _soap_addressing_get_child_element(envelope->header, WSA_RELATES_TO);
}
xmlNodePtr
-soap_addressing_add_relates_to(SoapEnv *envelope, xmlURI *id, xmlURI *type)
+soap_addressing_add_relates_to(struct SoapEnv *envelope, xmlURI *id, xmlURI *type)
{
xmlNodePtr node;
@@ -310,13 +347,13 @@ soap_addressing_add_relates_to(SoapEnv *envelope, xmlURI *id, xmlURI *type)
}
xmlNodePtr
-soap_addressing_get_reply_to(SoapEnv *envelope)
+soap_addressing_get_reply_to(struct SoapEnv *envelope)
{
return _soap_addressing_get_child_element(envelope->header, WSA_REPLY_TO);
}
xmlNodePtr
-soap_addressing_set_reply_to(SoapEnv *envelope, xmlNodePtr address)
+soap_addressing_set_reply_to(struct SoapEnv *envelope, xmlNodePtr address)
{
xmlNodePtr ret;
xmlNodePtr node;
@@ -337,7 +374,7 @@ soap_addressing_set_reply_to(SoapEnv *envelope, xmlNodePtr address)
}
xmlURI *
-soap_addressing_get_reply_to_address(SoapEnv *envelope)
+soap_addressing_get_reply_to_address(struct SoapEnv *envelope)
{
xmlNodePtr reply_to;
@@ -349,7 +386,7 @@ soap_addressing_get_reply_to_address(SoapEnv *envelope)
}
xmlNodePtr
-soap_addressing_set_reply_to_address(SoapEnv *envelope, xmlURI *address)
+soap_addressing_set_reply_to_address(struct SoapEnv *envelope, xmlURI *address)
{
xmlNodePtr ret;
xmlNodePtr node;
@@ -368,13 +405,13 @@ soap_addressing_set_reply_to_address(SoapEnv *envelope, xmlURI *address)
}
xmlNodePtr
-soap_addressing_get_from(SoapEnv *envelope)
+soap_addressing_get_from(struct SoapEnv *envelope)
{
return _soap_addressing_get_child_element(envelope->header, WSA_FROM);
}
xmlNodePtr
-soap_addressing_set_from(SoapEnv *envelope, xmlNodePtr address)
+soap_addressing_set_from(struct SoapEnv *envelope, xmlNodePtr address)
{
xmlNodePtr ret;
xmlNodePtr node;
@@ -395,7 +432,7 @@ soap_addressing_set_from(SoapEnv *envelope, xmlNodePtr address)
}
xmlURI *
-soap_addressing_get_from_address(SoapEnv *envelope)
+soap_addressing_get_from_address(struct SoapEnv *envelope)
{
xmlNodePtr from;
@@ -407,7 +444,7 @@ soap_addressing_get_from_address(SoapEnv *envelope)
}
xmlNodePtr
-soap_addressing_set_from_address(SoapEnv *envelope, xmlURI *address)
+soap_addressing_set_from_address(struct SoapEnv *envelope, xmlURI *address)
{
xmlNodePtr ret;
xmlNodePtr node;
@@ -426,13 +463,13 @@ soap_addressing_set_from_address(SoapEnv *envelope, xmlURI *address)
}
xmlNodePtr
-soap_addressing_get_fault_to(SoapEnv *envelope)
+soap_addressing_get_fault_to(struct SoapEnv *envelope)
{
return _soap_addressing_get_child_element(envelope->header, WSA_FAULT_TO);
}
xmlNodePtr
-soap_addressing_set_fault_to(SoapEnv *envelope, xmlNodePtr address)
+soap_addressing_set_fault_to(struct SoapEnv *envelope, xmlNodePtr address)
{
xmlNodePtr ret;
xmlNodePtr node;
@@ -453,7 +490,7 @@ soap_addressing_set_fault_to(SoapEnv *envelope, xmlNodePtr address)
}
xmlURI *
-soap_addressing_get_fault_to_address(SoapEnv *envelope)
+soap_addressing_get_fault_to_address(struct SoapEnv *envelope)
{
xmlNodePtr fault_to;
@@ -465,7 +502,7 @@ soap_addressing_get_fault_to_address(SoapEnv *envelope)
}
xmlNodePtr
-soap_addressing_set_fault_to_address(SoapEnv *envelope, xmlURI *address)
+soap_addressing_set_fault_to_address(struct SoapEnv *envelope, xmlURI *address)
{
xmlNodePtr ret;
xmlNodePtr node;
@@ -484,13 +521,13 @@ soap_addressing_set_fault_to_address(SoapEnv *envelope, xmlURI *address)
}
xmlNodePtr
-soap_addressing_get_to(SoapEnv *envelope)
+soap_addressing_get_to(struct SoapEnv *envelope)
{
return _soap_addressing_get_child_element(envelope->header, WSA_TO);
}
xmlNodePtr
-soap_addressing_set_to(SoapEnv *envelope, xmlNodePtr address)
+soap_addressing_set_to(struct SoapEnv *envelope, xmlNodePtr address)
{
xmlNodePtr ret;
xmlNodePtr node;
@@ -511,7 +548,7 @@ soap_addressing_set_to(SoapEnv *envelope, xmlNodePtr address)
}
xmlURI *
-soap_addressing_get_to_address(SoapEnv *envelope)
+soap_addressing_get_to_address(struct SoapEnv *envelope)
{
xmlNodePtr to;
@@ -522,7 +559,7 @@ soap_addressing_get_to_address(SoapEnv *envelope)
}
xmlChar *
-soap_addressing_get_to_address_string(SoapEnv *envelope)
+soap_addressing_get_to_address_string(struct SoapEnv *envelope)
{
xmlURI *uri;
xmlChar *ret;
@@ -537,7 +574,7 @@ soap_addressing_get_to_address_string(SoapEnv *envelope)
}
xmlNodePtr
-soap_addressing_set_to_address_string(SoapEnv *envelope, const char *to)
+soap_addressing_set_to_address_string(struct SoapEnv *envelope, const char *to)
{
xmlURI *uri;
xmlNodePtr ret;
@@ -552,7 +589,7 @@ soap_addressing_set_to_address_string(SoapEnv *envelope, const char *to)
}
xmlNodePtr
-soap_addressing_set_to_address(SoapEnv *envelope, xmlURI *address)
+soap_addressing_set_to_address(struct SoapEnv *envelope, xmlURI *address)
{
xmlNodePtr ret;
xmlNodePtr node;
@@ -571,7 +608,7 @@ soap_addressing_set_to_address(SoapEnv *envelope, xmlURI *address)
}
xmlURI *
-soap_addressing_get_action(SoapEnv *envelope)
+soap_addressing_get_action(struct SoapEnv *envelope)
{
xmlNodePtr action;
@@ -583,7 +620,7 @@ soap_addressing_get_action(SoapEnv *envelope)
}
xmlChar *
-soap_addressing_get_action_string(SoapEnv *envelope)
+soap_addressing_get_action_string(struct SoapEnv *envelope)
{
xmlURI *uri;
xmlChar *ret;
@@ -598,7 +635,7 @@ soap_addressing_get_action_string(SoapEnv *envelope)
}
xmlNodePtr
-soap_addressing_set_action(SoapEnv *envelope, xmlURI *action)
+soap_addressing_set_action(struct SoapEnv *envelope, xmlURI *action)
{
xmlNodePtr node;
@@ -610,7 +647,7 @@ soap_addressing_set_action(SoapEnv *envelope, xmlURI *action)
}
xmlNodePtr
-soap_addressing_set_action_string(SoapEnv *envelope, const char *action)
+soap_addressing_set_action_string(struct SoapEnv *envelope, const char *action)
{
xmlURI *uri;
xmlNodePtr ret;
diff --git a/libcsoap/soap-addressing.h b/libcsoap/soap-addressing.h
index 0677244..224fd33 100644
--- a/libcsoap/soap-addressing.h
+++ b/libcsoap/soap-addressing.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-addressing.h,v 1.2 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: soap-addressing.h,v 1.3 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2006 Heiko Ronsdorf
@@ -35,7 +35,7 @@
* in a transport-neutral manner.
*
* @author H. Ronsdorf
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @see http://www.w3.org/TR/ws-addr-core/
*
*/
@@ -196,45 +196,45 @@ xmlNodePtr soap_addressing_set_reference_properties(xmlNodePtr endpoint_referenc
xmlNodePtr soap_addressing_get_metadata(xmlNodePtr endpoint_reference);
xmlNodePtr soap_addressing_set_metadata(xmlNodePtr endpoint_reference, xmlNodePtr parameter);
-xmlURI *soap_addressing_get_message_id(SoapEnv *envelope);
-xmlNodePtr soap_addressing_set_message_id(SoapEnv *envelope, xmlURI *id);
+xmlURI *soap_addressing_get_message_id(struct SoapEnv *envelope);
+xmlNodePtr soap_addressing_set_message_id(struct SoapEnv *envelope, xmlURI *id);
-xmlNodePtr soap_addressing_get_relates_to(SoapEnv *envelope);
-xmlNodePtr soap_addressing_add_relates_to(SoapEnv *envelope, xmlURI *id, xmlURI *type);
+xmlNodePtr soap_addressing_get_relates_to(struct SoapEnv *envelope);
+xmlNodePtr soap_addressing_add_relates_to(struct SoapEnv *envelope, xmlURI *id, xmlURI *type);
-xmlNodePtr soap_addressing_get_reply_to(SoapEnv *envelope);
-xmlNodePtr soap_addressing_set_reply_to(SoapEnv *envelope, xmlNodePtr address);
+xmlNodePtr soap_addressing_get_reply_to(struct SoapEnv *envelope);
+xmlNodePtr soap_addressing_set_reply_to(struct SoapEnv *envelope, xmlNodePtr address);
-xmlURI *soap_addressing_get_reply_to_address(SoapEnv *envelope);
-xmlNodePtr soap_addressing_set_reply_to_address(SoapEnv *envelope, xmlURI *address);
+xmlURI *soap_addressing_get_reply_to_address(struct SoapEnv *envelope);
+xmlNodePtr soap_addressing_set_reply_to_address(struct SoapEnv *envelope, xmlURI *address);
-xmlNodePtr soap_addressing_get_from(SoapEnv *envelope);
-xmlURI *soap_addressing_get_from_address(SoapEnv *envelope);
+xmlNodePtr soap_addressing_get_from(struct SoapEnv *envelope);
+xmlURI *soap_addressing_get_from_address(struct SoapEnv *envelope);
-xmlNodePtr soap_addressing_set_from(SoapEnv *envelope, xmlNodePtr address);
-xmlNodePtr soap_addressing_set_from_address(SoapEnv *envelope, xmlURI *address);
-xmlNodePtr soap_addressing_set_from_string(SoapEnv *envelope, const char *from);
+xmlNodePtr soap_addressing_set_from(struct SoapEnv *envelope, xmlNodePtr address);
+xmlNodePtr soap_addressing_set_from_address(struct SoapEnv *envelope, xmlURI *address);
+xmlNodePtr soap_addressing_set_from_string(struct SoapEnv *envelope, const char *from);
-xmlNodePtr soap_addressing_get_fault_to(SoapEnv *envelope);
-xmlURI *soap_addressing_get_fault_to_address(SoapEnv *envelope);
+xmlNodePtr soap_addressing_get_fault_to(struct SoapEnv *envelope);
+xmlURI *soap_addressing_get_fault_to_address(struct SoapEnv *envelope);
-xmlNodePtr soap_addressing_set_fault_to(SoapEnv *envelope, xmlNodePtr address);
-xmlNodePtr soap_addressing_set_fault_to_address(SoapEnv *envelope, xmlURI *address);
-xmlNodePtr soap_addressing_set_fault_to_string(SoapEnv *envelope, const char *fault_to);
+xmlNodePtr soap_addressing_set_fault_to(struct SoapEnv *envelope, xmlNodePtr address);
+xmlNodePtr soap_addressing_set_fault_to_address(struct SoapEnv *envelope, xmlURI *address);
+xmlNodePtr soap_addressing_set_fault_to_string(struct SoapEnv *envelope, const char *fault_to);
-xmlNodePtr soap_addressing_get_to(SoapEnv *envelope);
-xmlURI *soap_addressing_get_to_address(SoapEnv *envelope);
-xmlChar *soap_addressing_get_to_address_string(SoapEnv *envelope);
+xmlNodePtr soap_addressing_get_to(struct SoapEnv *envelope);
+xmlURI *soap_addressing_get_to_address(struct SoapEnv *envelope);
+xmlChar *soap_addressing_get_to_address_string(struct SoapEnv *envelope);
-xmlNodePtr soap_addressing_set_to(SoapEnv *envelope, xmlNodePtr address);
-xmlNodePtr soap_addressing_set_to_address(SoapEnv *envelope, xmlURI *address);
-xmlNodePtr soap_addressing_set_to_address_string(SoapEnv *envelope, const char *to);
+xmlNodePtr soap_addressing_set_to(struct SoapEnv *envelope, xmlNodePtr address);
+xmlNodePtr soap_addressing_set_to_address(struct SoapEnv *envelope, xmlURI *address);
+xmlNodePtr soap_addressing_set_to_address_string(struct SoapEnv *envelope, const char *to);
-xmlURI *soap_addressing_get_action(SoapEnv *envelope);
-xmlChar *soap_addressing_get_action_string(SoapEnv *envelope);
+xmlURI *soap_addressing_get_action(struct SoapEnv *envelope);
+xmlChar *soap_addressing_get_action_string(struct SoapEnv *envelope);
-xmlNodePtr soap_addressing_set_action(SoapEnv *envelope, xmlURI *action);
-xmlNodePtr soap_addressing_set_action_string(SoapEnv *envelope, const char *action);
+xmlNodePtr soap_addressing_set_action(struct SoapEnv *envelope, xmlURI *action);
+xmlNodePtr soap_addressing_set_action_string(struct SoapEnv *envelope, const char *action);
#ifdef __cplusplus
}
diff --git a/libcsoap/soap-admin.c b/libcsoap/soap-admin.c
index 5558c75..b792ae6 100644
--- a/libcsoap/soap-admin.c
+++ b/libcsoap/soap-admin.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-admin.c,v 1.6 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-admin.c,v 1.7 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -45,17 +45,11 @@
#include <libxml/uri.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
#include <nanohttp/nanohttp-request.h>
#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-admin.h>
-#define __CSOAP_INTERNAL
-
-#include "soap-fault.h"
#include "soap-env.h"
-#include "soap-ctx.h"
#include "soap-service.h"
#include "soap-router.h"
#include "soap-server.h"
@@ -109,7 +103,7 @@ _soap_admin_list_routers(httpd_conn_t *conn)
static void
_soap_admin_list_services(httpd_conn_t *conn, const char *routername)
{
- SoapRouter *router;
+ struct SoapRouter *router;
SoapServiceNode *node;
char buffer[1024];
@@ -144,7 +138,7 @@ _soap_admin_list_services(httpd_conn_t *conn, const char *routername)
static void
-_soap_admin_handle_get(httpd_conn_t * conn, hrequest_t * req)
+_soap_admin_handle_get(httpd_conn_t * conn, struct hrequest_t * req)
{
char *param;
@@ -163,6 +157,7 @@ _soap_admin_handle_get(httpd_conn_t * conn, hrequest_t * req)
http_output_stream_write_string(conn->out,
"<ul>"
"<li><a href=\"?" SOAP_ADMIN_QUERY_ROUTERS "\">Routers</a></li>"
+ "<li><a href=\"../inspection.wsil\">inspection.wsil</a> (try: -CSOAPwsil)</li>"
"<li><a href=\"../nhttp\">nanoHTTP</a></li>"
"</ul>");
@@ -174,7 +169,7 @@ _soap_admin_handle_get(httpd_conn_t * conn, hrequest_t * req)
static void
-_soap_admin_entry(httpd_conn_t * conn, hrequest_t * req)
+_soap_admin_entry(httpd_conn_t * conn, struct hrequest_t * req)
{
if (req->method == HTTP_REQUEST_GET)
{
diff --git a/libcsoap/soap-admin.h b/libcsoap/soap-admin.h
index e49fbba..1d121b3 100644
--- a/libcsoap/soap-admin.h
+++ b/libcsoap/soap-admin.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-admin.h,v 1.3 2006/11/19 09:40:14 m0gg Exp $
+ * $Id: soap-admin.h,v 1.4 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -21,8 +21,8 @@
*
* Email: ferhatayaz@yahoo.com
******************************************************************/
-#ifndef cSOAP_ADMIN_H
-#define cSOAP_ADMIN_H
+#ifndef __csoap_admin_h
+#define __csoap_admin_h
#define CSOAP_ENABLE_ADMIN "-CSOAPadmin"
@@ -35,14 +35,16 @@ extern "C" {
#endif
/**
- Initializes the soap admin HTTP interface with commandline arguments.
-
- @param argc commandline arg count
- @param argv commandline arg vector
-
- @returns 1 if success, 0 otherwise
+ *
+ * Initializes the soap admin HTTP interface with commandline arguments.
+ *
+ * @param argc commandline arg count
+ * @param argv commandline arg vector
+ *
+ * @returns 1 if success, 0 otherwise
+ *
*/
-herror_t soap_admin_init_args(int argc, char *argv[]);
+extern herror_t soap_admin_init_args(int argc, char **argv);
#ifdef __cplusplus
}
diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c
index 4e12650..a49ba2a 100644
--- a/libcsoap/soap-client.c
+++ b/libcsoap/soap-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-client.c,v 1.29 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-client.c,v 1.30 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -25,16 +25,10 @@
#include <config.h>
#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
#include <libxml/tree.h>
#include <libxml/uri.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
#include <nanohttp/nanohttp-request.h>
#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-logging.h>
@@ -63,13 +57,20 @@ soap_client_destroy(void)
}
herror_t
-soap_client_invoke(SoapCtx *req, SoapCtx **res, const char *url, const char *action)
+soap_client_invoke(struct SoapCtx *req, struct SoapCtx **res, const char *url, const char *action)
{
+ char *id;
+
log_verbose2("action = \"%s\"", action);
soap_addressing_set_action_string(req->env, action);
log_verbose2("url = \"%s\"", url);
soap_addressing_set_to_address_string(req->env, url);
+ soap_addressing_set_message_id_string(req->env, NULL);
+ id = soap_addressing_get_message_id_string(req->env);
+ log_verbose2("message id = \"%s\"", id);
+ free(id);
+
return soap_transport_client_invoke(req, res);
}
diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h
index d8bf6ee..f74d881 100644
--- a/libcsoap/soap-client.h
+++ b/libcsoap/soap-client.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-client.h,v 1.13 2006/03/06 13:37:38 m0gg Exp $
+ * $Id: soap-client.h,v 1.14 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -21,11 +21,8 @@
*
* Email: ayaz@jprogrammer.net
******************************************************************/
-#ifndef cSOAP_CLIENT_H
-#define cSOAP_CLIENT_H
-
-#include <libcsoap/soap-env.h>
-#include <libcsoap/soap-ctx.h>
+#ifndef __csoap_client_h
+#define __csoap_client_h
#define SOAP_ERROR_CLIENT_INIT 5001
@@ -34,44 +31,32 @@ extern "C" {
#endif
/**
- 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();
-
+ *
+ * Initializes the client side soap engine
+ *
+ */
+extern herror_t soap_client_init_args(int argc, char **argv);
/**
- 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
+ *
+ * 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);
-
-
+extern herror_t soap_client_invoke(struct SoapCtx * ctx, struct 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();
+ *
+ * Destroy the soap client module
+ *
+ */
+extern void soap_client_destroy(void);
#ifdef __cplusplus
}
diff --git a/libcsoap/soap-ctx.c b/libcsoap/soap-ctx.c
index 2db0e7e..25c34dd 100755
--- a/libcsoap/soap-ctx.c
+++ b/libcsoap/soap-ctx.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-ctx.c,v 1.12 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: soap-ctx.c,v 1.13 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -50,12 +50,12 @@
#include "soap-env.h"
#include "soap-ctx.h"
-SoapCtx *
-soap_ctx_new(SoapEnv * env) /* should only be used internally */
+struct SoapCtx *
+soap_ctx_new(struct SoapEnv * env) /* should only be used internally */
{
- SoapCtx *ctx;
+ struct SoapCtx *ctx;
- if (!(ctx = (SoapCtx *) malloc(sizeof(SoapCtx))))
+ if (!(ctx = (struct SoapCtx *) malloc(sizeof(struct SoapCtx))))
{
log_error2("malloc failed (%s)", strerror(errno));
return NULL;
@@ -69,7 +69,7 @@ soap_ctx_new(SoapEnv * env) /* should only be used internally */
void
-soap_ctx_add_files(SoapCtx * ctx, attachments_t * attachments)
+soap_ctx_add_files(struct SoapCtx * ctx, attachments_t * attachments)
{
part_t *part;
char href[MAX_HREF_SIZE];
@@ -87,7 +87,7 @@ soap_ctx_add_files(SoapCtx * ctx, attachments_t * attachments)
herror_t
-soap_ctx_add_file(SoapCtx * ctx, const char *filename,
+soap_ctx_add_file(struct SoapCtx * ctx, const char *filename,
const char *content_type, char *dest_href)
{
char cid[250];
@@ -116,7 +116,7 @@ soap_ctx_add_file(SoapCtx * ctx, const char *filename,
}
part_t *
-soap_ctx_get_file(SoapCtx * ctx, xmlNodePtr node)
+soap_ctx_get_file(struct SoapCtx * ctx, xmlNodePtr node)
{
xmlChar *prop;
char href[MAX_HREF_SIZE];
@@ -156,7 +156,7 @@ soap_ctx_get_file(SoapCtx * ctx, xmlNodePtr node)
}
void
-soap_ctx_free(SoapCtx * ctx)
+soap_ctx_free(struct SoapCtx * ctx)
{
if (!ctx)
return;
@@ -174,9 +174,9 @@ soap_ctx_free(SoapCtx * ctx)
herror_t
-soap_ctx_new_with_method(const char *urn, const char *method, SoapCtx ** out)
+soap_ctx_new_with_method(const char *urn, const char *method, struct SoapCtx ** out)
{
- SoapEnv *env;
+ struct SoapEnv *env;
herror_t err;
err = soap_env_new_with_method(urn, method, &env);
if (err != H_OK)
diff --git a/libcsoap/soap-ctx.h b/libcsoap/soap-ctx.h
index 93631d2..b8bfb3d 100755
--- a/libcsoap/soap-ctx.h
+++ b/libcsoap/soap-ctx.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-ctx.h,v 1.11 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: soap-ctx.h,v 1.12 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -29,26 +29,25 @@
#define MAX_HREF_SIZE 150
-typedef struct _SoapCtx
+struct SoapCtx
{
- SoapEnv *env;
+ struct SoapEnv *env;
attachments_t *attachments;
-} SoapCtx;
+};
#ifdef __cplusplus
extern "C" {
#endif
/* should only be used internally */
-extern SoapCtx *soap_ctx_new(SoapEnv * env);
+extern struct SoapCtx *soap_ctx_new(struct SoapEnv * env);
/**
Creates a new soap context object.
*/
-extern herror_t soap_ctx_new_with_method(const char *urn, const char *method,
- SoapCtx ** out);
+extern herror_t soap_ctx_new_with_method(const char *urn, const char *method, struct SoapCtx ** out);
-extern void soap_ctx_free(SoapCtx * ctx);
+extern void soap_ctx_free(struct SoapCtx * ctx);
/**
Returns the attached file if any found.
@param ctx the SoapCtx object which should contain the part
@@ -57,16 +56,16 @@ extern void soap_ctx_free(SoapCtx * ctx);
@returns a part_t object of attachment was found, NULL otherwise.
*/
-extern part_t *soap_ctx_get_file(SoapCtx * ctx, xmlNodePtr node);
+extern part_t *soap_ctx_get_file(struct SoapCtx * ctx, xmlNodePtr node);
/* Size of destination dest_href should be MAX_HREF_SIZE */
-extern herror_t soap_ctx_add_file(SoapCtx * ctx, const char *filename,
+extern herror_t soap_ctx_add_file(struct 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.
*/
-extern void soap_ctx_add_files(SoapCtx * ctx, attachments_t * attachments);
+extern void soap_ctx_add_files(struct SoapCtx * ctx, attachments_t * attachments);
#ifdef __cplusplus
}
diff --git a/libcsoap/soap-env.c b/libcsoap/soap-env.c
index 9882cfb..6bdce39 100644
--- a/libcsoap/soap-env.c
+++ b/libcsoap/soap-env.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-env.c,v 1.23 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-env.c,v 1.24 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -50,6 +50,7 @@
#endif
#include <libxml/tree.h>
+#include <libxml/xpath.h>
#include <libxml/xmlstring.h>
#include <nanohttp/nanohttp-common.h>
@@ -164,14 +165,14 @@ xmlbuilder_end_element(const xmlChar * element_name, void *userData)
}
herror_t
-soap_env_new_from_doc(xmlDocPtr doc, SoapEnv ** out)
+soap_env_new_from_doc(xmlDocPtr doc, struct SoapEnv ** out)
{
xmlNodePtr node;
- SoapEnv *env;
+ struct SoapEnv *env;
if (doc == NULL)
{
- log_error1("Can not create xml document!");
+ log_error1("Cannot create XML document!");
return herror_new("soap_env_new_from_doc",
GENERAL_INVALID_PARAM,
"XML Document (xmlDocPtr) is NULL");
@@ -184,10 +185,10 @@ soap_env_new_from_doc(xmlDocPtr doc, SoapEnv ** out)
XML_ERROR_EMPTY_DOCUMENT, "XML Document is empty!");
}
- if (!(env = (SoapEnv *) malloc(sizeof(SoapEnv))))
+ if (!(env = (struct SoapEnv *) malloc(sizeof(struct SoapEnv))))
{
log_error2("malloc failed (%s)", strerror(errno));
- return herror_new("soap_env_from_doc", GENERAL_INVALID_PARAM, "malloc failed");
+ return herror_new("soap_env_from_doc", GENERAL_INVALID_PARAM, "malloc failed (%s)", strerror(errno));
}
env->root = node;
@@ -202,7 +203,7 @@ soap_env_new_from_doc(xmlDocPtr doc, SoapEnv ** out)
herror_t
-soap_env_new_from_buffer(const char *buffer, SoapEnv ** out)
+soap_env_new_from_buffer(const char *buffer, struct SoapEnv **out)
{
xmlDocPtr doc;
herror_t err;
@@ -213,7 +214,7 @@ soap_env_new_from_buffer(const char *buffer, SoapEnv ** out)
if (!(doc = xmlParseDoc(BAD_CAST buffer)))
return herror_new("soap_env_new_from_buffer",
- XML_ERROR_PARSE, "Can not parse xml");
+ XML_ERROR_PARSE, "Cannot parse XML");
if ((err = soap_env_new_from_doc(doc, out)) != H_OK)
{
@@ -224,13 +225,13 @@ soap_env_new_from_buffer(const char *buffer, SoapEnv ** out)
herror_t
-soap_env_new_with_fault(int faultcode, const char *faultstring, const char *faultactor, const char *detail, SoapEnv **out)
+soap_env_new_with_fault(int faultcode, const char *faultstring, const char *faultactor, const char *detail, struct SoapEnv **out)
{
xmlDocPtr doc;
herror_t err;
if (!(doc = soap_fault_build(faultcode, faultstring, faultactor, detail)))
- return herror_new("soap_env_new_with_fault", XML_ERROR_PARSE, "Can not parse fault xml");
+ return herror_new("soap_env_new_with_fault", XML_ERROR_PARSE, "Cannot parse fault XML");
if ((err = soap_env_new_from_doc(doc, out)) != H_OK)
xmlFreeDoc(doc);
@@ -240,11 +241,12 @@ soap_env_new_with_fault(int faultcode, const char *faultstring, const char *faul
herror_t
-soap_env_new_with_response(SoapEnv * request, SoapEnv ** out)
+soap_env_new_with_response(struct SoapEnv * request, struct SoapEnv ** out)
{
- char *method, *res_method;
+ const char *method;
+ char *res_method;
herror_t ret;
- char *urn;
+ const char *urn;
if (request == NULL)
{
@@ -256,7 +258,7 @@ soap_env_new_with_response(SoapEnv * request, SoapEnv ** out)
{
return herror_new("soap_env_new_with_response",
GENERAL_INVALID_PARAM,
- "request (first param) has no xml structure");
+ "request (first param) has no XML structure");
}
if (!(method = soap_env_find_methodname(request)))
@@ -289,7 +291,7 @@ soap_env_new_with_response(SoapEnv * request, SoapEnv ** out)
herror_t
-soap_env_new_with_method(const char *urn, const char *method, SoapEnv ** out)
+soap_env_new_with_method(const char *urn, const char *method, struct SoapEnv ** out)
{
xmlDocPtr env;
xmlChar buffer[1054];
@@ -312,47 +314,45 @@ soap_env_new_with_method(const char *urn, const char *method, SoapEnv ** out)
if (!(env = xmlParseDoc(buffer)))
return herror_new("soap_env_new_with_method",
- XML_ERROR_PARSE, "Can not parse xml");
+ XML_ERROR_PARSE, "Can not parse XML");
return soap_env_new_from_doc(env, out);
}
xmlNodePtr
-soap_env_add_item(SoapEnv * call, const char *type, const char *name, const char *value)
+soap_env_add_item(struct SoapEnv * call, const char *type, const char *name, const char *value)
{
- xmlNodePtr newnode;
+ xmlNodePtr newNode;
- newnode = xmlNewTextChild(call->cur, NULL, BAD_CAST name, BAD_CAST value);
+ newNode = xmlNewTextChild(call->cur, NULL, BAD_CAST name, BAD_CAST value);
- if (newnode == NULL)
+ if (newNode == NULL)
{
- log_error1("Can not create new xml node");
+ log_error1("Can not create new XML node");
return NULL;
}
if (type)
{
- if (!xmlNewProp(newnode, BAD_CAST "xsi:type", BAD_CAST type))
+ if (!xmlNewProp(newNode, BAD_CAST "xsi:type", BAD_CAST type))
{
- log_error1("Can not create new xml attribute");
+ log_error1("Can not create new XML attribute");
return NULL;
}
}
- return newnode;
+ return newNode;
}
xmlNodePtr
-soap_env_add_itemf(SoapEnv * call, const char *type,
- const char *name, const char *format, ...)
+soap_env_add_itemf(struct SoapEnv * call, const char *type, const char *name, const char *format, ...)
{
va_list ap;
char buffer[1054];
-
va_start(ap, format);
vsprintf(buffer, format, ap);
va_end(ap);
@@ -362,13 +362,13 @@ soap_env_add_itemf(SoapEnv * call, const char *type,
xmlNodePtr
-soap_env_add_attachment(SoapEnv * call, const char *name, const char *href)
+soap_env_add_attachment(struct SoapEnv * call, const char *name, const char *href)
{
- xmlNodePtr newnode;
+ xmlNodePtr newNode;
- newnode = xmlNewTextChild(call->cur, NULL, BAD_CAST name, BAD_CAST "");
+ newNode = xmlNewTextChild(call->cur, NULL, BAD_CAST name, BAD_CAST "");
- if (newnode == NULL)
+ if (newNode == NULL)
{
log_error1("Can not create new xml node");
return NULL;
@@ -376,19 +376,19 @@ soap_env_add_attachment(SoapEnv * call, const char *name, const char *href)
if (href)
{
- if (!xmlNewProp(newnode, BAD_CAST "href", BAD_CAST href))
+ if (!xmlNewProp(newNode, BAD_CAST "href", BAD_CAST href))
{
log_error1("Can not create new xml attribute");
return NULL;
}
}
- return newnode;
+ return newNode;
}
void
-soap_env_add_custom(SoapEnv * call, void *obj, XmlSerializerCallback cb, const char *type, const char *name)
+soap_env_add_custom(struct SoapEnv * call, void *obj, XmlSerializerCallback cb, const char *type, const char *name)
{
struct XmlNodeHolder holder;
@@ -403,7 +403,7 @@ soap_env_add_custom(SoapEnv * call, void *obj, XmlSerializerCallback cb, const c
xmlNodePtr
-soap_env_push_item(SoapEnv * call, const char *type, const char *name)
+soap_env_push_item(struct SoapEnv * call, const char *type, const char *name)
{
xmlNodePtr node;
@@ -416,7 +416,7 @@ soap_env_push_item(SoapEnv * call, const char *type, const char *name)
void
-soap_env_pop_item(SoapEnv * call)
+soap_env_pop_item(struct SoapEnv * call)
{
call->cur = call->cur->parent;
@@ -425,7 +425,7 @@ soap_env_pop_item(SoapEnv * call)
void
-soap_env_free(SoapEnv * env)
+soap_env_free(struct SoapEnv * env)
{
if (env)
{
@@ -441,7 +441,7 @@ soap_env_free(SoapEnv * env)
xmlNodePtr
-soap_env_get_body(SoapEnv * env)
+soap_env_get_body(struct SoapEnv * env)
{
xmlNodePtr node;
@@ -470,7 +470,7 @@ soap_env_get_body(SoapEnv * env)
xmlNodePtr
-soap_env_get_header(SoapEnv *env)
+soap_env_get_header(struct SoapEnv *env)
{
xmlNodePtr node;
@@ -498,7 +498,7 @@ soap_env_get_header(SoapEnv *env)
xmlNodePtr
-soap_env_get_fault(SoapEnv * env)
+soap_env_get_fault(struct SoapEnv * env)
{
xmlNodePtr node;
@@ -520,7 +520,7 @@ soap_env_get_fault(SoapEnv * env)
xmlNodePtr
-soap_env_get_method(SoapEnv * env)
+soap_env_get_method(struct SoapEnv * env)
{
xmlNodePtr body;
@@ -537,7 +537,7 @@ soap_env_get_method(SoapEnv * env)
/* XXX: unused function? */
xmlNodePtr
-_soap_env_get_body(SoapEnv * env)
+_soap_env_get_body(struct SoapEnv * env)
{
xmlNodePtr body;
xmlNodeSetPtr nodeset;
@@ -545,13 +545,13 @@ _soap_env_get_body(SoapEnv * env)
if (env == NULL)
{
- log_error1("SoapEnv is NULL");
+ log_error1("struct SoapEnv is NULL");
return NULL;
}
if (env->root == NULL)
{
- log_error1("SoapEnv contains no XML document");
+ log_error1("struct SoapEnv contains no XML document");
return NULL;
}
@@ -582,12 +582,11 @@ _soap_env_get_body(SoapEnv * env)
body = nodeset->nodeTab[0]; /* body is <Body> */
xmlXPathFreeObject(xpathobj);
return body;
-
}
-char *
-soap_env_find_urn(SoapEnv * env)
+const char *
+soap_env_find_urn(struct SoapEnv * env)
{
xmlNsPtr ns;
xmlNodePtr body, node;
@@ -595,14 +594,14 @@ soap_env_find_urn(SoapEnv * env)
if (!(body = soap_env_get_body(env)))
{
log_verbose1("body is NULL");
- return 0;
+ return NULL;
}
/* node is the first child */
if (!(node = soap_xml_get_children(body)))
{
log_error1("No namespace found");
- return 0;
+ return NULL;
}
/* if (node->ns && node->ns->prefix) MRC 1/25/2006 */
@@ -611,7 +610,7 @@ soap_env_find_urn(SoapEnv * env)
ns = xmlSearchNs(body->doc, node, node->ns->prefix);
if (ns != NULL)
{
- return((char *) ns->href); /* namespace found! */
+ return ((char *) ns->href); /* namespace found! */
}
}
else
@@ -621,35 +620,32 @@ soap_env_find_urn(SoapEnv * env)
return(empty);
}
- return 0;
+ return NULL;
}
-char *
-soap_env_find_methodname(SoapEnv * env)
+const char *
+soap_env_find_methodname(struct SoapEnv * env)
{
xmlNodePtr body, node;
- body = soap_env_get_body(env);
- if (body == NULL)
- return 0;
+ if (!(body = soap_env_get_body(env)))
+ return NULL;
node = soap_xml_get_children(body); /* node is the first child */
if (node == NULL)
{
log_error1("No method found");
- return 0;
+ return NULL;
}
if (node->name == NULL)
{
log_error1("No methodname found");
- return 0;
+ return NULL;
}
- return((char *) node->name);
+ return ((char *) node->name);
}
-
-
diff --git a/libcsoap/soap-env.h b/libcsoap/soap-env.h
index 2da9528..b73bb38 100644
--- a/libcsoap/soap-env.h
+++ b/libcsoap/soap-env.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-env.h,v 1.16 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: soap-env.h,v 1.17 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -21,300 +21,306 @@
*
* Email: ayaz@jprogrammer.net
******************************************************************/
-#ifndef cSOAP_ENV_H
-#define cSOAP_ENV_H
+#ifndef __csoap_env_h
+#define __csoap_env_h
/**
- The SOAP envelope object.
+ *
+ * The SOAP envelope namespace
+ *
*/
-typedef struct _SoapEnv
+static const char * const soap_env_ns = "http://schemas.xmlsoap.org/soap/envelope/";
+
+/**
+ *
+ * The SOAP envelope object.
+ *
+ */
+struct SoapEnv
{
xmlNodePtr root; /** Pointer to the firts xml element (envelope) */
xmlNodePtr header;
xmlNodePtr body;
xmlNodePtr cur; /** Pointer to the current xml element. (stack) */
-} SoapEnv;
+};
+
+typedef void (*XmlSerializerCallback) (void * obj, const xmlChar *root_element_name, void (*OnStartElement) (const xmlChar * element_name, int attr_count, xmlChar ** keys, xmlChar ** values, void *userData), void (*OnCharacters) (const xmlChar * element_name, const xmlChar * chars, void *userData), void (*OnEndElement) (const xmlChar * element_name, void *userData), void *userdata);
#ifdef __cplusplus
extern "C" {
#endif
-
-/* -------------------------------------------------------------- */
-/* Envelope creation methods */
-/* -------------------------------------------------------------- */
-
/**
- Creates an envelope with a fault object.
-
- @param faultcode The fault code @see fault_code_t
- @param faultstring A fault message
- @param faultactor The fault actor (This can be NULL)
- @param detail The detail of the error (This can be NULL)
- @param out the result envelope out parameter like follows
- @returns H_OK if success
-
- <pre>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
- xmlns:xsi="..."
- xmlns:xsd="...">
- <SOAP-ENV:Body>
-
- <Fault>
- <faultcode>...</faultcode>
- <faultstring>...</faultstring>
- <faultactor>...</faultactor>
- <faultdetail>..</faultdetail>
- </Fault>
-
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
-
- </pre>
-
+ *
+ * Creates an envelope with a fault object.
+ *
+ * @param faultcode The fault code @see fault_code_t
+ * @param faultstring A fault message
+ * @param faultactor The fault actor (This can be NULL)
+ * @param detail The detail of the error (This can be NULL)
+ * @param out the result envelope out parameter like follows
+ *
+ * <pre>
+ * <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
+ * xmlns:xsi="..."
+ * xmlns:xsd="...">
+ * <SOAP-ENV:Body>
+ *
+ * <Fault>
+ * <faultcode>...</faultcode>
+ * <faultstring>...</faultstring>
+ * <faultactor>...</faultactor>
+ * <faultdetail>..</faultdetail>
+ * </Fault>
+ *
+ * </SOAP-ENV:Body>
+ * </SOAP-ENV:Envelope>
+ * </pre>
+ *
+ * @returns H_OK if success
+ *
+ * @see soap_fault_new
+ *
*/
-herror_t
-soap_env_new_with_fault(int faultcode,
- const char *faultstring,
- const char *faultactor,
- const char *detail, SoapEnv ** out);
+extern herror_t soap_env_new_with_fault(int faultCode, const char *faultString, const char *faultActor, const char *detail, struct SoapEnv **out);
/**
- Creates an envelope with a method to invoke a soap service.
- Use this function to create a client call.
-
- @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
-
- <pre>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
- xmlns:xsi="..."
- xmlns:xsd="...">
- <SOAP-ENV:Body>
-
- <m:[method] xmlns:m="[urn]">
- </m:[method]>
-
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
-
- </pre>
-
+ *
+ * Creates an envelope with a method to invoke a soap service.
+ * Use this function to create a client call.
+ *
+ * @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
+ *
+ * <pre>
+ * <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
+ * xmlns:xsi="..."
+ * xmlns:xsd="...">
+ * <SOAP-ENV:Body>
+ *
+ * <m:[method] xmlns:m="[urn]">
+ * </m:[method]>
+ *
+ * </SOAP-ENV:Body>
+ * </SOAP-ENV:Envelope>
+ *
+ * </pre>
+ *
*/
-herror_t
-soap_env_new_with_method(const char *urn, const char *method, SoapEnv ** out);
-
+extern herror_t soap_env_new_with_method(const char *urn, const char *method, struct SoapEnv ** out);
/**
- Creates a soap envelope with a response.
- Use this function to create a response envelope object
- for a request. This function is only relevant for soap
- service implementors.
-
- @see example csoap/simpleserver.c
-
- @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
-
- <pre>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
- xmlns:xsi="..."
- xmlns:xsd="...">
- <SOAP-ENV:Body>
-
- <m:[req-method]Response xmlns:m="[req-urn]">
- </m:[req-method]>
-
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
-
- </pre>
-
-
+ *
+ * Creates a soap envelope with a response.
+ * Use this function to create a response envelope object
+ * for a request. This function is only relevant for soap
+ * service implementors.
+ *
+ * @see example csoap/simpleserver.c
+ *
+ * @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
+ *
+ * <pre>
+ * <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
+ * xmlns:xsi="..."
+ * xmlns:xsd="...">
+ * <SOAP-ENV:Body>
+ *
+ * <m:[req-method]Response xmlns:m="[req-urn]">
+ * </m:[req-method]>
+ *
+ * </SOAP-ENV:Body>
+ * </SOAP-ENV:Envelope>
+ *
+ * </pre>
+ *
+ *
*/
-herror_t soap_env_new_with_response(SoapEnv * req, SoapEnv ** out);
-
+extern herror_t soap_env_new_with_response(struct SoapEnv * req, struct SoapEnv ** out);
/**
- Creates an envelope from a given libxml2 xmlDoc
- pointer.
-
- @param doc the xml document pointer
- @param out the output envelope object
- @returns H_OK if success
-
+ *
+ * Creates an envelope from a given libxml2 xmlDocPtr.
+ *
+ * @param doc the xml document pointer
+ * @param out the output envelope object
+ *
+ * @returns H_OK if success
+ *
*/
-herror_t soap_env_new_from_doc(xmlDocPtr doc, SoapEnv ** out);
-
+extern herror_t soap_env_new_from_doc(xmlDocPtr doc, struct SoapEnv ** out);
/**
- Create an envelop object from a string.
- The string must be in xml format.
-
- @param buffer The string to parse into a envelope.
- @param out the output envelope object
- @returns H_OK if success
+ *
+ * Create an envelop object from a string.
+ * The string must be in xml format.
+ *
+ * @param buffer The string to parse into a envelope.
+ * @param out the output envelope object
+ * @returns H_OK if success
*/
-herror_t soap_env_new_from_buffer(const char *buffer, SoapEnv ** out);
-
-
-/* --------------------------------------------------- */
-/* XML Serializer functions and typedefs */
-/* --------------------------------------------------- */
-
-typedef void (*XmlSerializerCallback) (void * obj, const xmlChar *root_element_name, void (*OnStartElement) (const xmlChar * element_name, int attr_count, xmlChar ** keys, xmlChar ** values, void *userData), void (*OnCharacters) (const xmlChar * element_name, const xmlChar * chars, void *userData), void (*OnEndElement) (const xmlChar * element_name, void *userData), void *userdata);
-
-/* ------------------------------------------------------ */
-/* XML build and stack function */
-/* ------------------------------------------------------ */
-
+extern herror_t soap_env_new_from_buffer(const char *buffer, struct SoapEnv ** out);
/**
- Adds a new xml node under the current parent.
-
- <pre>
- <m:[name] type=[type]>[value]</m:[name]>
- </pre>
-
- @param env The envelope object
- @param type Type of the parameter. Something like "xsd:string" or
- "xsd:int" or custom types.
- @param name Name of the xml node
- @param value Text value of the xml node
-
- @returns The added xmlNode pointer.
-
- @see tutorial
+ *
+ * Adds a new xml node under the current parent.
+ *
+ * <pre>
+ * <m:[name] type=[type]>[value]</m:[name]>
+ * </pre>
+ *
+ * @param env The envelope object
+ * @param type Type of the parameter. Something like "xsd:string" or
+ * "xsd:int" or custom types.
+ * @param name Name of the xml node
+ * @param value Text value of the xml node
+ *
+ * @returns The added xmlNode pointer.
+ *
+ * @see tutorial
+ *
*/
-xmlNodePtr
-soap_env_add_item(SoapEnv * env, const char *type,
- const char *name, const char *value);
-
+extern xmlNodePtr soap_env_add_item(struct SoapEnv * env, const char *type, const char *name, const char *value);
/**
- Adds attachment href node to the envelope current parent.
-
- <pre>
- <m:[name] href=[href]/>
- </pre>
-
- @param env The envelope object
- @param name Name of the xml node
- @param href href. A CID string filled by
- soap_ctx_add_attachment()
-
- @returns The added xmlNode pointer.
-
- @see soap_ctx_add_file tutorial
+ *
+ * Adds attachment href node to the envelope current parent.
+ *
+ * <pre>
+ * <m:[name] href=[href]/>
+ * </pre>
+ *
+ * @param env The envelope object
+ * @param name Name of the xml node
+ * @param href href. A CID string filled by
+ * soap_ctx_add_attachment()
+ *
+ * @returns The added xmlNode pointer.
+ *
+ * @see soap_ctx_add_file tutorial
*/
-xmlNodePtr
-soap_env_add_attachment(SoapEnv * env, const char *name, const char *href);
-
+extern xmlNodePtr
+soap_env_add_attachment(struct SoapEnv * env, const char *name, const char *href);
/**
- Serialize and adds obj to the envelope.
- TODO: Document this function !
- <br>
- <b>Important: </b>
-
+ *
+ * Serialize and adds obj to the envelope.
+ * TODO: Document this function !
+ * <br>
+ * <b>Important: </b>
+ *
*/
-void
-soap_env_add_custom(SoapEnv * env, void *obj, XmlSerializerCallback cb,
- const char *type, const char *name);
+extern void soap_env_add_custom(struct SoapEnv * env, void *obj, XmlSerializerCallback cb, const char *type, const char *name);
/**
- Same as soap_env_add_item() with c style arguments
- like in printf(). "value" is the format string.
- <br>
- <b>Important: </b> The totally length of value (incl. args)
- must be lower the 1054.
-
- @see soap_env_add_item
+ *
+ * Same as soap_env_add_item() with c style arguments
+ * like in printf(). "value" is the format string.
+ * <br>
+ * <b>Important: </b> The totally length of value (incl. args)
+ * must be lower the 1054.
+ *
+ * @see soap_env_add_item
*/
-xmlNodePtr
-soap_env_add_itemf(SoapEnv * env, const char *type,
- const char *name, const char *value, ...);
-
+extern xmlNodePtr
+soap_env_add_itemf(struct SoapEnv * env, const char *type, const char *name, const char *value, ...);
/**
- Push the current xml node in the soap envelope one level
- deeper. Here an example:
-
- <pre>
- soap_env_push_item(env, "my:custom", "Person");
- soap_env_add_item(env, "xsd:string", "name", "Mickey");
- soap_env_add_item(env, "xsd:string", "lastname", "Mouse");
- soap_env_pop_item(env);
- </pre>
-
- This will create the xml like follows.
-
- <pre>
- <Person type="my:custom">
- <name>Mickey</name>
- <lastname>Mouse</lastname>
- </Person>
- </pre>
-
- @returns The added xmlNode pointer.
-
- @see tutorial
+ *
+ * Push the current xml node in the soap envelope one level
+ * deeper. Here an example:
+ *
+ * <pre>
+ * soap_env_push_item(env, "my:custom", "Person");
+ * soap_env_add_item(env, "xsd:string", "name", "Mickey");
+ * soap_env_add_item(env, "xsd:string", "lastname", "Mouse");
+ * soap_env_pop_item(env);
+ * </pre>
+ *
+ * This will create the xml like follows.
+ *
+ * <pre>
+ * <Person type="my:custom">
+ * <name>Mickey</name>
+ * <lastname>Mouse</lastname>
+ * </Person>
+ * </pre>
+ *
+ * @returns The added xmlNode pointer.
+ *
+ * @see tutorial
+ *
*/
-xmlNodePtr soap_env_push_item(SoapEnv * env, const char *type, const char *name);
+extern xmlNodePtr soap_env_push_item(struct SoapEnv * env, const char *type, const char *name);
/**
- Sets the xml pointer 1 level higher.
-
- @param env The envelope object
- @see soap_env_push_item
+ *
+ * Sets the xml pointer 1 level higher.
+ *
+ * @param env The envelope object
+ *
+ * @see soap_env_push_item
*/
-void soap_env_pop_item(SoapEnv * env);
+extern void soap_env_pop_item(struct SoapEnv * env);
/**
- Free the envelope.
-
- @param env The envelope object
+ *
+ * Free the envelope.
+ *
+ * @param env The envelope object
+ *
*/
-void soap_env_free(SoapEnv * env);
-
-
-/* --------------------------------------------------- */
-/* XML node finder functions */
-/* --------------------------------------------------- */
-
+extern void soap_env_free(struct SoapEnv * env);
/**
- Gets the xml node pointing to SOAP Body.
+ *
+ * Gets the xml node pointing to SOAP Body.
+ *
*/
-xmlNodePtr soap_env_get_body(SoapEnv * env);
+extern xmlNodePtr soap_env_get_body(struct SoapEnv * env);
/**
- Get the xml node pointing to SOAP method (call)
+ *
+ * Get the xml node pointing to SOAP method (call)
+ *
*/
-xmlNodePtr soap_env_get_method(SoapEnv * env);
-
+extern xmlNodePtr soap_env_get_method(struct SoapEnv * env);
/**
- Get the xml node pointing to SOAP Fault
+ *
+ * Get the xml node pointing to SOAP Fault
+ *
*/
-xmlNodePtr soap_env_get_fault(SoapEnv * env);
-
+extern xmlNodePtr soap_env_get_fault(struct SoapEnv * env);
/**
- Get the xml node pointing to SOAP Header
+ *
+ * Get the xml node pointing to SOAP Header
+ *
*/
-xmlNodePtr soap_env_get_header(SoapEnv * env);
+extern xmlNodePtr soap_env_get_header(struct SoapEnv * env);
+/**
+ *
+ * Get the URN of the message.
+ *
+ */
+extern const char *soap_env_find_urn(struct SoapEnv * env);
-char * soap_env_find_urn(SoapEnv * env);
-char * soap_env_find_methodname(SoapEnv * env);
+/**
+ *
+ * Get the method of the message.
+ *
+ */
+extern const char *soap_env_find_methodname(struct SoapEnv * env);
#ifdef __cplusplus
}
diff --git a/libcsoap/soap-fault.c b/libcsoap/soap-fault.c
index 6781e1e..242a51a 100644
--- a/libcsoap/soap-fault.c
+++ b/libcsoap/soap-fault.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-fault.c,v 1.12 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-fault.c,v 1.13 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -29,11 +29,17 @@
#include <string.h>
#endif
+#include <libxml/xpath.h>
+
#include <nanohttp/nanohttp-common.h>
#include <nanohttp/nanohttp-logging.h>
#include "soap-xml.h"
-// #include "soap-server.h"
+#include "soap-env.h"
+#include "soap-ctx.h"
+#include "soap-service.h"
+#include "soap-router.h"
+#include "soap-server.h"
#include "soap-fault.h"
/*
diff --git a/libcsoap/soap-nhttp.c b/libcsoap/soap-nhttp.c
index a49800b..b8b0e35 100644
--- a/libcsoap/soap-nhttp.c
+++ b/libcsoap/soap-nhttp.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-nhttp.c,v 1.1 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-nhttp.c,v 1.2 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -37,38 +37,30 @@
#include <errno.h>
#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef WIN32
-#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
-#endif
-
#include <libxml/tree.h>
#include <libxml/uri.h>
#include <nanohttp/nanohttp-common.h>
#include <nanohttp/nanohttp-logging.h>
-
-#include <nanohttp/nanohttp-socket.h>
#include <nanohttp/nanohttp-stream.h>
+
#include <nanohttp/nanohttp-request.h>
#include <nanohttp/nanohttp-response.h>
#include <nanohttp/nanohttp-client.h>
#include <nanohttp/nanohttp-server.h>
-#include "soap-admin.h"
#include "soap-fault.h"
#include "soap-env.h"
#include "soap-ctx.h"
#include "soap-service.h"
-#include "soap-router.h"
-#include "soap-server.h"
#include "soap-client.h"
+#include "soap-transport.h"
#include "soap-addressing.h"
+#include "soap-admin.h"
+#include "soap-wsil.h"
+
#include "soap-nhttp.h"
static herror_t
@@ -98,7 +90,7 @@ _soap_nhttp_send_fault(httpd_conn_t *conn, const char *message)
xmlDocPtr doc;
herror_t ret;
- doc = soap_fault_build(SOAP_FAULT_SENDER, message, soap_server_get_name(), NULL);
+ doc = soap_fault_build(SOAP_FAULT_SENDER, message, soap_transport_get_name(), NULL);
ret = _soap_nhttp_send_document(conn, doc);
xmlFreeDoc(doc);
@@ -106,7 +98,7 @@ _soap_nhttp_send_fault(httpd_conn_t *conn, const char *message)
}
static herror_t
-_soap_nhttp_send(httpd_conn_t *conn, SoapCtx *context, SoapEnv *env)
+_soap_nhttp_send(httpd_conn_t *conn, struct SoapCtx *context, struct SoapEnv *env)
{
return _soap_nhttp_send_document(conn, env->root->doc);
}
@@ -116,7 +108,7 @@ _soap_nhttp_xml_io_read(void *ctx, char *buffer, int len)
{
int ret;
- http_input_stream_t *in = (http_input_stream_t *)ctx;
+ struct http_input_stream_t *in = (struct http_input_stream_t *)ctx;
if (!http_input_stream_is_ready(in))
return 0;
@@ -134,7 +126,7 @@ _soap_nhttp_xml_io_close(void *ctx)
}
static herror_t
-_soap_nhttp_env_new_from_stream(http_input_stream_t *in, SoapEnv **out)
+_soap_nhttp_env_new_from_stream(struct http_input_stream_t *in, struct SoapEnv **out)
{
xmlDocPtr doc;
@@ -143,18 +135,18 @@ _soap_nhttp_env_new_from_stream(http_input_stream_t *in, SoapEnv **out)
return in->err;
if (doc == NULL)
- return herror_new("_soap_nhttp_env_new_from_stream", XML_ERROR_PARSE, "Trying to parse not valid xml");
+ return herror_new("_soap_nhttp_env_new_from_stream", XML_ERROR_PARSE, "Trying to parse invalid XML");
return soap_env_new_from_doc(doc, out);
}
static void
-soap_nhttp_process(httpd_conn_t * conn, hrequest_t * req)
+soap_nhttp_process(httpd_conn_t * conn, struct hrequest_t * req)
{
char *action;
- SoapEnv *env;
- SoapCtx *ctx;
- SoapCtx *response;
+ struct SoapEnv *env;
+ struct SoapCtx *ctx;
+ struct SoapCtx *response;
herror_t err;
/* if (req->method == HTTP_REQUEST_GET && router->wsdl)
@@ -203,14 +195,14 @@ soap_nhttp_process(httpd_conn_t * conn, hrequest_t * req)
xmlFree(uri);
}
- soap_xml_doc_print(ctx->env->root->doc);
+ xmlDocDump(stdout, ctx->env->root->doc);
soap_ctx_add_files(ctx, req->attachments);
/* only local part is interesting... */
soap_addressing_set_to_address_string(ctx->env, req->path);
- soap_server_process(ctx, &response);
+ soap_transport_process(ctx, &response);
_soap_nhttp_send_document(conn, response->env->root->doc);
@@ -227,13 +219,22 @@ soap_nhttp_server_init_args(int argc, char **argv)
herror_t err;
if ((err = httpd_init(argc, argv)) != H_OK)
+ {
+ log_error2("httpd_init failed (%s)", herror_message(err));
+ return err;
+ }
+
+ if ((err = soap_wsil_init_args(argc, argv)) != H_OK)
+ {
+ log_error2("soap_wsil_init_args failed (%s)", herror_message(err));
return err;
-
+ }
+
return soap_admin_init_args(argc, argv);
}
static herror_t
-_soap_nhttp_client_build_result(hresponse_t * res, SoapEnv ** env)
+_soap_nhttp_client_build_result(hresponse_t * res, struct SoapEnv ** env)
{
log_verbose2("Building result (%p)", res);
@@ -253,7 +254,7 @@ _soap_nhttp_client_build_result(hresponse_t * res, SoapEnv ** env)
}
static herror_t
-_soap_nhttp_client_invoke(void *unused, SoapCtx *request, SoapCtx **response)
+_soap_nhttp_client_invoke(void *unused, struct SoapCtx *request, struct SoapCtx **response)
{
herror_t status;
@@ -263,7 +264,7 @@ _soap_nhttp_client_invoke(void *unused, SoapCtx *request, SoapCtx **response)
char tmp[15];
char *action;
char *url;
- SoapEnv *res_env;
+ struct SoapEnv *res_env;
/* Transport variables */
httpc_conn_t *conn;
@@ -284,7 +285,7 @@ _soap_nhttp_client_invoke(void *unused, SoapCtx *request, SoapCtx **response)
xmlNodeDump(buffer, request->env->root->doc, request->env->root, 1, 0);
content = (char *) xmlBufferContent(buffer);
- soap_xml_doc_print(request->env->root->doc);
+ xmlDocDump(stdout, request->env->root->doc);
/* Transport via HTTP */
if (!(conn = httpc_new()))
@@ -412,6 +413,7 @@ _soap_nhttp_client_invoke(void *unused, SoapCtx *request, SoapCtx **response)
return H_OK;
}
+
herror_t
soap_nhttp_client_init_args(int argc, char **argv)
{
@@ -422,14 +424,18 @@ soap_nhttp_client_init_args(int argc, char **argv)
}
herror_t
-soap_nhttp_register_router(SoapRouter * router, const char *context)
+soap_nhttp_register(const void *data)
{
+ herror_t status;
+ const char *context;
+
+ context = (char *)data;
- if (!httpd_register_secure(context, soap_nhttp_process, router->auth))
+ if ((status = httpd_register(context, soap_nhttp_process)) != H_OK)
{
- return /* XXX */ H_OK;
+ log_error2("httpd_register_secure failed (%s)", herror_message(status));
+ return status;
}
-
return H_OK;
}
@@ -447,7 +453,6 @@ soap_nhttp_server_destroy(void)
return;
}
-
void
soap_nhttp_client_destroy(void)
{
diff --git a/libcsoap/soap-nhttp.h b/libcsoap/soap-nhttp.h
index fb060b5..acb5dc3 100644
--- a/libcsoap/soap-nhttp.h
+++ b/libcsoap/soap-nhttp.h
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-nhttp.h,v 1.1 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-nhttp.h,v 1.2 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2007 Heiko Ronsdorf
@@ -47,13 +47,13 @@ extern herror_t soap_nhttp_server_init_args(int argc, char **argv);
extern herror_t soap_nhttp_server_run(void);
extern void soap_nhttp_server_destroy(void);
-extern herror_t soap_nhttp_register_router(SoapRouter *router, const char *context);
+extern herror_t soap_nhttp_register(const void *data);
extern short soap_nhttp_get_port(void);
extern const char *soap_nhttp_get_protocol(void);
extern herror_t soap_nhttp_client_init_args(int argc, char **argv);
-extern herror_t soap_nhttp_client_invoke(void *unused, SoapCtx *req, SoapCtx **res);
+extern herror_t soap_nhttp_client_invoke(void *unused, struct SoapCtx *req, struct SoapCtx **res);
extern void soap_nhttp_client_destroy(void);
#ifdef __cplusplus
diff --git a/libcsoap/soap-nudp.c b/libcsoap/soap-nudp.c
index 985cfd8..4520631 100644
--- a/libcsoap/soap-nudp.c
+++ b/libcsoap/soap-nudp.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-nudp.c,v 1.1 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-nudp.c,v 1.2 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -33,18 +33,10 @@
#include <errno.h>
#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
#include <libxml/tree.h>
#include <libxml/uri.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
-#include <nanohttp/nanohttp-request.h>
-#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-logging.h>
#include "soap-fault.h"
@@ -62,7 +54,7 @@ soap_nudp_server_init_args(int argc, char **argv)
}
herror_t
-soap_nudp_register_router(SoapRouter *router, const char *context)
+soap_nudp_register(const void *data)
{
return H_OK;
}
@@ -86,7 +78,7 @@ soap_nudp_client_init_args(int argc, char **argv)
}
herror_t
-soap_nudp_client_invoke(SoapCtx *req, SoapCtx **res)
+soap_nudp_client_invoke(struct SoapCtx *req, struct SoapCtx **res)
{
return H_OK;
}
diff --git a/libcsoap/soap-nudp.h b/libcsoap/soap-nudp.h
index 73bc612..9b703ae 100644
--- a/libcsoap/soap-nudp.h
+++ b/libcsoap/soap-nudp.h
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-nudp.h,v 1.1 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-nudp.h,v 1.2 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2007 Heiko Ronsdorf
@@ -33,11 +33,11 @@ extern herror_t soap_nudp_server_run(void);
extern void soap_nudp_server_destroy(void);
#ifdef __CSOAP_INTERNAL
-extern herror_t soap_nudp_register_router(SoapRouter *router, const char *context);
+extern herror_t soap_nudp_register(const void *data);
#endif
extern herror_t soap_nudp_client_init_args(int argc, char **argv);
-extern herror_t soap_nudp_client_invoke(SoapCtx *req, SoapCtx **res);
+extern herror_t soap_nudp_client_invoke(struct SoapCtx *req, struct SoapCtx **res);
extern void soap_nudp_client_destroy(void);
#ifdef __cplusplus
diff --git a/libcsoap/soap-router.c b/libcsoap/soap-router.c
index 0a9ee63..c0891f6 100644
--- a/libcsoap/soap-router.c
+++ b/libcsoap/soap-router.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-router.c,v 1.12 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-router.c,v 1.13 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -33,10 +33,6 @@
#include <string.h>
#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
@@ -44,36 +40,31 @@
#include <libxml/tree.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
-#include <nanohttp/nanohttp-request.h>
-#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-logging.h>
#include "soap-fault.h"
-#include "soap-env.h"
#include "soap-ctx.h"
#include "soap-service.h"
#include "soap-router.h"
-SoapRouter *
+struct SoapRouter *
soap_router_new(void)
{
- SoapRouter *router;
+ struct SoapRouter *router;
- if (!(router = (SoapRouter *) malloc(sizeof(SoapRouter))))
+ if (!(router = (struct SoapRouter *) malloc(sizeof(struct SoapRouter))))
{
log_error2("malloc failed (%s)", strerror(errno));
return NULL;
}
- memset(router, 0, sizeof(SoapRouter));
+ memset(router, 0, sizeof(struct SoapRouter));
return router;
}
herror_t
-soap_router_register_service(SoapRouter *router, SoapServiceFunc func, const char *method, const char *urn)
+soap_router_register_service(struct SoapRouter *router, SoapServiceFunc func, const char *method, const char *urn)
{
SoapService *service;
@@ -97,7 +88,7 @@ soap_router_register_service(SoapRouter *router, SoapServiceFunc func, const cha
}
void
-soap_router_register_security(SoapRouter * router, httpd_auth auth)
+soap_router_register_security(struct SoapRouter * router, soap_auth auth)
{
router->auth = auth;
@@ -105,18 +96,18 @@ soap_router_register_security(SoapRouter * router, httpd_auth auth)
}
void
-soap_router_register_description(SoapRouter * router, xmlDocPtr wsdl)
+soap_router_register_description(struct SoapRouter * router, xmlDocPtr description)
{
- if (router->wsdl)
- xmlFreeDoc(router->wsdl);
+ if (router->description)
+ xmlFreeDoc(router->description);
- router->wsdl = xmlCopyDoc(wsdl, 1);
+ router->description = xmlCopyDoc(description, 1);
return;
}
herror_t
-soap_router_register_default_service(SoapRouter *router, SoapServiceFunc func, const char *method, const char *urn) {
+soap_router_register_default_service(struct SoapRouter *router, SoapServiceFunc func, const char *method, const char *urn) {
SoapService *service;
@@ -139,7 +130,7 @@ soap_router_register_default_service(SoapRouter *router, SoapServiceFunc func, c
}
SoapService *
-soap_router_find_service(SoapRouter *router, const char *urn, const char *method)
+soap_router_find_service(struct SoapRouter *router, const char *urn, const char *method)
{
SoapServiceNode *node;
@@ -180,7 +171,7 @@ soap_router_find_service(SoapRouter *router, const char *urn, const char *method
}
void
-soap_router_free(SoapRouter * router)
+soap_router_free(struct SoapRouter * router)
{
SoapServiceNode *node;
log_verbose2("enter: router=%p", router);
@@ -197,8 +188,8 @@ soap_router_free(SoapRouter * router)
free(router->service_head);
router->service_head = node;
}
- if (router->wsdl)
- xmlFreeDoc(router->wsdl);
+ if (router->description)
+ xmlFreeDoc(router->description);
free(router);
log_verbose1("leave with success");
diff --git a/libcsoap/soap-router.h b/libcsoap/soap-router.h
index da6199f..69f0e86 100644
--- a/libcsoap/soap-router.h
+++ b/libcsoap/soap-router.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-router.h,v 1.10 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: soap-router.h,v 1.11 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -25,72 +25,103 @@
#define __csoap_router_h
/**
- The router object. A router can store a set of
- services. A service is a C function.
+ *
+ * Authentication callback function for a cSOAP service.
+ *
+ */
+typedef int (*soap_auth) (struct SoapEnv *request, const char *user, const char *pass);
+
+/**
+ *
+ * The router object. A router can store a set of
+ * services. A service is a C function.
+ *
*/
-typedef struct _SoapRouter
+struct SoapRouter
{
SoapServiceNode *service_head;
SoapServiceNode *service_tail;
SoapService *default_service;
- httpd_auth auth;
- xmlDocPtr wsdl;
-} SoapRouter;
+ soap_auth auth;
+ xmlDocPtr description;
+};
#ifdef __cplusplus
extern "C" {
#endif
/**
- Creates a new router object. Create a router if
- you are implementing a soap server. Then register
- the services to this router.
- <P>A router points also to http url context.
-
- @returns Soap router
- @see soap_router_free
+ *
+ * Creates a new router object. Create a router if
+ * you are implementing a soap server. Then register
+ * the services to this router.
+ * <P>A router points also to http url context.
+ *
+ * @returns Soap router
+ *
+ * @see soap_router_free
+ *
*/
-extern SoapRouter *soap_router_new(void);
-
+extern struct SoapRouter *soap_router_new(void);
/**
- Registers a SOAP service (in this case a C function)
- to the router.
-
- @param router The router object
- @param func Function to register as a soap service
- @param method Method name to call the function from
- the client side.
- @param urn The urn for this service
+ *
+ * Registers a SOAP service (in this case a C function)
+ * to the router.
+ *
+ * @param router The router object
+ * @param func Function to register as a soap service
+ * @param method Method name to call the function from
+ * the client side.
+ * @param urn The urn for this service
+ *
*/
-extern herror_t soap_router_register_service(SoapRouter * router,
- SoapServiceFunc func,
- const char *method, const char *urn);
-
-extern herror_t soap_router_register_default_service(SoapRouter * router, SoapServiceFunc func, const char *method, const char *urn);
-
-
-extern void soap_router_register_description(SoapRouter *router, xmlDocPtr doc);
-
-extern void soap_router_register_security(SoapRouter *router, httpd_auth auth);
+extern herror_t soap_router_register_service(struct SoapRouter *router, SoapServiceFunc func, const char *method, const char *urn);
/**
- Searches for a registered soap service.
+ *
+ * Register a default service for the router.
+ *
+ */
+extern herror_t soap_router_register_default_service(struct SoapRouter * router, SoapServiceFunc func, const char *method, const char *urn);
- @param router The router object
- @param urn URN of the service
- @param method The name under which the service was registered.
+/**
+ *
+ * Register a service description for the router.
+ *
+ */
+extern void soap_router_register_description(struct SoapRouter *router, xmlDocPtr doc);
- @return The service if found, NULL otherwise.
+/**
+ *
+ * Register a security provider for the router.
+ *
*/
-extern SoapService *soap_router_find_service(SoapRouter * router, const char *urn, const char *method);
+extern void soap_router_register_security(struct SoapRouter *router, soap_auth auth);
/**
- Frees the router object.
+ *
+ * Searches for a registered soap service.
+ *
+ * @param router The router object
+ * @param urn URN of the service
+ * @param method The name under which the service was registered.
+ *
+ * @return The service if found, NULL otherwise.
+ *
+ */
+extern SoapService *soap_router_find_service(struct SoapRouter *router, const char *urn, const char *method);
- @param router The router object to free
+/**
+ *
+ * Frees the router object.
+ *
+ * @param router The router object to free
+ *
+ * @see soap_router_new
+ *
*/
-extern void soap_router_free(SoapRouter * router);
+extern void soap_router_free(struct SoapRouter * router);
#ifdef __cplusplus
}
diff --git a/libcsoap/soap-server.c b/libcsoap/soap-server.c
index 11dbf53..d8d996d 100644
--- a/libcsoap/soap-server.c
+++ b/libcsoap/soap-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-server.c,v 1.29 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-server.c,v 1.30 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -25,10 +25,6 @@
#include <config.h>
#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
@@ -41,20 +37,10 @@
#include <errno.h>
#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef WIN32
-#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
-#endif
-
#include <libxml/tree.h>
#include <libxml/uri.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
#include <nanohttp/nanohttp-request.h>
#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-logging.h>
@@ -73,7 +59,7 @@ static SoapRouterNode *head = NULL;
static SoapRouterNode *tail = NULL;
static SoapRouterNode *
-router_node_new(SoapRouter * router, const char *context, SoapRouterNode * next)
+router_node_new(struct SoapRouter * router, const char *context, SoapRouterNode * next)
{
const char *noname = "/lost_found";
SoapRouterNode *node;
@@ -100,7 +86,13 @@ router_node_new(SoapRouter * router, const char *context, SoapRouterNode * next)
return node;
}
-SoapRouter *
+static herror_t
+_soap_server_env_new_with_fault(const char *fault_string, const char *detail, struct SoapEnv **out)
+{
+ return soap_env_new_with_fault(SOAP_FAULT_RECEIVER, fault_string, soap_server_get_name(), detail, out);
+}
+
+struct SoapRouter *
soap_server_find_router(const char *context)
{
SoapRouterNode *node;
@@ -114,25 +106,19 @@ soap_server_find_router(const char *context)
return NULL;
}
-static herror_t
-_soap_server_env_new_with_fault(const char *fault_string, const char *detail, SoapEnv **out)
-{
- return soap_env_new_with_fault(SOAP_FAULT_RECEIVER, fault_string, soap_server_get_name(), detail, out);
-}
-
herror_t
-soap_server_process(SoapCtx *request, SoapCtx **response)
+soap_server_process(struct SoapCtx *request, struct SoapCtx **response)
{
char buffer[1054];
- char *urn;
- char *method;
+ const char *urn;
+ const char *method;
char *to;
- SoapRouter *router;
+ struct SoapRouter *router;
SoapService *service;
herror_t err;
log_verbose1("processing");
- soap_xml_doc_print(request->env->root->doc);
+ xmlDocDump(stdout, request->env->root->doc);
*response = soap_ctx_new(NULL);
@@ -196,12 +182,15 @@ soap_server_process(SoapCtx *request, SoapCtx **response)
}
herror_t
-soap_server_init_args(int argc, char *argv[])
+soap_server_init_args(int argc, char **argv)
{
herror_t status;
if ((status = soap_transport_server_init_args(argc, argv)) != H_OK)
+ {
+ log_error2("soap_transport_server_init_args failed (%s)", herror_message(status));
return status;
+ }
return H_OK;
}
@@ -213,12 +202,15 @@ soap_server_get_name(void)
}
herror_t
-soap_server_register_router(SoapRouter *router, const char *context)
+soap_server_register_router(struct SoapRouter *router, const char *context)
{
herror_t status;
- if ((status = soap_transport_register_router(router, context)) != H_OK)
+ if ((status = soap_transport_register(context)) != H_OK)
+ {
+ log_error2("soap_transport_register failed (%s)", herror_message(status));
return status;
+ }
if (tail == NULL)
{
diff --git a/libcsoap/soap-server.h b/libcsoap/soap-server.h
index 70fc6aa..cafa9a5 100644
--- a/libcsoap/soap-server.h
+++ b/libcsoap/soap-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-server.h,v 1.12 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: soap-server.h,v 1.13 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -43,7 +43,6 @@ extern "C" {
*/
herror_t soap_server_init_args(int argc, char **argv);
-
/**
*
* Register a router to the soap server.
@@ -59,8 +58,13 @@ herror_t soap_server_init_args(int argc, char **argv);
* @see soap_router_register_service
*
*/
-extern herror_t soap_server_register_router(SoapRouter * router, const char *context);
+extern herror_t soap_server_register_router(struct SoapRouter * router, const char *context);
+/**
+ *
+ * Returns an URI name of the server.
+ *
+ */
extern const char *soap_server_get_name(void);
/**
@@ -69,6 +73,7 @@ extern const char *soap_server_get_name(void);
*
* @see httpd_run
* @see udpd_run
+ * @see smptd_run
*
*/
extern herror_t soap_server_run(void);
@@ -88,16 +93,16 @@ extern void soap_server_destroy(void);
typedef struct _SoapRouterNode
{
char *context;
- SoapRouter *router;
+ struct SoapRouter *router;
struct _SoapRouterNode *next;
} SoapRouterNode;
-extern SoapRouter *soap_server_find_router(const char *context);
+extern struct SoapRouter *soap_server_find_router(const char *context);
extern SoapRouterNode * soap_server_get_routers(void);
-extern herror_t soap_server_process(SoapCtx *request, SoapCtx **response);
+extern herror_t soap_server_process(struct SoapCtx *request, struct SoapCtx **response);
#endif
diff --git a/libcsoap/soap-service.c b/libcsoap/soap-service.c
index 7a422c5..241eb82 100644
--- a/libcsoap/soap-service.c
+++ b/libcsoap/soap-service.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-service.c,v 1.10 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-service.c,v 1.11 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -55,6 +55,7 @@
#include "soap-env.h"
#include "soap-ctx.h"
#include "soap-service.h"
+#include "soap-router.h"
SoapServiceNode *
soap_service_node_new(SoapService * service, SoapServiceNode * next)
diff --git a/libcsoap/soap-service.h b/libcsoap/soap-service.h
index f507d77..e999e2e 100644
--- a/libcsoap/soap-service.h
+++ b/libcsoap/soap-service.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-service.h,v 1.7 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: soap-service.h,v 1.8 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -24,7 +24,7 @@
#ifndef __csoap_service_h
#define __csoap_service_h
-typedef herror_t(*SoapServiceFunc) (SoapCtx *, SoapCtx *);
+typedef herror_t (*SoapServiceFunc)(struct SoapCtx *request, struct SoapCtx *response);
typedef struct _SoapService
{
@@ -45,12 +45,11 @@ typedef struct _SoapServiceNode
extern "C" {
#endif
-SoapServiceNode *soap_service_node_new(SoapService * service,
- SoapServiceNode * next);
+extern SoapServiceNode *soap_service_node_new(SoapService * service, SoapServiceNode * next);
-SoapService *soap_service_new(const char *urn, const char *method, SoapServiceFunc f);
+extern SoapService *soap_service_new(const char *urn, const char *method, SoapServiceFunc f);
-void soap_service_free(SoapService * service);
+extern void soap_service_free(SoapService * service);
#ifdef __cplusplus
}
diff --git a/libcsoap/soap-transport.c b/libcsoap/soap-transport.c
index 6c84e35..1fc2c51 100644
--- a/libcsoap/soap-transport.c
+++ b/libcsoap/soap-transport.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-transport.c,v 1.1 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-transport.c,v 1.2 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2007 Heiko Ronsdorf
@@ -33,18 +33,10 @@
#include <string.h>
#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
#include <libxml/tree.h>
#include <libxml/uri.h>
#include <nanohttp/nanohttp-common.h>
-#include <nanohttp/nanohttp-socket.h>
-#include <nanohttp/nanohttp-stream.h>
-#include <nanohttp/nanohttp-request.h>
-#include <nanohttp/nanohttp-server.h>
#include <nanohttp/nanohttp-logging.h>
#include "soap-fault.h"
@@ -71,12 +63,6 @@ struct soap_transport
static struct soap_transport *head = NULL;
static char soap_transport_name[512] = "not set";
-herror_t
-soap_transport_receive(SoapCtx *request, SoapCtx **response)
-{
- return soap_server_process(request, response);
-}
-
static struct soap_transport *
_soap_transport_new(const char *scheme, void *data, msg_exchange invoke)
{
@@ -114,6 +100,13 @@ _soap_transport_destroy(struct soap_transport *transport)
return ret;
}
+
+herror_t
+soap_transport_process(struct SoapCtx *request, struct SoapCtx **response)
+{
+ return soap_server_process(request, response);
+}
+
herror_t
soap_transport_server_init_args(int argc, char **argv)
{
@@ -121,27 +114,39 @@ soap_transport_server_init_args(int argc, char **argv)
char hostname[256];
if ((status = soap_nhttp_server_init_args(argc, argv)) != H_OK)
+ {
+ log_error2("soap_nhttp_server_init_args failed (%s)", herror_message(status));
return status;
+ }
if ((status = soap_nudp_server_init_args(argc, argv)) != H_OK)
+ {
+ log_error2("soap_nudp_server_init_args failed (%s)", herror_message(status));
return status;
+ }
gethostname(hostname, 256);
- sprintf(soap_transport_name, "%s://%s:%i/csoap", soap_nhttp_get_protocol(), hostname, soap_nhttp_get_port());
+ sprintf(soap_transport_name, "%s://%s:%i", soap_nhttp_get_protocol(), hostname, soap_nhttp_get_port());
return H_OK;
}
herror_t
-soap_transport_register_router(SoapRouter *router, const char *context)
+soap_transport_register(const void *data)
{
herror_t status;
- if ((status = soap_nhttp_register_router(router, context)) != H_OK)
+ if ((status = soap_nhttp_register(data)) != H_OK)
+ {
+ log_error2("soap_nhttp_register failed (%s)", herror_message(status));
return status;
+ }
- if ((status = soap_nudp_register_router(router, context)) != H_OK)
+ if ((status = soap_nudp_register(data)) != H_OK)
+ {
+ log_error2("soap_nudp_register failed (%s)", herror_message(status));
return status;
+ }
return H_OK;
}
@@ -155,7 +160,7 @@ soap_transport_add(const char *scheme, void *data, msg_exchange invoke)
if (!(transport = _soap_transport_new(scheme, data, invoke)))
{
log_error1("_soap_transport_new failed");
- return H_OK;
+ return herror_new("soap_transport_add", 0, "_soap_transport_new failed");
}
if (head == NULL)
@@ -177,10 +182,16 @@ soap_transport_server_run(void)
herror_t status;
if ((status = soap_nhttp_server_run()) != H_OK)
+ {
+ log_error2("soap_nhttp_server_run failed (%s)", herror_message(status));
return status;
+ }
if ((status = soap_nudp_server_run()) != H_OK)
+ {
+ log_error2("soap_nudp_server_run failed (%s)", herror_message(status));
return status;
+ }
return H_OK;
}
@@ -207,23 +218,29 @@ soap_transport_client_init_args(int argc, char **argv)
herror_t status;
if ((status = soap_nhttp_client_init_args(argc, argv)) != H_OK)
+ {
+ log_error2("soap_nhttp_client_init_args failed (%s)", herror_message(status));
return status;
+ }
if ((status = soap_nudp_client_init_args(argc, argv)) != H_OK)
+ {
+ log_error2("soap_nudp_client_init_args failed (%s)", herror_message(status));
return status;
+ }
return H_OK;
}
herror_t
-soap_transport_client_invoke(SoapCtx *request, SoapCtx **response)
+soap_transport_client_invoke(struct SoapCtx *request, struct SoapCtx **response)
{
struct soap_transport *walker;
herror_t ret;
xmlURI *dest;
log_verbose1(__FUNCTION__);
- soap_xml_doc_print(request->env->root->doc);
+ xmlDocDump(stdout, request->env->root->doc);
dest = soap_addressing_get_to_address(request->env);
diff --git a/libcsoap/soap-transport.h b/libcsoap/soap-transport.h
index 8c31454..5cc3e68 100644
--- a/libcsoap/soap-transport.h
+++ b/libcsoap/soap-transport.h
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-transport.h,v 1.1 2006/11/21 20:59:02 m0gg Exp $
+* $Id: soap-transport.h,v 1.2 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2007 Heiko Ronsdorf
@@ -25,7 +25,7 @@
#define __csoap_transport_h
#ifdef __CSOAP_INTERNAL
-typedef herror_t (*msg_exchange)(void *data, SoapCtx *request, SoapCtx **response);
+typedef herror_t (*msg_exchange)(void *data, struct SoapCtx *request, struct SoapCtx **response);
#ifdef __cplusplus
extern "C" {
@@ -38,13 +38,13 @@ extern void soap_transport_server_destroy(void);
extern const char *soap_transport_get_name(void);
extern herror_t soap_transport_add(const char *protocol, void *data, msg_exchange invoke);
extern herror_t soap_transport_remove(const char *protocol, void *data);
-extern herror_t soap_transport_register_router(SoapRouter *router, const char *context);
+extern herror_t soap_transport_register(const void *data);
-extern herror_t soap_transport_send(SoapCtx *request, SoapCtx **response);
-extern herror_t soap_transport_receive(SoapCtx *request, SoapCtx **response);
+extern herror_t soap_transport_send(struct SoapCtx *request, struct SoapCtx **response);
+extern herror_t soap_transport_process(struct SoapCtx *request, struct SoapCtx **response);
extern herror_t soap_transport_client_init_args(int argc, char **argv);
-extern herror_t soap_transport_client_invoke(SoapCtx *req, SoapCtx **res);
+extern herror_t soap_transport_client_invoke(struct SoapCtx *req, struct SoapCtx **res);
extern void soap_transport_client_destroy(void);
#ifdef __cplusplus
diff --git a/libcsoap/soap-wsil.c b/libcsoap/soap-wsil.c
index ac4add8..7e0a7f2 100644
--- a/libcsoap/soap-wsil.c
+++ b/libcsoap/soap-wsil.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-wsil.c,v 1.1 2006/11/23 13:20:46 m0gg Exp $
+* $Id: soap-wsil.c,v 1.2 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -34,14 +34,11 @@
#endif
#include <libxml/tree.h>
-#include <libxml/uri.h>
#include <nanohttp/nanohttp-common.h>
#include <nanohttp/nanohttp-request.h>
#include <nanohttp/nanohttp-server.h>
-#include "soap-fault.h"
-#include "soap-env.h"
#include "soap-ctx.h"
#include "soap-service.h"
#include "soap-router.h"
@@ -49,38 +46,40 @@
#include "soap-wsil.h"
static void
-_soap_wsil_list_services(httpd_conn_t *conn, struct SoapRouter *router)
+_soap_wsil_list_routers(httpd_conn_t *conn)
{
- SoapServiceNode *node;
+ SoapRouterNode *node;
- for (node=router->service_head; node; node=node->next)
- {
+ for (node=soap_server_get_routers(); node; node=node->next)
+ {
http_output_stream_write_string(conn->out,
"<service>"
"<description "
- "referencedNamespace=\"http://schemas.xmlsoap.org/wsdl/\" "
"location=\"");
http_output_stream_write_string(conn->out, soap_transport_get_name());
- http_output_stream_write_string(conn->out, node->service->method);
+ http_output_stream_write_string(conn->out, node->context);
+ http_output_stream_write_string(conn->out,
+ "\" "
+ "referencedNamespace=\"");
+ if (node->router->description)
+ {
+ xmlNodePtr root;
+
+ root = xmlDocGetRootElement(node->router->description);
+ http_output_stream_write_string(conn->out, root->ns->href);
+ }
+ else
+ {
+ http_output_stream_write_string(conn->out, "http://schemas.xmlsoap.org/wsdl/");
+ }
http_output_stream_write_string(conn->out,
"\" />"
- "</service>\n");
+ "</service>");
}
return;
}
static void
-_soap_wsil_list_routers(httpd_conn_t *conn)
-{
- SoapRouterNode *node;
-
- for (node=soap_server_get_routers(); node; node=node->next)
- _soap_wsil_list_services(conn, node->router);
-
- return;
-}
-
-static void
_soap_wsil_handle_get(httpd_conn_t * conn, struct hrequest_t * req)
{
httpd_set_header(conn, HEADER_CONTENT_TYPE, "text/xml");
diff --git a/libcsoap/soap-xml.c b/libcsoap/soap-xml.c
index 801bdd1..e4cc894 100644
--- a/libcsoap/soap-xml.c
+++ b/libcsoap/soap-xml.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-xml.c,v 1.11 2006/07/09 16:24:19 snowdrop Exp $
+* $Id: soap-xml.c,v 1.12 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -25,6 +25,9 @@
#include <config.h>
#endif
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
#include <nanohttp/nanohttp-logging.h>
#include "soap-xml.h"
@@ -69,7 +72,6 @@ soap_xml_get_next(xmlNodePtr param)
return node;
}
-
xmlXPathObjectPtr
soap_xpath_eval(xmlDocPtr doc, const char *xpath)
{
@@ -88,62 +90,6 @@ soap_xpath_eval(xmlDocPtr doc, const char *xpath)
return result;
}
-
-int
-soap_xpath_foreach(xmlDocPtr doc, const char *xpath,
- soap_xmlnode_callback cb, void *userdata)
-{
- int i = 0;
- xmlNodeSetPtr nodeset;
- xmlXPathObjectPtr xpathobj;
-
- xpathobj = soap_xpath_eval(doc, xpath);
-
- if (!xpathobj)
- return 0;
-
- nodeset = xpathobj->nodesetval;
- if (!nodeset)
- return 0;
-
- for (i = 0; i < nodeset->nodeNr; i++)
- {
- if (!cb(nodeset->nodeTab[i], userdata))
- break;
- }
-
- xmlXPathFreeObject((xmlXPathObjectPtr) nodeset);
- return i;
-}
-
-
-void
-soap_xml_doc_print(xmlDocPtr doc)
-{
- xmlBufferPtr buffer;
- xmlNodePtr root;
-
- if (doc == NULL)
- {
- puts("xmlDocPtr is NULL!");
- return;
- }
-
- root = xmlDocGetRootElement(doc);
- if (root == NULL)
- {
- puts("Empty document!");
- return;
- }
-
-
- buffer = xmlBufferCreate();
- xmlNodeDump(buffer, doc, root, 1, 0);
- puts((const char *) xmlBufferContent(buffer));
- xmlBufferFree(buffer);
-
-}
-
char *
soap_xml_get_text(xmlNodePtr node)
{
diff --git a/libcsoap/soap-xml.h b/libcsoap/soap-xml.h
index 9b0a7a5..e7167b2 100644
--- a/libcsoap/soap-xml.h
+++ b/libcsoap/soap-xml.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-xml.h,v 1.10 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: soap-xml.h,v 1.11 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -21,36 +21,23 @@
*
* Email: ayaz@jprogrammer.net
******************************************************************/
-#ifndef cSOAP_XML_H
-#define cSOAP_XML_H
+#ifndef __csoap_xml_h
+#define __csoap_xml_h
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-
-static const char * const soap_env_ns = "http://schemas.xmlsoap.org/soap/envelope/";
static const char * const soap_env_enc = "http://schemas.xmlsoap.org/soap/encoding/";
static const char * const soap_xsi_ns = "http://www.w3.org/1999/XMLSchema-instance";
static const char * const soap_xsd_ns = "http://www.w3.org/1999/XMLSchema";
-
-typedef int (*soap_xmlnode_callback) (xmlNodePtr, void *);
-
#ifdef __cplusplus
extern "C" {
#endif
-xmlNodePtr soap_xml_get_children(xmlNodePtr param);
-xmlNodePtr soap_xml_get_next(xmlNodePtr param);
-
-xmlXPathObjectPtr soap_xpath_eval(xmlDocPtr doc, const char *xpath);
-
-int
-soap_xpath_foreach(xmlDocPtr doc, const char *xpath,
- soap_xmlnode_callback cb, void *userdata);
+extern xmlNodePtr soap_xml_get_children(xmlNodePtr param);
+extern xmlNodePtr soap_xml_get_next(xmlNodePtr param);
+extern xmlXPathObjectPtr soap_xpath_eval(xmlDocPtr doc, const char *xpath);
-void soap_xml_doc_print(xmlDocPtr doc);
-char *soap_xml_get_text(xmlNodePtr node);
+extern char *soap_xml_get_text(xmlNodePtr node);
#ifdef __cplusplus
}
diff --git a/nanohttp/nanohttp-admin.c b/nanohttp/nanohttp-admin.c
index 83c2931..746855b 100644
--- a/nanohttp/nanohttp-admin.c
+++ b/nanohttp/nanohttp-admin.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-admin.c,v 1.3 2006/11/21 20:59:02 m0gg Exp $
+* $Id: nanohttp-admin.c,v 1.4 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -25,10 +25,6 @@
#include <config.h>
#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
@@ -41,17 +37,12 @@
#include <pthread.h>
#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
#include "nanohttp-common.h"
-#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
#include "nanohttp-request.h"
#include "nanohttp-server.h"
-#include "nanohttp-admin.h"
+#include "nanohttp-admin.h"
static void
_httpd_admin_send_title(httpd_conn_t *conn, const char *title)
@@ -136,7 +127,7 @@ _httpd_admin_list_statistics(httpd_conn_t *conn, const char *service_name)
static void
-_httpd_admin_handle_get(httpd_conn_t * conn, hrequest_t * req)
+_httpd_admin_handle_get(httpd_conn_t * conn, struct hrequest_t *req)
{
char *param;
@@ -165,7 +156,7 @@ _httpd_admin_handle_get(httpd_conn_t * conn, hrequest_t * req)
static void
-_httpd_admin_entry(httpd_conn_t * conn, hrequest_t * req)
+_httpd_admin_entry(httpd_conn_t * conn, struct hrequest_t *req)
{
if (req->method == HTTP_REQUEST_GET)
{
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c
index a105b82..f8efeaf 100644
--- a/nanohttp/nanohttp-client.c
+++ b/nanohttp/nanohttp-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-client.c,v 1.43 2006/11/21 08:34:34 m0gg Exp $
+* $Id: nanohttp-client.c,v 1.44 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -45,6 +45,10 @@
#include <stdarg.h>
#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
#ifdef HAVE_STRING_H
#include <string.h>
#endif
@@ -60,6 +64,7 @@
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
+#include "nanohttp-request.h"
#include "nanohttp-response.h"
#include "nanohttp-base64.h"
#include "nanohttp-logging.h"
@@ -102,9 +107,19 @@ httpc_new(void)
httpc_conn_t *res;
if (!(res = (httpc_conn_t *) malloc(sizeof(httpc_conn_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ return NULL;
+ }
+
+ if (!(res->sock = (struct hsocket_t *)malloc(sizeof(struct hsocket_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ free(res);
return NULL;
+ }
- if ((status = hsocket_init(&res->sock)) != H_OK)
+ if ((status = hsocket_init(res->sock)) != H_OK)
{
log_warn2("hsocket_init failed (%s)", herror_message(status));
return NULL;
@@ -145,7 +160,8 @@ httpc_free(httpc_conn_t * conn)
conn->out = NULL;
}
- hsocket_free(&(conn->sock));
+ hsocket_free(conn->sock);
+ free(conn->sock);
free(conn);
return;
@@ -161,7 +177,7 @@ httpc_close_free(httpc_conn_t * conn)
if (conn == NULL)
return;
- hsocket_close(&(conn->sock));
+ hsocket_close(conn->sock);
httpc_free(conn);
return;
@@ -302,12 +318,12 @@ httpc_send_header(httpc_conn_t * conn)
if (walker->key && walker->value)
{
sprintf(buffer, "%s: %s\r\n", walker->key, walker->value);
- if ((status = hsocket_send(&(conn->sock), buffer)) != H_OK)
+ if ((status = hsocket_send(conn->sock, buffer)) != H_OK)
return status;
}
}
- return hsocket_send(&(conn->sock), "\r\n");
+ return hsocket_send(conn->sock, "\r\n");
}
/*--------------------------------------------------
@@ -386,7 +402,7 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
ssl = url.protocol == PROTOCOL_HTTPS ? 1 : 0;
/* Open connection */
- if ((status = hsocket_open(&conn->sock, url.host, url.port, ssl)) != H_OK)
+ if ((status = hsocket_open(conn->sock, url.host, url.port, ssl)) != H_OK)
return status;
switch(method)
@@ -413,10 +429,10 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
}
log_verbose1("Sending request...");
- if ((status = hsocket_send(&(conn->sock), buffer)) != H_OK)
+ if ((status = hsocket_send(conn->sock, buffer)) != H_OK)
{
log_error2("Cannot send request (%s)", herror_message(status));
- hsocket_close(&(conn->sock));
+ hsocket_close(conn->sock);
return status;
}
@@ -424,7 +440,7 @@ httpc_talk_to_server(hreq_method_t method, httpc_conn_t * conn,
if ((status = httpc_send_header(conn)) != H_OK)
{
log_error2("Cannot send header (%s)", herror_message(status));
- hsocket_close(&(conn->sock));
+ hsocket_close(conn->sock);
return status;
}
@@ -443,7 +459,7 @@ httpc_get(httpc_conn_t * conn, hresponse_t ** out, const char *urlstr)
if ((status = httpc_talk_to_server(HTTP_REQUEST_GET, conn, urlstr)) != H_OK)
return status;
- if ((status = hresponse_new_from_socket(&(conn->sock), out)) != H_OK)
+ if ((status = hresponse_new_from_socket(conn->sock, out)) != H_OK)
return status;
return H_OK;
@@ -462,7 +478,7 @@ httpc_post_begin(httpc_conn_t * conn, const char *url)
if ((status = httpc_talk_to_server(HTTP_REQUEST_POST, conn, url)) != H_OK)
return status;
- conn->out = http_output_stream_new(&(conn->sock), conn->header);
+ conn->out = http_output_stream_new(conn->sock, conn->header);
return H_OK;
}
@@ -481,7 +497,7 @@ httpc_post_end(httpc_conn_t * conn, hresponse_t ** out)
if ((status = http_output_stream_flush(conn->out)) != H_OK)
return status;
- if ((status = hresponse_new_from_socket(&(conn->sock), out)) != H_OK)
+ if ((status = hresponse_new_from_socket(conn->sock, out)) != H_OK)
return status;
return H_OK;
@@ -598,7 +614,7 @@ httpc_mime_end(httpc_conn_t * conn, hresponse_t ** out)
if ((status = http_output_stream_flush(conn->out)) != H_OK)
return status;
- if ((status = hresponse_new_from_socket(&(conn->sock), out)) != H_OK)
+ if ((status = hresponse_new_from_socket(conn->sock, out)) != H_OK)
return status;
return H_OK;
diff --git a/nanohttp/nanohttp-client.h b/nanohttp/nanohttp-client.h
index 2ef96a8..7a1cc79 100644
--- a/nanohttp/nanohttp-client.h
+++ b/nanohttp/nanohttp-client.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-client.h,v 1.25 2006/11/19 09:40:14 m0gg Exp $
+ * $Id: nanohttp-client.h,v 1.26 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -26,7 +26,7 @@
typedef struct httpc_conn
{
- hsocket_t sock;
+ struct hsocket_t *sock;
hpair_t *header;
hurl_t url;
http_version_t version;
@@ -36,7 +36,7 @@ typedef struct httpc_conn
long _dime_sent_bytes;
int errcode;
char errmsg[150];
- http_output_stream_t *out;
+ struct http_output_stream_t *out;
int id; /* uniq id */
} httpc_conn_t;
@@ -61,7 +61,7 @@ extern "C" {
*
* @see httpc_destroy, herror_t, soap_client_init_args
*/
-herror_t httpc_init(int argc, char *argv[]);
+herror_t httpc_init(int argc, char **argv);
/**
*
diff --git a/nanohttp/nanohttp-common.h b/nanohttp/nanohttp-common.h
index bf54a12..cc9f8f8 100644
--- a/nanohttp/nanohttp-common.h
+++ b/nanohttp/nanohttp-common.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-common.h,v 1.32 2006/11/19 09:40:14 m0gg Exp $
+ * $Id: nanohttp-common.h,v 1.33 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -21,8 +21,8 @@
*
* Email: ferhatayaz@yahoo.com
******************************************************************/
-#ifndef NANO_HTTP_COMMON_H
-#define NANO_HTTP_COMMON_H
+#ifndef __nanohttp_common_h
+#define __nanohttp_common_h
#define HEADER_CONTENT_ID "Content-Id"
#define HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
@@ -69,75 +69,14 @@
#define HEADER_EXPIRES "Expires"
#define HEADER_LAST_MODIFIED "Last-Modified"
-
/**
*
- * XXX: move to nanohttp-response.h
- *
- * Response Header Fields
- *
- * The response-header fields allow the server to pass additional information
- * about the response which cannot be placed in the Status-Line. These header
- * fields give information about the server and about further access to the
- * resource identified by the Request-URI. (see RFC2616)
+ * Command line arguments for client and server.
*
*/
-#define HEADER_ACCEPT_RANGES "Accept-Ranges"
-#define HEADER_AGE "Age"
-#define HEADER_EXTENSION_TAG "ETag"
-#define HEADER_LOCATION "Location"
-#define HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
-#define HEADER_RETRY_AFTER "Retry-After"
-#define HEADER_SERVER "Server"
-#define HEADER_VARY "Vary"
-#define HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
-
-/**
- *
- * XXX: move to nanohttp-request.h
- *
- * Request Header Fields
- *
- * The request-header fields allow the client to pass additional information
- * about the request, and about the client itself, to the server. These fields
- * act as request modifiers, with semantics equivalent to the parameters on a
- * programming language method invocation (see RFC2616).
- *
- */
-#define HEADER_ACCEPT "Accept"
-#define HEADER_CHARSET "Accept-Charset"
-#define HEADER_ACCEPT_ENCODING "Accept-Encoding"
-#define HEADER_ACCEPT_LANGUAGE "Accept-Language"
-#define HEADER_AUTHORIZATION "Authorization"
-#define HEADER_EXPECT "Expect"
-#define HEADER_FROM "From"
-#define HEADER_HOST "Host"
-#define HEADER_IF_MATCH "If-Match"
-#define HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
-#define HEADER_IF_NONE_MATCH "If-None-Match"
-#define HEADER_IF_RANGE "If-Range"
-#define HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
-#define HEADER_IF_MAX_FORWARDS "Max-Forwards"
-#define HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
-#define HEADER_RANGE "Range"
-#define HEADER_REFERER "Referer"
-#define HEADER_TRANSFER_EXTENSION "TE"
-#define HEADER_USER_AGENT "User-Agent"
-
-/**
- *
- * nanohttp command line flags
- *
- */
-#define NHTTPD_ARG_PORT "-NHTTPport"
-#define NHTTPD_ARG_TERMSIG "-NHTTPtsig"
-#define NHTTPD_ARG_MAXCONN "-NHTTPmaxconn"
-#define NHTTPD_ARG_TIMEOUT "-NHTTPtimeout"
-
#define NHTTP_ARG_CERT "-NHTTPcert"
#define NHTTP_ARG_CERTPASS "-NHTTPcertpass"
#define NHTTP_ARG_CA "-NHTTPCA"
-#define NHTTP_ARG_HTTPS "-NHTTPS"
#ifndef SAVE_STR
#define SAVE_STR(str) ((str==0)?("(null)"):(str))
@@ -146,27 +85,13 @@
#define BOUNDARY_LENGTH 18
#define MAX_HEADER_SIZE 4256
-#define MAX_SOCKET_BUFFER_SIZE 4256
#define MAX_FILE_BUFFER_SIZE 4256
-#define URL_MAX_HOST_SIZE 120
-#define URL_MAX_CONTEXT_SIZE 1024
-
-#define HSOCKET_MAX_BUFSIZE 1024
-
#define REQUEST_MAX_PATH_SIZE 1024
#define RESPONSE_MAX_DESC_SIZE 1024
-
-/*
- DIME common stuff
-*/
-#define DIME_VERSION_1 0x08
-#define DIME_FIRST_PACKAGE 0x04
-#define DIME_LAST_PACKAGE 0x02
-#define DIME_CHUNKED 0x01
-#define DIME_TYPE_URI 0x2
-
-
+
+#define URL_MAX_HOST_SIZE 120
+#define URL_MAX_CONTEXT_SIZE 1024
/* TODO (#1#): find proper ports */
#define URL_DEFAULT_PORT_HTTP 80
@@ -234,15 +159,6 @@
#define HSSL_ERROR_SERVER 1760
#define HSSL_ERROR_CONNECT 1770
-/*
-Set Sleep function platform depended
-*/
-#ifdef WIN32
-#define system_sleep(seconds) Sleep(seconds*1000);
-#else
-#define system_sleep(seconds) sleep(seconds);
-#endif
-
/**
Indicates the version of the
used HTTP protocol.
@@ -275,12 +191,6 @@ typedef enum _hreq_method
extern "C" {
#endif
-#ifdef WIN32
-#include <string.h>
-char *strtok_r(char *s, const char *delim, char **save_ptr);
-struct tm *localtime_r(const time_t * const timep, struct tm *p_tm);
-#endif
-
typedef void *herror_t;
herror_t herror_new(const char *func, int errcode, const char *format, ...);
@@ -543,7 +453,7 @@ typedef struct _attachments
part_t *root_part;
} attachments_t;
-attachments_t *attachments_new(); /* should be used internally */
+attachments_t *attachments_new(void); /* should be used internally */
/*
Free a attachment. Create attachments with MIME
diff --git a/nanohttp/nanohttp-logging.h b/nanohttp/nanohttp-logging.h
index a687717..7bc1076 100644
--- a/nanohttp/nanohttp-logging.h
+++ b/nanohttp/nanohttp-logging.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-logging.h,v 1.2 2006/08/28 10:39:52 m0gg Exp $
+ * $Id: nanohttp-logging.h,v 1.3 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2006 Ferhat Ayaz
@@ -47,7 +47,7 @@ extern log_level_t hlog_set_level(log_level_t level);
extern log_level_t hlog_get_level(void);
extern void hlog_set_file(const char *filename);
-extern char *hlog_get_file();
+extern char *hlog_get_file(void);
#ifdef WIN32
#if defined(_MSC_VER) && _MSC_VER <= 1200
diff --git a/nanohttp/nanohttp-mime.c b/nanohttp/nanohttp-mime.c
index a853486..1736e3b 100755
--- a/nanohttp/nanohttp-mime.c
+++ b/nanohttp/nanohttp-mime.c
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.c,v 1.15 2006/11/21 08:34:34 m0gg Exp $
+* $Id: nanohttp-mime.c,v 1.16 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -518,7 +518,7 @@ MIME_read_status
mime_streamreader_function(void *userdata, unsigned char *dest, int *size)
{
int readed = 0;
- http_input_stream_t *in = (http_input_stream_t *) userdata;
+ struct http_input_stream_t *in = (struct http_input_stream_t *) userdata;
if (!http_input_stream_is_ready(in))
return MIME_READ_EOF;
@@ -799,7 +799,7 @@ _mime_received_bytes(void *data, const unsigned char *bytes, int size)
*/
attachments_t *
-mime_message_parse(http_input_stream_t * in, const char *root_id,
+mime_message_parse(struct http_input_stream_t * in, const char *root_id,
const char *boundary, const char *dest_dir)
{
MIME_parser_status status;
@@ -896,7 +896,7 @@ mime_message_parse_from_file(FILE * in, const char *root_id,
}
herror_t
-mime_get_attachments(content_type_t * ctype, http_input_stream_t * in,
+mime_get_attachments(content_type_t * ctype, struct http_input_stream_t * in,
attachments_t ** dest)
{
/* MIME variables */
diff --git a/nanohttp/nanohttp-mime.h b/nanohttp/nanohttp-mime.h
index 7d718d9..655c7e2 100755
--- a/nanohttp/nanohttp-mime.h
+++ b/nanohttp/nanohttp-mime.h
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.h,v 1.9 2006/11/19 09:40:14 m0gg Exp $
+* $Id: nanohttp-mime.h,v 1.10 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -37,11 +37,7 @@ extern "C" {
"multipart/related" MIME Message Builder
------------------------------------------------------------------*/
-
-
-herror_t mime_get_attachments(content_type_t * ctype,
- http_input_stream_t * in,
- attachments_t ** dest);
+extern herror_t mime_get_attachments(content_type_t * ctype, struct http_input_stream_t * in, attachments_t ** dest);
#ifdef __cplusplus
}
diff --git a/nanohttp/nanohttp-request.c b/nanohttp/nanohttp-request.c
index 30c79df..0fd1d7e 100755
--- a/nanohttp/nanohttp-request.c
+++ b/nanohttp/nanohttp-request.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-request.c,v 1.17 2006/11/21 20:59:02 m0gg Exp $
+* $Id: nanohttp-request.c,v 1.18 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -56,24 +56,24 @@
#include "nanohttp-mime.h"
#include "nanohttp-request.h"
-
-static hrequest_t *
+static struct hrequest_t *
hrequest_new(void)
{
- hrequest_t *req;
+ struct hrequest_t *req;
- if (!(req = (hrequest_t *) malloc(sizeof(hrequest_t)))) {
-
+ if (!(req = (struct hrequest_t *) malloc(sizeof(struct hrequest_t))))
+ {
log_error2("malloc failed (%s)", strerror(errno));
return NULL;
}
- if (!(req->statistics = (struct request_statistics *)malloc(sizeof(struct request_statistics)))) {
-
+ if (!(req->statistics = (struct request_statistics *)malloc(sizeof(struct request_statistics))))
+ {
log_error2("malloc failed (%s)", strerror(errno));
free(req);
return NULL;
}
+
if (gettimeofday(&(req->statistics->time), NULL) < 0)
log_error2("gettimeofday failed (%s)", strerror(errno));
@@ -88,10 +88,10 @@ hrequest_new(void)
return req;
}
-static hrequest_t *
+static struct hrequest_t *
_hrequest_parse_header(char *data)
{
- hrequest_t *req;
+ struct hrequest_t *req;
hpair_t *hpair = NULL, *qpair = NULL, *tmppair = NULL;
char *tmp;
@@ -214,20 +214,12 @@ _hrequest_parse_header(char *data)
qpair->next = NULL;
qpair->key = strdup(opt_key);
qpair->value = strdup(opt_value);
-
}
}
}
}
else
{
-
- /* parse "key: value" */
- /* tmp2 = result; key = (char *) strtok_r(tmp2, ": ", &saveptr2); value
- = saveptr2; */
-
- /* create pair */
-/* tmppair = (hpair_t *) malloc(sizeof(hpair_t));*/
tmppair = hpairnode_parse(result, ":", NULL);
if (req->header == NULL)
@@ -239,13 +231,6 @@ _hrequest_parse_header(char *data)
hpair->next = tmppair;
hpair = tmppair;
}
-
- /* fill pairnode_t struct */
- /*
- hpair->next = NULL; hpair->key = (char *) malloc(strlen(key) + 1);
- hpair->value = (char *) malloc(strlen(value) + 1);
-
- strcpy(hpair->key, key); strcpy(hpair->value, value); */
}
}
@@ -257,9 +242,8 @@ _hrequest_parse_header(char *data)
return req;
}
-
void
-hrequest_free(hrequest_t * req)
+hrequest_free(struct hrequest_t * req)
{
if (req == NULL)
return;
@@ -284,13 +268,12 @@ hrequest_free(hrequest_t * req)
return;
}
-
herror_t
-hrequest_new_from_socket(hsocket_t *sock, hrequest_t ** out)
+hrequest_new_from_socket(struct hsocket_t *sock, struct hrequest_t ** out)
{
int i, readed;
herror_t status;
- hrequest_t *req;
+ struct hrequest_t *req;
char buffer[MAX_HEADER_SIZE + 1];
attachments_t *mimeMessage;
diff --git a/nanohttp/nanohttp-request.h b/nanohttp/nanohttp-request.h
index ba1b907..2234e99 100755
--- a/nanohttp/nanohttp-request.h
+++ b/nanohttp/nanohttp-request.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-request.h,v 1.9 2006/11/21 20:59:02 m0gg Exp $
+ * $Id: nanohttp-request.h,v 1.10 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -21,8 +21,38 @@
*
* Email: ferhatayaz@yahoo.com
******************************************************************/
-#ifndef NANO_HTTP_REQUEST_H
-#define NANO_HTTP_REQUEST_H
+#ifndef __nhttp_request_h
+#define __nhttp_request_h
+
+/**
+ *
+ * Request Header Fields
+ *
+ * The request-header fields allow the client to pass additional information
+ * about the request, and about the client itself, to the server. These fields
+ * act as request modifiers, with semantics equivalent to the parameters on a
+ * programming language method invocation (see RFC2616).
+ *
+ */
+#define HEADER_ACCEPT "Accept"
+#define HEADER_CHARSET "Accept-Charset"
+#define HEADER_ACCEPT_ENCODING "Accept-Encoding"
+#define HEADER_ACCEPT_LANGUAGE "Accept-Language"
+#define HEADER_AUTHORIZATION "Authorization"
+#define HEADER_EXPECT "Expect"
+#define HEADER_FROM "From"
+#define HEADER_HOST "Host"
+#define HEADER_IF_MATCH "If-Match"
+#define HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
+#define HEADER_IF_NONE_MATCH "If-None-Match"
+#define HEADER_IF_RANGE "If-Range"
+#define HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
+#define HEADER_IF_MAX_FORWARDS "Max-Forwards"
+#define HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
+#define HEADER_RANGE "Range"
+#define HEADER_REFERER "Referer"
+#define HEADER_TRANSFER_EXTENSION "TE"
+#define HEADER_USER_AGENT "User-Agent"
#ifdef __NHTTP_INTERNAL
struct request_statistics
@@ -36,7 +66,7 @@ struct request_statistics
/*
request object
*/
-typedef struct hrequest
+struct hrequest_t
{
hreq_method_t method;
http_version_t version;
@@ -47,18 +77,20 @@ typedef struct hrequest
struct request_statistics *statistics;
- http_input_stream_t *in;
+ struct http_input_stream_t *in;
content_type_t *content_type;
attachments_t *attachments;
char root_part_id[150];
-} hrequest_t;
+};
#ifdef __cplusplus
extern "C" {
#endif
-herror_t hrequest_new_from_socket(hsocket_t *sock, hrequest_t ** out);
-void hrequest_free(hrequest_t * req);
+#ifdef __NHTTP_INTERNAL
+herror_t hrequest_new_from_socket(struct hsocket_t *sock, struct hrequest_t **out);
+void hrequest_free(struct hrequest_t *req);
+#endif
#ifdef __cplusplus
}
diff --git a/nanohttp/nanohttp-response.c b/nanohttp/nanohttp-response.c
index db2f897..ad8c4a1 100755
--- a/nanohttp/nanohttp-response.c
+++ b/nanohttp/nanohttp-response.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-response.c,v 1.13 2006/11/21 08:34:34 m0gg Exp $
+* $Id: nanohttp-response.c,v 1.14 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -154,7 +154,7 @@ _hresponse_parse_header(const char *buffer)
herror_t
-hresponse_new_from_socket(hsocket_t *sock, hresponse_t ** out)
+hresponse_new_from_socket(struct hsocket_t *sock, hresponse_t ** out)
{
int i = 0, count;
herror_t status;
diff --git a/nanohttp/nanohttp-response.h b/nanohttp/nanohttp-response.h
index 4dcc452..553d69f 100755
--- a/nanohttp/nanohttp-response.h
+++ b/nanohttp/nanohttp-response.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-response.h,v 1.8 2006/11/19 09:40:14 m0gg Exp $
+ * $Id: nanohttp-response.h,v 1.9 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -24,6 +24,28 @@
#ifndef __nanohttp_response_h
#define __nanohttp_response_h
+/**
+ *
+ * Response Header Fields
+ *
+ * The response-header fields allow the server to pass additional information
+ * about the response which cannot be placed in the Status-Line. These header
+ * fields give information about the server and about further access to the
+ * resource identified by the Request-URI. (see RFC2616)
+ *
+ * @see http://www.ietf.org/rfc/rfc2616.txt
+ *
+ */
+#define HEADER_ACCEPT_RANGES "Accept-Ranges"
+#define HEADER_AGE "Age"
+#define HEADER_EXTENSION_TAG "ETag"
+#define HEADER_LOCATION "Location"
+#define HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
+#define HEADER_RETRY_AFTER "Retry-After"
+#define HEADER_SERVER "Server"
+#define HEADER_VARY "Vary"
+#define HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
+
/* response object */
typedef struct hresponse
{
@@ -33,7 +55,7 @@ typedef struct hresponse
hpair_t *header;
- http_input_stream_t *in;
+ struct http_input_stream_t *in;
content_type_t *content_type;
attachments_t *attachments;
char root_part_id[150];
@@ -43,8 +65,10 @@ typedef struct hresponse
extern "C" {
#endif
-herror_t hresponse_new_from_socket(hsocket_t *sock, hresponse_t ** out);
+#ifdef __NHTTP_INTERNAL
+herror_t hresponse_new_from_socket(struct hsocket_t *sock, hresponse_t ** out);
void hresponse_free(hresponse_t * res);
+#endif
#ifdef __cplusplus
}
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index 269e741..45b9348 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.64 2006/11/21 20:59:03 m0gg Exp $
+* $Id: nanohttp-server.c,v 1.65 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -82,6 +82,7 @@
#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
#include "nanohttp-request.h"
+#include "nanohttp-response.h"
#include "nanohttp-server.h"
#include "nanohttp-base64.h"
#include "nanohttp-ssl.h"
@@ -90,29 +91,27 @@
typedef struct _conndata
{
volatile int flag;
- hsocket_t sock;
+ struct hsocket_t sock;
#ifdef WIN32
HANDLE tid;
#else
pthread_t tid;
pthread_attr_t attr;
#endif
- time_t atime;
}
conndata_t;
#define CONNECTION_FREE 0
#define CONNECTION_IN_USE 1
-/*
- * -----------------------------------------------------
- * nano httpd
- * internally globals
- * -----------------------------------------------------
+/**
+ *
+ * nanohttpd internally globals
+ *
*/
static volatile int _httpd_run = 1;
-static hsocket_t _httpd_socket;
+static struct hsocket_t _httpd_socket;
static int _httpd_port = 10000;
static int _httpd_max_connections = 20;
static int _httpd_timeout = 10;
@@ -126,7 +125,6 @@ static conndata_t *_httpd_connection;
#ifdef WIN32
static DWORD _httpd_terminate_signal = CTRL_C_EVENT;
static int _httpd_max_idle = 120;
-static void WSAReaper(void *x);
HANDLE _httpd_connection_lock;
LPCTSTR _httpd_connection_lock_str;
#define strncasecmp(s1, s2, num) strncmp(s1, s2, num)
@@ -137,6 +135,23 @@ static sigset_t thrsigset;
static pthread_mutex_t _httpd_connection_lock;
#endif
+/**
+ *
+ * Set Sleep function platform depended
+ *
+ */
+#ifdef WIN32
+static void _sys_sleep(int secs)
+{
+ Sleep(secs*1000);
+}
+#else
+static inline void _sys_sleep(int secs)
+{
+ sleep(secs);
+}
+#endif
+
static void
_httpd_parse_arguments(int argc, char **argv)
{
@@ -186,38 +201,42 @@ _httpd_connection_slots_init(void)
return;
}
-static void
+static herror_t
_httpd_register_builtin_services(int argc, char **argv)
{
herror_t status;
if ((status = httpd_admin_init_args(argc, argv)) != H_OK)
+ {
log_error2("httpd_admin_init_args failed (%s)", herror_message(status));
+ return status;
+ }
- return;
+ return H_OK;
}
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_init
- * NOTE: This will be called from soap_server_init_args()
- * -----------------------------------------------------
- */
herror_t
-httpd_init(int argc, char *argv[])
+httpd_init(int argc, char **argv)
{
herror_t status;
_httpd_parse_arguments(argc, argv);
if ((status = hsocket_module_init(argc, argv)) != H_OK)
+ {
+ log_error2("hsocket_modeule_init failed (%s)", herror_message(status));
return status;
+ }
log_verbose2("socket bind to port '%d'", _httpd_port);
_httpd_connection_slots_init();
- _httpd_register_builtin_services(argc, argv);
+ if ((status = _httpd_register_builtin_services(argc, argv)) != H_OK)
+ {
+ log_error2("_httpd_register_builtin_services failed (%s)", herror_message(status));
+ return status;
+ }
if ((status = hsocket_init(&_httpd_socket)) != H_OK)
{
@@ -225,15 +244,16 @@ httpd_init(int argc, char *argv[])
return status;
}
- return hsocket_bind(&_httpd_socket, _httpd_port);
+ if ((status = hsocket_bind(&_httpd_socket, _httpd_port)) != H_OK)
+ {
+ log_error2("hsocket_bind failed (%s)", herror_message(status));
+ return status;
+ }
+
+ return H_OK;
}
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_register
- * -----------------------------------------------------
- */
-int
+herror_t
httpd_register_secure(const char *ctx, httpd_service func, httpd_auth auth)
{
hservice_t *service;
@@ -241,13 +261,13 @@ httpd_register_secure(const char *ctx, httpd_service func, httpd_auth auth)
if (!(service = (hservice_t *) malloc(sizeof(hservice_t))))
{
log_error2("malloc failed (%s)", strerror(errno));
- return -1;
+ return herror_new("httpd_register_secure", 0, "malloc failed (%s)", strerror(errno));
}
if (!(service->statistics = (struct service_statistics *)malloc(sizeof(struct service_statistics))))
{
log_error2("malloc failed (%s)", strerror(errno));
- return -1;
+ return herror_new("httpd_register_secure", 0, "malloc failed (%s)", strerror(errno));
}
memset(service->statistics, 0, sizeof(struct service_statistics));
service->statistics->time.tv_sec = 0;
@@ -270,19 +290,19 @@ httpd_register_secure(const char *ctx, httpd_service func, httpd_auth auth)
_httpd_services_tail = service;
}
- return 1;
+ return H_OK;
}
-int
+herror_t
httpd_register(const char *ctx, httpd_service service)
{
return httpd_register_secure(ctx, service, NULL);
}
-int
+herror_t
httpd_register_default_secure(const char *ctx, httpd_service service, httpd_auth auth)
{
- int ret;
+ herror_t ret;
ret = httpd_register_secure(ctx, service, auth);
@@ -292,13 +312,13 @@ httpd_register_default_secure(const char *ctx, httpd_service service, httpd_auth
return ret;
}
-int
+herror_t
httpd_register_default(const char *ctx, httpd_service service)
{
return httpd_register_default_secure(ctx, service, NULL);
}
-int
+short
httpd_get_port(void)
{
return _httpd_port;
@@ -314,6 +334,8 @@ void
httpd_set_timeout(int t)
{
_httpd_timeout = t;
+
+ return;
}
const char *
@@ -322,9 +344,6 @@ httpd_get_protocol(void)
return hssl_enabled() ? "https" : "http";
}
-/*--------------------------------------------------
-FUNCTION: httpd_get_conncount
-----------------------------------------------------*/
int
httpd_get_conncount(void)
{
@@ -339,22 +358,12 @@ httpd_get_conncount(void)
return ret;
}
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_get_services
- * -----------------------------------------------------
- */
hservice_t *
httpd_get_services(void)
{
return _httpd_services_head;
}
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_services
- * -----------------------------------------------------
- */
static void
hservice_free(hservice_t * service)
{
@@ -363,11 +372,6 @@ hservice_free(hservice_t * service)
return;
}
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_find_service
- * -----------------------------------------------------
- */
hservice_t *
httpd_find_service(const char *context)
{
@@ -382,12 +386,6 @@ httpd_find_service(const char *context)
return _httpd_services_default;
}
-
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_response_set_content_type
- * -----------------------------------------------------
- */
void
httpd_response_set_content_type(httpd_conn_t * res, const char *content_type)
{
@@ -396,12 +394,6 @@ httpd_response_set_content_type(httpd_conn_t * res, const char *content_type)
return;
}
-
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_response_send_header
- * -----------------------------------------------------
- */
herror_t
httpd_send_header(httpd_conn_t * res, int code, const char *text)
{
@@ -452,14 +444,21 @@ httpd_send_header(httpd_conn_t * res, int code, const char *text)
return H_OK;
}
-
herror_t
httpd_send_internal_error(httpd_conn_t * conn, const char *errmsg)
{
const char *template1 =
- "<html><body><h3>Error!</h3><hr> Message: '%s' </body></html>\r\n";
-
- char buffer[4064];
+ "<html>"
+ "<head>"
+ "</head>"
+ "<body>"
+ "<h3>Error!</h3>"
+ "<hr/>"
+ "<div>Message: '%s'</div>"
+ "</body>"
+ "</html>";
+
+ char buffer[4096];
char buflen[5];
sprintf(buffer, template1, errmsg);
@@ -471,13 +470,8 @@ httpd_send_internal_error(httpd_conn_t * conn, const char *errmsg)
return http_output_stream_write_string(conn->out, buffer);
}
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_request_print
- * -----------------------------------------------------
- */
static void
-httpd_request_print(hrequest_t * req)
+_httpd_request_print(struct hrequest_t * req)
{
hpair_t *pair;
@@ -501,15 +495,13 @@ httpd_request_print(hrequest_t * req)
return;
}
-
httpd_conn_t *
-httpd_new(hsocket_t * sock)
+httpd_new(struct hsocket_t * sock)
{
httpd_conn_t *conn;
if (!(conn = (httpd_conn_t *) malloc(sizeof(httpd_conn_t))))
{
-
log_error2("malloc failed (%s)", strerror(errno));
return NULL;
}
@@ -521,7 +513,6 @@ httpd_new(hsocket_t * sock)
return conn;
}
-
void
httpd_free(httpd_conn_t * conn)
{
@@ -539,11 +530,9 @@ httpd_free(httpd_conn_t * conn)
return;
}
-
static int
_httpd_decode_authorization(const char *value, char **user, char **pass)
{
-
unsigned char *tmp, *tmp2;
size_t len;
@@ -580,7 +569,7 @@ _httpd_decode_authorization(const char *value, char **user, char **pass)
}
static int
-_httpd_authenticate_request(hrequest_t * req, httpd_auth auth)
+_httpd_authenticate_request(struct hrequest_t * req, httpd_auth auth)
{
char *user, *pass;
char *authorization;
@@ -614,11 +603,6 @@ _httpd_authenticate_request(hrequest_t * req, httpd_auth auth)
return ret;
}
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_session_main
- * -----------------------------------------------------
- */
#ifdef WIN32
static unsigned _stdcall
httpd_session_main(void *data)
@@ -627,7 +611,7 @@ static void *
httpd_session_main(void *data)
#endif
{
- hrequest_t *req; /* only for test */
+ struct hrequest_t *req;
conndata_t *conn;
httpd_conn_t *rconn;
hservice_t *service;
@@ -649,9 +633,6 @@ httpd_session_main(void *data)
{
log_verbose3("starting HTTP request on socket %d (%p)", conn->sock, conn->sock.sock);
- /* XXX: only used in WSAreaper */
- conn->atime = time(NULL);
-
if ((status = hrequest_new_from_socket(&(conn->sock), &req)) != H_OK)
{
int code;
@@ -660,8 +641,7 @@ httpd_session_main(void *data)
{
case HSOCKET_ERROR_SSLCLOSE:
case HSOCKET_ERROR_RECEIVE:
- log_error2("hrequest_new_from_socket failed (%s)",
- herror_message(status));
+ log_error2("hrequest_new_from_socket failed (%s)", herror_message(status));
break;
default:
httpd_send_internal_error(rconn, herror_message(status));
@@ -729,11 +709,11 @@ httpd_session_main(void *data)
char *template =
"<html>"
"<head>"
- "<title>Unauthorized</title>"
- "</head>"
- "<body>"
- "<h1>Unauthorized request logged</h1>"
- "</body>"
+ "<title>Unauthorized</title>"
+ "</head>"
+ "<body>"
+ "<h1>Unauthorized request logged</h1>"
+ "</body>"
"</html>";
httpd_set_header(rconn, HEADER_WWW_AUTHENTICATE,
@@ -810,6 +790,7 @@ httpd_set_headers(httpd_conn_t * conn, hpair_t * header)
httpd_set_header(conn, header->key, header->value);
header = header->next;
}
+ return;
}
int
@@ -843,11 +824,6 @@ httpd_add_headers(httpd_conn_t * conn, const hpair_t * values)
return;
}
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_term
- * -----------------------------------------------------
- */
#ifdef WIN32
BOOL WINAPI
httpd_term(DWORD sig)
@@ -894,9 +870,6 @@ _httpd_register_signal_handler(void)
return;
}
-/*--------------------------------------------------
-FUNCTION: _httpd_wait_for_empty_conn
-----------------------------------------------------*/
static conndata_t *
_httpd_wait_for_empty_conn(void)
{
@@ -907,13 +880,13 @@ _httpd_wait_for_empty_conn(void)
#else
pthread_mutex_lock(&_httpd_connection_lock);
#endif
+
for (i = 0;; i++)
{
if (!_httpd_run)
{
-
#ifdef WIN32
- ReleaseMutex(_httpd_connection_lock);
+ ReleaseMutex(_httpd_connection_lock);
#else
pthread_mutex_unlock(&_httpd_connection_lock);
#endif
@@ -922,7 +895,7 @@ _httpd_wait_for_empty_conn(void)
if (i >= _httpd_max_connections)
{
- system_sleep(1);
+ _sys_sleep(1);
i = -1;
}
else if (_httpd_connection[i].flag == CONNECTION_FREE)
@@ -931,20 +904,16 @@ _httpd_wait_for_empty_conn(void)
break;
}
}
+
#ifdef WIN32
- ReleaseMutex(_httpd_connection_lock);
+ ReleaseMutex(_httpd_connection_lock);
#else
- pthread_mutex_unlock(&_httpd_connection_lock);
+ pthread_mutex_unlock(&_httpd_connection_lock);
#endif
return &_httpd_connection[i];
}
-/*
- * -----------------------------------------------------
- * FUNCTION: _httpd_start_thread
- * -----------------------------------------------------
- */
static void
_httpd_start_thread(conndata_t * conn)
{
@@ -969,13 +938,6 @@ _httpd_start_thread(conndata_t * conn)
return;
}
-
-/*
- * -----------------------------------------------------
- * FUNCTION: httpd_run
- * -----------------------------------------------------
- */
-
herror_t
httpd_run(void)
{
@@ -1074,55 +1036,8 @@ httpd_destroy(void)
return;
}
-#ifdef WIN32
-
-static void
-WSAReaper(void *x)
-{
- short int connections;
- short int i;
- char junk[10];
- int rc;
- time_t ctime;
-
- for (;;)
- {
- connections = 0;
- ctime = time((time_t) 0);
- for (i = 0; i < _httpd_max_connections; i++)
- {
- if (_httpd_connection[i].tid == 0)
- continue;
- GetExitCodeThread((HANDLE) _httpd_connection[i].tid, (PDWORD) & rc);
- if (rc != STILL_ACTIVE)
- continue;
- connections++;
- if ((ctime - _httpd_connection[i].atime < _httpd_max_idle) ||
- (_httpd_connection[i].atime == 0))
- continue;
- log_verbose3("Reaping socket %u from (runtime ~= %d seconds)",
- _httpd_connection[i].sock,
- ctime - _httpd_connection[i].atime);
- shutdown(_httpd_connection[i].sock.sock, 2);
- while (recv(_httpd_connection[i].sock.sock, junk, sizeof(junk), 0) > 0)
- {
- };
- closesocket(_httpd_connection[i].sock.sock);
- _httpd_connection[i].sock.sock = 0;
- TerminateThread(_httpd_connection[i].tid, (DWORD) & rc);
- CloseHandle(_httpd_connection[i].tid);
- memset((char *) &_httpd_connection[i], 0, sizeof(_httpd_connection[i]));
- }
- Sleep(100);
- }
- return;
-}
-
-#endif
-
unsigned char *
-httpd_get_postdata(httpd_conn_t * conn, hrequest_t * req, long *received,
- long max)
+httpd_get_postdata(httpd_conn_t * conn, struct hrequest_t * req, long *received, long max)
{
char *content_length_str;
long content_length = 0;
diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h
index eb3a06b..be48005 100644
--- a/nanohttp/nanohttp-server.h
+++ b/nanohttp/nanohttp-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-server.h,v 1.23 2006/11/21 20:59:03 m0gg Exp $
+ * $Id: nanohttp-server.h,v 1.24 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -24,26 +24,47 @@
#ifndef __nanohttp_server_h
#define __nanohttp_server_h
+/**
+ *
+ * nanohttp command line flags
+ *
+ */
+#define NHTTPD_ARG_PORT "-NHTTPport"
+#define NHTTPD_ARG_TERMSIG "-NHTTPtsig"
+#define NHTTPD_ARG_MAXCONN "-NHTTPmaxconn"
+#define NHTTPD_ARG_TIMEOUT "-NHTTPtimeout"
typedef struct httpd_conn
{
- hsocket_t *sock;
+ struct hsocket_t *sock;
char content_type[25];
- http_output_stream_t *out;
+ struct http_output_stream_t *out;
hpair_t *header;
}
httpd_conn_t;
+/**
+ *
+ * Service callback function for a nanoHTTP service.
+ *
+ */
+typedef void (*httpd_service) (httpd_conn_t *conn, struct hrequest_t *req);
-/*
- Service callback
+/**
+ *
+ * Authentication callback function for a nanoHTTP service.
+ *
*/
-typedef void (*httpd_service) (httpd_conn_t *, hrequest_t *);
-typedef int (*httpd_auth) (hrequest_t * req, const char *user,
- const char *password);
+typedef int (*httpd_auth) (struct hrequest_t *req, const char *user, const char *pass);
#ifdef __NHTTP_INTERNAL
-struct service_statistics {
+/**
+ *
+ * Service statistics per nanoHTTP service.
+ *
+ */
+struct service_statistics
+{
unsigned long requests;
unsigned long bytes_transmitted;
unsigned long bytes_received;
@@ -52,8 +73,10 @@ struct service_statistics {
};
#endif
-/*
+/**
+ *
* Service representation object
+ *
*/
typedef struct tag_hservice
{
@@ -65,7 +88,6 @@ typedef struct tag_hservice
}
hservice_t;
-
#ifdef __cplusplus
extern "C"
{
@@ -75,43 +97,35 @@ extern "C"
/*
Begin httpd_* function set
*/
- herror_t httpd_init(int argc, char *argv[]);
- void httpd_destroy(void);
+ extern herror_t httpd_init(int argc, char *argv[]);
+ extern void httpd_destroy(void);
- herror_t httpd_run(void);
+ extern herror_t httpd_run(void);
- int httpd_register(const char *ctx, httpd_service service);
- int httpd_register_secure(const char *ctx, httpd_service service,
- httpd_auth auth);
+ extern herror_t httpd_register(const char *ctx, httpd_service service);
+ extern herror_t httpd_register_secure(const char *ctx, httpd_service service, httpd_auth auth);
- int httpd_register_default(const char *ctx, httpd_service service);
- int httpd_register_default_secure(const char *ctx, httpd_service service,
- httpd_auth auth);
+ extern herror_t httpd_register_default(const char *ctx, httpd_service service);
+ extern herror_t httpd_register_default_secure(const char *ctx, httpd_service service, httpd_auth auth);
- int httpd_get_port(void);
- int httpd_get_timeout(void);
- void httpd_set_timeout(int t);
+ extern short httpd_get_port(void);
+ extern int httpd_get_timeout(void);
+ extern void httpd_set_timeout(int t);
- const char *httpd_get_protocol(void);
- int httpd_get_conncount(void);
+ extern const char *httpd_get_protocol(void);
+ extern int httpd_get_conncount(void);
- hservice_t *httpd_get_services(void);
- hservice_t *httpd_find_service(const char *name);
+ extern hservice_t *httpd_get_services(void);
+ extern hservice_t *httpd_find_service(const char *name);
- herror_t httpd_send_header(httpd_conn_t * res, int code, const char *text);
+ extern herror_t httpd_send_header(httpd_conn_t * res, int code, const char *text);
- int httpd_set_header(httpd_conn_t * conn, const char *key,
- const char *value);
- void httpd_set_headers(httpd_conn_t * conn, hpair_t * header);
+ extern int httpd_set_header(httpd_conn_t * conn, const char *key, const char *value);
+ extern void httpd_set_headers(httpd_conn_t * conn, hpair_t * header);
- int httpd_add_header(httpd_conn_t * conn, const char *key,
- const char *value);
- void httpd_add_headers(httpd_conn_t * conn, const hpair_t * values);
+ extern int httpd_add_header(httpd_conn_t * conn, const char *key, const char *value);
+ extern void httpd_add_headers(httpd_conn_t * conn, const hpair_t * values);
-/*
-unsigned char *httpd_get_postdata(httpd_conn_t *conn,
- hrequest_t *req, long *received, long max);
-*/
/* --------------------------------------------------------------
MIME RELATED FUNCTIONS
---------------------------------------------------------------*/
@@ -123,7 +137,7 @@ unsigned char *httpd_get_postdata(httpd_conn_t *conn,
Begin MIME multipart/related POST
Returns: HSOCKET_OK or error flag
*/
- herror_t httpd_mime_send_header(httpd_conn_t * conn,
+ extern herror_t httpd_mime_send_header(httpd_conn_t * conn,
const char *related_start,
const char *related_start_info,
const char *related_type, int code,
@@ -133,7 +147,7 @@ unsigned char *httpd_get_postdata(httpd_conn_t *conn,
Send boundary and part header and continue
with next part
*/
- herror_t httpd_mime_next(httpd_conn_t * conn,
+ extern herror_t httpd_mime_next(httpd_conn_t * conn,
const char *content_id,
const char *content_type,
const char *transfer_encoding);
@@ -142,7 +156,7 @@ unsigned char *httpd_get_postdata(httpd_conn_t *conn,
Send boundary and part header and continue
with next part
*/
- herror_t httpd_mime_send_file(httpd_conn_t * conn,
+ extern herror_t httpd_mime_send_file(httpd_conn_t * conn,
const char *content_id,
const char *content_type,
const char *transfer_encoding,
@@ -152,7 +166,7 @@ unsigned char *httpd_get_postdata(httpd_conn_t *conn,
Finish MIME request
Returns: HSOCKET_OK or error flag
*/
- herror_t httpd_mime_end(httpd_conn_t * conn);
+ extern herror_t httpd_mime_end(httpd_conn_t * conn);
#ifdef __cplusplus
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index d9e8900..9936379 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.62 2006/11/19 09:40:14 m0gg Exp $
+* $Id: nanohttp-socket.c,v 1.63 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -79,10 +79,10 @@ typedef int ssize_t;
#endif
-#include "nanohttp-logging.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-ssl.h"
+#include "nanohttp-logging.h"
#ifdef WIN32
static void
@@ -114,11 +114,6 @@ _hsocket_module_sys_destroy(void)
}
#endif
-/*--------------------------------------------------
-FUNCTION: hsocket_module_init
-NOTE: This will be called from httpd_init()
- for server and from httpc_init() for client
-----------------------------------------------------*/
herror_t
hsocket_module_init(int argc, char **argv)
{
@@ -127,9 +122,6 @@ hsocket_module_init(int argc, char **argv)
return hssl_module_init(argc, argv);
}
-/*--------------------------------------------------
-FUNCTION: hsocket_module_destroy
-----------------------------------------------------*/
void
hsocket_module_destroy(void)
{
@@ -138,34 +130,25 @@ hsocket_module_destroy(void)
return;
}
-/*--------------------------------------------------
-FUNCTION: hsocket_init
-----------------------------------------------------*/
herror_t
-hsocket_init(hsocket_t * sock)
+hsocket_init(struct hsocket_t * sock)
{
- memset(sock, 0, sizeof(hsocket_t));
+ memset(sock, 0, sizeof(struct hsocket_t));
sock->sock = HSOCKET_FREE;
return H_OK;
}
-/*--------------------------------------------------
-FUNCTION: hsocket_free
-----------------------------------------------------*/
void
-hsocket_free(hsocket_t * sock)
+hsocket_free(struct hsocket_t * sock)
{
/* nop */
return;
}
-/*--------------------------------------------------
-FUNCTION: hsocket_open
-----------------------------------------------------*/
herror_t
-hsocket_open(hsocket_t * dsock, const char *hostname, int port, int ssl)
+hsocket_open(struct hsocket_t * dsock, const char *hostname, int port, int ssl)
{
struct sockaddr_in address;
struct hostent *host;
@@ -209,13 +192,10 @@ hsocket_open(hsocket_t * dsock, const char *hostname, int port, int ssl)
return H_OK;
}
-/*--------------------------------------------------
-FUNCTION: hsocket_bind
-----------------------------------------------------*/
herror_t
-hsocket_bind(hsocket_t * dsock, unsigned short port)
+hsocket_bind(struct hsocket_t *dsock, unsigned short port)
{
- hsocket_t sock;
+ struct hsocket_t sock;
struct sockaddr_in addr;
int opt = 1;
@@ -234,8 +214,7 @@ hsocket_bind(hsocket_t * dsock, unsigned short port)
addr.sin_addr.s_addr = INADDR_ANY;
memset(&(addr.sin_zero), '\0', 8); /* zero the rest of the struct */
- if (bind(sock.sock, (struct sockaddr *) &addr, sizeof(struct sockaddr)) ==
- -1)
+ if (bind(sock.sock, (struct sockaddr *) &addr, sizeof(struct sockaddr)) == -1)
{
log_error2("Cannot bind socket (%s)", strerror(errno));
return herror_new("hsocket_bind", HSOCKET_ERROR_BIND, "Socket error (%s)",
@@ -247,16 +226,15 @@ hsocket_bind(hsocket_t * dsock, unsigned short port)
#ifdef WIN32
static herror_t
-_hsocket_sys_accept(hsocket_t * sock, hsocket_t * dest)
+_hsocket_sys_accept(struct hsocket_t * sock, struct hsocket_t * dest)
{
int asize;
- hsocket_t sockfd;
+ struct hsocket_t sockfd;
asize = sizeof(struct sockaddr_in);
while (1)
{
- sockfd.sock =
- accept(sock->sock, (struct sockaddr *) &(dest->addr), &asize);
+ sockfd.sock = accept(sock->sock, (struct sockaddr *) &(dest->addr), &asize);
if (sockfd.sock == INVALID_SOCKET)
{
if (WSAGetLastError() != WSAEWOULDBLOCK)
@@ -275,14 +253,13 @@ _hsocket_sys_accept(hsocket_t * sock, hsocket_t * dest)
}
#else
static herror_t
-_hsocket_sys_accept(hsocket_t * sock, hsocket_t * dest)
+_hsocket_sys_accept(struct hsocket_t * sock, struct hsocket_t * dest)
{
socklen_t len;
len = sizeof(struct sockaddr_in);
- if ((dest->sock =
- accept(sock->sock, (struct sockaddr *) &(dest->addr), &len)) == -1)
+ if ((dest->sock = accept(sock->sock, (struct sockaddr *) &(dest->addr), &len)) == -1)
{
log_warn2("accept failed (%s)", strerror(errno));
return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT,
@@ -294,11 +271,8 @@ _hsocket_sys_accept(hsocket_t * sock, hsocket_t * dest)
}
#endif
-/*----------------------------------------------------------
-FUNCTION: hsocket_accept
-----------------------------------------------------------*/
herror_t
-hsocket_accept(hsocket_t * sock, hsocket_t * dest)
+hsocket_accept(struct hsocket_t * sock, struct hsocket_t * dest)
{
herror_t status;
@@ -322,11 +296,8 @@ hsocket_accept(hsocket_t * sock, hsocket_t * dest)
return H_OK;
}
-/*--------------------------------------------------
-FUNCTION: hsocket_listen
-----------------------------------------------------*/
herror_t
-hsocket_listen(hsocket_t * sock)
+hsocket_listen(struct hsocket_t * sock)
{
if (sock->sock < 0)
return herror_new("hsocket_listen", HSOCKET_ERROR_NOT_INITIALIZED,
@@ -344,7 +315,7 @@ hsocket_listen(hsocket_t * sock)
#ifdef WIN32
static void
-_hsocket_sys_close(hsocket_t * sock)
+_hsocket_sys_close(struct hsocket_t * sock)
{
char junk[10];
@@ -359,7 +330,7 @@ _hsocket_sys_close(hsocket_t * sock)
}
#else
static inline void
-_hsocket_sys_close(hsocket_t * sock)
+_hsocket_sys_close(struct hsocket_t * sock)
{
shutdown(sock->sock, SHUT_RDWR);
@@ -370,11 +341,8 @@ _hsocket_sys_close(hsocket_t * sock)
}
#endif
-/*--------------------------------------------------
-FUNCTION: hsocket_close
-----------------------------------------------------*/
void
-hsocket_close(hsocket_t * sock)
+hsocket_close(struct hsocket_t * sock)
{
log_verbose3("closing socket %p (%d)...", sock, sock->sock);
@@ -390,11 +358,8 @@ hsocket_close(hsocket_t * sock)
return;
}
-/*--------------------------------------------------
-FUNCTION: hsocket_send
-----------------------------------------------------*/
herror_t
-hsocket_nsend(hsocket_t * sock, const unsigned char * bytes, int n)
+hsocket_nsend(struct hsocket_t * sock, const unsigned char * bytes, int n)
{
herror_t status;
size_t total = 0;
@@ -409,7 +374,6 @@ hsocket_nsend(hsocket_t * sock, const unsigned char * bytes, int n)
while (1)
{
-
if ((status = hssl_write(sock, bytes + total, n, &size)) != H_OK)
{
log_warn2("hssl_write failed (%s)", herror_message(status));
@@ -425,11 +389,8 @@ hsocket_nsend(hsocket_t * sock, const unsigned char * bytes, int n)
return H_OK;
}
-/*--------------------------------------------------
-FUNCTION: hsocket_send
-----------------------------------------------------*/
herror_t
-hsocket_send(hsocket_t * sock, const char *str)
+hsocket_send(struct hsocket_t * sock, const char *str)
{
return hsocket_nsend(sock, str, strlen(str));
}
@@ -457,8 +418,7 @@ hsocket_select_recv(int sock, char *buf, size_t len)
}
herror_t
-hsocket_read(hsocket_t * sock, unsigned char * buffer, int total, int force,
- int *received)
+hsocket_read(struct hsocket_t * sock, unsigned char * buffer, int total, int force, int *received)
{
herror_t status;
size_t totalRead;
@@ -470,9 +430,7 @@ hsocket_read(hsocket_t * sock, unsigned char * buffer, int total, int force,
do
{
- if ((status =
- hssl_read(sock, &buffer[totalRead], (size_t) total - totalRead,
- &count)) != H_OK)
+ if ((status = hssl_read(sock, &buffer[totalRead], (size_t) total - totalRead, &count)) != H_OK)
{
log_warn2("hssl_read failed (%s)", herror_message(status));
return status;
diff --git a/nanohttp/nanohttp-socket.h b/nanohttp/nanohttp-socket.h
index 9bb88b5..a9e4ef6 100644
--- a/nanohttp/nanohttp-socket.h
+++ b/nanohttp/nanohttp-socket.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-socket.h,v 1.30 2006/11/19 09:40:14 m0gg Exp $
+ * $Id: nanohttp-socket.h,v 1.31 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -29,7 +29,7 @@
/*
Socket definition
*/
-typedef struct hsocket_t
+struct hsocket_t
{
#ifdef WIN32
SOCKET sock;
@@ -40,8 +40,7 @@ typedef struct hsocket_t
size_t bytes_transmitted;
size_t bytes_received;
void *ssl;
-}
-hsocket_t; /* end of socket definition */
+};
#ifdef __cplusplus
extern "C"
@@ -49,157 +48,166 @@ extern "C"
#endif
/**
- Initializes the socket modul. This should be called only
- once for an application.
-
- @returns This function should always return H_OK.
+ *
+ * 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(int argc, char **argv);
+extern herror_t hsocket_module_init(int argc, char **argv);
/**
- Destroys the socket modul. This should be called after
- finishing an application.
-*/
- void hsocket_module_destroy(void);
-
+ *
+ * Destroys the socket modul. This should be called after finishing an
+ * application.
+ *
+ */
+extern void hsocket_module_destroy(void);
/**
- Initializes a given socket object. This function (or
- hsokcet_init_ssl) should
- be called for every socket before using it.
-
- @param sock the destination socket to initialize.
-
- @see hsocket_init_ssl
- @returns This function should always return H_OK.
+ *
+ * Initializes a given socket object. This function (or hsokcet_init_ssl) should
+ * be called for every socket before using it.
+ *
+ * @param sock the destination socket to initialize.
+ *
+ * @returns This function should always return H_OK.
+ *
+ * @see hsocket_init_ssl
+ *
*/
- herror_t hsocket_init(hsocket_t * sock);
+extern herror_t hsocket_init(struct hsocket_t * sock);
/**
- Destroys and releases a given socket.
-
- @param sock the socket to destroy
-*/
- void hsocket_free(hsocket_t * sock);
-
+ *
+ * Destroys and releases a given socket.
+ *
+ * @param sock the socket to destroy
+ *
+ */
+extern void hsocket_free(struct 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
- @param ssl whether to open a SSL connection
-
- @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
+ *
+ * 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
+ * @param ssl whether to open a SSL connection
+ *
+ * @returns H_OK if success. One of the followings if fails:<P>
+ * - HSOCKET_ERROR_CREATE
+ * - HSOCKET_ERROR_GET_HOSTNAME
+ * - HSOCKET_ERROR_CONNECT
+ *
*/
- herror_t hsocket_open(hsocket_t * sock, const char *host, int port,
- int ssl);
-
+extern herror_t hsocket_open(struct hsocket_t *sock, const char *host, int port, int ssl);
/**
- Close a socket connection.
-
- @param sock the socket to close
-*/
- void hsocket_close(hsocket_t * sock);
+ *
+ * Close a socket connection.
+ *
+ * @param sock the socket to close
+ *
+ */
+extern void hsocket_close(struct 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
+ *
+ * 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>
+ * - HSOCKET_ERROR_CREATE
+ * - HSOCKET_ERROR_BIND
+ *
+ * @see hsocket_listen
+ *
*/
- herror_t hsocket_bind(hsocket_t * sock, unsigned short port);
-
+extern herror_t hsocket_bind(struct hsocket_t *sock, unsigned short 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);
-
+ *
+ * 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>
+ * - HSOCKET_ERROR_NOT_INITIALIZED
+ * - HSOCKET_ERROR_LISTEN
+ */
+extern herror_t hsocket_listen(struct 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);
-
+ *
+ * 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>
+ * - HSOCKET_ERROR_NOT_INITIALIZED
+ * - HSOCKET_ERROR_ACCEPT
+ */
+extern herror_t hsocket_accept(struct hsocket_t *sock, struct 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 unsigned char *bytes, int size);
+ *
+ * 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>
+ * - HSOCKET_ERROR_NOT_INITIALIZED
+ * - HSOCKET_ERROR_SEND
+ */
+extern herror_t hsocket_nsend(struct hsocket_t *sock, const unsigned char *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);
+ *
+ * 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>
+ * - HSOCKET_ERROR_NOT_INITIALIZED
+ * - HSOCKET_ERROR_SEND
+ *
+ */
+extern herror_t hsocket_send(struct hsocket_t *sock, const char *str);
+extern int hsocket_select_read(int sock, char *buf, size_t len);
- int hsocket_select_read(int sock, char *buf, size_t len);
/**
- 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, unsigned char *buffer, int size,
- int force, int *readed);
+ *
+ * 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.
+ *
+ */
+extern herror_t hsocket_read(struct hsocket_t * sock, unsigned char *buffer, int size, int force, int *readed);
#ifdef __cplusplus
}
diff --git a/nanohttp/nanohttp-ssl.c b/nanohttp/nanohttp-ssl.c
index d8e6e3f..8dbc948 100644
--- a/nanohttp/nanohttp-ssl.c
+++ b/nanohttp/nanohttp-ssl.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-ssl.c,v 1.29 2006/11/19 09:40:14 m0gg Exp $
+* $Id: nanohttp-ssl.c,v 1.30 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2001-2005 Rochester Institute of Technology
@@ -71,9 +71,10 @@
#endif
#endif
-#include "nanohttp-logging.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
+#include "nanohttp-logging.h"
+
#include "nanohttp-ssl.h"
#ifdef HAVE_SSL
@@ -85,9 +86,42 @@ static SSL_CTX *context = NULL;
static int enabled = 0;
-static int _hssl_dummy_verify_cert(X509 * cert);
+static int
+_hssl_dummy_verify_cert(X509 * cert)
+{
+ /* TODO: Make sure that the client is providing a client cert, or that the
+ Module is providing the Module cert */
+
+ /* connect to anyone */
+
+ log_verbose1("Validating certificate.");
+ return 1;
+}
+
int (*_hssl_verify_cert) (X509 * cert) = _hssl_dummy_verify_cert;
+static int
+_hssl_cert_verify_callback(int prev_ok, X509_STORE_CTX * ctx)
+{
+/*
+ if ((X509_STORE_CTX_get_error(ctx) = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN))
+ {
+ log_verbose1("Self signed cert in chain");
+ return 1;
+ }
+*/
+ log_verbose2("Cert depth = %d", X509_STORE_CTX_get_error_depth(ctx));
+ if (X509_STORE_CTX_get_error_depth(ctx) == 0)
+ {
+ return _hssl_verify_cert(X509_STORE_CTX_get_current_cert(ctx));
+ }
+ else
+ {
+ log_verbose1("Cert ok (prev)");
+ return prev_ok;
+ }
+}
+
static void
_hssl_superseed(void)
{
@@ -104,7 +138,6 @@ _hssl_superseed(void)
return;
}
-
static char *
_hssl_get_error(SSL * ssl, int ret)
{
@@ -133,7 +166,6 @@ _hssl_get_error(SSL * ssl, int ret)
}
}
-
static int
_hssl_password_callback(char *buf, int num, int rwflag, void *userdata)
{
@@ -145,10 +177,10 @@ _hssl_password_callback(char *buf, int num, int rwflag, void *userdata)
return 0;
strcpy(buf, certpass);
+
return ret;
}
-
int
verify_sn(X509 * cert, int who, int nid, char *str)
{
@@ -179,70 +211,45 @@ void
hssl_set_hssl_verify_cert(int func(X509 * cert))
{
_hssl_verify_cert = func;
-}
-
-static int
-_hssl_dummy_verify_cert(X509 * cert)
-{
- /* TODO: Make sure that the client is providing a client cert, or that the
- Module is providing the Module cert */
-
- /* connect to anyone */
-
- log_verbose1("Validating certificate.");
- return 1;
-}
-static int
-_hssl_cert_verify_callback(int prev_ok, X509_STORE_CTX * ctx)
-{
-/*
- if ((X509_STORE_CTX_get_error(ctx) = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN))
- {
- log_verbose1("Self signed cert in chain");
- return 1;
- }
-*/
- log_verbose2("Cert depth = %d", X509_STORE_CTX_get_error_depth(ctx));
- if (X509_STORE_CTX_get_error_depth(ctx) == 0)
- {
- return _hssl_verify_cert(X509_STORE_CTX_get_current_cert(ctx));
- }
- else
- {
- log_verbose1("Cert ok (prev)");
- return prev_ok;
- }
+ return;
}
void
hssl_set_certificate(char *c)
{
certificate = c;
+
+ return;
}
void
hssl_set_certpass(char *c)
{
certpass = c;
+
+ return;
}
void
hssl_set_ca(char *c)
{
ca_list = c;
+
+ return;
}
void
hssl_enable(void)
{
enabled = 1;
+
+ return;
}
static void
_hssl_parse_arguments(int argc, char **argv)
{
-
int i;
for (i = 1; i < argc; i++)
@@ -259,7 +266,7 @@ _hssl_parse_arguments(int argc, char **argv)
{
ca_list = argv[i];
}
- else if (!strcmp(argv[i - 1], NHTTP_ARG_HTTPS))
+ else if (!strcmp(argv[i - 1], NHTTPD_ARG_HTTPS))
{
enabled = 1;
}
@@ -268,7 +275,6 @@ _hssl_parse_arguments(int argc, char **argv)
return;
}
-
static void
_hssl_library_init(void)
{
@@ -291,7 +297,6 @@ _hssl_library_init(void)
return;
}
-
static herror_t
_hssl_server_context_init(void)
{
@@ -352,7 +357,6 @@ _hssl_server_context_init(void)
return H_OK;
}
-
static void
_hssl_server_context_destroy(void)
{
@@ -364,7 +368,6 @@ _hssl_server_context_destroy(void)
return;
}
-
herror_t
hssl_module_init(int argc, char **argv)
{
@@ -383,7 +386,6 @@ hssl_module_init(int argc, char **argv)
return _hssl_server_context_init();
}
-
void
hssl_module_destroy(void)
{
@@ -392,16 +394,14 @@ hssl_module_destroy(void)
return;
}
-
int
hssl_enabled(void)
{
return enabled;
}
-
herror_t
-hssl_client_ssl(hsocket_t * sock)
+hssl_client_ssl(struct hsocket_t * sock)
{
SSL *ssl;
int ret;
@@ -452,7 +452,7 @@ _hssl_bio_read(BIO * b, char *out, int outl)
}
herror_t
-hssl_server_ssl(hsocket_t * sock)
+hssl_server_ssl(struct hsocket_t *sock)
{
SSL *ssl;
int ret;
@@ -502,9 +502,8 @@ hssl_server_ssl(hsocket_t * sock)
return H_OK;
}
-
void
-hssl_cleanup(hsocket_t * sock)
+hssl_cleanup(struct hsocket_t * sock)
{
if (sock->ssl)
{
@@ -517,7 +516,7 @@ hssl_cleanup(hsocket_t * sock)
}
herror_t
-hssl_read(hsocket_t * sock, char *buf, size_t len, size_t * received)
+hssl_read(struct hsocket_t * sock, char *buf, size_t len, size_t * received)
{
int count;
@@ -544,7 +543,7 @@ hssl_read(hsocket_t * sock, char *buf, size_t len, size_t * received)
herror_t
-hssl_write(hsocket_t * sock, const char *buf, size_t len, size_t * sent)
+hssl_write(struct hsocket_t * sock, const char *buf, size_t len, size_t * sent)
{
int count;
@@ -572,7 +571,7 @@ hssl_write(hsocket_t * sock, const char *buf, size_t len, size_t * sent)
#else
herror_t
-hssl_read(hsocket_t * sock, char *buf, size_t len, size_t * received)
+hssl_read(struct hsocket_t * sock, char *buf, size_t len, size_t * received)
{
int count;
@@ -587,7 +586,7 @@ hssl_read(hsocket_t * sock, char *buf, size_t len, size_t * received)
herror_t
-hssl_write(hsocket_t * sock, const char *buf, size_t len, size_t * sent)
+hssl_write(struct hsocket_t * sock, const char *buf, size_t len, size_t * sent)
{
int count;
diff --git a/nanohttp/nanohttp-ssl.h b/nanohttp/nanohttp-ssl.h
index e81668d..f796356 100644
--- a/nanohttp/nanohttp-ssl.h
+++ b/nanohttp/nanohttp-ssl.h
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-ssl.h,v 1.19 2006/11/19 09:40:14 m0gg Exp $
+* $Id: nanohttp-ssl.h,v 1.20 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2001-2005 Rochester Institute of Technology
@@ -34,6 +34,13 @@
#include <openssl/ssl.h>
#endif
+/**
+ *
+ * Commandline argument to enabled SSL in the nanoHTTP server.
+ *
+ */
+#define NHTTPD_ARG_HTTPS "-NHTTPS"
+
#ifdef __cplusplus
extern "C"
{
@@ -44,26 +51,26 @@ extern "C"
* Initialization and shutdown of the SSL module
*
*/
- herror_t hssl_module_init(int argc, char **argv);
- void hssl_module_destroy(void);
+extern herror_t hssl_module_init(int argc, char **argv);
+extern void hssl_module_destroy(void);
- void hssl_set_certificate(char *c);
- void hssl_set_certpass(char *c);
- void hssl_set_ca(char *c);
+extern void hssl_set_certificate(char *c);
+extern void hssl_set_certpass(char *c);
+extern void hssl_set_ca(char *c);
- void hssl_enable(void);
+extern void hssl_enable(void);
- int hssl_enabled(void);
+extern int hssl_enabled(void);
/**
*
* Socket initialization and shutdown
*
*/
- herror_t hssl_client_ssl(hsocket_t * sock);
- herror_t hssl_server_ssl(hsocket_t * sock);
+extern herror_t hssl_client_ssl(struct hsocket_t * sock);
+extern herror_t hssl_server_ssl(struct hsocket_t * sock);
- void hssl_cleanup(hsocket_t * sock);
+extern void hssl_cleanup(struct hsocket_t * sock);
/*
* Callback for password checker
@@ -77,7 +84,7 @@ extern "C"
*/
#define CERT_SUBJECT 1
- int verify_sn(X509 * cert, int who, int nid, char *str);
+extern int verify_sn(X509 * cert, int who, int nid, char *str);
/*
* Called by framework for verify
@@ -85,7 +92,7 @@ extern "C"
/* static int verify_cb(int prev_ok, X509_STORE_CTX* ctx); */
- void hssl_set_user_verify(int func(X509 * cert));
+extern void hssl_set_user_verify(int func(X509 * cert));
#ifdef __cplusplus
}
@@ -98,6 +105,7 @@ hssl_module_init(int argc, char **argv)
{
return H_OK;
}
+
static inline void
hssl_module_destroy(void)
{
@@ -111,19 +119,19 @@ hssl_enabled(void)
}
static inline herror_t
-hssl_client_ssl(hsocket_t * sock)
+hssl_client_ssl(struct hsocket_t *sock)
{
return H_OK;
}
static inline herror_t
-hssl_server_ssl(hsocket_t * sock)
+hssl_server_ssl(struct hsocket_t *sock)
{
return H_OK;
}
static inline void
-hssl_cleanup(hsocket_t * sock)
+hssl_cleanup(struct hsocket_t *sock)
{
return;
}
@@ -135,10 +143,8 @@ extern "C"
{
#endif
- herror_t hssl_read(hsocket_t * sock, char *buf, size_t len,
- size_t * received);
- herror_t hssl_write(hsocket_t * sock, const char *buf, size_t len,
- size_t * sent);
+extern herror_t hssl_read(struct hsocket_t * sock, char *buf, size_t len, size_t * received);
+extern herror_t hssl_write(struct hsocket_t * sock, const char *buf, size_t len, size_t * sent);
#ifdef __cplusplus
}
diff --git a/nanohttp/nanohttp-stream.c b/nanohttp/nanohttp-stream.c
index 27d8d62..09d06b2 100755
--- a/nanohttp/nanohttp-stream.c
+++ b/nanohttp/nanohttp-stream.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-stream.c,v 1.14 2006/11/19 09:40:14 m0gg Exp $
+* $Id: nanohttp-stream.c,v 1.15 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -79,16 +79,16 @@ _http_stream_is_chunked(hpair_t * header)
/**
Creates a new input stream.
*/
-http_input_stream_t *
-http_input_stream_new(hsocket_t *sock, hpair_t * header)
+struct http_input_stream_t *
+http_input_stream_new(struct hsocket_t *sock, hpair_t * header)
{
- http_input_stream_t *result;
+ struct http_input_stream_t *result;
char *content_length;
/* Paranoya check */
/* if (header == NULL) return NULL; */
/* Create object */
- if (!(result = (http_input_stream_t *) malloc(sizeof(http_input_stream_t))))
+ if (!(result = (struct http_input_stream_t *) malloc(sizeof(struct http_input_stream_t))))
{
log_error2("malloc failed (%s)", strerror(errno));
return NULL;
@@ -132,10 +132,10 @@ http_input_stream_new(hsocket_t *sock, hpair_t * header)
This function was added for MIME messages
and for debugging.
*/
-http_input_stream_t *
+struct http_input_stream_t *
http_input_stream_new_from_file(const char *filename)
{
- http_input_stream_t *result;
+ struct http_input_stream_t *result;
FILE *fd;
if (!(fd = fopen(filename, "rb"))) {
@@ -145,7 +145,7 @@ http_input_stream_new_from_file(const char *filename)
}
/* Create object */
- if (!(result = (http_input_stream_t *) malloc(sizeof(http_input_stream_t))))
+ if (!(result = (struct http_input_stream_t *) malloc(sizeof(struct http_input_stream_t))))
{
log_error2("malloc failed (%s)", strerror(errno));
fclose(fd);
@@ -164,7 +164,7 @@ http_input_stream_new_from_file(const char *filename)
Free input stream
*/
void
-http_input_stream_free(http_input_stream_t * stream)
+http_input_stream_free(struct http_input_stream_t * stream)
{
if (stream->type == HTTP_TRANSFER_FILE && stream->fd)
{
@@ -178,31 +178,31 @@ http_input_stream_free(http_input_stream_t * stream)
}
static int
-_http_input_stream_is_content_length_ready(http_input_stream_t * stream)
+_http_input_stream_is_content_length_ready(struct http_input_stream_t * stream)
{
return (stream->content_length > stream->received);
}
static int
-_http_input_stream_is_chunked_ready(http_input_stream_t * stream)
+_http_input_stream_is_chunked_ready(struct http_input_stream_t * stream)
{
return stream->chunk_size != 0;
}
static int
-_http_input_stream_is_connection_closed_ready(http_input_stream_t * stream)
+_http_input_stream_is_connection_closed_ready(struct http_input_stream_t * stream)
{
return !stream->connection_closed;
}
static int
-_http_input_stream_is_file_ready(http_input_stream_t * stream)
+_http_input_stream_is_file_ready(struct http_input_stream_t * stream)
{
return !feof(stream->fd);
}
static int
-_http_input_stream_content_length_read(http_input_stream_t * stream, unsigned char *dest, int size)
+_http_input_stream_content_length_read(struct http_input_stream_t * stream, unsigned char *dest, int size)
{
herror_t status;
int read;
@@ -223,7 +223,7 @@ _http_input_stream_content_length_read(http_input_stream_t * stream, unsigned ch
}
static int
-_http_input_stream_chunked_read_chunk_size(http_input_stream_t * stream)
+_http_input_stream_chunked_read_chunk_size(struct http_input_stream_t * stream)
{
char chunk[25];
int status, i = 0;
@@ -282,7 +282,7 @@ _http_input_stream_chunked_read_chunk_size(http_input_stream_t * stream)
}
static int
-_http_input_stream_chunked_read(http_input_stream_t * stream, unsigned char *dest,
+_http_input_stream_chunked_read(struct http_input_stream_t * stream, unsigned char *dest,
int size)
{
int status, counter;
@@ -386,8 +386,7 @@ _http_input_stream_chunked_read(http_input_stream_t * stream, unsigned char *des
static int
-_http_input_stream_connection_closed_read(http_input_stream_t * stream,
- unsigned char *dest, int size)
+_http_input_stream_connection_closed_read(struct http_input_stream_t * stream, unsigned char *dest, int size)
{
int status;
herror_t err;
@@ -407,7 +406,7 @@ _http_input_stream_connection_closed_read(http_input_stream_t * stream,
}
static int
-_http_input_stream_file_read(http_input_stream_t * stream, unsigned char *dest, int size)
+_http_input_stream_file_read(struct http_input_stream_t * stream, unsigned char *dest, int size)
{
size_t len;
@@ -425,7 +424,7 @@ _http_input_stream_file_read(http_input_stream_t * stream, unsigned char *dest,
Returns the actual status of the stream.
*/
int
-http_input_stream_is_ready(http_input_stream_t * stream)
+http_input_stream_is_ready(struct http_input_stream_t * stream)
{
/* paranoia check */
if (stream == NULL)
@@ -455,7 +454,7 @@ http_input_stream_is_ready(http_input_stream_t * stream)
<0 on error
*/
int
-http_input_stream_read(http_input_stream_t * stream, unsigned char *dest, int size)
+http_input_stream_read(struct http_input_stream_t * stream, unsigned char *dest, int size)
{
int len = 0;
/* paranoia check */
@@ -505,10 +504,10 @@ HTTP OUTPUT STREAM
/**
Creates a new output stream. Transfer code will be found from header.
*/
-http_output_stream_t *
-http_output_stream_new(hsocket_t *sock, hpair_t * header)
+struct http_output_stream_t *
+http_output_stream_new(struct hsocket_t *sock, hpair_t * header)
{
- http_output_stream_t *result;
+ struct http_output_stream_t *result;
char *content_length;
/* Paranoya check */
@@ -516,7 +515,7 @@ http_output_stream_new(hsocket_t *sock, hpair_t * header)
return NULL;
*/
/* Create object */
- if (!(result = (http_output_stream_t *) malloc(sizeof(http_output_stream_t))))
+ if (!(result = (struct http_output_stream_t *) malloc(sizeof(struct http_output_stream_t))))
{
log_error2("malloc failed (%s)", strerror(errno));
return NULL;
@@ -555,7 +554,7 @@ http_output_stream_new(hsocket_t *sock, hpair_t * header)
Free output stream
*/
void
-http_output_stream_free(http_output_stream_t * stream)
+http_output_stream_free(struct http_output_stream_t * stream)
{
free(stream);
@@ -567,7 +566,7 @@ http_output_stream_free(http_output_stream_t * stream)
Returns socket error flags or H_OK.
*/
herror_t
-http_output_stream_write(http_output_stream_t * stream,
+http_output_stream_write(struct http_output_stream_t * stream,
const unsigned char *bytes, int size)
{
herror_t status;
@@ -600,7 +599,7 @@ http_output_stream_write(http_output_stream_t * stream,
Returns socket error flags or H_OK.
*/
herror_t
-http_output_stream_write_string(http_output_stream_t * stream,
+http_output_stream_write_string(struct http_output_stream_t * stream,
const char *str)
{
return http_output_stream_write(stream, str, strlen(str));
@@ -608,7 +607,7 @@ http_output_stream_write_string(http_output_stream_t * stream,
herror_t
-http_output_stream_flush(http_output_stream_t * stream)
+http_output_stream_flush(struct http_output_stream_t * stream)
{
herror_t status;
diff --git a/nanohttp/nanohttp-stream.h b/nanohttp/nanohttp-stream.h
index 88e783e..cb37deb 100755
--- a/nanohttp/nanohttp-stream.h
+++ b/nanohttp/nanohttp-stream.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-stream.h,v 1.11 2006/11/19 09:40:14 m0gg Exp $
+ * $Id: nanohttp-stream.h,v 1.12 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -24,35 +24,38 @@
#ifndef __nanohttp_stream_h
#define __nanohttp_stream_h
-/*
- HTTP Stream modul:
-
- nanohttp supports 2 different streams:
-
- 1. http_input_stream_t
- 2. http_output_stream_t
-
- These are not regular streams. They will care about
- transfer styles while sending/receiving data.
-
- Supported transfer styles are
-
- o Content-length
- o Chunked encoding
- o Connection: "close"
-
- A stream will set its transfer style from the header
- information, which must be given while creating a stream.
-
- A stream will start sending/receiving data "after"
- sending/receiving header information. (After <CF><CF>)"
-
-*/
+/**
+ *
+ * HTTP Stream modul:
+ *
+ * nanohttp supports 2 different streams:
+ *
+ * 1. http_input_stream_t
+ * 2. http_output_stream_t
+ *
+ * These are not regular streams. They will care about transfer styles while
+ * sending/receiving data.
+ *
+ * Supported transfer styles are
+ *
+ * - Content-length
+ * - Chunked encoding
+ * - Connection: "close"
+ *
+ * A stream will set its transfer style from the header information, which must
+ * be given while creating a stream.
+ *
+ * A stream will start sending/receiving data "after" sending/receiving header
+ * information. (After <CF><CF>)"
+ *
+ */
/**
- Transfer types supported while
- sending/receiving data.
-*/
+ *
+ * Transfer types supported while
+ * sending/receiving data.
+ *
+ */
typedef enum http_transfer_type
{
/** The stream cares about Content-length */
@@ -61,23 +64,23 @@ typedef enum http_transfer_type
/** The stream sends/receives chunked data */
HTTP_TRANSFER_CHUNKED,
- /** The stream sends/receives data until
- connection is closed */
+ /** The stream sends/receives data until connection is closed */
HTTP_TRANSFER_CONNECTION_CLOSE,
- /** This transfer style will be used by MIME support
- and for debug purposes.*/
+ /** This transfer style will be used by MIME support and for debug purposes.*/
HTTP_TRANSFER_FILE
} http_transfer_type_t;
/**
- HTTP INPUT STREAM. Receives data from a socket/file
- and cares about the transfer style.
-*/
-typedef struct http_input_stream
+ *
+ * HTTP INPUT STREAM. Receives data from a socket/file
+ * and cares about the transfer style.
+ *
+ */
+struct http_input_stream_t
{
- hsocket_t *sock;
+ struct hsocket_t *sock;
herror_t err;
http_transfer_type_t type;
int received;
@@ -89,180 +92,175 @@ typedef struct http_input_stream
FILE *fd;
char filename[255];
int deleteOnExit; /* default is 0 */
-} http_input_stream_t;
-
+};
/**
- HTTP OUTPUT STREAM. Sends data to a socket
- and cares about the transfer style.
-*/
-typedef struct http_output_stream
+ *
+ * HTTP OUTPUT STREAM. Sends data to a socket
+ * and cares about the transfer style.
+ *
+ */
+struct http_output_stream_t
{
- hsocket_t *sock;
+ struct hsocket_t *sock;
http_transfer_type_t type;
int content_length;
int sent;
-} http_output_stream_t;
+};
#ifdef __cplusplus
extern "C" {
#endif
-/*
---------------------------------------------------------------
- HTTP INPUT STREAM
---------------------------------------------------------------
-*/
-
/**
- Creates a new input stream. The transfer style will be
- choosen from the given header.
-
- @param sock the socket to receive data from
- @param header the http header. This must be received before
- creating a http_input_stream_t.
-
- @returns a newly created http_input_stream_t object. If no
- transfer style was found in the header,
- HTTP_TRANSFER_CONNECTION_CLOSE will be used as default.
-
- @see http_input_stream_free
-*/
-http_input_stream_t *http_input_stream_new(hsocket_t *sock, hpair_t *header);
-
+ *
+ * Creates a new input stream. The transfer style will be
+ * choosen from the given header.
+ *
+ * @param sock the socket to receive data from
+ * @param header the http header. This must be received before
+ * creating a http_input_stream_t.
+ *
+ * @returns a newly created http_input_stream_t object. If no transfer style was
+ * found in the header, HTTP_TRANSFER_CONNECTION_CLOSE will be used as
+ * default.
+ *
+ * @see http_input_stream_free
+ *
+ */
+extern struct http_input_stream_t *http_input_stream_new(struct hsocket_t *sock, hpair_t *header);
/**
- Creates a new input stream from file.
- This function was added for MIME messages
- and for debugging. The transfer style is always
- HTTP_TRANSFER_FILE.
-
- @param filename the name of the file to open and read.
-
- @returns The return value is a http_input_stream_t object
- if the file exists and could be opened. NULL otherwise.
-
- @see http_input_stream_free
-*/
-http_input_stream_t *http_input_stream_new_from_file(const char *filename);
-
+ *
+ * Creates a new input stream from file. This function was added for MIME
+ * messages and for debugging. The transfer style is always HTTP_TRANSFER_FILE.
+ *
+ * @param filename the name of the file to open and read.
+ *
+ * @returns The return value is a http_input_stream_t object if the file exists
+ * and could be opened. NULL otherwise.
+ *
+ * @see http_input_stream_free
+ *
+ */
+extern struct http_input_stream_t *http_input_stream_new_from_file(const char *filename);
/**
- Free input stream. Note that the socket will not be closed
- by this functions.
-
- @param stream the input stream to free.
-*/
-void http_input_stream_free(http_input_stream_t * stream);
-
+ *
+ * Free input stream. Note that the socket will not be closed by this functions.
+ *
+ * @param stream the input stream to free.
+ *
+ */
+extern void http_input_stream_free(struct http_input_stream_t * stream);
/**
- Returns the actual status of the stream.
-
- @param stream the stream to check its status
- @returns <br>1 if there are still data to read.
- <br>0 if no more data exists.
-*/
-int http_input_stream_is_ready(http_input_stream_t * stream);
-
+ *
+ * Returns the actual status of the stream.
+ *
+ * @param stream the stream to check its status
+ *
+ * @returns <br>1 if there are still data to read.
+ * <br>0 if no more data exists.
+ */
+extern int http_input_stream_is_ready(struct http_input_stream_t * stream);
/**
- Tries to read 'size' bytes from the stream. Check always
- with http_input_stream_is_ready() if there are some data
- to read. If it returns 0, no more data is available on
- stream.
- <P>
- On error this function will return -1. In this case the
- "err" field of stream will be set to the actual error.
- This can be one of the followings: <P>
-
- <BR>STREAM_ERROR_NO_CHUNK_SIZE
- <BR>STREAM_ERROR_WRONG_CHUNK_SIZE
- <BR>STREAM_ERROR_INVALID_TYPE
- <BR>HSOCKET_ERROR_RECEIVE
-
- @param stream the stream to read data from
- @param dest destination memory to store readed bytes
- @param size maximum size of 'dest' (size to read)
-
- @returns the actual readed bytes or -1 on error.
-*/
-int http_input_stream_read(http_input_stream_t * stream,
- unsigned char* dest, int size);
-
-
-/*
---------------------------------------------------------------
- HTTP OUTPUT STREAM
---------------------------------------------------------------
-*/
+ *
+ * Tries to read 'size' bytes from the stream. Check always with
+ * http_input_stream_is_ready() if there are some data to read. If it returns 0,
+ * no more data is available on stream.
+ *
+ * On error this function will return -1. In this case the "err" field of stream
+ * will be set to the actual error. This can be one of the followings:
+ *
+ * - STREAM_ERROR_NO_CHUNK_SIZE
+ * - STREAM_ERROR_WRONG_CHUNK_SIZE
+ * - STREAM_ERROR_INVALID_TYPE
+ * - HSOCKET_ERROR_RECEIVE
+ *
+ * @param stream the stream to read data from
+ * @param dest destination memory to store readed bytes
+ * @param size maximum size of 'dest' (size to read)
+ *
+ * @returns the actual readed bytes or -1 on error.
+ *
+ */
+extern int http_input_stream_read(struct http_input_stream_t * stream, unsigned char *dest, int size);
/**
- Creates a new output stream. Transfer style will be found
- from the given header.
-
- @param sock the socket to to send data to
- @param header the header which must be sent before
-
- @returns a http_output_stream_t object. If no proper transfer
- style was found in the header, HTTP_TRANSFER_CONNECTION_CLOSE
- will be used as default.
-
- @see http_output_stream_free
-*/
-http_output_stream_t *http_output_stream_new(hsocket_t *sock,
- hpair_t * header);
+ *
+ * Creates a new output stream. Transfer style will be found from the given
+ * header.
+ *
+ * @param sock the socket to to send data to
+ * @param header the header which must be sent before
+ *
+ * @returns a http_output_stream_t object. If no proper transfer style was found
+ * in the header, HTTP_TRANSFER_CONNECTION_CLOSE will be used as default.
+ *
+ * @see http_output_stream_free
+ *
+ */
+extern struct http_output_stream_t *http_output_stream_new(struct hsocket_t *sock, hpair_t * header);
/**
- Free output stream. Note that this functions will not
- close any socket connections.
-
- @param stream the stream to free.
-*/
-void http_output_stream_free(http_output_stream_t * stream);
-
+ *
+ * Free output stream. Note that this functions will not close any socket
+ * connections.
+ *
+ * @param stream the stream to free.
+ *
+ */
+extern void http_output_stream_free(struct http_output_stream_t * stream);
/**
- Writes 'size' bytes of 'bytes' into stream.
-
- @param stream the stream to use to send data
- @param bytes bytes to send
- @param size size of bytes to send
-
- @returns H_OK if success. One of the followings otherwise
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_SEND
-*/
-herror_t http_output_stream_write(http_output_stream_t * stream,
- const unsigned char* bytes, int size);
+ *
+ * Writes 'size' bytes of 'bytes' into stream.
+ *
+ * @param stream the stream to use to send data
+ * @param bytes bytes to send
+ * @param size size of bytes to send
+ *
+ * @returns H_OK if success. One of the followings otherwise
+ *
+ * - HSOCKET_ERROR_NOT_INITIALIZED
+ * - HSOCKET_ERROR_SEND
+ *
+ */
+extern herror_t http_output_stream_write(struct http_output_stream_t *stream, const unsigned char* bytes, int size);
/**
- Writes a null terminated string to the stream.
-
- @param stream the stream to use to send data
- @param str a null terminated string to send
-
- @returns H_OK if success. One of the followings otherwise
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_SEND
-*/
-herror_t http_output_stream_write_string(http_output_stream_t * stream,
- const char *str);
-
+ *
+ * Writes a null terminated string to the stream.
+ *
+ * @param stream the stream to use to send data
+ * @param str a null terminated string to send
+ *
+ * @returns H_OK if success. One of the followings otherwise
+ *
+ * - HSOCKET_ERROR_NOT_INITIALIZED
+ * - HSOCKET_ERROR_SEND
+ *
+ */
+extern herror_t http_output_stream_write_string(struct http_output_stream_t *stream, const char *str);
/**
- Sends finish flags if nesseccary (like in chunked transport).
- Call always this function before closing the connections.
-
- @param stream the stream to send post data.
-
- @returns H_OK if success. One of the followings otherwise
- <BR>HSOCKET_ERROR_NOT_INITIALIZED
- <BR>HSOCKET_ERROR_SEND
-*/
-herror_t http_output_stream_flush(http_output_stream_t * stream);
+ *
+ * Sends finish flags if nesseccary (like in chunked transport).
+ * Call always this function before closing the connections.
+ *
+ * @param stream the stream to send post data.
+ *
+ * @returns H_OK if success. One of the followings otherwise
+ *
+ * - HSOCKET_ERROR_NOT_INITIALIZED
+ * - HSOCKET_ERROR_SEND
+ *
+ */
+extern herror_t http_output_stream_flush(struct http_output_stream_t *stream);
#ifdef __cplusplus
}