diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-03-03 18:13:26 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-03-03 18:13:26 +0000 |
commit | 67da2f8263b4e9bb5522fa59b27e143381d69774 (patch) | |
tree | e69baf2b1594606e9ea2e80d26d691a10bd23831 /1.2-netsec/apps/app_waitforring.c | |
parent | 187ac8fdb51443812933047136b96b5a532dd857 (diff) |
Creating tag for the release of asterisk-1.2.5
git-svn-id: http://svn.digium.com/svn/asterisk/tags/1.2.5@11747 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to '1.2-netsec/apps/app_waitforring.c')
-rw-r--r-- | 1.2-netsec/apps/app_waitforring.c | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/1.2-netsec/apps/app_waitforring.c b/1.2-netsec/apps/app_waitforring.c new file mode 100644 index 000000000..25e651d9e --- /dev/null +++ b/1.2-netsec/apps/app_waitforring.c @@ -0,0 +1,154 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 1999 - 2005, Digium, Inc. + * + * Mark Spencer <markster@digium.com> + * + * 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. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * + * \brief Wait for Ring Application + * + * \ingroup applications + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#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" + +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"; + +STANDARD_LOCAL_USER; + +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; + + if (!data || (sscanf(data, "%d", &ms) != 1)) { + ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n"); + return 0; + } + + LOCAL_USER_ADD(u); + + ms *= 1000; + 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; +} + +int unload_module(void) +{ + int res; + + res = ast_unregister_application(app); + + STANDARD_HANGUP_LOCALUSERS; + + return res; +} + +int load_module(void) +{ + return ast_register_application(app, waitforring_exec, synopsis, desc); +} + +char *description(void) +{ + return tdesc; +} + +int usecount(void) +{ + int res; + STANDARD_USECOUNT(res); + return res; +} + +char *key() +{ + return ASTERISK_GPL_KEY; +} |