Wed Aug 18 22:33:57 2010

Asterisk developer's documentation


agi.h File Reference

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

#include "asterisk/cli.h"

Go to the source code of this file.

Data Structures

struct  agi_command
struct  agi_state

Defines

#define AGI_WEAK

Typedefs

typedef agi_state AGI

Functions

int AGI_WEAK ast_agi_register (struct ast_module *mod, agi_command *cmd)
int AGI_WEAK 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 AGI_WEAK ast_agi_send (int fd, struct ast_channel *chan, char *fmt,...)
 Sends a string of text to an application connected via AGI.
int AGI_WEAK ast_agi_unregister (struct ast_module *mod, agi_command *cmd)
int AGI_WEAK 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.


Define Documentation

#define AGI_WEAK

Definition at line 61 of file agi.h.


Typedef Documentation

typedef struct agi_state AGI


Function Documentation

int AGI_WEAK ast_agi_register ( struct ast_module mod,
agi_command cmd 
)

Definition at line 2390 of file res_agi.c.

References ast_join(), AST_LIST_INSERT_TAIL, ast_log(), ast_module_ref(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, agi_command::cmda, find_command(), agi_command::list, LOG_WARNING, and agi_command::mod.

Referenced by ast_agi_register_multiple(), and load_module().

02391 {
02392    char fullcmd[80];
02393 
02394    ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
02395 
02396    if (!find_command(cmd->cmda,1)) {
02397       cmd->mod = mod;
02398       AST_RWLIST_WRLOCK(&agi_commands);
02399       AST_LIST_INSERT_TAIL(&agi_commands, cmd, list);
02400       AST_RWLIST_UNLOCK(&agi_commands);
02401       if (mod != ast_module_info->self)
02402          ast_module_ref(ast_module_info->self);
02403       ast_verb(2, "AGI Command '%s' registered\n",fullcmd);
02404       return 1;
02405    } else {
02406       ast_log(LOG_WARNING, "Command already registered!\n");
02407       return 0;
02408    }
02409 }

int AGI_WEAK 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 commands
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 2438 of file res_agi.c.

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

Referenced by load_module().

02439 {
02440    unsigned int i, x = 0;
02441 
02442    for (i = 0; i < len; i++) {
02443       if (ast_agi_register(mod, cmd + i) == 1) {
02444          x++;
02445          continue;
02446       }
02447 
02448       /* registration failed, unregister everything
02449          that had been registered up to that point
02450       */
02451       for (; x > 0; x--) {
02452          /* we are intentionally ignoring the
02453             result of ast_agi_unregister() here,
02454             but it should be safe to do so since
02455             we just registered these commands and
02456             the only possible way for unregistration
02457             to fail is if the command is not
02458             registered
02459          */
02460          (void) ast_agi_unregister(mod, cmd + x - 1);
02461       }
02462       return -1;
02463    }
02464 
02465    return 0;
02466 }

int AGI_WEAK 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 118 of file res_agi.c.

References agi_buf, AGI_BUF_INITSIZE, ast_carefulwrite(), ast_log(), ast_str_set_va(), ast_str_thread_get(), ast_verbose, buf, chan, 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(), and setup_env().

00119 {
00120    int res = 0;
00121    va_list ap;
00122    struct ast_str *buf;
00123 
00124    if (!(buf = ast_str_thread_get(&agi_buf, AGI_BUF_INITSIZE)))
00125       return -1;
00126 
00127    va_start(ap, fmt);
00128    res = ast_str_set_va(&buf, 0, fmt, ap);
00129    va_end(ap);
00130 
00131    if (res == -1) {
00132       ast_log(LOG_ERROR, "Out of memory\n");
00133       return -1;
00134    }
00135 
00136    if (agidebug) {
00137       if (chan) {
00138          ast_verbose("<%s>AGI Tx >> %s", chan->name, buf->str);
00139       } else {
00140          ast_verbose("AGI Tx >> %s", buf->str);
00141       }
00142    }
00143 
00144    return ast_carefulwrite(fd, buf->str, buf->used, 100);
00145 }

int AGI_WEAK ast_agi_unregister ( struct ast_module mod,
agi_command cmd 
)

Definition at line 2411 of file res_agi.c.

References 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, agi_command::cmda, agi_command::list, LOG_WARNING, and agi_command::mod.

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

02412 {
02413    struct agi_command *e;
02414    int unregistered = 0;
02415    char fullcmd[80];
02416 
02417    ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
02418 
02419    AST_RWLIST_WRLOCK(&agi_commands);
02420    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) {
02421       if (cmd == e) {
02422          AST_RWLIST_REMOVE_CURRENT(list);
02423          if (mod != ast_module_info->self)
02424             ast_module_unref(ast_module_info->self);
02425          unregistered=1;
02426          break;
02427       }
02428    }
02429    AST_RWLIST_TRAVERSE_SAFE_END;
02430    AST_RWLIST_UNLOCK(&agi_commands);
02431    if (unregistered)
02432       ast_verb(2, "AGI Command '%s' unregistered\n",fullcmd);
02433    else
02434       ast_log(LOG_WARNING, "Unable to unregister command: '%s'!\n",fullcmd);
02435    return unregistered;
02436 }

int AGI_WEAK 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 commands
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 2468 of file res_agi.c.

References ast_agi_unregister(), and agi_command::mod.

Referenced by unload_module().

02469 {
02470    unsigned int i;
02471    int res = 0;
02472 
02473    for (i = 0; i < len; i++) {
02474       /* remember whether any of the unregistration
02475          attempts failed... there is no recourse if
02476          any of them do
02477       */
02478       res |= ast_agi_unregister(mod, cmd + i);
02479    }
02480 
02481    return res;
02482 }


Generated on Wed Aug 18 22:33:57 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7