From 8a6946b18003fae6400a137389f0cb13d0ac4bd6 Mon Sep 17 00:00:00 2001 From: m0gg Date: Sat, 3 Nov 2007 22:40:09 +0000 Subject: Split nanoHTTP and cSOAP logging --- nanohttp/nanohttp-admin.c | 124 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 104 insertions(+), 20 deletions(-) (limited to 'nanohttp/nanohttp-admin.c') diff --git a/nanohttp/nanohttp-admin.c b/nanohttp/nanohttp-admin.c index 060cbb8..91ad0f0 100644 --- a/nanohttp/nanohttp-admin.c +++ b/nanohttp/nanohttp-admin.c @@ -1,5 +1,6 @@ +/** @file nanohttp-admin.c Administrator application */ /****************************************************************** -* $Id: nanohttp-admin.c,v 1.12 2007/01/01 22:54:46 m0gg Exp $ +* $Id: nanohttp-admin.c,v 1.13 2007/11/03 22:40:10 m0gg Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -21,6 +22,7 @@ * * Email: ayaz@jprogrammer.net ******************************************************************/ + #ifdef HAVE_CONFIG_H #include #endif @@ -42,6 +44,7 @@ #endif #include "nanohttp-error.h" +#include "nanohttp-logging.h" #include "nanohttp-common.h" #include "nanohttp-stream.h" #include "nanohttp-request.h" @@ -73,18 +76,17 @@ _httpd_admin_send_title(httpd_conn_t *conn, const char *title) "nhttpd "); http_output_stream_write_string(conn->out, title); http_output_stream_write_string(conn->out, "
"); - - return; } static inline void _httpd_admin_send_footer(httpd_conn_t *conn) { http_output_stream_write_string(conn->out, + "
" + "Admin page " + "cSOAP Home" "" ""); - - return; } static void @@ -125,8 +127,6 @@ _httpd_admin_list_services(httpd_conn_t *conn) http_output_stream_write_string(conn->out, ""); _httpd_admin_send_footer(conn); - - return; } static void @@ -135,10 +135,12 @@ _httpd_admin_list_statistics(httpd_conn_t *conn, const char *service_name) char buffer[1024]; hservice_t *service; + log_verbose("Client requested statistics for \"%s\"", service_name); + sprintf(buffer, "Listing statistics for service %s", service_name); _httpd_admin_send_title(conn, buffer); - if (!(service = httpd_find_service(service_name))) + if (!service_name || !(service = httpd_find_service(service_name))) { http_output_stream_write_string(conn->out, "

" @@ -154,7 +156,7 @@ _httpd_admin_list_statistics(httpd_conn_t *conn, const char *service_name) "

  • Bytes read: %lu
  • " "
  • Bytes sent: %lu
  • " "
  • Time used: %li.%li sec
  • " - "", service->statistics->requests, service->statistics->bytes_received, service->statistics->bytes_transmitted, @@ -165,8 +167,6 @@ _httpd_admin_list_statistics(httpd_conn_t *conn, const char *service_name) http_output_stream_write_string(conn->out, buffer); _httpd_admin_send_footer(conn); - - return; } static void @@ -197,8 +197,6 @@ _httpd_admin_enable_service(httpd_conn_t *conn, const char *service_name) "

    "); _httpd_admin_send_footer(conn); - - return; } static void @@ -227,8 +225,84 @@ _httpd_admin_disable_service(httpd_conn_t *conn, const char *service_name) "Service is down" "

    "); _httpd_admin_send_footer(conn); +} + +static void +_httpd_admin_set_loglevel(httpd_conn_t *conn, const char *loglevel) +{ + nanohttp_loglevel_t old; + char buffer[256]; + char *tmp; - return; + if (strcmp(loglevel, NANOHTTP_LOG_LEVEL_OFF_STRING) == 0) + { + old = nanohttp_log_set_loglevel(NANOHTTP_LOG_OFF); + } + else if (strcmp(loglevel, NANOHTTP_LOG_LEVEL_VERBOSE_STRING) == 0) + { + old = nanohttp_log_set_loglevel(NANOHTTP_LOG_VERBOSE); + } + else if (strcmp(loglevel, NANOHTTP_LOG_LEVEL_DEBUG_STRING) == 0) + { + old = nanohttp_log_set_loglevel(NANOHTTP_LOG_DEBUG); + } + else if (strcmp(loglevel, NANOHTTP_LOG_LEVEL_INFO_STRING) == 0) + { + old = nanohttp_log_set_loglevel(NANOHTTP_LOG_INFO); + } + else if (strcmp(loglevel, NANOHTTP_LOG_LEVEL_WARN_STRING) == 0) + { + old = nanohttp_log_set_loglevel(NANOHTTP_LOG_WARN); + } + else if (strcmp(loglevel, NANOHTTP_LOG_LEVEL_ERROR_STRING) == 0) + { + old = nanohttp_log_set_loglevel(NANOHTTP_LOG_ERROR); + } + else if (strcmp(loglevel, NANOHTTP_LOG_LEVEL_FATAL_STRING) == 0) + { + old = nanohttp_log_set_loglevel(NANOHTTP_LOG_FATAL); + } + else + { + old = nanohttp_log_get_loglevel(); + loglevel = NANOHTTP_LOG_LEVEL_UNKNOWN_STRING; + log_error("unknown loglevel requested"); + } + + switch (old) + { + case NANOHTTP_LOG_OFF: + tmp = NANOHTTP_LOG_LEVEL_OFF_STRING; + break; + case NANOHTTP_LOG_VERBOSE: + tmp = NANOHTTP_LOG_LEVEL_VERBOSE_STRING; + break; + case NANOHTTP_LOG_DEBUG: + tmp = NANOHTTP_LOG_LEVEL_DEBUG_STRING; + break; + case NANOHTTP_LOG_INFO: + tmp = NANOHTTP_LOG_LEVEL_INFO_STRING; + break; + case NANOHTTP_LOG_WARN: + tmp = NANOHTTP_LOG_LEVEL_WARN_STRING; + break; + case NANOHTTP_LOG_ERROR: + tmp = NANOHTTP_LOG_LEVEL_ERROR_STRING; + break; + case NANOHTTP_LOG_FATAL: + tmp = NANOHTTP_LOG_LEVEL_FATAL_STRING; + break; + default: + tmp = NANOHTTP_LOG_LEVEL_UNKNOWN_STRING; + break; + } + + _httpd_admin_send_title(conn, "Adjusting loglevel"); + + sprintf(buffer, "

    Switching from %s to %s

    ", tmp, loglevel); + http_output_stream_write_string(conn->out, buffer); + + _httpd_admin_send_footer(conn); } static void @@ -252,9 +326,13 @@ _httpd_admin_handle_get(httpd_conn_t * conn, struct hrequest_t *req) { _httpd_admin_disable_service(conn, param); } + else if ((param = hpairnode_get_ignore_case(req->query, NHTTPD_ADMIN_QUERY_SET_LOGLEVEL))) + { + _httpd_admin_set_loglevel(conn, param); + } else { - _httpd_admin_send_title(conn, "Welcome to the admin site"); + _httpd_admin_send_title(conn, "Welcome to the admin page"); http_output_stream_write_string(conn->out, ""); _httpd_admin_send_footer(conn); } - - return; } static void @@ -289,11 +374,10 @@ _httpd_admin_entry(httpd_conn_t * conn, struct hrequest_t *req) "" "

    Sorry!

    " "
    " - "
    POST Service is not implemented now. Use your browser.
    " + "
    Only GET method is implemented now. Use your browser.
    " "" ""); } - return; } herror_t @@ -305,7 +389,7 @@ httpd_admin_init_args(int argc, char **argv) { if (!strcmp(argv[i], NHTTPD_ARG_ENABLE_ADMIN)) { - httpd_register("/nhttp", _httpd_admin_entry); + httpd_register(NHTTPD_ADMIN_CONTEXT, _httpd_admin_entry); break; } } -- cgit v1.1-32-gdbae