]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
event cleanup from windows perspective
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 23 Dec 2005 21:09:36 +0000 (21:09 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 23 Dec 2005 21:09:36 +0000 (21:09 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@204 d0543943-73ff-0310-b7d9-9358b9ac24b2

13 files changed:
src/include/switch_caller.h
src/include/switch_event.h
src/include/switch_types.h
src/include/switch_utils.h
src/mod/mod_portaudio/mod_portaudio.c
src/mod/mod_xmpp_event/mod_xmpp_event.c
src/switch.c
src/switch_caller.c
src/switch_channel.c
src/switch_console.c
src/switch_event.c
src/switch_loadable_module.c
src/switch_utils.c

index b248bf1eb109e7d701e4a5b0533f91042d7b7d01..738685caaee1fedab43913b6eca04380840fa13b 100644 (file)
@@ -92,6 +92,7 @@ extern "C" {
        SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_session *session,
                                                                                                                                                switch_caller_profile *tocopy);
 
+       SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, switch_event *event);
 
 
 #ifdef __cplusplus
index 21bb02605d97052714017630b1e3fde72b7a7f69..92229fc9904330a0872a807890debfd4fcf853b5 100644 (file)
@@ -75,7 +75,7 @@ SWITCH_DECLARE(switch_status) switch_event_shutdown(void);
 SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool);
 SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id, char *subclass_name);
 SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header_name);
-SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, char *header_name, char *fmt, ...);
+SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...);
 SWITCH_DECLARE(void) switch_event_destroy(switch_event **event);
 SWITCH_DECLARE(switch_status) switch_event_dup(switch_event **event, switch_event *todup);
 SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, int line, switch_event **event, void *user_data);
@@ -90,5 +90,4 @@ SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *f
 #define switch_event_create(event, id) switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)
 #define switch_event_fire(event) switch_event_fire_detailed(__FILE__, (char * )__FUNCTION__, __LINE__, event, NULL)
 #define switch_event_fire_data(event, data) switch_event_fire_detailed(__FILE__, (char * )__FUNCTION__, __LINE__, event, data)
-
 #endif
index d155d3925d45b132d14079342c324f3d15022937..087bd82159456af338625464f2bde30bb8092797 100644 (file)
@@ -40,6 +40,11 @@ extern "C" {
 #define SWITCH_GLOBAL_VERSION "1"
 #define SWITCH_MAX_CODECS 30
 
+typedef enum {
+       SWITCH_STACK_BOTTOM,
+       SWITCH_STACK_TOP
+} switch_stack_t;
+
 typedef enum {
        SWITCH_STATUS_SUCCESS,
        SWITCH_STATUS_FALSE,
@@ -132,7 +137,6 @@ typedef enum {
        SWITCH_EVENT_ANSWER_CHAN,
        SWITCH_EVENT_HANGUP_CHAN,
        SWITCH_EVENT_STARTUP,
-       SWITCH_EVENT_EVENT_SHUTDOWN,
        SWITCH_EVENT_SHUTDOWN,
        SWITCH_EVENT_ALL
 } switch_event_t;
index 6cd55afc3d16c32cdb1a9a1be7b4f17ab9650828..8fd858a4717b47f78a26a36107b67c071a6ca544 100644 (file)
@@ -69,6 +69,7 @@ SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char
 SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock, unsigned int flags, switch_memory_pool *pool);
 SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms);
 SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len);
+SWITCH_DECLARE(char *) switch_cut_path(char *in);
 
 #if !defined(switch_strdupa) && defined(__GNUC__)
 # define switch_strdupa(s)                                                                     \
index bfbbf33139b054e34bbf16878874c7fc7a257de3..f7fe818d097aa2deca8778b197f49a95619a6d1d 100644 (file)
@@ -271,7 +271,7 @@ static switch_status channel_on_transmit(switch_core_session *session)
                snprintf(buf, sizeof(buf), "BRRRRING! BRRRRING! call %s\n", tech_pvt->call_id);
 
                if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) {
-                       switch_event_add_header(event, "event_info", buf);
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_info", buf);
                        switch_event_fire(&event);
                }
 
index 03ab8d5ff85daefa388d78c85ac2a1c91f8af63f..76dcb9eca392b31cf907ba02196e1858b9672e1b 100644 (file)
@@ -62,9 +62,14 @@ static void event_handler (switch_event *event)
 {
        char buf[1024];
        iks *msg;
+       int loops = 0;
 
-       if (!globals.session.authorized) {
-               return;
+       while (!globals.session.authorized) {
+               switch_yield(100000);
+               if (loops++ > 5) {
+                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Nothing to do with this Event!\n");
+                       return;
+               }
        }
 
        switch(event->event_id) {
index 868484f139857d2755d719817f52c87529e9488c..7e060969bab347567f335a78981f6949d1df1c94 100644 (file)
@@ -53,7 +53,7 @@ int main(int argc, char *argv[]) {
        }
 
        if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
-               switch_event_add_header(event, "event_info", "System Ready");
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
                switch_event_fire(&event);
        }
 
@@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
        switch_console_loop();
 
        if (switch_event_create(&event, SWITCH_EVENT_SHUTDOWN) == SWITCH_STATUS_SUCCESS) {
-               switch_event_add_header(event, "event_info", "System Shutting Down");
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Shutting Down");
                switch_event_fire(&event);
        }
 
index 54032df92a1b367649e698ad6bde9f0aadc8ad4f..dc0be92184637c8c724119ebed8d5587ca146a12 100644 (file)
@@ -75,6 +75,33 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_
        return profile;
 }
 
+SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, switch_event *event)
+
+{
+               if (caller_profile->dialplan) {
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Dialplan", caller_profile->dialplan);
+               }
+               if (caller_profile->caller_id_name) {
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Caller-ID-Name", caller_profile->caller_id_name);
+               }
+               if (caller_profile->caller_id_number) {
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Caller-ID-Number", caller_profile->caller_id_number);
+               }
+               if (caller_profile->network_addr) {
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Network-Addr", caller_profile->network_addr);
+               }
+               if (caller_profile->ani) {
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-ANI", caller_profile->ani);
+               }
+               if (caller_profile->ani2) {
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-ANI2", caller_profile->ani2);
+               }
+               if (caller_profile->destination_number) {
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Destination-Number", caller_profile->destination_number);
+               }
+
+}
+
 SWITCH_DECLARE(switch_caller_extension *) switch_caller_extension_new(switch_core_session *session,
                                                                                                                                          char *extension_name,
                                                                                                                                          char *extension_number
@@ -117,3 +144,4 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session
 }
 
 
+
index d5603d929de149aaad864ce373e140c1ce5a6bc0..44d028719a2db2a495514aa87bf110cebe756090 100644 (file)
@@ -153,7 +153,7 @@ SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *d
 
        if (bytes && switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
                switch_channel_event_set_data(channel, event);
-               switch_event_add_header(event, "dtmf_string", dtmf);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-String", dtmf);
                switch_event_fire(&event);
        }
 
@@ -405,59 +405,21 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit
        caller_profile = switch_channel_get_caller_profile(channel);
        originator_caller_profile = switch_channel_get_originator_caller_profile(channel);
        
-       switch_event_add_header(event, "channel_state", (char *) switch_channel_state_name(channel->state));
-       switch_event_add_header(event, "channel_name", switch_channel_get_name(channel));
-       switch_event_add_header(event, "unique_id", switch_core_session_get_uuid(channel->session));
+       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", (char *) switch_channel_state_name(channel->state));
+       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel));
+       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
 
 
        /* Index Caller's Profile */    
        if (caller_profile) {
-               if (caller_profile->dialplan) {
-                       switch_event_add_header(event, "channel_dialplan", caller_profile->dialplan);
-               }
-               if (caller_profile->caller_id_name) {
-                       switch_event_add_header(event, "channel_caller_id_name", caller_profile->caller_id_name);
-               }
-               if (caller_profile->caller_id_number) {
-                       switch_event_add_header(event, "channel_caller_id_number", caller_profile->caller_id_number);
-               }
-               if (caller_profile->network_addr) {
-                       switch_event_add_header(event, "channel_network_addr", caller_profile->network_addr);
-               }
-               if (caller_profile->ani) {
-                       switch_event_add_header(event, "channel_ani", caller_profile->ani);
-               }
-               if (caller_profile->ani2) {
-                       switch_event_add_header(event, "channel_ani2", caller_profile->ani2);
-               }
-               if (caller_profile->destination_number) {
-                       switch_event_add_header(event, "channel_destination_number", caller_profile->destination_number);
-               }
+               switch_caller_profile_event_set_data(caller_profile, event);
        }
+       
        /* Index Originator's Profile */
        if (originator_caller_profile) {
-               if (originator_caller_profile->dialplan) {
-                       switch_event_add_header(event, "channel_dialplan", originator_caller_profile->dialplan);
-               }
-               if (originator_caller_profile->caller_id_name) {
-                       switch_event_add_header(event, "channel_caller_id_name", originator_caller_profile->caller_id_name);
-               }
-               if (originator_caller_profile->caller_id_number) {
-                       switch_event_add_header(event, "channel_caller_id_number", originator_caller_profile->caller_id_number);
-               }
-               if (originator_caller_profile->network_addr) {
-                       switch_event_add_header(event, "channel_network_addr", originator_caller_profile->network_addr);
-               }
-               if (originator_caller_profile->ani) {
-                       switch_event_add_header(event, "channel_ani", originator_caller_profile->ani);
-               }
-               if (originator_caller_profile->ani2) {
-                       switch_event_add_header(event, "channel_ani2", originator_caller_profile->ani2);
-               }
-               if (originator_caller_profile->destination_number) {
-                       switch_event_add_header(event, "channel_destination_number", originator_caller_profile->destination_number);
-               }
+               switch_caller_profile_event_set_data(originator_caller_profile, event);
        }
+
        /* Index Variables */
        for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi; hi = switch_hash_next(hi)) {
                char buf[1024];
@@ -465,7 +427,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit
                switch_hash_this(hi, &var, NULL, &val);
                subclass = val;
                snprintf(buf, sizeof(buf), "variable_%s", (char *) var);
-               switch_event_add_header(event, buf, (char *) val);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, buf, (char *) val);
        }
 
 
index be7d8560e503fbd05104f92993d117bdc9870a4a..96f5c28d5a94595504034eedddb34a15452c7e37 100644 (file)
@@ -87,19 +87,12 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi
        int ret = 0;
        va_list ap;
        FILE *handle;
-       char *filep = file, *p;
+       char *filep = switch_cut_path(file);
 
        va_start(ap, fmt);
 
        handle = switch_core_data_channel(channel);
 
-       while((p = strchr(filep, '/'))) {
-               filep = p + 1;
-       }
-       while((p = strchr(filep, '\\'))) {
-               filep = p + 1;
-       }
-
 #ifdef HAVE_VASPRINTF
        ret = vasprintf(&data, fmt, ap);
 #else
@@ -129,10 +122,10 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi
                                         switch_event_running() == SWITCH_STATUS_SUCCESS && 
                                         switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
                                
-                               switch_event_add_header(event, "log_data", "%s", data);
-                               switch_event_add_header(event, "log_file", "%s", filep);
-                               switch_event_add_header(event, "log_function", "%s", func);
-                               switch_event_add_header(event, "log_line", "%d", line);
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func);
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
                                switch_event_fire(&event);
                        }
                        free(data);
index 076007967f35c4408d105bcd2bf186805edb3f66..49ad19212c6841ccf2f9a700c648ee579b4fb183 100644 (file)
@@ -97,7 +97,6 @@ static char *EVENT_NAMES[] = {
        "ANSWER_CHAN",
        "HANGUP_CHAN",
        "STARTUP",
-       "EVENT_SHUTDOWN",
        "SHUTDOWN",
        "ALL"
 };
@@ -234,13 +233,6 @@ SWITCH_DECLARE(switch_status) switch_event_reserve_subclass_detailed(char *owner
 
 SWITCH_DECLARE(switch_status) switch_event_shutdown(void)
 {
-       switch_event *event;
-
-       if (switch_event_create(&event, SWITCH_EVENT_EVENT_SHUTDOWN) == SWITCH_STATUS_SUCCESS) {
-               switch_event_add_header(event, "event_info", "Event System Shutting Down");
-               switch_event_fire(&event);
-       }
-
        THREAD_RUNNING = -1;
 
        while(THREAD_RUNNING) {
@@ -327,7 +319,7 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header
        return NULL;
 }
 
-SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, char *header_name, char *fmt, ...)
+SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...)
 {
     int ret = 0;
        char data[2048];
@@ -351,15 +343,18 @@ SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, char
 
                header->name = DUP(header_name);
                header->value = DUP(data);
-
-               for (hp = event->headers; hp && hp->next; hp = hp->next);
-               
-               if (hp) {
-                       hp->next = header;
-               } else {
+               if (stack = SWITCH_STACK_TOP) {
+                       header->next = event->headers;
                        event->headers = header;
-               }
+               } else {
+                       for (hp = event->headers; hp && hp->next; hp = hp->next);
                
+                       if (hp) {
+                               hp->next = header;
+                       } else {
+                               event->headers = header;
+                       }
+               }
                return SWITCH_STATUS_SUCCESS;
 
        }
@@ -444,7 +439,7 @@ SWITCH_DECLARE(switch_status) switch_event_dup(switch_event **event, switch_even
 
 SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *buf, size_t buflen, char *fmt, ...)
 {
-       size_t len;
+       size_t len = 0;
        switch_event_header *hp;
     char *data = NULL, *body = NULL;
     int ret = 0;
@@ -464,12 +459,6 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
                }
        }
 
-       snprintf(buf, buflen, "event_name: %s\n", switch_event_name(event->event_id));
-       len = strlen(buf);
-       if (event->subclass) {
-               snprintf(buf+len, buflen-len, "subclass-name: %s\nowner: %s", event->subclass->name, event->subclass->owner);
-       }
-       len = strlen(buf);
        for (hp = event->headers; hp; hp = hp->next) {
                snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value);
                len = strlen(buf);
@@ -518,17 +507,21 @@ SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func,
        }
 
 
-       switch_rfc822_date(date, switch_time_now());
-       switch_event_add_header(*event, "event_date_gmt", date);
-
+       switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-Line-Number", "%d", line);
+       switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-Function", func);
+       switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-File", switch_cut_path(file));
        switch_time_exp_lt(&tm, switch_time_now());
        switch_strftime(date, &retsize, sizeof(date), "%a, %d-%b-%Y %X", &tm);
-       switch_event_add_header(*event, "event_date_local", date);
+       switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Date-Local", date);
+       switch_rfc822_date(date, switch_time_now());
+       switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Date-GMT", date);
+       if ((*event)->subclass) {
+               switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Subclass", (*event)->subclass->name);
+               switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Subclass-Owner", (*event)->subclass->owner);
+       }
+       switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Name", switch_event_name((*event)->event_id));
+
 
-       switch_event_add_header(*event, "event_file", file);
-       switch_event_add_header(*event, "event_function", func);
-       switch_event_add_header(*event, "event_line_number", "%d", line);
-       
        if (user_data) {
                (*event)->event_user_data = user_data;
        }
index 882d7936d219fa4c304cadfd4c450278b0525130..d35f1b0323bab8550988a9228560e046c46b7027 100644 (file)
@@ -422,10 +422,10 @@ SWITCH_DECLARE(switch_status) switch_api_execute(char *cmd, char *arg, char *ret
 
        if (switch_event_create(&event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
                if (cmd) {
-                       switch_event_add_header(event, "re_command", cmd);
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "API-Command", cmd);
                }
                if (arg) {
-                       switch_event_add_header(event, "re_command_arg", arg);
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "API-Command-Arguement", arg);
                }
                switch_event_add_body(event, retbuf);
                switch_event_fire(&event);
index 8a6d604abdd2f12e02682a2b7afa39190732189d..8260d3bc138ae53eb73f19f7a6f679f728d8e383 100644 (file)
  */
 #include <switch_utils.h>
 
+SWITCH_DECLARE(char *) switch_cut_path(char *in)\r
+{\r
+    char *p, *ret = in;\r
+    char delims[] = "/\\";\r
+    char *i;\r
+\r
+    for(i = delims; *i; i++) {\r
+        p = in;\r
+        while((p = strchr(p, *i))) {\r
+            ret = ++p;\r
+        }\r
+    }\r
+    return ret;\r
+}\r
+
+
 SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len)
 {
     int i;