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 ast_frame *f;
LOCAL_USER_ADD(u);
ast_set_write_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);
}

View File

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

View File

@ -247,7 +247,7 @@ time_t t;
if (channel->ani) free(channel->ani);
channel->ani = NULL;
}
if (channel->state == AST_STATE_UP)
if (channel->_state == AST_STATE_UP)
if (debug) printf("@@@@ Autodial:Line is Up\n");
if (option_verbose > 2)
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 (debug) printf("@@@@ qcall_do:Phone Answered\n");
if (channel->state == AST_STATE_UP)
if (channel->_state == AST_STATE_UP)
{
unlink(fname);
if (option_verbose > 2)

View File

@ -95,7 +95,7 @@ static int record_exec(struct ast_channel *chan, void *data)
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
* 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);
ast_stopstream(chan);
if (chan->state != AST_STATE_UP) {
if (chan->_state != AST_STATE_UP) {
if (data && !strcasecmp(data, "answer"))
res = ast_answer(chan);
if (!res) {

View File

@ -125,7 +125,7 @@ static void run_ras(struct ast_channel *chan, char *args)
res = wait4(pid, &status, WNOHANG, NULL);
if (!res) {
/* 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);
kill(pid, SIGTERM);
signalled=1;
@ -182,7 +182,7 @@ static int zapras_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u);
strncpy(args, data, sizeof(args) - 1);
/* Answer the channel if it's not up */
if (chan->state != AST_STATE_UP)
if (chan->_state != AST_STATE_UP)
ast_answer(chan);
if (strcasecmp(chan->type, "Zap")) {
/* 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");
answer_sound();
c->state = AST_STATE_UP;
ast_setstate(c, AST_STATE_UP);
cursound = -1;
return 0;
}
@ -684,7 +684,7 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
needanswer = 0;
f.frametype = AST_FRAME_CONTROL;
f.subclass = AST_CONTROL_ANSWER;
chan->state = AST_STATE_UP;
ast_setstate(chan, AST_STATE_UP);
return &f;
}
@ -722,7 +722,7 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
/* A real frame */
readpos = 0;
left = FRAME_SIZE;
if (chan->state != AST_STATE_UP) {
if (chan->_state != AST_STATE_UP) {
/* Don't transmit unless it's up */
return &f;
}
@ -806,7 +806,7 @@ static struct ast_channel *alsa_new(struct chan_alsa_pvt *p, int state)
if (strlen(language))
strncpy(tmp->language, language, sizeof(tmp->language)-1);
p->owner = tmp;
tmp->state = state;
ast_setstate(tmp, state);
ast_pthread_mutex_lock(&usecnt_lock);
usecnt++;
ast_pthread_mutex_unlock(&usecnt_lock);
@ -1087,7 +1087,7 @@ int unload_module()
close(sndcmd[1]);
}
if (alsa.owner)
ast_softhangup(alsa.owner);
ast_softhangup(alsa.owner, AST_SOFTHANGUP_APPUNLOAD);
if (alsa.owner)
return -1;
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);
/* if not a transfer or just sending tones, must be in correct state */
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);
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))
return -1;
/* Should be immediately up */
ast->state = AST_STATE_UP;
ast_setstate(ast, AST_STATE_UP);
} else {
if (p->mc->setdev)
if (p->mc->setdev(p, MODEM_DEV_TELCO_SPK))
return -1;
if (p->mc->dial)
p->mc->dial(p, dstr);
ast->state = AST_STATE_DIALING;
while((ast->state != AST_STATE_UP) && (ms > 0)) {
ast_setstate(ast, AST_STATE_DIALING);
while((ast->_state != AST_STATE_UP) && (ms > 0)) {
ms = ast_waitfor(ast, ms);
/* Just read packets and watch what happens */
if (ms > 0) {
@ -410,7 +410,7 @@ static int modem_hangup(struct ast_channel *ast)
/* Re-initialize */
if (p->mc->init)
p->mc->init(p);
ast->state = AST_STATE_DOWN;
ast_setstate(ast, AST_STATE_DOWN);
memset(p->cid, 0, sizeof(p->cid));
memset(p->dnid, 0, sizeof(p->dnid));
((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)
ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
ast->pvt->pvt = NULL;
ast->state = AST_STATE_DOWN;
ast_setstate(ast, AST_STATE_DOWN);
restart_monitor();
return 0;
}
@ -440,7 +440,7 @@ static int modem_answer(struct ast_channel *ast)
}
if (!res) {
ast->rings = 0;
ast->state = AST_STATE_UP;
ast_setstate(ast, AST_STATE_UP);
}
return res;
}
@ -494,7 +494,7 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
tmp->type = type;
tmp->fds[0] = i->fd;
tmp->nativeformats = i->mc->formats;
tmp->state = state;
ast_setstate(tmp, state);
if (state == AST_STATE_RING)
tmp->rings = 1;
tmp->pvt->pvt = i;
@ -858,7 +858,7 @@ int unload_module()
p = iflist;
while(p) {
if (p->owner)
ast_softhangup(p->owner);
ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
p = p->next;
}
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.subclass = AST_CONTROL_RING;
if (p->owner)
p->owner->state = AST_STATE_UP;
ast_setstate(p->owner, AST_STATE_UP);
if (aopen_startrec(p))
return NULL;
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;
case '@': /* response from "OK" in command mode */
if (p->owner)
p->owner->state = AST_STATE_UP;
ast_setstate(p->owner, AST_STATE_UP);
if (bestdata_startrec(p)) return NULL;
p->fr.frametype = AST_FRAME_CONTROL;
p->fr.subclass = AST_CONTROL_RING;
@ -386,7 +386,7 @@ short *sp;
unsigned long u;
#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;
sp = (short *) f->data;
/* 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.subclass = AST_CONTROL_ANSWER;
if (p->owner)
p->owner->state = AST_STATE_UP;
ast_setstate(p->owner, AST_STATE_UP);
if (i4l_startrec(p))
return NULL;
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);
/*! Change the state of a channel */
int ast_setstate(struct ast_channel *chan, int state);
//! Free a channel structure
void ast_channel_free(struct ast_channel *);

View File

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

View File

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