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


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_agi_register (struct ast_module *mod, agi_command *cmd) |
| Registers an AGI command. | |
| int | 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_agi_send (int fd, struct ast_channel *chan, char *fmt,...) |
| Sends a string of text to an application connected via AGI. | |
| int | ast_agi_unregister (struct ast_module *mod, agi_command *cmd) |
| Unregisters an AGI command. | |
| int | ast_agi_unregister_multiple (struct ast_module *mod, struct agi_command *cmd, unsigned int len) |
| Unregisters a group of AGI commands, provided as an array of struct agi_command entries. | |
AGI Extension interfaces - Asterisk Gateway Interface.
Definition in file agi.h.
| typedef struct agi_command agi_command |
| int ast_agi_register | ( | struct ast_module * | mod, |
| agi_command * | cmd | ||
| ) |
Registers an AGI command.
| mod | Pointer to the module_info structure for the module that is registering the command |
| cmd | Pointer to the descriptor for the command |
| 1 | on success |
| 0 | the command is already registered |
| AST_OPTIONAL_API_UNAVAILABLE | the module is not loaded. |
Definition at line 3118 of file res_agi.c.
References ast_join(), AST_LIST_INSERT_TAIL, ast_log(), ast_module_ref(), 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 ast_module_info::self.
Referenced by ast_agi_register_multiple(), and load_module().
{
char fullcmd[MAX_CMD_LEN];
ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
if (!find_command(cmd->cmda, 1)) {
*((enum ast_doc_src *) &cmd->docsrc) = AST_STATIC_DOC;
if (ast_strlen_zero(cmd->summary) && ast_strlen_zero(cmd->usage)) {
#ifdef AST_XML_DOCS
*((char **) &cmd->summary) = ast_xmldoc_build_synopsis("agi", fullcmd, NULL);
*((char **) &cmd->usage) = ast_xmldoc_build_description("agi", fullcmd, NULL);
*((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd, NULL);
*((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd, NULL);
*((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC;
#endif
#ifndef HAVE_NULLSAFE_PRINTF
if (!cmd->summary) {
*((char **) &cmd->summary) = ast_strdup("");
}
if (!cmd->usage) {
*((char **) &cmd->usage) = ast_strdup("");
}
if (!cmd->syntax) {
*((char **) &cmd->syntax) = ast_strdup("");
}
if (!cmd->seealso) {
*((char **) &cmd->seealso) = ast_strdup("");
}
#endif
}
cmd->mod = mod;
AST_RWLIST_WRLOCK(&agi_commands);
AST_LIST_INSERT_TAIL(&agi_commands, cmd, list);
AST_RWLIST_UNLOCK(&agi_commands);
if (mod != ast_module_info->self)
ast_module_ref(ast_module_info->self);
ast_verb(2, "AGI Command '%s' registered\n",fullcmd);
return 1;
} else {
ast_log(LOG_WARNING, "Command already registered!\n");
return 0;
}
}
| int 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.
| mod | Pointer to the module_info structure for the module that is registering the commands |
| cmd | Pointer to the first entry in the array of command descriptors |
| len | Length of the array (use the ARRAY_LEN macro to determine this easily) |
Definition at line 3203 of file res_agi.c.
References ast_agi_register(), ast_agi_unregister(), len(), and agi_command::mod.
Referenced by load_module().
{
unsigned int i, x = 0;
for (i = 0; i < len; i++) {
if (ast_agi_register(mod, cmd + i) == 1) {
x++;
continue;
}
/* registration failed, unregister everything
that had been registered up to that point
*/
for (; x > 0; x--) {
/* we are intentionally ignoring the
result of ast_agi_unregister() here,
but it should be safe to do so since
we just registered these commands and
the only possible way for unregistration
to fail is if the command is not
registered
*/
(void) ast_agi_unregister(mod, cmd + x - 1);
}
return -1;
}
return 0;
}
| int ast_agi_send | ( | int | fd, |
| struct ast_channel * | chan, | ||
| char * | fmt, | ||
| ... | |||
| ) |
Sends a string of text to an application connected via AGI.
| fd | The file descriptor for the AGI session (from struct agi_state) |
| chan | Pointer to an associated Asterisk channel, if any |
| fmt | printf-style format string |
Definition at line 939 of file res_agi.c.
References agi_buf, AGI_BUF_INITSIZE, ast_carefulwrite(), ast_log(), ast_str_buffer(), ast_str_set_va(), ast_str_strlen(), ast_str_thread_get(), ast_verbose(), LOG_ERROR, and ast_channel::name.
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().
{
int res = 0;
va_list ap;
struct ast_str *buf;
if (!(buf = ast_str_thread_get(&agi_buf, AGI_BUF_INITSIZE)))
return -1;
va_start(ap, fmt);
res = ast_str_set_va(&buf, 0, fmt, ap);
va_end(ap);
if (res == -1) {
ast_log(LOG_ERROR, "Out of memory\n");
return -1;
}
if (agidebug) {
if (chan) {
ast_verbose("<%s>AGI Tx >> %s", chan->name, ast_str_buffer(buf));
} else {
ast_verbose("AGI Tx >> %s", ast_str_buffer(buf));
}
}
return ast_carefulwrite(fd, ast_str_buffer(buf), ast_str_strlen(buf), 100);
}
| int ast_agi_unregister | ( | struct ast_module * | mod, |
| agi_command * | cmd | ||
| ) |
Unregisters an AGI command.
| mod | Pointer to the module_info structure for the module that is unregistering the command |
| cmd | Pointer to the descriptor for the command |
Definition at line 3164 of file res_agi.c.
References ast_free, ast_join(), ast_log(), ast_module_unref(), 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, LOG_WARNING, MAX_CMD_LEN, agi_command::mod, agi_command::seealso, ast_module_info::self, agi_command::summary, agi_command::syntax, and agi_command::usage.
Referenced by ast_agi_register_multiple(), ast_agi_unregister_multiple(), and unload_module().
{
struct agi_command *e;
int unregistered = 0;
char fullcmd[MAX_CMD_LEN];
ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
AST_RWLIST_WRLOCK(&agi_commands);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) {
if (cmd == e) {
AST_RWLIST_REMOVE_CURRENT(list);
if (mod != ast_module_info->self)
ast_module_unref(ast_module_info->self);
#ifdef AST_XML_DOCS
if (e->docsrc == AST_XML_DOC) {
ast_free((char *) e->summary);
ast_free((char *) e->usage);
ast_free((char *) e->syntax);
ast_free((char *) e->seealso);
*((char **) &e->summary) = NULL;
*((char **) &e->usage) = NULL;
*((char **) &e->syntax) = NULL;
*((char **) &e->seealso) = NULL;
}
#endif
unregistered=1;
break;
}
}
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&agi_commands);
if (unregistered)
ast_verb(2, "AGI Command '%s' unregistered\n",fullcmd);
else
ast_log(LOG_WARNING, "Unable to unregister command: '%s'!\n",fullcmd);
return unregistered;
}
| int ast_agi_unregister_multiple | ( | struct ast_module * | mod, |
| struct agi_command * | cmd, | ||
| unsigned int | len | ||
| ) |
Unregisters a group of AGI commands, provided as an array of struct agi_command entries.
| mod | Pointer to the module_info structure for the module that is unregistering the commands |
| cmd | Pointer to the first entry in the array of command descriptors |
| len | Length of the array (use the ARRAY_LEN macro to determine this easily) |
Definition at line 3233 of file res_agi.c.
References ast_agi_unregister(), len(), and agi_command::mod.
Referenced by unload_module().
{
unsigned int i;
int res = 0;
for (i = 0; i < len; i++) {
/* remember whether any of the unregistration
attempts failed... there is no recourse if
any of them do
*/
res |= ast_agi_unregister(mod, cmd + i);
}
return res;
}