Changeset 576 for trunk


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?.

Location:
trunk/zoo-project
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/HISTORY.txt

    r558 r576  
    11Version 1.5.0-dev
     2  * Add support for multiple Exception nodes
     3  * Add a length key when creating MapArray
    24  * Add Orfeo Toolbox support for applications as a service
    35  * Add the otb2zcfg utility to produce zcfg for otb applications
  • trunk/zoo-project/zoo-kernel/service.h

    r554 r576  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2012 GeoLabs SARL
     4 * Copyright (c) 2009-2015 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    475475    tmp->value[size]=0;
    476476    char sin[128];
    477     sprintf(sin,"%ld",size);
     477    sprintf(sin,"%d",size);
    478478    addToMap(m,"size",sin);
    479479  }
     
    611611      if(size!=NULL)
    612612        loadMapBinary(out,in,-1);
    613     char* tmpSized=NULL;
    614    
    615613  }
    616614
     
    672670
    673671
    674   static void setMapArray(map* m,char* key,int index,char* value){
     672  static void setMapArray(map* m,const char* key,int index,const char* value){
    675673    char tmp[1024];
    676     if(index>0)
     674    if(index>0){
    677675      sprintf(tmp,"%s_%d",key,index);
     676      map* len=getMap(m,"length");
     677      if((len!=NULL && atoi(len->value)<index+1) || len==NULL){
     678        char tmp0[5];
     679        sprintf(tmp0,"%d",index+1);
     680        addToMap(m,"length",tmp0);
     681      }
     682    }
    678683    else
    679684      sprintf(tmp,"%s",key);
  • 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}
  • trunk/zoo-project/zoo-kernel/service_internal.h

    r550 r576  
    9999  int readServiceFile(maps*, char*,service**,char *);
    100100  int isValidLang(maps*,const char*);
     101  void addLangAttr(xmlNodePtr,maps*);
    101102
    102103  void printHeaders(maps*);
     
    137138  xmlNodePtr createExceptionReportNode(maps*,map*,int);
    138139  void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*);
    139   xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,const char*,maps*);
     140  xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*);
     141  xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*);
    140142  void printGetCapabilitiesForProcess(maps*,xmlNodePtr,service*);
    141   xmlNodePtr printDescribeProcessHeader(xmlDocPtr,const char*,maps*);
    142143  void printDescribeProcessForProcess(maps*,xmlNodePtr,service*);
    143144  void printFullDescription(int,elements*,const char*,xmlNsPtr,xmlNodePtr);
     
    148149  void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
    149150  void printBoundingBoxDocument(maps*,maps*,FILE*);
    150   void printOutputDefinitions1(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
    151  
     151  void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
     152
    152153  void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
    153154
     
    155156  char *base64d(const char*,int,int*);
    156157  void ensureDecodedBase64(maps**);
    157 
    158   char* addDefaultValues(maps**,elements*,maps*,int);
     158  void checkValidValue(map*,map**,const char*,const char**,int);
     159  char* addDefaultValues(maps**,elements*,maps*,int,map**);
    159160
    160161  int errorException(maps *, const char *, const char *, const char*);
    161162
     163  xmlNodePtr soapEnvelope(maps*,xmlNodePtr);
    162164  int checkForSoapEnvelope(xmlDocPtr);
    163165
  • trunk/zoo-project/zoo-kernel/service_internal_js.c

    r505 r576  
    200200    sprintf(tmp1,"Unable to load JavaScript file %s",filename);
    201201    free(filename);
    202     map* err=createMap("text",tmp1);
    203     addToMap(err,"code","NoApplicableCode");
    204     printExceptionReportResponse(mc,err);
    205     freeMap(&err);
    206     free(err);
     202    errorException(*main_conf,tmp1,"NoApplicableCode",NULL);
    207203    JS_MaybeGC(cx);
    208204    JS_DestroyContext(cx);
     
    248244    fprintf(stderr,"%s",tmp1);
    249245#endif
    250     map* err=createMap("text",tmp1);
    251     addToMap(err,"code","NoApplicableCode");
    252     printExceptionReportResponse(*main_conf,err);
    253     freeMap(&err);
    254     free(err);
     246    errorException(*main_conf,tmp1,"NoApplicableCode",NULL);
    255247    free(filename);
    256248    JS_MaybeGC(cx);
  • trunk/zoo-project/zoo-kernel/service_internal_otb.c

    r565 r576  
    137137                    else if (strncasecmp(test->value,"double",6)==0)
    138138                      outPixType = ImagePixelType_double;
    139                     char* ext="tiff";
     139                    const char* ext="tiff";
    140140                    if(tmpVal!=NULL){
    141141                      if(strncasecmp(tmpVal->value,"image/jp2",9)==0)
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r539 r576  
    215215  }
    216216  else{
    217     map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file.");
    218     addToMap(err,"code","NoApplicableCode");
    219     printExceptionReportResponse(m,err);
     217    errorException (m, "Unable to parse serviceProvider please check your zcfg file.", "NoApplicableCode", NULL);
    220218    exit(-1);
    221219  }
     
    250248#endif
    251249      }else{     
    252         PyObject *ptype,*pvalue, *ptraceback;
    253         PyErr_Fetch(&ptype, &pvalue, &ptraceback);
    254         PyObject *trace=PyObject_Str(pvalue);
    255         char pbt[10240];
    256         if(PyString_Check(trace))
    257           sprintf(pbt,"TRACE : %s",PyString_AsString(trace));
    258         else
    259           fprintf(stderr,"EMPTY TRACE ?");
    260         trace=NULL;
    261         trace=PyObject_Str(ptype);
    262         if(PyString_Check(trace)){
    263           char *tpbt=zStrdup(pbt);
    264           sprintf(pbt,"%s\n%s",tpbt,PyString_AsString(trace));
    265           free(tpbt);
    266         }
    267         else
    268           fprintf(stderr,"EMPTY TRACE ?");
    269        
    270         char *tpbt=zStrdup(pbt);
    271         pName = PyString_FromString("traceback");
    272         pModule = PyImport_Import(pName);
    273         pArgs = PyTuple_New(1);
    274         PyTuple_SetItem(pArgs, 0, ptraceback);
    275         pFunc = PyObject_GetAttrString(pModule,"format_tb");
    276         pValue = PyObject_CallObject(pFunc, pArgs);
    277         trace=NULL;
    278         trace=PyObject_Str(pValue);
    279         if(PyString_Check(trace))
    280           sprintf(pbt,"%s\nUnable to run your python process properly. Please check the following messages : %s",tpbt,PyString_AsString(trace));
    281         else
    282           sprintf(pbt,"%s \n Unable to run your python process properly. Unable to provide any futher informations.",tpbt);
    283         free(tpbt);
    284         map* err=createMap("text",pbt);
    285         addToMap(err,"code","NoApplicableCode");
    286         printExceptionReportResponse(m,err);
     250        PythonZooReport(m,tmp->value,0);
    287251        res=-1;
    288252      }
     
    291255      char tmpS[1024];
    292256      sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value);
    293       map* tmps=createMap("text",tmpS);
    294       printExceptionReportResponse(m,tmps);
     257      errorException(m,tmpS,"NoApplicableCode",NULL);
    295258      res=-1;
    296259    }
    297260  } else{
    298     char tmpS[1024];
    299     sprintf(tmpS, "Python module %s cannot be loaded.\n", tmp->value);
    300     map* tmps=createMap("text",tmpS);
    301     printExceptionReportResponse(m,tmps);
    302     if (PyErr_Occurred())
    303       PyErr_Print();
    304     PyErr_Clear();
     261    PythonZooReport(m,tmp->value,1);
    305262    res=-1;
    306263  }
     
    312269  Py_Finalize();
    313270  return res;
     271}
     272
     273void PythonZooReport(maps* m,const char* module,int load){
     274  PyObject *pName, *pModule, *pFunc;
     275  PyObject *ptype, *pvalue, *ptraceback,*pValue,*pArgs;
     276  PyErr_Fetch(&ptype, &pvalue, &ptraceback);
     277  char *pStrErrorMessage = PyString_AsString(pvalue);
     278  char *tmp0=_("Python module %s cannot be loaded. Message: %s\n");
     279 
     280  PyObject *trace=PyObject_Str(pvalue);
     281  char *pbt=NULL;
     282  if(PyString_Check(trace)){
     283    pbt=(char*)malloc((7+strlen(PyString_AsString(trace))+1)*sizeof(char));
     284    sprintf(pbt,"TRACE: %s",PyString_AsString(trace));
     285  }
     286  else
     287    fprintf(stderr,"EMPTY TRACE ?");
     288 
     289  trace=NULL;
     290 
     291  trace=PyObject_Str(ptype);
     292  if(PyString_Check(trace)){
     293    char *tpbt=zStrdup(pbt);
     294    if(pbt!=NULL)
     295      free(pbt);
     296    pbt=(char*)malloc((1+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));
     297    sprintf(pbt,"%s\n%s",tpbt,PyString_AsString(trace));
     298    free(tpbt);
     299  }
     300  else
     301    fprintf(stderr,"EMPTY TRACE ?");
     302 
     303  if(ptraceback!=NULL){
     304    char *tpbt=zStrdup(pbt);
     305    pName = PyString_FromString("traceback");
     306    pModule = PyImport_Import(pName);
     307    pArgs = PyTuple_New(1);
     308    PyTuple_SetItem(pArgs, 0, ptraceback);
     309    pFunc = PyObject_GetAttrString(pModule,"format_tb");
     310    pValue = PyObject_CallObject(pFunc, pArgs);
     311    trace=NULL;
     312    trace=PyObject_Str(pValue);
     313    if(PyString_Check(trace)){
     314      if(pbt!=NULL)
     315        free(pbt);
     316      pbt=(char*)malloc((90+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));
     317      sprintf(pbt,_("%s\nUnable to run your python process properly. Please check the following messages : %s"),tpbt,PyString_AsString(trace));
     318    }
     319    else{
     320      if(pbt!=NULL)
     321        free(pbt);
     322      pbt=(char*)malloc((90+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));     
     323      sprintf(pbt,_("%s \n Unable to run your python process properly. Unable to provide any futher informations."),tpbt);
     324    }
     325    free(tpbt);
     326  }
     327  if(load>0){
     328    char *tmpS=(char*)malloc((strlen(tmp0)+strlen(module)+strlen(pbt)+1)*sizeof(char));
     329    sprintf(tmpS,tmp0,module,pbt);
     330    errorException(m,tmpS,"NoApplicableCode",NULL);
     331    free(tmpS);
     332  }else
     333    errorException(m,pbt,"NoApplicableCode",NULL);
     334  free(pbt);
    314335}
    315336
  • trunk/zoo-project/zoo-kernel/service_internal_python.h

    r469 r576  
    4545int zoo_python_support(maps**,map*,service*,maps**,maps**);
    4646
     47void PythonZooReport(maps*,const char*,int);
     48
    4749PyObject* PythonTranslate(PyObject*, PyObject*);
    4850PyObject* PythonUpdateStatus(PyObject*, PyObject*);
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r557 r576  
    609609#endif
    610610          sprintf (tmps, _("C Library can't be loaded %s"), errstr);
    611           map *tmps1 = createMap ("text", tmps);
    612           printExceptionReportResponse (m, tmps1);
     611          errorException(m,tmps,"InternalError",NULL);
    613612          *eres = -1;
    614           freeMap (&tmps1);
    615           free (tmps1);
    616613        }
    617614    }
     
    697694               ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),
    698695               r_inputs->value);
    699       map *tmps = createMap ("text", tmpv);
    700       printExceptionReportResponse (m, tmps);
     696      errorException (m, tmpv, "InternalError", NULL);
    701697      *eres = -1;
    702698    }
     
    986982   * Check for minimum inputs
    987983   */
     984  map* err=NULL;
     985  const char *vvr[]={
     986    "GetCapabilities",
     987    "DescribeProcess",
     988    "Execute",
     989    NULL
     990  };
     991  checkValidValue(request_inputs,&err,"Request",(const char**)vvr,1);
     992  const char *vvs[]={
     993    "WPS",
     994    NULL
     995  };
     996  if(err!=NULL){
     997    checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
     998    printExceptionReportResponse (m, err);
     999    freeMap(&err);
     1000    free(err);
     1001    if (count (request_inputs) == 1)
     1002      {
     1003        freeMap (&request_inputs);
     1004        free (request_inputs);
     1005      }
     1006    freeMaps (&m);
     1007    free (m);
     1008    return 1;
     1009  }
     1010  checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
     1011  const char *vvv[]={
     1012    "1.0.0",
     1013    NULL
     1014  };
    9881015  r_inputs = getMap (request_inputs, "Request");
    989   if (request_inputs == NULL || r_inputs == NULL)
    990     {
    991       errorException (m, _("Parameter <request> was not specified"),
    992                       "MissingParameterValue", "request");
    993       if (count (request_inputs) == 1)
    994         {
    995           freeMap (&request_inputs);
    996           free (request_inputs);
    997         }
    998       freeMaps (&m);
    999       free (m);
    1000       return 1;
    1001     }
    1002   else
    1003     {
    1004       REQUEST = zStrdup (r_inputs->value);
    1005       if (strncasecmp (r_inputs->value, "GetCapabilities", 15) != 0
    1006           && strncasecmp (r_inputs->value, "DescribeProcess", 15) != 0
    1007           && strncasecmp (r_inputs->value, "Execute", 7) != 0)
    1008         {
    1009           errorException (m,
    1010                           _
    1011                           ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."),
    1012                           "OperationNotSupported", r_inputs->value);
    1013           freeMaps (&m);
    1014           free (m);
    1015           free (REQUEST);
    1016           return 1;
    1017         }
    1018     }
    1019   r_inputs = NULL;
    1020   r_inputs = getMap (request_inputs, "Service");
    1021   if (r_inputs == NULLMAP)
    1022     {
    1023       errorException (m, _("Parameter <service> was not specified"),
    1024                       "MissingParameterValue", "service");
    1025       freeMaps (&m);
    1026       free (m);
    1027       free (REQUEST);
    1028       return 1;
    1029     }
    1030   else
    1031     {
    1032       if (strcasecmp (r_inputs->value, "WPS") != 0)
    1033         {
    1034           errorException (m,
    1035                           _
    1036                           ("Unenderstood <service> value, WPS is the only acceptable value."),
    1037                           "InvalidParameterValue", "service");
    1038           freeMaps (&m);
    1039           free (m);
    1040           free (REQUEST);
    1041           return 1;
    1042         }
    1043     }
    1044   if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0)
    1045     {
    1046       r_inputs = getMap (request_inputs, "Version");
    1047       if (r_inputs == NULL)
    1048         {
    1049           errorException (m, _("Parameter <version> was not specified"),
    1050                           "MissingParameterValue", "version");
    1051           freeMaps (&m);
    1052           free (m);
    1053           free (REQUEST);
    1054           return 1;
    1055         }
    1056       else
    1057         {
    1058           if (strcasecmp (r_inputs->value, "1.0.0") != 0)
    1059             {
    1060               errorException (m,
    1061                               _
    1062                               ("Unenderstood <version> value, 1.0.0 is the only acceptable value."),
    1063                               "InvalidParameterValue", "service");
    1064               freeMaps (&m);
    1065               free (m);
    1066               free (REQUEST);
    1067               return 1;
    1068             }
    1069         }
    1070     }
    1071   else
    1072     {
    1073       r_inputs = getMap (request_inputs, "AcceptVersions");
    1074       if (r_inputs != NULL)
    1075         {
    1076           if (strncmp (r_inputs->value, "1.0.0", 5) != 0)
    1077             {
    1078               errorException (m,
    1079                               _
    1080                               ("Unenderstood <AcceptVersions> value, 1.0.0 is the only acceptable value."),
    1081                               "VersionNegotiationFailed", NULL);
    1082               freeMaps (&m);
    1083               free (m);
    1084               free (REQUEST);
    1085               return 1;
    1086             }
    1087         }
    1088     }
     1016  REQUEST = zStrdup (r_inputs->value);
     1017  if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){
     1018    checkValidValue(request_inputs,&err,"version",(const char**)vvv,1);
     1019    checkValidValue(request_inputs,&err,"identifier",NULL,1);
     1020  }else{
     1021    checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1);
     1022  }
     1023  if(err!=NULL){
     1024    printExceptionReportResponse (m, err);
     1025    freeMap(&err);
     1026    free(err);
     1027    if (count (request_inputs) == 1)
     1028      {
     1029        freeMap (&request_inputs);
     1030        free (request_inputs);
     1031      }
     1032    free(REQUEST);
     1033    freeMaps (&m);
     1034    free (m);
     1035    return 1;
     1036  }
    10891037
    10901038  r_inputs = getMap (request_inputs, "serviceprovider");
     
    10931041      addToMap (request_inputs, "serviceprovider", "");
    10941042    }
     1043
    10951044
    10961045  maps *request_output_real_format = NULL;
     
    11241073      xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
    11251074      r_inputs = NULL;
    1126       r_inputs = getMap (request_inputs, "ServiceProvider");
    1127       xmlNodePtr n;
    1128       if (r_inputs != NULL)
    1129         n = printGetCapabilitiesHeader (doc, r_inputs->value, m);
    1130       else
    1131         n = printGetCapabilitiesHeader (doc, "", m);
    1132     /**
    1133      * Here we need to close stdout to ensure that not supported chars
    1134      * has been found in the zcfg and then printed on stdout
    1135      */
     1075      //r_inputs = getMap (request_inputs, "ServiceProvider");
     1076      xmlNodePtr n=printGetCapabilitiesHeader(doc,m);
     1077      /**
     1078       * Here we need to close stdout to ensure that unsupported chars
     1079       * has been found in the zcfg and then printed on stdout
     1080       */
    11361081      int saved_stdout = dup (fileno (stdout));
    11371082      dup2 (fileno (stderr), fileno (stdout));
     
    11591104    {
    11601105      r_inputs = getMap (request_inputs, "Identifier");
    1161       if (r_inputs == NULL
    1162           || strlen (r_inputs->name) == 0 || strlen (r_inputs->value) == 0)
    1163         {
    1164           errorException (m, _("Mandatory <identifier> was not specified"),
    1165                           "MissingParameterValue", "identifier");
    1166           freeMaps (&m);
    1167           free (m);
    1168           free (REQUEST);
    1169           free (SERVICE_URL);
    1170           return 0;
    1171         }
    11721106
    11731107      struct dirent *dp;
     
    11851119      if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
    11861120        {
    1187       /**
    1188        * Loop over Identifier list
    1189        */
     1121          /**
     1122           * Loop over Identifier list
     1123           */
    11901124          xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
    11911125          r_inputs = NULL;
    1192           r_inputs = getMap (request_inputs, "ServiceProvider");
    1193 
    1194           xmlNodePtr n;
    1195           if (r_inputs != NULL)
    1196             n = printDescribeProcessHeader (doc, r_inputs->value, m);
    1197           else
    1198             n = printDescribeProcessHeader (doc, "", m);
     1126          xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
     1127                                        "ProcessDescriptions");
    11991128
    12001129          r_inputs = getMap (request_inputs, "Identifier");
     
    14601389      sprintf (tmpMsg,
    14611390               _
    1462                ("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),
     1391               ("The value for <identifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),
    14631392               r_inputs->value);
    14641393      errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
     
    16401569#endif
    16411570      char cursor_input[40960];
    1642       if (r_inputs != NULL)
     1571      if (r_inputs != NULL){
    16431572        snprintf (cursor_input, 40960, "%s", r_inputs->value);
    1644       else
    1645         {
    1646           errorException (m, _("Parameter <DataInputs> was not specified"),
    1647                           "MissingParameterValue", "DataInputs");
    1648           freeMaps (&m);
    1649           free (m);
    1650           free (REQUEST);
    1651           free (SERVICE_URL);
    1652           InternetCloseHandle (&hInternet);
    1653           freeService (&s1);
    1654           free (s1);
    1655           return 0;
    1656         }
    1657       j = 0;
    1658 
    1659     /**
    1660      * Put each DataInputs into the inputs_as_text array
    1661      */
    1662       char *tmp1 = zStrdup (cursor_input);
    1663       char *pToken;
    1664       pToken = strtok (cursor_input, ";");
    1665       if (pToken != NULL && strncasecmp (pToken, tmp1, strlen (tmp1)) == 0)
    1666         {
    1667           char *tmp2 = url_decode (tmp1);
    1668           snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s",
    1669                     tmp2);
    1670           free (tmp2);
    1671           pToken = strtok (cursor_input, ";");
    1672         }
    1673       free (tmp1);
    1674 
    1675       char **inputs_as_text = (char **) malloc (100 * sizeof (char *));
    1676       if (inputs_as_text == NULL)
    1677         {
    1678           return errorException (m, _("Unable to allocate memory."),
    1679                                  "InternalError", NULL);
    1680         }
    1681       i = 0;
    1682       while (pToken != NULL)
    1683         {
    1684 #ifdef DEBUG
    1685           fprintf (stderr, "***%s***\n", pToken);
    1686 #endif
    1687           fflush (stderr);
    1688 #ifdef DEBUG
    1689           fprintf (stderr, "***%s***\n", pToken);
    1690 #endif
    1691           inputs_as_text[i] =
    1692             (char *) malloc ((strlen (pToken) + 1) * sizeof (char));
    1693           snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken);
    1694           if (inputs_as_text[i] == NULL)
    1695             {
    1696               return errorException (m, _("Unable to allocate memory."),
    1697                                      "InternalError", NULL);
    1698             }
    1699           pToken = strtok (NULL, ";");
    1700           i++;
    1701         }
    1702 
    1703       for (j = 0; j < i; j++)
    1704         {
    1705           char *tmp = zStrdup (inputs_as_text[j]);
    1706           free (inputs_as_text[j]);
    1707           char *tmpc;
    1708           tmpc = strtok (tmp, "@");
    1709           while (tmpc != NULL)
    1710             {
    1711 #ifdef DEBUG
    1712               fprintf (stderr, "***\n***%s***\n", tmpc);
    1713 #endif
    1714               char *tmpv = strstr (tmpc, "=");
    1715               char tmpn[256];
    1716               memset (tmpn, 0, 256);
    1717               if (tmpv != NULL)
    1718                 {
    1719                   strncpy (tmpn, tmpc,
    1720                            (strlen (tmpc) - strlen (tmpv)) * sizeof (char));
    1721                   tmpn[strlen (tmpc) - strlen (tmpv)] = 0;
    1722                 }
    1723               else
    1724                 {
    1725                   strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char));
    1726                   tmpn[strlen (tmpc)] = 0;
    1727                 }
    1728 #ifdef DEBUG
    1729               fprintf (stderr, "***\n*** %s = %s ***\n", tmpn, tmpv + 1);
    1730 #endif
    1731               if (tmpmaps == NULL)
    1732                 {
    1733                   tmpmaps = (maps *) malloc (MAPS_SIZE);
    1734                   if (tmpmaps == NULL)
    1735                     {
    1736                       return errorException (m,
    1737                                              _("Unable to allocate memory."),
    1738                                              "InternalError", NULL);
    1739                     }
    1740                   tmpmaps->name = zStrdup (tmpn);
    1741                   if (tmpv != NULL)
    1742                     {
    1743                       char *tmpvf = url_decode (tmpv + 1);
    1744                       tmpmaps->content = createMap ("value", tmpvf);
    1745                       free (tmpvf);
    1746                     }
    1747                   else
    1748                     tmpmaps->content = createMap ("value", "Reference");
    1749                   tmpmaps->next = NULL;
    1750                 }
    1751               tmpc = strtok (NULL, "@");
    1752               while (tmpc != NULL)
    1753                 {
    1754 #ifdef DEBUG
    1755                   fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n",
    1756                            tmpc);
    1757 #endif
    1758                   char *tmpv1 = strstr (tmpc, "=");
    1759 #ifdef DEBUG
    1760                   fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
    1761                            tmpv1 + 1);
    1762 #endif
    1763                   char tmpn1[1024];
    1764                   memset (tmpn1, 0, 1024);
    1765                   if (tmpv1 != NULL)
    1766                     {
    1767                       strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1));
    1768                       tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0;
    1769                       addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
    1770                     }
    1771                   else
    1772                     {
    1773                       strncpy (tmpn1, tmpc, strlen (tmpc));
    1774                       tmpn1[strlen (tmpc)] = 0;
    1775                       map *lmap = getLastMap (tmpmaps->content);
    1776                       char *tmpValue =
    1777                         (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) *
    1778                                          sizeof (char));
    1779                       sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc);
    1780                       free (lmap->value);
    1781                       lmap->value = zStrdup (tmpValue);
    1782                       free (tmpValue);
    1783                       tmpc = strtok (NULL, "@");
    1784                       continue;
    1785                     }
    1786 #ifdef DEBUG
    1787                   fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n",
    1788                            tmpn1);
    1789                   fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
    1790                            tmpv1 + 1);
    1791 #endif
    1792                   if (strcmp (tmpn1, "xlink:href") != 0)
    1793                     addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
    1794                   else if (tmpv1 != NULL)
    1795                     {
    1796                       char *tmpx2 = url_decode (tmpv1 + 1);
    1797                       if (strncasecmp (tmpx2, "http://", 7) != 0 &&
    1798                           strncasecmp (tmpx2, "ftp://", 6) != 0 &&
    1799                           strncasecmp (tmpx2, "https://", 8) != 0)
    1800                         {
    1801                           char emsg[1024];
    1802                           sprintf (emsg,
    1803                                    _
    1804                                    ("Unable to find a valid protocol to download the remote file %s"),
    1805                                    tmpv1 + 1);
    1806                           errorException (m, emsg, "InternalError", NULL);
    1807                           freeMaps (&m);
    1808                           free (m);
    1809                           free (REQUEST);
    1810                           free (SERVICE_URL);
    1811                           InternetCloseHandle (&hInternet);
    1812                           freeService (&s1);
    1813                           free (s1);
    1814                           return 0;
    1815                         }
    1816 #ifdef DEBUG
    1817                       fprintf (stderr,
    1818                                "REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",
    1819                                tmpv1 + 1);
    1820 #endif
    1821                       addToMap (tmpmaps->content, tmpn1, tmpx2);
     1573        j = 0;
     1574
     1575        /**
     1576         * Put each DataInputs into the inputs_as_text array
     1577         */
     1578        char *tmp1 = zStrdup (cursor_input);
     1579        char *pToken;
     1580        pToken = strtok (cursor_input, ";");
     1581        if (pToken != NULL && strncasecmp (pToken, tmp1, strlen (tmp1)) == 0)
     1582          {
     1583            char *tmp2 = url_decode (tmp1);
     1584            snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s",
     1585                      tmp2);
     1586            free (tmp2);
     1587            pToken = strtok (cursor_input, ";");
     1588          }
     1589        free (tmp1);
     1590       
     1591        char **inputs_as_text = (char **) malloc (100 * sizeof (char *));
     1592        if (inputs_as_text == NULL)
     1593          {
     1594            return errorException (m, _("Unable to allocate memory."),
     1595                                   "InternalError", NULL);
     1596          }
     1597        i = 0;
     1598        while (pToken != NULL)
     1599          {
     1600#ifdef DEBUG
     1601            fprintf (stderr, "***%s***\n", pToken);
     1602            fflush (stderr);
     1603            fprintf (stderr, "***%s***\n", pToken);
     1604#endif
     1605            inputs_as_text[i] =
     1606              (char *) malloc ((strlen (pToken) + 1) * sizeof (char));
     1607            if (inputs_as_text[i] == NULL)
     1608              {
     1609                return errorException (m, _("Unable to allocate memory."),
     1610                                       "InternalError", NULL);
     1611              }
     1612            snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken);
     1613            pToken = strtok (NULL, ";");
     1614            i++;
     1615          }
     1616       
     1617        for (j = 0; j < i; j++)
     1618          {
     1619            char *tmp = zStrdup (inputs_as_text[j]);
     1620            free (inputs_as_text[j]);
     1621            char *tmpc;
     1622            tmpc = strtok (tmp, "@");
     1623            while (tmpc != NULL)
     1624              {
     1625#ifdef DEBUG
     1626                fprintf (stderr, "***\n***%s***\n", tmpc);
     1627#endif
     1628                char *tmpv = strstr (tmpc, "=");
     1629                char tmpn[256];
     1630                memset (tmpn, 0, 256);
     1631                if (tmpv != NULL)
     1632                  {
     1633                    strncpy (tmpn, tmpc,
     1634                             (strlen (tmpc) - strlen (tmpv)) * sizeof (char));
     1635                    tmpn[strlen (tmpc) - strlen (tmpv)] = 0;
     1636                  }
     1637                else
     1638                  {
     1639                    strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char));
     1640                    tmpn[strlen (tmpc)] = 0;
     1641                  }
     1642#ifdef DEBUG
     1643                fprintf (stderr, "***\n*** %s = %s ***\n", tmpn, tmpv + 1);
     1644#endif
     1645                if (tmpmaps == NULL)
     1646                  {
     1647                    tmpmaps = (maps *) malloc (MAPS_SIZE);
     1648                    if (tmpmaps == NULL)
     1649                      {
     1650                        return errorException (m,
     1651                                               _("Unable to allocate memory."),
     1652                                               "InternalError", NULL);
     1653                      }
     1654                    tmpmaps->name = zStrdup (tmpn);
     1655                    if (tmpv != NULL)
     1656                      {
     1657                        char *tmpvf = url_decode (tmpv + 1);
     1658                        tmpmaps->content = createMap ("value", tmpvf);
     1659                        free (tmpvf);
     1660                      }
     1661                    else
     1662                      tmpmaps->content = createMap ("value", "Reference");
     1663                    tmpmaps->next = NULL;
     1664                  }
     1665                tmpc = strtok (NULL, "@");
     1666                while (tmpc != NULL)
     1667                  {
     1668#ifdef DEBUG
     1669                    fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n",
     1670                             tmpc);
     1671#endif
     1672                    char *tmpv1 = strstr (tmpc, "=");
     1673#ifdef DEBUG
     1674                    fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
     1675                             tmpv1 + 1);
     1676#endif
     1677                    char tmpn1[1024];
     1678                    memset (tmpn1, 0, 1024);
     1679                    if (tmpv1 != NULL)
     1680                      {
     1681                        strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1));
     1682                        tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0;
     1683                        addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
     1684                      }
     1685                    else
     1686                      {
     1687                        strncpy (tmpn1, tmpc, strlen (tmpc));
     1688                        tmpn1[strlen (tmpc)] = 0;
     1689                        map *lmap = getLastMap (tmpmaps->content);
     1690                        char *tmpValue =
     1691                          (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) *
     1692                                           sizeof (char));
     1693                        sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc);
     1694                        free (lmap->value);
     1695                        lmap->value = zStrdup (tmpValue);
     1696                        free (tmpValue);
     1697                        tmpc = strtok (NULL, "@");
     1698                        continue;
     1699                      }
     1700#ifdef DEBUG
     1701                    fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n",
     1702                             tmpn1);
     1703                    fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
     1704                             tmpv1 + 1);
     1705#endif
     1706                    if (strcmp (tmpn1, "xlink:href") != 0)
     1707                      addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
     1708                    else if (tmpv1 != NULL)
     1709                      {
     1710                        char *tmpx2 = url_decode (tmpv1 + 1);
     1711                        if (strncasecmp (tmpx2, "http://", 7) != 0 &&
     1712                            strncasecmp (tmpx2, "ftp://", 6) != 0 &&
     1713                            strncasecmp (tmpx2, "https://", 8) != 0)
     1714                          {
     1715                            char emsg[1024];
     1716                            sprintf (emsg,
     1717                                     _
     1718                                     ("Unable to find a valid protocol to download the remote file %s"),
     1719                                     tmpv1 + 1);
     1720                            errorException (m, emsg, "InternalError", NULL);
     1721                            freeMaps (&m);
     1722                            free (m);
     1723                            free (REQUEST);
     1724                            free (SERVICE_URL);
     1725                            InternetCloseHandle (&hInternet);
     1726                            freeService (&s1);
     1727                            free (s1);
     1728                            return 0;
     1729                          }
     1730#ifdef DEBUG
     1731                        fprintf (stderr,
     1732                                 "REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",
     1733                                 tmpv1 + 1);
     1734#endif
     1735                        addToMap (tmpmaps->content, tmpn1, tmpx2);
    18221736#ifndef WIN32
    1823                       if (CHECK_INET_HANDLE (hInternet))
    1824 #endif
    1825                         {
    1826                           if (loadRemoteFile
    1827                               (&m, &tmpmaps->content, &hInternet, tmpx2) < 0)
    1828                             {
    1829                               freeMaps (&m);
    1830                               free (m);
    1831                               free (REQUEST);
    1832                               free (SERVICE_URL);
    1833                               InternetCloseHandle (&hInternet);
    1834                               freeService (&s1);
    1835                               free (s1);
    1836                               return 0;
    1837                             }
    1838                         }
    1839                       free (tmpx2);
    1840                       addToMap (tmpmaps->content, "Reference", tmpv1 + 1);
    1841                     }
    1842                   tmpc = strtok (NULL, "@");
    1843                 }
    1844 #ifdef DEBUG
    1845               dumpMaps (tmpmaps);
    1846               fflush (stderr);
    1847 #endif
    1848               if (request_input_real_format == NULL)
    1849                 request_input_real_format = dupMaps (&tmpmaps);
    1850               else
    1851                 {
    1852                   maps *testPresence =
    1853                     getMaps (request_input_real_format, tmpmaps->name);
    1854                   if (testPresence != NULL)
    1855                     {
    1856                       elements *elem =
    1857                         getElements (s1->inputs, tmpmaps->name);
    1858                       if (elem != NULL)
    1859                         {
    1860                           if (appendMapsToMaps
    1861                               (m, request_input_real_format, tmpmaps,
    1862                                elem) < 0)
    1863                             {
    1864                               freeMaps (&m);
    1865                               free (m);
    1866                               free (REQUEST);
    1867                               free (SERVICE_URL);
    1868                               InternetCloseHandle (&hInternet);
    1869                               freeService (&s1);
    1870                               free (s1);
    1871                               return 0;
    1872                             }
    1873                         }
    1874                     }
    1875                   else
    1876                     addMapsToMaps (&request_input_real_format, tmpmaps);
    1877                 }
    1878               freeMaps (&tmpmaps);
    1879               free (tmpmaps);
    1880               tmpmaps = NULL;
    1881               free (tmp);
    1882             }
    1883         }
    1884       free (inputs_as_text);
     1737                        if (CHECK_INET_HANDLE (hInternet))
     1738#endif
     1739                          {
     1740                            if (loadRemoteFile
     1741                                (&m, &tmpmaps->content, &hInternet, tmpx2) < 0)
     1742                              {
     1743                                freeMaps (&m);
     1744                                free (m);
     1745                                free (REQUEST);
     1746                                free (SERVICE_URL);
     1747                                InternetCloseHandle (&hInternet);
     1748                                freeService (&s1);
     1749                                free (s1);
     1750                                return 0;
     1751                              }
     1752                          }
     1753                        free (tmpx2);
     1754                        addToMap (tmpmaps->content, "Reference", tmpv1 + 1);
     1755                      }
     1756                    tmpc = strtok (NULL, "@");
     1757                  }
     1758#ifdef DEBUG
     1759                dumpMaps (tmpmaps);
     1760                fflush (stderr);
     1761#endif
     1762                if (request_input_real_format == NULL)
     1763                  request_input_real_format = dupMaps (&tmpmaps);
     1764                else
     1765                  {
     1766                    maps *testPresence =
     1767                      getMaps (request_input_real_format, tmpmaps->name);
     1768                    if (testPresence != NULL)
     1769                      {
     1770                        elements *elem =
     1771                          getElements (s1->inputs, tmpmaps->name);
     1772                        if (elem != NULL)
     1773                          {
     1774                            if (appendMapsToMaps
     1775                                (m, request_input_real_format, tmpmaps,
     1776                                 elem) < 0)
     1777                              {
     1778                                freeMaps (&m);
     1779                                free (m);
     1780                                free (REQUEST);
     1781                                free (SERVICE_URL);
     1782                                InternetCloseHandle (&hInternet);
     1783                                freeService (&s1);
     1784                                free (s1);
     1785                                return 0;
     1786                              }
     1787                          }
     1788                      }
     1789                    else
     1790                      addMapsToMaps (&request_input_real_format, tmpmaps);
     1791                  }
     1792                freeMaps (&tmpmaps);
     1793                free (tmpmaps);
     1794                tmpmaps = NULL;
     1795                free (tmp);
     1796              }
     1797          }
     1798        free (inputs_as_text);
     1799      }
    18851800    }
    18861801  else
     
    25802495              while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
    25812496                cur2 = cur2->next;
    2582               int cur1cnt = 0;
    25832497              while (cur2 != NULL)
    25842498                {
     
    29282842   * DataInputs and ResponseDocument / RawDataOutput
    29292843   */
    2930   char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0);
     2844  map* errI=NULL;
     2845  dumpMaps(request_input_real_format);
     2846  char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0,&errI);
     2847  dumpMaps(request_input_real_format);
    29312848  maps *ptr = request_input_real_format;
    29322849  while (ptr != NULL)
     
    29682885    }
    29692886
     2887  map* errO=NULL;
    29702888  char *dfv1 =
    2971     addDefaultValues (&request_output_real_format, s1->outputs, m, 1);
     2889    addDefaultValues (&request_output_real_format, s1->outputs, m, 1,&errO);
    29722890  if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0)
    29732891    {
    29742892      char tmps[1024];
    2975       map *tmpe = createMap ("code", "MissingParameterValue");
     2893      map *tmpe = NULL;
    29762894      if (strcmp (dfv, "") != 0)
    29772895        {
    2978           snprintf (tmps, 1024,
    2979                     _
    2980                     ("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."),
    2981                     dfv);
    2982           addToMap (tmpe, "locator", dfv);
    2983         }
    2984       else if (strcmp (dfv1, "") != 0)
     2896          tmpe = createMap ("code", "MissingParameterValue");
     2897          int nb=0;
     2898          int length=1;
     2899          map* len=getMap(errI,"length");
     2900          if(len!=NULL)
     2901            length=atoi(len->value);
     2902          for(nb=0;nb<length;nb++){
     2903            map* errp=getMapArray(errI,"value",nb);
     2904            snprintf (tmps, 1024,
     2905                      _
     2906                      ("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."),
     2907                      errp->value);
     2908            setMapArray (tmpe, "locator", nb , errp->value);
     2909            setMapArray (tmpe, "text", nb , tmps);
     2910            setMapArray (tmpe, "code", nb , "MissingParameterValue");
     2911          }
     2912        }
     2913      if (strcmp (dfv1, "") != 0)
    29852914        {
    2986           snprintf (tmps, 1024,
    2987                     _
    2988                     ("The <%s> argument was specified as Output identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."),
    2989                     dfv1);
    2990           addToMap (tmpe, "locator", dfv1);
    2991         }
    2992       addToMap (tmpe, "text", tmps);
     2915          int ilength=0;
     2916          if(tmpe==NULL)
     2917            tmpe = createMap ("code", "InvalidParameterValue");
     2918          else{
     2919            map* len=getMap(tmpe,"length");
     2920            if(len!=NULL)
     2921              ilength=atoi(len->value);
     2922          }
     2923          int nb=0;
     2924          int length=1;
     2925          map* len=getMap(errO,"length");
     2926          if(len!=NULL)
     2927            length=atoi(len->value);
     2928          for(nb=0;nb<length;nb++){
     2929            map* errp=getMapArray(errO,"value",nb);
     2930            snprintf (tmps, 1024,
     2931                      _
     2932                      ("The <%s> argument was specified as %s identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."),
     2933                      errp->value,
     2934                      ((getMap(request_inputs,"RawDataOutput")!=NULL)?"RawDataOutput":"ResponseDocument"));
     2935            setMapArray (tmpe, "locator", nb+ilength , errp->value);
     2936            setMapArray (tmpe, "text", nb+ilength , tmps);
     2937            setMapArray (tmpe, "code", nb+ilength , "InvalidParameterValue");
     2938          }
     2939        }
    29932940      printExceptionReportResponse (m, tmpe);
    29942941      freeService (&s1);
     
    30062953      freeMaps (&tmpmaps);
    30072954      free (tmpmaps);
     2955      if(errI!=NULL){
     2956        freeMap(&errI);
     2957        free(errI);
     2958      }
     2959      if(errO!=NULL){
     2960        freeMap(&errO);
     2961        free(errO);
     2962      }
    30082963      return 1;
    30092964    }
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