]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add ability to log commands executed in mod_xml_rpc
authorolegstolyar <olegstolyar@gmail.com>
Sun, 14 Sep 2014 16:14:26 +0000 (16:14 +0000)
committerOleg Stolyar <olegstolyar@gmail.com>
Wed, 29 Oct 2014 17:08:21 +0000 (17:08 +0000)
conf/vanilla/autoload_configs/xml_rpc.conf.xml
src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c

index 714a909907082d0153bc9cf241f2ef3ba0ebfe3e..c5c335429358907c1e495a861c173a6436e978c6 100644 (file)
@@ -6,5 +6,11 @@
     <param name="auth-realm" value="freeswitch"/>
     <param name="auth-user" value="freeswitch"/>
     <param name="auth-pass" value="works"/>
+
+
+    <!-- regex pattern to match against commands called against this service.
+         If a command with arguments matches, it will be logged at INFO level -->
+    <!--<param name="commands-to-log" value=""/> -->
+
   </settings>
 </configuration>
index 0951fc0d9cf6761608243b15abd95a34647d27ea..c271ffb359381275dea9d40b391e1214f5c1fed2 100644 (file)
@@ -89,6 +89,7 @@ static struct {
        TServer abyssServer;
        xmlrpc_registry *registryP;
        switch_bool_t enable_websocket;
+       char *commands_to_log;
 } globals;
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_realm, globals.realm);
@@ -103,6 +104,8 @@ static switch_status_t do_config(void)
        char *realm, *user, *pass, *default_domain;
 
        default_domain = realm = user = pass = NULL;
+       globals.commands_to_log = NULL;
+
        if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
                return SWITCH_STATUS_TERM;
@@ -130,6 +133,8 @@ static switch_status_t do_config(void)
                                        globals.virtual_host = switch_true(val);
                                } else if (!strcasecmp(var, "enable-websocket")) {
                                        globals.enable_websocket = switch_true(val);
+                               } else if (!strcasecmp(var, "commands-to-log")) {
+                                       globals.commands_to_log = val;
                                }
                        }
                }
@@ -800,6 +805,7 @@ abyss_bool handler_hook(TSession * r)
 {
        switch_stream_handle_t stream = { 0 };
        char *command;
+       char *full_command;
        int i;
        char *fs_user = NULL, *fs_domain = NULL;
        char *path_info = NULL;
@@ -1054,6 +1060,16 @@ abyss_bool handler_hook(TSession * r)
        /* fs api command will write to stream,  calling http_stream_write / http_stream_raw_write      */
        /* switch_api_execute will stream INVALID COMMAND before it fails                                               */
        switch_api_execute(command, api_str, NULL, &stream);
+       
+        if (globals.commands_to_log != NULL) {
+                full_command = switch_mprintf("%s%s%s", command, (api_str==NULL ? "" : " "), api_str);
+
+                if (switch_regex_match(full_command, globals.commands_to_log) == SWITCH_STATUS_SUCCESS) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Executed HTTP request command: [%s].\n", full_command);
+                }
+
+                switch_safe_free(full_command);
+        }
 
        r->responseStarted = TRUE;
        ResponseStatus(r, 200);     /* we don't want an assertion failure */