Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


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"

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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

static void __reg_module ( void  )
static

Definition at line 212 of file func_timeout.c.

static void __unreg_module ( void  )
static

Definition at line 212 of file func_timeout.c.

static int load_module ( void  )
static

Definition at line 207 of file func_timeout.c.

References ast_custom_function_register.

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:1164
static int timeout_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 77 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.

79 {
80  struct timeval myt;
81 
82  if (!chan)
83  return -1;
84 
85  if (!data) {
86  ast_log(LOG_ERROR, "Must specify type of timeout to get.\n");
87  return -1;
88  }
89 
90  switch (*data) {
91  case 'a':
92  case 'A':
93  if (ast_tvzero(chan->whentohangup)) {
94  ast_copy_string(buf, "0", len);
95  } else {
96  myt = ast_tvnow();
97  snprintf(buf, len, "%.3f", ast_tvdiff_ms(chan->whentohangup, myt) / 1000.0);
98  }
99  break;
100 
101  case 'r':
102  case 'R':
103  if (chan->pbx) {
104  snprintf(buf, len, "%.3f", chan->pbx->rtimeoutms / 1000.0);
105  }
106  break;
107 
108  case 'd':
109  case 'D':
110  if (chan->pbx) {
111  snprintf(buf, len, "%.3f", chan->pbx->dtimeoutms / 1000.0);
112  }
113  break;
114 
115  default:
116  ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
117  return -1;
118  }
119 
120  return 0;
121 }
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:100
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:90
#define LOG_ERROR
Definition: logger.h:155
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int dtimeoutms
Definition: pbx.h:180
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
struct timeval whentohangup
Definition: channel.h:789
struct ast_pbx * pbx
Definition: channel.h:761
int rtimeoutms
Definition: pbx.h:181
static int timeout_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Definition at line 123 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, VERBOSITY_ATLEAST, and ast_channel::whentohangup.

125 {
126  double x = 0.0;
127  long sec = 0L;
128  char timestr[64];
129  struct ast_tm myt;
130  struct timeval when = {0,};
131  int res;
132 
133  if (!chan)
134  return -1;
135 
136  if (!data) {
137  ast_log(LOG_ERROR, "Must specify type of timeout to set.\n");
138  return -1;
139  }
140 
141  if (!value)
142  return -1;
143 
144  res = sscanf(value, "%30ld%30lf", &sec, &x);
145  if (res == 0 || sec < 0) {
146  when.tv_sec = 0;
147  when.tv_usec = 0;
148  } else if (res == 1) {
149  when.tv_sec = sec;
150  } else if (res == 2) {
151  when.tv_sec = sec;
152  when.tv_usec = x * 1000000;
153  }
154 
155  switch (*data) {
156  case 'a':
157  case 'A':
158  ast_channel_setwhentohangup_tv(chan, when);
159  if (VERBOSITY_ATLEAST(3)) {
160  if (!ast_tvzero(chan->whentohangup)) {
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_verbose("Channel will hangup at %s.\n", timestr);
165  } else {
166  ast_verbose("Channel hangup cancelled.\n");
167  }
168  }
169  break;
170 
171  case 'r':
172  case 'R':
173  if (chan->pbx) {
174  chan->pbx->rtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
175  ast_verb(3, "Response timeout set to %.3f\n", chan->pbx->rtimeoutms / 1000.0);
176  }
177  break;
178 
179  case 'd':
180  case 'D':
181  if (chan->pbx) {
182  chan->pbx->dtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
183  ast_verb(3, "Digit timeout set to %.3f\n", chan->pbx->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 }
void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
Set when to hang a channel up.
Definition: channel.c:871
void ast_verbose(const char *fmt,...)
Definition: logger.c:1568
#define VERBOSITY_ATLEAST(level)
Definition: logger.h:241
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:1570
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:100
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
int value
Definition: syslog.c:39
#define ast_verb(level,...)
Definition: logger.h:243
#define LOG_ERROR
Definition: logger.h:155
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: utils.c:1587
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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:2351
int dtimeoutms
Definition: pbx.h:180
struct timeval whentohangup
Definition: channel.h:789
struct ast_pbx * pbx
Definition: channel.h:761
int rtimeoutms
Definition: pbx.h:181
static int unload_module ( void  )
static

Definition at line 202 of file func_timeout.c.

References ast_custom_function_unregister().

203 {
205 }
static struct ast_custom_function timeout_function
Definition: func_timeout.c:195
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 212 of file func_timeout.c.

Definition at line 212 of file func_timeout.c.

struct ast_custom_function timeout_function
static

Definition at line 195 of file func_timeout.c.