- Timestamp:
- Feb 1, 2018, 11:27:28 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c
r860 r862 112 112 } 113 113 114 115 114 /** 116 115 * Practically invoke the callback, meaning sending the HTTP POST request. … … 121 120 local_params* arg=(local_params*)args; 122 121 HINTERNET hInternet,res1; 122 const struct tm *tm; 123 size_t len; 124 time_t now; 125 char *tmp1; 126 map *tmpStatus; 123 127 hInternet=InternetOpen("ZooWPSClient\0", 124 128 INTERNET_OPEN_TYPE_PRECONFIG, … … 134 138 free(URL); 135 139 #ifdef CALLBACK_DEBUG 140 now = time ( NULL ); 141 tm = localtime ( &now ); 142 tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); 143 len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); 136 144 fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS cStep %d %d\n",pthread_self(),__FILE__,__LINE__,cStep,isOngoing); 137 145 fprintf(stderr," * JSON: [%s] \n",jsonStr); 138 146 fprintf(stderr," * URL: %s/ \n\n",hInternet.waitingRequests[0]); 147 fprintf(stderr," * DATE: %s/ \n\n",tmp1); 139 148 fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS\n",pthread_self(),__FILE__,__LINE__); 149 free(tmp1); 140 150 #endif 141 151 while( (arg->step!=7 || isOngoing>0) && … … 152 162 } 153 163 #endif 154 const struct tm *tm;155 size_t len;156 time_t now;157 char *tmp1;158 map *tmpStatus;159 164 160 165 now = time ( NULL ); … … 184 189 #ifdef CALLBACK_DEBUG 185 190 fprintf(stderr,"************************* From thread %d %s %d: REQUEST END (%s)\n\n",pthread_self(),__FILE__,__LINE__,tmp1); 186 #endif 191 #endif 187 192 free(tmp1); 188 193 char *tmp = (char *) malloc ((hInternet.ihandle[0].nDataLen + 1) … … 206 211 if(cStep==0 || cStep==6 || arg->state==1) 207 212 cStep=arg->step+1; 208 #ifdef CALLBACK_DEBUG 209 fprintf(stderr,"************************* From thread %d %s %d: RESPONSE CONTENT\n",pthread_self(),__FILE__,__LINE__); 213 #ifdef CALLBACK_DEBUG 214 now = time ( NULL ); 215 tm = localtime ( &now ); 216 tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); 217 len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); 218 fprintf(stderr,"************************* From thread %d %s %d: RESPONSE CONTENT (%s)\n",pthread_self(),__FILE__,__LINE__,,tmp1); 210 219 for(i=0;i<7;i++){ 211 220 fprintf(stderr,"%d) %d %d\n",i,steps[i][0],steps[i][1]); … … 214 223 fprintf(stderr,"************************* From thread %d %s %d\n\n",pthread_self(),__FILE__,__LINE__); 215 224 fflush(stderr); 225 free(tmp1); 216 226 #endif 217 227 steps[arg->step][arg->state]=true; 218 228 free(tmp); 219 //free(args); 229 #ifdef CALLBACK_DEBUG 220 230 fprintf(stderr,"************************* From thread %d %s %d: EXIT\n\n",pthread_self(),__FILE__,__LINE__); 221 231 fflush(stderr); 232 #endif 222 233 pthread_exit(NULL); 223 234 } … … 305 316 // Update the execute request stored on disk at step 0,0 to modify the references used. 306 317 if(state==1){ 307 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);308 fflush(stderr);309 318 maps* curs=inputs; 310 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);311 fflush(stderr);312 319 xmlInitParser(); 313 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);314 fflush(stderr);315 320 map* xmlPath=getMapFromMaps(conf,"lenv","execute_file"); 316 dumpMap(xmlPath);317 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);318 fflush(stderr);319 321 while(curs!=NULL){ 320 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 321 fflush(stderr); 322 dumpMap(curs->content); 323 //map* bvMap=getMap(curs->content,"byValue"); 324 // TODO handle mapArray 325 //if(bvMap!=NULL && strncasecmp(bvMap->value,"true",4)==0){ 326 if(getMap(curs->content,"href")==NULL && getMap(curs->content,"mimeType")!=NULL){ 327 map* tmpMap=getMap(curs->content,"value"); 328 char tmpStr[100]; 329 sprintf(tmpStr,"%d",strlen(tmpMap->value)); 330 addToMap(curs->content,"size",tmpStr); 331 tmpMap=getMap(curs->content,"mimeType"); 332 addToMap(curs->content,"fmimeType",tmpMap->value); 333 tmpMap=getMap(curs->content,"cache_file"); 334 addToMap(curs->content,"generated_file",tmpMap->value); 335 addToMap(curs->content,"storage",tmpMap->value); 336 setReferenceUrl(conf,curs); 337 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 338 fflush(stderr); 339 dumpMap(curs->content); 340 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 341 fflush(stderr); 342 const char *params[5]; 343 int xmlLoadExtDtdDefaultValue; 344 int hasFile=-1; 345 map* xslPath=getMapFromMaps(conf,"callback","template"); 346 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 347 fflush(stderr); 348 dumpMap(xslPath); 349 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 350 fflush(stderr); 351 map* filePath=getMap(curs->content,"ref_wfs_link"); 352 if(filePath==NULL) 353 filePath=getMap(curs->content,"ref_wcs_link"); 354 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 355 fflush(stderr); 356 dumpMap(filePath); 357 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 358 fflush(stderr); 359 char* inputName=curs->name; 360 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 361 fflush(stderr); 362 if(xslPath==NULL || xmlPath==NULL || filePath==NULL) 363 break; 364 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 365 fflush(stderr); 366 char *tmpParam=(char*)malloc((strlen(curs->name)+11)*sizeof(char)); 367 char *tmpParam1=(char*)malloc((strlen(filePath->value)+11)*sizeof(char)); 368 addToMap(curs->content,"href",filePath->value); 369 addToMap(curs->content,"xlink:href",filePath->value); 370 sprintf(tmpParam,"string(\"%s\")",curs->name); 371 sprintf(tmpParam1,"string(\"%s\")",filePath->value); 372 params[0]="attr"; 373 params[1]=tmpParam; 374 params[2]="value"; 375 params[3]=tmpParam1;//filePath->value; 376 params[4]=NULL; 377 fprintf(stderr, "## XSLT PARAMETERS ATTR: %s VALUE: %s \n", 378 tmpParam,tmpParam1); 379 xmlSubstituteEntitiesDefault(1); 380 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 381 fflush(stderr); 382 xmlLoadExtDtdDefaultValue = 0; 383 xsltStylesheetPtr cur = NULL; 384 xmlDocPtr doc, res; 385 cur = xsltParseStylesheetFile(BAD_CAST xslPath->value); 386 doc = xmlParseFile(xmlPath->value); 387 fflush(stderr); 388 res = xsltApplyStylesheet(cur, doc, params); 389 xmlChar *xmlbuff; 390 int buffersize; 391 xmlDocDumpFormatMemory(res, &xmlbuff, &buffersize, 1); 392 // Store the executeRequest in file again 393 free(tmpParam); 394 free(tmpParam1); 395 fprintf(stderr," # Request / XSLT: %s\n",xmlbuff); 396 fflush(stderr); 397 FILE* saveExecute=fopen(xmlPath->value,"wb"); 398 fwrite(xmlbuff,1,buffersize,saveExecute); 399 fflush(saveExecute); 400 fclose(saveExecute); 401 xmlFree(xmlbuff); 402 xmlFreeDoc(doc); 403 xsltFreeStylesheet(cur); 322 map* length=getMap(curs->content,"length"); 323 map* useMS=getMap(curs->content,"useMapserver"); 324 if(length==NULL){ 325 addToMap(curs->content,"length","1"); 326 length=getMap(curs->content,"length"); 404 327 } 405 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 406 fflush(stderr); 328 int len=atoi(length->value); 329 for(int ii=0;ii<len;ii++){ 330 if(getMapArray(curs->content,"byValue",ii)!=NULL && getMapArray(curs->content,"mimeType",ii)!=NULL && useMS!=NULL && strncasecmp(useMS->value,"true",4)==0){ 331 map* tmpMap=getMapArray(curs->content,"value",ii); 332 char tmpStr[100]; 333 sprintf(tmpStr,"%d",strlen(tmpMap->value)); 334 setMapArray(curs->content,"size",ii,tmpStr); 335 tmpMap=getMapArray(curs->content,"mimeType",ii); 336 setMapArray(curs->content,"fmimeType",ii,tmpMap->value); 337 tmpMap=getMapArray(curs->content,"cache_file",ii); 338 setMapArray(curs->content,"generated_file",ii,tmpMap->value); 339 setMapArray(curs->content,"storage",ii,tmpMap->value); 340 setReferenceUrl(conf,curs); 341 addIntToMap(curs->content,"published_id",ii+1); 342 const char *params[7]; 343 int xmlLoadExtDtdDefaultValue; 344 int hasFile=-1; 345 map* xslPath=getMapFromMaps(conf,"callback","template"); 346 map* filePath=getMapArray(curs->content,"ref_wfs_link",ii); 347 if(filePath==NULL) 348 filePath=getMap(curs->content,"ref_wcs_link"); 349 char* inputName=curs->name; 350 if(xslPath==NULL || xmlPath==NULL || filePath==NULL) 351 break; 352 char *tmpParam=(char*)malloc((strlen(curs->name)+11)*sizeof(char)); 353 char *tmpParam1=(char*)malloc((strlen(filePath->value)+11)*sizeof(char)); 354 char tmpParam2[16]; 355 sprintf(tmpParam2,"string(\"%d\")",ii); 356 setMapArray(curs->content,"href",ii,filePath->value); 357 setMapArray(curs->content,"xlink:href",ii,filePath->value); 358 tmpMap=getMapArray(curs->content,"cache_url",ii); 359 if(tmpMap!=NULL) 360 setMapArray(curs->content,"xlink:href",ii,tmpMap->value); 361 else 362 setMapArray(curs->content,"xlink:href",ii,filePath->value); 363 sprintf(tmpParam,"string(\"%s\")",curs->name); 364 sprintf(tmpParam1,"string(\"%s\")",filePath->value); 365 sprintf(tmpParam2,"string(\"%d\")",ii); 366 params[0]="attr"; 367 params[1]=tmpParam; 368 params[2]="value"; 369 params[3]=tmpParam1;//filePath->value; 370 params[4]="cnt"; 371 params[5]=tmpParam2; 372 params[6]=NULL; 373 fprintf(stderr, "## XSLT PARAMETERS ATTR: %s VALUE: %s INDEX: %s\n", 374 tmpParam,tmpParam1,tmpParam2); 375 fflush(stderr); 376 xmlSubstituteEntitiesDefault(1); 377 xmlLoadExtDtdDefaultValue = 0; 378 xsltStylesheetPtr cur = NULL; 379 xmlDocPtr doc, res; 380 cur = xsltParseStylesheetFile(BAD_CAST xslPath->value); 381 doc = xmlParseFile(xmlPath->value); 382 fflush(stderr); 383 res = xsltApplyStylesheet(cur, doc, params); 384 xmlChar *xmlbuff; 385 int buffersize; 386 xmlDocDumpFormatMemory(res, &xmlbuff, &buffersize, 1); 387 // Store the executeRequest in file again 388 free(tmpParam); 389 free(tmpParam1); 390 fprintf(stderr," # Request / XSLT: %s\n",xmlbuff); 391 fflush(stderr); 392 FILE* saveExecute=fopen(xmlPath->value,"wb"); 393 if(saveExecute!=NULL){ 394 fwrite(xmlbuff,1,buffersize,saveExecute); 395 fflush(saveExecute); 396 fclose(saveExecute); 397 } 398 xmlFree(xmlbuff); 399 xmlFreeDoc(doc); 400 xsltFreeStylesheet(cur); 401 } 402 } 403 addIntToMap(curs->content,"published_id",0); 407 404 curs=curs->next; 408 405 } 409 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);410 fflush(stderr);411 406 xmlCleanupParser(); 412 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);413 fflush(stderr);414 407 FILE* f0=fopen(xmlPath->value,"rb"); 415 408 if(f0!=NULL){ … … 423 416 fcontent[flen]=0; 424 417 fclose(f0); 425 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);426 fflush(stderr);427 418 map *schema=getMapFromMaps(conf,"database","schema"); 428 419 map* sid=getMapFromMaps(conf,"lenv","usid"); 429 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);430 fflush(stderr);431 420 char *req=(char*)malloc((flen+strlen(schema->value)+strlen(sid->value)+66)*sizeof(char)); 432 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);433 fflush(stderr);434 421 sprintf(req,"UPDATE %s.services set request_execute_content=$$%s$$ WHERE uuid=$$%s$$",schema->value,fcontent,sid->value); 435 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);436 fflush(stderr);437 422 execSql(conf,1,req); 438 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);439 fflush(stderr);440 423 free(fcontent); 441 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);442 fflush(stderr);443 424 free(req); 444 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);445 fflush(stderr);446 425 } 447 426 } … … 453 432 { 454 433 "xlink:href", 455 "ref "434 "ref_download_link" 456 435 }, 457 436 { … … 514 493 setMapArray(curs->content,"storage",ii,tmpMap->value); 515 494 } 516 fprintf(stderr,"%s %d\n",__FILE__,__LINE__);517 dumpMap(curs->content);518 495 struct stat buf; 519 496 char timeStr[ 100 ] = ""; … … 553 530 if(hasRef<0) 554 531 json_object_put(res3); 555 else 556 json_object_object_add(res1,curs->name,res3); 532 else{ 533 json_object_object_add(res1,curs->name,json_object_get(res3)); 534 json_object_put(res3); 535 } 557 536 addIntToMap(curs->content,"published_id",0); 558 537 curs=curs->next; … … 570 549 if(length!=NULL){ 571 550 json_object *res1=json_object_new_object(); 572 json_object *res3=json_object_new_array();573 551 int limit=atoi(length->value); 574 552 int i=0; … … 589 567 json_object_object_add(res1,tmp0->value,res2); 590 568 }else{ 591 if(json_object_is_type(res4,json_type_object)){ 592 json_object_array_add(res3,res4); 593 } 594 json_object_array_add(res3,res2); 595 if(json_object_is_type(res4,json_type_object)){ 569 if(json_object_is_type(res4,json_type_object) && !json_object_is_type(res4, json_type_array)){ 570 json_object *res3=json_object_new_array(); 571 json_object_array_add(res3,json_object_get(res4)); 572 json_object_array_add(res3,res2); 596 573 json_object_object_del(res1,tmp0->value); 597 574 json_object_object_add(res1,tmp0->value,res3); 598 } 575 }else 576 json_object_array_add(res4,res2); 599 577 } 600 578 } 601 579 } 602 if(json_object_array_length(res3)==0)603 json_object_put(res3);604 580 json_object_object_add(res,"inputs",res1); 605 581 } 606 //json_object_object_add(res,"inputs",in);607 582 } 608 583 break; … … 631 606 case 5: { 632 607 // Downloading process outputs from cluster 633 //json_object* in=mapsToJson(outputs);634 608 maps* curs=outputs; 635 609 dumpMaps(curs); … … 708 682 json_object *jsStr=json_object_new_string(sid->value); 709 683 json_object_object_add(res2,keys[i][1],jsStr); 710 if(i==0) 684 if(i==0){ 711 685 hasRef=1; 686 json_object_object_add(res2,"ref_download_link",jsStr); 687 } 688 if(i==1){ 689 struct stat buf; 690 char timeStr[ 100 ] = ""; 691 if (stat(sid->value, &buf)==0){ 692 strftime(timeStr, 100, "%d-%m-%Y %H:%M:%S", localtime( &buf.st_mtime)); 693 json_object *jsStr=json_object_new_string(timeStr); 694 json_object_object_add(res2,"creation_date",jsStr); 695 } 696 } 712 697 } 713 698 } … … 724 709 int i0=0; 725 710 for(;i0<6;i0++){ 726 if(i0==0) 727 sid=getMap(specificMaps->content,specifics[i][1]); 728 else 729 sid=getMap(specificMaps->content,keys[i0][0]); 711 sid=getMap(specificMaps->content,keys[i0][0]); 730 712 if(sid!=NULL){ 731 713 json_object *jsStr=json_object_new_string(sid->value); … … 760 742 json_object *jsStr=json_object_new_string(sid->value); 761 743 json_object_object_add(res3,keys[i0][1],jsStr); 762 //if(i0==0)763 744 hasRef0=1; 764 745 } … … 858 839 local_arguments[nbThreads]->step=step; 859 840 local_arguments[nbThreads]->state=state; 860 //pthread_t p1;861 841 if(myThreads==NULL) 862 842 myThreads=(pthread_t*)malloc((nbThreads+1)*sizeof(pthread_t)); … … 867 847 return false; 868 848 } 869 //free(argumentsA);870 849 nbThreads++; 871 850 return true; … … 878 857 int i=0; 879 858 for(i=0;i<nbThreads;i++){ 880 fprintf(stderr,"%s %d %d \n",__FILE__,__LINE__,i);881 fflush(stderr);882 859 pthread_join(myThreads[i],NULL); 883 860 free(local_arguments[i]);
Note: See TracChangeset
for help on using the changeset viewer.