Version 0.2.0 from FTP
authorMark Spencer <markster@digium.com>
Fri, 12 Jul 2002 09:03:50 +0000 (09:03 +0000)
committerMark Spencer <markster@digium.com>
Fri, 12 Jul 2002 09:03:50 +0000 (09:03 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@484 65c4cc65-6c06-0410-ace0-fbb531ad65f3

15 files changed:
apps/app_datetime.c [new file with mode: 0755]
apps/app_milliwatt.c
apps/app_playback.c
apps/app_qcall.c
apps/app_record.c
apps/app_zapateller.c
apps/app_zapras.c
channels/chan_alsa.c
channels/chan_modem.c
channels/chan_modem_aopen.c
channels/chan_modem_bestdata.c
channels/chan_modem_i4l.c
include/asterisk/channel_pvt.h
include/asterisk/vmodem.h
pbx/pbx_wilcalu.c

diff --git a/apps/app_datetime.c b/apps/app_datetime.c
new file mode 100755 (executable)
index 0000000..97c1088
--- /dev/null
@@ -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;
+}
index 2f162f2..b117441 100755 (executable)
@@ -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);
        }
index 5ca2626..3466173 100755 (executable)
@@ -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);
index 1a7887b..5a1df97 100755 (executable)
@@ -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)
index 4ad4a15..1e54276 100755 (executable)
@@ -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 */
        }
index 658fde5..c9e5fdc 100755 (executable)
@@ -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) {
index 82614f1..7d2b0b8 100755 (executable)
@@ -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
index be760b8..3e35a82 100755 (executable)
@@ -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;
index 09c58c2..758235b 100755 (executable)
@@ -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;
index b832f80..b33ce07 100755 (executable)
@@ -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;
index b9f56d3..08a1c2e 100755 (executable)
@@ -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 */
index 609feff..553f144 100755 (executable)
@@ -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;
index 9951561..a96b4a1 100755 (executable)
@@ -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 *);
 
index ab7274c..457606c 100755 (executable)
@@ -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
index df17888..a125bd1 100755 (executable)
@@ -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