Thu Oct 8 21:56:26 2009

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 189 of file func_timeout.c.

References ast_custom_function_register().

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

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

Definition at line 43 of file func_timeout.c.

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

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

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

Definition at line 89 of file func_timeout.c.

References ast_channel_setwhentohangup(), ast_log(), ast_verbose(), ast_pbx::dtimeout, LOG_ERROR, option_verbose, ast_channel::pbx, ast_pbx::rtimeout, VERBOSE_PREFIX_3, and ast_channel::whentohangup.

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

static int unload_module ( void   )  [static]

Definition at line 184 of file func_timeout.c.

References ast_custom_function_unregister().

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


Variable Documentation

Definition at line 155 of file func_timeout.c.


Generated on Thu Oct 8 21:56:26 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6