Changeset 469


Ignore:
Timestamp:
May 1, 2014, 1:28:14 AM (10 years ago)
Author:
djay
Message:

Support metapath embedded in service name. Add support for accessing ZOO-Kernel path subdirectories for full list of available services. Fix issue #98.

Location:
trunk
Files:
3 added
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/docs/services/zcfg-reference.txt

    r463 r469  
    1919
    20201. Main Metadata information
    21 2. List of Inputs metadata information
     212. List of Inputs metadata information (optional since `rev. 469 <http://zoo-project.org/trac/changeset/469>`__)
    22223. List of Outputs metadata information
    2323
     
    112112- :ref:`ComplexData <ComplexData>`
    113113
    114 Except for ``LiteralData``, each *Type Of Data* node must have at least one ``<Default>`` and one ``<Supported>`` node. Even
    115 if one of those are empty, it **has to be present** with an opening and closing tag on two different lines. So, something
    116 like the following:
    117 
    118 .. code-block:: guess
    119    :linenos:
    120 
    121    <Default>
    122    </Default>
    123 
    124 Otherwise, ZOO-Kernel won't be able to parse your ZCFG and will fail to process requests.
     114Except for ``LiteralData``, each *Type Of Data* node must have at least one ``<Default>`` node. Even
     115if empty, it **has to be present**. So, something
     116like the following should be present in your ZCFG file:
     117
     118.. code-block:: guess
     119   :linenos:
     120
     121   <Default />
     122
     123Otherwise, ZOO-Kernel won't be able to parse your ZCFG correctly.
    125124
    126125.. _LiteralData:
     
    132131
    133132- one (optional) ``AllowedValues`` key containing all value allowed for this input
     133- one (optional) ``range`` properties containing the range (``[``, ``]``)
    134134- one (optional) ``rangeMin`` (``rangeMax``) properties containing the minimum (maximum) value of this range
    135135- one (optional) ``rangeSpacing`` properties containing the regular distance or spacing between value in this range
     
    178178   </LiteralData>
    179179
     180Or more simply:
     181
     182.. code-block:: guess
     183   :linenos:
     184   
     185   <LiteralData>
     186     dataType = float
     187     range = [0.0,100.0]
     188     <Default />
     189   </LiteralData>
     190
    180191A typical ``<LiteralData>`` node, defining a ``string`` data type which
    181192support values ``hillshade``, ``slope``, ``aspect``, ``TRI``, ``TPI``
     
    192203
    193204Properties ``AllowedValues`` and ``range*`` can be conbined with both ``<Default>`` and
    194 ``<Supported>`` nodes in the same ``<LiteralData>`` node.
     205``<Supported>`` nodes in the same was as ``<LiteralData>`` node. For
     206instance, the following is supported:
     207
     208.. code-block:: guess
     209   :linenos:
     210   
     211   <LiteralData>
     212     dataType = int
     213     <Default>
     214       value = 11
     215       AllowedValues = -10,-8,-7,-5,-1
     216       rangeMin = 0
     217       rangeMin = 100
     218       rangeClosure = co
     219     </Default>
     220     <Supported>
     221       rangeMin = 200
     222       rangeMin = 600
     223       rangeClosure = co
     224     </Supported>
     225     <Supported>
     226       rangeMin = 750
     227       rangeMin = 990
     228       rangeClosure = co
     229       rangeSpacing = 10
     230     </Supported>
     231   </LiteralData>
    195232
    196233.. _BoundingBoxData:
  • trunk/zoo-project/zoo-kernel/service.h

    r466 r469  
    430430      map *tmp=getMap(m,n);
    431431      if(tmp->value!=NULL)
    432         free(tmp->value);
     432        free(tmp->value);
    433433      tmp->value=zStrdup(v);
    434434    }
     
    450450        while(_cursor->next!=NULL)
    451451          _cursor=_cursor->next;
    452         map* tmp1=getMap(_cursor,tmp->name);
    453         if(tmp1==NULL)
     452        map* tmp1=getMap(*mo,tmp->name);
     453        if(tmp1==NULL){
    454454          _cursor->next=createMap(tmp->name,tmp->value);
     455        }
    455456        else{
    456           free(tmp1->value);
     457          if(tmp1->value!=NULL)
     458            free(tmp1->value);
    457459          tmp1->value=zStrdup(tmp->value);
    458460        }
     
    567569      }
    568570      else{
    569         maps* tmp1=getMaps(*mo,tmp->name);
    570571        while(_cursor->next!=NULL)
    571572          _cursor=_cursor->next;
     573        maps* tmp1=getMaps(*mo,tmp->name);
    572574        if(tmp1==NULL)
    573575          _cursor->next=dupMaps(&tmp);
     
    687689        _ztmpm->value=zStrdup(value);
    688690      }else{
    689         addToMap(_tmpm->content,subkey,value);
     691        maps *tmp=(maps*)malloc(MAPS_SIZE);
     692        tmp->name=zStrdup(key);
     693        tmp->content=createMap(subkey,value);
     694        tmp->next=NULL;
     695        addMapsToMaps(&_tmpm,tmp);
     696        freeMaps(&tmp);
     697        free(tmp);
    690698      }
    691699    }else{
  • trunk/zoo-project/zoo-kernel/service_conf.y

    r465 r469  
    204204        dumpService(my_service);
    205205#endif 
    206         if(my_service->inputs==NULL){
     206        if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){
    207207          my_service->inputs=dupElements(current_element);
    208208          my_service->inputs->next=NULL;
     209          freeElements(&current_element);
    209210        }
    210211        else if(current_element!=NULL && current_element->name!=NULL){
    211212          addToElements(&my_service->inputs,current_element);
     213          freeElements(&current_element);
    212214        }
    213215#ifdef DEBUG_SERVICE_CONF
     
    218220        fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n");
    219221#endif
    220         freeElements(&current_element);
    221222        free(current_element);
    222223        current_element=NULL;
     
    848849  dumpService(my_service);
    849850#endif
    850   if(wait_outputs<0 || my_service==NULL || my_service->name==NULL || my_service->content==NULL || my_service->inputs==NULL || my_service->outputs==NULL){
     851  if(wait_outputs<0 || my_service==NULL || my_service->name==NULL || my_service->content==NULL || my_service->outputs==NULL){
    851852    setMapInMaps(conf,"lenv","message",srlval.chaine);
    852853#ifndef WIN32
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r467 r469  
    756756}
    757757
     758void addPrefix(maps* conf,map* level,service* serv){
     759  if(level!=NULL){
     760    char key[25];
     761    char* prefix=NULL;
     762    int clevel=atoi(level->value);
     763    int cl=0;
     764    for(cl=0;cl<clevel;cl++){
     765      sprintf(key,"sprefix_%d",cl);
     766      map* tmp2=getMapFromMaps(conf,"lenv",key);
     767      if(tmp2!=NULL){
     768        if(prefix==NULL)
     769          prefix=zStrdup(tmp2->value);
     770        else{
     771          int plen=strlen(prefix);
     772          prefix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char));
     773          memcpy(prefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char));
     774          prefix[plen+strlen(tmp2->value)]=0;
     775        }
     776      }
     777    }
     778    if(prefix!=NULL){
     779      char* tmp0=strdup(serv->name);
     780      free(serv->name);
     781      serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char));
     782      sprintf(serv->name,"%s%s",prefix,tmp0);
     783      free(tmp0);
     784      free(prefix);
     785      prefix=NULL;
     786    }
     787  }
     788}
     789
    758790void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){
    759791  xmlNsPtr ns,ns_ows,ns_xlink;
     
    776808    if(tmp1!=NULL)
    777809      xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value);
     810    map* tmp3=getMapFromMaps(m,"lenv","level");
     811    addPrefix(m,tmp3,serv);
    778812    printDescription(nc1,ns_ows,serv->name,serv->content);
    779813    tmp1=serv->metadata;
     
    816850}
    817851
    818 void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv,int sc){
     852void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv){
    819853  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
    820854  xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
     
    851885  }
    852886 
     887  tmp1=getMapFromMaps(m,"lenv","level");
     888  addPrefix(m,tmp1,serv);
    853889  printDescription(nc,ns_ows,serv->name,serv->content);
    854890
     
    18601896void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap){
    18611897  xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
     1898 
    18621899  xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
    18631900  xmlAddChild(root,nc2);
     
    19041941
    19051942void printExceptionReportResponse(maps* m,map* s){
     1943  if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
     1944    return;
    19061945  int buffersize;
    19071946  xmlDocPtr doc;
     
    19581997  xmlCleanupParser();
    19591998  zooXmlCleanupNs();
     1999  setMapInMaps(m,"lenv","hasPrinted","true");
    19602000}
    19612001
     
    19692009  maps* tmpMap=getMaps(m,"main");
    19702010
    1971   int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
     2011  int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows");
    19722012  ns=usedNs[nsid];
    19732013  n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
    19742014
    19752015  if(use_ns==1){
    1976     ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
     2016    ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1.0",BAD_CAST "ows");
    19772017    int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
    19782018    ns_xsi=usedNs[xsiId];
     2019    ns_xsi=xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
     2020    xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd");
    19792021    int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
    19802022    ns_xlink=usedNs[xlinkId];
    1981     xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd");
    19822023  }
    19832024  addLangAttr(n,m);
     
    28482889  return -1;
    28492890}
     2891
     2892#ifdef USE_MS
     2893char *readVSIFile(maps* conf,const char* dataSource){
     2894    VSILFILE * fichier=VSIFOpenL(dataSource,"rb");
     2895    VSIStatBufL file_status;
     2896    VSIStatL(dataSource, &file_status);
     2897    if(fichier==NULL){
     2898      char tmp[1024];
     2899      sprintf(tmp,"Failed to open file %s for reading purpose. File seems empty %d.",
     2900              dataSource,file_status.st_size);
     2901      setMapInMaps(conf,"lenv","message",tmp);
     2902      return NULL;
     2903    }
     2904    char *res1=(char *)malloc(file_status.st_size*sizeof(char));
     2905    VSIFReadL(res1,1,(file_status.st_size)*sizeof(char),fichier);
     2906    VSIFCloseL(fichier);
     2907    VSIUnlink(dataSource);
     2908    return res1;
     2909}
     2910#endif
     2911
     2912void parseIdentifier(maps* conf,char* conf_dir,char *identifier,char* buffer){
     2913  char *saveptr1;
     2914  char *tmps1=strtok_r(identifier,".",&saveptr1);
     2915  int level=0;
     2916  char key[25];
     2917  char levels[18];
     2918  while(tmps1!=NULL){
     2919    char *test=zStrdup(tmps1);
     2920    char* tmps2=(char*)malloc((strlen(test)+2)*sizeof(char));
     2921    sprintf(key,"sprefix_%d",level);
     2922    sprintf(tmps2,"%s.",test);
     2923    sprintf(levels,"%d",level);
     2924    setMapInMaps(conf,"lenv","level",levels);
     2925    setMapInMaps(conf,"lenv",key,tmps2);
     2926    free(tmps2);
     2927    level++;
     2928    tmps1=strtok_r(NULL,".",&saveptr1);
     2929  }
     2930  int i=0;
     2931  sprintf(buffer,"%s",conf_dir);
     2932  for(i=0;i<level;i++){
     2933    char *tmp0=zStrdup(buffer);
     2934    sprintf(key,"sprefix_%d",i);
     2935    map* tmp00=getMapFromMaps(conf,"lenv",key);
     2936    sprintf(buffer,"%s/%s",tmp0,tmp00->value);
     2937    free(tmp0);
     2938    buffer[strlen(buffer)-1]=0;
     2939    if(i+1<level){
     2940      map* tmpMap=getMapFromMaps(conf,"lenv","metapath");
     2941      if(tmpMap==NULL || strlen(tmpMap->value)==0){
     2942        char *tmp01=zStrdup(tmp00->value);
     2943        tmp01[strlen(tmp01)-1]=0;
     2944        setMapInMaps(conf,"lenv","metapath",tmp01);
     2945        free(tmp01);
     2946      }
     2947      else{
     2948        char *value=(char*)malloc((strlen(tmp00->value)+strlen(tmpMap->value)+2)*sizeof(char));
     2949        sprintf(value,"%s/%s",tmpMap->value,tmp00->value);
     2950        value[strlen(value)-1]=0;
     2951        setMapInMaps(conf,"lenv","metapath",value);
     2952        free(value);
     2953      }
     2954    }else{
     2955      char *tmp0=zStrdup(tmp00->value);
     2956      tmp0[strlen(tmp0)-1]=0;
     2957      setMapInMaps(conf,"lenv","Identifier",tmp0);
     2958      free(tmp0);
     2959    }
     2960  }
     2961  char *tmp0=zStrdup(buffer);
     2962  sprintf(buffer,"%s.zcfg",tmp0);
     2963  free(tmp0);
     2964}
     2965
  • trunk/zoo-project/zoo-kernel/service_internal.h

    r467 r469  
    3838#include <sys/stat.h>
    3939#include <sys/types.h>
     40#include "cgic.h"
    4041#ifndef WIN32
    4142#include <sys/ipc.h>
    4243#include <sys/shm.h>
    4344#else
    44 #include "cgic.h"
    4545#include <direct.h>
    4646#endif
     
    5656#include <xlocale.h>
    5757#endif
     58#include <dirent.h>
    5859#include "service.h"
    5960#include <openssl/sha.h>
     
    118119  void printGetCapabilitiesForProcess(maps*,xmlNodePtr,service*);
    119120  xmlNodePtr printDescribeProcessHeader(xmlDocPtr,const char*,maps*);
    120   void printDescribeProcessForProcess(maps*,xmlNodePtr,service*,int);
     121  void printDescribeProcessForProcess(maps*,xmlNodePtr,service*);
    121122  void printFullDescription(elements*,const char*,xmlNsPtr,xmlNodePtr);
    122123  void printDocument(maps*,xmlDocPtr,int);
     
    144145  int loadRemoteFile(maps*,map*,HINTERNET,char*);
    145146
     147#ifdef USE_MS
     148  char *readVSIFile(maps*,const char*);
     149#endif
     150  void parseIdentifier(maps*,char*,char*,char*);
     151
    146152#ifdef __cplusplus
    147153}
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r465 r469  
    289289#if PY_MAJOR_VERSION < 3
    290290  PyGILState_Release(gstate);
    291   PyEval_AcquireLock();
     291  PyEval_ReleaseLock();
    292292#endif
    293293  PyThreadState_Swap(mainstate);
  • trunk/zoo-project/zoo-kernel/service_internal_python.h

    r376 r469  
    2828#pragma once
    2929
    30 #include "service.h"
    3130#include "service_internal.h"
    3231#include <Python.h>
     32#include "cgic.h"
    3333#ifdef WIN32
    3434#include <windows.h>
  • trunk/zoo-project/zoo-kernel/zcfg2yaml.c

    r467 r469  
    3030int main(int argc, char** argv){
    3131  service* s1=NULL;
    32   maps *m;
     32  maps *m=NULL;
    3333  char conf_file[1024];
    3434  snprintf(conf_file,1024,"%s",argv[1]);
     
    3737    return errorException(m, _("Unable to allocate memory."),"InternalError",NULL);
    3838  }
    39   int t=getServiceFromFile(conf,file,service);
     39  int t=getServiceFromFile(m,conf_file,&s1);
    4040  if(t>=0)
    4141    dumpServiceAsYAML(s1);
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r467 r469  
    189189  }
    190190  return 0;
     191}
     192
     193int recursReaddirF(maps* m,xmlNodePtr n,char *conf_dir,char *prefix,int saved_stdout,int level,void (func) (maps*,xmlNodePtr,service*)){
     194  struct dirent *dp;
     195  int scount=0;
     196
     197  if(conf_dir==NULL)
     198    return 1;
     199  DIR *dirp = opendir(conf_dir);
     200  if(dirp==NULL){
     201    dup2(saved_stdout,fileno(stdout));
     202    errorException(m, _("The specified path doesn't exist."),"InvalidParameterValue","metapath");
     203    return -1;
     204  }
     205  char tmp1[25];
     206  sprintf(tmp1,"sprefix_%d",level);
     207  char levels[17];
     208  sprintf(levels,"%d",level);
     209  setMapInMaps(m,"lenv","level",levels);
     210  while ((dp = readdir(dirp)) != NULL)
     211    if((dp->d_type==DT_DIR || dp->d_type==DT_LNK) && dp->d_name[0]!='.' && strstr(dp->d_name,".")==NULL){
     212
     213      char *tmp=(char*)malloc((strlen(conf_dir)+strlen(dp->d_name)+2)*sizeof(char));
     214      sprintf(tmp,"%s/%s",conf_dir,dp->d_name);
     215
     216      if(prefix!=NULL){
     217        free(prefix);
     218        prefix=NULL;
     219      }
     220      prefix=(char*)malloc((strlen(dp->d_name)+2)*sizeof(char));
     221      sprintf(prefix,"%s.",dp->d_name);
     222     
     223      map* tmpMap=getMapFromMaps(m,"lenv",tmp1);
     224     
     225      int res;
     226      if(prefix!=NULL){
     227        setMapInMaps(m,"lenv",tmp1,prefix);
     228        char *cprefix=zStrdup(prefix);
     229        char levels1[17];
     230        sprintf(levels1,"%d",level+1);
     231        setMapInMaps(m,"lenv","level",levels1);
     232        res=recursReaddirF(m,n,tmp,cprefix,saved_stdout,level+1,func);
     233        sprintf(levels1,"%d",level);
     234        setMapInMaps(m,"lenv","level",levels1);
     235        free(prefix);
     236        prefix=NULL;
     237      }
     238      free(tmp);
     239      if(res<0){
     240        return res;
     241      }
     242    }
     243    else{
     244      char* tmp0=strdup(dp->d_name);
     245      if(dp->d_name[0]!='.' && strstr(dp->d_name,".zcfg")!=0){
     246        int t;
     247        char tmps1[1024];
     248        memset(tmps1,0,1024);
     249        snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name);
     250        service* s1=(service*)malloc(SERVICE_SIZE);
     251        if(s1 == NULL){
     252          dup2(saved_stdout,fileno(stdout));
     253          errorException(m, _("Unable to allocate memory."),"InternalError",NULL);
     254          return -1;
     255        }
     256#ifdef DEBUG
     257        fprintf(stderr,"#################\n%s\n#################\n",tmps1);
     258#endif
     259        t=readServiceFile(m,tmps1,&s1,dp->d_name);
     260        if(t<0){
     261          dumpMaps(m);
     262          map* tmp00=getMapFromMaps(m,"lenv","message");
     263          char tmp01[1024];
     264          if(tmp00!=NULL)
     265            sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value);
     266          else
     267            sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),dp->d_name);
     268          dup2(saved_stdout,fileno(stdout));
     269          errorException(m, tmp01,"InternalError",NULL);
     270          freeMaps(&m);
     271          free(m);
     272          return -1;
     273        }
     274#ifdef DEBUG
     275        dumpService(s1);
     276        fflush(stdout);
     277        fflush(stderr);
     278#endif
     279        func(m,n,s1);
     280        freeService(&s1);
     281        free(s1);
     282        scount++;
     283      }
     284    }
     285  (void)closedir(dirp);
     286  return 1;
    191287}
    192288
     
    277373    void* so = dlopen(tmps1, RTLD_LAZY);
    278374#endif
    279 #ifdef DEBUG
    280375#ifdef WIN32
    281376    DWORD errstr;
     
    285380    char *errstr;
    286381    errstr = dlerror();
    287 #endif
    288382#endif
    289383    if( so != NULL ) {
     
    346440#endif
    347441#endif
    348         r_inputs=getMap(request_inputs,"Identifier");
     442        r_inputs=getMapFromMaps(m,"lenv","Identifier");
    349443#ifdef DEBUG
    350444        fprintf(stderr,"Try to load function %s\n",r_inputs->value);
     
    356450        execute_t execute=(execute_t)dlsym(so,r_inputs->value);
    357451#endif
     452
     453        if(execute==NULL){
     454#ifdef WIN32
     455          errstr = GetLastError();
     456#else
     457          errstr = dlerror();
     458#endif
     459          char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value));
     460          sprintf(tmpMsg,_("Error occured while running the %s function: %s"),r_inputs->value,errstr);
     461          errorException(m, tmpMsg, "InternalError",NULL);
     462          free(tmpMsg);
     463          fprintf(stderr,"Function %s error %s\n",r_inputs->value,errstr);
     464          return;
     465        }
    358466
    359467#ifdef DEBUG
     
    758866    dumpMap(r_inputs);
    759867#endif
    760     DIR *dirp = opendir(conf_dir);
    761     if(dirp==NULL){
    762       return errorException(m, _("The specified path doesn't exist."),"InvalidParameterValue","metapath");
    763     }
    764868    xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
    765869    r_inputs=NULL;
     
    776880    int saved_stdout = dup(fileno(stdout));
    777881    dup2(fileno(stderr),fileno(stdout));
    778     while ((dp = readdir(dirp)) != NULL)
    779       if(strstr(dp->d_name,".zcfg")!=0){
    780         int t;
    781         memset(tmps1,0,1024);
    782         snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name);
    783         s1=(service*)malloc(SERVICE_SIZE);
    784         if(s1 == NULL){
    785           return errorException(m, _("Unable to allocate memory."),"InternalError",NULL);
    786         }
    787 #ifdef DEBUG
    788         fprintf(stderr,"#################\n%s\n#################\n",tmps1);
    789 #endif
    790         t=readServiceFile(m,tmps1,&s1,dp->d_name);
    791         if(t<0){
    792           dumpMaps(m);
    793           map* tmp00=getMapFromMaps(m,"lenv","message");
    794           char tmp01[1024];
    795           sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value);
    796           dup2(saved_stdout,fileno(stdout));
    797           errorException(m, tmp01,"InternalError",NULL);
    798           freeMaps(&m);
    799           free(m);
    800           return 1;
    801         }
    802 
    803 #ifdef DEBUG
    804         dumpService(s1);
    805         fflush(stdout);
    806         fflush(stderr);
    807 #endif
    808         printGetCapabilitiesForProcess(m,n,s1);
    809         freeService(&s1);
    810         free(s1);
    811         scount++;
    812       }
    813     (void)closedir(dirp);
    814     fflush(stdout);
     882    if(int res=recursReaddirF(m,n,conf_dir,NULL,saved_stdout,0,printGetCapabilitiesForProcess)<0)
     883      return res;
    815884    dup2(saved_stdout,fileno(stdout));
    816885    printDocument(m,doc,getpid());
     
    860929      r_inputs=getMap(request_inputs,"Identifier");
    861930     
    862       char *saveptr;
    863931      char *orig=zStrdup(r_inputs->value);
    864       char *tmps=strtok_r(orig,",",&saveptr);
    865      
    866       char buff[256];
    867       char buff1[1024];
     932
    868933      int saved_stdout = dup(fileno(stdout));
    869934      dup2(fileno(stderr),fileno(stdout));
    870       while(tmps){
    871         memset(buff,0,256);
    872         snprintf(buff,256,"%s.zcfg",tmps);
    873         memset(buff1,0,1024);
    874 #ifdef DEBUG
    875         printf("\n#######%s\n########\n",buff);
    876 #endif
    877         while ((dp = readdir(dirp)) != NULL)
    878           if((strcasecmp("all.zcfg",buff)==0 && strstr(dp->d_name,".zcfg")>0)
    879              || strcasecmp(dp->d_name,buff)==0){
    880             memset(buff1,0,1024);
    881             snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name);
     935      if(strcasecmp("all",orig)==0){
     936        if(int res=recursReaddirF(m,n,conf_dir,NULL,saved_stdout,0,printDescribeProcessForProcess)<0)
     937          return res;
     938      }
     939      else{
     940        char *saveptr;
     941        char *tmps=strtok_r(orig,",",&saveptr);
     942       
     943        char buff[256];
     944        char buff1[1024];
     945        while(tmps!=NULL){
     946          char *corig=strdup(tmps);
     947          if(strstr(corig,".")!=NULL){
     948            parseIdentifier(m,conf_dir,corig,buff1);
    882949            s1=(service*)malloc(SERVICE_SIZE);
    883             if(s1 == NULL){
    884               dup2(saved_stdout,fileno(stdout));
    885               return errorException(m, _("Unable to allocate memory."),"InternalError",NULL);
    886             }
    887 #ifdef DEBUG
    888             printf("#################\n(%s) %s\n#################\n",r_inputs->value,buff1);
    889 #endif
    890             char *tmp0=zStrdup(dp->d_name);
    891             tmp0[strlen(tmp0)-5]=0;
    892             t=readServiceFile(m,buff1,&s1,tmp0);
    893             free(tmp0);
     950            t=readServiceFile(m,buff1,&s1,corig);
    894951            if(t<0){
    895952              map* tmp00=getMapFromMaps(m,"lenv","message");
     
    908965            dumpService(s1);
    909966#endif
    910             printDescribeProcessForProcess(m,n,s1,1);
     967            printDescribeProcessForProcess(m,n,s1);
    911968            freeService(&s1);
    912969            free(s1);
    913970            s1=NULL;
    914971            scount++;
     972            setMapInMaps(m,"lenv","level","0");
    915973          }
    916         rewinddir(dirp);
    917         tmps=strtok_r(NULL,",",&saveptr);
     974         
     975          memset(buff,0,256);
     976          snprintf(buff,256,"%s.zcfg",tmps);
     977          memset(buff1,0,1024);
     978#ifdef DEBUG
     979          printf("\n#######%s\n########\n",buff);
     980#endif
     981          while ((dp = readdir(dirp)) != NULL)
     982            if( (strcasecmp("all.zcfg",buff)==0 && strstr(dp->d_name,".zcfg")>0)
     983                || strcasecmp(dp->d_name,buff)==0 ){
     984              memset(buff1,0,1024);
     985              snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name);
     986              s1=(service*)malloc(SERVICE_SIZE);
     987              if(s1 == NULL){
     988                dup2(saved_stdout,fileno(stdout));
     989                return errorException(m, _("Unable to allocate memory."),"InternalError",NULL);
     990              }
     991#ifdef DEBUG
     992              printf("#################\n(%s) %s\n#################\n",r_inputs->value,buff1);
     993#endif
     994              char *tmp0=zStrdup(dp->d_name);
     995              tmp0[strlen(tmp0)-5]=0;
     996              t=readServiceFile(m,buff1,&s1,tmp0);
     997              free(tmp0);
     998              if(t<0){
     999                map* tmp00=getMapFromMaps(m,"lenv","message");
     1000                char tmp01[1024];
     1001                if(tmp00!=NULL)
     1002                  sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value);
     1003                else
     1004                  sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),dp->d_name);
     1005                dup2(saved_stdout,fileno(stdout));
     1006                errorException(m, tmp01,"InternalError",NULL);
     1007                freeMaps(&m);
     1008                free(m);
     1009                return 1;
     1010              }
     1011#ifdef DEBUG
     1012              dumpService(s1);
     1013#endif
     1014              printDescribeProcessForProcess(m,n,s1);
     1015              freeService(&s1);
     1016              free(s1);
     1017              s1=NULL;
     1018              scount++;
     1019            }
     1020          rewinddir(dirp);
     1021          tmps=strtok_r(NULL,",",&saveptr);
     1022        }
    9181023      }
    9191024      closedir(dirp);
     
    9671072  fprintf(stderr,"Trying to load %s\n", tmps1);
    9681073#endif
     1074  if(strstr(r_inputs->value,".")!=NULL){
     1075    char *identifier=zStrdup(r_inputs->value);
     1076    parseIdentifier(m,conf_dir,identifier,tmps1);
     1077    map* tmpMap=getMapFromMaps(m,"lenv","metapath");
     1078    if(tmpMap!=NULL)
     1079      addToMap(request_inputs,"metapath",tmpMap->value);
     1080    free(identifier);
     1081  }else
     1082    setMapInMaps(m,"lenv","Identifier",r_inputs->value);
    9691083  int saved_stdout = dup(fileno(stdout));
    9701084  dup2(fileno(stderr),fileno(stdout));
     
    9741088  if(t<0){
    9751089    char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value));
    976    
    9771090    sprintf(tmpMsg,_("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),r_inputs->value);
    9781091    errorException(m, tmpMsg, "InvalidParameterValue","identifier");
  • trunk/zoo-project/zoo-services/cgal/Makefile

    r284 r469  
    1 ZRPATH=../../..
     1ZRPATH=../..
    22include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
    33CFLAGS=${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
    44CC=gcc
    55
    6 cgi-env/cgal_service.zo: service.c
    7         g++ ${CFLAGS} -shared -fpic -o cgi-env/cgal_service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS} -lCGAL
     6cgi-env/cgal_service.zo: delaunay.c voronoi.c cgal_service.o
     7        g++ ${CFLAGS} -c ./delaunay.c
     8        g++ ${CFLAGS} -c ./voronoi.c
     9        g++ ${CFLAGS} -shared -fpic -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${MACOS_LD_FLAGS} -lCGAL -lgmp
     10
     11cgal_service.o: cgal_service.c cgal_service.h
     12        g++ ${CFLAGS} -c ./cgal_service.c
     13
    814
    915clean:
    10         rm -f cgi-env/*.zo
     16        rm -f cgi-env/*.zo *.o
  • trunk/zoo-project/zoo-services/cgal/voronoi.c

    r468 r469  
    3636#include "ogrsf_frmts.h"
    3737#include "service.h"
    38 
    39 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
    40 
    41 typedef CGAL::Delaunay_triangulation_2<K>  Triangulation;
     38#include "cgal_service.h"
     39
     40typedef CGAL::Delaunay_triangulation_2<Kernel>  Triangulation;
    4241typedef Triangulation::Edge_iterator  Edge_iterator;
    43 typedef Triangulation::Point          Point;
    44 
    45 typedef CGAL::Constrained_Delaunay_triangulation_2<K> CDT;
    46 typedef CDT::Point Point;
    47 typedef CDT::Vertex_handle Vertex_handle;
    48 
    49 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
    50 typedef CGAL::Triangulation_euclidean_traits_xy_3<K>  Gt;
    51 typedef CGAL::Delaunay_triangulation_2<Gt> DelaunayTriangulation;
    52 
    5342typedef Triangulation::Vertex_circulator Vertex_circulator;
    5443
    55 typedef K::Point_3   Point1;
    56 
    5744extern "C" {
    58 #include <libxml/tree.h>
    59 #include <libxml/parser.h>
    60 #include <libxml/xpath.h>
    61 #include <libxml/xpathInternals.h>
    62 
    63 #include <openssl/sha.h>
    64 #include <openssl/hmac.h>
    65 #include <openssl/evp.h>
    66 #include <openssl/bio.h>
    67 #include <openssl/buffer.h>
    68 
    69   xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
    70   void printExceptionReportResponse(maps*,map*);
    7145
    7246  int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){
     
    7751    OGRGeometryH geometry,res;
    7852    int bufferDistance;
    79     xmlInitParser();
    8053    map* tmpm=NULL;
    8154    tmpm=getMapFromMaps(inputs,"InputPoints","value");
    82    
    83     xmlInitParser();
    84     xmlDocPtr doc =
    85       xmlParseMemory(tmpm->value,strlen(tmpm->value));
    86     xmlNodePtr cur = xmlDocGetRootElement(doc);
    87     /**
    88      * Parse every Input in DataInputs node.
    89      */
    90     maps* tempMaps=NULL;
    91     xmlXPathContextPtr xpathCtx;
    92     xmlXPathObjectPtr xpathObj;
    93     xpathCtx = xmlXPathNewContext(doc);
    94     xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx);
    95     xmlXPathFreeContext(xpathCtx);
    96     xmlNodeSet* nSet=xpathObj->nodesetval;
    97 
    98     if(nSet==NULL){
    99       setMapInMaps(conf,"lenv","message","Unable to continue !!!");
    100       return SERVICE_FAILED;
    101     }
    102     char filepath[2048];
    103     map* tmpMap=getMapFromMaps(conf,"main","tmpPath");
    104     if(tmpMap!=NULL){
    105       sprintf(filepath,"%s/varonoi_%d.tmp",tmpMap->value,getpid());
    106     }
    107     FILE *fo=fopen(filepath,"w");
    108 #ifdef DEBUG
    109     fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,nSet->nodeNr);
    110 #endif
    111     for(int k=0;k<nSet->nodeNr;k++){
    112       xmlNodePtr cur=nSet->nodeTab[k];
    113       char *val=
    114         (char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
    115       char *tmp=strstr(val,",");
    116       char tmp1[1024];
    117       strncpy(tmp1,val,strlen(val)-strlen(tmp));
    118       tmp1[strlen(val)-strlen(tmp)]=0;
    119       char buff[1024];
    120       sprintf(buff,"%s %s\n",tmp1,tmp+1);
    121       fwrite(buff,1,strlen(buff)*sizeof(char),fo);
    122     }
    123     fclose(fo);
    124 #ifdef DEBUG
    125     fprintf(stderr,"File Close (%s) OK\n",filepath);
    126 #endif
    127 
    128     std::ifstream in(filepath);
    129     std::istream_iterator<Point> begin(in);
    130     std::istream_iterator<Point> end;
     55
     56    OGRRegisterAll();
     57
     58    std::vector<Point> points;
     59    if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED)
     60      return res;
     61   
    13162    Triangulation T;
    132     T.insert(begin, end);
     63    T.insert(points.begin(), points.end());
    13364
    13465    OGRRegisterAll();
     
    14273    int                  iDriver;
    14374
    144     tmpMap=getMapFromMaps(outputs,"Result","mimeType");
     75    map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
    14576    const char *oDriver;
    14677    oDriver="GeoJSON";
     
    192123    /* -------------------------------------------------------------------- */
    193124    map* tpath=getMapFromMaps(conf,"main","tmpPath");
    194     char *pszDestDataSource=(char*)malloc(strlen(tpath->value)+20);
     125    char *pszDestDataSource=(char*)malloc(100);
    195126    char **papszDSCO=NULL;
    196     sprintf(pszDestDataSource,"%s/result_%d.json",tpath->value,getpid());
     127    sprintf(pszDestDataSource,"/vsimem/result_%d.json",tpath->value,getpid());
    197128    poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
    198129    if( poODS == NULL ){
     
    231162    for ( ; eit !=T.edges_end(); ++eit) {
    232163      CGAL::Object o = T.dual(eit);
    233       if (const K::Segment_2 *tmp=CGAL::object_cast<K::Segment_2>(&o)) {
    234         const K::Point_2 p1=tmp->source();
    235         const K::Point_2 p2=tmp->target();
     164      if (const Kernel::Segment_2 *tmp=CGAL::object_cast<Kernel::Segment_2>(&o)) {
     165        const Point p1=tmp->source();
     166        const Point p2=tmp->target();
    236167#ifdef DEBUG
    237168        fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y());
     
    250181        ++ns ;
    251182      }
    252       else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;}
     183      else if (const Kernel::Ray_2 *tmp=CGAL::object_cast<Kernel::Ray_2>(&o)) {
     184        const Point p1=tmp->source();
     185        const Point p2=tmp->point(2);
     186        OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) );
     187        OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString);
     188        OGR_G_AddPoint_2D(currLine,p1.x(),p1.y());
     189        OGR_G_AddPoint_2D(currLine,p2.x(),p2.y());
     190        OGR_F_SetGeometry( hFeature, currLine );
     191        OGR_G_DestroyGeometry(currLine);
     192        if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){
     193          setMapInMaps(conf,"lenv","message","Failed to create feature in file.\n");
     194          return SERVICE_FAILED;
     195        }
     196        OGR_F_Destroy( hFeature );
     197        ++nr;
     198      }
    253199    }
    254200    OGR_DS_Destroy( poODS );
    255     OGRCleanupAll();
    256201
    257202#ifdef DEBUG
     
    261206#endif
    262207   
    263     char tmp1[1024];
    264 
    265     FILE * fichier=fopen(pszDestDataSource,"r");
    266     struct stat file_status;
    267     stat(pszDestDataSource, &file_status);
    268     char *res1=(char *)malloc(file_status.st_size*sizeof(char));
    269     if(fichier==NULL){
    270       char tmp[1024];
    271       sprintf(tmp,"Failed to open file %s for reading purpose.\n",
    272               pszDestDataSource);
    273       setMapInMaps(conf,"lenv","message",tmp);
    274       return SERVICE_FAILED;
    275     }
    276     fread(res1,1,(file_status.st_size)*sizeof(char),fichier);
    277     res1[strlen(res1)]=0;
    278     fclose(fichier);
    279     unlink(pszDestDataSource);
     208
     209    char *res1=readVSIFile(conf,pszDestDataSource);
     210    if(res1==NULL)
     211      return SERVICE_FAILED;
    280212   
    281213    setMapInMaps(outputs,"Result","value",res1);
     
    290222    fprintf(stderr,"\nService internal print\n===\n");
    291223#endif
    292     xmlCleanupParser();
     224    OGRCleanupAll();
    293225    return SERVICE_SUCCEEDED;
    294226  }
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