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