aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_timeout.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-15 17:45:30 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-15 17:45:30 +0000
commit025aeb8f62d8b5c199846c20c73ff25720dae21e (patch)
tree0dca6952bac0dc48b1b51a445fb7c60fd5caf1ff /funcs/func_timeout.c
parentb59e7819bd13b8713fa249affc2b5c7e9a41a717 (diff)
add dialplan functions for Caller ID, language and timeouts (bug #4219, with mods)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5679 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_timeout.c')
-rwxr-xr-xfuncs/func_timeout.c159
1 files changed, 159 insertions, 0 deletions
diff --git a/funcs/func_timeout.c b/funcs/func_timeout.c
new file mode 100755
index 000000000..950e134c0
--- /dev/null
+++ b/funcs/func_timeout.c
@@ -0,0 +1,159 @@
+/*
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * Channel timeout related dialplan functions
+ *
+ * Copyright (C) 2005, Digium, Inc.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+#include "asterisk/app.h"
+#include "asterisk/options.h"
+
+static char *builtin_function_timeout_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ time_t myt;
+
+ if (!data) {
+ ast_log(LOG_ERROR, "Must specify type of timeout to get.");
+ return NULL;
+ }
+
+ switch(*data) {
+ case 'a':
+ case 'A':
+ if (chan->whentohangup == 0) {
+ ast_copy_string(buf, "0", len);
+ } else {
+ time(&myt);
+ snprintf(buf, len, "%d", (int) (chan->whentohangup - myt));
+ }
+ break;
+
+ case 'r':
+ case 'R':
+ if (chan->pbx) {
+ snprintf(buf, len, "%d", chan->pbx->rtimeout);
+ }
+ break;
+
+ case 'd':
+ case 'D':
+ if (chan->pbx) {
+ snprintf(buf, len, "%d", chan->pbx->dtimeout);
+ }
+ break;
+
+ default:
+ ast_log(LOG_ERROR, "Unknown timeout type specified.");
+ break;
+ }
+
+ return buf;
+}
+
+static void builtin_function_timeout_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
+{
+ int x;
+ char timestr[64];
+ struct tm myt;
+
+ if (!data) {
+ ast_log(LOG_ERROR, "Must specify type of timeout to set.");
+ return;
+ }
+
+ if (!value)
+ return;
+
+ x = atoi(value);
+
+ switch(*data) {
+ case 'a':
+ case 'A':
+ ast_channel_setwhentohangup(chan, x);
+ if (option_verbose > 2) {
+ if (chan->whentohangup) {
+ strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC", gmtime_r(&chan->whentohangup, &myt));
+ ast_verbose( VERBOSE_PREFIX_3 "Channel will hangup at %s.\n", timestr);
+ } else {
+ ast_verbose( VERBOSE_PREFIX_3 "Channel hangup cancelled.\n");
+ }
+ }
+ break;
+
+ case 'r':
+ case 'R':
+ if (chan->pbx) {
+ chan->pbx->rtimeout = x;
+ if (option_verbose > 2)
+ ast_verbose( VERBOSE_PREFIX_3 "Response timeout set to %d\n", chan->pbx->rtimeout);
+ }
+ break;
+
+ case 'd':
+ case 'D':
+ if (chan->pbx) {
+ chan->pbx->dtimeout = x;
+ if (option_verbose > 2)
+ ast_verbose( VERBOSE_PREFIX_3 "Digit timeout set to %d\n", chan->pbx->dtimeout);
+ }
+ break;
+
+ default:
+ ast_log(LOG_ERROR, "Unknown timeout type specified.");
+ break;
+ }
+}
+
+#ifndef BUILTIN_FUNC
+static
+#endif
+struct ast_custom_function timeout_function = {
+ .name = "TIMEOUT",
+ .synopsis = "Gets or sets timeouts on the channel.",
+ .syntax = "TIMEOUT(timeouttype)",
+ .desc = "Gets or sets various channel timeouts. The timeouts that can be\n"
+ "manipulated are:\n"
+ "\n"
+ "absolute: The absolute maximum amount of time permitted for a call. A\n"
+ " setting of 0 disables the timeout.\n"
+ "\n"
+ "digit: The maximum amount of time permitted between digits when the\n"
+ " user is typing in an extension. When this timeout expires,\n"
+ " after the user has started to type in an extension, the\n"
+ " extension will be considered complete, and will be\n"
+ " interpreted. Note that if an extension typed in is valid,\n"
+ " it will not have to timeout to be tested, so typically at\n"
+ " the expiry of this timeout, the extension will be considered\n"
+ " invalid (and thus control would be passed to the 'i'\n"
+ " extension, or if it doesn't exist the call would be\n"
+ " terminated). The default timeout is 5 seconds.\n"
+ "\n"
+ "response: The maximum amount of time permitted after falling through a\n"
+ " series of priorities for a channel in which the user may\n"
+ " begin typing an extension. If the user does not type an\n"
+ " extension in this amount of time, control will pass to the\n"
+ " 't' extension if it exists, and if not the call would be\n"
+ " terminated. The default timeout is 10 seconds.\n",
+ .read = builtin_function_timeout_read,
+ .write = builtin_function_timeout_write,
+};
+
+/*
+Local Variables:
+mode: C
+c-file-style: "linux"
+indent-tabs-mode: nil
+End:
+*/