Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
agi.h File Reference

AGI Extension interfaces - Asterisk Gateway Interface. More...

#include "asterisk/cli.h"
#include "asterisk/xmldoc.h"
#include "asterisk/optional_api.h"
Include dependency graph for agi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  agi_command
 
struct  agi_state
 

Typedefs

typedef struct agi_state AGI
 
typedef struct agi_command agi_command
 

Functions

int AST_OPTIONAL_API_NAME() ast_agi_register (struct ast_module *mod, agi_command *cmd)
 Registers an AGI command.
 
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.
 
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.
 
int AST_OPTIONAL_API_NAME() ast_agi_unregister (agi_command *cmd)
 Unregisters an AGI command.
 
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.
 

Detailed Description

AGI Extension interfaces - Asterisk Gateway Interface.

Definition in file agi.h.

Typedef Documentation

◆ AGI

typedef struct agi_state AGI

◆ agi_command

typedef struct agi_command agi_command

Function Documentation

◆ 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 3954 of file res_agi.c.

3955{
3956 char fullcmd[MAX_CMD_LEN];
3957
3958 ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
3959
3960 if (!find_command(cmd->cmda, 1)) {
3961 *((enum ast_doc_src *) &cmd->docsrc) = AST_STATIC_DOC;
3962 if (ast_strlen_zero(cmd->summary) && ast_strlen_zero(cmd->usage)) {
3963#ifdef AST_XML_DOCS
3964 *((char **) &cmd->summary) = ast_xmldoc_build_synopsis("agi", fullcmd, NULL);
3965 *((char **) &cmd->since) = ast_xmldoc_build_since("agi", fullcmd, NULL);
3966 *((char **) &cmd->usage) = ast_xmldoc_build_description("agi", fullcmd, NULL);
3967 *((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd, NULL);
3968 *((char **) &cmd->arguments) = ast_xmldoc_build_arguments("agi", fullcmd, NULL);
3969 *((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd, NULL);
3970 *((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC;
3971#endif
3972#ifndef HAVE_NULLSAFE_PRINTF
3973 if (!cmd->summary) {
3974 *((char **) &cmd->summary) = ast_strdup("");
3975 }
3976 if (!cmd->usage) {
3977 *((char **) &cmd->usage) = ast_strdup("");
3978 }
3979 if (!cmd->syntax) {
3980 *((char **) &cmd->syntax) = ast_strdup("");
3981 }
3982 if (!cmd->seealso) {
3983 *((char **) &cmd->seealso) = ast_strdup("");
3984 }
3985#endif
3986 }
3987
3988 cmd->mod = mod;
3992 ast_verb(5, "AGI Command '%s' registered\n",fullcmd);
3993 return 1;
3994 } else {
3995 ast_log(LOG_WARNING, "Command already registered!\n");
3996 return 0;
3997 }
3998}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_log
Definition astobj2.c:42
#define ast_verb(level,...)
#define LOG_WARNING
#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.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define MAX_CMD_LEN
Definition res_agi.c:1517
static agi_command * find_command(const char *const cmds[], int exact)
Definition res_agi.c:4086
#define NULL
Definition resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_join(s, len, w)
Join an array of strings into a single string.
Definition strings.h:520
const char *const since
Definition agi.h:64
const char *const summary
Definition agi.h:48
const char *const arguments
Definition agi.h:66
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:2361
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_arguments(const char *type, const char *name, const char *module)
Generate the [arguments] tag based on type of node ('application', 'function' or 'agi') and name.
Definition xmldoc.c:2174
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
Definition xmldoc.c:2338
char * ast_xmldoc_build_since(const char *type, const char *name, const char *module)
Parse the <since> node content.
Definition xmldoc.c:1792
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:1707

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_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_seealso(), ast_xmldoc_build_since(), 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 4040 of file res_agi.c.

4041{
4042 unsigned int i, x = 0;
4043
4044 for (i = 0; i < len; i++) {
4045 if (ast_agi_register(mod, cmd + i) == 1) {
4046 x++;
4047 continue;
4048 }
4049
4050 /* registration failed, unregister everything
4051 that had been registered up to that point
4052 */
4053 for (; x > 0; x--) {
4054 /* we are intentionally ignoring the
4055 result of ast_agi_unregister() here,
4056 but it should be safe to do so since
4057 we just registered these commands and
4058 the only possible way for unregistration
4059 to fail is if the command is not
4060 registered
4061 */
4062 (void) ast_agi_unregister(cmd + x - 1);
4063 }
4064 return -1;
4065 }
4066
4067 return 0;
4068}
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:4000
int AST_OPTIONAL_API_NAME() ast_agi_register(struct ast_module *mod, agi_command *cmd)
Registers an AGI command.
Definition res_agi.c:3954

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 1612 of file res_agi.c.

1613{
1614 int res = 0;
1615 va_list ap;
1616 struct ast_str *buf;
1617
1618 if (!(buf = ast_str_thread_get(&agi_buf, AGI_BUF_INITSIZE)))
1619 return -1;
1620
1621 va_start(ap, fmt);
1622 res = ast_str_set_va(&buf, 0, fmt, ap);
1623 va_end(ap);
1624
1625 if (res == -1) {
1626 ast_log(LOG_ERROR, "Out of memory\n");
1627 return -1;
1628 }
1629
1630 if (agidebug) {
1631 if (chan) {
1632 ast_verbose("<%s>AGI Tx >> %s", ast_channel_name(chan), ast_str_buffer(buf));
1633 } else {
1634 ast_verbose("AGI Tx >> %s", ast_str_buffer(buf));
1635 }
1636 }
1637
1639}
const char * ast_channel_name(const struct ast_channel *chan)
char buf[BUFSIZE]
Definition eagi_proxy.c:66
#define LOG_ERROR
#define ast_verbose(...)
static int agidebug
Definition res_agi.c:1526
#define AGI_BUF_INITSIZE
Definition res_agi.c:1610
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 attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
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
Support for dynamic strings.
Definition strings.h:623
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:1807

References 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_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 4000 of file res_agi.c.

4001{
4002 struct agi_command *e;
4003 int unregistered = 0;
4004 char fullcmd[MAX_CMD_LEN];
4005
4006 ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
4007
4010 if (cmd == e) {
4012#ifdef AST_XML_DOCS
4013 if (e->docsrc == AST_XML_DOC) {
4014 ast_free((char *) e->summary);
4015 ast_free((char *) e->since);
4016 ast_free((char *) e->usage);
4017 ast_free((char *) e->syntax);
4018 ast_free((char *) e->arguments);
4019 ast_free((char *) e->seealso);
4020 *((char **) &e->summary) = NULL;
4021 *((char **) &e->since) = NULL;
4022 *((char **) &e->usage) = NULL;
4023 *((char **) &e->syntax) = NULL;
4024 *((char **) &e->arguments) = NULL;
4025 *((char **) &e->seealso) = NULL;
4026 }
4027#endif
4028 unregistered=1;
4029 break;
4030 }
4031 }
4034 if (unregistered) {
4035 ast_verb(5, "AGI Command '%s' unregistered\n",fullcmd);
4036 }
4037 return unregistered;
4038}
#define ast_free(a)
Definition astmm.h:180
#define AST_RWLIST_REMOVE_CURRENT
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_TRAVERSE_SAFE_END
struct agi_command::@192 list

References agi_command::arguments, 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::since, 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 4070 of file res_agi.c.

4071{
4072 unsigned int i;
4073 int res = 0;
4074
4075 for (i = 0; i < len; i++) {
4076 /* remember whether any of the unregistration
4077 attempts failed... there is no recourse if
4078 any of them do
4079 */
4080 res |= ast_agi_unregister(cmd + i);
4081 }
4082
4083 return res;
4084}

References ast_agi_unregister(), and len().

Referenced by unload_module().