]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11693 [core] Added switch_channel_set_log_tag() and switch_channel_get_log_tags...
authorChris Rienzo <chris@signalwire.com>
Thu, 7 Mar 2019 15:26:34 +0000 (15:26 +0000)
committerChris Rienzo <chris@rienzo.com>
Sat, 9 Mar 2019 20:21:46 +0000 (15:21 -0500)
src/include/switch_channel.h
src/include/switch_log.h
src/switch_channel.c
src/switch_log.c

index 8e24893fdcacb9c0235f181fa7aef78302a187d2..ec066852c6db462d5dc8389ec34afd0571b44f4e 100644 (file)
@@ -270,6 +270,9 @@ SWITCH_DECLARE(char *) switch_channel_get_uuid(switch_channel_t *channel);
 
 SWITCH_DECLARE(switch_status_t) switch_channel_set_profile_var(switch_channel_t *channel, const char *name, const char *val);
 
+SWITCH_DECLARE(switch_status_t) switch_channel_set_log_tag(switch_channel_t *channel, const char *tagname, const char *tagvalue);
+SWITCH_DECLARE(switch_status_t) switch_channel_get_log_tags(switch_channel_t *channel, switch_event_t **log_tags);
+
 SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
                                                                                                                                          const char *varname, const char *value, switch_bool_t var_check);
 SWITCH_DECLARE(switch_status_t) switch_channel_add_variable_var_check(switch_channel_t *channel,
index f0df9d831535fa2db369d1127844ae188518d475..357f20f32469a827b570cb5ad160efeb9fe0c0b3 100644 (file)
@@ -65,6 +65,7 @@ SWITCH_BEGIN_EXTERN_C
        /* To maintain abi, only add new elements to the end of this struct and do not delete any elements */
        switch_text_channel_t channel;
        switch_log_level_t slevel;
+       switch_event_t *tags;
 } switch_log_node_t;
 
 typedef switch_status_t (*switch_log_function_t) (const switch_log_node_t *node, switch_log_level_t level);
index 684c4014ecd1200c238cd280fe96711f794429fd..b282e2385a0b748ecc8cefa038c2e97927df60e5 100644 (file)
@@ -176,6 +176,7 @@ struct switch_channel {
        switch_hold_record_t *hold_record;
        switch_device_node_t *device_node;
        char *device_id;
+       switch_event_t *log_tags;
 };
 
 static void process_device_hup(switch_channel_t *channel);
@@ -741,6 +742,9 @@ SWITCH_DECLARE(void) switch_channel_uninit(switch_channel_t *channel)
        switch_event_destroy(&channel->api_list);
        switch_event_destroy(&channel->var_list);
        switch_event_destroy(&channel->app_list);
+       if (channel->log_tags) {
+               switch_event_destroy(&channel->log_tags);
+       }
        switch_mutex_unlock(channel->profile_mutex);
 }
 
@@ -1412,6 +1416,37 @@ SWITCH_DECLARE(void) switch_channel_set_presence_data_vals(switch_channel_t *cha
        switch_safe_free(data_copy);
 }
 
+SWITCH_DECLARE(switch_status_t) switch_channel_set_log_tag(switch_channel_t *channel, const char *tagname, const char *tagvalue)
+{
+       switch_status_t status = SWITCH_STATUS_FALSE;
+       switch_assert(channel != NULL);
+       switch_mutex_lock(channel->profile_mutex);
+       if (!zstr(tagname)) {
+               if (!channel->log_tags) {
+                       switch_event_create_plain(&channel->log_tags, SWITCH_EVENT_CHANNEL_DATA);
+               }
+               if (zstr(tagvalue)) {
+                       switch_event_del_header(channel->log_tags, tagname);
+               } else {
+                       switch_event_add_header_string(channel->log_tags, SWITCH_STACK_BOTTOM, tagname, tagvalue);
+               }
+               status = SWITCH_STATUS_SUCCESS;
+       }
+       switch_mutex_unlock(channel->profile_mutex);
+       return status;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_channel_get_log_tags(switch_channel_t *channel, switch_event_t **log_tags)
+{
+       switch_status_t status = SWITCH_STATUS_FALSE;
+       switch_assert(channel != NULL);
+       switch_mutex_lock(channel->profile_mutex);
+       if (channel->log_tags && log_tags) {
+               status = switch_event_dup(log_tags, channel->log_tags);
+       }
+       switch_mutex_unlock(channel->profile_mutex);
+       return status;
+}
 
 SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
                                                                                                                                          const char *varname, const char *value, switch_bool_t var_check)
index bed7b48968d5c5812018e42ca112b3d85eeaf954..e33b0421f345c7acb512a84c16a3f09a5db56558 100644 (file)
@@ -125,6 +125,10 @@ SWITCH_DECLARE(switch_log_node_t *) switch_log_node_dup(const switch_log_node_t
                switch_assert(newnode->userdata);
        }
 
+       if (node->tags) {
+               switch_event_dup(&newnode->tags, node->tags);
+       }
+
        return newnode;
 }
 
@@ -141,6 +145,9 @@ SWITCH_DECLARE(void) switch_log_node_free(switch_log_node_t **pnode)
        if (node) {
                switch_safe_free(node->userdata);
                switch_safe_free(node->data);
+               if (node->tags) {
+                       switch_event_destroy(&node->tags);
+               }
 #ifdef SWITCH_LOG_RECYCLE
                if (switch_queue_trypush(LOG_RECYCLE_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
                        free(node);
@@ -490,9 +497,13 @@ SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const cha
                node->content = content;
                node->timestamp = now;
                node->channel = channel;
+               node->tags = NULL;
                if (channel == SWITCH_CHANNEL_ID_SESSION) {
                        switch_core_session_t *session = (switch_core_session_t *) userdata;
                        node->userdata = userdata ? strdup(switch_core_session_get_uuid(session)) : NULL;
+                       if (session) {
+                               switch_channel_get_log_tags(switch_core_session_get_channel(session), &node->tags);
+                       }
                } else {
                        node->userdata = !zstr(userdata) ? strdup(userdata) : NULL;
                }