[asterisk-commits] kpfleming: branch 1.6.0 r157738 - in /branches/1.6.0: ./ apps/ channels/ incl...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Nov 19 07:19:49 CST 2008
Author: kpfleming
Date: Wed Nov 19 07:19:49 2008
New Revision: 157738
URL: http://svn.digium.com/view/asterisk?view=rev&rev=157738
Log:
Merged revisions 157706 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r157706 | kpfleming | 2008-11-19 06:42:19 -0600 (Wed, 19 Nov 2008) | 5 lines
make some corrections to the ast_agi_register_multiple(), ast_agi_unregister_multiple() and ast_agi_fdprintf() API calls to be consistent with API guidelines
also, move UPGRADE.txt to UPGRADE-1.6.txt and make the new UPGRADE.txt contain information about upgrading between Asterisk 1.6 releases
........
Added:
branches/1.6.0/UPGRADE-1.6.txt (props changed)
- copied unchanged from r157719, branches/1.6.0/UPGRADE.txt
branches/1.6.0/UPGRADE.txt (contents, props changed)
- copied, changed from r157706, trunk/UPGRADE.txt
Modified:
branches/1.6.0/ (props changed)
branches/1.6.0/apps/app_stack.c
branches/1.6.0/channels/chan_sip.c
branches/1.6.0/include/asterisk/agi.h
branches/1.6.0/res/res_agi.c
Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.
Propchange: branches/1.6.0/UPGRADE-1.6.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: branches/1.6.0/UPGRADE-1.6.txt
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: branches/1.6.0/UPGRADE-1.6.txt
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange: branches/1.6.0/UPGRADE-1.6.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: branches/1.6.0/UPGRADE.txt (from r157706, trunk/UPGRADE.txt)
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/UPGRADE.txt?view=diff&rev=157738&p1=trunk/UPGRADE.txt&r1=157706&p2=branches/1.6.0/UPGRADE.txt&r2=157738
==============================================================================
--- trunk/UPGRADE.txt (original)
+++ branches/1.6.0/UPGRADE.txt Wed Nov 19 07:19:49 2008
@@ -7,7 +7,7 @@
=== UPGRADE-1.6.txt -- Upgrade info for 1.4 to 1.6
===========================================================
-From 1.6.0.1 to 1.6.0.2 or later, or 1.6.1 or later:
+From 1.6.0.1 to 1.6.0.2:
* The ast_agi_register_multiple() and ast_agi_unregister_multiple()
API calls were added in 1.6.0, so that modules that provide multiple
Propchange: branches/1.6.0/UPGRADE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: branches/1.6.0/UPGRADE.txt
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: branches/1.6.0/UPGRADE.txt
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange: branches/1.6.0/UPGRADE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: branches/1.6.0/apps/app_stack.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/apps/app_stack.c?view=diff&rev=157738&r1=157737&r2=157738
==============================================================================
--- branches/1.6.0/apps/app_stack.c (original)
+++ branches/1.6.0/apps/app_stack.c Wed Nov 19 07:19:49 2008
@@ -406,11 +406,11 @@
/* Lookup the priority label */
if ((priority = ast_findlabel_extension(chan, argv[1], argv[2], argv[3], chan->cid.cid_num)) < 0) {
ast_log(LOG_ERROR, "Priority '%s' not found in '%s@%s'\n", argv[3], argv[2], argv[1]);
- ast_agi_fdprintf(chan, agi->fd, "200 result=-1 Gosub label not found\n");
+ ast_agi_send(agi->fd, chan, "200 result=-1 Gosub label not found\n");
return RESULT_FAILURE;
}
} else if (!ast_exists_extension(chan, argv[1], argv[2], priority, chan->cid.cid_num)) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=-1 Gosub label not found\n");
+ ast_agi_send(agi->fd, chan, "200 result=-1 Gosub label not found\n");
return RESULT_FAILURE;
}
@@ -421,7 +421,7 @@
if (!(theapp = pbx_findapp("Gosub"))) {
ast_log(LOG_ERROR, "Gosub() cannot be found in the list of loaded applications\n");
- ast_agi_fdprintf(chan, agi->fd, "503 result=-2 Gosub is not loaded\n");
+ ast_agi_send(agi->fd, chan, "503 result=-2 Gosub is not loaded\n");
return RESULT_FAILURE;
}
@@ -455,19 +455,19 @@
struct ast_pbx *pbx = chan->pbx;
/* Suppress warning about PBX already existing */
chan->pbx = NULL;
- ast_agi_fdprintf(chan, agi->fd, "100 result=0 Trying...\n");
+ ast_agi_send(agi->fd, chan, "100 result=0 Trying...\n");
ast_pbx_run(chan);
- ast_agi_fdprintf(chan, agi->fd, "200 result=0 Gosub complete\n");
+ ast_agi_send(agi->fd, chan, "200 result=0 Gosub complete\n");
if (chan->pbx) {
ast_free(chan->pbx);
}
chan->pbx = pbx;
} else {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d Gosub failed\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d Gosub failed\n", res);
}
ast_free(gosub_args);
} else {
- ast_agi_fdprintf(chan, agi->fd, "503 result=-2 Memory allocation failure\n");
+ ast_agi_send(agi->fd, chan, "503 result=-2 Memory allocation failure\n");
return RESULT_FAILURE;
}
Modified: branches/1.6.0/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/channels/chan_sip.c?view=diff&rev=157738&r1=157737&r2=157738
==============================================================================
--- branches/1.6.0/channels/chan_sip.c (original)
+++ branches/1.6.0/channels/chan_sip.c Wed Nov 19 07:19:49 2008
@@ -4487,7 +4487,7 @@
int outgoing = fup->outgoing_call;
struct sip_user *u = NULL;
struct sip_peer *p = NULL;
- ast_mutex_t *pu_lock;
+ ast_mutex_t *pu_lock = NULL;
ast_debug(3, "Updating call counter for %s call\n", outgoing ? "outgoing" : "incoming");
Modified: branches/1.6.0/include/asterisk/agi.h
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/include/asterisk/agi.h?view=diff&rev=157738&r1=157737&r2=157738
==============================================================================
--- branches/1.6.0/include/asterisk/agi.h (original)
+++ branches/1.6.0/include/asterisk/agi.h Wed Nov 19 07:19:49 2008
@@ -61,11 +61,53 @@
#define AGI_WEAK
#endif
-int AGI_WEAK ast_agi_fdprintf(struct ast_channel *chan, int fd, char *fmt, ...);
+/*!
+ * \brief
+ *
+ * Sends a string of text to an application connected via AGI.
+ *
+ * \param fd The file descriptor for the AGI session (from struct agi_state)
+ * \param chan Pointer to an associated Asterisk channel, if any
+ * \param fmt printf-style format string
+ * \return 0 for success, -1 for failure
+ *
+ */
+int AGI_WEAK ast_agi_send(int fd, struct ast_channel *chan, char *fmt, ...) __attribute__((format(printf, 3, 4)));
int AGI_WEAK ast_agi_register(struct ast_module *mod, agi_command *cmd);
int AGI_WEAK ast_agi_unregister(struct ast_module *mod, agi_command *cmd);
-void AGI_WEAK ast_agi_register_multiple(struct ast_module *mod, agi_command *cmd, int len);
-void AGI_WEAK ast_agi_unregister_multiple(struct ast_module *mod, agi_command *cmd, int len);
+
+/*!
+ * \brief
+ *
+ * Registers a group of AGI commands, provided as an array of struct agi_command
+ * entries.
+ *
+ * \param mod Pointer to the module_info structure for the module that is registering the commands
+ * \param cmd Pointer to the first entry in the array of commands
+ * \param len Length of the array (use the ARRAY_LEN macro to determine this easily)
+ * \return 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.
+ */
+int AGI_WEAK ast_agi_register_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len);
+
+/*!
+ * \brief
+ *
+ * Unregisters a group of AGI commands, provided as an array of struct agi_command
+ * entries.
+ *
+ * \param mod Pointer to the module_info structure for the module that is unregistering the commands
+ * \param cmd Pointer to the first entry in the array of commands
+ * \param len Length of the array (use the ARRAY_LEN macro to determine this easily)
+ * \return 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.
+ */
+int AGI_WEAK ast_agi_unregister_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len);
#if defined(__cplusplus) || defined(c_plusplus)
}
Modified: branches/1.6.0/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/res/res_agi.c?view=diff&rev=157738&r1=157737&r2=157738
==============================================================================
--- branches/1.6.0/res/res_agi.c (original)
+++ branches/1.6.0/res/res_agi.c Wed Nov 19 07:19:49 2008
@@ -114,7 +114,7 @@
AST_THREADSTORAGE(agi_buf);
#define AGI_BUF_INITSIZE 256
-int ast_agi_fdprintf(struct ast_channel *chan, int fd, char *fmt, ...)
+int ast_agi_send(int fd, struct ast_channel *chan, char *fmt, ...)
{
int res = 0;
va_list ap;
@@ -581,7 +581,7 @@
}
}
- if (ast_agi_fdprintf(NULL, s, "agi_network: yes\n") < 0) {
+ if (ast_agi_send(s, NULL, "agi_network: yes\n") < 0) {
if (errno != EINTR) {
ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
close(s);
@@ -592,7 +592,7 @@
/* If we have a script parameter, relay it to the fastagi server */
/* Script parameters take the form of: AGI(agi://my.example.com/?extension=${EXTEN}) */
if (!ast_strlen_zero(script))
- ast_agi_fdprintf(NULL, s, "agi_network_script: %s\n", script);
+ ast_agi_send(s, NULL, "agi_network_script: %s\n", script);
ast_debug(4, "Wow, connected!\n");
fds[0] = s;
@@ -743,40 +743,40 @@
/* Print initial environment, with agi_request always being the first
thing */
- ast_agi_fdprintf(chan, fd, "agi_request: %s\n", request);
- ast_agi_fdprintf(chan, fd, "agi_channel: %s\n", chan->name);
- ast_agi_fdprintf(chan, fd, "agi_language: %s\n", chan->language);
- ast_agi_fdprintf(chan, fd, "agi_type: %s\n", chan->tech->type);
- ast_agi_fdprintf(chan, fd, "agi_uniqueid: %s\n", chan->uniqueid);
- ast_agi_fdprintf(chan, fd, "agi_version: %s\n", ast_get_version());
+ ast_agi_send(fd, chan, "agi_request: %s\n", request);
+ ast_agi_send(fd, chan, "agi_channel: %s\n", chan->name);
+ ast_agi_send(fd, chan, "agi_language: %s\n", chan->language);
+ ast_agi_send(fd, chan, "agi_type: %s\n", chan->tech->type);
+ ast_agi_send(fd, chan, "agi_uniqueid: %s\n", chan->uniqueid);
+ ast_agi_send(fd, chan, "agi_version: %s\n", ast_get_version());
/* ANI/DNIS */
- ast_agi_fdprintf(chan, fd, "agi_callerid: %s\n", S_OR(chan->cid.cid_num, "unknown"));
- ast_agi_fdprintf(chan, fd, "agi_calleridname: %s\n", S_OR(chan->cid.cid_name, "unknown"));
- ast_agi_fdprintf(chan, fd, "agi_callingpres: %d\n", chan->cid.cid_pres);
- ast_agi_fdprintf(chan, fd, "agi_callingani2: %d\n", chan->cid.cid_ani2);
- ast_agi_fdprintf(chan, fd, "agi_callington: %d\n", chan->cid.cid_ton);
- ast_agi_fdprintf(chan, fd, "agi_callingtns: %d\n", chan->cid.cid_tns);
- ast_agi_fdprintf(chan, fd, "agi_dnid: %s\n", S_OR(chan->cid.cid_dnid, "unknown"));
- ast_agi_fdprintf(chan, fd, "agi_rdnis: %s\n", S_OR(chan->cid.cid_rdnis, "unknown"));
+ ast_agi_send(fd, chan, "agi_callerid: %s\n", S_OR(chan->cid.cid_num, "unknown"));
+ ast_agi_send(fd, chan, "agi_calleridname: %s\n", S_OR(chan->cid.cid_name, "unknown"));
+ ast_agi_send(fd, chan, "agi_callingpres: %d\n", chan->cid.cid_pres);
+ ast_agi_send(fd, chan, "agi_callingani2: %d\n", chan->cid.cid_ani2);
+ ast_agi_send(fd, chan, "agi_callington: %d\n", chan->cid.cid_ton);
+ ast_agi_send(fd, chan, "agi_callingtns: %d\n", chan->cid.cid_tns);
+ ast_agi_send(fd, chan, "agi_dnid: %s\n", S_OR(chan->cid.cid_dnid, "unknown"));
+ ast_agi_send(fd, chan, "agi_rdnis: %s\n", S_OR(chan->cid.cid_rdnis, "unknown"));
/* Context information */
- ast_agi_fdprintf(chan, fd, "agi_context: %s\n", chan->context);
- ast_agi_fdprintf(chan, fd, "agi_extension: %s\n", chan->exten);
- ast_agi_fdprintf(chan, fd, "agi_priority: %d\n", chan->priority);
- ast_agi_fdprintf(chan, fd, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0");
+ ast_agi_send(fd, chan, "agi_context: %s\n", chan->context);
+ ast_agi_send(fd, chan, "agi_extension: %s\n", chan->exten);
+ ast_agi_send(fd, chan, "agi_priority: %d\n", chan->priority);
+ ast_agi_send(fd, chan, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0");
/* User information */
- ast_agi_fdprintf(chan, fd, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : "");
- ast_agi_fdprintf(chan, fd, "agi_threadid: %ld\n", (long)pthread_self());
+ ast_agi_send(fd, chan, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : "");
+ ast_agi_send(fd, chan, "agi_threadid: %ld\n", (long)pthread_self());
/* Send any parameters to the fastagi server that have been passed via the agi application */
/* Agi application paramaters take the form of: AGI(/path/to/example/script|${EXTEN}) */
for(count = 1; count < argc; count++)
- ast_agi_fdprintf(chan, fd, "agi_arg_%d: %s\n", count, argv[count]);
+ ast_agi_send(fd, chan, "agi_arg_%d: %s\n", count, argv[count]);
/* End with empty return */
- ast_agi_fdprintf(chan, fd, "\n");
+ ast_agi_send(fd, chan, "\n");
}
static int handle_answer(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
@@ -787,7 +787,7 @@
if (chan->_state != AST_STATE_UP)
res = ast_answer(chan);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -800,7 +800,7 @@
if (sscanf(argv[3], "%d", &to) != 1)
return RESULT_SHOWUSAGE;
res = ast_waitfordigit_full(chan, to, agi->audio, agi->ctrl);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -819,7 +819,7 @@
parsing, then here, add a newline at the end of the string
before sending it to ast_sendtext --DUDE */
res = ast_sendtext(chan, argv[2]);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -832,17 +832,15 @@
res = ast_recvchar(chan,atoi(argv[2]));
if (res == 0) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d (timeout)\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d (timeout)\n", res);
return RESULT_SUCCESS;
}
if (res > 0) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return RESULT_SUCCESS;
}
- else {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d (hangup)\n", res);
- return RESULT_FAILURE;
- }
+ ast_agi_send(agi->fd, chan, "200 result=%d (hangup)\n", res);
+ return RESULT_FAILURE;
}
static int handle_recvtext(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
@@ -854,10 +852,10 @@
buf = ast_recvtext(chan,atoi(argv[2]));
if (buf) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s)\n", buf);
+ ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", buf);
ast_free(buf);
} else {
- ast_agi_fdprintf(chan, agi->fd, "200 result=-1\n");
+ ast_agi_send(agi->fd, chan, "200 result=-1\n");
}
return RESULT_SUCCESS;
}
@@ -879,9 +877,9 @@
x = 1;
res = ast_channel_setoption(chan, AST_OPTION_TDD, &x, sizeof(char), 0);
if (res != RESULT_SUCCESS)
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -895,7 +893,7 @@
res = ast_send_image(chan, argv[2]);
if (!ast_check_hangup(chan))
res = 0;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -932,7 +930,7 @@
res = ast_control_streamfile(chan, argv[3], fwd, rev, stop, pause, NULL, skipms, NULL);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -954,7 +952,7 @@
return RESULT_SHOWUSAGE;
if (!(fs = ast_openstream(chan, argv[2], chan->language))) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", 0, sample_offset);
return RESULT_SUCCESS;
}
@@ -982,7 +980,7 @@
/* Stop this command, don't print a result line, as there is a new command */
return RESULT_SUCCESS;
}
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, sample_offset);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1009,7 +1007,7 @@
}
if (!(fs = ast_openstream(chan, argv[2], chan->language))) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", 0, sample_offset);
ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]);
return RESULT_SUCCESS;
}
@@ -1047,7 +1045,7 @@
res=0;
}
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, sample_offset);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1067,7 +1065,7 @@
res = ast_say_number_full(chan, num, argv[3], chan->language, argc > 4 ? argv[4] : NULL, agi->audio, agi->ctrl);
if (res == 1)
return RESULT_SUCCESS;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1083,7 +1081,7 @@
res = ast_say_digit_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
if (res == 1) /* New command */
return RESULT_SUCCESS;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1097,7 +1095,7 @@
res = ast_say_character_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
if (res == 1) /* New command */
return RESULT_SUCCESS;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1112,7 +1110,7 @@
res = ast_say_date(chan, num, argv[3], chan->language);
if (res == 1)
return RESULT_SUCCESS;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1127,7 +1125,7 @@
res = ast_say_time(chan, num, argv[3], chan->language);
if (res == 1)
return RESULT_SUCCESS;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1161,7 +1159,7 @@
if (res == 1)
return RESULT_SUCCESS;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1175,7 +1173,7 @@
res = ast_say_phonetic_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
if (res == 1) /* New command */
return RESULT_SUCCESS;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -1198,11 +1196,11 @@
if (res == 2) /* New command */
return RESULT_SUCCESS;
else if (res == 1)
- ast_agi_fdprintf(chan, agi->fd, "200 result=%s (timeout)\n", data);
+ ast_agi_send(agi->fd, chan, "200 result=%s (timeout)\n", data);
else if (res < 0 )
- ast_agi_fdprintf(chan, agi->fd, "200 result=-1\n");
+ ast_agi_send(agi->fd, chan, "200 result=-1\n");
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=%s\n", data);
+ ast_agi_send(agi->fd, chan, "200 result=%s\n", data);
return RESULT_SUCCESS;
}
@@ -1212,7 +1210,7 @@
if (argc != 3)
return RESULT_SHOWUSAGE;
ast_copy_string(chan->context, argv[2], sizeof(chan->context));
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1221,7 +1219,7 @@
if (argc != 3)
return RESULT_SHOWUSAGE;
ast_copy_string(chan->exten, argv[2], sizeof(chan->exten));
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1238,7 +1236,7 @@
}
ast_explicit_goto(chan, NULL, NULL, pri);
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1314,12 +1312,12 @@
if (!res)
res = ast_waitstream(chan, argv[4]);
if (res) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
} else {
fs = ast_writefile(argv[2], argv[3], NULL, O_CREAT | O_WRONLY | (sample_offset ? O_APPEND : 0), 0, AST_FILE_MODE);
if (!fs) {
res = -1;
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d (writefile)\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d (writefile)\n", res);
if (sildet)
ast_dsp_free(sildet);
return RESULT_FAILURE;
@@ -1339,14 +1337,14 @@
res = ast_waitfor(chan, -1);
if (res < 0) {
ast_closestream(fs);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d (waitfor) endpos=%ld\n", res,sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d (waitfor) endpos=%ld\n", res,sample_offset);
if (sildet)
ast_dsp_free(sildet);
return RESULT_FAILURE;
}
f = ast_read(chan);
if (!f) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d (hangup) endpos=%ld\n", -1, sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d (hangup) endpos=%ld\n", -1, sample_offset);
ast_closestream(fs);
if (sildet)
ast_dsp_free(sildet);
@@ -1361,7 +1359,7 @@
ast_stream_rewind(fs, 200);
ast_truncstream(fs);
sample_offset = ast_tellstream(fs);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d (dtmf) endpos=%ld\n", f->subclass, sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d (dtmf) endpos=%ld\n", f->subclass, sample_offset);
ast_closestream(fs);
ast_frfree(f);
if (sildet)
@@ -1406,7 +1404,7 @@
ast_truncstream(fs);
sample_offset = ast_tellstream(fs);
}
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset);
+ ast_agi_send(agi->fd, chan, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset);
ast_closestream(fs);
}
@@ -1433,7 +1431,7 @@
chan->whentohangup = time(NULL) + timeout;
else
chan->whentohangup = 0;
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1444,7 +1442,7 @@
if (argc == 1) {
/* no argument: hangup the current channel */
ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT);
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
} else if (argc == 2) {
/* one argument: look for info on the specified channel */
@@ -1452,12 +1450,12 @@
if (c) {
/* we have a matching channel */
ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT);
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
ast_channel_unlock(c);
return RESULT_SUCCESS;
}
/* if we get this far no channel name matched the argument given */
- ast_agi_fdprintf(chan, agi->fd, "200 result=-1\n");
+ ast_agi_send(agi->fd, chan, "200 result=-1\n");
return RESULT_SUCCESS;
} else {
return RESULT_SHOWUSAGE;
@@ -1496,7 +1494,7 @@
ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
res = -2;
}
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
/* Even though this is wrong, users are depending upon this result. */
return res;
@@ -1519,7 +1517,7 @@
ast_set_callerid(chan, l, n, NULL);
}
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -1528,18 +1526,18 @@
struct ast_channel *c;
if (argc == 2) {
/* no argument: supply info on the current channel */
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", chan->_state);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", chan->_state);
return RESULT_SUCCESS;
} else if (argc == 3) {
/* one argument: look for info on the specified channel */
c = ast_get_channel_by_name_locked(argv[2]);
if (c) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", c->_state);
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", c->_state);
ast_channel_unlock(c);
return RESULT_SUCCESS;
}
/* if we get this far no channel name matched the argument given */
- ast_agi_fdprintf(chan, agi->fd, "200 result=-1\n");
+ ast_agi_send(agi->fd, chan, "200 result=-1\n");
return RESULT_SUCCESS;
} else {
return RESULT_SHOWUSAGE;
@@ -1551,7 +1549,7 @@
if (argv[3])
pbx_builtin_setvar_helper(chan, argv[2], argv[3]);
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -1571,9 +1569,9 @@
}
if (ret)
- ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s)\n", ret);
+ ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ret);
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1592,9 +1590,9 @@
}
if (chan2) {
pbx_substitute_variables_helper(chan2, argv[3], tmp, sizeof(tmp) - 1);
- ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s)\n", tmp);
+ ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", tmp);
} else {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
}
if (chan2 && (chan2 != chan))
ast_channel_unlock(chan2);
@@ -1613,7 +1611,7 @@
ast_verb(level, "%s: %s\n", chan->data, argv[1]);
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -1627,9 +1625,9 @@
return RESULT_SHOWUSAGE;
res = ast_db_get(argv[2], argv[3], tmp, sizeof(tmp));
if (res)
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s)\n", tmp);
+ ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", tmp);
return RESULT_SUCCESS;
}
@@ -1641,7 +1639,7 @@
if (argc != 5)
return RESULT_SHOWUSAGE;
res = ast_db_put(argv[2], argv[3], argv[4]);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%c\n", res ? '0' : '1');
+ ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
return RESULT_SUCCESS;
}
@@ -1652,7 +1650,7 @@
if (argc != 4)
return RESULT_SHOWUSAGE;
res = ast_db_del(argv[2], argv[3]);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%c\n", res ? '0' : '1');
+ ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
return RESULT_SUCCESS;
}
@@ -1667,7 +1665,7 @@
else
res = ast_db_deltree(argv[2], NULL);
- ast_agi_fdprintf(chan, agi->fd, "200 result=%c\n", res ? '0' : '1');
+ ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
return RESULT_SUCCESS;
}
@@ -1702,7 +1700,7 @@
static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, char *argv[])
{
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1712,7 +1710,7 @@
ast_moh_start(chan, argc > 3 ? argv[3] : NULL, NULL);
else if (!strncasecmp(argv[2], "off", 3))
ast_moh_stop(chan);
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1720,14 +1718,14 @@
{
/* If a structure already exists, return an error */
if (agi->speech) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
if ((agi->speech = ast_speech_new(argv[2], AST_FORMAT_SLINEAR)))
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1740,12 +1738,12 @@
/* Check to make sure speech structure exists */
if (!agi->speech) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
ast_speech_change(agi->speech, argv[2], argv[3]);
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -1755,9 +1753,9 @@
if (agi->speech) {
ast_speech_destroy(agi->speech);
agi->speech = NULL;
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
} else {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
}
return RESULT_SUCCESS;
@@ -1769,14 +1767,14 @@
return RESULT_SHOWUSAGE;
if (!agi->speech) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
if (ast_speech_grammar_load(agi->speech, argv[3], argv[4]))
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -1787,14 +1785,14 @@
return RESULT_SHOWUSAGE;
if (!agi->speech) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
if (ast_speech_grammar_unload(agi->speech, argv[3]))
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -1805,14 +1803,14 @@
return RESULT_SHOWUSAGE;
if (!agi->speech) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
if (ast_speech_grammar_activate(agi->speech, argv[3]))
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -1823,14 +1821,14 @@
return RESULT_SHOWUSAGE;
if (!agi->speech) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
if (ast_speech_grammar_deactivate(agi->speech, argv[3]))
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
else
- ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+ ast_agi_send(agi->fd, chan, "200 result=1\n");
return RESULT_SUCCESS;
}
@@ -1870,7 +1868,7 @@
return RESULT_SHOWUSAGE;
if (!speech) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1884,7 +1882,7 @@
/* We want frames coming in signed linear */
old_read_format = chan->readformat;
if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
@@ -1989,13 +1987,13 @@
i++;
}
/* Print out */
- ast_agi_fdprintf(chan, agi->fd, "200 result=1 (speech) endpos=%ld results=%d %s\n", current_offset, i, tmp);
+ ast_agi_send(agi->fd, chan, "200 result=1 (speech) endpos=%ld results=%d %s\n", current_offset, i, tmp);
} else if (!strcasecmp(reason, "dtmf")) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=1 (digit) digit=%c endpos=%ld\n", dtmf, current_offset);
+ ast_agi_send(agi->fd, chan, "200 result=1 (digit) digit=%c endpos=%ld\n", dtmf, current_offset);
} else if (!strcasecmp(reason, "hangup") || !strcasecmp(reason, "timeout")) {
- ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s) endpos=%ld\n", reason, current_offset);
+ ast_agi_send(agi->fd, chan, "200 result=1 (%s) endpos=%ld\n", reason, current_offset);
} else {
- ast_agi_fdprintf(chan, agi->fd, "200 result=0 endpos=%ld\n", current_offset);
+ ast_agi_send(agi->fd, chan, "200 result=0 endpos=%ld\n", current_offset);
}
return RESULT_SUCCESS;
@@ -2003,7 +2001,7 @@
static int handle_asyncagi_break(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{
- ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
return AST_PBX_KEEPALIVE;
}
@@ -2418,21 +2416,50 @@
return unregistered;
}
-void ast_agi_register_multiple(struct ast_module *mod, agi_command *cmd, int len)
-{
- int i;
-
- for (i = 0; i < len; i++)
- ast_agi_register(mod, cmd + i);
-
-}
-
-void ast_agi_unregister_multiple(struct ast_module *mod, agi_command *cmd, int len)
-{
- int i;
-
- for (i = 0; i < len; i++)
- ast_agi_unregister(mod, cmd + i);
+int ast_agi_register_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len)
+{
+ unsigned int i, x = 0;
+
+ for (i = 0; i < len; i++) {
+ if (ast_agi_register(mod, cmd + i) == 1) {
+ x++;
+ continue;
+ }
+
+ /* registration failed, unregister everything
+ that had been registered up to that point
+ */
+ for (; x > 0; x--) {
+ /* we are intentionally ignoring the
+ result of ast_agi_unregister() here,
+ but it should be safe to do so since
+ we just registered these commands and
+ the only possible way for unregistration
+ to fail is if the command is not
+ registered
+ */
+ (void) ast_agi_unregister(mod, cmd + x - 1);
+ }
+ return -1;
+ }
+
+ return 0;
+}
+
+int ast_agi_unregister_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len)
+{
+ unsigned int i;
+ int res = 0;
+
+ for (i = 0; i < len; i++) {
+ /* remember whether any of the unregistration
+ attempts failed... there is no recourse if
+ any of them do
+ */
+ res |= ast_agi_unregister(mod, cmd + i);
+ }
+
+ return res;
}
static agi_command *find_command(char *cmds[], int exact)
@@ -2574,9 +2601,9 @@
"Result: %s\r\n", chan->name, command_id, ami_cmd, resultcode, ami_res);
switch(res) {
case RESULT_SHOWUSAGE:
- ast_agi_fdprintf(chan, agi->fd, "520-Invalid command syntax. Proper usage follows:\n");
- ast_agi_fdprintf(chan, agi->fd, c->usage);
- ast_agi_fdprintf(chan, agi->fd, "520 End of proper usage.\n");
+ ast_agi_send(agi->fd, chan, "520-Invalid command syntax. Proper usage follows:\n");
+ ast_agi_send(agi->fd, NULL, "%s", c->usage);
+ ast_agi_send(agi->fd, chan, "520 End of proper usage.\n");
break;
case AST_PBX_KEEPALIVE:
/* We've been asked to keep alive, so do so */
@@ -2588,7 +2615,7 @@
return -1;
}
} else if ((c = find_command(argv, 0))) {
- ast_agi_fdprintf(chan, agi->fd, "511 Command Not Permitted on a dead channel\n");
+ ast_agi_send(agi->fd, chan, "511 Command Not Permitted on a dead channel\n");
manager_event(EVENT_FLAG_CALL, "AGIExec",
"SubEvent: End\r\n"
"Channel: %s\r\n"
@@ -2597,7 +2624,7 @@
"ResultCode: 511\r\n"
"Result: Command not permitted on a dead channel\r\n", chan->name, command_id, ami_cmd);
} else {
- ast_agi_fdprintf(chan, agi->fd, "510 Invalid or unknown command\n");
+ ast_agi_send(agi->fd, chan, "510 Invalid or unknown command\n");
manager_event(EVENT_FLAG_CALL, "AGIExec",
"SubEvent: End\r\n"
"Channel: %s\r\n"
@@ -3018,7 +3045,10 @@
static int unload_module(void)
{
ast_cli_unregister_multiple(cli_agi, sizeof(cli_agi) / sizeof(struct ast_cli_entry));
- ast_agi_unregister_multiple(ast_module_info->self, commands, sizeof(commands) / sizeof(struct agi_command));
+ /* we can safely ignore the result of ast_agi_unregister_multiple() here, since it cannot fail, as
+ we know that these commands were registered by this module and are still registered
+ */
+ (void) ast_agi_unregister_multiple(ast_module_info->self, commands, ARRAY_LEN(commands));
ast_unregister_application(eapp);
ast_unregister_application(deadapp);
ast_manager_unregister("AGI");
@@ -3028,7 +3058,10 @@
static int load_module(void)
{
ast_cli_register_multiple(cli_agi, sizeof(cli_agi) / sizeof(struct ast_cli_entry));
- ast_agi_register_multiple(ast_module_info->self, commands, sizeof(commands) / sizeof(struct agi_command));
+ /* we can safely ignore the result of ast_agi_register_multiple() here, since it cannot fail, as
+ no other commands have been registered yet
+ */
+ (void) ast_agi_register_multiple(ast_module_info->self, commands, ARRAY_LEN(commands));
ast_register_application(deadapp, deadagi_exec, deadsynopsis, descrip);
ast_register_application(eapp, eagi_exec, esynopsis, descrip);
ast_manager_register2("AGI", EVENT_FLAG_CALL, action_add_agi_cmd, "Add an AGI command to execute by Async AGI", mandescr_asyncagi);
More information about the asterisk-commits
mailing list