Fri Jul 3 20:39:00 2009

Asterisk developer's documentation


res_agi.c File Reference

AGI - the Asterisk Gateway Interface. More...

#include "asterisk.h"
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/astdb.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/options.h"
#include "asterisk/image.h"
#include "asterisk/say.h"
#include "asterisk/app.h"
#include "asterisk/dsp.h"
#include "asterisk/musiconhold.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/strings.h"
#include "asterisk/agi.h"
#include "asterisk/features.h"

Include dependency graph for res_agi.c:

Go to the source code of this file.

Defines

#define AGI_BUF_LEN   2048
#define AGI_NANDFS_RETRY   3
#define AGI_PORT   4573
#define fdprintf   agi_debug_cli
#define MAX_AGI_CONNECT   2000
#define MAX_ARGS   128
#define MAX_COMMANDS   128
#define RETRY   3
#define TONE_BLOCK_SIZE   200

Enumerations

enum  agi_result { AGI_RESULT_FAILURE = -1, AGI_RESULT_SUCCESS, AGI_RESULT_SUCCESS_FAST, AGI_RESULT_HANGUP }

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int agi_debug_cli (int fd, char *fmt,...)
static int agi_do_debug (int fd, int argc, char *argv[])
static int agi_exec (struct ast_channel *chan, void *data)
static int agi_exec_full (struct ast_channel *chan, void *data, int enhanced, int dead)
static int agi_handle_command (struct ast_channel *chan, AGI *agi, char *buf)
static int agi_no_debug (int fd, int argc, char *argv[])
static int agi_no_debug_deprecated (int fd, int argc, char *argv[])
int ast_agi_register (agi_command *agi)
void ast_agi_unregister (agi_command *agi)
static int deadagi_exec (struct ast_channel *chan, void *data)
static int eagi_exec (struct ast_channel *chan, void *data)
static agi_command * find_command (char *cmds[], int exact)
static int handle_agidumphtml (int fd, int argc, char *argv[])
static int handle_answer (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_autohangup (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_channelstatus (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_controlstreamfile (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_dbdel (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_dbdeltree (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_dbget (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_dbput (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_exec (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_getdata (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_getoption (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_getvariable (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_getvariablefull (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_hangup (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_noop (struct ast_channel *chan, AGI *agi, int arg, char *argv[])
static int handle_recordfile (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_recvchar (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_recvtext (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_sayalpha (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_saydate (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_saydatetime (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_saydigits (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_saynumber (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_sayphonetic (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_saytime (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_sendimage (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_sendtext (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_setcallerid (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_setcontext (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_setextension (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_setmusic (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_setpriority (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_setvariable (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_showagi (int fd, int argc, char *argv[])
static int handle_streamfile (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_tddmode (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int handle_verbose (struct ast_channel *chan, AGI *agi, int argc, char **argv)
static int handle_waitfordigit (struct ast_channel *chan, AGI *agi, int argc, char *argv[])
static int help_workhorse (int fd, char *match[])
static enum agi_result launch_netscript (char *agiurl, char *argv[], int *fds, int *efd, int *opid)
static enum agi_result launch_script (char *script, char *argv[], int *fds, int *efd, int *opid)
static int load_module (void)
static int parse_args (char *s, int *max, char *argv[])
static enum agi_result run_agi (struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
static void setup_env (struct ast_channel *chan, char *request, int fd, int enhanced, int argc, char *argv[])
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_BUILDSUM, .description = "Asterisk Gateway Interface (AGI)" , .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, }
static int agidebug = 0
static char * app = "AGI"
static const struct
ast_module_info * 
ast_module_info = &__mod_info
static struct ast_cli_entry cli_agi []
static struct ast_cli_entry cli_agi_no_debug_deprecated
static struct ast_cli_entry cli_dump_agihtml_deprecated
static struct ast_cli_entry cli_show_agi_deprecated
static agi_command commands [MAX_COMMANDS]
static char * deadapp = "DeadAGI"
static char * deadsynopsis = "Executes AGI on a hungup channel"
static char debug_usage []
static char * descrip
static char dumpagihtml_help []
static char * eapp = "EAGI"
static char * esynopsis = "Executes an EAGI compliant application"
static char no_debug_usage []
static char showagi_help []
static char * synopsis = "Executes an AGI compliant application"
static char usage_answer []
static char usage_autohangup []
static char usage_channelstatus []
static char usage_controlstreamfile []
static char usage_dbdel []
static char usage_dbdeltree []
static char usage_dbget []
static char usage_dbput []
static char usage_exec []
static char usage_getdata []
static char usage_getoption []
static char usage_getvariable []
static char usage_getvariablefull []
static char usage_hangup []
static char usage_noop []
static char usage_recordfile []
static char usage_recvchar []
static char usage_recvtext []
static char usage_sayalpha []
static char usage_saydate []
static char usage_saydatetime []
static char usage_saydigits []
static char usage_saynumber []
static char usage_sayphonetic []
static char usage_saytime []
static char usage_sendimage []
static char usage_sendtext []
static char usage_setcallerid []
static char usage_setcontext []
static char usage_setextension []
static char usage_setmusic []
static char usage_setpriority []
static char usage_setvariable []
static char usage_streamfile []
static char usage_tddmode []
static char usage_verbose []
static char usage_waitfordigit []


Detailed Description

AGI - the Asterisk Gateway Interface.

Author:
Mark Spencer <markster@digium.com>

Definition in file res_agi.c.


Define Documentation

#define AGI_BUF_LEN   2048

Definition at line 73 of file res_agi.c.

Referenced by agi_exec_full(), and run_agi().

#define AGI_NANDFS_RETRY   3

Definition at line 72 of file res_agi.c.

Referenced by run_agi().

#define AGI_PORT   4573

Definition at line 114 of file res_agi.c.

Referenced by launch_netscript().

#define fdprintf   agi_debug_cli

#define MAX_AGI_CONNECT   2000

Definition at line 112 of file res_agi.c.

Referenced by launch_netscript().

#define MAX_ARGS   128

Definition at line 70 of file res_agi.c.

#define MAX_COMMANDS   128

Definition at line 71 of file res_agi.c.

Referenced by ast_agi_register(), and ast_agi_unregister().

#define RETRY   3

Definition at line 1855 of file res_agi.c.

#define TONE_BLOCK_SIZE   200

Definition at line 109 of file res_agi.c.


Enumeration Type Documentation

enum agi_result

Enumerator:
AGI_RESULT_FAILURE 
AGI_RESULT_SUCCESS 
AGI_RESULT_SUCCESS_FAST 
AGI_RESULT_HANGUP 

Definition at line 116 of file res_agi.c.

00116                 {
00117    AGI_RESULT_FAILURE = -1,
00118    AGI_RESULT_SUCCESS,
00119    AGI_RESULT_SUCCESS_FAST,
00120    AGI_RESULT_HANGUP
00121 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 2223 of file res_agi.c.

static void __unreg_module ( void   )  [static]

Definition at line 2223 of file res_agi.c.

static int agi_debug_cli ( int  fd,
char *  fmt,
  ... 
) [static]

Definition at line 123 of file res_agi.c.

References ast_carefulwrite(), ast_log(), ast_verbose(), free, LOG_ERROR, ast_variable::stuff, and vasprintf.

00124 {
00125    char *stuff;
00126    int res = 0;
00127 
00128    va_list ap;
00129    va_start(ap, fmt);
00130    res = vasprintf(&stuff, fmt, ap);
00131    va_end(ap);
00132    if (res == -1) {
00133       ast_log(LOG_ERROR, "Out of memory\n");
00134    } else {
00135       if (agidebug)
00136          ast_verbose("AGI Tx >> %s", stuff); /* \n provided by caller */
00137       res = ast_carefulwrite(fd, stuff, strlen(stuff), 100);
00138       free(stuff);
00139    }
00140 
00141    return res;
00142 }

static int agi_do_debug ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1341 of file res_agi.c.

References ast_cli(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01342 {
01343    if (argc != 2)
01344       return RESULT_SHOWUSAGE;
01345    agidebug = 1;
01346    ast_cli(fd, "AGI Debugging Enabled\n");
01347    return RESULT_SUCCESS;
01348 }

static int agi_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 2124 of file res_agi.c.

References ast_channel::_softhangup, agi_exec_full(), ast_log(), and LOG_WARNING.

Referenced by load_module().

02125 {
02126    if (chan->_softhangup)
02127       ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n");
02128    return agi_exec_full(chan, data, 0, 0);
02129 }

static int agi_exec_full ( struct ast_channel *  chan,
void *  data,
int  enhanced,
int  dead 
) [static]

Definition at line 2053 of file res_agi.c.

References ast_channel::_state, AGI_BUF_LEN, AGI_RESULT_FAILURE, AGI_RESULT_HANGUP, AGI_RESULT_SUCCESS, AGI_RESULT_SUCCESS_FAST, ast_answer(), ast_copy_string(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_replace_sigchld(), AST_STATE_UP, ast_strlen_zero(), ast_unreplace_sigchld(), agi_state::audio, agi_state::ctrl, agi_state::fast, agi_state::fd, launch_script(), LOG_WARNING, MAX_ARGS, pbx_builtin_setvar_helper(), and run_agi().

Referenced by agi_exec(), deadagi_exec(), and eagi_exec().

02054 {
02055    enum agi_result res;
02056    struct ast_module_user *u;
02057    char *argv[MAX_ARGS];
02058    char buf[AGI_BUF_LEN] = "";
02059    char *tmp = (char *)buf;
02060    int argc = 0;
02061    int fds[2];
02062    int efd = -1;
02063    int pid;
02064    char *stringp;
02065    AGI agi;
02066 
02067    if (ast_strlen_zero(data)) {
02068       ast_log(LOG_WARNING, "AGI requires an argument (script)\n");
02069       return -1;
02070    }
02071    ast_copy_string(buf, data, sizeof(buf));
02072 
02073    memset(&agi, 0, sizeof(agi));
02074         while ((stringp = strsep(&tmp, "|")) && argc < MAX_ARGS-1)
02075       argv[argc++] = stringp;
02076    argv[argc] = NULL;
02077 
02078    u = ast_module_user_add(chan);
02079 #if 0
02080     /* Answer if need be */
02081         if (chan->_state != AST_STATE_UP) {
02082       if (ast_answer(chan)) {
02083          LOCAL_USER_REMOVE(u);
02084          return -1;
02085       }
02086    }
02087 #endif
02088    ast_replace_sigchld();
02089    res = launch_script(argv[0], argv, fds, enhanced ? &efd : NULL, &pid);
02090    if (res == AGI_RESULT_SUCCESS || res == AGI_RESULT_SUCCESS_FAST) {
02091       int status = 0;
02092       agi.fd = fds[1];
02093       agi.ctrl = fds[0];
02094       agi.audio = efd;
02095       agi.fast = (res == AGI_RESULT_SUCCESS_FAST) ? 1 : 0;
02096       res = run_agi(chan, argv[0], &agi, pid, &status, dead, argc, argv);
02097       /* If the fork'd process returns non-zero, set AGISTATUS to FAILURE */
02098       if ((res == AGI_RESULT_SUCCESS || res == AGI_RESULT_SUCCESS_FAST) && status)
02099          res = AGI_RESULT_FAILURE;
02100       if (fds[1] != fds[0])
02101          close(fds[1]);
02102       if (efd > -1)
02103          close(efd);
02104    }
02105    ast_unreplace_sigchld();
02106    ast_module_user_remove(u);
02107 
02108    switch (res) {
02109    case AGI_RESULT_SUCCESS:
02110    case AGI_RESULT_SUCCESS_FAST:
02111       pbx_builtin_setvar_helper(chan, "AGISTATUS", "SUCCESS");
02112       break;
02113    case AGI_RESULT_FAILURE:
02114       pbx_builtin_setvar_helper(chan, "AGISTATUS", "FAILURE");
02115       break;
02116    case AGI_RESULT_HANGUP:
02117       pbx_builtin_setvar_helper(chan, "AGISTATUS", "HANGUP");
02118       return -1;
02119    }
02120 
02121    return 0;
02122 }

static int agi_handle_command ( struct ast_channel *  chan,
AGI *  agi,
char *  buf 
) [static]

Definition at line 1823 of file res_agi.c.

References AST_PBX_KEEPALIVE, agi_state::fd, fdprintf, find_command(), agi_command::handler, MAX_ARGS, parse_args(), RESULT_FAILURE, RESULT_SHOWUSAGE, and agi_command::usage.

Referenced by run_agi().

01824 {
01825    char *argv[MAX_ARGS];
01826    int argc = MAX_ARGS;
01827    int res;
01828    agi_command *c;
01829 
01830    parse_args(buf, &argc, argv);
01831    c = find_command(argv, 0);
01832    if (c) {
01833       res = c->handler(chan, agi, argc, argv);
01834       switch(res) {
01835       case RESULT_SHOWUSAGE:
01836          fdprintf(agi->fd, "520-Invalid command syntax.  Proper usage follows:\n");
01837          fdprintf(agi->fd, "%s", c->usage);
01838          fdprintf(agi->fd, "520 End of proper usage.\n");
01839          break;
01840       case AST_PBX_KEEPALIVE:
01841          /* We've been asked to keep alive, so do so */
01842          return AST_PBX_KEEPALIVE;
01843          break;
01844       case RESULT_FAILURE:
01845          /* They've already given the failure.  We've been hung up on so handle this
01846             appropriately */
01847          return -1;
01848       }
01849    } else {
01850       fdprintf(agi->fd, "510 Invalid or unknown command\n");
01851    }
01852    return 0;
01853 }

static int agi_no_debug ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1359 of file res_agi.c.

References ast_cli(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01360 {
01361    if (argc != 3)
01362       return RESULT_SHOWUSAGE;
01363    agidebug = 0;
01364    ast_cli(fd, "AGI Debugging Disabled\n");
01365    return RESULT_SUCCESS;
01366 }

static int agi_no_debug_deprecated ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1350 of file res_agi.c.

References ast_cli(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01351 {
01352    if (argc != 3)
01353       return RESULT_SHOWUSAGE;
01354    agidebug = 0;
01355    ast_cli(fd, "AGI Debugging Disabled\n");
01356    return RESULT_SUCCESS;
01357 }

int ast_agi_register ( agi_command *  agi  ) 

Definition at line 1694 of file res_agi.c.

References ast_log(), agi_command::cmda, LOG_WARNING, and MAX_COMMANDS.

01695 {
01696    int x;
01697    for (x=0; x<MAX_COMMANDS - 1; x++) {
01698       if (commands[x].cmda[0] == agi->cmda[0]) {
01699          ast_log(LOG_WARNING, "Command already registered!\n");
01700          return -1;
01701       }
01702    }
01703    for (x=0; x<MAX_COMMANDS - 1; x++) {
01704       if (!commands[x].cmda[0]) {
01705          commands[x] = *agi;
01706          return 0;
01707       }
01708    }
01709    ast_log(LOG_WARNING, "No more room for new commands!\n");
01710    return -1;
01711 }

void ast_agi_unregister ( agi_command *  agi  ) 

Definition at line 1713 of file res_agi.c.

References agi_command::cmda, and MAX_COMMANDS.

01714 {
01715    int x;
01716    for (x=0; x<MAX_COMMANDS - 1; x++) {
01717       if (commands[x].cmda[0] == agi->cmda[0]) {
01718          memset(&commands[x], 0, sizeof(agi_command));
01719       }
01720    }
01721 }

static int deadagi_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 2152 of file res_agi.c.

References agi_exec_full(), ast_check_hangup(), ast_log(), and LOG_WARNING.

Referenced by load_module().

02153 {
02154    if (!ast_check_hangup(chan))
02155       ast_log(LOG_WARNING,"Running DeadAGI on a live channel will cause problems, please use AGI\n");
02156    return agi_exec_full(chan, data, 0, 1);
02157 }

static int eagi_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 2131 of file res_agi.c.

References ast_channel::_softhangup, agi_exec_full(), AST_FORMAT_SLINEAR, ast_getformatname(), ast_log(), ast_set_read_format(), LOG_WARNING, ast_channel::name, and ast_channel::readformat.

Referenced by load_module().

02132 {
02133    int readformat;
02134    int res;
02135 
02136    if (chan->_softhangup)
02137       ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n");
02138    readformat = chan->readformat;
02139    if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
02140       ast_log(LOG_WARNING, "Unable to set channel '%s' to linear mode\n", chan->name);
02141       return -1;
02142    }
02143    res = agi_exec_full(chan, data, 1, 0);
02144    if (!res) {
02145       if (ast_set_read_format(chan, readformat)) {
02146          ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", chan->name, ast_getformatname(readformat));
02147       }
02148    }
02149    return res;
02150 }

static agi_command* find_command ( char *  cmds[],
int  exact 
) [static]

Definition at line 1723 of file res_agi.c.

References agi_command::cmda, and match().

Referenced by agi_handle_command(), and handle_showagi().

01724 {
01725    int x;
01726    int y;
01727    int match;
01728 
01729    for (x=0; x < sizeof(commands) / sizeof(commands[0]); x++) {
01730       if (!commands[x].cmda[0])
01731          break;
01732       /* start optimistic */
01733       match = 1;
01734       for (y=0; match && cmds[y]; y++) {
01735          /* If there are no more words in the command (and we're looking for
01736             an exact match) or there is a difference between the two words,
01737             then this is not a match */
01738          if (!commands[x].cmda[y] && !exact)
01739             break;
01740          /* don't segfault if the next part of a command doesn't exist */
01741          if (!commands[x].cmda[y])
01742             return NULL;
01743          if (strcasecmp(commands[x].cmda[y], cmds[y]))
01744             match = 0;
01745       }
01746       /* If more words are needed to complete the command then this is not
01747          a candidate (unless we're looking for a really inexact answer  */
01748       if ((exact > -1) && commands[x].cmda[y])
01749          match = 0;
01750       if (match)
01751          return &commands[x];
01752    }
01753    return NULL;
01754 }

static int handle_agidumphtml ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1999 of file res_agi.c.

References ast_cli(), ast_join(), agi_command::cmda, RESULT_SHOWUSAGE, RESULT_SUCCESS, agi_command::summary, and agi_command::usage.

02000 {
02001    struct agi_command *e;
02002    char fullcmd[80];
02003    int x;
02004    FILE *htmlfile;
02005 
02006    if ((argc < 3))
02007       return RESULT_SHOWUSAGE;
02008 
02009    if (!(htmlfile = fopen(argv[2], "wt"))) {
02010       ast_cli(fd, "Could not create file '%s'\n", argv[2]);
02011       return RESULT_SHOWUSAGE;
02012    }
02013 
02014    fprintf(htmlfile, "<HTML>\n<HEAD>\n<TITLE>AGI Commands</TITLE>\n</HEAD>\n");
02015    fprintf(htmlfile, "<BODY>\n<CENTER><B><H1>AGI Commands</H1></B></CENTER>\n\n");
02016 
02017 
02018    fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n");
02019 
02020    for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) {
02021       char *stringp, *tempstr;
02022 
02023       e = &commands[x]; 
02024       if (!e->cmda[0])  /* end ? */
02025          break;
02026       /* Hide commands that start with '_' */
02027       if ((e->cmda[0])[0] == '_')
02028          continue;
02029       ast_join(fullcmd, sizeof(fullcmd), e->cmda);
02030 
02031       fprintf(htmlfile, "<TR><TD><TABLE BORDER=\"1\" CELLPADDING=\"5\" WIDTH=\"100%%\">\n");
02032       fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TH></TR>\n", fullcmd,e->summary);
02033 
02034       stringp=e->usage;
02035       tempstr = strsep(&stringp, "\n");
02036 
02037       fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">%s</TD></TR>\n", tempstr);
02038       
02039       fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">\n");
02040       while ((tempstr = strsep(&stringp, "\n")) != NULL)
02041          fprintf(htmlfile, "%s<BR>\n",tempstr);
02042       fprintf(htmlfile, "</TD></TR>\n");
02043       fprintf(htmlfile, "</TABLE></TD></TR>\n\n");
02044 
02045    }
02046 
02047    fprintf(htmlfile, "</TABLE>\n</BODY>\n</HTML>\n");
02048    fclose(htmlfile);
02049    ast_cli(fd, "AGI HTML Commands Dumped to: %s\n", argv[2]);
02050    return RESULT_SUCCESS;
02051 }

static int handle_answer ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 426 of file res_agi.c.

References ast_channel::_state, ast_answer(), AST_STATE_UP, agi_state::fd, fdprintf, RESULT_FAILURE, and RESULT_SUCCESS.

00427 {
00428    int res;
00429    res = 0;
00430    if (chan->_state != AST_STATE_UP) {
00431       /* Answer the chan */
00432       res = ast_answer(chan);
00433    }
00434    fdprintf(agi->fd, "200 result=%d\n", res);
00435    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00436 }

static int handle_autohangup ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 1075 of file res_agi.c.

References agi_state::fd, fdprintf, RESULT_SHOWUSAGE, RESULT_SUCCESS, timeout, and ast_channel::whentohangup.

01076 {
01077    int timeout;
01078 
01079    if (argc != 3)
01080       return RESULT_SHOWUSAGE;
01081    if (sscanf(argv[2], "%d", &timeout) != 1)
01082       return RESULT_SHOWUSAGE;
01083    if (timeout < 0)
01084       timeout = 0;
01085    if (timeout)
01086       chan->whentohangup = time(NULL) + timeout;
01087    else
01088       chan->whentohangup = 0;
01089    fdprintf(agi->fd, "200 result=0\n");
01090    return RESULT_SUCCESS;
01091 }

static int handle_channelstatus ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1168 of file res_agi.c.

References ast_channel::_state, ast_channel_unlock, ast_get_channel_by_name_locked(), agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01169 {
01170    struct ast_channel *c;
01171    if (argc == 2) {
01172       /* no argument: supply info on the current channel */
01173       fdprintf(agi->fd, "200 result=%d\n", chan->_state);
01174       return RESULT_SUCCESS;
01175    } else if (argc == 3) {
01176       /* one argument: look for info on the specified channel */
01177       c = ast_get_channel_by_name_locked(argv[2]);
01178       if (c) {
01179          fdprintf(agi->fd, "200 result=%d\n", c->_state);
01180          ast_channel_unlock(c);
01181          return RESULT_SUCCESS;
01182       }
01183       /* if we get this far no channel name matched the argument given */
01184       fdprintf(agi->fd, "200 result=-1\n");
01185       return RESULT_SUCCESS;
01186    } else {
01187       return RESULT_SHOWUSAGE;
01188    }
01189 }

static int handle_controlstreamfile ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 537 of file res_agi.c.

References ast_control_streamfile(), ast_strlen_zero(), agi_state::fd, fdprintf, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, skipms, and stop.

00538 {
00539    int res = 0;
00540    int skipms = 3000;
00541    char *fwd = NULL;
00542    char *rev = NULL;
00543    char *pause = NULL;
00544    char *stop = NULL;
00545 
00546    if (argc < 5 || argc > 9)
00547       return RESULT_SHOWUSAGE;
00548 
00549    if (!ast_strlen_zero(argv[4]))
00550       stop = argv[4];
00551    else
00552       stop = NULL;
00553    
00554    if ((argc > 5) && (sscanf(argv[5], "%d", &skipms) != 1))
00555       return RESULT_SHOWUSAGE;
00556 
00557    if (argc > 6 && !ast_strlen_zero(argv[6]))
00558       fwd = argv[6];
00559    else
00560       fwd = "#";
00561 
00562    if (argc > 7 && !ast_strlen_zero(argv[7]))
00563       rev = argv[7];
00564    else
00565       rev = "*";
00566    
00567    if (argc > 8 && !ast_strlen_zero(argv[8]))
00568       pause = argv[8];
00569    else
00570       pause = NULL;
00571    
00572    res = ast_control_streamfile(chan, argv[3], fwd, rev, stop, pause, NULL, skipms);
00573    
00574    fdprintf(agi->fd, "200 result=%d\n", res);
00575 
00576    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00577 }

static int handle_dbdel ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1308 of file res_agi.c.

References ast_db_del(), agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01309 {
01310    int res;
01311 
01312    if (argc != 4)
01313       return RESULT_SHOWUSAGE;
01314    res = ast_db_del(argv[2], argv[3]);
01315    fdprintf(agi->fd, "200 result=%c\n", res ? '0' : '1');
01316    return RESULT_SUCCESS;
01317 }

static int handle_dbdeltree ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1319 of file res_agi.c.

References ast_db_deltree(), agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01320 {
01321    int res;
01322    if ((argc < 3) || (argc > 4))
01323       return RESULT_SHOWUSAGE;
01324    if (argc == 4)
01325       res = ast_db_deltree(argv[2], argv[3]);
01326    else
01327       res = ast_db_deltree(argv[2], NULL);
01328 
01329    fdprintf(agi->fd, "200 result=%c\n", res ? '0' : '1');
01330    return RESULT_SUCCESS;
01331 }

static int handle_dbget ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1281 of file res_agi.c.

References ast_db_get(), agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01282 {
01283    int res;
01284    char tmp[256];
01285 
01286    if (argc != 4)
01287       return RESULT_SHOWUSAGE;
01288    res = ast_db_get(argv[2], argv[3], tmp, sizeof(tmp));
01289    if (res) 
01290       fdprintf(agi->fd, "200 result=0\n");
01291    else
01292       fdprintf(agi->fd, "200 result=1 (%s)\n", tmp);
01293 
01294    return RESULT_SUCCESS;
01295 }

static int handle_dbput ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1297 of file res_agi.c.

References ast_db_put(), agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01298 {
01299    int res;
01300 
01301    if (argc != 5)
01302       return RESULT_SHOWUSAGE;
01303    res = ast_db_put(argv[2], argv[3], argv[4]);
01304    fdprintf(agi->fd, "200 result=%c\n", res ? '0' : '1');
01305    return RESULT_SUCCESS;
01306 }

static int handle_exec ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1119 of file res_agi.c.

References ast_log(), ast_masq_park_call(), ast_verbose(), agi_state::fd, fdprintf, LOG_WARNING, option_verbose, PARK_APP_NAME, pbx_exec(), pbx_findapp(), RESULT_SHOWUSAGE, and VERBOSE_PREFIX_3.

01120 {
01121    int res;
01122    struct ast_app *app;
01123 
01124    if (argc < 2)
01125       return RESULT_SHOWUSAGE;
01126 
01127    if (option_verbose > 2)
01128       ast_verbose(VERBOSE_PREFIX_3 "AGI Script Executing Application: (%s) Options: (%s)\n", argv[1], argv[2]);
01129 
01130    app = pbx_findapp(argv[1]);
01131 
01132    if (app) {
01133       if(!strcasecmp(argv[1], PARK_APP_NAME)) {
01134          ast_masq_park_call(chan, NULL, 0, NULL);
01135       }
01136       res = pbx_exec(chan, app, argv[2]);
01137    } else {
01138       ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
01139       res = -2;
01140    }
01141    fdprintf(agi->fd, "200 result=%d\n", res);
01142 
01143    /* Even though this is wrong, users are depending upon this result. */
01144    return res;
01145 }

static int handle_getdata ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 834 of file res_agi.c.

References ast_app_getdata_full(), agi_state::audio, agi_state::ctrl, agi_state::fd, fdprintf, RESULT_SHOWUSAGE, RESULT_SUCCESS, and timeout.

00835 {
00836    int res;
00837    char data[1024];
00838    int max;
00839    int timeout;
00840 
00841    if (argc < 3)
00842       return RESULT_SHOWUSAGE;
00843    if (argc >= 4)
00844       timeout = atoi(argv[3]); 
00845    else
00846       timeout = 0;
00847    if (argc >= 5) 
00848       max = atoi(argv[4]); 
00849    else
00850       max = 1024;
00851    res = ast_app_getdata_full(chan, argv[2], data, max, timeout, agi->audio, agi->ctrl);
00852    if (res == 2)        /* New command */
00853       return RESULT_SUCCESS;
00854    else if (res == 1)
00855       fdprintf(agi->fd, "200 result=%s (timeout)\n", data);
00856    else if (res < 0 )
00857       fdprintf(agi->fd, "200 result=-1\n");
00858    else
00859       fdprintf(agi->fd, "200 result=%s\n", data);
00860    return RESULT_SUCCESS;
00861 }

static int handle_getoption ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 635 of file res_agi.c.

References ast_applystream(), ast_log(), ast_openstream(), ast_openvstream(), ast_playstream(), ast_seekstream(), ast_stopstream(), ast_tellstream(), ast_verbose(), ast_waitfordigit_full(), ast_waitstream_full(), agi_state::audio, agi_state::ctrl, ast_pbx::dtimeout, agi_state::fd, fdprintf, ast_channel::language, LOG_DEBUG, LOG_WARNING, option_verbose, ast_channel::pbx, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, ast_channel::stream, timeout, VERBOSE_PREFIX_3, and ast_filestream::vfs.

00636 {
00637    int res;
00638    int vres;   
00639    struct ast_filestream *fs;
00640    struct ast_filestream *vfs;
00641    long sample_offset = 0;
00642    long max_length;
00643    int timeout = 0;
00644    char *edigits = "";
00645 
00646    if ( argc < 4 || argc > 5 )
00647       return RESULT_SHOWUSAGE;
00648 
00649    if ( argv[3] ) 
00650       edigits = argv[3];
00651 
00652    if ( argc == 5 )
00653       timeout = atoi(argv[4]);
00654    else if (chan->pbx->dtimeout) {
00655       /* by default dtimeout is set to 5sec */
00656       timeout = chan->pbx->dtimeout * 1000; /* in msec */
00657    }
00658 
00659    fs = ast_openstream(chan, argv[2], chan->language);
00660    if (!fs) {
00661       fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
00662       ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]);
00663       return RESULT_SUCCESS;
00664    }
00665    vfs = ast_openvstream(chan, argv[2], chan->language);
00666    if (vfs)
00667       ast_log(LOG_DEBUG, "Ooh, found a video stream, too\n");
00668    
00669    if (option_verbose > 2)
00670       ast_verbose(VERBOSE_PREFIX_3 "Playing '%s' (escape_digits=%s) (timeout %d)\n", argv[2], edigits, timeout);
00671 
00672    ast_seekstream(fs, 0, SEEK_END);
00673    max_length = ast_tellstream(fs);
00674    ast_seekstream(fs, sample_offset, SEEK_SET);
00675    res = ast_applystream(chan, fs);
00676    if (vfs)
00677       vres = ast_applystream(chan, vfs);
00678    ast_playstream(fs);
00679    if (vfs)
00680       ast_playstream(vfs);
00681 
00682    res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl);
00683    /* this is to check for if ast_waitstream closed the stream, we probably are at
00684     * the end of the stream, return that amount, else check for the amount */
00685    sample_offset = (chan->stream)?ast_tellstream(fs):max_length;
00686    ast_stopstream(chan);
00687    if (res == 1) {
00688       /* Stop this command, don't print a result line, as there is a new command */
00689       return RESULT_SUCCESS;
00690    }
00691 
00692    /* If the user didnt press a key, wait for digitTimeout*/
00693    if (res == 0 ) {
00694       res = ast_waitfordigit_full(chan, timeout, agi->audio, agi->ctrl);
00695       /* Make sure the new result is in the escape digits of the GET OPTION */
00696       if ( !strchr(edigits,res) )
00697          res=0;
00698    }
00699 
00700         fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
00701    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00702 }

static int handle_getvariable ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1200 of file res_agi.c.

References ast_func_read(), ast_strlen_zero(), agi_state::fd, fdprintf, pbx_retrieve_variable(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01201 {
01202    char *ret;
01203    char tempstr[1024];
01204 
01205    if (argc != 3)
01206       return RESULT_SHOWUSAGE;
01207 
01208    /* check if we want to execute an ast_custom_function */
01209    if (!ast_strlen_zero(argv[2]) && (argv[2][strlen(argv[2]) - 1] == ')')) {
01210       ret = ast_func_read(chan, argv[2], tempstr, sizeof(tempstr)) ? NULL : tempstr;
01211    } else {
01212       pbx_retrieve_variable(chan, argv[2], &ret, tempstr, sizeof(tempstr), NULL);
01213    }
01214 
01215    if (ret)
01216       fdprintf(agi->fd, "200 result=1 (%s)\n", ret);
01217    else
01218       fdprintf(agi->fd, "200 result=0\n");
01219 
01220    return RESULT_SUCCESS;
01221 }

static int handle_getvariablefull ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1223 of file res_agi.c.

References ast_channel_unlock, ast_get_channel_by_name_locked(), agi_state::fd, fdprintf, pbx_substitute_variables_helper(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01224 {
01225    char tmp[4096] = "";
01226    struct ast_channel *chan2=NULL;
01227 
01228    if ((argc != 4) && (argc != 5))
01229       return RESULT_SHOWUSAGE;
01230    if (argc == 5) {
01231       chan2 = ast_get_channel_by_name_locked(argv[4]);
01232    } else {
01233       chan2 = chan;
01234    }
01235    if (chan2) {
01236       pbx_substitute_variables_helper(chan2, argv[3], tmp, sizeof(tmp) - 1);
01237       fdprintf(agi->fd, "200 result=1 (%s)\n", tmp);
01238    } else {
01239       fdprintf(agi->fd, "200 result=0\n");
01240    }
01241    if (chan2 && (chan2 != chan))
01242       ast_channel_unlock(chan2);
01243    return RESULT_SUCCESS;
01244 }

static int handle_hangup ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1093 of file res_agi.c.

References ast_channel_unlock, ast_get_channel_by_name_locked(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01094 {
01095    struct ast_channel *c;
01096    if (argc == 1) {
01097       /* no argument: hangup the current channel */
01098       ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT);
01099       fdprintf(agi->fd, "200 result=1\n");
01100       return RESULT_SUCCESS;
01101    } else if (argc == 2) {
01102       /* one argument: look for info on the specified channel */
01103       c = ast_get_channel_by_name_locked(argv[1]);
01104       if (c) {
01105          /* we have a matching channel */
01106          ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT);
01107          fdprintf(agi->fd, "200 result=1\n");
01108          ast_channel_unlock(c);
01109          return RESULT_SUCCESS;
01110       }
01111       /* if we get this far no channel name matched the argument given */
01112       fdprintf(agi->fd, "200 result=-1\n");
01113       return RESULT_SUCCESS;
01114    } else {
01115       return RESULT_SHOWUSAGE;
01116    }
01117 }

static int handle_noop ( struct ast_channel *  chan,
AGI *  agi,
int  arg,
char *  argv[] 
) [static]

Definition at line 1368 of file res_agi.c.

References agi_state::fd, fdprintf, and RESULT_SUCCESS.

01369 {
01370    fdprintf(agi->fd, "200 result=0\n");
01371    return RESULT_SUCCESS;
01372 }

static int handle_recordfile ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 898 of file res_agi.c.

References ast_applystream(), ast_closestream(), AST_CONTROL_VIDUPDATE, ast_dsp_free(), ast_dsp_new(), ast_dsp_set_threshold(), ast_dsp_silence(), AST_FORMAT_SLINEAR, AST_FRAME_DTMF, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_indicate(), ast_log(), ast_read(), ast_seekstream(), ast_set_read_format(), ast_stream_rewind(), ast_streamfile(), ast_tellstream(), ast_truncstream(), ast_tvdiff_ms(), ast_tvnow(), ast_waitfor(), ast_waitstream(), ast_writefile(), ast_writestream(), f, agi_state::fd, fdprintf, ast_frame::frametype, ast_channel::language, LOG_WARNING, ast_channel::name, ast_channel::readformat, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, silence, ast_channel::stream, ast_frame::subclass, and ast_dsp::totalsilence.

00899 {
00900    struct ast_filestream *fs;
00901    struct ast_frame *f;
00902    struct timeval start;
00903    long sample_offset = 0;
00904    int res = 0;
00905    int ms;
00906 
00907         struct ast_dsp *sildet=NULL;         /* silence detector dsp */
00908         int totalsilence = 0;
00909         int dspsilence = 0;
00910         int silence = 0;                /* amount of silence to allow */
00911         int gotsilence = 0;             /* did we timeout for silence? */
00912         char *silencestr=NULL;
00913         int rfmt=0;
00914 
00915 
00916    /* XXX EAGI FIXME XXX */
00917 
00918    if (argc < 6)
00919       return RESULT_SHOWUSAGE;
00920    if (sscanf(argv[5], "%d", &ms) != 1)
00921       return RESULT_SHOWUSAGE;
00922 
00923    if (argc > 6)
00924       silencestr = strchr(argv[6],'s');
00925    if ((argc > 7) && (!silencestr))
00926       silencestr = strchr(argv[7],'s');
00927    if ((argc > 8) && (!silencestr))
00928       silencestr = strchr(argv[8],'s');
00929 
00930    if (silencestr) {
00931       if (strlen(silencestr) > 2) {
00932          if ((silencestr[0] == 's') && (silencestr[1] == '=')) {
00933             silencestr++;
00934             silencestr++;
00935             if (silencestr)
00936                         silence = atoi(silencestr);
00937                if (silence > 0)
00938                         silence *= 1000;
00939             }
00940       }
00941    }
00942 
00943         if (silence > 0) {
00944          rfmt = chan->readformat;
00945                 res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
00946                 if (res < 0) {
00947                   ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
00948                         return -1;
00949                 }
00950                   sildet = ast_dsp_new();
00951                 if (!sildet) {
00952                   ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
00953                         return -1;
00954                 }
00955                   ast_dsp_set_threshold(sildet, 256);
00956          }
00957 
00958    /* backward compatibility, if no offset given, arg[6] would have been
00959     * caught below and taken to be a beep, else if it is a digit then it is a
00960     * offset */
00961    if ((argc >6) && (sscanf(argv[6], "%ld", &sample_offset) != 1) && (!strchr(argv[6], '=')))
00962       res = ast_streamfile(chan, "beep", chan->language);
00963 
00964    if ((argc > 7) && (!strchr(argv[7], '=')))
00965       res = ast_streamfile(chan, "beep", chan->language);
00966 
00967    if (!res)
00968       res = ast_waitstream(chan, argv[4]);
00969    if (res) {
00970       fdprintf(agi->fd, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
00971    } else {
00972       fs = ast_writefile(argv[2], argv[3], NULL, O_CREAT | O_WRONLY | (sample_offset ? O_APPEND : 0), 0, 0644);
00973       if (!fs) {
00974          res = -1;
00975          fdprintf(agi->fd, "200 result=%d (writefile)\n", res);
00976          if (sildet)
00977             ast_dsp_free(sildet);
00978          return RESULT_FAILURE;
00979       }
00980       
00981       /* Request a video update */
00982       ast_indicate(chan, AST_CONTROL_VIDUPDATE);
00983    
00984       chan->stream = fs;
00985       ast_applystream(chan,fs);
00986       /* really should have checks */
00987       ast_seekstream(fs, sample_offset, SEEK_SET);
00988       ast_truncstream(fs);
00989       
00990       start = ast_tvnow();
00991       while ((ms < 0) || ast_tvdiff_ms(ast_tvnow(), start) < ms) {
00992          res = ast_waitfor(chan, ms - ast_tvdiff_ms(ast_tvnow(), start));
00993          if (res < 0) {
00994             ast_closestream(fs);
00995             fdprintf(agi->fd, "200 result=%d (waitfor) endpos=%ld\n", res,sample_offset);
00996             if (sildet)
00997                ast_dsp_free(sildet);
00998             return RESULT_FAILURE;
00999          }
01000          f = ast_read(chan);
01001          if (!f) {
01002             fdprintf(agi->fd, "200 result=%d (hangup) endpos=%ld\n", -1, sample_offset);
01003             ast_closestream(fs);
01004             if (sildet)
01005                ast_dsp_free(sildet);
01006             return RESULT_FAILURE;
01007          }
01008          switch(f->frametype) {
01009          case AST_FRAME_DTMF:
01010             if (strchr(argv[4], f->subclass)) {
01011                /* This is an interrupting chracter, so rewind to chop off any small
01012                   amount of DTMF that may have been recorded
01013                */
01014                ast_stream_rewind(fs, 200);
01015                ast_truncstream(fs);
01016                sample_offset = ast_tellstream(fs);
01017                fdprintf(agi->fd, "200 result=%d (dtmf) endpos=%ld\n", f->subclass, sample_offset);
01018                ast_closestream(fs);
01019                ast_frfree(f);
01020                if (sildet)
01021                   ast_dsp_free(sildet);
01022                return RESULT_SUCCESS;
01023             }
01024             break;
01025          case AST_FRAME_VOICE:
01026             ast_writestream(fs, f);
01027             /* this is a safe place to check progress since we know that fs
01028              * is valid after a write, and it will then have our current
01029              * location */
01030             sample_offset = ast_tellstream(fs);
01031                                 if (silence > 0) {
01032                                  dspsilence = 0;
01033                                         ast_dsp_silence(sildet, f, &dspsilence);
01034                                         if (dspsilence) {
01035                                              totalsilence = dspsilence;
01036                                         } else {
01037                                                 totalsilence = 0;
01038                                         }
01039                                         if (totalsilence > silence) {
01040                                              /* Ended happily with silence */
01041                                                 gotsilence = 1;
01042                                                 break;
01043                                         }
01044                               }
01045             break;
01046          case AST_FRAME_VIDEO:
01047             ast_writestream(fs, f);
01048          default:
01049             /* Ignore all other frames */
01050             break;
01051          }
01052          ast_frfree(f);
01053          if (gotsilence)
01054             break;
01055          }
01056 
01057                if (gotsilence) {
01058                         ast_stream_rewind(fs, silence-1000);
01059                   ast_truncstream(fs);
01060          sample_offset = ast_tellstream(fs);
01061       }     
01062       fdprintf(agi->fd, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset);
01063       ast_closestream(fs);
01064    }
01065 
01066         if (silence > 0) {
01067                 res = ast_set_read_format(chan, rfmt);
01068                 if (res)
01069                         ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
01070                 ast_dsp_free(sildet);
01071         }
01072    return RESULT_SUCCESS;
01073 }

static int handle_recvchar ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 468 of file res_agi.c.

References ast_recvchar(), agi_state::fd, fdprintf, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00469 {
00470    int res;
00471    if (argc != 3)
00472       return RESULT_SHOWUSAGE;
00473    res = ast_recvchar(chan,atoi(argv[2]));
00474    if (res == 0) {
00475       fdprintf(agi->fd, "200 result=%d (timeout)\n", res);
00476       return RESULT_SUCCESS;
00477    }
00478    if (res > 0) {
00479       fdprintf(agi->fd, "200 result=%d\n", res);
00480       return RESULT_SUCCESS;
00481    }
00482    else {
00483       fdprintf(agi->fd, "200 result=%d (hangup)\n", res);
00484       return RESULT_FAILURE;
00485    }
00486 }

static int handle_recvtext ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 488 of file res_agi.c.

References ast_recvtext(), agi_state::fd, fdprintf, free, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00489 {
00490    char *buf;
00491    
00492    if (argc != 3)
00493       return RESULT_SHOWUSAGE;
00494    buf = ast_recvtext(chan,atoi(argv[2]));
00495    if (buf) {
00496       fdprintf(agi->fd, "200 result=1 (%s)\n", buf);
00497       free(buf);
00498    } else { 
00499       fdprintf(agi->fd, "200 result=-1\n");
00500    }
00501    return RESULT_SUCCESS;
00502 }

static int handle_sayalpha ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 742 of file res_agi.c.

References ast_say_character_str_full, agi_state::audio, agi_state::ctrl, agi_state::fd, fdprintf, ast_channel::language, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00743 {
00744    int res;
00745 
00746    if (argc != 4)
00747       return RESULT_SHOWUSAGE;
00748 
00749    res = ast_say_character_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
00750    if (res == 1) /* New command */
00751       return RESULT_SUCCESS;
00752    fdprintf(agi->fd, "200 result=%d\n", res);
00753    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00754 }

static int handle_saydate ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 756 of file res_agi.c.

References ast_say_date, agi_state::fd, fdprintf, ast_channel::language, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00757 {
00758    int res;
00759    int num;
00760    if (argc != 4)
00761       return RESULT_SHOWUSAGE;
00762    if (sscanf(argv[2], "%d", &num) != 1)
00763       return RESULT_SHOWUSAGE;
00764    res = ast_say_date(chan, num, argv[3], chan->language);
00765    if (res == 1)
00766       return RESULT_SUCCESS;
00767    fdprintf(agi->fd, "200 result=%d\n", res);
00768    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00769 }

static int handle_saydatetime ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 786 of file res_agi.c.

References ast_get_time_t(), ast_say_date_with_format, ast_strlen_zero(), agi_state::fd, fdprintf, format, ast_channel::language, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00787 {
00788    int res=0;
00789    time_t unixtime;
00790    char *format, *zone=NULL;
00791    
00792    if (argc < 4)
00793       return RESULT_SHOWUSAGE;
00794 
00795    if (argc > 4) {
00796       format = argv[4];
00797    } else {
00798       /* XXX this doesn't belong here, but in the 'say' module */
00799       if (!strcasecmp(chan->language, "de")) {
00800          format = "A dBY HMS";
00801       } else {
00802          format = "ABdY 'digits/at' IMp"; 
00803       }
00804    }
00805 
00806    if (argc > 5 && !ast_strlen_zero(argv[5]))
00807       zone = argv[5];
00808 
00809    if (ast_get_time_t(argv[2], &unixtime, 0, NULL))
00810       return RESULT_SHOWUSAGE;
00811 
00812    res = ast_say_date_with_format(chan, unixtime, argv[3], chan->language, format, zone);
00813    if (res == 1)
00814       return RESULT_SUCCESS;
00815 
00816    fdprintf(agi->fd, "200 result=%d\n", res);
00817    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00818 }

static int handle_saydigits ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 725 of file res_agi.c.

References ast_say_digit_str_full, agi_state::audio, agi_state::ctrl, agi_state::fd, fdprintf, ast_channel::language, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00726 {
00727    int res;
00728    int num;
00729 
00730    if (argc != 4)
00731       return RESULT_SHOWUSAGE;
00732    if (sscanf(argv[2], "%d", &num) != 1)
00733       return RESULT_SHOWUSAGE;
00734 
00735    res = ast_say_digit_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
00736    if (res == 1) /* New command */
00737       return RESULT_SUCCESS;
00738    fdprintf(agi->fd, "200 result=%d\n", res);
00739    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00740 }

static int handle_saynumber ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 710 of file res_agi.c.

References ast_say_number_full, agi_state::audio, agi_state::ctrl, agi_state::fd, fdprintf, ast_channel::language, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00711 {
00712    int res;
00713    int num;
00714    if (argc != 4)
00715       return RESULT_SHOWUSAGE;
00716    if (sscanf(argv[2], "%d", &num) != 1)
00717       return RESULT_SHOWUSAGE;
00718    res = ast_say_number_full(chan, num, argv[3], chan->language, (char *) NULL, agi->audio, agi->ctrl);
00719    if (res == 1)
00720       return RESULT_SUCCESS;
00721    fdprintf(agi->fd, "200 result=%d\n", res);
00722    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00723 }

static int handle_sayphonetic ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 820 of file res_agi.c.

References ast_say_phonetic_str_full, agi_state::audio, agi_state::ctrl, agi_state::fd, fdprintf, ast_channel::language, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00821 {
00822    int res;
00823 
00824    if (argc != 4)
00825       return RESULT_SHOWUSAGE;
00826 
00827    res = ast_say_phonetic_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
00828    if (res == 1) /* New command */
00829       return RESULT_SUCCESS;
00830    fdprintf(agi->fd, "200 result=%d\n", res);
00831    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00832 }

static int handle_saytime ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 771 of file res_agi.c.

References ast_say_time, agi_state::fd, fdprintf, ast_channel::language, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00772 {
00773    int res;
00774    int num;
00775    if (argc != 4)
00776       return RESULT_SHOWUSAGE;
00777    if (sscanf(argv[2], "%d", &num) != 1)
00778       return RESULT_SHOWUSAGE;
00779    res = ast_say_time(chan, num, argv[3], chan->language);
00780    if (res == 1)
00781       return RESULT_SUCCESS;
00782    fdprintf(agi->fd, "200 result=%d\n", res);
00783    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00784 }

static int handle_sendimage ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 525 of file res_agi.c.

References ast_check_hangup(), ast_send_image(), agi_state::fd, fdprintf, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00526 {
00527    int res;
00528    if (argc != 3)
00529       return RESULT_SHOWUSAGE;
00530    res = ast_send_image(chan, argv[2]);
00531    if (!ast_check_hangup(chan))
00532       res = 0;
00533    fdprintf(agi->fd, "200 result=%d\n", res);
00534    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00535 }

static int handle_sendtext ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 451 of file res_agi.c.

References ast_sendtext(), agi_state::fd, fdprintf, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00452 {
00453    int res;
00454    if (argc != 3)
00455       return RESULT_SHOWUSAGE;
00456    /* At the moment, the parser (perhaps broken) returns with
00457       the last argument PLUS the newline at the end of the input
00458       buffer. This probably needs to be fixed, but I wont do that
00459       because other stuff may break as a result. The right way
00460       would probably be to strip off the trailing newline before
00461       parsing, then here, add a newline at the end of the string
00462       before sending it to ast_sendtext --DUDE */
00463    res = ast_sendtext(chan, argv[2]);
00464    fdprintf(agi->fd, "200 result=%d\n", res);
00465    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00466 }

static int handle_setcallerid ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1147 of file res_agi.c.

References ast_callerid_parse(), ast_copy_string(), ast_set_callerid(), ast_shrink_phone_number(), agi_state::fd, fdprintf, and RESULT_SUCCESS.

01148 {
01149    char tmp[256]="";
01150    char *l = NULL, *n = NULL;
01151 
01152    if (argv[2]) {
01153       ast_copy_string(tmp, argv[2], sizeof(tmp));
01154       ast_callerid_parse(tmp, &n, &l);
01155       if (l)
01156          ast_shrink_phone_number(l);
01157       else
01158          l = "";
01159       if (!n)
01160          n = "";
01161       ast_set_callerid(chan, l, n, NULL);
01162    }
01163 
01164    fdprintf(agi->fd, "200 result=1\n");
01165    return RESULT_SUCCESS;
01166 }

static int handle_setcontext ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 863 of file res_agi.c.

References ast_copy_string(), ast_channel::context, agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00864 {
00865 
00866    if (argc != 3)
00867       return RESULT_SHOWUSAGE;
00868    ast_copy_string(chan->context, argv[2], sizeof(chan->context));
00869    fdprintf(agi->fd, "200 result=0\n");
00870    return RESULT_SUCCESS;
00871 }

static int handle_setextension ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 873 of file res_agi.c.

References ast_copy_string(), ast_channel::exten, agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00874 {
00875    if (argc != 3)
00876       return RESULT_SHOWUSAGE;
00877    ast_copy_string(chan->exten, argv[2], sizeof(chan->exten));
00878    fdprintf(agi->fd, "200 result=0\n");
00879    return RESULT_SUCCESS;
00880 }

static int handle_setmusic ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 1374 of file res_agi.c.

References ast_moh_start(), ast_moh_stop(), agi_state::fd, fdprintf, and RESULT_SUCCESS.

01375 {
01376    if (!strncasecmp(argv[2], "on", 2))
01377       ast_moh_start(chan, argc > 3 ? argv[3] : NULL, NULL);
01378    else if (!strncasecmp(argv[2], "off", 3))
01379       ast_moh_stop(chan);
01380    fdprintf(agi->fd, "200 result=0\n");
01381    return RESULT_SUCCESS;
01382 }

static int handle_setpriority ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 882 of file res_agi.c.

References ast_explicit_goto(), ast_findlabel_extension(), ast_channel::cid, ast_callerid::cid_num, ast_channel::context, ast_channel::exten, agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00883 {
00884    int pri;
00885    if (argc != 3)
00886       return RESULT_SHOWUSAGE;   
00887 
00888    if (sscanf(argv[2], "%d", &pri) != 1) {
00889       if ((pri = ast_findlabel_extension(chan, chan->context, chan->exten, argv[2], chan->cid.cid_num)) < 1)
00890          return RESULT_SHOWUSAGE;
00891    }
00892 
00893    ast_explicit_goto(chan, NULL, NULL, pri);
00894    fdprintf(agi->fd, "200 result=0\n");
00895    return RESULT_SUCCESS;
00896 }

static int handle_setvariable ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1191 of file res_agi.c.

References agi_state::fd, fdprintf, pbx_builtin_setvar_helper(), and RESULT_SUCCESS.

01192 {
01193    if (argv[3])
01194       pbx_builtin_setvar_helper(chan, argv[2], argv[3]);
01195 
01196    fdprintf(agi->fd, "200 result=1\n");
01197    return RESULT_SUCCESS;
01198 }

static int handle_showagi ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1975 of file res_agi.c.

References ast_cli(), ast_join(), find_command(), help_workhorse(), RESULT_SHOWUSAGE, RESULT_SUCCESS, and agi_command::usage.

01976 {
01977    struct agi_command *e;
01978    char fullcmd[80];
01979    if ((argc < 2))
01980       return RESULT_SHOWUSAGE;
01981    if (argc > 2) {
01982       e = find_command(argv + 2, 1);
01983       if (e) 
01984          ast_cli(fd, "%s", e->usage);
01985       else {
01986          if (find_command(argv + 2, -1)) {
01987             return help_workhorse(fd, argv + 1);
01988          } else {
01989             ast_join(fullcmd, sizeof(fullcmd), argv+1);
01990             ast_cli(fd, "No such command '%s'.\n", fullcmd);
01991          }
01992       }
01993    } else {
01994       return help_workhorse(fd, NULL);
01995    }
01996    return RESULT_SUCCESS;
01997 }

static int handle_streamfile ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 579 of file res_agi.c.

References ast_applystream(), ast_log(), ast_openstream(), ast_openvstream(), ast_playstream(), ast_seekstream(), ast_stopstream(), ast_tellstream(), ast_verbose(), ast_waitstream_full(), agi_state::audio, agi_state::ctrl, agi_state::fd, fdprintf, ast_channel::language, LOG_DEBUG, option_verbose, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, ast_channel::stream, VERBOSE_PREFIX_3, and ast_filestream::vfs.

00580 {
00581    int res;
00582    int vres;   
00583    struct ast_filestream *fs;
00584    struct ast_filestream *vfs;
00585    long sample_offset = 0;
00586    long max_length;
00587    char *edigits = "";
00588 
00589    if (argc < 4 || argc > 5)
00590       return RESULT_SHOWUSAGE;
00591 
00592    if (argv[3]) 
00593       edigits = argv[3];
00594 
00595    if ((argc > 4) && (sscanf(argv[4], "%ld", &sample_offset) != 1))
00596       return RESULT_SHOWUSAGE;
00597    
00598    fs = ast_openstream(chan, argv[2], chan->language);   
00599    
00600    if (!fs) {
00601       fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
00602       return RESULT_SUCCESS;
00603    }  
00604    vfs = ast_openvstream(chan, argv[2], chan->language);
00605    if (vfs)
00606       ast_log(LOG_DEBUG, "Ooh, found a video stream, too\n");
00607       
00608    if (option_verbose > 2)
00609       ast_verbose(VERBOSE_PREFIX_3 "Playing '%s' (escape_digits=%s) (sample_offset %ld)\n", argv[2], edigits, sample_offset);
00610 
00611    ast_seekstream(fs, 0, SEEK_END);
00612    max_length = ast_tellstream(fs);
00613    ast_seekstream(fs, sample_offset, SEEK_SET);
00614    res = ast_applystream(chan, fs);
00615    if (vfs)
00616       vres = ast_applystream(chan, vfs);
00617    ast_playstream(fs);
00618    if (vfs)
00619       ast_playstream(vfs);
00620    
00621    res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl);
00622    /* this is to check for if ast_waitstream closed the stream, we probably are at
00623     * the end of the stream, return that amount, else check for the amount */
00624    sample_offset = (chan->stream) ? ast_tellstream(fs) : max_length;
00625    ast_stopstream(chan);
00626    if (res == 1) {
00627       /* Stop this command, don't print a result line, as there is a new command */
00628       return RESULT_SUCCESS;
00629    }
00630    fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
00631    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00632 }

static int handle_tddmode ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 504 of file res_agi.c.

References ast_channel_setoption(), AST_OPTION_TDD, agi_state::fd, fdprintf, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00505 {
00506    int res,x;
00507    if (argc != 3)
00508       return RESULT_SHOWUSAGE;
00509    if (!strncasecmp(argv[2],"on",2)) 
00510       x = 1; 
00511    else 
00512       x = 0;
00513    if (!strncasecmp(argv[2],"mate",4)) 
00514       x = 2;
00515    if (!strncasecmp(argv[2],"tdd",3))
00516       x = 1;
00517    res = ast_channel_setoption(chan, AST_OPTION_TDD, &x, sizeof(char), 0);
00518    if (res != RESULT_SUCCESS)
00519       fdprintf(agi->fd, "200 result=0\n");
00520    else
00521       fdprintf(agi->fd, "200 result=1\n");
00522    return RESULT_SUCCESS;
00523 }

static int handle_verbose ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char **  argv 
) [static]

Definition at line 1246 of file res_agi.c.

References ast_verbose(), ast_channel::data, agi_state::fd, fdprintf, option_verbose, prefix, RESULT_SHOWUSAGE, RESULT_SUCCESS, VERBOSE_PREFIX_1, VERBOSE_PREFIX_2, VERBOSE_PREFIX_3, and VERBOSE_PREFIX_4.

01247 {
01248    int level = 0;
01249    char *prefix;
01250 
01251    if (argc < 2)
01252       return RESULT_SHOWUSAGE;
01253 
01254    if (argv[2])
01255       sscanf(argv[2], "%d", &level);
01256 
01257    switch (level) {
01258       case 4:
01259          prefix = VERBOSE_PREFIX_4;
01260          break;
01261       case 3:
01262          prefix = VERBOSE_PREFIX_3;
01263          break;
01264       case 2:
01265          prefix = VERBOSE_PREFIX_2;
01266          break;
01267       case 1:
01268       default:
01269          prefix = VERBOSE_PREFIX_1;
01270          break;
01271    }
01272 
01273    if (level <= option_verbose)
01274       ast_verbose("%s %s: %s\n", prefix, chan->data, argv[1]);
01275    
01276    fdprintf(agi->fd, "200 result=1\n");
01277    
01278    return RESULT_SUCCESS;
01279 }

static int handle_waitfordigit ( struct ast_channel *  chan,
AGI *  agi,
int  argc,
char *  argv[] 
) [static]

Definition at line 438 of file res_agi.c.

References ast_waitfordigit_full(), agi_state::audio, agi_state::ctrl, agi_state::fd, fdprintf, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00439 {
00440    int res;
00441    int to;
00442    if (argc != 4)
00443       return RESULT_SHOWUSAGE;
00444    if (sscanf(argv[3], "%d", &to) != 1)
00445       return RESULT_SHOWUSAGE;
00446    res = ast_waitfordigit_full(chan, to, agi->audio, agi->ctrl);
00447    fdprintf(agi->fd, "200 result=%d\n", res);
00448    return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
00449 }

static int help_workhorse ( int  fd,
char *  match[] 
) [static]

Definition at line 1671 of file res_agi.c.

References ast_cli(), ast_join(), agi_command::cmda, and agi_command::summary.

Referenced by handle_showagi().

01672 {
01673    char fullcmd[80];
01674    char matchstr[80];
01675    int x;
01676    struct agi_command *e;
01677    if (match)
01678       ast_join(matchstr, sizeof(matchstr), match);
01679    for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) {
01680       e = &commands[x]; 
01681       if (!e->cmda[0])
01682          break;
01683       /* Hide commands that start with '_' */
01684       if ((e->cmda[0])[0] == '_')
01685          continue;
01686       ast_join(fullcmd, sizeof(fullcmd), e->cmda);
01687       if (match && strncasecmp(matchstr, fullcmd, strlen(matchstr)))
01688          continue;
01689       ast_cli(fd, "%20.20s   %s\n", fullcmd, e->summary);
01690    }
01691    return 0;
01692 }

static enum agi_result launch_netscript ( char *  agiurl,
char *  argv[],
int *  fds,
int *  efd,
int *  opid 
) [static]

Definition at line 146 of file res_agi.c.

References AGI_PORT, AGI_RESULT_FAILURE, AGI_RESULT_SUCCESS_FAST, ast_gethostbyname(), ast_log(), ast_strdupa, ast_strlen_zero(), errno, pollfd::events, pollfd::fd, fdprintf, hp, LOG_DEBUG, LOG_WARNING, MAX_AGI_CONNECT, option_debug, poll(), POLLOUT, and s.

Referenced by launch_script().

00147 {
00148    int s;
00149    int flags;
00150    struct pollfd pfds[1];
00151    char *host;
00152    char *c; int port = AGI_PORT;
00153    char *script="";
00154    struct sockaddr_in sin;
00155    struct hostent *hp;
00156    struct ast_hostent ahp;
00157    int res;
00158 
00159    /* agiusl is "agi://host.domain[:port][/script/name]" */
00160    host = ast_strdupa(agiurl + 6);  /* Remove agi:// */
00161    /* Strip off any script name */
00162    if ((c = strchr(host, '/'))) {
00163       *c = '\0';
00164       c++;
00165       script = c;
00166    }
00167    if ((c = strchr(host, ':'))) {
00168       *c = '\0';
00169       c++;
00170       port = atoi(c);
00171    }
00172    if (efd) {
00173       ast_log(LOG_WARNING, "AGI URI's don't support Enhanced AGI yet\n");
00174       return -1;
00175    }
00176    hp = ast_gethostbyname(host, &ahp);
00177    if (!hp) {
00178       ast_log(LOG_WARNING, "Unable to locate host '%s'\n", host);
00179       return -1;
00180    }
00181    s = socket(AF_INET, SOCK_STREAM, 0);
00182    if (s < 0) {
00183       ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
00184       return -1;
00185    }
00186    flags = fcntl(s, F_GETFL);
00187    if (flags < 0) {
00188       ast_log(LOG_WARNING, "Fcntl(F_GETFL) failed: %s\n", strerror(errno));
00189       close(s);
00190       return -1;
00191    }
00192    if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) {
00193       ast_log(LOG_WARNING, "Fnctl(F_SETFL) failed: %s\n", strerror(errno));
00194       close(s);
00195       return -1;
00196    }
00197    memset(&sin, 0, sizeof(sin));
00198    sin.sin_family = AF_INET;
00199    sin.sin_port = htons(port);
00200    memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
00201    if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) && (errno != EINPROGRESS)) {
00202       ast_log(LOG_WARNING, "Connect failed with unexpected error: %s\n", strerror(errno));
00203       close(s);
00204       return AGI_RESULT_FAILURE;
00205    }
00206 
00207    pfds[0].fd = s;
00208    pfds[0].events = POLLOUT;
00209    while ((res = poll(pfds, 1, MAX_AGI_CONNECT)) != 1) {
00210       if (errno != EINTR) {
00211          if (!res) {
00212             ast_log(LOG_WARNING, "FastAGI connection to '%s' timed out after MAX_AGI_CONNECT (%d) milliseconds.\n",
00213                agiurl, MAX_AGI_CONNECT);
00214          } else
00215             ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
00216          close(s);
00217          return AGI_RESULT_FAILURE;
00218       }
00219    }
00220 
00221    if (fdprintf(s, "agi_network: yes\n") < 0) {
00222       if (errno != EINTR) {
00223          ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
00224          close(s);
00225          return AGI_RESULT_FAILURE;
00226       }
00227    }
00228 
00229    /* If we have a script parameter, relay it to the fastagi server */
00230    /* Script parameters take the form of: AGI(agi://my.example.com/?extension=${EXTEN}) */
00231    if (!ast_strlen_zero(script))
00232       fdprintf(s, "agi_network_script: %s\n", script);
00233 
00234    if (option_debug > 3)
00235       ast_log(LOG_DEBUG, "Wow, connected!\n");
00236    fds[0] = s;
00237    fds[1] = s;
00238    *opid = -1;
00239    return AGI_RESULT_SUCCESS_FAST;
00240 }

static enum agi_result launch_script ( char *  script,
char *  argv[],
int *  fds,
int *  efd,
int *  opid 
) [static]

Definition at line 242 of file res_agi.c.

References AGI_RESULT_FAILURE, AGI_RESULT_SUCCESS, ast_config_AST_AGI_DIR, ast_config_AST_CONFIG_DIR, ast_config_AST_CONFIG_FILE, ast_config_AST_DATA_DIR, ast_config_AST_KEY_DIR, ast_config_AST_LOG_DIR, ast_config_AST_MODULE_DIR, ast_config_AST_MONITOR_DIR, ast_config_AST_RUN_DIR, ast_config_AST_SPOOL_DIR, ast_config_AST_VAR_DIR, ast_log(), ast_set_priority(), ast_verbose(), errno, launch_netscript(), LOG_WARNING, option_verbose, and VERBOSE_PREFIX_3.

Referenced by agi_exec_full().

00243 {
00244    char tmp[256];
00245    int pid;
00246    int toast[2];
00247    int fromast[2];
00248    int audio[2];
00249    int x;
00250    int res;
00251    sigset_t signal_set, old_set;
00252    struct stat statbuf;
00253 
00254    if (!strncasecmp(script, "agi://", 6))
00255       return launch_netscript(script, argv, fds, efd, opid);
00256    
00257    if (script[0] != '/') {
00258       snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_AGI_DIR, script);
00259       script = tmp;
00260    }
00261         if (stat(script, &statbuf) < 0) {
00262                 ast_log(LOG_WARNING, "Unable to execute %s: File does not exist\n", script);
00263                 return -1;
00264         }
00265         if (!(statbuf.st_mode & S_IXUSR)) {
00266                 ast_log(LOG_WARNING, "Unable to execute %s: File is not executable\n", script);
00267                 return -1;
00268         }
00269    if (pipe(toast)) {
00270       ast_log(LOG_WARNING, "Unable to create toast pipe: %s\n",strerror(errno));
00271       return AGI_RESULT_FAILURE;
00272    }
00273    if (pipe(fromast)) {
00274       ast_log(LOG_WARNING, "unable to create fromast pipe: %s\n", strerror(errno));
00275       close(toast[0]);
00276       close(toast[1]);
00277       return AGI_RESULT_FAILURE;
00278    }
00279    if (efd) {
00280       if (pipe(audio)) {
00281          ast_log(LOG_WARNING, "unable to create audio pipe: %s\n", strerror(errno));
00282          close(fromast[0]);
00283          close(fromast[1]);
00284          close(toast[0]);
00285          close(toast[1]);
00286          return AGI_RESULT_FAILURE;
00287       }
00288       res = fcntl(audio[1], F_GETFL);
00289       if (res > -1) 
00290          res = fcntl(audio[1], F_SETFL, res | O_NONBLOCK);
00291       if (res < 0) {
00292          ast_log(LOG_WARNING, "unable to set audio pipe parameters: %s\n", strerror(errno));
00293          close(fromast[0]);
00294          close(fromast[1]);
00295          close(toast[0]);
00296          close(toast[1]);
00297          close(audio[0]);
00298          close(audio[1]);
00299          return AGI_RESULT_FAILURE;
00300       }
00301    }
00302 
00303    /* Block SIGHUP during the fork - prevents a race */
00304    sigfillset(&signal_set);
00305    pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
00306    pid = fork();
00307    if (pid < 0) {
00308       ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
00309       pthread_sigmask(SIG_SETMASK, &old_set, NULL);
00310       return AGI_RESULT_FAILURE;
00311    }
00312    if (!pid) {
00313       /* Pass paths to AGI via environmental variables */
00314       setenv("AST_CONFIG_DIR", ast_config_AST_CONFIG_DIR, 1);
00315       setenv("AST_CONFIG_FILE", ast_config_AST_CONFIG_FILE, 1);
00316       setenv("AST_MODULE_DIR", ast_config_AST_MODULE_DIR, 1);
00317       setenv("AST_SPOOL_DIR", ast_config_AST_SPOOL_DIR, 1);
00318       setenv("AST_MONITOR_DIR", ast_config_AST_MONITOR_DIR, 1);
00319       setenv("AST_VAR_DIR", ast_config_AST_VAR_DIR, 1);
00320       setenv("AST_DATA_DIR", ast_config_AST_DATA_DIR, 1);
00321       setenv("AST_LOG_DIR", ast_config_AST_LOG_DIR, 1);
00322       setenv("AST_AGI_DIR", ast_config_AST_AGI_DIR, 1);
00323       setenv("AST_KEY_DIR", ast_config_AST_KEY_DIR, 1);
00324       setenv("AST_RUN_DIR", ast_config_AST_RUN_DIR, 1);
00325 
00326       /* Don't run AGI scripts with realtime priority -- it causes audio stutter */
00327       ast_set_priority(0);
00328 
00329       /* Redirect stdin and out, provide enhanced audio channel if desired */
00330       dup2(fromast[0], STDIN_FILENO);
00331       dup2(toast[1], STDOUT_FILENO);
00332       if (efd) {
00333          dup2(audio[0], STDERR_FILENO + 1);
00334       } else {
00335          close(STDERR_FILENO + 1);
00336       }
00337 
00338       /* Before we unblock our signals, return our trapped signals back to the defaults */
00339       signal(SIGHUP, SIG_DFL);
00340       signal(SIGCHLD, SIG_DFL);
00341       signal(SIGINT, SIG_DFL);
00342       signal(SIGURG, SIG_DFL);
00343       signal(SIGTERM, SIG_DFL);
00344       signal(SIGPIPE, SIG_DFL);
00345       signal(SIGXFSZ, SIG_DFL);
00346 
00347       /* unblock important signal handlers */
00348       if (pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
00349          ast_log(LOG_WARNING, "unable to unblock signals for AGI script: %s\n", strerror(errno));
00350          _exit(1);
00351       }
00352 
00353       /* Close everything but stdin/out/error */
00354       for (x=STDERR_FILENO + 2;x<1024;x++) 
00355          close(x);
00356 
00357       /* Execute script */
00358       /* XXX argv should be deprecated in favor of passing agi_argX paramaters */
00359       execv(script, argv);
00360       /* Can't use ast_log since FD's are closed */
00361       fprintf(stdout, "verbose \"Failed to execute '%s': %s\" 2\n", script, strerror(errno));
00362       /* Special case to set status of AGI to failure */
00363       fprintf(stdout, "failure\n");
00364       fflush(stdout);
00365       _exit(1);
00366    }
00367    pthread_sigmask(SIG_SETMASK, &old_set, NULL);
00368    if (option_verbose > 2) 
00369       ast_verbose(VERBOSE_PREFIX_3 "Launched AGI Script %s\n", script);
00370    fds[0] = toast[0];
00371    fds[1] = fromast[1];
00372    if (efd) {
00373       *efd = audio[1];
00374    }
00375    /* close what we're not using in the parent */
00376    close(toast[1]);
00377    close(fromast[0]);
00378 
00379    if (efd)
00380       close(audio[0]);
00381 
00382    *opid = pid;
00383    return AGI_RESULT_SUCCESS;
00384 }

static int load_module ( void   )  [static]

static int parse_args ( char *  s,
int *  max,
char *  argv[] 
) [static]

Definition at line 1757 of file res_agi.c.

References ast_log(), LOG_WARNING, and MAX_ARGS.

Referenced by agi_handle_command().

01758 {
01759    int x=0;
01760    int quoted=0;
01761    int escaped=0;
01762    int whitespace=1;
01763    char *cur;
01764 
01765    cur = s;
01766    while(*s) {
01767       switch(*s) {
01768       case '"':
01769          /* If it's escaped, put a literal quote */
01770          if (escaped) 
01771             goto normal;
01772          else 
01773             quoted = !quoted;
01774          if (quoted && whitespace) {
01775             /* If we're starting a quote, coming off white space start a new word, too */
01776             argv[x++] = cur;
01777             whitespace=0;
01778          }
01779          escaped = 0;
01780       break;
01781       case ' ':
01782       case '\t':
01783          if (!quoted && !escaped) {
01784             /* If we're not quoted, mark this as whitespace, and
01785                end the previous argument */
01786             whitespace = 1;
01787             *(cur++) = '\0';
01788          } else
01789             /* Otherwise, just treat it as anything else */ 
01790             goto normal;
01791          break;
01792       case '\\':
01793          /* If we're escaped, print a literal, otherwise enable escaping */
01794          if (escaped) {
01795             goto normal;
01796          } else {
01797             escaped=1;
01798          }
01799          break;
01800       default:
01801 normal:
01802          if (whitespace) {
01803             if (x >= MAX_ARGS -1) {
01804                ast_log(LOG_WARNING, "Too many arguments, truncating\n");
01805                break;
01806             }
01807             /* Coming off of whitespace, start the next argument */
01808             argv[x++] = cur;
01809             whitespace=0;
01810          }
01811          *(cur++) = *s;
01812          escaped=0;
01813       }
01814       s++;
01815    }
01816    /* Null terminate */
01817    *(cur++) = '\0';
01818    argv[x] = NULL;
01819    *max = x;
01820    return 0;
01821 }

static enum agi_result run_agi ( struct ast_channel *  chan,
char *  request,
AGI *  agi,
int  pid,
int *  status,
int  dead,
int  argc,
char *  argv[] 
) [static]

Definition at line 1856 of file res_agi.c.

References AGI_BUF_LEN, agi_handle_command(), AGI_NANDFS_RETRY, AGI_RESULT_FAILURE, AGI_RESULT_HANGUP, AGI_RESULT_SUCCESS, ast_false(), AST_FRAME_VOICE, ast_frfree, ast_log(), AST_PBX_KEEPALIVE, ast_read(), ast_strlen_zero(), ast_verbose(), ast_waitfor_nandfds(), agi_state::audio, agi_state::ctrl, ast_frame::data, ast_frame::datalen, errno, f, agi_state::fast, agi_state::fd, ast_frame::frametype, len(), LOG_DEBUG, LOG_WARNING, ast_channel::name, option_verbose, pbx_builtin_getvar_helper(), setup_env(), and VERBOSE_PREFIX_3.

Referenced by agi_exec_full().

01857 {
01858    struct ast_channel *c;
01859    int outfd;
01860    int ms;
01861    enum agi_result returnstatus = AGI_RESULT_SUCCESS;
01862    struct ast_frame *f;
01863    char buf[AGI_BUF_LEN];
01864    char *res = NULL;
01865    FILE *readf;
01866    /* how many times we'll retry if ast_waitfor_nandfs will return without either 
01867      channel or file descriptor in case select is interrupted by a system call (EINTR) */
01868    int retry = AGI_NANDFS_RETRY;
01869 
01870    if (!(readf = fdopen(agi->ctrl, "r"))) {
01871       ast_log(LOG_WARNING, "Unable to fdopen file descriptor\n");
01872       if (pid > -1)
01873          kill(pid, SIGHUP);
01874       close(agi->ctrl);
01875       return AGI_RESULT_FAILURE;
01876    }
01877    setlinebuf(readf);
01878    setup_env(chan, request, agi->fd, (agi->audio > -1), argc, argv);
01879    for (;;) {
01880       ms = -1;
01881       c = ast_waitfor_nandfds(&chan, dead ? 0 : 1, &agi->ctrl, 1, NULL, &outfd, &ms);
01882       if (c) {
01883          retry = AGI_NANDFS_RETRY;
01884          /* Idle the channel until we get a command */
01885          f = ast_read(c);
01886          if (!f) {
01887             ast_log(LOG_DEBUG, "%s hungup\n", chan->name);
01888             returnstatus = AGI_RESULT_HANGUP;
01889             break;
01890          } else {
01891             /* If it's voice, write it to the audio pipe */
01892             if ((agi->audio > -1) && (f->frametype == AST_FRAME_VOICE)) {
01893                /* Write, ignoring errors */
01894                if (write(agi->audio, f->data, f->datalen) < 0) {
01895                }
01896             }
01897             ast_frfree(f);
01898          }
01899       } else if (outfd > -1) {
01900          size_t len = sizeof(buf);
01901          size_t buflen = 0;
01902 
01903          retry = AGI_NANDFS_RETRY;
01904          buf[0] = '\0';
01905 
01906          while (buflen < (len - 1)) {
01907             res = fgets(buf + buflen, len, readf);
01908             if (feof(readf)) 
01909                break;
01910             if (ferror(readf) && ((errno != EINTR) && (errno != EAGAIN))) 
01911                break;
01912             if (res != NULL && !agi->fast)
01913                break;
01914             buflen = strlen(buf);
01915             if (buflen && buf[buflen - 1] == '\n')
01916                break;
01917             len -= buflen;
01918             if (agidebug)
01919                ast_verbose( "AGI Rx << temp buffer %s - errno %s\n", buf, strerror(errno));
01920          }
01921 
01922          if (!buf[0]) {
01923             /* Program terminated */
01924             if (returnstatus)
01925                returnstatus = -1;
01926             if (option_verbose > 2) 
01927                ast_verbose(VERBOSE_PREFIX_3 "AGI Script %s completed, returning %d\n", request, returnstatus);
01928             if (pid > 0)
01929                waitpid(pid, status, 0);
01930             /* No need to kill the pid anymore, since they closed us */
01931             pid = -1;
01932             break;
01933          }
01934 
01935          /* Special case for inability to execute child process */
01936          if (*buf && strncasecmp(buf, "failure", 7) == 0) {
01937             returnstatus = AGI_RESULT_FAILURE;
01938             break;
01939          }
01940 
01941          /* get rid of trailing newline, if any */
01942          if (*buf && buf[strlen(buf) - 1] == '\n')
01943             buf[strlen(buf) - 1] = 0;
01944          if (agidebug)
01945             ast_verbose("AGI Rx << %s\n", buf);
01946          returnstatus |= agi_handle_command(chan, agi, buf);
01947          /* If the handle_command returns -1, we need to stop */
01948          if ((returnstatus < 0) || (returnstatus == AST_PBX_KEEPALIVE)) {
01949             break;
01950          }
01951       } else {
01952          if (--retry <= 0) {
01953             ast_log(LOG_WARNING, "No channel, no fd?\n");
01954             returnstatus = AGI_RESULT_FAILURE;
01955             break;
01956          }
01957       }
01958    }
01959    /* Notify process */
01960    if (pid > -1) {
01961       const char *sighup = pbx_builtin_getvar_helper(chan, "AGISIGHUP");
01962       if (ast_strlen_zero(sighup) || !ast_false(sighup)) {
01963          if (kill(pid, SIGHUP)) {
01964             ast_log(LOG_WARNING, "unable to send SIGHUP to AGI process %d: %s\n", pid, strerror(errno));
01965          } else { /* Give the process a chance to die */
01966             usleep(1);
01967          }
01968       }
01969       waitpid(pid, status, WNOHANG);
01970    }
01971    fclose(readf);
01972    return returnstatus;
01973 }

static void setup_env ( struct ast_channel *  chan,
char *  request,
int  fd,
int  enhanced,
int  argc,
char *  argv[] 
) [static]

Definition at line 386 of file res_agi.c.

References ast_channel::accountcode, ast_channel::cid, ast_callerid::cid_ani2, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_callerid::cid_tns, ast_callerid::cid_ton, ast_channel::context, ast_channel::exten, fdprintf, ast_channel::language, ast_channel::name, ast_channel::priority, S_OR, ast_channel::tech, ast_channel_tech::type, and ast_channel::uniqueid.

Referenced by run_agi().

00387 {
00388    int count;
00389 
00390    /* Print initial environment, with agi_request always being the first
00391       thing */
00392    fdprintf(fd, "agi_request: %s\n", request);
00393    fdprintf(fd, "agi_channel: %s\n", chan->name);
00394    fdprintf(fd, "agi_language: %s\n", chan->language);
00395    fdprintf(fd, "agi_type: %s\n", chan->tech->type);
00396    fdprintf(fd, "agi_uniqueid: %s\n", chan->uniqueid);
00397 
00398    /* ANI/DNIS */
00399    fdprintf(fd, "agi_callerid: %s\n", S_OR(chan->cid.cid_num, "unknown"));
00400    fdprintf(fd, "agi_calleridname: %s\n", S_OR(chan->cid.cid_name, "unknown"));
00401    fdprintf(fd, "agi_callingpres: %d\n", chan->cid.cid_pres);
00402    fdprintf(fd, "agi_callingani2: %d\n", chan->cid.cid_ani2);
00403    fdprintf(fd, "agi_callington: %d\n", chan->cid.cid_ton);
00404    fdprintf(fd, "agi_callingtns: %d\n", chan->cid.cid_tns);
00405    fdprintf(fd, "agi_dnid: %s\n", S_OR(chan->cid.cid_dnid, "unknown"));
00406    fdprintf(fd, "agi_rdnis: %s\n", S_OR(chan->cid.cid_rdnis, "unknown"));
00407 
00408    /* Context information */
00409    fdprintf(fd, "agi_context: %s\n", chan->context);
00410    fdprintf(fd, "agi_extension: %s\n", chan->exten);
00411    fdprintf(fd, "agi_priority: %d\n", chan->priority);
00412    fdprintf(fd, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0");
00413 
00414    /* User information */
00415    fdprintf(fd, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : "");
00416     
00417    /* Send any parameters to the fastagi server that have been passed via the agi application */
00418    /* Agi application paramaters take the form of: AGI(/path/to/example/script|${EXTEN}) */
00419    for(count = 1; count < argc; count++)
00420       fdprintf(fd, "agi_arg_%d: %s\n", count, argv[count]);
00421 
00422    /* End with empty return */
00423    fdprintf(fd, "\n");
00424 }

static int unload_module ( void   )  [static]


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_BUILDSUM, .description = "Asterisk Gateway Interface (AGI)" , .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, } [static]

Definition at line 2223 of file res_agi.c.

int agidebug = 0 [static]

Definition at line 107 of file res_agi.c.

char* app = "AGI" [static]

Definition at line 78 of file res_agi.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 2223 of file res_agi.c.

struct ast_cli_entry cli_agi[] [static]

Definition at line 2185 of file res_agi.c.

Initial value:

 {
   { "agi", "no", "debug", NULL },
   agi_no_debug_deprecated, NULL,
   NULL }

Definition at line 2180 of file res_agi.c.

Initial value:

 {
   { "dump", "agihtml", NULL },
   handle_agidumphtml, NULL,
   NULL }

Definition at line 2175 of file res_agi.c.

Initial value:

 {
   { "show", "agi", NULL },
   handle_showagi, NULL,
   NULL }

Definition at line 2170 of file res_agi.c.

agi_command commands[MAX_COMMANDS] [static]

Definition at line 1631 of file res_agi.c.

Referenced by aji_dinfo_handler(), and dundi_showframe().

char* deadapp = "DeadAGI" [static]

Definition at line 82 of file res_agi.c.

char* deadsynopsis = "Executes AGI on a hungup channel" [static]

Definition at line 86 of file res_agi.c.

char debug_usage[] [static]

Initial value:

 
"Usage: agi debug\n"
"       Enables dumping of AGI transactions for debugging purposes\n"

Definition at line 1333 of file res_agi.c.

char* descrip [static]

Definition at line 88 of file res_agi.c.

char dumpagihtml_help[] [static]

Initial value:

"Usage: agi dumphtml <filename>\n"
"  Dumps the agi command list in html format to given filename\n"

Definition at line 2166 of file res_agi.c.

char* eapp = "EAGI" [static]

Definition at line 80 of file res_agi.c.

char* esynopsis = "Executes an EAGI compliant application" [static]

Definition at line 85 of file res_agi.c.

char no_debug_usage[] [static]

Initial value:

 
"Usage: agi debug off\n"
"       Disables dumping of AGI transactions for debugging purposes\n"

Definition at line 1337 of file res_agi.c.

char showagi_help[] [static]

Initial value:

"Usage: agi show [topic]\n"
"       When called with a topic as an argument, displays usage\n"
"       information on the given command.  If called without a\n"
"       topic, it provides a list of AGI commands.\n"

Definition at line 2159 of file res_agi.c.

char* synopsis = "Executes an AGI compliant application" [static]

Definition at line 84 of file res_agi.c.

char usage_answer[] [static]

Initial value:

 
" Usage: ANSWER\n"
"  Answers channel if not already in answer state. Returns -1 on\n"
" channel failure, or 0 if successful.\n"

Definition at line 1466 of file res_agi.c.

char usage_autohangup[] [static]

Initial value:

" Usage: SET AUTOHANGUP <time>\n"
"  Cause the channel to automatically hangup at <time> seconds in the\n"
" future.  Of course it can be hungup before then as well. Setting to 0 will\n"
" cause the autohangup feature to be disabled on this channel.\n"

Definition at line 1621 of file res_agi.c.

char usage_channelstatus[] [static]

Definition at line 1438 of file res_agi.c.

char usage_controlstreamfile[] [static]

Definition at line 1522 of file res_agi.c.

char usage_dbdel[] [static]

Initial value:

" Usage: DATABASE DEL <family> <key>\n"
"  Deletes an entry in the Asterisk database for a\n"
" given family and key.\n"
" Returns 1 if successful, 0 otherwise.\n"

Definition at line 1404 of file res_agi.c.

char usage_dbdeltree[] [static]

Initial value:

" Usage: DATABASE DELTREE <family> [keytree]\n"
"  Deletes a family or specific keytree within a family\n"
" in the Asterisk database.\n"
" Returns 1 if successful, 0 otherwise.\n"

Definition at line 1410 of file res_agi.c.

char usage_dbget[] [static]

Definition at line 1396 of file res_agi.c.

char usage_dbput[] [static]

Initial value:

" Usage: DATABASE PUT <family> <key> <value>\n"
"  Adds or updates an entry in the Asterisk database for a\n"
" given family, key, and value.\n"
" Returns 1 if successful, 0 otherwise.\n"

Definition at line 1390 of file res_agi.c.

char usage_exec[] [static]

Initial value:

" Usage: EXEC <application> <options>\n"
"  Executes <application> with given <options>.\n"
" Returns whatever the application returns, or -2 on failure to find application\n"

Definition at line 1456 of file res_agi.c.

char usage_getdata[] [static]

Initial value:

" Usage: GET DATA <file to be streamed> [timeout] [max digits]\n"
"  Stream the given file, and recieve DTMF data. Returns the digits received\n"
"from the channel at the other end.\n"

Definition at line 1591 of file res_agi.c.

char usage_getoption[] [static]

Initial value:

 
" Usage: GET OPTION <filename> <escape_digits> [timeout]\n"
"  Behaves similar to STREAM FILE but used with a timeout option.\n"

Definition at line 1532 of file res_agi.c.

char usage_getvariable[] [static]

Initial value:

" Usage: GET VARIABLE <variablename>\n"
"  Returns 0 if <variablename> is not set.  Returns 1 if <variablename>\n"
" is set and returns the variable in parentheses.\n"
" example return code: 200 result=1 (testvariable)\n"

Definition at line 1422 of file res_agi.c.

char usage_getvariablefull[] [static]

Definition at line 1428 of file res_agi.c.

char usage_hangup[] [static]

Initial value:

" Usage: HANGUP [<channelname>]\n"
"  Hangs up the specified channel.\n"
" If no channel name is given, hangs up the current channel\n"

Definition at line 1461 of file res_agi.c.

char usage_noop[] [static]

Initial value:

" Usage: NoOp\n"
"  Does nothing.\n"

Definition at line 1627 of file res_agi.c.

char usage_recordfile[] [static]

Definition at line 1609 of file res_agi.c.

char usage_recvchar[] [static]

Definition at line 1486 of file res_agi.c.

char usage_recvtext[] [static]

Initial value:

" Usage: RECEIVE TEXT <timeout>\n"
"  Receives a string of text on a channel. Specify timeout to be the\n"
" maximum time to wait for input in milliseconds, or 0 for infinite. Most channels\n"
" do not support the reception of text. Returns -1 for failure or 1 for success, and the string in parentheses.\n"

Definition at line 1494 of file res_agi.c.

char usage_sayalpha[] [static]

Definition at line 1550 of file res_agi.c.

char usage_saydate[] [static]

Definition at line 1557 of file res_agi.c.

char usage_saydatetime[] [static]

Definition at line 1573 of file res_agi.c.

char usage_saydigits[] [static]

Definition at line 1543 of file res_agi.c.

char usage_saynumber[] [static]

Definition at line 1536 of file res_agi.c.

char usage_sayphonetic[] [static]

Definition at line 1584 of file res_agi.c.

char usage_saytime[] [static]

Definition at line 1565 of file res_agi.c.

char usage_sendimage[] [static]

Definition at line 1505 of file res_agi.c.

char usage_sendtext[] [static]

Definition at line 1478 of file res_agi.c.

char usage_setcallerid[] [static]

Initial value:

" Usage: SET CALLERID <number>\n"
"  Changes the callerid of the current channel.\n"

Definition at line 1452 of file res_agi.c.

char usage_setcontext[] [static]

Initial value:

" Usage: SET CONTEXT <desired context>\n"
"  Sets the context for continuation upon exiting the application.\n"

Definition at line 1596 of file res_agi.c.

char usage_setextension[] [static]

Initial value:

" Usage: SET EXTENSION <new extension>\n"
"  Changes the extension for continuation upon exiting the application.\n"

Definition at line 1600 of file res_agi.c.

char usage_setmusic[] [static]

Initial value:

" Usage: SET MUSIC ON <on|off> <class>\n"
"  Enables/Disables the music on hold generator.  If <class> is\n"
" not specified, then the default music on hold class will be used.\n"
" Always returns 0.\n"

Definition at line 1384 of file res_agi.c.

char usage_setpriority[] [static]

Initial value:

" Usage: SET PRIORITY <priority>\n"
"  Changes the priority for continuation upon exiting the application.\n"
" The priority must be a valid priority or label.\n"

Definition at line 1604 of file res_agi.c.

char usage_setvariable[] [static]

Initial value:

" Usage: SET VARIABLE <variablename> <value>\n"

Definition at line 1435 of file res_agi.c.

char usage_streamfile[] [static]

Definition at line 1512 of file res_agi.c.

char usage_tddmode[] [static]

Initial value:

" Usage: TDD MODE <on|off>\n"
"  Enable/Disable TDD transmission/reception on a channel. Returns 1 if\n"
" successful, or 0 if channel is not TDD-capable.\n"

Definition at line 1500 of file res_agi.c.

char usage_verbose[] [static]

Initial value:

" Usage: VERBOSE <message> <level>\n"
"  Sends <message> to the console via verbose message system.\n"
" <level> is the the verbose level (1-4)\n"
" Always returns 1.\n"

Definition at line 1416 of file res_agi.c.

char usage_waitfordigit[] [static]

Definition at line 1471 of file res_agi.c.


Generated on Fri Jul 3 20:39:01 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9