Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
func_timeout.c File Reference

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"
Include dependency graph for func_timeout.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Channel timeout dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function timeout_function
 

Detailed Description

Channel timeout related dialplan functions.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file func_timeout.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 212 of file func_timeout.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 212 of file func_timeout.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 212 of file func_timeout.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 207 of file func_timeout.c.

208{
210}
static struct ast_custom_function timeout_function
Definition: func_timeout.c:195
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References ast_custom_function_register, and timeout_function.

◆ timeout_read()

static int timeout_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 75 of file func_timeout.c.

77{
78 struct timeval myt;
79
80 if (!chan)
81 return -1;
82
83 if (!data) {
84 ast_log(LOG_ERROR, "Must specify type of timeout to get.\n");
85 return -1;
86 }
87
88 switch (*data) {
89 case 'a':
90 case 'A':
92 ast_copy_string(buf, "0", len);
93 } else {
94 myt = ast_tvnow();
95 snprintf(buf, len, "%.3f", ast_tvdiff_ms(*ast_channel_whentohangup(chan), myt) / 1000.0);
96 }
97 break;
98
99 case 'r':
100 case 'R':
101 if (ast_channel_pbx(chan)) {
102 snprintf(buf, len, "%.3f", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
103 }
104 break;
105
106 case 'd':
107 case 'D':
108 if (ast_channel_pbx(chan)) {
109 snprintf(buf, len, "%.3f", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
110 }
111 break;
112
113 default:
114 ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
115 return -1;
116 }
117
118 return 0;
119}
#define ast_log
Definition: astobj2.c:42
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_ERROR
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:117
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

References ast_channel_pbx(), ast_channel_whentohangup(), ast_copy_string(), ast_log, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), buf, len(), and LOG_ERROR.

◆ timeout_write()

static int timeout_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Definition at line 121 of file func_timeout.c.

123{
124 double x = 0.0;
125 long sec = 0L;
126 char timestr[64];
127 struct ast_tm myt;
128 struct timeval when = {0,};
129 int res;
130
131 if (!chan)
132 return -1;
133
134 if (!data) {
135 ast_log(LOG_ERROR, "Must specify type of timeout to set.\n");
136 return -1;
137 }
138
139 if (!value)
140 return -1;
141
142 res = sscanf(value, "%30ld%30lf", &sec, &x);
143 if (res == 0 || sec < 0) {
144 when.tv_sec = 0;
145 when.tv_usec = 0;
146 } else if (res == 1) {
147 when.tv_sec = sec;
148 } else if (res == 2) {
149 when.tv_sec = sec;
150 when.tv_usec = x * 1000000;
151 }
152
153 switch (*data) {
154 case 'a':
155 case 'A':
156 ast_channel_lock(chan);
158 ast_channel_unlock(chan);
159 if (VERBOSITY_ATLEAST(3)) {
161 when = ast_tvadd(when, ast_tvnow());
162 ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z",
163 ast_localtime(&when, &myt, NULL));
164 ast_verb(3, "Channel will hangup at %s.\n", timestr);
165 } else {
166 ast_verb(3, "Channel hangup cancelled.\n");
167 }
168 }
169 break;
170
171 case 'r':
172 case 'R':
173 if (ast_channel_pbx(chan)) {
174 ast_channel_pbx(chan)->rtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
175 ast_verb(3, "Response timeout set to %.3f\n", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
176 }
177 break;
178
179 case 'd':
180 case 'D':
181 if (ast_channel_pbx(chan)) {
182 ast_channel_pbx(chan)->dtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
183 ast_verb(3, "Digit timeout set to %.3f\n", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
184 }
185 break;
186
187 default:
188 ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
189 break;
190 }
191
192 return 0;
193}
#define ast_channel_lock(chan)
Definition: channel.h:2968
void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
Set when to hang a channel up.
Definition: channel.c:510
#define ast_channel_unlock(chan)
Definition: channel.h:2969
#define VERBOSITY_ATLEAST(level)
#define ast_verb(level,...)
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition: localtime.c:2524
#define NULL
Definition: resample.c:96
int rtimeoutms
Definition: pbx.h:216
int dtimeoutms
Definition: pbx.h:215
int value
Definition: syslog.c:37
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2282

References ast_channel_lock, ast_channel_pbx(), ast_channel_setwhentohangup_tv(), ast_channel_unlock, ast_channel_whentohangup(), ast_localtime(), ast_log, ast_strftime(), ast_tvadd(), ast_tvnow(), ast_tvzero(), ast_verb, ast_pbx::dtimeoutms, LOG_ERROR, NULL, ast_pbx::rtimeoutms, value, and VERBOSITY_ATLEAST.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 202 of file func_timeout.c.

203{
205}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and timeout_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Channel timeout dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 212 of file func_timeout.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 212 of file func_timeout.c.

◆ timeout_function

struct ast_custom_function timeout_function
static

Definition at line 195 of file func_timeout.c.

Referenced by load_module(), and unload_module().