summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar m0gg2006-12-31 17:24:22 +0000
committerGravatar m0gg2006-12-31 17:24:22 +0000
commitd95f9da3572131ceeefd245d99c795ab8bc11880 (patch)
tree21897c4cec8b0d7b19d915a9c19c8366cad268a1
parent2fbfdcdff09db6a1c0041022b208320d15e24d13 (diff)
downloadcsoap-d95f9da3572131ceeefd245d99c795ab8bc11880.tar.gz
csoap-d95f9da3572131ceeefd245d99c795ab8bc11880.tar.bz2
Addded hooks for Web Service Management
-rw-r--r--libcsoap/soap-admin.c99
-rw-r--r--libcsoap/soap-admin.h16
-rw-r--r--libcsoap/soap-server.c37
-rw-r--r--libcsoap/soap-service.c4
-rw-r--r--libcsoap/soap-service.h28
-rw-r--r--nanohttp/nanohttp-admin.c43
-rw-r--r--nanohttp/nanohttp-server.c24
-rw-r--r--nanohttp/nanohttp-server.h12
8 files changed, 186 insertions, 77 deletions
diff --git a/libcsoap/soap-admin.c b/libcsoap/soap-admin.c
index 715e3ca..efc9651 100644
--- a/libcsoap/soap-admin.c
+++ b/libcsoap/soap-admin.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-admin.c,v 1.10 2006/11/26 20:13:05 m0gg Exp $
+* $Id: soap-admin.c,v 1.11 2006/12/31 17:24:22 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -62,23 +62,38 @@ static void
_soap_admin_send_title(httpd_conn_t *conn, const char *title)
{
httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE);
+
http_output_stream_write_string(conn->out,
- "<html><head><style>");
+ "<html>"
+ "<head>");
+
http_output_stream_write_string(conn->out,
- ".logo {"
- " color: #005177;"
- " background-color: transparent;"
- " font-family: Calligraphic, arial, sans-serif;"
- " font-size: 36px;"
- "}");
+ "<style>"
+ ".logo {"
+ " color: #005177;"
+ " background-color: transparent;"
+ " font-family: Calligraphic, arial, sans-serif;"
+ " font-size: 36px;"
+ "}"
+ "</style>");
+
http_output_stream_write_string(conn->out,
- "</style></head><body><span class=\"logo\">csoap</span> ");
+ "</head>"
+ "<body>"
+ "<span class=\"logo\">csoap</span> ");
http_output_stream_write_string(conn->out, title);
http_output_stream_write_string(conn->out, "<hr />");
return;
}
+static inline void
+_soap_admin_send_footer(httpd_conn_t *conn)
+{
+ http_output_stream_write_string(conn->out, "</body></html>");
+
+ return;
+}
static void
_soap_admin_list_routers(httpd_conn_t *conn)
@@ -91,18 +106,22 @@ _soap_admin_list_routers(httpd_conn_t *conn)
http_output_stream_write_string(conn->out, "<ul>");
for (node = soap_server_get_routers(); node; node = node->next)
{
- sprintf(buffer, "<li><a href=\"?" SOAP_ADMIN_QUERY_ROUTER "=%s\">%s</a> - <a href=\"%s\">[Service Description]</a> - <a href=\"../nhttp?" NHTTPD_ADMIN_QUERY_STATISTICS "=%s\">[Statistics]</a></li>",
- node->context, node->context, node->context, node->context);
+ sprintf(buffer,
+ "<li>"
+ "<a href=\"?" CSOAP_ADMIN_QUERY_ROUTER "=%s\">%s</a> - "
+ "<a href=\"%s\">[Service Description]</a> - "
+ "<a href=\"../nhttp?" NHTTPD_ADMIN_QUERY_STATISTICS "=%s\">[Statistics]</a>"
+ "</li>",
+ node->context, node->context, node->context, node->context);
http_output_stream_write_string(conn->out, buffer);
}
http_output_stream_write_string(conn->out, "</ul>");
- http_output_stream_write_string(conn->out, "</body></html>");
+ _soap_admin_send_footer(conn);
return;
}
-
static void
_soap_admin_list_services(httpd_conn_t *conn, const char *routername)
{
@@ -124,47 +143,78 @@ _soap_admin_list_services(httpd_conn_t *conn, const char *routername)
node = router->service_head;
http_output_stream_write_string(conn->out, "<ul>");
- while (node)
+ for (node = router->service_head; node; node = node->next)
{
- sprintf(buffer, "<li> [%s] (%s) </li>",
- node->service->urn,
- node->service->method);
+ switch (node->service->status)
+ {
+ case CSOAP_SERVICE_DOWN:
+ sprintf(buffer,
+ "<li>"
+ "%s (%s) <a href=\"?" CSOAP_ADMIN_QUERY_ACTIVATE "=%s&amp;" CSOAP_ADMIN_URN "=%s\">[Activate]</a>"
+ "</li>",
+ node->service->urn,
+ node->service->method,
+ node->service->method,
+ node->service->urn);
+ break;
+ case CSOAP_SERVICE_UP:
+ default:
+ sprintf(buffer,
+ "<li>"
+ "%s (%s) <a href=\"?" CSOAP_ADMIN_QUERY_PASSIVATE "=%s&amp;" CSOAP_ADMIN_URN "=%s\">[Passivate]</a>"
+ "</li>",
+ node->service->urn,
+ node->service->method,
+ node->service->method,
+ node->service->urn);
+ break;
+ }
http_output_stream_write_string(conn->out, buffer);
- node = node->next;
}
http_output_stream_write_string(conn->out, "</ul>");
- http_output_stream_write_string(conn->out, "</body></html>");
+ _soap_admin_send_footer(conn);
return;
}
-
static void
_soap_admin_handle_get(httpd_conn_t * conn, struct 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, CSOAP_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, CSOAP_ADMIN_QUERY_ROUTER)))
{
_soap_admin_list_services(conn, param);
}
+ else if ((param = hpairnode_get_ignore_case(req->query, CSOAP_ADMIN_QUERY_ACTIVATE)))
+ {
+ _soap_admin_send_title(conn, "Not implemented");
+ _soap_admin_send_footer(conn);
+ // _soap_admin_activate_service(conn, param);
+ }
+ else if ((param = hpairnode_get_ignore_case(req->query, CSOAP_ADMIN_QUERY_PASSIVATE)))
+ {
+ _soap_admin_send_title(conn, "Not implemented");
+ _soap_admin_send_footer(conn);
+ // _soap_admin_passivate_service(conn, param);
+ }
else
{
_soap_admin_send_title(conn, "Welcome to the admin site");
http_output_stream_write_string(conn->out,
"<ul>"
- "<li><a href=\"?" SOAP_ADMIN_QUERY_ROUTERS "\">Routers</a></li>"
+ "<li><a href=\"?" CSOAP_ADMIN_QUERY_ROUTERS "\">Routers</a></li>"
"<li><a href=\"../inspection.wsil\">inspection.wsil</a> (try: -CSOAPwsil)</li>"
"<li><a href=\"../nhttp\">nanoHTTP</a></li>"
"</ul>");
- http_output_stream_write_string(conn->out, "</body></html>");
+ _soap_admin_send_footer(conn);
}
return;
@@ -192,6 +242,7 @@ _soap_admin_entry(httpd_conn_t * conn, struct hrequest_t * req)
"</body>"
"</html>");
}
+
return;
}
diff --git a/libcsoap/soap-admin.h b/libcsoap/soap-admin.h
index 1d121b3..2e0ca80 100644
--- a/libcsoap/soap-admin.h
+++ b/libcsoap/soap-admin.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-admin.h,v 1.4 2006/11/23 15:27:33 m0gg Exp $
+ * $Id: soap-admin.h,v 1.5 2006/12/31 17:24:22 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -24,11 +24,17 @@
#ifndef __csoap_admin_h
#define __csoap_admin_h
-#define CSOAP_ENABLE_ADMIN "-CSOAPadmin"
+#define CSOAP_ENABLE_ADMIN "-CSOAPadmin"
-#define SOAP_ADMIN_QUERY_ROUTERS "routers"
-#define SOAP_ADMIN_QUERY_ROUTER "router"
-#define SOAP_ADMIN_QUERY_SERVICES "services"
+#define CSOAP_ADMIN_QUERY_ROUTERS "routers"
+#define CSOAP_ADMIN_QUERY_ROUTER "router"
+#define CSOAP_ADMIN_QUERY_SERVICES "services"
+
+#define CSOAP_ADMIN_QUERY_ACTIVATE "activate"
+#define CSOAP_ADMIN_QUERY_PASSIVATE "passivate"
+
+#define CSOAP_ADMIN_URN "urn"
+#define CSOAP_ADMIN_METHOD "method"
#ifdef __cplusplus
extern "C" {
diff --git a/libcsoap/soap-server.c b/libcsoap/soap-server.c
index b21688b..34b053f 100644
--- a/libcsoap/soap-server.c
+++ b/libcsoap/soap-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-server.c,v 1.35 2006/11/29 11:04:25 m0gg Exp $
+* $Id: soap-server.c,v 1.36 2006/12/31 17:24:22 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -179,19 +179,30 @@ soap_server_process(struct SoapCtx *request, struct SoapCtx **response)
if ((service = soap_router_find_service(router, urn, method)))
{
log_verbose3("service (%p) found, function (%p)", service, service->func);
- if ((err = service->func(request, *response)) == H_OK)
+ switch (service->status)
{
- if ((*response)->env == NULL)
- {
- sprintf(buffer, "Service for \"%s\" returned no envelope", urn);
- _soap_server_env_new_with_fault("Internal service error", buffer, &((*response)->env));
- }
- }
- else
- {
- sprintf(buffer, "Service returned following error message: \"%s\"", herror_message(err));
- herror_release(err);
- _soap_server_env_new_with_fault("Internal service error", buffer, &((*response)->env));
+ case CSOAP_SERVICE_UP:
+
+ if ((err = service->func(request, *response)) == H_OK)
+ {
+ if ((*response)->env == NULL)
+ {
+ sprintf(buffer, "Service for \"%s\" returned no envelope", urn);
+ _soap_server_env_new_with_fault("Internal service error", buffer, &((*response)->env));
+ }
+ }
+ else
+ {
+ sprintf(buffer, "Service returned following error message: \"%s\"", herror_message(err));
+ herror_release(err);
+ _soap_server_env_new_with_fault("Internal service error", buffer, &((*response)->env));
+ }
+ break;
+ case CSOAP_SERVICE_DOWN:
+ default:
+ sprintf(buffer, "Service for \"%s\" is down", urn);
+ _soap_server_env_new_with_fault("Internal service error", buffer, &((*response)->env));
+ break;
}
}
else
diff --git a/libcsoap/soap-service.c b/libcsoap/soap-service.c
index e63dd22..b731d76 100644
--- a/libcsoap/soap-service.c
+++ b/libcsoap/soap-service.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-service.c,v 1.12 2006/11/25 15:06:57 m0gg Exp $
+* $Id: soap-service.c,v 1.13 2006/12/31 17:24:22 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -100,6 +100,8 @@ soap_service_new(const char *urn, const char *method, SoapServiceFunc f)
}
service->method = strdup(method);
+ service->status = CSOAP_SERVICE_UP;
+
return service;
}
diff --git a/libcsoap/soap-service.h b/libcsoap/soap-service.h
index 33d69f6..47072b4 100644
--- a/libcsoap/soap-service.h
+++ b/libcsoap/soap-service.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-service.h,v 1.9 2006/11/27 10:49:57 m0gg Exp $
+ * $Id: soap-service.h,v 1.10 2006/12/31 17:24:22 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -33,12 +33,31 @@
* messages, typically conveyed using HTTP with an XML serialization in
* conjunction with other Web-related standards.
*
- * @see http://www.w3.org/TR/wslc/,
- * http://www.w3.org/TR/wsdl,
- * http://www.w3.org/TR/owl-ref/
+ * @see http://www.w3.org/TR/wslc/
+ * @see http://www.w3.org/TR/wsdl
+ * @see http://www.w3.org/TR/owl-ref/
*
*/
+/**
+ *
+ * This service status shows that the provider agent is not capable of accepting
+ * any requests (i.e. the service is not available).
+ *
+ * @see http://www.w3.org/TR/wslc/
+ *
+ */
+#define CSOAP_SERVICE_DOWN 0
+
+/**
+ *
+ * This service status shows that the provider agent is capable of accepting and
+ * processing requests (i.e. the service is available)
+ *
+ * @see http://www.w3.org/TR/wslc/
+ *
+ */
+#define CSOAP_SERVICE_UP 1
typedef herror_t (*SoapServiceFunc)(struct SoapCtx *request, struct SoapCtx *response);
@@ -46,6 +65,7 @@ typedef struct _SoapService
{
char *urn;
char *method;
+ int status;
SoapServiceFunc func;
} SoapService;
diff --git a/nanohttp/nanohttp-admin.c b/nanohttp/nanohttp-admin.c
index c06577b..3dbdbd6 100644
--- a/nanohttp/nanohttp-admin.c
+++ b/nanohttp/nanohttp-admin.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-admin.c,v 1.10 2006/12/19 08:55:17 m0gg Exp $
+* $Id: nanohttp-admin.c,v 1.11 2006/12/31 17:24:22 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -53,24 +53,31 @@ static void
_httpd_admin_send_title(httpd_conn_t *conn, const char *title)
{
httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE);
+
http_output_stream_write_string(conn->out,
- "<html><head><style>");
+ "<html>"
+ "<head>");
http_output_stream_write_string(conn->out,
- ".logo {"
- " color: #005177;"
- " background-color: transparent;"
- " font-family: Calligraphic, arial, sans-serif;"
- " font-size: 36px;"
- "}");
+ "<style>"
+ ".logo {"
+ " color: #005177;"
+ " background-color: transparent;"
+ " font-family: Calligraphic, arial, sans-serif;"
+ " font-size: 36px;"
+ "}"
+ "</style>");
+
http_output_stream_write_string(conn->out,
- "</style></head><body><span class=\"logo\">nhttpd</span> ");
+ "</head>"
+ "<body>"
+ "<span class=\"logo\">nhttpd</span> ");
http_output_stream_write_string(conn->out, title);
http_output_stream_write_string(conn->out, "<hr />");
return;
}
-static void
+static inline void
_httpd_admin_send_footer(httpd_conn_t *conn)
{
http_output_stream_write_string(conn->out, "</body></html>");
@@ -92,11 +99,23 @@ _httpd_admin_list_services(httpd_conn_t *conn)
switch (node->status)
{
case NHTTPD_SERVICE_DOWN:
- sprintf(buffer, "<li><a href=\"%s\">%s</a> <a href=\"?" NHTTPD_ADMIN_QUERY_ACTIVATE_SERVICE "=%s\">[Activate]</a> <a href=\"?" NHTTPD_ADMIN_QUERY_STATISTICS "=%s\">[Statistics]</a></li>", node->ctx, node->ctx, node->ctx, node->ctx);
+ sprintf(buffer,
+ "<li>"
+ "<a href=\"%s\">%s</a> "
+ "<a href=\"?" NHTTPD_ADMIN_QUERY_ACTIVATE_SERVICE "=%s\">[Activate]</a> "
+ "<a href=\"?" NHTTPD_ADMIN_QUERY_STATISTICS "=%s\">[Statistics]</a>"
+ "</li>",
+ node->context, node->context, node->context, node->context);
break;
case NHTTPD_SERVICE_UP:
default:
- sprintf(buffer, "<li><a href=\"%s\">%s</a> <a href=\"?" NHTTPD_ADMIN_QUERY_PASSIVATE_SERVICE "=%s\">[Passivate]</a> <a href=\"?" NHTTPD_ADMIN_QUERY_STATISTICS "=%s\">[Statistics]</a></li>", node->ctx, node->ctx, node->ctx, node->ctx);
+ sprintf(buffer,
+ "<li>"
+ "<a href=\"%s\">%s</a> "
+ "<a href=\"?" NHTTPD_ADMIN_QUERY_PASSIVATE_SERVICE "=%s\">[Passivate]</a> "
+ "<a href=\"?" NHTTPD_ADMIN_QUERY_STATISTICS "=%s\">[Statistics]</a> "
+ "</li>",
+ node->context, node->context, node->context, node->context);
break;
}
http_output_stream_write_string(conn->out, buffer);
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index 078eb76..bca46f4 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.77 2006/12/19 08:55:17 m0gg Exp $
+* $Id: nanohttp-server.c,v 1.78 2006/12/31 17:24:22 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -303,7 +303,7 @@ httpd_init(int argc, char **argv)
}
herror_t
-httpd_register_secure(const char *ctx, httpd_service func, httpd_auth auth)
+httpd_register_secure(const char *context, httpd_service func, httpd_auth auth)
{
hservice_t *service;
@@ -328,9 +328,9 @@ httpd_register_secure(const char *ctx, httpd_service func, httpd_auth auth)
service->auth = auth;
service->func = func;
service->status = NHTTPD_SERVICE_UP;
- strcpy(service->ctx, ctx);
+ service->context = strdup(context);
- log_verbose3("register service (%p) for \"%s\"", service, SAVE_STR(ctx));
+ log_verbose3("register service (%p) for \"%s\"", service, context);
if (_httpd_services_head == NULL)
{
_httpd_services_head = _httpd_services_tail = service;
@@ -345,17 +345,17 @@ httpd_register_secure(const char *ctx, httpd_service func, httpd_auth auth)
}
herror_t
-httpd_register(const char *ctx, httpd_service service)
+httpd_register(const char *context, httpd_service service)
{
- return httpd_register_secure(ctx, service, NULL);
+ return httpd_register_secure(context, service, NULL);
}
herror_t
-httpd_register_default_secure(const char *ctx, httpd_service service, httpd_auth auth)
+httpd_register_default_secure(const char *context, httpd_service service, httpd_auth auth)
{
herror_t ret;
- ret = httpd_register_secure(ctx, service, auth);
+ ret = httpd_register_secure(context, service, auth);
/* XXX: this is broken, but working */
_httpd_services_default = _httpd_services_tail;
@@ -364,9 +364,9 @@ httpd_register_default_secure(const char *ctx, httpd_service service, httpd_auth
}
herror_t
-httpd_register_default(const char *ctx, httpd_service service)
+httpd_register_default(const char *context, httpd_service service)
{
- return httpd_register_default_secure(ctx, service, NULL);
+ return httpd_register_default_secure(context, service, NULL);
}
short
@@ -456,7 +456,7 @@ httpd_find_service(const char *context)
for (cur = _httpd_services_head; cur; cur = cur->next)
{
- if (!strcmp(cur->ctx, context))
+ if (!strcmp(cur->context, context))
return cur;
}
@@ -739,7 +739,7 @@ httpd_session_main(void *data)
if ((service = httpd_find_service(req->path)))
{
- log_verbose3("service '%s' for '%s' found", service->ctx, req->path);
+ log_verbose3("service '%s' for '%s' found", service->context, req->path);
if (service->status == NHTTPD_SERVICE_UP)
{
diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h
index 7491722..bdb421c 100644
--- a/nanohttp/nanohttp-server.h
+++ b/nanohttp/nanohttp-server.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-server.h,v 1.33 2006/12/19 08:55:17 m0gg Exp $
+ * $Id: nanohttp-server.h,v 1.34 2006/12/31 17:24:22 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -261,7 +261,7 @@ struct service_statistics
*/
typedef struct tag_hservice
{
- char ctx[255];
+ char *context;
int status;
httpd_service func;
httpd_auth auth;
@@ -292,11 +292,11 @@ extern void httpd_destroy(void);
extern herror_t httpd_run(void);
-extern herror_t httpd_register(const char *ctx, httpd_service service);
-extern herror_t httpd_register_secure(const char *ctx, httpd_service service, httpd_auth auth);
+extern herror_t httpd_register(const char *context, httpd_service service);
+extern herror_t httpd_register_secure(const char *context, httpd_service service, httpd_auth auth);
-extern herror_t httpd_register_default(const char *ctx, httpd_service service);
-extern herror_t httpd_register_default_secure(const char *ctx, httpd_service service, httpd_auth auth);
+extern herror_t httpd_register_default(const char *context, httpd_service service);
+extern herror_t httpd_register_default_secure(const char *context, httpd_service service, httpd_auth auth);
extern short httpd_get_port(void);
extern int httpd_get_timeout(void);