1
0
mirror of https://github.com/signalwire/freeswitch.git synced 2025-04-01 02:52:32 +00:00

fix auto unpark

This commit is contained in:
Anthony Minessale 2011-10-19 14:19:36 -05:00
parent bd9317f254
commit 9bf000b585

@ -164,7 +164,11 @@ static valet_token_t *next_id(switch_core_session_t *session, valet_lot_t *lot,
switch_snprintf(buf, sizeof(buf), "%d", i); switch_snprintf(buf, sizeof(buf), "%d", i);
token = (valet_token_t *) switch_core_hash_find(lot->hash, buf); token = (valet_token_t *) switch_core_hash_find(lot->hash, buf);
if ((in && !token) || (!in && token && !token->timeout)) { if ((!in && token && !token->timeout)) {
goto end;
}
if (in && !token) {
r = i; r = i;
break; break;
} }
@ -180,6 +184,8 @@ static valet_token_t *next_id(switch_core_session_t *session, valet_lot_t *lot,
switch_core_hash_insert(lot->hash, buf, token); switch_core_hash_insert(lot->hash, buf, token);
} }
end:
switch_mutex_unlock(globals.mutex); switch_mutex_unlock(globals.mutex);
return token; return token;
@ -340,6 +346,7 @@ SWITCH_STANDARD_APP(valet_parking_function)
switch_input_args_t args = { 0 }; switch_input_args_t args = { 0 };
char dbuf[10]; char dbuf[10];
char *dest; char *dest;
int in = -1;
lot = valet_find_lot(lot_name); lot = valet_find_lot(lot_name);
switch_assert(lot); switch_assert(lot);
@ -348,7 +355,7 @@ SWITCH_STANDARD_APP(valet_parking_function)
const char *io = argv[2]; const char *io = argv[2];
const char *min = argv[3]; const char *min = argv[3];
const char *max = argv[4]; const char *max = argv[4];
int min_i, max_i, in = -1; int min_i, max_i;
if (argc < 5) { if (argc < 5) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", VALET_APP_SYNTAX); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", VALET_APP_SYNTAX);
@ -366,7 +373,6 @@ SWITCH_STANDARD_APP(valet_parking_function)
if (in < 0) { if (in < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", VALET_APP_SYNTAX); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", VALET_APP_SYNTAX);
switch_mutex_unlock(lot->mutex);
return; return;
} }
@ -375,12 +381,12 @@ SWITCH_STANDARD_APP(valet_parking_function)
if (!(token = next_id(session, lot, min_i, max_i, in))) { if (!(token = next_id(session, lot, min_i, max_i, in))) {
switch_ivr_phrase_macro(session, in ? "valet_lot_full" : "valet_lot_empty", "", NULL, NULL); switch_ivr_phrase_macro(session, in ? "valet_lot_full" : "valet_lot_empty", "", NULL, NULL);
switch_mutex_unlock(lot->mutex);
return; return;
} }
switch_snprintf(dtmf_buf, sizeof(dtmf_buf), "%s", token->ext); switch_snprintf(dtmf_buf, sizeof(dtmf_buf), "%s", token->ext);
ext = dtmf_buf; ext = dtmf_buf;
} else if (!strcasecmp(ext, "ask")) { } else if (!strcasecmp(ext, "ask")) {
const char *prompt = "ivr/ivr-enter_ext_pound.wav"; const char *prompt = "ivr/ivr-enter_ext_pound.wav";
int min = 1; int min = 1;
@ -425,11 +431,15 @@ SWITCH_STANDARD_APP(valet_parking_function)
} }
} }
if (!token) { if (!token || !in) {
if (!token) {
switch_mutex_lock(lot->mutex); switch_mutex_lock(lot->mutex);
if ((token = (valet_token_t *) switch_core_hash_find(lot->hash, ext))) { token = (valet_token_t *) switch_core_hash_find(lot->hash, ext);
switch_mutex_unlock(lot->mutex);
}
if (token) {
switch_core_session_t *b_session; switch_core_session_t *b_session;
if (token->timeout) { if (token->timeout) {
@ -461,7 +471,6 @@ SWITCH_STANDARD_APP(valet_parking_function)
token->bridged = 1; token->bridged = 1;
switch_ivr_uuid_bridge(switch_core_session_get_uuid(session), token->uuid); switch_ivr_uuid_bridge(switch_core_session_get_uuid(session), token->uuid);
switch_mutex_unlock(lot->mutex);
return; return;
} }
} }
@ -505,7 +514,6 @@ SWITCH_STANDARD_APP(valet_parking_function)
switch_ivr_phrase_macro(session, "valet_announce_ext", tmp, NULL, NULL); switch_ivr_phrase_macro(session, "valet_announce_ext", tmp, NULL, NULL);
} }
switch_ivr_session_transfer(b_session, dest, "inline", NULL); switch_ivr_session_transfer(b_session, dest, "inline", NULL);
switch_mutex_unlock(lot->mutex);
switch_core_session_rwunlock(b_session); switch_core_session_rwunlock(b_session);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
goto end; goto end;
@ -534,7 +542,6 @@ SWITCH_STANDARD_APP(valet_parking_function)
args.buf = dbuf; args.buf = dbuf;
args.buflen = sizeof(dbuf); args.buflen = sizeof(dbuf);
switch_mutex_unlock(lot->mutex);
while(switch_channel_ready(channel)) { while(switch_channel_ready(channel)) {