Version 0.2.0 from FTP

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@484 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2002-07-12 09:03:50 +00:00
parent 67751c3992
commit d233fd5d12
15 changed files with 119 additions and 30 deletions

84
apps/app_datetime.c Executable file
View File

@@ -0,0 +1,84 @@
/*
* Asterisk -- A telephony toolkit for Linux.
*
* Time of day - Report the time of day
*
* 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/say.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
static char *tdesc = "Date and Time";
static char *app = "DateTime";
static char *synopsis = "Say the date and time";
static char *descrip =
" DateTime(): Says the current date and time. Returns -1 on hangup or 0\n"
"otherwise.\n";
STANDARD_LOCAL_USER;
LOCAL_USER_DECL;
static int datetime_exec(struct ast_channel *chan, void *data)
{
int res=0;
time_t t;
struct localuser *u;
LOCAL_USER_ADD(u);
time(&t);
if (chan->_state != AST_STATE_UP)
res = ast_answer(chan);
if (!res)
res = ast_say_datetime(chan, t, "", chan->language);
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, datetime_exec, synopsis, descrip);
}
char *description(void)
{
return tdesc;
}
int usecount(void)
{
int res;
STANDARD_USECOUNT(res);
return res;
}
char *key()
{
return ASTERISK_GPL_KEY;
}

View File

@@ -100,11 +100,10 @@ static int milliwatt_exec(struct ast_channel *chan, void *data)
{ {
struct localuser *u; struct localuser *u;
struct ast_frame *f;
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
ast_set_write_format(chan, AST_FORMAT_ULAW); ast_set_write_format(chan, AST_FORMAT_ULAW);
ast_set_read_format(chan, AST_FORMAT_ULAW); ast_set_read_format(chan, AST_FORMAT_ULAW);
if (chan->state != AST_STATE_UP) if (chan->_state != AST_STATE_UP)
{ {
ast_answer(chan); ast_answer(chan);
} }

View File

@@ -63,7 +63,7 @@ static int playback_exec(struct ast_channel *chan, void *data)
if (options && !strcasecmp(options, "noanswer")) if (options && !strcasecmp(options, "noanswer"))
option_noanswer = 1; option_noanswer = 1;
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
if (chan->state != AST_STATE_UP) { if (chan->_state != AST_STATE_UP) {
if (option_skip) { if (option_skip) {
/* At the user's option, skip if the line is not up */ /* At the user's option, skip if the line is not up */
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
@@ -77,8 +77,10 @@ static int playback_exec(struct ast_channel *chan, void *data)
res = ast_streamfile(chan, tmp, chan->language); res = ast_streamfile(chan, tmp, chan->language);
if (!res) if (!res)
res = ast_waitstream(chan, ""); res = ast_waitstream(chan, "");
else else {
ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data); ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
res = 0;
}
ast_stopstream(chan); ast_stopstream(chan);
} }
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);

View File

@@ -247,7 +247,7 @@ time_t t;
if (channel->ani) free(channel->ani); if (channel->ani) free(channel->ani);
channel->ani = NULL; channel->ani = NULL;
} }
if (channel->state == AST_STATE_UP) if (channel->_state == AST_STATE_UP)
if (debug) printf("@@@@ Autodial:Line is Up\n"); if (debug) printf("@@@@ Autodial:Line is Up\n");
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Qcall waiting for answer on %s\n", ast_verbose(VERBOSE_PREFIX_3 "Qcall waiting for answer on %s\n",
@@ -274,7 +274,7 @@ time_t t;
if (f->subclass == AST_CONTROL_ANSWER) if (f->subclass == AST_CONTROL_ANSWER)
{ {
if (debug) printf("@@@@ qcall_do:Phone Answered\n"); if (debug) printf("@@@@ qcall_do:Phone Answered\n");
if (channel->state == AST_STATE_UP) if (channel->_state == AST_STATE_UP)
{ {
unlink(fname); unlink(fname);
if (option_verbose > 2) if (option_verbose > 2)

View File

@@ -95,7 +95,7 @@ static int record_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
if (chan->state != AST_STATE_UP) { if (chan->_state != AST_STATE_UP) {
res = ast_answer(chan); /* Shouldn't need this, but checking to see if channel is already answered res = ast_answer(chan); /* Shouldn't need this, but checking to see if channel is already answered
* Theoretically asterisk should already have answered before running the app */ * Theoretically asterisk should already have answered before running the app */
} }

View File

@@ -45,7 +45,7 @@ static int zapateller_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
ast_stopstream(chan); ast_stopstream(chan);
if (chan->state != AST_STATE_UP) { if (chan->_state != AST_STATE_UP) {
if (data && !strcasecmp(data, "answer")) if (data && !strcasecmp(data, "answer"))
res = ast_answer(chan); res = ast_answer(chan);
if (!res) { if (!res) {

View File

@@ -125,7 +125,7 @@ static void run_ras(struct ast_channel *chan, char *args)
res = wait4(pid, &status, WNOHANG, NULL); res = wait4(pid, &status, WNOHANG, NULL);
if (!res) { if (!res) {
/* Check for hangup */ /* Check for hangup */
if (chan->softhangup && !signalled) { if (chan->_softhangup && !signalled) {
ast_log(LOG_DEBUG, "Channel '%s' hungup. Signalling RAS at %d to die...\n", chan->name, pid); ast_log(LOG_DEBUG, "Channel '%s' hungup. Signalling RAS at %d to die...\n", chan->name, pid);
kill(pid, SIGTERM); kill(pid, SIGTERM);
signalled=1; signalled=1;
@@ -182,7 +182,7 @@ static int zapras_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
strncpy(args, data, sizeof(args) - 1); strncpy(args, data, sizeof(args) - 1);
/* Answer the channel if it's not up */ /* Answer the channel if it's not up */
if (chan->state != AST_STATE_UP) if (chan->_state != AST_STATE_UP)
ast_answer(chan); ast_answer(chan);
if (strcasecmp(chan->type, "Zap")) { if (strcasecmp(chan->type, "Zap")) {
/* If it's not a zap channel, we're done. Wait a couple of /* If it's not a zap channel, we're done. Wait a couple of

View File

@@ -506,7 +506,7 @@ static int alsa_answer(struct ast_channel *c)
{ {
ast_verbose( " << Console call has been answered >> \n"); ast_verbose( " << Console call has been answered >> \n");
answer_sound(); answer_sound();
c->state = AST_STATE_UP; ast_setstate(c, AST_STATE_UP);
cursound = -1; cursound = -1;
return 0; return 0;
} }
@@ -684,7 +684,7 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
needanswer = 0; needanswer = 0;
f.frametype = AST_FRAME_CONTROL; f.frametype = AST_FRAME_CONTROL;
f.subclass = AST_CONTROL_ANSWER; f.subclass = AST_CONTROL_ANSWER;
chan->state = AST_STATE_UP; ast_setstate(chan, AST_STATE_UP);
return &f; return &f;
} }
@@ -722,7 +722,7 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
/* A real frame */ /* A real frame */
readpos = 0; readpos = 0;
left = FRAME_SIZE; left = FRAME_SIZE;
if (chan->state != AST_STATE_UP) { if (chan->_state != AST_STATE_UP) {
/* Don't transmit unless it's up */ /* Don't transmit unless it's up */
return &f; return &f;
} }
@@ -806,7 +806,7 @@ static struct ast_channel *alsa_new(struct chan_alsa_pvt *p, int state)
if (strlen(language)) if (strlen(language))
strncpy(tmp->language, language, sizeof(tmp->language)-1); strncpy(tmp->language, language, sizeof(tmp->language)-1);
p->owner = tmp; p->owner = tmp;
tmp->state = state; ast_setstate(tmp, state);
ast_pthread_mutex_lock(&usecnt_lock); ast_pthread_mutex_lock(&usecnt_lock);
usecnt++; usecnt++;
ast_pthread_mutex_unlock(&usecnt_lock); ast_pthread_mutex_unlock(&usecnt_lock);
@@ -1087,7 +1087,7 @@ int unload_module()
close(sndcmd[1]); close(sndcmd[1]);
} }
if (alsa.owner) if (alsa.owner)
ast_softhangup(alsa.owner); ast_softhangup(alsa.owner, AST_SOFTHANGUP_APPUNLOAD);
if (alsa.owner) if (alsa.owner)
return -1; return -1;
return 0; return 0;

View File

@@ -177,7 +177,7 @@ static int modem_call(struct ast_channel *ast, char *idest, int timeout)
strcpy(dstr,where + p->stripmsd); strcpy(dstr,where + p->stripmsd);
/* if not a transfer or just sending tones, must be in correct state */ /* if not a transfer or just sending tones, must be in correct state */
if (strcasecmp(rdest, "transfer") && strcasecmp(rdest,"sendtones")) { if (strcasecmp(rdest, "transfer") && strcasecmp(rdest,"sendtones")) {
if ((ast->state != AST_STATE_DOWN) && (ast->state != AST_STATE_RESERVED)) { if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
ast_log(LOG_WARNING, "modem_call called on %s, neither down nor reserved\n", ast->name); ast_log(LOG_WARNING, "modem_call called on %s, neither down nor reserved\n", ast->name);
return -1; return -1;
} }
@@ -191,15 +191,15 @@ static int modem_call(struct ast_channel *ast, char *idest, int timeout)
if (p->mc->setdev(p, MODEM_DEV_HANDSET)) if (p->mc->setdev(p, MODEM_DEV_HANDSET))
return -1; return -1;
/* Should be immediately up */ /* Should be immediately up */
ast->state = AST_STATE_UP; ast_setstate(ast, AST_STATE_UP);
} else { } else {
if (p->mc->setdev) if (p->mc->setdev)
if (p->mc->setdev(p, MODEM_DEV_TELCO_SPK)) if (p->mc->setdev(p, MODEM_DEV_TELCO_SPK))
return -1; return -1;
if (p->mc->dial) if (p->mc->dial)
p->mc->dial(p, dstr); p->mc->dial(p, dstr);
ast->state = AST_STATE_DIALING; ast_setstate(ast, AST_STATE_DIALING);
while((ast->state != AST_STATE_UP) && (ms > 0)) { while((ast->_state != AST_STATE_UP) && (ms > 0)) {
ms = ast_waitfor(ast, ms); ms = ast_waitfor(ast, ms);
/* Just read packets and watch what happens */ /* Just read packets and watch what happens */
if (ms > 0) { if (ms > 0) {
@@ -410,7 +410,7 @@ static int modem_hangup(struct ast_channel *ast)
/* Re-initialize */ /* Re-initialize */
if (p->mc->init) if (p->mc->init)
p->mc->init(p); p->mc->init(p);
ast->state = AST_STATE_DOWN; ast_setstate(ast, AST_STATE_DOWN);
memset(p->cid, 0, sizeof(p->cid)); memset(p->cid, 0, sizeof(p->cid));
memset(p->dnid, 0, sizeof(p->dnid)); memset(p->dnid, 0, sizeof(p->dnid));
((struct ast_modem_pvt *)(ast->pvt->pvt))->owner = NULL; ((struct ast_modem_pvt *)(ast->pvt->pvt))->owner = NULL;
@@ -423,7 +423,7 @@ static int modem_hangup(struct ast_channel *ast)
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name); ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
ast->pvt->pvt = NULL; ast->pvt->pvt = NULL;
ast->state = AST_STATE_DOWN; ast_setstate(ast, AST_STATE_DOWN);
restart_monitor(); restart_monitor();
return 0; return 0;
} }
@@ -440,7 +440,7 @@ static int modem_answer(struct ast_channel *ast)
} }
if (!res) { if (!res) {
ast->rings = 0; ast->rings = 0;
ast->state = AST_STATE_UP; ast_setstate(ast, AST_STATE_UP);
} }
return res; return res;
} }
@@ -494,7 +494,7 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
tmp->type = type; tmp->type = type;
tmp->fds[0] = i->fd; tmp->fds[0] = i->fd;
tmp->nativeformats = i->mc->formats; tmp->nativeformats = i->mc->formats;
tmp->state = state; ast_setstate(tmp, state);
if (state == AST_STATE_RING) if (state == AST_STATE_RING)
tmp->rings = 1; tmp->rings = 1;
tmp->pvt->pvt = i; tmp->pvt->pvt = i;
@@ -858,7 +858,7 @@ int unload_module()
p = iflist; p = iflist;
while(p) { while(p) {
if (p->owner) if (p->owner)
ast_softhangup(p->owner); ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
p = p->next; p = p->next;
} }
iflist = NULL; iflist = NULL;

View File

@@ -202,7 +202,7 @@ static struct ast_frame *aopen_handle_escape(struct ast_modem_pvt *p, char esc)
p->fr.frametype = AST_FRAME_CONTROL; p->fr.frametype = AST_FRAME_CONTROL;
p->fr.subclass = AST_CONTROL_RING; p->fr.subclass = AST_CONTROL_RING;
if (p->owner) if (p->owner)
p->owner->state = AST_STATE_UP; ast_setstate(p->owner, AST_STATE_UP);
if (aopen_startrec(p)) if (aopen_startrec(p))
return NULL; return NULL;
return &p->fr; return &p->fr;

View File

@@ -208,7 +208,7 @@ static struct ast_frame *bestdata_handle_escape(struct ast_modem_pvt *p, char es
return &p->fr; return &p->fr;
case '@': /* response from "OK" in command mode */ case '@': /* response from "OK" in command mode */
if (p->owner) if (p->owner)
p->owner->state = AST_STATE_UP; ast_setstate(p->owner, AST_STATE_UP);
if (bestdata_startrec(p)) return NULL; if (bestdata_startrec(p)) return NULL;
p->fr.frametype = AST_FRAME_CONTROL; p->fr.frametype = AST_FRAME_CONTROL;
p->fr.subclass = AST_CONTROL_RING; p->fr.subclass = AST_CONTROL_RING;
@@ -386,7 +386,7 @@ short *sp;
unsigned long u; unsigned long u;
#define DLE 16 #define DLE 16
if (p->owner && (p->owner->state == AST_STATE_UP) && if (p->owner && (p->owner->_state == AST_STATE_UP) &&
(p->ministate != STATE_VOICEPLAY) && bestdata_startplay(p)) return -1; (p->ministate != STATE_VOICEPLAY) && bestdata_startplay(p)) return -1;
sp = (short *) f->data; sp = (short *) f->data;
/* stick DLE's in ahead of anything else */ /* stick DLE's in ahead of anything else */

View File

@@ -208,7 +208,7 @@ static struct ast_frame *i4l_handle_escape(struct ast_modem_pvt *p, char esc)
p->fr.frametype = AST_FRAME_CONTROL; p->fr.frametype = AST_FRAME_CONTROL;
p->fr.subclass = AST_CONTROL_ANSWER; p->fr.subclass = AST_CONTROL_ANSWER;
if (p->owner) if (p->owner)
p->owner->state = AST_STATE_UP; ast_setstate(p->owner, AST_STATE_UP);
if (i4l_startrec(p)) if (i4l_startrec(p))
return NULL; return NULL;
return &p->fr; return &p->fr;

View File

@@ -78,6 +78,9 @@ int ast_queue_hangup(struct ast_channel *chan, int lock);
int ast_queue_control(struct ast_channel *chan, int control, int lock); int ast_queue_control(struct ast_channel *chan, int control, int lock);
/*! Change the state of a channel */
int ast_setstate(struct ast_channel *chan, int state);
//! Free a channel structure //! Free a channel structure
void ast_channel_free(struct ast_channel *); void ast_channel_free(struct ast_channel *);

View File

@@ -16,6 +16,7 @@
#include <asterisk/frame.h> #include <asterisk/frame.h>
#include <asterisk/channel.h> #include <asterisk/channel.h>
#include <asterisk/channel_pvt.h>
#define CHAR_DLE 0x10 #define CHAR_DLE 0x10
#define CHAR_ETX 0x03 #define CHAR_ETX 0x03

View File

@@ -189,7 +189,7 @@ static void *dialstring(void *string){
free(string); free(string);
pthread_exit(NULL); pthread_exit(NULL);
} }
if(channel->state==AST_STATE_UP) if(channel->_state==AST_STATE_UP)
printf("Autodial:Line is Up\n"); printf("Autodial:Line is Up\n");
while(ms>0){ while(ms>0){
struct ast_frame *f; struct ast_frame *f;
@@ -202,7 +202,7 @@ static void *dialstring(void *string){
if(f->frametype==AST_FRAME_CONTROL){ if(f->frametype==AST_FRAME_CONTROL){
if(f->subclass==AST_CONTROL_ANSWER){ if(f->subclass==AST_CONTROL_ANSWER){
printf("Autodial:Phone Answered\n"); printf("Autodial:Phone Answered\n");
if(channel->state==AST_STATE_UP){ if(channel->_state==AST_STATE_UP){
char res; char res;
ast_streamfile(channel,filename,0); ast_streamfile(channel,filename,0);
// Press Five for snooze // Press Five for snooze