From d95f9da3572131ceeefd245d99c795ab8bc11880 Mon Sep 17 00:00:00 2001 From: m0gg Date: Sun, 31 Dec 2006 17:24:22 +0000 Subject: Addded hooks for Web Service Management --- nanohttp/nanohttp-admin.c | 43 +++++++++++++++++++++++++++++++------------ nanohttp/nanohttp-server.c | 24 ++++++++++++------------ nanohttp/nanohttp-server.h | 12 ++++++------ 3 files changed, 49 insertions(+), 30 deletions(-) (limited to 'nanohttp') 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, - ""); + http_output_stream_write_string(conn->out, - "nhttpd "); + "" + "" + "nhttpd "); http_output_stream_write_string(conn->out, title); http_output_stream_write_string(conn->out, "
"); return; } -static void +static inline void _httpd_admin_send_footer(httpd_conn_t *conn) { http_output_stream_write_string(conn->out, ""); @@ -92,11 +99,23 @@ _httpd_admin_list_services(httpd_conn_t *conn) switch (node->status) { case NHTTPD_SERVICE_DOWN: - sprintf(buffer, "
  • %s [Activate] [Statistics]
  • ", node->ctx, node->ctx, node->ctx, node->ctx); + sprintf(buffer, + "
  • " + "%s " + "[Activate] " + "[Statistics]" + "
  • ", + node->context, node->context, node->context, node->context); break; case NHTTPD_SERVICE_UP: default: - sprintf(buffer, "
  • %s [Passivate] [Statistics]
  • ", node->ctx, node->ctx, node->ctx, node->ctx); + sprintf(buffer, + "
  • " + "%s " + "[Passivate] " + "[Statistics] " + "
  • ", + 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); -- cgit v1.1-32-gdbae