source: trunk/zoo-project/zoo-kernel/response_print.c @ 738

Last change on this file since 738 was 738, checked in by knut, 9 years ago

Redefined the API function addToMapWithSize to fix problem with Python/PHP support. Added some variable initializations and NULL pointer checks.

  • Property svn:keywords set to Id
File size: 82.8 KB
Line 
1/*
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2009-2015 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#include "response_print.h"
26#include "request_parser.h"
27#include "server_internal.h"
28#include "service_internal.h"
29#ifdef USE_MS
30#include "service_internal_ms.h"
31#else
32#include "cpl_vsi.h"
33#endif
34
35#ifndef TRUE
36#define TRUE 1
37#endif
38#ifndef FALSE
39#define FALSE -1
40#endif
41
42#ifndef WIN32
43#include <dlfcn.h>
44#endif
45
46#include "mimetypes.h"
47
48
49/**
50 * Add prefix to the service name.
51 *
52 * @param conf the conf maps containing the main.cfg settings
53 * @param level the map containing the level information
54 * @param serv the service structure created from the zcfg file
55 */
56void addPrefix(maps* conf,map* level,service* serv){
57  if(level!=NULL){
58    char key[25];
59    char* prefix=NULL;
60    int clevel=atoi(level->value);
61    int cl=0;
62    for(cl=0;cl<clevel;cl++){
63      sprintf(key,"sprefix_%d",cl);
64      map* tmp2=getMapFromMaps(conf,"lenv",key);
65      if(tmp2!=NULL){
66        if(prefix==NULL)
67          prefix=zStrdup(tmp2->value);
68        else{
69          int plen=strlen(prefix);
70          prefix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char));
71          memcpy(prefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char));
72          prefix[plen+strlen(tmp2->value)]=0;
73        }
74      }
75    }
76    if(prefix!=NULL){
77      char* tmp0=strdup(serv->name);
78      free(serv->name);
79      serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char));
80      sprintf(serv->name,"%s%s",prefix,tmp0);
81      free(tmp0);
82      free(prefix);
83      prefix=NULL;
84    }
85  }
86}
87
88/**
89 * Print the HTTP headers based on a map.
90 *
91 * @param m the map containing the headers informations
92 */
93void printHeaders(maps* m){
94  maps *_tmp=getMaps(m,"headers");
95  if(_tmp!=NULL){
96    map* _tmp1=_tmp->content;
97    while(_tmp1!=NULL){
98      printf("%s: %s\r\n",_tmp1->name,_tmp1->value);
99      _tmp1=_tmp1->next;
100    }
101  }
102}
103
104/**
105 * Add a land attribute to a XML node
106 *
107 * @param n the XML node to add the attribute
108 * @param m the map containing the language key to add as xml:lang
109 */
110void addLangAttr(xmlNodePtr n,maps *m){
111  map *tmpLmap=getMapFromMaps(m,"main","language");
112  if(tmpLmap!=NULL)
113    xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST tmpLmap->value);
114  else
115    xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en-US");
116}
117
118/**
119 * Replace the first letter by its upper case version in a new char array
120 *
121 * @param tmp the char*
122 * @return a new char* with first letter in upper case
123 * @warning be sure to free() the returned string after use
124 */
125char *zCapitalize1(char *tmp){
126  char *res=zStrdup(tmp);
127  if(res[0]>=97 && res[0]<=122)
128    res[0]-=32;
129  return res;
130}
131
132/**
133 * Replace all letters by their upper case version in a new char array
134 *
135 * @param tmp the char*
136 * @return a new char* with first letter in upper case
137 * @warning be sure to free() the returned string after use
138 */
139char *zCapitalize(char *tmp){
140  int i=0;
141  char *res=zStrdup(tmp);
142  for(i=0;i<strlen(res);i++)
143    if(res[i]>=97 && res[i]<=122)
144      res[i]-=32;
145  return res;
146}
147
148/**
149 * Search for an existing XML namespace in usedNS.
150 *
151 * @param name the name of the XML namespace to search
152 * @return the index of the XML namespace found or -1 if not found.
153 */
154int zooXmlSearchForNs(const char* name){
155  int i;
156  int res=-1;
157  for(i=0;i<nbNs;i++)
158    if(strncasecmp(name,nsName[i],strlen(nsName[i]))==0){
159      res=i;
160      break;
161    }
162  return res;
163}
164
165/**
166 * Add an XML namespace to the usedNS if it was not already used.
167 *
168 * @param nr the xmlNodePtr to attach the XML namspace (can be NULL)
169 * @param url the url of the XML namespace to add
170 * @param name the name of the XML namespace to add
171 * @return the index of the XML namespace added.
172 */
173int zooXmlAddNs(xmlNodePtr nr,const char* url,const char* name){
174#ifdef DEBUG
175  fprintf(stderr,"zooXmlAddNs %d %s \n",nbNs,name);
176#endif
177  int currId=-1;
178  if(nbNs==0){
179    nbNs++;
180    currId=0;
181    nsName[currId]=strdup(name);
182    usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
183  }else{
184    currId=zooXmlSearchForNs(name);
185    if(currId<0){
186      nbNs++;
187      currId=nbNs-1;
188      nsName[currId]=strdup(name);
189      usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
190    }
191  }
192  return currId;
193}
194
195/**
196 * Free allocated memory to store used XML namespace.
197 */
198void zooXmlCleanupNs(){
199  int j;
200#ifdef DEBUG
201  fprintf(stderr,"zooXmlCleanup %d\n",nbNs);
202#endif
203  for(j=nbNs-1;j>=0;j--){
204#ifdef DEBUG
205    fprintf(stderr,"zooXmlCleanup %d\n",j);
206#endif
207    if(j==0)
208      xmlFreeNs(usedNs[j]);
209    free(nsName[j]);
210    nbNs--;
211  }
212  nbNs=0;
213}
214
215/**
216 * Add a XML document to the iDocs.
217 *
218 * @param value the string containing the XML document
219 * @return the index of the XML document added.
220 */
221int zooXmlAddDoc(const char* value){
222  int currId=0;
223  nbDocs++;
224  currId=nbDocs-1;
225  iDocs[currId]=xmlParseMemory(value,strlen(value));
226  return currId;
227}
228
229/**
230 * Free allocated memort to store XML documents
231 */
232void zooXmlCleanupDocs(){
233  int j;
234  for(j=nbDocs-1;j>=0;j--){
235    xmlFreeDoc(iDocs[j]);
236  }
237  nbDocs=0;
238}
239
240/**
241 * Generate a SOAP Envelope node when required (if the isSoap key of the [main]
242 * section is set to true).
243 *
244 * @param conf the conf maps containing the main.cfg settings
245 * @param n the node used as children of the generated soap:Envelope
246 * @return the generated soap:Envelope (if isSoap=true) or the input node n
247 *  (when isSoap=false)
248 */
249xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){
250  map* soap=getMapFromMaps(conf,"main","isSoap");
251  if(soap!=NULL && strcasecmp(soap->value,"true")==0){
252    int lNbNs=nbNs;
253    nsName[lNbNs]=strdup("soap");
254    usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
255    nbNs++;
256    xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope");
257    nsName[nbNs]=strdup("soap");
258    usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
259    nbNs++;
260    nsName[nbNs]=strdup("xsi");
261    usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
262    nbNs++;
263    xmlNsPtr ns_xsi=usedNs[nbNs-1];
264    xmlNewNsProp(nr,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope");
265    xmlNodePtr nr1 = xmlNewNode(usedNs[lNbNs], BAD_CAST "Body");
266    xmlAddChild(nr1,n);
267    xmlAddChild(nr,nr1);
268    return nr;
269  }else
270    return n;
271}
272
273/**
274 * Generate a WPS header.
275 *
276 * @param doc the document to add the header
277 * @param m the conf maps containing the main.cfg settings
278 * @param req the request type (GetCapabilities,DescribeProcess,Execute)
279 * @param rname the root node name
280 * @return the generated wps:rname xmlNodePtr (can be wps: Capabilities,
281 *  wps:ProcessDescriptions,wps:ExecuteResponse)
282 */
283xmlNodePtr printWPSHeader(xmlDocPtr doc,maps* m,const char* req,const char* rname,const char* version,int reqId){
284
285  xmlNsPtr ns,ns_xsi;
286  xmlNodePtr n;
287
288  int vid=getVersionId(version);
289
290  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
291  ns=usedNs[wpsId];
292  n = xmlNewNode(ns, BAD_CAST rname);
293  zooXmlAddNs(n,schemas[vid][1],"ows");
294  xmlNewNs(n,BAD_CAST schemas[vid][2],BAD_CAST "wps");
295  zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
296  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
297  ns_xsi=usedNs[xsiId];
298  char *tmp=(char*) malloc((86+strlen(req)+1)*sizeof(char));
299  sprintf(tmp,schemas[vid][4],schemas[vid][2],schemas[vid][3],req);
300  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp);
301  free(tmp);
302  if(vid==0 || reqId==0){
303    xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
304    xmlNewProp(n,BAD_CAST "version",BAD_CAST schemas[vid][0]);
305  }
306  if(vid==0)
307    addLangAttr(n,m);
308  xmlNodePtr fn=soapEnvelope(m,n);
309  xmlDocSetRootElement(doc, fn);
310  return n;
311}
312
313void addLanguageNodes(maps* conf,xmlNodePtr n,xmlNsPtr ns,xmlNsPtr ns_ows){
314  xmlNodePtr nc1,nc2,nc3,nc4;
315  map* version=getMapFromMaps(conf,"main","rversion");
316  int vid=getVersionId(version->value);
317  if(vid==1)
318    nc1 = xmlNewNode(ns_ows, BAD_CAST "Languages");
319  else{
320    nc1 = xmlNewNode(ns, BAD_CAST "Languages");
321    nc2 = xmlNewNode(ns, BAD_CAST "Default");
322    nc3 = xmlNewNode(ns, BAD_CAST "Supported");
323  }
324
325  maps* tmp=getMaps(conf,"main");
326  if(tmp!=NULL){
327    map* tmp1=getMap(tmp->content,"lang");
328    char *toto=tmp1->value;
329    char buff[256];
330    int i=0;
331    int j=0;
332    int dcount=0;
333    while(toto[i]){
334      if(toto[i]!=',' && toto[i]!=0){
335        buff[j]=toto[i];
336        buff[j+1]=0;
337        j++;
338      }
339      else{
340        nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
341        xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
342        if(dcount==0){
343          if(vid==0){
344            xmlAddChild(nc2,nc4);
345            xmlAddChild(nc1,nc2);
346          }
347          dcount++;
348        }
349        nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
350        xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
351        if(vid==0)
352          xmlAddChild(nc3,nc4);
353        else
354          xmlAddChild(nc1,nc4);
355        j=0;
356        buff[j]=0;
357      }
358      i++;
359    }
360    if(strlen(buff)>0){
361      nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
362      xmlAddChild(nc4,xmlNewText(BAD_CAST buff));             
363        if(vid==0)
364          xmlAddChild(nc3,nc4);
365        else
366          xmlAddChild(nc1,nc4);
367    }
368  }
369  if(vid==0)
370    xmlAddChild(nc1,nc3);
371  xmlAddChild(n,nc1);
372}
373
374/**
375 * Generate a Capabilities header.
376 *
377 * @param doc the document to add the header
378 * @param m the conf maps containing the main.cfg settings
379 * @return the generated wps:ProcessOfferings xmlNodePtr
380 */
381xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,maps* m,const char* version="1.0.0"){
382
383  xmlNsPtr ns,ns_ows,ns_xlink;
384  xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6;
385  n = printWPSHeader(doc,m,"GetCapabilities","Capabilities",version,0);
386  maps* toto1=getMaps(m,"main");
387  char tmp[256];
388  map* v=getMapFromMaps(m,"main","rversion");
389  int vid=getVersionId(v->value);
390
391  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
392  ns=usedNs[wpsId];
393  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
394  ns_xlink=usedNs[xlinkId];
395  int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows");
396  ns_ows=usedNs[owsId];
397
398  nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification");
399  maps* tmp4=getMaps(m,"identification");
400  if(tmp4!=NULL){
401    map* tmp2=tmp4->content;
402    const char *orderedFields[5];
403    orderedFields[0]="Title";
404    orderedFields[1]="Abstract";
405    orderedFields[2]="Keywords";
406    orderedFields[3]="Fees";
407    orderedFields[4]="AccessConstraints";
408    int oI=0;
409    for(oI=0;oI<5;oI++)
410      if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){
411        if(strcasecmp(tmp2->name,"abstract")==0 ||
412           strcasecmp(tmp2->name,"title")==0 ||
413           strcasecmp(tmp2->name,"accessConstraints")==0 ||
414           strcasecmp(tmp2->name,"fees")==0){
415          tmp2->name[0]=toupper(tmp2->name[0]);
416          nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
417          xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
418          xmlAddChild(nc,nc1);
419        }
420        else
421          if(strcmp(tmp2->name,"keywords")==0){
422            nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords");
423            char *toto=tmp2->value;
424            char buff[256];
425            int i=0;
426            int j=0;
427            while(toto[i]){
428              if(toto[i]!=',' && toto[i]!=0){
429                buff[j]=toto[i];
430                buff[j+1]=0;
431                j++;
432              }
433              else{
434                nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
435                xmlAddChild(nc2,xmlNewText(BAD_CAST buff));           
436                xmlAddChild(nc1,nc2);
437                j=0;
438              }
439              i++;
440            }
441            if(strlen(buff)>0){
442              nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
443              xmlAddChild(nc2,xmlNewText(BAD_CAST buff));             
444              xmlAddChild(nc1,nc2);
445            }
446            xmlAddChild(nc,nc1);
447            nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceType");
448            xmlAddChild(nc2,xmlNewText(BAD_CAST "WPS"));
449            xmlAddChild(nc,nc2);
450            nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion");
451            map* tmpv=getMapFromMaps(m,"main","rversion");
452            xmlAddChild(nc2,xmlNewText(BAD_CAST tmpv->value));
453            xmlAddChild(nc,nc2);
454          }
455        tmp2=tmp2->next;
456      }
457  }
458  else{
459    fprintf(stderr,"TMP4 NOT FOUND !!");
460    return NULL;
461  }
462  xmlAddChild(n,nc);
463
464  nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider");
465  nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact");
466  nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo");
467  nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone");
468  nc6 = xmlNewNode(ns_ows, BAD_CAST "Address");
469  tmp4=getMaps(m,"provider");
470  if(tmp4!=NULL){
471    map* tmp2=tmp4->content;
472    const char *tmpAddress[6];
473    tmpAddress[0]="addressDeliveryPoint";
474    tmpAddress[1]="addressCity";
475    tmpAddress[2]="addressAdministrativeArea";
476    tmpAddress[3]="addressPostalCode";
477    tmpAddress[4]="addressCountry";
478    tmpAddress[5]="addressElectronicMailAddress";
479    const char *tmpPhone[2];
480    tmpPhone[0]="phoneVoice";
481    tmpPhone[1]="phoneFacsimile";
482    const char *orderedFields[12];
483    orderedFields[0]="providerName";
484    orderedFields[1]="providerSite";
485    orderedFields[2]="individualName";
486    orderedFields[3]="positionName";
487    orderedFields[4]=tmpPhone[0];
488    orderedFields[5]=tmpPhone[1];
489    orderedFields[6]=tmpAddress[0];
490    orderedFields[7]=tmpAddress[1];
491    orderedFields[8]=tmpAddress[2];
492    orderedFields[9]=tmpAddress[3];
493    orderedFields[10]=tmpAddress[4];
494    orderedFields[11]=tmpAddress[5];
495    int oI=0;
496    for(oI=0;oI<12;oI++)
497      if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){
498        if(strcmp(tmp2->name,"keywords")!=0 &&
499           strcmp(tmp2->name,"serverAddress")!=0 &&
500           strcmp(tmp2->name,"lang")!=0){
501          tmp2->name[0]=toupper(tmp2->name[0]);
502          if(strcmp(tmp2->name,"ProviderName")==0){
503            nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
504            xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
505            xmlAddChild(nc,nc1);
506          }
507          else{
508            if(strcmp(tmp2->name,"ProviderSite")==0){
509              nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
510              xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value);
511              xmlAddChild(nc,nc1);
512            } 
513            else 
514              if(strcmp(tmp2->name,"IndividualName")==0 || 
515                 strcmp(tmp2->name,"PositionName")==0){
516                nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
517                xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
518                xmlAddChild(nc3,nc1);
519              } 
520              else 
521                if(strncmp(tmp2->name,"Phone",5)==0){
522                  int j;
523                  for(j=0;j<2;j++)
524                    if(strcasecmp(tmp2->name,tmpPhone[j])==0){
525                      char *tmp4=tmp2->name;
526                      nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+5);
527                      xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
528                      xmlAddChild(nc5,nc1);
529                    }
530                }
531                else 
532                  if(strncmp(tmp2->name,"Address",7)==0){
533                    int j;
534                    for(j=0;j<6;j++)
535                      if(strcasecmp(tmp2->name,tmpAddress[j])==0){
536                        char *tmp4=tmp2->name;
537                        nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+7);
538                        xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
539                        xmlAddChild(nc6,nc1);
540                      }
541                  }
542          }
543        }
544        else
545          if(strcmp(tmp2->name,"keywords")==0){
546            nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords");
547            char *toto=tmp2->value;
548            char buff[256];
549            int i=0;
550            int j=0;
551            while(toto[i]){
552              if(toto[i]!=',' && toto[i]!=0){
553                buff[j]=toto[i];
554                buff[j+1]=0;
555                j++;
556              }
557              else{
558                nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
559                xmlAddChild(nc2,xmlNewText(BAD_CAST buff));           
560                xmlAddChild(nc1,nc2);
561                j=0;
562              }
563              i++;
564            }
565            if(strlen(buff)>0){
566              nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
567              xmlAddChild(nc2,xmlNewText(BAD_CAST buff));             
568              xmlAddChild(nc1,nc2);
569            }
570            xmlAddChild(nc,nc1);
571          }
572        tmp2=tmp2->next;
573      }
574  }
575  else{
576    fprintf(stderr,"TMP4 NOT FOUND !!");
577  }
578  xmlAddChild(nc4,nc5);
579  xmlAddChild(nc4,nc6);
580  xmlAddChild(nc3,nc4);
581  xmlAddChild(nc,nc3);
582  xmlAddChild(n,nc);
583
584
585  nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata");
586
587  int j=0;
588
589  if(toto1!=NULL){
590    map* tmp=getMap(toto1->content,"serverAddress");
591    if(tmp!=NULL){
592      SERVICE_URL = strdup(tmp->value);
593    }
594    else
595      SERVICE_URL = strdup("not_defined");
596  }
597  else
598    SERVICE_URL = strdup("not_defined");
599
600  for(j=0;j<nbSupportedRequests;j++){
601    if(requests[vid][j]==NULL)
602      break;
603    else{
604      nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation");
605      xmlNewProp(nc1,BAD_CAST "name",BAD_CAST requests[vid][j]);
606      nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP");
607      nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP");
608      if(vid!=1 || j!=2){
609        nc4 = xmlNewNode(ns_ows, BAD_CAST "Get");
610        xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST SERVICE_URL);
611        xmlAddChild(nc3,nc4);
612      }
613      nc4 = xmlNewNode(ns_ows, BAD_CAST "Post");
614      xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST SERVICE_URL);
615      xmlAddChild(nc3,nc4);
616      xmlAddChild(nc2,nc3);
617      xmlAddChild(nc1,nc2);
618      xmlAddChild(nc,nc1);
619    }
620  }
621  xmlAddChild(n,nc);
622
623  if(vid==1)
624    addLanguageNodes(m,n,ns,ns_ows);
625  free(SERVICE_URL);
626
627  nc = xmlNewNode(ns, BAD_CAST root_nodes[vid][0]);
628  xmlAddChild(n,nc);
629
630  if(vid==0)
631    addLanguageNodes(m,n,ns,ns_ows);
632
633  return nc;
634}
635
636/**
637 * Generate a wps:Process node for a servie and add it to a given node.
638 *
639 * @param reg the profiles registry
640 * @param m the conf maps containing the main.cfg settings
641 * @param registry the profile registry if any
642 * @param nc the XML node to add the Process node
643 * @param serv the service structure created from the zcfg file
644 * @return the generated wps:ProcessOfferings xmlNodePtr
645 */
646void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
647  xmlNsPtr ns,ns_ows,ns_xml,ns_xlink;
648  xmlNodePtr n=NULL,nc1,nc2;
649  map* version=getMapFromMaps(m,"main","rversion");
650  int vid=getVersionId(version->value);
651  // Initialize or get existing namespaces
652  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
653  ns=usedNs[wpsId];
654  int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows");
655  ns_ows=usedNs[owsId];
656  int xmlId=zooXmlAddNs(NULL,"http://www.w3.org/XML/1998/namespace","xml");
657  ns_xml=usedNs[xmlId];
658  int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
659  ns_xlink=usedNs[xlinkId];
660  map* tmp1;
661  if(serv->content!=NULL){
662    nc1 = xmlNewNode(ns, BAD_CAST capabilities[vid][0]);
663    int i=1;
664    int limit=3;
665    if(vid==1){
666      ns=NULL;
667      limit=7;
668    }
669    for(;i<limit;i+=2){
670      if(capabilities[vid][i]==NULL)
671        break;
672      else{
673        tmp1=getMap(serv->content,capabilities[vid][i]);
674        if(tmp1!=NULL){
675          if(vid==1 && i==1 && strlen(tmp1->value)<5){
676            char *val=(char*)malloc((strlen(tmp1->value)+5)*sizeof(char));
677            sprintf(val,"%s.0.0",tmp1->value);
678            xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST val);
679            free(val);
680          }
681          else
682            xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value);
683        }
684        else
685          xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
686      }
687    }
688    map* tmp3=getMapFromMaps(m,"lenv","level");
689    addPrefix(m,tmp3,serv);
690    printDescription(nc1,ns_ows,serv->name,serv->content,vid);
691    tmp1=serv->metadata;
692    while(tmp1!=NULL){
693      nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
694      xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
695      xmlAddChild(nc1,nc2);
696      tmp1=tmp1->next;
697    }
698
699    xmlAddChild(nc,nc1);
700  }
701}
702
703/**
704 * Attach attributes to a ProcessDescription or a ProcessOffering node.
705 *
706 * @param n the XML node to attach the attributes to
707 * @param ns the XML namespace to create the attributes
708 * @param content the servive main content created from the zcfg file
709 * @param vid the version identifier (0 for 1.0.0 and 1 for 2.0.0)
710 */
711void attachAttributes(xmlNodePtr n,xmlNsPtr ns,map* content,int vid){
712  int limit=(vid==1?7:3);
713  for(int i=1;i<limit;i+=2){
714    map* tmp1=getMap(content,capabilities[vid][i]);
715    if(tmp1!=NULL){
716      if(vid==1 && i==1 && strlen(tmp1->value)<5){
717        char *val=(char*)malloc((strlen(tmp1->value)+5)*sizeof(char));
718        sprintf(val,"%s.0.0",tmp1->value);
719        xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST val);
720        free(val);
721      }
722      else
723        xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value);
724    }
725    else
726      xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
727  }
728}
729
730/**
731 * Add the ows:Metadata nodes relative to the profile registry
732 *
733 * @param n the XML node to add the ows:Metadata
734 * @param ns_ows the ows XML namespace
735 * @param ns_xlink the ows xlink namespace
736 * @param reg the profile registry
737 * @param main_conf the map containing the main configuration content
738 * @param serv the service
739 */
740void addInheritedMetadata(xmlNodePtr n,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,registry* reg,maps* main_conf,service* serv){
741  int vid=1;
742  map* tmp1=getMap(serv->content,"extend");
743  if(tmp1==NULL)
744    tmp1=getMap(serv->content,"concept");
745  if(tmp1!=NULL){
746    map* level=getMap(serv->content,"level");
747    if(level!=NULL){
748      xmlNodePtr nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
749      char* ckey=level->value;
750      if(strncasecmp(level->value,"profile",7)==0)
751        ckey="generic";
752      if(strncasecmp(level->value,"generic",7)==0)
753        ckey="concept";
754      service* inherited=getServiceFromRegistry(reg,ckey,tmp1->value);
755      if(inherited!=NULL){
756        addInheritedMetadata(n,ns_ows,ns_xlink,reg,main_conf,inherited);
757      }
758      char cschema[71];
759      sprintf(cschema,"%s%s",schemas[vid][7],ckey);
760      map* regUrl=getMapFromMaps(main_conf,"main","registryUrl");
761      map* regExt=getMapFromMaps(main_conf,"main","registryExt");
762      char* registryUrl=(char*)malloc((strlen(regUrl->value)+strlen(ckey)+
763                                       (regExt!=NULL?strlen(regExt->value)+1:0)+
764                                       strlen(tmp1->value)+2)*sizeof(char));
765      if(regExt!=NULL)
766        sprintf(registryUrl,"%s%s/%s.%s",regUrl->value,ckey,tmp1->value,regExt->value);
767      else
768        sprintf(registryUrl,"%s%s/%s",regUrl->value,ckey,tmp1->value);
769      xmlNewNsProp(nc1,ns_xlink,BAD_CAST "role",BAD_CAST cschema);
770      xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST registryUrl);
771      free(registryUrl);
772      xmlAddChild(n,nc1);
773    }
774  }
775}
776
777/**
778 * Generate a ProcessDescription node for a servie and add it to a given node.
779 *
780 * @param reg the profile registry
781 * @param m the conf maps containing the main.cfg settings
782 * @param nc the XML node to add the Process node
783 * @param serv the servive structure created from the zcfg file
784 * @return the generated wps:ProcessOfferings xmlNodePtr
785 */
786void printDescribeProcessForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
787  xmlNsPtr ns,ns_ows,ns_xlink;
788  xmlNodePtr n,nc1;
789  xmlNodePtr nc2 = NULL;
790  map* version=getMapFromMaps(m,"main","rversion");
791  int vid=getVersionId(version->value);
792
793  n=nc;
794 
795  int wpsId=zooXmlAddNs(NULL,schemas[vid][3],"wps");
796  ns=usedNs[wpsId];
797  int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows");
798  ns_ows=usedNs[owsId];
799  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
800  ns_xlink=usedNs[xlinkId];
801  map* tmp1=NULL;
802
803  if(vid==0){
804    nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription");
805    attachAttributes(nc,ns,serv->content,vid);
806  }
807  else{
808    nc2 = xmlNewNode(ns, BAD_CAST "ProcessOffering");
809    // In case mode was defined in the ZCFG file then restrict the
810    // jobControlOptions value to this value. The dismiss is always
811    // supported whatever you can set in the ZCFG file.
812    // cf. http://docs.opengeospatial.org/is/14-065/14-065.html#47 (Table 30)
813    map* mode=getMap(serv->content,"mode");
814    if(mode!=NULL){
815      if( strncasecmp(mode->value,"sync",strlen(mode->value))==0 ||
816          strncasecmp(mode->value,"async",strlen(mode->value))==0 ){
817        char toReplace[22];
818        sprintf(toReplace,"%s-execute dismiss",mode->value);
819        addToMap(serv->content,capabilities[vid][3],toReplace);
820      }
821    }
822    attachAttributes(nc2,NULL,serv->content,vid);
823    map* level=getMap(serv->content,"level");
824    if(level!=NULL && strcasecmp(level->value,"generic")==0)
825      nc = xmlNewNode(ns, BAD_CAST "GenericProcess");
826    else
827      nc = xmlNewNode(ns, BAD_CAST "Process");
828  }
829 
830  tmp1=getMapFromMaps(m,"lenv","level");
831  addPrefix(m,tmp1,serv);
832  printDescription(nc,ns_ows,serv->name,serv->content,vid);
833
834  if(vid==0){
835    tmp1=serv->metadata;
836    while(tmp1!=NULL){
837      nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
838      xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
839      xmlAddChild(nc,nc1);
840      tmp1=tmp1->next;
841    }
842    tmp1=getMap(serv->content,"Profile");
843    if(tmp1!=NULL && vid==0){
844      nc1 = xmlNewNode(ns, BAD_CAST "Profile");
845      xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value));
846      xmlAddChild(nc,nc1);
847    }
848  }else{
849    addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv);
850  }
851
852  if(serv->inputs!=NULL){
853    elements* e=serv->inputs;
854    if(vid==0){
855      nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs");
856      printFullDescription(1,e,"Input",ns,ns_ows,nc1,vid);
857      xmlAddChild(nc,nc1);
858    }
859    else{
860      printFullDescription(1,e,"wps:Input",ns,ns_ows,nc,vid);
861    }
862  }
863
864  elements* e=serv->outputs;
865  if(vid==0){
866    nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
867    printFullDescription(0,e,"Output",ns,ns_ows,nc1,vid);
868    xmlAddChild(nc,nc1);
869  }
870  else{
871    printFullDescription(0,e,"wps:Output",ns,ns_ows,nc,vid);
872  }
873  if(vid==0)
874    xmlAddChild(n,nc);
875  else if (nc2 != NULL) {         
876    xmlAddChild(nc2,nc);
877    xmlAddChild(n,nc2);
878  }
879
880}
881
882/**
883 * Generate the required XML tree for the detailled metadata informations of
884 * inputs or outputs
885 *
886 * @param in 1 in case of inputs, 0 for outputs
887 * @param elem the elements structure containing the metadata informations
888 * @param type the name ("Input" or "Output") of the XML node to create
889 * @param ns_ows the ows XML namespace
890 * @param ns_ows the ows XML namespace
891 * @param nc1 the XML node to use to add the created tree
892 * @param vid the WPS version id (0 for 1.0.0, 1 for 2.0.0)
893 */
894void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid){
895  xmlNsPtr ns1=NULL;
896  if(vid==1)
897    ns1=ns;
898
899  xmlNodePtr nc2,nc3,nc4,nc5,nc6,nc7,nc8,nc9;
900  elements* e=elem;
901  nc9=NULL;
902  map* tmp1=NULL;
903  while(e!=NULL){
904    int default1=0;
905    int isAnyValue=1;
906    nc2 = xmlNewNode(NULL, BAD_CAST type);
907    if(strstr(type,"Input")!=NULL){
908      tmp1=getMap(e->content,"minOccurs");
909      if(tmp1!=NULL){
910        xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
911      }else
912        xmlNewProp(nc2,BAD_CAST "minOccurs",BAD_CAST "0");
913      tmp1=getMap(e->content,"maxOccurs");
914      if(tmp1!=NULL){
915        if(strcasecmp(tmp1->value,"unbounded")!=0)
916          xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
917        else
918          xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1000");
919      }else
920        xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1");
921      if((tmp1=getMap(e->content,"maximumMegabytes"))!=NULL){
922        xmlNewProp(nc2,BAD_CAST "maximumMegabytes",BAD_CAST tmp1->value);
923      }
924    }
925
926    printDescription(nc2,ns_ows,e->name,e->content,vid);
927
928    if(e->format!=NULL){
929      const char orderedFields[13][14]={
930        "mimeType",
931        "encoding",
932        "schema",
933        "dataType",
934        "uom",
935        "CRS",
936        "AllowedValues",
937        "range",
938        "rangeMin",
939        "rangeMax",
940        "rangeClosure",
941        "rangeSpace"
942      };
943
944      //Build the (Literal/Complex/BoundingBox)Data node
945      if(strncmp(type,"Output",6)==0){
946        if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0)
947          nc3 = xmlNewNode(ns1, BAD_CAST "LiteralOutput");
948        else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
949          nc3 = xmlNewNode(ns1, BAD_CAST "ComplexOutput");
950        else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0)
951          nc3 = xmlNewNode(ns1, BAD_CAST "BoundingBoxOutput");
952        else
953          nc3 = xmlNewNode(ns1, BAD_CAST e->format);
954      }else{
955        if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0 ||
956           strncasecmp(e->format,"LITERALOUTPUT",strlen(e->format))==0){
957          nc3 = xmlNewNode(ns1, BAD_CAST "LiteralData");
958        }
959        else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
960          nc3 = xmlNewNode(ns1, BAD_CAST "ComplexData");
961        else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0)
962          nc3 = xmlNewNode(ns1, BAD_CAST "BoundingBoxData");
963        else
964          nc3 = xmlNewNode(ns1, BAD_CAST e->format);
965      }
966
967      iotype* _tmp0=NULL;
968      iotype* _tmp=e->defaults;
969      int datatype=0;
970      bool hasUOM=false;
971      bool hasUOM1=false;
972      if(_tmp!=NULL){
973        if(strcmp(e->format,"LiteralOutput")==0 ||
974           strcmp(e->format,"LiteralData")==0){
975          datatype=1;
976          if(vid==1){
977            nc4 = xmlNewNode(ns1, BAD_CAST "Format");
978            xmlNewProp(nc4,BAD_CAST "mimeType",BAD_CAST "text/plain");
979            xmlNewProp(nc4,BAD_CAST "default",BAD_CAST "true");
980            xmlAddChild(nc3,nc4);
981            nc5 = xmlNewNode(NULL, BAD_CAST "LiteralDataDomain");
982            xmlNewProp(nc5,BAD_CAST "default",BAD_CAST "true");
983          }
984          else{
985            nc4 = xmlNewNode(NULL, BAD_CAST "UOMs");
986            nc5 = xmlNewNode(NULL, BAD_CAST "Default");
987          }
988        }
989        else if(strcmp(e->format,"BoundingBoxOutput")==0 ||
990                strcmp(e->format,"BoundingBoxData")==0){
991          datatype=2;
992          nc5 = xmlNewNode(NULL, BAD_CAST "Default");
993        }
994        else{
995          if(vid==0)
996            nc4 = xmlNewNode(NULL, BAD_CAST "Default");
997          nc5 = xmlNewNode(ns1, BAD_CAST "Format");
998          if(vid==1){
999            xmlNewProp(nc5,BAD_CAST "default",BAD_CAST "true");
1000            int oI=0;
1001            for(oI=0;oI<3;oI++)
1002              if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1003                xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value);
1004              }
1005          }
1006        }
1007     
1008        tmp1=_tmp->content;
1009
1010        if(vid==0)
1011          if((tmp1=getMap(_tmp->content,"DataType"))!=NULL){
1012            nc8 = xmlNewNode(ns_ows, BAD_CAST "DataType");
1013            xmlAddChild(nc8,xmlNewText(BAD_CAST tmp1->value));
1014            char tmp[1024];
1015            sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
1016            xmlNewNsProp(nc8,ns_ows,BAD_CAST "reference",BAD_CAST tmp);
1017            if(vid==0)
1018              xmlAddChild(nc3,nc8);
1019            else
1020              xmlAddChild(nc5,nc8);
1021            datatype=1;
1022          }
1023
1024        bool isInput=false;
1025        if(strncmp(type,"Input",5)==0 || strncmp(type,"wps:Input",9)==0){
1026          isInput=true;
1027          if((tmp1=getMap(_tmp->content,"AllowedValues"))!=NULL){
1028            nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
1029            char *token,*saveptr1;
1030            token=strtok_r(tmp1->value,",",&saveptr1);
1031            while(token!=NULL){
1032              nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
1033              char *tmps=strdup(token);
1034              tmps[strlen(tmps)]=0;
1035              xmlAddChild(nc7,xmlNewText(BAD_CAST tmps));
1036              free(tmps);
1037              xmlAddChild(nc6,nc7);
1038              token=strtok_r(NULL,",",&saveptr1);
1039            }
1040            if(getMap(_tmp->content,"range")!=NULL ||
1041               getMap(_tmp->content,"rangeMin")!=NULL ||
1042               getMap(_tmp->content,"rangeMax")!=NULL ||
1043               getMap(_tmp->content,"rangeClosure")!=NULL )
1044              goto doRange;
1045            if(vid==0)
1046              xmlAddChild(nc3,nc6);
1047            else
1048              xmlAddChild(nc5,nc6);
1049            isAnyValue=-1;
1050          }
1051
1052          tmp1=getMap(_tmp->content,"range");
1053          if(tmp1==NULL)
1054            tmp1=getMap(_tmp->content,"rangeMin");
1055          if(tmp1==NULL)
1056            tmp1=getMap(_tmp->content,"rangeMax");
1057       
1058          if(tmp1!=NULL && isAnyValue==1){
1059            nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
1060          doRange:
1061         
1062            /**
1063             * Range: Table 46 OGC Web Services Common Standard
1064             */
1065            nc8 = xmlNewNode(ns_ows, BAD_CAST "Range");
1066         
1067            map* tmp0=getMap(tmp1,"range");
1068            if(tmp0!=NULL){
1069              char* pToken;
1070              char* orig=zStrdup(tmp0->value);
1071              /**
1072               * RangeClosure: Table 47 OGC Web Services Common Standard
1073               */
1074              const char *tmp="closed";
1075              if(orig[0]=='[' && orig[strlen(orig)-1]=='[')
1076                tmp="closed-open";
1077              else
1078                if(orig[0]==']' && orig[strlen(orig)-1]==']')
1079                  tmp="open-closed";
1080                else
1081                  if(orig[0]==']' && orig[strlen(orig)-1]=='[')
1082                    tmp="open";
1083              xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp);
1084              pToken=strtok(orig,",");
1085              int nci0=0;
1086              while(pToken!=NULL){
1087                char *tmpStr=(char*) malloc((strlen(pToken))*sizeof(char));
1088                if(nci0==0){
1089                  nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
1090                  strncpy( tmpStr, pToken+1, strlen(pToken)-1 );
1091                  tmpStr[strlen(pToken)-1] = '\0';
1092                }else{
1093                  nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
1094                  const char* bkt;
1095                  if ( ( bkt = strchr(pToken, '[') ) != NULL || ( bkt = strchr(pToken, ']') ) != NULL ){
1096                    strncpy( tmpStr, pToken, bkt - pToken );
1097                    tmpStr[bkt - pToken] = '\0';
1098                  }
1099                }
1100                xmlAddChild(nc7,xmlNewText(BAD_CAST tmpStr));
1101                free(tmpStr);
1102                xmlAddChild(nc8,nc7);
1103                nci0++;
1104                pToken = strtok(NULL,",");
1105              }             
1106              if(getMap(tmp1,"rangeSpacing")==NULL){
1107                nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing");
1108                xmlAddChild(nc7,xmlNewText(BAD_CAST "1"));
1109                xmlAddChild(nc8,nc7);
1110              }
1111              free(orig);
1112            }else{
1113           
1114              tmp0=getMap(tmp1,"rangeMin");
1115              if(tmp0!=NULL){
1116                nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
1117                xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
1118                xmlAddChild(nc8,nc7);
1119              }else{
1120                nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
1121                xmlAddChild(nc8,nc7);
1122              }
1123              tmp0=getMap(tmp1,"rangeMax");
1124              if(tmp0!=NULL){
1125                nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
1126                xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
1127                xmlAddChild(nc8,nc7);
1128              }else{
1129                nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
1130                xmlAddChild(nc8,nc7);
1131              }
1132              tmp0=getMap(tmp1,"rangeSpacing");
1133              if(tmp0!=NULL){
1134                nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing");
1135                xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
1136                xmlAddChild(nc8,nc7);
1137              }
1138              tmp0=getMap(tmp1,"rangeClosure");
1139              if(tmp0!=NULL){
1140                const char *tmp="closed";
1141                if(strcasecmp(tmp0->value,"co")==0)
1142                  tmp="closed-open";
1143                else
1144                  if(strcasecmp(tmp0->value,"oc")==0)
1145                    tmp="open-closed";
1146                  else
1147                    if(strcasecmp(tmp0->value,"o")==0)
1148                      tmp="open";
1149                xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp);
1150              }else
1151                xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST "closed");
1152            }
1153            if(_tmp0==NULL){
1154              xmlAddChild(nc6,nc8);
1155              _tmp0=e->supported;
1156              if(_tmp0!=NULL &&
1157                 (getMap(_tmp0->content,"range")!=NULL ||
1158                  getMap(_tmp0->content,"rangeMin")!=NULL ||
1159                  getMap(_tmp0->content,"rangeMax")!=NULL ||
1160                  getMap(_tmp0->content,"rangeClosure")!=NULL )){
1161                tmp1=_tmp0->content;
1162                goto doRange;
1163              }
1164            }else{
1165              _tmp0=_tmp0->next;
1166              if(_tmp0!=NULL){
1167                xmlAddChild(nc6,nc8);
1168                if(getMap(_tmp0->content,"range")!=NULL ||
1169                   getMap(_tmp0->content,"rangeMin")!=NULL ||
1170                   getMap(_tmp0->content,"rangeMax")!=NULL ||
1171                   getMap(_tmp0->content,"rangeClosure")!=NULL ){
1172                  tmp1=_tmp0->content;
1173                  goto doRange;
1174                }
1175              }
1176            }
1177            xmlAddChild(nc6,nc8);
1178            if(vid==0)
1179              xmlAddChild(nc3,nc6);
1180            else
1181              xmlAddChild(nc5,nc6);
1182            isAnyValue=-1;
1183          }
1184       
1185        }
1186     
1187        int oI=0;
1188        /*if(vid==0)*/ {
1189          for(oI=0;oI<13;oI++)
1190            if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1191#ifdef DEBUG
1192              printf("DATATYPE DEFAULT ? %s\n",tmp1->name);
1193#endif
1194              if(strcmp(tmp1->name,"asReference")!=0 &&
1195                 strncasecmp(tmp1->name,"DataType",8)!=0 &&
1196                 strcasecmp(tmp1->name,"extension")!=0 &&
1197                 strcasecmp(tmp1->name,"value")!=0 &&
1198                 strcasecmp(tmp1->name,"AllowedValues")!=0 &&
1199                 strncasecmp(tmp1->name,"range",5)!=0){
1200                if(datatype!=1){
1201                  char *tmp2=zCapitalize1(tmp1->name);
1202                  nc9 = xmlNewNode(NULL, BAD_CAST tmp2);
1203                  free(tmp2);
1204                }
1205                else{
1206                  char *tmp2=zCapitalize(tmp1->name);
1207                  nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
1208                  free(tmp2);
1209                }
1210                xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
1211                if(vid==0 || oI>=3){
1212                  if(vid==0 || oI!=4)
1213                    xmlAddChild(nc5,nc9);
1214                  if(oI==4 && vid==1){
1215                    xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true");
1216                  }
1217                }
1218                else
1219                  xmlFree(nc9);
1220                if(strcasecmp(tmp1->name,"uom")==0)
1221                  hasUOM1=true;
1222                hasUOM=true;
1223              }else       
1224                tmp1=tmp1->next;
1225            }
1226        }
1227   
1228        if(datatype!=2){
1229          if(hasUOM==true){
1230            if(vid==0){
1231              xmlAddChild(nc4,nc5);
1232              xmlAddChild(nc3,nc4);
1233            }
1234            else{
1235              xmlAddChild(nc3,nc5);
1236            }
1237          }else{
1238            if(hasUOM1==false && vid==0){
1239              xmlFreeNode(nc5);
1240              if(datatype==1)
1241                xmlFreeNode(nc4);
1242            }
1243            else
1244              xmlAddChild(nc3,nc5);
1245          }
1246        }else{
1247          xmlAddChild(nc3,nc5);
1248        }
1249     
1250        if(datatype!=1 && default1<0){
1251          xmlFreeNode(nc5);
1252          if(datatype!=2)
1253            xmlFreeNode(nc4);
1254        }
1255
1256
1257        if((isInput || vid==1) && datatype==1 &&
1258           getMap(_tmp->content,"AllowedValues")==NULL &&
1259           getMap(_tmp->content,"range")==NULL &&
1260           getMap(_tmp->content,"rangeMin")==NULL &&
1261           getMap(_tmp->content,"rangeMax")==NULL &&
1262           getMap(_tmp->content,"rangeClosure")==NULL ){
1263          tmp1=getMap(_tmp->content,"dataType");
1264          // We were tempted to define default value for boolean as {true,false}
1265          if(tmp1!=NULL && strcasecmp(tmp1->value,"boolean")==0){
1266            nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
1267            nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
1268            xmlAddChild(nc7,xmlNewText(BAD_CAST "true"));
1269            xmlAddChild(nc6,nc7);
1270            nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
1271            xmlAddChild(nc7,xmlNewText(BAD_CAST "false"));
1272            xmlAddChild(nc6,nc7);
1273            if(vid==0)
1274              xmlAddChild(nc3,nc6);
1275            else
1276              xmlAddChild(nc5,nc6);
1277          }
1278          else
1279            if(vid==0)
1280              xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
1281            else
1282              xmlAddChild(nc5,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
1283        }
1284
1285        if(vid==1){
1286          if((tmp1=getMap(_tmp->content,"DataType"))!=NULL){
1287            nc8 = xmlNewNode(ns_ows, BAD_CAST "DataType");
1288            xmlAddChild(nc8,xmlNewText(BAD_CAST tmp1->value));
1289            char tmp[1024];
1290            sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
1291            xmlNewNsProp(nc8,ns_ows,BAD_CAST "reference",BAD_CAST tmp);
1292            if(vid==0)
1293              xmlAddChild(nc3,nc8);
1294            else
1295              xmlAddChild(nc5,nc8);
1296            datatype=1;
1297          }
1298          if(hasUOM==true){
1299            tmp1=getMap(_tmp->content,"uom");
1300            if(tmp1!=NULL){
1301              char *tmp2=zCapitalize(tmp1->name);
1302              nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
1303              free(tmp2);
1304              //xmlNewProp(nc9, BAD_CAST "default", BAD_CAST "true");
1305              xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
1306              xmlAddChild(nc5,nc9);
1307              /*struct iotype * _ltmp=e->supported;
1308                while(_ltmp!=NULL){
1309                tmp1=getMap(_ltmp->content,"uom");
1310                if(tmp1!=NULL){
1311                char *tmp2=zCapitalize(tmp1->name);
1312                nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
1313                free(tmp2);
1314                xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
1315                xmlAddChild(nc5,nc9);
1316                }
1317                _ltmp=_ltmp->next;
1318                }*/
1319           
1320            }
1321          }
1322          if(e->defaults!=NULL && (tmp1=getMap(e->defaults->content,"value"))!=NULL){
1323            nc7 = xmlNewNode(ns_ows, BAD_CAST "DefaultValue");
1324            xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value));
1325            xmlAddChild(nc5,nc7);
1326          }
1327        }
1328
1329        map* metadata=e->metadata;
1330        xmlNodePtr n=NULL;
1331        int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
1332        xmlNsPtr ns_xlink=usedNs[xlinkId];
1333
1334        while(metadata!=NULL){
1335          nc6=xmlNewNode(ns_ows, BAD_CAST "Metadata");
1336          xmlNewNsProp(nc6,ns_xlink,BAD_CAST metadata->name,BAD_CAST metadata->value);
1337          xmlAddChild(nc2,nc6);
1338          metadata=metadata->next;
1339        }
1340
1341      }
1342
1343      _tmp=e->supported;
1344      if(_tmp==NULL && datatype!=1)
1345        _tmp=e->defaults;
1346
1347      int hasSupported=-1;
1348
1349      while(_tmp!=NULL){
1350        if(hasSupported<0){
1351          if(datatype==0){
1352            if(vid==0)
1353              nc4 = xmlNewNode(NULL, BAD_CAST "Supported");
1354            nc5 = xmlNewNode(ns1, BAD_CAST "Format");
1355            if(vid==1){
1356              int oI=0;
1357              for(oI=0;oI<3;oI++)
1358                if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1359                  xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value);
1360                }
1361            }
1362          }
1363          else
1364            if(vid==0)
1365              nc5 = xmlNewNode(NULL, BAD_CAST "Supported");
1366          hasSupported=0;
1367        }else
1368          if(datatype==0){
1369            nc5 = xmlNewNode(ns1, BAD_CAST "Format");
1370            if(vid==1){
1371              int oI=0;
1372              for(oI=0;oI<3;oI++)
1373                if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1374                  xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value);
1375                }
1376            }
1377          }
1378        tmp1=_tmp->content;
1379        int oI=0;
1380        for(oI=0;oI<6;oI++)
1381          if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1382#ifdef DEBUG
1383            printf("DATATYPE SUPPORTED ? %s\n",tmp1->name);
1384#endif
1385            if(strcmp(tmp1->name,"asReference")!=0 && 
1386               strcmp(tmp1->name,"value")!=0 && 
1387               strcmp(tmp1->name,"DataType")!=0 &&
1388               strcasecmp(tmp1->name,"extension")!=0){
1389              if(datatype!=1){
1390                char *tmp2=zCapitalize1(tmp1->name);
1391                nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
1392                free(tmp2);
1393              }
1394              else{
1395                char *tmp2=zCapitalize(tmp1->name);
1396                nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2);
1397                free(tmp2);
1398              }
1399              if(datatype==2){
1400                char *tmpv,*tmps;
1401                tmps=strtok_r(tmp1->value,",",&tmpv);
1402                while(tmps){
1403                  xmlAddChild(nc6,xmlNewText(BAD_CAST tmps));
1404                  tmps=strtok_r(NULL,",",&tmpv);
1405                  if(tmps){
1406                    char *tmp2=zCapitalize1(tmp1->name);
1407                    nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
1408                    free(tmp2);
1409                  }
1410                }
1411              }
1412              else{
1413                xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
1414              }
1415              if(vid==0 || oI>=3){
1416                if(vid==0 || oI!=4)
1417                  xmlAddChild(nc5,nc6);
1418                else
1419                  xmlFree(nc6);
1420              }
1421              else
1422                xmlFree(nc6);
1423            }
1424            tmp1=tmp1->next;
1425          }
1426        if(hasSupported<=0){
1427          if(datatype==0){
1428            if(vid==0){
1429              xmlAddChild(nc4,nc5);
1430              xmlAddChild(nc3,nc4);
1431            }
1432            else{
1433              xmlAddChild(nc3,nc5);
1434            }
1435
1436          }else{
1437            if(datatype!=1)
1438              xmlAddChild(nc3,nc5);
1439          }
1440          hasSupported=1;
1441        }
1442        else
1443          if(datatype==0){
1444            if(vid==0){
1445              xmlAddChild(nc4,nc5);
1446              xmlAddChild(nc3,nc4);
1447            }
1448            else{
1449              xmlAddChild(nc3,nc5);
1450            }
1451          }
1452          else
1453            if(datatype!=1)
1454              xmlAddChild(nc3,nc5);
1455
1456        _tmp=_tmp->next;
1457      }
1458
1459      if(hasSupported==0){
1460        if(datatype==0 && vid!=0)
1461          xmlFreeNode(nc4);
1462        xmlFreeNode(nc5);
1463      }
1464
1465      _tmp=e->defaults;
1466      if(datatype==1 && hasUOM1==true){
1467        if(vid==0){
1468          xmlAddChild(nc4,nc5);
1469          xmlAddChild(nc3,nc4);
1470        }
1471        else{
1472          xmlAddChild(nc3,nc5);
1473        }
1474      }
1475
1476      if(vid==0 && _tmp!=NULL && (tmp1=getMap(_tmp->content,"value"))!=NULL){
1477        nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue");
1478        xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value));
1479        xmlAddChild(nc3,nc7);
1480      }
1481   
1482      xmlAddChild(nc2,nc3);
1483    }
1484   
1485    xmlAddChild(nc1,nc2);
1486   
1487    e=e->next;
1488  }
1489}
1490
1491/**
1492 * Generate a wps:Execute XML document.
1493 *
1494 * @param m the conf maps containing the main.cfg settings
1495 * @param request the map representing the HTTP request
1496 * @param pid the process identifier linked to a service
1497 * @param serv the serv structure created from the zcfg file
1498 * @param service the service name
1499 * @param status the status returned by the service
1500 * @param inputs the inputs provided
1501 * @param outputs the outputs generated by the service
1502 */
1503void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
1504  xmlNsPtr ns,ns_ows,ns_xlink;
1505  xmlNodePtr nr,n,nc,nc1=NULL,nc3;
1506  xmlDocPtr doc;
1507  time_t time1; 
1508  time(&time1);
1509  nr=NULL;
1510
1511  doc = xmlNewDoc(BAD_CAST "1.0");
1512  map* version=getMapFromMaps(m,"main","rversion");
1513  int vid=getVersionId(version->value);
1514  n = printWPSHeader(doc,m,"Execute",root_nodes[vid][2],(version!=NULL?version->value:"1.0.0"),2);
1515  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
1516  ns=usedNs[wpsId];
1517  int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows");
1518  ns_ows=usedNs[owsId];
1519  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
1520  ns_xlink=usedNs[xlinkId];
1521  bool hasStoredExecuteResponse=false;
1522  char stored_path[1024];
1523  memset(stored_path,0,1024);
1524   
1525  if(vid==0){
1526    char tmp[256];
1527    char url[1024];
1528    memset(tmp,0,256);
1529    memset(url,0,1024);
1530    maps* tmp_maps=getMaps(m,"main");
1531    if(tmp_maps!=NULL){
1532      map* tmpm1=getMap(tmp_maps->content,"serverAddress");
1533      /**
1534       * Check if the ZOO Service GetStatus is available in the local directory.
1535       * If yes, then it uses a reference to an URL which the client can access
1536       * to get information on the status of a running Service (using the
1537       * percentCompleted attribute).
1538       * Else fallback to the initial method using the xml file to write in ...
1539       */
1540      char ntmp[1024];
1541#ifndef WIN32
1542      getcwd(ntmp,1024);
1543#else
1544      _getcwd(ntmp,1024);
1545#endif
1546      struct stat myFileInfo;
1547      int statRes;
1548      char file_path[1024];
1549      sprintf(file_path,"%s/GetStatus.zcfg",ntmp);
1550      statRes=stat(file_path,&myFileInfo);
1551      if(statRes==0){
1552        char currentSid[128];
1553        map* tmpm=getMap(tmp_maps->content,"rewriteUrl");
1554        map *tmp_lenv=NULL;
1555        tmp_lenv=getMapFromMaps(m,"lenv","usid");
1556        if(tmp_lenv==NULL)
1557          sprintf(currentSid,"%i",pid);
1558        else
1559          sprintf(currentSid,"%s",tmp_lenv->value);
1560        if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){
1561          sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
1562        }else{
1563          if(strlen(tmpm->value)>0)
1564            if(strcasecmp(tmpm->value,"true")!=0)
1565              sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid);
1566            else
1567              sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid);
1568          else
1569            sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
1570        }
1571      }else{
1572        int lpid;
1573        map* tmpm2=getMapFromMaps(m,"lenv","usid");
1574        map* tmpm3=getMap(tmp_maps->content,"tmpUrl");
1575        if(tmpm1!=NULL && tmpm3!=NULL){
1576          if( strncasecmp( tmpm3->value, "http://", 7) == 0 ||
1577              strncasecmp( tmpm3->value, "https://", 8 ) == 0 ){
1578            sprintf(url,"%s/%s_%s.xml",tmpm3->value,service,tmpm2->value);
1579          }else
1580            sprintf(url,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
1581        }
1582      }
1583      if(tmpm1!=NULL){
1584        sprintf(tmp,"%s",tmpm1->value);
1585      }
1586      int lpid;
1587      map* tmpm2=getMapFromMaps(m,"lenv","usid");
1588      tmpm1=getMapFromMaps(m,"main","TmpPath");
1589      sprintf(stored_path,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
1590    }
1591
1592    xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
1593    map* test=getMap(request,"storeExecuteResponse");
1594    if(test!=NULL && strcasecmp(test->value,"true")==0){
1595      xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
1596      hasStoredExecuteResponse=true;
1597    }
1598
1599    nc = xmlNewNode(ns, BAD_CAST "Process");
1600    map* tmp2=getMap(serv->content,"processVersion");
1601    if(tmp2!=NULL)
1602      xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value);
1603    else
1604      xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST "1");
1605 
1606    map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
1607    printDescription(nc,ns_ows,tmpI->value,serv->content,0);
1608
1609    xmlAddChild(n,nc);
1610
1611    nc = xmlNewNode(ns, BAD_CAST "Status");
1612    const struct tm *tm;
1613    size_t len;
1614    time_t now;
1615    char *tmp1;
1616    map *tmpStatus;
1617 
1618    now = time ( NULL );
1619    tm = localtime ( &now );
1620
1621    tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
1622
1623    len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
1624
1625    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
1626
1627    char sMsg[2048];
1628    switch(status){
1629    case SERVICE_SUCCEEDED:
1630      nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
1631      sprintf(sMsg,_("The service \"%s\" ran successfully."),serv->name);
1632      nc3=xmlNewText(BAD_CAST sMsg);
1633      xmlAddChild(nc1,nc3);
1634      break;
1635    case SERVICE_STARTED:
1636      nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
1637      tmpStatus=getMapFromMaps(m,"lenv","status");
1638      xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value);
1639      sprintf(sMsg,_("The ZOO service \"%s\" is currently running. Please reload this document to get the up-to-date status of the service."),serv->name);
1640      nc3=xmlNewText(BAD_CAST sMsg);
1641      xmlAddChild(nc1,nc3);
1642      break;
1643    case SERVICE_ACCEPTED:
1644      nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted");
1645      sprintf(sMsg,_("The service \"%s\" was accepted by the ZOO-Kernel and is running as a background task. Please access the URL in the statusLocation attribute provided in this document to get the up-to-date status and results."),serv->name);
1646      nc3=xmlNewText(BAD_CAST sMsg);
1647      xmlAddChild(nc1,nc3);
1648      break;
1649    case SERVICE_FAILED:
1650      nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
1651      map *errorMap;
1652      map *te;
1653      te=getMapFromMaps(m,"lenv","code");
1654      if(te!=NULL)
1655        errorMap=createMap("code",te->value);
1656      else
1657        errorMap=createMap("code","NoApplicableCode");
1658      te=getMapFromMaps(m,"lenv","message");
1659      if(te!=NULL)
1660        addToMap(errorMap,"text",_ss(te->value));
1661      else
1662        addToMap(errorMap,"text",_("No more information available"));
1663      nc3=createExceptionReportNode(m,errorMap,0);
1664      freeMap(&errorMap);
1665      free(errorMap);
1666      xmlAddChild(nc1,nc3);
1667      break;
1668    default :
1669      printf(_("error code not know : %i\n"),status);
1670      //exit(1);
1671      break;
1672    }
1673    xmlAddChild(nc,nc1);
1674    xmlAddChild(n,nc);
1675    free(tmp1);
1676
1677#ifdef DEBUG
1678    fprintf(stderr,"printProcessResponse %d\n",__LINE__);
1679#endif
1680
1681    map* lineage=getMap(request,"lineage");
1682    if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){
1683      nc = xmlNewNode(ns, BAD_CAST "DataInputs");
1684      maps* mcursor=inputs;
1685      elements* scursor=NULL;
1686      while(mcursor!=NULL /*&& scursor!=NULL*/){
1687        scursor=getElements(serv->inputs,mcursor->name);
1688        printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input",vid);
1689        mcursor=mcursor->next;
1690      }
1691      xmlAddChild(n,nc);
1692
1693      nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
1694      mcursor=outputs;
1695      scursor=NULL;
1696      while(mcursor!=NULL){
1697        scursor=getElements(serv->outputs,mcursor->name);
1698        printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
1699        mcursor=mcursor->next;
1700      }
1701      xmlAddChild(n,nc);
1702    }
1703  }
1704
1705  /**
1706   * Display the process output only when requested !
1707   */
1708  if(status==SERVICE_SUCCEEDED){
1709    if(vid==0){
1710      nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
1711    }
1712    maps* mcursor=outputs;
1713    elements* scursor=serv->outputs;
1714    map* testResponse=getMap(request,"RawDataOutput");
1715    if(testResponse==NULL)
1716      testResponse=getMap(request,"ResponseDocument");
1717    while(mcursor!=NULL){
1718      map* tmp0=getMap(mcursor->content,"inRequest");
1719      scursor=getElements(serv->outputs,mcursor->name);
1720      if(scursor!=NULL){
1721        if(testResponse==NULL || tmp0==NULL){
1722          if(vid==0)
1723            printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1724          else
1725            printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1726        }
1727        else
1728
1729          if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){
1730            if(vid==0)
1731              printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1732            else
1733              printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1734          }
1735      }else
1736        /**
1737         * In case there was no definition found in the ZCFG file but
1738         * present in the service code
1739         */
1740        if(vid==0)
1741          printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1742        else
1743          printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1744      mcursor=mcursor->next;
1745    }
1746    if(vid==0)
1747      xmlAddChild(n,nc);
1748  }
1749 
1750  if(vid==0 && 
1751     hasStoredExecuteResponse==true 
1752     && status!=SERVICE_STARTED
1753#ifndef WIN32
1754     && status!=SERVICE_ACCEPTED
1755#endif
1756     ){
1757#ifndef RELY_ON_DB
1758    semid lid=acquireLock(m);//,1);
1759    if(lid<0){
1760      /* If the lock failed */
1761      errorException(m,_("Lock failed."),"InternalError",NULL);
1762      xmlFreeDoc(doc);
1763      xmlCleanupParser();
1764      zooXmlCleanupNs();
1765      return;
1766    }
1767    else{
1768#endif
1769      /* We need to write the ExecuteResponse Document somewhere */
1770      FILE* output=fopen(stored_path,"w");
1771      if(output==NULL){
1772        /* If the file cannot be created return an ExceptionReport */
1773        char tmpMsg[1024];
1774        sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path);
1775
1776        errorException(m,tmpMsg,"InternalError",NULL);
1777        xmlFreeDoc(doc);
1778        xmlCleanupParser();
1779        zooXmlCleanupNs();
1780#ifndef RELY_ON_DB
1781        unlockShm(lid);
1782#endif
1783        return;
1784      }
1785      xmlChar *xmlbuff;
1786      int buffersize;
1787      xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1);
1788      fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output);
1789      xmlFree(xmlbuff);
1790      fclose(output);
1791#ifndef RELY_ON_DB
1792#ifdef DEBUG
1793      fprintf(stderr,"UNLOCK %s %d !\n",__FILE__,__LINE__);
1794#endif
1795      unlockShm(lid);
1796      map* v=getMapFromMaps(m,"lenv","sid");
1797      // Remove the lock when running as a normal task
1798      if(getpid()==atoi(v->value)){
1799        removeShmLock (m, 1);
1800      }
1801    }
1802#endif
1803  }
1804  printDocument(m,doc,pid);
1805
1806  xmlCleanupParser();
1807  zooXmlCleanupNs();
1808}
1809
1810/**
1811 * Print a XML document.
1812 *
1813 * @param m the conf maps containing the main.cfg settings
1814 * @param doc the XML document
1815 * @param pid the process identifier linked to a service
1816 */
1817void printDocument(maps* m, xmlDocPtr doc,int pid){
1818  char *encoding=getEncoding(m);
1819  if(pid==getpid()){
1820    printHeaders(m);
1821    printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
1822  }
1823  fflush(stdout);
1824  xmlChar *xmlbuff;
1825  int buffersize;
1826  /*
1827   * Dump the document to a buffer and print it on stdout
1828   * for demonstration purposes.
1829   */
1830  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
1831  printf("%s",xmlbuff);
1832  fflush(stdout);
1833  /*
1834   * Free associated memory.
1835   */
1836  xmlFree(xmlbuff);
1837  xmlFreeDoc(doc);
1838  xmlCleanupParser();
1839  zooXmlCleanupNs();
1840}
1841
1842/**
1843 * Print a XML document.
1844 *
1845 * @param doc the XML document (unused)
1846 * @param nc the XML node to add the output definition
1847 * @param ns_wps the wps XML namespace
1848 * @param ns_ows the ows XML namespace
1849 * @param e the output elements
1850 * @param m the conf maps containing the main.cfg settings
1851 * @param type the type (unused)
1852 */
1853void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){
1854  xmlNodePtr nc1;
1855  nc1=xmlNewNode(ns_wps, BAD_CAST type);
1856  map *tmp=NULL; 
1857  if(e!=NULL && e->defaults!=NULL)
1858    tmp=e->defaults->content;
1859  else{
1860    /*
1861    dumpElements(e);
1862    */
1863    return;
1864  }
1865  while(tmp!=NULL){
1866    if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0
1867       || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0
1868       || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0
1869       || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0)
1870    xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
1871    tmp=tmp->next;
1872  }
1873  tmp=getMap(e->defaults->content,"asReference");
1874  if(tmp==NULL)
1875    xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false");
1876
1877  tmp=e->content;
1878
1879  printDescription(nc1,ns_ows,m->name,e->content,0);
1880
1881  xmlAddChild(nc,nc1);
1882
1883}
1884
1885/**
1886 * Generate XML nodes describing inputs or outputs metadata.
1887 *
1888 * @param doc the XML document
1889 * @param nc the XML node to add the definition
1890 * @param ns_wps the wps namespace
1891 * @param ns_ows the ows namespace
1892 * @param ns_xlink the xlink namespace
1893 * @param e the output elements
1894 * @param m the conf maps containing the main.cfg settings
1895 * @param type the type
1896 */
1897void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){
1898
1899  xmlNodePtr nc1,nc2,nc3;
1900  nc1=xmlNewNode(ns_wps, BAD_CAST type);
1901  map *tmp=NULL;
1902  if(e!=NULL)
1903    tmp=e->content;
1904  else
1905    tmp=m->content;
1906
1907  if(vid==0){
1908    nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
1909    if(e!=NULL)
1910      nc3=xmlNewText(BAD_CAST e->name);
1911    else
1912      nc3=xmlNewText(BAD_CAST m->name);
1913   
1914    xmlAddChild(nc2,nc3);
1915    xmlAddChild(nc1,nc2);
1916 
1917    xmlAddChild(nc,nc1);
1918
1919    if(e!=NULL)
1920      tmp=getMap(e->content,"Title");
1921    else
1922      tmp=getMap(m->content,"Title");
1923   
1924    if(tmp!=NULL){
1925      nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
1926      nc3=xmlNewText(BAD_CAST _ss(tmp->value));
1927      xmlAddChild(nc2,nc3); 
1928      xmlAddChild(nc1,nc2);
1929    }
1930
1931    if(e!=NULL)
1932      tmp=getMap(e->content,"Abstract");
1933    else
1934      tmp=getMap(m->content,"Abstract");
1935
1936    if(tmp!=NULL){
1937      nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
1938      nc3=xmlNewText(BAD_CAST _ss(tmp->value));
1939      xmlAddChild(nc2,nc3); 
1940      xmlAddChild(nc1,nc2);
1941      xmlAddChild(nc,nc1);
1942    }
1943  }else{
1944    xmlNewProp(nc1,BAD_CAST "id",BAD_CAST (e!=NULL?e->name:m->name));
1945  }
1946
1947  /**
1948   * IO type Reference or full Data ?
1949   */
1950  map *tmpMap=getMap(m->content,"Reference");
1951  if(tmpMap==NULL){
1952    nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
1953    if(e!=NULL){
1954      if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
1955        nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
1956      else
1957        if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
1958          nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
1959        else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)
1960          nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
1961        else
1962          nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
1963    }
1964    else {
1965      map* tmpV=getMapFromMaps(m,"format","value");
1966      if(tmpV!=NULL)
1967        nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
1968      else
1969        nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
1970    } 
1971    tmp=m->content;
1972
1973    while(tmp!=NULL){
1974      if(strcasecmp(tmp->name,"mimeType")==0 ||
1975         strcasecmp(tmp->name,"encoding")==0 ||
1976         strcasecmp(tmp->name,"schema")==0 ||
1977         strcasecmp(tmp->name,"datatype")==0 ||
1978         strcasecmp(tmp->name,"uom")==0) {
1979       
1980        if(vid==0)
1981          xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
1982        else{
1983          if(strcasecmp(tmp->name,"datatype")==0)
1984            xmlNewProp(nc2,BAD_CAST "mimeType",BAD_CAST "text/plain");
1985          else
1986            if(strcasecmp(tmp->name,"uom")!=0)
1987              xmlNewProp(nc2,BAD_CAST tmp->name,BAD_CAST tmp->value);
1988        }
1989      }
1990      if(vid==0)
1991        xmlAddChild(nc2,nc3);
1992      tmp=tmp->next;
1993    }
1994    if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {
1995      map* bb=getMap(m->content,"value");
1996      if(bb!=NULL) {
1997        map* tmpRes=parseBoundingBox(bb->value);
1998        printBoundingBox(ns_ows,nc3,tmpRes);
1999        freeMap(&tmpRes);
2000        free(tmpRes);
2001      }
2002    }
2003    else {
2004      if(e!=NULL)
2005        tmp=getMap(e->defaults->content,"mimeType");
2006      else
2007        tmp=NULL;
2008       
2009      map* tmp1=getMap(m->content,"encoding");
2010      map* tmp2=getMap(m->content,"mimeType");
2011      map* tmp3=getMap(m->content,"value");
2012      int hasValue=1;
2013      if(tmp3==NULL){
2014        tmp3=createMap("value","");
2015        hasValue=-1;
2016      }
2017
2018      if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 )     // if encoding is base64
2019          ||                                                           // or if
2020          ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL       //  mime type is not text
2021                              &&                                       //  nor
2022                              strstr(tmp2->value,"xml") == NULL        //  xml
2023                              &&                                       // nor
2024                              strstr(tmp2->value,"javascript") == NULL // javascript
2025                              &&
2026                              strstr(tmp2->value,"json") == NULL
2027                              &&
2028                              strstr(tmp2->value,"ecmascript") == NULL
2029                              &&
2030                              // include for backwards compatibility,
2031                              // although correct mime type is ...kml+xml:
2032                              strstr(tmp2->value,"google-earth.kml") == NULL                                                    )
2033            )
2034          ) {                                                    // then       
2035        map* rs=getMap(m->content,"size");                       // obtain size
2036        bool isSized=true;
2037        if(rs==NULL){
2038          char tmp1[1024];
2039          sprintf(tmp1,"%ld",strlen(tmp3->value));
2040          rs=createMap("size",tmp1);
2041          isSized=false;
2042        }
2043         
2044        xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));  // base 64 encode in XML
2045               
2046        if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) {
2047          xmlAttrPtr ap = xmlHasProp((vid==0?nc3:nc2), BAD_CAST "encoding");
2048          if (ap != NULL) {
2049            xmlRemoveProp(ap);
2050          }                     
2051          xmlNewProp((vid==0?nc3:nc2),BAD_CAST "encoding",BAD_CAST "base64");
2052        }
2053               
2054        if(!isSized){
2055          freeMap(&rs);
2056          free(rs);
2057        }
2058      }
2059      else if (tmp2!=NULL) {                                 // else (text-based format)
2060        if(strstr(tmp2->value, "javascript") != NULL ||      //    if javascript put code in CDATA block
2061           strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader)
2062           strstr(tmp2->value, "ecmascript") != NULL
2063           ) {
2064          xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
2065        }   
2066        else {                                                     // else
2067          if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
2068              // include for backwards compatibility,
2069              // although correct mime type is ...kml+xml:                 
2070              strstr(tmp2->value, "google-earth.kml") != NULL
2071              ) { 
2072                         
2073            int li=zooXmlAddDoc(tmp3->value);
2074            xmlDocPtr doc = iDocs[li];
2075            xmlNodePtr ir = xmlDocGetRootElement(doc);
2076            xmlAddChild((vid==0?nc3:nc2),ir);
2077          }
2078          else                                                     // else     
2079            xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));    //   add text node
2080        }
2081        xmlAddChild(nc2,nc3);
2082      }
2083      else {
2084        xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));
2085      }
2086         
2087      if(hasValue<0) {
2088        freeMap(&tmp3);
2089        free(tmp3);
2090      }
2091    }
2092  }
2093  else { // Reference
2094    tmpMap=getMap(m->content,"Reference");
2095    nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference");
2096    if(strcasecmp(type,"Output")==0)
2097      xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value);
2098    else
2099      xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value);
2100   
2101    tmp=m->content;
2102    while(tmp!=NULL) {
2103      if(strcasecmp(tmp->name,"mimeType")==0 ||
2104         strcasecmp(tmp->name,"encoding")==0 ||
2105         strcasecmp(tmp->name,"schema")==0 ||
2106         strcasecmp(tmp->name,"datatype")==0 ||
2107         strcasecmp(tmp->name,"uom")==0){
2108
2109        if(strcasecmp(tmp->name,"datatype")==0)
2110          xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
2111        else
2112          xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
2113      }
2114      tmp=tmp->next;
2115      xmlAddChild(nc2,nc3);
2116    }
2117  }
2118  xmlAddChild(nc1,nc2);
2119  xmlAddChild(nc,nc1);
2120}
2121
2122/**
2123 * Create XML node with basic ows metadata informations (Identifier,Title,Abstract)
2124 *
2125 * @param root the root XML node to add the description
2126 * @param ns_ows the ows XML namespace
2127 * @param identifier the identifier to use
2128 * @param amap the map containing the ows metadata informations
2129 */
2130void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap,int vid=0){
2131  xmlNodePtr nc2;
2132  if(vid==0){
2133    nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
2134    xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
2135    xmlAddChild(root,nc2);
2136  }
2137  map* tmp=amap;
2138  const char *tmp2[2];
2139  tmp2[0]="Title";
2140  tmp2[1]="Abstract";
2141  int j=0;
2142  for(j=0;j<2;j++){
2143    map* tmp1=getMap(tmp,tmp2[j]);
2144    if(tmp1!=NULL){
2145      nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]);
2146      xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value)));
2147      xmlAddChild(root,nc2);
2148    }
2149  }
2150  if(vid==1){
2151    nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
2152    xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
2153    xmlAddChild(root,nc2);
2154  }
2155}
2156
2157/**
2158 * Print an OWS ExceptionReport Document and HTTP headers (when required)
2159 * depending on the code.
2160 * Set hasPrinted value to true in the [lenv] section.
2161 *
2162 * @param m the maps containing the settings of the main.cfg file
2163 * @param s the map containing the text,code,locator keys
2164 */
2165void printExceptionReportResponse(maps* m,map* s){
2166  if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
2167    return;
2168  int buffersize;
2169  xmlDocPtr doc;
2170  xmlChar *xmlbuff;
2171  xmlNodePtr n;
2172
2173  zooXmlCleanupNs();
2174  doc = xmlNewDoc(BAD_CAST "1.0");
2175  maps* tmpMap=getMaps(m,"main");
2176  char *encoding=getEncoding(tmpMap);
2177  const char *exceptionCode;
2178 
2179  map* tmp=getMap(s,"code");
2180  if(tmp!=NULL){
2181    if(strcmp(tmp->value,"OperationNotSupported")==0 ||
2182       strcmp(tmp->value,"NoApplicableCode")==0)
2183      exceptionCode="501 Not Implemented";
2184    else
2185      if(strcmp(tmp->value,"MissingParameterValue")==0 ||
2186         strcmp(tmp->value,"InvalidUpdateSequence")==0 ||
2187         strcmp(tmp->value,"OptionNotSupported")==0 ||
2188         strcmp(tmp->value,"VersionNegotiationFailed")==0 ||
2189         strcmp(tmp->value,"InvalidParameterValue")==0)
2190        exceptionCode="400 Bad request";
2191      else
2192        exceptionCode="501 Internal Server Error";
2193  }
2194  else
2195    exceptionCode="501 Internal Server Error";
2196
2197  if(m!=NULL){
2198    map *tmpSid=getMapFromMaps(m,"lenv","sid");
2199    if(tmpSid!=NULL){
2200      if( getpid()==atoi(tmpSid->value) ){
2201        printHeaders(m);
2202        printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2203      }
2204    }
2205    else{
2206      printHeaders(m);
2207      printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2208    }
2209  }else{
2210    printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2211  }
2212  n=createExceptionReportNode(m,s,1);
2213  xmlDocSetRootElement(doc, n);
2214  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2215  printf("%s",xmlbuff);
2216  fflush(stdout);
2217  xmlFreeDoc(doc);
2218  xmlFree(xmlbuff);
2219  xmlCleanupParser();
2220  zooXmlCleanupNs();
2221  if(m!=NULL)
2222    setMapInMaps(m,"lenv","hasPrinted","true");
2223}
2224
2225/**
2226 * Create an OWS ExceptionReport Node.
2227 *
2228 * @param m the conf maps
2229 * @param s the map containing the text,code,locator keys
2230 * @param use_ns (0/1) choose if you want to generate an ExceptionReport or
2231 *  ows:ExceptionReport node respectively
2232 * @return the ExceptionReport/ows:ExceptionReport node
2233 */
2234xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){
2235 
2236  xmlNsPtr ns,ns_xsi;
2237  xmlNodePtr n,nc,nc1;
2238
2239  int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows");
2240  ns=usedNs[nsid];
2241  if(use_ns==0){
2242    ns=NULL;
2243  }
2244  n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
2245  map* version=getMapFromMaps(m,"main","rversion");
2246  int vid=getVersionId(version->value);
2247  if(vid<0)
2248    vid=0;
2249  if(use_ns==1){
2250    xmlNewNs(n,BAD_CAST schemas[vid][1],BAD_CAST"ows");
2251    int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
2252    ns_xsi=usedNs[xsiId];
2253    char tmp[1024];
2254    sprintf(tmp,"%s %s",schemas[vid][1],schemas[vid][5]);
2255    xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp);
2256  }
2257
2258
2259  addLangAttr(n,m);
2260  xmlNewProp(n,BAD_CAST "version",BAD_CAST schemas[vid][6]);
2261 
2262  int length=1;
2263  int cnt=0;
2264  map* len=getMap(s,"length");
2265  if(len!=NULL)
2266    length=atoi(len->value);
2267  for(cnt=0;cnt<length;cnt++){
2268    nc = xmlNewNode(ns, BAD_CAST "Exception");
2269   
2270    map* tmp=getMapArray(s,"code",cnt);
2271    if(tmp==NULL)
2272      tmp=getMap(s,"code");
2273    if(tmp!=NULL)
2274      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value);
2275    else
2276      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode");
2277   
2278    tmp=getMapArray(s,"locator",cnt);
2279    if(tmp==NULL)
2280      tmp=getMap(s,"locator");
2281    if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0)
2282      xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value);
2283
2284    tmp=getMapArray(s,"text",cnt);
2285    nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
2286    if(tmp!=NULL){
2287      xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
2288      xmlAddChild(nc1,txt);
2289    }
2290    else{
2291      xmlNodeSetContent(nc1, BAD_CAST _("No debug message available"));
2292    }
2293    xmlAddChild(nc,nc1);
2294    xmlAddChild(n,nc);
2295  }
2296  return n;
2297}
2298
2299/**
2300 * Print an OWS ExceptionReport.
2301 *
2302 * @param m the conf maps
2303 * @param message the error message
2304 * @param errorcode the error code
2305 * @param locator the potential locator
2306 */
2307int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 
2308{
2309  map* errormap = createMap("text", message);
2310  addToMap(errormap,"code", errorcode);
2311  if(locator!=NULL)
2312    addToMap(errormap,"locator", locator);
2313  else
2314    addToMap(errormap,"locator", "NULL");
2315  printExceptionReportResponse(m,errormap);
2316  freeMap(&errormap);
2317  free(errormap);
2318  return -1;
2319}
2320
2321/**
2322 * Generate the output response (RawDataOutput or ResponseDocument)
2323 *
2324 * @param s the service structure containing the metadata informations
2325 * @param request_inputs the inputs provided to the service for execution
2326 * @param request_outputs the outputs updated by the service execution
2327 * @param request_inputs1 the map containing the HTTP request
2328 * @param cpid the process identifier attached to a service execution
2329 * @param m the conf maps containing the main.cfg settings
2330 * @param res the value returned by the service execution
2331 */
2332void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
2333                    map* request_inputs1,int cpid,maps* m,int res){
2334#ifdef DEBUG
2335  dumpMaps(request_inputs);
2336  dumpMaps(request_outputs);
2337  fprintf(stderr,"printProcessResponse\n");
2338#endif
2339  map* toto=getMap(request_inputs1,"RawDataOutput");
2340  int asRaw=0;
2341  if(toto!=NULL)
2342    asRaw=1;
2343  map* version=getMapFromMaps(m,"main","rversion");
2344  int vid=getVersionId(version->value);
2345
2346  maps* tmpSess=getMaps(m,"senv");
2347  if(tmpSess!=NULL){
2348    map *_tmp=getMapFromMaps(m,"lenv","cookie");
2349    char* sessId=NULL;
2350    if(_tmp!=NULL){
2351      printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
2352      printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
2353      char session_file_path[100];
2354      char *tmp1=strtok(_tmp->value,";");
2355      if(tmp1!=NULL)
2356        sprintf(session_file_path,"%s",strstr(tmp1,"=")+1);
2357      else
2358        sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1);
2359      sessId=strdup(session_file_path);
2360    }else{
2361      maps* t=getMaps(m,"senv");
2362      map*p=t->content;
2363      while(p!=NULL){
2364        if(strstr(p->name,"ID")!=NULL){
2365          sessId=strdup(p->value);
2366          break;
2367        }
2368        p=p->next;
2369      }
2370    }
2371    char session_file_path[1024];
2372    map *tmpPath=getMapFromMaps(m,"main","sessPath");
2373    if(tmpPath==NULL)
2374      tmpPath=getMapFromMaps(m,"main","tmpPath");
2375    sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId);
2376    FILE* teste=fopen(session_file_path,"w");
2377    if(teste==NULL){
2378      char tmpMsg[1024];
2379      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
2380      errorException(m,tmpMsg,"InternalError",NULL);
2381
2382      return;
2383    }
2384    else{
2385      fclose(teste);
2386      dumpMapsToFile(tmpSess,session_file_path,1);
2387    }
2388  }
2389 
2390  if(res==SERVICE_FAILED){
2391    map *lenv;
2392    lenv=getMapFromMaps(m,"lenv","message");
2393    char *tmp0;
2394    if(lenv!=NULL){
2395      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));
2396      sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value);
2397    }
2398    else{
2399      tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char));
2400      sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service."));
2401    }
2402    errorException(m,tmp0,"InternalError",NULL);
2403    free(tmp0);
2404    return;
2405  }
2406
2407  if(res==SERVICE_ACCEPTED && vid==1){
2408    map* statusInfo=createMap("Status","Accepted");
2409    map *usid=getMapFromMaps(m,"lenv","usid");
2410    addToMap(statusInfo,"JobID",usid->value);
2411    printStatusInfo(m,statusInfo,"Execute");
2412    freeMap(&statusInfo);
2413    free(statusInfo);
2414    return;
2415  }
2416
2417  map *tmp1=getMapFromMaps(m,"main","tmpPath");
2418  if(asRaw==0){
2419#ifdef DEBUG
2420    fprintf(stderr,"REQUEST_OUTPUTS FINAL\n");
2421    dumpMaps(request_outputs);
2422#endif
2423    maps* tmpI=request_outputs;
2424    map* usid=getMapFromMaps(m,"lenv","usid");
2425    int itn=0;
2426    while(tmpI!=NULL){
2427#ifdef USE_MS
2428      map* testMap=getMap(tmpI->content,"useMapserver");       
2429#endif
2430      map *gfile=getMap(tmpI->content,"generated_file");
2431      char *file_name;
2432      if(gfile!=NULL){
2433        gfile=getMap(tmpI->content,"expected_generated_file");
2434        if(gfile==NULL){
2435          gfile=getMap(tmpI->content,"generated_file");
2436        }
2437        readGeneratedFile(m,tmpI->content,gfile->value);           
2438        file_name=(char*)malloc((strlen(gfile->value)+strlen(tmp1->value)+1)*sizeof(char));
2439        for(int i=0;i<strlen(gfile->value);i++)
2440          file_name[i]=gfile->value[i+strlen(tmp1->value)];
2441      }
2442
2443      toto=getMap(tmpI->content,"asReference");
2444#ifdef USE_MS
2445      if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL)
2446#else
2447      if(toto!=NULL && strcasecmp(toto->value,"true")==0)
2448#endif
2449        {
2450          elements* in=getElements(s->outputs,tmpI->name);
2451          char *format=NULL;
2452          if(in!=NULL && in->format!=NULL){
2453            format=zStrdup(in->format);
2454          }else
2455            format=zStrdup("LiteralData");
2456          if(strcasecmp(format,"BoundingBoxData")==0){
2457            addToMap(tmpI->content,"extension","xml");
2458            addToMap(tmpI->content,"mimeType","text/xml");
2459            addToMap(tmpI->content,"encoding","UTF-8");
2460            addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
2461          }
2462
2463          if(gfile==NULL) {
2464            map *ext=getMap(tmpI->content,"extension");
2465            char *file_path;
2466            char file_ext[32];
2467
2468            if( ext != NULL && ext->value != NULL) {
2469              strncpy(file_ext, ext->value, 32);
2470            }
2471            else {
2472              // Obtain default file extension (see mimetypes.h).             
2473              // If the MIME type is not recognized, txt is used as the default extension
2474              map* mtype=getMap(tmpI->content,"mimeType");
2475              getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
2476            }
2477
2478            file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
2479            sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
2480            itn++;
2481            file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
2482            sprintf(file_path,"%s/%s",tmp1->value,file_name);
2483
2484            FILE *ofile=fopen(file_path,"wb");
2485            if(ofile==NULL){
2486              char tmpMsg[1024];
2487              sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
2488              errorException(m,tmpMsg,"InternalError",NULL);
2489              free(file_name);
2490              free(file_path);
2491              return;
2492            }
2493            free(file_path);
2494
2495            toto=getMap(tmpI->content,"value");
2496            if(strcasecmp(format,"BoundingBoxData")!=0){
2497              map* size=getMap(tmpI->content,"size");
2498              if(size!=NULL && toto!=NULL)
2499                fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
2500              else
2501                if(toto!=NULL && toto->value!=NULL)
2502                  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
2503            }else{
2504              printBoundingBoxDocument(m,tmpI,ofile);
2505            }
2506            fclose(ofile);
2507
2508          }
2509
2510          map *tmp2=getMapFromMaps(m,"main","tmpUrl");
2511          map *tmp3=getMapFromMaps(m,"main","serverAddress");
2512          char *file_url;
2513          if(strncasecmp(tmp2->value,"http://",7)==0 ||
2514             strncasecmp(tmp2->value,"https://",8)==0){
2515            file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
2516            sprintf(file_url,"%s/%s",tmp2->value,file_name);
2517          }else{
2518            file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
2519            sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
2520          }
2521
2522          addToMap(tmpI->content,"Reference",file_url);
2523          free(format);
2524          free(file_name);
2525          free(file_url);
2526         
2527        }
2528#ifdef USE_MS
2529      else{
2530        if(testMap!=NULL){
2531          setReferenceUrl(m,tmpI);
2532        }
2533      }
2534#endif
2535      tmpI=tmpI->next;
2536    }
2537#ifdef DEBUG
2538    fprintf(stderr,"SERVICE : %s\n",s->name);
2539    dumpMaps(m);
2540#endif
2541    printProcessResponse(m,request_inputs1,cpid,
2542                         s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
2543                         request_inputs,
2544                         request_outputs);
2545  }
2546  else{
2547    /**
2548     * We get the requested output or fallback to the first one if the
2549     * requested one is not present in the resulting outputs maps.
2550     */
2551    maps* tmpI=NULL;
2552    map* tmpIV=getMap(request_inputs1,"RawDataOutput");
2553    if(tmpIV!=NULL){
2554      tmpI=getMaps(request_outputs,tmpIV->value);
2555    }
2556    if(tmpI==NULL)
2557      tmpI=request_outputs;
2558    elements* e=getElements(s->outputs,tmpI->name);
2559    if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
2560      printBoundingBoxDocument(m,tmpI,NULL);
2561    }else{
2562      map *gfile=getMap(tmpI->content,"generated_file");
2563      if(gfile!=NULL){
2564        gfile=getMap(tmpI->content,"expected_generated_file");
2565        if(gfile==NULL){
2566          gfile=getMap(tmpI->content,"generated_file");
2567        }
2568        readGeneratedFile(m,tmpI->content,gfile->value);
2569      }
2570      toto=getMap(tmpI->content,"value");
2571      if(toto==NULL){
2572        char tmpMsg[1024];
2573        sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name);
2574        errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
2575        return;
2576      }
2577      map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
2578      if(fname!=NULL)
2579        printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
2580      map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
2581      if(rs!=NULL)
2582        printf("Content-Length: %s\r\n",rs->value);
2583      printHeaders(m);
2584      char mime[1024];
2585      map* mi=getMap(tmpI->content,"mimeType");
2586#ifdef DEBUG
2587      fprintf(stderr,"SERVICE OUTPUTS\n");
2588      dumpMaps(request_outputs);
2589      fprintf(stderr,"SERVICE OUTPUTS\n");
2590#endif
2591      map* en=getMap(tmpI->content,"encoding");
2592      if(mi!=NULL && en!=NULL)
2593        sprintf(mime,
2594                "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
2595                mi->value,en->value);
2596      else
2597        if(mi!=NULL)
2598          sprintf(mime,
2599                  "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
2600                  mi->value);
2601        else
2602          sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
2603      printf("%s",mime);
2604      if(rs!=NULL)
2605        fwrite(toto->value,1,atoi(rs->value),stdout);
2606      else
2607        fwrite(toto->value,1,strlen(toto->value),stdout);
2608#ifdef DEBUG
2609      dumpMap(toto);
2610#endif
2611    }
2612  }
2613}
2614
2615/**
2616 * Create required XML nodes for boundingbox and update the current XML node
2617 *
2618 * @param ns_ows the ows XML namespace
2619 * @param n the XML node to update
2620 * @param boundingbox the map containing the boundingbox definition
2621 */
2622void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){
2623
2624  xmlNodePtr lw=NULL,uc=NULL;
2625
2626  map* tmp=getMap(boundingbox,"value");
2627
2628  tmp=getMap(boundingbox,"lowerCorner");
2629  if(tmp!=NULL){
2630    lw=xmlNewNode(ns_ows,BAD_CAST "LowerCorner");
2631    xmlAddChild(lw,xmlNewText(BAD_CAST tmp->value));
2632  }
2633
2634  tmp=getMap(boundingbox,"upperCorner");
2635  if(tmp!=NULL){
2636    uc=xmlNewNode(ns_ows,BAD_CAST "UpperCorner");
2637    xmlAddChild(uc,xmlNewText(BAD_CAST tmp->value));
2638  }
2639
2640  tmp=getMap(boundingbox,"crs");
2641  if(tmp!=NULL)
2642    xmlNewProp(n,BAD_CAST "crs",BAD_CAST tmp->value);
2643
2644  tmp=getMap(boundingbox,"dimensions");
2645  if(tmp!=NULL)
2646    xmlNewProp(n,BAD_CAST "dimensions",BAD_CAST tmp->value);
2647
2648  xmlAddChild(n,lw);
2649  xmlAddChild(n,uc);
2650
2651}
2652
2653/**
2654 * Parse a BoundingBox string
2655 *
2656 * [OGC 06-121r3](http://portal.opengeospatial.org/files/?artifact_id=20040):
2657 *  10.2 Bounding box
2658 *
2659 *
2660 * Value is provided as : lowerCorner,upperCorner,crs,dimension
2661 * Exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84
2662 *
2663 * A map to store boundingbox informations should contain:
2664 *  - lowerCorner : double,double (minimum within this bounding box)
2665 *  - upperCorner : double,double (maximum within this bounding box)
2666 *  - crs : URI (Reference to definition of the CRS)
2667 *  - dimensions : int
2668 *
2669 * Note : support only 2D bounding box.
2670 *
2671 * @param value the char* containing the KVP bouding box
2672 * @return a map containing all the bounding box keys
2673 */
2674map* parseBoundingBox(const char* value){
2675  map *res=NULL;
2676  if(value!=NULL){
2677    char *cv,*cvp;
2678    cv=strtok_r((char*) value,",",&cvp);
2679    int cnt=0;
2680    int icnt=0;
2681    char *currentValue=NULL;
2682    while(cv){
2683      if(cnt<2)
2684        if(currentValue!=NULL){
2685          char *finalValue=(char*)malloc((strlen(currentValue)+strlen(cv)+1)*sizeof(char));
2686          sprintf(finalValue,"%s%s",currentValue,cv);
2687          switch(cnt){
2688          case 0:
2689            res=createMap("lowerCorner",finalValue);
2690            break;
2691          case 1:
2692            addToMap(res,"upperCorner",finalValue);
2693            icnt=-1;
2694            break;
2695          }
2696          cnt++;
2697          free(currentValue);
2698          currentValue=NULL;
2699          free(finalValue);
2700        }
2701        else{
2702          currentValue=(char*)malloc((strlen(cv)+2)*sizeof(char));
2703          sprintf(currentValue,"%s ",cv);
2704        }
2705      else
2706        if(cnt==2){
2707          addToMap(res,"crs",cv);
2708          cnt++;
2709        }
2710        else
2711          addToMap(res,"dimensions",cv);
2712      icnt++;
2713      cv=strtok_r(NULL,",",&cvp);
2714    }
2715  }
2716  return res;
2717}
2718
2719/**
2720 * Print an ows:BoundingBox XML document
2721 *
2722 * @param m the maps containing the settings of the main.cfg file
2723 * @param boundingbox the maps containing the boundingbox definition
2724 * @param file the file to print the BoundingBox (if NULL then print on stdout)
2725 * @see parseBoundingBox, printBoundingBox
2726 */
2727void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){
2728  if(file==NULL)
2729    rewind(stdout);
2730  xmlNodePtr n;
2731  xmlDocPtr doc;
2732  xmlNsPtr ns_ows,ns_xsi;
2733  xmlChar *xmlbuff;
2734  int buffersize;
2735  char *encoding=getEncoding(m);
2736  map *tmp;
2737  if(file==NULL){
2738    int pid=0;
2739    tmp=getMapFromMaps(m,"lenv","sid");
2740    if(tmp!=NULL)
2741      pid=atoi(tmp->value);
2742    if(pid==getpid()){
2743      printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
2744    }
2745    fflush(stdout);
2746  }
2747
2748  doc = xmlNewDoc(BAD_CAST "1.0");
2749  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
2750  ns_ows=usedNs[owsId];
2751  n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox");
2752  xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
2753  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
2754  ns_xsi=usedNs[xsiId];
2755  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
2756  map *tmp1=getMap(boundingbox->content,"value");
2757  tmp=parseBoundingBox(tmp1->value);
2758  printBoundingBox(ns_ows,n,tmp);
2759  xmlDocSetRootElement(doc, n);
2760
2761  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2762  if(file==NULL)
2763    printf("%s",xmlbuff);
2764  else{
2765    fprintf(file,"%s",xmlbuff);
2766  }
2767
2768  if(tmp!=NULL){
2769    freeMap(&tmp);
2770    free(tmp);
2771  }
2772  xmlFree(xmlbuff);
2773  xmlFreeDoc(doc);
2774  xmlCleanupParser();
2775  zooXmlCleanupNs();
2776 
2777}
2778
2779/**
2780 * Print a StatusInfo XML document.
2781 * a statusInfo map should contain the following keys:
2782 *  * JobID corresponding to usid key from the lenv section
2783 *  * Status the current state (Succeeded,Failed,Accepted,Running)
2784 *  * PercentCompleted (optional) the percent completed
2785 *  * Message (optional) any messages the service may wish to share
2786 *
2787 * @param conf the maps containing the settings of the main.cfg file
2788 * @param statusInfo the map containing the statusInfo definition
2789 * @param req the WPS requests (GetResult, GetStatus or Dismiss)
2790 */
2791void printStatusInfo(maps* conf,map* statusInfo,char* req){
2792  rewind(stdout);
2793  xmlNodePtr n,n1;
2794  xmlDocPtr doc;
2795  xmlNsPtr ns;
2796  xmlChar *xmlbuff;
2797  int buffersize;
2798  char *encoding=getEncoding(conf);
2799  map *tmp;
2800  int pid=0;
2801  printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
2802
2803  map* version=getMapFromMaps(conf,"main","rversion");
2804  int vid=getVersionId(version->value);
2805
2806  doc = xmlNewDoc(BAD_CAST "1.0");
2807  n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1);
2808
2809  map* val=getMap(statusInfo,"JobID");
2810  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
2811  ns=usedNs[wpsId];
2812  n = xmlNewNode(ns, BAD_CAST "JobID");
2813  xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2814
2815  xmlAddChild(n1,n);
2816
2817  val=getMap(statusInfo,"Status");
2818  n = xmlNewNode(ns, BAD_CAST "Status");
2819  xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2820
2821  xmlAddChild(n1,n);
2822
2823  if(strncasecmp(val->value,"Failed",6)!=0 &&
2824     strncasecmp(val->value,"Succeeded",9)!=0){
2825    val=getMap(statusInfo,"PercentCompleted");
2826    if(val!=NULL){
2827      n = xmlNewNode(ns, BAD_CAST "PercentCompleted");
2828      xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2829      xmlAddChild(n1,n);
2830    }
2831
2832    val=getMap(statusInfo,"Message");
2833    if(val!=NULL){   
2834      xmlAddChild(n1,xmlNewComment(BAD_CAST val->value));
2835    }
2836  }
2837  xmlDocSetRootElement(doc, n1);
2838
2839  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2840  printf("%s",xmlbuff);
2841
2842  xmlFree(xmlbuff);
2843  xmlFreeDoc(doc);
2844  xmlCleanupParser();
2845  zooXmlCleanupNs();
2846 
2847}
2848
Note: See TracBrowser for help on using the repository browser.

Search

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