]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add timout to record and time tables to all the channel events
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 31 May 2007 14:42:23 +0000 (14:42 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 31 May 2007 14:42:23 +0000 (14:42 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5236 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/include/switch_ivr.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_playback/mod_playback.c
src/switch_caller.c
src/switch_core_io.c
src/switch_core_media_bug.c
src/switch_ivr_async.c

index 31561cd88274a48eea984266792a366ecbfe675e..c10f7d253c74c157ef6532e678a87b12f25219ac 100644 (file)
@@ -136,6 +136,7 @@ struct switch_media_bug {
        void *user_data;
        uint32_t flags;
        uint8_t ready;
+       time_t stop_time;
        struct switch_media_bug *next;
 };
 
index afd85294c2504aaf3ebeb8a91d8c9bdd2b0c07cd..97586a2d06ac9cf97e4d353459dc7bddf27672ee 100644 (file)
@@ -130,7 +130,7 @@ struct switch_core_port_allocator;
 */
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session,
                                                                                                                  switch_media_bug_callback_t callback,
-                                                                                                                 void *user_data, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug);
+                                                                                                                 void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug);
 /*!
   \brief Obtain private data from a media bug
   \param bug the bug to get the data from
index 632e450bd72538a6571b9a257513852baaf3b982..dac4da79ef7d660516cbe154207c6078173f95eb 100644 (file)
@@ -198,7 +198,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_c
   \param fh file handle to use (NULL for builtin one)
   \return SWITCH_STATUS_SUCCESS if all is well
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, switch_file_handle_t *fh);
+SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, uint32_t limit, switch_file_handle_t *fh);
 
 /*!
   \brief Stop Recording a session
index a90011a34e2178bdf63bad6e26ab70fb1c535dec..892473f52bb360e7faa24216f2ff93d0ae18032d 100644 (file)
@@ -550,6 +550,7 @@ SWITCH_STANDARD_API(session_record_function)
        char *mycmd = NULL, *argv[4] = { 0 };
        char *uuid = NULL, *action = NULL, *path = NULL;
        int argc = 0;
+       uint32_t limit = 0;
 
        if (session) {
                return SWITCH_STATUS_FALSE;
@@ -570,7 +571,8 @@ SWITCH_STANDARD_API(session_record_function)
        uuid = argv[0];
        action = argv[1];
        path = argv[2];
-
+       limit = argv[3] ? atoi(argv[3]) : 0;
+       
        if (!(rsession = switch_core_session_locate(uuid))) {
                stream->write_function(stream, "-Error Cannot locate session!\n");
                return SWITCH_STATUS_SUCCESS;
@@ -581,7 +583,7 @@ SWITCH_STANDARD_API(session_record_function)
        }
 
        if (!strcasecmp(action, "start")) {
-               switch_ivr_record_session(rsession, path, NULL);
+               switch_ivr_record_session(rsession, path, limit, NULL);
        } else if (!strcasecmp(action, "stop")) {
                switch_ivr_stop_record_session(rsession, path);
        } else {
@@ -1230,7 +1232,7 @@ static switch_api_interface_t session_record_api_interface = {
        /*.interface_name */ "session_record",
        /*.desc */ "session record",
        /*.function */ session_record_function,
-       /*.syntax */ "<uuid> [start|stop] <path>",
+       /*.syntax */ "<uuid> [start|stop] <path> [<limit>]",
        /*.next */ &broadcast_api_interface
 };
 
index 561474f14f6e7b41801de7e6fc7d363c6d66e356..5382114e960bb9ce17438508500ed7fb2824f19e 100644 (file)
@@ -142,6 +142,11 @@ static void record_function(switch_core_session_t *session, char *data)
 
        path = switch_core_session_strdup(session, data);
        if ((p = strchr(path, '+'))) {
+               char *q = p - 1;
+               while(q && *q == ' ') {
+                       *q = '\0';
+                       q--;
+               }
                *p++ = '\0';
                limit = atoi(p);
        }
@@ -158,10 +163,24 @@ static void record_function(switch_core_session_t *session, char *data)
 static void record_session_function(switch_core_session_t *session, char *data)
 {
        switch_channel_t *channel;
+       char *p, *path = NULL;
+       uint32_t limit = 0;
+
        channel = switch_core_session_get_channel(session);
        assert(channel != NULL);
 
-       switch_ivr_record_session(session, data, NULL);
+       path = switch_core_session_strdup(session, data);
+       if ((p = strchr(path, '+'))) {
+               char *q = p - 1;
+               while(q && *q == ' ') {
+                       *q = '\0';
+                       q--;
+               }
+               *p++ = '\0';
+               limit = atoi(p);
+       }
+       
+       switch_ivr_record_session(session, path, limit, NULL);
 }
 
 
index 3aab596fe89d9a816b6f3cf90b9358066f7aaa72..e1a0a6f1c930e6f95f90c48256211b1bcfebf972 100644 (file)
@@ -193,6 +193,16 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_
                snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix);
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->chan_name);
        }
+       if (caller_profile->times) {
+               snprintf(header_name, sizeof(header_name), "%s-Channel-Created-Time", prefix);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
+               snprintf(header_name, sizeof(header_name), "%s-Channel-Answered-Time", prefix);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
+               snprintf(header_name, sizeof(header_name), "%s-Channel-Hangup-Time", prefix);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
+               snprintf(header_name, sizeof(header_name), "%s-Channel-Transfer-Time", prefix);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred);
+       }
 
        snprintf(header_name, sizeof(header_name), "%s-Screen-Bit", prefix);
        switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_SCREEN) ? "yes" : "no");
@@ -203,7 +213,7 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_
        snprintf(header_name, sizeof(header_name), "%s-Privacy-Hide-Number", prefix);
        switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER) ? "yes" : "no");
 
-
+       
 
 }
 
index cecf6dea78716565561e6b1a650696e606f0565e..a8fa5155f4b2eb948785ae83f27cc7f2680dd6cd 100644 (file)
@@ -232,7 +232,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                                        switch_mutex_lock(bp->read_mutex);
                                        switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
                                        if (bp->callback) {
-                                               if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE) {
+                                               if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE || (bp->stop_time && bp->stop_time >= time(NULL))) {
                                                        bp->ready = 0;
                                                        if (last) {
                                                                last->next = bp->next;
@@ -505,6 +505,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                                        }
                                }
 
+                               if (bp->stop_time && bp->stop_time >= time(NULL)) {
+                                       ok = SWITCH_FALSE;
+                               }
+
+
                                if (ok == SWITCH_FALSE) {
                                        bp->ready = 0;
                                        if (last) {
index a81c5b7cb663154cd873dfbeeeb273169ebff100..b61557328000097b3031d13e934fb0f4adc1e3e4 100644 (file)
@@ -144,7 +144,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
 #define MAX_BUG_BUFFER 1024 * 512
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session,
                                                                                                                  switch_media_bug_callback_t callback,
-                                                                                                                 void *user_data, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug)
+                                                                                                                 void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug)
 {
        switch_media_bug_t *bug, *bp;
        switch_size_t bytes;
@@ -170,6 +170,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t
        bug->session = session;
        bug->flags = flags;
        bug->ready = 1;
+       bug->stop_time = stop_time;
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel));
        bytes = session->read_codec->implementation->bytes_per_frame;
 
index 5977b2cff2c0258472bfb731d0a32dbf822952db..5a4ee5a7ab13f19ce4322ea0c9db67c9da772987 100644 (file)
@@ -147,7 +147,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_record_session(switch_core_sessi
 
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, switch_file_handle_t *fh)
+SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, uint32_t limit, switch_file_handle_t *fh)
 {
        switch_channel_t *channel;
        switch_codec_t *read_codec;
@@ -155,6 +155,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
        const char *vval;
        switch_media_bug_t *bug;
        switch_status_t status;
+       time_t to = 0;
 
        if (!fh) {
                if (!(fh = switch_core_session_alloc(session, sizeof(*fh)))) {
@@ -220,9 +221,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
                switch_channel_set_variable(channel, "RECORD_DATE", NULL);
        }
 
+       if (limit) {
+               to = time(NULL) + limit;
+       }
 
-
-       if ((status = switch_core_media_bug_add(session, record_callback, fh, SMBF_BOTH, &bug)) != SWITCH_STATUS_SUCCESS) {
+       if ((status = switch_core_media_bug_add(session, record_callback, fh, to, SMBF_BOTH, &bug)) != SWITCH_STATUS_SUCCESS) {
                switch_core_file_close(fh);
                return status;
        }
@@ -312,7 +315,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_sessi
 
        switch_channel_answer(channel);
 
-       if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) {
+       if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) {
                return status;
        }
 
@@ -597,7 +600,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *
        sth->session = session;
        sth->ah = ah;
 
-       if ((status = switch_core_media_bug_add(session, speech_callback, sth, SMBF_READ_STREAM, &sth->bug)) != SWITCH_STATUS_SUCCESS) {
+       if ((status = switch_core_media_bug_add(session, speech_callback, sth, 0, SMBF_READ_STREAM, &sth->bug)) != SWITCH_STATUS_SUCCESS) {
                switch_core_asr_close(ah, &flags);
                switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
                return status;