#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/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 | TONE_BLOCK_SIZE 200 |
Enumerations | |
| enum | agi_result { AGI_RESULT_FAILURE = -1, AGI_RESULT_SUCCESS, AGI_RESULT_SUCCESS_FAST, AGI_RESULT_HANGUP } |
Functions | |
| 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) |
| AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS,"Asterisk Gateway Interface (AGI)",.load=load_module,.unload=unload_module,) | |
| 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) |
| static void | setup_env (struct ast_channel *chan, char *request, int fd, int enhanced) |
| static int | unload_module (void) |
Variables | |
| static int | agidebug = 0 |
| static char * | app = "AGI" |
| 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 [] |
Definition in file res_agi.c.
| #define AGI_BUF_LEN 2048 |
| #define AGI_PORT 4573 |
| #define fdprintf agi_debug_cli |
Definition at line 75 of file res_agi.c.
Referenced by agi_handle_command(), handle_answer(), handle_autohangup(), handle_channelstatus(), handle_controlstreamfile(), handle_dbdel(), handle_dbdeltree(), handle_dbget(), handle_dbput(), handle_exec(), handle_getdata(), handle_getoption(), handle_getvariable(), handle_getvariablefull(), handle_hangup(), handle_noop(), handle_recordfile(), handle_recvchar(), handle_recvtext(), handle_sayalpha(), handle_saydate(), handle_saydatetime(), handle_saydigits(), handle_saynumber(), handle_sayphonetic(), handle_saytime(), handle_sendimage(), handle_sendtext(), handle_setcallerid(), handle_setcontext(), handle_setextension(), handle_setmusic(), handle_setpriority(), handle_setvariable(), handle_streamfile(), handle_tddmode(), handle_verbose(), handle_waitfordigit(), launch_netscript(), and setup_env().
| #define MAX_AGI_CONNECT 2000 |
| #define MAX_COMMANDS 128 |
| enum agi_result |
Definition at line 115 of file res_agi.c.
00115 { 00116 AGI_RESULT_FAILURE = -1, 00117 AGI_RESULT_SUCCESS, 00118 AGI_RESULT_SUCCESS_FAST, 00119 AGI_RESULT_HANGUP 00120 };
| static int agi_debug_cli | ( | int | fd, | |
| char * | fmt, | |||
| ... | ||||
| ) | [static] |
Definition at line 122 of file res_agi.c.
References ast_carefulwrite(), ast_log(), ast_verbose(), free, LOG_ERROR, ast_variable::stuff, and vasprintf.
00123 { 00124 char *stuff; 00125 int res = 0; 00126 00127 va_list ap; 00128 va_start(ap, fmt); 00129 res = vasprintf(&stuff, fmt, ap); 00130 va_end(ap); 00131 if (res == -1) { 00132 ast_log(LOG_ERROR, "Out of memory\n"); 00133 } else { 00134 if (agidebug) 00135 ast_verbose("AGI Tx >> %s", stuff); /* \n provided by caller */ 00136 res = ast_carefulwrite(fd, stuff, strlen(stuff), 100); 00137 free(stuff); 00138 } 00139 00140 return res; 00141 }
| static int agi_do_debug | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1322 of file res_agi.c.
References ast_cli(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
01323 { 01324 if (argc != 2) 01325 return RESULT_SHOWUSAGE; 01326 agidebug = 1; 01327 ast_cli(fd, "AGI Debugging Enabled\n"); 01328 return RESULT_SUCCESS; 01329 }
| static int agi_exec | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Definition at line 2102 of file res_agi.c.
References ast_channel::_softhangup, agi_exec_full(), ast_log(), ast_module_user::chan, and LOG_WARNING.
Referenced by load_module().
02103 { 02104 if (chan->_softhangup) 02105 ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n"); 02106 return agi_exec_full(chan, data, 0, 0); 02107 }
| static int agi_exec_full | ( | struct ast_channel * | chan, | |
| void * | data, | |||
| int | enhanced, | |||
| int | dead | |||
| ) | [static] |
Definition at line 2031 of file res_agi.c.
References ast_channel::_state, AGI_BUF_LEN, AGI_RESULT_FAILURE, AGI_RESULT_SUCCESS, AGI_RESULT_SUCCESS_FAST, ast_answer(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_replace_sigchld(), AST_STATE_UP, ast_strlen_zero(), ast_unreplace_sigchld(), ast_module_user::chan, launch_script(), LOG_WARNING, MAX_ARGS, pbx_builtin_setvar_helper(), run_agi(), and strsep().
Referenced by agi_exec(), deadagi_exec(), and eagi_exec().
02032 { 02033 enum agi_result res; 02034 struct ast_module_user *u; 02035 char *argv[MAX_ARGS]; 02036 char buf[AGI_BUF_LEN] = ""; 02037 char *tmp = (char *)buf; 02038 int argc = 0; 02039 int fds[2]; 02040 int efd = -1; 02041 int pid; 02042 char *stringp; 02043 AGI agi; 02044 02045 if (ast_strlen_zero(data)) { 02046 ast_log(LOG_WARNING, "AGI requires an argument (script)\n"); 02047 return -1; 02048 } 02049 ast_copy_string(buf, data, sizeof(buf)); 02050 02051 memset(&agi, 0, sizeof(agi)); 02052 while ((stringp = strsep(&tmp, "|")) && argc < MAX_ARGS-1) 02053 argv[argc++] = stringp; 02054 argv[argc] = NULL; 02055 02056 u = ast_module_user_add(chan); 02057 #if 0 02058 /* Answer if need be */ 02059 if (chan->_state != AST_STATE_UP) { 02060 if (ast_answer(chan)) { 02061 LOCAL_USER_REMOVE(u); 02062 return -1; 02063 } 02064 } 02065 #endif 02066 ast_replace_sigchld(); 02067 res = launch_script(argv[0], argv, fds, enhanced ? &efd : NULL, &pid); 02068 if (res == AGI_RESULT_SUCCESS || res == AGI_RESULT_SUCCESS_FAST) { 02069 int status = 0; 02070 agi.fd = fds[1]; 02071 agi.ctrl = fds[0]; 02072 agi.audio = efd; 02073 agi.fast = (res == AGI_RESULT_SUCCESS_FAST) ? 1 : 0; 02074 res = run_agi(chan, argv[0], &agi, pid, &status, dead); 02075 /* If the fork'd process returns non-zero, set AGISTATUS to FAILURE */ 02076 if ((res == AGI_RESULT_SUCCESS || res == AGI_RESULT_SUCCESS_FAST) && status) 02077 res = AGI_RESULT_FAILURE; 02078 if (fds[1] != fds[0]) 02079 close(fds[1]); 02080 if (efd > -1) 02081 close(efd); 02082 } 02083 ast_unreplace_sigchld(); 02084 ast_module_user_remove(u); 02085 02086 switch (res) { 02087 case AGI_RESULT_SUCCESS: 02088 case AGI_RESULT_SUCCESS_FAST: 02089 pbx_builtin_setvar_helper(chan, "AGISTATUS", "SUCCESS"); 02090 break; 02091 case AGI_RESULT_FAILURE: 02092 pbx_builtin_setvar_helper(chan, "AGISTATUS", "FAILURE"); 02093 break; 02094 case AGI_RESULT_HANGUP: 02095 pbx_builtin_setvar_helper(chan, "AGISTATUS", "HANGUP"); 02096 return -1; 02097 } 02098 02099 return 0; 02100 }
| static int agi_handle_command | ( | struct ast_channel * | chan, | |
| AGI * | agi, | |||
| char * | buf | |||
| ) | [static] |
Definition at line 1804 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().
01805 { 01806 char *argv[MAX_ARGS]; 01807 int argc = MAX_ARGS; 01808 int res; 01809 agi_command *c; 01810 01811 parse_args(buf, &argc, argv); 01812 c = find_command(argv, 0); 01813 if (c) { 01814 res = c->handler(chan, agi, argc, argv); 01815 switch(res) { 01816 case RESULT_SHOWUSAGE: 01817 fdprintf(agi->fd, "520-Invalid command syntax. Proper usage follows:\n"); 01818 fdprintf(agi->fd, c->usage); 01819 fdprintf(agi->fd, "520 End of proper usage.\n"); 01820 break; 01821 case AST_PBX_KEEPALIVE: 01822 /* We've been asked to keep alive, so do so */ 01823 return AST_PBX_KEEPALIVE; 01824 break; 01825 case RESULT_FAILURE: 01826 /* They've already given the failure. We've been hung up on so handle this 01827 appropriately */ 01828 return -1; 01829 } 01830 } else { 01831 fdprintf(agi->fd, "510 Invalid or unknown command\n"); 01832 } 01833 return 0; 01834 }
| static int agi_no_debug | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1340 of file res_agi.c.
References ast_cli(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
01341 { 01342 if (argc != 3) 01343 return RESULT_SHOWUSAGE; 01344 agidebug = 0; 01345 ast_cli(fd, "AGI Debugging Disabled\n"); 01346 return RESULT_SUCCESS; 01347 }
| static int agi_no_debug_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1331 of file res_agi.c.
References ast_cli(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
01332 { 01333 if (argc != 3) 01334 return RESULT_SHOWUSAGE; 01335 agidebug = 0; 01336 ast_cli(fd, "AGI Debugging Disabled\n"); 01337 return RESULT_SUCCESS; 01338 }
| int ast_agi_register | ( | agi_command * | agi | ) |
Definition at line 1675 of file res_agi.c.
References ast_log(), agi_command::cmda, commands, LOG_WARNING, and MAX_COMMANDS.
01676 { 01677 int x; 01678 for (x=0; x<MAX_COMMANDS - 1; x++) { 01679 if (commands[x].cmda[0] == agi->cmda[0]) { 01680 ast_log(LOG_WARNING, "Command already registered!\n"); 01681 return -1; 01682 } 01683 } 01684 for (x=0; x<MAX_COMMANDS - 1; x++) { 01685 if (!commands[x].cmda[0]) { 01686 commands[x] = *agi; 01687 return 0; 01688 } 01689 } 01690 ast_log(LOG_WARNING, "No more room for new commands!\n"); 01691 return -1; 01692 }
| void ast_agi_unregister | ( | agi_command * | agi | ) |
Definition at line 1694 of file res_agi.c.
References agi_command::cmda, and commands.
01695 { 01696 int x; 01697 for (x=0; x<MAX_COMMANDS - 1; x++) { 01698 if (commands[x].cmda[0] == agi->cmda[0]) { 01699 memset(&commands[x], 0, sizeof(agi_command)); 01700 } 01701 } 01702 }
| AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
| AST_MODFLAG_GLOBAL_SYMBOLS | , | |||
| "Asterisk Gateway Interface (AGI)" | , | |||
| . | load = load_module, |
|||
| . | unload = unload_module | |||
| ) |
| static int deadagi_exec | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Definition at line 2130 of file res_agi.c.
References agi_exec_full(), ast_check_hangup(), ast_log(), ast_module_user::chan, and LOG_WARNING.
Referenced by load_module().
02131 { 02132 if (!ast_check_hangup(chan)) 02133 ast_log(LOG_WARNING,"Running DeadAGI on a live channel will cause problems, please use AGI\n"); 02134 return agi_exec_full(chan, data, 0, 1); 02135 }
| static int eagi_exec | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Definition at line 2109 of file res_agi.c.
References ast_channel::_softhangup, agi_exec_full(), AST_FORMAT_SLINEAR, ast_getformatname(), ast_log(), ast_set_read_format(), ast_module_user::chan, LOG_WARNING, and ast_channel::readformat.
Referenced by load_module().
02110 { 02111 int readformat; 02112 int res; 02113 02114 if (chan->_softhangup) 02115 ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n"); 02116 readformat = chan->readformat; 02117 if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) { 02118 ast_log(LOG_WARNING, "Unable to set channel '%s' to linear mode\n", chan->name); 02119 return -1; 02120 } 02121 res = agi_exec_full(chan, data, 1, 0); 02122 if (!res) { 02123 if (ast_set_read_format(chan, readformat)) { 02124 ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", chan->name, ast_getformatname(readformat)); 02125 } 02126 } 02127 return res; 02128 }
| static agi_command* find_command | ( | char * | cmds[], | |
| int | exact | |||
| ) | [static] |
Definition at line 1704 of file res_agi.c.
References agi_command::cmda, commands, and match().
01705 { 01706 int x; 01707 int y; 01708 int match; 01709 01710 for (x=0; x < sizeof(commands) / sizeof(commands[0]); x++) { 01711 if (!commands[x].cmda[0]) 01712 break; 01713 /* start optimistic */ 01714 match = 1; 01715 for (y=0; match && cmds[y]; y++) { 01716 /* If there are no more words in the command (and we're looking for 01717 an exact match) or there is a difference between the two words, 01718 then this is not a match */ 01719 if (!commands[x].cmda[y] && !exact) 01720 break; 01721 /* don't segfault if the next part of a command doesn't exist */ 01722 if (!commands[x].cmda[y]) 01723 return NULL; 01724 if (strcasecmp(commands[x].cmda[y], cmds[y])) 01725 match = 0; 01726 } 01727 /* If more words are needed to complete the command then this is not 01728 a candidate (unless we're looking for a really inexact answer */ 01729 if ((exact > -1) && commands[x].cmda[y]) 01730 match = 0; 01731 if (match) 01732 return &commands[x]; 01733 } 01734 return NULL; 01735 }
| static int handle_agidumphtml | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1977 of file res_agi.c.
References ast_cli(), ast_join(), agi_command::cmda, commands, RESULT_SHOWUSAGE, RESULT_SUCCESS, strsep(), agi_command::summary, and agi_command::usage.
01978 { 01979 struct agi_command *e; 01980 char fullcmd[80]; 01981 int x; 01982 FILE *htmlfile; 01983 01984 if ((argc < 3)) 01985 return RESULT_SHOWUSAGE; 01986 01987 if (!(htmlfile = fopen(argv[2], "wt"))) { 01988 ast_cli(fd, "Could not create file '%s'\n", argv[2]); 01989 return RESULT_SHOWUSAGE; 01990 } 01991 01992 fprintf(htmlfile, "<HTML>\n<HEAD>\n<TITLE>AGI Commands</TITLE>\n</HEAD>\n"); 01993 fprintf(htmlfile, "<BODY>\n<CENTER><B><H1>AGI Commands</H1></B></CENTER>\n\n"); 01994 01995 01996 fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n"); 01997 01998 for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) { 01999 char *stringp, *tempstr; 02000 02001 e = &commands[x]; 02002 if (!e->cmda[0]) /* end ? */ 02003 break; 02004 /* Hide commands that start with '_' */ 02005 if ((e->cmda[0])[0] == '_') 02006 continue; 02007 ast_join(fullcmd, sizeof(fullcmd), e->cmda); 02008 02009 fprintf(htmlfile, "<TR><TD><TABLE BORDER=\"1\" CELLPADDING=\"5\" WIDTH=\"100%%\">\n"); 02010 fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TH></TR>\n", fullcmd,e->summary); 02011 02012 stringp=e->usage; 02013 tempstr = strsep(&stringp, "\n"); 02014 02015 fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">%s</TD></TR>\n", tempstr); 02016 02017 fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">\n"); 02018 while ((tempstr = strsep(&stringp, "\n")) != NULL) 02019 fprintf(htmlfile, "%s<BR>\n",tempstr); 02020 fprintf(htmlfile, "</TD></TR>\n"); 02021 fprintf(htmlfile, "</TABLE></TD></TR>\n\n"); 02022 02023 } 02024 02025 fprintf(htmlfile, "</TABLE>\n</BODY>\n</HTML>\n"); 02026 fclose(htmlfile); 02027 ast_cli(fd, "AGI HTML Commands Dumped to: %s\n", argv[2]); 02028 return RESULT_SUCCESS; 02029 }
| static int handle_answer | ( | struct ast_channel * | chan, | |
| AGI * | agi, | |||
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 407 of file res_agi.c.
References ast_channel::_state, ast_answer(), AST_STATE_UP, agi_state::fd, fdprintf, RESULT_FAILURE, and RESULT_SUCCESS.
00408 { 00409 int res; 00410 res = 0; 00411 if (chan->_state != AST_STATE_UP) { 00412 /* Answer the chan */ 00413 res = ast_answer(chan); 00414 } 00415 fdprintf(agi->fd, "200 result=%d\n", res); 00416 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE; 00417 }
| static int handle_autohangup | ( | struct ast_channel * | chan, | |
| AGI * | agi, | |||
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1056 of file res_agi.c.
References agi_state::fd, fdprintf, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_channel::whentohangup.
01057 { 01058 int timeout; 01059 01060 if (argc != 3) 01061 return RESULT_SHOWUSAGE; 01062 if (sscanf(argv[2], "%d", &timeout) != 1) 01063 return RESULT_SHOWUSAGE; 01064 if (timeout < 0) 01065 timeout = 0; 01066 if (timeout) 01067 chan->whentohangup = time(NULL) + timeout; 01068 else 01069 chan->whentohangup = 0; 01070 fdprintf(agi->fd, "200 result=0\n"); 01071 return RESULT_SUCCESS; 01072 }
| static int handle_channelstatus | ( | struct ast_channel * | chan, | |
| AGI * | agi, | |||
| int | argc, | |||
| char ** | argv | |||
| ) | [static] |
Definition at line 1149 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.
01150 { 01151 struct ast_channel *c; 01152 if (argc == 2) { 01153 /* no argument: supply info on the current channel */ 01154 fdprintf(agi->fd, "200 result=%d\n", chan->_state); 01155 return RESULT_SUCCESS; 01156 } else if (argc == 3) { 01157 /* one argument: look for info on the specified channel */ 01158 c = ast_get_channel_by_name_locked(argv[2]); 01159 if (c) { 01160 fdprintf(agi->fd, "200 result=%d\n", c->_state); 01161 ast_channel_unlock(c); 01162 return RESULT_SUCCESS; 01163 } 01164 /* if we get this far no channel name matched the argument given */ 01165 fdprintf(agi->fd, "200 result=-1\n"); 01166 return RESULT_SUCCESS; 01167 } else { 01168 return RESULT_SHOWUSAGE; 01169 } 01170 }
| static int handle_controlstreamfile | ( | struct ast_channel * | chan, | |
| AGI * | agi, | |||
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 518 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.
00519 { 00520 int res = 0; 00521 int skipms = 3000; 00522 char *fwd = NULL; 00523 char *rev = NULL; 00524 char *pause = NULL; 00525 char *stop = NULL; 00526 00527 if (argc < 5 || argc > 9) 00528 return RESULT_SHOWUSAGE; 00529 00530 if (!ast_strlen_zero(argv[4])) 00531 stop = argv[4]; 00532 else 00533 stop = NULL; 00534 00535 if ((argc > 5) && (sscanf(argv[5], "%d", &skipms) != 1)) 00536 return RESULT_SHOWUSAGE; 00537 00538 if (argc > 6 && !ast_strlen_zero(argv[6])) 00539 fwd = argv[6]; 00540 else 00541 fwd = "#"; 00542 00543 if (argc > 7 && !ast_strlen_zero(argv[7])) 00544 rev = argv[7]; 00545 else 00546 rev = "*"; 00547 00548 if (argc > 8 && !ast_strlen_zero(argv[8])) 00549 pause = argv[8]; 00550 else 00551 pause = NULL; 00552 00553 res = ast_control_streamfile(chan, argv[3], fwd, rev, stop, pause, NULL, skipms); 00554 00555 fdprintf(agi->fd, "200 result=%d\n", res); 00556 00557 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE; 00558 }
| static int handle_dbdel | ( | struct ast_channel * | chan, |