aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_agi.c
diff options
context:
space:
mode:
authorjeremy <jeremy@f38db490-d61c-443f-a65b-d21fe96a405b>2004-03-23 12:50:15 +0000
committerjeremy <jeremy@f38db490-d61c-443f-a65b-d21fe96a405b>2004-03-23 12:50:15 +0000
commit6c02eea3c2bb7b544c4da6f1e54b46e24a9c4d06 (patch)
treef5b35f62c50952af86ff7d71ab418c19e42f99b6 /apps/app_agi.c
parent9ea1d08cd6cdaf6f5f9a9876afa7ffd2ac3f0f41 (diff)
fix agi to accept multiple arguments. Bug #664
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2535 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_agi.c')
-rwxr-xr-xapps/app_agi.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/apps/app_agi.c b/apps/app_agi.c
index 67b017d2c..529fbe2e1 100755
--- a/apps/app_agi.c
+++ b/apps/app_agi.c
@@ -95,7 +95,7 @@ LOCAL_USER_DECL;
#define TONE_BLOCK_SIZE 200
-static int launch_script(char *script, char *args, int *fds, int *efd, int *opid)
+static int launch_script(char *script, char *argv[], int *fds, int *efd, int *opid)
{
char tmp[256];
int pid;
@@ -159,7 +159,7 @@ static int launch_script(char *script, char *args, int *fds, int *efd, int *opid
for (x=STDERR_FILENO + 2;x<1024;x++)
close(x);
/* Execute script */
- execl(script, script, args, (char *)NULL);
+ execv(script, argv);
/* Can't use ast_log since FD's are closed */
fprintf(stderr, "Failed to execute '%s': %s\n", script, strerror(errno));
exit(1);
@@ -1429,12 +1429,13 @@ static int agi_exec_full(struct ast_channel *chan, void *data, int enhanced, int
{
int res=0;
struct localuser *u;
- char *args,*ringy;
- char tmp[256];
+ char *argv[MAX_ARGS];
+ char *tmp = (char *)data;
+ int argc = 0;
int fds[2];
int efd = -1;
int pid;
- char *stringp=tmp;
+ char *stringp;
AGI agi;
if (!data || !strlen(data)) {
ast_log(LOG_WARNING, "AGI requires an argument (script)\n");
@@ -1443,28 +1444,22 @@ static int agi_exec_full(struct ast_channel *chan, void *data, int enhanced, int
memset(&agi, 0, sizeof(agi));
- strncpy(tmp, data, sizeof(tmp)-1);
- strsep(&stringp, "|");
- args = strsep(&stringp, "|");
- ringy = strsep(&stringp,"|");
- if (!args)
- args = "";
+ while ((stringp = strsep(&tmp, "|"))) {
+ argv[argc++] = stringp;
+ }
+ argv[argc] = NULL;
+
LOCAL_USER_ADD(u);
#if 0
/* Answer if need be */
if (chan->_state != AST_STATE_UP) {
- if (ringy) { /* if for ringing first */
- /* a little ringy-dingy first */
- ast_indicate(chan, AST_CONTROL_RINGING);
- sleep(3);
- }
if (ast_answer(chan)) {
LOCAL_USER_REMOVE(u);
return -1;
}
}
#endif
- res = launch_script(tmp, args, fds, enhanced ? &efd : NULL, &pid);
+ res = launch_script(argv[0], argv, fds, enhanced ? &efd : NULL, &pid);
if (!res) {
agi.fd = fds[1];
agi.ctrl = fds[0];