2003-02-23 06:00:11 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2003-02-23 06:00:11 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
2003-02-23 06:00:11 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
2003-02-23 06:00:11 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Wait for Ring Application
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2003-02-23 06:00:11 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <stdlib.h>
|
2005-11-08 04:48:00 +00:00
|
|
|
#include <stdio.h>
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <string.h>
|
2005-11-08 04:48:00 +00:00
|
|
|
#include <unistd.h>
|
2003-04-23 19:09:13 +00:00
|
|
|
#include <sys/types.h>
|
2005-06-06 22:39:32 +00:00
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#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 "asterisk/lock.h"
|
2003-02-23 06:00:11 +00:00
|
|
|
|
|
|
|
static char *synopsis = "Wait for Ring Application";
|
|
|
|
|
|
|
|
static char *tdesc = "Waits until first ring after time";
|
|
|
|
|
|
|
|
static char *desc = " WaitForRing(timeout)\n"
|
|
|
|
"Returns 0 after waiting at least timeout seconds. and\n"
|
|
|
|
"only after the next ring has completed. Returns 0 on\n"
|
|
|
|
"success or -1 on hangup\n";
|
|
|
|
|
|
|
|
static char *app = "WaitForRing";
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static int waitforring_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
struct localuser *u;
|
|
|
|
struct ast_frame *f;
|
|
|
|
int res = 0;
|
|
|
|
int ms;
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2003-02-23 06:00:11 +00:00
|
|
|
if (!data || (sscanf(data, "%d", &ms) != 1)) {
|
2004-02-15 08:41:56 +00:00
|
|
|
ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
|
2003-02-23 06:00:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2003-02-23 06:00:11 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
2005-10-19 18:19:02 +00:00
|
|
|
|
|
|
|
ms *= 1000;
|
2003-02-23 06:00:11 +00:00
|
|
|
while(ms > 0) {
|
|
|
|
ms = ast_waitfor(chan, ms);
|
|
|
|
if (ms < 0) {
|
|
|
|
res = ms;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ms > 0) {
|
|
|
|
f = ast_read(chan);
|
|
|
|
if (!f) {
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Got a ring but still waiting for timeout\n");
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Now we're really ready for the ring */
|
|
|
|
if (!res) {
|
|
|
|
ms = 99999999;
|
|
|
|
while(ms > 0) {
|
|
|
|
ms = ast_waitfor(chan, ms);
|
|
|
|
if (ms < 0) {
|
|
|
|
res = ms;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ms > 0) {
|
|
|
|
f = ast_read(chan);
|
|
|
|
if (!f) {
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Got a ring after the timeout\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static int unload_module(void *mod)
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2003-02-23 06:00:11 +00:00
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
2005-10-18 22:52:21 +00:00
|
|
|
|
|
|
|
return res;
|
2003-02-23 06:00:11 +00:00
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static int load_module(void *mod)
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
|
|
|
return ast_register_application(app, waitforring_exec, synopsis, desc);
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static const char *description(void)
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static const char *key(void)
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|
2006-04-14 14:08:19 +00:00
|
|
|
|
|
|
|
STD_MOD1;
|