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)
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 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 <markster@digium.com>

Definition in file func_timeout.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 214 of file func_timeout.c.

static void __unreg_module ( void   )  [static]

Definition at line 214 of file func_timeout.c.

static int load_module ( void   )  [static]

Definition at line 209 of file func_timeout.c.

References ast_custom_function_register.

00210 {
00211    return ast_custom_function_register(&timeout_function);
00212 }

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_channel_pbx(), ast_channel_whentohangup(), ast_copy_string(), ast_log, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and LOG_ERROR.

00079 {
00080    struct timeval myt;
00081 
00082    if (!chan)
00083       return -1;
00084 
00085    if (!data) {
00086       ast_log(LOG_ERROR, "Must specify type of timeout to get.\n");
00087       return -1;
00088    }
00089 
00090    switch (*data) {
00091    case 'a':
00092    case 'A':
00093       if (ast_tvzero(*ast_channel_whentohangup(chan))) {
00094          ast_copy_string(buf, "0", len);
00095       } else {
00096          myt = ast_tvnow();
00097          snprintf(buf, len, "%.3f", ast_tvdiff_ms(*ast_channel_whentohangup(chan), myt) / 1000.0);
00098       }
00099       break;
00100 
00101    case 'r':
00102    case 'R':
00103       if (ast_channel_pbx(chan)) {
00104          snprintf(buf, len, "%.3f", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
00105       }
00106       break;
00107 
00108    case 'd':
00109    case 'D':
00110       if (ast_channel_pbx(chan)) {
00111          snprintf(buf, len, "%.3f", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
00112       }
00113       break;
00114 
00115    default:
00116       ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
00117       return -1;
00118    }
00119 
00120    return 0;
00121 }

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_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, and VERBOSITY_ATLEAST.

00125 {
00126    double x = 0.0;
00127    long sec = 0L;
00128    char timestr[64];
00129    struct ast_tm myt;
00130    struct timeval when = {0,};
00131    int res;
00132 
00133    if (!chan)
00134       return -1;
00135 
00136    if (!data) {
00137       ast_log(LOG_ERROR, "Must specify type of timeout to set.\n");
00138       return -1;
00139    }
00140 
00141    if (!value)
00142       return -1;
00143 
00144    res = sscanf(value, "%30ld%30lf", &sec, &x);
00145    if (res == 0 || sec < 0) {
00146       when.tv_sec = 0;
00147       when.tv_usec = 0;
00148    } else if (res == 1) {
00149       when.tv_sec = sec;
00150    } else if (res == 2) {
00151       when.tv_sec = sec;
00152       when.tv_usec = x * 1000000;
00153    }
00154 
00155    switch (*data) {
00156    case 'a':
00157    case 'A':
00158       ast_channel_lock(chan);
00159       ast_channel_setwhentohangup_tv(chan, when);
00160       ast_channel_unlock(chan);
00161       if (VERBOSITY_ATLEAST(3)) {
00162          if (!ast_tvzero(*ast_channel_whentohangup(chan))) {
00163             when = ast_tvadd(when, ast_tvnow());
00164             ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z",
00165                ast_localtime(&when, &myt, NULL));
00166             ast_verb(3, "Channel will hangup at %s.\n", timestr);
00167          } else {
00168             ast_verb(3, "Channel hangup cancelled.\n");
00169          }
00170       }
00171       break;
00172 
00173    case 'r':
00174    case 'R':
00175       if (ast_channel_pbx(chan)) {
00176          ast_channel_pbx(chan)->rtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
00177          ast_verb(3, "Response timeout set to %.3f\n", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
00178       }
00179       break;
00180 
00181    case 'd':
00182    case 'D':
00183       if (ast_channel_pbx(chan)) {
00184          ast_channel_pbx(chan)->dtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
00185          ast_verb(3, "Digit timeout set to %.3f\n", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
00186       }
00187       break;
00188 
00189    default:
00190       ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
00191       break;
00192    }
00193 
00194    return 0;
00195 }

static int unload_module ( void   )  [static]

Definition at line 204 of file func_timeout.c.

References ast_custom_function_unregister().

00205 {
00206    return ast_custom_function_unregister(&timeout_function);
00207 }


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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 214 of file func_timeout.c.

Definition at line 214 of file func_timeout.c.

Definition at line 197 of file func_timeout.c.


Generated on Thu Apr 16 06:31:27 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6