[asterisk-commits] rmudgett: trunk r313659 - in /trunk: ./ res/res_agi.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 13 12:51:18 CDT 2011
Author: rmudgett
Date: Wed Apr 13 12:51:14 2011
New Revision: 313659
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=313659
Log:
Merged revisions 313658 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r313658 | rmudgett | 2011-04-13 12:47:43 -0500 (Wed, 13 Apr 2011) | 2 lines
Miscellaneous AGI diagnostic message cleanup and code optimization.
........
Modified:
trunk/ (props changed)
trunk/res/res_agi.c
Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: trunk/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_agi.c?view=diff&rev=313659&r1=313658&r2=313659
==============================================================================
--- trunk/res/res_agi.c (original)
+++ trunk/res/res_agi.c Wed Apr 13 12:51:14 2011
@@ -1003,7 +1003,8 @@
store = ast_channel_datastore_find(chan, &agi_commands_datastore_info, NULL);
ast_channel_unlock(chan);
if (!store) {
- ast_log(LOG_ERROR, "Hu? datastore disappeared at Async AGI on Channel %s!\n", chan->name);
+ ast_log(LOG_ERROR, "Huh? Async AGI datastore disappeared on Channel %s!\n",
+ chan->name);
return NULL;
}
agi_commands = store->data;
@@ -1022,7 +1023,7 @@
store = ast_channel_datastore_find(chan, &agi_commands_datastore_info, NULL);
if (!store) {
- ast_log(LOG_WARNING, "Channel %s is not at Async AGI.\n", chan->name);
+ ast_log(LOG_WARNING, "Channel %s is not setup for Async AGI.\n", chan->name);
return -1;
}
agi_commands = store->data;
@@ -1111,14 +1112,14 @@
}
if (!(chan = ast_channel_get_by_name(a->argv[2]))) {
- ast_log(LOG_WARNING, "Channel %s does not exists or cannot lock it\n", a->argv[2]);
+ ast_cli(a->fd, "Channel %s does not exist.\n", a->argv[2]);
return CLI_FAILURE;
}
ast_channel_lock(chan);
if (add_agi_cmd(chan, a->argv[3], (a->argc > 4 ? a->argv[4] : ""))) {
- ast_log(LOG_WARNING, "failed to add AGI command to queue of channel %s\n", chan->name);
+ ast_cli(a->fd, "Failed to add AGI command to queue of channel %s\n", chan->name);
ast_channel_unlock(chan);
chan = ast_channel_unref(chan);
return CLI_FAILURE;
@@ -1157,7 +1158,7 @@
}
if (!(chan = ast_channel_get_by_name(channel))) {
- snprintf(buf, sizeof(buf), "Channel %s does not exists or cannot get its lock", channel);
+ snprintf(buf, sizeof(buf), "Channel %s does not exist.", channel);
astman_send_error(s, m, buf);
return 0;
}
@@ -1182,6 +1183,7 @@
static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead);
static void setup_env(struct ast_channel *chan, char *request, int fd, int enhanced, int argc, char *argv[]);
+
static enum agi_result launch_asyncagi(struct ast_channel *chan, char *argv[], int *efd)
{
/* This buffer sizes might cause truncation if the AGI command writes more data
@@ -1219,7 +1221,7 @@
/* add AsyncAGI datastore to the channel */
if (add_to_agi(chan)) {
- ast_log(LOG_ERROR, "failed to start Async AGI on channel %s\n", chan->name);
+ ast_log(LOG_ERROR, "Failed to start Async AGI on channel %s\n", chan->name);
return AGI_RESULT_FAILURE;
}
@@ -1232,7 +1234,7 @@
the AGI commands */
res = pipe(fds);
if (res) {
- ast_log(LOG_ERROR, "failed to create Async AGI pipe\n");
+ ast_log(LOG_ERROR, "Failed to create Async AGI pipe\n");
/* intentionally do not remove datastore, added with
add_to_agi(), from channel. It will be removed when
the channel is hung up anyways */
@@ -1253,7 +1255,8 @@
/* read the environment */
res = read(fds[0], agi_buffer, AGI_BUF_SIZE);
if (!res) {
- ast_log(LOG_ERROR, "failed to read from Async AGI pipe on channel %s\n", chan->name);
+ ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s\n",
+ chan->name);
returnstatus = AGI_RESULT_FAILURE;
goto quit;
}
@@ -1285,7 +1288,8 @@
res = read(fds[0], agi_buffer, AGI_BUF_SIZE);
if (!res) {
returnstatus = AGI_RESULT_FAILURE;
- ast_log(LOG_ERROR, "failed to read from AsyncAGI pipe on channel %s\n", chan->name);
+ ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s\n",
+ chan->name);
free_agi_cmd(cmd);
break;
}
@@ -1771,7 +1775,8 @@
x = 1;
}
res = ast_channel_setoption(chan, AST_OPTION_TDD, &x, sizeof(char), 0);
- if (res != RESULT_SUCCESS) {
+ if (res) {
+ /* Set channel option failed */
ast_agi_send(agi->fd, chan, "200 result=0\n");
} else {
ast_agi_send(agi->fd, chan, "200 result=1\n");
@@ -3269,11 +3274,13 @@
static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead)
{
const char *argv[MAX_ARGS];
- int argc = MAX_ARGS, res;
+ int argc = MAX_ARGS;
+ int res;
agi_command *c;
- const char *ami_res = "Unknown Result";
+ const char *ami_res;
char *ami_cmd = ast_strdupa(buf);
- int command_id = ast_random(), resultcode = 200;
+ int command_id = ast_random();
+ int resultcode;
manager_event(EVENT_FLAG_AGI, "AGIExec",
"SubEvent: Start\r\n"
@@ -3281,8 +3288,9 @@
"CommandId: %d\r\n"
"Command: %s\r\n", chan->name, command_id, ami_cmd);
parse_args(buf, &argc, argv);
- if ((c = find_command(argv, 0)) && (!dead || (dead && c->dead))) {
- /* if this command wasnt registered by res_agi, be sure to usecount
+ c = find_command(argv, 0);
+ if (c && (!dead || (dead && c->dead))) {
+ /* if this command wasn't registered by res_agi, be sure to usecount
the module we are using */
if (c->mod != ast_module_info->self)
ast_module_ref(c->mod);
@@ -3295,9 +3303,22 @@
if (c->mod != ast_module_info->self)
ast_module_unref(c->mod);
switch (res) {
- case RESULT_SHOWUSAGE: ami_res = "Usage"; resultcode = 520; break;
- case RESULT_FAILURE: ami_res = "Failure"; resultcode = -1; break;
- case RESULT_SUCCESS: ami_res = "Success"; resultcode = 200; break;
+ case RESULT_SHOWUSAGE:
+ ami_res = "Usage";
+ resultcode = 520;
+ break;
+ case RESULT_FAILURE:
+ ami_res = "Failure";
+ resultcode = -1;
+ break;
+ case RESULT_SUCCESS:
+ ami_res = "Success";
+ resultcode = 200;
+ break;
+ default:
+ ami_res = "Unknown Result";
+ resultcode = 200;
+ break;
}
manager_event(EVENT_FLAG_AGI, "AGIExec",
"SubEvent: End\r\n"
@@ -3306,7 +3327,7 @@
"Command: %s\r\n"
"ResultCode: %d\r\n"
"Result: %s\r\n", chan->name, command_id, ami_cmd, resultcode, ami_res);
- switch(res) {
+ switch (res) {
case RESULT_SHOWUSAGE:
if (ast_strlen_zero(c->usage)) {
ast_agi_send(agi->fd, chan, "520 Invalid command syntax. Proper usage not available.\n");
@@ -3322,7 +3343,7 @@
default:
break;
}
- } else if ((c = find_command(argv, 0))) {
+ } else if (c) {
ast_agi_send(agi->fd, chan, "511 Command Not Permitted on a dead channel\n");
manager_event(EVENT_FLAG_AGI, "AGIExec",
"SubEvent: End\r\n"
@@ -3346,7 +3367,9 @@
static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
{
struct ast_channel *c;
- int outfd, ms, needhup = 0;
+ int outfd;
+ int ms;
+ int needhup = 0;
enum agi_result returnstatus = AGI_RESULT_SUCCESS;
struct ast_frame *f;
char buf[AGI_BUF_LEN];
@@ -3457,8 +3480,11 @@
}
/* get rid of trailing newline, if any */
- if (*buf && buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = 0;
+ buflen = strlen(buf);
+ if (buflen && buf[buflen - 1] == '\n') {
+ buf[buflen - 1] = '\0';
+ }
+
if (agidebug)
ast_verbose("<%s>AGI Rx << %s\n", chan->name, buf);
cmd_status = agi_handle_command(chan, agi, buf, dead);
More information about the asterisk-commits
mailing list