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
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
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
|
|
|
|
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 *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";
|
|
|
|
|
|
|
|
|
|
|
|
static int waitforring_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
2006-08-21 02:11:39 +00:00
|
|
|
struct ast_module_user *u;
|
2003-02-23 06:00:11 +00:00
|
|
|
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
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
u = ast_module_user_add(chan);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(u);
|
2003-02-23 06:00:11 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_hangup_all();
|
2005-10-18 22:52:21 +00:00
|
|
|
|
|
|
|
return res;
|
2003-02-23 06:00:11 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
|
|
|
return ast_register_application(app, waitforring_exec, synopsis, desc);
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Waits until first ring after time");
|