Wed Mar 3 22:37:49 2010

Asterisk developer's documentation


agi.h File Reference

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

#include "asterisk/cli.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

Defines

#define AGI_WEAK

Typedefs

typedef struct 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 2380 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(), LOG_WARNING, and agi_command::mod.

Referenced by ast_agi_register_multiple(), and load_module().

02381 {
02382    char fullcmd[80];
02383 
02384    ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
02385 
02386    if (!find_command(cmd->cmda,1)) {
02387       cmd->mod = mod;
02388       AST_RWLIST_WRLOCK(&agi_commands);
02389       AST_LIST_INSERT_TAIL(&agi_commands, cmd, list);
02390       AST_RWLIST_UNLOCK(&agi_commands);
02391       if (mod != ast_module_info->self)
02392          ast_module_ref(ast_module_info->self);
02393       ast_verb(2, "AGI Command '%s' registered\n",fullcmd);
02394       return 1;
02395    } else {
02396       ast_log(LOG_WARNING, "Command already registered!\n");
02397       return 0;
02398    }
02399 }

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

References ast_agi_register(), and ast_agi_unregister().

Referenced by load_module().

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

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, LOG_ERROR, ast_str::str, and ast_str::used.

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 2401 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, and LOG_WARNING.

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

02402 {
02403    struct agi_command *e;
02404    int unregistered = 0;
02405    char fullcmd[80];
02406 
02407    ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
02408 
02409    AST_RWLIST_WRLOCK(&agi_commands);
02410    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) {
02411       if (cmd == e) {
02412          AST_RWLIST_REMOVE_CURRENT(list);
02413          if (mod != ast_module_info->self)
02414             ast_module_unref(ast_module_info->self);
02415          unregistered=1;
02416          break;
02417       }
02418    }
02419    AST_RWLIST_TRAVERSE_SAFE_END;
02420    AST_RWLIST_UNLOCK(&agi_commands);
02421    if (unregistered)
02422       ast_verb(2, "AGI Command '%s' unregistered\n",fullcmd);
02423    else
02424       ast_log(LOG_WARNING, "Unable to unregister command: '%s'!\n",fullcmd);
02425    return unregistered;
02426 }

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

References ast_agi_unregister().

Referenced by unload_module().

02459 {
02460    unsigned int i;
02461    int res = 0;
02462 
02463    for (i = 0; i < len; i++) {
02464       /* remember whether any of the unregistration
02465          attempts failed... there is no recourse if
02466          any of them do
02467       */
02468       res |= ast_agi_unregister(mod, cmd + i);
02469    }
02470 
02471    return res;
02472 }


Generated on 3 Mar 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1