Changeset 862 for branches/prototype-v0


Ignore:
Timestamp:
Feb 1, 2018, 11:27:28 AM (7 years ago)
Author:
djay
Message:

Add the capability to publish heatmap or any templated mapfile using the epecific msInclude and msLayer keys for an output. For MapServer? published output, define 4096 as the default maxsize and use pixel width or height for raster files. use the correct MapServer? imagemode depending on GDALGetRasterDataType (MS_IMAGEMODE_BYTE for GDT_Byte, MS_IMAGEMODE_INT16 for GDT_Int16 and MS_IMAGEMODE_FLOAT32 for GDT_Float32). Create a text file (.maps) listing every mapfiles created for a MapServer? published output (or inputs) using saveMapNames function. Fixes in ulinet, use uuid for naming temporary files. Add dialect input to the ogr2ogr service. Use the .maps file for removing a file from the DeleteData? service

Location:
branches/prototype-v0/zoo-project
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/zoo-project/zoo-kernel/caching.c

    r860 r862  
    298298    if((tmp1=getMap(content->content,xname))!=NULL && tmap!=NULL && strcasecmp(tmap->value,sindex)==0){
    299299
    300       if(getMap(content->content,icname)==NULL){       
     300      if(getMap(content->content,icname)==NULL){
    301301        fcontent=(char*)malloc((hInternet->ihandle[*index].nDataLen+1)*sizeof(char));
    302302        if(fcontent == NULL){
     
    513513
    514514  map* tmpMap=getMapOrFill(content,"value","");
    515    
    516515  free(tmpMap->value);
    517516  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
  • branches/prototype-v0/zoo-project/zoo-kernel/response_print.c

    r860 r862  
    25622562      xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
    25632563      xmlAddChild(nc1,txt);
     2564      if(cnt==0)
     2565        setMapInMaps(m,"lenv","message",tmp->value);
    25642566    }
    25652567    else{
     
    27182720      toto=getMap(tmpI->content,"asReference");
    27192721#ifdef USE_MS
    2720     restartNoMS:
    27212722      map* geodatatype=getMap(tmpI->content,"geodatatype");
    2722      
    27232723      if(toto!=NULL && strcasecmp(toto->value,"true")==0 &&
    27242724         (testMap==NULL ||
     
    27492749            map *ext=getMap(tmpI->content,"extension");
    27502750            char file_ext[32];
    2751 
     2751           
    27522752            if( ext != NULL && ext->value != NULL) {
    27532753              strncpy(file_ext, ext->value, 32);
     
    28122812          }
    28132813          addToMap(tmpI->content,"Reference",file_url);
    2814           /*maps* curs=tmpI;
    2815           curs=curs->next;
    2816           map* test=getMap(tmpI->content,"replicateStorageNext");
    2817           if(test!=NULL && strncasecmp(test->value,"true",4)==0)
    2818             while(curs!=NULL){
    2819               addToMap(curs->content,"storage",file_path);
    2820               curs=curs->next;
    2821               }
    2822           if(file_path!=NULL)
    2823           free(file_path);*/
    28242814          if(file_name!=NULL)
    28252815            free(file_name);
     
    28302820#ifdef USE_MS
    28312821      else{
    2832         if(testMap!=NULL){
    2833           setMapInMaps(m,"lenv","state","out");
    2834           setReferenceUrl(m,tmpI);
    2835           geodatatype=getMap(tmpI->content,"geodatatype");
    2836           if(geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0)
    2837             goto restartNoMS;
    2838         }
    2839       }
     2822          if(testMap!=NULL){
     2823            setMapInMaps(m,"lenv","state","out");
     2824            setReferenceUrl(m,tmpI);
     2825            geodatatype=getMap(tmpI->content,"geodatatype");
     2826            if(geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0)
     2827              res=SERVICE_FAILED;
     2828          }
     2829        }
    28402830#endif
    28412831      if(file_name!=NULL){
  • branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c

    r858 r862  
    377377  struct stat file_status;
    378378  stat(filename, &file_status);
    379   map* tmpMap1=getMap(content,"value");
    380   if(tmpMap1==NULL){
    381     addToMap(content,"value","");
    382     tmpMap1=getMap(content,"value");
    383   }
    384   free(tmpMap1->value);
    385   tmpMap1->value=(char*) malloc((count+1)*sizeof(char)); 
    386   fread(tmpMap1->value,1,count,file);
    387   tmpMap1->value[count]=0;
     379  if(getMap(content,"storage")==NULL){
     380    map* tmpMap1=getMap(content,"value");
     381    if(tmpMap1==NULL){
     382      addToMap(content,"value","");
     383      tmpMap1=getMap(content,"value");
     384    }
     385    free(tmpMap1->value);
     386    tmpMap1->value=(char*) malloc((count+1)*sizeof(char));
     387    if(tmpMap1->value==NULL){
     388      setMapInMaps(m,"lenv","message","Unable to allocate the memory required to read the produced file.");
     389    }
     390    fread(tmpMap1->value,1,count,file);
     391    tmpMap1->value[count]=0;
     392  }
    388393  fclose(file);
    389394  char rsize[1000];
     
    423428void dumpMapsValuesToFiles(maps** main_conf,maps** in){
    424429  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
     430  map* tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl");
    425431  map* tmpSid=getMapFromMaps(*main_conf,"lenv","usid");
    426432  maps* inputs=*in;
     
    450456          setMapArray(cMap,"cache_file",k,val);
    451457          free(val);
     458          val=(char*)malloc((strlen(tmpUrl->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
     459          sprintf(val,"%s/Input_%s_%s_%d.%s",tmpUrl->value,inputs->name,tmpSid->value,k,file_ext);
     460          setMapArray(cMap,"cache_url",k,val);
     461          setMapArray(cMap,"byValue",k,"true");
     462          free(val);
    452463        }
    453464      }else{
     
    467478        addToMap(cMap,"cache_file",val);
    468479        free(val);
    469       }
    470       addToMap(inputs->content,"byValue","true");
     480        val=(char*)malloc((strlen(tmpUrl->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
     481        sprintf(val,"%s/Input_%s_%s_%d.%s",tmpUrl->value,inputs->name,tmpSid->value,0,file_ext);
     482        addToMap(cMap,"cache_url",val);
     483        addToMap(cMap,"byValue",val);
     484        free(val);
     485      }
    471486    }
    472487    inputs=inputs->next;
     
    641656        }
    642657        if(res==NULL){
     658          map* tmpMaxO0=getMap(tmpInputs->content,"useMapserver");
     659          if(tmpMaxO0!=NULL){
     660            if(tmpMaps2->content==NULL)
     661              tmpMaps2->content=createMap("useMapserver",tmpMaxO0->value);
     662            else
     663              addToMap(tmpMaps2->content,"useMapserver",tmpMaxO0->value);
     664          }
    643665          map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
    644666          if(tmpMaxO!=NULL){
     
    714736           * content map.
    715737           */
    716           map* tmpMap1=getMap(tmpInputs->content,"minOccurs");
    717           if(tmpMap1!=NULL){
    718             if(tmpMaps->content==NULL)
    719               tmpMaps->content=createMap("minOccurs",tmpMap1->value);
    720             else
    721               addToMap(tmpMaps->content,"minOccurs",tmpMap1->value);
    722           }
    723           map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
    724           if(tmpMaxO!=NULL){
    725             if(tmpMaps->content==NULL)
    726               tmpMaps->content=createMap("maxOccurs",tmpMaxO->value);
    727             else
    728               addToMap(tmpMaps->content,"maxOccurs",tmpMaxO->value);
    729           }
    730           map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
    731           if(tmpMaxMB!=NULL){
    732             if(tmpMaps->content==NULL)
    733               tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value);
    734             else
    735               addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value);
     738          char* keys[4]={
     739            "minOccurs",
     740            "maxOccurs",
     741            "maximumMegabytes",
     742            "useMapserver"
     743          };
     744          int i=0;
     745          for(i=0;i<4;i++){
     746            map* tmpMap1=getMap(tmpInputs->content,keys[i]);
     747            if(tmpMap1!=NULL){
     748              addToMap(tmpMaps->content,keys[i],tmpMap1->value);
     749            }
    736750          }
    737751          /**
     
    812826          if(tmpCheck!=NULL && strncasecmp(tmpCheck->value,"true",4)==0){
    813827            // Get the default value
     828            addToMap(tmpMaps->content,"useMapserver","true");
    814829            tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL);
    815830            tmpCheck=getMap(tmpMaps->content,"mimeType");
  • branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c

    r860 r862  
    112112  }
    113113
    114 
    115114  /**
    116115   * Practically invoke the callback, meaning sending the HTTP POST request.
     
    121120    local_params* arg=(local_params*)args;
    122121    HINTERNET hInternet,res1;
     122    const struct tm *tm;
     123    size_t len;
     124    time_t now;
     125    char *tmp1;
     126    map *tmpStatus;
    123127    hInternet=InternetOpen("ZooWPSClient\0",
    124128                           INTERNET_OPEN_TYPE_PRECONFIG,
     
    134138    free(URL);
    135139#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 );
    136144    fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS cStep %d %d\n",pthread_self(),__FILE__,__LINE__,cStep,isOngoing);
    137145    fprintf(stderr," * JSON: [%s] \n",jsonStr);
    138146    fprintf(stderr," * URL: %s/ \n\n",hInternet.waitingRequests[0]);
     147    fprintf(stderr," * DATE: %s/ \n\n",tmp1);
    139148    fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS\n",pthread_self(),__FILE__,__LINE__);
     149    free(tmp1);
    140150#endif
    141151    while( (arg->step!=7 || isOngoing>0) &&
     
    152162    }
    153163#endif
    154     const struct tm *tm;
    155     size_t len;
    156     time_t now;
    157     char *tmp1;
    158     map *tmpStatus;
    159164   
    160165    now = time ( NULL );
     
    184189#ifdef CALLBACK_DEBUG   
    185190    fprintf(stderr,"************************* From thread %d %s %d: REQUEST END (%s)\n\n",pthread_self(),__FILE__,__LINE__,tmp1);
    186 #endif   
     191#endif
    187192    free(tmp1);
    188193    char *tmp = (char *) malloc ((hInternet.ihandle[0].nDataLen + 1)
     
    206211    if(cStep==0 || cStep==6 || arg->state==1)
    207212      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);
    210219    for(i=0;i<7;i++){
    211220      fprintf(stderr,"%d) %d %d\n",i,steps[i][0],steps[i][1]);
     
    214223    fprintf(stderr,"************************* From thread %d %s %d\n\n",pthread_self(),__FILE__,__LINE__);
    215224    fflush(stderr);
     225    free(tmp1);
    216226#endif
    217227    steps[arg->step][arg->state]=true;
    218228    free(tmp);
    219     //free(args);
     229#ifdef CALLBACK_DEBUG
    220230    fprintf(stderr,"************************* From thread %d %s %d: EXIT\n\n",pthread_self(),__FILE__,__LINE__);
    221231    fflush(stderr);
     232#endif
    222233    pthread_exit(NULL);
    223234  }
     
    305316      // Update the execute request stored on disk at step 0,0 to modify the references used.
    306317      if(state==1){
    307         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    308         fflush(stderr);
    309318        maps* curs=inputs;
    310         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    311         fflush(stderr);
    312319        xmlInitParser();
    313         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    314         fflush(stderr);
    315320        map* xmlPath=getMapFromMaps(conf,"lenv","execute_file");
    316         dumpMap(xmlPath);
    317         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    318         fflush(stderr);
    319321        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");
    404327          }
    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);
    407404          curs=curs->next;
    408405        }
    409         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    410         fflush(stderr);
    411406        xmlCleanupParser();
    412         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    413         fflush(stderr);
    414407        FILE* f0=fopen(xmlPath->value,"rb");
    415408        if(f0!=NULL){
     
    423416          fcontent[flen]=0;
    424417          fclose(f0);
    425           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    426           fflush(stderr);
    427418          map *schema=getMapFromMaps(conf,"database","schema");
    428419          map* sid=getMapFromMaps(conf,"lenv","usid");
    429           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    430           fflush(stderr);
    431420          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);
    434421          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);
    437422          execSql(conf,1,req);
    438           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    439           fflush(stderr);
    440423          free(fcontent);
    441           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    442           fflush(stderr);
    443424          free(req);
    444           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    445           fflush(stderr);
    446425        }
    447426      }
     
    453432        {
    454433          "xlink:href",
    455           "ref"
     434          "ref_download_link"
    456435        },
    457436        {
     
    514493              setMapArray(curs->content,"storage",ii,tmpMap->value);
    515494            }
    516             fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    517             dumpMap(curs->content);
    518495            struct stat buf;
    519496            char timeStr[ 100 ] = "";
     
    553530        if(hasRef<0)
    554531          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        }
    557536        addIntToMap(curs->content,"published_id",0);
    558537        curs=curs->next;
     
    570549        if(length!=NULL){
    571550          json_object *res1=json_object_new_object();
    572           json_object *res3=json_object_new_array();
    573551          int limit=atoi(length->value);
    574552          int i=0;
     
    589567                json_object_object_add(res1,tmp0->value,res2);
    590568              }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);
    596573                  json_object_object_del(res1,tmp0->value);
    597574                  json_object_object_add(res1,tmp0->value,res3);
    598                 }
     575                }else
     576                  json_object_array_add(res4,res2);
    599577              }
    600578            }
    601579          }
    602           if(json_object_array_length(res3)==0)
    603             json_object_put(res3);
    604580          json_object_object_add(res,"inputs",res1);
    605581        }
    606         //json_object_object_add(res,"inputs",in);
    607582      }
    608583      break;
     
    631606    case 5: {
    632607      // Downloading process outputs from cluster
    633       //json_object* in=mapsToJson(outputs);
    634608      maps* curs=outputs;
    635609      dumpMaps(curs);
     
    708682            json_object *jsStr=json_object_new_string(sid->value);
    709683            json_object_object_add(res2,keys[i][1],jsStr);
    710             if(i==0)
     684            if(i==0){
    711685              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            }
    712697          }
    713698        }
     
    724709              int i0=0;
    725710              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]);
    730712                if(sid!=NULL){
    731713                  json_object *jsStr=json_object_new_string(sid->value);
     
    760742                  json_object *jsStr=json_object_new_string(sid->value);
    761743                  json_object_object_add(res3,keys[i0][1],jsStr);
    762                   //if(i0==0)
    763744                  hasRef0=1;
    764745                }
     
    858839    local_arguments[nbThreads]->step=step;
    859840    local_arguments[nbThreads]->state=state;
    860     //pthread_t p1;
    861841    if(myThreads==NULL)
    862842      myThreads=(pthread_t*)malloc((nbThreads+1)*sizeof(pthread_t));
     
    867847      return false;
    868848    }
    869     //free(argumentsA);
    870849    nbThreads++;
    871850    return true;
     
    878857    int i=0;
    879858    for(i=0;i<nbThreads;i++){
    880       fprintf(stderr,"%s %d %d \n",__FILE__,__LINE__,i);
    881       fflush(stderr);
    882859      pthread_join(myThreads[i],NULL);
    883860      free(local_arguments[i]);
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c

    r860 r862  
    6262    if(itn<ZOO_LOCK_MAX_RETRY){
    6363      itn++;
     64      fprintf(stderr,"(%d) Wait for write lock on %s, tried %d times (sleep) ... \n",getpid(),myLock->filename,itn);
     65      fflush(stderr);
    6466      sleep(5);
    6567      free(myLock->filename);
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c

    r860 r862  
    6060  while(cur!=NULL && cur->defaults!=NULL){
    6161    map* mimeType=getMap(cur->defaults->content,"mimeType");
    62     if(mimeType!=NULL){
     62    map* useMS=getMap(cur->defaults->content,"useMapserver");
     63    if(mimeType!=NULL && useMS!=NULL && strncasecmp(useMS->value,"true",4)==0){
    6364      int geo=isGeographic(mimeType->value);
    6465      if(geo>0){
     
    159160        free(tmp[0]);
    160161        //addToMap(cur->content,"internal","true");
    161       }
     162      }     
    162163    }
    163164    cur=cur->next;
     
    332333  int parameters_cnt=0;
    333334  while(input!=NULL && input->content!=NULL){
    334     if(getMaps(*real_outputs,input->name)==NULL){
     335    map* isInRequest=getMap(input->content,"inRequest");
     336    map* minNb=getMap(input->content,"minoccurs");
     337    if(getMaps(*real_outputs,input->name)==NULL &&
     338       ( (isInRequest!=NULL && strncasecmp(isInRequest->value,"true",4)==0)
     339         || (minNb!=NULL && atoi(minNb->value)>0) ) ){
    335340      parameters_cnt+=1;
    336341      if(parameters_cnt==1)
     
    345350          dumpMapsValuesToFiles(main_conf,&input);
    346351          addToMap(input->content,"toPublish","true");
    347           addToMap(input->content,"useMapserver","true");
     352          //addToMap(input->content,"useMapserver","true");
    348353        }
    349354        if(getMap(input->content,"cache_file")!=NULL){
     
    362367            setMapArray(input->content,"targetPath",i,targetPath);
    363368            setMapArray(input->content,"localPath",i,tmp->value);
    364             addToUploadQueue(main_conf,input);
     369            map* tmp1=getMapArray(input->content,"value",i);
     370            if(tmp1!=NULL){
     371              free(tmp1->value);
     372              tmp1->value=strdup("empty");
     373            }
    365374            if(i==0){
    366375              parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
    367376              sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath);
    368377            }else{
     378              fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     379              fflush(stderr);
    369380              char *tmpStr=zStrdup(parameters[parameters_cnt-1]);
    370381              parameters[parameters_cnt-1]=(char*)realloc(parameters[parameters_cnt-1],(strlen(tmpStr)+strlen(targetPath)+2)*sizeof(char));
    371382              sprintf(parameters[parameters_cnt-1],"%s %s",tmpStr,targetPath);
    372383              free(tmpStr);
     384              fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     385              fflush(stderr);
    373386            }
    374387            free(targetPath);
    375388          }
     389          addToUploadQueue(main_conf,input);
    376390        }else{
    377391          // ???
     
    396410#endif
    397411  invokeCallback(m,inputs,NULL,1,1);
     412  invokeCallback(m,inputs,NULL,2,0);
    398413  if(getMapFromMaps(m,"lenv","mapError")!=NULL){
    399     invokeCallback(m,inputs,NULL,7,0);
     414    invokeCallback(*main_conf,inputs,NULL,7,0);
    400415    return -1;
    401416  }
    402   invokeCallback(m,inputs,NULL,2,0);
    403417#ifdef HPC_DEBUG
    404418  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     
    408422  // Upload data on HPC
    409423  if(runUpload(main_conf)==false){
    410     errorException (m, _("Unable to lock the file for upload!"),
     424    errorException (*main_conf, _("Unable to lock the file for upload!"),
    411425                    "InternalError", NULL);
    412426#ifdef HPC_DEBUG
    413427    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    414428#endif
    415     invokeCallback(m,inputs,NULL,7,0);
     429    invokeCallback(*main_conf,inputs,NULL,7,0);
    416430#ifdef HPC_DEBUG
    417431    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     
    429443  // Add the filename to generate for every output to parameters
    430444  input=*real_outputs;
    431   // TODO: fix appendOutputParameters
    432   //appendOutputParameters(input,parameters,&parameters_cnt,s,uuid,targetPathMap);
    433445#ifdef HPC_DEBUG
    434446  dumpMaps(input);
    435447#endif
    436448  while(input!=NULL){
    437     // TODO: parse all outputs including inner outputs if required.
     449    // Parse all outputs including inner outputs if required.
    438450    if(input->child==NULL){
    439451      // Name every files that should be produced by the service execution
     
    453465      char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
    454466      sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
     467      map *tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl");
     468      char *targetUrl=(char*)malloc((strlen(tmpUrl->value)+strlen(targetName)+2)*sizeof(char));
     469      sprintf(targetUrl,"%s/%s",tmpUrl->value,targetName);
    455470      free(targetName);
    456471      setMapInMaps(*real_outputs,input->name,"generated_file",targetPath);
    457       if(strcasecmp(input->name,"wms_link")!=0&&
    458          strcasecmp(input->name,"wcs_link")!=0 &&
    459          strcasecmp(input->name,"wfs_link")!=0){
     472      addToMap(input->content,"generated_url",targetUrl);
     473      free(targetUrl);
     474      {
    460475        parameters_cnt+=1;
    461476        if(parameters_cnt==1)
     
    494509      char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
    495510      sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
     511      map *tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl");
     512      char *targetUrl=(char*)malloc((strlen(tmpUrl->value)+strlen(targetName)+2)*sizeof(char));
     513      sprintf(targetUrl,"%s/%s",tmpUrl->value,targetName);
    496514      free(targetName);
    497515      addToMap(input->content,"generated_file",targetPath);
    498516      addToMap(input->content,"storage",targetPath);
     517      addToMap(input->content,"generated_url",targetUrl);
     518      free(targetUrl);
    499519      if(strcasecmp(input->name,"wms_link")!=0&&
    500520         strcasecmp(input->name,"wcs_link")!=0 &&
     
    623643    setMapInMaps(*main_conf,"lenv","message",_("There is no remote_work_path defined in your section!"));
    624644    setMapInMaps(*main_conf,"lenv","status","failed");
    625     errorException (m, _("There is no remote_work_path defined in your section!"),
     645    errorException (*main_conf, _("There is no remote_work_path defined in your section!"),
    626646                    "InternalError", NULL);
    627647#ifdef HPC_DEBUG
     
    629649    fflush(stderr);
    630650#endif
    631     invokeCallback(m,NULL,NULL,7,0);
     651    invokeCallback(*main_conf,NULL,NULL,7,0);
    632652#ifdef HPC_DEBUG
    633653    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     
    645665  free(scriptPath);
    646666  if(copy0!=true){
    647     setMapInMaps(m,"lenv","message",_("Unable to upload the script"));
    648     invokeCallback(m,NULL,NULL,7,0);
    649     errorException(m,_("Unable to upload the script"),"NoApplicableCode",NULL);
     667    setMapInMaps(*main_conf,"lenv","message",_("Unable to upload the script"));
     668    invokeCallback(*main_conf,NULL,NULL,7,0);
     669    errorException(*main_conf,_("Unable to upload the script"),"NoApplicableCode",NULL);
    650670    return -1;
    651671  }
     
    688708    fflush(stderr);
    689709#endif
    690     invokeCallback(m,NULL,NULL,7,0);
     710    invokeCallback(*main_conf,NULL,NULL,7,0);
    691711#ifdef HPC_DEBUG
    692712    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     
    694714#endif
    695715    sprintf(tmpS, "Cannot execute the HPC ZOO-Service %s using %s: %s", s->name, configurationId, tmpPath->value);
    696     errorException(m,tmpS,"NoApplicableCode",NULL);
     716    errorException(*main_conf,tmpS,"NoApplicableCode",NULL);
    697717    free(command);
    698718    free(targetPath);
    699719    ssh_close(*main_conf);
    700720    removeReadLocks(main_conf);
    701     sleep(1);
    702721    return -1;
    703722  }
     
    728747  if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
    729748    perror("bind error");
    730     setMapInMaps(m,"lenv","message",_("Unable to bind socket!"));
    731     errorException (m, _("Unable to bind socket!"),
     749    setMapInMaps(*main_conf,"lenv","message",_("Unable to bind socket!"));
     750    errorException (*main_conf, _("Unable to bind socket!"),
    732751                    "InternalError", NULL);
    733752#ifdef HPC_DEBUG
     
    735754    fflush(stderr);
    736755#endif
    737     invokeCallback(m,NULL,NULL,7,0);
     756    invokeCallback(*main_conf,NULL,NULL,7,0);
    738757    removeReadLocks(main_conf);
    739758#ifdef HPC_DEBUG
     
    749768  if (listen(fd, 5) == -1) {
    750769    setMapInMaps(*main_conf,"lenv","message",_("Listen error"));
    751     errorException (m, _("Listen error"),
     770    errorException (*main_conf, _("Listen error"),
    752771                    "InternalError", NULL);
    753772#ifdef HPC_DEBUG
     
    755774    fflush(stderr);
    756775#endif
    757     invokeCallback(m,NULL,NULL,7,0);
     776    invokeCallback(*main_conf,NULL,NULL,7,0);
    758777    removeReadLocks(main_conf);
    759778#ifdef HPC_DEBUG
     
    765784  if ( (cl = accept(fd, NULL, NULL)) == -1) {
    766785    setMapInMaps(*main_conf,"lenv","message",_("Accept error"));
    767     errorException (m, _("Accept error"),
     786    errorException (*main_conf, _("Accept error"),
    768787                    "InternalError", NULL);
    769788#ifdef HPC_DEBUG
     
    771790    fflush(stderr);
    772791#endif
    773     invokeCallback(m,NULL,NULL,7,0);
     792    invokeCallback(*main_conf,NULL,NULL,7,0);
    774793    removeReadLocks(main_conf);
    775794#ifdef HPC_DEBUG
     
    788807    while ( (rc=read(cl,buf,10)) ) {     
    789808      if(rc==0){
    790         sleep(1);
    791809        setMapInMaps(*main_conf,"lenv","message",_("Read closed"));
    792         errorException (m, _("Read closed"),
     810        errorException (*main_conf, _("Read closed"),
    793811                        "InternalError", NULL);
    794812#ifdef HPC_DEBUG
     
    796814        fflush(stderr);
    797815#endif
    798         invokeCallback(m,NULL,NULL,7,0);
     816        invokeCallback(*main_conf,NULL,NULL,7,0);
    799817        removeReadLocks(main_conf);
    800818#ifdef HPC_DEBUG
     
    806824        if(rc<0){
    807825          setMapInMaps(*main_conf,"lenv","message",_("Read error"));
    808           errorException (m, _("Read error"),
     826          errorException (*main_conf, _("Read error"),
    809827                          "InternalError", NULL);
    810828#ifdef HPC_DEBUG
     
    812830          fflush(stderr);
    813831#endif
    814           invokeCallback(m,NULL,NULL,7,0);
     832          invokeCallback(*main_conf,NULL,NULL,7,0);
    815833          removeReadLocks(main_conf);
    816834#ifdef HPC_DEBUG
     
    872890                free(targetPath);
    873891              }else{
    874                 char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
    875                 sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
    876                 setMapInMaps(m,"lenv","message",tmpStr);
    877                 free(tmpStr);
    878                 invokeCallback(m,NULL,NULL,7,0);
     892                map* hpcStdErr=getMapFromMaps(*main_conf,"henv","StdErr");
     893                if(hpcStdErr!=NULL && ssh_fetch(*main_conf,targetPath,hpcStdErr->value,ssh_get_cnt(m))==0){
     894                  struct stat f_status;
     895                  int ts=stat(targetPath, &f_status);
     896                  if(ts==0) {
     897                    char* fcontent = NULL;
     898                    fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
     899                    FILE* f=fopen(targetPath,"rb");
     900                    fread(fcontent,f_status.st_size,1,f);
     901                    int fsize=f_status.st_size;
     902                    fcontent[fsize]=0;
     903                    fclose(f);
     904                    setMapInMaps(*main_conf,"lenv","message",fcontent);
     905                    free(fcontent);
     906                  }else{
     907                    char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
     908                    sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
     909                    setMapInMaps(*main_conf,"lenv","message",tmpStr);
     910                    free(tmpStr);
     911                  }
     912                }else{
     913                  char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
     914                  sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
     915                  setMapInMaps(*main_conf,"lenv","message",tmpStr);
     916                  free(tmpStr);
     917                }
     918                invokeCallback(*main_conf,NULL,NULL,7,0);
    879919                return SERVICE_FAILED;
    880920              }
     
    882922          }else{
    883923            map* generatedFile=getMap(input->content,"generated_file");
     924            map* generatedUrl=getMap(input->content,"generated_url");
    884925            if(generatedFile!=NULL){
    885926              char* filename=strrchr(generatedFile->value,'/');
     
    895936                maps* output=getMaps(*real_outputs,input->name);
    896937                setMapInMaps(output->child,"download_link","generated_file",targetPath);
     938                setMapInMaps(output->child,"download_link","generated_url",generatedUrl->value);
    897939                setMapInMaps(output->child,"download_link","storage",targetPath);
    898940                setMapInMaps(output->child,"download_link","useMapserver","false");
     
    908950                if(getMaps(output->child,"wcs_link")!=NULL){
    909951                  sprintf(serviceName,"wcs_link");
    910                   setMapInMaps(output->child,serviceName,"msOgc","WCS");
    911                   setMapInMaps(output->child,serviceName,"requestedMimeType","image/tiff");
    912                 }
    913                 else{
     952                  setMapInMaps(output->child,"wcs_link","msOgc","WCS");
     953                }else{
    914954                  sprintf(serviceName,"wfs_link");
    915                   setMapInMaps(output->child,serviceName,"msOgc","WFS");
    916                   setMapInMaps(output->child,serviceName,"requestedMimeType","text/xml");
    917                 }
     955                  setMapInMaps(output->child,"wfs_link","msOgc","WFS");
     956                }
    918957                setMapInMaps(output->child,serviceName,"storage",targetPath);
    919958                setMapInMaps(output->child,serviceName,"generated_file",targetPath);
     
    958997      }else{
    959998        // Try to access remotely to the log file and return a more relevant error message
    960         setMapInMaps(m,"lenv","message",_("HPC Execution failed!"));
    961         errorException (m, _("HPC Execution failed!"),
     999        setMapInMaps(*main_conf,"lenv","message",_("HPC Execution failed!"));
     1000        errorException (*main_conf, _("HPC Execution failed!"),
    9621001                        "InternalError", NULL);
    9631002#ifdef HPC_DEBUG
     
    9651004        fflush(stderr);
    9661005#endif
    967         invokeCallback(m,NULL,NULL,7,0);
     1006        invokeCallback(*main_conf,NULL,NULL,7,0);
    9681007#ifdef HPC_DEBUG
    9691008        fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     
    9711010#endif
    9721011      }
    973       //free(buf);
    9741012    }
    9751013    if(hasPassed<0){
    9761014      perror("Failed to read");
    9771015      setMapInMaps(*main_conf,"lenv","message",_("Unable to parse the value returned by remote execution"));
    978       errorException (m, _("Unable to parse the value returned by remote execution"),
     1016      errorException (*main_conf, _("Unable to parse the value returned by remote execution"),
    9791017                      "InternalError", NULL);
    9801018#ifdef HPC_DEBUG
     
    9821020      fflush(stderr);
    9831021#endif
    984       invokeCallback(m,NULL,NULL,7,0);
     1022      invokeCallback(*main_conf,NULL,NULL,7,0);
    9851023#ifdef HPC_DEBUG
    9861024      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c

    r860 r862  
    144144 */
    145145void setReferenceUrl(maps* m,maps* tmpI){
     146  int imyIndex=getPublishedId(tmpI);
     147  if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL)
     148    return;
     149  outputMapfile(m,tmpI);
    146150  map *msUrl=getMapFromMaps(m,"main","mapserverAddress");
    147151  if(msUrl==NULL){
     
    150154    exit(-1);
    151155  }
    152   int imyIndex=getPublishedId(tmpI);
    153156  if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL)
    154157    return;
    155   outputMapfile(m,tmpI);
    156158  int finalProto=-1;
    157159  map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion");
     
    165167  map* versionMap=getMapArray(tmpI->content,"msOgcVersion",imyIndex);
    166168  map* datatype=getMapArray(tmpI->content,"geodatatype",imyIndex);
     169  map* layerName=getMapArray(tmpI->content,"msLayer",imyIndex);
    167170  char options[4][5][25]={
    168171    {"WMS","1.3.0","GetMap","layers=%s","wms_extent"},
    169     {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"},
     172    {"WFS","1.0.0","GetFeature","typename=%s","wcs_extent"},
    170173    {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"},
    171     {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}
     174    {"WCS","1.0.0","GetCoverage","coverage=%s","wcs_extent"}
    172175  };
    173   if(datatype==NULL || strncmp(datatype->value,"other",5)==0){
     176  map *nbElements=getMapArray(tmpI->content,"nb_features",imyIndex);
     177  if(nbElements==NULL)
     178    nbElements=getMapArray(tmpI->content,"nb_pixels",imyIndex);
     179  if(datatype==NULL || strncmp(datatype->value,"other",5)==0 || (nbElements!=NULL && atoi(nbElements->value)==0)){
    174180    map* minNb=getMap(tmpI->content,"minoccurs");
    175     if(minNb==NULL || atoi(minNb->value)>=1){
     181    map* useMs=getMap(tmpI->content,"useMapserver");
     182    if((minNb==NULL || atoi(minNb->value)>=1) && useMs!=NULL && strncasecmp(useMs->value,"true",4)==0){
    176183      setMapInMaps(m,"lenv","mapError","true");
    177184      setMapInMaps(m,"lenv","locator",tmpI->name);
    178       setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
     185      if(nbElements==NULL)
     186        setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
     187      else
     188        setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not access any feature or pixel in te resulting file."));
    179189      if(getMapFromMaps(m,"lenv","state")==NULL)
    180190        errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name);
     
    229239  }
    230240  char layers[128];
    231   sprintf(layers,options[proto][3],tmpI->name);
    232 
     241  if(layerName==NULL)
     242    sprintf(layers,options[proto][3],tmpI->name);
     243  else
     244    sprintf(layers,options[proto][3],layerName->value);
     245 
    233246  if(format==NULL || width==NULL || height==NULL || extent==NULL){
    234247    char tmpStr[1024];
     
    525538  int imyIndex=getPublishedId(output);
    526539  msMapSetExtent(m,minX,minY,maxX,maxY);
     540  m->maxsize=4096;
    527541#ifdef DEBUGMS
    528542  fprintf(stderr,"Extent %.15f %.15f %.15f %.15f\n",minX,minY,maxX,maxY);
     
    743757     * Add a new layer set name, data
    744758     */
    745     if(msGrowMapLayers(m)==NULL){
    746       return -1;
    747     }
    748     if(initLayer((m->layers[m->numlayers]), m) == -1){
    749       return -1;
    750     }
    751 
    752     layerObj* myLayer=m->layers[m->numlayers];
     759    layerObj* myLayer=NULL;
     760    if(getMapArray(output->content,"msInclude",imyIndex)==NULL){
     761      if(msGrowMapLayers(m)==NULL){
     762        return -1;
     763      }
     764      if(initLayer((m->layers[m->numlayers]), m) == -1){
     765        return -1;
     766      }
     767      myLayer=m->layers[m->numlayers];
     768    }else{
     769      myLayer=m->layers[m->numlayers-1];
     770    }
     771   
    753772#ifdef DEBUGMS
    754773    dumpMaps(output);
     
    852871    else
    853872      msInsertHashTable(&(myLayer->metadata), "ows_title", "Default Title");
     873
     874    if(getMapArray(output->content,"msInclude",imyIndex)==NULL){
     875      if(msGrowLayerClasses(myLayer) == NULL)
     876        return -1;
     877      if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
     878        return -1;
     879      if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
     880        return -1;
     881      if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
     882        return -1;
     883      /**
     884       * Apply msStyle else fallback to the default style
     885       */
     886      tmpMap=getMap(output->content,"msStyle");
     887      if(tmpMap!=NULL)
     888        msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
     889      else{
     890        /**
     891         * Set style
     892         */
     893        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125;
     894        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125;
     895        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255;
     896        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80;
     897        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
     898        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
     899       
     900        /**
     901         * Set specific style depending on type
     902         */
     903        if(myLayer->type == MS_LAYER_POLYGON)
     904          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
     905        if(myLayer->type == MS_LAYER_LINE){
     906          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
     907          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5;
     908        }
     909        if(myLayer->type == MS_LAYER_POINT){
     910          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1;
     911          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
     912        }
     913       
     914      }
     915      myLayer->CLASS[myLayer->numclasses]->numstyles++;
     916      myLayer->numclasses++;
    854917   
    855     if(msGrowLayerClasses(myLayer) == NULL)
    856       return -1;
    857     if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
    858       return -1;
    859     if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
    860       return -1;
    861     if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
    862       return -1;
    863     /**
    864      * Apply msStyle else fallback to the default style
    865      */
    866     tmpMap=getMap(output->content,"msStyle");
    867     if(tmpMap!=NULL)
    868       msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
    869     else{
    870       /**
    871        * Set style
    872        */
    873       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125;
    874       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125;
    875       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255;
    876       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80;
    877       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
    878       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
    879      
    880       /**
    881        * Set specific style depending on type
    882        */
    883       if(myLayer->type == MS_LAYER_POLYGON)
    884         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
    885       if(myLayer->type == MS_LAYER_LINE){
    886         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
    887         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5;
    888       }
    889       if(myLayer->type == MS_LAYER_POINT){
    890         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1;
    891         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
    892       }
    893      
    894     }
    895     myLayer->CLASS[myLayer->numclasses]->numstyles++;
    896     myLayer->numclasses++;
    897    
    898     m->layerorder[m->numlayers] = m->numlayers;
    899     m->numlayers++;
    900 
    901   }
    902 
     918      m->layerorder[m->numlayers] = m->numlayers;
     919      m->numlayers++;
     920
     921    }
     922  }
    903923  OGR_DS_Destroy(poDS);
    904924  //OGRCleanupAll();
     
    9821002  m->width=GDALGetRasterXSize( hDataset );
    9831003  m->height=GDALGetRasterYSize( hDataset );
     1004  if(m->width>4096 || m->height>4096){
     1005    if(m->width>m->height)
     1006      m->maxsize=m->width;
     1007    else 
     1008      m->maxsize=m->height;
     1009  }else
     1010    m->maxsize=4096;
    9841011  addIntToMapArray(output->content,"nb_pixels",imyIndex,GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset ));
    985  
     1012  int pixel_type=GDALGetRasterDataType( hDataset );
     1013  addIntToMapArray(output->content,"pixel_data_type",imyIndex,pixel_type);
     1014
     1015  int outputIndex=msGetOutputFormatIndex(m,"tiff");
     1016  if(outputIndex>=0){
     1017    m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE)));
     1018    outputIndex=msGetOutputFormatIndex(m,"geotiff");
     1019    m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE)));   
     1020  }
     1021  //
     1022   
    9861023  /**
    9871024   * Set projection using Authority Code and Name if available or fallback to
     
    12411278   * Create an empty map, set name, default size and extent
    12421279   */
    1243   mapObj *myMap=msNewMapObj();
     1280  map* mapfileTemplate=getMapArray(outputs->content,"msInclude",imyIndex);
     1281  mapObj *myMap=NULL;
     1282  if(mapfileTemplate==NULL){
     1283    myMap=msNewMapObj();
     1284  }
     1285  else{
     1286    map* dataPath=getMapFromMaps(conf,"main","dataPath");
     1287    map* sid=getMapFromMaps(conf,"lenv","sid");
     1288    char *mapfileTemplatePath=(char*)malloc(((strlen(dataPath->value)+strlen(sid->value)+strlen(outputs->name)+10)*sizeof(char)));
     1289    sprintf(mapfileTemplatePath,"%s/%s_%s.map",dataPath->value,outputs->name,sid->value);
     1290    myMap=msLoadMap(mapfileTemplate->value,mapfileTemplatePath);
     1291    if(myMap==NULL){
     1292      setMapInMaps(conf,"lenv","message",_("Unable to open your template mapfile!"));
     1293      return ;
     1294    }
     1295  }
    12441296  free(myMap->name);
    12451297  myMap->name=zStrdup("ZOO-Project_WXS_Server");
     
    12811333    fprintf(stderr,"Unable to initialize GDAL driver !\n");
    12821334  else{
    1283     o3->imagemode=MS_IMAGEMODE_BYTE;
     1335    o3->imagemode=MS_IMAGEMODE_INT16;
    12841336    o3->inmapfile=MS_TRUE; 
    12851337    msAppendOutputFormat(myMap,msCloneOutputFormat(o3));
     
    12911343    fprintf(stderr,"Unable to initialize GDAL driver !\n");
    12921344  else{
    1293     o4->imagemode=MS_IMAGEMODE_INT16;
     1345    o4->imagemode=MS_IMAGEMODE_BYTE;
    12941346    o4->inmapfile=MS_TRUE; 
    12951347    msAppendOutputFormat(myMap,msCloneOutputFormat(o4));
     
    13101362#endif
    13111363
     1364 
    13121365  outputFormatObj *o6=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","geotiff");
    13131366  if(!o6)
     
    13211374  }
    13221375
     1376 
    13231377  /*
    13241378   * Set default projection to EPSG:4326
     
    14081462  sprintf(mapPath,"%s/%s_%d_%s.map",tmp1->value,outputs->name,imyIndex,sid->value);
    14091463  msSaveMap(myMap,mapPath);
     1464  saveMapNames(conf,outputs,mapPath);
    14101465  free(mapPath);
     1466  //free(myMap->symbolset.filename);
    14111467  //msFreeSymbolSet(&myMap->symbolset);
    14121468  msFreeMap(myMap);
     
    14151471}
    14161472
     1473/**
     1474 * Save the map fullpath in a text file (.maps)
     1475 * @param conf the main configuration map pointer
     1476 * @param output the current output for which a mapfile has been generated
     1477 * @param mapfile the mapfile saved to store in the text file
     1478 */
     1479void saveMapNames(maps* conf,maps* output,char* mapfile){
     1480  map* storage=getMap(output->content,"storage");
     1481  char *tmp=zStrdup(storage->value);
     1482  tmp[strlen(tmp)-strlen(strrchr(tmp,'.'))]=0;
     1483  char* mapName=(char*)malloc((strlen(tmp)+6)*sizeof(char*));
     1484  sprintf(mapName,"%s.maps",tmp);
     1485  FILE* myMaps=fopen(mapName,"a");
     1486  if(myMaps!=NULL){
     1487    fprintf(myMaps,"%s\n",mapfile);
     1488    fclose(myMaps);
     1489  }
     1490}
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.h

    r586 r862  
    5555  int tryGdal(maps* conf,maps* output,mapObj* m);
    5656  void outputMapfile(maps* conf,maps* outputs);
     57  void saveMapNames(maps*,maps*,char*);
     58
    5759#ifdef __cplusplus
    5860}
  • branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c

    r860 r862  
    205205    return NULL;
    206206
    207   libssh2_session_set_blocking(result->session, 0);
     207  libssh2_session_set_blocking(result->session, 1);
    208208
    209209  while ((rc = libssh2_session_handshake(result->session, result->sock_id))
     
    418418 */
    419419int ssh_fetch(maps* conf,const char* localPath,const char* targetPath,int cnt){
    420   char mem[1024];
    421420  size_t nread;
    422421  size_t memuse=0;
     
    436435    if (!sessions[cnt]->sftp_session &&
    437436        (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN)) {
    438      
    439437      fprintf(stderr, "Unable to init SFTP session\n");
    440438      return -1;
     
    452450      }
    453451      else {
    454         //non-blocking open
    455452        waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
    456453      }
    457454    }
     455    if(!sftp_handle)
     456      zSleep(100);
    458457  } while (!sftp_handle);
    459458 
     
    461460  do {
    462461    do {
    463       rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
    464       /*fprintf(stderr, "libssh2_sftp_read returned %d\n",
    465         rc);*/
     462      char* mem=(char*)malloc(16*1024*1024);
     463      rc = libssh2_sftp_read(sftp_handle, mem,16*1024*1024);
    466464      if(rc > 0) {
    467         //write(2, mem, rc);
    468465        fwrite(mem, rc, 1, local);
    469466      }
     467      free(mem);
    470468    } while (rc > 0);
    471469   
     
    585583 */
    586584bool ssh_close_session(maps* conf,SSHCON* con){
     585  if(con==NULL)
     586    return true;
    587587  while (libssh2_session_disconnect(con->session, "Normal Shutdown, Thank you for using the ZOO-Project sshapi")
    588588         == LIBSSH2_ERROR_EAGAIN);
     
    593593#endif
    594594  libssh2_session_free(con->session);
     595  con=NULL;
    595596  return true;
    596597}
     
    639640                     getMapArray(input->content,"targetPath",i)};
    640641
    641         setMapArray(queueMaps->content,"input",queueIndex,input->name);
    642         setMapArray(queueMaps->content,"localPath",queueIndex,tmp[0]->value);
    643         setMapArray(queueMaps->content,"targetPath",queueIndex,tmp[1]->value);
    644         queueIndex+=1;
     642        setMapArray(queueMaps->content,"input",queueIndex+i,input->name);
     643        setMapArray(queueMaps->content,"localPath",queueIndex+i,tmp[0]->value);
     644        setMapArray(queueMaps->content,"targetPath",queueIndex+i,tmp[1]->value);
     645
    645646      }
    646647    }
    647648  }
    648 #ifdef SSH_DEBUG 
    649   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    650   fflush(stderr);
    651   dumpMaps(queueMaps);
    652   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    653   fflush(stderr);
    654   dumpMaps(*conf);
    655   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    656   fflush(stderr);
    657 #endif
    658649  return true;
    659650}
     
    664655    return false;
    665656  }
    666 #ifdef SSH_DEBUG
    667   fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__);
    668   fflush(stderr);
    669   dumpMaps(getMaps(*conf,"uploadQueue"));
    670   fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__);
    671   fflush(stderr);
    672 #endif
    673657  map* queueLengthMap=getMapFromMaps(*conf,"uploadQueue","length");
    674658  maps* queueMaps=getMaps(*conf,"uploadQueue");
     
    682666        getMapArray(queueMaps->content,"targetPath",i)
    683667      };
    684 #ifdef SSH_DEBUG     
    685       fprintf(stderr,"*** %s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value);
    686 #endif     
    687668      /**/zooLock* lck;
    688669      if((lck=lockFile(*conf,argv[1]->value,'w'))!=NULL){/**/
     
    703684    }   
    704685  }
     686  while (libssh2_session_disconnect(test->session, "Normal Shutdown, Thank you for using the ZOO-Project sshapi")
     687         == LIBSSH2_ERROR_EAGAIN);
     688#ifdef WIN32
     689  closesocket(test->sock_id);
     690#else
     691  close(test->sock_id);
     692#endif
     693  libssh2_session_free(test->session);
     694  free(test);
     695  test=NULL;
     696  sessions[ssh_get_cnt(*conf)-1]=NULL;
     697  maps* tmp=getMaps(*conf,"lenv");
     698  addIntToMap(tmp->content,"nb_sessions",ssh_get_cnt(*conf)-1); 
     699
    705700  return true;
    706701}
  • branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c

    r860 r862  
    2929#define MAX_WAIT_MSECS 180*1000 /* Wait max. 180 seconds */
    3030#include "ulinet.h"
     31#include "server_internal.h"
    3132#include <assert.h>
    3233#include <ctype.h>
     
    6768  return realsize;
    6869}
     70
     71/**
     72 * Write the downloaded content to a _HINTERNET structure
     73 *
     74 * @param buffer the buffer to read
     75 * @param size size of each member
     76 * @param nmemb number of element to read
     77 * @param data the _HINTERNET structure to write in
     78 * @return the size red, -1 if buffer is NULL
     79 */
     80size_t write_data_into_file(void *buffer, size_t size, size_t nmemb, void *data)
     81{
     82   size_t realsize = size * nmemb;
     83   int writen=0;
     84   _HINTERNET *psInternet;
     85   if(buffer==NULL){
     86     buffer=NULL;
     87     return -1;
     88   }
     89   psInternet=(_HINTERNET *)data;
     90   writen+=fwrite(buffer, size, nmemb, psInternet->file);
     91   if(psInternet->nDataLen>0){
     92     psInternet->nDataAlloc+=psInternet->nDataLen+writen+1;
     93     psInternet->nDataLen += realsize;
     94   }else
     95     psInternet->nDataLen=realsize+1;
     96   buffer=NULL;
     97   return realsize;
     98}
     99
    69100
    70101/**
     
    363394        fclose(handle.file);
    364395        unlink(handle.filename);
     396        free(handle.filename);
    365397      }
    366398      else{
     
    411443 * @param dwFlags desired download mode (INTERNET_FLAG_NO_CACHE_WRITE for not using cache file)
    412444 * @param dwContext not used
     445 * @return the updated HINTERNET
    413446 */
    414447HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext){
     
    447480  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_VERBOSE, 1);
    448481#endif
    449 
    450482     
    451483  switch(dwFlags)
    452484    {
    453485    case INTERNET_FLAG_NO_CACHE_WRITE:
    454       hInternet->ihandle[hInternet->nb].hasCacheFile=-1;
    455486      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEFUNCTION, write_data_into);
    456487      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEDATA, (void*)&hInternet->ihandle[hInternet->nb]);
     488      hInternet->ihandle[hInternet->nb].hasCacheFile=-1;
    457489      break;
    458490    default:
    459       sprintf(hInternet->ihandle[hInternet->nb].filename,"/tmp/ZOO_Cache%d",(int)time(NULL));
    460       hInternet->ihandle[hInternet->nb].filename[24]=0;
    461 #ifdef MSG_LAF_VERBOSE
    462       fprintf(stderr,"file=%s",hInternet->ihandle[hInternet->nb].filename);
    463 #endif
    464       hInternet->ihandle[hInternet->nb].filename=filename;
     491      memset(filename,0,255);
     492      char* tmpUuid=get_uuid();
     493      sprintf(filename,"/tmp/ZOO_Cache%s", tmpUuid);
     494      free(tmpUuid);
     495      hInternet->ihandle[hInternet->nb].filename=strdup(filename);
    465496      hInternet->ihandle[hInternet->nb].file=fopen(hInternet->ihandle[hInternet->nb].filename,"w+");
    466    
    467497      hInternet->ihandle[hInternet->nb].hasCacheFile=1;
    468       curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEFUNCTION, NULL);
    469       curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEDATA, hInternet->ihandle[hInternet->nb].file);
    470       hInternet->ihandle[hInternet->nb].nDataLen=0;
     498      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEFUNCTION, write_data_into_file);
     499      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEDATA, (void*)&hInternet->ihandle[hInternet->nb]);
    471500      break;
    472501    }
     
    514543 */
    515544int processDownloads(HINTERNET* hInternet){
    516   int still_running=0;
     545  int still_running=0,numfds;
    517546  int msgs_left=0;
    518547  int i=0;
    519548  do{
    520     if(curl_multi_perform(hInternet->handle, &still_running)==CURLM_OK)
    521       if(still_running){
    522         zSleep(10);
    523       }
     549    CURLMcode mc;
     550    mc = curl_multi_perform(hInternet->handle, &still_running);
     551    if(mc==CURLM_OK){
     552      mc = curl_multi_wait(hInternet->handle, NULL, 0, 1000, &numfds);
     553    }
     554    if(mc != CURLM_OK) {
     555      fprintf(stderr, "curl_multi failed, code %d.n", mc);
     556      break;
     557    }
    524558  }while(still_running); 
    525559  for(i=0;i<hInternet->nb;i++){
     
    565599    fseek (hInternet.file , 0 , SEEK_END);
    566600    dwDataSize=ftell(hInternet.file); //taille du ficher
    567     rewind (hInternet.file);
     601    //dwDataSize=hInternet.nDataLen;
     602    //rewind (hInternet.file);
     603    fseek(hInternet.file, 0, SEEK_SET);
    568604  }
    569605  else{
     
    575611  }
    576612
    577   if( dwNumberOfBytesToRead /* buffer size */ < dwDataSize )
     613  if( dwNumberOfBytesToRead /* buffer size */ < dwDataSize ){
    578614    return 0;
     615  }
    579616
    580617#ifdef MSG_LAF_VERBOSE
    581   printf("\nfile size : %dko\n",dwDataSize/1024);
     618  fprintf(stderr,"\nfile size : %dko\n",dwDataSize/1024);
    582619#endif
    583620
    584621  if(hInternet.hasCacheFile>0){
    585     *lpdwNumberOfBytesRead = fread(lpBuffer,1,dwDataSize,hInternet.file);
     622    int freadRes = fread(lpBuffer,dwDataSize+1,1,hInternet.file);
     623    *lpdwNumberOfBytesRead = hInternet.nDataLen;
    586624  }
    587625  else{
  • branches/prototype-v0/zoo-project/zoo-kernel/zoo_loader.c

    r861 r862  
    6464#define FALSE -1
    6565#endif
     66
     67int cgiInit(){
     68  fprintf(FCGI_stderr,"ZOO-Kernel initialization %s %d ... \n",__FILE__,__LINE__);
     69  fflush(FCGI_stderr);
     70}
    6671
    6772/**
  • branches/prototype-v0/zoo-project/zoo-services/cgal/Makefile

    r779 r862  
    11ZRPATH=../..
    22include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
    3 CFLAGS=-I${INST_INCLUDE} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} ${CGAL_CFLAGS} -frounding-math -fPIC -DLINUX_FREE_ISSUE #-DDEBUG
     3CFLAGS= ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} ${CGAL_CFLAGS} -frounding-math -fPIC -DLINUX_FREE_ISSUE #-DDEBUG
    44CC=gcc
    55
     
    77        g++ ${CFLAGS} -c ./delaunay.c
    88        g++ ${CFLAGS} -c ./voronoi.c
    9         g++ ${CFLAGS} -shared -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${MACOS_LD_FLAGS} ${CGAL_LDFLAGS} -lCGAL -lgmp ${GDAL_LIBS} -L${ZRPATH}/zoo-kernel/ -lzoo_service
     9        g++ ${CFLAGS} -shared -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${CGAL_LDFLAGS} -lCGAL -lgmp ${GDAL_LIBS} -L${ZRPATH}/zoo-kernel/ -lzoo_service -lfcgi
    1010
    1111cgal_service.o: cgal_service.c cgal_service.h
  • branches/prototype-v0/zoo-project/zoo-services/cgal/cgal_service.c

    r775 r862  
    2424#include "cgal_service.h"
    2525
    26 int parseInput(maps* conf,maps* inputs, std::vector<Point>* points,char* filename){
     26int parseInput(maps* conf,maps* inputs, std::vector<Pointz>* points,char* filename){
    2727  map* tmpm=NULL;
    2828  tmpm=getMapFromMaps(inputs,"InputPoints","value");
     
    8787          break;
    8888        if(poFeature->GetGeometryRef() != NULL){
    89           points->push_back(Point(OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0)));
     89          points->push_back(Pointz(OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0)));
    9090        }
    9191      }
  • branches/prototype-v0/zoo-project/zoo-services/cgal/cgal_service.h

    r469 r862  
    3838
    3939typedef CGAL::Exact_predicates_inexact_constructions_kernel            Kernel;
    40 typedef Kernel::Point_2                                                Point;
     40typedef Kernel::Point_2                                                Pointz;
    4141
    42 int parseInput(maps*,maps*, std::vector<Point>*,char*);
     42int parseInput(maps*,maps*, std::vector<Pointz>*,char*);
    4343
    4444#endif
  • branches/prototype-v0/zoo-project/zoo-services/cgal/cgi-env/Voronoi.zcfg

    r536 r862  
    4646    </Default>
    4747    <Supported>
     48      mimeType = image/png
     49      useMapserver = true
     50      asReference = true
     51      msStyle = STYLE COLOR 125 0 105 OUTLINECOLOR 0 0 0 WIDTH 0.3 OPACITY 65 END
     52    </Supported>
     53    <Supported>
    4854     mimeType = text/xml
    4955     encoding = base64
  • branches/prototype-v0/zoo-project/zoo-services/cgal/delaunay.c

    r775 r862  
    4040    OGRRegisterAll();
    4141
    42     std::vector<Point> points;
     42    std::vector<Pointz> points;
    4343    if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED)
    4444      return res;
  • branches/prototype-v0/zoo-project/zoo-services/cgal/voronoi.c

    r775 r862  
    2424
    2525#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
    26 #include <CGAL/Triangulation_euclidean_traits_xy_3.h>
     26//#include <CGAL/Triangulation_euclidean_traits_2.h>
    2727#include <CGAL/Delaunay_triangulation_2.h>
    28 #include <CGAL/Constrained_Delaunay_triangulation_2.h>
     28//#include <CGAL/Constrained_Delaunay_triangulation_2.h>
    2929#include <CGAL/Triangulation_conformer_2.h>
    3030#include <CGAL/Triangulation_face_base_2.h>
     
    3939
    4040typedef CGAL::Delaunay_triangulation_2<Kernel>  Triangulation;
     41typedef Triangulation::Face_iterator  Face_iterator;
    4142typedef Triangulation::Edge_iterator  Edge_iterator;
    4243typedef Triangulation::Vertex_circulator Vertex_circulator;
     
    4546
    4647  int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){
    47 #ifdef DEBUG
     48    //#ifdef DEBUG
    4849    fprintf(stderr,"\nService internal print\nStarting\n");
    49 #endif
     50    //#endif
     51    //return SERVICE_FAILED;
    5052    maps* cursor=inputs;
    5153    OGRGeometryH geometry,res;
     
    5456    tmpm=getMapFromMaps(inputs,"InputPoints","value");
    5557
     58    fprintf(stderr," **** %s %d\n",__FILE__,__LINE__);
     59    fflush(stderr);
     60
    5661    OGRRegisterAll();
    5762
    58     std::vector<Point> points;
    59     if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED)
    60       return res;
     63    std::vector<Pointz> points;
     64    if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED){
     65      fprintf(stderr," **** %s %d\n",__FILE__,__LINE__);
     66      fflush(stderr);
     67      return SERVICE_FAILED;
     68    }
     69    fprintf(stderr," **** %s %d\n",__FILE__,__LINE__);
     70    fflush(stderr);
    6171   
    6272    Triangulation T;
    6373    T.insert(points.begin(), points.end());
    6474
    65     OGRRegisterAll();
     75    //OGRRegisterAll();
    6676    /* -------------------------------------------------------------------- */
    6777    /*      Try opening the output datasource as an existing, writable      */
     
    191201      CGAL::Object o = T.dual(eit);
    192202      if (const Kernel::Segment_2 *tmp=CGAL::object_cast<Kernel::Segment_2>(&o)) {
    193         const Point p1=tmp->source();
    194         const Point p2=tmp->target();
     203        const Pointz p1=tmp->source();
     204        const Pointz p2=tmp->target();
    195205#ifdef DEBUG
    196206        fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y());
     
    210220      }
    211221      else if (const Kernel::Ray_2 *tmp=CGAL::object_cast<Kernel::Ray_2>(&o)) {
    212         const Point p1=tmp->source();
    213         const Point p2=tmp->point(2);
     222        const Pointz p1=tmp->source();
     223        const Pointz p2=tmp->point(2);
    214224        OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) );
    215225        OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString);
     
    250260    fprintf(stderr,"\nService internal print\n===\n");
    251261#endif
    252     OGRCleanupAll();
     262    //OGRCleanupAll();
    253263    return SERVICE_SUCCEEDED;
    254264  }
  • branches/prototype-v0/zoo-project/zoo-services/ogr/ogr2ogr/service.c

    r790 r862  
    9696#endif
    9797{
     98    const char  *pszDialect = NULL;
    9899    const char  *pszFormat = "ESRI Shapefile";
    99100    const char  *pszDataSource = NULL;
     
    155156      sprintf(serverAddress,"%s",tmpMap->value);
    156157    }
    157    
     158
    158159    tmpMap=NULL;
    159160    char tmpurl[1024];
     
    223224    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    224225      pszSQLStatement = tmpMap->value;
     226    }
     227
     228    tmpMap=getMapFromMaps(inputs,"dialect","value");
     229    if(tmpMap!=NULL){
     230      pszDialect=strdup(tmpMap->value);
    225231    }
    226232
     
    367373    }*/
    368374
     375   
    369376    tmpMap=NULL;
    370377    tmpMap=getMapFromMaps(inputs,"InputDSN","value");
     
    825832       
    826833        poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter,
    827                                         NULL );
     834                                        pszDialect );
    828835
    829836        if( poResultSet != NULL )
     
    841848            }
    842849            poDS->ReleaseResultSet( poResultSet );
    843         }
    844     }
     850        }else{
     851          setMapInMaps(conf,"lenv","message","There was an error when running yoru SQL query.");
     852          if(pszDialect!=NULL)
     853            free(pszDialect);
     854          return SERVICE_FAILED;
     855        }
     856    }
     857    if(pszDialect!=NULL)
     858      free(pszDialect);
    845859
    846860/* -------------------------------------------------------------------- */
     
    901915
    902916#ifdef ZOO_SERVICE
    903     outputs->content=createMap("value",(char*)pszwebDestData);
     917    setMapInMaps(outputs,"OutputedDataSourceName","value",(char*)pszwebDestData);
     918    //outputs->content=createMap("value",(char*)pszwebDestData);
    904919#endif
    905920
     
    930945    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    931946
    932     OGRCleanupAll();
     947    //OGRCleanupAll();
    933948    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    934949
     
    939954   
    940955#ifdef ZOO_SERVICE
     956    //sleep(10);
    941957    return SERVICE_SUCCEEDED;
    942958#else
  • branches/prototype-v0/zoo-project/zoo-services/utils/hpc/service.c

    r854 r862  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright 2008-2009 GeoLabs SARL. All rights reserved.
     4 * Copyright 2017 GeoLabs SARL. All rights reserved.
    55 *
    66 * This work was supported by public funds received in the framework of GEOSUD,
  • branches/prototype-v0/zoo-project/zoo-services/utils/hpc/service2.c

    r854 r862  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright 2008-2009 GeoLabs SARL. All rights reserved.
    5  *
     4 * Copyright 2017 GeoLabs SARL. All rights reserved.
     5 *
     6 * This work was supported by public funds received in the framework of GEOSUD,
     7 * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
     8 * by the French National Research Agency
     9 *
    610 * This work was supported by public funds received in the framework of GEOSUD,
    711 * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
     
    4246
    4347#include <dirent.h>
     48#include <string.h>
     49#include <cerrno>
     50
    4451extern "C" {
     52
     53  /**
     54   * Retrieve the error message which occured when trying to remove a file
     55   * (return values can be EACCES, EBUSY, EFAULT, EIO, EISDIR, ELOOP,
     56   * ENAMETOOLONG, ENOENT, ENOMEM, ENOTDIR, EPERM, EROFS, UNKNOWN).
     57   *
     58   * @param errn
     59   * @result a string corresponding to the error number
     60   */
     61  char* fetchErrno(int errn){
     62   switch(errn){
     63    case EACCES:
     64        return "EACCES";
     65    case EBUSY:
     66        return "EBUSY";
     67    case EFAULT:
     68        return "EFAULT";
     69    case EIO:
     70        return "EIO";
     71    case EISDIR:
     72        return "EISDIR";
     73    case ELOOP:
     74        return "ELOOP";
     75    case ENAMETOOLONG:
     76        return "ENAMETOOLONG";
     77    case ENOENT:
     78        return "ENOENT";
     79    case ENOMEM:
     80        return "ENOMEM";
     81    case ENOTDIR:
     82        return "ENOTDIR";
     83    case EPERM:
     84        return "EPERM";
     85    case EROFS:
     86        return "EROFS";
     87    default:
     88        return "UNKNOWN";
     89   }
     90  }
    4591
    4692  /**
     
    78124   */
    79125  int tryDeleteDataFile(const char* storage,const char* filename){
    80     char* fullpath=(char*)malloc((strlen(storage)+strlen(filename)+2)*sizeof(char));
    81     sprintf(fullpath,"%s/%s",storage,filename);
     126    char* fullpath=NULL;
     127    if(filename!=NULL){
     128      fullpath=(char*)malloc((strlen(storage)+strlen(filename)+2)*sizeof(char));
     129      sprintf(fullpath,"%s/%s",storage,filename);
     130    }
     131    else
     132      fullpath=zStrdup(storage);
    82133    if(unlink(fullpath)==0){
    83134      // TODO store the filename_full in the deletedfiles
    84       fprintf(stderr,"#### DeleteData #### %s %d %s has been successfully deleted\n",__FILE__,__LINE__,filename);
     135      fprintf(stderr,"#### DeleteData #### %s %d %s has been successfully deleted\n",__FILE__,__LINE__,(strlen(filename)>0?filename:fullpath));
    85136    }else{
    86       fprintf(stderr,"#### DeleteData #### unable to delete %s \n",fullpath);
     137      fprintf(stderr,"#### DeleteData #### unable to delete %s %s \n",fullpath,fetchErrno(errno));
    87138    }
    88139    free(fullpath);
     
    138189        }
    139190        if(fcontent!=NULL && strcasecmp(fcontent,"SHARED")!=0){
    140           // Delete associated zcm and zcp
     191          // Delete associated zcm, zcp and maps files
    141192          tryDeleteCacheFile(cacheDir->value,filename->value,"zca");
    142193          tryDeleteCacheFile(cacheDir->value,filename->value,"zcm");
    143194          tryDeleteCacheFile(cacheDir->value,filename->value,"zcp");
    144           // Delete ZOO_DATA_<input>_<sid>.data and <input>_<sid>.map
     195          tryDeleteCacheFile(tmpPath->value,filename->value,"maps");
     196          // Delete <input>_<sid>.map
    145197          char* datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
    146           sprintf(datafile,"ZOO_DATA_%s_%s.data",ioname->value,jobid->value);
    147           tryDeleteDataFile(dataPath->value,datafile);
    148           free(datafile);
    149           datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
    150198          sprintf(datafile,"%s_%s.map",ioname->value,jobid->value);
    151199          tryDeleteDataFile(dataPath->value,datafile);
     
    160208        char tmp1[8];
    161209        snprintf(tmp1,7,"%s",filename->value);
    162         if(strcasecmp(tmp1,"output")==0){
    163           tryDeleteDataFile(tmpPath->value,filename->value);
     210        if(strcasecmp(tmp1,"output")==0 || strcasecmp(tmp1,"input_")==0){
     211          trydeletedatafile(tmppath->value,filename->value);
     212          char *tmp=zStrdup(filename->value);
     213          tmp[strlen(tmp)-strlen(strrchr(tmp,'.'))]=0;
     214          char *mapsfile=(char*)malloc((strlen(tmp)+6)*sizeof(char));
     215          sprintf(mapsfile,"%s.maps",tmp);
     216          char* mapPath=(char*)malloc((strlen(tmpPath->value)+strlen(mapsfile)+2)*sizeof(char));
     217          sprintf(mapPath,"%s/%s",tmpPath->value,mapsfile);
     218          FILE* myMapsfile=fopen(mapPath,"r");
     219          if(myMapsfile!=NULL){
     220            char *buffer=(char*)malloc(1024*sizeof(char));
     221            while(fgets(buffer, 1024, myMapsfile) != NULL){
     222              buffer[strlen(buffer)-1]=0;
     223              tryDeleteDataFile(buffer,NULL);
     224            }
     225            free(buffer);
     226            fclose(myMapsfile);
     227          }
     228          tryDeleteDataFile(mapPath,NULL);
     229          free(mapPath);
     230          free(mapsfile);
    164231          // Delete ZOO_DATA_<output>_<sid>.data and <output>_<sid>.map
    165232          char* datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
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