Ignore:
Timestamp:
Feb 11, 2015, 11:29:35 AM (9 years ago)
Author:
djay
Message:

Code cleanup, description of some functon included in the code, addition of support for multiple error output, beter internal gesture of MapArray?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r565 r576  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2013 GeoLabs SARL
     4 * Copyright (c) 2009-2015 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    399399            }
    400400        }
    401         errno = NULL;
     401        errno = ZOO_LOCK_ACQUIRE_FAILED;
    402402        if (!ready) {
    403403#ifdef DEBUG
     
    428428int lockShm(int id){
    429429  struct sembuf sb;
    430   int i;
    431430  sb.sem_num = 0;
    432431  sb.sem_op = -1;  /* set to allocate resource */
     
    629628
    630629char *zCapitalize1(char *tmp){
    631         char *res=strdup(tmp);
    632         if(res[0]>=97 && res[0]<=122)
    633                 res[0]-=32;
    634         return res;
     630  char *res=zStrdup(tmp);
     631  if(res[0]>=97 && res[0]<=122)
     632    res[0]-=32;
     633  return res;
    635634}
    636635
    637636char *zCapitalize(char *tmp){
    638637  int i=0;
    639   char *res=strdup(tmp);
     638  char *res=zStrdup(tmp);
    640639  for(i=0;i<strlen(res);i++)
    641640    if(res[i]>=97 && res[i]<=122)
     
    713712
    714713
     714/************************************************************************/
     715/*                             soapEnvelope()                           */
     716/************************************************************************/
     717
     718/**
     719 * Generate a SOAP Envelope node when required (if the isSoap key of the [main]
     720 * section is set to true).
     721 *
     722 * @param conf the conf maps containing the main.cfg settings
     723 * @param n the node used as children of the generated soap:Envelope
     724 * @return the generated soap:Envelope (if isSoap=true) or the input node n
     725 *  (when isSoap=false)
     726 */
    715727xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){
    716728  map* soap=getMapFromMaps(conf,"main","isSoap");
     
    737749}
    738750
    739 xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,const char* service,maps* m){
    740 
    741   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
     751/************************************************************************/
     752/*                            printWPSHeader()                          */
     753/************************************************************************/
     754
     755/**
     756 * Generate a WPS header.
     757 *
     758 * @param doc the document to add the header
     759 * @param m the conf maps containing the main.cfg settings
     760 * @param req the request type (GetCapabilities,DescribeProcess,Execute)
     761 * @param rname the root node name
     762 * @return the generated wps:rname xmlNodePtr (can be wps: Capabilities,
     763 *  wps:ProcessDescriptions,wps:ExecuteResponse)
     764 */
     765xmlNodePtr printWPSHeader(xmlDocPtr doc,maps* m,const char* req,const char* rname){
     766
     767  xmlNsPtr ns,ns_xsi;
     768  xmlNodePtr n;
     769
     770  int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps");
     771  ns=usedNs[wpsId];
     772  n = xmlNewNode(ns, BAD_CAST rname);
     773  zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
     774  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
     775  zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
     776  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
     777  ns_xsi=usedNs[xsiId];
     778 
     779  char *tmp=(char*) malloc((86+strlen(req)+1)*sizeof(char));
     780  sprintf(tmp,"http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wps%s_response.xsd",req);
     781  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp);
     782  free(tmp);
     783  xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
     784  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
     785  addLangAttr(n,m);
     786  xmlNodePtr fn=soapEnvelope(m,n);
     787  xmlDocSetRootElement(doc, fn);
     788  return n;
     789}
     790
     791/************************************************************************/
     792/*                     printGetCapabilitiesHeader()                     */
     793/************************************************************************/
     794
     795/**
     796 * Generate a Capabilities header.
     797 *
     798 * @param doc the document to add the header
     799 * @param m the conf maps containing the main.cfg settings
     800 * @return the generated wps:ProcessOfferings xmlNodePtr
     801 */
     802xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,maps* m){
     803
     804  xmlNsPtr ns,ns_ows,ns_xlink;
    742805  xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6;
    743   /**
    744    * Create the document and its temporary root.
    745    */
     806  n = printWPSHeader(doc,m,"GetCapabilities","Capabilities");
     807  maps* toto1=getMaps(m,"main");
     808  char tmp[256];
     809
    746810  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
    747811  ns=usedNs[wpsId];
    748   maps* toto1=getMaps(m,"main");
    749 
    750   n = xmlNewNode(ns, BAD_CAST "Capabilities");
    751   int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
     812  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
     813  ns_xlink=usedNs[xlinkId];
     814  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
    752815  ns_ows=usedNs[owsId];
    753   xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
    754   int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
    755   ns_xsi=usedNs[xsiId];
    756   int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
    757   ns_xlink=usedNs[xlinkId];
    758   xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd");
    759   xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
    760   addLangAttr(n,m);
    761  
    762   if(toto1!=NULL){
    763     map* tmp=getMap(toto1->content,"version");
    764     if(tmp!=NULL){
    765       xmlNewProp(n,BAD_CAST "version",BAD_CAST tmp->value);
    766     }
    767     else
    768       xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
    769   }
    770   else
    771     xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
    772 
    773   char tmp[256];
    774  
     816
    775817  nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification");
    776818  maps* tmp4=getMaps(m,"identification");
     
    827869            nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion");
    828870            xmlAddChild(nc2,xmlNewText(BAD_CAST "1.0.0"));
    829             xmlAddChild(nc,nc2);         
     871            xmlAddChild(nc,nc2);
    830872          }
    831873        tmp2=tmp2->next;
     
    9721014    }
    9731015    else
    974       SERVICE_URL = strdup("not_found");
     1016      SERVICE_URL = strdup("not_defined");
    9751017  }
    9761018  else
    977     SERVICE_URL = strdup("not_found");
     1019    SERVICE_URL = strdup("not_defined");
    9781020
    9791021  for(j=0;j<3;j++){
     
    9831025    nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP");
    9841026    nc4 = xmlNewNode(ns_ows, BAD_CAST "Get");
    985     sprintf(tmp,"%s/%s",SERVICE_URL,service);
     1027    sprintf(tmp,"%s",SERVICE_URL);
    9861028    xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp);
    9871029    xmlAddChild(nc3,nc4);
    988     if(j>0){
    989       nc4 = xmlNewNode(ns_ows, BAD_CAST "Post");
    990       xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp);
    991       xmlAddChild(nc3,nc4);
    992     }
     1030    nc4 = xmlNewNode(ns_ows, BAD_CAST "Post");
     1031    xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp);
     1032    xmlAddChild(nc3,nc4);
    9931033    xmlAddChild(nc2,nc3);
    9941034    xmlAddChild(nc1,nc2);   
     
    10451085  xmlAddChild(n,nc1);
    10461086 
    1047   xmlNodePtr fn=soapEnvelope(m,n);
    1048   xmlDocSetRootElement(doc, fn);
    1049   //xmlFreeNs(ns);
    10501087  free(SERVICE_URL);
    10511088  return nc;
    10521089}
     1090
    10531091
    10541092void addPrefix(maps* conf,map* level,service* serv){
     
    11151153    xmlAddChild(nc,nc1);
    11161154  }
    1117 }
    1118 
    1119 xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,const char* service,maps* m){
    1120 
    1121   xmlNsPtr ns,ns_xsi;
    1122   xmlNodePtr n;
    1123 
    1124   int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps");
    1125   ns=usedNs[wpsId];
    1126   n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions");
    1127   zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
    1128   xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
    1129   zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
    1130   int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
    1131   ns_xsi=usedNs[xsiId];
    1132  
    1133   xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd");
    1134   xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
    1135   xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
    1136   addLangAttr(n,m);
    1137 
    1138   xmlNodePtr fn=soapEnvelope(m,n);
    1139   xmlDocSetRootElement(doc, fn);
    1140 
    1141   return n;
    11421155}
    11431156
     
    16681681
    16691682void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
    1670   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
     1683  xmlNsPtr ns,ns_ows,ns_xlink;
    16711684  xmlNodePtr nr,n,nc,nc1=NULL,nc3;
    16721685  xmlDocPtr doc;
     
    16741687  time(&time1);
    16751688  nr=NULL;
    1676   /**
    1677    * Create the document and its temporary root.
    1678    */
    16791689  doc = xmlNewDoc(BAD_CAST "1.0");
     1690  n = printWPSHeader(doc,m,"Execute","ExecuteResponse");
    16801691  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
    16811692  ns=usedNs[wpsId];
    1682 
    1683   n = xmlNewNode(ns, BAD_CAST "ExecuteResponse");
    1684   xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
    1685   int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
     1693  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
    16861694  ns_ows=usedNs[owsId];
    1687   int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
     1695  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
    16881696  ns_xlink=usedNs[xlinkId];
    1689   int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
    1690   ns_xsi=usedNs[xsiId];
    1691  
    1692   xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd");
    1693  
    1694   xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
    1695   xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
    1696   addLangAttr(n,m);
    16971697
    16981698  char tmp[256];
     
    18761876    while(mcursor!=NULL){
    18771877      scursor=getElements(serv->outputs,mcursor->name);
    1878       printOutputDefinitions1(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
     1878      printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
    18791879      mcursor=mcursor->next;
    18801880    }
     
    19151915  }
    19161916
    1917 #ifdef DEBUG
    1918   fprintf(stderr,"printProcessResponse 1 202\n");
    1919 #endif
    1920   nr=soapEnvelope(m,n);
    1921   xmlDocSetRootElement(doc, nr);
    1922 
    19231917  if(hasStoredExecuteResponse==true && status!=SERVICE_STARTED){
    19241918    semid lid=getShmLockId(m,1);
     
    19361930        char tmpMsg[1024];
    19371931        sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the ExecuteResponse."),stored_path);
    1938         map * errormap = createMap("text",tmpMsg);
    1939         addToMap(errormap,"code", "InternalError");
    1940         printExceptionReportResponse(m,errormap);
    1941         freeMap(&errormap);
    1942         free(errormap);
     1932
     1933        errorException(m,tmpMsg,"InternalError",NULL);
    19431934        xmlFreeDoc(doc);
    19441935        xmlCleanupParser();
     
    19951986}
    19961987
    1997 void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){
     1988void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){
    19981989  xmlNodePtr nc1;
    19991990  nc1=xmlNewNode(ns_wps, BAD_CAST type);
     
    20122003       || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0
    20132004       || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0)
    2014     xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
    2015     tmp=tmp->next;
    2016   }
    2017   tmp=getMap(e->defaults->content,"asReference");
    2018   if(tmp==NULL)
    2019     xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false");
    2020 
    2021   tmp=e->content;
    2022 
    2023   printDescription(nc1,ns_ows,m->name,e->content);
    2024 
    2025   xmlAddChild(nc,nc1);
    2026 
    2027 }
    2028 
    2029 void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,const char* type){
    2030   xmlNodePtr nc1;
    2031   nc1=xmlNewNode(ns_wps, BAD_CAST type);
    2032   map *tmp=NULL; 
    2033   if(e!=NULL && e->defaults!=NULL)
    2034     tmp=e->defaults->content;
    2035   else{
    2036     /*
    2037     dumpElements(e);
    2038     */
    2039     return;
    2040   }
    2041   while(tmp!=NULL){
    20422005    xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
    20432006    tmp=tmp->next;
     
    22122175        if(rs==NULL){
    22132176          char tmp1[1024];
    2214           sprintf(tmp1,"%u",strlen(tmp3->value));
     2177          sprintf(tmp1,"%ld",strlen(tmp3->value));
    22152178          rs=createMap("size",tmp1);
    22162179          isSized=false;
     
    23352298}
    23362299
     2300/************************************************************************/
     2301/*                    printExceptionReportResponse()                    */
     2302/************************************************************************/
     2303
     2304/**
     2305 * Print an OWS ExceptionReport Document and HTTP headers (when required)
     2306 * depending on the code.
     2307 * Set hasPrinted value to true in the [lenv] section.
     2308 *
     2309 * @param m the conf maps
     2310 * @param s the map containing the text,code,locator keys
     2311 */
    23372312void printExceptionReportResponse(maps* m,map* s){
    23382313  if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
     
    23512326  map* tmp=getMap(s,"code");
    23522327  if(tmp!=NULL){
    2353     if(strcmp(tmp->value,"OperationNotSupported")==0)
     2328    if(strcmp(tmp->value,"OperationNotSupported")==0 ||
     2329       strcmp(tmp->value,"NoApplicableCode")==0)
    23542330      exceptionCode="501 Not Implemented";
    23552331    else
     
    23612337        exceptionCode="400 Bad request";
    23622338      else
    2363         if(strcmp(tmp->value,"NoApplicableCode")==0)
    2364           exceptionCode="501 Internal Server Error";
    2365         else
    2366           exceptionCode="501 Internal Server Error";
     2339        exceptionCode="501 Internal Server Error";
    23672340  }
    23682341  else
     
    23972370}
    23982371
     2372/************************************************************************/
     2373/*                      createExceptionReportNode()                     */
     2374/************************************************************************/
     2375
     2376/**
     2377 * Create an OWS ExceptionReport Node.
     2378 *
     2379 * @param m the conf maps
     2380 * @param s the map containing the text,code,locator keys
     2381 * @param use_ns (0/1) choose if you want to generate an ExceptionReport or
     2382 *  ows:ExceptionReport node respectively
     2383 * @return the ExceptionReport/ows:ExceptionReport node
     2384 */
    23992385xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){
    24002386 
     
    24042390  int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows");
    24052391  ns=usedNs[nsid];
    2406   if(use_ns==1){
     2392  if(use_ns==0){
    24072393    ns=NULL;
    24082394  }
    24092395  n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
    24102396  if(use_ns==1){
    2411     xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",NULL);
     2397    xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST"ows");
    24122398    int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
    24132399    ns_xsi=usedNs[xsiId];
     
    24192405  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0");
    24202406 
    2421   nc = xmlNewNode(ns, BAD_CAST "Exception");
    2422 
    2423   map* tmp=getMap(s,"code");
    2424   if(tmp!=NULL)
    2425     xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value);
     2407  int length=1;
     2408  int cnt=0;
     2409  map* len=getMap(s,"length");
     2410  if(len!=NULL)
     2411    length=atoi(len->value);
     2412  fprintf(stderr,"LEN %d %s %d \n",length,__FILE__,__LINE__);
     2413  for(cnt=0;cnt<length;cnt++){
     2414    nc = xmlNewNode(ns, BAD_CAST "Exception");
     2415   
     2416    map* tmp=getMapArray(s,"code",cnt);
     2417    if(tmp==NULL)
     2418      tmp=getMap(s,"code");
     2419    if(tmp!=NULL)
     2420      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value);
     2421    else
     2422      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode");
     2423   
     2424    tmp=getMapArray(s,"locator",cnt);
     2425    if(tmp==NULL)
     2426      tmp=getMap(s,"locator");
     2427    if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0)
     2428      xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value);
     2429
     2430    tmp=getMapArray(s,"text",cnt);
     2431    nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
     2432    if(tmp!=NULL){
     2433      xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
     2434      xmlAddChild(nc1,txt);
     2435    }
     2436    else{
     2437      xmlNodeSetContent(nc1, BAD_CAST _("No debug message available"));
     2438    }
     2439    xmlAddChild(nc,nc1);
     2440    xmlAddChild(n,nc);
     2441  }
     2442  return n;
     2443}
     2444
     2445/************************************************************************/
     2446/*                           errorException()                           */
     2447/************************************************************************/
     2448
     2449/**
     2450 * Print an OWS ExceptionReport.
     2451 *
     2452 * @param m the conf maps
     2453 * @param message the error message
     2454 * @param errorcode the error code
     2455 * @param locator the potential locator
     2456 */
     2457int errorException(maps *m, const char *message, const char *errorcode, const char *locator)
     2458{
     2459  map* errormap = createMap("text", message);
     2460  addToMap(errormap,"code", errorcode);
     2461  if(locator!=NULL)
     2462    addToMap(errormap,"locator", locator);
    24262463  else
    2427     xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode");
    2428 
    2429   tmp=getMap(s,"locator");
    2430   if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0)
    2431     xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value);
    2432 
    2433 
    2434   tmp=getMap(s,"text");
    2435   nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
    2436   if(tmp!=NULL){
    2437     xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
    2438     xmlAddChild(nc1,txt);
    2439   }
    2440   else{
    2441     xmlNodeSetContent(nc1, BAD_CAST _("No debug message available"));
    2442   }
    2443   xmlAddChild(nc,nc1);
    2444   xmlAddChild(n,nc);
    2445   return n;
     2464    addToMap(errormap,"locator", "NULL");
     2465  printExceptionReportResponse(m,errormap);
     2466  freeMap(&errormap);
     2467  free(errormap);
     2468  return -1;
    24462469}
    24472470
     
    24792502  fclose(file);
    24802503  char rsize[100];
    2481   sprintf(rsize,"%d",count*sizeof(char));
     2504  sprintf(rsize,"%ld",count*sizeof(char));
    24822505  addToMap(tmpMap1,"size",rsize);
    24832506}
     
    25292552      char tmpMsg[1024];
    25302553      sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the session maps."),session_file_path);
    2531       map * errormap = createMap("text",tmpMsg);
    2532       addToMap(errormap,"code", "InternalError");
    2533      
    2534       printExceptionReportResponse(m,errormap);
    2535       freeMap(&errormap);
    2536       free(errormap);
     2554      errorException(m,tmpMsg,"InternalError",NULL);
     2555
    25372556      return;
    25382557    }
     
    25432562  }
    25442563 
    2545     if(res==SERVICE_FAILED){
    2546       map * errormap;
    2547       map *lenv;
    2548       lenv=getMapFromMaps(m,"lenv","message");
    2549       char *tmp0;
    2550       if(lenv!=NULL){
    2551         tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char));
    2552         sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value);
    2553       }
    2554       else{
    2555         tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char));
    2556         sprintf(tmp0,_("Unable to run the Service. No more information was returned back by the Service."));
    2557       }
    2558       errormap = createMap("text",tmp0);
    2559       free(tmp0);
    2560       addToMap(errormap,"code", "InternalError");
    2561       dumpMap(errormap);
    2562       printExceptionReportResponse(m,errormap);
    2563       freeMap(&errormap);
    2564       free(errormap);
    2565       return;
    2566     }
    2567 
    2568 
     2564  if(res==SERVICE_FAILED){
     2565    map *lenv;
     2566    lenv=getMapFromMaps(m,"lenv","message");
     2567    char *tmp0;
     2568    if(lenv!=NULL){
     2569      tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char));
     2570      sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value);
     2571    }
     2572    else{
     2573      tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char));
     2574      sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service."));
     2575    }
     2576    errorException(m,tmp0,"InternalError",NULL);
     2577    free(tmp0);
     2578    return;
     2579  }
     2580
     2581
     2582  map *tmp1=getMapFromMaps(m,"main","tmpPath");
    25692583  if(asRaw==0){
    25702584#ifdef DEBUG
     
    25732587#endif
    25742588    maps* tmpI=request_outputs;
     2589
    25752590    while(tmpI!=NULL){
    25762591#ifdef USE_MS
     
    25962611            addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
    25972612          }
    2598 
    2599           map *tmp1=getMapFromMaps(m,"main","tmpPath");
    26002613
    26012614          map *gfile=getMap(tmpI->content,"generated_file");
     
    26482661              char tmpMsg[1024];
    26492662              sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the %s final result."),file_name,tmpI->name);
    2650               map * errormap = createMap("text",tmpMsg);
    2651               addToMap(errormap,"code", "InternalError");
    2652               printExceptionReportResponse(m,errormap);
    2653               freeMap(&errormap);
    2654               free(errormap);
     2663              errorException(m,tmpMsg,"InternalError",NULL);
    26552664              free(file_name);
    26562665              free(file_path);
     
    27302739      map *gfile=getMap(tmpI->content,"generated_file");
    27312740      if(gfile!=NULL){
     2741        gfile=getMap(tmpI->content,"expected_generated_file");
     2742        if(gfile==NULL){
     2743          gfile=getMap(tmpI->content,"generated_file");
     2744        }
    27322745        readGeneratedFile(m,tmpI->content,gfile->value);
    27332746      }
     
    27362749        char tmpMsg[1024];
    27372750        sprintf(tmpMsg,_("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."),tmpI->name);
    2738         map * errormap = createMap("text",tmpMsg);
    2739         addToMap(errormap,"code", "InvalidParameterValue");
    2740         printExceptionReportResponse(m,errormap);
    2741         freeMap(&errormap);
    2742         free(errormap);
     2751        errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
    27432752        return;
    27442753      }
     
    28422851}
    28432852
    2844 char* addDefaultValues(maps** out,elements* in,maps* m,int type){
     2853char* addDefaultValues(maps** out,elements* in,maps* m,int type,map** err){
     2854  map *res=*err;
    28452855  elements* tmpInputs=in;
    28462856  maps* out1=*out;
     2857  char *result=NULL;
     2858  int nb=0;
    28472859  if(type==1){
    28482860    while(out1!=NULL){
    2849       if(getElements(in,out1->name)==NULL)
    2850         return out1->name;
     2861      if(getElements(in,out1->name)==NULL){
     2862        if(res==NULL){
     2863          res=createMap("value",out1->name);
     2864        }else{
     2865          setMapArray(res,"value",nb,out1->name);
     2866        }
     2867        nb++;
     2868        result=out1->name;
     2869      }
    28512870      out1=out1->next;
     2871    }
     2872    if(res!=NULL){
     2873      *err=res;
     2874      return result;
    28522875    }
    28532876    out1=*out;
     
    28672890            freeMaps(&tmpMaps2);
    28682891            free(tmpMaps2);
    2869             return tmpInputs->name;
     2892            if(res==NULL){
     2893              res=createMap("value",tmpInputs->name);
     2894            }else{
     2895              setMapArray(res,"value",nb,tmpInputs->name);
     2896            }
     2897            nb++;
     2898            result=tmpInputs->name;
    28702899          }
    28712900          else{
     
    28762905          }
    28772906        }
    2878         map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
    2879         if(tmpMaxO!=NULL){
    2880           if(tmpMaps2->content==NULL)
    2881             tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value);
    2882           else
    2883             addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value);
    2884         }
    2885         map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
    2886         if(tmpMaxMB!=NULL){
    2887           if(tmpMaps2->content==NULL)
    2888             tmpMaps2->content=createMap("maximumMegabytes",tmpMaxMB->value);
    2889           else
    2890             addToMap(tmpMaps2->content,"maximumMegabytes",tmpMaxMB->value);
    2891         }
    2892       }
    2893 
    2894       iotype* tmpIoType=tmpInputs->defaults;
    2895       if(tmpIoType!=NULL){
    2896         map* tmpm=tmpIoType->content;
    2897         while(tmpm!=NULL){
    2898           if(tmpMaps2->content==NULL)
    2899             tmpMaps2->content=createMap(tmpm->name,tmpm->value);
    2900           else
    2901             addToMap(tmpMaps2->content,tmpm->name,tmpm->value);
    2902           tmpm=tmpm->next;
    2903         }
    2904       }
    2905       addToMap(tmpMaps2->content,"inRequest","false");
    2906       if(type==0){
    2907         map *tmpMap=getMap(tmpMaps2->content,"value");
    2908         if(tmpMap==NULL)
    2909           addToMap(tmpMaps2->content,"value","NULL");
    2910       }
    2911       if(out1==NULL){
    2912         *out=dupMaps(&tmpMaps2);
    2913         out1=*out;
    2914       }
    2915       else
    2916         addMapsToMaps(&out1,tmpMaps2);
    2917       freeMap(&tmpMaps2->content);
    2918       free(tmpMaps2->content);
    2919       tmpMaps2->content=NULL;
    2920       freeMaps(&tmpMaps2);
    2921       free(tmpMaps2);
    2922       tmpMaps2=NULL;
     2907        if(res==NULL){
     2908          map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
     2909          if(tmpMaxO!=NULL){
     2910            if(tmpMaps2->content==NULL)
     2911              tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value);
     2912            else
     2913              addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value);
     2914          }
     2915          map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
     2916          if(tmpMaxMB!=NULL){
     2917            if(tmpMaps2->content==NULL)
     2918              tmpMaps2->content=createMap("maximumMegabytes",tmpMaxMB->value);
     2919            else
     2920              addToMap(tmpMaps2->content,"maximumMegabytes",tmpMaxMB->value);
     2921          }
     2922        }
     2923      }
     2924
     2925      if(res==NULL){
     2926        iotype* tmpIoType=tmpInputs->defaults;
     2927        if(tmpIoType!=NULL){
     2928          map* tmpm=tmpIoType->content;
     2929          while(tmpm!=NULL){
     2930            if(tmpMaps2->content==NULL)
     2931              tmpMaps2->content=createMap(tmpm->name,tmpm->value);
     2932            else
     2933              addToMap(tmpMaps2->content,tmpm->name,tmpm->value);
     2934            tmpm=tmpm->next;
     2935          }
     2936        }
     2937        addToMap(tmpMaps2->content,"inRequest","false");
     2938        if(type==0){
     2939          map *tmpMap=getMap(tmpMaps2->content,"value");
     2940          if(tmpMap==NULL)
     2941            addToMap(tmpMaps2->content,"value","NULL");
     2942        }
     2943        if(out1==NULL){
     2944          *out=dupMaps(&tmpMaps2);
     2945          out1=*out;
     2946        }
     2947        else
     2948          addMapsToMaps(&out1,tmpMaps2);
     2949        freeMap(&tmpMaps2->content);
     2950        free(tmpMaps2->content);
     2951        tmpMaps2->content=NULL;
     2952        freeMaps(&tmpMaps2);
     2953        free(tmpMaps2);
     2954        tmpMaps2=NULL;
     2955      }
    29232956    }
    29242957    else{
     
    30483081    }
    30493082    tmpInputs=tmpInputs->next;
     3083  }
     3084  if(res!=NULL){
     3085    *err=res;
     3086    return result;
    30503087  }
    30513088  return "";
     
    33813418   
    33823419  }
     3420  return 0;
    33833421}
    33843422
     
    34803518}
    34813519
    3482 int errorException(maps *m, const char *message, const char *errorcode, const char *locator)
    3483 {
    3484   map* errormap = createMap("text", message);
    3485   addToMap(errormap,"code", errorcode);
    3486   if(locator!=NULL)
    3487     addToMap(errormap,"locator", locator);
    3488   else
    3489     addToMap(errormap,"locator", "NULL");
    3490   printExceptionReportResponse(m,errormap);
    3491   freeMap(&errormap);
    3492   free(errormap);
    3493   return -1;
    3494 }
    3495 
    3496 
    34973520char *readVSIFile(maps* conf,const char* dataSource){
    34983521    VSILFILE * fichier=VSIFOpenL(dataSource,"rb");
     
    35013524    if(fichier==NULL){
    35023525      char tmp[1024];
    3503       sprintf(tmp,"Failed to open file %s for reading purpose. File seems empty %d.",
     3526      sprintf(tmp,"Failed to open file %s for reading purpose. File seems empty %lld.",
    35043527              dataSource,file_status.st_size);
    35053528      setMapInMaps(conf,"lenv","message",tmp);
     
    36203643  return 0;
    36213644}
     3645
     3646/************************************************************************/
     3647/*                           checkValidValue()                          */
     3648/************************************************************************/
     3649
     3650/**
     3651 * Verify if a parameter value is valid.
     3652 *
     3653 * @param request the request map
     3654 * @param res the error map potentially generated
     3655 * @param avalues the acceptable values (or null if testing only for presence)
     3656 * @param mandatory verify the presence of the parameter if mandatory > 0
     3657 */
     3658void checkValidValue(map* request,map** res,const char* toCheck,const char** avalues,int mandatory){
     3659  map* lres=*res;
     3660  map* r_inputs = getMap (request,toCheck);
     3661  if (r_inputs == NULL){
     3662    if(mandatory>0){
     3663      char *replace=_("Mandatory parameter <%s> was not specified");
     3664      char *message=(char*)malloc((strlen(replace)+strlen(toCheck)+1)*sizeof(char));
     3665      sprintf(message,replace,toCheck);
     3666      if(lres==NULL){
     3667        lres=createMap("code","MissingParameterValue");
     3668        addToMap(lres,"text",message);
     3669        addToMap(lres,"locator",toCheck);       
     3670      }else{
     3671        int length=1;
     3672        map* len=getMap(lres,"length");
     3673        if(len!=NULL){
     3674          length=atoi(len->value);
     3675        }
     3676        setMapArray(lres,"text",length,message);
     3677        setMapArray(lres,"locator",length,toCheck);
     3678        setMapArray(lres,"code",length,"MissingParameter");
     3679      }
     3680      free(message);
     3681    }
     3682  }else{
     3683    if(avalues==NULL)
     3684      return;
     3685    int nb=0;
     3686    int hasValidValue=-1;
     3687    while(avalues[nb]!=NULL){
     3688      if(strcasecmp(avalues[nb],r_inputs->value)==0){
     3689        hasValidValue=1;
     3690        break;
     3691      }
     3692      nb++;
     3693    }
     3694    if(hasValidValue<0){
     3695      char *replace=_("Ununderstood <%s> value, %s %s the only acceptable value.");
     3696      nb=0;
     3697      char *vvalues=NULL;
     3698      char* num=_("is");
     3699      while(avalues[nb]!=NULL){
     3700        char *tvalues;
     3701        if(vvalues==NULL){
     3702          vvalues=(char*)malloc((strlen(avalues[nb])+3)*sizeof(char));
     3703          sprintf(vvalues,"%s",avalues[nb]);
     3704        }
     3705        else{
     3706          tvalues=zStrdup(vvalues);
     3707          vvalues=(char*)realloc(vvalues,(strlen(tvalues)+strlen(avalues[nb])+3)*sizeof(char));
     3708          sprintf(vvalues,"%s, %s",tvalues,avalues[nb]);
     3709          free(tvalues);
     3710          num=_("are");
     3711        }
     3712        nb++;
     3713      }
     3714      char *message=(char*)malloc((strlen(replace)+strlen(num)+strlen(vvalues)+strlen(toCheck)+1)*sizeof(char));
     3715      sprintf(message,replace,toCheck,vvalues,num);
     3716      if(lres==NULL){
     3717        lres=createMap("code","InvalidParameterValue");
     3718        addToMap(lres,"text",message);
     3719        addToMap(lres,"locator",toCheck);       
     3720      }else{
     3721        int length=1;
     3722        map* len=getMap(lres,"length");
     3723        if(len!=NULL){
     3724          length=atoi(len->value);
     3725        }
     3726        setMapArray(lres,"text",length,message);
     3727        setMapArray(lres,"locator",length,toCheck);
     3728        setMapArray(lres,"code",length,"InvalidParameterValue");
     3729      }
     3730    }
     3731  }
     3732  if(lres!=NULL){
     3733    *res=lres;
     3734  }
     3735}
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