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