Channel timeout related dialplan functions. More...
#include "asterisk.h"#include "asterisk/module.h"#include "asterisk/channel.h"#include "asterisk/pbx.h"#include "asterisk/utils.h"#include "asterisk/app.h"
Go to the source code of this file.
Functions | |
| AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Channel timeout dialplan functions") | |
| static int | load_module (void) |
| static int | timeout_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| static int | timeout_write (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| static int | unload_module (void) |
Variables | |
| static struct ast_custom_function | timeout_function |
Channel timeout related dialplan functions.
Definition in file func_timeout.c.
| AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
| "Channel timeout dialplan functions" | ||||
| ) |
| static int load_module | ( | void | ) | [static] |
Definition at line 202 of file func_timeout.c.
References ast_custom_function_register.
00203 { 00204 return ast_custom_function_register(&timeout_function); 00205 }
| static int timeout_read | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 73 of file func_timeout.c.
References ast_copy_string(), ast_log(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_pbx::dtimeoutms, LOG_ERROR, ast_channel::pbx, ast_pbx::rtimeoutms, and ast_channel::whentohangup.
00075 { 00076 struct timeval myt; 00077 00078 if (!chan) 00079 return -1; 00080 00081 if (!data) { 00082 ast_log(LOG_ERROR, "Must specify type of timeout to get.\n"); 00083 return -1; 00084 } 00085 00086 switch (*data) { 00087 case 'a': 00088 case 'A': 00089 if (ast_tvzero(chan->whentohangup)) { 00090 ast_copy_string(buf, "0", len); 00091 } else { 00092 myt = ast_tvnow(); 00093 snprintf(buf, len, "%.3f", ast_tvdiff_ms(chan->whentohangup, myt) / 1000.0); 00094 } 00095 break; 00096 00097 case 'r': 00098 case 'R': 00099 if (chan->pbx) { 00100 snprintf(buf, len, "%.3f", chan->pbx->rtimeoutms / 1000.0); 00101 } 00102 break; 00103 00104 case 'd': 00105 case 'D': 00106 if (chan->pbx) { 00107 snprintf(buf, len, "%.3f", chan->pbx->dtimeoutms / 1000.0); 00108 } 00109 break; 00110 00111 default: 00112 ast_log(LOG_ERROR, "Unknown timeout type specified.\n"); 00113 return -1; 00114 } 00115 00116 return 0; 00117 }
| static int timeout_write | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 119 of file func_timeout.c.
References ast_channel_setwhentohangup_tv(), ast_localtime(), ast_log(), ast_strftime(), ast_tvadd(), ast_tvnow(), ast_tvzero(), ast_verb, ast_verbose, ast_pbx::dtimeoutms, LOG_ERROR, ast_channel::pbx, ast_pbx::rtimeoutms, sec, VERBOSITY_ATLEAST, and ast_channel::whentohangup.
00121 { 00122 double x = 0.0; 00123 long sec = 0L; 00124 char timestr[64]; 00125 struct ast_tm myt; 00126 struct timeval when = {0,}; 00127 int res; 00128 00129 if (!chan) 00130 return -1; 00131 00132 if (!data) { 00133 ast_log(LOG_ERROR, "Must specify type of timeout to set.\n"); 00134 return -1; 00135 } 00136 00137 if (!value) 00138 return -1; 00139 00140 res = sscanf(value, "%30ld%30lf", &sec, &x); 00141 if (res == 0 || sec < 0) { 00142 when.tv_sec = 0; 00143 when.tv_usec = 0; 00144 } else if (res == 1) { 00145 when.tv_sec = sec; 00146 } else if (res == 2) { 00147 when.tv_sec = sec; 00148 when.tv_usec = x * 1000000; 00149 } 00150 00151 switch (*data) { 00152 case 'a': 00153 case 'A': 00154 ast_channel_setwhentohangup_tv(chan, when); 00155 if (VERBOSITY_ATLEAST(3)) { 00156 if (!ast_tvzero(chan->whentohangup)) { 00157 when = ast_tvadd(when, ast_tvnow()); 00158 ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z", 00159 ast_localtime(&when, &myt, NULL)); 00160 ast_verbose("Channel will hangup at %s.\n", timestr); 00161 } else { 00162 ast_verbose("Channel hangup cancelled.\n"); 00163 } 00164 } 00165 break; 00166 00167 case 'r': 00168 case 'R': 00169 if (chan->pbx) { 00170 chan->pbx->rtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000.0; 00171 ast_verb(3, "Response timeout set to %.3f\n", chan->pbx->rtimeoutms / 1000.0); 00172 } 00173 break; 00174 00175 case 'd': 00176 case 'D': 00177 if (chan->pbx) { 00178 chan->pbx->dtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000.0; 00179 ast_verb(3, "Digit timeout set to %.3f\n", chan->pbx->dtimeoutms / 1000.0); 00180 } 00181 break; 00182 00183 default: 00184 ast_log(LOG_ERROR, "Unknown timeout type specified.\n"); 00185 break; 00186 } 00187 00188 return 0; 00189 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 197 of file func_timeout.c.
References ast_custom_function_unregister().
00198 { 00199 return ast_custom_function_unregister(&timeout_function); 00200 }
struct ast_custom_function timeout_function [static] |
{
.name = "TIMEOUT",
.read = timeout_read,
.write = timeout_write,
}
Definition at line 191 of file func_timeout.c.
1.6.1