Changeset 216 for trunk/zoo-kernel/zoo_service_loader.c
- Timestamp:
- May 31, 2011, 3:13:53 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-kernel/zoo_service_loader.c
r214 r216 203 203 #endif 204 204 if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){ 205 #ifdef WIN32206 //Strange return value needed here !207 return 1;208 #endif209 205 r_inputs=getMap(request_inputs,"Identifier"); 210 206 char fname[1024]; … … 284 280 #endif 285 281 } 282 #ifdef WIN32 283 *ioutputs=dupMaps(&request_output_real_format); 284 FreeLibrary(so); 285 #else 286 286 dlclose(so); 287 #endif 287 288 } else { 288 289 /** … … 345 346 } 346 347 *myMap=m; 348 #ifndef WIN32 347 349 *ioutputs=request_output_real_format; 350 #endif 348 351 } 352 353 #ifdef WIN32 354 /** 355 * createProcess function: create a new process after setting some env variables 356 */ 357 void createProcess(maps* m,map* request_inputs,service* s1,char* opts,int cpid, maps* inputs,maps* outputs){ 358 STARTUPINFO si; 359 PROCESS_INFORMATION pi; 360 ZeroMemory( &si, sizeof(si) ); 361 si.cb = sizeof(si); 362 ZeroMemory( &pi, sizeof(pi) ); 363 char *tmp=(char *)malloc((1024+cgiContentLength)*sizeof(char)); 364 char *tmpq=(char *)malloc((1024+cgiContentLength)*sizeof(char)); 365 map *req=getMap(request_inputs,"request"); 366 map *id=getMap(request_inputs,"identifier"); 367 map *di=getMap(request_inputs,"DataInputs"); 368 369 char *dataInputsKVP=getMapsAsKVP(inputs,cgiContentLength,0); 370 char *dataOutputsKVP=getMapsAsKVP(outputs,cgiContentLength,1); 371 fprintf(stderr,"DATAINPUTSKVP %s\n",dataInputsKVP); 372 fprintf(stderr,"DATAOUTPUTSKVP %s\n",dataOutputsKVP); 373 map *sid=getMapFromMaps(m,"lenv","sid"); 374 map* r_inputs=getMapFromMaps(m,"main","tmpPath"); 375 map* r_inputs1=getMap(s1->content,"ServiceProvider"); 376 map* r_inputs2=getMap(s1->content,"ResponseDocument"); 377 if(r_inputs2==NULL) 378 r_inputs2=getMap(s1->content,"RawDataOutput"); 379 map *tmpPath=getMapFromMaps(m,"lenv","cwd"); 380 381 if(r_inputs2!=NULL){ 382 sprintf(tmp,"\"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"",req->value,id->value,dataInputsKVP,r_inputs2->name,r_inputs2->value,sid->value); 383 sprintf(tmpq,"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",req->value,id->value,dataInputsKVP,r_inputs2->name,dataOutputsKVP); 384 } 385 else{ 386 sprintf(tmp,"\"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"",req->value,id->value,dataInputsKVP,sid->value); 387 sprintf(tmpq,"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",req->value,id->value,dataInputsKVP,sid->value); 388 } 389 390 char *tmp1=strdup(tmp); 391 sprintf(tmp,"zoo_loader.cgi %s \"%s\"",tmp1,sid->value); 392 393 free(dataInputsKVP); 394 free(dataOutputsKVP); 395 fprintf(stderr,"REQUEST IS : %s \n",tmp); 396 SetEnvironmentVariable("CGISID",TEXT(sid->value)); 397 SetEnvironmentVariable("QUERY_STRING",TEXT(tmpq)); 398 char clen[1000]; 399 sprintf(clen,"%d",strlen(tmpq)); 400 SetEnvironmentVariable("CONTENT_LENGTH",TEXT(clen)); 401 402 if( !CreateProcess( NULL, // No module name (use command line) 403 TEXT(tmp), // Command line 404 NULL, // Process handle not inheritable 405 NULL, // Thread handle not inheritable 406 FALSE, // Set handle inheritance to FALSE 407 CREATE_NO_WINDOW, // Apache won't wait until the end 408 NULL, // Use parent's environment block 409 NULL, // Use parent's starting directory 410 &si, // Pointer to STARTUPINFO struct 411 &pi ) // Pointer to PROCESS_INFORMATION struct 412 ) 413 { 414 fprintf( stderr, "CreateProcess failed (%d).\n", GetLastError() ); 415 return ; 416 }else{ 417 fprintf( stderr, "CreateProcess successfull (%d).\n\n\n\n", GetLastError() ); 418 } 419 CloseHandle( pi.hProcess ); 420 CloseHandle( pi.hThread ); 421 fprintf(stderr,"CreateProcess finished !\n"); 422 } 423 #endif 349 424 350 425 int runRequest(map* request_inputs) … … 671 746 #endif 672 747 int saved_stdout = dup(fileno(stdout)); 673 dup2(fileno(stderr),fileno(stdout));748 dup2(fileno(stderr),fileno(stdout)); 674 749 t=getServiceFromFile(tmps1,&s1); 675 750 fflush(stdout); 676 751 dup2(saved_stdout,fileno(stdout)); 677 752 if(t<0){ 678 char tmpMsg[2048+strlen(r_inputs->value)]; 753 char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value)); 754 679 755 sprintf(tmpMsg,_("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),r_inputs->value); 680 756 errorException(m, tmpMsg, "InvalidParameterValue"); 757 free(tmpMsg); 681 758 freeService(&s1); 682 759 free(s1); … … 687 764 return 0; 688 765 } 689 close(saved_stdout);766 //close(saved_stdout); 690 767 691 768 #ifdef DEBUG … … 887 964 char tmpn[256]; 888 965 memset(tmpn,0,256); 889 strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); 890 tmpn[strlen(tmpc)-strlen(tmpv)]=0; 966 if(tmpv!=NULL){ 967 strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); 968 tmpn[strlen(tmpc)-strlen(tmpv)]=0; 969 } 970 else{ 971 strncpy(tmpn,tmpc,strlen(tmpc)*sizeof(char)); 972 tmpn[strlen(tmpc)]=0; 973 } 891 974 #ifdef DEBUG 892 975 fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1); … … 898 981 } 899 982 tmpmaps->name=strdup(tmpn); 900 tmpmaps->content=createMap("value",tmpv+1); 983 if(tmpv!=NULL) 984 tmpmaps->content=createMap("value",tmpv+1); 985 else 986 tmpmaps->content=createMap("value","Reference"); 901 987 tmpmaps->next=NULL; 902 988 } … … 912 998 char tmpn1[1024]; 913 999 memset(tmpn1,0,1024); 914 strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1)); 915 tmpn1[strlen(tmpc)-strlen(tmpv1)]=0; 1000 if(tmpv1!=NULL){ 1001 strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1)); 1002 tmpn1[strlen(tmpc)-strlen(tmpv1)]=0; 1003 addToMap(tmpmaps->content,tmpn1,tmpv1+1); 1004 } 1005 else{ 1006 strncpy(tmpn1,tmpc,strlen(tmpc)); 1007 tmpn1[strlen(tmpc)]=0; 1008 map* lmap=getLastMap(tmpmaps->content); 1009 char *tmpValue=(char*)calloc((strlen(lmap->value)+strlen(tmpc)+1),sizeof(char)); 1010 sprintf(tmpValue,"%s@%s",lmap->value,tmpc); 1011 free(lmap->value); 1012 lmap->value=strdup(tmpValue); 1013 free(tmpValue); 1014 dumpMap(tmpmaps->content); 1015 tmpc=strtok(NULL,"@"); 1016 continue; 1017 } 916 1018 #ifdef DEBUG 917 1019 fprintf(stderr,"*** NAME NON URL-ENCODED \n***%s***\n",tmpn1); … … 920 1022 if(strcmp(tmpn1,"xlink:href")!=0) 921 1023 addToMap(tmpmaps->content,tmpn1,tmpv1+1); 922 else{ 923 if(strncasecmp(tmpv1+1,"http://",7)!=0 && 924 strncasecmp(tmpv1+1,"ftp://",6)!=0){ 925 char emsg[1024]; 926 sprintf(emsg,_("Unable to find a valid protocol to download the remote file %s"),tmpv1+1); 927 errorException(m,emsg,"InternalError"); 928 freeMaps(&m); 929 free(m); 930 free(REQUEST); 931 free(SERVICE_URL); 932 InternetCloseHandle(hInternet); 933 freeService(&s1); 934 free(s1); 935 return 0; 1024 else 1025 if(tmpv1!=NULL){ 1026 if(strncasecmp(tmpv1+1,"http://",7)!=0 && 1027 strncasecmp(tmpv1+1,"ftp://",6)!=0){ 1028 char emsg[1024]; 1029 sprintf(emsg,_("Unable to find a valid protocol to download the remote file %s"),tmpv1+1); 1030 errorException(m,emsg,"InternalError"); 1031 freeMaps(&m); 1032 free(m); 1033 free(REQUEST); 1034 free(SERVICE_URL); 1035 InternetCloseHandle(hInternet); 1036 freeService(&s1); 1037 free(s1); 1038 return 0; 1039 } 1040 #ifdef DEBUG 1041 fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1); 1042 #endif 1043 #ifndef WIN32 1044 if(CHECK_INET_HANDLE(hInternet)) 1045 #endif 1046 { 1047 res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0, 1048 INTERNET_FLAG_NO_CACHE_WRITE,0); 1049 #ifdef DEBUG 1050 fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n", 1051 tmpv1+1,res.nDataAlloc,res.nDataLen); 1052 #endif 1053 char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char)); 1054 if(tmpContent == NULL){ 1055 return errorException(m, _("Unable to allocate memory."), "InternalError"); 1056 } 1057 size_t dwRead; 1058 InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead); 1059 map* tmpMap=getMap(tmpmaps->content,"value"); 1060 if(tmpMap!=NULL){ 1061 free(tmpMap->value); 1062 tmpMap->value=(char*)malloc((res.nDataLen+1)*sizeof(char)); 1063 memmove(tmpMap->value,tmpContent,(res.nDataLen)*sizeof(char)); 1064 tmpMap->value[res.nDataLen]=0; 1065 if(strlen(tmpContent)!=res.nDataLen){ 1066 char tmp[256]; 1067 sprintf(tmp,"%d",res.nDataLen*sizeof(char)); 1068 addToMap(tmpmaps->content,"size",tmp); 1069 } 1070 } 1071 free(tmpContent); 1072 } 1073 char *tmpx=url_encode(tmpv1+1); 1074 addToMap(tmpmaps->content,tmpn1,tmpx); 1075 free(tmpx); 1076 addToMap(tmpmaps->content,"Reference",tmpv1+1); 1077 dumpMap(tmpmaps->content); 936 1078 } 937 #ifdef DEBUG938 fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);939 #endif940 #ifndef WIN32941 if(CHECK_INET_HANDLE(hInternet))942 #endif943 {944 res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,945 INTERNET_FLAG_NO_CACHE_WRITE,0);946 #ifdef DEBUG947 fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",948 tmpv1+1,res.nDataAlloc,res.nDataLen);949 #endif950 char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));951 if(tmpContent == NULL){952 return errorException(m, _("Unable to allocate memory."), "InternalError");953 }954 size_t dwRead;955 InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);956 map* tmpMap=getMap(tmpmaps->content,"value");957 if(tmpMap!=NULL){958 free(tmpMap->value);959 tmpMap->value=(char*)malloc((res.nDataLen+1)*sizeof(char));960 memmove(tmpMap->value,tmpContent,(res.nDataLen)*sizeof(char));961 tmpMap->value[res.nDataLen]=0;962 if(strlen(tmpContent)!=res.nDataLen){963 char tmp[256];964 sprintf(tmp,"%d",res.nDataLen*sizeof(char));965 addToMap(tmpmaps->content,"size",tmp);966 }967 }968 free(tmpContent);969 }970 addToMap(tmpmaps->content,tmpn1,tmpv1+1);971 addToMap(tmpmaps->content,"Reference",tmpv1+1);972 }973 1079 tmpc=strtok(NULL,"@"); 974 1080 } … … 1132 1238 hInternet.header=NULL; 1133 1239 while(cur3){ 1240 while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE) 1241 cur2=cur3->next; 1134 1242 if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){ 1135 1243 const char *ha[2]; … … 1697 1805 _tmpMaps->next=NULL; 1698 1806 addToMap(_tmpMaps->content,"status","0"); 1807 addToMap(_tmpMaps->content,"cwd",ntmp); 1699 1808 if(cgiCookie!=NULL && strlen(cgiCookie)>0){ 1700 1809 addToMap(_tmpMaps->content,"sessid",strstr(cgiCookie,"=")+1); … … 1722 1831 dumpMap(request_inputs); 1723 1832 #endif 1724 1833 #ifdef WIN32 1834 char *cgiSidL=NULL; 1835 if(getenv("CGISID")!=NULL) 1836 addToMap(request_inputs,"cgiSid",getenv("CGISID")); 1837 map* test1=getMap(request_inputs,"cgiSid"); 1838 if(test1!=NULL){ 1839 cgiSid=test1->value; 1840 } 1841 if(cgiSid!=NULL){ 1842 addToMap(request_inputs,"storeExecuteResponse","true"); 1843 addToMap(request_inputs,"status","true"); 1844 status=getMap(request_inputs,"status"); 1845 dumpMap(request_inputs); 1846 fprintf(stderr,"cgiSID : %s",cgiSid); 1847 } 1848 #endif 1725 1849 if(status!=NULL) 1726 1850 if(strcasecmp(status->value,"false")==0) … … 1738 1862 pid = fork (); 1739 1863 #else 1740 pid = 0; 1864 if(cgiSid==NULL){ 1865 addToMap(request_inputs,"cgSid",cgiSid); 1866 createProcess(m,request_inputs,s1,NULL,cpid,request_input_real_format,request_output_real_format); 1867 pid = cpid; 1868 }else{ 1869 pid=0; 1870 cpid=atoi(cgiSid); 1871 } 1872 fflush(stderr); 1741 1873 #endif 1742 1874 if (pid > 0) { … … 1765 1897 fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value); 1766 1898 #endif 1899 freopen(flog,"w+",stderr); 1767 1900 freopen(fbkp , "w+", stdout); 1768 1901 fclose(stdin); 1769 freopen(flog,"w+",stderr);1770 1902 free(fbkp); 1771 1903 free(flog); … … 1778 1910 updateStatus(m); 1779 1911 printProcessResponse(m,request_inputs,cpid, 1780 s1,r_inputs1->value,SERVICE_STARTED, 1781 request_input_real_format, 1782 request_output_real_format); 1912 s1,r_inputs1->value,SERVICE_STARTED, 1913 request_input_real_format, 1914 request_output_real_format); 1915 #ifndef WIN32 1783 1916 fflush(stdout); 1784 1917 rewind(stdout); 1918 #endif 1785 1919 1786 1920 loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres); … … 1798 1932 #ifdef DEBUG 1799 1933 dumpMaps(request_output_real_format); 1800 fprintf(stderr,"Function loaded and returned %d\n", eres);1934 fprintf(stderr,"Function loaded and returned %d\n",*eres); 1801 1935 fflush(stderr); 1802 1936 #endif … … 1805 1939 request_output_real_format,request_inputs, 1806 1940 cpid,m,eres); 1941 fflush(stdout); 1807 1942 /** 1808 1943 * Ensure that if error occurs when freeing memory, no signal will return
Note: See TracChangeset
for help on using the changeset viewer.