move functions to strip commas and non-numeric chars to switch_utils

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16936 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2010-03-08 08:12:12 +00:00
parent 8b20d78f8d
commit f8974f03f9
12 changed files with 66 additions and 454 deletions

View File

@ -545,6 +545,8 @@ SWITCH_DECLARE(unsigned int) switch_separate_string_string(char *buf, char *deli
SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str); SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str);
SWITCH_DECLARE(char *) switch_strip_spaces(const char *str); SWITCH_DECLARE(char *) switch_strip_spaces(const char *str);
SWITCH_DECLARE(char *) switch_strip_commas(char *in, char *out, switch_size_t len);
SWITCH_DECLARE(char *) switch_strip_nonnumerics(char *in, char *out, switch_size_t len);
SWITCH_DECLARE(char *) switch_separate_paren_args(char *str); SWITCH_DECLARE(char *) switch_separate_paren_args(char *str);
SWITCH_DECLARE(const char *) switch_stristr(const char *instr, const char *str); SWITCH_DECLARE(const char *) switch_stristr(const char *instr, const char *str);
SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip); SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip);

View File

@ -122,49 +122,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
// valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t de_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t de_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -173,7 +130,7 @@ static switch_status_t de_say_general_count(switch_core_session_t *session, char
char sbuf[13] = ""; char sbuf[13] = "";
switch_status_t status; switch_status_t status;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -408,7 +365,7 @@ static switch_status_t de_say_money(switch_core_session_t *session, char *tosay,
char *dollars = NULL; char *dollars = NULL;
char *cents = NULL; char *cents = NULL;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -117,49 +117,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
// valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t en_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t en_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -169,7 +126,7 @@ static switch_status_t en_say_general_count(switch_core_session_t *session, char
switch_status_t status; switch_status_t status;
if (say_args->method == SSM_ITERATED) { if (say_args->method == SSM_ITERATED) {
if ((tosay = strip_commas(tosay, sbuf, sizeof(sbuf)))) { if ((tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)))) {
char *p; char *p;
for (p = tosay; p && *p; p++) { for (p = tosay; p && *p; p++) {
say_file("digits/%c.wav", *p); say_file("digits/%c.wav", *p);
@ -181,7 +138,7 @@ static switch_status_t en_say_general_count(switch_core_session_t *session, char
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -475,7 +432,7 @@ static switch_status_t en_say_money(switch_core_session_t *session, char *tosay,
char *dollars = NULL; char *dollars = NULL;
char *cents = NULL; char *cents = NULL;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -142,49 +142,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
// valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t es_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t es_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -193,7 +150,7 @@ static switch_status_t es_say_general_count(switch_core_session_t *session, char
char sbuf[13] = ""; char sbuf[13] = "";
switch_status_t status; switch_status_t status;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -429,7 +386,7 @@ static switch_status_t es_say_money(switch_core_session_t *session, char *tosay,
char *dollars = NULL; char *dollars = NULL;
char *cents = NULL; char *cents = NULL;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -139,49 +139,6 @@ static switch_status_t play_group(switch_say_method_t method, switch_say_gender_
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
/* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t fr_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t fr_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -190,7 +147,7 @@ static switch_status_t fr_say_general_count(switch_core_session_t *session, char
char sbuf[13] = ""; char sbuf[13] = "";
switch_status_t status; switch_status_t status;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -480,7 +437,7 @@ static switch_status_t fr_say_money(switch_core_session_t *session, char *tosay,
char *dollars = NULL; char *dollars = NULL;
char *cents = NULL; char *cents = NULL;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -117,49 +117,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
// valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t hu_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t hu_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -169,7 +126,7 @@ static switch_status_t hu_say_general_count(switch_core_session_t *session, char
int number; int number;
switch_status_t status; switch_status_t status;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -437,7 +394,7 @@ static switch_status_t hu_say_money(switch_core_session_t *session, char *tosay,
char sbuf[16] = ""; char sbuf[16] = "";
char *forint; char *forint;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -126,49 +126,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
/* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t it_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t it_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -177,7 +134,7 @@ static switch_status_t it_say_general_count(switch_core_session_t *session, char
char sbuf[13] = ""; char sbuf[13] = "";
switch_status_t status; switch_status_t status;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -436,7 +393,7 @@ static switch_status_t it_say_money(switch_core_session_t *session, char *tosay,
char *dollars = NULL; char *dollars = NULL;
char *cents = NULL; char *cents = NULL;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -113,49 +113,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
// valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t nl_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t nl_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -164,7 +121,7 @@ static switch_status_t nl_say_general_count(switch_core_session_t *session, char
char sbuf[13] = ""; char sbuf[13] = "";
switch_status_t status; switch_status_t status;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -400,7 +357,7 @@ static switch_status_t nl_say_money(switch_core_session_t *session, char *tosay,
char *dollars = NULL; char *dollars = NULL;
char *cents = NULL; char *cents = NULL;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -72,45 +72,6 @@ SWITCH_MODULE_DEFINITION(mod_say_ru, mod_say_ru_load, NULL, NULL);
return SWITCH_STATUS_FALSE;\ return SWITCH_STATUS_FALSE;\
}} }}
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
/* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t play_group(say_type_t say_type, casus_t casus, int a, int b, int c, static switch_status_t play_group(say_type_t say_type, casus_t casus, int a, int b, int c,
unit_t what, switch_core_session_t *session, switch_input_args_t *args) unit_t what, switch_core_session_t *session, switch_input_args_t *args)
{ {
@ -203,7 +164,7 @@ static switch_status_t ru_say_count(switch_core_session_t *session, char *tosay,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say_count %s!\n", tosay); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say_count %s!\n", tosay);
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -300,7 +261,7 @@ static switch_status_t ru_say_money(switch_core_session_t *session, char *tosay,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_money %s\n", tosay); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_money %s\n", tosay);
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -87,52 +87,6 @@ SWITCH_MODULE_DEFINITION(mod_say_th, mod_say_th_load, NULL, NULL);
return SWITCH_STATUS_FALSE; \ return SWITCH_STATUS_FALSE; \
}} \ }} \
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in;
char *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p >= '0' && *p <= '9')) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in;
char *q = out;
char *ret = out;
switch_size_t x = 0;
/* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
for (; p && *p; p++) {
if ((*p >= '0' && *p <= '9') || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t th_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t th_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -140,7 +94,7 @@ static switch_status_t th_say_general_count(switch_core_session_t *session, char
char digits[11]; char digits[11];
int i; int i;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -505,7 +459,7 @@ static switch_status_t th_say_money(switch_core_session_t *session, char *tosay,
char *dollars = NULL; char *dollars = NULL;
char *cents = NULL; char *cents = NULL;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -86,53 +86,6 @@ SWITCH_MODULE_DEFINITION(mod_say_zh, mod_say_zh_load, NULL, NULL);
return SWITCH_STATUS_FALSE; \ return SWITCH_STATUS_FALSE; \
}} \ }} \
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in;
char *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p >= '0' && *p <= '9')) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in;
char *q = out;
char *ret = out;
switch_size_t x = 0;
/* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
for (; p && *p; p++) {
if ((*p >= '0' && *p <= '9') || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
static switch_status_t zh_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t zh_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int in; int in;
@ -140,7 +93,7 @@ static switch_status_t zh_say_general_count(switch_core_session_t *session, char
char digits[11]; char digits[11];
int i; int i;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -485,7 +438,7 @@ static switch_status_t zh_say_money(switch_core_session_t *session, char *tosay,
char *dollars = NULL; char *dollars = NULL;
char *cents = NULL; char *cents = NULL;
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -742,6 +742,49 @@ SWITCH_DECLARE(char *) switch_strip_spaces(const char *str)
return s; return s;
} }
SWITCH_DECLARE(char *) switch_strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
ret = NULL;
break;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
SWITCH_DECLARE(char *) switch_strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
/* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
if (++x > len) {
ret = NULL;
break;
}
}
return ret;
}
SWITCH_DECLARE(char *) switch_separate_paren_args(char *str) SWITCH_DECLARE(char *) switch_separate_paren_args(char *str)
{ {
char *e, *args; char *e, *args;