Fri Aug 24 02:26:10 2007

Asterisk developer's documentation


func_timeout.c File Reference

Channel timeout related dialplan functions. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/options.h"

Include dependency graph for func_timeout.c:

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, char *cmd, char *data, char *buf, size_t len)
static int timeout_write (struct ast_channel *chan, char *cmd, char *data, const char *value)
static int unload_module (void)

Variables

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

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Channel timeout dialplan functions"   
)

static int load_module ( void   )  [static]

Definition at line 188 of file func_timeout.c.

References ast_custom_function_register(), and timeout_function.

00189 {
00190    return ast_custom_function_register(&timeout_function);
00191 }

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

Definition at line 44 of file func_timeout.c.

References ast_log(), ast_pbx::dtimeout, LOG_ERROR, ast_channel::pbx, ast_pbx::rtimeout, and ast_channel::whentohangup.

00046 {
00047    time_t myt;
00048 
00049    if (!chan)
00050       return -1;
00051 
00052    if (!data) {
00053       ast_log(LOG_ERROR, "Must specify type of timeout to get.\n");
00054       return -1;
00055    }
00056 
00057    switch (*data) {
00058    case 'a':
00059    case 'A':
00060       if (chan->whentohangup == 0) {
00061          ast_copy_string(buf, "0", len);
00062       } else {
00063          time(&myt);
00064          snprintf(buf, len, "%d", (int) (chan->whentohangup - myt));
00065       }
00066       break;
00067 
00068    case 'r':
00069    case 'R':
00070       if (chan->pbx) {
00071          snprintf(buf, len, "%d", chan->pbx->rtimeout);
00072       }
00073       break;
00074 
00075    case 'd':
00076    case 'D':
00077       if (chan->pbx) {
00078          snprintf(buf, len, "%d", chan->pbx->dtimeout);
00079       }
00080       break;
00081 
00082    default:
00083       ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
00084       break;
00085    }
00086 
00087    return 0;
00088 }

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

Definition at line 90 of file func_timeout.c.

References ast_channel_setwhentohangup(), ast_log(), ast_verbose(), LOG_ERROR, option_verbose, and VERBOSE_PREFIX_3.

00092 {
00093    int x;
00094    char timestr[64];
00095    struct tm myt;
00096 
00097    if (!chan)
00098       return -1;
00099 
00100    if (!data) {
00101       ast_log(LOG_ERROR, "Must specify type of timeout to set.\n");
00102       return -1;
00103    }
00104 
00105    if (!value)
00106       return -1;
00107 
00108    x = atoi(value);
00109 
00110    switch (*data) {
00111    case 'a':
00112    case 'A':
00113       ast_channel_setwhentohangup(chan, x);
00114       if (option_verbose > 2) {
00115          if (chan->whentohangup) {
00116             strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC",
00117                 gmtime_r(&chan->whentohangup, &myt));
00118             ast_verbose(VERBOSE_PREFIX_3 "Channel will hangup at %s.\n",
00119                    timestr);
00120          } else {
00121             ast_verbose(VERBOSE_PREFIX_3 "Channel hangup cancelled.\n");
00122          }
00123       }
00124       break;
00125 
00126    case 'r':
00127    case 'R':
00128       if (chan->pbx) {
00129          chan->pbx->rtimeout = x;
00130          if (option_verbose > 2)
00131             ast_verbose(VERBOSE_PREFIX_3 "Response timeout set to %d\n",
00132                    chan->pbx->rtimeout);
00133       }
00134       break;
00135 
00136    case 'd':
00137    case 'D':
00138       if (chan->pbx) {
00139          chan->pbx->dtimeout = x;
00140          if (option_verbose > 2)
00141             ast_verbose(VERBOSE_PREFIX_3 "Digit timeout set to %d\n",
00142                    chan->pbx->dtimeout);
00143       }
00144       break;
00145 
00146    default:
00147       ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
00148       break;
00149    }
00150 
00151    return 0;
00152 }

static int unload_module ( void   )  [static]

Definition at line 183 of file func_timeout.c.

References ast_custom_function_unregister(), and timeout_function.

00184 {
00185    return ast_custom_function_unregister(&timeout_function);
00186 }


Variable Documentation

struct ast_custom_function timeout_function [static]

Definition at line 154 of file func_timeout.c.

Referenced by load_module(), and unload_module().


Generated on Fri Aug 24 02:26:10 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1