mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-02 03:48:02 +00:00
Even more minor code cleanup!
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@68920 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
95
main/app.c
95
main/app.c
@@ -81,9 +81,8 @@ int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect,
|
|||||||
timeout = chan->pbx->dtimeout;
|
timeout = chan->pbx->dtimeout;
|
||||||
else if (!timeout)
|
else if (!timeout)
|
||||||
timeout = 5;
|
timeout = 5;
|
||||||
|
|
||||||
ts = ast_get_indication_tone(chan->zone, "dial");
|
if ((ts = ast_get_indication_tone(chan->zone, "dial")) && ts->data[0])
|
||||||
if (ts && ts->data[0])
|
|
||||||
res = ast_playtones_start(chan, 0, ts->data, 0);
|
res = ast_playtones_start(chan, 0, ts->data, 0);
|
||||||
else
|
else
|
||||||
ast_log(LOG_NOTICE,"Huh....? no dial for indications?\n");
|
ast_log(LOG_NOTICE,"Huh....? no dial for indications?\n");
|
||||||
@@ -162,19 +161,21 @@ int ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxl
|
|||||||
|
|
||||||
int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd)
|
int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd)
|
||||||
{
|
{
|
||||||
int res, to, fto;
|
int res, to = 2000, fto = 6000;
|
||||||
if (prompt) {
|
|
||||||
|
if (!ast_strlen_zero(prompt)) {
|
||||||
res = ast_streamfile(c, prompt, c->language);
|
res = ast_streamfile(c, prompt, c->language);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
fto = 6000;
|
|
||||||
to = 2000;
|
|
||||||
if (timeout > 0)
|
if (timeout > 0)
|
||||||
fto = to = timeout;
|
fto = to = timeout;
|
||||||
if (timeout < 0)
|
if (timeout < 0)
|
||||||
fto = to = 1000000000;
|
fto = to = 1000000000;
|
||||||
|
|
||||||
res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd);
|
res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,34 +302,37 @@ struct linear_state {
|
|||||||
static void linear_release(struct ast_channel *chan, void *params)
|
static void linear_release(struct ast_channel *chan, void *params)
|
||||||
{
|
{
|
||||||
struct linear_state *ls = params;
|
struct linear_state *ls = params;
|
||||||
if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt)) {
|
|
||||||
|
if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt))
|
||||||
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, ls->origwfmt);
|
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, ls->origwfmt);
|
||||||
}
|
|
||||||
if (ls->autoclose)
|
if (ls->autoclose)
|
||||||
close(ls->fd);
|
close(ls->fd);
|
||||||
|
|
||||||
ast_free(params);
|
ast_free(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int linear_generator(struct ast_channel *chan, void *data, int len, int samples)
|
static int linear_generator(struct ast_channel *chan, void *data, int len, int samples)
|
||||||
{
|
{
|
||||||
struct ast_frame f;
|
|
||||||
short buf[2048 + AST_FRIENDLY_OFFSET / 2];
|
short buf[2048 + AST_FRIENDLY_OFFSET / 2];
|
||||||
struct linear_state *ls = data;
|
struct linear_state *ls = data;
|
||||||
|
struct ast_frame f = {
|
||||||
|
.frametype = AST_FRAME_VOICE,
|
||||||
|
.subclass = AST_FORMAT_SLINEAR,
|
||||||
|
.data = buf + AST_FRIENDLY_OFFSET / 2,
|
||||||
|
.offset = AST_FRIENDLY_OFFSET,
|
||||||
|
};
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
len = samples * 2;
|
len = samples * 2;
|
||||||
if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
|
if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
|
||||||
ast_log(LOG_WARNING, "Can't generate %d bytes of data!\n" ,len);
|
ast_log(LOG_WARNING, "Can't generate %d bytes of data!\n" ,len);
|
||||||
len = sizeof(buf) - AST_FRIENDLY_OFFSET;
|
len = sizeof(buf) - AST_FRIENDLY_OFFSET;
|
||||||
}
|
}
|
||||||
memset(&f, 0, sizeof(f));
|
|
||||||
res = read(ls->fd, buf + AST_FRIENDLY_OFFSET/2, len);
|
res = read(ls->fd, buf + AST_FRIENDLY_OFFSET/2, len);
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
f.frametype = AST_FRAME_VOICE;
|
|
||||||
f.subclass = AST_FORMAT_SLINEAR;
|
|
||||||
f.data = buf + AST_FRIENDLY_OFFSET/2;
|
|
||||||
f.datalen = res;
|
f.datalen = res;
|
||||||
f.samples = res / 2;
|
f.samples = res / 2;
|
||||||
f.offset = AST_FRIENDLY_OFFSET;
|
|
||||||
ast_write(chan, &f);
|
ast_write(chan, &f);
|
||||||
if (res == len)
|
if (res == len)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -338,21 +342,25 @@ static int linear_generator(struct ast_channel *chan, void *data, int len, int s
|
|||||||
|
|
||||||
static void *linear_alloc(struct ast_channel *chan, void *params)
|
static void *linear_alloc(struct ast_channel *chan, void *params)
|
||||||
{
|
{
|
||||||
struct linear_state *ls;
|
struct linear_state *ls = params;
|
||||||
|
|
||||||
|
if (!params)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* In this case, params is already malloc'd */
|
/* In this case, params is already malloc'd */
|
||||||
if (params) {
|
if (ls->allowoverride)
|
||||||
ls = params;
|
ast_set_flag(chan, AST_FLAG_WRITE_INT);
|
||||||
if (ls->allowoverride)
|
else
|
||||||
ast_set_flag(chan, AST_FLAG_WRITE_INT);
|
ast_clear_flag(chan, AST_FLAG_WRITE_INT);
|
||||||
else
|
|
||||||
ast_clear_flag(chan, AST_FLAG_WRITE_INT);
|
ls->origwfmt = chan->writeformat;
|
||||||
ls->origwfmt = chan->writeformat;
|
|
||||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
|
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
|
||||||
ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name);
|
ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name);
|
||||||
ast_free(ls);
|
ast_free(ls);
|
||||||
ls = params = NULL;
|
ls = params = NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,8 +385,7 @@ int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, in
|
|||||||
ast_copy_string(tmpf, filename, sizeof(tmpf));
|
ast_copy_string(tmpf, filename, sizeof(tmpf));
|
||||||
else
|
else
|
||||||
snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);
|
snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);
|
||||||
fd = open(tmpf, O_RDONLY);
|
if ((fd = open(tmpf, O_RDONLY)) < 0) {
|
||||||
if (fd < 0){
|
|
||||||
ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));
|
ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -515,12 +522,15 @@ int ast_control_streamfile(struct ast_channel *chan, const char *file,
|
|||||||
|
|
||||||
int ast_play_and_wait(struct ast_channel *chan, const char *fn)
|
int ast_play_and_wait(struct ast_channel *chan, const char *fn)
|
||||||
{
|
{
|
||||||
int d;
|
int d = 0;
|
||||||
d = ast_streamfile(chan, fn, chan->language);
|
|
||||||
if (d)
|
if ((d = ast_streamfile(chan, fn, chan->language)))
|
||||||
return d;
|
return d;
|
||||||
|
|
||||||
d = ast_waitstream(chan, AST_DIGIT_ANY);
|
d = ast_waitstream(chan, AST_DIGIT_ANY);
|
||||||
|
|
||||||
ast_stopstream(chan);
|
ast_stopstream(chan);
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1383,21 +1393,22 @@ int ast_ivr_menu_run(struct ast_channel *chan, struct ast_ivr_menu *menu, void *
|
|||||||
|
|
||||||
char *ast_read_textfile(const char *filename)
|
char *ast_read_textfile(const char *filename)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd, count = 0, res;
|
||||||
char *output = NULL;
|
char *output = NULL;
|
||||||
struct stat filesize;
|
struct stat filesize;
|
||||||
int count = 0;
|
|
||||||
int res;
|
|
||||||
if (stat(filename, &filesize) == -1) {
|
if (stat(filename, &filesize) == -1) {
|
||||||
ast_log(LOG_WARNING, "Error can't stat %s\n", filename);
|
ast_log(LOG_WARNING, "Error can't stat %s\n", filename);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = filesize.st_size + 1;
|
count = filesize.st_size + 1;
|
||||||
fd = open(filename, O_RDONLY);
|
|
||||||
if (fd < 0) {
|
if ((fd = open(filename, O_RDONLY)) < 0) {
|
||||||
ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno));
|
ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((output = ast_malloc(count))) {
|
if ((output = ast_malloc(count))) {
|
||||||
res = read(fd, output, count - 1);
|
res = read(fd, output, count - 1);
|
||||||
if (res == count - 1) {
|
if (res == count - 1) {
|
||||||
@@ -1408,17 +1419,17 @@ char *ast_read_textfile(const char *filename)
|
|||||||
output = NULL;
|
output = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
|
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s, *arg;
|
||||||
int curarg;
|
int curarg, res = 0;
|
||||||
unsigned int argloc;
|
unsigned int argloc;
|
||||||
char *arg;
|
|
||||||
int res = 0;
|
|
||||||
|
|
||||||
ast_clear_flag(flags, AST_FLAGS_ALL);
|
ast_clear_flag(flags, AST_FLAGS_ALL);
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,7 @@ static void *autoservice_run(void *ign)
|
|||||||
{
|
{
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct ast_channel *mons[MAX_AUTOMONS];
|
struct ast_channel *mons[MAX_AUTOMONS], *chan;
|
||||||
struct ast_channel *chan;
|
|
||||||
struct asent *as;
|
struct asent *as;
|
||||||
int x = 0, ms = 500;
|
int x = 0, ms = 500;
|
||||||
|
|
||||||
@@ -81,15 +80,16 @@ static void *autoservice_run(void *ign)
|
|||||||
}
|
}
|
||||||
AST_RWLIST_UNLOCK(&aslist);
|
AST_RWLIST_UNLOCK(&aslist);
|
||||||
|
|
||||||
chan = ast_waitfor_n(mons, x, &ms);
|
if ((chan = ast_waitfor_n(mons, x, &ms))) {
|
||||||
if (chan) {
|
|
||||||
/* Read and ignore anything that occurs */
|
/* Read and ignore anything that occurs */
|
||||||
struct ast_frame *f = ast_read(chan);
|
struct ast_frame *f = ast_read(chan);
|
||||||
if (f)
|
if (f)
|
||||||
ast_frfree(f);
|
ast_frfree(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
asthread = AST_PTHREADT_NULL;
|
asthread = AST_PTHREADT_NULL;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,5 +151,6 @@ int ast_autoservice_stop(struct ast_channel *chan)
|
|||||||
/* Wait for it to un-block */
|
/* Wait for it to un-block */
|
||||||
while (ast_test_flag(chan, AST_FLAG_BLOCKING))
|
while (ast_test_flag(chan, AST_FLAG_BLOCKING))
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user