diff --git a/src/include/switch_caller.h b/src/include/switch_caller.h index ce7e141170..a288f91a36 100644 --- a/src/include/switch_caller.h +++ b/src/include/switch_caller.h @@ -88,6 +88,9 @@ struct switch_caller_profile { char *context; /*! flags */ switch_caller_profile_flag_t flags; + struct switch_caller_profile *originator_caller_profile; + struct switch_caller_profile *originatee_caller_profile; + struct switch_channel_timetable *times; struct switch_caller_profile *next; }; diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index 3bcebfc47c..5a473493bf 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -46,6 +46,7 @@ struct switch_channel_timetable { switch_time_t created; switch_time_t answered; switch_time_t hungup; + switch_time_t transferred; struct switch_channel_timetable *next; }; @@ -428,9 +429,6 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw */ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel, char *in); -// These may go away -SWITCH_DECLARE(switch_status_t) switch_channel_set_raw_mode (switch_channel_t *channel, int freq, int bits, int channels, int ms, int kbps); -SWITCH_DECLARE(switch_status_t) switch_channel_get_raw_mode (switch_channel_t *channel, int *freq, int *bits, int *channels, int *ms, int *kbps); /** @} */ SWITCH_END_EXTERN_C diff --git a/src/mod/applications/mod_enum/mod_enum.c b/src/mod/applications/mod_enum/mod_enum.c index 9bf46a50a2..a954ba212f 100644 --- a/src/mod/applications/mod_enum/mod_enum.c +++ b/src/mod/applications/mod_enum/mod_enum.c @@ -570,7 +570,7 @@ static void enum_app_function(switch_core_session_t *session, char *data) char vbuf[1024] = ""; char *rbp = rbuf; switch_size_t l = 0, rbl = sizeof(rbuf); - uint32_t cnt = 0; + uint32_t cnt = 1; switch_channel_t *channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -583,10 +583,21 @@ static void enum_app_function(switch_core_session_t *session, char *data) dest = argv[0]; root = argv[1] ? argv[1] : globals.root; if (enum_lookup(root, data, &results) == SWITCH_STATUS_SUCCESS) { + switch_hash_index_t *hi; + void *vval; + const void *vvar; + + 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 && !strncmp(vvar, "enum_", 5)) { + switch_channel_set_variable(channel, (char *) vvar, NULL); + } + } + for(rtp = globals.route_order; rtp; rtp = rtp->next) { for(rp = results; rp; rp = rp->next) { if (!strcmp(rtp->service, rp->service)) { - snprintf(vbuf, sizeof(vbuf), "enum_route_%d", ++cnt); + snprintf(vbuf, sizeof(vbuf), "enum_route_%d", cnt++); switch_channel_set_variable(channel, vbuf, rp->route); snprintf(rbp, rbl, "%s|", rp->route); @@ -596,6 +607,8 @@ static void enum_app_function(switch_core_session_t *session, char *data) } } } + snprintf(vbuf, sizeof(vbuf), "%d", cnt); + switch_channel_set_variable(channel, "enum_route_count", vbuf); *(rbuf+strlen(rbuf)-1) = '\0'; switch_channel_set_variable(channel, "enum_auto_route", rbuf); free_results(&results); diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index c68d1f9c96..acb63c72bc 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -862,14 +862,14 @@ static JSBool session_recordfile(JSContext *cx, JSObject *obj, uintN argc, jsval } if (argc > 4) { - int32_t thresh; - JS_ValueToInt32(cx, argv[4], &(int32)thresh); + int32 thresh; + JS_ValueToInt32(cx, argv[4], &thresh); fh.thresh = thresh; } if (argc > 5) { - int32_t silence_hits; - JS_ValueToInt32(cx, argv[5], &(int32)silence_hits); + int32 silence_hits; + JS_ValueToInt32(cx, argv[5], &silence_hits); fh.silence_hits = silence_hits; } } diff --git a/src/switch_channel.c b/src/switch_channel.c index a340319288..7f523a3f6c 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -108,20 +108,12 @@ struct switch_channel { uint32_t flags; uint32_t state_flags; switch_caller_profile_t *caller_profile; - switch_caller_profile_t *originator_caller_profile; - switch_caller_profile_t *originatee_caller_profile; switch_caller_extension_t *caller_extension; const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS]; int state_handler_index; switch_hash_t *variables; switch_hash_t *private_hash; - switch_channel_timetable_t *times; switch_call_cause_t hangup_cause; - int freq; - int bits; - int channels; - int ms; - int kbps; }; @@ -160,8 +152,16 @@ SWITCH_DECLARE(switch_call_cause_t) switch_channel_get_cause(switch_channel_t *c SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(switch_channel_t *channel) { + switch_channel_timetable_t *times = NULL; + assert(channel != NULL); - return channel->times; + if (channel->caller_profile) { + switch_mutex_lock(channel->profile_mutex); + times = channel->caller_profile->times; + switch_mutex_unlock(channel->profile_mutex); + } + + return times; } SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel, switch_memory_pool_t *pool) @@ -184,46 +184,6 @@ SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel, return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status_t) switch_channel_set_raw_mode(switch_channel_t *channel, int freq, int bits, int channels, - int ms, int kbps) -{ - - assert(channel != NULL); - - channel->freq = freq; - channel->bits = bits; - channel->channels = channels; - channel->ms = ms; - channel->kbps = kbps; - - - return SWITCH_STATUS_SUCCESS; -} - -SWITCH_DECLARE(switch_status_t) switch_channel_get_raw_mode(switch_channel_t *channel, int *freq, int *bits, int *channels, - int *ms, int *kbps) -{ - if (freq) { - *freq = channel->freq; - } - if (bits) { - *bits = channel->bits; - } - if (channels) { - *channels = channel->channels; - } - if (ms) { - *ms = channel->ms; - } - if (kbps) { - *kbps = channel->kbps; - } - - return SWITCH_STATUS_SUCCESS; - -} - - SWITCH_DECLARE(switch_size_t) switch_channel_has_dtmf(switch_channel_t *channel) { switch_size_t has; @@ -306,7 +266,6 @@ SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel, channel->state = state; channel->flags = flags; channel->session = session; - switch_channel_set_raw_mode(channel, 8000, 16, 1, 20, 8); return SWITCH_STATUS_SUCCESS; } @@ -348,7 +307,7 @@ SWITCH_DECLARE(char *) switch_channel_get_variable(switch_channel_t *channel, ch assert(channel != NULL); if (!(v=switch_core_hash_find(channel->variables, varname))) { - if (!(v = switch_caller_get_field_by_name(channel->caller_profile, varname))) { + if (!channel->caller_profile || !(v = switch_caller_get_field_by_name(channel->caller_profile, varname))) { if (!strcmp(varname, "base_dir")) { return SWITCH_GLOBAL_dirs.base_dir; } @@ -710,16 +669,17 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, switch_event_t *event) { - switch_caller_profile_t *caller_profile, *originator_caller_profile, *originatee_caller_profile; + switch_caller_profile_t *caller_profile, *originator_caller_profile = NULL, *originatee_caller_profile = NULL; switch_hash_index_t *hi; switch_codec_t *codec; void *val; const void *var; char state_num[25]; - caller_profile = switch_channel_get_caller_profile(channel); - originator_caller_profile = switch_channel_get_originator_caller_profile(channel); - originatee_caller_profile = switch_channel_get_originatee_caller_profile(channel); + if ((caller_profile = switch_channel_get_caller_profile(channel))) { + originator_caller_profile = caller_profile->originator_caller_profile; + originatee_caller_profile = caller_profile->originatee_caller_profile; + } switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", (char *) switch_channel_state_name(channel->state)); snprintf(state_num, sizeof(state_num), "%d", channel->state); @@ -767,11 +727,10 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile) { - switch_channel_timetable_t *times; - assert(channel != NULL); assert(channel->session != NULL); switch_mutex_lock(channel->profile_mutex); + assert(caller_profile != NULL); if (!caller_profile->uuid) { caller_profile->uuid = switch_core_session_strdup(channel->session, switch_core_session_get_uuid(channel->session)); @@ -793,12 +752,14 @@ SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel switch_event_fire(&event); } } - - if ((times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*times)))) { - times->next = channel->times; - channel->times = times; - } - channel->times->created = switch_time_now(); + + caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*caller_profile->times)); + caller_profile->times->created = switch_time_now(); + + if (channel->caller_profile && channel->caller_profile->times) { + channel->caller_profile->times->transferred = switch_time_now(); + caller_profile->times->answered = channel->caller_profile->times->answered; + } caller_profile->next = channel->caller_profile; channel->caller_profile = caller_profile; @@ -822,30 +783,50 @@ SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel switch_caller_profile_t *caller_profile) { assert(channel != NULL); - switch_mutex_lock(channel->profile_mutex); - caller_profile->next = channel->originator_caller_profile; - channel->originator_caller_profile = caller_profile; - switch_mutex_unlock(channel->profile_mutex); + if (channel->caller_profile) { + switch_mutex_lock(channel->profile_mutex); + caller_profile->next = channel->caller_profile->originator_caller_profile; + channel->caller_profile->originator_caller_profile = caller_profile; + switch_mutex_unlock(channel->profile_mutex); + } } SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile) { assert(channel != NULL); - switch_mutex_lock(channel->profile_mutex); - caller_profile->next = channel->originatee_caller_profile; - channel->originatee_caller_profile = caller_profile; - switch_mutex_unlock(channel->profile_mutex); + if (channel->caller_profile) { + switch_mutex_lock(channel->profile_mutex); + caller_profile->next = channel->caller_profile->originatee_caller_profile; + channel->caller_profile->originatee_caller_profile = caller_profile; + switch_mutex_unlock(channel->profile_mutex); + } } SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originator_caller_profile(switch_channel_t *channel) { - switch_caller_profile_t *profile; + switch_caller_profile_t *profile = NULL; assert(channel != NULL); - switch_mutex_lock(channel->profile_mutex); - profile = channel->originator_caller_profile; - switch_mutex_unlock(channel->profile_mutex); + if (channel->caller_profile) { + switch_mutex_lock(channel->profile_mutex); + profile = channel->caller_profile->originator_caller_profile; + switch_mutex_unlock(channel->profile_mutex); + } + + return profile; +} + +SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originatee_caller_profile(switch_channel_t *channel) +{ + switch_caller_profile_t *profile = NULL; + assert(channel != NULL); + + if (channel->caller_profile) { + switch_mutex_lock(channel->profile_mutex); + profile = channel->caller_profile->originatee_caller_profile; + switch_mutex_unlock(channel->profile_mutex); + } return profile; } @@ -857,18 +838,6 @@ SWITCH_DECLARE(char *) switch_channel_get_uuid(switch_channel_t *channel) return switch_core_session_get_uuid(channel->session); } -SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originatee_caller_profile(switch_channel_t *channel) -{ - switch_caller_profile_t *profile; - assert(channel != NULL); - - switch_mutex_lock(channel->profile_mutex); - profile = channel->originatee_caller_profile; - switch_mutex_unlock(channel->profile_mutex); - - return profile; -} - SWITCH_DECLARE(int) switch_channel_add_state_handler(switch_channel_t *channel, const switch_state_handler_table_t *state_handler) { @@ -974,8 +943,10 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan assert(channel != NULL); switch_mutex_lock(channel->flag_mutex); - if (channel->times && !channel->times->hungup) { - channel->times->hungup = switch_time_now(); + if (channel->caller_profile && channel->caller_profile->times && !channel->caller_profile->times->hungup) { + switch_mutex_lock(channel->profile_mutex); + channel->caller_profile->times->hungup = switch_time_now(); + switch_mutex_unlock(channel->profile_mutex); } if (channel->state < CS_HANGUP) { @@ -1096,7 +1067,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t * if (switch_core_session_answer_channel(channel->session) == SWITCH_STATUS_SUCCESS) { switch_event_t *event; - channel->times->answered = switch_time_now(); + if (channel->caller_profile && channel->caller_profile->times) { + switch_mutex_lock(channel->profile_mutex); + channel->caller_profile->times->answered = switch_time_now(); + switch_mutex_unlock(channel->profile_mutex); + } + switch_channel_set_flag(channel, CF_ANSWERED); switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Answer %s!\n", channel->name); if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {