Fri Nov 12 11:47:52 2010

Asterisk developer's documentation


agi.h File Reference

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

#include "asterisk/cli.h"
#include "asterisk/xmldoc.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) attribute_weak
 Registers an AGI command.
int ast_agi_register_multiple (struct ast_module *mod, struct agi_command *cmd, unsigned int len) attribute_weak
 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,...) attribute_weak
 Sends a string of text to an application connected via AGI.
int ast_agi_unregister (struct ast_module *mod, agi_command *cmd) attribute_weak
 Unregisters an AGI command.
int ast_agi_unregister_multiple (struct ast_module *mod, struct agi_command *cmd, unsigned int len) attribute_weak
 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
Returns:
1 on success, 0 if the command is already registered

Definition at line 2556 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(), agi_command::cmda, agi_command::docsrc, find_command(), 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(), and load_module().

02557 {
02558    char fullcmd[MAX_CMD_LEN];
02559 
02560    ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
02561 
02562    if (!find_command(cmd->cmda,1)) {
02563       cmd->docsrc = AST_STATIC_DOC;
02564       if (ast_strlen_zero(cmd->summary) && ast_strlen_zero(cmd->usage)) {
02565 #ifdef AST_XML_DOCS
02566          *((char **) &cmd->summary) = ast_xmldoc_build_synopsis("agi", fullcmd);
02567          *((char **) &cmd->usage) = ast_xmldoc_build_description("agi", fullcmd);
02568          *((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd);
02569          *((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd);
02570          *((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC;
02571 #elif (!defined(HAVE_NULLSAFE_PRINTF))
02572          *((char **) &cmd->summary) = ast_strdup("");
02573          *((char **) &cmd->usage) = ast_strdup("");
02574          *((char **) &cmd->syntax) = ast_strdup("");
02575          *((char **) &cmd->seealso) = ast_strdup("");
02576 #endif
02577       }
02578 
02579       cmd->mod = mod;
02580       AST_RWLIST_WRLOCK(&agi_commands);
02581       AST_LIST_INSERT_TAIL(&agi_commands, cmd, list);
02582       AST_RWLIST_UNLOCK(&agi_commands);
02583       if (mod != ast_module_info->self)
02584          ast_module_ref(ast_module_info->self);
02585       ast_verb(2, "AGI Command '%s' registered\n",fullcmd);
02586       return 1;
02587    } else {
02588       ast_log(LOG_WARNING, "Command already registered!\n");
02589       return 0;
02590    }
02591 }

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

References ast_agi_register(), and ast_agi_unregister().

Referenced by load_module().

02631 {
02632    unsigned int i, x = 0;
02633 
02634    for (i = 0; i < len; i++) {
02635       if (ast_agi_register(mod, cmd + i) == 1) {
02636          x++;
02637          continue;
02638       }
02639 
02640       /* registration failed, unregister everything
02641          that had been registered up to that point
02642       */
02643       for (; x > 0; x--) {
02644          /* we are intentionally ignoring the
02645             result of ast_agi_unregister() here,
02646             but it should be safe to do so since
02647             we just registered these commands and
02648             the only possible way for unregistration
02649             to fail is if the command is not
02650             registered
02651          */
02652          (void) ast_agi_unregister(mod, cmd + x - 1);
02653       }
02654       return -1;
02655    }
02656 
02657    return 0;
02658 }

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

Definition at line 375 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, buf, 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(), and setup_env().

00376 {
00377    int res = 0;
00378    va_list ap;
00379    struct ast_str *buf;
00380 
00381    if (!(buf = ast_str_thread_get(&agi_buf, AGI_BUF_INITSIZE)))
00382       return -1;
00383 
00384    va_start(ap, fmt);
00385    res = ast_str_set_va(&buf, 0, fmt, ap);
00386    va_end(ap);
00387 
00388    if (res == -1) {
00389       ast_log(LOG_ERROR, "Out of memory\n");
00390       return -1;
00391    }
00392 
00393    if (agidebug) {
00394       if (chan) {
00395          ast_verbose("<%s>AGI Tx >> %s", chan->name, ast_str_buffer(buf));
00396       } else {
00397          ast_verbose("AGI Tx >> %s", ast_str_buffer(buf));
00398       }
00399    }
00400 
00401    return ast_carefulwrite(fd, ast_str_buffer(buf), ast_str_strlen(buf), 100);
00402 }

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 2593 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::cmda, agi_command::docsrc, agi_command::list, LOG_WARNING, MAX_CMD_LEN, 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().

02594 {
02595    struct agi_command *e;
02596    int unregistered = 0;
02597    char fullcmd[MAX_CMD_LEN];
02598 
02599    ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
02600 
02601    AST_RWLIST_WRLOCK(&agi_commands);
02602    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) {
02603       if (cmd == e) {
02604          AST_RWLIST_REMOVE_CURRENT(list);
02605          if (mod != ast_module_info->self)
02606             ast_module_unref(ast_module_info->self);
02607 #ifdef AST_XML_DOCS
02608          if (e->docsrc == AST_XML_DOC) {
02609             ast_free(e->summary);
02610             ast_free(e->usage);
02611             ast_free(e->syntax);
02612             ast_free(e->seealso);
02613             e->summary = NULL, e->usage = NULL;
02614             e->syntax = NULL, e->seealso = NULL;
02615          }
02616 #endif
02617          unregistered=1;
02618          break;
02619       }
02620    }
02621    AST_RWLIST_TRAVERSE_SAFE_END;
02622    AST_RWLIST_UNLOCK(&agi_commands);
02623    if (unregistered)
02624       ast_verb(2, "AGI Command '%s' unregistered\n",fullcmd);
02625    else
02626       ast_log(LOG_WARNING, "Unable to unregister command: '%s'!\n",fullcmd);
02627    return unregistered;
02628 }

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

References ast_agi_unregister().

Referenced by unload_module().

02661 {
02662    unsigned int i;
02663    int res = 0;
02664 
02665    for (i = 0; i < len; i++) {
02666       /* remember whether any of the unregistration
02667          attempts failed... there is no recourse if
02668          any of them do
02669       */
02670       res |= ast_agi_unregister(mod, cmd + i);
02671    }
02672 
02673    return res;
02674 }


Generated by  doxygen 1.6.2