]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add bind meta on A-D and refactor
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 5 Jan 2011 23:53:27 +0000 (17:53 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 5 Jan 2011 23:53:27 +0000 (17:53 -0600)
src/include/switch_channel.h
src/include/switch_types.h
src/include/switch_utils.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/applications/mod_fifo/mod_fifo.c
src/mod/applications/mod_spy/mod_spy.c
src/mod/applications/mod_valet_parking/mod_valet_parking.c
src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp
src/switch_channel.c
src/switch_ivr_async.c
src/switch_ivr_play_say.c

index 368b8950e43d2217a24327d461a1e427522bbd60..c0bef4be597045ae04424ce549ad1cb53ae69a86 100644 (file)
@@ -256,6 +256,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_partner_var_check(sw
                                                                                                                                                          const char *varname, const char *value, switch_bool_t var_check);
 SWITCH_DECLARE(const char *) switch_channel_get_variable_partner(switch_channel_t *channel, const char *varname);
 
+SWITCH_DECLARE(const char *) switch_channel_get_hold_music(switch_channel_t *channel);
+SWITCH_DECLARE(const char *) switch_channel_get_hold_music_partner(switch_channel_t *channel);
 
 #define switch_channel_set_variable(_channel, _var, _val) switch_channel_set_variable_var_check(_channel, _var, _val, SWITCH_TRUE)
 #define switch_channel_set_variable_partner(_channel, _var, _val) switch_channel_set_variable_partner_var_check(_channel, _var, _val, SWITCH_TRUE)
index 98ac80430816f6b5ea3fed87f7c5c225eab781fc..01f890d51c11c804d8fe9e5f433bc8934a5fb753 100644 (file)
@@ -156,6 +156,7 @@ SWITCH_BEGIN_EXTERN_C
 #define SWITCH_PROXY_MEDIA_VARIABLE "proxy_media"
 #define SWITCH_ENDPOINT_DISPOSITION_VARIABLE "endpoint_disposition"
 #define SWITCH_HOLD_MUSIC_VARIABLE "hold_music"
+#define SWITCH_TEMP_HOLD_MUSIC_VARIABLE "temp_hold_music"
 #define SWITCH_EXPORT_VARS_VARIABLE "export_vars"
 #define SWITCH_BRIDGE_EXPORT_VARS_VARIABLE "bridge_export_vars"
 #define SWITCH_R_SDP_VARIABLE "switch_r_sdp"
index 259de0a67bbc55b6f9f06f400f5d4da886f43e83..4771dba40a795597d452362a0df2265e787463a0 100644 (file)
@@ -184,6 +184,32 @@ static inline switch_bool_t switch_is_digit_string(const char *s)
        return SWITCH_TRUE;
 }
 
+static inline char switch_itodtmf(char i)
+{
+       char r = i;
+
+       if (i > 9 && i < 14) {
+               r = i + 55;
+       }
+
+       return r;
+}
+
+static inline int switch_dtmftoi(char *s)
+{
+       int r;
+
+       switch_assert(s);
+
+       if (!(r = atoi(s))) {
+               int l = tolower(*s);
+               if (l > 96 && l < 101) {
+                       r = l - 87;
+               }
+       }
+
+       return r;
+}
 
 static inline uint32_t switch_known_bitrate(switch_payload_t payload)
 {
index e5e4fe5e0f7baceb1a574e2bf9f1c494868c9f9b..7388094568768de7834ae2da293ab65301b78070 100755 (executable)
@@ -389,7 +389,7 @@ SWITCH_STANDARD_APP(dtmf_unbind_function)
        int kval = 0;
 
        if (key) {
-               kval = atoi(key);
+               kval = switch_dtmftoi(key);
        }
 
        switch_ivr_unbind_dtmf_meta_session(session, kval);
@@ -405,7 +405,7 @@ SWITCH_STANDARD_APP(dtmf_bind_function)
 
        if (!zstr(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]);
+               int kval = switch_dtmftoi(argv[0]);
                switch_bind_flag_t bind_flags = 0;
 
                if (strchr(argv[1], 'a')) {
@@ -2531,7 +2531,7 @@ SWITCH_STANDARD_APP(audio_bridge_function)
                        camp_data = (char *) data;
                }
 
-               if (!(moh = switch_channel_get_variable(caller_channel, "hold_music"))) {
+               if (!(moh = switch_channel_get_variable(caller_channel, SWITCH_HOLD_MUSIC_VARIABLE))) {
                        moh = switch_channel_get_variable(caller_channel, "campon_hold_music");
                }
 
index 570b2fd430c6f3e4335aa7d484b0b5c55a61c18b..1f9d9d6a576025f5ba16a6e0b1db13a8d2a85f09 100644 (file)
@@ -397,12 +397,12 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
                                        const char *moh_a = NULL, *moh_b = NULL;
 
                                        if (!(moh_b = switch_channel_get_variable(bchan, "fifo_music"))) {
-                                               moh_b = switch_channel_get_variable(bchan, "hold_music");
+                                               moh_b = switch_channel_get_variable(bchan, SWITCH_HOLD_MUSIC_VARIABLE);
                                        }
 
                                        if (!(moh_a = switch_channel_get_variable(channel, "fifo_hold_music"))) {
                                                if (!(moh_a = switch_channel_get_variable(channel, "fifo_music"))) {
-                                                       moh_a = switch_channel_get_variable(channel, "hold_music");
+                                                       moh_a = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE);
                                                }
                                        }
 
index e6f3beffb1d5089e08c84d252e60179dcec270d6..411ed090a3dc6b2d9c02e8f60029008d492d9e67 100644 (file)
@@ -83,7 +83,7 @@ static switch_status_t spy_on_exchange_media(switch_core_session_t *session)
 static switch_status_t spy_on_park(switch_core_session_t *session)
 {
        switch_channel_t *channel = switch_core_session_get_channel(session);
-       const char *moh = switch_channel_get_variable(channel, "hold_music");
+       const char *moh = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE);
 
        while (switch_channel_ready(channel) && switch_channel_get_state(channel) == CS_PARK) {
                if (moh) {
index 4de727ceda2763350a67c72dd6b0dcf312535d0f..369ae972e70881afbc833664dcc897535bff4264 100644 (file)
@@ -234,7 +234,7 @@ SWITCH_STANDARD_APP(valet_parking_function)
                }
 
                if (!(tmp = switch_channel_get_variable(channel, "valet_hold_music"))) {
-                       tmp = switch_channel_get_variable(channel, "hold_music");
+                       tmp = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE);
                }
                if (tmp)
                        music = tmp;
index 3eb3ad292648a4d61a8bf1fba9a2835cc2ba92a5..fe1f7cb8c0a0876bf9db2f849a241c50b84c2d64 100644 (file)
@@ -1512,7 +1512,7 @@ static switch_status_t load_config(int reload_type)
                                        hotline = val;
                                } else if (!strcasecmp(var, "dial_regex")) {
                                        dial_regex = val;
-                               } else if (!strcasecmp(var, "hold_music")) {
+                               } else if (!strcasecmp(var, SWITCH_HOLD_MUSIC_VARIABLE)) {
                                        hold_music = val;
                                } else if (!strcasecmp(var, "fail_dial_regex")) {
                                        fail_dial_regex = val;
index 9c696688099268e18b7f451cdcecfe1ff34d4c7e..f592158254298c6aef0286a31e6fa93c899e0a43 100644 (file)
@@ -646,6 +646,30 @@ SWITCH_DECLARE(void) switch_channel_mark_hold(switch_channel_t *channel, switch_
 
 }
 
+SWITCH_DECLARE(const char *) switch_channel_get_hold_music(switch_channel_t *channel)
+{
+       const char *var = switch_channel_get_variable(channel, SWITCH_TEMP_HOLD_MUSIC_VARIABLE);
+
+       if (!var) {
+               var = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE);
+       }
+
+       return var;
+}
+
+SWITCH_DECLARE(const char *) switch_channel_get_hold_music_partner(switch_channel_t *channel)
+{
+       switch_core_session_t *session;
+       const char *r = NULL;
+
+       if (switch_core_session_get_partner(channel->session, &session) == SWITCH_STATUS_SUCCESS) {
+               r = switch_channel_get_hold_music(switch_core_session_get_channel(session));
+               switch_core_session_rwunlock(session);
+       }
+
+       return r;
+}
+
 SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup)
 {
        const char *v = NULL, *r = NULL;
index f476c8fecf22125f060e191b4a7cb1a09c760a98..e987a4671a0227ab523d888ea3f0e310a0aa1fcf 100644 (file)
@@ -2727,7 +2727,7 @@ typedef struct {
 } dtmf_meta_app_t;
 
 typedef struct {
-       dtmf_meta_app_t map[10];
+       dtmf_meta_app_t map[14];
        time_t last_digit;
        switch_bool_t meta_on;
        char meta;
@@ -2974,14 +2974,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_se
        if (meta != '*' && meta != '#') {
                str[0] = meta;
 
-               if (atoi(str) == (int)key) {
+               if (switch_dtmftoi(str) == (char)key) {
                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid key %u, same as META CHAR\n", key);
                        return SWITCH_STATUS_FALSE;
                }
        }
 
 
-       if (key > 9) {
+       if (key > 13) {
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid key %u\n", key);
                return SWITCH_STATUS_FALSE;
        }
@@ -3000,8 +3000,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_se
                        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_SESSION_LOG(session), SWITCH_LOG_INFO, "Bound A-Leg: %c%d %s\n", meta, key, app);
+                       
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Bound A-Leg: %c%c %s\n", meta, switch_itodtmf(key), app);
                }
                if ((bind_flags & SBF_DIAL_BLEG)) {
                        md->sr[SWITCH_DTMF_SEND].meta = meta;
@@ -3009,12 +3009,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_se
                        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_SESSION_LOG(session), SWITCH_LOG_INFO, "Bound B-Leg: %c%d %s\n", meta, key, app);
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Bound B-Leg: %c%c %s\n", meta, switch_itodtmf(key), app);
                }
 
        } else {
                if ((bind_flags & SBF_DIAL_ALEG)) {
-                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "UnBound A-Leg: %c%d\n", meta, key);
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "UnBound A-Leg: %c%c\n", meta, switch_itodtmf(key));
                        md->sr[SWITCH_DTMF_SEND].map[key].app = NULL;
                } else {
                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "UnBound: B-Leg %c%d\n", meta, key);
index f254b677d7196eabc55592632b483f505bbaefb2..7e5f71edc7231cee881345ac0a185115355676b1 100644 (file)
@@ -2394,7 +2394,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess
                        if (moh_b) {
                                moh = moh_b;
                        } else {
-                               moh = switch_channel_get_variable(other_channel, "hold_music");
+                               moh = switch_channel_get_variable(other_channel, SWITCH_HOLD_MUSIC_VARIABLE);
                        }
 
                        if (!zstr(moh) && strcasecmp(moh, "silence") && !switch_channel_test_flag(other_channel, CF_BROADCAST)) {
@@ -2405,7 +2405,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess
                        if (moh_a) {
                                moh = moh_a;
                        } else {
-                               moh = switch_channel_get_variable(channel, "hold_music");
+                               moh = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE);
                        }
 
                        if (!zstr(moh) && strcasecmp(moh, "silence")) {