Author: anthm Date: Mon May 19 17:02:26 2008 New Revision: 8475 Modified: freeswitch/trunk/src/include/switch_core_event_hook.h freeswitch/trunk/src/include/switch_ivr.h freeswitch/trunk/src/include/switch_types.h freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c freeswitch/trunk/src/switch_core_io.c freeswitch/trunk/src/switch_ivr_async.c freeswitch/trunk/src/switch_ivr_originate.c Log: following the att_xfer can o worms deeper Modified: freeswitch/trunk/src/include/switch_core_event_hook.h ============================================================================== --- freeswitch/trunk/src/include/switch_core_event_hook.h (original) +++ freeswitch/trunk/src/include/switch_core_event_hook.h Mon May 19 17:02:26 2008 @@ -56,8 +56,8 @@ typedef switch_status_t (*switch_write_frame_hook_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int); typedef switch_status_t (*switch_video_write_frame_hook_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int); typedef switch_status_t (*switch_kill_channel_hook_t) (switch_core_session_t *, int); -typedef switch_status_t (*switch_send_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *); -typedef switch_status_t (*switch_recv_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *); +typedef switch_status_t (*switch_send_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction); +typedef switch_status_t (*switch_recv_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction); typedef switch_status_t (*switch_state_change_hook_t) (switch_core_session_t *); typedef switch_call_cause_t (*switch_resurrect_session_hook_t)(switch_core_session_t **, switch_memory_pool_t **, void *); Modified: freeswitch/trunk/src/include/switch_ivr.h ============================================================================== --- freeswitch/trunk/src/include/switch_ivr.h (original) +++ freeswitch/trunk/src/include/switch_ivr.h Mon May 19 17:02:26 2008 @@ -753,7 +753,7 @@ const char *valid_terminators); SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, - switch_bool_t dial_b, switch_bool_t exec_b, const char *app); + switch_bind_flag_t bind_flags, const char *app); SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session); SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *session, const char *unhold_key, const char *moh_a, const char *moh_b); SWITCH_DECLARE(switch_status_t) switch_ivr_say(switch_core_session_t *session, const char *tosay, const char *module_name, const char *say_type, const char *say_method, switch_input_args_t *args); Modified: freeswitch/trunk/src/include/switch_types.h ============================================================================== --- freeswitch/trunk/src/include/switch_types.h (original) +++ freeswitch/trunk/src/include/switch_types.h Mon May 19 17:02:26 2008 @@ -151,6 +151,20 @@ } switch_dtmf_t; typedef enum { + SBF_DIAL_ALEG = (1 << 0), + SBF_EXEC_ALEG = (1 << 1), + SBF_DIAL_BLEG = (1 << 2), + SBF_EXEC_BLEG = (1 << 3), + SBF_EXEC_OPPOSITE = (1 << 4), + SBF_EXEC_SAME = (1 << 5) +} switch_bind_flag_t; + +typedef enum { + SWITCH_DTMF_RECV, + SWITCH_DTMF_SEND +} switch_dtmf_direction_t; + +typedef enum { SOF_NONE = 0, SOF_NOBLOCK = (1 << 0), SOF_FORKED_DIAL = (1 << 1) Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (original) +++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c Mon May 19 17:02:26 2008 @@ -160,7 +160,7 @@ } } -#define BIND_SYNTAX "<key> [a|b] [a|b] <app>" +#define BIND_SYNTAX "<key> [a|b|ab] [a|b|o|s] <app>" SWITCH_STANDARD_APP(dtmf_bind_function) { char *argv[4] = { 0 }; @@ -170,10 +170,46 @@ if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) { int kval = atoi(argv[0]); - char a1 = (char)tolower(*argv[1]); - char a2 = (char)tolower(*argv[2]); - - if (switch_ivr_bind_dtmf_meta_session(session, kval, a1 == 'b', a2 == 'b', argv[3]) != SWITCH_STATUS_SUCCESS) { + switch_bind_flag_t bind_flags = 0; + + if (strchr(argv[1], 'a')) { + bind_flags |= SBF_DIAL_ALEG; + } + if (strchr(argv[1], 'b')) { + bind_flags |= SBF_DIAL_BLEG; + } + if (strchr(argv[2], 'a')) { + if ((bind_flags & SBF_EXEC_BLEG)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind execute to multiple legs\n"); + } else { + bind_flags |= SBF_EXEC_ALEG; + } + } + if (strchr(argv[2], 'b')) { + if ((bind_flags & SBF_EXEC_ALEG)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind execute to multiple legs\n"); + } else { + bind_flags |= SBF_EXEC_BLEG; + } + } + + if (strchr(argv[2], 'o')) { + if ((bind_flags & SBF_EXEC_BLEG) || (bind_flags & SBF_EXEC_ALEG) || (bind_flags & SBF_EXEC_SAME)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind execute to multiple legs\n"); + } else { + bind_flags |= SBF_EXEC_OPPOSITE; + } + } + + if (strchr(argv[2], 's')) { + if ((bind_flags & SBF_EXEC_BLEG) || (bind_flags & SBF_EXEC_ALEG) || (bind_flags & SBF_EXEC_SAME)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind execute to multiple legs\n"); + } else { + bind_flags |= SBF_EXEC_SAME; + } + } + + if (switch_ivr_bind_dtmf_meta_session(session, kval, bind_flags, argv[3]) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bind Error!\n"); } } else { @@ -1381,6 +1417,8 @@ switch_channel_t *channel, *peer_channel = NULL; const char *bond = NULL; int timelimit = 60; + switch_core_session_t *b_session = NULL; + channel = switch_core_session_get_channel(session); @@ -1396,7 +1434,7 @@ } if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) { - return; + goto end; } peer_channel = switch_core_session_get_channel(peer_session); @@ -1404,12 +1442,16 @@ switch_channel_set_flag(channel, CF_INNER_BRIDGE); switch_ivr_multi_threaded_bridge(session, peer_session, xfer_on_dtmf, peer_session, NULL); - + switch_channel_clear_flag(peer_channel, CF_INNER_BRIDGE); switch_channel_clear_flag(channel, CF_INNER_BRIDGE); + if (!switch_channel_get_state(peer_channel) >= CS_HANGUP) { + switch_core_session_rwunlock(peer_session); + goto end; + } + if (bond) { - switch_core_session_t *b_session; char buf[128] = ""; if (!switch_channel_ready(channel)) { @@ -1431,12 +1473,13 @@ switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, bond); } + end: + if (peer_session) { switch_core_session_rwunlock(peer_session); } switch_channel_set_variable(channel, SWITCH_HOLDING_UUID_VARIABLE, NULL); - } Modified: freeswitch/trunk/src/switch_core_io.c ============================================================================== --- freeswitch/trunk/src/switch_core_io.c (original) +++ freeswitch/trunk/src/switch_core_io.c Mon May 19 17:02:26 2008 @@ -962,7 +962,7 @@ } for (ptr = session->event_hooks.recv_dtmf; ptr; ptr = ptr->next) { - if ((status = ptr->recv_dtmf(session, &new_dtmf)) != SWITCH_STATUS_SUCCESS) { + if ((status = ptr->recv_dtmf(session, &new_dtmf, SWITCH_DTMF_RECV)) != SWITCH_STATUS_SUCCESS) { return status; } } @@ -993,7 +993,7 @@ for (ptr = session->event_hooks.send_dtmf; ptr; ptr = ptr->next) { - if ((status = ptr->send_dtmf(session, dtmf)) != SWITCH_STATUS_SUCCESS) { + if ((status = ptr->send_dtmf(session, dtmf, SWITCH_DTMF_SEND)) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_SUCCESS; } } Modified: freeswitch/trunk/src/switch_ivr_async.c ============================================================================== --- freeswitch/trunk/src/switch_ivr_async.c (original) +++ freeswitch/trunk/src/switch_ivr_async.c Mon May 19 17:02:26 2008 @@ -928,7 +928,7 @@ return 0; } -static switch_status_t generate_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) +static switch_status_t generate_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_media_bug_t *bug = switch_channel_get_private(channel, "dtmf_generate"); @@ -1298,17 +1298,23 @@ typedef struct { const char *app; uint32_t flags; + switch_bind_flag_t bind_flags; } dtmf_meta_app_t; typedef struct { dtmf_meta_app_t map[10]; time_t last_digit; - switch_bool_t meta_on; + switch_bool_t meta_on; + int up; +} dtmf_meta_settings_t; + +typedef struct { + dtmf_meta_settings_t sr[2]; } dtmf_meta_data_t; #define SWITCH_META_VAR_KEY "__dtmf_meta" -static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) +static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction) { switch_channel_t *channel = switch_core_session_get_channel(session); dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY); @@ -1320,39 +1326,77 @@ return SWITCH_STATUS_SUCCESS; } - if (md->meta_on && now - md->last_digit > 5) { - md->meta_on = SWITCH_FALSE; + if (direction == SWITCH_DTMF_RECV && !md->sr[SWITCH_DTMF_RECV].up) { + return SWITCH_STATUS_SUCCESS; + } + + if (direction == SWITCH_DTMF_SEND && !md->sr[SWITCH_DTMF_SEND].up) { + return SWITCH_STATUS_SUCCESS; + } + + if (md->sr[direction].meta_on && now - md->sr[direction].last_digit > 5) { + md->sr[direction].meta_on = SWITCH_FALSE; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Meta digit timeout parsing %c\n", switch_channel_get_name(channel), dtmf->digit); return SWITCH_STATUS_SUCCESS; } - md->last_digit = now; + md->sr[direction].last_digit = now; if (dtmf->digit == '*') { - if (md->meta_on) { - md->meta_on = SWITCH_FALSE; + if (md->sr[direction].meta_on) { + md->sr[direction].meta_on = SWITCH_FALSE; return SWITCH_STATUS_SUCCESS; } else { - md->meta_on = SWITCH_TRUE; + md->sr[direction].meta_on = SWITCH_TRUE; return SWITCH_STATUS_FALSE; } } - if (md->meta_on) { + if (md->sr[direction].meta_on) { if (dtmf->digit >= '0' && dtmf->digit <= '9') { *digit = dtmf->digit; dval = atoi(digit); - if (md->map[dval].app) { + int ok = 0; + + if (direction == SWITCH_DTMF_RECV && (md->sr[direction].map[dval].bind_flags & SBF_DIAL_ALEG)) { + ok = 1; + } else if (direction == SWITCH_DTMF_SEND && (md->sr[direction].map[dval].bind_flags & SBF_DIAL_BLEG)) { + ok = 1; + } + + if (ok && md->sr[direction].map[dval].app) { + uint32_t flags = md->sr[direction].map[dval].flags; + + if ((md->sr[direction].map[dval].bind_flags & SBF_EXEC_OPPOSITE)) { + if (direction == SWITCH_DTMF_SEND) { + flags |= SMF_ECHO_ALEG; + } else { + flags |= SMF_ECHO_BLEG; + } + } else if ((md->sr[direction].map[dval].bind_flags & SBF_EXEC_SAME)) { + if (direction == SWITCH_DTMF_SEND) { + flags |= SMF_ECHO_BLEG; + } else { + flags |= SMF_ECHO_ALEG; + } + } else if ((md->sr[direction].map[dval].bind_flags & SBF_EXEC_ALEG)) { + flags |= SMF_ECHO_ALEG; + } else if ((md->sr[direction].map[dval].bind_flags & SBF_EXEC_BLEG)) { + flags |= SMF_ECHO_BLEG; + } else { + flags |= SMF_ECHO_ALEG; + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Processing meta digit '%c' [%s]\n", - switch_channel_get_name(channel), dtmf->digit, md->map[dval].app); - switch_ivr_broadcast(switch_core_session_get_uuid(session), md->map[dval].app, md->map[dval].flags); + switch_channel_get_name(channel), dtmf->digit, md->sr[direction].map[dval].app); + switch_ivr_broadcast(switch_core_session_get_uuid(session), md->sr[direction].map[dval].app, flags); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Ignoring meta digit '%c' not mapped\n", switch_channel_get_name(channel), dtmf->digit); } } - md->meta_on = SWITCH_FALSE; + md->sr[direction].meta_on = SWITCH_FALSE; return SWITCH_STATUS_FALSE; } @@ -1368,7 +1412,7 @@ } SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, - switch_bool_t dial_b, switch_bool_t exec_b, const char *app) + switch_bind_flag_t bind_flags, const char *app) { switch_channel_t *channel = switch_core_session_get_channel(session); dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY); @@ -1377,25 +1421,39 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid key %u\n", key); return SWITCH_STATUS_FALSE; } - + if (!md) { md = switch_core_session_alloc(session, sizeof(*md)); switch_channel_set_private(channel, SWITCH_META_VAR_KEY, md); - if (dial_b) { - switch_core_event_hook_add_send_dtmf(session, meta_on_dtmf); - } else { - switch_core_event_hook_add_recv_dtmf(session, meta_on_dtmf); - } + switch_core_event_hook_add_send_dtmf(session, meta_on_dtmf); + switch_core_event_hook_add_recv_dtmf(session, meta_on_dtmf); } if (!switch_strlen_zero(app)) { - md->map[key].app = switch_core_session_strdup(session, app); - md->map[key].flags = exec_b ? SMF_ECHO_BLEG : SMF_ECHO_ALEG; - md->map[key].flags |= SMF_HOLD_BLEG; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound: %d %s\n", key, app); + if ((bind_flags & SBF_DIAL_ALEG)) { + md->sr[SWITCH_DTMF_RECV].up = 1; + md->sr[SWITCH_DTMF_RECV].map[key].app = switch_core_session_strdup(session, app); + md->sr[SWITCH_DTMF_RECV].map[key].flags |= SMF_HOLD_BLEG; + md->sr[SWITCH_DTMF_RECV].map[key].bind_flags = bind_flags; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound A-Leg: %d %s\n", key, app); + } + if ((bind_flags & SBF_DIAL_BLEG)) { + md->sr[SWITCH_DTMF_SEND].up = 1; + md->sr[SWITCH_DTMF_SEND].map[key].app = switch_core_session_strdup(session, app); + md->sr[SWITCH_DTMF_SEND].map[key].flags |= SMF_HOLD_BLEG; + md->sr[SWITCH_DTMF_SEND].map[key].bind_flags = bind_flags; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound B-Leg: %d %s\n", key, app); + } + } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "UnBound: %d\n", key); - md->map[key].app = NULL; + if ((bind_flags & SBF_DIAL_ALEG)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "UnBound A-Leg: %d\n", key); + md->sr[SWITCH_DTMF_SEND].map[key].app = NULL; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "UnBound: B-Leg %d\n", key); + md->sr[SWITCH_DTMF_SEND].map[key].app = NULL; + } } return SWITCH_STATUS_SUCCESS; Modified: freeswitch/trunk/src/switch_ivr_originate.c ============================================================================== --- freeswitch/trunk/src/switch_ivr_originate.c (original) +++ freeswitch/trunk/src/switch_ivr_originate.c Mon May 19 17:02:26 2008 @@ -1154,16 +1154,17 @@ } } } - - if (caller_channel && i == 0) { - holding = switch_channel_get_variable(caller_channel, SWITCH_HOLDING_UUID_VARIABLE); - holding = switch_core_session_strdup(session, holding); - switch_channel_set_variable(caller_channel, SWITCH_HOLDING_UUID_VARIABLE, NULL); - } - if (holding) { - switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(peer_sessions[i])); - } else { - switch_channel_hangup(peer_channels[i], reason); + if (switch_channel_ready(peer_channels[i])) { + if (caller_channel && i == 0) { + holding = switch_channel_get_variable(caller_channel, SWITCH_HOLDING_UUID_VARIABLE); + holding = switch_core_session_strdup(session, holding); + switch_channel_set_variable(caller_channel, SWITCH_HOLDING_UUID_VARIABLE, NULL); + } + if (holding) { + switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(peer_sessions[i])); + } else { + switch_channel_hangup(peer_channels[i], reason); + } } } }