Asterisk - The Open Source Telephony Project GIT-master-a358458
Data Structures | Macros | Enumerations | Functions | Variables
res_agi.c File Reference

AGI - the Asterisk Gateway Interface. More...

#include "asterisk.h"
#include <math.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <pthread.h>
#include "asterisk/paths.h"
#include "asterisk/network.h"
#include "asterisk/file.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/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/manager.h"
#include "asterisk/ast_version.h"
#include "asterisk/speech.h"
#include "asterisk/term.h"
#include "asterisk/xmldoc.h"
#include "asterisk/srv.h"
#include "asterisk/test.h"
#include "asterisk/netsock2.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/format_cache.h"
#include "asterisk/agi.h"
Include dependency graph for res_agi.c:

Go to the source code of this file.

Data Structures

struct  agi_cmd
 
struct  agi_commands
 

Macros

#define AGI_BUF_INITSIZE   256
 
#define AGI_BUF_LEN   2048
 
#define AGI_BUF_SIZE   1024
 
#define AGI_NANDFS_RETRY   3
 
#define AGI_PORT   4573
 
#define AMI_BUF_SIZE   2048
 
#define AST_API_MODULE
 
#define ASYNC_AGI_BREAK   3
 
#define MAX_AGI_CONNECT   2000
 
#define MAX_ARGS   128
 
#define MAX_CMD_LEN   80
 
#define SRV_PREFIX   "_agi._tcp."
 
#define TONE_BLOCK_SIZE   200
 

Enumerations

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

Functions

static void __init_agi_buf (void)
 
static void __reg_module (void)
 
static void __unreg_module (void)
 
static int action_add_agi_cmd (struct mansession *s, const struct message *m)
 Add a new command to execute by the Async AGI application. More...
 
static int add_agi_cmd (struct ast_channel *chan, const char *cmd_buff, const char *cmd_id)
 
static int add_to_agi (struct ast_channel *chan)
 
static struct ast_manager_event_blobagi_async_end_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobagi_async_exec_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobagi_async_start_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobagi_channel_to_ami (const char *type, struct stasis_message *message)
 
static void agi_destroy_commands_cb (void *data)
 
static int agi_exec (struct ast_channel *chan, const char *data)
 
static struct ast_manager_event_blobagi_exec_end_to_ami (struct stasis_message *message)
 
static int agi_exec_full (struct ast_channel *chan, const char *data, int enhanced, int dead)
 
static struct ast_manager_event_blobagi_exec_start_to_ami (struct stasis_message *message)
 
static enum agi_result agi_handle_command (struct ast_channel *chan, AGI *agi, char *buf, int dead)
 
int AST_OPTIONAL_API_NAME() ast_agi_register (struct ast_module *mod, agi_command *cmd)
 Registers an AGI command. More...
 
int AST_OPTIONAL_API_NAME() ast_agi_register_multiple (struct ast_module *mod, struct agi_command *cmd, unsigned int len)
 Registers a group of AGI commands, provided as an array of struct agi_command entries. More...
 
int AST_OPTIONAL_API_NAME() ast_agi_send (int fd, struct ast_channel *chan, char *fmt,...)
 Sends a string of text to an application connected via AGI. More...
 
int AST_OPTIONAL_API_NAME() ast_agi_unregister (agi_command *cmd)
 Unregisters an AGI command. More...
 
int AST_OPTIONAL_API_NAME() ast_agi_unregister_multiple (struct agi_command *cmd, unsigned int len)
 Unregisters a group of AGI commands, provided as an array of struct agi_command entries. More...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static enum agi_result async_agi_read_frame (struct ast_channel *chan)
 
static int deadagi_exec (struct ast_channel *chan, const char *data)
 
static int eagi_exec (struct ast_channel *chan, const char *data)
 
static agi_commandfind_command (const char *const cmds[], int exact)
 
static void free_agi_cmd (struct agi_cmd *cmd)
 
static int get_agi_cmd (struct ast_channel *chan, struct agi_cmd **cmd)
 Retrieve the list head to the requested channel's AGI datastore. More...
 
static int handle_answer (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_asyncagi_break (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_autohangup (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_channelstatus (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static char * handle_cli_agi_add_cmd (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to add applications to execute in Async AGI. More...
 
static char * handle_cli_agi_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_agi_dump_html (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_agi_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int handle_connection (const char *agiurl, const struct ast_sockaddr addr, const int netsockfd)
 
static int handle_controlstreamfile (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_dbdel (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_dbdeltree (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_dbget (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_dbput (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_exec (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_getdata (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_getoption (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 get option - really similar to the handle_streamfile, but with a timeout More...
 
static int handle_getvariable (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_getvariablefull (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_hangup (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_noop (struct ast_channel *chan, AGI *agi, int arg, const char *const argv[])
 
static int handle_recordfile (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_recvchar (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_recvtext (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_sayalpha (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_saydate (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_saydatetime (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_saydigits (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_saynumber (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 Say number in various language syntaxes. More...
 
static int handle_sayphonetic (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_saytime (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_sendimage (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_sendtext (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_setcallerid (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_setcontext (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_setextension (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_setmusic (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_setpriority (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_setvariable (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_speechactivategrammar (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_speechcreate (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_speechdeactivategrammar (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_speechdestroy (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_speechloadgrammar (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_speechrecognize (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_speechset (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_speechunloadgrammar (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_streamfile (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_tddmode (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_verbose (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static int handle_waitfordigit (struct ast_channel *chan, AGI *agi, int argc, const char *const argv[])
 
static char * help_workhorse (int fd, const char *const match[])
 
static enum agi_result launch_asyncagi (struct ast_channel *chan, int argc, char *argv[], int *efd)
 
static enum agi_result launch_ha_netscript (char *agiurl, char *argv[], int *fds)
 
static enum agi_result launch_netscript (char *agiurl, char *argv[], int *fds)
 
static enum agi_result launch_script (struct ast_channel *chan, char *script, int argc, char *argv[], int *fds, int *efd, int *opid)
 
static int load_module (void)
 
static int parse_args (char *s, int *max, const char *argv[])
 
static void publish_async_exec_end (struct ast_channel *chan, int command_id, const char *command, int result_code, const char *result)
 
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 speech_streamfile (struct ast_channel *chan, const char *filename, const char *preflang, int offset)
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (agi_async_end_type,.to_ami=agi_async_end_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (agi_async_exec_type,.to_ami=agi_async_exec_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (agi_async_start_type,.to_ami=agi_async_start_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (agi_exec_end_type,.to_ami=agi_exec_end_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (agi_exec_start_type,.to_ami=agi_exec_start_to_ami,)
 
static int unload_module (void)
 
static void write_html_escaped (FILE *htmlfile, char *str)
 Convert string to use HTML escaped characters. More...
 
static int write_htmldump (const char *filename)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_speech", }
 
static struct ast_threadstorage agi_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_agi_buf , .custom_init = NULL , }
 
static struct agi_commands agi_commands = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static const struct ast_datastore_info agi_commands_datastore_info
 
static int agidebug = 0
 
static char * app = "AGI"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_agi []
 
static struct agi_command commands []
 AGI commands list. More...
 
static char * deadapp = "DeadAGI"
 
static char * eapp = "EAGI"
 

Detailed Description

AGI - the Asterisk Gateway Interface.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file res_agi.c.

Macro Definition Documentation

◆ AGI_BUF_INITSIZE

#define AGI_BUF_INITSIZE   256

Definition at line 1479 of file res_agi.c.

◆ AGI_BUF_LEN

#define AGI_BUF_LEN   2048

Definition at line 1386 of file res_agi.c.

◆ AGI_BUF_SIZE

#define AGI_BUF_SIZE   1024

◆ AGI_NANDFS_RETRY

#define AGI_NANDFS_RETRY   3

Definition at line 1385 of file res_agi.c.

◆ AGI_PORT

#define AGI_PORT   4573

Definition at line 1402 of file res_agi.c.

◆ AMI_BUF_SIZE

#define AMI_BUF_SIZE   2048

◆ AST_API_MODULE

#define AST_API_MODULE

Definition at line 71 of file res_agi.c.

◆ ASYNC_AGI_BREAK

#define ASYNC_AGI_BREAK   3

Special return code for "asyncagi break" command.

Definition at line 1405 of file res_agi.c.

◆ MAX_AGI_CONNECT

#define MAX_AGI_CONNECT   2000

Definition at line 1400 of file res_agi.c.

◆ MAX_ARGS

#define MAX_ARGS   128

Definition at line 1383 of file res_agi.c.

◆ MAX_CMD_LEN

#define MAX_CMD_LEN   80

Definition at line 1384 of file res_agi.c.

◆ SRV_PREFIX

#define SRV_PREFIX   "_agi._tcp."

Definition at line 1387 of file res_agi.c.

◆ TONE_BLOCK_SIZE

#define TONE_BLOCK_SIZE   200

Definition at line 1397 of file res_agi.c.

Enumeration Type Documentation

◆ agi_result

enum agi_result
Enumerator
AGI_RESULT_FAILURE 
AGI_RESULT_SUCCESS 
AGI_RESULT_SUCCESS_FAST 
AGI_RESULT_SUCCESS_ASYNC 
AGI_RESULT_NOTFOUND 
AGI_RESULT_HANGUP 

Definition at line 1407 of file res_agi.c.

1407 {
1408 AGI_RESULT_FAILURE = -1,
1414};
@ AGI_RESULT_HANGUP
Definition: res_agi.c:1413
@ AGI_RESULT_SUCCESS
Definition: res_agi.c:1409
@ AGI_RESULT_FAILURE
Definition: res_agi.c:1408
@ AGI_RESULT_SUCCESS_ASYNC
Definition: res_agi.c:1411
@ AGI_RESULT_SUCCESS_FAST
Definition: res_agi.c:1410
@ AGI_RESULT_NOTFOUND
Definition: res_agi.c:1412

Function Documentation

◆ __init_agi_buf()

static void __init_agi_buf ( void  )
static

Definition at line 1478 of file res_agi.c.

1482{

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 4747 of file res_agi.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 4747 of file res_agi.c.

◆ action_add_agi_cmd()

static int action_add_agi_cmd ( struct mansession s,
const struct message m 
)
static

Add a new command to execute by the Async AGI application.

Parameters
s
m

It will append the application to the specified channel's queue if the channel is not inside Async AGI application it will return an error

Return values
0on success or incorrect use
1on failure to add the command ( most likely because the channel is not in Async AGI loop )

Definition at line 1704 of file res_agi.c.

1705{
1706 const char *channel = astman_get_header(m, "Channel");
1707 const char *cmdbuff = astman_get_header(m, "Command");
1708 const char *cmdid = astman_get_header(m, "CommandID");
1709 struct ast_channel *chan;
1710 char buf[256];
1711
1712 if (ast_strlen_zero(channel) || ast_strlen_zero(cmdbuff)) {
1713 astman_send_error(s, m, "Both, Channel and Command are *required*");
1714 return 0;
1715 }
1716
1717 if (!(chan = ast_channel_get_by_name(channel))) {
1718 snprintf(buf, sizeof(buf), "Channel %s does not exist.", channel);
1719 astman_send_error(s, m, buf);
1720 return 0;
1721 }
1722
1723 ast_channel_lock(chan);
1724
1725 if (add_agi_cmd(chan, cmdbuff, cmdid)) {
1726 snprintf(buf, sizeof(buf), "Failed to add AGI command to channel %s queue", ast_channel_name(chan));
1727 astman_send_error(s, m, buf);
1728 ast_channel_unlock(chan);
1729 chan = ast_channel_unref(chan);
1730 return 0;
1731 }
1732
1733 ast_channel_unlock(chan);
1734 chan = ast_channel_unref(chan);
1735
1736 astman_send_ack(s, m, "Added AGI command to queue");
1737
1738 return 0;
1739}
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2922
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
#define ast_channel_unlock(chan)
Definition: channel.h:2923
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3381
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3413
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition: manager.c:3042
static int add_agi_cmd(struct ast_channel *chan, const char *cmd_buff, const char *cmd_id)
Definition: res_agi.c:1575
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.

References add_agi_cmd(), ast_channel_get_by_name(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_channel_unref, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), and buf.

Referenced by load_module().

◆ add_agi_cmd()

static int add_agi_cmd ( struct ast_channel chan,
const char *  cmd_buff,
const char *  cmd_id 
)
static

Definition at line 1575 of file res_agi.c.

1576{
1577 struct ast_datastore *store;
1578 struct agi_cmd *cmd;
1580
1582 if (!store) {
1583 ast_log(LOG_WARNING, "Channel %s is not setup for Async AGI.\n", ast_channel_name(chan));
1584 return -1;
1585 }
1586 agi_commands = store->data;
1587 cmd = ast_calloc(1, sizeof(*cmd));
1588 if (!cmd) {
1589 return -1;
1590 }
1591 cmd->cmd_buffer = ast_strdup(cmd_buff);
1592 if (!cmd->cmd_buffer) {
1593 ast_free(cmd);
1594 return -1;
1595 }
1596 cmd->cmd_id = ast_strdup(cmd_id);
1597 if (!cmd->cmd_id) {
1598 ast_free(cmd->cmd_buffer);
1599 ast_free(cmd);
1600 return -1;
1601 }
1605 return 0;
1606}
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2399
#define LOG_WARNING
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
Definition: linkedlists.h:173
static struct agi_commands agi_commands
static const struct ast_datastore_info agi_commands_datastore_info
Definition: res_agi.c:1539
#define NULL
Definition: resample.c:96
char * cmd_buffer
Definition: res_agi.c:1512
char * cmd_id
Definition: res_agi.c:1513
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
Definition: search.h:40

References agi_commands, agi_commands_datastore_info, ast_calloc, ast_channel_datastore_find(), ast_channel_name(), ast_free, AST_LIST_HEAD, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log, ast_strdup, agi_cmd::cmd_buffer, agi_cmd::cmd_id, ast_datastore::data, LOG_WARNING, and NULL.

Referenced by action_add_agi_cmd(), and handle_cli_agi_add_cmd().

◆ add_to_agi()

static int add_to_agi ( struct ast_channel chan)
static

Definition at line 1608 of file res_agi.c.

1609{
1610 struct ast_datastore *datastore;
1611 AST_LIST_HEAD(, agi_cmd) *agi_cmds_list;
1612
1613 /* check if already on AGI */
1614 ast_channel_lock(chan);
1616 ast_channel_unlock(chan);
1617 if (datastore) {
1618 /* we already have an AGI datastore, let's just
1619 return success */
1620 return 0;
1621 }
1622
1623 /* the channel has never been on Async AGI,
1624 let's allocate it's datastore */
1626 if (!datastore) {
1627 return -1;
1628 }
1629 agi_cmds_list = ast_calloc(1, sizeof(*agi_cmds_list));
1630 if (!agi_cmds_list) {
1631 ast_log(LOG_ERROR, "Unable to allocate Async AGI commands list.\n");
1632 ast_datastore_free(datastore);
1633 return -1;
1634 }
1635 datastore->data = agi_cmds_list;
1636 AST_LIST_HEAD_INIT(agi_cmds_list);
1637 ast_channel_lock(chan);
1638 ast_channel_datastore_add(chan, datastore);
1639 ast_channel_unlock(chan);
1640 return 0;
1641}
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2385
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
#define LOG_ERROR
#define AST_LIST_HEAD_INIT(head)
Initializes a list head structure.
Definition: linkedlists.h:626

References agi_commands_datastore_info, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), AST_LIST_HEAD, AST_LIST_HEAD_INIT, ast_log, ast_datastore::data, LOG_ERROR, and NULL.

Referenced by launch_asyncagi().

◆ agi_async_end_to_ami()

static struct ast_manager_event_blob * agi_async_end_to_ami ( struct stasis_message message)
static

Definition at line 1455 of file res_agi.c.

1456{
1457 return agi_channel_to_ami("AsyncAGIEnd", message);
1458}
static struct ast_manager_event_blob * agi_channel_to_ami(const char *type, struct stasis_message *message)
Definition: res_agi.c:1416

References agi_channel_to_ami().

◆ agi_async_exec_to_ami()

static struct ast_manager_event_blob * agi_async_exec_to_ami ( struct stasis_message message)
static

Definition at line 1450 of file res_agi.c.

1451{
1452 return agi_channel_to_ami("AsyncAGIExec", message);
1453}

References agi_channel_to_ami().

◆ agi_async_start_to_ami()

static struct ast_manager_event_blob * agi_async_start_to_ami ( struct stasis_message message)
static

Definition at line 1445 of file res_agi.c.

1446{
1447 return agi_channel_to_ami("AsyncAGIStart", message);
1448}

References agi_channel_to_ami().

◆ agi_channel_to_ami()

static struct ast_manager_event_blob * agi_channel_to_ami ( const char *  type,
struct stasis_message message 
)
static

Definition at line 1416 of file res_agi.c.

1417{
1419 RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
1420 RAII_VAR(struct ast_str *, event_string, NULL, ast_free);
1421
1422 channel_string = ast_manager_build_channel_state_string(obj->snapshot);
1423 event_string = ast_manager_str_from_json_object(obj->blob, NULL);
1424 if (!channel_string || !event_string) {
1425 return NULL;
1426 }
1427
1429 "%s"
1430 "%s",
1431 ast_str_buffer(channel_string),
1432 ast_str_buffer(event_string));
1433}
static const char type[]
Definition: chan_ooh323.c:109
struct ast_str * ast_manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
Convert a JSON object into an AMI compatible string.
Definition: manager.c:1973
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition: manager.c:10548
#define EVENT_FLAG_AGI
Definition: manager.h:88
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
Blob of data associated with a channel.
struct ast_channel_snapshot * snapshot
struct ast_json * blob
Support for dynamic strings.
Definition: strings.h:623
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References ast_free, ast_manager_build_channel_state_string(), ast_manager_event_blob_create(), ast_manager_str_from_json_object(), ast_str_buffer(), ast_channel_blob::blob, EVENT_FLAG_AGI, NULL, RAII_VAR, ast_channel_blob::snapshot, stasis_message_data(), and type.

Referenced by agi_async_end_to_ami(), agi_async_exec_to_ami(), agi_async_start_to_ami(), agi_exec_end_to_ami(), and agi_exec_start_to_ami().

◆ agi_destroy_commands_cb()

static void agi_destroy_commands_cb ( void *  data)
static

Definition at line 1525 of file res_agi.c.

1526{
1527 struct agi_cmd *cmd;
1528 AST_LIST_HEAD(, agi_cmd) *chan_cmds = data;
1529 AST_LIST_LOCK(chan_cmds);
1530 while ( (cmd = AST_LIST_REMOVE_HEAD(chan_cmds, entry)) ) {
1531 free_agi_cmd(cmd);
1532 }
1533 AST_LIST_UNLOCK(chan_cmds);
1534 AST_LIST_HEAD_DESTROY(chan_cmds);
1535 ast_free(chan_cmds);
1536}
#define AST_LIST_HEAD_DESTROY(head)
Destroys a list head structure.
Definition: linkedlists.h:653
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
static void free_agi_cmd(struct agi_cmd *cmd)
Definition: res_agi.c:1517

References ast_free, AST_LIST_HEAD, AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, and free_agi_cmd().

◆ agi_exec()

static int agi_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 4593 of file res_agi.c.

4594{
4595 if (!ast_check_hangup(chan))
4596 return agi_exec_full(chan, data, 0, 0);
4597 else
4598 return agi_exec_full(chan, data, 0, 1);
4599}
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
static int agi_exec_full(struct ast_channel *chan, const char *data, int enhanced, int dead)
Definition: res_agi.c:4526

References agi_exec_full(), and ast_check_hangup().

Referenced by deadagi_exec(), and load_module().

◆ agi_exec_end_to_ami()

static struct ast_manager_event_blob * agi_exec_end_to_ami ( struct stasis_message message)
static

Definition at line 1440 of file res_agi.c.

1441{
1442 return agi_channel_to_ami("AGIExecEnd", message);
1443}

References agi_channel_to_ami().

◆ agi_exec_full()

static int agi_exec_full ( struct ast_channel chan,
const char *  data,
int  enhanced,
int  dead 
)
static

Definition at line 4526 of file res_agi.c.

4527{
4528 enum agi_result res;
4529 char *buf;
4530 int fds[2], efd = -1, pid = -1;
4532 AST_APP_ARG(arg)[MAX_ARGS];
4533 );
4534 AGI agi;
4535
4536 if (ast_strlen_zero(data)) {
4537 ast_log(LOG_WARNING, "AGI requires an argument (script)\n");
4538 return -1;
4539 }
4540 if (dead)
4541 ast_debug(3, "Hungup channel detected, running agi in dead mode.\n");
4542 memset(&agi, 0, sizeof(agi));
4543 buf = ast_strdupa(data);
4545 args.arg[args.argc] = NULL;
4546#if 0
4547 /* Answer if need be */
4548 if (chan->_state != AST_STATE_UP) {
4549 if (ast_answer(chan))
4550 return -1;
4551 }
4552#endif
4553 res = launch_script(chan, args.arg[0], args.argc, args.arg, fds, enhanced ? &efd : NULL, &pid);
4554 /* Async AGI do not require run_agi(), so just proceed if normal AGI
4555 or Fast AGI are setup with success. */
4556 if (res == AGI_RESULT_SUCCESS || res == AGI_RESULT_SUCCESS_FAST) {
4557 int status = 0;
4558 agi.fd = fds[1];
4559 agi.ctrl = fds[0];
4560 agi.audio = efd;
4561 agi.fast = (res == AGI_RESULT_SUCCESS_FAST) ? 1 : 0;
4562 res = run_agi(chan, args.arg[0], &agi, pid, &status, dead, args.argc, args.arg);
4563 /* If the fork'd process returns non-zero, set AGISTATUS to FAILURE */
4564 if ((res == AGI_RESULT_SUCCESS || res == AGI_RESULT_SUCCESS_FAST) && status)
4565 res = AGI_RESULT_FAILURE;
4566 if (fds[1] != fds[0])
4567 close(fds[1]);
4568 if (efd > -1)
4569 close(efd);
4570 }
4572
4573 switch (res) {
4574 case AGI_RESULT_SUCCESS:
4577 pbx_builtin_setvar_helper(chan, "AGISTATUS", "SUCCESS");
4578 break;
4579 case AGI_RESULT_FAILURE:
4580 pbx_builtin_setvar_helper(chan, "AGISTATUS", "FAILURE");
4581 break;
4583 pbx_builtin_setvar_helper(chan, "AGISTATUS", "NOTFOUND");
4584 break;
4585 case AGI_RESULT_HANGUP:
4586 pbx_builtin_setvar_helper(chan, "AGISTATUS", "HANGUP");
4587 return -1;
4588 }
4589
4590 return 0;
4591}
jack_status_t status
Definition: app_jack.c:146
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2805
@ AST_STATE_UP
Definition: channelstate.h:42
#define AST_APP_ARG(name)
Define an application argument.
void ast_safe_fork_cleanup(void)
Common routine to cleanup after fork'ed process is complete (if reaping was stopped)
Definition: main/app.c:3258
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ast_debug(level,...)
Log a DEBUG message.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
#define MAX_ARGS
Definition: res_agi.c:1383
static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
Definition: res_agi.c:4144
static enum agi_result launch_script(struct ast_channel *chan, char *script, int argc, char *argv[], int *fds, int *efd, int *opid)
Definition: res_agi.c:2195
agi_result
Definition: res_agi.c:1407
Definition: agi.h:34
const char * args

References AGI_RESULT_FAILURE, AGI_RESULT_HANGUP, AGI_RESULT_NOTFOUND, AGI_RESULT_SUCCESS, AGI_RESULT_SUCCESS_ASYNC, AGI_RESULT_SUCCESS_FAST, args, ast_answer(), AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_log, ast_safe_fork_cleanup(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_strlen_zero(), buf, agi_command::dead, launch_script(), LOG_WARNING, MAX_ARGS, NULL, pbx_builtin_setvar_helper(), run_agi(), and status.

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

◆ agi_exec_start_to_ami()

static struct ast_manager_event_blob * agi_exec_start_to_ami ( struct stasis_message message)
static

Definition at line 1435 of file res_agi.c.

1436{
1437 return agi_channel_to_ami("AGIExecStart", message);
1438}

References agi_channel_to_ami().

◆ agi_handle_command()

static enum agi_result agi_handle_command ( struct ast_channel chan,
AGI agi,
char *  buf,
int  dead 
)
static

Definition at line 4053 of file res_agi.c.

4054{
4055 const char *argv[MAX_ARGS] = {0};
4056 int argc = MAX_ARGS;
4057 int res;
4058 agi_command *c;
4059 char *ami_cmd = ast_strdupa(buf);
4060 const char *ami_res;
4061 int command_id = ast_random();
4062 int resultcode = 0;
4063 RAII_VAR(struct ast_json *, startblob, NULL, ast_json_unref);
4064
4065 startblob = ast_json_pack("{s: i, s: s}",
4066 "CommandId", command_id,
4067 "Command", ami_cmd);
4068 ast_channel_publish_cached_blob(chan, agi_exec_start_type(), startblob);
4069
4070 parse_args(buf, &argc, argv);
4071 c = find_command(argv, 0);
4072 if (!c || !ast_module_running_ref(c->mod)) {
4073 ami_res = "Invalid or unknown command";
4074 resultcode = 510;
4075
4076 ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
4077
4078 publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
4079
4080 return AGI_RESULT_SUCCESS;
4081 }
4082
4083 if (!dead || (dead && c->dead)) {
4084 res = c->handler(chan, agi, argc, argv);
4085 switch (res) {
4086 case RESULT_SHOWUSAGE:
4087 ami_res = "Usage";
4088 resultcode = 520;
4089
4090 publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
4091
4092 if (ast_strlen_zero(c->usage)) {
4093 ast_agi_send(agi->fd, chan, "520 Invalid command syntax. Proper usage not available.\n");
4094 } else {
4095 ast_agi_send(agi->fd, chan, "520-Invalid command syntax. Proper usage follows:\n");
4096 ast_agi_send(agi->fd, chan, "%s\n", c->usage);
4097 ast_agi_send(agi->fd, chan, "520 End of proper usage.\n");
4098 }
4099
4100 break;
4101 case RESULT_FAILURE:
4102 ami_res = "Failure";
4103 resultcode = -1;
4104
4105 publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
4106
4107 /* The RESULT_FAILURE code is usually because the channel hungup. */
4108 return AGI_RESULT_FAILURE;
4109 case ASYNC_AGI_BREAK:
4110 ami_res = "Success";
4111 resultcode = 200;
4112
4113 publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
4114
4116 case RESULT_SUCCESS:
4117 ami_res = "Success";
4118 resultcode = 200;
4119
4120 publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
4121
4122 break;
4123 default:
4124 ami_res = "Unknown Result";
4125 resultcode = 200;
4126
4127 publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
4128
4129 break;
4130 }
4131 } else {
4132 ami_res = "Command Not Permitted on a dead channel or intercept routine";
4133 resultcode = 511;
4134
4135 ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
4136
4137 publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
4138 }
4139 ast_module_unref(c->mod);
4140
4141 return AGI_RESULT_SUCCESS;
4142}
#define RESULT_SHOWUSAGE
Definition: cli.h:41
#define RESULT_SUCCESS
Definition: cli.h:40
#define RESULT_FAILURE
Definition: cli.h:42
void ast_channel_publish_cached_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Publish a channel blob message using the latest snapshot from the cache.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
Definition: module.h:455
static int parse_args(char *s, int *max, const char *argv[])
Definition: res_agi.c:3979
static agi_command * find_command(const char *const cmds[], int exact)
Definition: res_agi.c:3941
#define ASYNC_AGI_BREAK
Definition: res_agi.c:1405
static void publish_async_exec_end(struct ast_channel *chan, int command_id, const char *command, int result_code, const char *result)
Definition: res_agi.c:4042
int AST_OPTIONAL_API_NAME() ast_agi_send(int fd, struct ast_channel *chan, char *fmt,...)
Sends a string of text to an application connected via AGI.
Definition: res_agi.c:1481
int fd
Definition: agi.h:35
Abstract JSON element (object, array, string, int, ...).
static struct test_val c
long int ast_random(void)
Definition: utils.c:2312

References AGI_RESULT_FAILURE, AGI_RESULT_SUCCESS, AGI_RESULT_SUCCESS_ASYNC, ast_agi_send(), ast_channel_publish_cached_blob(), ast_json_pack(), ast_json_unref(), ast_module_running_ref, ast_module_unref, ast_random(), ast_strdupa, ast_strlen_zero(), ASYNC_AGI_BREAK, buf, c, agi_command::dead, agi_state::fd, find_command(), MAX_ARGS, NULL, parse_args(), publish_async_exec_end(), RAII_VAR, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

Referenced by launch_asyncagi(), and run_agi().

◆ ast_agi_register()

int AST_OPTIONAL_API_NAME() ast_agi_register ( struct ast_module mod,
agi_command cmd 
)

Registers an AGI command.

Parameters
modPointer to the module_info structure for the module that is registering the command
cmdPointer to the descriptor for the command
Return values
1on success
0the command is already registered
AST_OPTIONAL_API_UNAVAILABLEthe module is not loaded.

Definition at line 3815 of file res_agi.c.

3816{
3817 char fullcmd[MAX_CMD_LEN];
3818
3819 ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
3820
3821 if (!find_command(cmd->cmda, 1)) {
3822 *((enum ast_doc_src *) &cmd->docsrc) = AST_STATIC_DOC;
3823 if (ast_strlen_zero(cmd->summary) && ast_strlen_zero(cmd->usage)) {
3824#ifdef AST_XML_DOCS
3825 *((char **) &cmd->summary) = ast_xmldoc_build_synopsis("agi", fullcmd, NULL);
3826 *((char **) &cmd->usage) = ast_xmldoc_build_description("agi", fullcmd, NULL);
3827 *((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd, NULL);
3828 *((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd, NULL);
3829 *((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC;
3830#endif
3831#ifndef HAVE_NULLSAFE_PRINTF
3832 if (!cmd->summary) {
3833 *((char **) &cmd->summary) = ast_strdup("");
3834 }
3835 if (!cmd->usage) {
3836 *((char **) &cmd->usage) = ast_strdup("");
3837 }
3838 if (!cmd->syntax) {
3839 *((char **) &cmd->syntax) = ast_strdup("");
3840 }
3841 if (!cmd->seealso) {
3842 *((char **) &cmd->seealso) = ast_strdup("");
3843 }
3844#endif
3845 }
3846
3847 cmd->mod = mod;
3851 ast_verb(5, "AGI Command '%s' registered\n",fullcmd);
3852 return 1;
3853 } else {
3854 ast_log(LOG_WARNING, "Command already registered!\n");
3855 return 0;
3856 }
3857}
#define ast_verb(level,...)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define MAX_CMD_LEN
Definition: res_agi.c:1384
#define ast_join(s, len, w)
Join an array of strings into a single string.
Definition: strings.h:520
const char *const summary
Definition: agi.h:48
struct ast_module * mod
Definition: agi.h:60
enum ast_doc_src docsrc
Definition: agi.h:58
const char *const usage
Definition: agi.h:50
const char *const seealso
Definition: agi.h:56
const char *const syntax
Definition: agi.h:54
const char *const cmda[AST_MAX_CMD_LEN]
Definition: agi.h:43
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
Definition: xmldoc.c:2271
char * ast_xmldoc_build_syntax(const char *type, const char *name, const char *module)
Get the syntax for a specified application or function.
Definition: xmldoc.c:1252
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
Definition: xmldoc.c:2248
ast_doc_src
From where the documentation come from, this structure is useful for use it inside application/functi...
Definition: xmldoc.h:30
@ AST_XML_DOC
Definition: xmldoc.h:31
@ AST_STATIC_DOC
Definition: xmldoc.h:32
char * ast_xmldoc_build_seealso(const char *type, const char *name, const char *module)
Parse the <see-also> node content.
Definition: xmldoc.c:1702

References ast_join, AST_LIST_INSERT_TAIL, ast_log, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STATIC_DOC, ast_strdup, ast_strlen_zero(), ast_verb, AST_XML_DOC, ast_xmldoc_build_description(), ast_xmldoc_build_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), find_command(), LOG_WARNING, MAX_CMD_LEN, and NULL.

Referenced by ast_agi_register_multiple(), AST_TEST_DEFINE(), and load_module().

◆ ast_agi_register_multiple()

int AST_OPTIONAL_API_NAME() ast_agi_register_multiple ( struct ast_module mod,
struct agi_command cmd,
unsigned int  len 
)

Registers a group of AGI commands, provided as an array of struct agi_command entries.

Parameters
modPointer to the module_info structure for the module that is registering the commands
cmdPointer to the first entry in the array of command descriptors
lenLength of the array (use the ARRAY_LEN macro to determine this easily)
Returns
0 on success, -1 on failure, AST_OPTIONAL_API_UNAVAILABLE if res_agi is not loaded
Note
If any command fails to register, all commands previously registered during the operation will be unregistered. In other words, this function registers all the provided commands, or none of them.

Definition at line 3895 of file res_agi.c.

3896{
3897 unsigned int i, x = 0;
3898
3899 for (i = 0; i < len; i++) {
3900 if (ast_agi_register(mod, cmd + i) == 1) {
3901 x++;
3902 continue;
3903 }
3904
3905 /* registration failed, unregister everything
3906 that had been registered up to that point
3907 */
3908 for (; x > 0; x--) {
3909 /* we are intentionally ignoring the
3910 result of ast_agi_unregister() here,
3911 but it should be safe to do so since
3912 we just registered these commands and
3913 the only possible way for unregistration
3914 to fail is if the command is not
3915 registered
3916 */
3917 (void) ast_agi_unregister(cmd + x - 1);
3918 }
3919 return -1;
3920 }
3921
3922 return 0;
3923}
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int AST_OPTIONAL_API_NAME() ast_agi_unregister(agi_command *cmd)
Unregisters an AGI command.
Definition: res_agi.c:3859
int AST_OPTIONAL_API_NAME() ast_agi_register(struct ast_module *mod, agi_command *cmd)
Registers an AGI command.
Definition: res_agi.c:3815

References ast_agi_register(), ast_agi_unregister(), len(), and agi_command::mod.

Referenced by load_module().

◆ ast_agi_send()

int AST_OPTIONAL_API_NAME() ast_agi_send ( int  fd,
struct ast_channel chan,
char *  fmt,
  ... 
)

Sends a string of text to an application connected via AGI.

Parameters
fdThe file descriptor for the AGI session (from struct agi_state)
chanPointer to an associated Asterisk channel, if any
fmtprintf-style format string
Returns
0 for success, -1 for failure, AST_OPTIONAL_API_UNAVAILABLE if res_agi is not loaded

Definition at line 1481 of file res_agi.c.

1482{
1483 int res = 0;
1484 va_list ap;
1485 struct ast_str *buf;
1486
1488 return -1;
1489
1490 va_start(ap, fmt);
1491 res = ast_str_set_va(&buf, 0, fmt, ap);
1492 va_end(ap);
1493
1494 if (res == -1) {
1495 ast_log(LOG_ERROR, "Out of memory\n");
1496 return -1;
1497 }
1498
1499 if (agidebug) {
1500 if (chan) {
1501 ast_verbose("<%s>AGI Tx >> %s", ast_channel_name(chan), ast_str_buffer(buf));
1502 } else {
1503 ast_verbose("AGI Tx >> %s", ast_str_buffer(buf));
1504 }
1505 }
1506
1508}
void ast_verbose(const char *fmt,...)
Definition: extconf.c:2206
static struct ast_threadstorage agi_buf
Definition: res_agi.c:1478
static int agidebug
Definition: res_agi.c:1395
#define AGI_BUF_INITSIZE
Definition: res_agi.c:1479
int ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Set a dynamic string from a va_list.
Definition: strings.h:1030
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:730
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:909
int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
Try to write string, but wait no more than ms milliseconds before timing out.
Definition: utils.c:1771

References agi_buf, AGI_BUF_INITSIZE, agidebug, ast_carefulwrite(), ast_channel_name(), ast_log, ast_str_buffer(), ast_str_set_va(), ast_str_strlen(), ast_str_thread_get(), ast_verbose(), buf, and LOG_ERROR.

Referenced by agi_handle_command(), handle_answer(), handle_asyncagi_break(), 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_gosub(), 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_speechactivategrammar(), handle_speechcreate(), handle_speechdeactivategrammar(), handle_speechdestroy(), handle_speechloadgrammar(), handle_speechrecognize(), handle_speechset(), handle_speechunloadgrammar(), handle_streamfile(), handle_tddmode(), handle_verbose(), handle_waitfordigit(), launch_netscript(), run_agi(), and setup_env().

◆ ast_agi_unregister()

int AST_OPTIONAL_API_NAME() ast_agi_unregister ( agi_command cmd)

Unregisters an AGI command.

Parameters
cmdPointer to the descriptor for the command
Returns
1 on success, 0 if the command was not already registered

Definition at line 3859 of file res_agi.c.

3860{
3861 struct agi_command *e;
3862 int unregistered = 0;
3863 char fullcmd[MAX_CMD_LEN];
3864
3865 ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
3866
3869 if (cmd == e) {
3871#ifdef AST_XML_DOCS
3872 if (e->docsrc == AST_XML_DOC) {
3873 ast_free((char *) e->summary);
3874 ast_free((char *) e->usage);
3875 ast_free((char *) e->syntax);
3876 ast_free((char *) e->seealso);
3877 *((char **) &e->summary) = NULL;
3878 *((char **) &e->usage) = NULL;
3879 *((char **) &e->syntax) = NULL;
3880 *((char **) &e->seealso) = NULL;
3881 }
3882#endif
3883 unregistered=1;
3884 break;
3885 }
3886 }
3889 if (unregistered) {
3890 ast_verb(5, "AGI Command '%s' unregistered\n",fullcmd);
3891 }
3892 return unregistered;
3893}
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617
struct agi_command::@181 list

References ast_free, ast_join, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, AST_XML_DOC, agi_command::docsrc, agi_command::list, MAX_CMD_LEN, NULL, agi_command::seealso, agi_command::summary, agi_command::syntax, and agi_command::usage.

Referenced by ast_agi_register_multiple(), ast_agi_unregister_multiple(), AST_TEST_DEFINE(), and unload_module().

◆ ast_agi_unregister_multiple()

int AST_OPTIONAL_API_NAME() ast_agi_unregister_multiple ( struct agi_command cmd,
unsigned int  len 
)

Unregisters a group of AGI commands, provided as an array of struct agi_command entries.

Parameters
cmdPointer to the first entry in the array of command descriptors
lenLength of the array (use the ARRAY_LEN macro to determine this easily)
Returns
0 on success, -1 on failure, AST_OPTIONAL_API_UNAVAILABLE if res_agi is not loaded
Note
If any command fails to unregister, this function will continue to unregister the remaining commands in the array; it will not reregister the already-unregistered commands.

Definition at line 3925 of file res_agi.c.

3926{
3927 unsigned int i;
3928 int res = 0;
3929
3930 for (i = 0; i < len; i++) {
3931 /* remember whether any of the unregistration
3932 attempts failed... there is no recourse if
3933 any of them do
3934 */
3935 res |= ast_agi_unregister(cmd + i);
3936 }
3937
3938 return res;
3939}

References ast_agi_unregister(), and len().

Referenced by unload_module().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 4747 of file res_agi.c.

◆ async_agi_read_frame()

static enum agi_result async_agi_read_frame ( struct ast_channel chan)
static

Definition at line 1754 of file res_agi.c.

1755{
1756 struct ast_frame *f;
1757
1758 f = ast_read(chan);
1759 if (!f) {
1760 ast_debug(3, "No frame read on channel %s, going out ...\n", ast_channel_name(chan));
1761 return AGI_RESULT_HANGUP;
1762 }
1763 if (f->frametype == AST_FRAME_CONTROL) {
1764 /*
1765 * Is there any other frame we should care about besides
1766 * AST_CONTROL_HANGUP?
1767 */
1768 switch (f->subclass.integer) {
1769 case AST_CONTROL_HANGUP:
1770 ast_debug(3, "Got HANGUP frame on channel %s, going out ...\n", ast_channel_name(chan));
1771 ast_frfree(f);
1772 return AGI_RESULT_HANGUP;
1773 default:
1774 break;
1775 }
1776 }
1777 ast_frfree(f);
1778
1779 return AGI_RESULT_SUCCESS;
1780}
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4257
#define ast_frfree(fr)
@ AST_FRAME_CONTROL
@ AST_CONTROL_HANGUP
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype

References AGI_RESULT_HANGUP, AGI_RESULT_SUCCESS, ast_channel_name(), AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CONTROL, ast_frfree, ast_read(), ast_frame::frametype, ast_frame_subclass::integer, and ast_frame::subclass.

Referenced by launch_asyncagi().

◆ deadagi_exec()

static int deadagi_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 4643 of file res_agi.c.

4644{
4645 ast_log(LOG_WARNING, "DeadAGI has been deprecated, please use AGI in all cases!\n");
4646 return agi_exec(chan, data);
4647}
static int agi_exec(struct ast_channel *chan, const char *data)
Definition: res_agi.c:4593

References agi_exec(), ast_log, and LOG_WARNING.

Referenced by load_module().

◆ eagi_exec()

static int eagi_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 4601 of file res_agi.c.

4602{
4603 int res;
4604 struct ast_format *readformat;
4605 struct ast_format *requested_format = NULL;
4606 const char *requested_format_name;
4607
4608 if (ast_check_hangup(chan)) {
4609 ast_log(LOG_ERROR, "EAGI cannot be run on a dead/hungup channel, please use AGI.\n");
4610 return 0;
4611 }
4612
4613 requested_format_name = pbx_builtin_getvar_helper(chan, "EAGI_AUDIO_FORMAT");
4614 if (requested_format_name) {
4615 requested_format = ast_format_cache_get(requested_format_name);
4616 if (requested_format) {
4617 ast_verb(3, "<%s> Setting EAGI audio pipe format to %s\n",
4618 ast_channel_name(chan), ast_format_get_name(requested_format));
4619 } else {
4620 ast_log(LOG_ERROR, "Could not find requested format: %s\n", requested_format_name);
4621 }
4622 }
4623
4624 readformat = ao2_bump(ast_channel_readformat(chan));
4625 if (ast_set_read_format(chan, requested_format ?: ast_format_slin)) {
4626 ast_log(LOG_WARNING, "Unable to set channel '%s' to linear mode\n", ast_channel_name(chan));
4627 ao2_cleanup(requested_format);
4628 ao2_cleanup(readformat);
4629 return -1;
4630 }
4631 res = agi_exec_full(chan, data, 1, 0);
4632 if (!res) {
4633 if (ast_set_read_format(chan, readformat)) {
4634 ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", ast_channel_name(chan),
4635 ast_format_get_name(readformat));
4636 }
4637 }
4638 ao2_cleanup(requested_format);
4639 ao2_cleanup(readformat);
4640 return res;
4641}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition: channel.c:5762
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define ast_format_cache_get(name)
Retrieve a named format from the cache.
Definition: format_cache.h:278
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
Definition of a media format.
Definition: format.c:43

References agi_exec_full(), ao2_bump, ao2_cleanup, ast_channel_name(), ast_channel_readformat(), ast_check_hangup(), ast_format_cache_get, ast_format_get_name(), ast_format_slin, ast_log, ast_set_read_format(), ast_verb, LOG_ERROR, LOG_WARNING, NULL, and pbx_builtin_getvar_helper().

Referenced by load_module().

◆ find_command()

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

Definition at line 3941 of file res_agi.c.

3942{
3943 int y, match;
3944 struct agi_command *e;
3945
3948 if (!e->cmda[0])
3949 break;
3950 /* start optimistic */
3951 match = 1;
3952 for (y = 0; match && cmds[y]; y++) {
3953 /* If there are no more words in the command (and we're looking for
3954 an exact match) or there is a difference between the two words,
3955 then this is not a match */
3956 if (!e->cmda[y] && !exact)
3957 break;
3958 /* don't segfault if the next part of a command doesn't exist */
3959 if (!e->cmda[y]) {
3961 return NULL;
3962 }
3963 if (strcasecmp(e->cmda[y], cmds[y]))
3964 match = 0;
3965 }
3966 /* If more words are needed to complete the command then this is not
3967 a candidate (unless we're looking for a really inexact answer */
3968 if ((exact > -1) && e->cmda[y])
3969 match = 0;
3970 if (match) {
3972 return e;
3973 }
3974 }
3976 return NULL;
3977}
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2362
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, agi_command::cmda, agi_command::list, match(), and NULL.

Referenced by agi_handle_command(), ast_agi_register(), and handle_cli_agi_show().

◆ free_agi_cmd()

static void free_agi_cmd ( struct agi_cmd cmd)
static

Definition at line 1517 of file res_agi.c.

1518{
1519 ast_free(cmd->cmd_buffer);
1520 ast_free(cmd->cmd_id);
1521 ast_free(cmd);
1522}

References ast_free, agi_cmd::cmd_buffer, and agi_cmd::cmd_id.

Referenced by agi_destroy_commands_cb(), and launch_asyncagi().

◆ get_agi_cmd()

static int get_agi_cmd ( struct ast_channel chan,
struct agi_cmd **  cmd 
)
static

Retrieve the list head to the requested channel's AGI datastore.

Parameters
chanChannel datastore is requested for
cmdPointer to the struct pointer which will reference the head of the agi command list.
Return values
0if the datastore was valid and the list head was retrieved appropriately (even if it's NULL and the list is empty)
-1if the datastore could not be retrieved causing an error

Definition at line 1553 of file res_agi.c.

1554{
1555 struct ast_datastore *store;
1557
1558 ast_channel_lock(chan);
1560 ast_channel_unlock(chan);
1561 if (!store) {
1562 ast_log(LOG_ERROR, "Huh? Async AGI datastore disappeared on Channel %s!\n",
1563 ast_channel_name(chan));
1564 *cmd = NULL;
1565 return -1;
1566 }
1567 agi_commands = store->data;
1571 return 0;
1572}

References agi_commands, agi_commands_datastore_info, ast_channel_datastore_find(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, AST_LIST_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log, ast_datastore::data, LOG_ERROR, and NULL.

Referenced by launch_asyncagi().

◆ handle_answer()

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

Definition at line 2359 of file res_agi.c.

2360{
2361 int res = 0;
2362
2363 /* Answer the channel */
2364 if (ast_channel_state(chan) != AST_STATE_UP)
2365 res = ast_answer(chan);
2366
2367 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2368 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2369}
ast_channel_state
ast_channel states
Definition: channelstate.h:35

References ast_agi_send(), ast_answer(), AST_STATE_UP, agi_state::fd, RESULT_FAILURE, and RESULT_SUCCESS.

◆ handle_asyncagi_break()

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

Definition at line 2371 of file res_agi.c.

2372{
2373 ast_agi_send(agi->fd, chan, "200 result=0\n");
2374 return ASYNC_AGI_BREAK;
2375}

References ast_agi_send(), ASYNC_AGI_BREAK, and agi_state::fd.

◆ handle_autohangup()

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

Definition at line 3094 of file res_agi.c.

3095{
3096 double timeout;
3097 struct timeval whentohangup = { 0, 0 };
3098
3099 if (argc != 3)
3100 return RESULT_SHOWUSAGE;
3101 if (sscanf(argv[2], "%30lf", &timeout) != 1)
3102 return RESULT_SHOWUSAGE;
3103 if (timeout < 0)
3104 timeout = 0;
3105 if (timeout) {
3106 whentohangup.tv_sec = timeout;
3107 whentohangup.tv_usec = (timeout - whentohangup.tv_sec) * 1000000.0;
3108 }
3109 ast_channel_lock(chan);
3110 ast_channel_setwhentohangup_tv(chan, whentohangup);
3111 ast_channel_unlock(chan);
3112 ast_agi_send(agi->fd, chan, "200 result=0\n");
3113 return RESULT_SUCCESS;
3114}
void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
Set when to hang a channel up.
Definition: channel.c:510

References ast_agi_send(), ast_channel_lock, ast_channel_setwhentohangup_tv(), ast_channel_unlock, agi_state::fd, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_channelstatus()

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

Definition at line 3211 of file res_agi.c.

3212{
3213 if (argc == 2) {
3214 /* no argument: supply info on the current channel */
3215 ast_agi_send(agi->fd, chan, "200 result=%u\n", ast_channel_state(chan));
3216 return RESULT_SUCCESS;
3217 } else if (argc == 3) {
3218 struct ast_channel_snapshot *snapshot;
3219
3220 /* one argument: look for info on the specified channel */
3221 snapshot = ast_channel_snapshot_get_latest_by_name(argv[2]);
3222 if (snapshot) {
3223 ast_agi_send(agi->fd, chan, "200 result=%u\n", snapshot->state);
3224 ao2_ref(snapshot, -1);
3225 return RESULT_SUCCESS;
3226 }
3227 /* if we get this far no channel name matched the argument given */
3228 ast_agi_send(agi->fd, chan, "200 result=-1\n");
3229 return RESULT_SUCCESS;
3230 } else {
3231 return RESULT_SHOWUSAGE;
3232 }
3233}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_channel_snapshot * ast_channel_snapshot_get_latest_by_name(const char *name)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...
Structure representing a snapshot of channel state.
enum ast_channel_state state

References ao2_ref, ast_agi_send(), ast_channel_snapshot_get_latest_by_name(), agi_state::fd, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_channel_snapshot::state.

◆ handle_cli_agi_add_cmd()

static char * handle_cli_agi_add_cmd ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

CLI command to add applications to execute in Async AGI.

Parameters
e
cmd
a
Return values
CLI_SUCCESSon success
NULLwhen init or tab completion is used

Definition at line 1652 of file res_agi.c.

1653{
1654 struct ast_channel *chan;
1655 switch (cmd) {
1656 case CLI_INIT:
1657 e->command = "agi exec";
1658 e->usage = "Usage: agi exec <channel name> <app and arguments> [id]\n"
1659 " Add AGI command to the execute queue of the specified channel in Async AGI\n";
1660 return NULL;
1661 case CLI_GENERATE:
1662 if (a->pos == 2)
1663 return ast_complete_channels(a->line, a->word, a->pos, a->n, 2);
1664 return NULL;
1665 }
1666
1667 if (a->argc < 4) {
1668 return CLI_SHOWUSAGE;
1669 }
1670
1671 if (!(chan = ast_channel_get_by_name(a->argv[2]))) {
1672 ast_cli(a->fd, "Channel %s does not exist.\n", a->argv[2]);
1673 return CLI_FAILURE;
1674 }
1675
1676 ast_channel_lock(chan);
1677
1678 if (add_agi_cmd(chan, a->argv[3], (a->argc > 4 ? a->argv[4] : ""))) {
1679 ast_cli(a->fd, "Failed to add AGI command to queue of channel %s\n", ast_channel_name(chan));
1680 ast_channel_unlock(chan);
1681 chan = ast_channel_unref(chan);
1682 return CLI_FAILURE;
1683 }
1684
1685 ast_debug(1, "Added AGI command to channel %s queue\n", ast_channel_name(chan));
1686
1687 ast_channel_unlock(chan);
1688 chan = ast_channel_unref(chan);
1689
1690 return CLI_SUCCESS;
1691}
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_SUCCESS
Definition: cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
char * ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos)
Command completion for the list of active channels.
Definition: main/cli.c:1860
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#define CLI_FAILURE
Definition: cli.h:46
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
static struct test_val a

References a, add_agi_cmd(), ast_channel_get_by_name(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_channel_unref, ast_cli(), ast_complete_channels(), ast_debug, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.

◆ handle_cli_agi_debug()

static char * handle_cli_agi_debug ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 3394 of file res_agi.c.

3395{
3396 switch (cmd) {
3397 case CLI_INIT:
3398 e->command = "agi set debug [on|off]";
3399 e->usage =
3400 "Usage: agi set debug [on|off]\n"
3401 " Enables/disables dumping of AGI transactions for\n"
3402 " debugging purposes.\n";
3403 return NULL;
3404
3405 case CLI_GENERATE:
3406 return NULL;
3407 }
3408
3409 if (a->argc != e->args)
3410 return CLI_SHOWUSAGE;
3411
3412 if (strncasecmp(a->argv[3], "off", 3) == 0) {
3413 agidebug = 0;
3414 } else if (strncasecmp(a->argv[3], "on", 2) == 0) {
3415 agidebug = 1;
3416 } else {
3417 return CLI_SHOWUSAGE;
3418 }
3419 ast_cli(a->fd, "AGI Debugging %sabled\n", agidebug ? "En" : "Dis");
3420 return CLI_SUCCESS;
3421}
int args
This gets set in ast_cli_register()
Definition: cli.h:185

References a, agidebug, ast_cli_entry::args, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.

◆ handle_cli_agi_dump_html()

static char * handle_cli_agi_dump_html ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 4502 of file res_agi.c.

4503{
4504 switch (cmd) {
4505 case CLI_INIT:
4506 e->command = "agi dump html";
4507 e->usage =
4508 "Usage: agi dump html <filename>\n"
4509 " Dumps the AGI command list in HTML format to the given\n"
4510 " file.\n";
4511 return NULL;
4512 case CLI_GENERATE:
4513 return NULL;
4514 }
4515 if (a->argc != e->args + 1)
4516 return CLI_SHOWUSAGE;
4517
4518 if (write_htmldump(a->argv[e->args]) < 0) {
4519 ast_cli(a->fd, "Could not create file '%s'\n", a->argv[e->args]);
4520 return CLI_SHOWUSAGE;
4521 }
4522 ast_cli(a->fd, "AGI HTML commands dumped to: %s\n", a->argv[e->args]);
4523 return CLI_SUCCESS;
4524}
static int write_htmldump(const char *filename)
Definition: res_agi.c:4450

References a, ast_cli_entry::args, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, ast_cli_entry::usage, and write_htmldump().

◆ handle_cli_agi_show()

static char * handle_cli_agi_show ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 4316 of file res_agi.c.

4317{
4318 struct agi_command *command;
4319 char fullcmd[MAX_CMD_LEN];
4320 int error = 0;
4321
4322 switch (cmd) {
4323 case CLI_INIT:
4324 e->command = "agi show commands [topic]";
4325 e->usage =
4326 "Usage: agi show commands [topic] <topic>\n"
4327 " When called with a topic as an argument, displays usage\n"
4328 " information on the given command. If called without a\n"
4329 " topic, it provides a list of AGI commands.\n";
4330 case CLI_GENERATE:
4331 return NULL;
4332 }
4333 if (a->argc < e->args - 1 || (a->argc >= e->args && strcasecmp(a->argv[e->args - 1], "topic")))
4334 return CLI_SHOWUSAGE;
4335 if (a->argc > e->args - 1) {
4336 command = find_command(a->argv + e->args, 1);
4337 if (command) {
4338 char *synopsis = NULL, *description = NULL, *syntax = NULL, *seealso = NULL;
4339 char info[30 + MAX_CMD_LEN]; /* '-= Info about...' */
4340 char infotitle[30 + MAX_CMD_LEN + AST_TERM_MAX_ESCAPE_CHARS]; /* '-= Info about...' with colors */
4341 char syntitle[11 + AST_TERM_MAX_ESCAPE_CHARS]; /* [Syntax]\n with colors */
4342 char desctitle[15 + AST_TERM_MAX_ESCAPE_CHARS]; /* [Description]\n with colors */
4343 char deadtitle[13 + AST_TERM_MAX_ESCAPE_CHARS]; /* [Runs Dead]\n with colors */
4344 char deadcontent[3 + AST_TERM_MAX_ESCAPE_CHARS]; /* 'Yes' or 'No' with colors */
4345 char seealsotitle[12 + AST_TERM_MAX_ESCAPE_CHARS]; /* [See Also]\n with colors */
4346 char stxtitle[10 + AST_TERM_MAX_ESCAPE_CHARS]; /* [Syntax]\n with colors */
4347 size_t synlen, desclen, seealsolen, stxlen;
4348
4349 term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, sizeof(syntitle));
4350 term_color(desctitle, "[Description]\n", COLOR_MAGENTA, 0, sizeof(desctitle));
4351 term_color(deadtitle, "[Runs Dead]\n", COLOR_MAGENTA, 0, sizeof(deadtitle));
4352 term_color(seealsotitle, "[See Also]\n", COLOR_MAGENTA, 0, sizeof(seealsotitle));
4353 term_color(stxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, sizeof(stxtitle));
4354 term_color(deadcontent, command->dead ? "Yes" : "No", COLOR_CYAN, 0, sizeof(deadcontent));
4355
4356 ast_join(fullcmd, sizeof(fullcmd), a->argv + e->args);
4357 snprintf(info, sizeof(info), "\n -= Info about agi '%s' =- ", fullcmd);
4358 term_color(infotitle, info, COLOR_CYAN, 0, sizeof(infotitle));
4359#ifdef AST_XML_DOCS
4360 if (command->docsrc == AST_XML_DOC) {
4361 synopsis = ast_xmldoc_printable(S_OR(command->summary, "Not available"), 1);
4362 description = ast_xmldoc_printable(S_OR(command->usage, "Not available"), 1);
4363 seealso = ast_xmldoc_printable(S_OR(command->seealso, "Not available"), 1);
4364 if (!seealso || !description || !synopsis) {
4365 error = 1;
4366 goto return_cleanup;
4367 }
4368 } else
4369#endif
4370 {
4371 synlen = strlen(S_OR(command->summary, "Not available")) + AST_TERM_MAX_ESCAPE_CHARS;
4372 synopsis = ast_malloc(synlen);
4373
4374 desclen = strlen(S_OR(command->usage, "Not available")) + AST_TERM_MAX_ESCAPE_CHARS;
4375 description = ast_malloc(desclen);
4376
4377 seealsolen = strlen(S_OR(command->seealso, "Not available")) + AST_TERM_MAX_ESCAPE_CHARS;
4378 seealso = ast_malloc(seealsolen);
4379
4380 if (!synopsis || !description || !seealso) {
4381 error = 1;
4382 goto return_cleanup;
4383 }
4384 term_color(synopsis, S_OR(command->summary, "Not available"), COLOR_CYAN, 0, synlen);
4385 term_color(description, S_OR(command->usage, "Not available"), COLOR_CYAN, 0, desclen);
4386 term_color(seealso, S_OR(command->seealso, "Not available"), COLOR_CYAN, 0, seealsolen);
4387 }
4388
4389 stxlen = strlen(S_OR(command->syntax, "Not available")) + AST_TERM_MAX_ESCAPE_CHARS;
4390 syntax = ast_malloc(stxlen);
4391 if (!syntax) {
4392 error = 1;
4393 goto return_cleanup;
4394 }
4395 term_color(syntax, S_OR(command->syntax, "Not available"), COLOR_CYAN, 0, stxlen);
4396
4397 ast_cli(a->fd, "%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n", infotitle, stxtitle, syntax,
4398 desctitle, description, syntitle, synopsis, deadtitle, deadcontent,
4399 seealsotitle, seealso);
4400return_cleanup:
4402 ast_free(description);
4405 } else {
4406 if (find_command(a->argv + e->args, -1)) {
4407 return help_workhorse(a->fd, a->argv + e->args);
4408 } else {
4409 ast_join(fullcmd, sizeof(fullcmd), a->argv + e->args);
4410 ast_cli(a->fd, "No such command '%s'.\n", fullcmd);
4411 }
4412 }
4413 } else {
4414 return help_workhorse(a->fd, NULL);
4415 }
4416 return (error ? CLI_FAILURE : CLI_SUCCESS);
4417}
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
static char * synopsis
Definition: func_enum.c:154
def info(msg)
static char * help_workhorse(int fd, const char *const match[])
Definition: res_agi.c:3789
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
const int dead
Definition: agi.h:52
#define COLOR_CYAN
Definition: term.h:62
#define COLOR_MAGENTA
Definition: term.h:60
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
Definition: term.c:235
#define AST_TERM_MAX_ESCAPE_CHARS
Maximum number of characters needed for a color escape sequence, and another one for a trailing reset...
Definition: term.h:75
int error(const char *format,...)
Definition: utils/frame.c:999
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
Definition: xmldoc.c:241

References a, ast_cli_entry::args, ast_cli(), ast_free, ast_join, ast_malloc, AST_TERM_MAX_ESCAPE_CHARS, AST_XML_DOC, ast_xmldoc_printable(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, COLOR_CYAN, COLOR_MAGENTA, ast_cli_entry::command, agi_command::dead, agi_command::docsrc, error(), find_command(), help_workhorse(), sip_to_pjsip::info(), MAX_CMD_LEN, NULL, S_OR, agi_command::seealso, agi_command::summary, synopsis, agi_command::syntax, term_color(), agi_command::usage, and ast_cli_entry::usage.

◆ handle_connection()

static int handle_connection ( const char *  agiurl,
const struct ast_sockaddr  addr,
const int  netsockfd 
)
static

Definition at line 2007 of file res_agi.c.

2008{
2009 struct pollfd pfds[1];
2010 int res, conresult;
2011 socklen_t reslen;
2012
2013 reslen = sizeof(conresult);
2014
2015 pfds[0].fd = netsockfd;
2016 pfds[0].events = POLLOUT;
2017
2018 while ((res = ast_poll(pfds, 1, MAX_AGI_CONNECT)) != 1) {
2019 if (errno != EINTR) {
2020 if (!res) {
2021 ast_log(LOG_WARNING, "FastAGI connection to '%s' timed out after MAX_AGI_CONNECT (%d) milliseconds.\n",
2022 agiurl, MAX_AGI_CONNECT);
2023 } else {
2024 ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
2025 }
2026
2027 return 1;
2028 }
2029 }
2030
2031 if (getsockopt(pfds[0].fd, SOL_SOCKET, SO_ERROR, &conresult, &reslen) < 0) {
2032 ast_log(LOG_WARNING, "Connection to %s failed with error: %s\n",
2033 ast_sockaddr_stringify(&addr), strerror(errno));
2034 return 1;
2035 }
2036
2037 if (conresult) {
2038 ast_log(LOG_WARNING, "Connecting to '%s' failed for url '%s': %s\n",
2039 ast_sockaddr_stringify(&addr), agiurl, strerror(conresult));
2040 return 1;
2041 }
2042
2043 return 0;
2044}
int errno
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:256
#define ast_poll(a, b, c)
Definition: poll-compat.h:88
#define MAX_AGI_CONNECT
Definition: res_agi.c:1400

References ast_log, ast_poll, ast_sockaddr_stringify(), errno, LOG_WARNING, and MAX_AGI_CONNECT.

Referenced by launch_netscript().

◆ handle_controlstreamfile()

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

Definition at line 2490 of file res_agi.c.

2491{
2492 int res = 0, skipms = 3000;
2493 const char *fwd = "#", *rev = "*", *suspend = NULL, *stop = NULL; /* Default values */
2494 char stopkeybuf[2];
2495 long offsetms = 0;
2496 char offsetbuf[20];
2497
2498 if (argc < 5 || argc > 10) {
2499 return RESULT_SHOWUSAGE;
2500 }
2501
2502 if (!ast_strlen_zero(argv[4])) {
2503 stop = argv[4];
2504 }
2505
2506 if ((argc > 5) && (sscanf(argv[5], "%30d", &skipms) != 1)) {
2507 return RESULT_SHOWUSAGE;
2508 }
2509
2510 if (argc > 6 && !ast_strlen_zero(argv[6])) {
2511 fwd = argv[6];
2512 }
2513
2514 if (argc > 7 && !ast_strlen_zero(argv[7])) {
2515 rev = argv[7];
2516 }
2517
2518 if (argc > 8 && !ast_strlen_zero(argv[8])) {
2519 suspend = argv[8];
2520 }
2521
2522 if (argc > 9 && (sscanf(argv[9], "%30ld", &offsetms) != 1)) {
2523 return RESULT_SHOWUSAGE;
2524 }
2525
2526 res = ast_control_streamfile(chan, argv[3], fwd, rev, stop, suspend, NULL, skipms, &offsetms);
2527
2528 /* If we stopped on one of our stop keys, return 0 */
2529 if (res > 0 && stop && strchr(stop, res)) {
2530 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
2531 snprintf(stopkeybuf, sizeof(stopkeybuf), "%c", res);
2532 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTOPKEY", stopkeybuf);
2533 } else if (res > 0 && res == AST_CONTROL_STREAM_STOP) {
2534 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "REMOTESTOPPED");
2535 res = 0;
2536 } else {
2537 if (res < 0) {
2538 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
2539 } else {
2540 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
2541 }
2542 }
2543
2544 snprintf(offsetbuf, sizeof(offsetbuf), "%ld", offsetms);
2545 pbx_builtin_setvar_helper(chan, "CPLAYBACKOFFSET", offsetbuf);
2546
2547 ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, offsetms);
2548
2549 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2550}
unsigned int stop
Definition: app_sla.c:336
static int skipms
static void suspend(struct cc_core_instance *core_instance)
Definition: ccss.c:3160
int ast_control_streamfile(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *pause, const char *restart, int skipms, long *offsetms)
Stream a file with fast forward, pause, reverse, restart.
Definition: main/app.c:1465
@ AST_CONTROL_STREAM_STOP

References ast_agi_send(), AST_CONTROL_STREAM_STOP, ast_control_streamfile(), ast_strlen_zero(), agi_state::fd, NULL, pbx_builtin_setvar_helper(), RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, skipms, stop, and suspend().

◆ handle_dbdel()

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

Definition at line 3366 of file res_agi.c.

3367{
3368 int res;
3369
3370 if (argc != 4)
3371 return RESULT_SHOWUSAGE;
3372 res = ast_db_del(argv[2], argv[3]);
3373 ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
3374 return RESULT_SUCCESS;
3375}
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition: main/db.c:476

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

◆ handle_dbdeltree()

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

Definition at line 3377 of file res_agi.c.

3378{
3379 int num_deleted;
3380
3381 if ((argc < 3) || (argc > 4)) {
3382 return RESULT_SHOWUSAGE;
3383 }
3384 if (argc == 4) {
3385 num_deleted = ast_db_deltree(argv[2], argv[3]);
3386 } else {
3387 num_deleted = ast_db_deltree(argv[2], NULL);
3388 }
3389
3390 ast_agi_send(agi->fd, chan, "200 result=%c\n", num_deleted > 0 ? '0' : '1');
3391 return RESULT_SUCCESS;
3392}
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Definition: main/db.c:536

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

◆ handle_dbget()

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

Definition at line 3322 of file res_agi.c.

3323{
3324 int res;
3325 struct ast_str *buf;
3326
3327 if (argc != 4)
3328 return RESULT_SHOWUSAGE;
3329
3330 if (!(buf = ast_str_create(16))) {
3331 ast_agi_send(agi->fd, chan, "200 result=-1\n");
3332 return RESULT_SUCCESS;
3333 }
3334
3335 do {
3336 res = ast_db_get(argv[2], argv[3], ast_str_buffer(buf), ast_str_size(buf));
3338 if (ast_str_strlen(buf) < ast_str_size(buf) - 1) {
3339 break;
3340 }
3341 if (ast_str_make_space(&buf, ast_str_size(buf) * 2)) {
3342 break;
3343 }
3344 } while (1);
3345
3346 if (res)
3347 ast_agi_send(agi->fd, chan, "200 result=0\n");
3348 else
3349 ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ast_str_buffer(buf));
3350
3351 ast_free(buf);
3352 return RESULT_SUCCESS;
3353}
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition: main/db.c:427
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
#define ast_str_make_space(buf, new_len)
Definition: strings.h:828
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition: strings.h:703
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:742

References ast_agi_send(), ast_db_get(), ast_free, ast_str_buffer(), ast_str_create, ast_str_make_space, ast_str_size(), ast_str_strlen(), ast_str_update(), buf, agi_state::fd, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_dbput()

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

Definition at line 3355 of file res_agi.c.

3356{
3357 int res;
3358
3359 if (argc != 5)
3360 return RESULT_SHOWUSAGE;
3361 res = ast_db_put(argv[2], argv[3], argv[4]);
3362 ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
3363 return RESULT_SUCCESS;
3364}
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:342

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

◆ handle_exec()

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

Definition at line 3144 of file res_agi.c.

3145{
3146 int res, workaround;
3147 struct ast_app *app_to_exec;
3148 const char *agi_exec_full_str;
3149 int agi_exec_full;
3150 struct ast_str *data_with_var = NULL;
3151
3152 if (argc < 2)
3153 return RESULT_SHOWUSAGE;
3154
3155 ast_verb(3, "AGI Script Executing Application: (%s) Options: (%s)\n", argv[1], argc >= 3 ? argv[2] : "");
3156
3157 if ((app_to_exec = pbx_findapp(argv[1]))) {
3158 ast_channel_lock(chan);
3159 if (!(workaround = ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS))) {
3161 }
3162 agi_exec_full_str = pbx_builtin_getvar_helper(chan, "AGIEXECFULL");
3163 agi_exec_full = ast_true(agi_exec_full_str);
3164 ast_channel_unlock(chan);
3165
3166 if (agi_exec_full) {
3167 if ((data_with_var = ast_str_create(16))) {
3168 ast_str_substitute_variables(&data_with_var, 0, chan, argv[2]);
3169 res = pbx_exec(chan, app_to_exec, argc == 2 ? "" : ast_str_buffer(data_with_var));
3170 ast_free(data_with_var);
3171 } else {
3172 res = -2;
3173 }
3174 } else {
3175 res = pbx_exec(chan, app_to_exec, argc == 2 ? "" : argv[2]);
3176 }
3177 if (!workaround) {
3179 }
3180 } else {
3181 ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
3182 res = -2;
3183 }
3184 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
3185
3186 /* Even though this is wrong, users are depending upon this result. */
3187 return res;
3188}
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Clear a flag on a channel.
Definition: channel.c:11034
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
@ AST_FLAG_DISABLE_WORKAROUNDS
Definition: channel.h:1022
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx_app.c:471
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: ael_main.c:165
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
ast_app: A registered application
Definition: pbx_app.c:45
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_set_flag(p, flag)
Definition: utils.h:70

References agi_exec_full(), ast_agi_send(), ast_channel_clear_flag(), ast_channel_flags(), ast_channel_lock, ast_channel_unlock, AST_FLAG_DISABLE_WORKAROUNDS, ast_free, ast_log, ast_set_flag, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), ast_test_flag, ast_true(), ast_verb, agi_state::fd, LOG_WARNING, NULL, pbx_builtin_getvar_helper(), pbx_exec(), pbx_findapp(), and RESULT_SHOWUSAGE.

◆ handle_getdata()

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

Definition at line 2829 of file res_agi.c.

2830{
2831 int res, max, timeout;
2832 char data[1024];
2833
2834 if (argc < 3)
2835 return RESULT_SHOWUSAGE;
2836 if (argc >= 4)
2837 timeout = atoi(argv[3]);
2838 else
2839 timeout = 0;
2840 if (argc >= 5)
2841 max = atoi(argv[4]);
2842 else
2843 max = 1024;
2844 res = ast_app_getdata_full(chan, argv[2], data, max, timeout, agi->audio, agi->ctrl);
2845 if (res == 2) /* New command */
2846 return RESULT_SUCCESS;
2847 else if (res == 1)
2848 ast_agi_send(agi->fd, chan, "200 result=%s (timeout)\n", data);
2849 else if (res < 0 )
2850 ast_agi_send(agi->fd, chan, "200 result=-1\n");
2851 else
2852 ast_agi_send(agi->fd, chan, "200 result=%s\n", data);
2853 return RESULT_SUCCESS;
2854}
#define max(a, b)
Definition: f2c.h:198
int ast_app_getdata_full(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd)
Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other fu...
Definition: main/app.c:247
int ctrl
Definition: agi.h:37
int audio
Definition: agi.h:36

References ast_agi_send(), ast_app_getdata_full(), agi_state::audio, agi_state::ctrl, agi_state::fd, max, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_getoption()

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

get option - really similar to the handle_streamfile, but with a timeout

Definition at line 2611 of file res_agi.c.

2612{
2613 int res;
2614 struct ast_filestream *fs, *vfs;
2615 long sample_offset = 0, max_length;
2616 int timeout = 0;
2617 const char *edigits = "";
2618
2619 if ( argc < 4 || argc > 5 )
2620 return RESULT_SHOWUSAGE;
2621
2622 if ( argv[3] )
2623 edigits = argv[3];
2624
2625 if ( argc == 5 )
2626 timeout = atoi(argv[4]);
2627 else if (ast_channel_pbx(chan)->dtimeoutms) {
2628 /* by default dtimeout is set to 5sec */
2629 timeout = ast_channel_pbx(chan)->dtimeoutms; /* in msec */
2630 }
2631
2632 if (!(fs = ast_openstream(chan, argv[2], ast_channel_language(chan)))) {
2633 ast_agi_send(agi->fd, chan, "200 result=-1 endpos=%ld\n", sample_offset);
2634 ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]);
2635 return RESULT_FAILURE;
2636 }
2637
2638 if ((vfs = ast_openvstream(chan, argv[2], ast_channel_language(chan))))
2639 ast_debug(1, "Ooh, found a video stream, too\n");
2640
2641 ast_verb(3, "Playing '%s' (escape_digits=%s) (timeout %d)\n", argv[2], edigits, timeout);
2642
2643 ast_seekstream(fs, 0, SEEK_END);
2644 max_length = ast_tellstream(fs);
2645 ast_seekstream(fs, sample_offset, SEEK_SET);
2646 res = ast_applystream(chan, fs);
2647 if (vfs)
2648 ast_applystream(chan, vfs);
2649 ast_playstream(fs);
2650 if (vfs)
2652
2653 res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl);
2654 /* this is to check for if ast_waitstream closed the stream, we probably are at
2655 * the end of the stream, return that amount, else check for the amount */
2656 sample_offset = (ast_channel_stream(chan))?ast_tellstream(fs):max_length;
2657 ast_stopstream(chan);
2658 if (res == 1) {
2659 /* Stop this command, don't print a result line, as there is a new command */
2660 return RESULT_SUCCESS;
2661 }
2662
2663 /* If the user didnt press a key, wait for digitTimeout*/
2664 if (res == 0 ) {
2665 res = ast_waitfordigit_full(chan, timeout, NULL, agi->audio, agi->ctrl);
2666 /* Make sure the new result is in the escape digits of the GET OPTION */
2667 if ( !strchr(edigits,res) )
2668 res=0;
2669 }
2670
2671 ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, sample_offset);
2672 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2673}
const char * ast_channel_language(const struct ast_channel *chan)
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
int ast_waitfordigit_full(struct ast_channel *c, int ms, const char *breakon, int audiofd, int ctrlfd)
Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to mon...
Definition: channel.c:3239
off_t ast_tellstream(struct ast_filestream *fs)
Tell where we are in a stream.
Definition: file.c:1085
struct ast_filestream * ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
Definition: file.c:790
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd)
Definition: file.c:1849
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:222
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
Definition: file.c:1075
int ast_applystream(struct ast_channel *chan, struct ast_filestream *s)
Applies a open stream to a channel.
Definition: file.c:1057
struct ast_filestream * ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
Definition: file.c:848
int ast_playstream(struct ast_filestream *s)
Play a open stream on a channel.
Definition: file.c:1063
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Definition: mod_format.h:101
struct ast_filestream * vfs
Definition: mod_format.h:110
int dtimeoutms
Definition: pbx.h:215

References ast_agi_send(), ast_applystream(), ast_channel_language(), ast_channel_pbx(), ast_channel_stream(), ast_debug, ast_log, ast_openstream(), ast_openvstream(), ast_playstream(), ast_seekstream(), ast_stopstream(), ast_tellstream(), ast_verb, ast_waitfordigit_full(), ast_waitstream_full(), agi_state::audio, agi_state::ctrl, ast_pbx::dtimeoutms, agi_state::fd, LOG_WARNING, NULL, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_filestream::vfs.

◆ handle_getvariable()

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

Definition at line 3248 of file res_agi.c.

3249{
3250 char *ret;
3251 char tempstr[1024] = "";
3252
3253 if (argc != 3)
3254 return RESULT_SHOWUSAGE;
3255
3256 /* check if we want to execute an ast_custom_function */
3257 if (!ast_strlen_zero(argv[2]) && (argv[2][strlen(argv[2]) - 1] == ')')) {
3258 ret = ast_func_read(chan, argv[2], tempstr, sizeof(tempstr)) ? NULL : tempstr;
3259 } else {
3260 pbx_retrieve_variable(chan, argv[2], &ret, tempstr, sizeof(tempstr), NULL);
3261 }
3262
3263 if (ret)
3264 ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ret);
3265 else
3266 ast_agi_send(agi->fd, chan, "200 result=0\n");
3267
3268 return RESULT_SUCCESS;
3269}
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
Retrieve the value of a builtin variable or variable from the channel variable stack.

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

◆ handle_getvariablefull()

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

Definition at line 3271 of file res_agi.c.

3272{
3273 struct ast_channel *chan2 = NULL;
3274
3275 if (argc != 4 && argc != 5) {
3276 return RESULT_SHOWUSAGE;
3277 }
3278
3279 if (argc == 5) {
3280 chan2 = ast_channel_get_by_name(argv[4]);
3281 } else {
3282 chan2 = ast_channel_ref(chan);
3283 }
3284
3285 if (chan2) {
3286 struct ast_str *str = ast_str_create(16);
3287 if (!str) {
3288 ast_agi_send(agi->fd, chan, "200 result=0\n");
3289 return RESULT_SUCCESS;
3290 }
3291 ast_str_substitute_variables(&str, 0, chan2, argv[3]);
3292 ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ast_str_buffer(str));
3293 ast_free(str);
3294 } else {
3295 ast_agi_send(agi->fd, chan, "200 result=0\n");
3296 }
3297
3298 if (chan2) {
3299 chan2 = ast_channel_unref(chan2);
3300 }
3301
3302 return RESULT_SUCCESS;
3303}
const char * str
Definition: app_jack.c:147
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947

References ast_agi_send(), ast_channel_get_by_name(), ast_channel_ref, ast_channel_unref, ast_free, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), agi_state::fd, NULL, RESULT_SHOWUSAGE, RESULT_SUCCESS, and str.

◆ handle_hangup()

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

Definition at line 3116 of file res_agi.c.

3117{
3118 struct ast_channel *c;
3119
3120 if (argc == 1) {
3121 /* no argument: hangup the current channel */
3122 ast_set_hangupsource(chan, "dialplan/agi", 0);
3124 ast_agi_send(agi->fd, chan, "200 result=1\n");
3125 return RESULT_SUCCESS;
3126 } else if (argc == 2) {
3127 /* one argument: look for info on the specified channel */
3128 if ((c = ast_channel_get_by_name(argv[1]))) {
3129 /* we have a matching channel */
3130 ast_set_hangupsource(c, "dialplan/agi", 0);
3133 ast_agi_send(agi->fd, chan, "200 result=1\n");
3134 return RESULT_SUCCESS;
3135 }
3136 /* if we get this far no channel name matched the argument given */
3137 ast_agi_send(agi->fd, chan, "200 result=-1\n");
3138 return RESULT_SUCCESS;
3139 } else {
3140 return RESULT_SHOWUSAGE;
3141 }
3142}
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it's bridge.
Definition: channel.c:2499
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition: channel.c:2471
@ AST_SOFTHANGUP_EXPLICIT
Definition: channel.h:1148

References ast_agi_send(), ast_channel_get_by_name(), ast_channel_unref, ast_set_hangupsource(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, c, agi_state::fd, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_noop()

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

Definition at line 3423 of file res_agi.c.

3424{
3425 ast_agi_send(agi->fd, chan, "200 result=0\n");
3426 return RESULT_SUCCESS;
3427}

References ast_agi_send(), agi_state::fd, and RESULT_SUCCESS.

◆ handle_recordfile()

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

Definition at line 2894 of file res_agi.c.

2895{
2896 struct ast_filestream *fs;
2897 struct ast_frame *f;
2898 struct timeval start;
2899 long sample_offset = 0;
2900 int res = 0;
2901 int ms;
2902
2903 struct ast_dsp *sildet=NULL; /* silence detector dsp */
2904 int totalsilence = 0;
2905 int dspsilence = 0;
2906 int silence = 0; /* amount of silence to allow */
2907 int gotsilence = 0; /* did we timeout for silence? */
2908 char *silencestr = NULL;
2909 RAII_VAR(struct ast_format *, rfmt, NULL, ao2_cleanup);
2910 struct ast_silence_generator *silgen = NULL;
2911
2912 /* XXX EAGI FIXME XXX */
2913
2914 if (argc < 6)
2915 return RESULT_SHOWUSAGE;
2916 if (sscanf(argv[5], "%30d", &ms) != 1)
2917 return RESULT_SHOWUSAGE;
2918
2919 if (argc > 6)
2920 silencestr = strchr(argv[6],'s');
2921 if ((argc > 7) && (!silencestr))
2922 silencestr = strchr(argv[7],'s');
2923 if ((argc > 8) && (!silencestr))
2924 silencestr = strchr(argv[8],'s');
2925
2926 if (silencestr) {
2927 if (strlen(silencestr) > 2) {
2928 if ((silencestr[0] == 's') && (silencestr[1] == '=')) {
2929 silencestr++;
2930 silencestr++;
2931 if (silencestr)
2932 silence = atoi(silencestr);
2933 if (silence > 0)
2934 silence *= 1000;
2935 }
2936 }
2937 }
2938
2939 if (silence > 0) {
2940 rfmt = ao2_bump(ast_channel_readformat(chan));
2942 if (res < 0) {
2943 ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
2944 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2945 return RESULT_FAILURE;
2946 }
2947 sildet = ast_dsp_new();
2948 if (!sildet) {
2949 ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
2950 ast_agi_send(agi->fd, chan, "200 result=-1\n");
2951 return RESULT_FAILURE;
2952 }
2954 }
2955
2956 /* backward compatibility, if no offset given, arg[6] would have been
2957 * caught below and taken to be a beep, else if it is a digit then it is a
2958 * offset.
2959 *
2960 * In other words, if the argument does not look like the offset_samples
2961 * argument (a number) and it doesn't look like the silence argument (starts
2962 * with "s=") then it must be the beep argument. The beep argument has no
2963 * required value, the presence of anything in the argument slot we are
2964 * inspecting is an indication that the user wants a beep played.
2965 */
2966 if ((argc > 6 && sscanf(argv[6], "%30ld", &sample_offset) != 1 && !ast_begins_with(argv[6], "s="))
2967 || (argc > 7 && !ast_begins_with(argv[7], "s="))) {
2968 res = ast_streamfile(chan, "beep", ast_channel_language(chan));
2969 }
2970
2971 if (!res)
2972 res = ast_waitstream(chan, argv[4]);
2973 if (res) {
2974 ast_agi_send(agi->fd, chan, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
2975 } else {
2976 fs = ast_writefile(argv[2], argv[3], NULL, O_CREAT | O_WRONLY | (sample_offset ? O_APPEND : 0), 0, AST_FILE_MODE);
2977 if (!fs) {
2978 res = -1;
2979 ast_agi_send(agi->fd, chan, "200 result=%d (writefile)\n", res);
2980 if (sildet)
2981 ast_dsp_free(sildet);
2982 return RESULT_FAILURE;
2983 }
2984
2985 /* Request a video update */
2987
2988 ast_channel_stream_set(chan, fs);
2989 ast_applystream(chan,fs);
2990 /* really should have checks */
2991 ast_seekstream(fs, sample_offset, SEEK_SET);
2992 ast_truncstream(fs);
2993
2996 }
2997
2998 start = ast_tvnow();
2999 while ((ms < 0) || ast_tvdiff_ms(ast_tvnow(), start) < ms) {
3000 res = ast_waitfor(chan, ms - ast_tvdiff_ms(ast_tvnow(), start));
3001 if (res < 0) {
3002 ast_closestream(fs);
3003 ast_agi_send(agi->fd, chan, "200 result=%d (waitfor) endpos=%ld\n", res,sample_offset);
3004 if (sildet)
3005 ast_dsp_free(sildet);
3006 if (silgen)
3008 return RESULT_FAILURE;
3009 }
3010 f = ast_read(chan);
3011 if (!f) {
3012 ast_closestream(fs);
3013 ast_agi_send(agi->fd, chan, "200 result=%d (hangup) endpos=%ld\n", -1, sample_offset);
3014 if (sildet)
3015 ast_dsp_free(sildet);
3016 if (silgen)
3018 return RESULT_FAILURE;
3019 }
3020 switch(f->frametype) {
3021 case AST_FRAME_DTMF:
3022 if (strchr(argv[4], f->subclass.integer)) {
3023 /* This is an interrupting character, so rewind to chop off any small
3024 amount of DTMF that may have been recorded
3025 */
3026 ast_stream_rewind(fs, 200);
3027 ast_truncstream(fs);
3028 sample_offset = ast_tellstream(fs);
3029 ast_closestream(fs);
3030 ast_agi_send(agi->fd, chan, "200 result=%d (dtmf) endpos=%ld\n", f->subclass.integer, sample_offset);
3031 ast_frfree(f);
3032 if (sildet)
3033 ast_dsp_free(sildet);
3034 if (silgen)
3036 return RESULT_SUCCESS;
3037 }
3038 break;
3039 case AST_FRAME_VOICE:
3040 ast_writestream(fs, f);
3041 /* this is a safe place to check progress since we know that fs
3042 * is valid after a write, and it will then have our current
3043 * location */
3044 sample_offset = ast_tellstream(fs);
3045 if (silence > 0) {
3046 dspsilence = 0;
3047 ast_dsp_silence(sildet, f, &dspsilence);
3048 if (dspsilence) {
3049 totalsilence = dspsilence;
3050 } else {
3051 totalsilence = 0;
3052 }
3053 if (totalsilence > silence) {
3054 /* Ended happily with silence */
3055 gotsilence = 1;
3056 break;
3057 }
3058 }
3059 break;
3060 case AST_FRAME_VIDEO:
3061 ast_writestream(fs, f);
3062 default:
3063 /* Ignore all other frames */
3064 break;
3065 }
3066 ast_frfree(f);
3067 if (gotsilence)
3068 break;
3069 }
3070
3071 if (gotsilence) {
3072 ast_stream_rewind(fs, silence-1000);
3073 ast_truncstream(fs);
3074 sample_offset = ast_tellstream(fs);
3075 }
3076 ast_closestream(fs);
3077 ast_agi_send(agi->fd, chan, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset);
3078 }
3079
3080 if (silence > 0) {
3081 res = ast_set_read_format(chan, rfmt);
3082 if (res)
3083 ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", ast_channel_name(chan));
3084 ast_dsp_free(sildet);
3085 }
3086
3087 if (silgen) {
3089 }
3090
3091 return RESULT_SUCCESS;
3092}
#define AST_FILE_MODE
Definition: asterisk.h:32
void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition: channel.c:8164
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3162
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
Stops a previously-started silence generator on the given channel.
Definition: channel.c:8210
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4277
void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
Set the minimum average magnitude threshold to determine talking by the DSP.
Definition: dsp.c:1788
void ast_dsp_free(struct ast_dsp *dsp)
Definition: dsp.c:1783
@ THRESHOLD_SILENCE
Definition: dsp.h:73
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
Process the audio frame for silence.
Definition: dsp.c:1488
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition: dsp.c:2009
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
Definition: dsp.c:1758
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
Definition: file.c:244
int ast_stream_rewind(struct ast_filestream *fs, off_t ms)
Rewind stream ms.
Definition: file.c:1100
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1293
struct ast_filestream * ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts writing a file.
Definition: file.c:1423
int ast_truncstream(struct ast_filestream *fs)
Trunc stream at current location.
Definition: file.c:1080
int ast_closestream(struct ast_filestream *f)
Closes a stream.
Definition: file.c:1111
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1840
#define AST_FRAME_DTMF
@ AST_FRAME_VIDEO
@ AST_FRAME_VOICE
@ AST_CONTROL_VIDUPDATE
#define ast_opt_transmit_silence
Definition: options.h:124
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition: strings.h:97
Definition: dsp.c:407
int totalsilence
Definition: dsp.c:411
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

References ao2_bump, ao2_cleanup, ast_agi_send(), ast_applystream(), ast_begins_with(), ast_channel_language(), ast_channel_name(), ast_channel_readformat(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_channel_stream_set(), ast_closestream(), AST_CONTROL_VIDUPDATE, ast_dsp_free(), ast_dsp_get_threshold_from_settings(), ast_dsp_new(), ast_dsp_set_threshold(), ast_dsp_silence(), AST_FILE_MODE, ast_format_slin, AST_FRAME_DTMF, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_indicate(), ast_log, ast_opt_transmit_silence, 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(), agi_state::fd, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, NULL, RAII_VAR, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, ast_frame::subclass, THRESHOLD_SILENCE, and ast_dsp::totalsilence.

◆ handle_recvchar()

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

Definition at line 2409 of file res_agi.c.

2410{
2411 int res;
2412
2413 if (argc != 3)
2414 return RESULT_SHOWUSAGE;
2415
2416 res = ast_recvchar(chan,atoi(argv[2]));
2417 if (res == 0) {
2418 ast_agi_send(agi->fd, chan, "200 result=%d (timeout)\n", res);
2419 return RESULT_SUCCESS;
2420 }
2421 if (res > 0) {
2422 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2423 return RESULT_SUCCESS;
2424 }
2425 ast_agi_send(agi->fd, chan, "200 result=%d (hangup)\n", res);
2426 return RESULT_FAILURE;
2427}
int ast_recvchar(struct ast_channel *chan, int timeout)
Receives a text character from a channel.
Definition: channel.c:4706

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

◆ handle_recvtext()

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

Definition at line 2429 of file res_agi.c.

2430{
2431 char *buf;
2432
2433 if (argc != 3)
2434 return RESULT_SHOWUSAGE;
2435
2436 buf = ast_recvtext(chan, atoi(argv[2]));
2437 if (buf) {
2438 ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", buf);
2439 ast_free(buf);
2440 } else {
2441 ast_agi_send(agi->fd, chan, "200 result=-1\n");
2442 }
2443 return RESULT_SUCCESS;
2444}
char * ast_recvtext(struct ast_channel *chan, int timeout)
Receives a text string from a channel Read a string of text from a channel.
Definition: channel.c:4717

References ast_agi_send(), ast_free, ast_recvtext(), buf, agi_state::fd, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_sayalpha()

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

Definition at line 2711 of file res_agi.c.

2712{
2713 int res;
2714 int sensitivity = AST_SAY_CASE_NONE;
2715
2716 if (argc < 4 || argc > 5) {
2717 return RESULT_SHOWUSAGE;
2718 }
2719
2720 if (argc > 4) {
2721 switch (argv[4][0]) {
2722 case 'a':
2723 case 'A':
2724 sensitivity = AST_SAY_CASE_ALL;
2725 break;
2726 case 'l':
2727 case 'L':
2728 sensitivity = AST_SAY_CASE_LOWER;
2729 break;
2730 case 'n':
2731 case 'N':
2732 sensitivity = AST_SAY_CASE_NONE;
2733 break;
2734 case 'u':
2735 case 'U':
2736 sensitivity = AST_SAY_CASE_UPPER;
2737 break;
2738 case '\0':
2739 break;
2740 default:
2741 return RESULT_SHOWUSAGE;
2742 }
2743 }
2744 res = ast_say_character_str_full(chan, argv[2], argv[3], ast_channel_language(chan), sensitivity, agi->audio, agi->ctrl);
2745 if (res == 1) /* New command */
2746 return RESULT_SUCCESS;
2747 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2748 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2749}
SAY_EXTERN int(* ast_say_character_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity, int audiofd, int ctrlfd) SAY_INIT(ast_say_character_str_full)
Definition: say.h:194
@ AST_SAY_CASE_LOWER
Definition: say.h:183
@ AST_SAY_CASE_ALL
Definition: say.h:185
@ AST_SAY_CASE_UPPER
Definition: say.h:184
@ AST_SAY_CASE_NONE
Definition: say.h:182

References ast_agi_send(), ast_channel_language(), AST_SAY_CASE_ALL, AST_SAY_CASE_LOWER, AST_SAY_CASE_NONE, AST_SAY_CASE_UPPER, ast_say_character_str_full, agi_state::audio, agi_state::ctrl, agi_state::fd, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_saydate()

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

Definition at line 2751 of file res_agi.c.

2752{
2753 int res, num;
2754
2755 if (argc != 4)
2756 return RESULT_SHOWUSAGE;
2757 if (sscanf(argv[2], "%30d", &num) != 1)
2758 return RESULT_SHOWUSAGE;
2759 res = ast_say_date(chan, num, argv[3], ast_channel_language(chan));
2760 if (res == 1)
2761 return RESULT_SUCCESS;
2762 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2763 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2764}
SAY_EXTERN int(* ast_say_date)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_date)
Definition: say.h:204

References ast_agi_send(), ast_channel_language(), ast_say_date, agi_state::fd, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_saydatetime()

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

Definition at line 2781 of file res_agi.c.

2782{
2783 int res = 0;
2784 time_t unixtime;
2785 const char *format, *zone = NULL;
2786
2787 if (argc < 4)
2788 return RESULT_SHOWUSAGE;
2789
2790 if (argc > 4) {
2791 format = argv[4];
2792 } else {
2793 /* XXX this doesn't belong here, but in the 'say' module */
2794 if (!strcasecmp(ast_channel_language(chan), "de")) {
2795 format = "A dBY HMS";
2796 } else {
2797 format = "ABdY 'digits/at' IMp";
2798 }
2799 }
2800
2801 if (argc > 5 && !ast_strlen_zero(argv[5]))
2802 zone = argv[5];
2803
2804 if (ast_get_time_t(argv[2], &unixtime, 0, NULL))
2805 return RESULT_SHOWUSAGE;
2806
2807 res = ast_say_date_with_format(chan, unixtime, argv[3], ast_channel_language(chan), format, zone);
2808 if (res == 1)
2809 return RESULT_SUCCESS;
2810
2811 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2812 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2813}
SAY_EXTERN int(* ast_say_date_with_format)(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezone) SAY_INIT(ast_say_date_with_format)
Definition: say.h:208
int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed)
Parse a time (integer) string.
Definition: utils.c:2446

References ast_agi_send(), ast_channel_language(), ast_get_time_t(), ast_say_date_with_format, ast_strlen_zero(), agi_state::fd, NULL, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_saydigits()

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

Definition at line 2695 of file res_agi.c.

2696{
2697 int res, num;
2698
2699 if (argc != 4)
2700 return RESULT_SHOWUSAGE;
2701 if (sscanf(argv[2], "%30d", &num) != 1)
2702 return RESULT_SHOWUSAGE;
2703
2704 res = ast_say_digit_str_full(chan, argv[2], argv[3], ast_channel_language(chan), agi->audio, agi->ctrl);
2705 if (res == 1) /* New command */
2706 return RESULT_SUCCESS;
2707 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2708 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2709}
SAY_EXTERN int(* ast_say_digit_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_digit_str_full)
Same as ast_say_digit_str() with audiofd for received audio and returns 1 on ctrlfd being readable.
Definition: say.h:162

References ast_agi_send(), ast_channel_language(), ast_say_digit_str_full, agi_state::audio, agi_state::ctrl, agi_state::fd, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_saynumber()

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

Say number in various language syntaxes.

Definition at line 2680 of file res_agi.c.

2681{
2682 int res, num;
2683
2684 if (argc < 4 || argc > 5)
2685 return RESULT_SHOWUSAGE;
2686 if (sscanf(argv[2], "%30d", &num) != 1)
2687 return RESULT_SHOWUSAGE;
2688 res = ast_say_number_full(chan, num, argv[3], ast_channel_language(chan), argc > 4 ? argv[4] : NULL, agi->audio, agi->ctrl);
2689 if (res == 1)
2690 return RESULT_SUCCESS;
2691 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2692 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2693}
SAY_EXTERN int(* ast_say_number_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_number_full)
Same as ast_say_number() with audiofd for received audio and returns 1 on ctrlfd being readable.
Definition: say.h:86

References ast_agi_send(), ast_channel_language(), ast_say_number_full, agi_state::audio, agi_state::ctrl, agi_state::fd, NULL, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_sayphonetic()

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

Definition at line 2815 of file res_agi.c.

2816{
2817 int res;
2818
2819 if (argc != 4)
2820 return RESULT_SHOWUSAGE;
2821
2822 res = ast_say_phonetic_str_full(chan, argv[2], argv[3], ast_channel_language(chan), agi->audio, agi->ctrl);
2823 if (res == 1) /* New command */
2824 return RESULT_SUCCESS;
2825 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2826 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2827}
SAY_EXTERN int(* ast_say_phonetic_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_phonetic_str_full)
Definition: say.h:199

References ast_agi_send(), ast_channel_language(), ast_say_phonetic_str_full, agi_state::audio, agi_state::ctrl, agi_state::fd, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_saytime()

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

Definition at line 2766 of file res_agi.c.

2767{
2768 int res, num;
2769
2770 if (argc != 4)
2771 return RESULT_SHOWUSAGE;
2772 if (sscanf(argv[2], "%30d", &num) != 1)
2773 return RESULT_SHOWUSAGE;
2774 res = ast_say_time(chan, num, argv[3], ast_channel_language(chan));
2775 if (res == 1)
2776 return RESULT_SUCCESS;
2777 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2778 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2779}
SAY_EXTERN int(* ast_say_time)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_time)
Definition: say.h:202

References ast_agi_send(), ast_channel_language(), ast_say_time, agi_state::fd, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_sendimage()

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

Definition at line 2474 of file res_agi.c.

2475{
2476 int res;
2477
2478 if (argc != 3) {
2479 return RESULT_SHOWUSAGE;
2480 }
2481
2482 res = ast_send_image(chan, argv[2]);
2483 if (!ast_check_hangup(chan)) {
2484 res = 0;
2485 }
2486 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2487 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2488}
int ast_send_image(struct ast_channel *chan, const char *filename)
Sends an image.
Definition: image.c:158

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

◆ handle_sendtext()

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

Definition at line 2390 of file res_agi.c.

2391{
2392 int res;
2393
2394 if (argc != 3)
2395 return RESULT_SHOWUSAGE;
2396
2397 /* At the moment, the parser (perhaps broken) returns with
2398 the last argument PLUS the newline at the end of the input
2399 buffer. This probably needs to be fixed, but I wont do that
2400 because other stuff may break as a result. The right way
2401 would probably be to strip off the trailing newline before
2402 parsing, then here, add a newline at the end of the string
2403 before sending it to ast_sendtext --DUDE */
2404 res = ast_sendtext(chan, argv[2]);
2405 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2406 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2407}
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition: channel.c:4809

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

◆ handle_setcallerid()

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

Definition at line 3190 of file res_agi.c.

3191{
3192 char tmp[256]="";
3193 char *l = NULL, *n = NULL;
3194
3195 if (argv[2]) {
3196 ast_copy_string(tmp, argv[2], sizeof(tmp));
3197 ast_callerid_parse(tmp, &n, &l);
3198 if (l)
3200 else
3201 l = "";
3202 if (!n)
3203 n = "";
3204 ast_set_callerid(chan, l, n, NULL);
3205 }
3206
3207 ast_agi_send(agi->fd, chan, "200 result=1\n");
3208 return RESULT_SUCCESS;
3209}
static int tmp()
Definition: bt_open.c:389
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1063
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s,...
Definition: callerid.c:1002
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
Set caller ID number, name and ANI and generate AMI event.
Definition: channel.c:7334
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425

References ast_agi_send(), ast_callerid_parse(), ast_copy_string(), ast_set_callerid(), ast_shrink_phone_number(), agi_state::fd, NULL, RESULT_SUCCESS, and tmp().

◆ handle_setcontext()

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

Definition at line 2856 of file res_agi.c.

2857{
2858
2859 if (argc != 3)
2860 return RESULT_SHOWUSAGE;
2861 ast_channel_context_set(chan, argv[2]);
2862 ast_agi_send(agi->fd, chan, "200 result=0\n");
2863 return RESULT_SUCCESS;
2864}
void ast_channel_context_set(struct ast_channel *chan, const char *value)

References ast_agi_send(), ast_channel_context_set(), agi_state::fd, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_setextension()

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

Definition at line 2866 of file res_agi.c.

2867{
2868 if (argc != 3)
2869 return RESULT_SHOWUSAGE;
2870 ast_channel_exten_set(chan, argv[2]);
2871 ast_agi_send(agi->fd, chan, "200 result=0\n");
2872 return RESULT_SUCCESS;
2873}
void ast_channel_exten_set(struct ast_channel *chan, const char *value)

References ast_agi_send(), ast_channel_exten_set(), agi_state::fd, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_setmusic()

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

Definition at line 3429 of file res_agi.c.

3430{
3431 if (argc < 3) {
3432 return RESULT_SHOWUSAGE;
3433 }
3434 if (!strncasecmp(argv[2], "on", 2))
3435 ast_moh_start(chan, argc > 3 ? argv[3] : NULL, NULL);
3436 else if (!strncasecmp(argv[2], "off", 3))
3437 ast_moh_stop(chan);
3438 ast_agi_send(agi->fd, chan, "200 result=0\n");
3439 return RESULT_SUCCESS;
3440}
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7766
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7776

References ast_agi_send(), ast_moh_start(), ast_moh_stop(), agi_state::fd, NULL, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_setpriority()

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

Definition at line 2875 of file res_agi.c.

2876{
2877 int pri;
2878
2879 if (argc != 3)
2880 return RESULT_SHOWUSAGE;
2881
2882 if (sscanf(argv[2], "%30d", &pri) != 1) {
2883 pri = ast_findlabel_extension(chan, ast_channel_context(chan), ast_channel_exten(chan), argv[2],
2884 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
2885 if (pri < 1)
2886 return RESULT_SHOWUSAGE;
2887 }
2888
2889 ast_explicit_goto(chan, NULL, NULL, pri);
2890 ast_agi_send(agi->fd, chan, "200 result=0\n");
2891 return RESULT_SUCCESS;
2892}
const char * ast_channel_context(const struct ast_channel *chan)
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
Find the priority of an extension that has the specified label.
Definition: pbx.c:4180
int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition: pbx.c:6945
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
Number structure.
Definition: app_followme.c:154

References ast_agi_send(), ast_channel_caller(), ast_channel_context(), ast_channel_exten(), ast_explicit_goto(), ast_findlabel_extension(), agi_state::fd, NULL, RESULT_SHOWUSAGE, RESULT_SUCCESS, and S_COR.

◆ handle_setvariable()

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

Definition at line 3235 of file res_agi.c.

3236{
3237 if (argc != 4) {
3238 return RESULT_SHOWUSAGE;
3239 }
3240
3241 if (argv[3])
3242 pbx_builtin_setvar_helper(chan, argv[2], argv[3]);
3243
3244 ast_agi_send(agi->fd, chan, "200 result=1\n");
3245 return RESULT_SUCCESS;
3246}

References ast_agi_send(), agi_state::fd, pbx_builtin_setvar_helper(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_speechactivategrammar()

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

Definition at line 3533 of file res_agi.c.

3534{
3535 if (argc != 4)
3536 return RESULT_SHOWUSAGE;
3537
3538 if (!agi->speech) {
3539 ast_agi_send(agi->fd, chan, "200 result=0\n");
3540 return RESULT_SUCCESS;
3541 }
3542
3543 if (ast_speech_grammar_activate(agi->speech, argv[3]))
3544 ast_agi_send(agi->fd, chan, "200 result=0\n");
3545 else
3546 ast_agi_send(agi->fd, chan, "200 result=1\n");
3547
3548 return RESULT_SUCCESS;
3549}
int ast_speech_grammar_activate(struct ast_speech *speech, const char *grammar_name)
Activate a grammar on a speech structure.
Definition: res_speech.c:66
struct ast_speech * speech
Definition: agi.h:39

References ast_agi_send(), ast_speech_grammar_activate(), agi_state::fd, RESULT_SHOWUSAGE, RESULT_SUCCESS, and agi_state::speech.

◆ handle_speechcreate()

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

Definition at line 3442 of file res_agi.c.

3443{
3444 struct ast_format_cap *cap;
3445
3446 /* If a structure already exists, return an error */
3447 if (agi->speech) {
3448 ast_agi_send(agi->fd, chan, "200 result=0\n");
3449 return RESULT_SUCCESS;
3450 }
3451
3453 return RESULT_FAILURE;
3454 }
3456 if ((agi->speech = ast_speech_new(argv[2], cap))) {
3457 ast_agi_send(agi->fd, chan, "200 result=1\n");
3458 } else {
3459 ast_agi_send(agi->fd, chan, "200 result=0\n");
3460 }
3461 ao2_ref(cap, -1);
3462
3463 return RESULT_SUCCESS;
3464}
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
struct ast_speech * ast_speech_new(const char *engine_name, const struct ast_format_cap *formats)
Create a new speech structure.
Definition: res_speech.c:181
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54

References ao2_ref, ast_agi_send(), ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_slin, ast_speech_new(), agi_state::fd, RESULT_FAILURE, RESULT_SUCCESS, and agi_state::speech.

◆ handle_speechdeactivategrammar()

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

Definition at line 3551 of file res_agi.c.

3552{
3553 if (argc != 4)
3554 return RESULT_SHOWUSAGE;
3555
3556 if (!agi->speech) {
3557 ast_agi_send(agi->fd, chan, "200 result=0\n");
3558 return RESULT_SUCCESS;
3559 }
3560
3561 if (ast_speech_grammar_deactivate(agi->speech, argv[3]))
3562 ast_agi_send(agi->fd, chan, "200 result=0\n");
3563 else
3564 ast_agi_send(agi->fd, chan, "200 result=1\n");
3565
3566 return RESULT_SUCCESS;
3567}
int ast_speech_grammar_deactivate(struct ast_speech *speech, const char *grammar_name)
Deactivate a grammar on a speech structure.
Definition: res_speech.c:72

References ast_agi_send(), ast_speech_grammar_deactivate(), agi_state::fd, RESULT_SHOWUSAGE, RESULT_SUCCESS, and agi_state::speech.

◆ handle_speechdestroy()

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

Definition at line 3484 of file res_agi.c.

3485{
3486 if (agi->speech) {
3488 agi->speech = NULL;
3489 ast_agi_send(agi->fd, chan, "200 result=1\n");
3490 } else {
3491 ast_agi_send(agi->fd, chan, "200 result=0\n");
3492 }
3493
3494 return RESULT_SUCCESS;
3495}
int ast_speech_destroy(struct ast_speech *speech)
Destroy a speech structure.
Definition: res_speech.c:251

References ast_agi_send(), ast_speech_destroy(), agi_state::fd, NULL, RESULT_SUCCESS, and agi_state::speech.

◆ handle_speechloadgrammar()

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

Definition at line 3497 of file res_agi.c.

3498{
3499 if (argc != 5)
3500 return RESULT_SHOWUSAGE;
3501
3502 if (!agi->speech) {
3503 ast_agi_send(agi->fd, chan, "200 result=0\n");
3504 return RESULT_SUCCESS;
3505 }
3506
3507 if (ast_speech_grammar_load(agi->speech, argv[3], argv[4]))
3508 ast_agi_send(agi->fd, chan, "200 result=0\n");
3509 else
3510 ast_agi_send(agi->fd, chan, "200 result=1\n");
3511
3512 return RESULT_SUCCESS;
3513}
int ast_speech_grammar_load(struct ast_speech *speech, const char *grammar_name, const char *grammar)
Load a grammar on a speech structure (not globally)
Definition: res_speech.c:78

References ast_agi_send(), ast_speech_grammar_load(), agi_state::fd, RESULT_SHOWUSAGE, RESULT_SUCCESS, and agi_state::speech.

◆ handle_speechrecognize()

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

Definition at line 3588 of file res_agi.c.

3589{
3590 struct ast_speech *speech = agi->speech;
3591 const char *prompt;
3592 char dtmf = 0, tmp[4096] = "", *buf = tmp;
3593 int timeout = 0, offset = 0, res = 0, i = 0;
3594 long current_offset = 0;
3595 const char *reason = NULL;
3596 struct ast_frame *fr = NULL;
3597 struct ast_speech_result *result = NULL;
3598 size_t left = sizeof(tmp);
3599 time_t start = 0, current;
3600
3601 if (argc < 4)
3602 return RESULT_SHOWUSAGE;
3603
3604 if (!speech) {
3605 ast_agi_send(agi->fd, chan, "200 result=0\n");
3606 return RESULT_SUCCESS;
3607 }
3608
3609 prompt = argv[2];
3610 timeout = atoi(argv[3]);
3611
3612 /* If offset is specified then convert from text to integer */
3613 if (argc == 5)
3614 offset = atoi(argv[4]);
3615
3616 /* We want frames coming in signed linear */
3618 ast_agi_send(agi->fd, chan, "200 result=0\n");
3619 return RESULT_SUCCESS;
3620 }
3621
3622 /* Setup speech structure */
3623 if (speech->state == AST_SPEECH_STATE_NOT_READY || speech->state == AST_SPEECH_STATE_DONE) {
3625 ast_speech_start(speech);
3626 }
3627
3628 /* Start playing prompt */
3629 speech_streamfile(chan, prompt, ast_channel_language(chan), offset);
3630
3631 /* Go into loop reading in frames, passing to speech thingy, checking for hangup, all that jazz */
3632 while (ast_strlen_zero(reason)) {
3633 /* Run scheduled items */
3635
3636 /* See maximum time of waiting */
3637 if ((res = ast_sched_wait(ast_channel_sched(chan))) < 0)
3638 res = 1000;
3639
3640 /* Wait for frame */
3641 if (ast_waitfor(chan, res) > 0) {
3642 if (!(fr = ast_read(chan))) {
3643 reason = "hangup";
3644 break;
3645 }
3646 }
3647
3648 /* Perform timeout check */
3649 if ((timeout > 0) && (start > 0)) {
3650 time(&current);
3651 if ((current - start) >= timeout) {
3652 reason = "timeout";
3653 if (fr)
3654 ast_frfree(fr);
3655 break;
3656 }
3657 }
3658
3659 /* Check the speech structure for any changes */
3660 ast_mutex_lock(&speech->lock);
3661
3662 /* See if we need to quiet the audio stream playback */
3663 if (ast_test_flag(speech, AST_SPEECH_QUIET) && ast_channel_stream(chan)) {
3664 current_offset = ast_tellstream(ast_channel_stream(chan));
3665 ast_stopstream(chan);
3667 }
3668
3669 /* Check each state */
3670 switch (speech->state) {
3672 /* If the stream is done, start timeout calculation */
3673 if ((timeout > 0) && start == 0 && ((!ast_channel_stream(chan)) || (ast_channel_streamid(chan) == -1 && ast_channel_timingfunc(chan) == NULL))) {
3674 ast_stopstream(chan);
3675 time(&start);
3676 }
3677 /* Write audio frame data into speech engine if possible */
3678 if (fr && fr->frametype == AST_FRAME_VOICE)
3679 ast_speech_write(speech, fr->data.ptr, fr->datalen);
3680 break;
3682 /* Cue waiting sound if not already playing */
3683 if ((!ast_channel_stream(chan)) || (ast_channel_streamid(chan) == -1 && ast_channel_timingfunc(chan) == NULL)) {
3684 ast_stopstream(chan);
3685 /* If a processing sound exists, or is not none - play it */
3686 if (!ast_strlen_zero(speech->processing_sound) && strcasecmp(speech->processing_sound, "none"))
3688 }
3689 break;
3691 /* Get the results */
3692 speech->results = ast_speech_results_get(speech);
3693 /* Change state to not ready */
3695 reason = "speech";
3696 break;
3697 default:
3698 break;
3699 }
3700 ast_mutex_unlock(&speech->lock);
3701
3702 /* Check frame for DTMF or hangup */
3703 if (fr) {
3704 if (fr->frametype == AST_FRAME_DTMF) {
3705 reason = "dtmf";
3706 dtmf = fr->subclass.integer;
3707 } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass.integer == AST_CONTROL_HANGUP) {
3708 reason = "hangup";
3709 }
3710 ast_frfree(fr);
3711 }
3712 }
3713
3714 if (!strcasecmp(reason, "speech")) {
3715 /* Build string containing speech results */
3716 for (result = speech->results; result; result = AST_LIST_NEXT(result, list)) {
3717 /* Build result string */
3718 ast_build_string(&buf, &left, "%sscore%d=%d text%d=\"%s\" grammar%d=%s", (i > 0 ? " " : ""), i, result->score, i, result->text, i, result->grammar);
3719 /* Increment result count */
3720 i++;
3721 }
3722 /* Print out */
3723 ast_agi_send(agi->fd, chan, "200 result=1 (speech) endpos=%ld results=%d %s\n", current_offset, i, tmp);
3724 } else if (!strcasecmp(reason, "dtmf")) {
3725 ast_agi_send(agi->fd, chan, "200 result=1 (digit) digit=%c endpos=%ld\n", dtmf, current_offset);
3726 } else if (!strcasecmp(reason, "hangup") || !strcasecmp(reason, "timeout")) {
3727 ast_agi_send(agi->fd, chan, "200 result=1 (%s) endpos=%ld\n", reason, current_offset);
3728 } else {
3729 ast_agi_send(agi->fd, chan, "200 result=0 endpos=%ld\n", current_offset);
3730 }
3731
3732 return RESULT_SUCCESS;
3733}
static struct ast_str * prompt
Definition: asterisk.c:2763
static PGresult * result
Definition: cel_pgsql.c:84
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
int ast_channel_streamid(const struct ast_channel *chan)
struct ast_sched_context * ast_channel_sched(const struct ast_channel *chan)
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
#define ast_mutex_unlock(a)
Definition: lock.h:190
#define ast_mutex_lock(a)
Definition: lock.h:189
size_t current
Definition: main/cli.c:113
static int speech_streamfile(struct ast_channel *chan, const char *filename, const char *preflang, int offset)
Definition: res_agi.c:3569
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
Definition: sched.c:786
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
Definition: sched.c:433
void ast_speech_start(struct ast_speech *speech)
Indicate to the speech engine that audio is now going to start being written.
Definition: res_speech.c:122
int ast_speech_write(struct ast_speech *speech, void *data, int len)
Write audio to the speech engine.
Definition: res_speech.c:144
int ast_speech_change_state(struct ast_speech *speech, int state)
Change state of a speech structure.
Definition: res_speech.c:278
@ AST_SPEECH_STATE_DONE
Definition: speech.h:42
@ AST_SPEECH_STATE_READY
Definition: speech.h:40
@ AST_SPEECH_STATE_NOT_READY
Definition: speech.h:39
@ AST_SPEECH_STATE_WAIT
Definition: speech.h:41
struct ast_speech_result * ast_speech_results_get(struct ast_speech *speech)
Get speech recognition results.
Definition: res_speech.c:90
@ AST_SPEECH_QUIET
Definition: speech.h:32
int ast_build_string(char **buffer, size_t *space, const char *fmt,...)
Build a string in a buffer, designed to be called repeatedly.
Definition: utils.c:2167
union ast_frame::@226 data
char * processing_sound
Definition: speech.h:60
int state
Definition: speech.h:62
ast_mutex_t lock
Definition: speech.h:56
struct ast_speech_result * results
Definition: speech.h:68
#define ast_clear_flag(p, flag)
Definition: utils.h:77

References ast_agi_send(), ast_build_string(), ast_channel_language(), ast_channel_sched(), ast_channel_stream(), ast_channel_streamid(), ast_channel_timingfunc(), ast_clear_flag, AST_CONTROL_HANGUP, ast_format_slin, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_frfree, AST_LIST_NEXT, ast_mutex_lock, ast_mutex_unlock, ast_read(), ast_sched_runq(), ast_sched_wait(), ast_set_read_format(), ast_speech_change_state(), AST_SPEECH_QUIET, ast_speech_results_get(), ast_speech_start(), AST_SPEECH_STATE_DONE, AST_SPEECH_STATE_NOT_READY, AST_SPEECH_STATE_READY, AST_SPEECH_STATE_WAIT, ast_speech_write(), ast_stopstream(), ast_strlen_zero(), ast_tellstream(), ast_test_flag, ast_waitfor(), buf, current, ast_frame::data, ast_frame::datalen, agi_state::fd, ast_frame::frametype, ast_frame_subclass::integer, ast_speech::lock, NULL, ast_speech::processing_sound, prompt, ast_frame::ptr, result, RESULT_SHOWUSAGE, RESULT_SUCCESS, ast_speech::results, agi_state::speech, speech_streamfile(), ast_speech::state, ast_frame::subclass, and tmp().

◆ handle_speechset()

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

Definition at line 3466 of file res_agi.c.

3467{
3468 /* Check for minimum arguments */
3469 if (argc != 4)
3470 return RESULT_SHOWUSAGE;
3471
3472 /* Check to make sure speech structure exists */
3473 if (!agi->speech) {
3474 ast_agi_send(agi->fd, chan, "200 result=0\n");
3475 return RESULT_SUCCESS;
3476 }
3477
3478 ast_speech_change(agi->speech, argv[2], argv[3]);
3479 ast_agi_send(agi->fd, chan, "200 result=1\n");
3480
3481 return RESULT_SUCCESS;
3482}
int ast_speech_change(struct ast_speech *speech, const char *name, const char *value)
Change an engine specific attribute.
Definition: res_speech.c:169

References ast_agi_send(), ast_speech_change(), agi_state::fd, RESULT_SHOWUSAGE, RESULT_SUCCESS, and agi_state::speech.

◆ handle_speechunloadgrammar()

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

Definition at line 3515 of file res_agi.c.

3516{
3517 if (argc != 4)
3518 return RESULT_SHOWUSAGE;
3519
3520 if (!agi->speech) {
3521 ast_agi_send(agi->fd, chan, "200 result=0\n");
3522 return RESULT_SUCCESS;
3523 }
3524
3525 if (ast_speech_grammar_unload(agi->speech, argv[3]))
3526 ast_agi_send(agi->fd, chan, "200 result=0\n");
3527 else
3528 ast_agi_send(agi->fd, chan, "200 result=1\n");
3529
3530 return RESULT_SUCCESS;
3531}
int ast_speech_grammar_unload(struct ast_speech *speech, const char *grammar_name)
Unload a grammar.
Definition: res_speech.c:84

References ast_agi_send(), ast_speech_grammar_unload(), agi_state::fd, RESULT_SHOWUSAGE, RESULT_SUCCESS, and agi_state::speech.

◆ handle_streamfile()

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

Definition at line 2552 of file res_agi.c.

2553{
2554 int res;
2555 struct ast_filestream *fs, *vfs;
2556 long sample_offset = 0, max_length;
2557 const char *edigits = "";
2558
2559 if (argc < 4 || argc > 5) {
2560 return RESULT_SHOWUSAGE;
2561 }
2562
2563 if (argv[3]) {
2564 edigits = argv[3];
2565 }
2566
2567 if ((argc > 4) && (sscanf(argv[4], "%30ld", &sample_offset) != 1)) {
2568 return RESULT_SHOWUSAGE;
2569 }
2570
2571 if (!(fs = ast_openstream(chan, argv[2], ast_channel_language(chan)))) {
2572 ast_agi_send(agi->fd, chan, "200 result=-1 endpos=%ld\n", sample_offset);
2573 return RESULT_FAILURE;
2574 }
2575
2576 if ((vfs = ast_openvstream(chan, argv[2], ast_channel_language(chan)))) {
2577 ast_debug(1, "Ooh, found a video stream, too\n");
2578 }
2579 ast_verb(3, "<%s> Playing '%s.%s' (escape_digits=%s) (sample_offset %ld) (language '%s')\n",
2581 edigits, sample_offset, S_OR(ast_channel_language(chan), "default"));
2582
2583 ast_seekstream(fs, 0, SEEK_END);
2584 max_length = ast_tellstream(fs);
2585 ast_seekstream(fs, sample_offset, SEEK_SET);
2586 res = ast_applystream(chan, fs);
2587 if (vfs) {
2588 ast_applystream(chan, vfs);
2589 }
2590 ast_playstream(fs);
2591 if (vfs) {
2593 }
2594
2595 res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl);
2596 /* this is to check for if ast_waitstream closed the stream, we probably are at
2597 * the end of the stream, return that amount, else check for the amount */
2598 sample_offset = (ast_channel_stream(chan)) ? ast_tellstream(fs) : max_length;
2599 ast_stopstream(chan);
2600 if (res == 1) {
2601 /* Stop this command, don't print a result line, as there is a new command */
2602 return RESULT_SUCCESS;
2603 }
2604 ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, sample_offset);
2605 pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", res ? "FAILED" : "SUCCESS");
2606
2607 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2608}
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)

References ast_agi_send(), ast_applystream(), ast_channel_language(), ast_channel_name(), ast_channel_stream(), ast_channel_writeformat(), ast_debug, ast_format_get_name(), ast_openstream(), ast_openvstream(), ast_playstream(), ast_seekstream(), ast_stopstream(), ast_tellstream(), ast_verb, ast_waitstream_full(), agi_state::audio, agi_state::ctrl, agi_state::fd, pbx_builtin_setvar_helper(), RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, S_OR, and ast_filestream::vfs.

◆ handle_tddmode()

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

Definition at line 2446 of file res_agi.c.

2447{
2448 int res, x;
2449
2450 if (argc != 3)
2451 return RESULT_SHOWUSAGE;
2452
2453 if (!strncasecmp(argv[2],"on",2)) {
2454 x = 1;
2455 } else {
2456 x = 0;
2457 }
2458 if (!strncasecmp(argv[2],"mate",4)) {
2459 x = 2;
2460 }
2461 if (!strncasecmp(argv[2],"tdd",3)) {
2462 x = 1;
2463 }
2464 res = ast_channel_setoption(chan, AST_OPTION_TDD, &x, sizeof(char), 0);
2465 if (res) {
2466 /* Set channel option failed */
2467 ast_agi_send(agi->fd, chan, "200 result=0\n");
2468 } else {
2469 ast_agi_send(agi->fd, chan, "200 result=1\n");
2470 }
2471 return RESULT_SUCCESS;
2472}
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition: channel.c:7422
#define AST_OPTION_TDD

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

◆ handle_verbose()

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

Definition at line 3305 of file res_agi.c.

3306{
3307 int level = 0;
3308
3309 if (argc < 2)
3310 return RESULT_SHOWUSAGE;
3311
3312 if (argv[2])
3313 sscanf(argv[2], "%30d", &level);
3314
3315 ast_verb(level, "%s: %s\n", ast_channel_data(chan), argv[1]);
3316
3317 ast_agi_send(agi->fd, chan, "200 result=1\n");
3318
3319 return RESULT_SUCCESS;
3320}
const char * ast_channel_data(const struct ast_channel *chan)

References ast_agi_send(), ast_channel_data(), ast_verb, agi_state::fd, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

◆ handle_waitfordigit()

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

Definition at line 2377 of file res_agi.c.

2378{
2379 int res, to;
2380
2381 if (argc != 4)
2382 return RESULT_SHOWUSAGE;
2383 if (sscanf(argv[3], "%30d", &to) != 1)
2384 return RESULT_SHOWUSAGE;
2385 res = ast_waitfordigit_full(chan, to, NULL, agi->audio, agi->ctrl);
2386 ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
2387 return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
2388}

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

◆ help_workhorse()

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

Definition at line 3789 of file res_agi.c.

3790{
3791 char fullcmd[MAX_CMD_LEN], matchstr[MAX_CMD_LEN];
3792 struct agi_command *e;
3793
3794 if (match)
3795 ast_join(matchstr, sizeof(matchstr), match);
3796
3797 ast_cli(fd, "%5.5s %30.30s %s\n","Dead","Command","Description");
3800 if (!e->cmda[0])
3801 break;
3802 /* Hide commands that start with '_' */
3803 if ((e->cmda[0])[0] == '_')
3804 continue;
3805 ast_join(fullcmd, sizeof(fullcmd), e->cmda);
3806 if (match && strncasecmp(matchstr, fullcmd, strlen(matchstr)))
3807 continue;
3808 ast_cli(fd, "%5.5s %30.30s %s\n", e->dead ? "Yes" : "No" , fullcmd, S_OR(e->summary, "Not available"));
3809 }
3811
3812 return CLI_SUCCESS;
3813}

References ast_cli(), ast_join, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_SUCCESS, agi_command::cmda, agi_command::dead, agi_command::list, match(), MAX_CMD_LEN, S_OR, and agi_command::summary.

Referenced by handle_cli_agi_show().

◆ launch_asyncagi()

static enum agi_result launch_asyncagi ( struct ast_channel chan,
int  argc,
char *  argv[],
int *  efd 
)
static

Definition at line 1782 of file res_agi.c.

1783{
1784/* This buffer sizes might cause truncation if the AGI command writes more data
1785 than AGI_BUF_SIZE as result. But let's be serious, is there an AGI command
1786 that writes a response larger than 1024 bytes?, I don't think so, most of
1787 them are just result=blah stuff. However probably if GET VARIABLE is called
1788 and the variable has large amount of data, that could be a problem. We could
1789 make this buffers dynamic, but let's leave that as a second step.
1790
1791 AMI_BUF_SIZE is twice AGI_BUF_SIZE just for the sake of choosing a safe
1792 number. Some characters of AGI buf will be url encoded to be sent to manager
1793 clients. An URL encoded character will take 3 bytes, but again, to cause
1794 truncation more than about 70% of the AGI buffer should be URL encoded for
1795 that to happen. Not likely at all.
1796
1797 On the other hand. I wonder if read() could eventually return less data than
1798 the amount already available in the pipe? If so, how to deal with that?
1799 So far, my tests on Linux have not had any problems.
1800 */
1801#define AGI_BUF_SIZE 1024
1802#define AMI_BUF_SIZE 2048
1803 enum agi_result cmd_status;
1804 struct agi_cmd *cmd;
1805 int res;
1806 int fds[2];
1807 int hungup;
1808 int timeout = 100;
1809 char agi_buffer[AGI_BUF_SIZE + 1];
1810 char ami_buffer[AMI_BUF_SIZE];
1811 enum agi_result returnstatus = AGI_RESULT_SUCCESS;
1812 AGI async_agi;
1813 RAII_VAR(struct ast_json *, startblob, NULL, ast_json_unref);
1814
1815 if (efd) {
1816 ast_log(LOG_WARNING, "Async AGI does not support Enhanced AGI yet\n");
1817 return AGI_RESULT_FAILURE;
1818 }
1819
1820 /* add AsyncAGI datastore to the channel */
1821 if (add_to_agi(chan)) {
1822 ast_log(LOG_ERROR, "Failed to start Async AGI on channel %s\n", ast_channel_name(chan));
1823 return AGI_RESULT_FAILURE;
1824 }
1825
1826 /* this pipe allows us to create a "fake" AGI struct to use
1827 the AGI commands */
1828 res = pipe(fds);
1829 if (res) {
1830 ast_log(LOG_ERROR, "Failed to create Async AGI pipe\n");
1831 /*
1832 * Intentionally do not remove the datastore added with
1833 * add_to_agi() the from channel. It will be removed when the
1834 * channel is hung up anyway.
1835 */
1836 return AGI_RESULT_FAILURE;
1837 }
1838
1839 /* handlers will get the pipe write fd and we read the AGI responses
1840 from the pipe read fd */
1841 async_agi.fd = fds[1];
1842 async_agi.ctrl = fds[1];
1843 async_agi.audio = -1; /* no audio support */
1844 async_agi.fast = 0;
1845 async_agi.speech = NULL;
1846
1847 /* notify possible manager users of a new channel ready to
1848 receive commands */
1849 setup_env(chan, "async", fds[1], 0, argc, argv);
1850 /* read the environment */
1851 res = read(fds[0], agi_buffer, AGI_BUF_SIZE);
1852 if (res <= 0) {
1853 ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s: %s\n",
1854 ast_channel_name(chan), res < 0 ? strerror(errno) : "EOF");
1855 returnstatus = AGI_RESULT_FAILURE;
1856 goto async_agi_abort;
1857 }
1858 agi_buffer[res] = '\0';
1859 /* encode it and send it thru the manager so whoever is going to take
1860 care of AGI commands on this channel can decide which AGI commands
1861 to execute based on the setup info */
1862 ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
1863 startblob = ast_json_pack("{s: s}", "Env", ami_buffer);
1864
1865 ast_channel_publish_cached_blob(chan, agi_async_start_type(), startblob);
1866
1867 hungup = ast_check_hangup_locked(chan);
1868
1869 for (;;) {
1870 /*
1871 * Process as many commands as we can. Commands are added via
1872 * the manager or the cli threads.
1873 */
1874 while (!hungup) {
1875 RAII_VAR(struct ast_json *, execblob, NULL, ast_json_unref);
1876 res = get_agi_cmd(chan, &cmd);
1877
1878 if (res) {
1879 returnstatus = AGI_RESULT_FAILURE;
1880 goto async_agi_done;
1881 } else if (!cmd) {
1882 break;
1883 }
1884
1885 /* OK, we have a command, let's call the command handler. */
1886 cmd_status = agi_handle_command(chan, &async_agi, cmd->cmd_buffer, 0);
1887
1888 /*
1889 * The command handler must have written to our fake AGI struct
1890 * fd (the pipe), let's read the response.
1891 */
1892 res = read(fds[0], agi_buffer, AGI_BUF_SIZE);
1893 if (res <= 0) {
1894 ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s: %s\n",
1895 ast_channel_name(chan), res < 0 ? strerror(errno) : "EOF");
1896 free_agi_cmd(cmd);
1897 returnstatus = AGI_RESULT_FAILURE;
1898 goto async_agi_done;
1899 }
1900 /*
1901 * We have a response, let's send the response thru the manager.
1902 * Include the CommandID if it was specified when the command
1903 * was added.
1904 */
1905 agi_buffer[res] = '\0';
1906 ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
1907
1908 execblob = ast_json_pack("{s: s}", "Result", ami_buffer);
1909 if (execblob && !ast_strlen_zero(cmd->cmd_id)) {
1910 ast_json_object_set(execblob, "CommandId", ast_json_string_create(cmd->cmd_id));
1911 }
1912 ast_channel_publish_cached_blob(chan, agi_async_exec_type(), execblob);
1913
1914 free_agi_cmd(cmd);
1915
1916 /*
1917 * Check the command status to determine if we should continue
1918 * executing more commands.
1919 */
1920 hungup = ast_check_hangup(chan);
1921 switch (cmd_status) {
1922 case AGI_RESULT_FAILURE:
1923 if (!hungup) {
1924 /* The failure was not because of a hangup. */
1925 returnstatus = AGI_RESULT_FAILURE;
1926 goto async_agi_done;
1927 }
1928 break;
1930 /* Only the "asyncagi break" command does this. */
1931 returnstatus = AGI_RESULT_SUCCESS_ASYNC;
1932 goto async_agi_done;
1933 default:
1934 break;
1935 }
1936 }
1937
1938 if (!hungup) {
1939 /* Wait a bit for a frame to read or to poll for a new command. */
1940 res = ast_waitfor(chan, timeout);
1941 if (res < 0) {
1942 ast_debug(1, "ast_waitfor returned <= 0 on chan %s\n", ast_channel_name(chan));
1943 returnstatus = AGI_RESULT_FAILURE;
1944 break;
1945 }
1946 } else {
1947 /*
1948 * Read the channel control queue until it is dry so we can
1949 * quit.
1950 */
1951 res = 1;
1952 }
1953 if (0 < res) {
1954 do {
1955 cmd_status = async_agi_read_frame(chan);
1956 if (cmd_status != AGI_RESULT_SUCCESS) {
1957 returnstatus = cmd_status;
1958 goto async_agi_done;
1959 }
1960 hungup = ast_check_hangup(chan);
1961 } while (hungup);
1962 } else {
1963 hungup = ast_check_hangup(chan);
1964 }
1965 }
1966async_agi_done:
1967
1968 if (async_agi.speech) {
1969 ast_speech_destroy(async_agi.speech);
1970 }
1971 /* notify manager users this channel cannot be controlled anymore by Async AGI */
1972 ast_channel_publish_cached_blob(chan, agi_async_end_type(), NULL);
1973
1974async_agi_abort:
1975 /* close the pipe */
1976 close(fds[0]);
1977 close(fds[1]);
1978
1979 /*
1980 * Intentionally do not remove the datastore added with
1981 * add_to_agi() the from channel. There might be commands still
1982 * in the queue or in-flight to us and AsyncAGI may get called
1983 * again. The datastore destructor will be called on channel
1984 * destruction anyway.
1985 */
1986
1987 if (returnstatus == AGI_RESULT_SUCCESS) {
1988 returnstatus = AGI_RESULT_SUCCESS_ASYNC;
1989 }
1990 return returnstatus;
1991
1992#undef AGI_BUF_SIZE
1993#undef AMI_BUF_SIZE
1994}
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:459
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:278
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
static void setup_env(struct ast_channel *chan, char *request, int fd, int enhanced, int argc, char *argv[])
Definition: res_agi.c:2313
#define AMI_BUF_SIZE
static enum agi_result async_agi_read_frame(struct ast_channel *chan)
Definition: res_agi.c:1754
static int add_to_agi(struct ast_channel *chan)
Definition: res_agi.c:1608
static int get_agi_cmd(struct ast_channel *chan, struct agi_cmd **cmd)
Retrieve the list head to the requested channel's AGI datastore.
Definition: res_agi.c:1553
#define AGI_BUF_SIZE
static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead)
Definition: res_agi.c:4053
unsigned int fast
Definition: agi.h:38
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
Definition: utils.c:723
const struct ast_flags ast_uri_http
Definition: utils.c:719

References add_to_agi(), AGI_BUF_SIZE, agi_handle_command(), AGI_RESULT_FAILURE, AGI_RESULT_SUCCESS, AGI_RESULT_SUCCESS_ASYNC, AMI_BUF_SIZE, ast_channel_name(), ast_channel_publish_cached_blob(), ast_check_hangup(), ast_check_hangup_locked(), ast_debug, ast_json_object_set(), ast_json_pack(), ast_json_string_create(), ast_json_unref(), ast_log, ast_speech_destroy(), ast_strlen_zero(), ast_uri_encode(), ast_uri_http, ast_waitfor(), async_agi_read_frame(), agi_state::audio, agi_cmd::cmd_buffer, agi_cmd::cmd_id, agi_state::ctrl, errno, agi_state::fast, agi_state::fd, free_agi_cmd(), get_agi_cmd(), LOG_ERROR, LOG_WARNING, NULL, RAII_VAR, setup_env(), and agi_state::speech.

Referenced by launch_script().

◆ launch_ha_netscript()

static enum agi_result launch_ha_netscript ( char *  agiurl,
char *  argv[],
int *  fds 
)
static

Definition at line 2141 of file res_agi.c.

2142{
2143 char *host, *script;
2144 enum agi_result result;
2145 struct srv_context *context = NULL;
2146 int srv_ret;
2147 char service[256];
2148 char resolved_uri[1024];
2149 const char *srvhost;
2150 unsigned short srvport;
2151
2152 /* format of agiurl is "hagi://host.domain[:port][/script/name]" */
2153 if (strlen(agiurl) < 7) { /* Remove hagi:// */
2154 ast_log(LOG_WARNING, "An error occurred parsing the AGI URI: %s", agiurl);
2155 return AGI_RESULT_FAILURE;
2156 }
2157 host = ast_strdupa(agiurl + 7);
2158
2159 /* Strip off any script name */
2160 if ((script = strchr(host, '/'))) {
2161 *script++ = '\0';
2162 } else {
2163 script = "";
2164 }
2165
2166 if (strchr(host, ':')) {
2167 ast_log(LOG_WARNING, "Specifying a port number disables SRV lookups: %s\n", agiurl);
2168 return launch_netscript(agiurl + 1, argv, fds); /* +1 to strip off leading h from hagi:// */
2169 }
2170
2171 snprintf(service, sizeof(service), "%s%s", SRV_PREFIX, host);
2172
2173 while (!(srv_ret = ast_srv_lookup(&context, service, &srvhost, &srvport))) {
2174 snprintf(resolved_uri, sizeof(resolved_uri), "agi://%s:%d/%s", srvhost, srvport, script);
2175 result = launch_netscript(resolved_uri, argv, fds);
2177 ast_log(LOG_WARNING, "AGI request failed for host '%s' (%s:%d)\n", host, srvhost, srvport);
2178 } else {
2179 /* The script launched so we must cleanup the context. */
2181 return result;
2182 }
2183 }
2184 /*
2185 * The DNS SRV lookup failed or we ran out of servers to check.
2186 * ast_srv_lookup() has already cleaned up the context for us.
2187 */
2188 if (srv_ret < 0) {
2189 ast_log(LOG_WARNING, "SRV lookup failed for %s\n", agiurl);
2190 }
2191
2192 return AGI_RESULT_FAILURE;
2193}
enum ast_cc_service_type service
Definition: ccss.c:383
static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds)
Definition: res_agi.c:2048
#define SRV_PREFIX
Definition: res_agi.c:1387
void ast_srv_cleanup(struct srv_context **context)
Cleanup resources associated with ast_srv_lookup.
Definition: srv.c:248
int ast_srv_lookup(struct srv_context **context, const char *service, const char **host, unsigned short *port)
Retrieve set of SRV lookups, in order.
Definition: srv.c:202

References AGI_RESULT_FAILURE, AGI_RESULT_NOTFOUND, ast_log, ast_srv_cleanup(), ast_srv_lookup(), ast_strdupa, voicemailpwcheck::context, launch_netscript(), LOG_WARNING, NULL, result, service, and SRV_PREFIX.

Referenced by launch_script().

◆ launch_netscript()

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

Definition at line 2048 of file res_agi.c.

2049{
2050 int s = 0;
2051 char *host, *script;
2052 int num_addrs = 0, i = 0;
2053 struct ast_sockaddr *addrs;
2054
2055 /* agiurl is "agi://host.domain[:port][/script/name]" */
2056 host = ast_strdupa(agiurl + 6); /* Remove agi:// */
2057
2058 /* Strip off any script name */
2059 if ((script = strchr(host, '/'))) {
2060 *script++ = '\0';
2061 } else {
2062 script = "";
2063 }
2064
2065 if (!(num_addrs = ast_sockaddr_resolve(&addrs, host, 0, AST_AF_UNSPEC))) {
2066 ast_log(LOG_WARNING, "Unable to locate host '%s'\n", host);
2067 return AGI_RESULT_FAILURE;
2068 }
2069
2070 for (i = 0; i < num_addrs; i++) {
2071 if (!ast_sockaddr_port(&addrs[i])) {
2072 ast_sockaddr_set_port(&addrs[i], AGI_PORT);
2073 }
2074
2075 if ((s = ast_socket_nonblock(addrs[i].ss.ss_family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
2076 ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
2077 continue;
2078 }
2079
2080 if (ast_connect(s, &addrs[i]) && errno == EINPROGRESS) {
2081
2082 if (handle_connection(agiurl, addrs[i], s)) {
2083 close(s);
2084 continue;
2085 }
2086
2087 } else {
2088 ast_log(LOG_WARNING, "Connection to %s failed with unexpected error: %s\n",
2089 ast_sockaddr_stringify(&addrs[i]), strerror(errno));
2090 }
2091
2092 break;
2093 }
2094
2095 ast_free(addrs);
2096
2097 if (i == num_addrs) {
2098 ast_log(LOG_WARNING, "Couldn't connect to any host. FastAGI failed.\n");
2099 return AGI_RESULT_FAILURE;
2100 }
2101
2102 if (ast_agi_send(s, NULL, "agi_network: yes\n") < 0) {
2103 if (errno != EINTR) {
2104 ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
2105 close(s);
2106 return AGI_RESULT_FAILURE;
2107 }
2108 }
2109
2110 /* If we have a script parameter, relay it to the fastagi server */
2111 /* Script parameters take the form of: AGI(agi://my.example.com/?extension=${EXTEN}) */
2112 if (!ast_strlen_zero(script)) {
2113 ast_agi_send(s, NULL, "agi_network_script: %s\n", script);
2114 }
2115
2116 ast_debug(4, "Wow, connected!\n");
2117 fds[0] = s;
2118 fds[1] = s;
2120}
@ AST_AF_UNSPEC
Definition: netsock2.h:54
int ast_connect(int sockfd, const struct ast_sockaddr *addr)
Wrapper around connect(2) that uses struct ast_sockaddr.
Definition: netsock2.c:595
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Definition: netsock2.h:517
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
Definition: netsock2.c:280
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition: netsock2.h:532
static int handle_connection(const char *agiurl, const struct ast_sockaddr addr, const int netsockfd)
Definition: res_agi.c:2007
#define AGI_PORT
Definition: res_agi.c:1402
Socket address structure.
Definition: netsock2.h:97
struct sockaddr_storage ss
Definition: netsock2.h:98
#define ast_socket_nonblock(domain, type, protocol)
Create a non-blocking socket.
Definition: utils.h:1073

References AGI_PORT, AGI_RESULT_FAILURE, AGI_RESULT_SUCCESS_FAST, AST_AF_UNSPEC, ast_agi_send(), ast_connect(), ast_debug, ast_free, ast_log, ast_sockaddr_port, ast_sockaddr_resolve(), ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_socket_nonblock, ast_strdupa, ast_strlen_zero(), errno, handle_connection(), LOG_WARNING, NULL, and ast_sockaddr::ss.

Referenced by launch_ha_netscript(), and launch_script().

◆ launch_script()

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

Definition at line 2195 of file res_agi.c.

2196{
2197 char tmp[256];
2198 int pid, toast[2], fromast[2], audio[2], res;
2199 struct stat st;
2200
2201 if (!strncasecmp(script, "agi://", 6)) {
2202 return (efd == NULL) ? launch_netscript(script, argv, fds) : AGI_RESULT_FAILURE;
2203 }
2204 if (!strncasecmp(script, "hagi://", 7)) {
2205 return (efd == NULL) ? launch_ha_netscript(script, argv, fds) : AGI_RESULT_FAILURE;
2206 }
2207 if (!strncasecmp(script, "agi:async", sizeof("agi:async") - 1)) {
2208 return launch_asyncagi(chan, argc, argv, efd);
2209 }
2210
2211 if (script[0] != '/') {
2212 snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_AGI_DIR, script);
2213 script = tmp;
2214 }
2215
2216 /* Before even trying let's see if the file actually exists */
2217 if (stat(script, &st)) {
2218 ast_log(LOG_WARNING, "Failed to execute '%s': File does not exist.\n", script);
2219 return AGI_RESULT_NOTFOUND;
2220 }
2221
2222 if (pipe(toast)) {
2223 ast_log(LOG_WARNING, "Unable to create toast pipe: %s\n",strerror(errno));
2224 return AGI_RESULT_FAILURE;
2225 }
2226 if (pipe(fromast)) {
2227 ast_log(LOG_WARNING, "unable to create fromast pipe: %s\n", strerror(errno));
2228 close(toast[0]);
2229 close(toast[1]);
2230 return AGI_RESULT_FAILURE;
2231 }
2232 if (efd) {
2233 if (pipe(audio)) {
2234 ast_log(LOG_WARNING, "unable to create audio pipe: %s\n", strerror(errno));
2235 close(fromast[0]);
2236 close(fromast[1]);
2237 close(toast[0]);
2238 close(toast[1]);
2239 return AGI_RESULT_FAILURE;
2240 }
2241
2242 res = ast_fd_set_flags(audio[1], O_NONBLOCK);
2243 if (res < 0) {
2244 ast_log(LOG_WARNING, "unable to set audio pipe parameters: %s\n", strerror(errno));
2245 close(fromast[0]);
2246 close(fromast[1]);
2247 close(toast[0]);
2248 close(toast[1]);
2249 close(audio[0]);
2250 close(audio[1]);
2251 return AGI_RESULT_FAILURE;
2252 }
2253 }
2254
2255 if ((pid = ast_safe_fork(1)) < 0) {
2256 ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
2257 return AGI_RESULT_FAILURE;
2258 }
2259 if (!pid) {
2260 /* Pass paths to AGI via environmental variables */
2261 setenv("AST_CONFIG_DIR", ast_config_AST_CONFIG_DIR, 1);
2262 setenv("AST_CONFIG_FILE", ast_config_AST_CONFIG_FILE, 1);
2263 setenv("AST_MODULE_DIR", ast_config_AST_MODULE_DIR, 1);
2264 setenv("AST_SPOOL_DIR", ast_config_AST_SPOOL_DIR, 1);
2265 setenv("AST_MONITOR_DIR", ast_config_AST_MONITOR_DIR, 1);
2266 setenv("AST_VAR_DIR", ast_config_AST_VAR_DIR, 1);
2267 setenv("AST_DATA_DIR", ast_config_AST_DATA_DIR, 1);
2268 setenv("AST_LOG_DIR", ast_config_AST_LOG_DIR, 1);
2269 setenv("AST_AGI_DIR", ast_config_AST_AGI_DIR, 1);
2270 setenv("AST_KEY_DIR", ast_config_AST_KEY_DIR, 1);
2271 setenv("AST_RUN_DIR", ast_config_AST_RUN_DIR, 1);
2272
2273 /* Don't run AGI scripts with realtime priority -- it causes audio stutter */
2275
2276 /* Redirect stdin and out, provide enhanced audio channel if desired */
2277 dup2(fromast[0], STDIN_FILENO);
2278 dup2(toast[1], STDOUT_FILENO);
2279 if (efd)
2280 dup2(audio[0], STDERR_FILENO + 1);
2281 else
2282 close(STDERR_FILENO + 1);
2283
2284 /* Close everything but stdin/out/error */
2285 ast_close_fds_above_n(STDERR_FILENO + 1);
2286
2287 /* Execute script */
2288 /* XXX argv should be deprecated in favor of passing agi_argX paramaters */
2289 execv(script, argv);
2290 /* Can't use ast_log since FD's are closed */
2291 ast_child_verbose(1, "Failed to execute '%s': %s", script, strerror(errno));
2292 /* Special case to set status of AGI to failure */
2293 fprintf(stdout, "failure\n");
2294 fflush(stdout);
2295 _exit(1);
2296 }
2297 ast_verb(3, "Launched AGI Script %s\n", script);
2298 fds[0] = toast[0];
2299 fds[1] = fromast[1];
2300 if (efd)
2301 *efd = audio[1];
2302 /* close what we're not using in the parent */
2303 close(toast[1]);
2304 close(fromast[0]);
2305
2306 if (efd)
2307 close(audio[0]);
2308
2309 *opid = pid;
2310 return AGI_RESULT_SUCCESS;
2311}
int ast_set_priority(int)
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy ac...
Definition: asterisk.c:1837
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child.
Definition: main/app.c:3197
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
Definition: main/app.c:3192
int setenv(const char *name, const char *value, int overwrite)
void ast_child_verbose(int level, const char *fmt,...)
Definition: logger.c:909
const char * ast_config_AST_KEY_DIR
Definition: options.c:161
const char * ast_config_AST_MODULE_DIR
Definition: options.c:153
const char * ast_config_AST_RUN_DIR
Definition: options.c:162
const char * ast_config_AST_DATA_DIR
Definition: options.c:158
const char * ast_config_AST_CONFIG_DIR
Definition: options.c:151
const char * ast_config_AST_SPOOL_DIR
Definition: options.c:154
const char * ast_config_AST_AGI_DIR
Definition: options.c:160
const char * ast_config_AST_VAR_DIR
Definition: options.c:157
const char * ast_config_AST_CONFIG_FILE
Definition: options.c:152
const char * ast_config_AST_MONITOR_DIR
Definition: options.c:155
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
static enum agi_result launch_ha_netscript(char *agiurl, char *argv[], int *fds)
Definition: res_agi.c:2141
static enum agi_result launch_asyncagi(struct ast_channel *chan, int argc, char *argv[], int *efd)
Definition: res_agi.c:1782
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
Definition: utils.h:1039

References AGI_RESULT_FAILURE, AGI_RESULT_NOTFOUND, AGI_RESULT_SUCCESS, ast_child_verbose(), ast_close_fds_above_n(), 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_fd_set_flags, ast_log, ast_safe_fork(), ast_set_priority(), ast_verb, errno, launch_asyncagi(), launch_ha_netscript(), launch_netscript(), LOG_WARNING, NULL, setenv(), and tmp().

Referenced by agi_exec_full().

◆ load_module()

static int load_module ( void  )
static

Definition at line 4714 of file res_agi.c.

4715{
4716 int err = 0;
4717
4718 err |= STASIS_MESSAGE_TYPE_INIT(agi_exec_start_type);
4719 err |= STASIS_MESSAGE_TYPE_INIT(agi_exec_end_type);
4720 err |= STASIS_MESSAGE_TYPE_INIT(agi_async_start_type);
4721 err |= STASIS_MESSAGE_TYPE_INIT(agi_async_exec_type);
4722 err |= STASIS_MESSAGE_TYPE_INIT(agi_async_end_type);
4723
4730
4731 AST_TEST_REGISTER(test_agi_null_docs);
4732
4733 if (err) {
4734 unload_module();
4736 }
4737
4739}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:191
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
static char * eapp
Definition: res_agi.c:1391
static struct ast_cli_entry cli_agi[]
Definition: res_agi.c:4649
static int eagi_exec(struct ast_channel *chan, const char *data)
Definition: res_agi.c:4601
static char * deadapp
Definition: res_agi.c:1393
static char * app
Definition: res_agi.c:1389
static int action_add_agi_cmd(struct mansession *s, const struct message *m)
Add a new command to execute by the Async AGI application.
Definition: res_agi.c:1704
static struct agi_command commands[]
AGI commands list.
Definition: res_agi.c:3738
static int unload_module(void)
Definition: res_agi.c:4696
int AST_OPTIONAL_API_NAME() ast_agi_register_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len)
Registers a group of AGI commands, provided as an array of struct agi_command entries.
Definition: res_agi.c:3895
static int deadagi_exec(struct ast_channel *chan, const char *data)
Definition: res_agi.c:4643
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493
struct ast_module * self
Definition: module.h:342
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
#define ARRAY_LEN(a)
Definition: utils.h:666

References action_add_agi_cmd(), agi_exec(), app, ARRAY_LEN, ast_agi_register_multiple(), ast_cli_register_multiple, ast_manager_register_xml, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, AST_TEST_REGISTER, cli_agi, commands, deadagi_exec(), deadapp, eagi_exec(), eapp, EVENT_FLAG_AGI, ast_module_info::self, STASIS_MESSAGE_TYPE_INIT, and unload_module().

◆ parse_args()

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

Definition at line 3979 of file res_agi.c.

3980{
3981 int x = 0, quoted = 0, escaped = 0, whitespace = 1;
3982 char *cur;
3983
3984 cur = s;
3985 while(*s) {
3986 switch(*s) {
3987 case '"':
3988 /* If it's escaped, put a literal quote */
3989 if (escaped)
3990 goto normal;
3991 else
3992 quoted = !quoted;
3993 if (quoted && whitespace) {
3994 /* If we're starting a quote, coming off white space start a new word, too */
3995 argv[x++] = cur;
3996 whitespace=0;
3997 }
3998 escaped = 0;
3999 break;
4000 case ' ':
4001 case '\t':
4002 if (!quoted && !escaped) {
4003 /* If we're not quoted, mark this as whitespace, and
4004 end the previous argument */
4005 whitespace = 1;
4006 *(cur++) = '\0';
4007 } else
4008 /* Otherwise, just treat it as anything else */
4009 goto normal;
4010 break;
4011 case '\\':
4012 /* If we're escaped, print a literal, otherwise enable escaping */
4013 if (escaped) {
4014 goto normal;
4015 } else {
4016 escaped=1;
4017 }
4018 break;
4019 default:
4020normal:
4021 if (whitespace) {
4022 if (x >= MAX_ARGS -1) {
4023 ast_log(LOG_WARNING, "Too many arguments, truncating\n");
4024 break;
4025 }
4026 /* Coming off of whitespace, start the next argument */
4027 argv[x++] = cur;
4028 whitespace=0;
4029 }
4030 *(cur++) = *s;
4031 escaped=0;
4032 }
4033 s++;
4034 }
4035 /* Null terminate */
4036 *(cur++) = '\0';
4037 argv[x] = NULL;
4038 *max = x;
4039 return 0;
4040}

References ast_log, LOG_WARNING, max, MAX_ARGS, and NULL.

Referenced by agi_handle_command().

◆ publish_async_exec_end()

static void publish_async_exec_end ( struct ast_channel chan,
int  command_id,
const char *  command,
int  result_code,
const char *  result 
)
static

Definition at line 4042 of file res_agi.c.

4043{
4044 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
4045 blob = ast_json_pack("{s: i, s: s, s: i, s: s}",
4046 "CommandId", command_id,
4047 "Command", command,
4048 "ResultCode", result_code,
4049 "Result", result);
4050 ast_channel_publish_cached_blob(chan, agi_exec_end_type(), blob);
4051}

References ast_channel_publish_cached_blob(), ast_json_pack(), ast_json_unref(), NULL, RAII_VAR, and result.

Referenced by agi_handle_command().

◆ run_agi()

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

Running in an interception routine is like DeadAGI mode. No touchy the channel frames.

Definition at line 4144 of file res_agi.c.

4145{
4146 struct ast_channel *c;
4147 int outfd;
4148 int ms;
4149 int needhup = 0;
4150 enum agi_result returnstatus = AGI_RESULT_SUCCESS;
4151 struct ast_frame *f;
4152 char buf[AGI_BUF_LEN];
4153 char *res = NULL;
4154 FILE *readf;
4155 /* how many times we'll retry if ast_waitfor_nandfs will return without either
4156 channel or file descriptor in case select is interrupted by a system call (EINTR) */
4157 int retry = AGI_NANDFS_RETRY;
4158 int send_sighup;
4159 const char *sighup_str;
4160 const char *exit_on_hangup_str;
4161 int exit_on_hangup;
4162 /*! Running in an interception routine is like DeadAGI mode. No touchy the channel frames. */
4163 int in_intercept = ast_channel_get_intercept_mode();
4164
4165 ast_channel_lock(chan);
4166 sighup_str = pbx_builtin_getvar_helper(chan, "AGISIGHUP");
4167 send_sighup = !ast_false(sighup_str);
4168 exit_on_hangup_str = pbx_builtin_getvar_helper(chan, "AGIEXITONHANGUP");
4169 exit_on_hangup = ast_true(exit_on_hangup_str);
4170 ast_channel_unlock(chan);
4171
4172 if (!(readf = fdopen(agi->ctrl, "r"))) {
4173 ast_log(LOG_WARNING, "Unable to fdopen file descriptor\n");
4174 if (send_sighup && pid > -1)
4175 kill(pid, SIGHUP);
4176 close(agi->ctrl);
4177 return AGI_RESULT_FAILURE;
4178 }
4179
4180 setlinebuf(readf);
4181 setup_env(chan, request, agi->fd, (agi->audio > -1), argc, argv);
4182 for (;;) {
4183 if (needhup) {
4184 needhup = 0;
4185 dead = 1;
4186 if (send_sighup) {
4187 if (pid > -1) {
4188 kill(pid, SIGHUP);
4189 } else if (agi->fast) {
4190 ast_agi_send(agi->fd, chan, "HANGUP\n");
4191 }
4192 }
4193 if (exit_on_hangup) {
4194 break;
4195 }
4196 }
4197 ms = -1;
4198 if (dead || in_intercept) {
4199 c = ast_waitfor_nandfds(&chan, 0, &agi->ctrl, 1, NULL, &outfd, &ms);
4200 } else if (!ast_check_hangup(chan)) {
4201 c = ast_waitfor_nandfds(&chan, 1, &agi->ctrl, 1, NULL, &outfd, &ms);
4202 } else {
4203 /*
4204 * Read the channel control queue until it is dry so we can
4205 * switch to dead mode.
4206 */
4207 c = chan;
4208 }
4209 if (c) {
4210 retry = AGI_NANDFS_RETRY;
4211 /* Idle the channel until we get a command */
4212 f = ast_read(c);
4213 if (!f) {
4214 ast_debug(1, "%s hungup\n", ast_channel_name(chan));
4215 needhup = 1;
4216 if (!returnstatus) {
4217 returnstatus = AGI_RESULT_HANGUP;
4218 }
4219 } else {
4220 /* If it's voice, write it to the audio pipe */
4221 if ((agi->audio > -1) && (f->frametype == AST_FRAME_VOICE)) {
4222 /* Write, ignoring errors */
4223 if (write(agi->audio, f->data.ptr, f->datalen) < 0) {
4224 }
4225 }
4226 ast_frfree(f);
4227 }
4228 } else if (outfd > -1) {
4229 size_t len = sizeof(buf);
4230 size_t buflen = 0;
4231 enum agi_result cmd_status;
4232
4233 retry = AGI_NANDFS_RETRY;
4234 buf[0] = '\0';
4235
4236 while (len > 1) {
4237 res = fgets(buf + buflen, len, readf);
4238 if (feof(readf))
4239 break;
4240 if (ferror(readf) && ((errno != EINTR) && (errno != EAGAIN)))
4241 break;
4242 if (res != NULL && !agi->fast)
4243 break;
4244 buflen = strlen(buf);
4245 if (buflen && buf[buflen - 1] == '\n')
4246 break;
4247 len = sizeof(buf) - buflen;
4248 if (agidebug)
4249 ast_verbose("AGI Rx << temp buffer %s - errno %s\nNo \\n received, checking again.\n", buf, strerror(errno));
4250 }
4251
4252 if (!buf[0]) {
4253 /* Program terminated */
4254 ast_verb(3, "<%s>AGI Script %s completed, returning %d\n", ast_channel_name(chan), request, returnstatus);
4255 if (pid > 0)
4256 waitpid(pid, status, 0);
4257 /* No need to kill the pid anymore, since they closed us */
4258 pid = -1;
4259 break;
4260 }
4261
4262 /* Special case for inability to execute child process */
4263 if (*buf && strncasecmp(buf, "failure", 7) == 0) {
4264 returnstatus = AGI_RESULT_FAILURE;
4265 break;
4266 }
4267
4268 /* get rid of trailing newline, if any */
4269 buflen = strlen(buf);
4270 if (buflen && buf[buflen - 1] == '\n') {
4271 buf[buflen - 1] = '\0';
4272 }
4273
4274 if (agidebug)
4275 ast_verbose("<%s>AGI Rx << %s\n", ast_channel_name(chan), buf);
4276 cmd_status = agi_handle_command(chan, agi, buf, dead || in_intercept);
4277 switch (cmd_status) {
4278 case AGI_RESULT_FAILURE:
4279 if (dead || in_intercept || !ast_check_hangup(chan)) {
4280 /* The failure was not because of a hangup. */
4281 returnstatus = AGI_RESULT_FAILURE;
4282 }
4283 break;
4284 default:
4285 break;
4286 }
4287 } else {
4288 if (--retry <= 0) {
4289 ast_log(LOG_WARNING, "No channel, no fd?\n");
4290 returnstatus = AGI_RESULT_FAILURE;
4291 break;
4292 }
4293 }
4294 }
4295
4296 if (agi->speech) {
4298 }
4299 /* Notify process */
4300 if (send_sighup) {
4301 if (pid > -1) {
4302 if (kill(pid, SIGHUP)) {
4303 ast_log(LOG_WARNING, "unable to send SIGHUP to AGI process %d: %s\n", pid, strerror(errno));
4304 } else { /* Give the process a chance to die */
4305 usleep(1);
4306 }
4307 waitpid(pid, status, WNOHANG);
4308 } else if (agi->fast) {
4309 ast_agi_send(agi->fd, chan, "HANGUP\n");
4310 }
4311 }
4312 fclose(readf);
4313 return returnstatus;
4314}
static int request(void *obj)
Definition: chan_pjsip.c:2601
struct ast_channel * ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
Waits for activity on a group of channels.
Definition: channel.c:2988
int ast_channel_get_intercept_mode(void)
Am I currently running an intercept dialplan routine.
Definition: channel.c:10333
#define AGI_NANDFS_RETRY
Definition: res_agi.c:1385
#define AGI_BUF_LEN
Definition: res_agi.c:1386
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"....
Definition: utils.c:2216

References AGI_BUF_LEN, agi_handle_command(), AGI_NANDFS_RETRY, AGI_RESULT_FAILURE, AGI_RESULT_HANGUP, AGI_RESULT_SUCCESS, agidebug, ast_agi_send(), ast_channel_get_intercept_mode(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_check_hangup(), ast_debug, ast_false(), AST_FRAME_VOICE, ast_frfree, ast_log, ast_read(), ast_speech_destroy(), ast_true(), ast_verb, ast_verbose(), ast_waitfor_nandfds(), agi_state::audio, buf, c, agi_state::ctrl, ast_frame::data, ast_frame::datalen, errno, agi_state::fast, agi_state::fd, ast_frame::frametype, len(), LOG_WARNING, NULL, pbx_builtin_getvar_helper(), ast_frame::ptr, request(), setup_env(), agi_state::speech, and status.

Referenced by agi_exec_full().

◆ setup_env()

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

Definition at line 2313 of file res_agi.c.

2314{
2315 int count;
2316
2317 /* Print initial environment, with agi_request always being the first
2318 thing */
2319 ast_agi_send(fd, chan, "agi_request: %s\n", request);
2320 ast_agi_send(fd, chan, "agi_channel: %s\n", ast_channel_name(chan));
2321 ast_agi_send(fd, chan, "agi_language: %s\n", ast_channel_language(chan));
2322 ast_agi_send(fd, chan, "agi_type: %s\n", ast_channel_tech(chan)->type);
2323 ast_agi_send(fd, chan, "agi_uniqueid: %s\n", ast_channel_uniqueid(chan));
2324 ast_agi_send(fd, chan, "agi_version: %s\n", ast_get_version());
2325
2326 /* ANI/DNIS */
2327 ast_agi_send(fd, chan, "agi_callerid: %s\n",
2328 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, "unknown"));
2329 ast_agi_send(fd, chan, "agi_calleridname: %s\n",
2330 S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, "unknown"));
2331 ast_agi_send(fd, chan, "agi_callingpres: %d\n",
2333 ast_agi_send(fd, chan, "agi_callingani2: %d\n", ast_channel_caller(chan)->ani2);
2334 ast_agi_send(fd, chan, "agi_callington: %d\n", ast_channel_caller(chan)->id.number.plan);
2335 ast_agi_send(fd, chan, "agi_callingtns: %d\n", ast_channel_dialed(chan)->transit_network_select);
2336 ast_agi_send(fd, chan, "agi_dnid: %s\n", S_OR(ast_channel_dialed(chan)->number.str, "unknown"));
2337 ast_agi_send(fd, chan, "agi_rdnis: %s\n",
2338 S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, "unknown"));
2339
2340 /* Context information */
2341 ast_agi_send(fd, chan, "agi_context: %s\n", ast_channel_context(chan));
2342 ast_agi_send(fd, chan, "agi_extension: %s\n", ast_channel_exten(chan));
2343 ast_agi_send(fd, chan, "agi_priority: %d\n", ast_channel_priority(chan));
2344 ast_agi_send(fd, chan, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0");
2345
2346 /* User information */
2347 ast_agi_send(fd, chan, "agi_accountcode: %s\n", ast_channel_accountcode(chan) ? ast_channel_accountcode(chan) : "");
2348 ast_agi_send(fd, chan, "agi_threadid: %ld\n", (long)pthread_self());
2349
2350 /* Send any parameters to the fastagi server that have been passed via the agi application */
2351 /* Agi application paramaters take the form of: AGI(/path/to/example/script|${EXTEN}) */
2352 for(count = 1; count < argc; count++)
2353 ast_agi_send(fd, chan, "agi_arg_%d: %s\n", count, argv[count]);
2354
2355 /* End with empty return */
2356 ast_agi_send(fd, chan, "\n");
2357}
const char * ast_get_version(void)
Retrieve the Asterisk version string.
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:1821
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
int ast_channel_priority(const struct ast_channel *chan)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_channel_accountcode(const struct ast_channel *chan)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
static const char name[]
Definition: format_mp3.c:68

References ast_agi_send(), ast_channel_accountcode(), ast_channel_caller(), ast_channel_context(), ast_channel_dialed(), ast_channel_exten(), ast_channel_language(), ast_channel_name(), ast_channel_priority(), ast_channel_redirecting(), ast_channel_tech(), ast_channel_uniqueid(), ast_get_version(), ast_party_id_presentation(), name, request(), S_COR, S_OR, and type.

Referenced by launch_asyncagi(), and run_agi().

◆ speech_streamfile()

static int speech_streamfile ( struct ast_channel chan,
const char *  filename,
const char *  preflang,
int  offset 
)
static

Definition at line 3569 of file res_agi.c.

3570{
3571 struct ast_filestream *fs = NULL;
3572
3573 if (!(fs = ast_openstream(chan, filename, preflang)))
3574 return -1;
3575
3576 if (offset)
3577 ast_seekstream(fs, offset, SEEK_SET);
3578
3579 if (ast_applystream(chan, fs))
3580 return -1;
3581
3582 if (ast_playstream(fs))
3583 return -1;
3584
3585 return 0;
3586}
char * filename
Definition: mod_format.h:107

References ast_applystream(), ast_openstream(), ast_playstream(), ast_seekstream(), ast_filestream::filename, and NULL.

Referenced by handle_speechrecognize().

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL() [1/5]

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( agi_async_end_type  ,
to_ami = agi_async_end_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL() [2/5]

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( agi_async_exec_type  ,
to_ami = agi_async_exec_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL() [3/5]

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( agi_async_start_type  ,
to_ami = agi_async_start_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL() [4/5]

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( agi_exec_end_type  ,
to_ami = agi_exec_end_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL() [5/5]

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( agi_exec_start_type  ,
to_ami = agi_exec_start_to_ami 
)

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 4696 of file res_agi.c.

4697{
4698 STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_start_type);
4699 STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_end_type);
4700 STASIS_MESSAGE_TYPE_CLEANUP(agi_async_start_type);
4701 STASIS_MESSAGE_TYPE_CLEANUP(agi_async_exec_type);
4702 STASIS_MESSAGE_TYPE_CLEANUP(agi_async_end_type);
4703
4710 AST_TEST_UNREGISTER(test_agi_null_docs);
4711 return 0;
4712}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:8041
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
int AST_OPTIONAL_API_NAME() ast_agi_unregister_multiple(struct agi_command *cmd, unsigned int len)
Unregisters a group of AGI commands, provided as an array of struct agi_command entries.
Definition: res_agi.c:3925
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1515
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References app, ARRAY_LEN, ast_agi_unregister_multiple(), ast_cli_unregister_multiple(), ast_manager_unregister(), AST_TEST_UNREGISTER, ast_unregister_application(), cli_agi, commands, deadapp, eapp, and STASIS_MESSAGE_TYPE_CLEANUP.

Referenced by load_module().

◆ write_html_escaped()

static void write_html_escaped ( FILE *  htmlfile,
char *  str 
)
static

Convert string to use HTML escaped characters.

Note
Maybe this should be a generic function?

Definition at line 4422 of file res_agi.c.

4423{
4424 char *cur = str;
4425
4426 while(*cur) {
4427 switch (*cur) {
4428 case '<':
4429 fprintf(htmlfile, "%s", "&lt;");
4430 break;
4431 case '>':
4432 fprintf(htmlfile, "%s", "&gt;");
4433 break;
4434 case '&':
4435 fprintf(htmlfile, "%s", "&amp;");
4436 break;
4437 case '"':
4438 fprintf(htmlfile, "%s", "&quot;");
4439 break;
4440 default:
4441 fprintf(htmlfile, "%c", *cur);
4442 break;
4443 }
4444 cur++;
4445 }
4446
4447 return;
4448}

References str.

Referenced by write_htmldump().

◆ write_htmldump()

static int write_htmldump ( const char *  filename)
static

Definition at line 4450 of file res_agi.c.

4451{
4452 struct agi_command *command;
4453 char fullcmd[MAX_CMD_LEN];
4454 FILE *htmlfile;
4455
4456 if (!(htmlfile = fopen(filename, "wt")))
4457 return -1;
4458
4459 fprintf(htmlfile, "<HTML>\n<HEAD>\n<TITLE>AGI Commands</TITLE>\n</HEAD>\n");
4460 fprintf(htmlfile, "<BODY>\n<CENTER><B><H1>AGI Commands</H1></B></CENTER>\n\n");
4461 fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n");
4462
4465 char *tempstr, *stringp;
4466
4467 if (!command->cmda[0]) /* end ? */
4468 break;
4469 /* Hide commands that start with '_' */
4470 if ((command->cmda[0])[0] == '_')
4471 continue;
4472 ast_join(fullcmd, sizeof(fullcmd), command->cmda);
4473
4474 fprintf(htmlfile, "<TR><TD><TABLE BORDER=\"1\" CELLPADDING=\"5\" WIDTH=\"100%%\">\n");
4475 fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TH></TR>\n", fullcmd, command->summary);
4476#ifdef AST_XML_DOCS
4477 stringp = ast_xmldoc_printable(command->usage, 0);
4478#else
4479 stringp = ast_strdup(command->usage);
4480#endif
4481 tempstr = strsep(&stringp, "\n");
4482
4483 fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">");
4484 write_html_escaped(htmlfile, tempstr);
4485 fprintf(htmlfile, "</TD></TR>\n");
4486 fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">\n");
4487
4488 while ((tempstr = strsep(&stringp, "\n")) != NULL) {
4489 write_html_escaped(htmlfile, tempstr);
4490 fprintf(htmlfile, "<BR>\n");
4491 }
4492 fprintf(htmlfile, "</TD></TR>\n");
4493 fprintf(htmlfile, "</TABLE></TD></TR>\n\n");
4494 ast_free(stringp);
4495 }
4497 fprintf(htmlfile, "</TABLE>\n</BODY>\n</HTML>\n");
4498 fclose(htmlfile);
4499 return 0;
4500}
char * strsep(char **str, const char *delims)
static void write_html_escaped(FILE *htmlfile, char *str)
Convert string to use HTML escaped characters.
Definition: res_agi.c:4422

References ast_free, ast_join, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_xmldoc_printable(), agi_command::cmda, agi_command::list, MAX_CMD_LEN, NULL, strsep(), agi_command::summary, agi_command::usage, and write_html_escaped().

Referenced by handle_cli_agi_dump_html().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_speech", }
static

Definition at line 4747 of file res_agi.c.

◆ agi_buf

struct ast_threadstorage agi_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_agi_buf , .custom_init = NULL , }
static

Definition at line 1478 of file res_agi.c.

Referenced by ast_agi_send().

◆ agi_commands

struct agi_commands agi_commands = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static

Referenced by add_agi_cmd(), and get_agi_cmd().

◆ agi_commands_datastore_info

const struct ast_datastore_info agi_commands_datastore_info
static
Initial value:
= {
.type = "AsyncAGI",
}
static void agi_destroy_commands_cb(void *data)
Definition: res_agi.c:1525

Definition at line 1539 of file res_agi.c.

Referenced by add_agi_cmd(), add_to_agi(), and get_agi_cmd().

◆ agidebug

int agidebug = 0
static

Definition at line 1395 of file res_agi.c.

Referenced by ast_agi_send(), handle_cli_agi_debug(), and run_agi().

◆ app

char* app = "AGI"
static

Definition at line 1389 of file res_agi.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 4747 of file res_agi.c.

◆ cli_agi

struct ast_cli_entry cli_agi[]
static

Definition at line 4649 of file res_agi.c.

Referenced by load_module(), and unload_module().

◆ commands

struct agi_command commands[]
static

AGI commands list.

Definition at line 3738 of file res_agi.c.

Referenced by dundi_showframe(), load_module(), unload_module(), and xmpp_component_service_discovery_get_hook().

◆ deadapp

char* deadapp = "DeadAGI"
static

Definition at line 1393 of file res_agi.c.

Referenced by load_module(), and unload_module().

◆ eapp

char* eapp = "EAGI"
static

Definition at line 1391 of file res_agi.c.

Referenced by load_module(), and unload_module().