From f1f5c38793bfc6160e1e377d3061e8ba592e3057 Mon Sep 17 00:00:00 2001 From: snowdrop Date: Fri, 15 Oct 2004 13:42:07 +0000 Subject: development --- examples/csoap/echoattachments-client.c | 142 ++++++++++++++++++++++++++++++++ examples/csoap/echoattachments-server.c | 81 ++++++++++++++++++ examples/csoap/simpleclient.c | 29 ++++++- examples/csoap/simpleserver.c | 14 ++-- 4 files changed, 257 insertions(+), 9 deletions(-) create mode 100755 examples/csoap/echoattachments-client.c create mode 100755 examples/csoap/echoattachments-server.c (limited to 'examples/csoap') diff --git a/examples/csoap/echoattachments-client.c b/examples/csoap/echoattachments-client.c new file mode 100755 index 0000000..9bf4559 --- /dev/null +++ b/examples/csoap/echoattachments-client.c @@ -0,0 +1,142 @@ +/****************************************************************** + * $Id: echoattachments-client.c,v 1.1 2004/10/15 13:42:57 snowdrop Exp $ + * + * CSOAP Project: CSOAP examples project + * Copyright (C) 2003 Ferhat Ayaz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA + * + * Email: ayaz@jprogrammer.net + ******************************************************************/ + +#include + + +/* +static const char *url = "http://csoap.sourceforge.net/cgi-bin/csoapserver"; +*/ +static const char *url = "http://localhost:10000/echoattachments"; +static const char *urn = ""; +static const char *method = "echo"; + + +void compareFiles(const char* received, const char *sent) +{ + FILE *f1, *f2; + char c1, c2; + long s1,s2; + + printf("Opening received file to compare: '%s'\n", received); + f1 = fopen(received, "r"); + if (!f1) { + fprintf(stderr, "Can not open '%s'\n", received); + return; + } + + printf("Opening sent file to compare: '%s'\n", sent); + f2 = fopen(sent, "r"); + if (!f2) { + fprintf(stderr, "Can not open '%s'\n", sent); + fclose(f1); + return; + } + + fseek(f1, 0, SEEK_END); + fseek(f2, 0, SEEK_END); + + s1 = ftell(f1); + s2 = ftell(f2); + + fseek(f1, 0, SEEK_SET); + fseek(f2, 0, SEEK_SET); + + if (s1 > s2) { + + printf("ERROR: files are not equal! Received file is bigger\n"); + fclose(f1); fclose(f2); + return; + + } else if (s2 > s1) { + + printf("ERROR: files are not equal! Sent file is bigger\n"); + fclose(f1); fclose(f2); + return; + } + + while (feof(f1)) { + + c1= fgetc(f1); + c2= fgetc(f2); + if (c1 != c2){ + printf("ERROR: files are not equal! Byte compare failed\n"); + fclose(f1); fclose(f2); + break; + } + } + + printf("OK: files are equal!\n"); + fclose(f1); fclose(f2); + +} + +int main(int argc, char *argv[]) +{ + SoapCtx *ctx, *ctx2; + char href[MAX_HREF_SIZE]; + xmlNodePtr fault; + + if (argc < 2) { + fprintf(stderr, "usage: %s [url]\n", argv[0]); + exit(1); + } + + log_set_level(HLOG_VERBOSE); + if (!soap_client_init_args(argc, argv)) { + return 1; + } + + ctx = soap_client_ctx_new(urn, method); + if (soap_ctx_add_file(ctx, argv[1], "application/octet-stream", href) != H_OK) { + fprintf(stderr, "Error while adding '%s'\n", argv[1]); + soap_ctx_free(ctx); + exit(1); + } + soap_env_add_attachment(ctx->env,"source", href); + + printf("sending request ...\n"); + if (argc > 2) + ctx2 = soap_client_invoke(ctx, argv[2], ""); + else + ctx2 = soap_client_invoke(ctx, url, ""); + + fault = soap_env_get_fault(ctx2->env); + if (fault) { + soap_xml_doc_print(ctx2->env->root->doc); + } else if (ctx2->attachments) { + compareFiles(ctx2->attachments->parts->filename, argv[1]); + } else { + printf("No attachments!"); + soap_xml_doc_print(ctx2->env->root->doc); + } + + soap_ctx_free(ctx2); + soap_ctx_free(ctx); + + return 0; +} + + + + diff --git a/examples/csoap/echoattachments-server.c b/examples/csoap/echoattachments-server.c new file mode 100755 index 0000000..319618d --- /dev/null +++ b/examples/csoap/echoattachments-server.c @@ -0,0 +1,81 @@ +/****************************************************************** + * $Id: echoattachments-server.c,v 1.1 2004/10/15 13:42:57 snowdrop Exp $ + * + * CSOAP Project: CSOAP examples project + * Copyright (C) 2003-2004 Ferhat Ayaz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA + * + * Email: ferhatayaz@yahoo.com + ******************************************************************/ + +#include + + +static const char *url = "/axis/services/urn:EchoAttachmentsService"; +static const char *urn = ""; +static const char *method = "echo"; + + + +SoapCtx* echo_attachments(SoapCtx *req) +{ + + SoapEnv *env; + SoapCtx* ctx; + part_t *part; + char href[MAX_HREF_SIZE]; + + env = soap_env_new_with_response(req->env); + ctx = soap_ctx_new(env); + + if (req->attachments) { + part = req->attachments->parts; + while (part) { + log_verbose2("Adding part '%s'", part->filename); + soap_ctx_add_file(ctx, part->filename, "text/plain", href); + soap_env_add_attachment(ctx->env, "echoFile", href); + part = part->next; + } + } + + return ctx; +} + + +int main(int argc, char *argv[]) +{ + + SoapRouter *router; + + log_set_level(HLOG_VERBOSE); + + if (!soap_server_init_args(argc, argv)) { + return 1; + } + + router = soap_router_new(); + soap_router_register_service(router, echo_attachments, method, urn); + soap_server_register_router(router, url); + + log_info1("send SIGTERM to shutdown"); + soap_server_run(); + + log_info1("shutting down\n"); + soap_server_destroy(); + + return 0; +} + diff --git a/examples/csoap/simpleclient.c b/examples/csoap/simpleclient.c index 4f2bcfe..3ac1588 100644 --- a/examples/csoap/simpleclient.c +++ b/examples/csoap/simpleclient.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: simpleclient.c,v 1.4 2004/08/30 15:26:48 snowdrop Exp $ + * $Id: simpleclient.c,v 1.5 2004/10/15 13:42:57 snowdrop Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003 Ferhat Ayaz @@ -27,12 +27,35 @@ /* static const char *url = "http://csoap.sourceforge.net/cgi-bin/csoapserver"; */ -static const char *url = "http://localhost:10000/csoapserver"; +static const char *url = "http://localhost:3031/csoapserver"; static const char *urn = "urn:examples"; static const char *method = "sayHello"; int main(int argc, char *argv[]) +{ + SoapCtx *ctx, *ctx2; + + log_set_level(HLOG_VERBOSE); + if (!soap_client_init_args(argc, argv)) { + return 1; + } + + ctx = soap_client_ctx_new(urn, method); + soap_env_add_item(ctx->env, "xsd:string", "name", "Jonny B. Good"); + + if (argc > 1) + ctx2 = soap_client_invoke(ctx, argv[1], ""); + else + ctx2 = soap_client_invoke(ctx, url, ""); + + soap_xml_doc_print(ctx2->env->root->doc); + soap_ctx_free(ctx2); + soap_ctx_free(ctx); +} + +/* +int main2(int argc, char *argv[]) { SoapEnv *env, *res; @@ -55,7 +78,7 @@ int main(int argc, char *argv[]) return 0; } - +*/ diff --git a/examples/csoap/simpleserver.c b/examples/csoap/simpleserver.c index a5a3318..3ccd61e 100644 --- a/examples/csoap/simpleserver.c +++ b/examples/csoap/simpleserver.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: simpleserver.c,v 1.9 2004/09/19 07:05:01 snowdrop Exp $ + * $Id: simpleserver.c,v 1.10 2004/10/15 13:42:57 snowdrop Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003 Ferhat Ayaz @@ -41,20 +41,21 @@ void add_name(xmlNodePtr node, SoapEnv *env) soap_env_add_itemf(env,"xsd:string", "echo", "Hello '%s'", name); - xmlFree(BAD_CAST name); + /*xmlFree(BAD_CAST name);*/ } -SoapEnv* say_hello(SoapEnv *request) +SoapCtx* say_hello(SoapCtx *request) { SoapEnv *env; + SoapCtx* ctx; xmlNodePtr method, node; - env = soap_env_new_with_response(request); + env = soap_env_new_with_response(request->env); - method = soap_env_get_method(request); + method = soap_env_get_method(request->env); node = soap_xml_get_children(method); while (node) { @@ -62,7 +63,8 @@ SoapEnv* say_hello(SoapEnv *request) node = soap_xml_get_next(node); } - return env; + ctx = soap_ctx_new(env); + return ctx; } -- cgit v1.1-32-gdbae