Cleanup code. Spacing issues, nested if issues, lots of strlen used instead of ast_strlen_zero

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3800 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
James Golovich
2004-09-17 14:15:11 +00:00
parent a9f5393bfe
commit 877f1f64c2
3 changed files with 130 additions and 137 deletions

View File

@@ -814,22 +814,22 @@ static void *fast_originate(void *data)
} else { } else {
res = ast_pbx_outgoing_exten(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, !ast_strlen_zero(in->callerid) ? in->callerid : NULL, in->variable, in->account); res = ast_pbx_outgoing_exten(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, !ast_strlen_zero(in->callerid) ? in->callerid : NULL, in->variable, in->account);
} }
if(!res) if (!res)
manager_event(EVENT_FLAG_CALL, manager_event(EVENT_FLAG_CALL,
"OriginateSuccess", "OriginateSuccess",
"%s" "%s"
"Channel: %s/%s\r\n" "Channel: %s/%s\r\n"
"Context: %s\r\n" "Context: %s\r\n"
"Exten: %s\r\n", "Exten: %s\r\n",
in->tech, in->data, in->idtext, in->context, in->exten); in->tech, in->data, in->idtext, in->context, in->exten);
else else
manager_event(EVENT_FLAG_CALL, manager_event(EVENT_FLAG_CALL,
"OriginateFailure", "OriginateFailure",
"%s" "%s"
"Channel: %s/%s\r\n" "Channel: %s/%s\r\n"
"Context: %s\r\n" "Context: %s\r\n"
"Exten: %s\r\n", "Exten: %s\r\n",
in->tech, in->data, in->idtext, in->context, in->exten); in->tech, in->data, in->idtext, in->context, in->exten);
free(in); free(in);
return NULL; return NULL;
@@ -894,15 +894,11 @@ static int action_originate(struct mansession *s, struct message *m)
} }
*data = '\0'; *data = '\0';
data++; data++;
if (ast_true(async)) if (ast_true(async)) {
{
struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper)); struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper));
if (!fast) if (!fast) {
{
res = -1; res = -1;
} } else {
else
{
memset(fast, 0, sizeof(struct fast_originate_helper)); memset(fast, 0, sizeof(struct fast_originate_helper));
if (id && !ast_strlen_zero(id)) if (id && !ast_strlen_zero(id))
snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id); snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id);
@@ -919,12 +915,9 @@ static int action_originate(struct mansession *s, struct message *m)
fast->priority = pi; fast->priority = pi;
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (ast_pthread_create(&th, &attr, fast_originate, fast)) if (ast_pthread_create(&th, &attr, fast_originate, fast)) {
{
res = -1; res = -1;
} } else {
else
{
res = 0; res = 0;
} }
} }

View File

@@ -181,11 +181,11 @@ int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeou
*extout = x; *extout = x;
/* Remember what had been dialed, so that if the parking /* Remember what had been dialed, so that if the parking
expires, we try to come back to the same place */ expires, we try to come back to the same place */
if (strlen(chan->macrocontext)) if (!ast_strlen_zero(chan->macrocontext))
strncpy(pu->context, chan->macrocontext, sizeof(pu->context)-1); strncpy(pu->context, chan->macrocontext, sizeof(pu->context)-1);
else else
strncpy(pu->context, chan->context, sizeof(pu->context)-1); strncpy(pu->context, chan->context, sizeof(pu->context)-1);
if (strlen(chan->macroexten)) if (!ast_strlen_zero(chan->macroexten))
strncpy(pu->exten, chan->macroexten, sizeof(pu->exten)-1); strncpy(pu->exten, chan->macroexten, sizeof(pu->exten)-1);
else else
strncpy(pu->exten, chan->exten, sizeof(pu->exten)-1); strncpy(pu->exten, chan->exten, sizeof(pu->exten)-1);
@@ -302,13 +302,14 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
int allowdisconnect_in,allowdisconnect_out,allowredirect_in,allowredirect_out; int allowdisconnect_in,allowdisconnect_out,allowredirect_in,allowredirect_out;
char *monitor_exec; char *monitor_exec;
if(monitor_ok) { if (monitor_ok) {
if(!monitor_app) if (!monitor_app) {
if(!(monitor_app = pbx_findapp("Monitor"))) if (!(monitor_app = pbx_findapp("Monitor")))
monitor_ok=0; monitor_ok=0;
if((monitor_exec = pbx_builtin_getvar_helper(chan,"AUTO_MONITOR"))) }
if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR")))
pbx_exec(chan, monitor_app, monitor_exec, 1); pbx_exec(chan, monitor_app, monitor_exec, 1);
else if((monitor_exec = pbx_builtin_getvar_helper(peer,"AUTO_MONITOR"))) else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
pbx_exec(peer, monitor_app, monitor_exec, 1); pbx_exec(peer, monitor_app, monitor_exec, 1);
} }
@@ -324,9 +325,9 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
peer->appl = "Bridged Call"; peer->appl = "Bridged Call";
peer->data = chan->name; peer->data = chan->name;
/* copy the userfield from the B-leg to A-leg if applicable */ /* copy the userfield from the B-leg to A-leg if applicable */
if (chan->cdr && peer->cdr && strlen(peer->cdr->userfield)) { if (chan->cdr && peer->cdr && !ast_strlen_zero(peer->cdr->userfield)) {
char tmp[256]; char tmp[256];
if (strlen(chan->cdr->userfield)) { if (!ast_strlen_zero(chan->cdr->userfield)) {
snprintf(tmp, sizeof(tmp), "%s;%s",chan->cdr->userfield, peer->cdr->userfield); snprintf(tmp, sizeof(tmp), "%s;%s",chan->cdr->userfield, peer->cdr->userfield);
ast_cdr_appenduserfield(chan, tmp); ast_cdr_appenduserfield(chan, tmp);
} else } else
@@ -399,21 +400,20 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
if ((f->frametype == AST_FRAME_DTMF) && if ((f->frametype == AST_FRAME_DTMF) &&
((allowredirect_in && who == peer) || (allowredirect_out && who == chan)) && ((allowredirect_in && who == peer) || (allowredirect_out && who == chan)) &&
(f->subclass == '#')) { (f->subclass == '#')) {
if(allowredirect_in && who == peer) { if (allowredirect_in && who == peer) {
transferer = peer; transferer = peer;
transferee = chan; transferee = chan;
} } else {
else {
transferer = chan; transferer = chan;
transferee = peer; transferee = peer;
} }
if(!(transferer_real_context=pbx_builtin_getvar_helper(transferee, "TRANSFER_CONTEXT")) && if (!(transferer_real_context=pbx_builtin_getvar_helper(transferee, "TRANSFER_CONTEXT")) &&
!(transferer_real_context=pbx_builtin_getvar_helper(transferer, "TRANSFER_CONTEXT"))) { !(transferer_real_context=pbx_builtin_getvar_helper(transferer, "TRANSFER_CONTEXT"))) {
/* Use the non-macro context to transfer the call */ /* Use the non-macro context to transfer the call */
if(strlen(transferer->macrocontext)) if (!ast_strlen_zero(transferer->macrocontext))
transferer_real_context=transferer->macrocontext; transferer_real_context = transferer->macrocontext;
else else
transferer_real_context=transferer->context; transferer_real_context = transferer->context;
} }
/* Start autoservice on chan while we talk /* Start autoservice on chan while we talk
to the originator */ to the originator */
@@ -442,7 +442,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
len --; len --;
} }
res = 0; res = 0;
while(strlen(newext) < sizeof(newext) - 1) { while (strlen(newext) < sizeof(newext) - 1) {
res = ast_waitfordigit(transferer, transferdigittimeout); res = ast_waitfordigit(transferer, transferdigittimeout);
if (res < 1) if (res < 1)
break; break;
@@ -470,7 +470,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
the thread dies -- We have to be careful now though. We are responsible for the thread dies -- We have to be careful now though. We are responsible for
hanging up the channel, else it will never be hung up! */ hanging up the channel, else it will never be hung up! */
if(transferer==peer) if (transferer==peer)
res=AST_PBX_KEEPALIVE; res=AST_PBX_KEEPALIVE;
else else
res=AST_PBX_NO_HANGUP_PEER; res=AST_PBX_NO_HANGUP_PEER;
@@ -903,13 +903,13 @@ int load_module(void)
} }
} else if (!strcasecmp(var->name, "adsipark")) { } else if (!strcasecmp(var->name, "adsipark")) {
adsipark = ast_true(var->value); adsipark = ast_true(var->value);
} else if(!strcasecmp(var->name, "transferdigittimeout")) { } else if (!strcasecmp(var->name, "transferdigittimeout")) {
if ((sscanf(var->value, "%d", &transferdigittimeout) != 1) || (transferdigittimeout < 1)) { if ((sscanf(var->value, "%d", &transferdigittimeout) != 1) || (transferdigittimeout < 1)) {
ast_log(LOG_WARNING, "%s is not a valid transferdigittimeout\n", var->value); ast_log(LOG_WARNING, "%s is not a valid transferdigittimeout\n", var->value);
transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT; transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
} else } else
transferdigittimeout = transferdigittimeout * 1000; transferdigittimeout = transferdigittimeout * 1000;
} else if (!strcasecmp(var->name, "courtesytone")) { } else if (!strcasecmp(var->name, "courtesytone")) {
strncpy(courtesytone, var->value, sizeof(courtesytone) - 1); strncpy(courtesytone, var->value, sizeof(courtesytone) - 1);
} }
var = var->next; var = var->next;

View File

@@ -65,35 +65,35 @@ static char *changemonitor_descrip = "ChangeMonitor\n"
/* Start monitoring a channel */ /* Start monitoring a channel */
int ast_monitor_start( struct ast_channel *chan, const char *format_spec, int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
const char *fname_base, int need_lock ) const char *fname_base, int need_lock)
{ {
int res = 0; int res = 0;
char tmp[256]; char tmp[256];
if( need_lock ) { if (need_lock) {
if (ast_mutex_lock(&chan->lock)) { if (ast_mutex_lock(&chan->lock)) {
ast_log(LOG_WARNING, "Unable to lock channel\n"); ast_log(LOG_WARNING, "Unable to lock channel\n");
return -1; return -1;
} }
} }
if( !(chan->monitor) ) { if (!(chan->monitor)) {
struct ast_channel_monitor *monitor; struct ast_channel_monitor *monitor;
char *channel_name, *p; char *channel_name, *p;
/* Create monitoring directory if needed */ /* Create monitoring directory if needed */
if( mkdir( AST_MONITOR_DIR, 0770 ) < 0 ) { if (mkdir(AST_MONITOR_DIR, 0770) < 0) {
if( errno != EEXIST ) { if (errno != EEXIST) {
ast_log(LOG_WARNING, "Unable to create audio monitor directory: %s\n", ast_log(LOG_WARNING, "Unable to create audio monitor directory: %s\n",
strerror( errno ) ); strerror(errno));
} }
} }
monitor = malloc( sizeof( struct ast_channel_monitor ) ); monitor = malloc(sizeof(struct ast_channel_monitor));
memset( monitor, 0, sizeof( struct ast_channel_monitor ) ); memset(monitor, 0, sizeof(struct ast_channel_monitor));
/* Determine file names */ /* Determine file names */
if( fname_base && strlen( fname_base ) ) { if (fname_base && !ast_strlen_zero(fname_base)) {
int directory = strchr(fname_base, '/') ? 1 : 0; int directory = strchr(fname_base, '/') ? 1 : 0;
/* try creating the directory just in case it doesn't exist */ /* try creating the directory just in case it doesn't exist */
if (directory) { if (directory) {
@@ -102,83 +102,83 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
free(name); free(name);
system(tmp); system(tmp);
} }
snprintf( monitor->read_filename, FILENAME_MAX, "%s/%s-in", snprintf(monitor->read_filename, FILENAME_MAX, "%s/%s-in",
directory ? "" : AST_MONITOR_DIR, fname_base ); directory ? "" : AST_MONITOR_DIR, fname_base);
snprintf( monitor->write_filename, FILENAME_MAX, "%s/%s-out", snprintf(monitor->write_filename, FILENAME_MAX, "%s/%s-out",
directory ? "" : AST_MONITOR_DIR, fname_base ); directory ? "" : AST_MONITOR_DIR, fname_base);
strncpy(monitor->filename_base, fname_base, sizeof(monitor->filename_base) - 1); strncpy(monitor->filename_base, fname_base, sizeof(monitor->filename_base) - 1);
} else { } else {
ast_mutex_lock( &monitorlock ); ast_mutex_lock(&monitorlock);
snprintf( monitor->read_filename, FILENAME_MAX, "%s/audio-in-%ld", snprintf(monitor->read_filename, FILENAME_MAX, "%s/audio-in-%ld",
AST_MONITOR_DIR, seq ); AST_MONITOR_DIR, seq);
snprintf( monitor->write_filename, FILENAME_MAX, "%s/audio-out-%ld", snprintf(monitor->write_filename, FILENAME_MAX, "%s/audio-out-%ld",
AST_MONITOR_DIR, seq ); AST_MONITOR_DIR, seq);
seq++; seq++;
ast_mutex_unlock( &monitorlock ); ast_mutex_unlock(&monitorlock);
channel_name = strdup( chan->name ); channel_name = strdup(chan->name);
while( ( p = strchr( channel_name, '/' ) ) ) { while((p = strchr(channel_name, '/'))) {
*p = '-'; *p = '-';
} }
snprintf( monitor->filename_base, FILENAME_MAX, "%s/%s", snprintf(monitor->filename_base, FILENAME_MAX, "%s/%s",
AST_MONITOR_DIR, channel_name ); AST_MONITOR_DIR, channel_name);
monitor->filename_changed = 1; monitor->filename_changed = 1;
free( channel_name ); free(channel_name);
} }
monitor->stop = ast_monitor_stop; monitor->stop = ast_monitor_stop;
// Determine file format // Determine file format
if( format_spec && strlen( format_spec ) ) { if (format_spec && !ast_strlen_zero(format_spec)) {
monitor->format = strdup( format_spec ); monitor->format = strdup(format_spec);
} else { } else {
monitor->format = strdup( "wav" ); monitor->format = strdup("wav");
} }
// open files // open files
if( ast_fileexists( monitor->read_filename, NULL, NULL ) > 0 ) { if (ast_fileexists(monitor->read_filename, NULL, NULL) > 0) {
ast_filedelete( monitor->read_filename, NULL ); ast_filedelete(monitor->read_filename, NULL);
} }
if( !(monitor->read_stream = ast_writefile( monitor->read_filename, if (!(monitor->read_stream = ast_writefile(monitor->read_filename,
monitor->format, NULL, monitor->format, NULL,
O_CREAT|O_TRUNC|O_WRONLY, 0, 0644 ) ) ) { O_CREAT|O_TRUNC|O_WRONLY, 0, 0644))) {
ast_log( LOG_WARNING, "Could not create file %s\n", ast_log(LOG_WARNING, "Could not create file %s\n",
monitor->read_filename ); monitor->read_filename);
free( monitor ); free(monitor);
ast_mutex_unlock(&chan->lock); ast_mutex_unlock(&chan->lock);
return -1; return -1;
} }
if( ast_fileexists( monitor->write_filename, NULL, NULL ) > 0 ) { if (ast_fileexists(monitor->write_filename, NULL, NULL) > 0) {
ast_filedelete( monitor->write_filename, NULL ); ast_filedelete(monitor->write_filename, NULL);
} }
if( !(monitor->write_stream = ast_writefile( monitor->write_filename, if (!(monitor->write_stream = ast_writefile(monitor->write_filename,
monitor->format, NULL, monitor->format, NULL,
O_CREAT|O_TRUNC|O_WRONLY, 0, 0644 ) ) ) { O_CREAT|O_TRUNC|O_WRONLY, 0, 0644))) {
ast_log( LOG_WARNING, "Could not create file %s\n", ast_log(LOG_WARNING, "Could not create file %s\n",
monitor->write_filename ); monitor->write_filename);
ast_closestream( monitor->read_stream ); ast_closestream(monitor->read_stream);
free( monitor ); free(monitor);
ast_mutex_unlock(&chan->lock); ast_mutex_unlock(&chan->lock);
return -1; return -1;
} }
chan->monitor = monitor; chan->monitor = monitor;
} else { } else {
ast_log( LOG_DEBUG,"Cannot start monitoring %s, already monitored\n", ast_log(LOG_DEBUG,"Cannot start monitoring %s, already monitored\n",
chan->name ); chan->name);
res = -1; res = -1;
} }
if( need_lock ) { if (need_lock) {
ast_mutex_unlock(&chan->lock); ast_mutex_unlock(&chan->lock);
} }
return res; return res;
} }
/* Stop monitoring a channel */ /* Stop monitoring a channel */
int ast_monitor_stop( struct ast_channel *chan, int need_lock ) int ast_monitor_stop(struct ast_channel *chan, int need_lock)
{ {
char *execute,*execute_args; char *execute, *execute_args;
int delfiles =0; int delfiles = 0;
if (need_lock) { if (need_lock) {
if (ast_mutex_lock(&chan->lock)) { if (ast_mutex_lock(&chan->lock)) {
@@ -191,35 +191,35 @@ int ast_monitor_stop( struct ast_channel *chan, int need_lock )
char filename[ FILENAME_MAX ]; char filename[ FILENAME_MAX ];
if (chan->monitor->read_stream) { if (chan->monitor->read_stream) {
ast_closestream( chan->monitor->read_stream ); ast_closestream(chan->monitor->read_stream);
} }
if (chan->monitor->write_stream) { if (chan->monitor->write_stream) {
ast_closestream( chan->monitor->write_stream ); ast_closestream(chan->monitor->write_stream);
} }
if (chan->monitor->filename_changed&&strlen(chan->monitor->filename_base)) { if (chan->monitor->filename_changed && !ast_strlen_zero(chan->monitor->filename_base)) {
if (ast_fileexists(chan->monitor->read_filename,NULL,NULL) > 0 ) { if (ast_fileexists(chan->monitor->read_filename,NULL,NULL) > 0) {
snprintf(filename, FILENAME_MAX, "%s-in", chan->monitor->filename_base); snprintf(filename, FILENAME_MAX, "%s-in", chan->monitor->filename_base);
if (ast_fileexists( filename, NULL, NULL ) > 0) { if (ast_fileexists(filename, NULL, NULL) > 0) {
ast_filedelete( filename, NULL ); ast_filedelete(filename, NULL);
} }
ast_filerename(chan->monitor->read_filename, filename, chan->monitor->format ); ast_filerename(chan->monitor->read_filename, filename, chan->monitor->format);
} else { } else {
ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->read_filename ); ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->read_filename);
} }
if (ast_fileexists(chan->monitor->write_filename,NULL,NULL) > 0) { if (ast_fileexists(chan->monitor->write_filename,NULL,NULL) > 0) {
snprintf(filename, FILENAME_MAX, "%s-out", chan->monitor->filename_base ); snprintf(filename, FILENAME_MAX, "%s-out", chan->monitor->filename_base);
if (ast_fileexists(filename, NULL, NULL) > 0 ) { if (ast_fileexists(filename, NULL, NULL) > 0) {
ast_filedelete(filename, NULL); ast_filedelete(filename, NULL);
} }
ast_filerename(chan->monitor->write_filename, filename, chan->monitor->format ); ast_filerename(chan->monitor->write_filename, filename, chan->monitor->format);
} else { } else {
ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->write_filename ); ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->write_filename);
} }
} }
if (chan->monitor->joinfiles && strlen(chan->monitor->filename_base)) { if (chan->monitor->joinfiles && !ast_strlen_zero(chan->monitor->filename_base)) {
char tmp[1024]; char tmp[1024];
char tmp2[1024]; char tmp2[1024];
char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format; char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format;
@@ -228,12 +228,12 @@ int ast_monitor_stop( struct ast_channel *chan, int need_lock )
char *dir = directory ? "" : AST_MONITOR_DIR; char *dir = directory ? "" : AST_MONITOR_DIR;
/* Set the execute application */ /* Set the execute application */
execute=pbx_builtin_getvar_helper(chan,"MONITOR_EXEC"); execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC");
if (!execute || ast_strlen_zero(execute)) { if (!execute || ast_strlen_zero(execute)) {
execute = "nice -n 19 soxmix"; execute = "nice -n 19 soxmix";
delfiles = 1; delfiles = 1;
} }
execute_args = pbx_builtin_getvar_helper(chan,"MONITOR_EXEC_ARGS"); execute_args = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC_ARGS");
if (!execute_args || ast_strlen_zero(execute_args)) { if (!execute_args || ast_strlen_zero(execute_args)) {
execute_args = ""; execute_args = "";
} }
@@ -262,8 +262,8 @@ int ast_monitor_stop( struct ast_channel *chan, int need_lock )
int ast_monitor_change_fname(struct ast_channel *chan, const char *fname_base, int need_lock) int ast_monitor_change_fname(struct ast_channel *chan, const char *fname_base, int need_lock)
{ {
char tmp[256]; char tmp[256];
if ((!fname_base) || (!strlen(fname_base))) { if ((!fname_base) || (ast_strlen_zero(fname_base))) {
ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to null", chan->name ); ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to null", chan->name);
return -1; return -1;
} }
@@ -284,9 +284,9 @@ int ast_monitor_change_fname(struct ast_channel *chan, const char *fname_base, i
system(tmp); system(tmp);
} }
snprintf(chan->monitor->filename_base, FILENAME_MAX, "%s/%s", directory ? "" : AST_MONITOR_DIR, fname_base ); snprintf(chan->monitor->filename_base, FILENAME_MAX, "%s/%s", directory ? "" : AST_MONITOR_DIR, fname_base);
} else { } else {
ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to %s, monitoring not started", chan->name, fname_base ); ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to %s, monitoring not started", chan->name, fname_base);
} }
if (need_lock) if (need_lock)
@@ -307,7 +307,7 @@ static int start_monitor_exec(struct ast_channel *chan, void *data)
int res = 0; int res = 0;
/* Parse arguments. */ /* Parse arguments. */
if (data && strlen((char*)data)) { if (data && !ast_strlen_zero((char*)data)) {
arg = ast_strdupa((char*)data); arg = ast_strdupa((char*)data);
format = arg; format = arg;
fname_base = strchr(arg, '|'); fname_base = strchr(arg, '|');
@@ -320,12 +320,12 @@ static int start_monitor_exec(struct ast_channel *chan, void *data)
if (strchr(options, 'm')) if (strchr(options, 'm'))
joinfiles = 1; joinfiles = 1;
if (strchr(options, 'b')) if (strchr(options, 'b'))
waitforbridge = 1; waitforbridge = 1;
} }
} }
} }
if(waitforbridge) { if (waitforbridge) {
/* We must remove the "b" option if listed. In principle none of /* We must remove the "b" option if listed. In principle none of
the following could give NULL results, but we check just to the following could give NULL results, but we check just to
be pedantic. Reconstructing with checks for 'm' option does not be pedantic. Reconstructing with checks for 'm' option does not
@@ -346,7 +346,7 @@ static int start_monitor_exec(struct ast_channel *chan, void *data)
res = ast_monitor_start(chan, format, fname_base, 1); res = ast_monitor_start(chan, format, fname_base, 1);
if (res < 0) if (res < 0)
res = ast_monitor_change_fname( chan, fname_base, 1 ); res = ast_monitor_change_fname(chan, fname_base, 1);
ast_monitor_setjoinfiles(chan, joinfiles); ast_monitor_setjoinfiles(chan, joinfiles);
return res; return res;
@@ -371,7 +371,7 @@ static int start_monitor_action(struct mansession *s, struct message *m)
char *mix = astman_get_header(m, "Mix"); char *mix = astman_get_header(m, "Mix");
char *d; char *d;
if ((!name)||(!strlen(name))) { if ((!name) || (ast_strlen_zero(name))) {
astman_send_error(s, m, "No channel specified"); astman_send_error(s, m, "No channel specified");
return 0; return 0;
} }
@@ -388,16 +388,16 @@ static int start_monitor_action(struct mansession *s, struct message *m)
return 0; return 0;
} }
if ((!fname) || (!strlen(fname))) { if ((!fname) || (ast_strlen_zero(fname))) {
// No filename base specified, default to channel name as per CLI // No filename base specified, default to channel name as per CLI
fname = malloc (FILENAME_MAX); fname = malloc (FILENAME_MAX);
memset( fname, 0, FILENAME_MAX); memset(fname, 0, FILENAME_MAX);
strncpy( fname, c->name, FILENAME_MAX-1); strncpy(fname, c->name, FILENAME_MAX-1);
// Channels have the format technology/channel_name - have to replace that / // Channels have the format technology/channel_name - have to replace that /
if( (d=strchr( fname, '/')) ) *d='-'; if ((d=strchr(fname, '/'))) *d='-';
} }
if (ast_monitor_start( c, format, fname, 1)) { if (ast_monitor_start(c, format, fname, 1)) {
if (ast_monitor_change_fname(c, fname, 1)) { if (ast_monitor_change_fname(c, fname, 1)) {
astman_send_error(s, m, "Could not start monitoring channel"); astman_send_error(s, m, "Could not start monitoring channel");
ast_mutex_unlock(&c->lock); ast_mutex_unlock(&c->lock);
@@ -406,7 +406,7 @@ static int start_monitor_action(struct mansession *s, struct message *m)
} }
if (ast_true(mix)) { if (ast_true(mix)) {
ast_monitor_setjoinfiles( c, 1); ast_monitor_setjoinfiles(c, 1);
} }
ast_mutex_unlock(&c->lock); ast_mutex_unlock(&c->lock);
@@ -419,7 +419,7 @@ static int stop_monitor_action(struct mansession *s, struct message *m)
struct ast_channel *c = NULL; struct ast_channel *c = NULL;
char *name = astman_get_header(m, "Channel"); char *name = astman_get_header(m, "Channel");
int res; int res;
if ((!name)||(!strlen(name))) { if ((!name) || (ast_strlen_zero(name))) {
astman_send_error(s, m, "No channel specified"); astman_send_error(s, m, "No channel specified");
return 0; return 0;
} }
@@ -450,11 +450,11 @@ static int change_monitor_action(struct mansession *s, struct message *m)
struct ast_channel *c = NULL; struct ast_channel *c = NULL;
char *name = astman_get_header(m, "Channel"); char *name = astman_get_header(m, "Channel");
char *fname = astman_get_header(m, "File"); char *fname = astman_get_header(m, "File");
if ((!name) || (!strlen(name))) { if ((!name) || (ast_strlen_zero(name))) {
astman_send_error(s, m, "No channel specified"); astman_send_error(s, m, "No channel specified");
return 0; return 0;
} }
if ((!fname)||(!strlen(fname))) { if ((!fname)||(ast_strlen_zero(fname))) {
astman_send_error(s, m, "No filename specified"); astman_send_error(s, m, "No filename specified");
return 0; return 0;
} }
@@ -488,20 +488,20 @@ void ast_monitor_setjoinfiles(struct ast_channel *chan, int turnon)
int load_module(void) int load_module(void)
{ {
ast_register_application( "Monitor", start_monitor_exec, monitor_synopsis, monitor_descrip ); ast_register_application("Monitor", start_monitor_exec, monitor_synopsis, monitor_descrip);
ast_register_application( "StopMonitor", stop_monitor_exec, stopmonitor_synopsis, stopmonitor_descrip ); ast_register_application("StopMonitor", stop_monitor_exec, stopmonitor_synopsis, stopmonitor_descrip);
ast_register_application( "ChangeMonitor", change_monitor_exec, changemonitor_synopsis, changemonitor_descrip ); ast_register_application("ChangeMonitor", change_monitor_exec, changemonitor_synopsis, changemonitor_descrip);
ast_manager_register( "Monitor", EVENT_FLAG_CALL, start_monitor_action, monitor_synopsis ); ast_manager_register("Monitor", EVENT_FLAG_CALL, start_monitor_action, monitor_synopsis);
ast_manager_register( "StopMonitor", EVENT_FLAG_CALL, stop_monitor_action, stopmonitor_synopsis ); ast_manager_register("StopMonitor", EVENT_FLAG_CALL, stop_monitor_action, stopmonitor_synopsis);
ast_manager_register( "ChangeMonitor", EVENT_FLAG_CALL, change_monitor_action, changemonitor_synopsis ); ast_manager_register("ChangeMonitor", EVENT_FLAG_CALL, change_monitor_action, changemonitor_synopsis);
return 0; return 0;
} }
int unload_module(void) int unload_module(void)
{ {
ast_unregister_application( "Monitor" ); ast_unregister_application("Monitor");
ast_unregister_application( "StopMonitor" ); ast_unregister_application("StopMonitor");
return 0; return 0;
} }