From b50e8f5c9ae6e85c2144b7a42dadd42a98afb877 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 16 Oct 2007 14:24:02 +0000 Subject: [PATCH] add switch_stristr and use it in dptools git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5887 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 2 ++ .../applications/mod_dptools/mod_dptools.c | 2 +- src/switch_utils.c | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 1f93b89085..de811dd83b 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -298,6 +298,8 @@ if (vname) {free(vname); vname = NULL;}vname = strdup(string);} */ SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char **array, int arraylen); +SWITCH_DECLARE(const char *) switch_stristr(const char *str, const char *instr); + /*! \brief Escape a string by prefixing a list of characters with an escape character \param pool a memory pool to use diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 775a27dd4b..97813137dc 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -1223,7 +1223,7 @@ SWITCH_STANDARD_APP(audio_bridge_function) cause_str = switch_channel_cause2str(cause); snprintf(cause_num, sizeof(cause_num), "%u", cause); - if (switch_true(continue_on_fail) || strstr(cause_str, continue_on_fail) || strstr(cause_str, cause_num)) { + if (switch_true(continue_on_fail) || switch_stristr(cause_str, continue_on_fail) || strstr(cause_str, cause_num)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Continue on fail [%s]: Cause: %s\n", continue_on_fail, cause_str); return; } diff --git a/src/switch_utils.c b/src/switch_utils.c index ce2683c3f0..ddd9cb6e30 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -197,6 +197,27 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *he } +SWITCH_DECLARE(const char *) switch_stristr(const char *str, const char *instr) +{ + size_t score = strlen(str), x = 0; + const char *a = str, *b = instr, *p = NULL; + + while(*a && *b) { + if (tolower(*b) == tolower(*a)) { + if (++x == score) { + return p; + } + a++; + } else { + a = str; + p = b+1; + x = 0; + } + b++; + } + return NULL; +} + SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int family) { switch_status_t status = SWITCH_STATUS_FALSE;