summaryrefslogtreecommitdiff
path: root/apps/app_waitforring.c
diff options
context:
space:
mode:
authorMatteo Brancaleoni <mbrancaleoni@espia.it>2003-02-23 06:00:11 +0000
committerMatteo Brancaleoni <mbrancaleoni@espia.it>2003-02-23 06:00:11 +0000
commit17769619c2d3d5c96c906a383ec06df2efbb0e35 (patch)
treee05618b650b51c146c697c794e3e510343de7230 /apps/app_waitforring.c
parent877a281b742fc0d7cda64f34aa633d8b3972da47 (diff)
Sun Feb 23 07:00:00 CET 2003
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@621 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps/app_waitforring.c')
-rwxr-xr-xapps/app_waitforring.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/apps/app_waitforring.c b/apps/app_waitforring.c
new file mode 100755
index 000000000..06a18a7d8
--- /dev/null
+++ b/apps/app_waitforring.c
@@ -0,0 +1,130 @@
+/*
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * Wait for Ring Application
+ *
+ * Copyright (C) 2003, Digium
+ *
+ * Mark Spencer <markster@linux-support.net>
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ */
+
+#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 <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <pthread.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, "SoftHangup requires an argument (minimum seconds)\n");
+ return 0;
+ }
+ ms *= 1000;
+ LOCAL_USER_ADD(u);
+ 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)
+{
+ STANDARD_HANGUP_LOCALUSERS;
+ return ast_unregister_application(app);
+}
+
+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;
+}