diff options
Diffstat (limited to 'libcsoap')
-rw-r--r-- | libcsoap/soap-client.h | 87 | ||||
-rw-r--r-- | libcsoap/soap-nudp.c | 4 | ||||
-rw-r--r-- | libcsoap/soap-server.h | 128 |
3 files changed, 212 insertions, 7 deletions
diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h index e821b9b..b4a0cce 100644 --- a/libcsoap/soap-client.h +++ b/libcsoap/soap-client.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-client.h,v 1.16 2006/11/30 14:23:59 m0gg Exp $ + * $Id: soap-client.h,v 1.17 2006/12/10 19:21:06 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -32,6 +32,91 @@ #include <libcsoap/soap-addressing.h> #endif +/** @page nanohttp_client Howto write a SOAP client + * + * @section toc_sec Table of contents + * + * - @ref soap_client_init + * - @ref envelope_sec + * - @ref invoke_sec + * - @ref result_sec + * - @ref soap_request_cleanup_sec + * - @ref soap_client_cleanup_sec + * + * @section soap_client_init Client initialization + * + * @code + * static char *url = "http://localhost:10000/csoapserver"; + * static char *urn = "urn:examples"; + * static char *method = "sayHello"; + * + * int * main(int argc, char **argv) + * { + * struct SoapCtx *request; + * struct SoapCtx *response; + * herror_t err; + * + * if ((err = soap_client_init_args(argc, argv)) != H_OK) + * { + * printf("%s():%s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); + * herror_release(err); + * exit(1); + * } + * @endcode + * + * @section envelope_sec Envelope creation + * + * @code + * if ((err = soap_ctx_new_with_method(urn, method, &request)) != H_OK) + * { + * printf("%s():%s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); + * herror_release(err); + * soap_client_destroy(); + * exit(1); + * } + * + * soap_env_add_item(request->env, "xsd:string", "name", "Jonny B. Good"); + * @endcode + * + * @section invoke_sec Invocation + * + * @code + * if ((err = soap_client_invoke(request, &response, url, "")) != H_OK) + * { + * printf("[%d] %s(): %s\n", herror_code(err), herror_func(err), herror_message(err)); + * herror_release(err); + * soap_ctx_free(request); + * soap_client_destroy(); + * exit(1); + * } + * @endcode + * + * @section result_sec Printout result + * + * @code + * printf("**** received from \"%s\" ****\n", soap_addressing_get_from_address_string(response->env)); + * xmlDocFormatDump(stdout, response->env->root->doc, 1); + * @endcode + * + * @section soap_request_cleanup_sec Request cleanup + * + * @code + * soap_ctx_free(response); + * soap_ctx_free(request); + * @endcode + * + * @section soap_client_cleanup_sec Client cleanup + * + * @code + * soap_client_destroy(); + * + * exit(0); + * } + * @endcode + * + */ + + #define SOAP_ERROR_CLIENT 5000 #define SOAP_ERROR_CLIENT_GENERIC (SOAP_ERROR_CLIENT + 0) #define SOAP_ERROR_CLIENT_INIT (SOAP_ERROR_CLIENT + 1) diff --git a/libcsoap/soap-nudp.c b/libcsoap/soap-nudp.c index 60a7d25..cde774a 100644 --- a/libcsoap/soap-nudp.c +++ b/libcsoap/soap-nudp.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-nudp.c,v 1.7 2006/12/06 11:27:21 m0gg Exp $ +* $Id: soap-nudp.c,v 1.8 2006/12/10 19:21:06 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2006 Heiko Ronsdorf @@ -103,7 +103,7 @@ _soap_nudp_server_set_port(void) } else { - _soap_nudp_port = entry->s_port; + _soap_nudp_port = ntohs(entry->s_port); } return _soap_nudp_port; } diff --git a/libcsoap/soap-server.h b/libcsoap/soap-server.h index e858db9..8cad6ff 100644 --- a/libcsoap/soap-server.h +++ b/libcsoap/soap-server.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-server.h,v 1.19 2006/12/10 12:23:45 m0gg Exp $ + * $Id: soap-server.h,v 1.20 2006/12/10 19:21:06 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -56,9 +56,129 @@ * @see http://www.aleksey.com/xmlsec/ */ -/** @file - * - * @version $Revision: 1.19 $ +/** @page soap_server_page Howto write an SOAP server + * + * @section soap_server_toc_sec Table of contents + * + * - @ref soap_server_init_sec + * - @ref soap_server_router_sec + * - @ref soap_server_registration_sec + * - @ref soap_server_running_sec + * - @ref soap_server_cleanup_sec + * - @ref soap_server_function_sec + * + * @section soap_server_init_sec Server initialization + * + * @code + * int main(int argc, char **argv) + * { + * herror_t err; + * struct SoapRouter *router; + * + * if ((err = soap_server_init_args(argc, argv)) != H_OK) + * { + * printf("%s(): %s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); + * herror_release(err); + * exit(1); + * } + * @endcode + * + * @section soap_server_router_sec Router creation + * + * @code + * if (!(router = soap_router_new())) + * { + * printf("soap_router_new failed (router == %p)\n", router); + * herror_release(err); + * exit(1); + * } + * @endcode + * + * @section soap_server_registration_sec Service registration + * + * @code + * if ((err = soap_router_register_service(router, say_hello, method, urn)) != H_OK) + * { + * printf("%s(): %s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); + * herror_release(err); + * exit(1); + * } + * @endcode + * + * @code + * if ((err = soap_server_register_router(router, url))) + * { + * printf("%s(): %s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); + * herror_release(err); + * exit(1); + * } + * printf("router (%p) registered for \"%s\"\n", router, url); + * @endcode + * + * @section soap_server_running_sec Serving requests + * + * @code + * printf("press ctrl-c to shutdown\n"); + * if ((err = soap_server_run()) != H_OK) + * { + * printf("%s(): %s [%d]\n", herror_func(err), herror_message(err), herror_code(err)); + * herror_release(err); + * exit(1); + * } + * @endcode + * + * @section soap_server_cleanup_sec Server cleanup + * + * @code + * soap_server_destroy(); + * + * exit(0); + * } + * @endcode + * + * @section soap_server_function_sec Service function + * + * @code + * herror_t say_hello(struct SoapCtx *req, struct SoapCtx *res) + * { + * herror_t err; + * char *name; + * xmlNodePtr method, node; + * + * printf("processing service request\n"); + * + * xmlDocFormatDump(stdout, req->env->root->doc, 1); + * + * err = soap_env_new_with_response(req->env, &res->env); + * if (err != H_OK) + * { + * printf("soap_env_new_with_response failed (%s)\n", herror_message(err)); + * return err; + * } + * printf("empty response created\n"); + * + * if (!(method = soap_env_get_method(req->env))) + * { + * printf("soap_env_get_method failed\n"); + * return herror_new("say_hello", 0, "There may be a bug in the library..."); + * } + * printf("method found\n"); + * + * printf("adding response content...\n"); + * node = soap_xml_get_children(method); + * + * while (node) + * { + * name = (char *) xmlNodeListGetString(node->doc, node->xmlChildrenNode, 1); + * soap_env_add_itemf(res->env, "xsd:string", "echo", "Hello '%s'", name); + * node = soap_xml_get_next(node); + * if (name) + * xmlFree(name); + * } + * printf("service request done\n"); + * return H_OK; + * } + * @endcode * */ |