From 94e6bcfd2be07308c91da7ac15ea226059a05614 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 28 Feb 2011 16:36:28 -0500 Subject: [PATCH 1/3] mod_sofia: fix bugzilla 6341 - dialplan not replacing user in contact string --- src/mod/endpoints/mod_sofia/mod_sofia.c | 184 ++++++++++++------------ 1 file changed, 93 insertions(+), 91 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 5ce681880c..82f4c2ca02 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3552,97 +3552,6 @@ SWITCH_STANDARD_API(sofia_contact_function) } } - if (user_replacement) { - int urlcount = 0; - int copyerr = 0; - char *newreply = NULL; - char *urlstart = NULL; - char *newptr = NULL; - char *bufend = NULL; - char *str = reply; - switch_size_t copysize = 0; - switch_size_t replacesize = strlen(user_replacement); - switch_size_t allocsize = 0; - - /* first pass to count how many URLs we have */ - while ((urlstart = strcasestr(str, "sip:")) || (urlstart = strcasestr(str, "sips:"))) { - urlcount++; - str = urlstart + 4; - } - - if (!urlcount) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): no sip URLs found to replace the user\n"); - copyerr++; - goto copydone; - } - - /* this allocates a bit more than needed but better safe than sorry doing more funky math */ - allocsize = strlen(reply) + (urlcount * replacesize); - newreply = switch_core_session_alloc(session, allocsize); - if (!newreply) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): no buffer space available for replacement\n"); - copyerr++; - goto copydone; - } - - /* get a working pointer to the new reply */ - newptr = newreply; - - /* pointer to the end of the allocated buffer for safety checks */ - bufend = newreply + allocsize; - *bufend = 0; - - /* go thru all the urls and replace the user part */ - str = reply; - while ((urlstart = strcasestr(str, "sip:")) || (urlstart = strcasestr(str, "sips:"))) { - - /* found an URL, copy up to the start of the url */ - copysize = ( urlstart - str ) + 4; - - /* double check boundaries before copying anything at all (this should not happen) */ - if ((newptr + copysize + replacesize) >= bufend) { - copyerr++; - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): wow buffer was not big enough!\n"); - break; - } - - /* copy the original contact string except for the user */ - memcpy(newptr, str, copysize); - newptr += copysize; - - /* copy the user replacement */ - memcpy(newptr, user_replacement, replacesize); - newptr += replacesize; - - /* skip the original user part */ - str = strchr(urlstart, '@'); - if (!str) { - copyerr++; - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): not host part found for contact\n"); - break; - } - /* continue searching for the next sip: URL */ - } - -copydone: - if (!copyerr) { - /* copy the remaining reply string */ - copysize = strlen(str); - if ((newptr + copysize) >= bufend) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): wow buffer was not big enough, close, but not enough!\n"); - } else { - strcpy(newptr, str); - reply = newreply; - } - } else { - reply = "error/replacement error"; - } - } - - stream->write_function(stream, "%s", reply); - reply = NULL; - - switch_safe_free(mystream.data); } switch_mutex_unlock(mod_sofia_globals.hash_mutex); @@ -3650,6 +3559,99 @@ copydone: reply = (char *) mystream.data; + if (user_replacement) { + int urlcount = 0; + int copyerr = 0; + char *newreply = NULL; + char *urlstart = NULL; + char *newptr = NULL; + char *bufend = NULL; + char *str = reply; + switch_size_t copysize = 0; + switch_size_t replacesize = strlen(user_replacement); + switch_size_t allocsize = 0; + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "sofia_contact(): trying to replace %s in %s\n", + user_replacement, str); + + /* first pass to count how many URLs we have */ + while ((urlstart = strcasestr(str, "sip:")) || (urlstart = strcasestr(str, "sips:"))) { + urlcount++; + str = urlstart + 4; + } + + if (!urlcount) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): no sip URLs found to replace the user\n"); + copyerr++; + goto copydone; + } + + /* this allocates a bit more than needed but better safe than sorry doing more funky math */ + allocsize = strlen(reply) + (urlcount * replacesize); + newreply = switch_core_session_alloc(session, allocsize); + if (!newreply) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): no buffer space available for replacement\n"); + copyerr++; + goto copydone; + } + + /* get a working pointer to the new reply */ + newptr = newreply; + + /* pointer to the end of the allocated buffer for safety checks */ + bufend = newreply + allocsize; + *bufend = 0; + + /* go thru all the urls and replace the user part */ + str = reply; + while ((urlstart = strcasestr(str, "sip:")) || (urlstart = strcasestr(str, "sips:"))) { + + /* found an URL, copy up to the start of the url */ + copysize = ( urlstart - str ) + 4; + + /* double check boundaries before copying anything at all (this should not happen) */ + if ((newptr + copysize + replacesize) >= bufend) { + copyerr++; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): wow buffer was not big enough!\n"); + break; + } + + /* copy the original contact string except for the user */ + memcpy(newptr, str, copysize); + newptr += copysize; + + /* copy the user replacement */ + memcpy(newptr, user_replacement, replacesize); + newptr += replacesize; + + /* skip the original user part */ + str = strchr(urlstart, '@'); + if (!str) { + copyerr++; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): not host part found for contact\n"); + break; + } + /* continue searching for the next sip: URL */ + } + +copydone: + if (!copyerr) { + /* copy the remaining reply string */ + copysize = strlen(str); + if ((newptr + copysize) >= bufend) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sofia_contact(): wow buffer was not big enough, close, but not enough!\n"); + } else { + strcpy(newptr, str); + reply = newreply; + goto end; + } + } else { + /* on error, we do nothing and just default to the original stream returned (mystream.data) */ + } + } + + reply = (char *) mystream.data; + end: if (zstr(reply)) { From 6692a70c52db01b1206cc153a0967226f18cb310 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 1 Mar 2011 12:31:35 -0500 Subject: [PATCH 2/3] set default smg event socket port to 8821 instead of 8021 which is for FreeSWITCH event socket --- libs/esl/fs_cli.c | 6 +++--- libs/esl/fs_cli.conf | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/esl/fs_cli.c b/libs/esl/fs_cli.c index 5a52c63085..749c8df167 100644 --- a/libs/esl/fs_cli.c +++ b/libs/esl/fs_cli.c @@ -1040,7 +1040,7 @@ int main(int argc, char *argv[]) strncpy(internal_profile.host, "127.0.0.1", sizeof(internal_profile.host)); strncpy(internal_profile.pass, "ClueCon", sizeof(internal_profile.pass)); strncpy(internal_profile.name, "internal", sizeof(internal_profile.name)); - internal_profile.port = 8021; + internal_profile.port = 8821; set_fn_keys(&internal_profile); @@ -1139,7 +1139,7 @@ int main(int argc, char *argv[]) esl_set_string(profiles[pcount].name, cur_cat); esl_set_string(profiles[pcount].host, "localhost"); esl_set_string(profiles[pcount].pass, "ClueCon"); - profiles[pcount].port = 8021; + profiles[pcount].port = 8821; set_fn_keys(&profiles[pcount]); esl_log(ESL_LOG_DEBUG, "Found Profile [%s]\n", profiles[pcount].name); pcount++; @@ -1218,7 +1218,7 @@ int main(int argc, char *argv[]) esl_log(ESL_LOG_DEBUG, "Using profile %s [%s]\n", profile->name, profile->host); if (argv_host) { - if (argv_port && profile->port != 8021) { + if (argv_port && profile->port != 8821) { snprintf(prompt_str, sizeof(prompt_str), PROMPT_PREFIX "@%s:%u@%s> ", profile->host, profile->port, profile->name); } else { snprintf(prompt_str, sizeof(prompt_str), PROMPT_PREFIX "@%s@%s> ", profile->host, profile->name); diff --git a/libs/esl/fs_cli.conf b/libs/esl/fs_cli.conf index 34932df48a..47de41be70 100644 --- a/libs/esl/fs_cli.conf +++ b/libs/esl/fs_cli.conf @@ -4,7 +4,7 @@ host => 127.0.0.1 password => ClueCon -port => 8021 +port => 8821 debug => 2 key_f1 => help From a60086cd22766fd9b9dc0ccfe243d12b47d958c5 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 11 Mar 2011 17:39:07 -0500 Subject: [PATCH 3/3] Changed Freeswitch core to return with error instead of abort when a critical module fails to load --- src/switch_loadable_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index d6796c8119..fe596bdf6b 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -1300,7 +1300,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init(switch_bool_t autolo if (switch_loadable_module_load_module_ex((char *) path, (char *) val, SWITCH_FALSE, global, &err) == SWITCH_STATUS_GENERR) { if (critical && switch_true(critical)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to load critical module '%s', abort()\n", val); - abort(); + return SWITCH_STATUS_FALSE; } } count++;