Sat Apr 26 2014 22:02:52

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"
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, }
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 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.

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.

{
   struct timeval myt;

   if (!chan)
      return -1;

   if (!data) {
      ast_log(LOG_ERROR, "Must specify type of timeout to get.\n");
      return -1;
   }

   switch (*data) {
   case 'a':
   case 'A':
      if (ast_tvzero(*ast_channel_whentohangup(chan))) {
         ast_copy_string(buf, "0", len);
      } else {
         myt = ast_tvnow();
         snprintf(buf, len, "%.3f", ast_tvdiff_ms(*ast_channel_whentohangup(chan), myt) / 1000.0);
      }
      break;

   case 'r':
   case 'R':
      if (ast_channel_pbx(chan)) {
         snprintf(buf, len, "%.3f", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
      }
      break;

   case 'd':
   case 'D':
      if (ast_channel_pbx(chan)) {
         snprintf(buf, len, "%.3f", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
      }
      break;

   default:
      ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
      return -1;
   }

   return 0;
}
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_pbx(), ast_channel_setwhentohangup_tv(), ast_channel_whentohangup(), ast_localtime(), ast_log(), ast_strftime(), ast_tvadd(), ast_tvnow(), ast_tvzero(), ast_verb, ast_pbx::dtimeoutms, LOG_ERROR, ast_pbx::rtimeoutms, and VERBOSITY_ATLEAST.

{
   double x = 0.0;
   long sec = 0L;
   char timestr[64];
   struct ast_tm myt;
   struct timeval when = {0,};
   int res;

   if (!chan)
      return -1;

   if (!data) {
      ast_log(LOG_ERROR, "Must specify type of timeout to set.\n");
      return -1;
   }

   if (!value)
      return -1;

   res = sscanf(value, "%30ld%30lf", &sec, &x);
   if (res == 0 || sec < 0) {
      when.tv_sec = 0;
      when.tv_usec = 0;
   } else if (res == 1) {
      when.tv_sec = sec;
   } else if (res == 2) {
      when.tv_sec = sec;
      when.tv_usec = x * 1000000;
   }

   switch (*data) {
   case 'a':
   case 'A':
      ast_channel_setwhentohangup_tv(chan, when);
      if (VERBOSITY_ATLEAST(3)) {
         if (!ast_tvzero(*ast_channel_whentohangup(chan))) {
            when = ast_tvadd(when, ast_tvnow());
            ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z",
               ast_localtime(&when, &myt, NULL));
            ast_verb(3, "Channel will hangup at %s.\n", timestr);
         } else {
            ast_verb(3, "Channel hangup cancelled.\n");
         }
      }
      break;

   case 'r':
   case 'R':
      if (ast_channel_pbx(chan)) {
         ast_channel_pbx(chan)->rtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
         ast_verb(3, "Response timeout set to %.3f\n", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
      }
      break;

   case 'd':
   case 'D':
      if (ast_channel_pbx(chan)) {
         ast_channel_pbx(chan)->dtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
         ast_verb(3, "Digit timeout set to %.3f\n", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
      }
      break;

   default:
      ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
      break;
   }

   return 0;
}
static int unload_module ( void  ) [static]

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, } [static]

Definition at line 212 of file func_timeout.c.

Definition at line 212 of file func_timeout.c.

Definition at line 195 of file func_timeout.c.