fix agi to accept multiple arguments. Bug #664

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2535 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
Jeremy McNamara 21 years ago
parent 6e15f28d6a
commit 484484ce89

@ -95,7 +95,7 @@ LOCAL_USER_DECL;
#define TONE_BLOCK_SIZE 200 #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]; char tmp[256];
int pid; 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++) for (x=STDERR_FILENO + 2;x<1024;x++)
close(x); close(x);
/* Execute script */ /* Execute script */
execl(script, script, args, (char *)NULL); execv(script, argv);
/* Can't use ast_log since FD's are closed */ /* Can't use ast_log since FD's are closed */
fprintf(stderr, "Failed to execute '%s': %s\n", script, strerror(errno)); fprintf(stderr, "Failed to execute '%s': %s\n", script, strerror(errno));
exit(1); exit(1);
@ -1429,12 +1429,13 @@ static int agi_exec_full(struct ast_channel *chan, void *data, int enhanced, int
{ {
int res=0; int res=0;
struct localuser *u; struct localuser *u;
char *args,*ringy; char *argv[MAX_ARGS];
char tmp[256]; char *tmp = (char *)data;
int argc = 0;
int fds[2]; int fds[2];
int efd = -1; int efd = -1;
int pid; int pid;
char *stringp=tmp; char *stringp;
AGI agi; AGI agi;
if (!data || !strlen(data)) { if (!data || !strlen(data)) {
ast_log(LOG_WARNING, "AGI requires an argument (script)\n"); 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)); memset(&agi, 0, sizeof(agi));
strncpy(tmp, data, sizeof(tmp)-1); while ((stringp = strsep(&tmp, "|"))) {
strsep(&stringp, "|"); argv[argc++] = stringp;
args = strsep(&stringp, "|"); }
ringy = strsep(&stringp,"|"); argv[argc] = NULL;
if (!args)
args = "";
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
#if 0 #if 0
/* Answer if need be */ /* Answer if need be */
if (chan->_state != AST_STATE_UP) { 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)) { if (ast_answer(chan)) {
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
return -1; return -1;
} }
} }
#endif #endif
res = launch_script(tmp, args, fds, enhanced ? &efd : NULL, &pid); res = launch_script(argv[0], argv, fds, enhanced ? &efd : NULL, &pid);
if (!res) { if (!res) {
agi.fd = fds[1]; agi.fd = fds[1];
agi.ctrl = fds[0]; agi.ctrl = fds[0];

Loading…
Cancel
Save