fix for MODAPP-24

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5571 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-08-06 17:18:16 +00:00
parent e34d546285
commit 55b1d281a3
1 changed files with 83 additions and 29 deletions

View File

@ -131,11 +131,55 @@ void die(char *error_str)
} }
static void set_vars(char *data)
{
char *start, *end, *p=malloc(strlen(data)+1);
char name[8192],value[8192];
if(!p) {
perror("malloc");
exit(1);
}
memcpy(p,data,strlen(data)+1);
start=p;
while(start != 0 && *start != '\0') {
if(end = strchr(start,'\r')) {
*end = '\0';
if(*(end + 1) == '\n') {
end+=2;
} else {
end++;
}
} else {
return;
}
sscanf(start,"%s: %s",name,value);
setenv(name,value,1);
start = end;
}
free(p);
}
static int cheezy_get_var(char *data, char *name, char *buf, size_t buflen) static int cheezy_get_var(char *data, char *name, char *buf, size_t buflen)
{ {
char *p; char *p=data;
if ((p = strstr(data, name))) { /* the old way didnt make sure that variable values were used for the name hunt
* and didnt ensure that only a full match of the variable name was used
*/
do {
if(!strncmp(p,name,strlen(name)) && *(p+strlen(name))==':') break;
} while((p = (strstr(p,"\n")+1))!=(char *)1);
if (p != (char *)1 && *p!='\0') {
char *v, *e; char *v, *e;
if ((v = strchr(p, ':'))) { if ((v = strchr(p, ':'))) {
@ -227,6 +271,12 @@ void client_run(int client_socket, char *local_ip, int local_port, char *remote_
send_fax = TRUE; send_fax = TRUE;
} }
} }
if (cheezy_get_var(infobuf, "variable_fax_preexec", tmp, sizeof(tmp))) {
set_vars(infobuf);
system(tmp);
}
#if SOCKET2ME_DEBUG #if SOCKET2ME_DEBUG
printf("SEND: [%s]\n", sendbuf); printf("SEND: [%s]\n", sendbuf);
#endif #endif
@ -382,6 +432,10 @@ void client_run(int client_socket, char *local_ip, int local_port, char *remote_
t30_terminate(&fax.t30_state); t30_terminate(&fax.t30_state);
fax_release(&fax); fax_release(&fax);
if (cheezy_get_var(infobuf, "variable_fax_postexec", tmp, sizeof(tmp))) {
set_vars(infobuf);
system(tmp);
}
printf("Done\n"); printf("Done\n");
snprintf(sendbuf, sizeof(sendbuf), "hangup\n\n"); snprintf(sendbuf, sizeof(sendbuf), "hangup\n\n");
send(client_socket, sendbuf, strlen(sendbuf), 0); send(client_socket, sendbuf, strlen(sendbuf), 0);