soap-wsil.c

Go to the documentation of this file.
00001 /******************************************************************
00002 *  $Id: soap-wsil.c,v 1.6 2006/11/27 11:15:27 m0gg Exp $
00003 *
00004 * CSOAP Project:  A SOAP client/server library in C
00005 * Copyright (C) 2003  Ferhat Ayaz
00006 *
00007 * This library is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU Library General Public
00009 * License as published by the Free Software Foundation; either
00010 * version 2 of the License, or (at your option) any later version.
00011 *
00012 * This library is distributed in the hope that it will be useful,
00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 * Library General Public License for more details.
00016 *
00017 * You should have received a copy of the GNU Library General Public
00018 * License along with this library; if not, write to the
00019 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020 * Boston, MA  02111-1307, USA.
00021 * 
00022 * Email: ayaz@jprogrammer.net
00023 ******************************************************************/
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #ifdef HAVE_STDIO_H
00029 #include <stdio.h>
00030 #endif
00031 
00032 #ifdef HAVE_STRING_H
00033 #include <string.h>
00034 #endif
00035 
00036 #include <libxml/tree.h>
00037 
00038 #include <nanohttp/nanohttp-error.h>
00039 #include <nanohttp/nanohttp-common.h>
00040 #include <nanohttp/nanohttp-stream.h>
00041 #include <nanohttp/nanohttp-request.h>
00042 #include <nanohttp/nanohttp-server.h>
00043 
00044 #include "soap-ctx.h"
00045 #include "soap-service.h"
00046 #include "soap-router.h"
00047 #include "soap-server.h"
00048 #include "soap-transport.h"
00049 #include "soap-wsil.h"
00050 
00051 static void
00052 _soap_wsil_list_routers(httpd_conn_t *conn)
00053 {
00054   SoapRouterNode *node;
00055 
00056   for (node=soap_server_get_routers(); node; node=node->next)
00057   { 
00058     http_output_stream_write_string(conn->out,
00059       "<wsil:service>"
00060         "<wsil:description "
00061           "location=\"");
00062     http_output_stream_write_string(conn->out, soap_transport_get_name());
00063     http_output_stream_write_string(conn->out, node->context);
00064     http_output_stream_write_string(conn->out,
00065           "\" "
00066           "referencedNamespace=\"");
00067     if (node->router->description)
00068     {
00069       xmlNodePtr root;
00070 
00071       root = xmlDocGetRootElement(node->router->description);
00072       http_output_stream_write_string(conn->out, root->ns->href);
00073     }
00074     else
00075     {
00076       http_output_stream_write_string(conn->out, "http://schemas.xmlsoap.org/wsdl/");
00077     }
00078     http_output_stream_write_string(conn->out,
00079           "\" />"
00080       "</wsil:service>");
00081   }
00082   return;
00083 }
00084 
00085 static void
00086 _soap_wsil_handle_get(httpd_conn_t * conn, struct hrequest_t * req)
00087 {
00088   httpd_set_header(conn, HEADER_CONTENT_TYPE, "text/xml");
00089   httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE);
00090 
00091   http_output_stream_write_string(conn->out,
00092     "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
00093     "<wsil:inspection xmlns:wsil=\"http://schemas.xmlsoap.org/ws/2001/10/inspection/\">"
00094   );
00095 
00096   _soap_wsil_list_routers(conn);
00097 
00098   http_output_stream_write_string(conn->out,
00099     "</wsil:inspection>\n");
00100 
00101   return;
00102 }
00103 
00104 static void
00105 _soap_wsil_entry(httpd_conn_t * conn, struct hrequest_t * req)
00106 {
00107   if (req->method == HTTP_REQUEST_GET)
00108   {
00109     _soap_wsil_handle_get(conn, req);
00110   }
00111   else
00112   {
00113     httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE);
00114     http_output_stream_write_string(conn->out,
00115       "<html>"
00116         "<head>"
00117         "</head>"
00118         "<body>"
00119           "<h1>Sorry!</h1>"
00120           "<hr />"
00121           "<div>POST Service is not implemented now. Use your browser</div>"
00122         "</body>"
00123       "</html>");
00124   }
00125   return;
00126 }
00127 
00128 herror_t
00129 soap_wsil_init_args(int argc, char **argv)
00130 {
00131   int i;
00132 
00133   for (i=0; i<argc; i++) {
00134 
00135     if (!strcmp(argv[i], CSOAP_ENABLE_WSIL)) {
00136 
00137       httpd_register("/inspection.wsil", _soap_wsil_entry);
00138       break;
00139     }
00140   }
00141 
00142   return H_OK;
00143 }

Generated on Thu Jan 25 23:36:03 2007 for csoap by  doxygen 1.4.6