From 06a83e24332e3bd95826fc156f728dea214b998e Mon Sep 17 00:00:00 2001 From: m0gg Date: Wed, 29 Mar 2006 08:35:55 +0000 Subject: Don't #include soap-admin.c --- libcsoap/Makefile.am | 6 ++-- libcsoap/soap-admin.c | 86 +++++++++++++++++++++++++++++++++++++++----------- libcsoap/soap-admin.h | 45 ++++++++++++++++++++++++++ libcsoap/soap-server.c | 43 ++++++++++++++----------- libcsoap/soap-server.h | 13 +++++++- 5 files changed, 153 insertions(+), 40 deletions(-) create mode 100644 libcsoap/soap-admin.h diff --git a/libcsoap/Makefile.am b/libcsoap/Makefile.am index dcbac69..8b096d4 100644 --- a/libcsoap/Makefile.am +++ b/libcsoap/Makefile.am @@ -4,10 +4,12 @@ lib_LTLIBRARIES=libcsoap.la 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-router.c soap-client.c soap-server.c soap-ctx.c \ + soap-admin.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-router.h soap-client.h soap-server.h soap-ctx.h \ + soap-admin.h libcsoap_la_LDFLAGS= -version-info @csoap_version@ -release @csoap_release@ libcsoap_la_CFLAGS=-I${top_srcdir} diff --git a/libcsoap/soap-admin.c b/libcsoap/soap-admin.c index 1ee9db5..8aa7138 100644 --- a/libcsoap/soap-admin.c +++ b/libcsoap/soap-admin.c @@ -1,9 +1,39 @@ - - -#define SOAP_ADMIN_QUERY_ROUTERS "routers" -#define SOAP_ADMIN_QUERY_ROUTER "router" -#define SOAP_ADMIN_QUERY_SERVICES "services" - +/****************************************************************** +* $Id: soap-admin.c,v 1.2 2006/03/29 08:35:55 m0gg Exp $ +* +* CSOAP Project: A SOAP client/server library in C +* Copyright (C) 2003 Ferhat Ayaz +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Library General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Library General Public License for more details. +* +* You should have received a copy of the GNU Library General Public +* License along with this library; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 02111-1307, USA. +* +* Email: ayaz@jprogrammer.net +******************************************************************/ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "soap-router.h" +#include "soap-server.h" +#include "soap-admin.h" + +#define SOAP_ADMIN_QUERY_ROUTERS "routers" +#define SOAP_ADMIN_QUERY_ROUTER "router" +#define SOAP_ADMIN_QUERY_SERVICES "services" static void _soap_admin_send_title(httpd_conn_t* conn, const char* title) @@ -33,9 +63,9 @@ _soap_admin_list_routers(httpd_conn_t* conn) _soap_admin_send_title(conn, "Available routers"); - for (node = head; node; node = node->next) + for (node = soap_server_get_routers(); node; node = node->next) { - sprintf(buffer, "
  • %s", + sprintf(buffer, "
  • %s
  • ", node->context, node->context); http_output_stream_write_string(conn->out, buffer); } @@ -43,6 +73,7 @@ _soap_admin_list_routers(httpd_conn_t* conn) http_output_stream_write_string(conn->out, ""); } + static void _soap_admin_list_services(httpd_conn_t* conn, const char* routername) { @@ -53,8 +84,9 @@ _soap_admin_list_services(httpd_conn_t* conn, const char* routername) sprintf(buffer, "Listing Services for Router %s", routername); _soap_admin_send_title(conn, buffer); - router = router_find(routername); - if (!router) { + router = soap_server_find_router(routername); + if (!router) + { http_output_stream_write_string(conn->out, "Router not found!"); http_output_stream_write_string(conn->out, ""); return; @@ -62,8 +94,9 @@ _soap_admin_list_services(httpd_conn_t* conn, const char* routername) node = router->service_head; - while (node) { - sprintf(buffer, "
  • [%s] (%s)", + while (node) + { + sprintf(buffer, "
  • [%s] (%s)
  • ", node->service->urn, node->service->method); http_output_stream_write_string(conn->out, buffer); @@ -74,17 +107,21 @@ _soap_admin_list_services(httpd_conn_t* conn, const char* routername) } - static void _soap_admin_handle_get(httpd_conn_t * conn, hrequest_t * req) { char *param; - if ((param = hpairnode_get_ignore_case(req->query, SOAP_ADMIN_QUERY_ROUTERS))) { + if ((param = hpairnode_get_ignore_case(req->query, SOAP_ADMIN_QUERY_ROUTERS))) + { _soap_admin_list_routers(conn); - } else if ((param = hpairnode_get_ignore_case(req->query, SOAP_ADMIN_QUERY_ROUTER))) { + } + else if ((param = hpairnode_get_ignore_case(req->query, SOAP_ADMIN_QUERY_ROUTER))) + { _soap_admin_list_services(conn, param); - } else { + } + else + { _soap_admin_send_title(conn, "Welcome to the admin site"); http_output_stream_write_string(conn->out, "
  • Routers "); @@ -93,12 +130,16 @@ _soap_admin_handle_get(httpd_conn_t * conn, hrequest_t * req) } } + static void _soap_admin_entry(httpd_conn_t * conn, hrequest_t * req) { - if (req->method == HTTP_REQUEST_GET) { + if (req->method == HTTP_REQUEST_GET) + { _soap_admin_handle_get(conn, req); - } else { + } + else + { httpd_send_header(conn, 200, "OK"); http_output_stream_write_string(conn->out, "" @@ -112,3 +153,12 @@ _soap_admin_entry(httpd_conn_t * conn, hrequest_t * req) ""); } } + + +herror_t soap_admin_init_args(int argc, char **argv) +{ + + httpd_register("/csoap", _soap_admin_entry); + + return H_OK; +} diff --git a/libcsoap/soap-admin.h b/libcsoap/soap-admin.h new file mode 100644 index 0000000..b652f01 --- /dev/null +++ b/libcsoap/soap-admin.h @@ -0,0 +1,45 @@ +/****************************************************************** + * $Id: soap-admin.h,v 1.1 2006/03/29 08:35:55 m0gg Exp $ + * + * CSOAP Project: A SOAP client/server library in C + * Copyright (C) 2003 Ferhat Ayaz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Email: ferhatayaz@yahoo.com + ******************************************************************/ +#ifndef cSOAP_ADMIN_H +#define cSOAP_ADMIN_H + +#ifdef __cplusplus +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 + */ +herror_t soap_admin_init_args(int argc, char *argv[]); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libcsoap/soap-server.c b/libcsoap/soap-server.c index c89fba2..a9671e3 100644 --- a/libcsoap/soap-server.c +++ b/libcsoap/soap-server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-server.c,v 1.21 2006/03/27 12:14:12 snowdrop Exp $ +* $Id: soap-server.c,v 1.22 2006/03/29 08:35:55 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -39,23 +39,13 @@ #include +#include "soap-admin.h" #include "soap-server.h" -typedef struct _SoapRouterNode -{ - char *context; - SoapRouter *router; - struct _SoapRouterNode *next; - -} SoapRouterNode; - static SoapRouterNode *head = NULL; static SoapRouterNode *tail = NULL; -static SoapRouter *router_find(const char *context); - -/* Include soap-admin functions */ -#include "soap-admin.c" +// static SoapRouter *router_find(const char *context); static void _soap_server_send_env(http_output_stream_t * out, SoapEnv * env) @@ -199,6 +189,7 @@ _soap_server_send_description(httpd_conn_t *conn, xmlDocPtr wsdl) xmlNodeDump(buf, wsdl, xmlDocGetRootElement(wsdl), 0, 0); sprintf(length, "%d", xmlBufferLength(buf)); + httpd_set_header(conn, HEADER_CONTENT_TYPE, "text/xml"); httpd_set_header(conn, HEADER_CONTENT_LENGTH, length); httpd_send_header(conn, 200, "OK"); @@ -237,8 +228,8 @@ router_node_new(SoapRouter * router, const char *context, SoapRouterNode * next) return node; } -static SoapRouter * -router_find(const char *context) +SoapRouter * +soap_server_find_router(const char *context) { SoapRouterNode *node; @@ -264,7 +255,7 @@ soap_server_entry(httpd_conn_t * conn, hrequest_t * req) herror_t err; - if (!(router = router_find(req->path))) + if (!(router = soap_server_find_router(req->path))) { _soap_server_send_fault(conn, "Cannot find router"); return; @@ -400,10 +391,12 @@ soap_server_entry(httpd_conn_t * conn, hrequest_t * req) herror_t soap_server_init_args(int argc, char *argv[]) { - herror_t err = httpd_init(argc, argv); + herror_t err; + + if ((err = httpd_init(argc, argv)) != H_OK) + return err; - httpd_register("/csoap", _soap_admin_entry); - return err; + return soap_admin_init_args(argc, argv); } int @@ -428,6 +421,12 @@ soap_server_register_router(SoapRouter * router, const char *context) return 1; } +SoapRouterNode * +soap_server_get_routers(void) +{ + return head; +} + herror_t soap_server_run(void) { @@ -440,6 +439,12 @@ soap_server_get_port(void) return httpd_get_port(); } +const char * +soap_server_get_protocol(void) +{ + return httpd_get_protocol(); +} + void soap_server_destroy() { diff --git a/libcsoap/soap-server.h b/libcsoap/soap-server.h index 89c5dbd..01f3e66 100644 --- a/libcsoap/soap-server.h +++ b/libcsoap/soap-server.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-server.h,v 1.9 2006/03/06 13:37:38 m0gg Exp $ + * $Id: soap-server.h,v 1.10 2006/03/29 08:35:56 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -28,6 +28,14 @@ #include #include +typedef struct _SoapRouterNode +{ + char *context; + SoapRouter *router; + struct _SoapRouterNode *next; + +} SoapRouterNode; + #ifdef __cplusplus extern "C" { #endif @@ -66,6 +74,9 @@ herror_t soap_server_init_args(int argc, char *argv[]); */ int soap_server_register_router(SoapRouter * router, const char *context); +SoapRouter *soap_server_find_router(const char *context); + +SoapRouterNode * soap_server_get_routers(void); /** Enters the server loop and starts to listen to -- cgit v1.1-32-gdbae