summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGravatar m0gg2006-11-23 15:27:32 +0000
committerGravatar m0gg2006-11-23 15:27:32 +0000
commit6457c46897d6e0c63476bf4ba4ca14b4844fac0d (patch)
treeb1f892f4f1d7cb58ff50660c73947847447a14ce /examples
parent06906cd337028c9e42e10916d08db64e1e22d0f1 (diff)
downloadcsoap-6457c46897d6e0c63476bf4ba4ca14b4844fac0d.tar.gz
csoap-6457c46897d6e0c63476bf4ba4ca14b4844fac0d.tar.bz2
Code cleanup
Diffstat (limited to 'examples')
-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
7 files changed, 58 insertions, 96 deletions
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);