Ignore:
Timestamp:
May 31, 2011, 3:13:53 AM (13 years ago)
Author:
djay
Message:

Add WIN32 platform support. Fix for values containing @ passed as KVP.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/zoo_service_loader.c

    r214 r216  
    203203#endif
    204204      if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){
    205 #ifdef WIN32
    206         //Strange return value needed here !
    207         return 1;
    208 #endif
    209205        r_inputs=getMap(request_inputs,"Identifier");
    210206        char fname[1024];
     
    284280#endif
    285281      }
     282#ifdef WIN32
     283      *ioutputs=dupMaps(&request_output_real_format);
     284      FreeLibrary(so);
     285#else
    286286      dlclose(so);
     287#endif
    287288    } else {
    288289      /**
     
    345346              }
    346347  *myMap=m;
     348#ifndef WIN32
    347349  *ioutputs=request_output_real_format;
     350#endif
    348351}
     352
     353#ifdef WIN32
     354/**
     355 * createProcess function: create a new process after setting some env variables
     356 */
     357void 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
    349424
    350425int runRequest(map* request_inputs)
     
    671746#endif
    672747  int saved_stdout = dup(fileno(stdout));
    673   dup2(fileno(stderr),fileno(stdout));
     748    dup2(fileno(stderr),fileno(stdout));
    674749  t=getServiceFromFile(tmps1,&s1);
    675750  fflush(stdout);
    676751  dup2(saved_stdout,fileno(stdout));
    677752  if(t<0){
    678     char tmpMsg[2048+strlen(r_inputs->value)];
     753    char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value));
     754   
    679755    sprintf(tmpMsg,_("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),r_inputs->value);
    680756    errorException(m, tmpMsg, "InvalidParameterValue");
     757    free(tmpMsg);
    681758    freeService(&s1);
    682759    free(s1);
     
    687764    return 0;
    688765  }
    689   close(saved_stdout);
     766  //close(saved_stdout);
    690767
    691768#ifdef DEBUG
     
    887964        char tmpn[256];
    888965        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        }
    891974#ifdef DEBUG
    892975        fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1);
     
    898981          }
    899982          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");
    901987          tmpmaps->next=NULL;
    902988        }
     
    912998          char tmpn1[1024];
    913999          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          }
    9161018#ifdef DEBUG
    9171019          fprintf(stderr,"*** NAME NON URL-ENCODED \n***%s***\n",tmpn1);
     
    9201022          if(strcmp(tmpn1,"xlink:href")!=0)
    9211023            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);
    9361078            }
    937 #ifdef DEBUG
    938             fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);
    939 #endif
    940 #ifndef WIN32
    941             if(CHECK_INET_HANDLE(hInternet))
    942 #endif
    943               {
    944                 res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
    945                                     INTERNET_FLAG_NO_CACHE_WRITE,0);
    946 #ifdef DEBUG
    947                 fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
    948                         tmpv1+1,res.nDataAlloc,res.nDataLen);
    949 #endif
    950                 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           }
    9731079          tmpc=strtok(NULL,"@");
    9741080        }
     
    11321238            hInternet.header=NULL;
    11331239            while(cur3){
     1240              while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE)
     1241                cur2=cur3->next;
    11341242              if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){
    11351243                const char *ha[2];
     
    16971805  _tmpMaps->next=NULL;
    16981806  addToMap(_tmpMaps->content,"status","0");
     1807  addToMap(_tmpMaps->content,"cwd",ntmp);
    16991808  if(cgiCookie!=NULL && strlen(cgiCookie)>0){
    17001809    addToMap(_tmpMaps->content,"sessid",strstr(cgiCookie,"=")+1);
     
    17221831  dumpMap(request_inputs);
    17231832#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
    17251849  if(status!=NULL)
    17261850    if(strcasecmp(status->value,"false")==0)
     
    17381862    pid = fork ();
    17391863#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);
    17411873#endif
    17421874    if (pid > 0) {
     
    17651897      fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value);
    17661898#endif
     1899      freopen(flog,"w+",stderr);
    17671900      freopen(fbkp , "w+", stdout);
    17681901      fclose(stdin);
    1769       freopen(flog,"w+",stderr);
    17701902      free(fbkp);
    17711903      free(flog);
     
    17781910      updateStatus(m);
    17791911      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
    17831916      fflush(stdout);
    17841917      rewind(stdout);
     1918#endif
    17851919
    17861920      loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres);
     
    17981932#ifdef DEBUG
    17991933  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);
    18011935  fflush(stderr);
    18021936#endif
     
    18051939                   request_output_real_format,request_inputs,
    18061940                   cpid,m,eres);
     1941  fflush(stdout);
    18071942  /**
    18081943   * Ensure that if error occurs when freeing memory, no signal will return
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png