Ignore:
Timestamp:
May 7, 2019, 2:17:08 PM (5 years ago)
Author:
djay
Message:

Merge prototype-v0 branch in trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/zoo-project/zoo-kernel/response_print.c

    r889 r917  
    2323 */
    2424
     25#include "service.h"
    2526#include "response_print.h"
    2627#include "request_parser.h"
     
    3132#else
    3233#include "cpl_vsi.h"
     34#endif
     35#ifdef USE_CALLBACK
     36#include "service_callback.h"
    3337#endif
    3438
     
    7579    }
    7680    if(prefix!=NULL){
    77       char* tmp0=strdup(serv->name);
     81      char* tmp0=zStrdup(serv->name);
    7882      free(serv->name);
    7983      serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char));
     
    179183    nbNs++;
    180184    currId=0;
    181     nsName[currId]=strdup(name);
     185    nsName[currId]=zStrdup(name);
    182186    usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
    183187  }else{
     
    186190      nbNs++;
    187191      currId=nbNs-1;
    188       nsName[currId]=strdup(name);
     192      nsName[currId]=zStrdup(name);
    189193      usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
    190194    }
     
    251255  if(soap!=NULL && strcasecmp(soap->value,"true")==0){
    252256    int lNbNs=nbNs;
    253     nsName[lNbNs]=strdup("soap");
     257    nsName[lNbNs]=zStrdup("soap");
    254258    usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
    255259    nbNs++;
    256260    xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope");
    257     nsName[nbNs]=strdup("soap");
     261    nsName[nbNs]=zStrdup("soap");
    258262    usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
    259263    nbNs++;
    260     nsName[nbNs]=strdup("xsi");
     264    nsName[nbNs]=zStrdup("xsi");
    261265    usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
    262266    nbNs++;
     
    338342      }
    339343      else{
    340         nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
    341         xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
    342344        if(dcount==0){
    343345          if(vid==0){
     346            nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
     347            xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
    344348            xmlAddChild(nc2,nc4);
    345349            xmlAddChild(nc1,nc2);
     
    361365      nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
    362366      xmlAddChild(nc4,xmlNewText(BAD_CAST buff));             
    363         if(vid==0)
    364           xmlAddChild(nc3,nc4);
    365         else
    366           xmlAddChild(nc1,nc4);
     367      if(vid==0)
     368        xmlAddChild(nc3,nc4);
     369      else
     370        xmlAddChild(nc1,nc4);
    367371    }
    368372  }
     
    590594    map* tmp=getMap(toto1->content,"serverAddress");
    591595    if(tmp!=NULL){
    592       SERVICE_URL = strdup(tmp->value);
     596      SERVICE_URL = zStrdup(tmp->value);
    593597    }
    594598    else
    595       SERVICE_URL = strdup("not_defined");
     599      SERVICE_URL = zStrdup("not_defined");
    596600  }
    597601  else
    598     SERVICE_URL = strdup("not_defined");
     602    SERVICE_URL = zStrdup("not_defined");
    599603
    600604  for(j=0;j<nbSupportedRequests;j++){
     
    644648 * @return the generated wps:ProcessOfferings xmlNodePtr
    645649 */
    646 void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
     650void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){
    647651  xmlNsPtr ns,ns_ows,ns_xml,ns_xlink;
    648   xmlNodePtr n=NULL,nc1,nc2;
     652  xmlNodePtr n=NULL,nc1,nc2,nc3;
    649653  map* version=getMapFromMaps(m,"main","rversion");
    650654  int vid=getVersionId(version->value);
     
    667671      limit=7;
    668672    }
     673    nc3=NULL;
     674    map* sType=getMap(serv->content,"serviceType");
    669675    for(;i<limit;i+=2){
    670676      if(capabilities[vid][i]==NULL)
     
    682688            xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value);
    683689        }
    684         else
    685           xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
     690        else{
     691          if(i==3 && vid==1 && sType!=NULL && strstr(sType->value,"HPC")!=NULL)
     692            xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST "async-execute dismiss");
     693          else
     694            xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
     695        }
    686696      }
    687697    }
     
    690700    printDescription(nc1,ns_ows,serv->name,serv->content,vid);
    691701    tmp1=serv->metadata;
    692     while(tmp1!=NULL){
    693       nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
    694       xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
    695       xmlAddChild(nc1,nc2);
    696       tmp1=tmp1->next;
    697     }
    698 
     702
     703    addMetadata(tmp1,doc,nc1,ns_ows,ns_xlink,vid);
     704    tmp1=serv->additional_parameters;
     705    int fromDb=-1;
     706    map* test=getMap(serv->content,"fromDb");
     707    if(test!=NULL && strncasecmp(test->value,"true",4)==0)
     708      fromDb=1;
     709    addAdditionalParameters(tmp1,doc,nc1,ns_ows,ns_xlink,fromDb);
     710
     711    if(nc3!=NULL)
     712      xmlAddChild(nc1,nc3);
    699713    xmlAddChild(nc,nc1);
    700714  }
     715
    701716}
    702717
     
    708723 * @param content the servive main content created from the zcfg file
    709724 * @param vid the version identifier (0 for 1.0.0 and 1 for 2.0.0)
    710  */
    711 void attachAttributes(xmlNodePtr n,xmlNsPtr ns,map* content,int vid){
     725 * @param serviceType string containing the current service type
     726 */
     727void attachAttributes(xmlNodePtr n,xmlNsPtr ns,map* content,int vid,map* serviceType){
    712728  int limit=7;
    713729  for(int i=1;i<limit;i+=2){
     
    728744    }
    729745    else{
    730       if(vid==0 && i>=2)
    731         xmlNewProp(n,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
     746      if(i==3 && vid==1 && serviceType!=NULL && strstr(serviceType->value,"HPC")!=NULL)
     747        xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST "async-execute dismiss");
    732748      else
    733         xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
    734     }
     749        if(vid==0 && i>=2)
     750          xmlNewProp(n,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
     751        else
     752          xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
     753    }
     754  }
     755}
     756
     757/**
     758 * Add a Metadata node to any existing node.
     759 * @param meta the map defining the additional parameters
     760 * @param doc the XML document used
     761 * @param nb the node to add the additional parameters
     762 * @param ns_ows the OWS namespace
     763 * @param ns_xlink the xlink namespace
     764 * @param vid the version of WPS to use (0 for 1.0.0 and 1 for 2.0)
     765 */
     766void addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int vid){
     767  int hasTitle=-1;
     768  int hasValue=-1;
     769  xmlNodePtr nc1;
     770  map* oMeta=meta;
     771  int isAdditionalParameters=-1;
     772  int level=0;
     773  map* test=getMap(meta,"title");
     774  if(test!=NULL)
     775    level+=1;
     776  test=getMap(meta,"href");
     777  if(test!=NULL)
     778    level+=1;
     779  test=getMap(meta,"role");
     780  if(test!=NULL)
     781    level+=1;
     782  if(count(oMeta)>level+1)
     783    isAdditionalParameters=1;
     784  char *ctitle=NULL;
     785  while(meta!=NULL){
     786    if(hasTitle<0)
     787      if(isAdditionalParameters<0)
     788        nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
     789      else
     790        if(hasValue<0)
     791          nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
     792    if(strncasecmp(meta->name,"title",5)==0 ||
     793       strcasecmp(meta->name,"href")==0 ||
     794       strcasecmp(meta->name,"role")==0 ){
     795      int index=5;
     796      if(strncasecmp(meta->name,"title",5)==0){
     797        index=6;
     798        hasTitle=1;
     799        if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
     800          xmlAddChild(nc,nc1);
     801          nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
     802          free(ctitle);
     803          ctitle=NULL;
     804        }
     805        if(ctitle==NULL){
     806          char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
     807          snprintf(tmp,index,"%s",meta->name);
     808          xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
     809          free(tmp);
     810        }         
     811        if(ctitle!=NULL)
     812          free(ctitle);
     813        ctitle=zStrdup(meta->value);
     814      }
     815    }else{
     816      xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
     817      xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
     818      xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
     819      xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
     820      xmlAddChild(nc4,xmlNewText(BAD_CAST meta->value));
     821      xmlAddChild(nc2,nc3);
     822      xmlAddChild(nc2,nc4);
     823      xmlAddChild(nc1,nc2);
     824      hasTitle=-1;
     825    }
     826    meta=meta->next;
     827    if(hasTitle<0){
     828      hasValue=1;
     829      if(isAdditionalParameters){
     830        if(vid==0){
     831          meta=NULL;
     832          break;
     833        }else
     834          xmlAddChild(nc,nc1);
     835      }
     836    }
     837  }
     838  if(oMeta!=NULL && hasValue<0 && nc1!=NULL){
     839    xmlAddChild(nc,nc1);
     840  }
     841}
     842
     843/**
     844 * Add AdditionalParameters nodes to any existing node.
     845 * @param meta the map defining the additional parameters
     846 * @param doc the XML document used
     847 * @param nb the node to add the additional parameters
     848 * @param ns_ows the OWS namespace
     849 * @param ns_xlink the xlink namespace
     850 * @param fromDb 1 if the metadata has been extracted from the metadb,
     851 * 0 otherwise
     852 */
     853void addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){
     854  int hasTitle=-1;
     855  int hasValue=-1;
     856  int toAddAtEnd=-1;
     857  int cnt=0;
     858  xmlNodePtr* ncr=NULL;
     859  xmlNodePtr nc1;
     860  map* oMeta=meta;
     861  int isAdditionalParameters=-1;
     862  int level=0;
     863  map* test=getMap(meta,"title");
     864  map* otitle=getMap(meta,"title");
     865  map* length=getMap(meta,"length");
     866  int len=0;
     867  char *ctitle=NULL;
     868   
     869  if(test!=NULL)
     870    level+=1;
     871  test=getMap(meta,"href");
     872  if(test!=NULL)
     873    level+=1;
     874  test=getMap(meta,"role");
     875  if(test!=NULL)
     876    level+=1;
     877  if(count(oMeta)>level+1)
     878    isAdditionalParameters=1;
     879
     880  while(meta!=NULL){
     881    if(hasTitle<0 && hasValue<0){
     882      nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
     883    }
     884    if(strncasecmp(meta->name,"title",5)==0 ||
     885       strcasecmp(meta->name,"href")==0 ||
     886       strcasecmp(meta->name,"role")==0 ){
     887      int index=5;
     888      if(strncasecmp(meta->name,"title",5)==0){
     889        index=6;
     890        hasTitle=1;
     891        if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
     892          xmlNodePtr ncTmp = xmlDocCopyNodeList(doc,nc1);
     893          xmlAddChild(nc,ncTmp);
     894          xmlFreeNode(nc1);
     895          toAddAtEnd=1;
     896          cnt++;
     897          nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
     898          free(ctitle);
     899          ctitle=NULL;
     900        }
     901        if(ctitle==NULL){
     902          char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
     903          snprintf(tmp,index,"%s",meta->name);
     904          xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
     905          free(tmp);
     906        }         
     907        if(ctitle!=NULL)
     908          free(ctitle);
     909        ctitle=zStrdup(meta->value);
     910      }else{
     911        xmlNewNsProp(nc1,ns_xlink,BAD_CAST meta->name,BAD_CAST meta->value);
     912      }
     913    }else{
     914      if(strncasecmp(meta->name,"length",6)!=0 && strncasecmp(meta->name,"fromDb",6)!=0){
     915        xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
     916        xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
     917        xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
     918        xmlAddChild(nc2,nc3);
     919        if(fromDb<0){
     920          char *mptr;
     921          char* meta_values=strtok_r(meta->value,",",&mptr);
     922          while(meta_values!=NULL){
     923            xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
     924            xmlAddChild(nc4,xmlNewText(BAD_CAST meta_values));
     925            xmlAddChild(nc2,nc4);
     926            meta_values=strtok_r(NULL,",",&mptr);
     927          }
     928        }else{
     929          xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
     930          xmlAddChild(nc4,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value)));
     931          xmlAddChild(nc2,nc4);
     932        }
     933        xmlAddChild(nc1,nc2);
     934      }
     935      hasTitle=-1;
     936    }
     937    meta=meta->next;
     938    if(hasTitle<0){
     939      //xmlAddChild(nc,nc1);
     940      hasValue=1;
     941    }/*else
     942       if(ctitle!=NULL)
     943       free(ctitle);*/
     944  }
     945  if(length!=NULL)
     946    len=atoi(length->value);
     947  if(otitle!=NULL)
     948    len=1;
     949  if(cnt<len){
     950    xmlAddChild(nc,nc1);
     951    free(ctitle);
    735952  }
    736953}
     
    7921009 * @return the generated wps:ProcessOfferings xmlNodePtr
    7931010 */
    794 void printDescribeProcessForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
     1011void printDescribeProcessForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){
    7951012  xmlNsPtr ns,ns_ows,ns_xlink;
    7961013  xmlNodePtr n,nc1;
     
    7981015  map* version=getMapFromMaps(m,"main","rversion");
    7991016  int vid=getVersionId(version->value);
     1017  int fromDb=-1;
     1018  map* serviceType=getMap(serv->content,"serviceType");
     1019  map* test=getMap(serv->content,"fromDb");
     1020  if(test!=NULL && strncasecmp(test->value,"true",4)==0)
     1021    fromDb=1;
    8001022
    8011023  n=nc;
     
    8111033  if(vid==0){
    8121034    nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription");
    813     attachAttributes(nc,ns,serv->content,vid);
     1035    attachAttributes(nc,ns,serv->content,vid,NULL);
    8141036  }
    8151037  else{
     
    8281050      }
    8291051    }
    830     attachAttributes(nc2,NULL,serv->content,vid);
     1052    attachAttributes(nc2,NULL,serv->content,vid,serviceType);
    8311053    map* level=getMap(serv->content,"level");
    8321054    if(level!=NULL && strcasecmp(level->value,"generic")==0)
     
    8431065    tmp1=serv->metadata;
    8441066    while(tmp1!=NULL){
    845       nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
    846       xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
    847       xmlAddChild(nc,nc1);
     1067      addMetadata(tmp1,doc,nc,ns_ows,ns_xlink,vid);
    8481068      tmp1=tmp1->next;
    8491069    }
     
    8551075    }
    8561076  }else{
     1077    tmp1=serv->metadata;
     1078    addMetadata(tmp1,doc,nc,ns_ows,ns_xlink,vid);
    8571079    addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv);
     1080    tmp1=serv->additional_parameters;
     1081    if(vid!=0)
     1082      addAdditionalParameters(tmp1,doc,nc,ns_ows,ns_xlink,fromDb);
    8581083  }
    8591084
     
    8621087    if(vid==0){
    8631088      nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs");
    864       printFullDescription(1,e,"Input",ns,ns_ows,nc1,vid);
     1089      printFullDescription(doc,1,e,"Input",ns,ns_ows,nc1,vid,fromDb,NULL);
    8651090      xmlAddChild(nc,nc1);
    8661091    }
    8671092    else{
    868       printFullDescription(1,e,"wps:Input",ns,ns_ows,nc,vid);
     1093      printFullDescription(doc,1,e,"wps:Input",ns,ns_ows,nc,vid,fromDb,NULL);
    8691094    }
    8701095  }
     
    8731098  if(vid==0){
    8741099    nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
    875     printFullDescription(0,e,"Output",ns,ns_ows,nc1,vid);
     1100    printFullDescription(doc,0,e,"Output",ns,ns_ows,nc1,vid,fromDb,NULL);
    8761101    xmlAddChild(nc,nc1);
    8771102  }
    8781103  else{
    879     printFullDescription(0,e,"wps:Output",ns,ns_ows,nc,vid);
     1104    printFullDescription(doc,0,e,"wps:Output",ns,ns_ows,nc,vid,fromDb,serviceType);
    8801105  }
    8811106  if(vid==0)
     
    8991124 * @param nc1 the XML node to use to add the created tree
    9001125 * @param vid the WPS version id (0 for 1.0.0, 1 for 2.0.0)
    901  */
    902 void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid){
     1126 * @param fromDb 1 in case the metadata comes from the DB, -1 in other cases
     1127 * @param serviceType the serviceType found in the ZCFG file or the DB
     1128 */
     1129void printFullDescription(xmlDocPtr doc,int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid,int fromDb,const map* serviceType){
    9031130  xmlNsPtr ns1=NULL;
    9041131  if(vid==1)
     
    9131140    int isAnyValue=1;
    9141141    nc2 = xmlNewNode(NULL, BAD_CAST type);
     1142    // Extract min/max Occurence information
    9151143    if(strstr(type,"Input")!=NULL){
    9161144      tmp1=getMap(e->content,"minOccurs");
     
    9351163
    9361164    if(e->format!=NULL){
     1165#ifdef USE_HPC     
     1166    DEFAULT_OUT:
     1167#endif
    9371168      const char orderedFields[13][14]={
    9381169        "mimeType",
     
    9521183      //Build the (Literal/Complex/BoundingBox)Data node
    9531184      if(strncmp(type,"Output",6)==0){
    954         if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0)
     1185        if(strncasecmp(e->format,"LITERAL",7)==0)
    9551186          nc3 = xmlNewNode(ns1, BAD_CAST "LiteralOutput");
    9561187        else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
     
    9981229                strcmp(e->format,"BoundingBoxData")==0){
    9991230          datatype=2;
    1000           nc5 = xmlNewNode(NULL, BAD_CAST "Default");
     1231          if(vid==0)
     1232            nc5 = xmlNewNode(NULL, BAD_CAST "Default");
     1233          else{
     1234            xmlNodePtr nc6 = xmlNewNode(ns1, BAD_CAST "Format");
     1235            xmlNewProp(nc6,BAD_CAST "mimeType",BAD_CAST "text/xml");
     1236            xmlNewProp(nc6,BAD_CAST "default",BAD_CAST "true");
     1237            xmlAddChild(nc3,nc6);
     1238            nc5 = xmlNewNode(NULL, BAD_CAST "SupportedCRS");
     1239          }
    10011240        }
    10021241        else{
     
    10391278            while(token!=NULL){
    10401279              nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
    1041               char *tmps=strdup(token);
     1280              char *tmps=zStrdup(token);
    10421281              tmps[strlen(tmps)]=0;
    1043               xmlAddChild(nc7,xmlNewText(BAD_CAST tmps));
     1282              nc8 = xmlNewText(BAD_CAST tmps);
     1283              xmlAddChild(nc7,nc8);
    10441284              free(tmps);
    10451285              xmlAddChild(nc6,nc7);
     
    12071447                 strncasecmp(tmp1->name,"range",5)!=0){
    12081448                if(datatype!=1){
    1209                   char *tmp2=zCapitalize1(tmp1->name);
    1210                   nc9 = xmlNewNode(NULL, BAD_CAST tmp2);
    1211                   free(tmp2);
     1449                  if(datatype==2 && vid==1){
     1450                    nc9 = xmlNewNode(ns, BAD_CAST "SupportedCRS");
     1451                    xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true");
     1452                  }
     1453                  else{
     1454                    char *tmp2=zCapitalize1(tmp1->name);
     1455                    nc9 = xmlNewNode(NULL, BAD_CAST tmp2);
     1456                    free(tmp2);
     1457                  }
    12121458                }
    12131459                else{
     
    12181464                xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
    12191465                if(vid==0 || oI>=3){
    1220                   if(vid==0 || oI!=4)
    1221                     xmlAddChild(nc5,nc9);
     1466                  if(vid==0 || oI!=4){
     1467                    if(datatype==2 && vid==1)
     1468                      xmlAddChild(nc3,nc9);
     1469                    else
     1470                      xmlAddChild(nc5,nc9);
     1471                  }
    12221472                  if(oI==4 && vid==1){
    12231473                    xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true");
    12241474                  }
    12251475                }
    1226                 else
    1227                   xmlFree(nc9);
     1476                else{
     1477                  xmlFreeNode(nc9);
     1478                }
    12281479                if(strcasecmp(tmp1->name,"uom")==0)
    12291480                  hasUOM1=true;
    12301481                hasUOM=true;
    1231               }else       
    1232                 tmp1=tmp1->next;
     1482              }
    12331483            }
    12341484        }
     
    12451495          }else{
    12461496            if(hasUOM1==false && vid==0){
    1247               xmlFreeNode(nc5);
    1248               if(datatype==1)
     1497              if(nc5!=NULL)
     1498                xmlFreeNode(nc5);
     1499              if(datatype==1){
    12491500                xmlFreeNode(nc4);
     1501              }
    12501502            }
    1251             else
     1503            else{
    12521504              xmlAddChild(nc3,nc5);
     1505            }
    12531506          }
    12541507        }else{
    1255           xmlAddChild(nc3,nc5);
     1508          if(vid==0)
     1509            xmlAddChild(nc3,nc5);
     1510          else
     1511            xmlFreeNode(nc5);
    12561512        }
    12571513     
    1258         if(datatype!=1 && default1<0){
     1514        if(datatype==0 && default1<0){
    12591515          xmlFreeNode(nc5);
    1260           if(datatype!=2)
     1516          if(datatype!=2){
    12611517            xmlFreeNode(nc4);
     1518          }
    12621519        }
    12631520
     
    13101567              nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
    13111568              free(tmp2);
    1312               //xmlNewProp(nc9, BAD_CAST "default", BAD_CAST "true");
    13131569              xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
    13141570              xmlAddChild(nc5,nc9);
    1315               /*struct iotype * _ltmp=e->supported;
    1316                 while(_ltmp!=NULL){
    1317                 tmp1=getMap(_ltmp->content,"uom");
    1318                 if(tmp1!=NULL){
    1319                 char *tmp2=zCapitalize(tmp1->name);
    1320                 nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
    1321                 free(tmp2);
    1322                 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
    1323                 xmlAddChild(nc5,nc9);
    1324                 }
    1325                 _ltmp=_ltmp->next;
    1326                 }*/
    1327            
    13281571            }
    13291572          }
     
    13401583        xmlNsPtr ns_xlink=usedNs[xlinkId];
    13411584
    1342         while(metadata!=NULL){
    1343           nc6=xmlNewNode(ns_ows, BAD_CAST "Metadata");
    1344           xmlNewNsProp(nc6,ns_xlink,BAD_CAST metadata->name,BAD_CAST metadata->value);
    1345           xmlAddChild(nc2,nc6);
    1346           metadata=metadata->next;
    1347         }
     1585        addMetadata(metadata,doc,nc2,ns_ows,ns_xlink,vid);
     1586        if(vid!=0)
     1587          addAdditionalParameters(e->additional_parameters,doc,nc2,ns_ows,ns_xlink,fromDb);
    13481588
    13491589      }
    13501590
    13511591      _tmp=e->supported;
    1352       if(_tmp==NULL && datatype!=1)
     1592      if(_tmp==NULL && datatype==0)
    13531593        _tmp=e->defaults;
    13541594
     
    13961636               strcasecmp(tmp1->name,"extension")!=0){
    13971637              if(datatype!=1){
    1398                 char *tmp2=zCapitalize1(tmp1->name);
    1399                 nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
    1400                 free(tmp2);
     1638                if(datatype==2 && vid==1){
     1639                  nc6 = xmlNewNode(ns, BAD_CAST "SupportedCRS");
     1640                }
     1641                else{
     1642                  char *tmp2=zCapitalize1(tmp1->name);
     1643                  nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
     1644                  free(tmp2);
     1645                }
    14011646              }
    14021647              else{
     
    14221667              }
    14231668              if(vid==0 || oI>=3){
    1424                 if(vid==0 || oI!=4)
    1425                   xmlAddChild(nc5,nc6);
    1426                 else
    1427                   xmlFree(nc6);
     1669                if(vid==0 || oI!=4){
     1670                  if(datatype==2 && vid==1)
     1671                    xmlAddChild(nc3,nc6);
     1672                  else
     1673                    xmlAddChild(nc5,nc6);
     1674                }
     1675                else{
     1676                  xmlFreeNode(nc6);
     1677                }
    14281678              }
    1429               else
    1430                 xmlFree(nc6);
     1679              else{
     1680                xmlFreeNode(nc6);
     1681              }
    14311682            }
    14321683            tmp1=tmp1->next;
     
    14391690            }
    14401691            else{
    1441               xmlAddChild(nc3,nc5);
     1692              if(datatype!=2)
     1693                xmlAddChild(nc3,nc5);
    14421694            }
    14431695
    14441696          }else{
    1445             if(datatype!=1)
     1697            if(datatype==2 && vid==0)
    14461698              xmlAddChild(nc3,nc5);
    14471699          }
     
    14591711          }
    14601712          else
    1461             if(datatype!=1)
     1713            if(datatype==0){
     1714              xmlFreeNode(nc4);
    14621715              xmlAddChild(nc3,nc5);
     1716            }
    14631717
    14641718        _tmp=_tmp->next;
     
    14661720
    14671721      if(hasSupported==0){
    1468         if(datatype==0 && vid!=0)
     1722        if(datatype==0 && vid!=0){
    14691723          xmlFreeNode(nc4);
     1724        }
    14701725        xmlFreeNode(nc5);
    14711726      }
     
    14781733        }
    14791734        else{
     1735          xmlFreeNode(nc4);
    14801736          xmlAddChild(nc3,nc5);
    14811737        }
     
    14911747    }else{
    14921748      if(e->child!=NULL && vid!=0){
    1493         printFullDescription(in,e->child,type,ns,ns_ows,nc2,vid);
    1494       }
    1495     }
    1496    
     1749        printFullDescription(doc,in,e->child,type,ns,ns_ows,nc2,vid,fromDb,NULL);
     1750      }
     1751    }
    14971752    if(e->child!=NULL && vid==0){
    14981753      elements* children=dupElements(e->child);
    14991754      elements* cursor=children;
    15001755      while(cursor!=NULL){
    1501         char* tmp=strdup(cursor->name);
    1502         free(cursor->name);
    1503         cursor->name=(char*)malloc((strlen(cursor->name)+strlen(e->name)+2)*sizeof(char));
    1504         sprintf(cursor->name,"%s.%s",e->name,tmp);
     1756        elements* ccursor=cursor;
     1757        char* tmp=zStrdup(ccursor->name);
     1758        free(ccursor->name);
     1759        ccursor->name=(char*)malloc((strlen(tmp)+strlen(e->name)+2)*sizeof(char));
     1760        sprintf(ccursor->name,"%s.%s",e->name,tmp);
    15051761        cursor=cursor->next;
    15061762      }
    1507       printFullDescription(in,children,type,ns,ns_ows,nc2,vid);
    1508       xmlAddChild(nc1,nc2);
     1763      printFullDescription(doc,in,children,type,ns,ns_ows,nc1,vid,fromDb,serviceType);
    15091764      freeElements(&children);
    15101765      free(children);
    1511     }else
    1512       xmlAddChild(nc1,nc2);
    1513    
     1766    }else{
     1767      if(nc2!=NULL){
     1768        xmlAddChild(nc1,nc2);
     1769      }
     1770    }
    15141771    e=e->next;
    15151772  }
     
    15281785 * @param outputs the outputs generated by the service
    15291786 */
    1530 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
     1787void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){       
    15311788  xmlNsPtr ns,ns_ows,ns_xlink;
    15321789  xmlNodePtr nr,n,nc,nc1=NULL,nc3;
     
    15491806  char stored_path[1024];
    15501807  memset(stored_path,0,1024);
    1551    
     1808 
    15521809  if(vid==0){
    15531810    char tmp[256];
     
    17341991    }
    17351992  }
    1736 
     1993 
    17371994  /**
    17381995   * Display the process output only when requested !
     
    17442001    maps* mcursor=outputs;
    17452002    elements* scursor=serv->outputs;
    1746     map* testResponse=getMap(request,"RawDataOutput");
     2003    map* testResponse=getMap(request,"RawDataOutput"); 
    17472004    if(testResponse==NULL)
    17482005      testResponse=getMap(request,"ResponseDocument");
    1749     while(mcursor!=NULL){
     2006    while(mcursor!=NULL){               
    17502007      map* tmp0=getMap(mcursor->content,"inRequest");
    1751       scursor=getElements(serv->outputs,mcursor->name);
    1752       if(scursor!=NULL){
    1753         if(testResponse==NULL || tmp0==NULL){
     2008      scursor=getElements(serv->outputs,mcursor->name);   
     2009      if(scursor!=NULL){                 
     2010        if(testResponse==NULL || tmp0==NULL){           
    17542011          if(vid==0)
    17552012            printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
     
    17582015        }
    17592016        else
    1760 
    1761           if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){
     2017          if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){             
    17622018            if(vid==0)
    17632019              printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
    17642020            else
    17652021              printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
    1766           }
     2022          }     
    17672023      }else
    17682024        /**
     
    17752031          printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
    17762032      mcursor=mcursor->next;
    1777     }
     2033    }   
    17782034    if(vid==0)
    17792035      xmlAddChild(n,nc);
    1780   }
    1781 
     2036  } 
    17822037  if(vid==0 &&
    17832038     hasStoredExecuteResponse==true
     
    18342089#endif
    18352090  }
     2091
    18362092  printDocument(m,doc,pid);
    18372093
     
    18912147  else{
    18922148    /*
    1893     dumpElements(e);
     2149      dumpElements(e);
    18942150    */
    18952151    return;
     
    19002156       || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0
    19012157       || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0)
    1902     xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
     2158      xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
    19032159    tmp=tmp->next;
    19042160  }
     
    19272183 * @param type the type
    19282184 */
    1929 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){
    1930 
     2185void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){   
    19312186  xmlNodePtr nc1,nc2,nc3;
    19322187  nc1=xmlNewNode(ns_wps, BAD_CAST type);
     
    19352190    tmp=e->content;
    19362191  else
    1937     tmp=m->content;
    1938 
     2192    tmp=m->content; 
    19392193  if(vid==0){
    19402194    nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
     
    19762230    xmlNewProp(nc1,BAD_CAST "id",BAD_CAST (e!=NULL?e->name:m->name));
    19772231  }
    1978 
     2232 
    19792233  // IO type nested outputs
    1980   if(m->child!=NULL){
     2234  if(m->child!=NULL){     
    19812235    maps* curs=m->child;
    19822236    elements* ecurs=getElements(e,(e!=NULL?e->name:m->name));
    19832237    ecurs=ecurs->child;
    1984     while(curs!=NULL){
     2238    while(curs!=NULL/* && ecurs!=NULL*/){
    19852239      ecurs=getElements(ecurs,(curs->name));
    19862240      map* inRequest=getMap(curs->content,"inRequest");
     
    19922246    }
    19932247  }
    1994   else{
     2248  else{   
    19952249    map *tmpMap=getMap(m->content,"Reference");
    1996     if(tmpMap==NULL){
     2250    if(tmpMap==NULL){           
    19972251      nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
    1998       if(e!=NULL && e->format!=NULL){
    1999         if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
    2000           nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
     2252      if(e!=NULL && e->format!=NULL){             
     2253                  if (strncasecmp(e->format, "LiteralOutput", strlen(e->format)) == 0)                                   
     2254                          nc3 = xmlNewNode(ns_wps, BAD_CAST "LiteralData");               
    20012255        else
    20022256          if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
     
    20052259            nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
    20062260          else
    2007             nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
    2008       }
    2009       else {
    2010         map* tmpV=getMapFromMaps(m,"format","value");
     2261            nc3=xmlNewNode(ns_wps, BAD_CAST e->format);           
     2262      }
     2263      else {             
     2264        map* tmpV=getMapFromMaps(m,"format","value");   
    20112265        if(tmpV!=NULL)
    20122266          nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
     
    20142268          nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
    20152269      }
    2016       tmp=m->content;
    2017      
     2270      tmp=m->content;     
     2271
    20182272      while(tmp!=NULL){
    20192273        if(strcasecmp(tmp->name,"mimeType")==0 ||
     
    20212275           strcasecmp(tmp->name,"schema")==0 ||
    20222276           strcasecmp(tmp->name,"datatype")==0 ||
    2023            strcasecmp(tmp->name,"uom")==0) {
    2024          
     2277           strcasecmp(tmp->name,"uom")==0) {   
    20252278          if(vid==0)
    20262279            xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
     
    20332286          }
    20342287        }
     2288
    20352289        if(vid==0)
    20362290          xmlAddChild(nc2,nc3);
    2037         tmp=tmp->next;
     2291        tmp=tmp->next; 
    20382292      }
    20392293      if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {
     
    20462300        }
    20472301      }
    2048       else {
    2049         if(e!=NULL)
    2050           tmp=getMap(e->defaults->content,"mimeType");
     2302      else {             
     2303                  //if (e != NULL) {
     2304                  if (e != NULL && e->defaults != NULL) { // knut: add extra NULL pointer check in case user omits <Default> block in config file                         
     2305                          tmp = getMap(e->defaults->content, "mimeType");
     2306                  }
    20512307        else
    2052           tmp=NULL;
    2053        
     2308          tmp=NULL;     
    20542309        map* tmp1=getMap(m->content,"encoding");
    20552310        map* tmp2=getMap(m->content,"mimeType");
     
    21062361             strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader)
    21072362             strstr(tmp2->value, "ecmascript") != NULL
    2108            ) {
     2363             ) {
    21092364            xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
    21102365          }   
     
    21122367            if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
    21132368                // include for backwards compatibility,
    2114               // although correct mime type is ...kml+xml:                 
     2369                // although correct mime type is ...kml+xml:               
    21152370                strstr(tmp2->value, "google-earth.kml") != NULL
    21162371                ) {
     
    22412496  else
    22422497    exceptionCode="501 Internal Server Error";
    2243 
     2498  tmp=getMapFromMaps(m,"lenv","status_code");
     2499  if(tmp!=NULL)
     2500    exceptionCode=tmp->value;
    22442501  if(m!=NULL){
    22452502    map *tmpSid=getMapFromMaps(m,"lenv","sid");
     
    23322589
    23332590    tmp=getMapArray(s,"text",cnt);
     2591    if(tmp==NULL)
     2592      tmp=getMapArray(s,"message",cnt);
    23342593    nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
    23352594    if(tmp!=NULL){
    23362595      xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
    23372596      xmlAddChild(nc1,txt);
     2597      if(cnt==0)
     2598        setMapInMaps(m,"lenv","message",tmp->value);
    23382599    }
    23392600    else{
     
    23812642void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
    23822643                    map* request_inputs1,int cpid,maps* m,int res){
    2383                
    23842644#ifdef DEBUG
    23852645  dumpMaps(request_inputs);
    23862646  dumpMaps(request_outputs);
    23872647  fprintf(stderr,"printProcessResponse\n");
    2388 #endif
     2648#endif 
    23892649  map* toto=getMap(request_inputs1,"RawDataOutput");
    23902650  int asRaw=0;
     
    23962656  if(tmpSess!=NULL){
    23972657    map *_tmp=getMapFromMaps(m,"lenv","cookie");
     2658    maps *tmps=getMaps(m,"senv");
    23982659    char* sessId=NULL;
    23992660    if(_tmp!=NULL){
    24002661      printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
     2662      map *_tmp1=getMapFromMaps(m,"senv","ecookie_length");
     2663      if(_tmp1!=NULL){
     2664        int len=atoi(_tmp1->value);
     2665        int cnt=0;
     2666        for(cnt=0;cnt<len;cnt++){
     2667          map* _tmp2=getMapArray(tmps->content,"ecookie",cnt);
     2668          if(_tmp2!=NULL)
     2669            printf("Set-Cookie: %s; HttpOnly\r\n",_tmp2->value);
     2670        }
     2671      }
    24012672      printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
    24022673      char session_file_path[100];
     
    24062677      else
    24072678        sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1);
    2408       sessId=strdup(session_file_path);
     2679      sessId=zStrdup(session_file_path);
    24092680    }else{
    24102681      maps* t=getMaps(m,"senv");
     
    24122683      while(p!=NULL){
    24132684        if(strstr(p->name,"ID")!=NULL){
    2414           sessId=strdup(p->value);
     2685          sessId=zStrdup(p->value);
    24152686          break;
    24162687        }
     
    24352706    }
    24362707  }
    2437                  
    24382708  if(res==SERVICE_FAILED){
    24392709    map *lenv;
     
    24622732    return;
    24632733  }
    2464        
     2734
     2735  if(res!=SERVICE_SUCCEEDED){     
     2736    printProcessResponse(m,request_inputs1,cpid,
     2737                         s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
     2738                         request_inputs,
     2739                         request_outputs);
     2740    return;
     2741  }
     2742     
    24652743  map *tmp1=getMapFromMaps(m,"main","tmpPath");
    24662744  if(asRaw==0){
     
    24732751    map* usid=getMapFromMaps(m,"lenv","usid");
    24742752    int itn=0;
     2753    int error=-1;
    24752754  NESTED0:
    24762755    while(tmpI!=NULL){
     
    24832762#endif
    24842763      map *gfile=getMap(tmpI->content,"generated_file");
    2485       char *file_name;
     2764      char *file_name=NULL;       
    24862765      if(gfile!=NULL){
    24872766        gfile=getMap(tmpI->content,"expected_generated_file");
     
    24912770        readGeneratedFile(m,tmpI->content,gfile->value);
    24922771        file_name=zStrdup((gfile->value)+strlen(tmp1->value));
    2493       }
    2494 
     2772      }   
    24952773      toto=getMap(tmpI->content,"asReference");
    24962774#ifdef USE_MS
    2497       if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL)
     2775      map* geodatatype=getMap(tmpI->content,"geodatatype");
     2776      if(toto!=NULL && strcasecmp(toto->value,"true")==0 &&
     2777         (testMap==NULL ||
     2778          strncasecmp(testMap->value,"true",4)!=0 ||
     2779          (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) ) )
    24982780#else
    2499       if(toto!=NULL && strcasecmp(toto->value,"true")==0)
     2781        if(toto!=NULL && strcasecmp(toto->value,"true")==0)
    25002782#endif
    2501         {
    2502           elements* in=getElements(s->outputs,tmpI->name);
    2503           if(in==NULL && s->outputs->child!=NULL){
    2504             in=getElements(s->outputs->child,tmpI->name);
     2783          {             
     2784            elements* in=getElements(s->outputs,tmpI->name);
     2785            if(in==NULL && s->outputs->child!=NULL){
     2786              in=getElements(s->outputs->child,tmpI->name);
     2787            }
     2788            char *format=NULL;
     2789            if(in!=NULL && in->format!=NULL){
     2790              format=in->format;
     2791            }else
     2792              format=(char*)"LiteralData";
     2793            if(format!=NULL && strcasecmp(format,"BoundingBoxData")==0){
     2794              addToMap(tmpI->content,"extension","xml");
     2795              addToMap(tmpI->content,"mimeType","text/xml");
     2796              addToMap(tmpI->content,"encoding","UTF-8");
     2797              addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
     2798            }           
     2799            char *file_path=NULL;
     2800            if(gfile==NULL) {
     2801              map *ext=getMap(tmpI->content,"extension");
     2802              char file_ext[32];
     2803           
     2804              if( ext != NULL && ext->value != NULL) {
     2805                strncpy(file_ext, ext->value, 32);
     2806              }
     2807              else {
     2808                // Obtain default file extension (see mimetypes.h).           
     2809                // If the MIME type is not recognized, txt is used as the default extension
     2810                map* mtype=getMap(tmpI->content,"mimeType");
     2811                getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
     2812              }
     2813              if(file_name!=NULL)
     2814                free(file_name);
     2815              file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
     2816              sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
     2817              itn++;
     2818              file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
     2819              sprintf(file_path,"%s/%s",tmp1->value,file_name);
     2820
     2821              FILE *ofile=fopen(file_path,"wb");
     2822              if(ofile==NULL){
     2823                char tmpMsg[1024];
     2824                sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
     2825                errorException(m,tmpMsg,"InternalError",NULL);
     2826                free(file_name);
     2827                free(file_path);
     2828                return;
     2829              }
     2830
     2831              toto=getMap(tmpI->content,"value");
     2832              if(toto==NULL){
     2833                char tmpMsg[1024];
     2834                sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name);
     2835                errorException(m,tmpMsg,"InternalError",NULL);
     2836                fclose(ofile);
     2837                free(file_name);
     2838                free(file_path);
     2839                return;
     2840              }
     2841              if(strcasecmp(format,"BoundingBoxData")!=0){
     2842                map* size=getMap(tmpI->content,"size");
     2843                if(size!=NULL && toto!=NULL)
     2844                  fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
     2845                else
     2846                  if(toto!=NULL && toto->value!=NULL)
     2847                    fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
     2848              }else{
     2849                printBoundingBoxDocument(m,tmpI,ofile);
     2850              }
     2851              fclose(ofile);
     2852            }
     2853
     2854            map *tmp2=getMapFromMaps(m,"main","tmpUrl");
     2855            map *tmp3=getMapFromMaps(m,"main","serverAddress");
     2856            char *file_url=NULL;
     2857            if(strncasecmp(tmp2->value,"http://",7)==0 ||
     2858               strncasecmp(tmp2->value,"https://",8)==0){
     2859              file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
     2860              sprintf(file_url,"%s/%s",tmp2->value,file_name);
     2861            }else{
     2862              file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
     2863              sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
     2864            }
     2865            addToMap(tmpI->content,"Reference",file_url);
     2866            if(file_name!=NULL)
     2867              free(file_name);
     2868            if(file_url!=NULL)
     2869              free(file_url);
     2870            file_name=NULL;
    25052871          }
    2506           char *format=NULL;
    2507           if(in!=NULL && in->format!=NULL){
    2508             format=in->format;
    2509           }else
    2510             format=(char*)"LiteralData";
    2511           if(format!=NULL && strcasecmp(format,"BoundingBoxData")==0){
    2512             addToMap(tmpI->content,"extension","xml");
    2513             addToMap(tmpI->content,"mimeType","text/xml");
    2514             addToMap(tmpI->content,"encoding","UTF-8");
    2515             addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
     2872#ifdef USE_MS
     2873        else{
     2874          if(testMap!=NULL){
     2875            map* nbFeatures;
     2876            setMapInMaps(m,"lenv","state","out");
     2877            setReferenceUrl(m,tmpI);
     2878            nbFeatures=getMap(tmpI->content,"nb_features");
     2879            geodatatype=getMap(tmpI->content,"geodatatype");
     2880            if((nbFeatures!=NULL && atoi(nbFeatures->value)==0) ||
     2881               (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0)){
     2882              error=1;
     2883              res=SERVICE_FAILED;
     2884            }
    25162885          }
    2517 
    2518           if(gfile==NULL) {
    2519             map *ext=getMap(tmpI->content,"extension");
    2520             char *file_path;
    2521             char file_ext[32];
    2522 
    2523             if( ext != NULL && ext->value != NULL) {
    2524               strncpy(file_ext, ext->value, 32);
    2525             }
    2526             else {
    2527               // Obtain default file extension (see mimetypes.h).             
    2528               // If the MIME type is not recognized, txt is used as the default extension
    2529               map* mtype=getMap(tmpI->content,"mimeType");
    2530               getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
    2531             }
    2532 
    2533             file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
    2534             sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
    2535             itn++;
    2536             file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
    2537             sprintf(file_path,"%s/%s",tmp1->value,file_name);
    2538 
    2539             FILE *ofile=fopen(file_path,"wb");
    2540             if(ofile==NULL){
    2541               char tmpMsg[1024];
    2542               sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
    2543               errorException(m,tmpMsg,"InternalError",NULL);
    2544               free(file_name);
    2545               free(file_path);
    2546               return;
    2547             }
    2548             free(file_path);
    2549 
    2550             toto=getMap(tmpI->content,"value");
    2551             if(strcasecmp(format,"BoundingBoxData")!=0){
    2552               map* size=getMap(tmpI->content,"size");
    2553               if(size!=NULL && toto!=NULL)
    2554                 fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
    2555               else
    2556                 if(toto!=NULL && toto->value!=NULL)
    2557                   fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
    2558             }else{
    2559               printBoundingBoxDocument(m,tmpI,ofile);
    2560             }
    2561             fclose(ofile);
    2562 
    2563           }
    2564 
    2565           map *tmp2=getMapFromMaps(m,"main","tmpUrl");
    2566           map *tmp3=getMapFromMaps(m,"main","serverAddress");
    2567           char *file_url;
    2568           if(strncasecmp(tmp2->value,"http://",7)==0 ||
    2569              strncasecmp(tmp2->value,"https://",8)==0){
    2570             file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
    2571             sprintf(file_url,"%s/%s",tmp2->value,file_name);
    2572           }else{
    2573             file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
    2574             sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
    2575           }
    2576           addToMap(tmpI->content,"Reference",file_url);
    2577           free(file_name);
    2578           free(file_url);
    2579          
    2580         }
    2581 #ifdef USE_MS
    2582       else{
    2583         if(testMap!=NULL){
    2584           setReferenceUrl(m,tmpI);
    2585         }
    2586       }
    2587 #endif
     2886        }
     2887#endif 
     2888      if(file_name!=NULL){
     2889        free(file_name);
     2890        file_name=NULL;
     2891      }
    25882892      tmpI=tmpI->next;
    25892893    }
     
    25932897      if(tmpI!=NULL)
    25942898        goto NESTED0;
    2595     }
     2899    }   
    25962900#ifdef DEBUG
    25972901    fprintf(stderr,"SERVICE : %s\n",s->name);
    25982902    dumpMaps(m);
     2903#endif 
     2904    if(error<0)
     2905      printProcessResponse(m,request_inputs1,cpid,
     2906                           s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
     2907                           request_inputs,
     2908                           request_outputs);
     2909    else{
     2910      maps* tmpMaps=getMaps(m,"lenv");
     2911#ifdef USE_CALLBACK
     2912      invokeCallback(m,NULL,NULL,7,0);
    25992913#endif
    2600     printProcessResponse(m,request_inputs1,cpid,
    2601                          s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
    2602                          request_inputs,
    2603                          request_outputs);
     2914      printExceptionReportResponse(m,tmpMaps->content);
     2915    }
    26042916  }
    26052917  else{
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