From c788145f57d26ab773853f39b3749838c8ac5e9d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 8 Mar 2010 08:38:50 +0000 Subject: [PATCH] use common code to say ip when possible git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16937 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_ivr.h | 5 +++ src/mod/say/mod_say_de/mod_say_de.c | 40 +-------------------- src/mod/say/mod_say_en/mod_say_en.c | 40 +-------------------- src/mod/say/mod_say_es/mod_say_es.c | 40 +-------------------- src/mod/say/mod_say_fr/mod_say_fr.c | 40 +-------------------- src/mod/say/mod_say_hu/mod_say_hu.c | 40 +-------------------- src/mod/say/mod_say_it/mod_say_it.c | 40 +-------------------- src/mod/say/mod_say_nl/mod_say_nl.c | 40 +-------------------- src/mod/say/mod_say_th/mod_say_th.c | 39 +------------------- src/mod/say/mod_say_zh/mod_say_zh.c | 39 +------------------- src/switch_ivr_say.c | 55 +++++++++++++++++++++++++++++ 11 files changed, 69 insertions(+), 349 deletions(-) diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 1e9ad9797f..3affb6c0ad 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -822,6 +822,11 @@ SWITCH_DECLARE(switch_say_method_t) switch_ivr_get_say_method_by_name(const char SWITCH_DECLARE(switch_say_gender_t) switch_ivr_get_say_gender_by_name(const char *name); SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *name); SWITCH_DECLARE(switch_status_t) switch_ivr_say_spell(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args); +SWITCH_DECLARE(switch_status_t) switch_ivr_say_ip(switch_core_session_t *session, + char *tosay, + switch_say_callback_t number_func, + switch_say_args_t *say_args, + switch_input_args_t *args); SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *session, const char *data); SWITCH_DECLARE(switch_status_t) switch_ivr_sound_test(switch_core_session_t *session); diff --git a/src/mod/say/mod_say_de/mod_say_de.c b/src/mod/say/mod_say_de/mod_say_de.c index e36abbdb39..ea0b380e4e 100644 --- a/src/mod/say/mod_say_de/mod_say_de.c +++ b/src/mod/say/mod_say_de/mod_say_de.c @@ -176,44 +176,6 @@ static switch_status_t de_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t de_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - - static switch_status_t de_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -438,7 +400,7 @@ static switch_status_t de_say(switch_core_session_t *session, char *tosay, switc say_cb = de_say_time; break; case SST_IP_ADDRESS: - say_cb = de_ip; + return switch_ivr_say_ip(session, tosay, de_say_general_count, say_args, args); break; case SST_NAME_SPELLED: case SST_NAME_PHONETIC: diff --git a/src/mod/say/mod_say_en/mod_say_en.c b/src/mod/say/mod_say_en/mod_say_en.c index 450047ad67..03bea87bc1 100644 --- a/src/mod/say/mod_say_en/mod_say_en.c +++ b/src/mod/say/mod_say_en/mod_say_en.c @@ -176,44 +176,6 @@ static switch_status_t en_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t en_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - - static switch_status_t en_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -506,7 +468,7 @@ static switch_status_t en_say(switch_core_session_t *session, char *tosay, switc say_cb = en_say_time; break; case SST_IP_ADDRESS: - say_cb = en_ip; + return switch_ivr_say_ip(session, tosay, en_say_general_count, say_args, args); break; case SST_NAME_SPELLED: case SST_NAME_PHONETIC: diff --git a/src/mod/say/mod_say_es/mod_say_es.c b/src/mod/say/mod_say_es/mod_say_es.c index 3ab3349618..e2786d940f 100644 --- a/src/mod/say/mod_say_es/mod_say_es.c +++ b/src/mod/say/mod_say_es/mod_say_es.c @@ -196,44 +196,6 @@ static switch_status_t es_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t es_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - - static switch_status_t es_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -459,7 +421,7 @@ static switch_status_t es_say(switch_core_session_t *session, char *tosay, switc say_cb = es_say_time; break; case SST_IP_ADDRESS: - say_cb = es_ip; + return switch_ivr_say_ip(session, tosay, es_say_general_count, say_args, args); break; case SST_NAME_SPELLED: case SST_NAME_PHONETIC: diff --git a/src/mod/say/mod_say_fr/mod_say_fr.c b/src/mod/say/mod_say_fr/mod_say_fr.c index 670746a8d3..cf3ebabcdb 100644 --- a/src/mod/say/mod_say_fr/mod_say_fr.c +++ b/src/mod/say/mod_say_fr/mod_say_fr.c @@ -197,44 +197,6 @@ static switch_status_t fr_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t fr_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - - static switch_status_t fr_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -510,7 +472,7 @@ static switch_status_t fr_say(switch_core_session_t *session, char *tosay, switc say_cb = fr_say_time; break; case SST_IP_ADDRESS: - say_cb = fr_ip; + return switch_ivr_say_ip(session, tosay, fr_say_general_count, say_args, args); break; case SST_TELEPHONE_NUMBER: case SST_TELEPHONE_EXTENSION: diff --git a/src/mod/say/mod_say_hu/mod_say_hu.c b/src/mod/say/mod_say_hu/mod_say_hu.c index 5e92ff5cc8..6a3dfdc65e 100644 --- a/src/mod/say/mod_say_hu/mod_say_hu.c +++ b/src/mod/say/mod_say_hu/mod_say_hu.c @@ -175,44 +175,6 @@ static switch_status_t hu_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t hu_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - - static switch_status_t hu_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -438,7 +400,7 @@ static switch_status_t hu_say(switch_core_session_t *session, char *tosay, switc say_cb = hu_say_time; break; case SST_IP_ADDRESS: - say_cb = hu_ip; + return switch_ivr_say_ip(session, tosay, hu_say_general_count, say_args, args); break; case SST_NAME_SPELLED: case SST_NAME_PHONETIC: diff --git a/src/mod/say/mod_say_it/mod_say_it.c b/src/mod/say/mod_say_it/mod_say_it.c index b42d084e8d..7a3c7bc99c 100644 --- a/src/mod/say/mod_say_it/mod_say_it.c +++ b/src/mod/say/mod_say_it/mod_say_it.c @@ -220,44 +220,6 @@ static switch_status_t it_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t it_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - - static switch_status_t it_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -466,7 +428,7 @@ static switch_status_t it_say(switch_core_session_t *session, char *tosay, switc say_cb = it_say_time; break; case SST_IP_ADDRESS: - say_cb = it_ip; + return switch_ivr_say_ip(session, tosay, it_say_general_count, say_args, args); break; case SST_NAME_SPELLED: case SST_NAME_PHONETIC: diff --git a/src/mod/say/mod_say_nl/mod_say_nl.c b/src/mod/say/mod_say_nl/mod_say_nl.c index 2ee8b35473..4f4ec7edd0 100644 --- a/src/mod/say/mod_say_nl/mod_say_nl.c +++ b/src/mod/say/mod_say_nl/mod_say_nl.c @@ -167,44 +167,6 @@ static switch_status_t nl_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t nl_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - - static switch_status_t nl_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -430,7 +392,7 @@ static switch_status_t nl_say(switch_core_session_t *session, char *tosay, switc say_cb = nl_say_time; break; case SST_IP_ADDRESS: - say_cb = nl_ip; + return switch_ivr_say_ip(session, tosay, nl_say_general_count, say_args, args); break; case SST_NAME_SPELLED: case SST_NAME_PHONETIC: diff --git a/src/mod/say/mod_say_th/mod_say_th.c b/src/mod/say/mod_say_th/mod_say_th.c index 95b2ff0833..59b077a0fe 100644 --- a/src/mod/say/mod_say_th/mod_say_th.c +++ b/src/mod/say/mod_say_th/mod_say_th.c @@ -225,43 +225,6 @@ static switch_status_t th_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t th_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - static switch_status_t th_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -517,7 +480,7 @@ static switch_status_t th_say(switch_core_session_t *session, char *tosay, switc say_cb = th_say_time; break; case SST_IP_ADDRESS: - say_cb = th_ip; + return switch_ivr_say_ip(session, tosay, th_say_general_count, say_args, args); break; case SST_NAME_SPELLED: case SST_NAME_PHONETIC: diff --git a/src/mod/say/mod_say_zh/mod_say_zh.c b/src/mod/say/mod_say_zh/mod_say_zh.c index 6432ded61c..69e2c73cf6 100644 --- a/src/mod/say/mod_say_zh/mod_say_zh.c +++ b/src/mod/say/mod_say_zh/mod_say_zh.c @@ -204,43 +204,6 @@ static switch_status_t zh_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - -static switch_status_t zh_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) -{ - char *a, *b, *c, *d; - if (!(a = switch_core_session_strdup(session, tosay))) { - return SWITCH_STATUS_FALSE; - } - - if (!(b = strchr(a, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *b++ = '\0'; - - if (!(c = strchr(b, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *c++ = '\0'; - - if (!(d = strchr(c, '.'))) { - return SWITCH_STATUS_FALSE; - } - - *d++ = '\0'; - - say_num(atoi(a), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(b), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(c), say_args->method); - say_file("digits/dot.wav"); - say_num(atoi(d), say_args->method); - - return SWITCH_STATUS_SUCCESS; -} - static switch_status_t zh_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int32_t t; @@ -496,7 +459,7 @@ static switch_status_t zh_say(switch_core_session_t *session, char *tosay, switc say_cb = zh_say_time; break; case SST_IP_ADDRESS: - say_cb = zh_ip; + return switch_ivr_say_ip(session, tosay, zh_say_general_count, say_args, args); break; case SST_NAME_SPELLED: case SST_NAME_PHONETIC: diff --git a/src/switch_ivr_say.c b/src/switch_ivr_say.c index cd4ea0d118..23be59edaa 100644 --- a/src/switch_ivr_say.c +++ b/src/switch_ivr_say.c @@ -128,6 +128,7 @@ SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *na return SWITCH_STATUS_FALSE; \ }} \ + SWITCH_DECLARE(switch_status_t) switch_ivr_say_spell(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { char *p; @@ -148,6 +149,60 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_say_spell(switch_core_session_t *sess return SWITCH_STATUS_SUCCESS; } +#define say_num(num, meth) { \ + char tmp[80]; \ + switch_status_t tstatus; \ + switch_say_method_t smeth = say_args->method; \ + switch_say_type_t stype = say_args->type; \ + say_args->type = SST_ITEMS; say_args->method = meth; \ + switch_snprintf(tmp, sizeof(tmp), "%u", (unsigned)num); \ + if ((tstatus = \ + number_func(session, tmp, say_args, args)) \ + != SWITCH_STATUS_SUCCESS) { \ + return tstatus; \ + } \ + say_args->method = smeth; say_args->type = stype; \ + } \ + +SWITCH_DECLARE(switch_status_t) switch_ivr_say_ip(switch_core_session_t *session, + char *tosay, + switch_say_callback_t number_func, + switch_say_args_t *say_args, + switch_input_args_t *args) +{ + char *a, *b, *c, *d; + if (!(a = switch_core_session_strdup(session, tosay))) { + return SWITCH_STATUS_FALSE; + } + + if (!(b = strchr(a, '.'))) { + return SWITCH_STATUS_FALSE; + } + + *b++ = '\0'; + + if (!(c = strchr(b, '.'))) { + return SWITCH_STATUS_FALSE; + } + + *c++ = '\0'; + + if (!(d = strchr(c, '.'))) { + return SWITCH_STATUS_FALSE; + } + + *d++ = '\0'; + + say_num(atoi(a), say_args->method); + say_file("digits/dot.wav"); + say_num(atoi(b), say_args->method); + say_file("digits/dot.wav"); + say_num(atoi(c), say_args->method); + say_file("digits/dot.wav"); + say_num(atoi(d), say_args->method); + + return SWITCH_STATUS_SUCCESS; +} /* For Emacs: