2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * Channel timeout related dialplan functions
27 #include <sys/types.h>
31 /* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
33 #include "asterisk/channel.h"
34 #include "asterisk/pbx.h"
35 #include "asterisk/logger.h"
36 #include "asterisk/utils.h"
37 #include "asterisk/app.h"
38 #include "asterisk/options.h"
40 static char *builtin_function_timeout_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
45 ast_log(LOG_ERROR, "Must specify type of timeout to get.");
52 if (chan->whentohangup == 0) {
53 ast_copy_string(buf, "0", len);
56 snprintf(buf, len, "%d", (int) (chan->whentohangup - myt));
63 snprintf(buf, len, "%d", chan->pbx->rtimeout);
70 snprintf(buf, len, "%d", chan->pbx->dtimeout);
75 ast_log(LOG_ERROR, "Unknown timeout type specified.");
82 static void builtin_function_timeout_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
89 ast_log(LOG_ERROR, "Must specify type of timeout to set.");
101 ast_channel_setwhentohangup(chan, x);
102 if (option_verbose > 2) {
103 if (chan->whentohangup) {
104 strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC", gmtime_r(&chan->whentohangup, &myt));
105 ast_verbose( VERBOSE_PREFIX_3 "Channel will hangup at %s.\n", timestr);
107 ast_verbose( VERBOSE_PREFIX_3 "Channel hangup cancelled.\n");
115 chan->pbx->rtimeout = x;
116 if (option_verbose > 2)
117 ast_verbose( VERBOSE_PREFIX_3 "Response timeout set to %d\n", chan->pbx->rtimeout);
124 chan->pbx->dtimeout = x;
125 if (option_verbose > 2)
126 ast_verbose( VERBOSE_PREFIX_3 "Digit timeout set to %d\n", chan->pbx->dtimeout);
131 ast_log(LOG_ERROR, "Unknown timeout type specified.");
139 struct ast_custom_function timeout_function = {
141 .synopsis = "Gets or sets timeouts on the channel.",
142 .syntax = "TIMEOUT(timeouttype)",
143 .desc = "Gets or sets various channel timeouts. The timeouts that can be\n"
146 "absolute: The absolute maximum amount of time permitted for a call. A\n"
147 " setting of 0 disables the timeout.\n"
149 "digit: The maximum amount of time permitted between digits when the\n"
150 " user is typing in an extension. When this timeout expires,\n"
151 " after the user has started to type in an extension, the\n"
152 " extension will be considered complete, and will be\n"
153 " interpreted. Note that if an extension typed in is valid,\n"
154 " it will not have to timeout to be tested, so typically at\n"
155 " the expiry of this timeout, the extension will be considered\n"
156 " invalid (and thus control would be passed to the 'i'\n"
157 " extension, or if it doesn't exist the call would be\n"
158 " terminated). The default timeout is 5 seconds.\n"
160 "response: The maximum amount of time permitted after falling through a\n"
161 " series of priorities for a channel in which the user may\n"
162 " begin typing an extension. If the user does not type an\n"
163 " extension in this amount of time, control will pass to the\n"
164 " 't' extension if it exists, and if not the call would be\n"
165 " terminated. The default timeout is 10 seconds.\n",
166 .read = builtin_function_timeout_read,
167 .write = builtin_function_timeout_write,
173 c-file-style: "linux"
174 indent-tabs-mode: nil