00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "asterisk.h"
00027
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 61681 $")
00029
00030 #include <stdlib.h>
00031 #include <stdio.h>
00032 #include <string.h>
00033 #include <sys/types.h>
00034
00035 #include "asterisk/module.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/logger.h"
00039 #include "asterisk/utils.h"
00040 #include "asterisk/app.h"
00041 #include "asterisk/options.h"
00042
00043 static int timeout_read(struct ast_channel *chan, char *cmd, char *data,
00044 char *buf, size_t len)
00045 {
00046 time_t myt;
00047
00048 if (!chan)
00049 return -1;
00050
00051 if (!data) {
00052 ast_log(LOG_ERROR, "Must specify type of timeout to get.\n");
00053 return -1;
00054 }
00055
00056 switch (*data) {
00057 case 'a':
00058 case 'A':
00059 if (chan->whentohangup == 0) {
00060 ast_copy_string(buf, "0", len);
00061 } else {
00062 time(&myt);
00063 snprintf(buf, len, "%d", (int) (chan->whentohangup - myt));
00064 }
00065 break;
00066
00067 case 'r':
00068 case 'R':
00069 if (chan->pbx) {
00070 snprintf(buf, len, "%d", chan->pbx->rtimeout);
00071 }
00072 break;
00073
00074 case 'd':
00075 case 'D':
00076 if (chan->pbx) {
00077 snprintf(buf, len, "%d", chan->pbx->dtimeout);
00078 }
00079 break;
00080
00081 default:
00082 ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
00083 break;
00084 }
00085
00086 return 0;
00087 }
00088
00089 static int timeout_write(struct ast_channel *chan, char *cmd, char *data,
00090 const char *value)
00091 {
00092 int x;
00093 char timestr[64];
00094 struct tm myt;
00095
00096 if (!chan)
00097 return -1;
00098
00099 if (!data) {
00100 ast_log(LOG_ERROR, "Must specify type of timeout to set.\n");
00101 return -1;
00102 }
00103
00104 if (!value)
00105 return -1;
00106
00107 x = atoi(value);
00108
00109 switch (*data) {
00110 case 'a':
00111 case 'A':
00112 ast_channel_setwhentohangup(chan, x);
00113 if (option_verbose > 2) {
00114 if (chan->whentohangup) {
00115 strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC",
00116 gmtime_r(&chan->whentohangup, &myt));
00117 ast_verbose(VERBOSE_PREFIX_3 "Channel will hangup at %s.\n",
00118 timestr);
00119 } else {
00120 ast_verbose(VERBOSE_PREFIX_3 "Channel hangup cancelled.\n");
00121 }
00122 }
00123 break;
00124
00125 case 'r':
00126 case 'R':
00127 if (chan->pbx) {
00128 chan->pbx->rtimeout = x;
00129 if (option_verbose > 2)
00130 ast_verbose(VERBOSE_PREFIX_3 "Response timeout set to %d\n",
00131 chan->pbx->rtimeout);
00132 }
00133 break;
00134
00135 case 'd':
00136 case 'D':
00137 if (chan->pbx) {
00138 chan->pbx->dtimeout = x;
00139 if (option_verbose > 2)
00140 ast_verbose(VERBOSE_PREFIX_3 "Digit timeout set to %d\n",
00141 chan->pbx->dtimeout);
00142 }
00143 break;
00144
00145 default:
00146 ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
00147 break;
00148 }
00149
00150 return 0;
00151 }
00152
00153 static struct ast_custom_function timeout_function = {
00154 .name = "TIMEOUT",
00155 .synopsis = "Gets or sets timeouts on the channel.",
00156 .syntax = "TIMEOUT(timeouttype)",
00157 .desc =
00158 "Gets or sets various channel timeouts. The timeouts that can be\n"
00159 "manipulated are:\n" "\n"
00160 "absolute: The absolute maximum amount of time permitted for a call. A\n"
00161 " setting of 0 disables the timeout.\n" "\n"
00162 "digit: The maximum amount of time permitted between digits when the\n"
00163 " user is typing in an extension. When this timeout expires,\n"
00164 " after the user has started to type in an extension, the\n"
00165 " extension will be considered complete, and will be\n"
00166 " interpreted. Note that if an extension typed in is valid,\n"
00167 " it will not have to timeout to be tested, so typically at\n"
00168 " the expiry of this timeout, the extension will be considered\n"
00169 " invalid (and thus control would be passed to the 'i'\n"
00170 " extension, or if it doesn't exist the call would be\n"
00171 " terminated). The default timeout is 5 seconds.\n" "\n"
00172 "response: The maximum amount of time permitted after falling through a\n"
00173 " series of priorities for a channel in which the user may\n"
00174 " begin typing an extension. If the user does not type an\n"
00175 " extension in this amount of time, control will pass to the\n"
00176 " 't' extension if it exists, and if not the call would be\n"
00177 " terminated. The default timeout is 10 seconds.\n",
00178 .read = timeout_read,
00179 .write = timeout_write,
00180 };
00181
00182 static int unload_module(void)
00183 {
00184 return ast_custom_function_unregister(&timeout_function);
00185 }
00186
00187 static int load_module(void)
00188 {
00189 return ast_custom_function_register(&timeout_function);
00190 }
00191
00192 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel timeout dialplan functions");