mirror of https://github.com/asterisk/asterisk
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@600 65c4cc65-6c06-0410-ace0-fbb531ad65f31.0
parent
8dd7713d21
commit
6315850d11
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Asterisk -- A telephony toolkit for Linux.
|
||||
*
|
||||
* App to flash a zap trunk
|
||||
*
|
||||
* Copyright (C) 1999, Mark Spencer
|
||||
*
|
||||
* Mark Spencer <markster@linux-support.net>
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License
|
||||
*/
|
||||
|
||||
#include <asterisk/lock.h>
|
||||
#include <asterisk/file.h>
|
||||
#include <asterisk/logger.h>
|
||||
#include <asterisk/channel.h>
|
||||
#include <asterisk/pbx.h>
|
||||
#include <asterisk/module.h>
|
||||
#include <asterisk/translate.h>
|
||||
#include <asterisk/image.h>
|
||||
#include <asterisk/options.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/zaptel.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static char *tdesc = "Flash zap trunk application";
|
||||
|
||||
static char *app = "Flash";
|
||||
|
||||
static char *synopsis = "Flashes a Zap Trunk";
|
||||
|
||||
static char *descrip =
|
||||
" Flash(): Sends a flash on a zap trunk. This is only a hack for\n"
|
||||
"people who want to perform transfers and such via AGI and is generally\n"
|
||||
"quite useless otherwise. Returns 0 on success or -1 if this is not\n"
|
||||
"a zap trunk\n";
|
||||
|
||||
STANDARD_LOCAL_USER;
|
||||
|
||||
LOCAL_USER_DECL;
|
||||
|
||||
static inline int zt_wait_event(int fd)
|
||||
{
|
||||
/* Avoid the silly zt_waitevent which ignores a bunch of events */
|
||||
int i,j=0;
|
||||
i = ZT_IOMUX_SIGEVENT;
|
||||
if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
|
||||
if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
|
||||
return j;
|
||||
}
|
||||
|
||||
static int flash_exec(struct ast_channel *chan, void *data)
|
||||
{
|
||||
int res = -1;
|
||||
int x;
|
||||
struct localuser *u;
|
||||
struct zt_params ztp;
|
||||
LOCAL_USER_ADD(u);
|
||||
if (!strcasecmp(chan->type, "Zap")) {
|
||||
memset(&ztp, 0, sizeof(ztp));
|
||||
res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
|
||||
if (!res) {
|
||||
if (ztp.sigtype & __ZT_SIG_FXS) {
|
||||
x = ZT_FLASH;
|
||||
res = ioctl(chan->fds[0], ZT_HOOK, &x);
|
||||
if (!res || (errno == EINPROGRESS)) {
|
||||
if (res) {
|
||||
/* Wait for the event to finish */
|
||||
zt_wait_event(chan->fds[0]);
|
||||
}
|
||||
res = ast_safe_sleep(chan, 1000);
|
||||
if (option_verbose > 2)
|
||||
ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
|
||||
} else
|
||||
ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
|
||||
} else
|
||||
ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
|
||||
LOCAL_USER_REMOVE(u);
|
||||
return res;
|
||||
}
|
||||
|
||||
int unload_module(void)
|
||||
{
|
||||
STANDARD_HANGUP_LOCALUSERS;
|
||||
return ast_unregister_application(app);
|
||||
}
|
||||
|
||||
int load_module(void)
|
||||
{
|
||||
return ast_register_application(app, flash_exec, synopsis, descrip);
|
||||
}
|
||||
|
||||
char *description(void)
|
||||
{
|
||||
return tdesc;
|
||||
}
|
||||
|
||||
int usecount(void)
|
||||
{
|
||||
int res;
|
||||
STANDARD_USECOUNT(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
char *key()
|
||||
{
|
||||
return ASTERISK_GPL_KEY;
|
||||
}
|
@ -0,0 +1,305 @@
|
||||
/*
|
||||
* Asterisk -- A telephony toolkit for Linux.
|
||||
*
|
||||
* Zap Barge support
|
||||
*
|
||||
* Copyright (C) 2003, Digium
|
||||
*
|
||||
* Mark Spencer <markster@digium.com>
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License
|
||||
*
|
||||
* Special thanks to comphealth.com for sponsoring this
|
||||
* GPL application.
|
||||
*/
|
||||
|
||||
#include <asterisk/lock.h>
|
||||
#include <asterisk/file.h>
|
||||
#include <asterisk/logger.h>
|
||||
#include <asterisk/channel.h>
|
||||
#include <asterisk/pbx.h>
|
||||
#include <asterisk/module.h>
|
||||
#include <asterisk/config.h>
|
||||
#include <asterisk/app.h>
|
||||
#include <asterisk/options.h>
|
||||
#include <asterisk/cli.h>
|
||||
#include <asterisk/say.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <linux/zaptel.h>
|
||||
static char *tdesc = "Barge in on Zap channel application";
|
||||
|
||||
static char *app = "ZapBarge";
|
||||
|
||||
static char *synopsis = "Barge in (monitor) Zap channel";
|
||||
|
||||
static char *descrip =
|
||||
" ZapBarge([channel]): Barges in on a specified zap\n"
|
||||
"channel or prompts if one is not specified. Returns\n"
|
||||
"-1 when caller user hangs up and is independent of the\n"
|
||||
"state of the channel being monitored.";
|
||||
|
||||
|
||||
STANDARD_LOCAL_USER;
|
||||
|
||||
LOCAL_USER_DECL;
|
||||
|
||||
|
||||
#define CONF_SIZE 160
|
||||
|
||||
static int careful_write(int fd, unsigned char *data, int len)
|
||||
{
|
||||
int res;
|
||||
while(len) {
|
||||
res = write(fd, data, len);
|
||||
if (res < 1) {
|
||||
if (errno != EAGAIN) {
|
||||
ast_log(LOG_WARNING, "Failed to write audio data to conference: %s\n", strerror(errno));
|
||||
return -1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
len -= res;
|
||||
data += res;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int conf_run(struct ast_channel *chan, int confno, int confflags)
|
||||
{
|
||||
int fd;
|
||||
struct zt_confinfo ztc;
|
||||
struct ast_frame *f;
|
||||
struct ast_channel *c;
|
||||
struct ast_frame fr;
|
||||
int outfd;
|
||||
int ms;
|
||||
int nfds;
|
||||
int res;
|
||||
int flags;
|
||||
int retryzap;
|
||||
int origfd;
|
||||
int ret = -1;
|
||||
|
||||
ZT_BUFFERINFO bi;
|
||||
char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
|
||||
char *buf = __buf + AST_FRIENDLY_OFFSET;
|
||||
|
||||
/* Set it into U-law mode (write) */
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
|
||||
/* Set it into U-law mode (read) */
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
ast_indicate(chan, -1);
|
||||
retryzap = strcasecmp(chan->type, "Zap");
|
||||
zapretry:
|
||||
origfd = chan->fds[0];
|
||||
if (retryzap) {
|
||||
fd = open("/dev/zap/pseudo", O_RDWR);
|
||||
if (fd < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
|
||||
goto outrun;
|
||||
}
|
||||
/* Make non-blocking */
|
||||
flags = fcntl(fd, F_GETFL);
|
||||
if (flags < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to get flags: %s\n", strerror(errno));
|
||||
close(fd);
|
||||
goto outrun;
|
||||
}
|
||||
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
|
||||
ast_log(LOG_WARNING, "Unable to set flags: %s\n", strerror(errno));
|
||||
close(fd);
|
||||
goto outrun;
|
||||
}
|
||||
/* Setup buffering information */
|
||||
memset(&bi, 0, sizeof(bi));
|
||||
bi.bufsize = CONF_SIZE;
|
||||
bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
|
||||
bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
|
||||
bi.numbufs = 4;
|
||||
if (ioctl(fd, ZT_SET_BUFINFO, &bi)) {
|
||||
ast_log(LOG_WARNING, "Unable to set buffering information: %s\n", strerror(errno));
|
||||
close(fd);
|
||||
goto outrun;
|
||||
}
|
||||
nfds = 1;
|
||||
} else {
|
||||
/* XXX Make sure we're not running on a pseudo channel XXX */
|
||||
fd = chan->fds[0];
|
||||
nfds = 0;
|
||||
}
|
||||
memset(&ztc, 0, sizeof(ztc));
|
||||
/* Check to see if we're in a conference... */
|
||||
ztc.chan = 0;
|
||||
if (ioctl(fd, ZT_GETCONF, &ztc)) {
|
||||
ast_log(LOG_WARNING, "Error getting conference\n");
|
||||
close(fd);
|
||||
goto outrun;
|
||||
}
|
||||
if (ztc.confmode) {
|
||||
/* Whoa, already in a conference... Retry... */
|
||||
if (!retryzap) {
|
||||
ast_log(LOG_DEBUG, "Zap channel is in a conference already, retrying with pseudo\n");
|
||||
retryzap = 1;
|
||||
goto zapretry;
|
||||
}
|
||||
}
|
||||
memset(&ztc, 0, sizeof(ztc));
|
||||
/* Add us to the conference */
|
||||
ztc.chan = 0;
|
||||
ztc.confno = confno;
|
||||
ztc.confmode = ZT_CONF_MONITORBOTH;
|
||||
|
||||
if (ioctl(fd, ZT_SETCONF, &ztc)) {
|
||||
ast_log(LOG_WARNING, "Error setting conference\n");
|
||||
close(fd);
|
||||
goto outrun;
|
||||
}
|
||||
ast_log(LOG_DEBUG, "Placed channel %s in ZAP channel %d monitor\n", chan->name, confno);
|
||||
|
||||
for(;;) {
|
||||
outfd = -1;
|
||||
ms = -1;
|
||||
c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
|
||||
if (c) {
|
||||
if (c->fds[0] != origfd) {
|
||||
if (retryzap) {
|
||||
/* Kill old pseudo */
|
||||
close(fd);
|
||||
}
|
||||
ast_log(LOG_DEBUG, "Ooh, something swapped out under us, starting over\n");
|
||||
retryzap = 0;
|
||||
goto zapretry;
|
||||
}
|
||||
f = ast_read(c);
|
||||
if (!f)
|
||||
break;
|
||||
if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) {
|
||||
ret = 0;
|
||||
break;
|
||||
} else if (fd != chan->fds[0]) {
|
||||
if (f->frametype == AST_FRAME_VOICE) {
|
||||
if (f->subclass == AST_FORMAT_ULAW) {
|
||||
/* Carefully write */
|
||||
careful_write(fd, f->data, f->datalen);
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Huh? Got a non-ulaw (%d) frame in the conference\n", f->subclass);
|
||||
}
|
||||
}
|
||||
ast_frfree(f);
|
||||
} else if (outfd > -1) {
|
||||
res = read(outfd, buf, CONF_SIZE);
|
||||
if (res > 0) {
|
||||
memset(&fr, 0, sizeof(fr));
|
||||
fr.frametype = AST_FRAME_VOICE;
|
||||
fr.subclass = AST_FORMAT_ULAW;
|
||||
fr.datalen = res;
|
||||
fr.samples = res;
|
||||
fr.data = buf;
|
||||
fr.offset = AST_FRIENDLY_OFFSET;
|
||||
if (ast_write(chan, &fr) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
|
||||
/* break; */
|
||||
}
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
if (fd != chan->fds[0])
|
||||
close(fd);
|
||||
else {
|
||||
/* Take out of conference */
|
||||
/* Add us to the conference */
|
||||
ztc.chan = 0;
|
||||
ztc.confno = 0;
|
||||
ztc.confmode = 0;
|
||||
if (ioctl(fd, ZT_SETCONF, &ztc)) {
|
||||
ast_log(LOG_WARNING, "Error setting conference\n");
|
||||
}
|
||||
}
|
||||
|
||||
outrun:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int conf_exec(struct ast_channel *chan, void *data)
|
||||
{
|
||||
int res=-1;
|
||||
struct localuser *u;
|
||||
int retrycnt = 0;
|
||||
int confflags = 0;
|
||||
int confno = 0;
|
||||
char confstr[80];
|
||||
|
||||
if (data && strlen(data)) {
|
||||
if ((sscanf(data, "Zap/%d", &confno) != 1) &&
|
||||
(sscanf(data, "%d", &confno) != 1)) {
|
||||
ast_log(LOG_WARNING, "ZapBarge Argument (if specified) must be a channel number, not '%s'\n", (char *)data);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
LOCAL_USER_ADD(u);
|
||||
if (chan->_state != AST_STATE_UP)
|
||||
ast_answer(chan);
|
||||
|
||||
while(!confno && (++retrycnt < 4)) {
|
||||
/* Prompt user for conference number */
|
||||
strcpy(confstr, "");
|
||||
res = ast_app_getdata(chan, "conf-getchannel",confstr, sizeof(confstr) - 1, 0);
|
||||
if (res <0) goto out;
|
||||
if (sscanf(confstr, "%d", &confno) != 1)
|
||||
confno = 0;
|
||||
}
|
||||
if (confno) {
|
||||
/* XXX Should prompt user for pin if pin is required XXX */
|
||||
/* Run the conference */
|
||||
res = conf_run(chan, confno, confflags);
|
||||
}
|
||||
out:
|
||||
/* Do the conference */
|
||||
LOCAL_USER_REMOVE(u);
|
||||
return res;
|
||||
}
|
||||
|
||||
int unload_module(void)
|
||||
{
|
||||
STANDARD_HANGUP_LOCALUSERS;
|
||||
return ast_unregister_application(app);
|
||||
}
|
||||
|
||||
int load_module(void)
|
||||
{
|
||||
return ast_register_application(app, conf_exec, synopsis, descrip);
|
||||
}
|
||||
|
||||
char *description(void)
|
||||
{
|
||||
return tdesc;
|
||||
}
|
||||
|
||||
int usecount(void)
|
||||
{
|
||||
int res;
|
||||
STANDARD_USECOUNT(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
char *key()
|
||||
{
|
||||
return ASTERISK_GPL_KEY;
|
||||
}
|
@ -0,0 +1,470 @@
|
||||
/*
|
||||
* Asterisk -- A telephony toolkit for Linux.
|
||||
*
|
||||
* Tone Management
|
||||
*
|
||||
* Copyright (C) 2002, Pauline Middelink
|
||||
*
|
||||
* Pauline Middelink <middelink@polyware.nl>
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License
|
||||
*
|
||||
* This set of function allow us to play a list of tones on a channel.
|
||||
* Each element has two frequencies, which are mixed together and a
|
||||
* duration. For silence both frequencies can be set to 0.
|
||||
* The playtones can be given as a comma seperated string.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <math.h> /* For PI */
|
||||
#include <asterisk/indications.h>
|
||||
#include <asterisk/frame.h>
|
||||
#include <asterisk/options.h>
|
||||
#include <asterisk/channel.h>
|
||||
#include <asterisk/logger.h>
|
||||
|
||||
#define PTHREAD_MUTEX_LOCK(a) ast_pthread_mutex_lock(a)
|
||||
#define PTHREAD_MUTEX_UNLOCK(a) ast_pthread_mutex_unlock(a)
|
||||
|
||||
struct playtones_item {
|
||||
int freq1;
|
||||
int freq2;
|
||||
int duration;
|
||||
};
|
||||
|
||||
struct playtones_def {
|
||||
int vol;
|
||||
int reppos;
|
||||
int nitems;
|
||||
struct playtones_item *items;
|
||||
};
|
||||
|
||||
struct playtones_state {
|
||||
int vol;
|
||||
int reppos;
|
||||
int nitems;
|
||||
struct playtones_item *items;
|
||||
int npos;
|
||||
int pos;
|
||||
int origwfmt;
|
||||
struct ast_frame f;
|
||||
short data[4000];
|
||||
};
|
||||
|
||||
static void playtones_release(struct ast_channel *chan, void *params)
|
||||
{
|
||||
struct playtones_state *ps = params;
|
||||
if (chan) {
|
||||
ast_set_write_format(chan, ps->origwfmt);
|
||||
}
|
||||
if (ps->items) free(ps->items);
|
||||
free(ps);
|
||||
}
|
||||
|
||||
static void * playtones_alloc(struct ast_channel *chan, void *params)
|
||||
{
|
||||
struct playtones_def *pd = params;
|
||||
struct playtones_state *ps = malloc(sizeof(struct playtones_state));
|
||||
if (!ps)
|
||||
return NULL;
|
||||
memset(ps, 0, sizeof(struct playtones_state));
|
||||
ps->origwfmt = chan->writeformat;
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
|
||||
playtones_release(NULL, ps);
|
||||
ps = NULL;
|
||||
} else {
|
||||
ps->vol = pd->vol;
|
||||
ps->reppos = pd->reppos;
|
||||
ps->nitems = pd->nitems;
|
||||
ps->items = pd->items;
|
||||
}
|
||||
/* Let interrupts interrupt :) */
|
||||
chan->writeinterrupt = 1;
|
||||
return ps;
|
||||
}
|
||||
|
||||
static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
|
||||
{
|
||||
struct playtones_state *ps = data;
|
||||
struct playtones_item *pi;
|
||||
int x;
|
||||
/* we need to prepare a frame with 16 * timelen samples as we're
|
||||
* generating SLIN audio
|
||||
*/
|
||||
len = samples * 2;
|
||||
if (len > sizeof(ps->data) / 2 - 1) {
|
||||
ast_log(LOG_WARNING, "Can't generate that much data!\n");
|
||||
return -1;
|
||||
}
|
||||
memset(&ps->f, 0, sizeof(ps->f));
|
||||
|
||||
pi = &ps->items[ps->npos];
|
||||
for (x=0;x<len/2;x++) {
|
||||
ps->data[x] = ps->vol * (
|
||||
sin((pi->freq1 * 2.0 * M_PI / 8000.0) * (ps->pos + x)) +
|
||||
sin((pi->freq2 * 2.0 * M_PI / 8000.0) * (ps->pos + x))
|
||||
);
|
||||
}
|
||||
ps->f.frametype = AST_FRAME_VOICE;
|
||||
ps->f.subclass = AST_FORMAT_SLINEAR;
|
||||
ps->f.datalen = len;
|
||||
ps->f.samples = samples;
|
||||
ps->f.offset = AST_FRIENDLY_OFFSET;
|
||||
ps->f.data = ps->data;
|
||||
ast_write(chan, &ps->f);
|
||||
|
||||
ps->pos += x;
|
||||
if (pi->duration && ps->pos >= pi->duration * 8) { /* item finished? */
|
||||
ps->pos = 0; /* start new item */
|
||||
ps->npos++;
|
||||
if (ps->npos >= ps->nitems) { /* last item? */
|
||||
if (ps->reppos == -1) /* repeat set? */
|
||||
return -1;
|
||||
ps->npos = ps->reppos; /* redo from top */
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ast_generator playtones = {
|
||||
alloc: playtones_alloc,
|
||||
release: playtones_release,
|
||||
generate: playtones_generator,
|
||||
};
|
||||
|
||||
int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst)
|
||||
{
|
||||
char *s, *data = strdupa(playlst); /* cute */
|
||||
struct playtones_def d = { vol, -1, 0, NULL};
|
||||
char *stringp=NULL;
|
||||
if (!data)
|
||||
return -1;
|
||||
if (vol < 1)
|
||||
d.vol = 8192;
|
||||
|
||||
stringp=data;
|
||||
s = strsep(&stringp,",");
|
||||
while(s && *s) {
|
||||
int freq1, freq2, time;
|
||||
|
||||
if (s[0]=='!')
|
||||
s++;
|
||||
else if (d.reppos == -1)
|
||||
d.reppos = d.nitems;
|
||||
|
||||
if (sscanf(s, "%d+%d/%d", &freq1, &freq2, &time) == 3) {
|
||||
/* f1+f2/time format */
|
||||
} else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) {
|
||||
/* f1+f2 format */
|
||||
time = 0;
|
||||
} else if (sscanf(s, "%d/%d", &freq1, &time) == 2) {
|
||||
/* f1/time format */
|
||||
freq2 = 0;
|
||||
} else if (sscanf(s, "%d", &freq1) == 1) {
|
||||
/* f1 format */
|
||||
freq2 = 0;
|
||||
time = 0;
|
||||
} else {
|
||||
ast_log(LOG_WARNING,"%s: tone component '%s' of '%s' is no good\n",chan->name,s,playlst);
|
||||
return -1;
|
||||
}
|
||||
|
||||
d.items = realloc(d.items,(d.nitems+1)*sizeof(struct playtones_item));
|
||||
if (d.items == NULL)
|
||||
return -1;
|
||||
d.items[d.nitems].freq1 = freq1;
|
||||
d.items[d.nitems].freq2 = freq2;
|
||||
d.items[d.nitems].duration = time;
|
||||
d.nitems++;
|
||||
|
||||
s = strsep(&stringp,",");
|
||||
}
|
||||
|
||||
if (ast_activate_generator(chan, &playtones, &d)) {
|
||||
free(d.items);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ast_playtones_stop(struct ast_channel *chan)
|
||||
{
|
||||
ast_deactivate_generator(chan);
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
|
||||
struct tone_zone *tone_zones;
|
||||
static struct tone_zone *current_tonezone;
|
||||
|
||||
/* Protect the tone_zones list (highly unlikely that two things would change
|
||||
* it at the same time, but still! */
|
||||
pthread_mutex_t tzlock = AST_MUTEX_INITIALIZER;
|
||||
|
||||
/* Set global indication country */
|
||||
int ast_set_indication_country(const char *country)
|
||||
{
|
||||
if (country) {
|
||||
struct tone_zone *z = ast_get_indication_zone(country);
|
||||
if (z) {
|
||||
ast_verbose(VERBOSE_PREFIX_3 "Setting default indication country to '%s'\n",country);
|
||||
current_tonezone = z;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1; /* not found */
|
||||
}
|
||||
|
||||
/* locate tone_zone, given the country. if country == NULL, use the default country */
|
||||
struct tone_zone *ast_get_indication_zone(const char *country)
|
||||
{
|
||||
struct tone_zone *tz;
|
||||
int alias_loop = 0;
|
||||
|
||||
/* we need some tonezone, pick the first */
|
||||
if (country == NULL && current_tonezone)
|
||||
return current_tonezone; /* default country? */
|
||||
if (country == NULL && tone_zones)
|
||||
return tone_zones; /* any country? */
|
||||
if (country == NULL)
|
||||
return 0; /* not a single country insight */
|
||||
|
||||
if (PTHREAD_MUTEX_LOCK(&tzlock)) {
|
||||
ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
|
||||
return 0;
|
||||
}
|
||||
do {
|
||||
for (tz=tone_zones; tz; tz=tz->next) {
|
||||
if (strcasecmp(country,tz->country)==0) {
|
||||
/* tone_zone found */
|
||||
if (tz->alias && tz->alias[0]) {
|
||||
country = tz->alias;
|
||||
break;
|
||||
}
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return tz;
|
||||
}
|
||||
}
|
||||
} while (++alias_loop<20 && tz);
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
if (alias_loop==20)
|
||||
ast_log(LOG_NOTICE,"Alias loop for '%s' forcefull broken\n",country);
|
||||
/* nothing found, sorry */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* locate a tone_zone_sound, given the tone_zone. if tone_zone == NULL, use the default tone_zone */
|
||||
struct tone_zone_sound *ast_get_indication_tone(const struct tone_zone *zone, const char *indication)
|
||||
{
|
||||
struct tone_zone_sound *ts;
|
||||
|
||||
/* we need some tonezone, pick the first */
|
||||
if (zone == NULL && current_tonezone)
|
||||
zone = current_tonezone; /* default country? */
|
||||
if (zone == NULL && tone_zones)
|
||||
zone = tone_zones; /* any country? */
|
||||
if (zone == NULL)
|
||||
return 0; /* not a single country insight */
|
||||
|
||||
if (PTHREAD_MUTEX_LOCK(&tzlock)) {
|
||||
ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
|
||||
return 0;
|
||||
}
|
||||
for (ts=zone->tones; ts; ts=ts->next) {
|
||||
if (strcasecmp(indication,ts->name)==0) {
|
||||
/* found indication! */
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
/* nothing found, sorry */
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* helper function to delete a tone_zone in its entirety */
|
||||
static inline void free_zone(struct tone_zone* zone)
|
||||
{
|
||||
while (zone->tones) {
|
||||
struct tone_zone_sound *tmp = zone->tones->next;
|
||||
free((void*)zone->tones->name);
|
||||
free((void*)zone->tones->data);
|
||||
free(zone->tones);
|
||||
zone->tones = tmp;
|
||||
}
|
||||
free(zone);
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
|
||||
/* add a new country, if country exists, it will be replaced. */
|
||||
int ast_register_indication_country(struct tone_zone *zone)
|
||||
{
|
||||
struct tone_zone *tz,*pz;
|
||||
|
||||
if (PTHREAD_MUTEX_LOCK(&tzlock)) {
|
||||
ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
|
||||
return -1;
|
||||
}
|
||||
for (pz=NULL,tz=tone_zones; tz; pz=tz,tz=tz->next) {
|
||||
if (strcasecmp(zone->country,tz->country)==0) {
|
||||
/* tone_zone already there, replace */
|
||||
zone->next = tz->next;
|
||||
if (pz)
|
||||
pz->next = zone;
|
||||
else
|
||||
tone_zones = zone;
|
||||
/* if we are replacing the default zone, re-point it */
|
||||
if (tz == current_tonezone)
|
||||
current_tonezone = zone;
|
||||
/* now free the previous zone */
|
||||
free_zone(tz);
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* country not there, add */
|
||||
zone->next = NULL;
|
||||
if (pz)
|
||||
pz->next = zone;
|
||||
else
|
||||
tone_zones = zone;
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
|
||||
ast_verbose(VERBOSE_PREFIX_3 "Registered indication country '%s'\n",zone->country);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* remove an existing country and all its indications, country must exist.
|
||||
* Also, all countries which are an alias for the specified country are removed. */
|
||||
int ast_unregister_indication_country(const char *country)
|
||||
{
|
||||
struct tone_zone *tz, *pz = NULL, *tmp;
|
||||
int res = -1;
|
||||
|
||||
if (PTHREAD_MUTEX_LOCK(&tzlock)) {
|
||||
ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
|
||||
return -1;
|
||||
}
|
||||
tz = tone_zones;
|
||||
while (tz) {
|
||||
if (country==NULL ||
|
||||
(strcasecmp(country, tz->country)==0 ||
|
||||
strcasecmp(country, tz->alias)==0)) {
|
||||
/* tone_zone found, remove */
|
||||
tmp = tz->next;
|
||||
if (pz)
|
||||
pz->next = tmp;
|
||||
else
|
||||
tone_zones = tmp;
|
||||
/* if we are unregistering the default country, w'll notice */
|
||||
if (tz == current_tonezone) {
|
||||
ast_log(LOG_NOTICE,"Removed default indication country '%s'\n",tz->country);
|
||||
current_tonezone = NULL;
|
||||
}
|
||||
ast_verbose(VERBOSE_PREFIX_3 "Unregistered indication country '%s'\n",tz->country);
|
||||
free_zone(tz);
|
||||
tz = tmp;
|
||||
res = 0;
|
||||
}
|
||||
else {
|
||||
/* next zone please */
|
||||
pz = tz;
|
||||
tz = tz->next;
|
||||
}
|
||||
}
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* add a new indication to a tone_zone. tone_zone must exist. if the indication already
|
||||
* exists, it will be replaced. */
|
||||
int ast_register_indication(struct tone_zone *zone, const char *indication, const char *tonelist)
|
||||
{
|
||||
struct tone_zone_sound *ts,*ps;
|
||||
|
||||
/* is it an alias? stop */
|
||||
if (zone->alias[0])
|
||||
return -1;
|
||||
|
||||
if (PTHREAD_MUTEX_LOCK(&tzlock)) {
|
||||
ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
|
||||
return -2;
|
||||
}
|
||||
for (ps=NULL,ts=zone->tones; ts; ps=ts,ts=ts->next) {
|
||||
if (strcasecmp(indication,ts->name)==0) {
|
||||
/* indication already there, replace */
|
||||
free((void*)ts->name);
|
||||
free((void*)ts->data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ts) {
|
||||
/* not there, we have to add */
|
||||
ts = malloc(sizeof(struct tone_zone_sound));
|
||||
if (!ts) {
|
||||
ast_log(LOG_WARNING, "Out of memory\n");
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return -2;
|
||||
}
|
||||
ts->next = NULL;
|
||||
}
|
||||
ts->name = strdup(indication);
|
||||
ts->data = strdup(tonelist);
|
||||
if (ts->name==NULL || ts->data==NULL) {
|
||||
ast_log(LOG_WARNING, "Out of memory\n");
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return -2;
|
||||
}
|
||||
if (ps)
|
||||
ps->next = ts;
|
||||
else
|
||||
zone->tones = ts;
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* remove an existing country's indication. Both country and indication must exist */
|
||||
int ast_unregister_indication(struct tone_zone *zone, const char *indication)
|
||||
{
|
||||
struct tone_zone_sound *ts,*ps = NULL, *tmp;
|
||||
int res = -1;
|
||||
|
||||
/* is it an alias? stop */
|
||||
if (zone->alias[0])
|
||||
return -1;
|
||||
|
||||
if (PTHREAD_MUTEX_LOCK(&tzlock)) {
|
||||
ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
|
||||
return -1;
|
||||
}
|
||||
ts = zone->tones;
|
||||
while (ts) {
|
||||
if (strcasecmp(indication,ts->name)==0) {
|
||||
/* indication found */
|
||||
tmp = ts->next;
|
||||
if (ps)
|
||||
ps->next = tmp;
|
||||
else
|
||||
zone->tones = tmp;
|
||||
free((void*)ts->name);
|
||||
free((void*)ts->data);
|
||||
free(ts);
|
||||
ts = tmp;
|
||||
res = 0;
|
||||
}
|
||||
else {
|
||||
/* next zone please */
|
||||
ps = ts;
|
||||
ts = ts->next;
|
||||
}
|
||||
}
|
||||
/* indication not found, goodbye */
|
||||
PTHREAD_MUTEX_UNLOCK(&tzlock);
|
||||
return res;
|
||||
}
|
@ -0,0 +1,365 @@
|
||||
/*
|
||||
* Asterisk -- A telephony toolkit for Linux.
|
||||
*
|
||||
* Full-featured outgoing call spool support
|
||||
*
|
||||
* Copyright (C) 2002, Digium
|
||||
*
|
||||
* Mark Spencer <markster@digium.com>
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License
|
||||
*/
|
||||
|
||||
#include <asterisk/lock.h>
|
||||
#include <asterisk/file.h>
|
||||
#include <asterisk/logger.h>
|
||||
#include <asterisk/channel.h>
|
||||
#include <asterisk/pbx.h>
|
||||
#include <asterisk/module.h>
|
||||
#include <asterisk/options.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "../astconf.h"
|
||||
|
||||
/*
|
||||
* pbx_spool is similar in spirit to qcall, but with substantially enhanced functionality...
|
||||
* The spool file contains a header
|
||||
*/
|
||||
|
||||
static char *tdesc = "Outgoing Spool Support";
|
||||
static char qdir[255];
|
||||
|
||||
struct outgoing {
|
||||
char fn[256];
|
||||
/* Current number of retries */
|
||||
int retries;
|
||||
/* Maximum number of retries permitted */
|
||||
int maxretries;
|
||||
/* How long to wait between retries (in seconds) */
|
||||
int retrytime;
|
||||
/* How long to wait for an answer */
|
||||
int waittime;
|
||||
|
||||
/* What to connect to outgoing */
|
||||
char tech[256];
|
||||
char dest[256];
|
||||
|
||||
/* If application */
|
||||
char app[256];
|
||||
char data[256];
|
||||
|
||||
/* If extension/context/priority */
|
||||
char exten[256];
|
||||
char context[256];
|
||||
int priority;
|
||||
|
||||
/* CallerID Information */
|
||||
char callerid[256];
|
||||
|
||||
/* Channel variables */
|
||||
char variable[10*256];
|
||||
|
||||
/* Maximum length of call */
|
||||
int maxlen;
|
||||
|
||||
};
|
||||
|
||||
static void init_outgoing(struct outgoing *o)
|
||||
{
|
||||
memset(o, 0, sizeof(struct outgoing));
|
||||
o->priority = 1;
|
||||
o->retrytime = 300;
|
||||
o->waittime = 45;
|
||||
}
|
||||
|
||||
static int apply_outgoing(struct outgoing *o, char *fn, FILE *f)
|
||||
{
|
||||
char buf[256];
|
||||
char *c, *c2;
|
||||
int lineno = 0;
|
||||
while(!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
lineno++;
|
||||
if (!feof(f)) {
|
||||
/* Trim comments */
|
||||
c = strchr(buf, '#');
|
||||
if (c)
|
||||
*c = '\0';
|
||||
c = strchr(buf, ';');
|
||||
if (c)
|
||||
*c = '\0';
|
||||
|
||||
/* Trim trailing white space */
|
||||
while(strlen(buf) && buf[strlen(buf) - 1] < 33)
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
if (strlen(buf)) {
|
||||
c = strchr(buf, ':');
|
||||
if (c) {
|
||||
*c = '\0';
|
||||
c++;
|
||||
while(*c < 33)
|
||||
c++;
|
||||
#if 0
|
||||
printf("'%s' is '%s' at line %d\n", buf, c, lineno);
|
||||
#endif
|
||||
if (!strcasecmp(buf, "channel")) {
|
||||
strncpy(o->tech, c, sizeof(o->tech) - 1);
|
||||
if ((c2 = strchr(o->tech, '/'))) {
|
||||
*c2 = '\0';
|
||||
c2++;
|
||||
strncpy(o->dest, c2, sizeof(o->dest) - 1);
|
||||
} else {
|
||||
ast_log(LOG_NOTICE, "Channel should be in form Tech/Dest at line %d of %s\n", lineno, fn);
|
||||
strcpy(o->tech, "");
|
||||
}
|
||||
} else if (!strcasecmp(buf, "callerid")) {
|
||||
strncpy(o->callerid, c, sizeof(o->callerid) - 1);
|
||||
} else if (!strcasecmp(buf, "application")) {
|
||||
strncpy(o->app, c, sizeof(o->app) - 1);
|
||||
} else if (!strcasecmp(buf, "data")) {
|
||||
strncpy(o->data, c, sizeof(o->data) - 1);
|
||||
} else if (!strcasecmp(buf, "maxretries")) {
|
||||
if (sscanf(c, "%d", &o->maxretries) != 1) {
|
||||
ast_log(LOG_WARNING, "Invalid max retries at line %d of %s\n", lineno, fn);
|
||||
o->maxretries = 0;
|
||||
}
|
||||
} else if (!strcasecmp(buf, "context")) {
|
||||
strncpy(o->context, c, sizeof(o->context) - 1);
|
||||
} else if (!strcasecmp(buf, "extension")) {
|
||||
strncpy(o->exten, c, sizeof(o->exten) - 1);
|
||||
} else if (!strcasecmp(buf, "priority")) {
|
||||
if ((sscanf(c, "%d", &o->priority) != 1) || (o->priority < 1)) {
|
||||
ast_log(LOG_WARNING, "Invalid priority at line %d of %s\n", lineno, fn);
|
||||
o->priority = 1;
|
||||
}
|
||||
} else if (!strcasecmp(buf, "retrytime")) {
|
||||
if ((sscanf(c, "%d", &o->retrytime) != 1) || (o->retrytime < 1)) {
|
||||
ast_log(LOG_WARNING, "Invalid retrytime at line %d of %s\n", lineno, fn);
|
||||
o->retrytime = 300;
|
||||
}
|
||||
} else if (!strcasecmp(buf, "waittime")) {
|
||||
if ((sscanf(c, "%d", &o->waittime) != 1) || (o->waittime < 1)) {
|
||||
ast_log(LOG_WARNING, "Invalid retrytime at line %d of %s\n", lineno, fn);
|
||||
o->waittime = 45;
|
||||
}
|
||||
} else if (!strcasecmp(buf, "retry")) {
|
||||
o->retries++;
|
||||
} else if (!strcasecmp(buf, "setvar")) { /* JDG variable support */
|
||||
strncat(o->variable, c, sizeof(o->variable) - strlen(o->variable) - 1);
|
||||
strncat(o->variable, "|", sizeof(o->variable) - strlen(o->variable) - 1);
|
||||
|
||||
} else {
|
||||
ast_log(LOG_WARNING, "Unknown keyword '%s' at line %d of %s\n", buf, lineno, fn);
|
||||
}
|
||||
} else
|
||||
ast_log(LOG_NOTICE, "Syntax error at line %d of %s\n", lineno, fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
strncpy(o->fn, fn, sizeof(o->fn) - 1);
|
||||
/* Check sanity of times */
|
||||
if (o->retrytime < o->waittime + 5)
|
||||
o->retrytime = o->waittime + 5;
|
||||
if (!strlen(o->tech) || !strlen(o->dest) || (!strlen(o->app) && !strlen(o->exten))) {
|
||||
ast_log(LOG_WARNING, "At least one of app or extension must be specified, along with tech and dest in file %s\n", fn);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *attempt_thread(void *data)
|
||||
{
|
||||
struct outgoing *o = data;
|
||||
int res, reason;
|
||||
if (strlen(o->app)) {
|
||||
if (option_verbose > 2)
|
||||
ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for application %s(%s) (Retry %d)\n", o->tech, o->dest, o->app, o->data, o->retries);
|
||||
res = ast_pbx_outgoing_app(o->tech, AST_FORMAT_SLINEAR, o->dest, o->waittime * 1000, o->app, o->data, &reason, 2 /* wait to finish */, o->callerid);
|
||||
} else {
|
||||
if (option_verbose > 2)
|
||||
ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for %s@%s:%d (Retry %d)\n", o->tech, o->dest, o->exten, o->context,o->priority, o->retries);
|
||||
res = ast_pbx_outgoing_exten(o->tech, AST_FORMAT_SLINEAR, o->dest, o->waittime * 1000, o->context, o->exten, o->priority, &reason, 2 /* wait to finish */, o->callerid, o->variable );
|
||||
}
|
||||
if (res) {
|
||||
ast_log(LOG_NOTICE, "Call failed to go through, reason %d\n", reason);
|
||||
if (o->retries >= o->maxretries + 1) {
|
||||
/* Max retries exceeded */
|
||||
ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt(s)\n", o->tech, o->dest, o->retries - 1);
|
||||
unlink(o->fn);
|
||||
}
|
||||
} else {
|
||||
ast_log(LOG_NOTICE, "Call completed to %s/%s\n", o->tech, o->dest);
|
||||
ast_log(LOG_EVENT, "Queued call to %s/%s completed\n", o->tech, o->dest);
|
||||
unlink(o->fn);
|
||||
}
|
||||
free(o);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void launch_service(struct outgoing *o)
|
||||
{
|
||||
pthread_t t;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
if (pthread_create(&t,&attr,attempt_thread, o) == -1) {
|
||||
ast_log(LOG_WARNING, "Unable to create thread :(\n");
|
||||
free(o);
|
||||
}
|
||||
}
|
||||
|
||||
static int scan_service(char *fn, time_t now, time_t atime)
|
||||
{
|
||||
struct outgoing *o;
|
||||
struct utimbuf tbuf;
|
||||
FILE *f;
|
||||
o = malloc(sizeof(struct outgoing));
|
||||
if (o) {
|
||||
init_outgoing(o);
|
||||
f = fopen(fn, "r+");
|
||||
if (f) {
|
||||
if (!apply_outgoing(o, fn, f)) {
|
||||
/* Update the file time */
|
||||
tbuf.actime = atime;
|
||||
tbuf.modtime = now + o->retrytime;
|
||||
if (utime(o->fn, &tbuf))
|
||||
ast_log(LOG_WARNING, "Unable to set utime on %s: %s\n", fn, strerror(errno));
|
||||
/* Increment retries */
|
||||
o->retries++;
|
||||
#if 0
|
||||
printf("Retries: %d, max: %d\n", o->retries, o->maxretries);
|
||||
#endif
|
||||
if (o->retries <= o->maxretries + 1) {
|
||||
/* Add a retry line at the end */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
fprintf(f, "Retry: %d (%ld)\n", o->retries, now);
|
||||
fclose(f);
|
||||
now += o->retrytime;
|
||||
launch_service(o);
|
||||
return now;
|
||||
} else {
|
||||
ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt(s)\n", o->tech, o->dest, o->retries - 1);
|
||||
fclose(f);
|
||||
free(o);
|
||||
unlink(fn);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
free(o);
|
||||
ast_log(LOG_WARNING, "Invalid file contents in %s, deleting\n", fn);
|
||||
fclose(f);
|
||||
unlink(fn);
|
||||
}
|
||||
} else {
|
||||
free(o);
|
||||
ast_log(LOG_WARNING, "Unable to open %s: %s, deleting\n", fn, strerror(errno));
|
||||
unlink(fn);
|
||||
}
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Out of memory :(\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void *scan_thread(void *unused)
|
||||
{
|
||||
struct stat st;
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
char fn[256];
|
||||
int res;
|
||||
time_t last = 0, next = 0, now;
|
||||
for(;;) {
|
||||
/* Wait a sec */
|
||||
sleep(1);
|
||||
time(&now);
|
||||
if (!stat(qdir, &st)) {
|
||||
if ((st.st_mtime != last) || (next && (now > next))) {
|
||||
#if 0
|
||||
printf("atime: %ld, mtime: %ld, ctime: %ld\n", st.st_atime, st.st_mtime, st.st_ctime);
|
||||
printf("Ooh, something changed / timeout\n");
|
||||
#endif
|
||||
next = 0;
|
||||
last = st.st_mtime;
|
||||
dir = opendir(qdir);
|
||||
if (dir) {
|
||||
while((de = readdir(dir))) {
|
||||
snprintf(fn, sizeof(fn), "%s/%s", qdir, de->d_name);
|
||||
if (!stat(fn, &st)) {
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
if (st.st_mtime <= now) {
|
||||
res = scan_service(fn, now, st.st_atime);
|
||||
if (res > 0) {
|
||||
/* Update next service time */
|
||||
if (!next || (res < next)) {
|
||||
next = res;
|
||||
}
|
||||
} else if (res)
|
||||
ast_log(LOG_WARNING, "Failed to scan service '%s'\n", fn);
|
||||
} else {
|
||||
/* Update "next" update if necessary */
|
||||
if (!next || (st.st_mtime < next))
|
||||
next = st.st_mtime;
|
||||
}
|
||||
}
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Unable to stat %s: %s\n", fn, strerror(errno));
|
||||
}
|
||||
closedir(dir);
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Unable to open directory %s: %s\n", qdir, strerror(errno));
|
||||
}
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Unable to stat %s\n", qdir);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int unload_module(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int load_module(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
snprintf((char *)qdir,sizeof(qdir)-1,"%s/%s",(char *)ast_config_AST_SPOOL_DIR,"outgoing");
|
||||
printf("%s\n",qdir);
|
||||
if (mkdir(qdir, 0700) && (errno != EEXIST)) {
|
||||
ast_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool disabled\n", qdir);
|
||||
return 0;
|
||||
}
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
if (pthread_create(&thread,&attr,scan_thread, NULL) == -1) {
|
||||
ast_log(LOG_WARNING, "Unable to create thread :(\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *description(void)
|
||||
{
|
||||
return tdesc;
|
||||
}
|
||||
|
||||
int usecount(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *key()
|
||||
{
|
||||
return ASTERISK_GPL_KEY;
|
||||
}
|
Loading…
Reference in new issue