1 | /** |
---|
2 | * Author : Gérald FENOY |
---|
3 | * |
---|
4 | * Copyright 2008-2009 GeoLabs SARL. All rights reserved. |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
7 | * of this software and associated documentation files (the "Software"), to deal |
---|
8 | * in the Software without restriction, including without limitation the rights |
---|
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
10 | * copies of the Software, and to permit persons to whom the Software is |
---|
11 | * furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
22 | * THE SOFTWARE. |
---|
23 | */ |
---|
24 | |
---|
25 | #define length(x) (sizeof(x) / sizeof(x[0])) |
---|
26 | |
---|
27 | extern "C" int yylex(); |
---|
28 | extern "C" int crlex(); |
---|
29 | extern "C" { |
---|
30 | #include <libxml/tree.h> |
---|
31 | #include <libxml/xmlmemory.h> |
---|
32 | #include <libxml/parser.h> |
---|
33 | #include <libxml/xpath.h> |
---|
34 | #include <libxml/xpathInternals.h> |
---|
35 | } |
---|
36 | |
---|
37 | #include "cgic.h" |
---|
38 | #include "ulinet.h" |
---|
39 | |
---|
40 | #include <string.h> |
---|
41 | |
---|
42 | #include "service.h" |
---|
43 | #include "service_internal.h" |
---|
44 | #include "service_internal_python.h" |
---|
45 | |
---|
46 | #ifdef USE_JAVA |
---|
47 | #include "service_internal_java.h" |
---|
48 | #endif |
---|
49 | |
---|
50 | #ifdef USE_PHP |
---|
51 | #include "service_internal_php.h" |
---|
52 | #endif |
---|
53 | |
---|
54 | #ifdef USE_JS |
---|
55 | #include "service_internal_js.h" |
---|
56 | #endif |
---|
57 | |
---|
58 | |
---|
59 | #include <dirent.h> |
---|
60 | #include <signal.h> |
---|
61 | #include <unistd.h> |
---|
62 | #ifndef WIN32 |
---|
63 | #include <dlfcn.h> |
---|
64 | #include <libgen.h> |
---|
65 | #else |
---|
66 | #include <windows.h> |
---|
67 | #include <direct.h> |
---|
68 | #endif |
---|
69 | #include <fcntl.h> |
---|
70 | #include <time.h> |
---|
71 | #include <stdarg.h> |
---|
72 | |
---|
73 | xmlNodeSet* extractFromDoc(xmlDocPtr doc,char* search){ |
---|
74 | xmlXPathContextPtr xpathCtx; |
---|
75 | xmlXPathObjectPtr xpathObj; |
---|
76 | xpathCtx = xmlXPathNewContext(doc); |
---|
77 | xpathObj = xmlXPathEvalExpression(BAD_CAST search,xpathCtx); |
---|
78 | xmlXPathFreeContext(xpathCtx); |
---|
79 | return xpathObj->nodesetval; |
---|
80 | } |
---|
81 | |
---|
82 | void sigint_handler(int sig){ |
---|
83 | fprintf(stderr,"Not this time!\n"); |
---|
84 | } |
---|
85 | |
---|
86 | int runRequest(map* request_inputs) |
---|
87 | { |
---|
88 | |
---|
89 | map* r_inputs=NULL,*tmps=NULL; |
---|
90 | maps* m=NULL; |
---|
91 | int argc=count(request_inputs); |
---|
92 | |
---|
93 | char* REQUEST=NULL; |
---|
94 | /** |
---|
95 | * Parsing service specfic configuration file |
---|
96 | */ |
---|
97 | m=(maps*)malloc(MAPS_SIZE); |
---|
98 | char ntmp[1024]; |
---|
99 | #ifndef WIN32 |
---|
100 | getcwd(ntmp,1024); |
---|
101 | #else |
---|
102 | _getcwd(ntmp,1024); |
---|
103 | #endif |
---|
104 | char conf_file[1024]; |
---|
105 | sprintf(conf_file,"%s/main.cfg",ntmp); |
---|
106 | conf_read(conf_file,m); |
---|
107 | |
---|
108 | /** |
---|
109 | * Check for minimum inputs |
---|
110 | */ |
---|
111 | r_inputs=getMap(request_inputs,"Request"); |
---|
112 | if(r_inputs==NULLMAP){ |
---|
113 | tmps=createMap("text","Parameter <request> was not specified"); |
---|
114 | addToMap(tmps,"code","MissingParameterValue"); |
---|
115 | printExceptionReportResponse(m,tmps); |
---|
116 | return 1; |
---|
117 | } |
---|
118 | else |
---|
119 | REQUEST=strdup(r_inputs->value); |
---|
120 | r_inputs=NULL; |
---|
121 | r_inputs=getMap(request_inputs,"Service"); |
---|
122 | if(r_inputs==NULLMAP){ |
---|
123 | tmps=createMap("text","Parameter <service> was not specified"); |
---|
124 | addToMap(tmps,"code","MissingParameterValue"); |
---|
125 | printExceptionReportResponse(m,tmps); |
---|
126 | return 1; |
---|
127 | } |
---|
128 | if(strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0){ |
---|
129 | r_inputs=getMap(request_inputs,"Version"); |
---|
130 | if(r_inputs==NULL){ |
---|
131 | tmps=createMap("text","Parameter <version> was not specified"); |
---|
132 | addToMap(tmps,"code","MissingParameterValue"); |
---|
133 | printExceptionReportResponse(m,tmps); |
---|
134 | return 1; |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * Need to print std exception message here |
---|
140 | */ |
---|
141 | char SP[1024]; |
---|
142 | if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)){ |
---|
143 | r_inputs=getMap(request_inputs,"ServiceProvider"); |
---|
144 | if(r_inputs==NULLMAP){ |
---|
145 | tmps=createMap("text","Parameter <serviceprovider> was not specified"); |
---|
146 | addToMap(tmps,"code","MissingParameterValue"); |
---|
147 | printExceptionReportResponse(m,tmps); |
---|
148 | return 1; |
---|
149 | } |
---|
150 | else |
---|
151 | sprintf(SP,"%s",r_inputs->value); |
---|
152 | r_inputs=getMap(request_inputs,"MetaPath"); |
---|
153 | if(r_inputs==NULLMAP){ |
---|
154 | tmps=createMap("text","Parameter <metapath> was not specified"); |
---|
155 | addToMap(tmps,"code","MissingParameterValue"); |
---|
156 | printExceptionReportResponse(m,tmps); |
---|
157 | return 1; |
---|
158 | } |
---|
159 | tmps=createMap("text","Parameter <unknown> was not specified"); |
---|
160 | addToMap(tmps,"code","MissingParameterValue"); |
---|
161 | printExceptionReportResponse(m,tmps); |
---|
162 | return 1; |
---|
163 | } |
---|
164 | |
---|
165 | map* outputs=NULL; |
---|
166 | maps* request_output_real_format=NULL; |
---|
167 | map* tmpm=getMapFromMaps(m,"main","serverAddress"); |
---|
168 | if(tmpm!=NULL) |
---|
169 | SERVICE_URL=strdup(tmpm->value); |
---|
170 | else |
---|
171 | SERVICE_URL=DEFAULT_SERVICE_URL; |
---|
172 | |
---|
173 | service* s[100]; |
---|
174 | service* s1; |
---|
175 | int scount=0; |
---|
176 | |
---|
177 | #ifdef DEBUG |
---|
178 | dumpMap(r_inputs); |
---|
179 | #endif |
---|
180 | char conf_dir[1024]; |
---|
181 | int t; |
---|
182 | char tmps1[1024]; |
---|
183 | |
---|
184 | if(strcmp(mtoupper(REQUEST),mtoupper("GetCapabilities"))==0){ |
---|
185 | int i=0; |
---|
186 | struct dirent *dp; |
---|
187 | r_inputs=NULL; |
---|
188 | r_inputs=getMap(request_inputs,"metapath"); |
---|
189 | #ifdef DEBUG |
---|
190 | dumpMap(r_inputs); |
---|
191 | #endif |
---|
192 | sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value); |
---|
193 | DIR *dirp = opendir(conf_dir); |
---|
194 | if(dirp==NULL){ |
---|
195 | tmps=createMap("text","The specified path doesn't exist."); |
---|
196 | addToMap(tmps,"code","InvalidParameterValue"); |
---|
197 | printExceptionReportResponse(m,tmps); |
---|
198 | return -1; |
---|
199 | } |
---|
200 | xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
201 | doc->encoding = xmlCharStrdup ("UTF-8"); |
---|
202 | r_inputs=NULL; |
---|
203 | r_inputs=getMap(request_inputs,"ServiceProvider"); |
---|
204 | xmlNodePtr n = printGetCapabilitiesHeader(doc,r_inputs->value,m); |
---|
205 | /** |
---|
206 | * Strange, here we need to close stdout to ensure that no uneeded |
---|
207 | * char will be printed (parser issue ?) |
---|
208 | */ |
---|
209 | int saved_stdout = dup(fileno(stdout)); |
---|
210 | dup2(fileno(stderr),fileno(stdout)); |
---|
211 | while ((dp = readdir(dirp)) != NULL) |
---|
212 | if(strstr(dp->d_name,".zcfg")!=0){ |
---|
213 | sprintf(tmps1,"%s/%s",conf_dir,dp->d_name); |
---|
214 | char *tmps=tmps1; |
---|
215 | s1=(service*)malloc(sizeof(service*)); |
---|
216 | s[0]=(service*)malloc(sizeof(service*)); |
---|
217 | #ifdef DEBUG |
---|
218 | fprintf(stderr,"#################\n%s\n#################\n",tmps1); |
---|
219 | #endif |
---|
220 | t=getServiceFromFile(tmps1,&s1); |
---|
221 | #ifdef DEBUG |
---|
222 | dumpService(s1); |
---|
223 | fflush(stdout); |
---|
224 | fflush(stderr); |
---|
225 | #endif |
---|
226 | s[0]=s1; |
---|
227 | printGetCapabilitiesForProcess(m,n,s1); |
---|
228 | //freeService(&s1); |
---|
229 | //s1=NULL; |
---|
230 | scount++; |
---|
231 | } |
---|
232 | (void)closedir(dirp); |
---|
233 | fflush(stdout); |
---|
234 | dup2(saved_stdout,fileno(stdout)); |
---|
235 | |
---|
236 | printDocument(doc); |
---|
237 | fflush(stdout); |
---|
238 | xmlFree(n); |
---|
239 | return 0; |
---|
240 | } |
---|
241 | else{ |
---|
242 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
243 | if(r_inputs==NULL |
---|
244 | || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){ |
---|
245 | if(r_inputs!=NULL && strlen(r_inputs->value)==0) |
---|
246 | tmps=createMap("text","Mandatory value for <identifier> was not specified"); |
---|
247 | else |
---|
248 | tmps=createMap("text","Mandatory <identifier> was not specified"); |
---|
249 | addToMap(tmps,"code","MissingParameterValue"); |
---|
250 | printExceptionReportResponse(m,tmps); |
---|
251 | return 1; |
---|
252 | } |
---|
253 | |
---|
254 | r_inputs=getMap(request_inputs,"metapath"); |
---|
255 | sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value); |
---|
256 | struct dirent *dp; |
---|
257 | DIR *dirp = opendir(conf_dir); |
---|
258 | if(dirp==NULL){ |
---|
259 | tmps=createMap("text","The specified metapath path doesn't exist."); |
---|
260 | addToMap(tmps,"code","InvalidParameterValue"); |
---|
261 | printExceptionReportResponse(m,tmps); |
---|
262 | return -1; |
---|
263 | } |
---|
264 | if(strcmp(mtoupper(REQUEST),"DESCRIBEPROCESS")==0){ |
---|
265 | /** |
---|
266 | * Loop over Identifier list |
---|
267 | */ |
---|
268 | xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
269 | doc->encoding = xmlCharStrdup ("UTF-8"); |
---|
270 | r_inputs=NULL; |
---|
271 | r_inputs=getMap(request_inputs,"ServiceProvider"); |
---|
272 | xmlNodePtr n; |
---|
273 | if(r_inputs!=NULL) |
---|
274 | n = printDescribeProcessHeader(doc,r_inputs->value,m); |
---|
275 | |
---|
276 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
277 | char *tmps=strtok(r_inputs->value,","); |
---|
278 | |
---|
279 | char buff[256]; |
---|
280 | char buff1[1024]; |
---|
281 | int i=0; |
---|
282 | int j=0; |
---|
283 | int end=-1; |
---|
284 | int saved_stdout = dup(fileno(stdout)); |
---|
285 | dup2(fileno(stderr),fileno(stdout)); |
---|
286 | while(tmps){ |
---|
287 | memset(buff,0,256); |
---|
288 | sprintf(buff,"%s.zcfg",tmps); |
---|
289 | memset(buff1,0,1024); |
---|
290 | #ifdef DEBUG |
---|
291 | fprintf(stderr,"\n#######%s\n########\n",buff1); |
---|
292 | #endif |
---|
293 | while ((dp = readdir(dirp)) != NULL) |
---|
294 | if(strcmp(dp->d_name,buff)==0){ |
---|
295 | memset(buff1,0,1024); |
---|
296 | sprintf(buff1,"%s/%s",conf_dir,dp->d_name); |
---|
297 | s1=(service*)malloc(sizeof(service*)); |
---|
298 | s[scount]=(service*)malloc(sizeof(service*)); |
---|
299 | #ifdef DEBUG |
---|
300 | fprintf(stderr,"#################\n%s\n#################\n",tmps1); |
---|
301 | #endif |
---|
302 | t=getServiceFromFile(buff1,&s1); |
---|
303 | /*dumpService(s1); |
---|
304 | fflush(stdout); |
---|
305 | fflush(stderr);*/ |
---|
306 | s[0]=s1; |
---|
307 | printDescribeProcessForProcess(m,n,s,1); |
---|
308 | scount++; |
---|
309 | } |
---|
310 | rewinddir(dirp); |
---|
311 | tmps=strtok(NULL,","); |
---|
312 | } |
---|
313 | (void)closedir(dirp); |
---|
314 | fflush(stdout); |
---|
315 | dup2(saved_stdout,fileno(stdout)); |
---|
316 | |
---|
317 | printDocument(doc); |
---|
318 | fflush(stdout); |
---|
319 | //xmlFree(n); |
---|
320 | #ifndef LINUX_FREE_ISSUE |
---|
321 | free(s1); |
---|
322 | #endif |
---|
323 | return 0; |
---|
324 | } |
---|
325 | else |
---|
326 | if(strcmp(mtoupper(REQUEST),"EXECUTE")!=0){ |
---|
327 | tmps=createMap("text","Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."); |
---|
328 | addToMap(tmps,"code","InvalidParameterValue"); |
---|
329 | printExceptionReportResponse(m,tmps); |
---|
330 | #ifdef DEBUG |
---|
331 | fprintf(stderr,"No request found %s",REQUEST); |
---|
332 | #endif |
---|
333 | free(s); |
---|
334 | return 0; |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | s1=NULL; |
---|
339 | s1=(service*)malloc(sizeof(service*)); |
---|
340 | s[0]=(service*)malloc(sizeof(service*)); |
---|
341 | r_inputs=getMap(request_inputs,"MetaPath"); |
---|
342 | sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); |
---|
343 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
344 | |
---|
345 | sprintf(tmps1,"%s/%s.zcfg",strdup(tmps1),r_inputs->value); |
---|
346 | |
---|
347 | #ifdef DEBUG |
---|
348 | fprintf(stderr,"Trying to load %s\n", tmps1); |
---|
349 | #endif |
---|
350 | int saved_stdout = dup(fileno(stdout)); |
---|
351 | dup2(fileno(stderr),fileno(stdout)); |
---|
352 | t=getServiceFromFile(tmps1,&s1); |
---|
353 | fflush(stdout); |
---|
354 | dup2(saved_stdout,fileno(stdout)); |
---|
355 | if(t==22){ |
---|
356 | tmps=createMap("text","The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request."); |
---|
357 | addToMap(tmps,"code","InvalidParameterValue"); |
---|
358 | printExceptionReportResponse(m,tmps); |
---|
359 | exit(0); |
---|
360 | } |
---|
361 | s[0]=s1; |
---|
362 | |
---|
363 | #ifdef DEBUG |
---|
364 | dumpService(s1); |
---|
365 | #endif |
---|
366 | map* inputs=NULL; |
---|
367 | elements* c_inputs=s1->inputs; |
---|
368 | int j; |
---|
369 | |
---|
370 | /** |
---|
371 | * Create the input maps data structure |
---|
372 | */ |
---|
373 | int i=0; |
---|
374 | HINTERNET hInternet; |
---|
375 | HINTERNET res; |
---|
376 | hInternet=InternetOpen( |
---|
377 | #ifndef WIN32 |
---|
378 | (LPCTSTR) |
---|
379 | #endif |
---|
380 | "ZooWPSClient\0", |
---|
381 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
382 | NULL,NULL, 0); |
---|
383 | |
---|
384 | #ifndef WIN32 |
---|
385 | if(!CHECK_INET_HANDLE(hInternet)) |
---|
386 | fprintf(stderr,"WARNING : hInternet handle failed to initialize"); |
---|
387 | #endif |
---|
388 | maps* request_input_real_format=NULL; |
---|
389 | maps* tmpmaps = request_input_real_format; |
---|
390 | map* postRequest=NULL; |
---|
391 | postRequest=getMap(request_inputs,"xrequest"); |
---|
392 | if(postRequest==NULLMAP){ |
---|
393 | /** |
---|
394 | * Parsing outputs provided as KVP |
---|
395 | */ |
---|
396 | r_inputs=NULL; |
---|
397 | #ifdef DEBUG |
---|
398 | fprintf(stderr,"OUTPUT Parsing ... \n"); |
---|
399 | #endif |
---|
400 | r_inputs=getMap(request_inputs,"ResponseDocument"); |
---|
401 | if(r_inputs==NULLMAP) |
---|
402 | r_inputs=getMap(request_inputs,"RawDataOutput"); |
---|
403 | #ifdef DEBUG |
---|
404 | fprintf(stderr,"OUTPUT Parsing ... \n"); |
---|
405 | #endif |
---|
406 | if(r_inputs!=NULLMAP){ |
---|
407 | #ifdef DEBUG |
---|
408 | fprintf(stderr,"OUTPUT Parsing start now ... \n"); |
---|
409 | #endif |
---|
410 | char current_output_as_string[10240]; |
---|
411 | char cursor_output[10240]; |
---|
412 | sprintf(cursor_output,"%s",strdup(r_inputs->value)); |
---|
413 | j=0; |
---|
414 | map* request_kvp_outputs=NULL; |
---|
415 | |
---|
416 | /** |
---|
417 | * Put each Output into the outputs_as_text array |
---|
418 | */ |
---|
419 | char * pToken; |
---|
420 | maps* tmp_output=NULL; |
---|
421 | #ifdef DEBUG |
---|
422 | fprintf(stderr,"OUTPUT [%s]\n",cursor_output); |
---|
423 | #endif |
---|
424 | pToken=strtok(cursor_output,";"); |
---|
425 | char** outputs_as_text=(char**)malloc(128*sizeof(char*)); |
---|
426 | i=0; |
---|
427 | while(pToken!=NULL){ |
---|
428 | #ifdef DEBUG |
---|
429 | fprintf(stderr,"***%s***\n",pToken); |
---|
430 | fflush(stderr); |
---|
431 | fprintf(stderr,"***%s***\n",pToken); |
---|
432 | #endif |
---|
433 | outputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char)); |
---|
434 | sprintf(outputs_as_text[i],"%s",pToken); |
---|
435 | pToken = strtok(NULL,";"); |
---|
436 | i++; |
---|
437 | } |
---|
438 | for(j=0;j<i;j++){ |
---|
439 | char *tmp=strdup(outputs_as_text[j]); |
---|
440 | char *tmpc; |
---|
441 | tmpc=strtok(tmp,"@"); |
---|
442 | int k=0; |
---|
443 | while(tmpc!=NULL){ |
---|
444 | if(k==0){ |
---|
445 | if(tmp_output==NULL){ |
---|
446 | tmp_output=(maps*)malloc(MAPS_SIZE); |
---|
447 | tmp_output->name=strdup(tmpc); |
---|
448 | tmp_output->content=NULL; |
---|
449 | tmp_output->next=NULL; |
---|
450 | } |
---|
451 | } |
---|
452 | else{ |
---|
453 | char *tmpv=strstr(tmpc,"="); |
---|
454 | char tmpn[256]; |
---|
455 | memset(tmpn,0,256); |
---|
456 | strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); |
---|
457 | tmpn[strlen(tmpc)-strlen(tmpv)]=0; |
---|
458 | #ifdef DEBUG |
---|
459 | fprintf(stderr,"OUTPUT DEF [%s]=[%s]\n",tmpn,tmpv+1); |
---|
460 | #endif |
---|
461 | if(tmp_output->content==NULL){ |
---|
462 | tmp_output->content=createMap(tmpn,tmpv+1); |
---|
463 | tmp_output->content->next=NULL; |
---|
464 | } |
---|
465 | else |
---|
466 | addToMap(tmp_output->content,tmpn,tmpv+1); |
---|
467 | } |
---|
468 | k++; |
---|
469 | #ifdef DEBUG |
---|
470 | fprintf(stderr,"***%s***\n",tmpc); |
---|
471 | #endif |
---|
472 | tmpc=strtok(NULL,"@"); |
---|
473 | } |
---|
474 | if(request_output_real_format==NULL) |
---|
475 | request_output_real_format=tmp_output; |
---|
476 | else |
---|
477 | addMapsToMaps(&request_output_real_format,tmp_output); |
---|
478 | #ifdef DEBUG |
---|
479 | dumpMaps(tmp_output); |
---|
480 | fflush(stderr); |
---|
481 | #endif |
---|
482 | tmp_output=tmp_output->next; |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | |
---|
487 | /** |
---|
488 | * Parsing inputs provided as KVP |
---|
489 | */ |
---|
490 | r_inputs=getMap(request_inputs,"DataInputs"); |
---|
491 | #ifdef DEBUG |
---|
492 | fprintf(stderr,"DATA INPUTS [%s]\n",r_inputs->value); |
---|
493 | #endif |
---|
494 | char current_input_as_string[40960]; |
---|
495 | char cursor_input[40960]; |
---|
496 | sprintf(cursor_input,"%s",strdup(r_inputs->value)); |
---|
497 | j=0; |
---|
498 | map* request_kvp_inputs=NULL; |
---|
499 | |
---|
500 | /** |
---|
501 | * Put each DataInputs into the inputs_as_text array |
---|
502 | */ |
---|
503 | char * pToken; |
---|
504 | pToken=strtok(cursor_input,";"); |
---|
505 | char** inputs_as_text=(char**)malloc(100*sizeof(char*)); |
---|
506 | i=0; |
---|
507 | while(pToken!=NULL){ |
---|
508 | #ifdef DEBUG |
---|
509 | fprintf(stderr,"***%s***\n",pToken); |
---|
510 | #endif |
---|
511 | fflush(stderr); |
---|
512 | #ifdef DEBUG |
---|
513 | fprintf(stderr,"***%s***\n",pToken); |
---|
514 | #endif |
---|
515 | inputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char)); |
---|
516 | sprintf(inputs_as_text[i],"%s",pToken); |
---|
517 | pToken = strtok(NULL,";"); |
---|
518 | i++; |
---|
519 | } |
---|
520 | |
---|
521 | for(j=0;j<i;j++){ |
---|
522 | char *tmp=strdup(inputs_as_text[j]); |
---|
523 | char *tmpc; |
---|
524 | tmpc=strtok(tmp,"@"); |
---|
525 | while(tmpc!=NULL){ |
---|
526 | #ifdef DEBUG |
---|
527 | fprintf(stderr,"***\n***%s***\n",tmpc); |
---|
528 | #endif |
---|
529 | char *tmpv=strstr(tmpc,"="); |
---|
530 | char tmpn[256]; |
---|
531 | memset(tmpn,0,256); |
---|
532 | strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); |
---|
533 | tmpn[strlen(tmpc)-strlen(tmpv)]=0; |
---|
534 | int cnt=0; |
---|
535 | #ifdef DEBUG |
---|
536 | fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1); |
---|
537 | #endif |
---|
538 | if(tmpmaps==NULL){ |
---|
539 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
540 | tmpmaps->name=strdup(tmpn); |
---|
541 | tmpmaps->content=createMap("value",tmpv+1); |
---|
542 | tmpmaps->next=NULL; |
---|
543 | } |
---|
544 | tmpc=strtok(NULL,"@"); |
---|
545 | while(tmpc!=NULL){ |
---|
546 | #ifdef DEBUG |
---|
547 | fprintf(stderr,"*** KVP NON URL-ENCODED \n***%s***\n",tmpc); |
---|
548 | #endif |
---|
549 | char *tmpv1=strstr(tmpc,"="); |
---|
550 | #ifdef DEBUG |
---|
551 | fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1); |
---|
552 | #endif |
---|
553 | char tmpn1[1024]; |
---|
554 | memset(tmpn1,0,1024); |
---|
555 | strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1)); |
---|
556 | tmpn1[strlen(tmpc)-strlen(tmpv1)]=0; |
---|
557 | #ifdef DEBUG |
---|
558 | fprintf(stderr,"*** NAME NON URL-ENCODED \n***%s***\n",tmpn1); |
---|
559 | fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1); |
---|
560 | #endif |
---|
561 | if(strcmp(tmpn1,"xlink:href")!=0) |
---|
562 | addToMap(tmpmaps->content,tmpn1,tmpv1+1); |
---|
563 | else{ |
---|
564 | #ifdef DEBUG |
---|
565 | fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1); |
---|
566 | #endif |
---|
567 | #ifndef WIN32 |
---|
568 | if(CHECK_INET_HANDLE(hInternet)) |
---|
569 | #endif |
---|
570 | { |
---|
571 | res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0, |
---|
572 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
573 | #ifdef DEBUG |
---|
574 | fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n", |
---|
575 | tmpv1+1,res.nDataAlloc,res.nDataLen); |
---|
576 | #endif |
---|
577 | char* tmpContent=(char*)malloc((res.nDataLen+1)*sizeof(char)); |
---|
578 | size_t dwRead; |
---|
579 | InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead); |
---|
580 | map* tmpMap=getMap(tmpmaps->content,"value"); |
---|
581 | if(tmpMap!=NULL) |
---|
582 | tmpMap->value=tmpContent; |
---|
583 | } |
---|
584 | addToMap(tmpmaps->content,tmpn1,tmpv1+1); |
---|
585 | } |
---|
586 | tmpc=strtok(NULL,"@"); |
---|
587 | } |
---|
588 | if(request_input_real_format==NULL) |
---|
589 | request_input_real_format=tmpmaps; |
---|
590 | else |
---|
591 | addMapsToMaps(&request_input_real_format,tmpmaps); |
---|
592 | #ifdef DEBUG |
---|
593 | dumpMaps(tmpmaps); |
---|
594 | fflush(stderr); |
---|
595 | #endif |
---|
596 | tmpmaps=tmpmaps->next; |
---|
597 | } |
---|
598 | } |
---|
599 | } |
---|
600 | else { |
---|
601 | xmlInitParser(); |
---|
602 | #ifdef DEBUG |
---|
603 | fflush(stderr); |
---|
604 | fprintf(stderr,"BEFORE %s\n",postRequest->value); |
---|
605 | fflush(stderr); |
---|
606 | #endif |
---|
607 | xmlDocPtr doc = |
---|
608 | xmlParseMemory(postRequest->value,cgiContentLength); |
---|
609 | #ifdef DEBUG |
---|
610 | fprintf(stderr,"AFTER\n"); |
---|
611 | fflush(stderr); |
---|
612 | #endif |
---|
613 | xmlNodePtr cur = xmlDocGetRootElement(doc); |
---|
614 | /** |
---|
615 | * Parse every Input in DataInputs node. |
---|
616 | */ |
---|
617 | maps* tempMaps=NULL; |
---|
618 | xmlNodeSet* tmps=extractFromDoc(doc, |
---|
619 | "/*/*/*[local-name()='Input']"); |
---|
620 | #ifdef DEBUG |
---|
621 | fprintf(stderr,"*****%d*****\n",tmps->nodeNr); |
---|
622 | #endif |
---|
623 | for(int k=0;k<tmps->nodeNr;k++){ |
---|
624 | maps *tmpmaps=NULL; |
---|
625 | xmlNodePtr cur=tmps->nodeTab[k]; |
---|
626 | if(tmps->nodeTab[k]->type == XML_ELEMENT_NODE) { |
---|
627 | /** |
---|
628 | * A specific Input node. |
---|
629 | */ |
---|
630 | #ifdef DEBUG |
---|
631 | fprintf(stderr, "= element 0 node \"%s\"\n", cur->name); |
---|
632 | #endif |
---|
633 | xmlNodePtr cur1=cur->children; |
---|
634 | while(cur1){ |
---|
635 | #ifdef DEBUG |
---|
636 | fprintf(stderr, "= element 1 node \"%s\" = (%s)\n", |
---|
637 | cur1->name,xmlNodeListGetString(doc,cur1,1)); |
---|
638 | #endif |
---|
639 | xmlNodePtr cur2=cur1/*->next*/; |
---|
640 | while(cur2){ |
---|
641 | /** |
---|
642 | * Indentifier |
---|
643 | */ |
---|
644 | if(strcmp(mtoupper((char*)cur2->name), |
---|
645 | mtoupper("Identifier"))==0){ |
---|
646 | xmlChar *val= |
---|
647 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
648 | if(tmpmaps==NULL){ |
---|
649 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
650 | tmpmaps->name=strdup((char*)val); |
---|
651 | tmpmaps->content=NULL; |
---|
652 | tmpmaps->next=NULL; |
---|
653 | } |
---|
654 | xmlFree(val); |
---|
655 | } |
---|
656 | /** |
---|
657 | * Title, Asbtract |
---|
658 | */ |
---|
659 | if(strcmp(mtoupper((char*)cur2->name), |
---|
660 | mtoupper("Title"))==0 || |
---|
661 | strcmp(mtoupper((char*)cur2->name), |
---|
662 | mtoupper("Abstract"))==0){ |
---|
663 | xmlChar *val= |
---|
664 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
665 | if(tmpmaps==NULL){ |
---|
666 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
667 | tmpmaps->name="missingIndetifier"; |
---|
668 | tmpmaps->content=createMap((char*)cur2->name,(char*)val); |
---|
669 | tmpmaps->next=NULL; |
---|
670 | } |
---|
671 | else{ |
---|
672 | if(tmpmaps->content!=NULL) |
---|
673 | addToMap(tmpmaps->content, |
---|
674 | (char*)cur2->name,(char*)val); |
---|
675 | else |
---|
676 | tmpmaps->content= |
---|
677 | createMap((char*)cur2->name,(char*)val); |
---|
678 | } |
---|
679 | #ifdef DEBUG |
---|
680 | dumpMaps(tmpmaps); |
---|
681 | #endif |
---|
682 | xmlFree(val); |
---|
683 | } |
---|
684 | /** |
---|
685 | * InputDataFormChoice (Reference or Data ?) |
---|
686 | */ |
---|
687 | if(strcmp(mtoupper((char*)cur2->name), |
---|
688 | mtoupper("Reference"))==0){ |
---|
689 | /** |
---|
690 | * Get every attribute from a Reference node |
---|
691 | * mimeType, encoding, schema, href, method |
---|
692 | * Header and Body gesture should be added here |
---|
693 | */ |
---|
694 | #ifdef DEBUG |
---|
695 | fprintf(stderr,"REFERENCE\n"); |
---|
696 | #endif |
---|
697 | map* referenceMap=NULL; |
---|
698 | char *refs[5]; |
---|
699 | refs[0]="mimeType"; |
---|
700 | refs[1]="encoding"; |
---|
701 | refs[2]="schema"; |
---|
702 | refs[3]="method"; |
---|
703 | refs[4]="href"; |
---|
704 | char*url; |
---|
705 | for(int l=0;l<5;l++){ |
---|
706 | #ifdef DEBUG |
---|
707 | fprintf(stderr,"*** %s ***\t",refs[l]); |
---|
708 | #endif |
---|
709 | xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]); |
---|
710 | if(val!=NULL && strlen((char*)val)>0){ |
---|
711 | if(tmpmaps->content!=NULL) |
---|
712 | addToMap(tmpmaps->content,refs[l],(char*)val); |
---|
713 | else |
---|
714 | tmpmaps->content=createMap(refs[l],(char*)val); |
---|
715 | map* ltmp=getMap(tmpmaps->content,"method"); |
---|
716 | if(l==4){ |
---|
717 | if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0) |
---|
718 | && CHECK_INET_HANDLE(hInternet)){ |
---|
719 | res=InternetOpenUrl(hInternet,(char*)val,NULL,0, |
---|
720 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
721 | char* tmpContent= |
---|
722 | (char*)malloc((res.nDataLen+1)*sizeof(char)); |
---|
723 | size_t dwRead; |
---|
724 | InternetReadFile(res, (LPVOID)tmpContent, |
---|
725 | res.nDataLen, &dwRead); |
---|
726 | tmpContent[res.nDataLen]=0; |
---|
727 | addToMap(tmpmaps->content,"value",tmpContent); |
---|
728 | } |
---|
729 | } |
---|
730 | |
---|
731 | } |
---|
732 | #ifdef DEBUG |
---|
733 | fprintf(stderr,"%s\n",val); |
---|
734 | #endif |
---|
735 | xmlFree(val); |
---|
736 | } |
---|
737 | #ifdef POST_DEBUG |
---|
738 | fprintf(stderr,"Parse Header and Body from Reference \n"); |
---|
739 | #endif |
---|
740 | xmlNodePtr cur3=cur2->children; |
---|
741 | hInternet.header=NULL; |
---|
742 | while(cur3){ |
---|
743 | if(strcmp(mtoupper((char*)cur3->name), mtoupper("Header"))==0 ){ |
---|
744 | xmlNodePtr cur4=cur3; |
---|
745 | char *tmp=new char[cgiContentLength]; |
---|
746 | char *ha[2]; |
---|
747 | ha[0]="key"; |
---|
748 | ha[1]="value"; |
---|
749 | int hai; |
---|
750 | char *has; |
---|
751 | char *key; |
---|
752 | for(hai=0;hai<2;hai++){ |
---|
753 | xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]); |
---|
754 | #ifdef POST_DEBUG |
---|
755 | fprintf(stderr,"%s = %s\n",ha[hai],(char*)val); |
---|
756 | #endif |
---|
757 | if(hai==0){ |
---|
758 | key=(char*)malloc((1+strlen((char*)val))*sizeof(char)); |
---|
759 | sprintf(key,"%s",(char*)val); |
---|
760 | }else{ |
---|
761 | has=(char*)malloc((3+strlen((char*)val)+strlen(key))*sizeof(char)); |
---|
762 | sprintf(has,"%s: %s",key,(char*)val); |
---|
763 | #ifdef POST_DEBUG |
---|
764 | fprintf(stderr,"%s\n",has); |
---|
765 | #endif |
---|
766 | } |
---|
767 | } |
---|
768 | hInternet.header=curl_slist_append(hInternet.header, has); |
---|
769 | //free(has); |
---|
770 | } |
---|
771 | else{ |
---|
772 | #ifdef POST_DEBUG |
---|
773 | fprintf(stderr,"Try to fetch the body part of the request ...\n"); |
---|
774 | #endif |
---|
775 | if(strcmp(mtoupper((char*)cur3->name),mtoupper("Body"))==0 ){ |
---|
776 | #ifdef POST_DEBUG |
---|
777 | fprintf(stderr,"Body part found !!!\n",(char*)cur3->content); |
---|
778 | #endif |
---|
779 | char *tmp=new char[cgiContentLength]; |
---|
780 | memset(tmp,cgiContentLength,0); |
---|
781 | xmlNodePtr cur4=cur3->children; |
---|
782 | while(cur4!=NULL){ |
---|
783 | xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0"); |
---|
784 | bdoc->encoding = xmlCharStrdup ("UTF-8"); |
---|
785 | xmlDocSetRootElement(bdoc,cur4); |
---|
786 | xmlChar* btmps; |
---|
787 | int bsize; |
---|
788 | xmlDocDumpMemory(bdoc,&btmps,&bsize); |
---|
789 | #ifdef POST_DEBUG |
---|
790 | fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps); |
---|
791 | #endif |
---|
792 | if(btmps!=NULL) |
---|
793 | sprintf(tmp,"%s",(char*)btmps); |
---|
794 | xmlFreeDoc(bdoc); |
---|
795 | cur4=cur4->next; |
---|
796 | } |
---|
797 | map *btmp=getMap(tmpmaps->content,"href"); |
---|
798 | if(btmp!=NULL){ |
---|
799 | #ifdef POST_DEBUG |
---|
800 | fprintf(stderr,"%s %s\n",btmp->value,tmp); |
---|
801 | curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); |
---|
802 | #endif |
---|
803 | res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp), |
---|
804 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
805 | char* tmpContent= |
---|
806 | (char*)malloc((res.nDataLen+1)*sizeof(char)); |
---|
807 | size_t dwRead; |
---|
808 | InternetReadFile(res, (LPVOID)tmpContent, |
---|
809 | res.nDataLen, &dwRead); |
---|
810 | tmpContent[res.nDataLen]=0; |
---|
811 | if(hInternet.header!=NULL) |
---|
812 | curl_slist_free_all(hInternet.header); |
---|
813 | addToMap(tmpmaps->content,"value",tmpContent); |
---|
814 | #ifdef POST_DEBUG |
---|
815 | fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent); |
---|
816 | #endif |
---|
817 | } |
---|
818 | } |
---|
819 | else |
---|
820 | if(strcmp(mtoupper((char*)cur3->name),mtoupper("BodyReference"))==0 ){ |
---|
821 | xmlChar *val=xmlGetProp(cur3,BAD_CAST "href"); |
---|
822 | HINTERNET bInternet,res1; |
---|
823 | bInternet=InternetOpen( |
---|
824 | #ifndef WIN32 |
---|
825 | (LPCTSTR) |
---|
826 | #endif |
---|
827 | "ZooWPSClient\0", |
---|
828 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
829 | NULL,NULL, 0); |
---|
830 | if(!CHECK_INET_HANDLE(bInternet)) |
---|
831 | fprintf(stderr,"WARNING : hInternet handle failed to initialize"); |
---|
832 | #ifdef POST_DEBUG |
---|
833 | curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1); |
---|
834 | #endif |
---|
835 | res1=InternetOpenUrl(bInternet,(char*)val,NULL,0, |
---|
836 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
837 | char* tmp= |
---|
838 | (char*)malloc((res1.nDataLen+1)*sizeof(char)); |
---|
839 | size_t bRead; |
---|
840 | InternetReadFile(res1, (LPVOID)tmp, |
---|
841 | res1.nDataLen, &bRead); |
---|
842 | tmp[res1.nDataLen]=0; |
---|
843 | InternetCloseHandle(bInternet); |
---|
844 | map *btmp=getMap(tmpmaps->content,"href"); |
---|
845 | if(btmp!=NULL){ |
---|
846 | #ifdef POST_DEBUG |
---|
847 | fprintf(stderr,"%s %s\n",btmp->value,tmp); |
---|
848 | curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); |
---|
849 | #endif |
---|
850 | res=InternetOpenUrl(hInternet,btmp->value,tmp, |
---|
851 | strlen(tmp), |
---|
852 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
853 | char* tmpContent= |
---|
854 | (char*)malloc((res.nDataLen+1)*sizeof(char)); |
---|
855 | size_t dwRead; |
---|
856 | InternetReadFile(res, (LPVOID)tmpContent, |
---|
857 | res.nDataLen, &dwRead); |
---|
858 | tmpContent[res.nDataLen]=0; |
---|
859 | if(hInternet.header!=NULL) |
---|
860 | curl_slist_free_all(hInternet.header); |
---|
861 | addToMap(tmpmaps->content,"value",tmpContent); |
---|
862 | #ifdef POST_DEBUG |
---|
863 | fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent); |
---|
864 | #endif |
---|
865 | } |
---|
866 | } |
---|
867 | } |
---|
868 | cur3=cur3->next; |
---|
869 | } |
---|
870 | #ifdef POST_DEBUG |
---|
871 | fprintf(stderr,"Header and Body was parsed from Reference \n"); |
---|
872 | #endif |
---|
873 | #ifdef DEBUG |
---|
874 | dumpMap(tmpmaps->content); |
---|
875 | fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", |
---|
876 | cur2->name,cur2->content); |
---|
877 | #endif |
---|
878 | } |
---|
879 | else if(strcmp(mtoupper((char*)cur2->name), |
---|
880 | mtoupper("Data"))==0){ |
---|
881 | #ifdef DEBUG |
---|
882 | fprintf(stderr,"DATA\n"); |
---|
883 | #endif |
---|
884 | xmlNodePtr cur4=cur2->children; |
---|
885 | while(cur4){ |
---|
886 | if(strcmp(mtoupper((char*)cur4->name), |
---|
887 | mtoupper("LiteralData"))==0){ |
---|
888 | /** |
---|
889 | * Get every attribute from a LiteralData node |
---|
890 | * dataType , uom |
---|
891 | */ |
---|
892 | char *lits[2]; |
---|
893 | lits[0]="dataType"; |
---|
894 | lits[1]="uom"; |
---|
895 | for(int l=0;l<2;l++){ |
---|
896 | #ifdef DEBUG |
---|
897 | fprintf(stderr,"*** %s ***\t",lits[l]); |
---|
898 | #endif |
---|
899 | xmlChar *val=xmlGetProp(cur4,BAD_CAST lits[l]); |
---|
900 | if(val!=NULL && strlen((char*)val)>0){ |
---|
901 | if(tmpmaps->content!=NULL) |
---|
902 | addToMap(tmpmaps->content,lits[l],(char*)val); |
---|
903 | else |
---|
904 | tmpmaps->content=createMap(lits[l],(char*)val); |
---|
905 | } |
---|
906 | #ifdef DEBUG |
---|
907 | fprintf(stderr,"%s\n",val); |
---|
908 | #endif |
---|
909 | xmlFree(val); |
---|
910 | } |
---|
911 | xmlChar* mv=xmlNodeListGetString(doc, |
---|
912 | cur4->xmlChildrenNode,1); |
---|
913 | if(tmpmaps->content!=NULL) |
---|
914 | addToMap(tmpmaps->content, |
---|
915 | "value", |
---|
916 | (char*)mv); |
---|
917 | else |
---|
918 | tmpmaps->content= |
---|
919 | createMap("value", |
---|
920 | (char*)mv); |
---|
921 | xmlFree(mv); |
---|
922 | } |
---|
923 | else if(strcmp(mtoupper((char*)cur4->name), |
---|
924 | mtoupper("ComplexData"))==0){ |
---|
925 | /** |
---|
926 | * Get every attribute from a Reference node |
---|
927 | * mimeType, encoding, schema |
---|
928 | */ |
---|
929 | char *coms[2]; |
---|
930 | coms[0]="mimeType"; |
---|
931 | coms[1]="encoding"; |
---|
932 | coms[2]="schema"; |
---|
933 | for(int l=0;l<2;l++){ |
---|
934 | #ifdef DEBUG |
---|
935 | fprintf(stderr,"*** %s ***\t",coms[l]); |
---|
936 | #endif |
---|
937 | xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]); |
---|
938 | if(val!=NULL && strlen((char*)val)>0){ |
---|
939 | if(tmpmaps->content!=NULL) |
---|
940 | addToMap(tmpmaps->content,coms[l],(char*)val); |
---|
941 | else |
---|
942 | tmpmaps->content=createMap(coms[l],(char*)val); |
---|
943 | } |
---|
944 | #ifdef DEBUG |
---|
945 | fprintf(stderr,"%s\n",val); |
---|
946 | #endif |
---|
947 | xmlFree(val); |
---|
948 | } |
---|
949 | xmlChar* mv=xmlNodeListGetString(doc, |
---|
950 | cur4->xmlChildrenNode,1); |
---|
951 | if(tmpmaps->content!=NULL) |
---|
952 | addToMap(tmpmaps->content, |
---|
953 | "value", |
---|
954 | (char*)mv); |
---|
955 | else |
---|
956 | tmpmaps->content= |
---|
957 | createMap("value", |
---|
958 | (char*)mv); |
---|
959 | xmlFree(mv); |
---|
960 | } |
---|
961 | cur4=cur4->next; |
---|
962 | } |
---|
963 | } |
---|
964 | #ifdef DEBUG |
---|
965 | dumpMap(tmpmaps->content); |
---|
966 | fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", |
---|
967 | cur2->name,cur2->content); |
---|
968 | #endif |
---|
969 | xmlNodePtr cur3=cur->children; |
---|
970 | while(cur3){ |
---|
971 | #ifdef DEBUG |
---|
972 | fprintf(stderr, "= element 3 node \"%s\" = (%s)\n",cur3->name, |
---|
973 | xmlNodeListGetString(doc,cur3->xmlChildrenNode,1)); |
---|
974 | #endif |
---|
975 | if(strcmp(mtoupper((char*)cur3->name), |
---|
976 | mtoupper("Title"))==0){ |
---|
977 | #ifdef DEBUG |
---|
978 | fprintf(stderr, "= element 3 node \"%s\" = (%s)\n", |
---|
979 | cur3->name,xmlNodeListGetString(doc,cur3,1)); |
---|
980 | #endif |
---|
981 | } |
---|
982 | cur3=cur3->children; |
---|
983 | } |
---|
984 | cur2=cur2->next; |
---|
985 | } |
---|
986 | cur1=cur1->children; |
---|
987 | } |
---|
988 | if(request_input_real_format==NULL) |
---|
989 | request_input_real_format=tmpmaps; |
---|
990 | else |
---|
991 | addMapsToMaps(&request_input_real_format,tmpmaps); |
---|
992 | #ifdef DEBUG |
---|
993 | dumpMaps(tmpmaps); |
---|
994 | #endif |
---|
995 | fflush(stderr); |
---|
996 | tmpmaps=tmpmaps->next; |
---|
997 | |
---|
998 | } else { |
---|
999 | #ifdef DEBUG |
---|
1000 | fprintf(stderr, "= node \"%s\": type %d\n", cur->name, cur->type); |
---|
1001 | #endif |
---|
1002 | } |
---|
1003 | #ifdef DEBUG |
---|
1004 | dumpMaps(tmpmaps); |
---|
1005 | #endif |
---|
1006 | } |
---|
1007 | |
---|
1008 | xmlFree(tmps); |
---|
1009 | tmps=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']"); |
---|
1010 | #ifdef DEBUG |
---|
1011 | fprintf(stderr,"*****%d*****\n",tmps->nodeNr); |
---|
1012 | #endif |
---|
1013 | for(int k=0;k<tmps->nodeNr;k++){ |
---|
1014 | addToMap(request_inputs,"ResponseDocument",""); |
---|
1015 | request_output_real_format; |
---|
1016 | maps *tmpmaps=NULL; |
---|
1017 | xmlNodePtr cur=tmps->nodeTab[k]; |
---|
1018 | if(cur->type == XML_ELEMENT_NODE) { |
---|
1019 | /** |
---|
1020 | * A specific responseDocument node. |
---|
1021 | */ |
---|
1022 | if(tmpmaps==NULL){ |
---|
1023 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
1024 | tmpmaps->name="unknownIdentifier"; |
---|
1025 | tmpmaps->next=NULL; |
---|
1026 | } |
---|
1027 | /** |
---|
1028 | * Get every attribute from a LiteralData node |
---|
1029 | * storeExecuteResponse, lineage, status |
---|
1030 | */ |
---|
1031 | char *ress[3]; |
---|
1032 | ress[0]="storeExecuteResponse"; |
---|
1033 | ress[1]="lineage"; |
---|
1034 | ress[2]="status"; |
---|
1035 | xmlChar *val; |
---|
1036 | for(int l=0;l<3;l++){ |
---|
1037 | #ifdef DEBUG |
---|
1038 | fprintf(stderr,"*** %s ***\t",ress[l]); |
---|
1039 | #endif |
---|
1040 | val=xmlGetProp(cur,BAD_CAST ress[l]); |
---|
1041 | if(val!=NULL && strlen((char*)val)>0){ |
---|
1042 | if(tmpmaps->content!=NULL) |
---|
1043 | addToMap(tmpmaps->content,ress[l],(char*)val); |
---|
1044 | else |
---|
1045 | tmpmaps->content=createMap(ress[l],(char*)val); |
---|
1046 | addToMap(request_inputs,ress[l],(char*)val); |
---|
1047 | } |
---|
1048 | #ifdef DEBUG |
---|
1049 | fprintf(stderr,"%s\n",val); |
---|
1050 | #endif |
---|
1051 | xmlFree(val); |
---|
1052 | } |
---|
1053 | xmlNodePtr cur1=cur->children; |
---|
1054 | while(cur1){ |
---|
1055 | if(strcmp(mtoupper((char*)cur1->name), |
---|
1056 | mtoupper("Output"))==0){ |
---|
1057 | /** |
---|
1058 | * Get every attribute from a Output node |
---|
1059 | * mimeType, encoding, schema, uom, asReference |
---|
1060 | */ |
---|
1061 | char *outs[5]; |
---|
1062 | outs[0]="mimeType"; |
---|
1063 | outs[1]="encoding"; |
---|
1064 | outs[2]="schema"; |
---|
1065 | outs[3]="uom"; |
---|
1066 | outs[4]="asReference"; |
---|
1067 | for(int l=0;l<5;l++){ |
---|
1068 | #ifdef DEBUG |
---|
1069 | fprintf(stderr,"*** %s ***\t",outs[l]); |
---|
1070 | #endif |
---|
1071 | val=xmlGetProp(cur1,BAD_CAST outs[l]); |
---|
1072 | if(val!=NULL && strlen((char*)val)>0){ |
---|
1073 | if(tmpmaps->content!=NULL) |
---|
1074 | addToMap(tmpmaps->content,outs[l],(char*)val); |
---|
1075 | else |
---|
1076 | tmpmaps->content=createMap(outs[l],(char*)val); |
---|
1077 | } |
---|
1078 | #ifdef DEBUG |
---|
1079 | fprintf(stderr,"%s\n",val); |
---|
1080 | #endif |
---|
1081 | xmlFree(val); |
---|
1082 | } |
---|
1083 | |
---|
1084 | xmlNodePtr cur2=cur1->children; |
---|
1085 | while(cur2){ |
---|
1086 | /** |
---|
1087 | * Indentifier |
---|
1088 | */ |
---|
1089 | if(strcmp(mtoupper((char*)cur2->name), |
---|
1090 | mtoupper("Identifier"))==0){ |
---|
1091 | xmlChar *val= |
---|
1092 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
1093 | if(tmpmaps==NULL){ |
---|
1094 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
1095 | tmpmaps->name=strdup((char*)val); |
---|
1096 | tmpmaps->content=NULL; |
---|
1097 | tmpmaps->next=NULL; |
---|
1098 | } |
---|
1099 | else |
---|
1100 | tmpmaps->name=strdup((char*)val);; |
---|
1101 | xmlFree(val); |
---|
1102 | } |
---|
1103 | /** |
---|
1104 | * Title, Asbtract |
---|
1105 | */ |
---|
1106 | if(strcmp(mtoupper((char*)cur2->name), |
---|
1107 | mtoupper("Title"))==0 || |
---|
1108 | strcmp(mtoupper((char*)cur2->name), |
---|
1109 | mtoupper("Abstract"))==0){ |
---|
1110 | xmlChar *val= |
---|
1111 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
1112 | if(tmpmaps==NULL){ |
---|
1113 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
1114 | tmpmaps->name="missingIndetifier"; |
---|
1115 | tmpmaps->content=createMap((char*)cur2->name,(char*)val); |
---|
1116 | tmpmaps->next=NULL; |
---|
1117 | } |
---|
1118 | else{ |
---|
1119 | if(tmpmaps->content!=NULL) |
---|
1120 | addToMap(tmpmaps->content, |
---|
1121 | (char*)cur2->name,(char*)val); |
---|
1122 | else |
---|
1123 | tmpmaps->content= |
---|
1124 | createMap((char*)cur2->name,(char*)val); |
---|
1125 | } |
---|
1126 | xmlFree(val); |
---|
1127 | } |
---|
1128 | cur2=cur2->next; |
---|
1129 | } |
---|
1130 | } |
---|
1131 | cur1=cur1->next; |
---|
1132 | } |
---|
1133 | } |
---|
1134 | //xmlFree(cur); |
---|
1135 | if(request_output_real_format==NULL) |
---|
1136 | request_output_real_format=tmpmaps; |
---|
1137 | else |
---|
1138 | addMapsToMaps(&request_output_real_format,tmpmaps); |
---|
1139 | #ifdef DEBUG |
---|
1140 | dumpMaps(tmpmaps); |
---|
1141 | #endif |
---|
1142 | } |
---|
1143 | |
---|
1144 | xmlFree(tmps); |
---|
1145 | tmps=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']"); |
---|
1146 | #ifdef DEBUG |
---|
1147 | fprintf(stderr,"*****%d*****\n",tmps->nodeNr); |
---|
1148 | #endif |
---|
1149 | for(int k=0;k<tmps->nodeNr;k++){ |
---|
1150 | addToMap(request_inputs,"RawDataOutput",""); |
---|
1151 | xmlNodePtr cur1=tmps->nodeTab[k]; |
---|
1152 | xmlChar *val; |
---|
1153 | /** |
---|
1154 | * Get every attribute from a Output node |
---|
1155 | * mimeType, encoding, schema, uom, asReference |
---|
1156 | */ |
---|
1157 | char *outs[4]; |
---|
1158 | outs[0]="mimeType"; |
---|
1159 | outs[1]="encoding"; |
---|
1160 | outs[2]="schema"; |
---|
1161 | outs[3]="uom"; |
---|
1162 | for(int l=0;l<4;l++){ |
---|
1163 | #ifdef DEBUG |
---|
1164 | fprintf(stderr,"*** %s ***\t",outs[l]); |
---|
1165 | #endif |
---|
1166 | val=xmlGetProp(cur1,BAD_CAST outs[l]); |
---|
1167 | if(val!=NULL && strlen((char*)val)>0){ |
---|
1168 | if(tmpmaps==NULL){ |
---|
1169 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
1170 | tmpmaps->name="unknownIdentifier"; |
---|
1171 | tmpmaps->content=createMap(outs[l],(char*)val); |
---|
1172 | tmpmaps->next=NULL; |
---|
1173 | } |
---|
1174 | else |
---|
1175 | addToMap(tmpmaps->content,outs[l],(char*)val); |
---|
1176 | } |
---|
1177 | #ifdef DEBUG |
---|
1178 | fprintf(stderr,"%s\n",val); |
---|
1179 | #endif |
---|
1180 | xmlFree(val); |
---|
1181 | } |
---|
1182 | |
---|
1183 | xmlNodePtr cur2=cur1->children; |
---|
1184 | while(cur2){ |
---|
1185 | /** |
---|
1186 | * Indentifier |
---|
1187 | */ |
---|
1188 | if(strcmp(mtoupper((char*)cur2->name), |
---|
1189 | mtoupper("Identifier"))==0){ |
---|
1190 | val= |
---|
1191 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
1192 | if(tmpmaps==NULL){ |
---|
1193 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
1194 | tmpmaps->name=strdup((char*)val); |
---|
1195 | tmpmaps->content=NULL; |
---|
1196 | tmpmaps->next=NULL; |
---|
1197 | } |
---|
1198 | else |
---|
1199 | tmpmaps->name=strdup((char*)val);; |
---|
1200 | xmlFree(val); |
---|
1201 | } |
---|
1202 | cur2=cur2->next; |
---|
1203 | } |
---|
1204 | if(request_output_real_format==NULL) |
---|
1205 | request_output_real_format=tmpmaps; |
---|
1206 | else |
---|
1207 | addMapsToMaps(&request_output_real_format,tmpmaps); |
---|
1208 | #ifdef DEBUG |
---|
1209 | dumpMaps(tmpmaps); |
---|
1210 | #endif |
---|
1211 | } |
---|
1212 | |
---|
1213 | xmlFree(tmps); |
---|
1214 | xmlCleanupParser(); |
---|
1215 | } |
---|
1216 | |
---|
1217 | if(CHECK_INET_HANDLE(hInternet)) |
---|
1218 | InternetCloseHandle(hInternet); |
---|
1219 | |
---|
1220 | #ifdef DEBUG |
---|
1221 | fprintf(stderr,"\n%i\n",i); |
---|
1222 | dumpMaps(request_input_real_format); |
---|
1223 | dumpMaps(request_output_real_format); |
---|
1224 | dumpElements(); |
---|
1225 | #endif |
---|
1226 | |
---|
1227 | /** |
---|
1228 | * Ensure that each requested arguments are present in the request |
---|
1229 | * DataInputs and ResponseDocument / RawDataOutput |
---|
1230 | */ |
---|
1231 | addDefaultValues(&request_input_real_format,s1->inputs,m,"inputs"); |
---|
1232 | addDefaultValues(&request_output_real_format,s1->outputs,m,"outputs"); |
---|
1233 | |
---|
1234 | const struct tm *tm; |
---|
1235 | size_t len; |
---|
1236 | time_t now; |
---|
1237 | char *sDate; |
---|
1238 | |
---|
1239 | now = time ( NULL ); |
---|
1240 | tm = localtime ( &now ); |
---|
1241 | |
---|
1242 | sDate = new char[TIME_SIZE]; |
---|
1243 | |
---|
1244 | maps* curs=getMaps(m,"env"); |
---|
1245 | if(curs!=NULL){ |
---|
1246 | map* mapcs=curs->content; |
---|
1247 | while(mapcs!=NULLMAP){ |
---|
1248 | #ifndef WIN32 |
---|
1249 | setenv(mapcs->name,mapcs->value,1); |
---|
1250 | #else |
---|
1251 | #ifdef DEBUG |
---|
1252 | fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value); |
---|
1253 | #endif |
---|
1254 | if(mapcs->value[strlen(mapcs->value)-2]=='\r'){ |
---|
1255 | #ifdef DEBUG |
---|
1256 | fprintf(stderr,"[ZOO: Env var finish with \r]\n"); |
---|
1257 | #endif |
---|
1258 | mapcs->value[strlen(mapcs->value)-1]=0; |
---|
1259 | } |
---|
1260 | #ifdef DEBUG |
---|
1261 | fflush(stderr); |
---|
1262 | fprintf(stderr,"setting variable... %s\n", |
---|
1263 | #endif |
---|
1264 | SetEnvironmentVariable(mapcs->name,mapcs->value) |
---|
1265 | #ifdef DEBUG |
---|
1266 | ? "OK" : "FAILED"); |
---|
1267 | #else |
---|
1268 | ; |
---|
1269 | #endif |
---|
1270 | #ifdef DEBUG |
---|
1271 | fflush(stderr); |
---|
1272 | #endif |
---|
1273 | #endif |
---|
1274 | #ifdef DEBUG |
---|
1275 | fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value); |
---|
1276 | fflush(stderr); |
---|
1277 | #endif |
---|
1278 | mapcs=mapcs->next; |
---|
1279 | } |
---|
1280 | } |
---|
1281 | |
---|
1282 | len = strftime ( sDate, TIME_SIZE, "%d-%B-%YT%I:%M:%SZ", tm ); |
---|
1283 | |
---|
1284 | #ifdef DEBUG |
---|
1285 | dumpMap(request_inputs); |
---|
1286 | #endif |
---|
1287 | |
---|
1288 | /** |
---|
1289 | * Need to check if we need to fork to load a status enabled |
---|
1290 | */ |
---|
1291 | r_inputs=NULL; |
---|
1292 | r_inputs=getMap(request_inputs,"storeExecuteResponse"); |
---|
1293 | int eres=SERVICE_STARTED; |
---|
1294 | int cpid=getpid(); |
---|
1295 | #ifdef DEBUG |
---|
1296 | dumpMap(request_inputs); |
---|
1297 | #endif |
---|
1298 | |
---|
1299 | if(r_inputs==NULLMAP){ |
---|
1300 | /** |
---|
1301 | * Extract serviceType to know what kind of service shoudl be loaded |
---|
1302 | */ |
---|
1303 | r_inputs=NULL; |
---|
1304 | r_inputs=getMap(s1->content,"serviceType"); |
---|
1305 | #ifdef DEBUG |
---|
1306 | fprintf(stderr,"LOAD A %s SERVICE PROVIDER IN NORMAL MODE \n",r_inputs->value); |
---|
1307 | fflush(stderr); |
---|
1308 | #endif |
---|
1309 | |
---|
1310 | if(strncmp(mtoupper(r_inputs->value),"C",1)==0){ |
---|
1311 | r_inputs=getMap(request_inputs,"metapath"); |
---|
1312 | sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); |
---|
1313 | char *altPath=strdup(tmps1); |
---|
1314 | r_inputs=getMap(s1->content,"ServiceProvider"); |
---|
1315 | sprintf(tmps1,"%s/%s",altPath,r_inputs->value); |
---|
1316 | free(altPath); |
---|
1317 | #ifdef DEBUG |
---|
1318 | fprintf(stderr,"Trying to load %s\n",tmps1); |
---|
1319 | #endif |
---|
1320 | #ifdef WIN32 |
---|
1321 | HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); |
---|
1322 | #else |
---|
1323 | void* so = dlopen(tmps1, RTLD_LAZY); |
---|
1324 | #endif |
---|
1325 | #ifdef WIN32 |
---|
1326 | DWORD errstr; |
---|
1327 | errstr = GetLastError(); |
---|
1328 | #ifdef DEBUG |
---|
1329 | fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr); |
---|
1330 | #endif |
---|
1331 | #else |
---|
1332 | char *errstr; |
---|
1333 | errstr = dlerror(); |
---|
1334 | #endif |
---|
1335 | |
---|
1336 | if( so != NULL ) { |
---|
1337 | #ifdef DEBUG |
---|
1338 | fprintf(stderr,"Library loaded %s \n",errstr); |
---|
1339 | fprintf(stderr,"Service Shared Object = %s\n",r_inputs->value); |
---|
1340 | #endif |
---|
1341 | r_inputs=getMap(s1->content,"serviceType"); |
---|
1342 | #ifdef DEBUG |
---|
1343 | dumpMap(r_inputs); |
---|
1344 | fprintf(stderr,"%s %s",r_inputs->value,mtoupper(r_inputs->value)); |
---|
1345 | fflush(stderr); |
---|
1346 | #endif |
---|
1347 | if(strcmp(mtoupper(r_inputs->value),"C-FORTRAN")==0){ |
---|
1348 | #ifdef WIN32 |
---|
1349 | //Strange return value needed here ! |
---|
1350 | return 1; |
---|
1351 | #endif |
---|
1352 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
1353 | char fname[1024]; |
---|
1354 | sprintf(fname,"%s",r_inputs->value); |
---|
1355 | #ifdef DEBUG |
---|
1356 | fprintf(stderr,"Try to load function %s\n",fname); |
---|
1357 | #endif |
---|
1358 | #ifdef WIN32 |
---|
1359 | typedef int (CALLBACK* execute_t)(char***,char***,char***); |
---|
1360 | execute_t execute=(execute_t)GetProcAddress(so,fname); |
---|
1361 | #else |
---|
1362 | typedef int (*execute_t)(char***,char***,char***); |
---|
1363 | execute_t execute=(execute_t)dlsym(so,fname); |
---|
1364 | #endif |
---|
1365 | #ifdef DEBUG |
---|
1366 | #ifdef WIN32 |
---|
1367 | errstr = GetLastError(); |
---|
1368 | #else |
---|
1369 | errstr = dlerror(); |
---|
1370 | #endif |
---|
1371 | fprintf(stderr,"Function loaded %s\n",errstr); |
---|
1372 | #endif |
---|
1373 | char main_conf[10][30][1024]; |
---|
1374 | char inputs[10][30][1024]; |
---|
1375 | char outputs[10][30][1024]; |
---|
1376 | for(int i=0;i<10;i++){ |
---|
1377 | for(int j=0;j<30;j++){ |
---|
1378 | memset(main_conf[i][j],0,1024); |
---|
1379 | memset(inputs[i][j],0,1024); |
---|
1380 | memset(outputs[i][j],0,1024); |
---|
1381 | } |
---|
1382 | } |
---|
1383 | mapsToCharXXX(m,(char***)main_conf); |
---|
1384 | mapsToCharXXX(request_input_real_format,(char***)inputs); |
---|
1385 | mapsToCharXXX(request_output_real_format,(char***)outputs); |
---|
1386 | eres=execute((char***)&main_conf[0],(char***)&inputs[0],(char***)&outputs[0]); |
---|
1387 | #ifdef DEBUG |
---|
1388 | fprintf(stderr,"Function run successfully \n"); |
---|
1389 | #endif |
---|
1390 | charxxxToMaps((char***)&outputs[0],&request_output_real_format); |
---|
1391 | }else{ |
---|
1392 | #ifdef WIN32 |
---|
1393 | errstr = GetLastError(); |
---|
1394 | #ifdef DEBUG |
---|
1395 | fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr); |
---|
1396 | #endif |
---|
1397 | #endif |
---|
1398 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
1399 | #ifdef DEBUG |
---|
1400 | fprintf(stderr,"Try to load function %s\n",r_inputs->value); |
---|
1401 | #endif |
---|
1402 | typedef int (*execute_t)(maps**,maps**,maps**); |
---|
1403 | #ifdef WIN32 |
---|
1404 | execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); |
---|
1405 | #ifdef DEBUG |
---|
1406 | /*if(!execute)*/ |
---|
1407 | errstr = GetLastError(); |
---|
1408 | fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr); |
---|
1409 | /*else |
---|
1410 | fprintf(stderr,"Function %s loaded\n",r_inputs->value);*/ |
---|
1411 | #endif |
---|
1412 | #else |
---|
1413 | execute_t execute=(execute_t)dlsym(so,r_inputs->value); |
---|
1414 | #endif |
---|
1415 | |
---|
1416 | #ifdef DEBUG |
---|
1417 | #ifdef WIN32 |
---|
1418 | errstr = GetLastError(); |
---|
1419 | #else |
---|
1420 | errstr = dlerror(); |
---|
1421 | #endif |
---|
1422 | fprintf(stderr,"Function loaded %s\n",errstr); |
---|
1423 | #endif |
---|
1424 | |
---|
1425 | #ifdef DEBUG |
---|
1426 | fprintf(stderr,"Now run the function \n"); |
---|
1427 | fflush(stderr); |
---|
1428 | #endif |
---|
1429 | eres=execute(&m,&request_input_real_format,&request_output_real_format); |
---|
1430 | #ifdef DEBUG |
---|
1431 | fprintf(stderr,"Function loaded and returned %d\n",eres); |
---|
1432 | fflush(stderr); |
---|
1433 | #endif |
---|
1434 | } |
---|
1435 | |
---|
1436 | dlclose(so); |
---|
1437 | } else { |
---|
1438 | /** |
---|
1439 | * Unable to load the specified shared library |
---|
1440 | */ |
---|
1441 | char tmps[1024]; |
---|
1442 | sprintf(tmps,"C Library can't be loaded %s \n",errstr); |
---|
1443 | map* tmps1=createMap("text",tmps); |
---|
1444 | printExceptionReportResponse(m,tmps1); |
---|
1445 | exit(1); |
---|
1446 | } |
---|
1447 | } |
---|
1448 | else{ |
---|
1449 | if(strcmp(mtoupper(r_inputs->value),"PYTHON")==0){ |
---|
1450 | eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
1451 | } |
---|
1452 | else |
---|
1453 | |
---|
1454 | #ifdef USE_JAVA |
---|
1455 | if(strcmp(mtoupper(r_inputs->value),"JAVA")==0){ |
---|
1456 | eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
1457 | } |
---|
1458 | else |
---|
1459 | #endif |
---|
1460 | |
---|
1461 | #ifdef USE_PHP |
---|
1462 | if(strcmp(mtoupper(r_inputs->value),"PHP")==0){ |
---|
1463 | eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
1464 | } |
---|
1465 | else |
---|
1466 | #endif |
---|
1467 | |
---|
1468 | #ifdef USE_JS |
---|
1469 | if(strcmp(mtoupper(r_inputs->value),"JS")==0){ |
---|
1470 | eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
1471 | } |
---|
1472 | else |
---|
1473 | #endif |
---|
1474 | { |
---|
1475 | char tmpv[1024]; |
---|
1476 | sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value); |
---|
1477 | map* tmps=createMap("text",tmpv); |
---|
1478 | printExceptionReportResponse(m,tmps); |
---|
1479 | return(-1); |
---|
1480 | } |
---|
1481 | } |
---|
1482 | } |
---|
1483 | else{ |
---|
1484 | |
---|
1485 | pid_t pid; |
---|
1486 | #ifdef DEBUG |
---|
1487 | fprintf(stderr,"\nPID : %d\n",cpid); |
---|
1488 | #endif |
---|
1489 | #ifndef WIN32 |
---|
1490 | pid = fork (); |
---|
1491 | #else |
---|
1492 | pid = 0; |
---|
1493 | #endif |
---|
1494 | if (pid > 0) { |
---|
1495 | /** |
---|
1496 | * dady : |
---|
1497 | * set status to SERVICE_ACCEPTED |
---|
1498 | */ |
---|
1499 | #ifdef DEBUG |
---|
1500 | fprintf(stderr,"father pid continue (origin %d) %d ...\n",cpid,getpid()); |
---|
1501 | #endif |
---|
1502 | eres=SERVICE_ACCEPTED; |
---|
1503 | }else if (pid == 0) { |
---|
1504 | /** |
---|
1505 | * son : have to close the stdout, stdin and stderr to let the parent |
---|
1506 | * process answer to http client. |
---|
1507 | */ |
---|
1508 | char tmp1[256]; |
---|
1509 | r_inputs=getMapFromMaps(m,"main","tmpPath"); |
---|
1510 | sprintf(tmp1,"%s",r_inputs->value); |
---|
1511 | r_inputs=getMap(s1->content,"ServiceProvider"); |
---|
1512 | sprintf(tmp1,"%s/%s",strdup(tmp1),r_inputs->value); |
---|
1513 | sprintf(tmp1,"%s_%d.xml",strdup(tmp1),cpid); |
---|
1514 | #ifdef DEBUG |
---|
1515 | fprintf(stderr,"RUN IN BACKGROUND MODE \n"); |
---|
1516 | fprintf(stderr,"son pid continue (origin %d) %d ...\n",cpid,getpid()); |
---|
1517 | fprintf(stderr,"\nFILE TO STORE DATA %s\n",tmp1); |
---|
1518 | #endif |
---|
1519 | freopen(tmp1 , "w+", stdout); |
---|
1520 | fclose(stdin); |
---|
1521 | r_inputs=getMapFromMaps(m,"main","tmpPath"); |
---|
1522 | sprintf(tmp1,"%s",r_inputs->value); |
---|
1523 | r_inputs=getMap(s1->content,"ServiceProvider"); |
---|
1524 | sprintf(tmp1,"%s/%s",strdup(tmp1),r_inputs->value); |
---|
1525 | sprintf(tmp1,"%s_%d_error.log",strdup(tmp1),cpid); |
---|
1526 | freopen(tmp1,"w+",stderr); |
---|
1527 | /** |
---|
1528 | * set status to SERVICE_STARTED and flush stdout to ensure full |
---|
1529 | * content was outputed (the file used to store the ResponseDocument). |
---|
1530 | * The rewind stdout to restart writing from the bgining of the file, |
---|
1531 | * this way the data will be updated at the end of the process run. |
---|
1532 | */ |
---|
1533 | printProcessResponse1(m,request_inputs,cpid, |
---|
1534 | s[0],r_inputs->value,SERVICE_STARTED, |
---|
1535 | request_input_real_format, |
---|
1536 | request_output_real_format); |
---|
1537 | fflush(stdout); |
---|
1538 | rewind(stdout); |
---|
1539 | /** |
---|
1540 | * Extract serviceType to know what kind of service shoudl be loaded |
---|
1541 | */ |
---|
1542 | r_inputs=NULL; |
---|
1543 | r_inputs=getMap(s1->content,"serviceType"); |
---|
1544 | #ifdef DEBUG |
---|
1545 | fprintf(stderr,"LOAD A %s SERVICE PROVIDER IN BACKGROUND MODE \n",r_inputs->value); |
---|
1546 | #endif |
---|
1547 | |
---|
1548 | if(strncmp(mtoupper(r_inputs->value),"C",1)==0){ |
---|
1549 | r_inputs=getMap(request_inputs,"metapath"); |
---|
1550 | sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); |
---|
1551 | r_inputs=getMap(s1->content,"ServiceProvider"); |
---|
1552 | sprintf(tmps1,"%s/%s",strdup(tmps1),r_inputs->value); |
---|
1553 | |
---|
1554 | #ifdef DEBUG |
---|
1555 | fprintf(stderr,"Trying to load %s\n",tmps1); |
---|
1556 | #endif |
---|
1557 | #ifdef WIN32 |
---|
1558 | HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); |
---|
1559 | #else |
---|
1560 | void* so = dlopen(tmps1, RTLD_LAZY); |
---|
1561 | #endif |
---|
1562 | #ifdef WIN32 |
---|
1563 | DWORD errstr; |
---|
1564 | errstr = GetLastError(); |
---|
1565 | #else |
---|
1566 | char *errstr; |
---|
1567 | errstr = dlerror(); |
---|
1568 | #endif |
---|
1569 | if( so != NULL ) { |
---|
1570 | r_inputs=getMap(s1->content,"serviceType"); |
---|
1571 | #ifdef DEBUG |
---|
1572 | fprintf(stderr,"r_inputs->value = %s\n",r_inputs->value); |
---|
1573 | #endif |
---|
1574 | if(strcmp(mtoupper(r_inputs->value),"C-FORTRAN")==0){ |
---|
1575 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
1576 | #ifdef DEBUG |
---|
1577 | fprintf(stderr,"Try to load function %s\n",r_inputs->value); |
---|
1578 | #endif |
---|
1579 | typedef int (*execute_t)(char***,char***,char***); |
---|
1580 | char fname[1024]; |
---|
1581 | sprintf(fname,"%s_",r_inputs->value); |
---|
1582 | #ifdef DEBUG |
---|
1583 | fprintf(stderr,"Try to load function %s\n",fname); |
---|
1584 | #endif |
---|
1585 | #ifdef WIN32 |
---|
1586 | execute_t execute=(execute_t)GetProcAddress(so,fname); |
---|
1587 | #else |
---|
1588 | execute_t execute=(execute_t)dlsym(so,fname); |
---|
1589 | #endif |
---|
1590 | #ifdef DEBUG |
---|
1591 | #ifdef WIN32 |
---|
1592 | errstr = GetLastError(); |
---|
1593 | #else |
---|
1594 | errstr = dlerror(); |
---|
1595 | #endif |
---|
1596 | #endif |
---|
1597 | char main_conf[10][10][1024]; |
---|
1598 | char inputs[10][10][1024]; |
---|
1599 | char outputs[10][10][1024]; |
---|
1600 | for(int i=0;i<10;i++){ |
---|
1601 | for(int j=0;j<10;j++){ |
---|
1602 | memset(main_conf[i][j],0,1024); |
---|
1603 | memset(inputs[i][j],0,1024); |
---|
1604 | memset(outputs[i][j],0,1024); |
---|
1605 | } |
---|
1606 | } |
---|
1607 | mapsToCharXXX(m,(char***)main_conf); |
---|
1608 | mapsToCharXXX(request_input_real_format,(char***)inputs); |
---|
1609 | //mapsToCharXXX(request_output_real_format,(char***)outputs); |
---|
1610 | eres=execute((char***)&main_conf[0],(char***)&inputs[0],(char***)&outputs[0]); |
---|
1611 | charxxxToMaps((char***)&outputs[0],&request_output_real_format); |
---|
1612 | |
---|
1613 | }else{ |
---|
1614 | |
---|
1615 | typedef int (*execute_t)(maps**,maps**,maps**); |
---|
1616 | #ifdef DEBUG |
---|
1617 | fprintf(stderr,"Library loaded %s \n",errstr); |
---|
1618 | #endif |
---|
1619 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
1620 | #ifdef DEBUG |
---|
1621 | fprintf(stderr,"Try to load function %s\n",r_inputs->value); |
---|
1622 | #endif |
---|
1623 | #ifdef WIN32 |
---|
1624 | execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); |
---|
1625 | #else |
---|
1626 | execute_t execute=(execute_t)dlsym(so,r_inputs->value); |
---|
1627 | #endif |
---|
1628 | #ifdef DEBUG |
---|
1629 | #ifdef WIN32 |
---|
1630 | errstr = GetLastError(); |
---|
1631 | #else |
---|
1632 | errstr = dlerror(); |
---|
1633 | #endif |
---|
1634 | fprintf(stderr,"Function loaded %s\n",errstr); |
---|
1635 | #endif |
---|
1636 | /** |
---|
1637 | * set the status code value returned by the service function itself |
---|
1638 | */ |
---|
1639 | eres=execute(&m,&request_input_real_format,&request_output_real_format); |
---|
1640 | dlclose(so); |
---|
1641 | } |
---|
1642 | } else { |
---|
1643 | /** |
---|
1644 | * Unable to load the requested C Library |
---|
1645 | */ |
---|
1646 | char tmps2[1024]; |
---|
1647 | sprintf(tmps1,"C Library can't be loaded %s \n",errstr); |
---|
1648 | map* tmps=createMap("text",tmps1); |
---|
1649 | printExceptionReportResponse(m,tmps); |
---|
1650 | exit(1); |
---|
1651 | } |
---|
1652 | } else{ |
---|
1653 | if(strcmp(mtoupper(r_inputs->value),"PYTHON")==0){ |
---|
1654 | eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
1655 | } |
---|
1656 | else |
---|
1657 | |
---|
1658 | #ifdef USE_JAVA |
---|
1659 | if(strcmp(mtoupper(r_inputs->value),"JAVA")==0){ |
---|
1660 | eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
1661 | } |
---|
1662 | else |
---|
1663 | #endif |
---|
1664 | |
---|
1665 | #ifdef USE_PHP |
---|
1666 | if(strcmp(mtoupper(r_inputs->value),"PHP")==0){ |
---|
1667 | eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
1668 | } |
---|
1669 | else |
---|
1670 | #endif |
---|
1671 | |
---|
1672 | #ifdef USE_JS |
---|
1673 | if(strcmp(mtoupper(r_inputs->value),"JS")==0){ |
---|
1674 | eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
1675 | } |
---|
1676 | else |
---|
1677 | #endif |
---|
1678 | { |
---|
1679 | char tmpv[1024]; |
---|
1680 | sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value); |
---|
1681 | map* tmps=createMap("text",tmpv); |
---|
1682 | printExceptionReportResponse(m,tmps); |
---|
1683 | return -1; |
---|
1684 | } |
---|
1685 | } |
---|
1686 | |
---|
1687 | //res=execute(&m,&request_input_real_format,&request_output_real_format); |
---|
1688 | } else { |
---|
1689 | /** |
---|
1690 | * error server don't accept the process need to output a valid |
---|
1691 | * error response here !!! |
---|
1692 | */ |
---|
1693 | } |
---|
1694 | |
---|
1695 | } |
---|
1696 | |
---|
1697 | #ifdef DEBUG |
---|
1698 | dumpMaps(request_output_real_format); |
---|
1699 | #endif |
---|
1700 | outputResponse(s1,request_input_real_format, |
---|
1701 | request_output_real_format,request_inputs, |
---|
1702 | cpid,m,eres); |
---|
1703 | |
---|
1704 | #ifdef DEBUG |
---|
1705 | fprintf(stderr,"Processed response \n"); |
---|
1706 | fflush(stdout); |
---|
1707 | fflush(stderr); |
---|
1708 | #endif |
---|
1709 | |
---|
1710 | return 0; |
---|
1711 | } |
---|