[PATCH] admin http 'loglevel' command for bearerbox

"Angel Fradejas" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi all

Find attached a patch to support an admin HTTP command to change the log
level without restaring bearerbox.

Example: http://localhost:13000/loglevel?password=xxxxx&level=1

Please consider committing to cvs.

Angel Fradejas
Mediafusión España, S.A.
[email protected]
www.mediafusion.es
Tel. +34 91 252 32 00
Fax +34 91 572 27 08
patch_bearerbox_dynamic_loglevel.diff (application/octet-stream, 2.5 KB)
Index: gw/bb_http.c
===================================================================
RCS file: /home/cvs/gateway/gw/bb_http.c,v
retrieving revision 1.42
diff -u -r1.42 bb_http.c
--- gw/bb_http.c	24 Feb 2003 10:42:51 -0000	1.42
+++ gw/bb_http.c	27 Feb 2003 10:54:54 -0000
@@ -95,6 +95,27 @@
     return store_status(status_type);
 }
 
+static Octstr *httpd_loglevel(List *cgivars)
+{
+    Octstr *reply;
+    Octstr *level;
+    int new_loglevel;
+    
+    if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;
+    if ((reply = httpd_check_status())!= NULL) return reply;
+ 
+    /* check if new loglevel is given */
+    level = http_cgi_variable(cgivars, "level");
+    if (level) {
+        new_loglevel = atoi(octstr_get_cstr(level));
+        log_set_log_level(new_loglevel);
+        return octstr_format("log-level set to %d", new_loglevel);
+    }
+    else {
+        return octstr_create("New level not given");
+    }
+}
+
 static Octstr *httpd_shutdown(List *cgivars)
 {
     Octstr *reply;
@@ -261,6 +282,9 @@
     } else if (octstr_str_compare(url, "/store-status.xml") == 0) {
         status_type = BBSTATUS_XML;
         reply = httpd_store_status(cgivars, status_type);
+    } else if (octstr_str_compare(url, "/cgi-bin/loglevel")==0
+	       || octstr_str_compare(url, "/loglevel")==0) {
+	reply = httpd_loglevel(cgivars);
     } else if (octstr_str_compare(url, "/cgi-bin/shutdown")==0
 	       || octstr_str_compare(url, "/shutdown")==0) {
 	reply = httpd_shutdown(cgivars);
Index: gwlib/log.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/log.c,v
retrieving revision 1.28
diff -u -r1.28 log.c
--- gwlib/log.c	9 Jul 2002 00:50:49 -0000	1.28
+++ gwlib/log.c	27 Feb 2003 10:54:54 -0000
@@ -92,6 +92,15 @@
     }
 }
 
+void log_set_log_level(enum output_level level) 
+{
+    int i;
+    
+    for (i = 0; i < num_logfiles; ++i) {
+	    logfiles[i].minimum_output_level = level;
+    }
+}
+
 
 void log_set_syslog(const char *ident, int syslog_level) 
 {
Index: gwlib/log.h
===================================================================
RCS file: /home/cvs/gateway/gwlib/log.h,v
retrieving revision 1.15
diff -u -r1.15 log.h
--- gwlib/log.h	9 Jul 2002 00:50:49 -0000	1.15
+++ gwlib/log.h	27 Feb 2003 10:54:54 -0000
@@ -77,6 +77,10 @@
    (see below). */
 void log_set_output_level(enum output_level level);
 
+/* Set minimum level for output messages to logfiles */
+void log_set_log_level(enum output_level level);
+
+
 /*
  * Set syslog usage. If `ident' is NULL, syslog is not used.
  */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.