Merge branch 'smgmaster' of git.sangoma.com:/smg_freeswitch into smgmaster

This commit is contained in:
Konrad Hammel 2011-03-15 10:53:59 -04:00
commit 0bb7fd42be
4 changed files with 98 additions and 96 deletions

View File

@ -1049,7 +1049,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);
@ -1151,7 +1151,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++;
@ -1230,7 +1230,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);

View File

@ -4,7 +4,7 @@
host => 127.0.0.1
password => ClueCon
port => 8021
port => 8821
debug => 2
key_f1 => help

View File

@ -3562,97 +3562,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);
@ -3660,6 +3569,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)) {

View File

@ -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++;