Fri Feb 10 06:34:15 2012

Asterisk developer's documentation


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

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.


Detailed Description

AGI Extension interfaces - Asterisk Gateway Interface.

Definition in file agi.h.


Typedef Documentation

typedef struct agi_state AGI


Function Documentation

int ast_agi_register ( struct ast_module mod,
agi_command cmd 
)

Registers an AGI command.

Parameters:
mod Pointer to the module_info structure for the module that is registering the command
cmd Pointer to the descriptor for the command
Return values:
1 on success
0 the command is already registered
AST_OPTIONAL_API_UNAVAILABLE the module is not loaded.

Definition at line 3136 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, find_command(), LOG_WARNING, and MAX_CMD_LEN.

Referenced by ast_agi_register_multiple(), and load_module().

03137 {
03138    char fullcmd[MAX_CMD_LEN];
03139 
03140    ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
03141 
03142    if (!find_command(cmd->cmda, 1)) {
03143       *((enum ast_doc_src *) &cmd->docsrc) = AST_STATIC_DOC;
03144       if (ast_strlen_zero(cmd->summary) && ast_strlen_zero(cmd->usage)) {
03145 #ifdef AST_XML_DOCS
03146          *((char **) &cmd->summary) = ast_xmldoc_build_synopsis("agi", fullcmd, NULL);
03147          *((char **) &cmd->usage) = ast_xmldoc_build_description("agi", fullcmd, NULL);
03148          *((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd, NULL);
03149          *((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd, NULL);
03150          *((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC;
03151 #endif
03152 #ifndef HAVE_NULLSAFE_PRINTF
03153          if (!cmd->summary) {
03154             *((char **) &cmd->summary) = ast_strdup("");
03155          }
03156          if (!cmd->usage) {
03157             *((char **) &cmd->usage) = ast_strdup("");
03158          }
03159          if (!cmd->syntax) {
03160             *((char **) &cmd->syntax) = ast_strdup("");
03161          }
03162          if (!cmd->seealso) {
03163             *((char **) &cmd->seealso) = ast_strdup("");
03164          }
03165 #endif
03166       }
03167 
03168       cmd->mod = mod;
03169       AST_RWLIST_WRLOCK(&agi_commands);
03170       AST_LIST_INSERT_TAIL(&agi_commands, cmd, list);
03171       AST_RWLIST_UNLOCK(&agi_commands);
03172       if (mod != ast_module_info->self)
03173          ast_module_ref(ast_module_info->self);
03174       ast_verb(2, "AGI Command '%s' registered\n",fullcmd);
03175       return 1;
03176    } else {
03177       ast_log(LOG_WARNING, "Command already registered!\n");
03178       return 0;
03179    }
03180 }

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.

Parameters:
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)
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 3221 of file res_agi.c.

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

Referenced by load_module().

03222 {
03223    unsigned int i, x = 0;
03224 
03225    for (i = 0; i < len; i++) {
03226       if (ast_agi_register(mod, cmd + i) == 1) {
03227          x++;
03228          continue;
03229       }
03230 
03231       /* registration failed, unregister everything
03232          that had been registered up to that point
03233       */
03234       for (; x > 0; x--) {
03235          /* we are intentionally ignoring the
03236             result of ast_agi_unregister() here,
03237             but it should be safe to do so since
03238             we just registered these commands and
03239             the only possible way for unregistration
03240             to fail is if the command is not
03241             registered
03242          */
03243          (void) ast_agi_unregister(mod, cmd + x - 1);
03244       }
03245       return -1;
03246    }
03247 
03248    return 0;
03249 }

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

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

Parameters:
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
Returns:
0 for success, -1 for failure, AST_OPTIONAL_API_UNAVAILABLE if res_agi is not loaded

Definition at line 939 of file res_agi.c.

References agi_buf, AGI_BUF_INITSIZE, ast_carefulwrite(), ast_channel_name(), ast_log(), ast_str_buffer(), ast_str_set_va(), ast_str_strlen(), ast_str_thread_get(), ast_verbose, 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().

00940 {
00941    int res = 0;
00942    va_list ap;
00943    struct ast_str *buf;
00944 
00945    if (!(buf = ast_str_thread_get(&agi_buf, AGI_BUF_INITSIZE)))
00946       return -1;
00947 
00948    va_start(ap, fmt);
00949    res = ast_str_set_va(&buf, 0, fmt, ap);
00950    va_end(ap);
00951 
00952    if (res == -1) {
00953       ast_log(LOG_ERROR, "Out of memory\n");
00954       return -1;
00955    }
00956 
00957    if (agidebug) {
00958       if (chan) {
00959          ast_verbose("<%s>AGI Tx >> %s", ast_channel_name(chan), ast_str_buffer(buf));
00960       } else {
00961          ast_verbose("AGI Tx >> %s", ast_str_buffer(buf));
00962       }
00963    }
00964 
00965    return ast_carefulwrite(fd, ast_str_buffer(buf), ast_str_strlen(buf), 100);
00966 }

int ast_agi_unregister ( struct ast_module mod,
agi_command cmd 
)

Unregisters an AGI command.

Parameters:
mod Pointer to the module_info structure for the module that is unregistering the command
cmd Pointer to the descriptor for the command
Returns:
1 on success, 0 if the command was not already registered

Definition at line 3182 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, agi_command::summary, agi_command::syntax, and agi_command::usage.

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

03183 {
03184    struct agi_command *e;
03185    int unregistered = 0;
03186    char fullcmd[MAX_CMD_LEN];
03187 
03188    ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
03189 
03190    AST_RWLIST_WRLOCK(&agi_commands);
03191    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) {
03192       if (cmd == e) {
03193          AST_RWLIST_REMOVE_CURRENT(list);
03194          if (mod != ast_module_info->self)
03195             ast_module_unref(ast_module_info->self);
03196 #ifdef AST_XML_DOCS
03197          if (e->docsrc == AST_XML_DOC) {
03198             ast_free((char *) e->summary);
03199             ast_free((char *) e->usage);
03200             ast_free((char *) e->syntax);
03201             ast_free((char *) e->seealso);
03202             *((char **) &e->summary) = NULL;
03203             *((char **) &e->usage) = NULL;
03204             *((char **) &e->syntax) = NULL;
03205             *((char **) &e->seealso) = NULL;
03206          }
03207 #endif
03208          unregistered=1;
03209          break;
03210       }
03211    }
03212    AST_RWLIST_TRAVERSE_SAFE_END;
03213    AST_RWLIST_UNLOCK(&agi_commands);
03214    if (unregistered)
03215       ast_verb(2, "AGI Command '%s' unregistered\n",fullcmd);
03216    else
03217       ast_log(LOG_WARNING, "Unable to unregister command: '%s'!\n",fullcmd);
03218    return unregistered;
03219 }

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.

Parameters:
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)
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 3251 of file res_agi.c.

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

Referenced by unload_module().

03252 {
03253    unsigned int i;
03254    int res = 0;
03255 
03256    for (i = 0; i < len; i++) {
03257       /* remember whether any of the unregistration
03258          attempts failed... there is no recourse if
03259          any of them do
03260       */
03261       res |= ast_agi_unregister(mod, cmd + i);
03262    }
03263 
03264    return res;
03265 }


Generated on Fri Feb 10 06:34:16 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6