1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
main(void)
{
char *lenstr;
char input[MAXINPUT], data[MAXINPUT];
long len;
char *AudioFile;
char *Grammar;
char *GrammerFileName;
char GrammarPath[255];
char DefaultAudioFilePath[255];
char *DefaultDirectoryPath="/tmp/mondir/";
char *CurrentGrammarPath="/var/www/cgi/";
char ExtarctCommand[40];
char **buf = NULL;
int rc;
char *result;
int i = 0;
char *XMLResult="<?xml version='1.0' encoding='UTF-8'?><vxml version='2.0'><form><block><var name='ResultASR' expr='RecoRes'/><return namelist='ResultASR'/></block></form></vxml>";
/*
calculate the size of informations placed in the input stream
*/
FILE * test;
lenstr = getenv("CONTENT_LENGTH");
if(lenstr == NULL)
PrintHTMLHeaderAndMessage(500,"lentstr problem\n");
else if ( sscanf(lenstr,"%ld",&len)!=1)
PrintHTMLHeaderAndMessage(500,"error sscanf.\n");
else if ( len > MAXLEN)
PrintHTMLHeaderAndMessage(500,"len et MAXLEN prob.\n");
else
{
FILE * f;
/*
delete old toto.mul file if it exist.
*/
if(f=fopen("toto.mul", "a"))
{
fclose(f);
system("rm toto.mul");
}
/* ompen the toto.mul file */
f = fopen("toto.mul", "a");
if(f == NULL){
PrintHTMLHeaderAndMessage(500,"Sorry, cannot store your data.\n");
perror("You goofed!");
printf("errno = %d.\n", errno);
}
else
{
/*
read and copy informations posted by the user int the toto.mul file
*/
int bytes_read = fread(input, sizeof(char),len+100,stdin);
if(bytes_read > 0)
{
fwrite(input, sizeof(char), bytes_read,f);
bytes_read = fread(input, sizeof(char),len+100,stdin);
}
fclose(f);
/*
Executing the extractmulitpart Script: extracting all useful data
posted by the user( AudioFile and Grammar) without Mime header.
*/
system("extractmultipart /tmp/mondir/%s < toto.mul");
/*
Finding the full name of the AudioFile and the Grammar
uploaded on the server by the user.
*/
ExtractAudioFileAndGrammar(&AudioFile,&Grammar,&GrammerFileName);
test=fopen("test.txt","w");
if(test==NULL)
{
printf("erreur");
}
else{
fprintf(test,Grammar);
fclose(test);
}
/*
Downloading the grammar
*/
strcat(ExtarctCommand,"wget");
strcat(ExtarctCommand," ");
strcat(ExtarctCommand,Grammar);
system(ExtarctCommand);
/*constuction of the path of grammar*/
strcpy(GrammarPath,CurrentGrammarPath);
strcat(GrammarPath,GrammerFileName);
/*
Construction of the AudioFile real Path on the disc
*/
strcpy(DefaultAudioFilePath,DefaultDirectoryPath);
strcat(DefaultAudioFilePath,AudioFile);
/*
Initialising all needed server parmaters for recognition
*/
int res=nc_init();
/*
Loading grammar for the recognition process
*/
res=set_param("load_grammar",GrammarPath);
/*
Starting the recognition
*/
if(AudioFile)
{
printf ("\n Calling Reconize.\n");
result=reconize(DefaultAudioFilePath);
printf("%s\n",result);
result =XMLParser("SWI_literal",result);
replace(XMLResult,"RecoRes",result);
/*just for testing*/
PrintXMLHeaderAndMessage(200,XMLResult);
}
else{
printf("audio file missing");
return 0;
}
/*
close all ressources
*/
nc_close();
/*
Delete the temporary AudioFile and Grammar.
*/
system("rm -f /tmp/mondir/*" );
}
}
return 0;
} |
Partager