#include "asterisk/cli.h"
#include "asterisk/xmldoc.h"


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. | |
Definition in file agi.h.
| 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 |
Definition at line 2557 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().
02558 { 02559 char fullcmd[MAX_CMD_LEN]; 02560 02561 ast_join(fullcmd, sizeof(fullcmd), cmd->cmda); 02562 02563 if (!find_command(cmd->cmda,1)) { 02564 cmd->docsrc = AST_STATIC_DOC; 02565 if (ast_strlen_zero(cmd->summary) && ast_strlen_zero(cmd->usage)) { 02566 #ifdef AST_XML_DOCS 02567 *((char **) &cmd->summary) = ast_xmldoc_build_synopsis("agi", fullcmd); 02568 *((char **) &cmd->usage) = ast_xmldoc_build_description("agi", fullcmd); 02569 *((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd); 02570 *((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd); 02571 *((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC; 02572 #elif (!defined(HAVE_NULLSAFE_PRINTF)) 02573 *((char **) &cmd->summary) = ast_strdup(""); 02574 *((char **) &cmd->usage) = ast_strdup(""); 02575 *((char **) &cmd->syntax) = ast_strdup(""); 02576 *((char **) &cmd->seealso) = ast_strdup(""); 02577 #endif 02578 } 02579 02580 cmd->mod = mod; 02581 AST_RWLIST_WRLOCK(&agi_commands); 02582 AST_LIST_INSERT_TAIL(&agi_commands, cmd, list); 02583 AST_RWLIST_UNLOCK(&agi_commands); 02584 if (mod != ast_module_info->self) 02585 ast_module_ref(ast_module_info->self); 02586 ast_verb(2, "AGI Command '%s' registered\n",fullcmd); 02587 return 1; 02588 } else { 02589 ast_log(LOG_WARNING, "Command already registered!\n"); 02590 return 0; 02591 } 02592 }
| 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 2631 of file res_agi.c.
References ast_agi_register(), and ast_agi_unregister().
Referenced by load_module().
02632 { 02633 unsigned int i, x = 0; 02634 02635 for (i = 0; i < len; i++) { 02636 if (ast_agi_register(mod, cmd + i) == 1) { 02637 x++; 02638 continue; 02639 } 02640 02641 /* registration failed, unregister everything 02642 that had been registered up to that point 02643 */ 02644 for (; x > 0; x--) { 02645 /* we are intentionally ignoring the 02646 result of ast_agi_unregister() here, 02647 but it should be safe to do so since 02648 we just registered these commands and 02649 the only possible way for unregistration 02650 to fail is if the command is not 02651 registered 02652 */ 02653 (void) ast_agi_unregister(mod, cmd + x - 1); 02654 } 02655 return -1; 02656 } 02657 02658 return 0; 02659 }
| 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 376 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().
00377 { 00378 int res = 0; 00379 va_list ap; 00380 struct ast_str *buf; 00381 00382 if (!(buf = ast_str_thread_get(&agi_buf, AGI_BUF_INITSIZE))) 00383 return -1; 00384 00385 va_start(ap, fmt); 00386 res = ast_str_set_va(&buf, 0, fmt, ap); 00387 va_end(ap); 00388 00389 if (res == -1) { 00390 ast_log(LOG_ERROR, "Out of memory\n"); 00391 return -1; 00392 } 00393 00394 if (agidebug) { 00395 if (chan) { 00396 ast_verbose("<%s>AGI Tx >> %s", chan->name, ast_str_buffer(buf)); 00397 } else { 00398 ast_verbose("AGI Tx >> %s", ast_str_buffer(buf)); 00399 } 00400 } 00401 00402 return ast_carefulwrite(fd, ast_str_buffer(buf), ast_str_strlen(buf), 100); 00403 }
| 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 2594 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().
02595 { 02596 struct agi_command *e; 02597 int unregistered = 0; 02598 char fullcmd[MAX_CMD_LEN]; 02599 02600 ast_join(fullcmd, sizeof(fullcmd), cmd->cmda); 02601 02602 AST_RWLIST_WRLOCK(&agi_commands); 02603 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) { 02604 if (cmd == e) { 02605 AST_RWLIST_REMOVE_CURRENT(list); 02606 if (mod != ast_module_info->self) 02607 ast_module_unref(ast_module_info->self); 02608 #ifdef AST_XML_DOCS 02609 if (e->docsrc == AST_XML_DOC) { 02610 ast_free(e->summary); 02611 ast_free(e->usage); 02612 ast_free(e->syntax); 02613 ast_free(e->seealso); 02614 e->summary = NULL, e->usage = NULL; 02615 e->syntax = NULL, e->seealso = NULL; 02616 } 02617 #endif 02618 unregistered=1; 02619 break; 02620 } 02621 } 02622 AST_RWLIST_TRAVERSE_SAFE_END; 02623 AST_RWLIST_UNLOCK(&agi_commands); 02624 if (unregistered) 02625 ast_verb(2, "AGI Command '%s' unregistered\n",fullcmd); 02626 else 02627 ast_log(LOG_WARNING, "Unable to unregister command: '%s'!\n",fullcmd); 02628 return unregistered; 02629 }
| 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 2661 of file res_agi.c.
References ast_agi_unregister().
Referenced by unload_module().
02662 { 02663 unsigned int i; 02664 int res = 0; 02665 02666 for (i = 0; i < len; i++) { 02667 /* remember whether any of the unregistration 02668 attempts failed... there is no recourse if 02669 any of them do 02670 */ 02671 res |= ast_agi_unregister(mod, cmd + i); 02672 } 02673 02674 return res; 02675 }
1.5.9