]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
put math patch back
authorBrian West <brian@freeswitch.org>
Wed, 20 Jan 2010 19:19:48 +0000 (19:19 +0000)
committerBrian West <brian@freeswitch.org>
Wed, 20 Jan 2010 19:19:48 +0000 (19:19 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16423 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/private/switch_core_pvt.h
src/include/switch_channel.h
src/include/switch_core.h
src/include/switch_types.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_channel.c
src/switch_core_session.c
src/switch_log.c

index 8f2ef2a3095297d1cd1f7687ee6f6ee60dbd3d48..2df7e24a03432b840747abaf4c6aa22937638abb 100644 (file)
@@ -156,6 +156,7 @@ struct switch_core_session {
        uint32_t read_frame_count;
        uint32_t track_duration;
        uint32_t track_id;
+       switch_log_level_t loglevel;
 };
 
 struct switch_media_bug {
index 95ddd778cf900cebd34f5ce56a8b4f26ead172b2..a906b3659aa1e67719938afb0dc6186f01c1776b 100644 (file)
@@ -537,6 +537,7 @@ SWITCH_DECLARE(void) switch_channel_clear_app_flag(switch_channel_t *channel, ui
 SWITCH_DECLARE(int) switch_channel_test_app_flag(switch_channel_t *channel, uint32_t flags);
 SWITCH_DECLARE(void) switch_channel_set_hangup_time(switch_channel_t *channel);
 SWITCH_DECLARE(switch_call_direction_t) switch_channel_direction(switch_channel_t *channel);
+SWITCH_DECLARE(switch_core_session_t*) switch_channel_get_session(switch_channel_t *channel);
 
 /** @} */
 
index 19aea4337795ce29fa82e36f770151ca09f8ca43..2997f567050bbe4913644a4999fccfb9c6a28591 100644 (file)
@@ -676,6 +676,22 @@ SWITCH_DECLARE(void) switch_core_session_signal_state_change(_In_ switch_core_se
 */
 SWITCH_DECLARE(char *) switch_core_session_get_uuid(_In_ switch_core_session_t *session);
 
+
+/*! 
+  \brief Sets the log level for a session
+  \param session the session to set the log level on 
+  \return SWITCH_STATUS_SUCCESS
+*/
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_loglevel(switch_core_session_t *session, switch_log_level_t loglevel);
+
+
+/*! 
+  \brief Get the log level for a session
+  \param session the session to get the log level from 
+  \return the log level
+*/
+SWITCH_DECLARE(switch_log_level_t) switch_core_session_get_loglevel(switch_core_session_t *session);
+
 /*! 
   \brief Retrieve the unique identifier from the core
   \return a string representing the uuid
index 309c00eade26330672433d6f33d1a2d9786ff3cb..7d2b2495472642f16242d6e8bf6433c383c69a04 100644 (file)
@@ -805,7 +805,8 @@ SWITCH_CHANNEL_ID_EVENT                     - Write to the event engine as a LOG event
 typedef enum {
        SWITCH_CHANNEL_ID_LOG,
        SWITCH_CHANNEL_ID_LOG_CLEAN,
-       SWITCH_CHANNEL_ID_EVENT
+       SWITCH_CHANNEL_ID_EVENT,
+       SWITCH_CHANNEL_ID_SESSION
 } switch_text_channel_t;
 
 typedef enum {
@@ -817,11 +818,11 @@ typedef uint32_t switch_core_session_message_flag_t;
 
 #define SWITCH_CHANNEL_LOG SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, NULL
 #define SWITCH_CHANNEL_LOG_CLEAN SWITCH_CHANNEL_ID_LOG_CLEAN, __FILE__, __SWITCH_FUNC__, __LINE__, NULL
-#define SWITCH_CHANNEL_SESSION_LOG_CLEAN(x) SWITCH_CHANNEL_ID_LOG_CLEAN, __FILE__, __SWITCH_FUNC__, __LINE__, ((x) ? switch_core_session_get_uuid(x) : NULL)
+#define SWITCH_CHANNEL_SESSION_LOG_CLEAN(x) SWITCH_CHANNEL_ID_LOG_CLEAN, __FILE__, __SWITCH_FUNC__, __LINE__, switch_core_session_get_uuid((x))
 #define SWITCH_CHANNEL_EVENT SWITCH_CHANNEL_ID_EVENT, __FILE__, __SWITCH_FUNC__, __LINE__, NULL
-#define SWITCH_CHANNEL_SESSION_LOG(x) SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, ((x) ? switch_core_session_get_uuid(x) : NULL)
-#define SWITCH_CHANNEL_CHANNEL_LOG(x) SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, ((x) ? switch_channel_get_uuid(x) : NULL)
-#define SWITCH_CHANNEL_UUID_LOG(x) SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, x
+#define SWITCH_CHANNEL_SESSION_LOG(x) SWITCH_CHANNEL_ID_SESSION, __FILE__, __SWITCH_FUNC__, __LINE__, (const char*)(x)
+#define SWITCH_CHANNEL_CHANNEL_LOG(x) SWITCH_CHANNEL_ID_SESSION, __FILE__, __SWITCH_FUNC__, __LINE__, (const char*)switch_channel_get_session(x)
+#define SWITCH_CHANNEL_UUID_LOG(x) SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, (x)
 
 /*!
   \enum switch_channel_state_t
index 75da1211db7e8d9b8b079d7caaf9c36b16f48587..ca5c303c43aa0763b0cb2142010baac7e37fd8e9 100644 (file)
@@ -4006,6 +4006,41 @@ SWITCH_STANDARD_API(escape_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
+#define UUID_LOGLEVEL_SYNTAX "<uuid> <level>"
+SWITCH_STANDARD_API(uuid_loglevel)
+{
+       switch_core_session_t *tsession = NULL;
+       char *uuid = NULL, *text = NULL;
+
+       if (!zstr(cmd) && (uuid = strdup(cmd))) {
+               if ((text = strchr(uuid, ' '))) {
+                       *text++ = '\0';
+               }
+       }
+
+       if (zstr(uuid) || zstr(text)) {
+               stream->write_function(stream, "-USAGE: %s\n", UUID_LOGLEVEL_SYNTAX);
+       } else {
+               switch_log_level_t level = switch_log_str2level(text);
+
+               if (level == SWITCH_LOG_INVALID) {
+                       stream->write_function(stream, "-ERR Invalid log level!\n");
+               }
+               else if ((tsession = switch_core_session_locate(uuid))) {
+
+                       switch_core_session_set_loglevel(tsession, level);
+                       stream->write_function(stream, "+OK\n");
+                       switch_core_session_rwunlock(tsession);
+               }
+               else {
+                       stream->write_function(stream, "-ERR No Such Channel %s!\n", uuid);
+               }
+       }
+
+       switch_safe_free(uuid);
+       return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown)
 {
        int x;
@@ -4108,6 +4143,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        SWITCH_ADD_API(commands_api_interface, "uuid_getvar", "uuid_getvar", uuid_getvar_function, GETVAR_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_hold", "hold", uuid_hold_function, HOLD_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_kill", "Kill Channel", kill_function, KILL_SYNTAX);
+       SWITCH_ADD_API(commands_api_interface, "uuid_loglevel", "set loglevel on session", uuid_loglevel, UUID_LOGLEVEL_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_media", "media", uuid_media_function, MEDIA_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_park", "Park Channel", park_function, PARK_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_preprocess", "Pre-process Channel", preprocess_function, PREPROCESS_SYNTAX);
@@ -4130,6 +4166,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        switch_console_set_complete("add fsctl default_dtmf_duration");
        switch_console_set_complete("add fsctl hupall");
        switch_console_set_complete("add fsctl loglevel");
+       switch_console_set_complete("add fsctl loglevel console");
+       switch_console_set_complete("add fsctl loglevel alert");
+       switch_console_set_complete("add fsctl loglevel crit");
+       switch_console_set_complete("add fsctl loglevel err");
+       switch_console_set_complete("add fsctl loglevel warning");
+       switch_console_set_complete("add fsctl loglevel notice");
+       switch_console_set_complete("add fsctl loglevel info");
+       switch_console_set_complete("add fsctl loglevel debug");
        switch_console_set_complete("add fsctl max_dtmf_duration");
        switch_console_set_complete("add fsctl max_sessions");
        switch_console_set_complete("add fsctl min_dtmf_duration");
@@ -4193,6 +4237,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        switch_console_set_complete("add uuid_getvar ::console::list_uuid");
        switch_console_set_complete("add uuid_hold ::console::list_uuid");
        switch_console_set_complete("add uuid_kill ::console::list_uuid");
+       switch_console_set_complete("add uuid_loglevel ::console::list_uuid console");
+       switch_console_set_complete("add uuid_loglevel ::console::list_uuid alert");
+       switch_console_set_complete("add uuid_loglevel ::console::list_uuid crit");
+       switch_console_set_complete("add uuid_loglevel ::console::list_uuid err");
+       switch_console_set_complete("add uuid_loglevel ::console::list_uuid warning");
+       switch_console_set_complete("add uuid_loglevel ::console::list_uuid notice");
+       switch_console_set_complete("add uuid_loglevel ::console::list_uuid info");
+       switch_console_set_complete("add uuid_loglevel ::console::list_uuid debug");
        switch_console_set_complete("add uuid_media ::console::list_uuid");
        switch_console_set_complete("add uuid_park ::console::list_uuid");
        switch_console_set_complete("add uuid_preprocess ::console::list_uuid");
index 487d9e450dc0f99dc49a168af7b7510dab322735..fab0548940b40daf10860fd9369e6a4293b6c3a6 100644 (file)
@@ -2948,6 +2948,24 @@ static switch_status_t api_chat_send(const char *proto, const char *from, const
        return SWITCH_STATUS_SUCCESS;
 }
 
+
+#define SESSION_LOGLEVEL_SYNTAX "<level>"
+SWITCH_STANDARD_APP(session_loglevel_function)
+{
+       if (!zstr(data)) {
+               switch_log_level_t level = switch_log_str2level(data);
+
+               if (level == SWITCH_LOG_INVALID) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid log level: %s\n", data);
+               } else {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting log level \"%s\" on session\n", switch_log_level2str(level));
+                       switch_core_session_set_loglevel(session, level);
+               }
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No log level specified\n");
+       }
+}
+
 #define SPEAK_DESC "Speak text to a channel via the tts interface"
 #define DISPLACE_DESC "Displace audio from a file to the channels input"
 #define SESS_REC_DESC "Starts a background recording of the entire session"
@@ -3108,6 +3126,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
        SWITCH_ADD_APP(app_interface, "say", "say", "say", say_function, SAY_SYNTAX, SAF_NONE);
 
        SWITCH_ADD_APP(app_interface, "wait_for_silence", "wait_for_silence", "wait_for_silence", wait_for_silence_function, WAIT_FOR_SILENCE_SYNTAX, SAF_NONE);
+       SWITCH_ADD_APP(app_interface, "session_loglevel", "session_loglevel", "session_loglevel", session_loglevel_function, SESSION_LOGLEVEL_SYNTAX, SAF_SUPPORT_NOMEDIA);
 
        SWITCH_ADD_DIALPLAN(dp_interface, "inline", inline_dialplan_hunt);
 
index 1e9c27dc13bbab86971b2749ae7fdcb947312469..8329b9553d36828213980598149eede75b65dcbd 100644 (file)
@@ -2649,6 +2649,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_get_variables(switch_channel_t *c
        return status;
 }
 
+SWITCH_DECLARE(switch_core_session_t*) switch_channel_get_session(switch_channel_t *channel)
+{
+       switch_assert(channel);
+       return channel->session;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *channel)
 {
        switch_status_t status = SWITCH_STATUS_SUCCESS;
index d2ef5490a11eedfa9388b71019c3d9db964cbeac..304ecc2a36e814bb5cd2a3c23a4f554076848ecd 100644 (file)
@@ -1712,6 +1712,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
        return status;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_loglevel(switch_core_session_t *session, switch_log_level_t loglevel)
+{
+       switch_assert(session != NULL);
+       session->loglevel = loglevel;
+       return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_DECLARE(switch_log_level_t) switch_core_session_get_loglevel(switch_core_session_t *session)
+{
+       switch_assert(session != NULL);
+       return session->loglevel;
+}
+
 /* For Emacs:
  * Local Variables:
  * mode:c
index fcafd060db2008b31b58e260137bc326f60cc76f..b07978506065f732829beb18343caa59f76b4c8a 100644 (file)
@@ -339,6 +339,14 @@ SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const cha
 #else
        const char *extra_fmt = "%s [%s] %s:%d%c%s";
 #endif
+       switch_log_level_t limit_level = runtime.hard_log_level;
+
+       if (channel == SWITCH_CHANNEL_ID_SESSION && userdata) {
+               switch_core_session_t *session = (switch_core_session_t*)userdata;
+               if (limit_level < session->loglevel) {
+                       limit_level = session->loglevel;
+               }
+       }
 
        if (level > 100) {
                if ((uint32_t)(level - 100) > runtime.debug_level) {
@@ -348,7 +356,7 @@ SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const cha
                level = 7;
        }
 
-       if (level > runtime.hard_log_level) {
+       if (level > limit_level) {
                return;
        }
 
@@ -466,7 +474,11 @@ SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const cha
                node->content = content;
                node->timestamp = now;
                node->channel = channel;
-               node->userdata = !zstr(userdata) ? strdup(userdata) : NULL;
+               if (channel == SWITCH_CHANNEL_ID_SESSION) {
+                       node->userdata = userdata ? strdup(switch_core_session_get_uuid((switch_core_session_t*)userdata)) : NULL;
+               } else {
+                       node->userdata = !zstr(userdata) ? strdup(userdata) : NULL;
+               }
 
                if (switch_queue_trypush(LOG_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
                        switch_log_node_free(&node);