--- /dev/null
+/*
+ * 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;
+}
{
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);
}
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);
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);
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",
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)
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 */
}
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) {
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;
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
{
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;
}
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;
}
/* 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;
}
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);
close(sndcmd[1]);
}
if (alsa.owner)
- ast_softhangup(alsa.owner);
+ ast_softhangup(alsa.owner, AST_SOFTHANGUP_APPUNLOAD);
if (alsa.owner)
return -1;
return 0;
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;
}
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) {
/* 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;
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;
}
}
if (!res) {
ast->rings = 0;
- ast->state = AST_STATE_UP;
+ ast_setstate(ast, AST_STATE_UP);
}
return res;
}
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;
p = iflist;
while(p) {
if (p->owner)
- ast_softhangup(p->owner);
+ ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
p = p->next;
}
iflist = NULL;
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;
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;
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 */
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;
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 *);
#include <asterisk/frame.h>
#include <asterisk/channel.h>
+#include <asterisk/channel_pvt.h>
#define CHAR_DLE 0x10
#define CHAR_ETX 0x03
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;
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