More formatting cleanups.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3337 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
James Golovich 21 years ago
parent 560068617a
commit 3d0e3d3c0f

@ -209,29 +209,28 @@ int ast_safe_system(const char *s)
*/ */
static void ast_network_puts(const char *string) static void ast_network_puts(const char *string)
{ {
int x; int x;
for (x=0;x<AST_MAX_CONNECTS; x++) { for (x=0;x<AST_MAX_CONNECTS; x++) {
if (consoles[x].fd > -1) if (consoles[x].fd > -1)
fdprint(consoles[x].p[1], string); fdprint(consoles[x].p[1], string);
} }
} }
/* /*
* write the string to the console, and all attached * write the string to the console, and all attached
* console clients * console clients
*/ */
void ast_console_puts(const char *string) void ast_console_puts(const char *string)
{ {
fputs(string, stdout); fputs(string, stdout);
fflush(stdout); fflush(stdout);
ast_network_puts(string); ast_network_puts(string);
} }
static void network_verboser(const char *s, int pos, int replace, int complete) static void network_verboser(const char *s, int pos, int replace, int complete)
/* ARGUSED */ /* ARGUSED */
{ {
ast_network_puts(s); ast_network_puts(s);
} }
static pthread_t lthread; static pthread_t lthread;
@ -840,7 +839,7 @@ static struct ast_cli_entry astbang = { { "!", NULL }, handle_bang, "Execute a s
static int ast_el_read_char(EditLine *el, char *cp) static int ast_el_read_char(EditLine *el, char *cp)
{ {
int num_read=0; int num_read=0;
int lastpos=0; int lastpos=0;
struct pollfd fds[2]; struct pollfd fds[2];
int res; int res;
@ -1065,24 +1064,24 @@ static char *cli_prompt(EditLine *el)
static char **ast_el_strtoarr(char *buf) static char **ast_el_strtoarr(char *buf)
{ {
char **match_list = NULL, *retstr; char **match_list = NULL, *retstr;
size_t match_list_len; size_t match_list_len;
int matches = 0; int matches = 0;
match_list_len = 1; match_list_len = 1;
while ( (retstr = strsep(&buf, " ")) != NULL) { while ( (retstr = strsep(&buf, " ")) != NULL) {
if (!strcmp(retstr, AST_CLI_COMPLETE_EOF)) if (!strcmp(retstr, AST_CLI_COMPLETE_EOF))
break; break;
if (matches + 1 >= match_list_len) { if (matches + 1 >= match_list_len) {
match_list_len <<= 1; match_list_len <<= 1;
match_list = realloc(match_list, match_list_len * sizeof(char *)); match_list = realloc(match_list, match_list_len * sizeof(char *));
} }
match_list[matches++] = strdup(retstr); match_list[matches++] = strdup(retstr);
} }
if (!match_list) if (!match_list)
return (char **) NULL; return (char **) NULL;
if (matches>= match_list_len) if (matches>= match_list_len)
match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *)); match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
@ -1596,8 +1595,8 @@ int main(int argc, char *argv[])
fflush(stdout); fflush(stdout);
/* Test recursive mutex locking. */ /* Test recursive mutex locking. */
if(test_for_thread_safety()) if (test_for_thread_safety())
ast_verbose("Warning! Asterisk is not thread safe.\n"); ast_verbose("Warning! Asterisk is not thread safe.\n");
if (option_console && !option_verbose) if (option_console && !option_verbose)
ast_verbose("[ Reading Master Configuration ]"); ast_verbose("[ Reading Master Configuration ]");
@ -1611,11 +1610,11 @@ int main(int argc, char *argv[])
if (option_console) { if (option_console) {
if (el_hist == NULL || el == NULL) if (el_hist == NULL || el == NULL)
ast_el_initialize(); ast_el_initialize();
if (!ast_strlen_zero(filename)) if (!ast_strlen_zero(filename))
ast_el_read_history(filename); ast_el_read_history(filename);
} }
if (ast_tryconnect()) { if (ast_tryconnect()) {
@ -1768,12 +1767,12 @@ int main(int argc, char *argv[])
consolehandler((char *)buf); consolehandler((char *)buf);
} else { } else {
if (option_remote) if (option_remote)
ast_cli(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n"); ast_cli(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n");
} }
} }
} else { } else {
/* Do nothing */ /* Do nothing */
for(;;) for(;;)
poll(NULL,0, -1); poll(NULL,0, -1);
} }

@ -1469,7 +1469,7 @@ static int do_senddigit(struct ast_channel *chan, char digit)
int ast_senddigit(struct ast_channel *chan, char digit) int ast_senddigit(struct ast_channel *chan, char digit)
{ {
return do_senddigit(chan, digit); return do_senddigit(chan, digit);
} }
int ast_prod(struct ast_channel *chan) int ast_prod(struct ast_channel *chan)

@ -39,8 +39,9 @@ static int syslog_level_map[] = {
LOG_NOTICE, LOG_NOTICE,
LOG_WARNING, LOG_WARNING,
LOG_ERR, LOG_ERR,
LOG_DEBUG LOG_DEBUG
}; };
#define SYSLOG_NLEVELS 6 #define SYSLOG_NLEVELS 6
#include <asterisk/logger.h> #include <asterisk/logger.h>
@ -58,13 +59,13 @@ static struct msglist {
} *list = NULL, *last = NULL; } *list = NULL, *last = NULL;
struct logchannel { struct logchannel {
int logmask; int logmask;
int facility; /* syslog */ int facility; /* syslog */
int syslog; /* syslog flag */ int syslog; /* syslog flag */
int console; /* console logging */ int console; /* console logging */
FILE *fileptr; /* logfile logging */ FILE *fileptr; /* logfile logging */
char filename[256]; char filename[256];
struct logchannel *next; struct logchannel *next;
}; };
static struct logchannel *logchannels = NULL; static struct logchannel *logchannels = NULL;
@ -74,21 +75,21 @@ static int msgcnt = 0;
static FILE *eventlog = NULL; static FILE *eventlog = NULL;
static char *levels[] = { static char *levels[] = {
"DEBUG", "DEBUG",
"EVENT", "EVENT",
"NOTICE", "NOTICE",
"WARNING", "WARNING",
"ERROR", "ERROR",
"VERBOSE" "VERBOSE"
}; };
static int colors[] = { static int colors[] = {
COLOR_BRGREEN, COLOR_BRGREEN,
COLOR_BRBLUE, COLOR_BRBLUE,
COLOR_YELLOW, COLOR_YELLOW,
COLOR_BRRED, COLOR_BRRED,
COLOR_RED, COLOR_RED,
COLOR_GREEN COLOR_GREEN
}; };
static int make_components(char *s, int lineno) static int make_components(char *s, int lineno)
@ -389,10 +390,11 @@ static struct ast_cli_entry rotate_logger_cli =
handle_logger_rotate, "Rotates and reopens the log files", handle_logger_rotate, "Rotates and reopens the log files",
logger_rotate_help }; logger_rotate_help };
static int handle_SIGXFSZ(int sig) { static int handle_SIGXFSZ(int sig)
{
/* Indicate need to reload */ /* Indicate need to reload */
pending_logger_reload = 1; pending_logger_reload = 1;
return 0; return 0;
} }
int init_logger(void) int init_logger(void)
@ -446,23 +448,24 @@ void close_logger(void)
return; return;
} }
static void ast_log_vsyslog(int level, const char *file, int line, const char *function, const char *fmt, va_list args) { static void ast_log_vsyslog(int level, const char *file, int line, const char *function, const char *fmt, va_list args)
char buf[BUFSIZ]; {
char buf[BUFSIZ];
if(level >= SYSLOG_NLEVELS) { if (level >= SYSLOG_NLEVELS) {
/* we are locked here, so cannot ast_log() */ /* we are locked here, so cannot ast_log() */
fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", level); fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", level);
return; return;
} }
if(level == __LOG_VERBOSE) { if (level == __LOG_VERBOSE) {
snprintf(buf, sizeof(buf), "VERBOSE[%ld]: ", (long)pthread_self()); snprintf(buf, sizeof(buf), "VERBOSE[%ld]: ", (long)pthread_self());
level = __LOG_DEBUG; level = __LOG_DEBUG;
} else { } else {
snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: ", snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: ",
levels[level], (long)pthread_self(), file, line, function); levels[level], (long)pthread_self(), file, line, function);
} }
vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, args); vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, args);
syslog(syslog_level_map[level], "%s", buf); syslog(syslog_level_map[level], "%s", buf);
} }
/* /*
@ -470,97 +473,96 @@ static void ast_log_vsyslog(int level, const char *file, int line, const char *f
*/ */
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
{ {
struct logchannel *chan; struct logchannel *chan;
char buf[BUFSIZ]; char buf[BUFSIZ];
time_t t; time_t t;
struct tm tm; struct tm tm;
char date[256]; char date[256];
va_list ap; va_list ap;
if (!option_verbose && !option_debug && (level == __LOG_DEBUG)) { if (!option_verbose && !option_debug && (level == __LOG_DEBUG)) {
return; return;
} }
/* begin critical section */
ast_mutex_lock(&loglock);
time(&t);
localtime_r(&t, &tm);
strftime(date, sizeof(date), dateformat, &tm);
/* begin critical section */
ast_mutex_lock(&loglock);
if (level == __LOG_EVENT) { time(&t);
va_start(ap, fmt); localtime_r(&t, &tm);
strftime(date, sizeof(date), dateformat, &tm);
fprintf(eventlog, "%s asterisk[%d]: ", date, getpid()); if (level == __LOG_EVENT) {
vfprintf(eventlog, fmt, ap); va_start(ap, fmt);
fflush(eventlog);
va_end(ap); fprintf(eventlog, "%s asterisk[%d]: ", date, getpid());
ast_mutex_unlock(&loglock); vfprintf(eventlog, fmt, ap);
return; fflush(eventlog);
}
if (logchannels) {
chan = logchannels;
while(chan) {
if (chan->syslog && (chan->logmask & (1 << level))) {
va_start(ap, fmt);
ast_log_vsyslog(level, file, line, function, fmt, ap);
va_end(ap); va_end(ap);
} else if ((chan->logmask & (1 << level)) && (chan->console)) { ast_mutex_unlock(&loglock);
char linestr[128]; return;
char tmp1[80], tmp2[80], tmp3[80], tmp4[80]; }
if(level != __LOG_VERBOSE) { if (logchannels) {
sprintf(linestr, "%d", line); chan = logchannels;
snprintf(buf, sizeof(buf), "%s %s[%ld]: %s:%s %s: ", while(chan) {
date, if (chan->syslog && (chan->logmask & (1 << level))) {
term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)), va_start(ap, fmt);
(long)pthread_self(), ast_log_vsyslog(level, file, line, function, fmt, ap);
term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)), va_end(ap);
term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)), } else if ((chan->logmask & (1 << level)) && (chan->console)) {
term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4))); char linestr[128];
char tmp1[80], tmp2[80], tmp3[80], tmp4[80];
if (level != __LOG_VERBOSE) {
sprintf(linestr, "%d", line);
snprintf(buf, sizeof(buf), "%s %s[%ld]: %s:%s %s: ",
date,
term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
(long)pthread_self(),
term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
ast_console_puts(buf); ast_console_puts(buf);
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap); vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap); va_end(ap);
ast_console_puts(buf); ast_console_puts(buf);
}
} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
snprintf(buf, sizeof(buf), "%s %s[%ld]: ", date,
levels[level], (long)pthread_self());
fprintf(chan->fileptr, buf);
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
fputs(buf, chan->fileptr);
fflush(chan->fileptr);
}
chan = chan->next;
} }
} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) { } else {
snprintf(buf, sizeof(buf), "%s %s[%ld]: ", date, /*
levels[level], (long)pthread_self()); * we don't have the logger chain configured yet,
fprintf(chan->fileptr, buf); * so just log to stdout
va_start(ap, fmt); */
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
fputs(buf, chan->fileptr);
fflush(chan->fileptr);
}
chan = chan->next;
}
} else {
/*
* we don't have the logger chain configured yet,
* so just log to stdout
*/
if (level != __LOG_VERBOSE) { if (level != __LOG_VERBOSE) {
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap); vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap); va_end(ap);
fputs(buf, stdout); fputs(buf, stdout);
} }
} }
ast_mutex_unlock(&loglock); ast_mutex_unlock(&loglock);
/* end critical section */ /* end critical section */
if (pending_logger_reload) { if (pending_logger_reload) {
reload_logger(1); reload_logger(1);
ast_log(LOG_EVENT,"Rotated Logs Per SIGXFSZ\n"); ast_log(LOG_EVENT,"Rotated Logs Per SIGXFSZ\n");
if (option_verbose) if (option_verbose)
ast_verbose("Rotated Logs Per SIGXFSZ\n"); ast_verbose("Rotated Logs Per SIGXFSZ\n");
} }
} }

@ -306,11 +306,11 @@ int adsi_begin_download(struct ast_channel *chan, char *service, char *fdn, char
int bytes; int bytes;
unsigned char buf[256]; unsigned char buf[256];
char ack[2]; char ack[2];
bytes = 0; bytes = 0;
/* Setup the resident soft key stuff, a piece at a time */ /* Setup the resident soft key stuff, a piece at a time */
/* Upload what scripts we can for voicemail ahead of time */ /* Upload what scripts we can for voicemail ahead of time */
bytes += adsi_download_connect(buf + bytes, service, fdn, sec, version); bytes += adsi_download_connect(buf + bytes, service, fdn, sec, version);
if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD))
return -1; return -1;
if (ast_readstring(chan, ack, 1, 10000, 10000, "")) if (ast_readstring(chan, ack, 1, 10000, 10000, ""))
return -1; return -1;
@ -328,7 +328,7 @@ int adsi_end_download(struct ast_channel *chan)
/* Setup the resident soft key stuff, a piece at a time */ /* Setup the resident soft key stuff, a piece at a time */
/* Upload what scripts we can for voicemail ahead of time */ /* Upload what scripts we can for voicemail ahead of time */
bytes += adsi_download_disconnect(buf + bytes); bytes += adsi_download_disconnect(buf + bytes);
if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) if (adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD))
return -1; return -1;
return 0; return 0;
} }
@ -798,7 +798,7 @@ int adsi_input_control(unsigned char *buf, int page, int line, int display, int
{ {
int bytes=0; int bytes=0;
if (page) { if (page) {
if (line > 4) return -1; if (line > 4) return -1;
} else { } else {
if (line > 33) return -1; if (line > 33) return -1;
@ -857,7 +857,7 @@ int adsi_set_line(unsigned char *buf, int page, int line)
/* Sanity check line number */ /* Sanity check line number */
if (page) { if (page) {
if (line > 4) return -1; if (line > 4) return -1;
} else { } else {
if (line > 33) return -1; if (line > 33) return -1;

@ -172,50 +172,45 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
/* 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; char *execute;
int soxmix =0; int soxmix =0;
if(need_lock) {
if(ast_mutex_lock(&chan->lock)) { if (need_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) {
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&&strlen(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", snprintf(filename, FILENAME_MAX, "%s-in", chan->monitor->filename_base);
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, ast_filerename(chan->monitor->read_filename, filename, chan->monitor->format );
chan->monitor->format );
} else { } else {
ast_log( LOG_WARNING, "File %s not found\n", ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->read_filename );
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", snprintf(filename, FILENAME_MAX, "%s-out", chan->monitor->filename_base );
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, ast_filerename(chan->monitor->write_filename, filename, chan->monitor->format );
chan->monitor->format );
} else { } else {
ast_log( LOG_WARNING, "File %s not found\n", ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->write_filename );
chan->monitor->write_filename );
} }
} }
@ -227,53 +222,49 @@ int ast_monitor_stop( struct ast_channel *chan, int need_lock )
int directory = strchr(name, '/') ? 1 : 0; int directory = strchr(name, '/') ? 1 : 0;
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";
soxmix = 1; soxmix = 1;
} }
snprintf(tmp, sizeof(tmp), "%s %s/%s-in.%s %s/%s-out.%s %s/%s.%s &", execute, dir, name, format, dir, name, format, dir, name, format); snprintf(tmp, sizeof(tmp), "%s %s/%s-in.%s %s/%s-out.%s %s/%s.%s &", execute, dir, name, format, dir, name, format, dir, name, format);
if (soxmix) { if (soxmix) {
snprintf(tmp2,sizeof(tmp2), "( %s& rm -f %s/%s-* ) &",tmp, dir ,name); /* remove legs when done mixing */ snprintf(tmp2,sizeof(tmp2), "( %s& rm -f %s/%s-* ) &",tmp, dir ,name); /* remove legs when done mixing */
strncpy(tmp, tmp2, sizeof(tmp) - 1); strncpy(tmp, tmp2, sizeof(tmp) - 1);
} }
ast_verbose("monitor executing %s\n",tmp); ast_verbose("monitor executing %s\n",tmp);
if (ast_safe_system(tmp) == -1) if (ast_safe_system(tmp) == -1)
ast_log(LOG_WARNING, "Execute of %s failed.\n",tmp); ast_log(LOG_WARNING, "Execute of %s failed.\n",tmp);
} }
free( chan->monitor->format ); free(chan->monitor->format);
free( chan->monitor ); free(chan->monitor);
chan->monitor = NULL; chan->monitor = NULL;
} }
if( need_lock ) { if (need_lock)
ast_mutex_unlock(&chan->lock); ast_mutex_unlock(&chan->lock);
}
return 0; return 0;
} }
/* Change monitoring filename of a channel */ /* Change monitoring filename of a channel */
int ast_monitor_change_fname( struct ast_channel *chan, int ast_monitor_change_fname(struct ast_channel *chan, const char *fname_base, int need_lock)
const char *fname_base, int need_lock )
{ {
char tmp[256]; char tmp[256];
if( (!fname_base) || (!strlen(fname_base)) ) { if ((!fname_base) || (!strlen(fname_base))) {
ast_log( LOG_WARNING, ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to null", chan->name );
"Cannot change monitor filename of channel %s to null",
chan->name );
return -1; return -1;
} }
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) {
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) {
@ -283,18 +274,14 @@ int ast_monitor_change_fname( struct ast_channel *chan,
system(tmp); system(tmp);
} }
snprintf( chan->monitor->filename_base, FILENAME_MAX, "%s/%s", snprintf(chan->monitor->filename_base, FILENAME_MAX, "%s/%s", directory ? "" : AST_MONITOR_DIR, fname_base );
directory ? "" : AST_MONITOR_DIR, fname_base );
} else { } else {
ast_log( LOG_WARNING, ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to %s, monitoring not started", chan->name, fname_base );
"Cannot change monitor filename of channel %s to %s, monitoring not started",
chan->name, fname_base );
} }
if( need_lock ) { if (need_lock)
ast_mutex_unlock(&chan->lock); ast_mutex_unlock(&chan->lock);
}
return 0; return 0;
} }
@ -308,11 +295,11 @@ static int start_monitor_exec(struct ast_channel *chan, void *data)
int res; int res;
/* Parse arguments. */ /* Parse arguments. */
if( data && strlen((char*)data) ) { if (data && strlen((char*)data)) {
arg = strdup( (char*)data ); arg = strdup((char*)data);
format = arg; format = arg;
fname_base = strchr( arg, '|' ); fname_base = strchr(arg, '|');
if( fname_base ) { if (fname_base) {
*fname_base = 0; *fname_base = 0;
fname_base++; fname_base++;
if ((options = strchr(fname_base, '|'))) { if ((options = strchr(fname_base, '|'))) {
@ -325,27 +312,25 @@ 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);
if( arg ) { if (arg)
free( arg ); free( arg );
}
return res; return res;
} }
static int stop_monitor_exec(struct ast_channel *chan, void *data) static int stop_monitor_exec(struct ast_channel *chan, void *data)
{ {
return ast_monitor_stop( chan, 1 ); return ast_monitor_stop(chan, 1);
} }
static int change_monitor_exec(struct ast_channel *chan, void *data) static int change_monitor_exec(struct ast_channel *chan, void *data)
{ {
return ast_monitor_change_fname( chan, (const char*)data, 1 ); return ast_monitor_change_fname(chan, (const char*)data, 1);
} }
static int start_monitor_action(struct mansession *s, struct message *m) static int start_monitor_action(struct mansession *s, struct message *m)
@ -357,12 +342,12 @@ 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)||(!strlen(name))) {
astman_send_error(s, m, "No channel specified"); astman_send_error(s, m, "No channel specified");
return 0; return 0;
} }
c = ast_channel_walk_locked(NULL); c = ast_channel_walk_locked(NULL);
while(c) { while (c) {
if (!strcasecmp(c->name, name)) { if (!strcasecmp(c->name, name)) {
break; break;
} }
@ -373,8 +358,8 @@ static int start_monitor_action(struct mansession *s, struct message *m)
astman_send_error(s, m, "No such channel"); astman_send_error(s, m, "No such channel");
return 0; return 0;
} }
if( (!fname) || (!strlen(fname)) ) { if ((!fname) || (!strlen(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);
@ -383,16 +368,16 @@ static int start_monitor_action(struct mansession *s, struct message *m)
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);
return 0; return 0;
} }
} }
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);
@ -405,7 +390,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)||(!strlen(name))) {
astman_send_error(s, m, "No channel specified"); astman_send_error(s, m, "No channel specified");
return 0; return 0;
} }
@ -421,9 +406,9 @@ static int stop_monitor_action(struct mansession *s, struct message *m)
astman_send_error(s, m, "No such channel"); astman_send_error(s, m, "No such channel");
return 0; return 0;
} }
res = ast_monitor_stop( c, 1 ); res = ast_monitor_stop(c, 1);
ast_mutex_unlock(&c->lock); ast_mutex_unlock(&c->lock);
if( res ) { if (res) {
astman_send_error(s, m, "Could not stop monitoring channel"); astman_send_error(s, m, "Could not stop monitoring channel");
return 0; return 0;
} }
@ -436,7 +421,7 @@ 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) || (!strlen(name))) {
astman_send_error(s, m, "No channel specified"); astman_send_error(s, m, "No channel specified");
return 0; return 0;
} }
@ -456,7 +441,7 @@ static int change_monitor_action(struct mansession *s, struct message *m)
astman_send_error(s, m, "No such channel"); astman_send_error(s, m, "No such channel");
return 0; return 0;
} }
if( ast_monitor_change_fname( c, fname, 1 ) ) { if (ast_monitor_change_fname(c, fname, 1)) {
astman_send_error(s, m, "Could not change monitored filename of channel"); astman_send_error(s, m, "Could not change monitored filename of channel");
ast_mutex_unlock(&c->lock); ast_mutex_unlock(&c->lock);
return 0; return 0;

@ -233,7 +233,7 @@ static void *monmp3thread(void *data)
error_usec = 0; error_usec = 0;
for(;/* ever */;) { for(;/* ever */;) {
/* Spawn mp3 player if it's not there */ /* Spawn mp3 player if it's not there */
if (class->srcfd < 0) { if (class->srcfd < 0) {
if ((class->srcfd = spawn_mp3(class)) < 0) { if ((class->srcfd = spawn_mp3(class)) < 0) {
ast_log(LOG_WARNING, "unable to spawn mp3player\n"); ast_log(LOG_WARNING, "unable to spawn mp3player\n");
/* Try again later */ /* Try again later */
@ -300,7 +300,7 @@ static void *monmp3thread(void *data)
/* Write data */ /* Write data */
if ((res = write(moh->pipe[1], sbuf, res2)) != res2) if ((res = write(moh->pipe[1], sbuf, res2)) != res2)
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Only wrote %d of %d bytes to pipe\n", res, res2); ast_log(LOG_DEBUG, "Only wrote %d of %d bytes to pipe\n", res, res2);
moh = moh->next; moh = moh->next;
} }
ast_mutex_unlock(&moh_lock); ast_mutex_unlock(&moh_lock);

Loading…
Cancel
Save