]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add app log
authorAnthony Minessale <anthony.minessale@gmail.com>
Sat, 21 Apr 2007 01:03:58 +0000 (01:03 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Sat, 21 Apr 2007 01:03:58 +0000 (01:03 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4994 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/private/switch_core.h
src/include/switch_caller.h
src/include/switch_core.h
src/include/switch_types.h
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_core_session.c
src/switch_core_state_machine.c
src/switch_ivr.c
src/switch_ivr_menu.c
src/switch_ivr_originate.c

index 11ea9cb025d7ac33aa925917e44ac3fd30601804..162c5297aaa41972ea2f036ade232361557ffd1f 100644 (file)
@@ -126,6 +126,7 @@ struct switch_core_session {
        switch_queue_t *private_event_queue;
        switch_thread_rwlock_t *bug_rwlock;
        switch_media_bug_t *bugs;
+       switch_app_log_t *app_log;
 };
 
 struct switch_media_bug {
index b2e429ffb19cd6b791d506ceb2cfbdfb8dec2311..5401a15ce3e2d88b76bb59e3466f138290a5ff3b 100644 (file)
@@ -117,6 +117,7 @@ struct switch_caller_extension {
        switch_caller_application_t *last_application;
        /*! Pointer to the entire stack of applications for this extension */
        switch_caller_application_t *applications;
+       struct switch_caller_profile *children;
        struct switch_caller_extension *next;
 };
 
index 2c6603568cc53e5bb454552198d32c6bc529bab3..bb3cedaedf090a2f15e3e8917270afa048515f6d 100644 (file)
@@ -43,7 +43,7 @@
 SWITCH_BEGIN_EXTERN_C
 #define SWITCH_MAX_CORE_THREAD_SESSION_OBJS 128
 #define SWITCH_MAX_STREAMS 128
-       struct switch_core_time_duration {
+struct switch_core_time_duration {
        uint32_t mms;
        uint32_t ms;
        uint32_t sec;
@@ -53,6 +53,12 @@ SWITCH_BEGIN_EXTERN_C
        uint32_t yr;
 };
 
+struct switch_app_log {
+       char *app;
+       char *arg;
+       struct switch_app_log *next;
+};
+
 /*! \brief A message object designed to allow unlike technologies to exchange data */
 struct switch_core_session_message {
        /*! uuid of the sender (for replies) */
@@ -565,6 +571,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_flush_message(switch_core_se
 */
 SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(char *uuid_str, switch_event_t **event);
 
+SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(switch_core_session_t *session);
+SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *session,
+                                                                                                                const switch_application_interface_t *application_interface, char *arg);
 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_session_t *session, char *exten, char *dialplan, char *context);
 
 /*! 
index 19aa2867bd27cbd65e0b652b0b26b53854c051f1..0f5669ca56e7a0d472426bc66701ab469dd1006e 100644 (file)
@@ -954,6 +954,7 @@ typedef enum {
 
 typedef uint16_t switch_port_t;
 typedef uint8_t switch_payload_t;
+typedef struct switch_app_log switch_app_log_t;
 typedef struct switch_rtp switch_rtp_t;
 typedef struct switch_core_session_message switch_core_session_message_t;
 typedef struct switch_event_header switch_event_header_t;
index 7b0cd0301c2752c006b5d3a87d8f3f1702a4e5cc..a9cc48d6109ee2b678e561812af1f053949e8bfc 100644 (file)
@@ -1615,7 +1615,7 @@ static JSBool session_execute(JSContext * cx, JSObject * obj, uintN argc, jsval
                if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
                        if (application_interface->application_function) {
                                saveDepth = JS_SuspendRequest(cx);
-                               application_interface->application_function(jss->session, app_arg);
+                               switch_core_session_exec(jss->session, application_interface, app_arg);
                                JS_ResumeRequest(cx, saveDepth);
                                retval = JS_TRUE;
                        }
index 74982016d6e5c7f51b13e533746bc44c7a3e2de7..43226eedc83127ff81bce16a54ad3c83a85c7a51 100644 (file)
@@ -873,19 +873,48 @@ void switch_core_session_init(switch_memory_pool_t *pool)
 }
 
 
+SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(switch_core_session_t *session)
+{
+       return session->app_log;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *session,
+                                                                                                                const switch_application_interface_t *application_interface, char *arg) {
+       switch_app_log_t *log, *lp;
+       
+       log = switch_core_session_alloc(session, sizeof(*log));
+
+       assert(log != NULL);
+
+       log->app = switch_core_session_strdup(session, application_interface->interface_name);
+       log->arg = switch_core_session_strdup(session, arg);
+
+       for(lp = session->app_log; lp && lp->next; lp = lp->next);
+
+       if (lp) {
+               lp->next = log;
+       } else {
+               session->app_log = log;
+       }
+       
+       application_interface->application_function(session, arg);
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_session_t *session, char *exten, char *dialplan, char *context)
 {
        char *dp[25];
        char *dpstr;
        int argc, x, count = 0;
        char *expanded = NULL;
-       switch_caller_profile_t *profile, *new_profile;
+       switch_caller_profile_t *profile, *new_profile, *pp;
        switch_channel_t *channel;
        switch_dialplan_interface_t *dialplan_interface = NULL;
        switch_caller_extension_t *extension = NULL;
        const switch_application_interface_t *application_interface;
        switch_event_t *event;
-
+       
        channel = switch_core_session_get_channel(session);
        
        if (!(profile = switch_channel_get_caller_profile(channel))) {
@@ -922,7 +951,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
                }
                        
                count++;
-                       
+               
                if ((extension = dialplan_interface->hunt_function(session, dparg, new_profile)) != 0) {
                        break;
                }
@@ -932,6 +961,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
                return SWITCH_STATUS_FALSE;
        }
 
+       new_profile->caller_extension = extension;
+
+       for(pp = profile->caller_extension->children; pp && pp->next; pp = pp->next);
+
+       if (pp) {
+               pp->next = new_profile;
+       } else {
+               profile->caller_extension->children = new_profile;
+       }
+
        while (switch_channel_ready(channel) && extension->current_application) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Execute %s(%s)\n",
                                                  extension->current_application->application_name, switch_str_nil(extension->current_application->application_data));
@@ -975,7 +1014,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
                        }
                }
 
-               application_interface->application_function(session, expanded);
+               switch_core_session_exec(session, application_interface, expanded);
 
                if (expanded != extension->current_application->application_data) {
                        switch_safe_free(expanded);
index 5b0850ce8964b4a3fdc1ab9ee8e5ae0a5698fb3c..4ce4d64198c5a43a39742be6dedeced8dda01a7c 100644 (file)
@@ -165,8 +165,8 @@ static void switch_core_standard_on_execute(switch_core_session_t *session)
                                switch_safe_free(arg);
                        }
                }
-
-               application_interface->application_function(session, expanded);
+               switch_core_session_exec(session, application_interface, expanded);
+               //application_interface->application_function(session, expanded);
 
                if (expanded != extension->current_application->application_data) {
                        switch_safe_free(expanded);
index 5566f55c9790a2fcda1afe52debb4731929d9e04..bccbc7f540183c488ff64b4fd816f6559c9fdd86 100644 (file)
@@ -303,7 +303,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
                                        int x;
                                        switch_channel_set_flag(channel, CF_BROADCAST);
                                        for (x = 0; x < loops || loops < 0; x++) {
-                                               application_interface->application_function(session, app_arg);
+                                               switch_core_session_exec(session, application_interface, app_arg);
                                                if (!switch_channel_test_flag(channel, CF_BROADCAST)) {
                                                        break;
                                                }
@@ -1224,7 +1224,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
        switch_hash_index_t *hi;
        void *vval;
        const void *vvar;
-       switch_xml_t variable, variables, cdr, x_caller_profile, x_caller_extension, x_times, time_tag, x_application, x_callflow;
+       switch_xml_t variable, variables, cdr, x_caller_profile, x_caller_extension, x_times, time_tag, 
+               x_application, x_callflow, x_inner_extension, x_apps;
+       switch_app_log_t *app_log;
+       
        char tmp[512];
        int cdr_off = 0, v_off = 0;
 
@@ -1239,6 +1242,24 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
                goto error;
        }
 
+       if ((app_log = switch_core_session_get_app_log(session))) {
+               int app_off = 0;
+               switch_app_log_t *ap;
+               
+               if (!(x_apps = switch_xml_add_child_d(cdr, "app_log", cdr_off++))) {
+                       goto error;
+               }
+               for(ap = app_log; ap; ap = ap->next) {
+
+                       if (!(x_application = switch_xml_add_child_d(x_apps, "application", app_off++))) {
+                               goto error;
+                       }
+                       
+                       switch_xml_set_attr_d(x_application, "app_name", ap->app);
+                       switch_xml_set_attr_d(x_application, "app_data", ap->arg);
+               }
+       }
+
        for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
                switch_hash_this(hi, &vvar, NULL, &vval);
                if (vvar && vval) {
@@ -1263,6 +1284,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
                if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) {
                        goto error;
                }
+               switch_xml_set_attr_d(x_callflow, "dialplan", caller_profile->dialplan);
 
                if (caller_profile->caller_extension) {
                        switch_caller_application_t *ap;
@@ -1287,8 +1309,47 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
                                switch_xml_set_attr_d(x_application, "app_name", ap->application_name);
                                switch_xml_set_attr_d(x_application, "app_data", ap->application_data);
                        }
+
+                       if (caller_profile->caller_extension->children) {
+                               switch_caller_profile_t *cp = NULL;
+                               int i_off = 0;
+                               for (cp = caller_profile->caller_extension->children; cp; cp = cp->next) {
+                                       switch_caller_application_t *ap;
+                                       int app_off = 0;
+                                       
+                                       if (!cp->caller_extension) {
+                                               continue;
+                                       }
+                                       if (!(x_inner_extension = switch_xml_add_child_d(x_caller_extension, "sub_extensions", i_off++))) {
+                                               goto error;
+                                       }                               
+
+                                       if (!(x_caller_extension = switch_xml_add_child_d(x_inner_extension, "extension", cf_off++))) {
+                                               goto error;
+                                       }
+                                       switch_xml_set_attr_d(x_caller_extension, "name", cp->caller_extension->extension_name);
+                                       switch_xml_set_attr_d(x_caller_extension, "number", cp->caller_extension->extension_number);
+                                       switch_xml_set_attr_d(x_caller_extension, "dialplan", cp->dialplan);
+                                       if (cp->caller_extension->current_application) {
+                                               switch_xml_set_attr_d(x_caller_extension, "current_app", cp->caller_extension->current_application->application_name);
+                                       }
+                               
+                                       for (ap = cp->caller_extension->applications; ap; ap = ap->next) {
+                                               if (!(x_application = switch_xml_add_child_d(x_caller_extension, "application", app_off++))) {
+                                                       goto error;
+                                               }
+                                               if (ap == cp->caller_extension->current_application) {
+                                                       switch_xml_set_attr_d(x_application, "last_executed", "true");
+                                               }
+                                               switch_xml_set_attr_d(x_application, "app_name", ap->application_name);
+                                               switch_xml_set_attr_d(x_application, "app_data", ap->application_data);
+                                       }
+                               }
+                       }
+
                }
 
+
                if (!(x_caller_profile = switch_xml_add_child_d(x_callflow, "caller_profile", cf_off++))) {
                        goto error;
                }
@@ -1342,6 +1403,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
                caller_profile = caller_profile->next;
        }
 
+
+
+
        *xml_cdr = cdr;
 
        return SWITCH_STATUS_SUCCESS;
index 7fd215525d36d22d896f7ce9ea7fe2e0c7e2df69..28f69c016cdc2d2b3cddf24aeb8a1664b1b257f0 100644 (file)
@@ -397,7 +397,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s
                                                                if (app_name && app_arg) {
                                                                        if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
                                                                                if (application_interface->application_function) {
-                                                                                       application_interface->application_function(session, app_arg);
+                                                                                       switch_core_session_exec(session, application_interface, app_arg);
                                                                                }
                                                                        }
                                                                }
index 6395a9fecfd80b0302197655041c61e9f9562591..f24e91e0f30f22fcd2b423e71fa0de550938f9ac 100644 (file)
@@ -107,7 +107,8 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t * thread, voi
                        goto wbreak;
                }
 
-               application_interface->application_function(collect->session, app_data);
+               switch_core_session_exec(collect->session, application_interface, app_data);
+               
                if (switch_channel_get_state(channel) < CS_HANGUP) {
                        switch_channel_set_flag(channel, CF_WINNER);
                }