Changeset 967


Ignore:
Timestamp:
Dec 18, 2020, 2:13:22 PM (3 years ago)
Author:
djay
Message:

Add support for the two inputs / outputs syntaxes discussed in SWG in both the ZOO-Kernel and the HTML basic UI. Update documentation, add a section for the ZOO-API in Python language section. Rename variables in service.c to ease readabiliy.

Location:
trunk
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/services/howtos.rst

    r917 r967  
    2727
    2828You'll find here information needed to deploy your own Python Services Provider.
     29
     30ZOO-API
     31*******
     32
     33From your python module where you define your services, you can access
     34the ZOO-API by importing the ``zoo`` module. No need to install
     35anything here, the module will be automatically created from the
     36ZOO-Kernel code at runtime.
     37
     38The following attributes are available from the ZOO-API :
     39
     40SERVICE_SUCCEEDED
     41    Value to return in case your service end successfully.
     42SERVICE_FAILED
     43    Value to retrun in case of failure.
     44   
     45
     46The following functions are defined in the ZOO-API:
     47
     48_(strToTranslate)
     49    return the translated string (using the "zoo-service" `textdomain
     50    <http://www.gnu.org/software/libc/manual/html_node/Locating-gettext-catalog.html#index-textdomain>`__)
     51
     52update_status(dictConf,iPourcent)
     53    update the status of the running service
    2954
    3055Python ZCFG requirements
     
    102127  {
    103128  'variable_name': {'minOccurs': '1',
    104                     'DataType': 'string',
     129                    'dataType': 'string',
    105130                    'value': 'this_is_the_value',
    106131                    'maxOccurs': '1',
     
    118143
    119144  {
    120   'result': {'DataType': 'string',
     145  'result': {'dataType': 'string',
    121146             'inRequest': 'true',
    122147            }
     
    157182
    158183The ZOO-API for the PHP language is automatically available from your
    159 service code. Tthe following functions are defined in the ZOO-API:
     184service code. The following functions are defined in the ZOO-API:
    160185
    161186int zoo_SERVICE_SUCCEEDED()
  • trunk/zoo-project/HISTORY.txt

    r966 r967  
    11Version 1.8.0-dev
     2  * Support raw response in OGC API - Processes
     3  * Add a ZOO-API section to the howtos documentation
     4  * OGC API - Processes support:
     5  https://github.com/gfenoy/wps-rest-binding/tree/change-request/95
     6  * Support two inputs/outputs syntaxes discussed (using json object
     7  or array of json object) for ZOO-Kernel and the HTML client
    28  * Fix issue in kvParseInput when memory!=load and handle session
    39  from the OGC API - Processes
  • trunk/zoo-project/zoo-kernel/Makefile.in

    r962 r967  
    44
    55version.h: Makefile
    6         echo "#define ZOO_VERSION \"1.7.0 `svnversion`\"" > version.h
     6        echo "#define ZOO_VERSION \"1.8.0-rc1 `svnversion`\"" > version.h
    77        echo "@ETC_DEF@" >> version.h
    88        echo "#define LOCALEDIR \"@localedir@\"" >>  version.h
     
    5757
    5858response_print.o: response_print.c response_print.h
    59         g++ -fPIC ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} ${HPC_ENABLED} -c response_print.c
     59        g++ -fPIC ${JSON_CFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} ${HPC_ENABLED} -c response_print.c
    6060
    6161server_internal.o: server_internal.c server_internal.h service.h mimetypes.h
  • trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in

    r917 r967  
    44INST_LIB=@libdir@
    55INST_INCLUDE=@includedir@
    6 VERSION=1.5
     6VERSION=1.8
    77REVISION=0
    88EXT=so
  • trunk/zoo-project/zoo-kernel/configure.ac

    r962 r967  
    1 AC_INIT([ZOO Kernel], [1.7.0], [bugs@zoo-project.org])
     1AC_INIT([ZOO Kernel], [1.8.0-rc1], [bugs@zoo-project.org])
    22
    33AC_CONFIG_MACRO_DIR([macros])
     
    10791079        WX_ISSUE="-D_WX_WXCRTVARARG_H_"
    10801080        SAGA_DEFS="-D_SAGA_LINUX -D_TYPEDEF_BYTE -D_TYPEDEF_WORD -DMODULE_LIBRARY_PATH=\\\"$SAGAPATH/lib/saga\\\""
    1081         SAGA_CPPFLAGS="-DSAGA_VERSION=${SAGAVERS} -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE"
     1081        SAGA_CPPFLAGS="-DSAGA_VERSION=${SAGAVERS} -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ -I$SAGAPATH/include/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE"
    10821082        SAGA_LDFLAGS="-fPIC `$WXCFG --unicode=yes --static=no --libs` -lsaga_api"
    10831083        SAGA_ENABLED="-DUSE_SAGA"
  • trunk/zoo-project/zoo-kernel/oas.cfg

    r962 r967  
    1212wsUrl=wss://demo.mapmint.com:4430/
    1313publisherUrl=http://127.0.0.1/cgi-bin3/publish.py?jobid=
     14io_as_array=true
    1415
    1516[/]
     
    2425tags=Home
    2526tags_description=
    26 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/LandingPage.yaml
     27schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/LandingPage.yaml
    2728
    2829[/index.html]
     
    5354rel=conformance
    5455type=application/json
    55 title=WPS 2.0 REST/JSON Binding Extension conformance classes implemented by this server
     56title=OGC API - Processes conformance classes implemented by this server
    5657
    5758[conformance]
     
    6162tags=Conformance
    6263tags_description=
    63 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ConformanceDeclaration.yaml
     64schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ConformanceDeclaration.yaml
    6465
    6566[/conformance.html]
     
    7879tags=GetCapabilities
    7980tags_description=
    80 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ProcessList.yaml
     81schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ProcessList.yaml
    8182
    8283[/processes.html]
     
    9091tags=ProcessDescription
    9192tags_description=
    92 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ProcessDescription.yaml
     93schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ProcessDescription.yaml
    9394ecode=404
    9495parameters=/components/parameters/id
     
    107108tags=JobList
    108109tags_description=
    109 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/JobList.yaml
     110schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/JobList.yaml
    110111parameters=/components/parameters/id
    111112ecode=404,500
     
    115116tags_1=Execute Endpoint
    116117tags_description_1=
    117 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ExecuteSync.yaml
     118schema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ExecuteSync.yaml
    118119parameters_1=/components/parameters/id
    119120ecode_1=400,404,500
    120 eschema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ExecuteAsync.yaml
     121eschema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ExecuteAsync.yaml
    121122ep=,/components/parameters/oas-header1
    122123
     
    124125abstract=Mandatory execute request in JSON format
    125126type=application/json
    126 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/execute.yaml
     127schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/execute.yaml
    127128
    128129[/processes/{id}/jobs/{jobID}]
     
    138139tags=GetStatus
    139140tags_description=
    140 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/Status.yaml
     141schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/Status.yaml
    141142parameters=/components/parameters/id,/components/parameters/jobID
    142143method_1=delete
     
    145146tags_1=Dismiss
    146147tags_description_1=Cencel a job execution
    147 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/Status.yaml
     148schema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/Status.yaml
    148149parameters_1=/components/parameters/id,/components/parameters/jobID
    149150ecode_1=404,500
     
    161162tags=GetResult
    162163tags_description=
    163 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/Results.yaml
     164schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/Results.yaml
    164165parameters=/components/parameters/id,/components/parameters/jobID
    165166ecode=404,500
     
    177178tags=GetResult
    178179tags_description=
    179 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/valueType.yaml
     180schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/valueType.yaml
    180181parameters=/components/parameters/id,/components/parameters/jobID,/components/parameters/resultID
    181182ep=,/components/parameters/oas-header2
     
    226227abstract=Exception
    227228type=application/json
    228 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/NotFound.yaml
    229 default_schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ServerError.yaml
     229schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/NotFound.yaml
     230default_schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ServerError.yaml
    230231
    231232[responses]
    232233length=5
    233234code=404
    234 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/NotFound.yaml
     235schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/NotFound.yaml
    235236type=application/json
    236237title=NotFound
    237238code_1=500
    238 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ServerError.yaml
     239schema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/ServerError.yaml
    239240type_1=application/json
    240241title_1=ServerError
    241242code_2=400
    242 schema_2=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/InvalidParameter.yaml
     243schema_2=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/InvalidParameter.yaml
    243244type_2=appliction/json
    244245title_2=InvalidParameter
    245246code_3=405
    246 schema_3=https://github.com/opengeospatial/wps-rest-binding/blob/master/core/openapi/responses/NotAllowed.yaml
     247schema_3=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/NotAllowed.yaml
    247248type_3=appliction/json
    248249title_3=NotAllowed
    249250code_4=406
    250 schema_4=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/NotSupported.yaml
     251schema_4=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/responses/NotSupported.yaml
    251252type_4=appliction/json
    252253title_4=NotSupported
     
    256257state=jobSuccess
    257258uri=successUri
    258 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/result.yaml
     259schema=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/result.yaml
    259260type=application/json
    260261title=Results received successfully
    261262state_1=jobInProgress
    262263uri_1=inProgressUri
    263 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/statusInfo.yaml
     264schema_1=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/statusInfo.yaml
    264265type_1=application/json
    265266title_1=Results received successfully
    266267state_2=jobFailed
    267268uri_2=failedUrii
    268 schema_2=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/exception.yaml
     269schema_2=https://raw.githubusercontent.com/gfenoy/wps-rest-binding/change-request/95/core/openapi/schemas/exception.yaml
    269270type_2=application/json
    270271title_2=Exception received successfully
  • trunk/zoo-project/zoo-kernel/request_parser.c

    r966 r967  
    16891689int validateRequest(maps** main_conf,service* s,map* original_request, maps** request_inputs,maps** request_outputs,HINTERNET* hInternet){
    16901690
    1691   map* errI0=NULL;
    1692   runHttpRequests (main_conf, request_inputs, hInternet,&errI0);
    1693   if(errI0!=NULL){
    1694     printExceptionReportResponse (*main_conf, errI0);
     1691  if(hInternet!=NULL){
     1692    map* errI0=NULL;
     1693    runHttpRequests (main_conf, request_inputs, hInternet,&errI0);
     1694    if(errI0!=NULL){
     1695      printExceptionReportResponse (*main_conf, errI0);
     1696      InternetCloseHandle (hInternet);
     1697      return -1;
     1698    }
    16951699    InternetCloseHandle (hInternet);
    1696     return -1;
    16971700  }
    1698   InternetCloseHandle (hInternet);
    1699 
    17001701
    17011702  map* errI=NULL;
     
    17201721              addToMap (tmpe, "locator", ptr->name);
    17211722              addToMap (tmpe, "text", tmps);
    1722               printExceptionReportResponse (*main_conf, tmpe);
     1723              printExceptionReportResponse (*main_conf, tmpe);
    17231724              freeMap (&tmpe);
    17241725              free (tmpe);
  • trunk/zoo-project/zoo-kernel/response_print.c

    r966 r967  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2015 GeoLabs SARL
     4 * Copyright (c) 2009-2020 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    4141
    4242#include "mimetypes.h"
     43#include "service_json.h"
    4344
    4445/**
    4546 * Add prefix to the service name.
    4647 *
    47  * @param conf the conf maps containing the main.cfg settings
    48  * @param level the map containing the level information
    49  * @param serv the service structure created from the zcfg file
    50  */
    51 void addPrefix(maps* conf,map* level,service* serv){
    52   if(level!=NULL){
    53     char key[25];
    54     char* prefix=NULL;
    55     int clevel=atoi(level->value);
    56     int cl=0;
    57     for(cl=0;cl<clevel;cl++){
    58       sprintf(key,"sprefix_%d",cl);
    59       map* tmp2=getMapFromMaps(conf,"lenv",key);
     48 * @param pmsConf the conf maps containing the main.cfg settings
     49 * @param pmLevel the map containing the level information
     50 * @param psService the service structure created from the zcfg file
     51 */
     52void addPrefix(maps* pmsConf,map* pmLevel,service* psService){
     53  if(pmLevel!=NULL){
     54    char acKey[25];
     55    char* pcaPrefix=NULL;
     56    int iClevel=atoi(pmLevel->value);
     57    int iCl=0;
     58    for(iCl=0;iCl<iClevel;iCl++){
     59      sprintf(acKey,"sprefix_%d",iCl);
     60      map* tmp2=getMapFromMaps(pmsConf,"lenv",acKey);
    6061      if(tmp2!=NULL){
    61         if(prefix==NULL)
    62           prefix=zStrdup(tmp2->value);
     62        if(pcaPrefix==NULL)
     63          pcaPrefix=zStrdup(tmp2->value);
    6364        else{
    64           int plen=strlen(prefix);
    65           prefix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char));
    66           memcpy(prefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char));
    67           prefix[plen+strlen(tmp2->value)]=0;
    68         }
    69       }
    70     }
    71     if(prefix!=NULL){
    72       char* tmp0=zStrdup(serv->name);
    73       free(serv->name);
    74       serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char));
    75       sprintf(serv->name,"%s%s",prefix,tmp0);
    76       free(tmp0);
    77       free(prefix);
    78       prefix=NULL;
     65          int plen=strlen(pcaPrefix);
     66          pcaPrefix=(char*)realloc(pcaPrefix,(plen+strlen(tmp2->value)+2)*sizeof(char));
     67          memcpy(pcaPrefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char));
     68          pcaPrefix[plen+strlen(tmp2->value)]=0;
     69        }
     70      }
     71    }
     72    if(pcaPrefix!=NULL){
     73      char* pcaTmp=zStrdup(psService->name);
     74      free(psService->name);
     75      psService->name=(char*)malloc((strlen(pcaPrefix)+strlen(pcaTmp)+1)*sizeof(char));
     76      sprintf(psService->name,"%s%s",pcaPrefix,pcaTmp);
     77      free(pcaTmp);
     78      free(pcaPrefix);
     79      pcaPrefix=NULL;
    7980    }
    8081  }
     
    8485 * Print the HTTP headers based on a map.
    8586 *
    86  * @param m the map containing the headers information
    87  */
    88 void printHeaders(maps* m){
    89   maps *_tmp=getMaps(m,"headers");
    90   if(_tmp!=NULL){
    91     map* _tmp1=_tmp->content;
    92     while(_tmp1!=NULL){
    93       printf("%s: %s\r\n",_tmp1->name,_tmp1->value);
    94       _tmp1=_tmp1->next;
    95     }
    96   }
    97   printSessionHeaders(m);
     87 * @param pmsConf the map containing the headers information
     88 */
     89void printHeaders(maps* pmsConf){
     90  maps *pmsTmp=getMaps(pmsConf,"headers");
     91  if(pmsTmp!=NULL){
     92    map* pmTmp=pmsTmp->content;
     93    while(pmTmp!=NULL){
     94      printf("%s: %s\r\n",pmTmp->name,pmTmp->value);
     95      pmTmp=pmTmp->next;
     96    }
     97  }
     98  printSessionHeaders(pmsConf);
    9899}
    99100
     
    104105 * The session file (sess_<SESSID>_.cfg where <SESSID> is the cookie value) is
    105106 * stored in the conf["main"]["tmpPath"] directory.
    106  * @param m the main configuration map
    107  */
    108 void printSessionHeaders(maps* m){
    109   maps* tmpSess=getMaps(m,"senv");
    110   if(tmpSess!=NULL){
    111     map *_tmp=getMapFromMaps(m,"lenv","cookie");
    112     maps *tmps=getMaps(m,"senv");
     107 * @param pmsConf the main configuration map
     108 */
     109void printSessionHeaders(maps* pmsConf){
     110  maps* pmsSess=getMaps(pmsConf,"senv");
     111  if(pmsSess!=NULL){
     112    map *pmTmp=getMapFromMaps(pmsConf,"lenv","cookie");
    113113    char* sessId=NULL;
    114     if(_tmp!=NULL){
    115       printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
    116       map *_tmp1=getMapFromMaps(m,"senv","ecookie_length");
    117       if(_tmp1!=NULL){
    118         int len=atoi(_tmp1->value);
     114    if(pmTmp!=NULL){
     115      printf("Set-Cookie: %s; HttpOnly\r\n",pmTmp->value);
     116      map *pmTmp1=getMapFromMaps(pmsConf,"senv","ecookie_length");
     117      if(pmTmp1!=NULL){
     118        int len=atoi(pmTmp1->value);
    119119        int cnt=0;
    120120        for(cnt=0;cnt<len;cnt++){
    121           map* _tmp2=getMapArray(tmps->content,"ecookie",cnt);
    122           if(_tmp2!=NULL)
    123             printf("Set-Cookie: %s; HttpOnly\r\n",_tmp2->value);
     121          map* pmTmp2=getMapArray(pmsSess->content,"ecookie",cnt);
     122          if(pmTmp2!=NULL)
     123            printf("Set-Cookie: %s; HttpOnly\r\n",pmTmp2->value);
    124124        }
    125125      }
    126126      printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
    127127      char session_file_path[100];
    128       char *tmp1=strtok(_tmp->value,";");
     128      char *tmp1=strtok(pmTmp->value,";");
    129129      if(tmp1!=NULL)
    130130        sprintf(session_file_path,"%s",strstr(tmp1,"=")+1);
    131131      else
    132         sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1);
     132        sprintf(session_file_path,"%s",strstr(pmTmp->value,"=")+1);
    133133      sessId=zStrdup(session_file_path);
    134134    }else{
    135       maps* t=getMaps(m,"senv");
     135      maps* t=getMaps(pmsConf,"senv");
    136136      map*p=t->content;
    137137      while(p!=NULL){
     
    144144    }
    145145    char session_file_path[1024];
    146     map *tmpPath=getMapFromMaps(m,"main","sessPath");
     146    map *tmpPath=getMapFromMaps(pmsConf,"main","sessPath");
    147147    if(tmpPath==NULL)
    148       tmpPath=getMapFromMaps(m,"main","tmpPath");
     148      tmpPath=getMapFromMaps(pmsConf,"main","tmpPath");
    149149    sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId);
    150150    FILE* teste=fopen(session_file_path,"w");
     
    152152      char tmpMsg[1024];
    153153      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
    154       errorException(m,tmpMsg,"InternalError",NULL);
     154      errorException(pmsConf,tmpMsg,"InternalError",NULL);
    155155      return;
    156156    }
    157157    else{
    158158      fclose(teste);
    159       dumpMapsToFile(tmpSess,session_file_path,1);
     159      dumpMapsToFile(pmsSess,session_file_path,1);
    160160    }
    161161  } 
     
    20962096            if(vid==0)
    20972097              printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
    2098             else
     2098            else 
    20992099              printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
    21002100          }     
     
    25352535
    25362536/**
     2537 * Produce the status string used in HTTP headers.
     2538 *
     2539 * @param pmConf the maps containing the settings of the main.cfg file
     2540 * @param pmCode the map containing the error code (or a map array of the same keys)
     2541 */
     2542const char* produceStatusString(maps* pmConf,map* pmCode){
     2543  if(pmCode!=NULL){
     2544    int iI=0;
     2545    for(iI=0;iI<3;iI++){
     2546      int iJ=0;
     2547      for(iJ=0;;iJ++){
     2548        if(aapccStatusCodes[iI][iJ]==NULL)
     2549          break;
     2550        else{
     2551          if(strcmp(aapccStatusCodes[iI][iJ],pmCode->value)==0)
     2552            return aapccStatusCodes[iI][0];
     2553        }
     2554      }
     2555    }
     2556  }
     2557  else{
     2558    return aapccStatusCodes[3][0];
     2559  }
     2560}
     2561
     2562/**
    25372563 * Print an OWS ExceptionReport Document and HTTP headers (when required)
    25382564 * depending on the code.
     
    25422568 * @param s the map containing the text,code,locator keys (or a map array of the same keys)
    25432569 */
    2544 void printExceptionReportResponse(maps* m,map* s){
    2545   if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
    2546     return;
     2570void _printExceptionReportResponse(maps* m,map* s){
    25472571  int buffersize;
    25482572  xmlDocPtr doc;
     
    25572581 
    25582582  map* tmp=getMap(s,"code");
    2559   if(tmp!=NULL){
    2560     if(strcmp(tmp->value,"OperationNotSupported")==0 ||
    2561        strcmp(tmp->value,"NoApplicableCode")==0)
    2562       exceptionCode="501 Not Implemented";
    2563     else
    2564       if(strcmp(tmp->value,"MissingParameterValue")==0 ||
    2565          strcmp(tmp->value,"InvalidUpdateSequence")==0 ||
    2566          strcmp(tmp->value,"OptionNotSupported")==0 ||
    2567          strcmp(tmp->value,"VersionNegotiationFailed")==0 ||
    2568          strcmp(tmp->value,"InvalidParameterValue")==0)
    2569         exceptionCode="400 Bad request";
    2570       else
    2571         exceptionCode="501 Internal Server Error";
    2572   }
    2573   else
    2574     exceptionCode="501 Internal Server Error";
     2583  exceptionCode=produceStatusString(m,tmp);
    25752584  tmp=getMapFromMaps(m,"lenv","status_code");
    25762585  if(tmp!=NULL)
     
    26012610  zooXmlCleanupNs();
    26022611  if(m!=NULL)
    2603     setMapInMaps(m,"lenv","hasPrinted","true");
     2612    setMapInMaps(m,"lenv","hasPrinted","true"); 
     2613}
     2614
     2615/**
     2616 * Print an OWS ExceptionReport or exception.yaml Document and HTTP headers
     2617 * (when required) depending on the code.
     2618 *
     2619 * @param pmsConf the maps containing the settings of the main.cfg file
     2620 * @param psService the service
     2621 */
     2622void printExceptionReportResponse(maps* pmsConf,map* psService){
     2623  if(getMapFromMaps(pmsConf,"lenv","hasPrinted")!=NULL)
     2624    return;
     2625  map* pmExecutionType=getMapFromMaps(pmsConf,"main","executionType");
     2626  if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0)
     2627    _printExceptionReportResponse(pmsConf,psService);
     2628  else
     2629    printExceptionReportResponseJ(pmsConf,psService);
    26042630}
    26052631
     
    26942720int errorException(maps *m, const char *message, const char *errorcode, const char *locator)
    26952721{
     2722  map* pmExectionType=getMapFromMaps(m,"main","executionType");
    26962723  map* errormap = createMap("text", message);
    26972724  addToMap(errormap,"code", errorcode);
     
    27002727  else
    27012728    addToMap(errormap,"locator", "NULL");
    2702   printExceptionReportResponse(m,errormap);
     2729  if(pmExectionType!=NULL && strncasecmp(pmExectionType->value,"xml",3)==0)
     2730    printExceptionReportResponse(m,errormap);
     2731  else{
     2732    printExceptionReportResponseJ(m,errormap);
     2733    setMapInMaps(m,"lenv","no-headers","true");
     2734  }
    27032735  freeMap(&errormap);
    27042736  free(errormap);
    27052737  return -1;
     2738}
     2739
     2740/**
     2741 * Produce a copy file and the corresponding url in case it is required
     2742 * Please, free the returned ressource while used
     2743 *
     2744 * @param pmConf maps* pointing to the main configuration file
     2745 */
     2746char* produceFileUrl(service* psService,maps* pmsConf,maps* pmsOutputs,const char* pccFormat, int itn){
     2747  // Create file for reference data if not existing
     2748  map *pmGFile=getMap(pmsOutputs->content,"generated_file");
     2749  map *pmTmpPath=getMapFromMaps(pmsConf,"main","tmpPath");
     2750  map *pmTmpUrl=getMapFromMaps(pmsConf,"main","tmpUrl");
     2751  char *pcaFileName=NULL;
     2752  char *pcaFilePath=NULL;
     2753  char *pcaFileUrl=NULL;
     2754  if(pmGFile!=NULL){
     2755    pmGFile=getMap(pmsOutputs->content,"expected_generated_file");
     2756    if(pmGFile==NULL){
     2757      pmGFile=getMap(pmsOutputs->content,"generated_file");
     2758    }
     2759    if(strstr(pmGFile->value,pmTmpPath->value)!=NULL)
     2760      pcaFileName=zStrdup(strstr(pmGFile->value,pmTmpPath->value)+strlen(pmTmpPath->value));
     2761  }
     2762  // Create file for reference data
     2763  map *pmUsid=getMapFromMaps(pmsConf,"lenv","usid");
     2764  map *pmExt=getMap(pmsOutputs->content,"extension");
     2765  if(pmGFile==NULL){
     2766    char acFileExt[32];     
     2767    if( pmExt != NULL && pmExt->value != NULL) {
     2768      strncpy(acFileExt, pmExt->value, 32);
     2769    }
     2770    else {
     2771      // Obtain default file extension (see mimetypes.h).             
     2772      // If the MIME type is not recognized, txt is used as the default extension
     2773      map* pmType=getMap(pmsOutputs->content,"mimeType");
     2774      getFileExtension(pmType != NULL ? pmType->value : NULL, acFileExt, 32);
     2775    }
     2776    if(pcaFileName!=NULL)
     2777      free(pcaFileName);
     2778             
     2779    pcaFileName=(char*)malloc((strlen(psService->name)+strlen(pmUsid->value)+strlen(acFileExt)+strlen(pmsOutputs->name)+45)*sizeof(char));
     2780    sprintf(pcaFileName,"ZOO_DATA_%s_%s_%s_%d.%s",psService->name,pmsOutputs->name,pmUsid->value,itn,acFileExt);
     2781
     2782    pcaFilePath=(char*)malloc((strlen(pmTmpPath->value)+strlen(pcaFileName)+2)*sizeof(char));
     2783    sprintf(pcaFilePath,"%s/%s",pmTmpPath->value,pcaFileName);
     2784  }else{
     2785    pcaFilePath=(char*)malloc((strlen(pmGFile->value)+1)*sizeof(char));
     2786    sprintf(pcaFilePath,"%s",pmGFile->value);
     2787  }
     2788 
     2789  pcaFileUrl=(char*)malloc((strlen(pmTmpUrl->value)+
     2790                          strlen(pcaFileName)+2)*sizeof(char));
     2791  sprintf(pcaFileUrl,"%s/%s",pmTmpUrl->value,pcaFileName);
     2792
     2793  if(pmGFile==NULL) {
     2794    FILE *pfOfile=fopen(pcaFilePath,"wb");
     2795    if(pfOfile==NULL){
     2796      char acTmpMsg[1024];
     2797      sprintf(acTmpMsg,
     2798              _("Unable to create the file \"%s\" for storing the %s final result."),
     2799              pcaFileName,pmsOutputs->name);
     2800      map* pmError=createMap("code","InternalError");
     2801      addToMap(pmError,"message",acTmpMsg);
     2802      printExceptionReportResponseJ(pmsConf,pmError);
     2803      free(pcaFileName);
     2804      free(pcaFilePath);
     2805      return NULL;
     2806    }
     2807
     2808    map* pmValue=getMap(pmsOutputs->content,"value");
     2809    if(pmValue==NULL){
     2810      char acTmpMsg[1024];
     2811      sprintf(acTmpMsg,
     2812              _("No value found for the requested output %s."),
     2813              pmsOutputs->name);
     2814      map* pmError=createMap("code","InternalError");
     2815      addToMap(pmError,"message",acTmpMsg);
     2816      printExceptionReportResponseJ(pmsConf,pmError);
     2817      fclose(pfOfile);
     2818      free(pcaFileName);
     2819      free(pcaFilePath);
     2820      return NULL;
     2821    }
     2822    if(pccFormat==NULL || strcasecmp(pccFormat,"BoundingBoxData")!=0){
     2823      map* size=getMap(pmsOutputs->content,"size");
     2824      if(size!=NULL && pmValue!=NULL)
     2825        fwrite(pmValue->value,1,(atoi(size->value))*sizeof(char),pfOfile);
     2826      else
     2827        if(pmValue!=NULL && pmValue->value!=NULL)
     2828          fwrite(pmValue->value,1,
     2829                 strlen(pmValue->value)*sizeof(char),pfOfile);
     2830    }else
     2831      printBoundingBoxDocument(pmsConf,pmsOutputs,pfOfile);
     2832    fclose(pfOfile);
     2833  }
     2834  free(pcaFileName);
     2835  free(pcaFilePath);
     2836  return pcaFileUrl;
    27062837}
    27072838
     
    27242855  fprintf(stderr,"printProcessResponse\n");
    27252856#endif 
    2726   map* toto=getMap(request_inputs1,"RawDataOutput");
     2857  map* pmRawData=getMap(request_inputs1,"RawDataOutput");
    27272858  int asRaw=0;
    2728   if(toto!=NULL)
     2859  if(pmRawData!=NULL)
    27292860    asRaw=1;
    27302861  map* version=getMapFromMaps(m,"main","rversion");
     
    27762907      map* testMap=getMap(tmpI->content,"useMapserver");       
    27772908#endif
    2778       map *gfile=getMap(tmpI->content,"generated_file");
     2909      /*map *gfile=getMap(tmpI->content,"generated_file");
    27792910      char *file_name=NULL;       
    27802911      if(gfile!=NULL){
     
    27852916        readGeneratedFile(m,tmpI->content,gfile->value);
    27862917        file_name=zStrdup((gfile->value)+strlen(tmp1->value));
    2787       }   
    2788       toto=getMap(tmpI->content,"asReference");
     2918        }*/
     2919      char *pcaFileUrl=NULL;
     2920      pmRawData=getMap(tmpI->content,"asReference");
    27892921#ifdef USE_MS
    27902922      map* geodatatype=getMap(tmpI->content,"geodatatype");
    2791       if(toto!=NULL && strcasecmp(toto->value,"true")==0 &&
     2923      if(pmRawData!=NULL && strcasecmp(pmRawData->value,"true")==0 &&
    27922924         (testMap==NULL ||
    27932925          strncasecmp(testMap->value,"true",4)!=0 ||
    27942926          (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) ) )
    27952927#else
    2796         if(toto!=NULL && strcasecmp(toto->value,"true")==0)
     2928        if(pmRawData!=NULL && strcasecmp(pmRawData->value,"true")==0)
    27972929#endif
    27982930          {             
     
    28112943              addToMap(tmpI->content,"encoding","UTF-8");
    28122944              addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
    2813             }           
    2814             char *file_path=NULL;
    2815             if(gfile==NULL) {
    2816               map *ext=getMap(tmpI->content,"extension");
    2817               char file_ext[32];
    2818            
    2819               if( ext != NULL && ext->value != NULL) {
    2820                 strncpy(file_ext, ext->value, 32);
    2821               }
    2822               else {
    2823                 // Obtain default file extension (see mimetypes.h).           
    2824                 // If the MIME type is not recognized, txt is used as the default extension
    2825                 map* mtype=getMap(tmpI->content,"mimeType");
    2826                 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
    2827               }
    2828               if(file_name!=NULL)
    2829                 free(file_name);
    2830               file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
    2831               sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
    2832               itn++;
    2833               file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
    2834               sprintf(file_path,"%s/%s",tmp1->value,file_name);
    2835 
    2836               FILE *ofile=fopen(file_path,"wb");
    2837               if(ofile==NULL){
    2838                 char tmpMsg[1024];
    2839                 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
    2840                 errorException(m,tmpMsg,"InternalError",NULL);
    2841                 free(file_name);
    2842                 free(file_path);
    2843                 return;
    2844               }
    2845 
    2846               toto=getMap(tmpI->content,"value");
    2847               if(toto==NULL){
    2848                 char tmpMsg[1024];
    2849                 sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name);
    2850                 errorException(m,tmpMsg,"InternalError",NULL);
    2851                 fclose(ofile);
    2852                 free(file_name);
    2853                 free(file_path);
    2854                 return;
    2855               }
    2856               if(strcasecmp(format,"BoundingBoxData")!=0){
    2857                 map* size=getMap(tmpI->content,"size");
    2858                 if(size!=NULL && toto!=NULL)
    2859                   fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
    2860                 else
    2861                   if(toto!=NULL && toto->value!=NULL)
    2862                     fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
    2863               }else{
    2864                 printBoundingBoxDocument(m,tmpI,ofile);
    2865               }
    2866               fclose(ofile);
    28672945            }
    2868 
    2869             map *tmp2=getMapFromMaps(m,"main","tmpUrl");
    2870             map *tmp3=getMapFromMaps(m,"main","serverAddress");
    2871             char *file_url=NULL;
    2872             if(strncasecmp(tmp2->value,"http://",7)==0 ||
    2873                strncasecmp(tmp2->value,"https://",8)==0){
    2874               file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
    2875               sprintf(file_url,"%s/%s",tmp2->value,file_name);
    2876             }else{
    2877               file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
    2878               sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
    2879             }
    2880             addToMap(tmpI->content,"Reference",file_url);
    2881             if(file_name!=NULL)
    2882               free(file_name);
    2883             if(file_url!=NULL)
    2884               free(file_url);
    2885             file_name=NULL;
     2946            pcaFileUrl=produceFileUrl(s,m,tmpI,format,itn);
     2947            itn++;
     2948            if(pcaFileUrl==NULL)
     2949              return;
     2950            addToMap(tmpI->content,"Reference",pcaFileUrl);
    28862951          }
    28872952#ifdef USE_MS
     
    29012966        }
    29022967#endif 
    2903       if(file_name!=NULL){
    2904         free(file_name);
    2905         file_name=NULL;
     2968      if(pcaFileUrl!=NULL){
     2969        free(pcaFileUrl);
     2970        pcaFileUrl=NULL;
    29062971      }
    29072972      tmpI=tmpI->next;
     
    29473012      printBoundingBoxDocument(m,tmpI,NULL);
    29483013    }else{
    2949       map *gfile=getMap(tmpI->content,"generated_file");
    2950       if(gfile!=NULL){
    2951         gfile=getMap(tmpI->content,"expected_generated_file"); 
    2952         if(gfile==NULL){
    2953           gfile=getMap(tmpI->content,"generated_file");
    2954         }
    2955         readGeneratedFile(m,tmpI->content,gfile->value);
    2956       }
    2957       toto=getMap(tmpI->content,"value");       
    2958       if(toto==NULL){
    2959         char tmpMsg[1024];
    2960         sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name);
    2961         errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
    2962         return;
    2963       }   
    2964       map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");             
    2965       if(fname!=NULL)
    2966         printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
    2967       map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
    2968       if(rs!=NULL)
    2969         printf("Content-Length: %s\r\n",rs->value);
    2970       printHeaders(m);
    2971       char mime[1024];
    2972       map* mi=getMap(tmpI->content,"mimeType");
    2973 #ifdef DEBUG
    2974       fprintf(stderr,"SERVICE OUTPUTS\n");
    2975       dumpMaps(request_outputs);
    2976       fprintf(stderr,"SERVICE OUTPUTS\n");
    2977 #endif
    2978       map* en=getMap(tmpI->content,"encoding");
    2979       if(mi!=NULL && en!=NULL)
    2980         sprintf(mime,
    2981                 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
    2982                 mi->value,en->value);
    2983       else
    2984         if(mi!=NULL)
    2985           sprintf(mime,
    2986                   "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
    2987                   mi->value);
    2988         else
    2989           sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
    2990       printf("%s",mime);
    2991       if(rs!=NULL)
    2992         fwrite(toto->value,1,atoi(rs->value),stdout);
    2993       else
    2994         fwrite(toto->value,1,strlen(toto->value),stdout);
    2995 #ifdef DEBUG
    2996       dumpMap(toto);
    2997 #endif
    2998     }
    2999   }
     3014      printRawdataOutput(m,tmpI);
     3015    }
     3016  }
     3017}
     3018
     3019/**
     3020 * Print one outputs as raw
     3021 *
     3022 * @param conf the main configuration maps
     3023 * @param outputs the output to be print as raw
     3024 */
     3025void* printRawdataOutput(maps* conf,maps* outputs){
     3026  map *gfile=getMap(outputs->content,"generated_file");
     3027  if(gfile!=NULL){
     3028    gfile=getMap(outputs->content,"expected_generated_file");
     3029    if(gfile==NULL){
     3030      gfile=getMap(outputs->content,"generated_file");
     3031    }
     3032    readGeneratedFile(conf,outputs->content,gfile->value);
     3033  }
     3034  map* toto=getMap(outputs->content,"value");
     3035  if(toto==NULL){
     3036    char tmpMsg[1024];
     3037    sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),outputs->name);
     3038    map* pmExecutionType=getMapFromMaps(conf,"main","executionType");
     3039    if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0)
     3040      errorException(conf,tmpMsg,"InvalidParameterValue","RawDataOutput");
     3041    else{
     3042      setMapInMaps(conf,"lenv","error","true");
     3043      setMapInMaps(conf,"lenv","code","InvalidParameterValue");
     3044      setMapInMaps(conf,"lenv","message",tmpMsg);
     3045    }
     3046    return NULL;
     3047  }
     3048  map* fname=getMapFromMaps(outputs,outputs->name,"filename");           
     3049  if(fname!=NULL)
     3050    printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
     3051  map* rs=getMapFromMaps(outputs,outputs->name,"size");
     3052  if(rs!=NULL)
     3053    printf("Content-Length: %s\r\n",rs->value);
     3054  char mime[1024];
     3055  map* mi=getMap(outputs->content,"mimeType");
     3056  map* en=getMap(outputs->content,"encoding");
     3057  if(mi!=NULL && en!=NULL)
     3058    sprintf(mime,
     3059            "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
     3060            mi->value,en->value);
     3061  else
     3062    if(mi!=NULL)
     3063      sprintf(mime,
     3064              "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
     3065              mi->value);
     3066    else
     3067      sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
     3068  printf("%s",mime);
     3069  if(rs!=NULL)
     3070    fwrite(toto->value,1,atoi(rs->value),stdout);
     3071  else
     3072    fwrite(toto->value,1,strlen(toto->value),stdout);   
    30003073}
    30013074
  • trunk/zoo-project/zoo-kernel/response_print.h

    r966 r967  
    194194  };
    195195
     196
     197  static const char* const aapccStatusCodes[][8] = {
     198    {
     199      "500 Not Implemented",
     200      "OperationNotSupported",
     201      "NoApplicableCode",
     202      NULL
     203    },
     204    {
     205      "400 Bad request",
     206      "MissingParameterValue"
     207      "InvalidParameterValue",
     208      "InvalidUpdateSequence",
     209      "OptionNotSupported",
     210      "VersionNegotiationFailed",
     211      "NoSuchMode",
     212      NULL
     213    },
     214    {
     215      "404 Not Found",
     216      "NotFound",
     217      "NoSuchProcess",
     218      "NoSuchJob",
     219      "ResultNotReady",
     220      NULL
     221    },
     222    {
     223      "500 Not Implemented",
     224      NULL
     225    }
     226  };
     227 
    196228  void addLangAttr(xmlNodePtr,maps*);
    197229
     
    205237  int zooXmlAddDoc(xmlNodePtr,const char*,const char*);
    206238  void zooXmlCleanupDocs();
    207  
     239
     240  const char* produceStatusString(maps*,map*);
    208241  void printExceptionReportResponse(maps*,map*);
    209242  xmlNodePtr createExceptionReportNode(maps*,map*,int);
     
    217250  void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int);
    218251  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*,int);
     252  void* printRawdataOutput(maps*,maps*);
    219253  map* parseBoundingBox(const char*);
    220254  void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
     
    225259  void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
    226260
     261  char* produceFileUrl(service*,maps*,maps*,const char*, int);
    227262  void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
    228263
  • trunk/zoo-project/zoo-kernel/server_internal.c

    r962 r967  
    377377  sprintf(rsize,"%lld",f_status.st_size);
    378378  if(getMap(content,"storage")==NULL){
    379     map* memUse=getMapFromMaps(m,"main","memory");
    380     if(memUse==NULL || strncmp(memUse->value,"load",4)==0){
    381       map* tmpMap1=getMap(content,"value");
    382       if(tmpMap1==NULL){
    383         addToMap(content,"value","");
    384         tmpMap1=getMap(content,"value");
    385       }
    386       free(tmpMap1->value);
    387       tmpMap1->value=(char*) malloc((f_status.st_size+1)*sizeof(char));
    388       if(tmpMap1->value==NULL){
    389         setMapInMaps(m,"lenv","message","Unable to allocate the memory required to read the produced file.");
    390         return;
    391       }
    392       fread(&tmpMap1->value,1,f_status.st_size,file);
    393       tmpMap1->value[f_status.st_size]=0;
    394     }
     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((f_status.st_size+1)*sizeof(char));
     386    if(tmpMap1->value==NULL){
     387      setMapInMaps(m,"lenv","message","Unable to allocate the memory required to read the produced file.");
     388      return;
     389    }
     390    fread(tmpMap1->value,1,f_status.st_size,file);
     391    tmpMap1->value[f_status.st_size]=0;
    395392  }
    396393  fclose(file);
     
    994991void runGetStatus(maps* conf,char* pid,char* req){
    995992  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
    996   map* e_type = getMapFromMaps (conf, "lenv", "executionType");
     993  map* e_type = getMapFromMaps (conf, "main", "executionType");
    997994  char *sid=getStatusId(conf,pid);
    998995  if(sid==NULL){
     
    11011098void runDismiss(maps* conf,char* pid){
    11021099  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
    1103   map* e_type = getMapFromMaps (conf, "lenv", "executionType");
     1100  map* e_type = getMapFromMaps (conf, "main", "executionType");
    11041101  char *sid=getStatusId(conf,pid);
    11051102  if(sid==NULL){
  • trunk/zoo-project/zoo-kernel/service.c

    r961 r967  
    3939 * See https://dxr.mozilla.org/mozilla-central/source/media/mtransport/third_party/nrappkit/src/util/util.c
    4040 */
    41 int snprintf(char *buffer, size_t n, const char *format, ...)
     41int snprintf(char *pcBuffer, size_t n, const char *pccFormat, ...)
    4242{
    4343  va_list argp;
    4444  int ret;
    45   va_start(argp, format);
    46   ret = _vscprintf(format, argp);
    47   vsnprintf_s(buffer, n, _TRUNCATE, format, argp);
     45  va_start(argp, pccFormat);
     46  ret = _vscprintf(pccFormat, argp);
     47  vsnprintf_s(pcBuffer, n, _TRUNCATE, pccFormat, argp);
    4848  va_end(argp);
    4949  return ret;
     
    5454 * Dump a map on stderr
    5555 *
    56  * @param t the map to dump
    57  */
    58 void _dumpMap(map* t){
    59   if(t!=NULL){
    60     fprintf(stderr,"%s: %s\n",t->name,t->value);
     56 * @param pmMap the map to dump
     57 */
     58void _dumpMap(map* pmMap){
     59  if(pmMap!=NULL){
     60    fprintf(stderr,"%s: %s\n",pmMap->name,pmMap->value);
    6161    fflush(stderr);
    6262  }else{
     
    6969 * Dump a map on stderr, see _dumpMap()
    7070 *
    71  * @param t the map to dump
    72  */
    73 void dumpMap(map* t){
    74   map* tmp=t;
    75   while(tmp!=NULL){
    76     _dumpMap(tmp);
    77     tmp=tmp->next;
     71 * @param pmMap the map to dump
     72 */
     73void dumpMap(map* pmMap){
     74  map* pmTmp=pmMap;
     75  while(pmTmp!=NULL){
     76    _dumpMap(pmTmp);
     77    pmTmp=pmTmp->next;
    7878  }
    7979}
     
    8282 * Dump a map to a file
    8383 *
    84  * @param t the map to dump to file
    85  * @param file the file pointer to store the map
    86  */
    87 void dumpMapToFile(map* t,FILE* file){
    88   map* tmp=t;
    89   while(tmp!=NULL){
    90     fprintf(file,"%s = %s\n",tmp->name,tmp->value);
    91     tmp=tmp->next;
     84 * @param pmMap the map to dump to file
     85 * @param pfFile the file pointer to store the map
     86 */
     87void dumpMapToFile(map* pmMap,FILE* pfFile){
     88  map* pmTmp=pmMap;
     89  while(pmTmp!=NULL){
     90    fprintf(pfFile,"%s = %s\n",pmTmp->name,pmTmp->value);
     91    pmTmp=pmTmp->next;
    9292  }
    9393}
     
    9696 * Dump a maps on stderr, see dumpMap().
    9797 *
    98  * @param m the map to dump
    99  */
    100 void dumpMaps(maps* m){
    101   maps* tmp=m;
    102   while(tmp!=NULL){
    103     fprintf(stderr,"MAP => [%s] \n",tmp->name);
    104     fprintf(stderr," * CONTENT [%s] \n",tmp->name);
    105     dumpMap(tmp->content);
    106     if(tmp->child!=NULL){
    107       fprintf(stderr," * CHILD [%s] \n",tmp->name);
    108       dumpMaps(tmp->child);
    109       fprintf(stderr," * /CHILD [%s] \n",tmp->name);
    110     }
    111     tmp=tmp->next;
     98 * @param pmMap the map to dump
     99 */
     100void dumpMaps(maps* pmMap){
     101  maps* pmTmp=pmMap;
     102  while(pmTmp!=NULL){
     103    fprintf(stderr,"MAP => [%s] \n",pmTmp->name);
     104    fprintf(stderr," * CONTENT [%s] \n",pmTmp->name);
     105    dumpMap(pmTmp->content);
     106    if(pmTmp->child!=NULL){
     107      fprintf(stderr," * CHILD [%s] \n",pmTmp->name);
     108      dumpMaps(pmTmp->child);
     109      fprintf(stderr," * /CHILD [%s] \n",pmTmp->name);
     110    }
     111    pmTmp=pmTmp->next;
    112112  }
    113113}
     
    116116 * Dump a maps to a file, see dumpMapToFile().
    117117 *
    118  * @param m the map to dump
    119  * @param file the the file pointer to store the map
    120  */
    121 void _dumpMapsToFile(maps* m,FILE* file,int limit){
    122   maps* tmp=m;
     118 * @param pmsMaps the map to dump
     119 * @param psFile the the file pointer to store the map
     120 * @param iLimit the number of maps to print (0 for no limit)
     121 */
     122void _dumpMapsToFile(maps* pmsMaps,FILE* psFile,int iLimit){
     123  maps* tmp=pmsMaps;
    123124  int cnt=0;
    124125  while(tmp!=NULL){
    125     fprintf(file,"[%s]\n",tmp->name);
     126    fprintf(psFile,"[%s]\n",tmp->name);
    126127    if(tmp->child!=NULL){
    127       _dumpMapsToFile(tmp->child,file,limit);
     128      _dumpMapsToFile(tmp->child,psFile,iLimit);
    128129    }else
    129       dumpMapToFile(tmp->content,file);
    130     fflush(file);
     130      dumpMapToFile(tmp->content,psFile);
     131    fflush(psFile);
    131132    tmp=tmp->next;
    132133    cnt++;
    133     if(limit>=0 && cnt==limit)
     134    if(iLimit>=0 && cnt==iLimit)
    134135      tmp=NULL;
    135136  }
    136   fflush(file);
     137  fflush(psFile);
    137138}
    138139
     
    140141 * Dump a maps to a file, see _dumpMapsToFile().
    141142 *
    142  * @param m the map to dump
    143  * @param file_path the full path to the file name to store the map
    144  * @param limit the number limiting the maps to be dumped
    145  */
    146 void dumpMapsToFile(maps* m,char* file_path,int limit){
    147   FILE* file=fopen(file_path,"w+");
    148   _dumpMapsToFile(m,file,limit);
    149   fflush(file);
    150   fclose(file);
     143 * @param pmsMaps the map to dump
     144 * @param pcaFilePath the the file pointer to store the map
     145 * @param iLimit the number of maps to print (0 for no limit)
     146 */
     147void dumpMapsToFile(maps* pmsMaps,char* pcaFilePath,int iLimit){
     148  FILE* psFile=fopen(pcaFilePath,"w+");
     149  _dumpMapsToFile(pmsMaps,psFile,iLimit);
     150  fflush(psFile);
     151  fclose(psFile);
    151152}
    152153
     
    157158 */
    158159iotype* createIoType(){
    159   iotype* io=(iotype*)malloc(IOTYPE_SIZE);
    160   io->content=NULL;
    161   io->next=NULL;
    162   return io;
     160  iotype* pioIO=(iotype*)malloc(IOTYPE_SIZE);
     161  pioIO->content=NULL;
     162  pioIO->next=NULL;
     163  return pioIO;
    163164}
    164165
     
    166167 * Create a new map
    167168 *
    168  * @param name the key to add to the map
    169  * @param value the corresponding value to add to the map
     169 * @param pccName the key to add to the map
     170 * @param pccValue the corresponding value to add to the map
    170171 * @return a pointer to the allocated map
    171172 */
    172 map* createMap(const char* name,const char* value){
    173   map* tmp=(map *)malloc(MAP_SIZE);
    174   tmp->name=zStrdup(name);
    175   tmp->value=zStrdup(value);
    176   tmp->next=NULL;
    177   return tmp;
     173map* createMap(const char* pccName,const char* pccValue){
     174  map* pmTtmp=(map *)malloc(MAP_SIZE);
     175  pmTtmp->name=zStrdup(pccName);
     176  pmTtmp->value=zStrdup(pccValue);
     177  pmTtmp->next=NULL;
     178  return pmTtmp;
    178179}
    179180
     
    181182 * Create a new maps with the given name
    182183 *
    183  * @param name of the maps
     184 * @param pccName of the maps
    184185 * @return the allocated map
    185186 */
    186 maps* createMaps(const char* name){
    187   maps* tmp = (maps *) malloc (MAPS_SIZE);
    188   tmp->name = zStrdup (name);
    189   tmp->content = NULL;
    190   tmp->child = NULL;
    191   tmp->next = NULL;
    192   return tmp;
     187maps* createMaps(const char* pccName){
     188  maps* pmTmp = (maps *) malloc (MAPS_SIZE);
     189  pmTmp->name = zStrdup (pccName);
     190  pmTmp->content = NULL;
     191  pmTmp->child = NULL;
     192  pmTmp->next = NULL;
     193  return pmTmp;
    193194}
    194195
     
    196197 * Count number of map in a map
    197198 *
    198  * @param m the map to count
     199 * @param pmMap the map to count
    199200 * @return number of map in a map
    200201 */
    201 int count(map* m){
    202   map* tmp=m;
     202int count(map* pmMap){
     203  map* pmTmp=pmMap;
    203204  int c=0;
    204   while(tmp!=NULL){
     205  while(pmTmp!=NULL){
    205206    c++;
    206     tmp=tmp->next;
     207    pmTmp=pmTmp->next;
    207208  }
    208209  return c;
     
    212213 * Count number of maps in a maps
    213214 *
    214  * @param m the maps to count
     215 * @param pmMap the maps to count
    215216 * @return number of maps in a maps
    216217 */
    217 int maps_length(maps* m){
    218   maps* tmp=m;
     218int maps_length(maps* pmMap){
     219  maps* pmTmp=pmMap;
    219220  int c=0;
    220   while(tmp!=NULL){
     221  while(pmTmp!=NULL){
    221222    c++;
    222     tmp=tmp->next;
     223    pmTmp=pmTmp->next;
    223224  }
    224225  return c;
     
    228229 * Verify if a key exist in a map
    229230 *
    230  * @param m the map to search for the key
    231  * @param key the key to search in the map
     231 * @param pmMap the map to search for the key
     232 * @param pccKey the key to search in the map
    232233 * @return true if the key wwas found, false in other case
    233234 */
    234 bool hasKey(map* m,const char *key){
    235   map* tmp=m;
    236   while(tmp!=NULL){
    237     if(strcasecmp(tmp->name,key)==0)
     235bool hasKey(map* pmMap,const char *pccKey){
     236  map* pmTmp=pmMap;
     237  while(pmTmp!=NULL){
     238    if(strcasecmp(pmTmp->name,pccKey)==0)
    238239      return true;
    239     tmp=tmp->next;
     240    pmTmp=pmTmp->next;
    240241  }
    241242#ifdef DEBUG_MAP
     
    248249 * Access a specific maps
    249250 *
    250  * @param m the maps to search for the key
    251  * @param key the key to search in the maps
     251 * @param pmMap the maps to search for the key
     252 * @param pccKey the key to search in the maps
    252253 * @return a pointer on the maps found or NULL if not found
    253254 */
    254 maps* getMaps(maps* m,const char *key){
    255   maps* tmp=m;
    256   while(tmp!=NULL){
    257     if(strcasecmp(tmp->name,key)==0){
    258       return tmp;
    259     }
    260     tmp=tmp->next;
     255maps* getMaps(maps* pmsMaps,const char *pccKey){
     256  maps* pmTmp=pmsMaps;
     257  while(pmTmp!=NULL){
     258    if(strcasecmp(pmTmp->name,pccKey)==0){
     259      return pmTmp;
     260    }
     261    pmTmp=pmTmp->next;
    261262  }
    262263  return NULL;
     
    266267 * Access a specific map
    267268 *
    268  * @param m the map to search for the key
    269  * @param key the key to search in the map
     269 * @param pmMap the map to search for the key
     270 * @param pccKey the key to search in the map
    270271 * @return a pointer on the map found or NULL if not found
    271272 */
    272 map* getMap(map* m,const char *key){
    273   map* tmp=m;
    274   while(tmp!=NULL){
    275     if(strcasecmp(tmp->name,key)==0){
    276       return tmp;
    277     }
    278     tmp=tmp->next;
     273map* getMap(map* pmMap,const char *pccKey){
     274  map* pmTmp=pmMap;
     275  while(pmTmp!=NULL){
     276    if(strcasecmp(pmTmp->name,pccKey)==0){
     277      return pmTmp;
     278    }
     279    pmTmp=pmTmp->next;
    279280  }
    280281  return NULL;
     
    285286 * Access the last map
    286287 *
    287  * @param m the map to search for the lastest map
     288 * @param pmMap the map to search for the lastest map
    288289 * @return a pointer on the lastest map found or NULL if not found
    289290 */
    290 map* getLastMap(map* m){
    291   map* tmp=m;
    292   while(tmp!=NULL){
    293     if(tmp->next==NULL){
    294       return tmp;
    295     }
    296     tmp=tmp->next;
     291map* getLastMap(map* pmMap){
     292  map* pmTmp=pmMap;
     293  while(pmTmp!=NULL){
     294    if(pmTmp->next==NULL){
     295      return pmTmp;
     296    }
     297    pmTmp=pmTmp->next;
    297298  }
    298299  return NULL;
     
    302303 * Access a specific map from a maps
    303304 *
    304  * @param m the maps to search for the key
    305  * @param key the key to search in the maps
    306  * @param subkey the key to search in the map (found for the key, if any)
     305 * @param pmMap the maps to search for the key
     306 * @param pccKey the key to search in the maps
     307 * @param pccSubkey the key to search in the map (found for the key, if any)
    307308 * @return a pointer on the map found or NULL if not found
    308309 */
    309 map* getMapFromMaps(maps* m,const char* key,const char* subkey){
    310   maps* _tmpm=getMaps(m,key);
    311   if(_tmpm!=NULL){
    312     map* _ztmpm=getMap(_tmpm->content,subkey);
    313     return _ztmpm;
     310map* getMapFromMaps(maps* pmMap,const char* pccKey,const char* pccSubkey){
     311  maps* pmTmp=getMaps(pmMap,pccKey);
     312  if(pmTmp!=NULL){
     313    map* pmTmp1=getMap(pmTmp->content,pccSubkey);
     314    return pmTmp1;
    314315  }
    315316  else return NULL;
     
    320321 * Require to call free on mo after calling this function.
    321322 *
    322  * @param mo the map to free
    323  */
    324 void freeMap(map** mo){
    325   map* _cursor=*mo;
    326   if(_cursor!=NULL){
     323 * @param pmMap the map to free
     324 */
     325void freeMap(map** pmMap){
     326  map* pmCursor=*pmMap;
     327  if(pmCursor!=NULL){
    327328#ifdef DEBUG
    328329    fprintf(stderr,"freeMap\n");
    329330#endif
    330     if(_cursor->name!=NULL)
    331       free(_cursor->name);
    332     if(_cursor->value!=NULL)
    333       free(_cursor->value);
    334     if(_cursor->next!=NULL){
    335       freeMap(&_cursor->next);
    336       if(_cursor->next!=NULL)
    337         free(_cursor->next);
     331    if(pmCursor->name!=NULL)
     332      free(pmCursor->name);
     333    if(pmCursor->value!=NULL)
     334      free(pmCursor->value);
     335    if(pmCursor->next!=NULL){
     336      freeMap(&pmCursor->next);
     337      if(pmCursor->next!=NULL)
     338        free(pmCursor->next);
    338339    }
    339340  }
     
    344345 * Require to call free on mo after calling this function.
    345346 *
    346  * @param mo the maps to free
    347  */
    348 void freeMaps(maps** mo){
    349   maps* _cursor=*mo;
    350   if(_cursor && _cursor!=NULL){
     347 * @param pmMap the maps to free
     348 */
     349void freeMaps(maps** pmMap){
     350  maps* pmCursor=*pmMap;
     351  if(pmCursor && pmCursor!=NULL){
    351352#ifdef DEBUG
    352353    fprintf(stderr,"freeMaps\n");
    353354#endif
    354     free(_cursor->name);
    355     if(_cursor->content!=NULL){
    356       freeMap(&_cursor->content);
    357       free(_cursor->content);
    358     }
    359     if(_cursor->child!=NULL){
    360       freeMaps(&_cursor->child);
    361       free(_cursor->child);
    362     }
    363     if(_cursor->next!=NULL){
    364       freeMaps(&_cursor->next);
    365       free(_cursor->next);
     355    free(pmCursor->name);
     356    if(pmCursor->content!=NULL){
     357      freeMap(&pmCursor->content);
     358      free(pmCursor->content);
     359    }
     360    if(pmCursor->child!=NULL){
     361      freeMaps(&pmCursor->child);
     362      free(pmCursor->child);
     363    }
     364    if(pmCursor->next!=NULL){
     365      freeMaps(&pmCursor->next);
     366      free(pmCursor->next);
    366367    }
    367368  }
     
    371372 * Verify if an elements contains a name equal to the given key.
    372373 *
    373  * @param e the elements to search for the key
    374  * @param key the elements name to search
     374 * @param peElem the elements to search for the key
     375 * @param pccKey the elements name to search
    375376 * @return true if the elements contains the name, false in other cases.
    376377 */
    377 bool hasElement(elements* e,const char* key){
    378   elements* tmp=e;
    379   while(tmp!=NULL){
    380     if(strcasecmp(key,tmp->name)==0)
     378bool hasElement(elements* peElem,const char* pccKey){
     379  elements* peTmp=peElem;
     380  while(peTmp!=NULL){
     381    if(strcasecmp(pccKey,peTmp->name)==0)
    381382      return true;
    382     tmp=tmp->next;
     383    peTmp=peTmp->next;
    383384  }
    384385  return false;
     
    388389 * Access a specific elements named key.
    389390 *
    390  * @param m the elements to search
    391  * @param key the elements name to search
     391 * @param peElem the elements to search
     392 * @param pccKey the elements name to search
    392393 * @return a pointer to the specific element if found, NULL in other case.
    393394 */
    394 elements* getElements(elements* m,const char *key){
    395   elements* tmp=m;
    396   while(tmp!=NULL){
    397     if(strcasecmp(tmp->name,key)==0)
    398       return tmp;
    399     tmp=tmp->next;
     395elements* getElements(elements* peElem,const char *pccKey){
     396  elements* peTmp=peElem;
     397  while(peTmp!=NULL){
     398    if(strcasecmp(peTmp->name,pccKey)==0)
     399      return peTmp;
     400    peTmp=peTmp->next;
    400401  }
    401402  return NULL;
     
    406407 * Require to call free on i after calling this function.
    407408 *
    408  * @param i the iotype to free
    409  */
    410 void freeIOType(iotype** i){
    411   iotype* _cursor=*i;
    412   if(_cursor!=NULL){
    413     if(_cursor->next!=NULL){
    414       freeIOType(&_cursor->next);
    415       free(_cursor->next);
    416     }
    417     freeMap(&_cursor->content);
    418     free(_cursor->content);
     409 * @param piotIO the iotype to free
     410 */
     411void freeIOType(iotype** piotIO){
     412  iotype* piotCursor=*piotIO;
     413  if(piotCursor!=NULL){
     414    if(piotCursor->next!=NULL){
     415      freeIOType(&piotCursor->next);
     416      free(piotCursor->next);
     417    }
     418    freeMap(&piotCursor->content);
     419    free(piotCursor->content);
    419420  }
    420421}
     
    424425 * Require to call free on e after calling this function.
    425426 *
    426  * @param e the iotype to free
    427  */
    428 void freeElements(elements** e){
    429   elements* tmp=*e;
    430   if(tmp!=NULL){
    431     if(tmp->name!=NULL)
    432       free(tmp->name);
    433     freeMap(&tmp->content);
    434     if(tmp->content!=NULL)
    435       free(tmp->content);
    436     freeMap(&tmp->metadata);
    437     if(tmp->metadata!=NULL)
    438       free(tmp->metadata);
    439     freeMap(&tmp->additional_parameters);
    440     if(tmp->additional_parameters!=NULL)
    441       free(tmp->additional_parameters);
    442     if(tmp->format!=NULL)
    443       free(tmp->format);
    444     freeElements(&tmp->child);
    445     if(tmp->child!=NULL){
    446       free(tmp->child);
    447     }
    448     if(tmp->defaults!=NULL){
    449       freeIOType(&tmp->defaults);
    450       free(tmp->defaults);
    451     }
    452     if(tmp->supported!=NULL){
    453       freeIOType(&tmp->supported);
    454       free(tmp->supported);
    455     }
    456     if(tmp->next!=NULL){
    457       freeElements(&tmp->next);
    458       free(tmp->next);
     427 * @param peElem the iotype to free
     428 */
     429void freeElements(elements** peElem){
     430  elements* peTmp=*peElem;
     431  if(peTmp!=NULL){
     432    if(peTmp->name!=NULL)
     433      free(peTmp->name);
     434    freeMap(&peTmp->content);
     435    if(peTmp->content!=NULL)
     436      free(peTmp->content);
     437    freeMap(&peTmp->metadata);
     438    if(peTmp->metadata!=NULL)
     439      free(peTmp->metadata);
     440    freeMap(&peTmp->additional_parameters);
     441    if(peTmp->additional_parameters!=NULL)
     442      free(peTmp->additional_parameters);
     443    if(peTmp->format!=NULL)
     444      free(peTmp->format);
     445    freeElements(&peTmp->child);
     446    if(peTmp->child!=NULL){
     447      free(peTmp->child);
     448    }
     449    if(peTmp->defaults!=NULL){
     450      freeIOType(&peTmp->defaults);
     451      free(peTmp->defaults);
     452    }
     453    if(peTmp->supported!=NULL){
     454      freeIOType(&peTmp->supported);
     455      free(peTmp->supported);
     456    }
     457    if(peTmp->next!=NULL){
     458      freeElements(&peTmp->next);
     459      free(peTmp->next);
    459460    }
    460461  }
     
    469470 */
    470471service* createService(){
    471   service *s1 = (service *) malloc (SERVICE_SIZE);
    472   s1->name=NULL;
    473   s1->content=NULL;
    474   s1->metadata=NULL;
    475   s1->additional_parameters=NULL;
    476   s1->inputs=NULL;
    477   s1->outputs=NULL;
    478   return s1;
     472  service *psService = (service *) malloc (SERVICE_SIZE);
     473  psService->name=NULL;
     474  psService->content=NULL;
     475  psService->metadata=NULL;
     476  psService->additional_parameters=NULL;
     477  psService->inputs=NULL;
     478  psService->outputs=NULL;
     479  return psService;
    479480}
    480481
     
    483484 * Require to be invoked for every createService call.
    484485 *
    485  * @param s the service to free
    486  */
    487 void freeService(service** s){
    488   service* tmp=*s;
    489   if(tmp!=NULL){
    490     if(tmp->name!=NULL)
    491       free(tmp->name);
    492     freeMap(&tmp->content);
    493     if(tmp->content!=NULL)
    494       free(tmp->content);
    495     freeMap(&tmp->metadata);
    496     if(tmp->metadata!=NULL)
    497       free(tmp->metadata);
    498     freeMap(&tmp->additional_parameters);
    499     if(tmp->additional_parameters!=NULL)
    500       free(tmp->additional_parameters);
    501     freeElements(&tmp->inputs);
    502     if(tmp->inputs!=NULL)
    503       free(tmp->inputs);
    504     freeElements(&tmp->outputs);
    505     if(tmp->outputs!=NULL)
    506       free(tmp->outputs);
     486 * @param psService the service to free
     487 */
     488void freeService(service** psService){
     489  service* psTmp=*psService;
     490  if(psTmp!=NULL){
     491    if(psTmp->name!=NULL)
     492      free(psTmp->name);
     493    freeMap(&psTmp->content);
     494    if(psTmp->content!=NULL)
     495      free(psTmp->content);
     496    freeMap(&psTmp->metadata);
     497    if(psTmp->metadata!=NULL)
     498      free(psTmp->metadata);
     499    freeMap(&psTmp->additional_parameters);
     500    if(psTmp->additional_parameters!=NULL)
     501      free(psTmp->additional_parameters);
     502    freeElements(&psTmp->inputs);
     503    if(psTmp->inputs!=NULL)
     504      free(psTmp->inputs);
     505    freeElements(&psTmp->outputs);
     506    if(psTmp->outputs!=NULL)
     507      free(psTmp->outputs);
    507508  }
    508509}
     
    511512 * Add key value pair to an existing map.
    512513 *
    513  * @param m the map to add the KVP
    514  * @param n the key to add
    515  * @param v the corresponding value to add
    516  */
    517 void addToMap(map* m,const char* n,const char* v){
    518     if (m != NULL) { // knut: add NULL-pointer check
    519         if (hasKey(m, n) == false) {
    520             map* _cursor = m;
    521             while (_cursor->next != NULL) {
    522                 _cursor = _cursor->next;
    523             }
    524             _cursor->next = createMap(n, v);
    525         }
    526         else {
    527             map *tmp = getMap(m, n);
    528             if (tmp->value != NULL)
    529                 free(tmp->value);
    530             tmp->value = zStrdup(v);
    531         }
    532     }
     514 * @param pMap the map to add the KVP
     515 * @param pccName the key to add
     516 * @param pccValue the corresponding value to add
     517 */
     518void addToMap(map* pMap,const char* pccName,const char* pccValue){
     519  if (pMap != NULL) { // knut: add NULL-pointer check
     520    if (hasKey(pMap, pccName) == false) {
     521      map* pmCursor = pMap;
     522      while (pmCursor->next != NULL) {
     523        pmCursor = pmCursor->next;
     524      }
     525      pmCursor->next = createMap(pccName, pccValue);
     526    }
     527    else {
     528      map *tmp = getMap(pMap, pccName);
     529      if (tmp->value != NULL)
     530        free(tmp->value);
     531      tmp->value = zStrdup(pccValue);
     532    }
     533  }
    533534}
    534535
     
    536537 * Add a key and an integer value to an existing map.
    537538 *
    538  * @param m the map to add the KVP
    539  * @param n the key to add
    540  * @param v the corresponding value to add
    541  */
    542 void addIntToMap(map* m,const char* n,const int v){
    543   char svalue[10];
    544   sprintf(svalue,"%d",v);
    545   if(hasKey(m,n)==false){
    546     map* _cursor=m;
    547     while(_cursor->next!=NULL){
    548       _cursor=_cursor->next;
    549     }
    550     _cursor->next=createMap(n,svalue);
     539 * @param pMap the map to add the KVP
     540 * @param pccName the key to add
     541 * @param iValue the corresponding value to add
     542 */
     543void addIntToMap(map* pMap,const char* pccName,const int iValue){
     544  char acValue[10];
     545  sprintf(acValue,"%d",iValue);
     546  if(hasKey(pMap,pccName)==false){
     547    map* pmCursor=pMap;
     548    while(pmCursor->next!=NULL){
     549      pmCursor=pmCursor->next;
     550    }
     551    pmCursor->next=createMap(pccName,acValue);
    551552  }
    552553  else{
    553     map *tmp=getMap(m,n);
    554     if(tmp->value!=NULL)
    555       free(tmp->value);
    556     tmp->value=zStrdup(svalue);
     554    map *pmTmp=getMap(pMap,pccName);
     555    if(pmTmp->value!=NULL)
     556      free(pmTmp->value);
     557    pmTmp->value=zStrdup(acValue);
    557558  }
    558559}
     
    561562 * Add a key and a binary value to an existing map.
    562563 *
    563  * @param m the map to add the KVP
    564  * @param n the key to add
    565  * @param v the corresponding value to add
    566  * @param size the size of the given value
     564 * @param pMap the map to add the KVP
     565 * @param pccName the key to add
     566 * @param pccValue the corresponding value to add
     567 * @param iSize the size of the given value
    567568 * @return a pointer to the updated map m
    568569 */
    569 map* addToMapWithSize(map* m,const char* n,const char* v,int size){
    570   char sin[128];
    571   char sname[10]="size";
    572   map *tmp;
    573   if(hasKey(m,n)==false){
    574     map* _cursor=m;
     570map* addToMapWithSize(map* pMap,const char* pccName,const char* pccValue,int iSize){
     571  char acIn[128];
     572  char acName[10]="size";
     573  map *pmTmp;
     574  if(hasKey(pMap,pccName)==false){
     575    map* _cursor=pMap;
    575576    if(_cursor!=NULL){
    576       addToMap(m,n,"");
     577      addToMap(pMap,pccName,"");
    577578    }else{
    578       m=createMap(n,"");
    579     }
    580   }
    581   if(strlen(n)>5)
    582     sprintf(sname,"size_%s",n+6);
    583   tmp=getMap(m,n);
    584   if(tmp->value!=NULL)
    585     free(tmp->value);
    586   tmp->value=(char*)malloc((size+1)*sizeof(char));
    587   if(v!=NULL)
    588     memmove(tmp->value,v,size*sizeof(char));
    589   tmp->value[size]=0;
    590   sprintf(sin,"%d",size);
    591   addToMap(m,sname,sin);
    592   return m;
     579      pMap=createMap(pccName,"");
     580    }
     581  }
     582  if(strlen(pccName)>5)
     583    sprintf(acName,"size_%s",pccName+6);
     584  pmTmp=getMap(pMap,pccName);
     585  if(pmTmp->value!=NULL)
     586    free(pmTmp->value);
     587  pmTmp->value=(char*)malloc((iSize+1)*sizeof(char));
     588  if(pccValue!=NULL)
     589    memmove(pmTmp->value,pccValue,iSize*sizeof(char));
     590  pmTmp->value[iSize]=0;
     591  sprintf(acIn,"%d",iSize);
     592  addToMap(pMap,acName,acIn);
     593  return pMap;
    593594}
    594595
     
    596597 * Add a map at the end of another map.
    597598 *
    598  * @param mo the map to add mi
    599  * @param mi the map to add to mo
    600  */
    601 void addMapToMap(map** mo,map* mi){
    602   map* tmp=mi;
    603   map* _cursor=*mo;
    604   while(tmp!=NULL){
    605     if(_cursor==NULL){
    606       *mo=createMap(tmp->name,tmp->value);
    607       (*mo)->next=NULL;
     599 * @param pmMapOut the map to add pmMapIn to
     600 * @param pmMapIn the map to add to pmMapOut
     601 */
     602void addMapToMap(map** pmMapOut,map* pmMapIn){
     603  map* pmTmp=pmMapIn;
     604  map* pmCursor=*pmMapOut;
     605  while(pmTmp!=NULL){
     606    if(pmCursor==NULL){
     607      *pmMapOut=createMap(pmTmp->name,pmTmp->value);
     608      (*pmMapOut)->next=NULL;
    608609    }
    609610    else{
    610       map* tmp1=getMap(*mo,tmp->name);
    611       if(tmp1==NULL){
    612         while(_cursor->next!=NULL)
    613           _cursor=_cursor->next;
    614         _cursor->next=createMap(tmp->name,tmp->value);
     611      map* pmTmp1=getMap(*pmMapOut,pmTmp->name);
     612      if(pmTmp1==NULL){
     613        while(pmCursor->next!=NULL)
     614          pmCursor=pmCursor->next;
     615        pmCursor->next=createMap(pmTmp->name,pmTmp->value);
    615616      }
    616617      else{
    617         addToMap(*mo,tmp->name,tmp->value);
     618        addToMap(*pmMapOut,pmTmp->name,pmTmp->value);
    618619      }
    619620    }
    620     _cursor=*mo;
    621     tmp=tmp->next;
     621    pmCursor=*pmMapOut;
     622    pmTmp=pmTmp->next;
    622623  }
    623624}
     
    626627 * Add a map to iotype.
    627628 *
    628  * @param io the iotype to add the map
    629  * @param mi the map to add to io
    630  */
    631 void addMapToIoType(iotype** io,map* mi){
    632   iotype* tmp=*io;
    633   while(tmp->next!=NULL){
    634     tmp=tmp->next;
    635   }
    636   tmp->next=(iotype*)malloc(IOTYPE_SIZE);
    637   tmp->next->content=NULL;
    638   addMapToMap(&tmp->next->content,mi);
    639   tmp->next->next=NULL;
     629 * @param piotType the iotype to add the map
     630 * @param pmMap the map to add to io
     631 */
     632void addMapToIoType(iotype** piotType,map* pmMap){
     633  iotype* piotTmp=*piotType;
     634  while(piotTmp->next!=NULL){
     635    piotTmp=piotTmp->next;
     636  }
     637  piotTmp->next=(iotype*)malloc(IOTYPE_SIZE);
     638  piotTmp->next->content=NULL;
     639  addMapToMap(&piotTmp->next->content,pmMap);
     640  piotTmp->next->next=NULL;
    640641}
    641642
     
    643644 * Access a specific map or set its value.
    644645 *
    645  * @param m the map to search for the key
    646  * @param key the key to search/add in the map
    647  * @param value the value to add if the key does not exist
     646 * @param ppmMap the map to search for the key
     647 * @param pccKey the key to search/add in the map
     648 * @param pccValue the value to add if the key does not exist
    648649 * @return a pointer on the map found or NULL if not found
    649650 */
    650 map* getMapOrFill(map** m,const char *key,const char* value){
    651   map* tmp=*m;
    652   map* tmpMap=getMap(tmp,key);
    653   if(tmpMap==NULL){
    654     if(tmp!=NULL){
    655       addToMap((*m),key,value);
     651map* getMapOrFill(map** ppmMap,const char *pccKey,const char* pccValue){
     652  map* pmTmp=*ppmMap;
     653  map* pmTmp1=getMap(pmTmp,pccKey);
     654  if(pmTmp1==NULL){
     655    if(pmTmp!=NULL){
     656      addToMap((*ppmMap),pccKey,pccValue);
    656657    }
    657658    else
    658       (*m)=createMap(key,value);
    659     tmpMap=getMap(*m,key);
    660   }
    661   return tmpMap;
     659      (*ppmMap)=createMap(pccKey,pccValue);
     660    pmTmp1=getMap(*ppmMap,pccKey);
     661  }
     662  return pmTmp1;
    662663}
    663664
     
    665666 * Verify if a map is contained in another map.
    666667 *
    667  * @param m the map to search for i
    668  * @param i the map to search in m
     668 * @param pmMap the map to search for i
     669 * @param pmSearch the map to search in m
    669670 * @return true if i was found in m, false in other case
    670671 */
    671 bool contains(map* m,map* i){
    672   while(i!=NULL){     
    673     if(strcasecmp(i->name,"value")!=0 &&
    674        strcasecmp(i->name,"xlink:href")!=0 &&
    675        strcasecmp(i->name,"useMapServer")!=0 &&
    676        strcasecmp(i->name,"asReference")!=0){
     672bool contains(map* pmMap,map* pmSearch){
     673  while(pmSearch!=NULL){     
     674    if(strcasecmp(pmSearch->name,"value")!=0 &&
     675       strcasecmp(pmSearch->name,"xlink:href")!=0 &&
     676       strcasecmp(pmSearch->name,"useMapServer")!=0 &&
     677       strcasecmp(pmSearch->name,"asReference")!=0){
    677678      map *tmp;
    678       if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL &&
    679          strcasecmp(i->value,tmp->value)!=0)
     679      if(hasKey(pmMap,pmSearch->name) &&
     680         (tmp=getMap(pmMap,pmSearch->name))!=NULL &&
     681         strcasecmp(pmSearch->value,tmp->value)!=0)
    680682        return false;
    681683    }
    682     i=i->next;
     684    pmSearch=pmSearch->next;
    683685  }
    684686  return true;
     
    688690 * Access a specific iotype from an elements.
    689691 *
    690  * @param e the elements to search for the name
    691  * @param name the name to search in the elements e
    692  * @param values the map to verify it was contained in the defaults or
     692 * @param peElem the elements to search for the name
     693 * @param pcName the name to search in the elements e
     694 * @param pcValues the map to verify it was contained in the defaults or
    693695 *  supported content of the elements e
    694696 * @return a pointer on the iotype found or NULL if not found
    695697 */
    696 iotype* getIoTypeFromElement(elements* e,char *name, map* values){
    697   elements* cursor=e;
    698   if(values!=NULL){
    699     while(cursor!=NULL){
    700       if(strcasecmp(cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){
    701         if(contains(cursor->defaults->content,values)==true)
    702           return cursor->defaults;
     698iotype* getIoTypeFromElement(elements* peElem,char *pcName, map* pcValues){
     699  elements* peCursor=peElem;
     700  if(pcValues!=NULL){
     701    while(peCursor!=NULL){
     702      if(strcasecmp(peCursor->name,pcName)==0 && (peCursor->defaults!=NULL || peCursor->supported!=NULL)){
     703        if(contains(peCursor->defaults->content,pcValues)==true)
     704          return peCursor->defaults;
    703705        else{
    704           iotype* tmp=cursor->supported;
     706          iotype* tmp=peCursor->supported;
    705707          while(tmp!=NULL){
    706             if(contains(tmp->content,values)==true)
     708            if(contains(tmp->content,pcValues)==true)
    707709              return tmp;           
    708710            tmp=tmp->next;
     
    710712        }
    711713      }
    712       cursor=cursor->next;
     714      peCursor=peCursor->next;
    713715    }
    714716  }else{
    715     while(cursor!=NULL){
    716       if(strcasecmp(cursor->name,name)==0 && cursor->defaults!=NULL){
    717         return cursor->defaults;
     717    while(peCursor!=NULL){
     718      if(strcasecmp(peCursor->name,pcName)==0 && peCursor->defaults!=NULL){
     719        return peCursor->defaults;
    718720      }
    719       cursor=cursor->next;
     721      peCursor=peCursor->next;
    720722    }
    721723  }
     
    726728 * Load binary values from a map (in) and add them to another map (out)
    727729 *
    728  * @param out the map to add binaries values
    729  * @param in the map containing the binary values to add ti out
    730  * @param pos index of the binary in an array (in case of "MapArray")
    731  */
    732 void loadMapBinary(map** out,map* in,int pos){
    733   map* size=getMap(in,"size");
    734   map *lout=*out;
    735   map *tmpVin,*tmpVout;
    736   if(size!=NULL && pos>0){
     730 * @param pmOut the map to add binaries values
     731 * @param pmIn the map containing the binary values to add ti out
     732 * @param iPos index of the binary in an array (in case of "MapArray")
     733 */
     734void loadMapBinary(map** ppmOut,map* pmIn,int iPos){
     735  map* pmSize=getMap(pmIn,"size");
     736  map *pmOut=*ppmOut;
     737  map *pmTmpVin,*pmTmpVout;
     738  if(pmSize!=NULL && iPos>0){
    737739    char tmp[11];
    738     sprintf(tmp,"size_%d",pos);
    739     size=getMap(in,tmp);
    740     sprintf(tmp,"value_%d",pos);
    741     tmpVin=getMap(in,tmp);
    742     tmpVout=getMap(lout,tmp);
    743     free(tmpVout->value);
    744     tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
    745     memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
    746     tmpVout->value[atoi(size->value)]=0;
     740    sprintf(tmp,"size_%d",iPos);
     741    pmSize=getMap(pmIn,tmp);
     742    sprintf(tmp,"value_%d",iPos);
     743    pmTmpVin=getMap(pmIn,tmp);
     744    pmTmpVout=getMap(pmOut,tmp);
     745    free(pmTmpVout->value);
     746    pmTmpVout->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char));
     747    memmove(pmTmpVout->value,pmTmpVin->value,atoi(pmSize->value)*sizeof(char));
     748    pmTmpVout->value[atoi(pmSize->value)]=0;
    747749  }else{
    748     if(size!=NULL){
    749       tmpVin=getMap(in,"value");
    750       tmpVout=getMap(lout,"value");
    751       free(tmpVout->value);
    752       tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
    753       memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
    754       tmpVout->value[atoi(size->value)]=0;
    755     }
    756   }
    757 }
    758  
     750    if(pmSize!=NULL){
     751      pmTmpVin=getMap(pmIn,"value");
     752      pmTmpVout=getMap(pmOut,"value");
     753      free(pmTmpVout->value);
     754      pmTmpVout->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char));
     755      memmove(pmTmpVout->value,pmTmpVin->value,atoi(pmSize->value)*sizeof(char));
     756      pmTmpVout->value[atoi(pmSize->value)]=0;
     757    }
     758  }
     759}
     760
    759761/**
    760762 * Load binary values from a map (in) and add them to another map (out).
     
    762764 * @see loadMapBinary
    763765 *
    764  * @param out the map to add binaries values
    765  * @param in the map containing the binary values to add ti out
    766  */
    767 void loadMapBinaries(map** out,map* in){
    768   map* size=getMap(in,"size");
    769   map* length=getMap(in,"length");
    770   map* toload=getMap(in,"to_load");
    771   if(toload!=NULL && strcasecmp(toload->value,"false")==0){
     766 * @param ppmOut the map to add binaries values
     767 * @param pmIn the map containing the binary values to add ti out
     768 */
     769void loadMapBinaries(map** ppmOut,map* pmIn){
     770  map* pmSize=getMap(pmIn,"size");
     771  map* pmLength=getMap(pmIn,"length");
     772  map* pmToload=getMap(pmIn,"to_load");
     773  if(pmToload!=NULL && strcasecmp(pmToload->value,"false")==0){
    772774#ifdef DEBUG
    773775    fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__);
     
    775777    return ;
    776778  }
    777   if(length!=NULL){
    778     int len=atoi(length->value);
     779  if(pmLength!=NULL){
     780    int len=atoi(pmLength->value);
    779781    int i=0;
    780782    for(i=0;i<len;i++){
    781       loadMapBinary(out,in,i);
     783      loadMapBinary(ppmOut,pmIn,i);
    782784    }
    783785  }
    784786  else
    785     if(size!=NULL)
    786       loadMapBinary(out,in,-1);
     787    if(pmSize!=NULL)
     788      loadMapBinary(ppmOut,pmIn,-1);
    787789}
    788790
     
    790792 * Duplicate a Maps
    791793 *
    792  * @param mo the maps to clone
     794 * @param ppmsOut the maps to clone
    793795 * @return the allocated maps containing a copy of the mo maps
    794796 */
    795 maps* dupMaps(maps** mo){
    796   maps* _cursor=*mo;
    797   maps* res=NULL;
    798   if(_cursor!=NULL){
    799     map* mc=_cursor->content;
    800     maps* mcs=_cursor->child;
    801     res=createMaps(_cursor->name);
    802     if(mc!=NULL){
    803       addMapToMap(&res->content,mc);
    804       loadMapBinaries(&res->content,mc);
    805     }
    806     if(mcs!=NULL){
    807       res->child=dupMaps(&mcs);
    808     }
    809     res->next=dupMaps(&_cursor->next);
    810   }
    811   return res;
     797maps* dupMaps(maps** ppmsOut){
     798  maps* pmsCursor=*ppmsOut;
     799  maps* pmRes=NULL;
     800  if(pmsCursor!=NULL){
     801    map* pmContent=pmsCursor->content;
     802    maps* pmsChild=pmsCursor->child;
     803    pmRes=createMaps(pmsCursor->name);
     804    if(pmContent!=NULL){
     805      addMapToMap(&pmRes->content,pmContent);
     806      loadMapBinaries(&pmRes->content,pmContent);
     807    }
     808    if(pmsChild!=NULL){
     809      pmRes->child=dupMaps(&pmsChild);
     810    }
     811    pmRes->next=dupMaps(&pmsCursor->next);
     812  }
     813  return pmRes;
    812814}
    813815
     
    816818 *
    817819 * @see addMapToMap, dupMaps, getMaps
    818  * @param mo the maps to add mi
    819  * @param mi the maps to add to mo
    820  */
    821 void addMapsToMaps(maps** mo,maps* mi){
    822   maps* tmp=mi;
    823   maps* _cursor=*mo;
    824   while(tmp!=NULL){
    825     if(_cursor==NULL){
    826       *mo=dupMaps(&mi);
     820 * @param ppmsOut the maps to add mi
     821 * @param pmIn the maps to add to mo
     822 */
     823void addMapsToMaps(maps** ppmsOut,maps* pmIn){
     824  maps* pmsTmp=pmIn;
     825  maps* pmsCursor=*ppmsOut;
     826  while(pmsTmp!=NULL){
     827    if(pmsCursor==NULL){
     828      *ppmsOut=dupMaps(&pmIn);
    827829    }
    828830    else{
    829       maps* tmp1=getMaps(*mo,tmp->name);
    830       if(tmp1==NULL){
    831         while(_cursor->next!=NULL)
    832           _cursor=_cursor->next;
    833         _cursor->next=dupMaps(&tmp);
    834         if(tmp->child!=NULL)
    835           _cursor->next->child=dupMaps(&tmp->child);
     831      maps* pmsTmp1=getMaps(*ppmsOut,pmsTmp->name);
     832      if(pmsTmp1==NULL){
     833        while(pmsCursor->next!=NULL)
     834          pmsCursor=pmsCursor->next;
     835        pmsCursor->next=dupMaps(&pmsTmp);
     836        if(pmsTmp->child!=NULL)
     837          pmsCursor->next->child=dupMaps(&pmsTmp->child);
    836838        else
    837           _cursor->next->child=NULL;
     839          pmsCursor->next->child=NULL;
    838840      }
    839841      else{
    840         addMapToMap(&tmp1->content,tmp->content);
    841         if(tmp->child!=NULL)
    842           tmp1->child=dupMaps(&tmp->child);
     842        addMapToMap(&pmsTmp1->content,pmsTmp->content);
     843        if(pmsTmp->child!=NULL)
     844          pmsTmp1->child=dupMaps(&pmsTmp->child);
    843845        else
    844           tmp1->child=NULL;
     846          pmsTmp1->child=NULL;
    845847      }
    846       _cursor=*mo;
    847     }
    848     tmp=tmp->next;
     848      pmsCursor=*ppmsOut;
     849    }
     850    pmsTmp=pmsTmp->next;
    849851  }
    850852}
     
    853855 * Access a specific map array element
    854856 *
    855  * @param m the map to search for the key
    856  * @param key the key to search in the map
    857  * @param index of the MapArray
     857 * @param pmMap the map to search for the key
     858 * @param pccKey the key to search in the map
     859 * @param iIndex of the MapArray
    858860 * @return a pointer on the map found or NULL if not found
    859861 */
    860 map* getMapArray(map* m,const char* key,int index){
    861   char tmp[1024];
    862   map* tmpMap;
    863   if(index>0)
    864     sprintf(tmp,"%s_%d",key,index);
     862map* getMapArray(map* pmMap,const char* pccKey,int iIndex){
     863  char acTmp[1024];
     864  map* pmTmp;
     865  if(iIndex>0)
     866    sprintf(acTmp,"%s_%d",pccKey,iIndex);
    865867  else
    866     sprintf(tmp,"%s",key);
     868    sprintf(acTmp,"%s",pccKey);
    867869#ifdef DEBUG
    868   fprintf(stderr,"** KEY %s\n",tmp);
     870  fprintf(stderr,"** KEY %s\n",acTmp);
    869871#endif
    870   tmpMap=getMap(m,tmp);
     872  pmTmp=getMap(pmMap,acTmp);
    871873#ifdef DEBUG
    872   if(tmpMap!=NULL)
    873     dumpMap(tmpMap);
     874  if(pmTmp!=NULL)
     875    dumpMap(pmTmp);
    874876#endif
    875   return tmpMap;
     877  return pmTmp;
    876878}
    877879
     
    879881 * Add a key value in a MapArray for a specific index
    880882 *
    881  * @param m the map to search for the key
    882  * @param key the key to search in the map
    883  * @param index the index of the MapArray
    884  * @param value the value to set in the MapArray
     883 * @param pmMap the map to search for the key
     884 * @param pccKey the key to search in the map
     885 * @param iIndex the index of the MapArray
     886 * @param pccValue the value to set in the MapArray
    885887 * @return a pointer on the map found or NULL if not found
    886888 */
    887 void setMapArray(map* m,const char* key,int index,const char* value){
    888   char tmp[1024];
    889   map* tmpSize;
    890   if(index>0){
    891     map* len=getMap(m,"length");
    892     sprintf(tmp,"%s_%d",key,index);
    893     if((len!=NULL && atoi(len->value)<index+1) || len==NULL){
    894       char tmp0[5];
    895       sprintf(tmp0,"%d",index+1);
    896       addToMap(m,"length",tmp0);
     889void setMapArray(map* pmMap,const char* pccKey,int iIndex,const char* pccValue){
     890  char acTmp[1024];
     891  map* pmSize;
     892  if(iIndex>0){
     893    map* pmLen=getMap(pmMap,"length");
     894    sprintf(acTmp,"%s_%d",pccKey,iIndex);
     895    if((pmLen!=NULL && atoi(pmLen->value)<iIndex+1) || pmLen==NULL){
     896      char acTmp0[5];
     897      sprintf(acTmp0,"%d",iIndex+1);
     898      addToMap(pmMap,"length",acTmp0);
    897899    }
    898900  }
    899901  else{
    900     sprintf(tmp,"%s",key);
    901     addToMap(m,"length","1");
    902   }
    903   tmpSize=getMapArray(m,"size",index);
    904   if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
    905     map* ptr=getMapOrFill(&m,tmp,(char *)"");
     902    sprintf(acTmp,"%s",pccKey);
     903    addToMap(pmMap,"length","1");
     904  }
     905  pmSize=getMapArray(pmMap,"size",iIndex);
     906  if(pmSize!=NULL && strncasecmp(pccKey,"value",5)==0){
     907    map* pmPtr=getMapOrFill(&pmMap,acTmp,(char *)"");
    906908#ifdef DEBUG
    907     fprintf(stderr,"%s\n",tmpSize->value);
     909    fprintf(stderr,"%s\n",pmSize->value);
    908910#endif
    909     free(ptr->value);
    910     ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
    911     memcpy(ptr->value,value,atoi(tmpSize->value));
     911    free(pmPtr->value);
     912    pmPtr->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char));
     913    memcpy(pmPtr->value,pccValue,atoi(pmSize->value));
    912914  }
    913915  else
    914     addToMap(m,tmp,value);
     916    addToMap(pmMap,acTmp,pccValue);
    915917}
    916918
     
    918920 * Add a key and an integer value to an existing map array.
    919921 *
    920  * @param m the map to add the KVP
    921  * @param n the key to add
    922  * @param index the index of the MapArray
    923  * @param v the corresponding value to add
    924  */
    925 void addIntToMapArray(map* m,const char* n,int index,const int v){
    926   char svalue[10];
    927   sprintf(svalue,"%d",v);
    928   setMapArray(m,n,index,svalue);
     922 * @param pmMap the map to add the KVP
     923 * @param pccName the key to add
     924 * @param iIndex the index of the MapArray
     925 * @param icValue the corresponding value to add
     926 */
     927void addIntToMapArray(map* pmMap,const char* pccName,int iIndex,const int icValue){
     928  char acValue[10];
     929  sprintf(acValue,"%d",icValue);
     930  setMapArray(pmMap,pccName,iIndex,acValue);
    929931}
    930932
     
    932934 * Access the map "type"
    933935 *
    934  * @param mt the map
     936 * @param pmMap the map
    935937 * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in
    936938 *  other case
    937939 */
    938 map* getMapType(map* mt){
    939   map* tmap=getMap(mt,(char *)"mimeType");
    940   if(tmap==NULL){
    941     tmap=getMap(mt,"dataType");
    942     if(tmap==NULL){
    943       tmap=getMap(mt,"CRS");
     940map* getMapType(map* pmMap){
     941  map* pmMime=getMap(pmMap,(char *)"mimeType");
     942  if(pmMime==NULL){
     943    pmMime=getMap(pmMap,"dataType");
     944    if(pmMime==NULL){
     945      pmMime=getMap(pmMap,"CRS");
    944946    }
    945947  }
    946948#ifdef DEBUG
    947   dumpMap(tmap);
     949  dumpMap(pmMime);
    948950#endif
    949   return tmap;
     951  return pmMime;
    950952}
    951953
     
    954956 *
    955957 * @see getMapType
    956  * @param mo the maps
    957  * @param mi the maps
    958  * @param typ the map "type"
     958 * @param pmsOut the maps
     959 * @param pmsIn the maps
     960 * @param pcType the map "type"
    959961 * @return
    960962 */
    961 int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
    962   maps* tmp=mi;   
    963   maps* _cursor=getMaps(*mo,tmp->name);
    964   char tmpLen[10];
    965   int len=1;
    966   char *tmpV[14]={
     963int addMapsArrayToMaps(maps** pmsOut,maps* pmsIn,char* pcType){
     964  maps* pmsTmp=pmsIn;
     965  maps* pmsCursor=getMaps(*pmsOut,pmsTmp->name);
     966  char acLen[10];
     967  int iLen=1;
     968  char *acV[14]={
    967969    (char*)"size",
    968970    (char*)"value",
     
    973975    (char*)"fmimeType",
    974976    (char*)"xlink:href",
    975     typ,
     977    pcType,
    976978    (char*)"schema",
    977979    (char*)"encoding",
     
    980982    (char*)"UpperCorner"
    981983  };
    982   int i=0;
    983   map* tmpLength;
     984  int iCounter=0;
     985  map* pmLength;
    984986 
    985   if(_cursor==NULL)
     987  if(pmsCursor==NULL)
    986988    return -1;
    987989
    988   tmpLength=getMap(_cursor->content,"length");
    989   if(tmpLength!=NULL){
    990     len=atoi(tmpLength->value);
    991   }
    992 
    993   sprintf(tmpLen,"%d",len+1);
    994   addToMap(_cursor->content,"length",tmpLen);
    995   for(i=0;i<14;i++){
    996     map* tmpVI=getMap(tmp->content,tmpV[i]);
    997     if(tmpVI!=NULL){
     990  pmLength=getMap(pmsCursor->content,"length");
     991  if(pmLength!=NULL){
     992    iLen=atoi(pmLength->value);
     993  }
     994
     995  sprintf(acLen,"%d",iLen+1);
     996  addToMap(pmsCursor->content,"length",acLen);
     997  for(iCounter=0;iCounter<14;iCounter++){
     998    map* pmTmp=getMap(pmsTmp->content,acV[iCounter]);
     999    if(pmTmp!=NULL){
    9981000#ifdef DEBUG
    999       fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
     1001      fprintf(stderr,"%s = %s\n",pmTmp[iCounter],pmTmp->value);
    10001002#endif
    1001       setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
     1003      setMapArray(pmsCursor->content,acV[iCounter],iLen,pmTmp->value);
    10021004    }
    10031005  }
    10041006   
    1005   addToMap(_cursor->content,"isArray","true");
     1007  addToMap(pmsCursor->content,"isArray","true");
    10061008  return 0;
    10071009}
     
    10101012 * Set a key value pair to a map contained in a Maps
    10111013 *
    1012  * @param m the maps
    1013  * @param key the maps name
    1014  * @param subkey the map name included in the maps corresponding to key
    1015  * @param value the corresponding value to add in the map
    1016  */
    1017 void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
    1018   maps* _tmpm=getMaps(m,key);
    1019   if(_tmpm!=NULL){
    1020     map* _ztmpm=getMap(_tmpm->content,subkey);
    1021     if(_ztmpm!=NULL){
    1022       if(_ztmpm->value!=NULL)
    1023         free(_ztmpm->value);
    1024       _ztmpm->value=zStrdup(value);
     1014 * @param pmsMaps the maps
     1015 * @param pccKey the maps name
     1016 * @param pccSubkey the map name included in the maps corresponding to key
     1017 * @param pccValue the corresponding value to add in the map
     1018 */
     1019void setMapInMaps(maps* pmsMaps,const char* pccKey,const char* pccSubkey,const char *pccValue){
     1020  maps* pmsTmp=getMaps(pmsMaps,pccKey);
     1021  if(pmsTmp!=NULL){
     1022    map* pmTmpSub=getMap(pmsTmp->content,pccSubkey);
     1023    if(pmTmpSub!=NULL){
     1024      if(pmTmpSub->value!=NULL)
     1025        free(pmTmpSub->value);
     1026      pmTmpSub->value=zStrdup(pccValue);
    10251027    }else{
    1026       maps *tmp=createMaps(key);
    1027       tmp->content=createMap(subkey,value);
    1028       addMapsToMaps(&_tmpm,tmp);
    1029       freeMaps(&tmp);
    1030       free(tmp);
     1028      maps *pmsToAdd=createMaps(pccKey);
     1029      pmsToAdd->content=createMap(pccSubkey,pccValue);
     1030      addMapsToMaps(&pmsTmp,pmsToAdd);
     1031      freeMaps(&pmsToAdd);
     1032      free(pmsToAdd);
    10311033    }
    10321034  }else{
    1033     maps *tmp=createMaps(key);
    1034     tmp->content=createMap(subkey,value);
    1035     addMapsToMaps(&m,tmp);
    1036     freeMaps(&tmp);
    1037     free(tmp);
     1035    maps *pmsToAdd=createMaps(pccKey);
     1036    pmsToAdd->content=createMap(pccSubkey,pccValue);
     1037    addMapsToMaps(&pmsMaps,pmsToAdd);
     1038    freeMaps(&pmsToAdd);
     1039    free(pmsToAdd);
    10381040  }
    10391041}
     
    10451047 */
    10461048elements* createEmptyElements(){
    1047   elements* res=(elements*)malloc(ELEMENTS_SIZE);
    1048   res->name=NULL;
    1049   res->content=NULL;
    1050   res->metadata=NULL;
    1051   res->additional_parameters=NULL; 
    1052   res->format=NULL;
    1053   res->defaults=NULL;
    1054   res->supported=NULL;
    1055   res->child=NULL;
    1056   res->next=NULL;
    1057   return res;
     1049  elements* peRes=(elements*)malloc(ELEMENTS_SIZE);
     1050  peRes->name=NULL;
     1051  peRes->content=NULL;
     1052  peRes->metadata=NULL;
     1053  peRes->additional_parameters=NULL; 
     1054  peRes->format=NULL;
     1055  peRes->defaults=NULL;
     1056  peRes->supported=NULL;
     1057  peRes->child=NULL;
     1058  peRes->next=NULL;
     1059  return peRes;
    10581060}
    10591061
     
    10611063 * Create a named elements
    10621064 *
    1063  * @param name the elements name
     1065 * @param pcName the elements name
    10641066 * @return a pointer to the allocated elements
    10651067 */
    1066 elements* createElements(const char* name){
    1067   elements* res=(elements*)malloc(ELEMENTS_SIZE);
    1068   res->name=zStrdup(name);
    1069   res->content=NULL;
    1070   res->metadata=NULL;
    1071   res->additional_parameters=NULL;
    1072   res->format=NULL;
    1073   res->defaults=NULL;
    1074   res->supported=NULL;
    1075   res->child=NULL;
    1076   res->next=NULL;
    1077   return res;
     1068elements* createElements(const char* pcName){
     1069  elements* peRes=(elements*)malloc(ELEMENTS_SIZE);
     1070  peRes->name=zStrdup(pcName);
     1071  peRes->content=NULL;
     1072  peRes->metadata=NULL;
     1073  peRes->additional_parameters=NULL;
     1074  peRes->format=NULL;
     1075  peRes->defaults=NULL;
     1076  peRes->supported=NULL;
     1077  peRes->child=NULL;
     1078  peRes->next=NULL;
     1079  return peRes;
    10781080}
    10791081
     
    10811083 * Set the name of an elements
    10821084 *
    1083  * @param name the elements name
     1085 * @param peElem the elements to modify
     1086 * @param pcName the elements name
    10841087 * @return a pointer to the allocated elements
    10851088 */
    1086 void setElementsName(elements** elem,char* name){
    1087   elements* res=*elem;
    1088   res->name=zStrdup(name);
    1089   res->content=NULL;
    1090   res->metadata=NULL;
    1091   res->format=NULL;
    1092   res->defaults=NULL;
    1093   res->supported=NULL;
    1094   res->child=NULL;
    1095   res->next=NULL;
     1089void setElementsName(elements** ppeElem,char* pcName){
     1090  elements* peRes=*ppeElem;
     1091  peRes->name=zStrdup(pcName);
     1092  peRes->content=NULL;
     1093  peRes->metadata=NULL;
     1094  peRes->format=NULL;
     1095  peRes->defaults=NULL;
     1096  peRes->supported=NULL;
     1097  peRes->child=NULL;
     1098  peRes->next=NULL;
    10961099}
    10971100
     
    10991102 * Dump an elements on stderr
    11001103 *
    1101  * @param e the elements to dump
    1102  */
    1103 void dumpElements(elements* e){
    1104   elements* tmp=e;
    1105   while(tmp!=NULL){
    1106     iotype* tmpio=tmp->defaults;
     1104 * @param peElem the elements to dump
     1105 */
     1106void dumpElements(elements* peElem){
     1107  elements* peTmp=peElem;
     1108  while(peTmp!=NULL){
     1109    iotype* piotTmp=peTmp->defaults;
    11071110    int ioc=0;
    1108     fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
    1109     fprintf(stderr," > CONTENT [%s]\n",tmp->name);
    1110     dumpMap(tmp->content);
    1111     fprintf(stderr," > METADATA [%s]\n",tmp->name);
    1112     dumpMap(tmp->metadata);
    1113     fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",tmp->name);
    1114     dumpMap(tmp->additional_parameters);
    1115     fprintf(stderr," > FORMAT [%s]\n",tmp->format);
    1116     while(tmpio!=NULL){
    1117       fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
    1118       dumpMap(tmpio->content);
    1119       tmpio=tmpio->next;
     1111    fprintf(stderr,"ELEMENT [%s]\n",peTmp->name);
     1112    fprintf(stderr," > CONTENT [%s]\n",peTmp->name);
     1113    dumpMap(peTmp->content);
     1114    fprintf(stderr," > METADATA [%s]\n",peTmp->name);
     1115    dumpMap(peTmp->metadata);
     1116    fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",peTmp->name);
     1117    dumpMap(peTmp->additional_parameters);
     1118    fprintf(stderr," > FORMAT [%s]\n",peTmp->format);
     1119    while(piotTmp!=NULL){
     1120      fprintf(stderr," > DEFAULTS [%s] (%i)\n",peTmp->name,ioc);
     1121      dumpMap(piotTmp->content);
     1122      piotTmp=piotTmp->next;
    11201123      ioc++;
    11211124    }
    1122     tmpio=tmp->supported;
     1125    piotTmp=peTmp->supported;
    11231126    ioc=0;
    1124     while(tmpio!=NULL){
    1125       fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
    1126       dumpMap(tmpio->content);
    1127       tmpio=tmpio->next;
     1127    while(piotTmp!=NULL){
     1128      fprintf(stderr," > SUPPORTED [%s] (%i)\n",peTmp->name,ioc);
     1129      dumpMap(piotTmp->content);
     1130      piotTmp=piotTmp->next;
    11281131      ioc++;
    11291132    }
    1130     if(tmp->child!=NULL){
     1133    if(peTmp->child!=NULL){
    11311134      fprintf(stderr," > CHILD \n");
    1132       dumpElements(tmp->child);
     1135      dumpElements(peTmp->child);
    11331136    }
    11341137    fprintf(stderr,"------------------\n");
    1135     tmp=tmp->next;
     1138    peTmp=peTmp->next;
    11361139  }
    11371140}
     
    11401143 * Dump an elements on stderr using the YAML syntaxe
    11411144 *
    1142  * @param e the elements to dump
    1143  */
    1144 void dumpElementsAsYAML(elements* e,int level){
    1145   elements* tmp=e;
     1145 * @param peElem the elements to dump
     1146 * @param iLevel the current level
     1147 */
     1148void dumpElementsAsYAML(elements* peElem,int iLevel){
     1149  elements* peTmp=peElem;
    11461150  int i;
    1147   while(tmp!=NULL){
    1148     map* mcurs=tmp->content;
     1151  while(peTmp!=NULL){
     1152    map* pmCurs=peTmp->content;
    11491153    int ioc=0;
    1150     iotype* tmpio;
    1151     for(i=0;i<2+(4*level);i++)
     1154    iotype* piotTmp;
     1155    for(i=0;i<2+(4*iLevel);i++)
    11521156      fprintf(stderr," ");
    1153     fprintf(stderr,"%s:\n",tmp->name);
    1154     while(mcurs!=NULL){
    1155       for(i=0;i<4+(4*level);i++)
     1157    fprintf(stderr,"%s:\n",peTmp->name);
     1158    while(pmCurs!=NULL){
     1159      for(i=0;i<4+(4*iLevel);i++)
    11561160        fprintf(stderr," ");
    1157       _dumpMap(mcurs);
    1158       mcurs=mcurs->next;
    1159     }
    1160     mcurs=tmp->metadata;
    1161     if(mcurs!=NULL){
    1162       for(i=0;i<4+(4*level);i++)
     1161      _dumpMap(pmCurs);
     1162      pmCurs=pmCurs->next;
     1163    }
     1164    pmCurs=peTmp->metadata;
     1165    if(pmCurs!=NULL){
     1166      for(i=0;i<4+(4*iLevel);i++)
    11631167        fprintf(stderr," ");
    11641168      fprintf(stderr,"MetaData:\n");
    1165       while(mcurs!=NULL){
    1166         for(i=0;i<6+(4*level);i++)
     1169      while(pmCurs!=NULL){
     1170        for(i=0;i<6+(4*iLevel);i++)
    11671171          fprintf(stderr," ");
    1168         _dumpMap(mcurs);
    1169         mcurs=mcurs->next;
     1172        _dumpMap(pmCurs);
     1173        pmCurs=pmCurs->next;
    11701174      }
    11711175    }
    1172     for(i=0;i<4+(4*level);i++)
     1176    for(i=0;i<4+(4*iLevel);i++)
    11731177      fprintf(stderr," ");
    1174     if(tmp->format!=NULL)
    1175       fprintf(stderr,"%s:\n",tmp->format);
     1178    if(peTmp->format!=NULL)
     1179      fprintf(stderr,"%s:\n",peTmp->format);
    11761180    else{
    11771181      fprintf(stderr,"Child:\n");
    1178       if(tmp->child!=NULL)
    1179         dumpElementsAsYAML(tmp->child,level+1);
    1180     }
    1181     tmpio=tmp->defaults;
    1182     while(tmpio!=NULL){
    1183       for(i=0;i<6+(4*level);i++)
     1182      if(peTmp->child!=NULL)
     1183        dumpElementsAsYAML(peTmp->child,iLevel+1);
     1184    }
     1185    piotTmp=peTmp->defaults;
     1186    while(piotTmp!=NULL){
     1187      for(i=0;i<6+(4*iLevel);i++)
    11841188        fprintf(stderr," ");
    11851189      fprintf(stderr,"default:\n");
    1186       mcurs=tmpio->content;
    1187       while(mcurs!=NULL){
    1188         for(i=0;i<8+(4*level);i++)
     1190      pmCurs=piotTmp->content;
     1191      while(pmCurs!=NULL){
     1192        for(i=0;i<8+(4*iLevel);i++)
    11891193          fprintf(stderr," ");
    1190         if(strcasecmp(mcurs->name,"range")==0){
    1191           fprintf(stderr,"range: \"%s\"\n",mcurs->value);
     1194        if(strcasecmp(pmCurs->name,"range")==0){
     1195          fprintf(stderr,"range: \"%s\"\n",pmCurs->value);
    11921196        }else
    1193           _dumpMap(mcurs);
    1194         mcurs=mcurs->next;
     1197          _dumpMap(pmCurs);
     1198        pmCurs=pmCurs->next;
    11951199      }
    1196       tmpio=tmpio->next;
     1200      piotTmp=piotTmp->next;
    11971201      ioc++;
    11981202    }
    1199     tmpio=tmp->supported;
     1203    piotTmp=peTmp->supported;
    12001204    ioc=0;
    1201     while(tmpio!=NULL){
    1202       for(i=0;i<6+(4*level);i++)
     1205    while(piotTmp!=NULL){
     1206      for(i=0;i<6+(4*iLevel);i++)
    12031207        fprintf(stderr," ");
    12041208      fprintf(stderr,"supported:\n");
    1205       mcurs=tmpio->content;
    1206       while(mcurs!=NULL){
    1207         for(i=0;i<8+(4*level);i++)
     1209      pmCurs=piotTmp->content;
     1210      while(pmCurs!=NULL){
     1211        for(i=0;i<8+(4*iLevel);i++)
    12081212          fprintf(stderr," ");
    1209         if(strcasecmp(mcurs->name,"range")==0){
    1210           fprintf(stderr,"range: \"%s\"\n",mcurs->value);
     1213        if(strcasecmp(pmCurs->name,"range")==0){
     1214          fprintf(stderr,"range: \"%s\"\n",pmCurs->value);
    12111215        }else
    1212           _dumpMap(mcurs);
    1213         mcurs=mcurs->next;
     1216          _dumpMap(pmCurs);
     1217        pmCurs=pmCurs->next;
    12141218      }
    1215       tmpio=tmpio->next;
     1219      piotTmp=piotTmp->next;
    12161220      ioc++;
    12171221    }
    1218     tmp=tmp->next;
     1222    peTmp=peTmp->next;
    12191223  }
    12201224}
     
    12231227 * Duplicate an elements
    12241228 *
    1225  * @param e the elements to clone
     1229 * @param peElem the elements to clone
    12261230 * @return the allocated elements containing a copy of the elements e
    12271231 */
    1228 elements* dupElements(elements* e){
    1229   elements* cursor=e;
    1230   elements* tmp=NULL;
    1231   if(cursor!=NULL && cursor->name!=NULL){
     1232elements* dupElements(elements* peElem){
     1233  elements* peCursor=peElem;
     1234  elements* peTmp=NULL;
     1235  if(peCursor!=NULL && peCursor->name!=NULL){
    12321236#ifdef DEBUG
    12331237    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
     
    12351239    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
    12361240#endif
    1237     tmp=(elements*)malloc(ELEMENTS_SIZE);
    1238     tmp->name=zStrdup(cursor->name);
    1239     tmp->content=NULL;
    1240     addMapToMap(&tmp->content,cursor->content);
    1241     tmp->metadata=NULL;
    1242     addMapToMap(&tmp->metadata,cursor->metadata);
    1243     tmp->additional_parameters=NULL;
    1244     addMapToMap(&tmp->additional_parameters,cursor->additional_parameters);
    1245     if(cursor->format!=NULL)
    1246       tmp->format=zStrdup(cursor->format);
     1241    peTmp=(elements*)malloc(ELEMENTS_SIZE);
     1242    peTmp->name=zStrdup(peCursor->name);
     1243    peTmp->content=NULL;
     1244    addMapToMap(&peTmp->content,peCursor->content);
     1245    peTmp->metadata=NULL;
     1246    addMapToMap(&peTmp->metadata,peCursor->metadata);
     1247    peTmp->additional_parameters=NULL;
     1248    addMapToMap(&peTmp->additional_parameters,peCursor->additional_parameters);
     1249    if(peCursor->format!=NULL)
     1250      peTmp->format=zStrdup(peCursor->format);
    12471251    else
    1248       tmp->format=NULL;
    1249     if(cursor->defaults!=NULL){
    1250       tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
    1251       tmp->defaults->content=NULL;
    1252       addMapToMap(&tmp->defaults->content,cursor->defaults->content);
    1253       tmp->defaults->next=NULL;
     1252      peTmp->format=NULL;
     1253    if(peCursor->defaults!=NULL){
     1254      peTmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
     1255      peTmp->defaults->content=NULL;
     1256      addMapToMap(&peTmp->defaults->content,peCursor->defaults->content);
     1257      peTmp->defaults->next=NULL;
    12541258#ifdef DEBUG
    12551259      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
    1256       dumpMap(tmp->defaults->content);
     1260      dumpMap(peTmp->defaults->content);
    12571261#endif
    12581262    }else
    1259       tmp->defaults=NULL;
    1260     if(cursor->supported!=NULL && cursor->supported->content!=NULL){
    1261       iotype *tmp2=cursor->supported->next;
    1262       tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
    1263       tmp->supported->content=NULL;
    1264       addMapToMap(&tmp->supported->content,cursor->supported->content);
    1265       tmp->supported->next=NULL;
    1266             while(tmp2!=NULL){
    1267         addMapToIoType(&tmp->supported,tmp2->content);
     1263      peTmp->defaults=NULL;
     1264    if(peCursor->supported!=NULL && peCursor->supported->content!=NULL){
     1265      iotype *piotTmp=peCursor->supported->next;
     1266      peTmp->supported=(iotype*)malloc(IOTYPE_SIZE);
     1267      peTmp->supported->content=NULL;
     1268      addMapToMap(&peTmp->supported->content,peCursor->supported->content);
     1269      peTmp->supported->next=NULL;
     1270            while(piotTmp!=NULL){
     1271        addMapToIoType(&peTmp->supported,piotTmp->content);
    12681272#ifdef DEBUG
    12691273        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
    1270         dumpMap(tmp->defaults->content);
     1274        dumpMap(peTmp->defaults->content);
    12711275#endif
    1272         tmp2=tmp2->next;
     1276        piotTmp=piotTmp->next;
    12731277      }
    12741278    }
    12751279    else
    1276       tmp->supported=NULL;
    1277     if(cursor->child!=NULL)
    1278       tmp->child=dupElements(cursor->child);
     1280      peTmp->supported=NULL;
     1281    if(peCursor->child!=NULL)
     1282      peTmp->child=dupElements(peCursor->child);
    12791283    else
    1280       tmp->child=NULL;
    1281     if(cursor->next!=NULL)
    1282       tmp->next=dupElements(cursor->next);
     1284      peTmp->child=NULL;
     1285    if(peCursor->next!=NULL)
     1286      peTmp->next=dupElements(peCursor->next);
    12831287    else
    1284       tmp->next=NULL;
    1285   }
    1286   return tmp;
     1288      peTmp->next=NULL;
     1289  }
     1290  return peTmp;
    12871291}
    12881292
     
    12911295 *
    12921296 * @see dupElements
    1293  * @param m the elements to add the e
    1294  * @param e the elements to be added to m
    1295  */
    1296 void addToElements(elements** m,elements* e){
    1297   elements* tmp=e;
    1298   if(*m==NULL){
    1299     (*m)=dupElements(tmp);
     1297 * @param ppeElem the elements to add the e
     1298 * @param peELem the elements to be added to m
     1299 */
     1300void addToElements(elements** ppeElem,elements* peELem){
     1301  elements* peTmp=peELem;
     1302  if(*ppeElem==NULL){
     1303    (*ppeElem)=dupElements(peTmp);
    13001304  }else{
    1301     addToElements(&(*m)->next,tmp);
     1305    addToElements(&(*ppeElem)->next,peTmp);
    13021306  }
    13031307}
     
    13061310 * Set the name of a service
    13071311 *
    1308  * @param name the service name
    1309  */
    1310 void setServiceName(service** serv,char* name){
    1311   service* res=*serv;
    1312   res->name=zStrdup(name);
    1313   res->content=NULL;
    1314   res->metadata=NULL;
    1315   res->inputs=NULL;
    1316   res->outputs=NULL;
     1312 * @param ppsServ the service
     1313 * @param pcName the service name
     1314 */
     1315void setServiceName(service** ppsServ,char* pcName){
     1316  service* psRes=*ppsServ;
     1317  psRes->name=zStrdup(pcName);
     1318  psRes->content=NULL;
     1319  psRes->metadata=NULL;
     1320  psRes->inputs=NULL;
     1321  psRes->outputs=NULL;
    13171322}
    13181323
     
    13201325 * Dump a service on stderr
    13211326 *
    1322  * @param s the service to dump
    1323  */
    1324 void dumpService(service* s){
    1325   if(s==NULL)
     1327 * @param psServ the service to dump
     1328 */
     1329void dumpService(service* psServ){
     1330  if(psServ==NULL)
    13261331    return;
    1327   fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
    1328   if(s->content!=NULL){
     1332  fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",psServ->name);
     1333  if(psServ->content!=NULL){
    13291334    fprintf(stderr,"CONTENT MAP\n");
    1330     dumpMap(s->content);
    1331     if(s->metadata!=NULL)
     1335    dumpMap(psServ->content);
     1336    if(psServ->metadata!=NULL)
    13321337      fprintf(stderr,"CONTENT METADATA\n");
    1333     dumpMap(s->metadata);
    1334     if(s->additional_parameters!=NULL)
     1338    dumpMap(psServ->metadata);
     1339    if(psServ->additional_parameters!=NULL)
    13351340      fprintf(stderr,"CONTENT AdditionalParameters\n");
    1336     dumpMap(s->additional_parameters);
    1337   }
    1338   if(s->inputs!=NULL){
    1339     fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
    1340     dumpElements(s->inputs);
    1341   }
    1342   if(s->outputs!=NULL){
    1343     fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
    1344     dumpElements(s->outputs);
     1341    dumpMap(psServ->additional_parameters);
     1342  }
     1343  if(psServ->inputs!=NULL){
     1344    fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",psServ->name);
     1345    dumpElements(psServ->inputs);
     1346  }
     1347  if(psServ->outputs!=NULL){
     1348    fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",psServ->name);
     1349    dumpElements(psServ->outputs);
    13451350  }
    13461351  fprintf(stderr,"++++++++++++++++++\n");
     
    13501355 * Dump a service on stderr using the YAML syntaxe
    13511356 *
    1352  * @param s the service to dump
    1353  */
    1354 void dumpServiceAsYAML(service* s){
     1357 * @param psServ the service to dump
     1358 */
     1359void dumpServiceAsYAML(service* psServ){
    13551360  int i;
    1356   fprintf(stderr,"# %s\n\n",s->name);
    1357   if(s->content!=NULL){
    1358     map* mcurs=s->content;
    1359     dumpMap(mcurs);
    1360     mcurs=s->metadata;
    1361     if(mcurs!=NULL){
     1361  fprintf(stderr,"# %s\n\n",psServ->name);
     1362  if(psServ->content!=NULL){
     1363    map* pmCurs=psServ->content;
     1364    dumpMap(pmCurs);
     1365    pmCurs=psServ->metadata;
     1366    if(pmCurs!=NULL){
    13621367      fprintf(stderr,"MetaData:\n");
    1363       while(mcurs!=NULL){
     1368      while(pmCurs!=NULL){
    13641369        for(i=0;i<2;i++)
    13651370          fprintf(stderr," ");
    1366         _dumpMap(mcurs);
    1367         mcurs=mcurs->next;
     1371        _dumpMap(pmCurs);
     1372        pmCurs=pmCurs->next;
    13681373      }
    13691374    }
    13701375  }
    1371   if(s->inputs!=NULL){
     1376  if(psServ->inputs!=NULL){
    13721377    fprintf(stderr,"\ninputs:\n");
    1373     dumpElementsAsYAML(s->inputs,0);
    1374   }
    1375   if(s->outputs!=NULL){
     1378    dumpElementsAsYAML(psServ->inputs,0);
     1379  }
     1380  if(psServ->outputs!=NULL){
    13761381    fprintf(stderr,"\noutputs:\n");
    1377     dumpElementsAsYAML(s->outputs,0);
     1382    dumpElementsAsYAML(psServ->outputs,0);
    13781383  }
    13791384}
     
    13821387 * Duplicate a service
    13831388 *
    1384  * @param s the service to clone
     1389 * @param psServ the service to clone
    13851390 * @return the allocated service containing a copy of the serfvice s
    13861391 */
    1387 service* dupService(service* s){
    1388   service *res=(service*)malloc(SERVICE_SIZE);
    1389   res->name=zStrdup(s->name);
    1390   res->content=NULL;
    1391   addMapToMap(&res->content,s->content);
    1392   res->metadata=NULL;
    1393   addMapToMap(&res->metadata,s->metadata);
    1394   res->additional_parameters=NULL;
    1395   addMapToMap(&res->additional_parameters,s->additional_parameters);
    1396   res->inputs=dupElements(s->inputs);
    1397   res->outputs=dupElements(s->outputs);
    1398   return res;
     1392service* dupService(service* psServ){
     1393  service *psRes=(service*)malloc(SERVICE_SIZE);
     1394  psRes->name=zStrdup(psServ->name);
     1395  psRes->content=NULL;
     1396  addMapToMap(&psRes->content,psServ->content);
     1397  psRes->metadata=NULL;
     1398  addMapToMap(&psRes->metadata,psServ->metadata);
     1399  psRes->additional_parameters=NULL;
     1400  addMapToMap(&psRes->additional_parameters,psServ->additional_parameters);
     1401  psRes->inputs=dupElements(psServ->inputs);
     1402  psRes->outputs=dupElements(psServ->outputs);
     1403  return psRes;
    13991404}
    14001405
     
    14021407 * Print the registry on stderr.
    14031408 *
    1404  * @param r the registry
    1405  */
    1406 void dumpRegistry(registry* r){
    1407   registry* p=r;
    1408   while(p!=NULL){
    1409     services* s=p->content;
    1410     fprintf(stderr,"%s \n",p->name);
    1411     s=p->content;
    1412     while(s!=NULL){
    1413       dumpService(s->content);
    1414       s=s->next;
    1415     }
    1416     p=p->next;
     1409 * @param prReg the registry
     1410 */
     1411void dumpRegistry(registry* prReg){
     1412  registry* prCurs=prReg;
     1413  while(prCurs!=NULL){
     1414    services* psServ=prCurs->content;
     1415    fprintf(stderr,"%s \n",prCurs->name);
     1416    psServ=prCurs->content;
     1417    while(psServ!=NULL){
     1418      dumpService(psServ->content);
     1419      psServ=psServ->next;
     1420    }
     1421    prCurs=prCurs->next;
    14171422  }
    14181423}
     
    14211426 * Add a service to the registry
    14221427 *
    1423  * @param reg the resgitry to add the service
    1424  * @param name the registry name to update
    1425  * @param content the service to add
    1426  */
    1427 bool addServiceToRegistry(registry** reg,char* name,service* content){
    1428   registry *l=*reg;
     1428 * @param prReg the resgitry to add the service
     1429 * @param pcName the registry name to update
     1430 * @param psContent the service to add
     1431 */
     1432bool addServiceToRegistry(registry** prReg,char* pcName,service* psContent){
     1433  registry *l=*prReg;
    14291434  int isInitial=-1;
    14301435  if(l==NULL){
     
    14351440    int hasLevel=-1;
    14361441    while(isInitial<0 && l!=NULL){
    1437       if(l->name!=NULL && strcasecmp(name,l->name)==0){
     1442      if(l->name!=NULL && strcasecmp(pcName,l->name)==0){
    14381443        hasLevel=1;
    14391444        break;
     
    14441449      if(isInitial<0)
    14451450        l=(registry*)malloc(REGISTRY_SIZE);
    1446       l->name=zStrdup(name);
     1451      l->name=zStrdup(pcName);
    14471452      l->content=NULL;
    14481453      l->next=NULL;
     
    14501455    if(l->content==NULL){
    14511456      l->content=(services*)malloc(SERVICES_SIZE);
    1452       l->content->content=dupService(content);
     1457      l->content->content=dupService(psContent);
    14531458      l->content->next=NULL;
    14541459    }
    14551460    else{
    1456       services* s=l->content;
    1457       while(s->next!=NULL)
    1458         s=s->next;
    1459       s->next=(services*)malloc(SERVICES_SIZE);
    1460       s->next->content=dupService(content);
    1461       s->next->next=NULL;
     1461      services* psServ=l->content;
     1462      while(psServ->next!=NULL)
     1463        psServ=psServ->next;
     1464      psServ->next=(services*)malloc(SERVICES_SIZE);
     1465      psServ->next->content=dupService(psContent);
     1466      psServ->next->next=NULL;
    14621467    }
    14631468    l->next=NULL;
    14641469    if(isInitial>0)
    1465       *reg=l;
     1470      *prReg=l;
    14661471    else{
    1467       registry *r=*reg;
    1468       while(r->next!=NULL)
    1469         r=r->next;
    1470       r->next=l;
    1471       r->next->next=NULL;
     1472      registry *prCurs=*prReg;
     1473      while(prCurs->next!=NULL)
     1474        prCurs=prCurs->next;
     1475      prCurs->next=l;
     1476      prCurs->next->next=NULL;
    14721477    }
    14731478    return true;
     
    14801485 * Free memory allocated for the registry
    14811486 *
    1482  * @param r the registry
    1483  */
    1484 void freeRegistry(registry** r){
    1485   registry* lr=*r;
    1486   while(lr!=NULL){
    1487     services* s=lr->content;
    1488     free(lr->name);
    1489     while(s!=NULL){
    1490       service* s1=s->content;
    1491       s=s->next;
    1492       if(s1!=NULL){
    1493         freeService(&s1);
    1494         free(s1);
    1495         s1=NULL;
     1487 * @param prReg the registry
     1488 */
     1489void freeRegistry(registry** prReg){
     1490  registry* prLocalRef=*prReg;
     1491  while(prLocalRef!=NULL){
     1492    services* psServ=prLocalRef->content;
     1493    free(prLocalRef->name);
     1494    while(psServ!=NULL){
     1495      service* psServ1=psServ->content;
     1496      psServ=psServ->next;
     1497      if(psServ1!=NULL){
     1498        freeService(&psServ1);
     1499        free(psServ1);
     1500        psServ1=NULL;
    14961501      }
    14971502    }
    1498     lr=lr->next;
     1503    prLocalRef=prLocalRef->next;
    14991504  }   
    15001505}
     
    15031508 * Access a service in the registry
    15041509 *
    1505  * @param r the registry
    1506  * @param level the regitry to search ("concept", "generic" or "implementation")
    1507  * @param sname the service name
     1510 * @param prReg the registry
     1511 * @param pcLevel the regitry to search ("concept", "generic" or "implementation")
     1512 * @param pcName the service name
    15081513 * @return the service pointer if a corresponding service was found or NULL
    15091514 */
    1510 service* getServiceFromRegistry(registry* r,char  *level,char* sname){
    1511   registry *lr=r;
    1512   while(lr!=NULL){
    1513     if(strcasecmp(lr->name,level)==0){
    1514       services* s=lr->content;
    1515       while(s!=NULL){
    1516         if(s->content!=NULL && strcasecmp(s->content->name,sname)==0)
    1517           return s->content;
    1518         s=s->next;
     1515service* getServiceFromRegistry(registry* prReg,char  *pcLevel,char* pcName){
     1516  registry *prLocalRef=prReg;
     1517  while(prLocalRef!=NULL){
     1518    if(strcasecmp(prLocalRef->name,pcLevel)==0){
     1519      services* psServ=prLocalRef->content;
     1520      while(psServ!=NULL){
     1521        if(psServ->content!=NULL && strcasecmp(psServ->content->name,pcName)==0)
     1522          return psServ->content;
     1523        psServ=psServ->next;
    15191524      }
    15201525      break;
    15211526    }
    1522     lr=lr->next;
     1527    prLocalRef=prLocalRef->next;
    15231528  }
    15241529  return NULL;
     
    15281533 * Apply inheritance to an out map from a reference in map
    15291534 *
    1530  * @param out the map to update
    1531  * @param in the reference map (containing inherited properties)
    1532  */
    1533 void inheritMap(map** out,map* in){
    1534   map* content=in;
    1535   if((*out)==NULL){
    1536     addMapToMap(out,in);
     1535 * @param ppmOut the map to update
     1536 * @param pmIn the reference map (containing inherited properties)
     1537 */
     1538void inheritMap(map** ppmOut,map* pmIn){
     1539  map* pmContent=pmIn;
     1540  if((*ppmOut)==NULL){
     1541    addMapToMap(ppmOut,pmIn);
    15371542    return;
    15381543  }
    1539   while(content!=NULL){
    1540     map* cmap=getMap(*out,content->name);
    1541     if(cmap==NULL)
    1542       addToMap(*out,content->name,content->value);
    1543     content=content->next;
     1544  while(pmContent!=NULL){
     1545    map* pmCurrent=getMap(*ppmOut,pmContent->name);
     1546    if(pmCurrent==NULL)
     1547      addToMap(*ppmOut,pmCurrent->name,pmCurrent->value);
     1548    pmCurrent=pmCurrent->next;
    15441549  }
    15451550}
     
    15481553 * Apply inheritance to an out iotype from a reference in iotype
    15491554 *
    1550  * @param out the iotype to update
    1551  * @param in the reference iotype (containing inherited properties)
    1552  */
    1553 void inheritIOType(iotype** out,iotype* in){
    1554   iotype* io=in;
    1555   iotype* oio=*out;
    1556   if(io!=NULL){
    1557     if(*out==NULL){
    1558       *out=(iotype*)malloc(IOTYPE_SIZE);
    1559       (*out)->content=NULL;
    1560       addMapToMap(&(*out)->content,io->content);
    1561       (*out)->next=NULL;
    1562       oio=*out;
    1563       inheritIOType(&oio->next,io->next);
     1555 * @param ppiotOut the iotype to update
     1556 * @param piotIn the reference iotype (containing inherited properties)
     1557 */
     1558void inheritIOType(iotype** ppiotOut,iotype* piotIn){
     1559  iotype* piotInCurosor=piotIn;
     1560  iotype* ppiotOutCursor=*ppiotOut;
     1561  if(piotInCurosor!=NULL){
     1562    if(*ppiotOut==NULL){
     1563      *ppiotOut=(iotype*)malloc(IOTYPE_SIZE);
     1564      (*ppiotOut)->content=NULL;
     1565      addMapToMap(&(*ppiotOut)->content,piotInCurosor->content);
     1566      (*ppiotOut)->next=NULL;
     1567      ppiotOutCursor=*ppiotOut;
     1568      inheritIOType(&ppiotOutCursor->next,piotInCurosor->next);
    15641569    }else{
    1565       inheritIOType(&oio->next,io->next);
     1570      inheritIOType(&ppiotOutCursor->next,piotInCurosor->next);
    15661571    }
    15671572  }
     
    15711576 * Apply inheritance to an out elements from a reference in elements
    15721577 *
    1573  * @param out the elements to update
    1574  * @param in the reference elements (containing inherited properties)
    1575  */
    1576 void inheritElements(elements** out,elements* in){
    1577   elements* content=in;
    1578   while(content!=NULL && *out!=NULL){
    1579     elements* cmap=getElements(*out,content->name);
    1580     if(cmap==NULL)
    1581       addToElements(out,content);
     1578 * @param ppeOut the elements to update
     1579 * @param peIn the reference elements (containing inherited properties)
     1580 */
     1581void inheritElements(elements** ppeOut,elements* peIn){
     1582  elements* peContent=peIn;
     1583  while(peContent!=NULL && *ppeOut!=NULL){
     1584    elements* peCurrent=getElements(*ppeOut,peContent->name);
     1585    if(peCurrent==NULL)
     1586      addToElements(ppeOut,peContent);
    15821587    else{
    1583       inheritMap(&cmap->content,content->content);
    1584       inheritMap(&cmap->metadata,content->metadata);
    1585       if(cmap->format==NULL && content->format!=NULL)
    1586         cmap->format=zStrdup(content->format);
    1587       inheritIOType(&cmap->defaults,content->defaults);
    1588       if(cmap->supported==NULL)
    1589         inheritIOType(&cmap->supported,content->supported);
     1588      inheritMap(&peCurrent->content,peContent->content);
     1589      inheritMap(&peCurrent->metadata,peContent->metadata);
     1590      if(peCurrent->format==NULL && peContent->format!=NULL)
     1591        peCurrent->format=zStrdup(peContent->format);
     1592      inheritIOType(&peCurrent->defaults,peContent->defaults);
     1593      if(peCurrent->supported==NULL)
     1594        inheritIOType(&peCurrent->supported,peContent->supported);
    15901595      else{
    1591         iotype* p=content->supported;
    1592         while(p!=NULL){
    1593           addMapToIoType(&cmap->supported,p->content);
    1594           p=p->next;
     1596        iotype* piotTmp=peContent->supported;
     1597        while(piotTmp!=NULL){
     1598          addMapToIoType(&peCurrent->supported,piotTmp->content);
     1599          piotTmp=piotTmp->next;
    15951600        }
    15961601      }
    15971602    }
    1598     content=content->next;
     1603    peContent=peContent->next;
    15991604  }
    16001605}
     
    16031608 * Apply inheritance to a service based on a registry
    16041609 *
    1605  * @param r the registry storing profiles hierarchy
    1606  * @param s the service to update depending on its inheritance
    1607  */
    1608 void inheritance(registry *r,service** s){
    1609   service* ls=*s;
     1610 * @param prReg the registry storing profiles hierarchy
     1611 * @param psServ the service to update depending on its inheritance
     1612 */
     1613void inheritance(registry *prReg,service** psServ){
     1614  service* psCursor=*psServ;
    16101615  map *profile,*level;
    1611   if(r==NULL)
     1616  if(prReg==NULL)
    16121617    return;
    1613   if(ls==NULL || ls->content==NULL)
     1618  if(psCursor==NULL || psCursor->content==NULL)
    16141619    return;
    1615   profile=getMap(ls->content,"extend");
    1616   level=getMap(ls->content,"level");
     1620  profile=getMap(psCursor->content,"extend");
     1621  level=getMap(psCursor->content,"level");
    16171622  if(profile!=NULL&&level!=NULL){
    16181623    service* s1;
    16191624    if(strncasecmp(level->value,"profile",7)==0)
    1620       s1=getServiceFromRegistry(r,(char*)"generic",profile->value);
     1625      s1=getServiceFromRegistry(prReg,(char*)"generic",profile->value);
    16211626    else
    1622       s1=getServiceFromRegistry(r,level->value,profile->value);
     1627      s1=getServiceFromRegistry(prReg,level->value,profile->value);
    16231628     
    1624     inheritMap(&ls->content,s1->content);
    1625     inheritMap(&ls->metadata,s1->metadata);
    1626     if(ls->inputs==NULL && s1->inputs!=NULL){
    1627       ls->inputs=dupElements(s1->inputs);
     1629    inheritMap(&psCursor->content,s1->content);
     1630    inheritMap(&psCursor->metadata,s1->metadata);
     1631    if(psCursor->inputs==NULL && s1->inputs!=NULL){
     1632      psCursor->inputs=dupElements(s1->inputs);
    16281633    }else{
    1629       inheritElements(&ls->inputs,s1->inputs);
    1630     }
    1631     if(ls->outputs==NULL && s1->outputs!=NULL){
    1632       ls->outputs=dupElements(s1->outputs);
     1634      inheritElements(&psCursor->inputs,s1->inputs);
     1635    }
     1636    if(psCursor->outputs==NULL && s1->outputs!=NULL){
     1637      psCursor->outputs=dupElements(s1->outputs);
    16331638    }else
    1634       inheritElements(&ls->outputs,s1->outputs);
     1639      inheritElements(&psCursor->outputs,s1->outputs);
    16351640  }
    16361641}
     
    16391644 * Convert a maps to a char*** (only used for Fortran support)
    16401645 *
    1641  * @param m the maps to convert
    1642  * @param c the resulting array
    1643  */
    1644 void mapsToCharXXX(maps* m,char*** c){
    1645   maps* tm=m;
     1646 * @param pmsMap the maps to convert
     1647 * @param pppcValues the resulting array
     1648 */
     1649void mapsToCharXXX(maps* pmsMap,char*** pppcValues){
     1650  maps* pmsCursor=pmsMap;
    16461651  int i=0;
    16471652  int j=0;
    1648   char tmp[10][30][1024];
    1649   memset(tmp,0,1024*10*10);
    1650   while(tm!=NULL){
    1651     map* tc=tm->content;
     1653  char aaacTmp[10][30][1024];
     1654  memset(aaacTmp,0,1024*10*10);
     1655  while(pmsCursor!=NULL){
     1656    map* pmContent=pmsCursor->content;
    16521657    if(i>=10)
    16531658      break;
    1654     strcpy(tmp[i][j],"name");
     1659    strcpy(aaacTmp[i][j],"name");
    16551660    j++;
    1656     strcpy(tmp[i][j],tm->name);
     1661    strcpy(aaacTmp[i][j],pmsCursor->name);
    16571662    j++;
    1658     while(tc!=NULL){
     1663    while(pmContent!=NULL){
    16591664      if(j>=30)
    16601665        break;
    1661       strcpy(tmp[i][j],tc->name);
     1666      strcpy(aaacTmp[i][j],pmContent->name);
    16621667      j++;
    1663       strcpy(tmp[i][j],tc->value);
     1668      strcpy(aaacTmp[i][j],pmContent->value);
    16641669      j++;
    1665       tc=tc->next;
    1666     }
    1667     tm=tm->next;
     1670      pmContent=pmContent->next;
     1671    }
     1672    pmsCursor=pmsCursor->next;
    16681673    j=0;
    16691674    i++;
    16701675  }
    1671   memcpy(c,tmp,10*10*1024);
     1676  memcpy(pppcValues,aaacTmp,10*10*1024);
    16721677}
    16731678
     
    16751680 * Convert a char*** to a maps (only used for Fortran support)
    16761681 *
    1677  * @param c the array to convert
    1678  * @param m the resulting maps
    1679  */
    1680 void charxxxToMaps(char*** c,maps**m){
    1681   maps* trorf=*m;
     1682 * @param pppcValues the array to convert
     1683 * @param ppmsMaps the resulting maps
     1684 */
     1685void charxxxToMaps(char*** pppcValues,maps** ppmsMaps){
     1686  maps* pmsCursor=*ppmsMaps;
    16821687  int i,j;
    1683   char tmp[10][30][1024];
    1684   memcpy(tmp,c,10*30*1024);
     1688  char aaaTmp[10][30][1024];
     1689  memcpy(aaaTmp,pppcValues,10*30*1024);
    16851690  for(i=0;i<10;i++){
    1686     if(strlen(tmp[i][1])==0)
     1691    if(strlen(aaaTmp[i][1])==0)
    16871692      break;
    1688     trorf->name=tmp[i][1];
    1689     trorf->content=NULL;
    1690     trorf->next=NULL;
     1693    pmsCursor->name=aaaTmp[i][1];
     1694    pmsCursor->content=NULL;
     1695    pmsCursor->next=NULL;
    16911696    for(j=2;j<29;j+=2){
    1692       if(strlen(tmp[i][j+1])==0)
     1697      if(strlen(aaaTmp[i][j+1])==0)
    16931698        break;
    1694       if(trorf->content==NULL)
    1695         trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
     1699      if(pmsCursor->content==NULL)
     1700        pmsCursor->content=createMap(aaaTmp[i][j],aaaTmp[i][j+1]);
    16961701      else
    1697         addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
    1698     }
    1699     trorf=trorf->next;
    1700   }
    1701   m=&trorf;
     1702        addToMap(pmsCursor->content,aaaTmp[i][j],aaaTmp[i][j+1]);
     1703    }
     1704    pmsCursor=pmsCursor->next;
     1705  }
     1706  ppmsMaps=&pmsCursor;
    17021707}
    17031708
     
    17051710 * Verify that a map has a value
    17061711 *
    1707  * @param map pointer to map that should be checked
     1712 * @param pmMap pointer to map that should be checked
    17081713 * @return true if map has a value or false if value is missing/empty/NULL
    17091714 */
    1710 bool nonempty(map* map) {
    1711         return (map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0);
     1715bool nonempty(map* pmMap) {
     1716  return (pmMap != NULL && pmMap->value != NULL && strlen(pmMap->value) > 0 && strcmp(pmMap->value, "NULL") != 0);
    17121717}
    17131718
     
    17161721 * data structure, and obtain that value
    17171722 *
    1718  * @param source pointer to maps structure
    1719  * @param node name of maps node to search
    1720  * @param key name of map node to find
    1721  * @param kvp address to the map* if it exists, otherwise NULL
     1723 * @param pmsSource pointer to maps structure
     1724 * @param pccNode name of maps node to search
     1725 * @param pccKey name of map node to find
     1726 * @param ppmKvp address to the map* if it exists, otherwise NULL
    17221727 * @return true if map has a value or false if value is missing/NULL
    17231728 *
    17241729 * @note The map assigned to kvp is owned by the source maps
    17251730 */
    1726 bool hasvalue(maps* source, const char* node, const char* key, map** kvp) {
    1727         *kvp = getMapFromMaps(source, node, key);
    1728         return (*kvp != NULL && (*kvp)->value != NULL &&
    1729                 strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0);
     1731bool hasvalue(maps* pmsSource, const char* pccNode, const char* pccKey, map** ppmKvp) {
     1732  *ppmKvp = getMapFromMaps(pmsSource, pccNode, pccKey);
     1733  return (*ppmKvp != NULL && (*ppmKvp)->value != NULL &&
     1734          strlen((*ppmKvp)->value) > 0 && strcmp((*ppmKvp)->value, "NULL") != 0);
    17301735}
    17311736
     
    17331738 * Set error message in configuration maps
    17341739 *
    1735  * @param conf reference to configuration maps
    1736  * @param service name of service
    1737  * @param exc WPSException code
    1738  * @param message exception text (default: exception text in WPS specification)
    1739  */
    1740 void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message) {
    1741 
    1742         if (message == NULL) {
    1743                 message = WPSExceptionText[exc];
    1744         }
    1745 
    1746         size_t len = strlen(service) + strlen(": ") + strlen(message) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16;
    1747         char* msg = (char*)malloc(len * sizeof(char));
    1748 
    1749         if (msg != NULL) {
    1750                 snprintf(msg, len * sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc]);
    1751                 setMapInMaps(conf, "lenv", "message", msg);
    1752                 free(msg);
    1753         }
    1754 }
    1755 
    1756 void logMessage(const char* source, const char* function, int line, const char* file, const char* message) { //, const char* source, const char* function, int line) {
    1757 
    1758         size_t msglen = 512;
    1759         const char empty[] = "";
    1760 
    1761         FILE* log;
    1762 
    1763         // system time, process time [nanoseconds]   
    1764         unsigned long long sys_t, proc_t;
    1765 
    1766         // processor time consumed by the program:
    1767         clock_t t = clock();
    1768 
    1769         // system time:
    1770         std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
    1771 
    1772         std::time_t now_t = std::chrono::system_clock::to_time_t(now);
    1773         std::tm* tm = localtime(&now_t);
    1774         char* str = asctime(tm);
    1775         str[strlen(str) - 1] = '\0'; // remove newline
    1776 
    1777         sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
    1778         //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC);
    1779         proc_t = t;
    1780 
    1781         if (message != NULL) {
    1782                 msglen += strlen(message);
    1783         }
    1784         else {
    1785                 message = empty;
    1786         }
    1787         //getLastErrorMessage(); // cgiScriptName 
    1788         char* text = (char*)malloc(sizeof(char)*msglen);
    1789 
    1790         snprintf(text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n",
    1791                 zGetpid(), source, line, function, str, sys_t, proc_t, message); // __FILE__ __LINE__ __func__ //
    1792 
    1793         if (file != NULL && (log = fopen(file, "a+")) != NULL) {
    1794                 fputs(text, log);
    1795                 fclose(log);
    1796         }
    1797         else {
     1740 * @param pmsaConf reference to configuration maps
     1741 * @param pccService name of service
     1742 * @param weExc WPSException code
     1743 * @param pccMessage exception text (default: exception text in WPS specification)
     1744 */
     1745void setErrorMessage(maps*& pmsaConf, const char* pccService, WPSException weExc, const char* pccMessage) {
     1746  if (pccMessage == NULL) {
     1747    pccMessage = WPSExceptionText[weExc];
     1748  }
     1749  size_t len = strlen(pccService) + strlen(": ") + strlen(pccMessage) + strlen(": ") + strlen(WPSExceptionCode[weExc]) + 16;
     1750  char* pcMsg = (char*)malloc(len * sizeof(char));
     1751  if (pcMsg != NULL) {
     1752    snprintf(pcMsg, len * sizeof(char), "\n%s: %s: %s\n", pccService, pccMessage, WPSExceptionCode[weExc]);
     1753    setMapInMaps(pmsaConf, "lenv", "message", pcMsg);
     1754    free(pcMsg);
     1755  }
     1756}
     1757
     1758/**
     1759 * Print debug message
     1760 *
     1761 * @param pccSource the file invoking the function
     1762 * @param pccFunction the function calling for logMessage
     1763 * @param iLine the line number
     1764 * @param pccFile the file to log informations
     1765 * @param pccMessage the message to be print
     1766 */
     1767void logMessage(const char* pccSource, const char* pccFunction, int iLne, const char* pccFile, const char* pccMessage) { //, const char* source, const char* function, int line) {
     1768
     1769  size_t msglen = 512;
     1770  const char empty[] = "";
     1771
     1772  FILE* pfLog;
     1773
     1774  // system time, process time [nanoseconds]   
     1775  unsigned long long sys_t, proc_t;
     1776
     1777  // processor time consumed by the program:
     1778  clock_t t = clock();
     1779
     1780  // system time:
     1781  std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
     1782
     1783  std::time_t now_t = std::chrono::system_clock::to_time_t(now);
     1784  std::tm* tm = localtime(&now_t);
     1785  char* pcStr = asctime(tm);
     1786  pcStr[strlen(pcStr) - 1] = '\0'; // remove newline
     1787
     1788  sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
     1789  //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC);
     1790  proc_t = t;
     1791
     1792  if (pccMessage != NULL) {
     1793    msglen += strlen(pccMessage);
     1794  }
     1795  else {
     1796    pccMessage = empty;
     1797  }
     1798  //getLastErrorMessage(); // cgiScriptName 
     1799  char* pcText = (char*)malloc(sizeof(char)*msglen);
     1800
     1801  snprintf(pcText, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n",
     1802           zGetpid(), pccSource, iLne, pccFunction, pcStr, sys_t, proc_t, pccMessage); // __FILE__ __LINE__ __func__ //
     1803
     1804  if (pccFile != NULL && (pfLog = fopen(pccFile, "a+")) != NULL) {
     1805    fputs(pcText, pfLog);
     1806    fclose(pfLog);
     1807  }
     1808  else {
    17981809#ifdef MSG_LOG_FILE
    1799                 if ((log = fopen(MSG_LOG_FILE, "a+")) != NULL) {
    1800                         fputs(text, log);
    1801                         fclose(log);
    1802                 }
     1810    if ((pfLog = fopen(MSG_LOG_FILE, "a+")) != NULL) {
     1811      fputs(pcText, pfLog);
     1812      fclose(pfLog);
     1813    }
    18031814#endif
    1804         }
    1805 
    1806         if (text != NULL) free(text);
     1815  }
     1816
     1817  if (pcText != NULL) free(pcText);
    18071818}
    18081819
     
    18151826#ifdef WIN32
    18161827#ifndef USE_MS
    1817 char *strcasestr (char const *a, char const *b)
     1828char *strcasestr (char const *pccA, char const *pccB)
    18181829  {
    1819     char *x = zStrdup (a);
    1820     char *y = zStrdup (b);
     1830    char *pcX = zStrdup (pccA);
     1831    char *pcY = zStrdup (pccB);
    18211832 
    1822       x = _strlwr (x);
    1823       y = _strlwr (y);
    1824     char *pos = strstr (x, y);
    1825     char *ret = pos == NULL ? NULL : (char *) (a + (pos - x));
    1826       free (x);
    1827       free (y);
     1833      pcX = _strlwr (pcX);
     1834      pcY = _strlwr (pcY);
     1835    char *pos = strstr (pcX, pcY);
     1836    char *ret = pos == NULL ? NULL : (char *) (pccA + (pos - pcX));
     1837      free (pcX);
     1838      free (pcY);
    18281839      return ret;
    18291840  };
     
    18431854 * The memory should be deallocated by calling freeMap.
    18441855 */
    1845 char* allocateMapValue(map* node, size_t num_bytes)
     1856char* allocateMapValue(map* pmNode, size_t sNumBytes)
    18461857{
    1847         if (node == NULL) {
    1848                 return NULL;
    1849         }
    1850 
    1851         if (node->value != NULL) {
    1852                 free(node->value);
    1853         }
    1854         node->value = (char*) malloc(num_bytes);
     1858  if (pmNode == NULL) {
     1859    return NULL;
     1860  }
     1861
     1862  if (pmNode->value != NULL) {
     1863    free(pmNode->value);
     1864  }
     1865  pmNode->value = (char*) malloc(sNumBytes);
    18551866               
    1856         return node->value;
    1857 }
     1867  return pmNode->value;
     1868}
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r962 r967  
    468468  while(tmp!=NULL){
    469469    PyObject* name=PyString_FromString(tmp->name);
    470     if(strcasecmp(tmp->name,"value")==0 && strlen(tmp->value)>0) {
     470    if(strcasecmp(tmp->name,"value")==0) {
    471471      if(isArray!=NULL){
    472472        map* len=getMap(tmp,"length");
     
    492492              lvalue=PyString_FromString(vMap->value);
    493493            }
    494             else{   
    495               lvalue=PyString_FromStringAndSize(vMap->value,atoi(sMap->value));
     494            else{
     495              if(strlen(vMap->value)>0)
     496                lvalue=PyString_FromStringAndSize(vMap->value,atoi(sMap->value));
     497              else
     498                lvalue=Py_None;
    496499            }
    497500            if(sMap!=NULL){
     
    553556      }
    554557      else if(size!=NULL && useFile==NULL){
    555         PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value));
     558        PyObject* value;
     559        if(strlen(tmp->value)>0)
     560          value=PyString_FromStringAndSize(tmp->value,atoi(size->value));
     561        else
     562          value=Py_None;
    556563        if(PyDict_SetItem(res,name,value)<0){
    557564          Py_DECREF(value);
     
    572579    }
    573580    else{
    574       if(PyDict_GetItem(res,name)==NULL && strlen(tmp->value)>0){
     581      if(PyDict_GetItem(res,name)==NULL){
    575582        PyObject* value=PyString_FromString(tmp->value);
    576583        if(PyDict_SetItem(res,name,value)<0){
  • trunk/zoo-project/zoo-kernel/service_json.c

    r965 r967  
    603603   
    604604    map* tmp=getMap(s,"code");
     605    exceptionCode=produceStatusString(m,tmp);   
    605606    if(tmp!=NULL){
    606       if(strcmp(tmp->value,"OperationNotSupported")==0 ||
    607          strcmp(tmp->value,"NoApplicableCode")==0)
    608         exceptionCode="500 Not Implemented";
    609       else
    610         if(strcmp(tmp->value,"MissingParameterValue")==0 ||
    611            strcmp(tmp->value,"InvalidUpdateSequence")==0 ||
    612            strcmp(tmp->value,"OptionNotSupported")==0 ||
    613            strcmp(tmp->value,"VersionNegotiationFailed")==0 ||
    614            strcmp(tmp->value,"InvalidParameterValue")==0)
    615           exceptionCode="400 Bad request";
    616         else
    617           if(strcmp(tmp->value,"NotFound")==0 ||
    618              strcmp(tmp->value,"NoSuchProcess")==0 ||
    619              strcmp(tmp->value,"NoSuchJob")==0 ||
    620              strcmp(tmp->value,"ResultNotReady")==0)
    621             exceptionCode="404 Not Found";
    622           else
    623             exceptionCode="500 Internal Server Error";
    624607      json_object_object_add(res,"code",json_object_new_string(tmp->value));
    625608    }
    626609    else{
    627       exceptionCode="500 Internal Server Error";
    628610      json_object_object_add(res,"code",json_object_new_string("NoApplicableCode"));
    629611    }
     
    716698    json_object* json_cinput=NULL;
    717699    if(json_object_object_get_ex(req,"value",&json_cinput)!=FALSE){
     700      output->content=createMap("value",json_object_get_string(json_cinput));
     701    }
     702    else{
    718703      json_object* json_value=NULL;
    719       if(json_object_object_get_ex(json_cinput,"inlineValue",&json_value)!=FALSE)
    720         output->content=createMap("value",json_object_get_string(json_value));
    721       else{
    722         if(json_object_object_get_ex(json_cinput,"href",&json_value)!=FALSE){
    723           output->content=createMap("xlink:href",json_object_get_string(json_value));
    724           int len=0;
    725           int createdStr=0;
    726           char *tmpStr="url";
    727           char *tmpStr1="input";
    728           if(getMaps(conf,"http_requests")==NULL){
    729             maps* tmpMaps=createMaps("http_requests");
    730             tmpMaps->content=createMap("length","1");
    731             addMapsToMaps(&conf,tmpMaps);
    732             freeMaps(&tmpMaps);
    733             free(tmpMaps);
    734           }else{
    735             map* tmpMap=getMapFromMaps(conf,"http_requests","length");
    736             int len=atoi(tmpMap->value);
    737             createdStr=1;
    738             tmpStr=(char*) malloc((12)*sizeof(char));
    739             sprintf(tmpStr,"%d",len+1);
    740             setMapInMaps(conf,"http_requests","length",tmpStr);
    741             sprintf(tmpStr,"url_%d",len);
    742             tmpStr1=(char*) malloc((14)*sizeof(char));
    743             sprintf(tmpStr1,"input_%d",len);
    744           }
    745           setMapInMaps(conf,"http_requests",tmpStr,json_object_get_string(json_value));
    746           setMapInMaps(conf,"http_requests",tmpStr1,name);
    747           if(createdStr>0){
    748             free(tmpStr);
    749             free(tmpStr1);
    750           }
     704      if(json_object_object_get_ex(req,"href",&json_value)!=FALSE){
     705        output->content=createMap("xlink:href",json_object_get_string(json_value));
     706        int len=0;
     707        int createdStr=0;
     708        char *tmpStr="url";
     709        char *tmpStr1="input";
     710        if(getMaps(conf,"http_requests")==NULL){
     711          maps* tmpMaps=createMaps("http_requests");
     712          tmpMaps->content=createMap("length","1");
     713          addMapsToMaps(&conf,tmpMaps);
     714          freeMaps(&tmpMaps);
     715          free(tmpMaps);
     716        }else{
     717          map* tmpMap=getMapFromMaps(conf,"http_requests","length");
     718          int len=atoi(tmpMap->value);
     719          createdStr=1;
     720          tmpStr=(char*) malloc((12)*sizeof(char));
     721          sprintf(tmpStr,"%d",len+1);
     722          setMapInMaps(conf,"http_requests","length",tmpStr);
     723          sprintf(tmpStr,"url_%d",len);
     724          tmpStr1=(char*) malloc((14)*sizeof(char));
     725          sprintf(tmpStr1,"input_%d",len);
     726        }
     727        setMapInMaps(conf,"http_requests",tmpStr,json_object_get_string(json_value));
     728        setMapInMaps(conf,"http_requests",tmpStr1,name);
     729        if(createdStr>0){
     730          free(tmpStr);
     731          free(tmpStr1);
    751732        }
    752733      }
     
    807788
    808789  /**
    809    * Parse inputs / outputs
     790   * Parse a single input / output entity
     791   *
     792   * @param conf the maps containing the settings of the main.cfg file
     793   * @param ioElements the elements extracted from the zcfg
     794   * @param ioMaps the produced maps containing inputs (or outputs)
     795   * @param ioType the char* set to inputs or outputs
     796   * @param key char* the input/output name
     797   * @param val json_object pointing to the input/output
     798   * @param cMaps the outputed maps containing input (or output) metedata
     799   */
     800  void _parseJIOSingle(maps* conf,elements* cio, maps** ioMaps,const char* ioType,const char* key,json_object* val,maps* cMaps){
     801    json_object* json_cinput;
     802    if(json_object_object_get_ex(val,"dataType",&json_cinput)!=FALSE){
     803      parseJLiteral(conf,val,cio,cMaps);
     804    } else if(json_object_object_get_ex(val,"format",&json_cinput)!=FALSE){
     805      parseJComplex(conf,val,cio,cMaps,key);
     806    } else if(json_object_object_get_ex(val,"bbox",&json_cinput)!=FALSE){
     807      parseJBoundingBox(conf,val,cio,cMaps);
     808    }// else error!
     809    else{
     810      if(json_object_object_get_ex(val,"value",&json_cinput)!=FALSE){
     811        map* error=createMap("code","BadRequest");
     812        char tmpS[1024];
     813        sprintf(tmpS,_("Missing input for %s"),cio->name);
     814        addToMap(error,"message",tmpS);
     815        setMapInMaps(conf,"lenv","status_code","400 Bad Request");
     816        printExceptionReportResponseJ(conf,error);
     817        return;
     818      }else{
     819        if(json_object_get_type(json_cinput)==json_type_string){
     820          parseJLiteral(conf,val,cio,cMaps);
     821        }else if(json_object_get_type(json_cinput)==json_type_object){
     822          json_object* json_ccinput=NULL;
     823          if(json_object_object_get_ex(json_cinput,"bbox",&json_ccinput)!=FALSE){
     824            parseJComplex(conf,val,cio,cMaps,key);
     825          }
     826          else{
     827            parseJBoundingBox(conf,val,cio,cMaps);
     828          }
     829        }else{
     830          if(strcmp(ioType,"input")==0){
     831            map* error=createMap("code","BadRequest");
     832            char tmpS1[1024];
     833            sprintf(tmpS1,_("Issue with input %s"),cio->name);
     834            addToMap(error,"message",tmpS1);
     835            setMapInMaps(conf,"lenv","status_code","400 Bad Request");
     836            printExceptionReportResponseJ(conf,error);
     837            return;
     838          }
     839        }
     840      }
     841    }   
     842  }
     843 
     844  /**
     845   * Parse a single input / output entity that can be an array
     846   *
     847   * @param conf the maps containing the settings of the main.cfg file
     848   * @param ioElements the elements extracted from the zcfg
     849   * @param ioMaps the produced maps containing inputs (or outputs)
     850   * @param ioType the char* set to inputs or outputs
     851   * @param key char* the input/output name
     852   * @param val json_object pointing to the input/output
     853   */
     854  void parseJIOSingle(maps* conf,elements* ioElements, maps** ioMaps,const char* ioType,const char* key,json_object* val){
     855    maps *cMaps=NULL;
     856    cMaps=createMaps(key);
     857    elements* cio=getElements(ioElements,key);   
     858    if(json_object_is_type(val,json_type_array)){
     859      int i=0;
     860      size_t len=json_object_array_length(val);
     861      for(i=0;i<len;i++){
     862        json_object* json_current_io=json_object_array_get_idx(val,i);
     863        maps* pmsExtra=createMaps(key);
     864        _parseJIOSingle(conf,cio,ioMaps,ioType,key,json_current_io,pmsExtra);
     865        map* pmCtx=pmsExtra->content;
     866        while(pmCtx!=NULL){
     867          if(cMaps->content==NULL)
     868            cMaps->content=createMap(pmCtx->name,pmCtx->value);
     869          else
     870            setMapArray(cMaps->content,pmCtx->name,i,pmCtx->value);
     871          pmCtx=pmCtx->next;
     872        }
     873        freeMaps(&pmsExtra);
     874        free(pmsExtra);
     875      }
     876    }else{
     877      _parseJIOSingle(conf,cio,ioMaps,ioType,key,val,cMaps);
     878    }
     879
     880   
     881    if(strcmp(ioType,"outputs")==0){
     882      // Outputs
     883      json_object* json_cinput;
     884      if(json_object_object_get_ex(val,"transmissionMode",&json_cinput)!=FALSE){
     885        if(cMaps->content==NULL)
     886          cMaps->content=createMap("transmissionMode",json_object_get_string(json_cinput));
     887        else
     888          addToMap(cMaps->content,"transmissionMode",json_object_get_string(json_cinput));
     889      }
     890      if(json_object_object_get_ex(val,"format",&json_cinput)!=FALSE){
     891        json_object_object_foreach(json_cinput, key1, val1) {
     892          if(cMaps->content==NULL)
     893            cMaps->content=createMap(key1,json_object_get_string(val1));
     894          else
     895            addToMap(cMaps->content,key1,json_object_get_string(val1));
     896        }
     897      }
     898    }
     899
     900    addToMap(cMaps->content,"inRequest","true");
     901    if (ioMaps == NULL)
     902      *ioMaps = dupMaps(&cMaps);
     903    else
     904      addMapsToMaps (ioMaps, cMaps);
     905
     906    freeMaps(&cMaps);
     907    free(cMaps);   
     908  }
     909 
     910  /**
     911   * Parse all the inputs / outputs entities
     912   *
    810913   * @param conf the maps containing the settings of the main.cfg file
    811914   * @param req json_object pointing to the input/output
     
    816919  void parseJIO(maps* conf, json_object* req, elements* ioElements, maps** ioMaps,const char* ioType){
    817920    json_object* json_io=NULL;
    818     if(json_object_object_get_ex(req,ioType,&json_io)!=FALSE){     
     921    if(json_object_object_get_ex(req,ioType,&json_io)!=FALSE){
    819922      json_object* json_current_io=NULL;
    820       size_t len=json_object_array_length(json_io);
    821       for(int i=0;i<len;i++){
    822         maps *cMaps=NULL;
    823         json_current_io=json_object_array_get_idx(json_io,i);
    824         json_object* cname=NULL;
    825         if(json_object_object_get_ex(json_current_io,"id",&cname)!=FALSE){
    826           cMaps=createMaps(json_object_get_string(cname));
    827           elements* cio=getElements(ioElements,json_object_get_string(cname));
    828           json_object* json_input;
    829           json_object* json_cinput;
    830           if(json_object_object_get_ex(json_current_io,"input",&json_input)!=FALSE){
    831             if(json_object_object_get_ex(json_input,"dataType",&json_cinput)!=FALSE){
    832               parseJLiteral(conf,json_input,cio,cMaps);
    833             } else if(json_object_object_get_ex(json_input,"format",&json_cinput)!=FALSE){
    834               parseJComplex(conf,json_input,cio,cMaps,json_object_get_string(cname));
    835             } else if(json_object_object_get_ex(json_input,"bbox",&json_cinput)!=FALSE){
    836               parseJBoundingBox(conf,json_input,cio,cMaps);
    837             }// else error!
    838             else{
    839               if(json_object_object_get_ex(json_input,"value",&json_cinput)!=FALSE){
    840                 map* error=createMap("code","BadRequest");
    841                 char tmpS[1024];
    842                 sprintf(tmpS,_("Missing input for %s"),ioElements->name);
    843                 addToMap(error,"message",tmpS);
    844                 setMapInMaps(conf,"lenv","status_code","400 Bad Request");
    845                 printExceptionReportResponseJ(conf,error);
    846                 return;
    847               }else{
    848                 if(json_object_get_type(json_cinput)==json_type_string){
    849                   parseJLiteral(conf,json_input,cio,cMaps);
    850                 }else if(json_object_get_type(json_cinput)==json_type_object){
    851                   json_object* json_ccinput=NULL;
    852                   if(json_object_object_get_ex(json_cinput,"bbox",&json_ccinput)!=FALSE){
    853                     parseJComplex(conf,json_input,cio,cMaps,json_object_get_string(cname));
    854                   }
    855                   else{
    856                     parseJBoundingBox(conf,json_input,cio,cMaps);
    857                   }
    858                 }else{
    859                   if(strcmp(ioType,"input")==0){
    860                     map* error=createMap("code","BadRequest");
    861                     char tmpS1[1024];
    862                     sprintf(tmpS1,_("Issue with input %s"),ioElements->name);
    863                     addToMap(error,"message",tmpS1);
    864                     setMapInMaps(conf,"lenv","status_code","400 Bad Request");
    865                     printExceptionReportResponseJ(conf,error);
    866                     return;
    867                   }
    868                 }
    869               }
    870             }
    871           }else{
    872             if(strcmp(ioType,"input")==0){
    873               map* error=createMap("code","BadRequest");
    874               char tmpS1[1024];
    875               sprintf(tmpS1,_("Missing input for %s"),ioElements->name);
    876               addToMap(error,"message",tmpS1);
    877               setMapInMaps(conf,"lenv","status_code","400 Bad Request");
    878               printExceptionReportResponseJ(conf,error);
    879               return;
    880             }else{
    881               // Outputs
    882               if(json_object_object_get_ex(json_current_io,"transmissionMode",&json_cinput)!=FALSE){
    883                 if(cMaps->content==NULL)
    884                   cMaps->content=createMap("transmissionMode",json_object_get_string(json_cinput));
    885                 else
    886                   addToMap(cMaps->content,"transmissionMode",json_object_get_string(json_cinput));
    887               }
    888               if(json_object_object_get_ex(json_current_io,"format",&json_cinput)!=FALSE){
    889                 json_object_object_foreach(json_cinput, key, val) {
    890                   if(cMaps->content==NULL)
    891                     cMaps->content=createMap(key,json_object_get_string(val));
    892                   else
    893                     addToMap(cMaps->content,key,json_object_get_string(val));
    894                 }
    895               }       
    896             }
     923      if(json_object_is_type(json_io,json_type_array)){
     924        size_t len=json_object_array_length(json_io);
     925        for(int i=0;i<len;i++){
     926          maps *cMaps=NULL;
     927          json_current_io=json_object_array_get_idx(json_io,i);
     928          json_object* cname=NULL;
     929          if(json_object_object_get_ex(json_current_io,"id",&cname)!=FALSE) {
     930            json_object* json_input=NULL;
     931            if(json_object_object_get_ex(json_current_io,"input",&json_input)!=FALSE) {     
     932              parseJIOSingle(conf,ioElements,ioMaps,ioType,json_object_get_string(cname),json_input);
     933            }else
     934              parseJIOSingle(conf,ioElements,ioMaps,ioType,json_object_get_string(cname),json_current_io);
    897935          }
    898936        }
    899         addToMap(cMaps->content,"inRequest","true");
    900         if (ioMaps == NULL)
    901           *ioMaps = dupMaps(&cMaps);
    902         else
    903           addMapsToMaps (ioMaps, cMaps);
     937      }else{
     938        json_object_object_foreach(json_io, key, val) {
     939          parseJIOSingle(conf,ioElements,ioMaps,ioType,key,val);
     940        }
    904941      }
    905942    }
     
    924961    maps* in=*inputs;
    925962    parseJIO(conf,req,s->inputs,inputs,"inputs");
     963    parseJIO(conf,req,s->outputs,outputs,"outputs");
    926964
    927965    if(parsed==0){
    928       json_io=NULL;
    929       if(json_object_object_get_ex(req,"outputs",&json_io)!=FALSE){
    930         parseJIO(conf,req,s->outputs,outputs,"outputs");
    931       }
    932966      json_io=NULL;
    933967      if(json_object_object_get_ex(req,"mode",&json_io)!=FALSE){
     
    9671001  }
    9681002
     1003  /**
     1004   * Print the jobs status info
     1005   * cf.
     1006   *
     1007   * @param conf the maps containing the settings of the main.cfg file
     1008   * @return the JSON object pointer to the jobs list
     1009   */
     1010  json_object* printJobStatus(maps* pmsConf,char* pcJobId){
     1011    json_object* pjoRes=NULL;
     1012    runGetStatus(pmsConf,pcJobId,"GetStatus");
     1013    map* pmError=getMapFromMaps(pmsConf,"lenv","error");
     1014    if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){
     1015      printExceptionReportResponseJ(pmsConf,getMapFromMaps(pmsConf,"lenv","code"));
     1016      return NULL;
     1017    }else{
     1018      map* pmStatus=getMapFromMaps(pmsConf,"lenv","status");
     1019      setMapInMaps(pmsConf,"lenv","gs_location","false");
     1020      setMapInMaps(pmsConf,"lenv","gs_usid",pcJobId);
     1021      if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Failed",6)==0)
     1022        pjoRes=createStatus(pmsConf,SERVICE_FAILED);
     1023      else
     1024        if(pmStatus!=NULL  && strncasecmp(pmStatus->value,"Succeeded",9)==0)
     1025          pjoRes=createStatus(pmsConf,SERVICE_SUCCEEDED);
     1026        else
     1027          if(pmStatus!=NULL  && strncasecmp(pmStatus->value,"Running",7)==0){
     1028            map* tmpMap=getMapFromMaps(pmsConf,"lenv","Message");
     1029            if(tmpMap!=NULL)
     1030              setMapInMaps(pmsConf,"lenv","gs_message",tmpMap->value);
     1031            pjoRes=createStatus(pmsConf,SERVICE_STARTED);
     1032          }
     1033          else
     1034            pjoRes=createStatus(pmsConf,SERVICE_FAILED);
     1035    }
     1036    return pjoRes;
     1037  }
     1038 
    9691039  /**
    9701040   * Print the jobs list
     
    9851055        char* extn = strstr(dp->d_name, ".json");
    9861056        if(extn!=NULL){
    987           json_object* cjob=json_object_new_object();
    9881057          char* tmpStr=zStrdup(dp->d_name);
    9891058          tmpStr[strlen(dp->d_name)-5]=0;
     1059          json_object* cjob=json_object_new_object();
    9901060          json_object_object_add(cjob,"id",json_object_new_string(tmpStr));
    991           char *tmps1=(char*)malloc((strlen(cpath)+strlen(dp->d_name)+2)*sizeof(char));
    992           sprintf (tmps1, "%s/%s", cpath, dp->d_name);
    993           FILE* cdat=fopen(tmps1,"rb");
    994           if(cdat!=NULL){
    995             zStatStruct f_status;
    996             int s=zStat(tmps1, &f_status);
    997             char* mystring=(char*)malloc((f_status.st_size+1)*sizeof(char));
    998             fread(mystring,1,f_status.st_size,cdat);
    999             mystring[f_status.st_size]=0;           
    1000             json_object *jobj = NULL;
    1001             int slen = 0;
    1002             enum json_tokener_error jerr;
    1003             struct json_tokener* tok=json_tokener_new();
    1004             do {
    1005               slen = strlen(mystring);
    1006               jobj = json_tokener_parse_ex(tok, mystring, slen);
    1007             } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue);
    1008             if (jerr != json_tokener_success) {
    1009               fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
    1010               return NULL;
    1011             }
    1012             if (tok->char_offset < slen){
    1013               return NULL;
    1014             }
     1061          json_object *jobj=printJobStatus(conf,tmpStr);
     1062          if(jobj!=NULL)
    10151063            json_object_object_add(cjob,"infos",jobj);
    1016             free(mystring);
    1017             fclose(cdat);
    1018           }
    10191064          free(tmpStr);
    10201065          json_object_array_add(res,cjob);
     
    10361081   */
    10371082  json_object* printJResult(maps* conf,service* s,maps* result,int res){
    1038     json_object* eres1=json_object_new_object();
    10391083    if(res==SERVICE_FAILED){
    10401084      char* pacTmp=produceErrorMessage(conf);
     
    10511095    if(getMapFromMaps(conf,"lenv","no-headers")==NULL)
    10521096      printHeaders(conf);
    1053     json_object* eres=json_object_new_array();
    1054     maps* resu=result;
    1055     int itn=0;
    1056     while(resu!=NULL){
    1057       json_object* res1=json_object_new_object();
    1058       json_object_object_add(res1,"id",json_object_new_string(resu->name));
    1059       map* tmpMap=getMap(resu->content,"mimeType");
    1060       json_object* res3=json_object_new_object();
    1061       if(tmpMap!=NULL)
    1062         json_object_object_add(res3,"mimeType",json_object_new_string(tmpMap->value));
    1063       if((tmpMap=getMap(resu->content,"value"))!=NULL ||
    1064          (getMap(resu->content,"generated_file"))!=NULL){
    1065         json_object* res2=json_object_new_object();
    1066         map* tmpMap1=NULL;
    1067         if((tmpMap1=getMap(resu->content,"transmissionMode"))!=NULL) {
    1068           if(strcmp(tmpMap1->value,"value")==0) {
    1069             map* tmpMap2=getMap(resu->content,"mimeType");
    1070             if(tmpMap2!=NULL && strstr(tmpMap2->value,"json")!=NULL){
    1071               json_object *jobj = NULL;
    1072               int slen = 0;
    1073               enum json_tokener_error jerr;
    1074               struct json_tokener* tok=json_tokener_new();
    1075               do {
    1076                 slen = strlen(tmpMap->value);
    1077                 jobj = json_tokener_parse_ex(tok, tmpMap->value, slen);
    1078               } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue);
    1079               if (jerr != json_tokener_success) {
    1080                 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
    1081                 return eres1;
     1097    map* pmMode=getMapFromMaps(conf,"request","response");
     1098    if(pmMode!=NULL && strncasecmp(pmMode->value,"raw",3)==0){
     1099      maps* resu=result;
     1100      printRawdataOutput(conf,resu);
     1101      map* pmError=getMapFromMaps(conf,"lenv","error");
     1102      if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){
     1103        printExceptionReportResponseJ(conf,pmError);
     1104      }
     1105      return NULL;
     1106    }else{
     1107      json_object* eres1=json_object_new_object();
     1108      map* pmIOAsArray=getMapFromMaps(conf,"openapi","io_as_array");
     1109      json_object* eres;
     1110      if(pmIOAsArray!=NULL && strncasecmp(pmIOAsArray->value,"true",4)==0)
     1111        eres=json_object_new_array();
     1112      else
     1113        eres=json_object_new_object();
     1114      maps* resu=result;
     1115      int itn=0;
     1116      while(resu!=NULL){
     1117        json_object* res1=json_object_new_object();
     1118        if(pmIOAsArray!=NULL && strncasecmp(pmIOAsArray->value,"true",4)==0)
     1119          json_object_object_add(res1,"id",json_object_new_string(resu->name));
     1120        map* tmpMap=getMap(resu->content,"mimeType");
     1121        json_object* res3=json_object_new_object();
     1122        if(tmpMap!=NULL)
     1123          json_object_object_add(res3,"mimeType",json_object_new_string(tmpMap->value));
     1124        else{
     1125          json_object_object_add(res3,"mimeType",json_object_new_string("text/plain"));
     1126          map* pmDataType=getMap(resu->content,"dataType");
     1127          if(pmDataType!=NULL){
     1128            json_object* pjoTmp3=json_object_new_object();
     1129            json_object_object_add(pjoTmp3,"name",json_object_new_string(pmDataType->value));
     1130            json_object_object_add(res1,"dataType",pjoTmp3);
     1131          }
     1132        }
     1133        if((tmpMap=getMap(resu->content,"value"))!=NULL ||
     1134           (getMap(resu->content,"generated_file"))!=NULL){
     1135          //json_object* res2=json_object_new_object();
     1136          map* tmpMap1=NULL;
     1137          if((tmpMap1=getMap(resu->content,"transmissionMode"))!=NULL) {
     1138            if(strcmp(tmpMap1->value,"value")==0) {
     1139              map* tmpMap2=getMap(resu->content,"mimeType");
     1140              if(tmpMap2!=NULL && strstr(tmpMap2->value,"json")!=NULL){
     1141                json_object *jobj = NULL;
     1142                int slen = 0;
     1143                enum json_tokener_error jerr;
     1144                struct json_tokener* tok=json_tokener_new();
     1145                do {
     1146                  slen = strlen(tmpMap->value);
     1147                  jobj = json_tokener_parse_ex(tok, tmpMap->value, slen);
     1148                } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue);
     1149                if (jerr != json_tokener_success) {
     1150                  fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
     1151                  return eres1;
     1152                }
     1153                if (tok->char_offset < slen){
     1154                  return eres1;         
     1155                }
     1156                json_object_object_add(res3,"encoding",json_object_new_string("utf-8"));
     1157                json_object_object_add(res1,"value",jobj);
     1158              }else{
     1159                map* tmp1=getMapFromMaps(conf,"main","tmpPath");
     1160                map *gfile=getMap(resu->content,"generated_file");
     1161                if(gfile!=NULL){
     1162                  gfile=getMap(resu->content,"expected_generated_file");
     1163                  if(gfile==NULL){
     1164                    gfile=getMap(resu->content,"generated_file");
     1165                  }
     1166                  FILE* pfData=fopen(gfile->value,"rb");
     1167                  if(pfData!=NULL){
     1168                    zStatStruct f_status;
     1169                    int s=zStat(gfile->value, &f_status);
     1170                    char* pcaTmp=(char*)malloc((f_status.st_size+1)*sizeof(char));
     1171                    fread(pcaTmp,1,f_status.st_size,pfData);
     1172                    pcaTmp[f_status.st_size]=0;     
     1173                    fclose(pfData);
     1174                    json_object_object_add(res1,"value",json_object_new_string(base64(pcaTmp,f_status.st_size)));
     1175                    json_object_object_add(res3,"encoding",json_object_new_string("base64"));
     1176                    free(pcaTmp);
     1177                  }
     1178                }else{
     1179                  json_object_object_add(res3,"encoding",json_object_new_string("utf-8"));
     1180                  json_object_object_add(res1,"value",json_object_new_string(tmpMap->value));
     1181                }
    10821182              }
    1083               if (tok->char_offset < slen){
    1084                 return eres1;           
    1085               }
    1086               json_object_object_add(res3,"encoding",json_object_new_string("utf-8"));
    1087               json_object_object_add(res2,"inlineValue",jobj);
    1088             }else{
    1089               map* tmp1=getMapFromMaps(conf,"main","tmpPath");
    1090               map *gfile=getMap(resu->content,"generated_file");
    1091               if(gfile!=NULL){
    1092                 gfile=getMap(resu->content,"expected_generated_file");
    1093                 if(gfile==NULL){
    1094                   gfile=getMap(resu->content,"generated_file");
    1095                 }
    1096                 FILE* pfData=fopen(gfile->value,"rb");
    1097                 if(pfData!=NULL){
    1098                   zStatStruct f_status;
    1099                   int s=zStat(gfile->value, &f_status);
    1100                   char* pcaTmp=(char*)malloc((f_status.st_size+1)*sizeof(char));
    1101                   fread(pcaTmp,1,f_status.st_size,pfData);
    1102                   pcaTmp[f_status.st_size]=0;       
    1103                   fclose(pfData);
    1104                   json_object_object_add(res2,"inlineValue",json_object_new_string(base64(pcaTmp,f_status.st_size)));
    1105                   json_object_object_add(res3,"encoding",json_object_new_string("base64"));
    1106                   free(pcaTmp);
    1107                 }
    1108               }else{
    1109                 json_object_object_add(res3,"encoding",json_object_new_string("utf-8"));
    1110                 json_object_object_add(res2,"inlineValue",json_object_new_string(tmpMap->value));
     1183            }
     1184            else{
     1185              char *pcaFileUrl=produceFileUrl(s,conf,resu,NULL,itn);
     1186              itn++;
     1187              if(pcaFileUrl!=NULL){
     1188                json_object_object_add(res1,"href",
     1189                                       json_object_new_string(pcaFileUrl));
     1190                free(pcaFileUrl);
    11111191              }
    11121192            }
    11131193          }
    1114           else{
    1115             // Create file for reference data if not existing
    1116             map *gfile=getMap(resu->content,"generated_file");
    1117             char *file_name=NULL;
    1118             char *file_path=NULL;
    1119             char *file_url=NULL;
    1120             map *tmp1=getMapFromMaps(conf,"main","tmpPath");
    1121             if(gfile!=NULL){
    1122               gfile=getMap(resu->content,"expected_generated_file");
    1123               if(gfile==NULL){
    1124                 gfile=getMap(resu->content,"generated_file");
    1125               }
    1126               if(strstr(gfile->value,tmp1->value)!=NULL)
    1127                 file_name=zStrdup(strstr(gfile->value,tmp1->value)+strlen(tmp1->value));
    1128             }/*else*/
    1129             {
    1130               // Create file for reference data
    1131               map *tmpUrl=getMapFromMaps(conf,"main","tmpUrl");
    1132               map *usid=getMapFromMaps(conf,"lenv","usid");
    1133               map *ext=getMap(resu->content,"extension");
    1134               if(gfile==NULL){
    1135                 char file_ext[32];         
    1136                 if( ext != NULL && ext->value != NULL) {
    1137                   strncpy(file_ext, ext->value, 32);
    1138                 }
    1139                 else {
    1140                   // Obtain default file extension (see mimetypes.h).         
    1141                   // If the MIME type is not recognized, txt is used as the default extension
    1142                   map* mtype=getMap(resu->content,"mimeType");
    1143                   getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
    1144                 }
    1145                 if(file_name!=NULL)
    1146                   free(file_name);
    1147              
    1148                 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(resu->name)+45)*sizeof(char));
    1149                 sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,resu->name,usid->value,itn,file_ext);
    1150 
    1151                 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
    1152                 sprintf(file_path,"%s/%s",tmp1->value,file_name);
    1153               }else{
    1154                 file_path=(char*)malloc((strlen(gfile->value)+1)*sizeof(char));
    1155                 sprintf(file_path,"%s",gfile->value);
    1156               }
    1157                
    1158              
    1159               itn++;
    1160              
    1161               file_url=(char*)malloc((strlen(tmpUrl->value)+
    1162                                       strlen(file_name)+2)*sizeof(char));
    1163               sprintf(file_url,"%s/%s",tmpUrl->value,file_name);
    1164 
    1165               if(gfile==NULL){
    1166                 FILE *ofile=fopen(file_path,"wb");
    1167                 if(ofile==NULL){
    1168                   char tmpMsg[1024];
    1169                   sprintf(tmpMsg,
    1170                           _("Unable to create the file \"%s\" for storing the %s final result."),
    1171                           file_name,resu->name);
    1172                   map* error=createMap("code","InternalError");
    1173                   addToMap(error,"message",tmpMsg);
    1174                   printExceptionReportResponseJ(conf,error);
    1175                   free(file_name);
    1176                   free(file_path);
    1177                   return NULL;
    1178                 }
    1179 
    1180                 map* toto=getMap(resu->content,"value");
    1181                 if(toto==NULL){
    1182                   char tmpMsg[1024];
    1183                   sprintf(tmpMsg,
    1184                           _("No value found for the requested output %s."),
    1185                           resu->name);
    1186                   map* error=createMap("code","InternalError");
    1187                   addToMap(error,"message",tmpMsg);
    1188                   printExceptionReportResponseJ(conf,error);
    1189                   fclose(ofile);
    1190                   free(file_name);
    1191                   free(file_path);
    1192                   return NULL;
    1193                 }
    1194                 map* size=getMap(resu->content,"size");
    1195                 if(size!=NULL && toto!=NULL)
    1196                   fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
    1197                 else
    1198                   if(toto!=NULL && toto->value!=NULL)
    1199                     fwrite(toto->value,1,
    1200                            strlen(toto->value)*sizeof(char),ofile);
    1201                 fclose(ofile);
    1202               }
    1203               json_object_object_add(res2,"href",
    1204                                      json_object_new_string(file_url));
    1205               free(file_url);
    1206               free(file_name);
    1207               free(file_path);
    1208              
    1209             }
    1210            
    1211           }
    1212         }
    1213         json_object_object_add(res1,"value",res2);     
    1214         json_object_object_add(res1,"format",res3);     
    1215         json_object_array_add(eres,res1);
    1216       }
    1217       resu=resu->next;
    1218     }
    1219     json_object_object_add(eres1,"outputs",eres);
    1220     const char* jsonStr =
    1221       json_object_to_json_string_ext(eres1,JSON_C_TO_STRING_PLAIN);
    1222     map *tmpPath = getMapFromMaps (conf, "main", "tmpPath");
    1223     map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");
    1224     map *sessId = getMapFromMaps (conf, "lenv", "usid");
    1225     char *pacTmp=(char*)malloc((strlen(tmpPath->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char));
    1226     sprintf(pacTmp,"%s/%s_%s.json",
    1227             tmpPath->value,cIdentifier->value,sessId->value);
    1228     zStatStruct zsFStatus;
    1229     int iS=zStat(pacTmp, &zsFStatus);
    1230     if(iS==0 && zsFStatus.st_size>0){
    1231       map* tmpPath1 = getMapFromMaps (conf, "main", "tmpUrl");
    1232       char* pacTmpUrl=(char*)malloc((strlen(tmpPath1->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char));;
    1233       sprintf(pacTmpUrl,"%s/%s_%s.json",tmpPath1->value,
    1234               cIdentifier->value,sessId->value);
    1235       if(getMapFromMaps(conf,"lenv","gs_location")==NULL)
    1236         setMapInMaps(conf,"headers","Location",pacTmpUrl);
    1237       free(pacTmpUrl);
    1238     }
    1239     free(pacTmp);
    1240     if(res==3){
    1241       map* mode=getMapFromMaps(conf,"request","mode");
    1242       if(mode!=NULL && strncasecmp(mode->value,"async",5)==0)
    1243         setMapInMaps(conf,"headers","Status","201 Created");
    1244       else
    1245         setMapInMaps(conf,"headers","Status","200 Ok");
    1246     }
    1247     else{
    1248       setMapInMaps(conf,"headers","Status","500 Issue running your service");
    1249     }
    1250     return eres1;
     1194          //json_object_object_add(res1,"value",res2);
     1195          json_object_object_add(res1,"format",res3);
     1196          if(pmIOAsArray!=NULL && strncasecmp(pmIOAsArray->value,"true",4)==0){
     1197            json_object_array_add(eres,res1);
     1198          }else
     1199            json_object_object_add(eres,resu->name,res1);
     1200        }
     1201        resu=resu->next;
     1202      }
     1203      json_object_object_add(eres1,"outputs",eres);
     1204      const char* jsonStr =
     1205        json_object_to_json_string_ext(eres1,JSON_C_TO_STRING_PLAIN);
     1206      map *tmpPath = getMapFromMaps (conf, "main", "tmpPath");
     1207      map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");
     1208      map *sessId = getMapFromMaps (conf, "lenv", "usid");
     1209      char *pacTmp=(char*)malloc((strlen(tmpPath->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char));
     1210      sprintf(pacTmp,"%s/%s_%s.json",
     1211              tmpPath->value,cIdentifier->value,sessId->value);
     1212      zStatStruct zsFStatus;
     1213      int iS=zStat(pacTmp, &zsFStatus);
     1214      if(iS==0 && zsFStatus.st_size>0){
     1215        map* tmpPath1 = getMapFromMaps (conf, "main", "tmpUrl");
     1216        char* pacTmpUrl=(char*)malloc((strlen(tmpPath1->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char));;
     1217        sprintf(pacTmpUrl,"%s/%s_%s.json",tmpPath1->value,
     1218                cIdentifier->value,sessId->value);
     1219        if(getMapFromMaps(conf,"lenv","gs_location")==NULL)
     1220          setMapInMaps(conf,"headers","Location",pacTmpUrl);
     1221        free(pacTmpUrl);
     1222      }
     1223      free(pacTmp);
     1224      if(res==3){
     1225        map* mode=getMapFromMaps(conf,"request","mode");
     1226        if(mode!=NULL && strncasecmp(mode->value,"async",5)==0)
     1227          setMapInMaps(conf,"headers","Status","201 Created");
     1228        else
     1229          setMapInMaps(conf,"headers","Status","200 Ok");
     1230      }
     1231      else{
     1232        setMapInMaps(conf,"headers","Status","500 Issue running your service");
     1233      }
     1234      return eres1;
     1235    }
    12511236  }
    12521237
     
    13381323    }
    13391324    tmp1=(char*) realloc(tmp1,(strlen(tmpPath->value)+
    1340                          strlen(cIdentifier->value)+
    1341                          strlen(sessId->value)+21)*sizeof(char));
     1325                               strlen(cIdentifier->value)+
     1326                               strlen(sessId->value)+21)*sizeof(char));
    13421327    int needResult=0;
    13431328    char *message, *rstatus;
     
    16521637      json_object_object_add(cc,"$ref",json_object_new_string(pmSchema->value));
    16531638    if(useContent!=NULL && strncasecmp(useContent->value,"true",4)!=0){
    1654         json_object_object_add(res,code,cc);
     1639      json_object_object_add(res,code,cc);
    16551640    }else{
    1656         json_object *cc0=json_object_new_object();
    1657         if(pmSchema!=NULL)
    1658           json_object_object_add(cc0,"schema",cc);
    1659         json_object *cc1=json_object_new_object();
    1660         if(pmType!=NULL)
    1661           json_object_object_add(cc1,pmType->value,cc0);
    1662         else
    1663           json_object_object_add(cc1,"application/json",cc0);
    1664         json_object *cc2=json_object_new_object();
    1665         json_object_object_add(cc2,"content",cc1);
    1666         json_object_object_add(cc2,"description",json_object_new_string(msg));
    1667         json_object_object_add(res,code,cc2);
     1641      json_object *cc0=json_object_new_object();
     1642      if(pmSchema!=NULL)
     1643        json_object_object_add(cc0,"schema",cc);
     1644      json_object *cc1=json_object_new_object();
     1645      if(pmType!=NULL)
     1646        json_object_object_add(cc1,pmType->value,cc0);
     1647      else
     1648        json_object_object_add(cc1,"application/json",cc0);
     1649      json_object *cc2=json_object_new_object();
     1650      json_object_object_add(cc2,"content",cc1);
     1651      json_object_object_add(cc2,"description",json_object_new_string(msg));
     1652      json_object_object_add(res,code,cc2);
    16681653    }
    16691654  }
  • trunk/zoo-project/zoo-kernel/service_json.h

    r962 r967  
    5252  void parseJRequest(maps*,service* s,json_object*,map*,maps**,maps**);
    5353  json_object*  printJResult(maps*,service*,maps*,int);
     54  json_object* printJobStatus(maps*,char*);
    5455  json_object* printJobList(maps*);
    5556  int createStatusFile(maps*,int);
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r966 r967  
    419419 
    420420  map* errormap = createMap("text", tmp01);
    421   map* tmpMap=getMapFromMaps(m,"lenv","executionType");
     421  map* tmpMap=getMapFromMaps(m,"main","executionType");
    422422  char* errorCode=(char*)code;
    423423  if(tmpMap!=NULL && strncasecmp(tmpMap->value,"json",4)==0)
     
    18881888  maps *request_input_real_format = NULL;
    18891889
    1890   setMapInMaps(m,"lenv","executionType","xml");
     1890  setMapInMaps(m,"main","executionType","xml");
    18911891  if((strlen(cgiQueryString)>0 && cgiQueryString[0]=='/') /*&& strstr(cgiAccept,"json")!=NULL*/){
    18921892    //
    1893     // OGC API - Processing starts here
     1893    // OGC API - Processes starts here
    18941894    //
    18951895#ifndef USE_JSON
    1896     errorException (m, _("OGC API - Processing is not supported by this ZOO-Kernel."), "InternalError", NULL);
     1896    errorException (m, _("OGC API - Processes is not supported by this ZOO-Kernel, please contact the service provider."), "InternalError", NULL);
    18971897    return 1;
    18981898#else
     
    19081908    signal (SIGABRT, json_sig_handler);
    19091909#endif
     1910    setMapInMaps(m,"main","executionType","json");
    19101911    r_inputs = getMapOrFill (&request_inputs, "metapath", "");
    19111912    char conf_file1[10240];
     
    19201921      }
    19211922    addMapsToMaps(&m,m1);
    1922     setMapInMaps(m,"lenv","executionType","json");
    19231923    map* pmTmp0=getMapFromMaps(m,"openapi","full_html_support");
    1924     dumpMap(pmTmp0);
    19251924    if(strstr(cgiQueryString,".html")==NULL && strstr(cgiAccept,"text/html")!=NULL && pmTmp0!=NULL && strncasecmp(pmTmp0->value,"true",4)==0){
    19261925      map* pmTmpUrl=getMapFromMaps(m,"openapi","rootUrl");
     
    23052304                }else{
    23062305                  char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
    2307                   runGetStatus(m,jobId,"GetStatus");
    2308                   map* pmError=getMapFromMaps(m,"lenv","error");
    2309                   if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){
    2310                     printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code"));
    2311                     return 1;
    2312                   }else{
    2313                     map* pmStatus=getMapFromMaps(m,"lenv","status");
    2314                     setMapInMaps(m,"lenv","gs_location","false");
    2315                     setMapInMaps(m,"lenv","gs_usid",jobId);
    2316                     if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Failed",6)==0)
    2317                       res=createStatus(m,SERVICE_FAILED);
    2318                     else
    2319                       if(pmStatus!=NULL  && strncasecmp(pmStatus->value,"Succeeded",9)==0)
    2320                         res=createStatus(m,SERVICE_SUCCEEDED);
    2321                       else
    2322                         if(pmStatus!=NULL  && strncasecmp(pmStatus->value,"Running",7)==0){
    2323                           map* tmpMap=getMapFromMaps(m,"lenv","Message");
    2324                           if(tmpMap!=NULL)
    2325                             setMapInMaps(m,"lenv","gs_message",tmpMap->value);
    2326                           res=createStatus(m,SERVICE_STARTED);
    2327                         }
    2328                         else
    2329                           res=createStatus(m,SERVICE_FAILED);
    2330                   }
     2306                  res=printJobStatus(m,jobId);
    23312307                  free(jobId);
    23322308                }
     
    25302506                    map* testMap=getMapFromMaps(m,"main","memory");
    25312507                    loadHttpRequests(m,request_input_real_format);
    2532                     dumpMaps(request_input_real_format);
     2508
     2509                    if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0)
     2510                      return -1;
    25332511                    loadServiceAndRun (&m, s1, request_inputs,
    25342512                                       &request_input_real_format,
     
    25482526              }else{
    25492527                loadHttpRequests(m,request_input_real_format);
     2528                if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0)
     2529                  return -1;
    25502530                loadServiceAndRun (&m,s1,request_inputs,
    25512531                                   &request_input_real_format,
     
    25602540        }
    25612541    }
    2562     if(res!=NULL){
     2542    map* pmHasPrinted=getMapFromMaps(m,"lenv","hasPrinted");
     2543    if(res!=NULL && (pmHasPrinted==NULL || strncasecmp(pmHasPrinted->value,"false",5)==0)){
    25632544      if(getMapFromMaps(m,"lenv","no-headers")==NULL){
    25642545        printHeaders(m);
     
    25732554#endif
    25742555  }else{
    2575 
    25762556    //
    25772557    // WPS 1.0.0 and 2.0.0 starts here
    25782558    //
     2559    setMapInMaps(m,"main","executionType","xml");
    25792560    //Check for minimum inputs
    25802561    map* version=getMap(request_inputs,"version");
     
    34353416  signal (SIGABRT, donothing);
    34363417#endif
     3418    fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
     3419    fflush(stderr);
    34373420
    34383421  if (((int) zGetpid ()) != cpid || cgiSid != NULL)
    34393422    {
     3423    fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
     3424    fflush(stderr);
    34403425      if (eres == SERVICE_SUCCEEDED)
    34413426#ifdef USE_CALLBACK
     
    34953480      if(cgiSid!=NULL)
    34963481        free(cgiSid);
    3497       map* tMap=getMapFromMaps(m,"lenv","executionType");
     3482      map* tMap=getMapFromMaps(m,"main","executionType");
    34983483      if(tMap!=NULL && strncasecmp(tMap->value,"xml",3)==0)
    34993484        InternetCloseHandle (&hInternet);
     
    35243509  free (REQUEST);
    35253510  free (SERVICE_URL);
     3511
    35263512#ifdef DEBUG
    35273513  fprintf (stderr, "Processed response \n");
  • trunk/zoo-project/zoo-services/utils/open-api/server/.htaccess

    r962 r967  
    1 RewriteRule ^ogc-api/api.html$ /cgi-bin3/zoo_loader.cgi?/api.html [L,QSA]
    2 RewriteRule ^ogc-api/index.html$ /cgi-bin3/zoo_loader.cgi?service=WPS&service=WPS&request=Execute&version=1.0.0&Identifier=display&RawDataOutput=Result&DataInputs=tmpl=@xlink:href=https://demo.mapmint.com/ogc-api/ [L,QSA]
    3 RewriteRule ^ogc-api(.*).html$ /cgi-bin3/zoo_loader.cgi?service=WPS&service=WPS&request=Execute&version=1.0.0&Identifier=display&RawDataOutput=Result&DataInputs=tmpl=@xlink:href=https://demo.mapmint.com/ogc-api$1 [L,QSA]
    4 RewriteRule ^ogc-api(.*)$ /cgi-bin3/zoo_loader.cgi?$1 [L,QSA]
     1RewriteRule ^ogc-api/api.html$ /cgi-bin/zoo_loader.cgi?/api.html [L,QSA]
     2RewriteRule ^ogc-api/index.html$ /cgi-bin/zoo_loader.cgi?service=WPS&service=WPS&request=Execute&version=1.0.0&Identifier=display&RawDataOutput=Result&DataInputs=tmpl=@xlink:href=https://demo.mapmint.com/ogc-api/ [L,QSA]
     3RewriteRule ^ogc-api(.*).html$ /cgi-bin/zoo_loader.cgi?service=WPS&service=WPS&request=Execute&version=1.0.0&Identifier=display&RawDataOutput=Result&DataInputs=tmpl=@xlink:href=https://demo.mapmint.com/ogc-api$1 [L,QSA]
     4RewriteRule ^ogc-api(.*)$ /cgi-bin/zoo_loader.cgi?$1 [L,QSA]
  • trunk/zoo-project/zoo-services/utils/open-api/templates/index.html

    r965 r967  
    269269#set $cid="JOBSOCKET-"+$conf["lenv"]["usid"]
    270270        <form class="needs-validation" data-id="$cid" novalidate>
    271     <h3>Inputs</h3>
    272     <div class="accordion" id="accordionInputExample">
    273       #for i in range(len(values["inputs"]))
    274       #set cInput=$values["inputs"][$i]
    275       #set cName=$cInput["id"].replace(".","_")
    276       $printCard({"id": $cName, "title": $cInput["id"],"content":'<p>'+$cInput["description"]+'</p>'+$printInputContent($cInput)})
    277       #end for   
    278     </div>
     271          <input type="hidden" name="oapi_ioAsArray" value="#if "io_as_array" in $openapi["openapi"]#$openapi["openapi"]["io_as_array"]#else#false#end if#" />
     272          <input type="hidden" name="oapi_wsUrl" value="$openapi["openapi"]["wsurl"]" />
     273          <input type="hidden" name="oapi_jobUrl" value="$openapi["openapi"]["rootUrl"]$(currentUrl)/jobs" />
     274          <input type="hidden" name="oapi_reqID" value="$cid" />
     275          <h3>Inputs</h3>
     276          <div class="accordion" id="accordionInputExample">
     277            #for i in range(len(values["inputs"]))
     278            #set cInput=$values["inputs"][$i]
     279            #set cName=$cInput["id"].replace(".","_")
     280            $printCard({"id": $cName, "title": $cInput["id"],"content":'<p>'+$cInput["description"]+'</p>'+$printInputContent($cInput)})
     281            #end for   
     282          </div>
    279283     
    280     <h3>Outputs</h3>
    281     <div class="accordion" id="accordionOutputExample">
    282       #for i in range(len(values["outputs"]))
    283       #set cOutput=$values["outputs"][$i]
    284       #set cName=$cOutput["id"].replace(".","_")
    285       #set cFormats=[]
    286       #if "formats" in $cOutput["output"]
    287       #for j in range(len($cOutput["output"]["formats"]))
    288       #set cFormats+=[$cOutput["output"]["formats"][$j]["mimeType"]]
    289       #end for
    290       #end if
    291       #set cTransmissions=[]
    292       #for j in range(len($values["outputTransmission"]))
    293       #set cTransmissions+=[$values["outputTransmission"][$j]]
    294       #end for
    295       #set cContent="<p>"+$cOutput["description"]+"</p>"
    296       #if len(cFormats)>0
    297       #set $cContent+=$printControl({"id": $cOutput["id"], "title": "format","type": "format","name": $cName,"options":$cFormats})
    298       #end if
    299       #if len(cTransmissions)>0
    300       #set $cContent+=$printControl({"id": $cOutput["id"], "title": "transmission","type": "transmission","name": $cName,"options":$cTransmissions})
    301       #end if
    302       $printCard({"id": $cName+"_"+str($i),"title": $cOutput["id"],"content": $cContent})
    303       #end for
    304     </div>
     284          <h3>Outputs</h3>
     285          <div class="accordion" id="accordionOutputExample">
     286            #for i in range(len(values["outputs"]))
     287            #set cOutput=$values["outputs"][$i]
     288            #set cName=$cOutput["id"].replace(".","_")
     289            #set cFormats=[]
     290            #if "formats" in $cOutput["output"]
     291            #for j in range(len($cOutput["output"]["formats"]))
     292            #set cFormats+=[$cOutput["output"]["formats"][$j]["mimeType"]]
     293            #end for
     294            #end if
     295            #set cTransmissions=[]
     296            #for j in range(len($values["outputTransmission"]))
     297            #set cTransmissions+=[$values["outputTransmission"][$j]]
     298            #end for
     299            #set cContent="<p>"+$cOutput["description"]+"</p>"
     300            #if len(cFormats)>0
     301            #set $cContent+=$printControl({"id": $cOutput["id"], "title": "format","type": "format","name": $cName,"options":$cFormats})
     302            #end if
     303            #if len(cTransmissions)>0
     304            #set $cContent+=$printControl({"id": $cOutput["id"], "title": "transmission","type": "transmission","name": $cName,"options":$cTransmissions})
     305            #end if
     306            $printCard({"id": $cName+"_"+str($i),"title": $cOutput["id"],"content": $cContent})
     307            #end for
     308          </div>
    305309   
    306     <h3>Execution options</h3>
    307     <div class="accordion" id="accordionExampleExecutionMode">
    308       #set cContent=""
    309       #set cUrl=$openapi["openapi"]["publisherurl"]+cid+"&type="
    310       #for a in ["successUri","inProgressUri","failedUri"]
    311       #set $cContent+=$printControl({"title": $a,"type": "main_value","name": $a,"ph":"URL","value":$cUrl+$a.replace("Uri","")})
    312       #end for
    313       $printCard({"id":"ModeOne","title":"Subscribers","content": $cContent})
    314       $printCard({"id":"ModeTwo","title":"Response","content": $printControl({"title":"format","type": "main_value","name": "format","options":["document","raw"]})})
    315       $printCard({"id":"ModeThree","title":"Mode","content": $printControl({"title":"mode","type": "main_value","name": "mode","options":["async","sync"]})})
    316     </div>
    317     <button type="submit" class="btn btn-primary" >Submit</button>
    318     </form>
     310          <h3>Execution options</h3>
     311          <div class="accordion" id="accordionExampleExecutionMode">
     312            #set cContent=""
     313            #set cUrl=$openapi["openapi"]["publisherurl"]+cid+"&type="
     314            #for a in ["successUri","inProgressUri","failedUri"]
     315            #set $cContent+=$printControl({"title": $a,"type": "main_value","name": $a,"ph":"URL","value":$cUrl+$a.replace("Uri","")})
     316            #end for
     317            $printCard({"id":"ModeOne","title":"Subscribers","content": $cContent})
     318            $printCard({"id":"ModeTwo","title":"Response","content": $printControl({"title":"format","type": "main_value","name": "format","options":["document","raw"]})})
     319            $printCard({"id":"ModeThree","title":"Mode","content": $printControl({"title":"mode","type": "main_value","name": "mode","options":["async","sync"]})})
     320          </div>
     321         
     322          <button type="submit" class="btn btn-primary" >Submit</button>
     323        </form>
    319324    <div class="modal" tabindex="-1" id="exampleModal">
    320325      <div class="modal-dialog modal-xl">
     
    343348      </div>
    344349    </div>
    345     <script>
    346       var socket;
    347       function addElementToList(){
    348         var lClosure=arguments[0];
    349         var isOver=false;
    350         var cnt=0;
    351         lClosure.parent().parent().find("div").each(function(){
    352           if(isOver) return;
    353           if(\$(this).hasClass("btn-group")) isOver=true;
    354           if(\$(this).hasClass("input-group")){
    355             lClosure.parent().parent().append(\$(this)[0].outerHTML);
    356             cnt++;
    357           }
    358         });
    359         if(lClosure.parent().parent().find(".input-group").length>cnt)
    360           lClosure.next().attr("disabled",false);
    361         else
    362           lClosure.next().attr("disabled",true);
    363       }
    364       function delElementToList(){
    365         var lClosure=arguments[0];
    366         var isOver=false;
    367         var cnt=0;
    368         lClosure.parent().parent().find("div").each(function(){
    369           if(isOver) return;
    370           if(\$(this).hasClass("btn-group")) isOver=true;
    371           if(\$(this).hasClass("input-group")) cnt++;
    372         });
    373         if(lClosure.parent().parent().find(".input-group").length>cnt)
    374         for(var i=0;i<cnt;i++)
    375           lClosure.parent().parent().find(".input-group").last().remove();
    376         if(lClosure.parent().parent().find(".input-group").length==cnt)
    377           lClosure.attr("disabled",true);
    378         else
    379           lClosure.attr("disabled",false);
    380       }
    381      
    382       function loadRequest(){
    383         var requestObject={
    384           "inputs":[],
    385           "outputs":[],
    386           "subscriber":{},
    387           "mode": \$("select[name='main_value_mode']").val(),
    388           "response": \$("select[name='main_value_format']").val()
    389         }
    390         for(var i=0;i < System["JSON_STR"]["inputs"].length;i++){
    391           var cName=System["JSON_STR"]["inputs"][i]["id"].replace(".","_");
    392           var selector="input[name='input_value_"+cName+"'],"+
    393                        "select[name='input_value_"+cName+"']";
    394           if(\$(selector).val()!=""){
    395             \$(selector).each(function(){
    396             var cInput={"id": System["JSON_STR"]["inputs"][i]["id"], "input": {}};
    397             if(System["JSON_STR"]["inputs"][i]["input"]["formats"]){
    398               var selector1="input[name='input_format_"+cName+"'],"+
    399                 "select[name='input_format_"+cName+"']";
    400               console.log(\$(this).parent().prev().find("select").val());
    401               cInput["input"]["format"]={
    402                 "mimeType": \$(this).parent().prev().find("select").val()
    403               };
    404               cInput["input"]["value"]={
    405                 "href": \$(this).val()
    406               };
    407             }
    408             else{
    409               if(System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"]){
    410                 console.log(System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"]);
    411                 cInput["input"]["dataType"]={
    412                   "name": System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"][0]["dataType"]["name"]
    413                 };
    414                 cInput["input"]["value"]=\$(this).val();
    415               }
    416             }console.log(cInput);
    417             requestObject["inputs"].push(cInput);
    418             });
    419           }
    420         }
    421         console.log(System["JSON_STR"]["outputs"]);
    422         for(var i=0;i < System["JSON_STR"]["outputs"].length;i++){
    423           var cOutput={"id": System["JSON_STR"]["outputs"][i]["id"]};
    424           var cName=System["JSON_STR"]["outputs"][i]["id"].replace(/\./g,"_");
    425           if(System["JSON_STR"]["outputs"][i]["output"]["formats"]){
    426             var selector="select[name='format_"+cName+"']";
    427             cOutput["format"]={
    428               "mimeType": \$(selector).val()
    429             };
    430           }
    431           else{
    432             if(System["JSON_STR"]["outputs"][i]["output"]["literalDataDomains"]){
    433               cOutput["dataType"]={
    434                 "name": System["JSON_STR"]["outputs"][i]["output"]["literalDataDomains"][0]["dataType"]["name"]
    435               };
    436             }
    437           }
    438           var selector1="select[name='transmission_"+cName+"']";
    439           cOutput["transmissionMode"]=\$(selector1).val();
    440           requestObject["outputs"].push(cOutput);
    441         }
    442         if(\$("input[name='main_value_successUri']").val()!="")
    443           requestObject["subscriber"]["successUri"]=\$("input[name='main_value_successUri']").val();
    444         if(\$("input[name='main_value_inProgressUri']").val()!="")
    445           requestObject["subscriber"]["inProgressUri"]=\$("input[name='main_value_inProgressUri']").val();
    446         if(\$("input[name='main_value_failedUri']").val()!="")
    447           requestObject["subscriber"]["failedUri"]=\$("input[name='main_value_failedUri']").val();
    448         \$(".modal").find("textarea").first().val(js_beautify(JSON.stringify(requestObject)));
    449         \$("#exampleModal").modal('toggle');
    450         \$('#result').html("");
    451         \$("#exampleModal").find(".btn-primary").off('click');
    452         \$("#exampleModal").find(".btn-primary").click(function(){
    453           \$('#result').html("");
    454           if(!socket && requestObject["mode"]!="sync")
    455             socket = new WebSocket("$openapi["openapi"]["wsurl"]");
    456           else
    457               \$.ajax({
    458                 contentType: "application/json",
    459                 data: \$("textarea").val(),
    460                 type: "POST",
    461                 url: "$openapi["openapi"]["rootUrl"]$(currentUrl)/jobs",
    462                 success: function (msg) {
    463                   console.log(msg);
    464                   var cObj=msg;
    465                   \$('#result').html(js_beautify(JSON.stringify(msg["outputs"])));
    466                 },
    467                 error: function(){
    468                   console.log(arguments);
    469                 },
    470               });
    471           if(requestObject["mode"]=="sync"){
    472            return;
    473           }
    474           socket.onopen = function () {
    475             console.log('Connected!');
    476             socket.send("SUB $cid");
    477           };
    478           socket.onmessage = function(event) {
    479             console.log('MESSAGE: ' + event.data);
    480             if(event.data=="1")
    481               \$.ajax({
    482                 contentType: "application/json",
    483                 data: \$("textarea").val(),
    484                 type: "POST",
    485                 url: "$openapi["openapi"]["rootUrl"]$(currentUrl)/jobs",
    486                 success: function (msg) {
    487                   console.log(msg);
    488                 },
    489                 error: function(){
    490                   console.log(arguments);
    491                 },
    492               });
    493             else{
    494               //progressBar
    495               \$("#progress_details").show();
    496               var cObj=JSON.parse(event.data);
    497               if(cObj["jobID"]){
    498                 \$("#prgress_description").html(cObj["jobID"]+": "+cObj["message"]);
    499                 \$(".progress-bar").attr("aria-valuenow",cObj["progress"]);
    500                 \$(".progress-bar").css("width",cObj["progress"]+"%");
    501               }else{
    502                 \$("#progress_details").hide();
    503                 if(cObj["outputs"])
    504                   \$('#result').html(js_beautify(JSON.stringify(cObj["outputs"])));
    505                 else
    506                   \$('#result').html(cObj["message"]);
    507               }
    508             }
    509           };
    510         });
    511       }
    512     </script>
     350    <script src="$openapi["openapi"]["rootUrl"]/../static/openapi.js"></script>
    513351    #end if
    514352   
     
    687525      <hr>
    688526      <address>$openapi["openapi"]["rootUrl"]$(currentUrl).html</address>
    689       <!-- hhmts start -->Last modified: Fri Oct 23 18:25:03 CEST 2020 <!-- hhmts end -->
     527      <!-- hhmts start -->Last modified: Wed Dec 16 16:06:56 CET 2020 <!-- hhmts end -->
    690528    </main>
    691529#if $currentKey=="root"
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