]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
wash behind your ears
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 31 Dec 2008 22:44:23 +0000 (22:44 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 31 Dec 2008 22:44:23 +0000 (22:44 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11040 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_event_socket/mod_event_socket.c
src/switch_event.c

index cd7538a571f387c8f866b255a6ae909455f75c4e..fb55cae4c89af89d00d1071e0d3e9be2b47446ae 100644 (file)
@@ -628,15 +628,67 @@ SWITCH_STANDARD_API(event_sink_function)
 
                switch_mutex_unlock(listener->filter_mutex);
 
+       } else if (!strcasecmp(wcmd, "stop-logging")) {
+               char *id = switch_event_get_header(stream->param_event, "listen-id");
+               uint32_t idl = 0;
+
+               if (id) {
+                       idl = (uint32_t) atol(id);
+               }
+
+               if (!(listener = find_listener(idl))) {
+                       stream->write_function(stream, "<data><reply type=\"error\">Invalid Listen-ID</reply></data>\n");
+            goto end;
+               }
+
+               if (switch_test_flag(listener, LFLAG_LOG)) {
+                       switch_clear_flag_locked(listener, LFLAG_LOG);
+                       stream->write_function(stream, "<data><reply type=\"success\">Not Logging</reply></data>\n");
+               } else {
+                       stream->write_function(stream, "<data><reply type=\"error\">Not Logging</reply></data>\n");
+               }
+
+               goto end;
+
+       } else if (!strcasecmp(wcmd, "set-loglevel")) {
+               char *loglevel = switch_event_get_header(stream->param_event, "loglevel");
+               char *id = switch_event_get_header(stream->param_event, "listen-id");
+               uint32_t idl = 0;
+
+               if (id) {
+                       idl = (uint32_t) atol(id);
+               }
+
+               if (!(listener = find_listener(idl))) {
+                       stream->write_function(stream, "<data><reply type=\"error\">Invalid Listen-ID</reply></data>\n");
+            goto end;
+               }
+
+               if (loglevel) {
+                       switch_log_level_t ltype = switch_log_str2level(loglevel);
+                       if (ltype != SWITCH_LOG_INVALID) {
+                               listener->level = ltype;
+                               switch_set_flag(listener, LFLAG_LOG);
+                               stream->write_function(stream, "<data><reply type=\"success\">Log Level %s</reply></data>\n", loglevel);
+                       } else {
+                               stream->write_function(stream, "<data><reply type=\"error\">Invalid Level</reply></data>\n");
+                       }
+               } else {
+                       stream->write_function(stream, "<data><reply type=\"error\">Invalid Syntax</reply></data>\n");
+               }
+
+               goto end;
+
        } else if (!strcasecmp(wcmd, "create-listener")) {
                char *events = switch_event_get_header(stream->param_event, "events");
+               char *loglevel = switch_event_get_header(stream->param_event, "loglevel");
                switch_memory_pool_t *pool;
                char *next, *cur;
                uint32_t count = 0, key_count = 0;
                uint8_t custom = 0;
                char *edup;
                
-               if (switch_strlen_zero(events)) {
+               if (switch_strlen_zero(events) && switch_strlen_zero(loglevel)) {
                        stream->write_function(stream, "<data><reply type=\"error\">Missing parameter!</reply></data>\n");
                        goto end;
                }
@@ -652,58 +704,69 @@ SWITCH_STANDARD_API(event_sink_function)
                switch_set_flag(listener, LFLAG_AUTHED);
                switch_set_flag(listener, LFLAG_STATEFUL);
                switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, listener->pool);
+               switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, listener->pool);
+
+               if (loglevel) {
+                       switch_log_level_t ltype = switch_log_str2level(loglevel);
+                       if (ltype != SWITCH_LOG_INVALID) {
+                               listener->level = ltype;
+                               switch_set_flag(listener, LFLAG_LOG);
+                       }
+               }
                switch_thread_rwlock_create(&listener->rwlock, listener->pool);
                listener->id = next_id();
                listener->timeout = 60;
                listener->last_flush = switch_timestamp(NULL);
                
-               if (switch_stristr("xml", format)) {
-                       listener->format = EVENT_FORMAT_XML;
-               } else {
-                       listener->format = EVENT_FORMAT_PLAIN;
-               }
-
-               edup = strdup(events);
-               
-               for (cur = edup; cur; count++) {
-                       switch_event_types_t type;
+               if (events) {
 
-                       if ((next = strchr(cur, ' '))) {
-                               *next++ = '\0';
+                       if (switch_stristr("xml", format)) {
+                               listener->format = EVENT_FORMAT_XML;
+                       } else {
+                               listener->format = EVENT_FORMAT_PLAIN;
                        }
+                       
+                       edup = strdup(events);
+                       
+                       for (cur = edup; cur; count++) {
+                               switch_event_types_t type;
+                               
+                               if ((next = strchr(cur, ' '))) {
+                                       *next++ = '\0';
+                               }
 
-                       if (custom) {
-                               switch_core_hash_insert(listener->event_hash, cur, MARKER);
-                       } else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
-                               key_count++;
-                               if (type == SWITCH_EVENT_ALL) {
-                                       uint32_t x = 0;
-                                       for (x = 0; x < SWITCH_EVENT_ALL; x++) {
-                                               listener->event_list[x] = 1;
+                               if (custom) {
+                                       switch_core_hash_insert(listener->event_hash, cur, MARKER);
+                               } else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
+                                       key_count++;
+                                       if (type == SWITCH_EVENT_ALL) {
+                                               uint32_t x = 0;
+                                               for (x = 0; x < SWITCH_EVENT_ALL; x++) {
+                                                       listener->event_list[x] = 1;
+                                               }
+                                       }
+                                       if (type <= SWITCH_EVENT_ALL) {
+                                               listener->event_list[type] = 1;
+                                       }
+                                       if (type == SWITCH_EVENT_CUSTOM) {
+                                               custom++;
                                        }
                                }
-                               if (type <= SWITCH_EVENT_ALL) {
-                                       listener->event_list[type] = 1;
-                               }
-                               if (type == SWITCH_EVENT_CUSTOM) {
-                                       custom++;
-                               }
+                               
+                               cur = next;
                        }
-
-                       cur = next;
-               }
                
 
-               switch_safe_free(edup);
+                       switch_safe_free(edup);
 
-               if (!key_count) {
-                       switch_core_hash_destroy(&listener->event_hash);
-                       switch_core_destroy_memory_pool(&listener->pool);
-                       stream->write_function(stream, "<data><reply type=\"error\">No keywords supplied</reply></data>\n");
-                       goto end;
+                       if (!key_count) {
+                               switch_core_hash_destroy(&listener->event_hash);
+                               switch_core_destroy_memory_pool(&listener->pool);
+                               stream->write_function(stream, "<data><reply type=\"error\">No keywords supplied</reply></data>\n");
+                               goto end;
+                       }
                }
 
-
                switch_set_flag_locked(listener, LFLAG_EVENTS);
                add_listener(listener);
                stream->write_function(stream, "<data>\n");
@@ -750,7 +813,38 @@ SWITCH_STANDARD_API(event_sink_function)
                listener->last_flush = switch_timestamp(NULL);
                stream->write_function(stream, "<data>\n <reply type=\"success\">Current Events Follow</reply>\n");                     
                xmlize_listener(listener, stream);
-               stream->write_function(stream, "<events>\n");                   
+
+               if (switch_test_flag(listener, LFLAG_LOG)) {
+                       stream->write_function(stream, "<log_data>\n");
+
+                       while (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
+                               switch_log_node_t *dnode = (switch_log_node_t *) pop;
+                               int encode_len = (strlen(dnode->data) * 3) + 1;
+                               char *encode_buf = malloc(encode_len);
+                               
+                               switch_assert(encode_buf);
+                               
+                               memset(encode_buf, 0, encode_len);
+                               switch_url_encode((char *) dnode->data, encode_buf, encode_len);
+                               
+
+                               stream->write_function(stream, "<log log-level=\"%d\" text-channel=\"%d\" log-file=\"%s\" log-func=\"%s\" log-line=\"%d\">%s</log>\n",
+                                                                          dnode->level,
+                                                                          dnode->channel,
+                                                                          dnode->file,
+                                                                          dnode->func,
+                                                                          dnode->line,
+                                                                          encode_buf
+                                                                          );
+                               free(encode_buf);
+                               free(dnode->data);
+                               free(dnode);
+                       }
+
+                       stream->write_function(stream, "</log_data>\n");
+               }
+
+               stream->write_function(stream, "<events>\n");
 
                while (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
                        char *etype;
index 05c5cd2dd164a5ae35ce8de472d996ec7ff8430d..f7403db4cc877e6fe69e5ef0a0475f40d799f14e 100644 (file)
@@ -930,13 +930,20 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
 
 static switch_xml_t add_xml_header(switch_xml_t xml, char *name, char *value, int offset)
 {
-       switch_xml_t header = switch_xml_add_child_d(xml, "header", offset);
-
+       switch_xml_t header = switch_xml_add_child_d(xml, name, offset);
+       
        if (header) {
-               switch_xml_set_attr_d(header, "name", name);
-               switch_xml_set_attr_d(header, "value", value);
+               int encode_len = (strlen(value) * 3) + 1;
+               char *encode_buf = malloc(encode_len);
+               
+               switch_assert(encode_buf);
+               memset(encode_buf, 0, encode_len);
+               switch_url_encode((char *) value, encode_buf, encode_len);
+               switch_xml_set_txt_d(header, encode_buf);
+               free(encode_buf);
        }
-
+       
        return header;
 }
 
@@ -948,6 +955,7 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
        switch_xml_t xml = NULL;
        uint32_t off = 0;
        va_list ap;
+       switch_xml_t xheaders = NULL;
 
        if (!(xml = switch_xml_new("event"))) {
                return xml;
@@ -972,8 +980,11 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
                }
        }
 
-       for (hp = event->headers; hp; hp = hp->next) {
-               add_xml_header(xml, hp->name, hp->value, off++);
+       if ((xheaders = switch_xml_add_child_d(xml, "headers", off++))) {
+               int hoff = 0;
+               for (hp = event->headers; hp; hp = hp->next) {
+                       add_xml_header(xheaders, hp->name, hp->value, hoff++);
+               }
        }
 
        if (!switch_strlen_zero(data)) {
@@ -1032,7 +1043,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_fire_detailed(const char *file, con
        switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-Local", date);
        switch_rfc822_date(date, ts);
        switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", date);
-       switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-timestamp", "%" SWITCH_UINT64_T_FMT, (uint64_t) ts);
+       switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-Timestamp", "%" SWITCH_UINT64_T_FMT, (uint64_t) ts);
        switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Calling-File", switch_cut_path(file));
        switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Function", func);
        switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Line-Number", "%d", line);