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