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

Last change on this file since 756 was 756, checked in by djay, 8 years ago

Remove prefix for storeSupported and statusSupported for 1.0.0. Fix isValidLang function. Fix error code to MissingParameterValue? or any other relevant code.

  • Property svn:keywords set to Id
File size: 83.0 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=7;
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        if(vid==0 && i>=2)
724          xmlNewProp(n,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value);
725        else
726          xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value);
727      }
728    }
729    else{
730      if(vid==0 && i>=2)
731        xmlNewProp(n,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
732      else
733        xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);
734    }
735  }
736}
737
738/**
739 * Add the ows:Metadata nodes relative to the profile registry
740 *
741 * @param n the XML node to add the ows:Metadata
742 * @param ns_ows the ows XML namespace
743 * @param ns_xlink the ows xlink namespace
744 * @param reg the profile registry
745 * @param main_conf the map containing the main configuration content
746 * @param serv the service
747 */
748void addInheritedMetadata(xmlNodePtr n,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,registry* reg,maps* main_conf,service* serv){
749  int vid=1;
750  map* tmp1=getMap(serv->content,"extend");
751  if(tmp1==NULL)
752    tmp1=getMap(serv->content,"concept");
753  if(tmp1!=NULL){
754    map* level=getMap(serv->content,"level");
755    if(level!=NULL){
756      xmlNodePtr nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
757      char* ckey=level->value;
758      if(strncasecmp(level->value,"profile",7)==0)
759        ckey="generic";
760      if(strncasecmp(level->value,"generic",7)==0)
761        ckey="concept";
762      service* inherited=getServiceFromRegistry(reg,ckey,tmp1->value);
763      if(inherited!=NULL){
764        addInheritedMetadata(n,ns_ows,ns_xlink,reg,main_conf,inherited);
765      }
766      char cschema[71];
767      sprintf(cschema,"%s%s",schemas[vid][7],ckey);
768      map* regUrl=getMapFromMaps(main_conf,"main","registryUrl");
769      map* regExt=getMapFromMaps(main_conf,"main","registryExt");
770      char* registryUrl=(char*)malloc((strlen(regUrl->value)+strlen(ckey)+
771                                       (regExt!=NULL?strlen(regExt->value)+1:0)+
772                                       strlen(tmp1->value)+2)*sizeof(char));
773      if(regExt!=NULL)
774        sprintf(registryUrl,"%s%s/%s.%s",regUrl->value,ckey,tmp1->value,regExt->value);
775      else
776        sprintf(registryUrl,"%s%s/%s",regUrl->value,ckey,tmp1->value);
777      xmlNewNsProp(nc1,ns_xlink,BAD_CAST "role",BAD_CAST cschema);
778      xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST registryUrl);
779      free(registryUrl);
780      xmlAddChild(n,nc1);
781    }
782  }
783}
784
785/**
786 * Generate a ProcessDescription node for a servie and add it to a given node.
787 *
788 * @param reg the profile registry
789 * @param m the conf maps containing the main.cfg settings
790 * @param nc the XML node to add the Process node
791 * @param serv the servive structure created from the zcfg file
792 * @return the generated wps:ProcessOfferings xmlNodePtr
793 */
794void printDescribeProcessForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
795  xmlNsPtr ns,ns_ows,ns_xlink;
796  xmlNodePtr n,nc1;
797  xmlNodePtr nc2 = NULL;
798  map* version=getMapFromMaps(m,"main","rversion");
799  int vid=getVersionId(version->value);
800
801  n=nc;
802 
803  int wpsId=zooXmlAddNs(NULL,schemas[vid][3],"wps");
804  ns=usedNs[wpsId];
805  int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows");
806  ns_ows=usedNs[owsId];
807  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
808  ns_xlink=usedNs[xlinkId];
809  map* tmp1=NULL;
810
811  if(vid==0){
812    nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription");
813    attachAttributes(nc,ns,serv->content,vid);
814  }
815  else{
816    nc2 = xmlNewNode(ns, BAD_CAST "ProcessOffering");
817    // In case mode was defined in the ZCFG file then restrict the
818    // jobControlOptions value to this value. The dismiss is always
819    // supported whatever you can set in the ZCFG file.
820    // cf. http://docs.opengeospatial.org/is/14-065/14-065.html#47 (Table 30)
821    map* mode=getMap(serv->content,"mode");
822    if(mode!=NULL){
823      if( strncasecmp(mode->value,"sync",strlen(mode->value))==0 ||
824          strncasecmp(mode->value,"async",strlen(mode->value))==0 ){
825        char toReplace[22];
826        sprintf(toReplace,"%s-execute dismiss",mode->value);
827        addToMap(serv->content,capabilities[vid][3],toReplace);
828      }
829    }
830    attachAttributes(nc2,NULL,serv->content,vid);
831    map* level=getMap(serv->content,"level");
832    if(level!=NULL && strcasecmp(level->value,"generic")==0)
833      nc = xmlNewNode(ns, BAD_CAST "GenericProcess");
834    else
835      nc = xmlNewNode(ns, BAD_CAST "Process");
836  }
837 
838  tmp1=getMapFromMaps(m,"lenv","level");
839  addPrefix(m,tmp1,serv);
840  printDescription(nc,ns_ows,serv->name,serv->content,vid);
841
842  if(vid==0){
843    tmp1=serv->metadata;
844    while(tmp1!=NULL){
845      nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
846      xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
847      xmlAddChild(nc,nc1);
848      tmp1=tmp1->next;
849    }
850    tmp1=getMap(serv->content,"Profile");
851    if(tmp1!=NULL && vid==0){
852      nc1 = xmlNewNode(ns, BAD_CAST "Profile");
853      xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value));
854      xmlAddChild(nc,nc1);
855    }
856  }else{
857    addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv);
858  }
859
860  if(serv->inputs!=NULL){
861    elements* e=serv->inputs;
862    if(vid==0){
863      nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs");
864      printFullDescription(1,e,"Input",ns,ns_ows,nc1,vid);
865      xmlAddChild(nc,nc1);
866    }
867    else{
868      printFullDescription(1,e,"wps:Input",ns,ns_ows,nc,vid);
869    }
870  }
871
872  elements* e=serv->outputs;
873  if(vid==0){
874    nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
875    printFullDescription(0,e,"Output",ns,ns_ows,nc1,vid);
876    xmlAddChild(nc,nc1);
877  }
878  else{
879    printFullDescription(0,e,"wps:Output",ns,ns_ows,nc,vid);
880  }
881  if(vid==0)
882    xmlAddChild(n,nc);
883  else if (nc2 != NULL) {         
884    xmlAddChild(nc2,nc);
885    xmlAddChild(n,nc2);
886  }
887
888}
889
890/**
891 * Generate the required XML tree for the detailled metadata informations of
892 * inputs or outputs
893 *
894 * @param in 1 in case of inputs, 0 for outputs
895 * @param elem the elements structure containing the metadata informations
896 * @param type the name ("Input" or "Output") of the XML node to create
897 * @param ns_ows the ows XML namespace
898 * @param ns_ows the ows XML namespace
899 * @param nc1 the XML node to use to add the created tree
900 * @param vid the WPS version id (0 for 1.0.0, 1 for 2.0.0)
901 */
902void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid){
903  xmlNsPtr ns1=NULL;
904  if(vid==1)
905    ns1=ns;
906
907  xmlNodePtr nc2,nc3,nc4,nc5,nc6,nc7,nc8,nc9;
908  elements* e=elem;
909  nc9=NULL;
910  map* tmp1=NULL;
911  while(e!=NULL){
912    int default1=0;
913    int isAnyValue=1;
914    nc2 = xmlNewNode(NULL, BAD_CAST type);
915    if(strstr(type,"Input")!=NULL){
916      tmp1=getMap(e->content,"minOccurs");
917      if(tmp1!=NULL){
918        xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
919      }else
920        xmlNewProp(nc2,BAD_CAST "minOccurs",BAD_CAST "0");
921      tmp1=getMap(e->content,"maxOccurs");
922      if(tmp1!=NULL){
923        if(strcasecmp(tmp1->value,"unbounded")!=0)
924          xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
925        else
926          xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1000");
927      }else
928        xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1");
929      if((tmp1=getMap(e->content,"maximumMegabytes"))!=NULL){
930        xmlNewProp(nc2,BAD_CAST "maximumMegabytes",BAD_CAST tmp1->value);
931      }
932    }
933
934    printDescription(nc2,ns_ows,e->name,e->content,vid);
935
936    if(e->format!=NULL){
937      const char orderedFields[13][14]={
938        "mimeType",
939        "encoding",
940        "schema",
941        "dataType",
942        "uom",
943        "CRS",
944        "AllowedValues",
945        "range",
946        "rangeMin",
947        "rangeMax",
948        "rangeClosure",
949        "rangeSpace"
950      };
951
952      //Build the (Literal/Complex/BoundingBox)Data node
953      if(strncmp(type,"Output",6)==0){
954        if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0)
955          nc3 = xmlNewNode(ns1, BAD_CAST "LiteralOutput");
956        else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
957          nc3 = xmlNewNode(ns1, BAD_CAST "ComplexOutput");
958        else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0)
959          nc3 = xmlNewNode(ns1, BAD_CAST "BoundingBoxOutput");
960        else
961          nc3 = xmlNewNode(ns1, BAD_CAST e->format);
962      }else{
963        if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0 ||
964           strncasecmp(e->format,"LITERALOUTPUT",strlen(e->format))==0){
965          nc3 = xmlNewNode(ns1, BAD_CAST "LiteralData");
966        }
967        else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
968          nc3 = xmlNewNode(ns1, BAD_CAST "ComplexData");
969        else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0)
970          nc3 = xmlNewNode(ns1, BAD_CAST "BoundingBoxData");
971        else
972          nc3 = xmlNewNode(ns1, BAD_CAST e->format);
973      }
974
975      iotype* _tmp0=NULL;
976      iotype* _tmp=e->defaults;
977      int datatype=0;
978      bool hasUOM=false;
979      bool hasUOM1=false;
980      if(_tmp!=NULL){
981        if(strcmp(e->format,"LiteralOutput")==0 ||
982           strcmp(e->format,"LiteralData")==0){
983          datatype=1;
984          if(vid==1){
985            nc4 = xmlNewNode(ns1, BAD_CAST "Format");
986            xmlNewProp(nc4,BAD_CAST "mimeType",BAD_CAST "text/plain");
987            xmlNewProp(nc4,BAD_CAST "default",BAD_CAST "true");
988            xmlAddChild(nc3,nc4);
989            nc5 = xmlNewNode(NULL, BAD_CAST "LiteralDataDomain");
990            xmlNewProp(nc5,BAD_CAST "default",BAD_CAST "true");
991          }
992          else{
993            nc4 = xmlNewNode(NULL, BAD_CAST "UOMs");
994            nc5 = xmlNewNode(NULL, BAD_CAST "Default");
995          }
996        }
997        else if(strcmp(e->format,"BoundingBoxOutput")==0 ||
998                strcmp(e->format,"BoundingBoxData")==0){
999          datatype=2;
1000          nc5 = xmlNewNode(NULL, BAD_CAST "Default");
1001        }
1002        else{
1003          if(vid==0)
1004            nc4 = xmlNewNode(NULL, BAD_CAST "Default");
1005          nc5 = xmlNewNode(ns1, BAD_CAST "Format");
1006          if(vid==1){
1007            xmlNewProp(nc5,BAD_CAST "default",BAD_CAST "true");
1008            int oI=0;
1009            for(oI=0;oI<3;oI++)
1010              if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1011                xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value);
1012              }
1013          }
1014        }
1015     
1016        tmp1=_tmp->content;
1017
1018        if(vid==0)
1019          if((tmp1=getMap(_tmp->content,"DataType"))!=NULL){
1020            nc8 = xmlNewNode(ns_ows, BAD_CAST "DataType");
1021            xmlAddChild(nc8,xmlNewText(BAD_CAST tmp1->value));
1022            char tmp[1024];
1023            sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
1024            xmlNewNsProp(nc8,ns_ows,BAD_CAST "reference",BAD_CAST tmp);
1025            if(vid==0)
1026              xmlAddChild(nc3,nc8);
1027            else
1028              xmlAddChild(nc5,nc8);
1029            datatype=1;
1030          }
1031
1032        bool isInput=false;
1033        if(strncmp(type,"Input",5)==0 || strncmp(type,"wps:Input",9)==0){
1034          isInput=true;
1035          if((tmp1=getMap(_tmp->content,"AllowedValues"))!=NULL){
1036            nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
1037            char *token,*saveptr1;
1038            token=strtok_r(tmp1->value,",",&saveptr1);
1039            while(token!=NULL){
1040              nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
1041              char *tmps=strdup(token);
1042              tmps[strlen(tmps)]=0;
1043              xmlAddChild(nc7,xmlNewText(BAD_CAST tmps));
1044              free(tmps);
1045              xmlAddChild(nc6,nc7);
1046              token=strtok_r(NULL,",",&saveptr1);
1047            }
1048            if(getMap(_tmp->content,"range")!=NULL ||
1049               getMap(_tmp->content,"rangeMin")!=NULL ||
1050               getMap(_tmp->content,"rangeMax")!=NULL ||
1051               getMap(_tmp->content,"rangeClosure")!=NULL )
1052              goto doRange;
1053            if(vid==0)
1054              xmlAddChild(nc3,nc6);
1055            else
1056              xmlAddChild(nc5,nc6);
1057            isAnyValue=-1;
1058          }
1059
1060          tmp1=getMap(_tmp->content,"range");
1061          if(tmp1==NULL)
1062            tmp1=getMap(_tmp->content,"rangeMin");
1063          if(tmp1==NULL)
1064            tmp1=getMap(_tmp->content,"rangeMax");
1065       
1066          if(tmp1!=NULL && isAnyValue==1){
1067            nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
1068          doRange:
1069         
1070            /**
1071             * Range: Table 46 OGC Web Services Common Standard
1072             */
1073            nc8 = xmlNewNode(ns_ows, BAD_CAST "Range");
1074         
1075            map* tmp0=getMap(tmp1,"range");
1076            if(tmp0!=NULL){
1077              char* pToken;
1078              char* orig=zStrdup(tmp0->value);
1079              /**
1080               * RangeClosure: Table 47 OGC Web Services Common Standard
1081               */
1082              const char *tmp="closed";
1083              if(orig[0]=='[' && orig[strlen(orig)-1]=='[')
1084                tmp="closed-open";
1085              else
1086                if(orig[0]==']' && orig[strlen(orig)-1]==']')
1087                  tmp="open-closed";
1088                else
1089                  if(orig[0]==']' && orig[strlen(orig)-1]=='[')
1090                    tmp="open";
1091              xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp);
1092              pToken=strtok(orig,",");
1093              int nci0=0;
1094              while(pToken!=NULL){
1095                char *tmpStr=(char*) malloc((strlen(pToken))*sizeof(char));
1096                if(nci0==0){
1097                  nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
1098                  strncpy( tmpStr, pToken+1, strlen(pToken)-1 );
1099                  tmpStr[strlen(pToken)-1] = '\0';
1100                }else{
1101                  nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
1102                  const char* bkt;
1103                  if ( ( bkt = strchr(pToken, '[') ) != NULL || ( bkt = strchr(pToken, ']') ) != NULL ){
1104                    strncpy( tmpStr, pToken, bkt - pToken );
1105                    tmpStr[bkt - pToken] = '\0';
1106                  }
1107                }
1108                xmlAddChild(nc7,xmlNewText(BAD_CAST tmpStr));
1109                free(tmpStr);
1110                xmlAddChild(nc8,nc7);
1111                nci0++;
1112                pToken = strtok(NULL,",");
1113              }             
1114              if(getMap(tmp1,"rangeSpacing")==NULL){
1115                nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing");
1116                xmlAddChild(nc7,xmlNewText(BAD_CAST "1"));
1117                xmlAddChild(nc8,nc7);
1118              }
1119              free(orig);
1120            }else{
1121           
1122              tmp0=getMap(tmp1,"rangeMin");
1123              if(tmp0!=NULL){
1124                nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
1125                xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
1126                xmlAddChild(nc8,nc7);
1127              }else{
1128                nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
1129                xmlAddChild(nc8,nc7);
1130              }
1131              tmp0=getMap(tmp1,"rangeMax");
1132              if(tmp0!=NULL){
1133                nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
1134                xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
1135                xmlAddChild(nc8,nc7);
1136              }else{
1137                nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
1138                xmlAddChild(nc8,nc7);
1139              }
1140              tmp0=getMap(tmp1,"rangeSpacing");
1141              if(tmp0!=NULL){
1142                nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing");
1143                xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
1144                xmlAddChild(nc8,nc7);
1145              }
1146              tmp0=getMap(tmp1,"rangeClosure");
1147              if(tmp0!=NULL){
1148                const char *tmp="closed";
1149                if(strcasecmp(tmp0->value,"co")==0)
1150                  tmp="closed-open";
1151                else
1152                  if(strcasecmp(tmp0->value,"oc")==0)
1153                    tmp="open-closed";
1154                  else
1155                    if(strcasecmp(tmp0->value,"o")==0)
1156                      tmp="open";
1157                xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp);
1158              }else
1159                xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST "closed");
1160            }
1161            if(_tmp0==NULL){
1162              xmlAddChild(nc6,nc8);
1163              _tmp0=e->supported;
1164              if(_tmp0!=NULL &&
1165                 (getMap(_tmp0->content,"range")!=NULL ||
1166                  getMap(_tmp0->content,"rangeMin")!=NULL ||
1167                  getMap(_tmp0->content,"rangeMax")!=NULL ||
1168                  getMap(_tmp0->content,"rangeClosure")!=NULL )){
1169                tmp1=_tmp0->content;
1170                goto doRange;
1171              }
1172            }else{
1173              _tmp0=_tmp0->next;
1174              if(_tmp0!=NULL){
1175                xmlAddChild(nc6,nc8);
1176                if(getMap(_tmp0->content,"range")!=NULL ||
1177                   getMap(_tmp0->content,"rangeMin")!=NULL ||
1178                   getMap(_tmp0->content,"rangeMax")!=NULL ||
1179                   getMap(_tmp0->content,"rangeClosure")!=NULL ){
1180                  tmp1=_tmp0->content;
1181                  goto doRange;
1182                }
1183              }
1184            }
1185            xmlAddChild(nc6,nc8);
1186            if(vid==0)
1187              xmlAddChild(nc3,nc6);
1188            else
1189              xmlAddChild(nc5,nc6);
1190            isAnyValue=-1;
1191          }
1192       
1193        }
1194     
1195        int oI=0;
1196        /*if(vid==0)*/ {
1197          for(oI=0;oI<13;oI++)
1198            if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1199#ifdef DEBUG
1200              printf("DATATYPE DEFAULT ? %s\n",tmp1->name);
1201#endif
1202              if(strcmp(tmp1->name,"asReference")!=0 &&
1203                 strncasecmp(tmp1->name,"DataType",8)!=0 &&
1204                 strcasecmp(tmp1->name,"extension")!=0 &&
1205                 strcasecmp(tmp1->name,"value")!=0 &&
1206                 strcasecmp(tmp1->name,"AllowedValues")!=0 &&
1207                 strncasecmp(tmp1->name,"range",5)!=0){
1208                if(datatype!=1){
1209                  char *tmp2=zCapitalize1(tmp1->name);
1210                  nc9 = xmlNewNode(NULL, BAD_CAST tmp2);
1211                  free(tmp2);
1212                }
1213                else{
1214                  char *tmp2=zCapitalize(tmp1->name);
1215                  nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
1216                  free(tmp2);
1217                }
1218                xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
1219                if(vid==0 || oI>=3){
1220                  if(vid==0 || oI!=4)
1221                    xmlAddChild(nc5,nc9);
1222                  if(oI==4 && vid==1){
1223                    xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true");
1224                  }
1225                }
1226                else
1227                  xmlFree(nc9);
1228                if(strcasecmp(tmp1->name,"uom")==0)
1229                  hasUOM1=true;
1230                hasUOM=true;
1231              }else       
1232                tmp1=tmp1->next;
1233            }
1234        }
1235   
1236        if(datatype!=2){
1237          if(hasUOM==true){
1238            if(vid==0){
1239              xmlAddChild(nc4,nc5);
1240              xmlAddChild(nc3,nc4);
1241            }
1242            else{
1243              xmlAddChild(nc3,nc5);
1244            }
1245          }else{
1246            if(hasUOM1==false && vid==0){
1247              xmlFreeNode(nc5);
1248              if(datatype==1)
1249                xmlFreeNode(nc4);
1250            }
1251            else
1252              xmlAddChild(nc3,nc5);
1253          }
1254        }else{
1255          xmlAddChild(nc3,nc5);
1256        }
1257     
1258        if(datatype!=1 && default1<0){
1259          xmlFreeNode(nc5);
1260          if(datatype!=2)
1261            xmlFreeNode(nc4);
1262        }
1263
1264
1265        if((isInput || vid==1) && datatype==1 &&
1266           getMap(_tmp->content,"AllowedValues")==NULL &&
1267           getMap(_tmp->content,"range")==NULL &&
1268           getMap(_tmp->content,"rangeMin")==NULL &&
1269           getMap(_tmp->content,"rangeMax")==NULL &&
1270           getMap(_tmp->content,"rangeClosure")==NULL ){
1271          tmp1=getMap(_tmp->content,"dataType");
1272          // We were tempted to define default value for boolean as {true,false}
1273          if(tmp1!=NULL && strcasecmp(tmp1->value,"boolean")==0){
1274            nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
1275            nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
1276            xmlAddChild(nc7,xmlNewText(BAD_CAST "true"));
1277            xmlAddChild(nc6,nc7);
1278            nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
1279            xmlAddChild(nc7,xmlNewText(BAD_CAST "false"));
1280            xmlAddChild(nc6,nc7);
1281            if(vid==0)
1282              xmlAddChild(nc3,nc6);
1283            else
1284              xmlAddChild(nc5,nc6);
1285          }
1286          else
1287            if(vid==0)
1288              xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
1289            else
1290              xmlAddChild(nc5,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
1291        }
1292
1293        if(vid==1){
1294          if((tmp1=getMap(_tmp->content,"DataType"))!=NULL){
1295            nc8 = xmlNewNode(ns_ows, BAD_CAST "DataType");
1296            xmlAddChild(nc8,xmlNewText(BAD_CAST tmp1->value));
1297            char tmp[1024];
1298            sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
1299            xmlNewNsProp(nc8,ns_ows,BAD_CAST "reference",BAD_CAST tmp);
1300            if(vid==0)
1301              xmlAddChild(nc3,nc8);
1302            else
1303              xmlAddChild(nc5,nc8);
1304            datatype=1;
1305          }
1306          if(hasUOM==true){
1307            tmp1=getMap(_tmp->content,"uom");
1308            if(tmp1!=NULL){
1309              char *tmp2=zCapitalize(tmp1->name);
1310              nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
1311              free(tmp2);
1312              //xmlNewProp(nc9, BAD_CAST "default", BAD_CAST "true");
1313              xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
1314              xmlAddChild(nc5,nc9);
1315              /*struct iotype * _ltmp=e->supported;
1316                while(_ltmp!=NULL){
1317                tmp1=getMap(_ltmp->content,"uom");
1318                if(tmp1!=NULL){
1319                char *tmp2=zCapitalize(tmp1->name);
1320                nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
1321                free(tmp2);
1322                xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
1323                xmlAddChild(nc5,nc9);
1324                }
1325                _ltmp=_ltmp->next;
1326                }*/
1327           
1328            }
1329          }
1330          if(e->defaults!=NULL && (tmp1=getMap(e->defaults->content,"value"))!=NULL){
1331            nc7 = xmlNewNode(ns_ows, BAD_CAST "DefaultValue");
1332            xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value));
1333            xmlAddChild(nc5,nc7);
1334          }
1335        }
1336
1337        map* metadata=e->metadata;
1338        xmlNodePtr n=NULL;
1339        int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
1340        xmlNsPtr ns_xlink=usedNs[xlinkId];
1341
1342        while(metadata!=NULL){
1343          nc6=xmlNewNode(ns_ows, BAD_CAST "Metadata");
1344          xmlNewNsProp(nc6,ns_xlink,BAD_CAST metadata->name,BAD_CAST metadata->value);
1345          xmlAddChild(nc2,nc6);
1346          metadata=metadata->next;
1347        }
1348
1349      }
1350
1351      _tmp=e->supported;
1352      if(_tmp==NULL && datatype!=1)
1353        _tmp=e->defaults;
1354
1355      int hasSupported=-1;
1356
1357      while(_tmp!=NULL){
1358        if(hasSupported<0){
1359          if(datatype==0){
1360            if(vid==0)
1361              nc4 = xmlNewNode(NULL, BAD_CAST "Supported");
1362            nc5 = xmlNewNode(ns1, BAD_CAST "Format");
1363            if(vid==1){
1364              int oI=0;
1365              for(oI=0;oI<3;oI++)
1366                if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1367                  xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value);
1368                }
1369            }
1370          }
1371          else
1372            if(vid==0)
1373              nc5 = xmlNewNode(NULL, BAD_CAST "Supported");
1374          hasSupported=0;
1375        }else
1376          if(datatype==0){
1377            nc5 = xmlNewNode(ns1, BAD_CAST "Format");
1378            if(vid==1){
1379              int oI=0;
1380              for(oI=0;oI<3;oI++)
1381                if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1382                  xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value);
1383                }
1384            }
1385          }
1386        tmp1=_tmp->content;
1387        int oI=0;
1388        for(oI=0;oI<6;oI++)
1389          if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
1390#ifdef DEBUG
1391            printf("DATATYPE SUPPORTED ? %s\n",tmp1->name);
1392#endif
1393            if(strcmp(tmp1->name,"asReference")!=0 && 
1394               strcmp(tmp1->name,"value")!=0 && 
1395               strcmp(tmp1->name,"DataType")!=0 &&
1396               strcasecmp(tmp1->name,"extension")!=0){
1397              if(datatype!=1){
1398                char *tmp2=zCapitalize1(tmp1->name);
1399                nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
1400                free(tmp2);
1401              }
1402              else{
1403                char *tmp2=zCapitalize(tmp1->name);
1404                nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2);
1405                free(tmp2);
1406              }
1407              if(datatype==2){
1408                char *tmpv,*tmps;
1409                tmps=strtok_r(tmp1->value,",",&tmpv);
1410                while(tmps){
1411                  xmlAddChild(nc6,xmlNewText(BAD_CAST tmps));
1412                  tmps=strtok_r(NULL,",",&tmpv);
1413                  if(tmps){
1414                    char *tmp2=zCapitalize1(tmp1->name);
1415                    nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
1416                    free(tmp2);
1417                  }
1418                }
1419              }
1420              else{
1421                xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
1422              }
1423              if(vid==0 || oI>=3){
1424                if(vid==0 || oI!=4)
1425                  xmlAddChild(nc5,nc6);
1426                else
1427                  xmlFree(nc6);
1428              }
1429              else
1430                xmlFree(nc6);
1431            }
1432            tmp1=tmp1->next;
1433          }
1434        if(hasSupported<=0){
1435          if(datatype==0){
1436            if(vid==0){
1437              xmlAddChild(nc4,nc5);
1438              xmlAddChild(nc3,nc4);
1439            }
1440            else{
1441              xmlAddChild(nc3,nc5);
1442            }
1443
1444          }else{
1445            if(datatype!=1)
1446              xmlAddChild(nc3,nc5);
1447          }
1448          hasSupported=1;
1449        }
1450        else
1451          if(datatype==0){
1452            if(vid==0){
1453              xmlAddChild(nc4,nc5);
1454              xmlAddChild(nc3,nc4);
1455            }
1456            else{
1457              xmlAddChild(nc3,nc5);
1458            }
1459          }
1460          else
1461            if(datatype!=1)
1462              xmlAddChild(nc3,nc5);
1463
1464        _tmp=_tmp->next;
1465      }
1466
1467      if(hasSupported==0){
1468        if(datatype==0 && vid!=0)
1469          xmlFreeNode(nc4);
1470        xmlFreeNode(nc5);
1471      }
1472
1473      _tmp=e->defaults;
1474      if(datatype==1 && hasUOM1==true){
1475        if(vid==0){
1476          xmlAddChild(nc4,nc5);
1477          xmlAddChild(nc3,nc4);
1478        }
1479        else{
1480          xmlAddChild(nc3,nc5);
1481        }
1482      }
1483
1484      if(vid==0 && _tmp!=NULL && (tmp1=getMap(_tmp->content,"value"))!=NULL){
1485        nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue");
1486        xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value));
1487        xmlAddChild(nc3,nc7);
1488      }
1489   
1490      xmlAddChild(nc2,nc3);
1491    }
1492   
1493    xmlAddChild(nc1,nc2);
1494   
1495    e=e->next;
1496  }
1497}
1498
1499/**
1500 * Generate a wps:Execute XML document.
1501 *
1502 * @param m the conf maps containing the main.cfg settings
1503 * @param request the map representing the HTTP request
1504 * @param pid the process identifier linked to a service
1505 * @param serv the serv structure created from the zcfg file
1506 * @param service the service name
1507 * @param status the status returned by the service
1508 * @param inputs the inputs provided
1509 * @param outputs the outputs generated by the service
1510 */
1511void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
1512  xmlNsPtr ns,ns_ows,ns_xlink;
1513  xmlNodePtr nr,n,nc,nc1=NULL,nc3;
1514  xmlDocPtr doc;
1515  time_t time1; 
1516  time(&time1);
1517  nr=NULL;
1518
1519  doc = xmlNewDoc(BAD_CAST "1.0");
1520  map* version=getMapFromMaps(m,"main","rversion");
1521  int vid=getVersionId(version->value);
1522  n = printWPSHeader(doc,m,"Execute",root_nodes[vid][2],(version!=NULL?version->value:"1.0.0"),2);
1523  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
1524  ns=usedNs[wpsId];
1525  int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows");
1526  ns_ows=usedNs[owsId];
1527  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
1528  ns_xlink=usedNs[xlinkId];
1529  bool hasStoredExecuteResponse=false;
1530  char stored_path[1024];
1531  memset(stored_path,0,1024);
1532   
1533  if(vid==0){
1534    char tmp[256];
1535    char url[1024];
1536    memset(tmp,0,256);
1537    memset(url,0,1024);
1538    maps* tmp_maps=getMaps(m,"main");
1539    if(tmp_maps!=NULL){
1540      map* tmpm1=getMap(tmp_maps->content,"serverAddress");
1541      /**
1542       * Check if the ZOO Service GetStatus is available in the local directory.
1543       * If yes, then it uses a reference to an URL which the client can access
1544       * to get information on the status of a running Service (using the
1545       * percentCompleted attribute).
1546       * Else fallback to the initial method using the xml file to write in ...
1547       */
1548      char ntmp[1024];
1549#ifndef WIN32
1550      getcwd(ntmp,1024);
1551#else
1552      _getcwd(ntmp,1024);
1553#endif
1554      struct stat myFileInfo;
1555      int statRes;
1556      char file_path[1024];
1557      sprintf(file_path,"%s/GetStatus.zcfg",ntmp);
1558      statRes=stat(file_path,&myFileInfo);
1559      if(statRes==0){
1560        char currentSid[128];
1561        map* tmpm=getMap(tmp_maps->content,"rewriteUrl");
1562        map *tmp_lenv=NULL;
1563        tmp_lenv=getMapFromMaps(m,"lenv","usid");
1564        if(tmp_lenv==NULL)
1565          sprintf(currentSid,"%i",pid);
1566        else
1567          sprintf(currentSid,"%s",tmp_lenv->value);
1568        if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){
1569          sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
1570        }else{
1571          if(strlen(tmpm->value)>0)
1572            if(strcasecmp(tmpm->value,"true")!=0)
1573              sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid);
1574            else
1575              sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid);
1576          else
1577            sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
1578        }
1579      }else{
1580        int lpid;
1581        map* tmpm2=getMapFromMaps(m,"lenv","usid");
1582        map* tmpm3=getMap(tmp_maps->content,"tmpUrl");
1583        if(tmpm1!=NULL && tmpm3!=NULL){
1584          if( strncasecmp( tmpm3->value, "http://", 7) == 0 ||
1585              strncasecmp( tmpm3->value, "https://", 8 ) == 0 ){
1586            sprintf(url,"%s/%s_%s.xml",tmpm3->value,service,tmpm2->value);
1587          }else
1588            sprintf(url,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
1589        }
1590      }
1591      if(tmpm1!=NULL){
1592        sprintf(tmp,"%s",tmpm1->value);
1593      }
1594      int lpid;
1595      map* tmpm2=getMapFromMaps(m,"lenv","usid");
1596      tmpm1=getMapFromMaps(m,"main","TmpPath");
1597      sprintf(stored_path,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
1598    }
1599
1600    xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
1601    map* test=getMap(request,"storeExecuteResponse");
1602    if(test!=NULL && strcasecmp(test->value,"true")==0){
1603      xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
1604      hasStoredExecuteResponse=true;
1605    }
1606
1607    nc = xmlNewNode(ns, BAD_CAST "Process");
1608    map* tmp2=getMap(serv->content,"processVersion");
1609    if(tmp2!=NULL)
1610      xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value);
1611    else
1612      xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST "1");
1613 
1614    map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
1615    printDescription(nc,ns_ows,tmpI->value,serv->content,0);
1616
1617    xmlAddChild(n,nc);
1618
1619    nc = xmlNewNode(ns, BAD_CAST "Status");
1620    const struct tm *tm;
1621    size_t len;
1622    time_t now;
1623    char *tmp1;
1624    map *tmpStatus;
1625 
1626    now = time ( NULL );
1627    tm = localtime ( &now );
1628
1629    tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
1630
1631    len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
1632
1633    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
1634
1635    char sMsg[2048];
1636    switch(status){
1637    case SERVICE_SUCCEEDED:
1638      nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
1639      sprintf(sMsg,_("The service \"%s\" ran successfully."),serv->name);
1640      nc3=xmlNewText(BAD_CAST sMsg);
1641      xmlAddChild(nc1,nc3);
1642      break;
1643    case SERVICE_STARTED:
1644      nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
1645      tmpStatus=getMapFromMaps(m,"lenv","status");
1646      xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value);
1647      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);
1648      nc3=xmlNewText(BAD_CAST sMsg);
1649      xmlAddChild(nc1,nc3);
1650      break;
1651    case SERVICE_ACCEPTED:
1652      nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted");
1653      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);
1654      nc3=xmlNewText(BAD_CAST sMsg);
1655      xmlAddChild(nc1,nc3);
1656      break;
1657    case SERVICE_FAILED:
1658      nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
1659      map *errorMap;
1660      map *te;
1661      te=getMapFromMaps(m,"lenv","code");
1662      if(te!=NULL)
1663        errorMap=createMap("code",te->value);
1664      else
1665        errorMap=createMap("code","NoApplicableCode");
1666      te=getMapFromMaps(m,"lenv","message");
1667      if(te!=NULL)
1668        addToMap(errorMap,"text",_ss(te->value));
1669      else
1670        addToMap(errorMap,"text",_("No more information available"));
1671      nc3=createExceptionReportNode(m,errorMap,0);
1672      freeMap(&errorMap);
1673      free(errorMap);
1674      xmlAddChild(nc1,nc3);
1675      break;
1676    default :
1677      printf(_("error code not know : %i\n"),status);
1678      //exit(1);
1679      break;
1680    }
1681    xmlAddChild(nc,nc1);
1682    xmlAddChild(n,nc);
1683    free(tmp1);
1684
1685#ifdef DEBUG
1686    fprintf(stderr,"printProcessResponse %d\n",__LINE__);
1687#endif
1688
1689    map* lineage=getMap(request,"lineage");
1690    if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){
1691      nc = xmlNewNode(ns, BAD_CAST "DataInputs");
1692      maps* mcursor=inputs;
1693      elements* scursor=NULL;
1694      while(mcursor!=NULL /*&& scursor!=NULL*/){
1695        scursor=getElements(serv->inputs,mcursor->name);
1696        printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input",vid);
1697        mcursor=mcursor->next;
1698      }
1699      xmlAddChild(n,nc);
1700
1701      nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
1702      mcursor=outputs;
1703      scursor=NULL;
1704      while(mcursor!=NULL){
1705        scursor=getElements(serv->outputs,mcursor->name);
1706        printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
1707        mcursor=mcursor->next;
1708      }
1709      xmlAddChild(n,nc);
1710    }
1711  }
1712
1713  /**
1714   * Display the process output only when requested !
1715   */
1716  if(status==SERVICE_SUCCEEDED){
1717    if(vid==0){
1718      nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
1719    }
1720    maps* mcursor=outputs;
1721    elements* scursor=serv->outputs;
1722    map* testResponse=getMap(request,"RawDataOutput");
1723    if(testResponse==NULL)
1724      testResponse=getMap(request,"ResponseDocument");
1725    while(mcursor!=NULL){
1726      map* tmp0=getMap(mcursor->content,"inRequest");
1727      scursor=getElements(serv->outputs,mcursor->name);
1728      if(scursor!=NULL){
1729        if(testResponse==NULL || tmp0==NULL){
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          if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){
1738            if(vid==0)
1739              printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1740            else
1741              printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1742          }
1743      }else
1744        /**
1745         * In case there was no definition found in the ZCFG file but
1746         * present in the service code
1747         */
1748        if(vid==0)
1749          printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1750        else
1751          printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1752      mcursor=mcursor->next;
1753    }
1754    if(vid==0)
1755      xmlAddChild(n,nc);
1756  }
1757 
1758  if(vid==0 && 
1759     hasStoredExecuteResponse==true 
1760     && status!=SERVICE_STARTED
1761#ifndef WIN32
1762     && status!=SERVICE_ACCEPTED
1763#endif
1764     ){
1765#ifndef RELY_ON_DB
1766    semid lid=acquireLock(m);//,1);
1767    if(lid<0){
1768      /* If the lock failed */
1769      errorException(m,_("Lock failed."),"InternalError",NULL);
1770      xmlFreeDoc(doc);
1771      xmlCleanupParser();
1772      zooXmlCleanupNs();
1773      return;
1774    }
1775    else{
1776#endif
1777      /* We need to write the ExecuteResponse Document somewhere */
1778      FILE* output=fopen(stored_path,"w");
1779      if(output==NULL){
1780        /* If the file cannot be created return an ExceptionReport */
1781        char tmpMsg[1024];
1782        sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path);
1783
1784        errorException(m,tmpMsg,"InternalError",NULL);
1785        xmlFreeDoc(doc);
1786        xmlCleanupParser();
1787        zooXmlCleanupNs();
1788#ifndef RELY_ON_DB
1789        unlockShm(lid);
1790#endif
1791        return;
1792      }
1793      xmlChar *xmlbuff;
1794      int buffersize;
1795      xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1);
1796      fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output);
1797      xmlFree(xmlbuff);
1798      fclose(output);
1799#ifndef RELY_ON_DB
1800#ifdef DEBUG
1801      fprintf(stderr,"UNLOCK %s %d !\n",__FILE__,__LINE__);
1802#endif
1803      unlockShm(lid);
1804      map* v=getMapFromMaps(m,"lenv","sid");
1805      // Remove the lock when running as a normal task
1806      if(getpid()==atoi(v->value)){
1807        removeShmLock (m, 1);
1808      }
1809    }
1810#endif
1811  }
1812  printDocument(m,doc,pid);
1813
1814  xmlCleanupParser();
1815  zooXmlCleanupNs();
1816}
1817
1818/**
1819 * Print a XML document.
1820 *
1821 * @param m the conf maps containing the main.cfg settings
1822 * @param doc the XML document
1823 * @param pid the process identifier linked to a service
1824 */
1825void printDocument(maps* m, xmlDocPtr doc,int pid){
1826  char *encoding=getEncoding(m);
1827  if(pid==getpid()){
1828    printHeaders(m);
1829    printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
1830  }
1831  fflush(stdout);
1832  xmlChar *xmlbuff;
1833  int buffersize;
1834  /*
1835   * Dump the document to a buffer and print it on stdout
1836   * for demonstration purposes.
1837   */
1838  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
1839  printf("%s",xmlbuff);
1840  fflush(stdout);
1841  /*
1842   * Free associated memory.
1843   */
1844  xmlFree(xmlbuff);
1845  xmlFreeDoc(doc);
1846  xmlCleanupParser();
1847  zooXmlCleanupNs();
1848}
1849
1850/**
1851 * Print a XML document.
1852 *
1853 * @param doc the XML document (unused)
1854 * @param nc the XML node to add the output definition
1855 * @param ns_wps the wps XML namespace
1856 * @param ns_ows the ows XML namespace
1857 * @param e the output elements
1858 * @param m the conf maps containing the main.cfg settings
1859 * @param type the type (unused)
1860 */
1861void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){
1862  xmlNodePtr nc1;
1863  nc1=xmlNewNode(ns_wps, BAD_CAST type);
1864  map *tmp=NULL; 
1865  if(e!=NULL && e->defaults!=NULL)
1866    tmp=e->defaults->content;
1867  else{
1868    /*
1869    dumpElements(e);
1870    */
1871    return;
1872  }
1873  while(tmp!=NULL){
1874    if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0
1875       || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0
1876       || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0
1877       || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0)
1878    xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
1879    tmp=tmp->next;
1880  }
1881  tmp=getMap(e->defaults->content,"asReference");
1882  if(tmp==NULL)
1883    xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false");
1884
1885  tmp=e->content;
1886
1887  printDescription(nc1,ns_ows,m->name,e->content,0);
1888
1889  xmlAddChild(nc,nc1);
1890
1891}
1892
1893/**
1894 * Generate XML nodes describing inputs or outputs metadata.
1895 *
1896 * @param doc the XML document
1897 * @param nc the XML node to add the definition
1898 * @param ns_wps the wps namespace
1899 * @param ns_ows the ows namespace
1900 * @param ns_xlink the xlink namespace
1901 * @param e the output elements
1902 * @param m the conf maps containing the main.cfg settings
1903 * @param type the type
1904 */
1905void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){
1906
1907  xmlNodePtr nc1,nc2,nc3;
1908  nc1=xmlNewNode(ns_wps, BAD_CAST type);
1909  map *tmp=NULL;
1910  if(e!=NULL)
1911    tmp=e->content;
1912  else
1913    tmp=m->content;
1914
1915  if(vid==0){
1916    nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
1917    if(e!=NULL)
1918      nc3=xmlNewText(BAD_CAST e->name);
1919    else
1920      nc3=xmlNewText(BAD_CAST m->name);
1921   
1922    xmlAddChild(nc2,nc3);
1923    xmlAddChild(nc1,nc2);
1924 
1925    xmlAddChild(nc,nc1);
1926
1927    if(e!=NULL)
1928      tmp=getMap(e->content,"Title");
1929    else
1930      tmp=getMap(m->content,"Title");
1931   
1932    if(tmp!=NULL){
1933      nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
1934      nc3=xmlNewText(BAD_CAST _ss(tmp->value));
1935      xmlAddChild(nc2,nc3); 
1936      xmlAddChild(nc1,nc2);
1937    }
1938
1939    if(e!=NULL)
1940      tmp=getMap(e->content,"Abstract");
1941    else
1942      tmp=getMap(m->content,"Abstract");
1943
1944    if(tmp!=NULL){
1945      nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
1946      nc3=xmlNewText(BAD_CAST _ss(tmp->value));
1947      xmlAddChild(nc2,nc3); 
1948      xmlAddChild(nc1,nc2);
1949      xmlAddChild(nc,nc1);
1950    }
1951  }else{
1952    xmlNewProp(nc1,BAD_CAST "id",BAD_CAST (e!=NULL?e->name:m->name));
1953  }
1954
1955  /**
1956   * IO type Reference or full Data ?
1957   */
1958  map *tmpMap=getMap(m->content,"Reference");
1959  if(tmpMap==NULL){
1960    nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
1961    if(e!=NULL){
1962      if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
1963        nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
1964      else
1965        if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
1966          nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
1967        else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)
1968          nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
1969        else
1970          nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
1971    }
1972    else {
1973      map* tmpV=getMapFromMaps(m,"format","value");
1974      if(tmpV!=NULL)
1975        nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
1976      else
1977        nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
1978    } 
1979    tmp=m->content;
1980
1981    while(tmp!=NULL){
1982      if(strcasecmp(tmp->name,"mimeType")==0 ||
1983         strcasecmp(tmp->name,"encoding")==0 ||
1984         strcasecmp(tmp->name,"schema")==0 ||
1985         strcasecmp(tmp->name,"datatype")==0 ||
1986         strcasecmp(tmp->name,"uom")==0) {
1987       
1988        if(vid==0)
1989          xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
1990        else{
1991          if(strcasecmp(tmp->name,"datatype")==0)
1992            xmlNewProp(nc2,BAD_CAST "mimeType",BAD_CAST "text/plain");
1993          else
1994            if(strcasecmp(tmp->name,"uom")!=0)
1995              xmlNewProp(nc2,BAD_CAST tmp->name,BAD_CAST tmp->value);
1996        }
1997      }
1998      if(vid==0)
1999        xmlAddChild(nc2,nc3);
2000      tmp=tmp->next;
2001    }
2002    if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {
2003      map* bb=getMap(m->content,"value");
2004      if(bb!=NULL) {
2005        map* tmpRes=parseBoundingBox(bb->value);
2006        printBoundingBox(ns_ows,nc3,tmpRes);
2007        freeMap(&tmpRes);
2008        free(tmpRes);
2009      }
2010    }
2011    else {
2012      if(e!=NULL)
2013        tmp=getMap(e->defaults->content,"mimeType");
2014      else
2015        tmp=NULL;
2016       
2017      map* tmp1=getMap(m->content,"encoding");
2018      map* tmp2=getMap(m->content,"mimeType");
2019      map* tmp3=getMap(m->content,"value");
2020      int hasValue=1;
2021      if(tmp3==NULL){
2022        tmp3=createMap("value","");
2023        hasValue=-1;
2024      }
2025
2026      if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 )     // if encoding is base64
2027          ||                                                           // or if
2028          ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL       //  mime type is not text
2029                              &&                                       //  nor
2030                              strstr(tmp2->value,"xml") == NULL        //  xml
2031                              &&                                       // nor
2032                              strstr(tmp2->value,"javascript") == NULL // javascript
2033                              &&
2034                              strstr(tmp2->value,"json") == NULL
2035                              &&
2036                              strstr(tmp2->value,"ecmascript") == NULL
2037                              &&
2038                              // include for backwards compatibility,
2039                              // although correct mime type is ...kml+xml:
2040                              strstr(tmp2->value,"google-earth.kml") == NULL                                                    )
2041            )
2042          ) {                                                    // then       
2043        map* rs=getMap(m->content,"size");                       // obtain size
2044        bool isSized=true;
2045        if(rs==NULL){
2046          char tmp1[1024];
2047          sprintf(tmp1,"%ld",strlen(tmp3->value));
2048          rs=createMap("size",tmp1);
2049          isSized=false;
2050        }
2051         
2052        xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));  // base 64 encode in XML
2053               
2054        if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) {
2055          xmlAttrPtr ap = xmlHasProp((vid==0?nc3:nc2), BAD_CAST "encoding");
2056          if (ap != NULL) {
2057            xmlRemoveProp(ap);
2058          }                     
2059          xmlNewProp((vid==0?nc3:nc2),BAD_CAST "encoding",BAD_CAST "base64");
2060        }
2061               
2062        if(!isSized){
2063          freeMap(&rs);
2064          free(rs);
2065        }
2066      }
2067      else if (tmp2!=NULL) {                                 // else (text-based format)
2068        if(strstr(tmp2->value, "javascript") != NULL ||      //    if javascript put code in CDATA block
2069           strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader)
2070           strstr(tmp2->value, "ecmascript") != NULL
2071           ) {
2072          xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
2073        }   
2074        else {                                                     // else
2075          if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
2076              // include for backwards compatibility,
2077              // although correct mime type is ...kml+xml:                 
2078              strstr(tmp2->value, "google-earth.kml") != NULL
2079              ) { 
2080                         
2081            int li=zooXmlAddDoc(tmp3->value);
2082            xmlDocPtr doc = iDocs[li];
2083            xmlNodePtr ir = xmlDocGetRootElement(doc);
2084            xmlAddChild((vid==0?nc3:nc2),ir);
2085          }
2086          else                                                     // else     
2087            xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));    //   add text node
2088        }
2089        xmlAddChild(nc2,nc3);
2090      }
2091      else {
2092        xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));
2093      }
2094         
2095      if(hasValue<0) {
2096        freeMap(&tmp3);
2097        free(tmp3);
2098      }
2099    }
2100  }
2101  else { // Reference
2102    tmpMap=getMap(m->content,"Reference");
2103    nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference");
2104    if(strcasecmp(type,"Output")==0)
2105      xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value);
2106    else
2107      xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value);
2108   
2109    tmp=m->content;
2110    while(tmp!=NULL) {
2111      if(strcasecmp(tmp->name,"mimeType")==0 ||
2112         strcasecmp(tmp->name,"encoding")==0 ||
2113         strcasecmp(tmp->name,"schema")==0 ||
2114         strcasecmp(tmp->name,"datatype")==0 ||
2115         strcasecmp(tmp->name,"uom")==0){
2116
2117        if(strcasecmp(tmp->name,"datatype")==0)
2118          xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
2119        else
2120          xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
2121      }
2122      tmp=tmp->next;
2123      xmlAddChild(nc2,nc3);
2124    }
2125  }
2126  xmlAddChild(nc1,nc2);
2127  xmlAddChild(nc,nc1);
2128}
2129
2130/**
2131 * Create XML node with basic ows metadata informations (Identifier,Title,Abstract)
2132 *
2133 * @param root the root XML node to add the description
2134 * @param ns_ows the ows XML namespace
2135 * @param identifier the identifier to use
2136 * @param amap the map containing the ows metadata informations
2137 */
2138void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap,int vid=0){
2139  xmlNodePtr nc2;
2140  if(vid==0){
2141    nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
2142    xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
2143    xmlAddChild(root,nc2);
2144  }
2145  map* tmp=amap;
2146  const char *tmp2[2];
2147  tmp2[0]="Title";
2148  tmp2[1]="Abstract";
2149  int j=0;
2150  for(j=0;j<2;j++){
2151    map* tmp1=getMap(tmp,tmp2[j]);
2152    if(tmp1!=NULL){
2153      nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]);
2154      xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value)));
2155      xmlAddChild(root,nc2);
2156    }
2157  }
2158  if(vid==1){
2159    nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
2160    xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
2161    xmlAddChild(root,nc2);
2162  }
2163}
2164
2165/**
2166 * Print an OWS ExceptionReport Document and HTTP headers (when required)
2167 * depending on the code.
2168 * Set hasPrinted value to true in the [lenv] section.
2169 *
2170 * @param m the maps containing the settings of the main.cfg file
2171 * @param s the map containing the text,code,locator keys
2172 */
2173void printExceptionReportResponse(maps* m,map* s){
2174  if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
2175    return;
2176  int buffersize;
2177  xmlDocPtr doc;
2178  xmlChar *xmlbuff;
2179  xmlNodePtr n;
2180
2181  zooXmlCleanupNs();
2182  doc = xmlNewDoc(BAD_CAST "1.0");
2183  maps* tmpMap=getMaps(m,"main");
2184  char *encoding=getEncoding(tmpMap);
2185  const char *exceptionCode;
2186 
2187  map* tmp=getMap(s,"code");
2188  if(tmp!=NULL){
2189    if(strcmp(tmp->value,"OperationNotSupported")==0 ||
2190       strcmp(tmp->value,"NoApplicableCode")==0)
2191      exceptionCode="501 Not Implemented";
2192    else
2193      if(strcmp(tmp->value,"MissingParameterValue")==0 ||
2194         strcmp(tmp->value,"InvalidUpdateSequence")==0 ||
2195         strcmp(tmp->value,"OptionNotSupported")==0 ||
2196         strcmp(tmp->value,"VersionNegotiationFailed")==0 ||
2197         strcmp(tmp->value,"InvalidParameterValue")==0)
2198        exceptionCode="400 Bad request";
2199      else
2200        exceptionCode="501 Internal Server Error";
2201  }
2202  else
2203    exceptionCode="501 Internal Server Error";
2204
2205  if(m!=NULL){
2206    map *tmpSid=getMapFromMaps(m,"lenv","sid");
2207    if(tmpSid!=NULL){
2208      if( getpid()==atoi(tmpSid->value) ){
2209        printHeaders(m);
2210        printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2211      }
2212    }
2213    else{
2214      printHeaders(m);
2215      printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2216    }
2217  }else{
2218    printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2219  }
2220  n=createExceptionReportNode(m,s,1);
2221  xmlDocSetRootElement(doc, n);
2222  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2223  printf("%s",xmlbuff);
2224  fflush(stdout);
2225  xmlFreeDoc(doc);
2226  xmlFree(xmlbuff);
2227  xmlCleanupParser();
2228  zooXmlCleanupNs();
2229  if(m!=NULL)
2230    setMapInMaps(m,"lenv","hasPrinted","true");
2231}
2232
2233/**
2234 * Create an OWS ExceptionReport Node.
2235 *
2236 * @param m the conf maps
2237 * @param s the map containing the text,code,locator keys
2238 * @param use_ns (0/1) choose if you want to generate an ExceptionReport or
2239 *  ows:ExceptionReport node respectively
2240 * @return the ExceptionReport/ows:ExceptionReport node
2241 */
2242xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){
2243 
2244  xmlNsPtr ns,ns_xsi;
2245  xmlNodePtr n,nc,nc1;
2246
2247  int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows");
2248  ns=usedNs[nsid];
2249  if(use_ns==0){
2250    ns=NULL;
2251  }
2252  n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
2253  map* version=getMapFromMaps(m,"main","rversion");
2254  int vid=-1;
2255  if(version!=NULL)
2256    vid=getVersionId(version->value);
2257  if(vid<0)
2258    vid=0;
2259  if(use_ns==1){
2260    xmlNewNs(n,BAD_CAST schemas[vid][1],BAD_CAST"ows");
2261    int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
2262    ns_xsi=usedNs[xsiId];
2263    char tmp[1024];
2264    sprintf(tmp,"%s %s",schemas[vid][1],schemas[vid][5]);
2265    xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp);
2266  }
2267
2268
2269  addLangAttr(n,m);
2270  xmlNewProp(n,BAD_CAST "version",BAD_CAST schemas[vid][6]);
2271 
2272  int length=1;
2273  int cnt=0;
2274  map* len=getMap(s,"length");
2275  if(len!=NULL)
2276    length=atoi(len->value);
2277  for(cnt=0;cnt<length;cnt++){
2278    nc = xmlNewNode(ns, BAD_CAST "Exception");
2279   
2280    map* tmp=getMapArray(s,"code",cnt);
2281    if(tmp==NULL)
2282      tmp=getMap(s,"code");
2283    if(tmp!=NULL)
2284      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value);
2285    else
2286      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode");
2287   
2288    tmp=getMapArray(s,"locator",cnt);
2289    if(tmp==NULL)
2290      tmp=getMap(s,"locator");
2291    if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0)
2292      xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value);
2293
2294    tmp=getMapArray(s,"text",cnt);
2295    nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
2296    if(tmp!=NULL){
2297      xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
2298      xmlAddChild(nc1,txt);
2299    }
2300    else{
2301      xmlNodeSetContent(nc1, BAD_CAST _("No debug message available"));
2302    }
2303    xmlAddChild(nc,nc1);
2304    xmlAddChild(n,nc);
2305  }
2306  return n;
2307}
2308
2309/**
2310 * Print an OWS ExceptionReport.
2311 *
2312 * @param m the conf maps
2313 * @param message the error message
2314 * @param errorcode the error code
2315 * @param locator the potential locator
2316 */
2317int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 
2318{
2319  map* errormap = createMap("text", message);
2320  addToMap(errormap,"code", errorcode);
2321  if(locator!=NULL)
2322    addToMap(errormap,"locator", locator);
2323  else
2324    addToMap(errormap,"locator", "NULL");
2325  printExceptionReportResponse(m,errormap);
2326  freeMap(&errormap);
2327  free(errormap);
2328  return -1;
2329}
2330
2331/**
2332 * Generate the output response (RawDataOutput or ResponseDocument)
2333 *
2334 * @param s the service structure containing the metadata informations
2335 * @param request_inputs the inputs provided to the service for execution
2336 * @param request_outputs the outputs updated by the service execution
2337 * @param request_inputs1 the map containing the HTTP request
2338 * @param cpid the process identifier attached to a service execution
2339 * @param m the conf maps containing the main.cfg settings
2340 * @param res the value returned by the service execution
2341 */
2342void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
2343                    map* request_inputs1,int cpid,maps* m,int res){
2344#ifdef DEBUG
2345  dumpMaps(request_inputs);
2346  dumpMaps(request_outputs);
2347  fprintf(stderr,"printProcessResponse\n");
2348#endif
2349  map* toto=getMap(request_inputs1,"RawDataOutput");
2350  int asRaw=0;
2351  if(toto!=NULL)
2352    asRaw=1;
2353  map* version=getMapFromMaps(m,"main","rversion");
2354  int vid=getVersionId(version->value);
2355
2356  maps* tmpSess=getMaps(m,"senv");
2357  if(tmpSess!=NULL){
2358    map *_tmp=getMapFromMaps(m,"lenv","cookie");
2359    char* sessId=NULL;
2360    if(_tmp!=NULL){
2361      printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
2362      printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
2363      char session_file_path[100];
2364      char *tmp1=strtok(_tmp->value,";");
2365      if(tmp1!=NULL)
2366        sprintf(session_file_path,"%s",strstr(tmp1,"=")+1);
2367      else
2368        sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1);
2369      sessId=strdup(session_file_path);
2370    }else{
2371      maps* t=getMaps(m,"senv");
2372      map*p=t->content;
2373      while(p!=NULL){
2374        if(strstr(p->name,"ID")!=NULL){
2375          sessId=strdup(p->value);
2376          break;
2377        }
2378        p=p->next;
2379      }
2380    }
2381    char session_file_path[1024];
2382    map *tmpPath=getMapFromMaps(m,"main","sessPath");
2383    if(tmpPath==NULL)
2384      tmpPath=getMapFromMaps(m,"main","tmpPath");
2385    sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId);
2386    FILE* teste=fopen(session_file_path,"w");
2387    if(teste==NULL){
2388      char tmpMsg[1024];
2389      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
2390      errorException(m,tmpMsg,"InternalError",NULL);
2391
2392      return;
2393    }
2394    else{
2395      fclose(teste);
2396      dumpMapsToFile(tmpSess,session_file_path,1);
2397    }
2398  }
2399 
2400  if(res==SERVICE_FAILED){
2401    map *lenv;
2402    lenv=getMapFromMaps(m,"lenv","message");
2403    char *tmp0;
2404    if(lenv!=NULL){
2405      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));
2406      sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value);
2407    }
2408    else{
2409      tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char));
2410      sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service."));
2411    }
2412    errorException(m,tmp0,"InternalError",NULL);
2413    free(tmp0);
2414    return;
2415  }
2416
2417  if(res==SERVICE_ACCEPTED && vid==1){
2418    map* statusInfo=createMap("Status","Accepted");
2419    map *usid=getMapFromMaps(m,"lenv","usid");
2420    addToMap(statusInfo,"JobID",usid->value);
2421    printStatusInfo(m,statusInfo,"Execute");
2422    freeMap(&statusInfo);
2423    free(statusInfo);
2424    return;
2425  }
2426
2427  map *tmp1=getMapFromMaps(m,"main","tmpPath");
2428  if(asRaw==0){
2429#ifdef DEBUG
2430    fprintf(stderr,"REQUEST_OUTPUTS FINAL\n");
2431    dumpMaps(request_outputs);
2432#endif
2433    maps* tmpI=request_outputs;
2434    map* usid=getMapFromMaps(m,"lenv","usid");
2435    int itn=0;
2436    while(tmpI!=NULL){
2437#ifdef USE_MS
2438      map* testMap=getMap(tmpI->content,"useMapserver");       
2439#endif
2440      map *gfile=getMap(tmpI->content,"generated_file");
2441      char *file_name;
2442      if(gfile!=NULL){
2443        gfile=getMap(tmpI->content,"expected_generated_file");
2444        if(gfile==NULL){
2445          gfile=getMap(tmpI->content,"generated_file");
2446        }
2447        readGeneratedFile(m,tmpI->content,gfile->value);           
2448        file_name=(char*)malloc((strlen(gfile->value)+strlen(tmp1->value)+1)*sizeof(char));
2449        for(int i=0;i<strlen(gfile->value);i++)
2450          file_name[i]=gfile->value[i+strlen(tmp1->value)];
2451      }
2452
2453      toto=getMap(tmpI->content,"asReference");
2454#ifdef USE_MS
2455      if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL)
2456#else
2457      if(toto!=NULL && strcasecmp(toto->value,"true")==0)
2458#endif
2459        {
2460          elements* in=getElements(s->outputs,tmpI->name);
2461          char *format=NULL;
2462          if(in!=NULL && in->format!=NULL){
2463            format=zStrdup(in->format);
2464          }else
2465            format=zStrdup("LiteralData");
2466          if(strcasecmp(format,"BoundingBoxData")==0){
2467            addToMap(tmpI->content,"extension","xml");
2468            addToMap(tmpI->content,"mimeType","text/xml");
2469            addToMap(tmpI->content,"encoding","UTF-8");
2470            addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
2471          }
2472
2473          if(gfile==NULL) {
2474            map *ext=getMap(tmpI->content,"extension");
2475            char *file_path;
2476            char file_ext[32];
2477
2478            if( ext != NULL && ext->value != NULL) {
2479              strncpy(file_ext, ext->value, 32);
2480            }
2481            else {
2482              // Obtain default file extension (see mimetypes.h).             
2483              // If the MIME type is not recognized, txt is used as the default extension
2484              map* mtype=getMap(tmpI->content,"mimeType");
2485              getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
2486            }
2487
2488            file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
2489            sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
2490            itn++;
2491            file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
2492            sprintf(file_path,"%s/%s",tmp1->value,file_name);
2493
2494            FILE *ofile=fopen(file_path,"wb");
2495            if(ofile==NULL){
2496              char tmpMsg[1024];
2497              sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
2498              errorException(m,tmpMsg,"InternalError",NULL);
2499              free(file_name);
2500              free(file_path);
2501              return;
2502            }
2503            free(file_path);
2504
2505            toto=getMap(tmpI->content,"value");
2506            if(strcasecmp(format,"BoundingBoxData")!=0){
2507              map* size=getMap(tmpI->content,"size");
2508              if(size!=NULL && toto!=NULL)
2509                fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
2510              else
2511                if(toto!=NULL && toto->value!=NULL)
2512                  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
2513            }else{
2514              printBoundingBoxDocument(m,tmpI,ofile);
2515            }
2516            fclose(ofile);
2517
2518          }
2519
2520          map *tmp2=getMapFromMaps(m,"main","tmpUrl");
2521          map *tmp3=getMapFromMaps(m,"main","serverAddress");
2522          char *file_url;
2523          if(strncasecmp(tmp2->value,"http://",7)==0 ||
2524             strncasecmp(tmp2->value,"https://",8)==0){
2525            file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
2526            sprintf(file_url,"%s/%s",tmp2->value,file_name);
2527          }else{
2528            file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
2529            sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
2530          }
2531
2532          addToMap(tmpI->content,"Reference",file_url);
2533          free(format);
2534          free(file_name);
2535          free(file_url);
2536         
2537        }
2538#ifdef USE_MS
2539      else{
2540        if(testMap!=NULL){
2541          setReferenceUrl(m,tmpI);
2542        }
2543      }
2544#endif
2545      tmpI=tmpI->next;
2546    }
2547#ifdef DEBUG
2548    fprintf(stderr,"SERVICE : %s\n",s->name);
2549    dumpMaps(m);
2550#endif
2551    printProcessResponse(m,request_inputs1,cpid,
2552                         s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
2553                         request_inputs,
2554                         request_outputs);
2555  }
2556  else{
2557    /**
2558     * We get the requested output or fallback to the first one if the
2559     * requested one is not present in the resulting outputs maps.
2560     */
2561    maps* tmpI=NULL;
2562    map* tmpIV=getMap(request_inputs1,"RawDataOutput");
2563    if(tmpIV!=NULL){
2564      tmpI=getMaps(request_outputs,tmpIV->value);
2565    }
2566    if(tmpI==NULL)
2567      tmpI=request_outputs;
2568    elements* e=getElements(s->outputs,tmpI->name);
2569    if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
2570      printBoundingBoxDocument(m,tmpI,NULL);
2571    }else{
2572      map *gfile=getMap(tmpI->content,"generated_file");
2573      if(gfile!=NULL){
2574        gfile=getMap(tmpI->content,"expected_generated_file");
2575        if(gfile==NULL){
2576          gfile=getMap(tmpI->content,"generated_file");
2577        }
2578        readGeneratedFile(m,tmpI->content,gfile->value);
2579      }
2580      toto=getMap(tmpI->content,"value");
2581      if(toto==NULL){
2582        char tmpMsg[1024];
2583        sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name);
2584        errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
2585        return;
2586      }
2587      map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
2588      if(fname!=NULL)
2589        printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
2590      map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
2591      if(rs!=NULL)
2592        printf("Content-Length: %s\r\n",rs->value);
2593      printHeaders(m);
2594      char mime[1024];
2595      map* mi=getMap(tmpI->content,"mimeType");
2596#ifdef DEBUG
2597      fprintf(stderr,"SERVICE OUTPUTS\n");
2598      dumpMaps(request_outputs);
2599      fprintf(stderr,"SERVICE OUTPUTS\n");
2600#endif
2601      map* en=getMap(tmpI->content,"encoding");
2602      if(mi!=NULL && en!=NULL)
2603        sprintf(mime,
2604                "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
2605                mi->value,en->value);
2606      else
2607        if(mi!=NULL)
2608          sprintf(mime,
2609                  "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
2610                  mi->value);
2611        else
2612          sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
2613      printf("%s",mime);
2614      if(rs!=NULL)
2615        fwrite(toto->value,1,atoi(rs->value),stdout);
2616      else
2617        fwrite(toto->value,1,strlen(toto->value),stdout);
2618#ifdef DEBUG
2619      dumpMap(toto);
2620#endif
2621    }
2622  }
2623}
2624
2625/**
2626 * Create required XML nodes for boundingbox and update the current XML node
2627 *
2628 * @param ns_ows the ows XML namespace
2629 * @param n the XML node to update
2630 * @param boundingbox the map containing the boundingbox definition
2631 */
2632void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){
2633
2634  xmlNodePtr lw=NULL,uc=NULL;
2635
2636  map* tmp=getMap(boundingbox,"value");
2637
2638  tmp=getMap(boundingbox,"lowerCorner");
2639  if(tmp!=NULL){
2640    lw=xmlNewNode(ns_ows,BAD_CAST "LowerCorner");
2641    xmlAddChild(lw,xmlNewText(BAD_CAST tmp->value));
2642  }
2643
2644  tmp=getMap(boundingbox,"upperCorner");
2645  if(tmp!=NULL){
2646    uc=xmlNewNode(ns_ows,BAD_CAST "UpperCorner");
2647    xmlAddChild(uc,xmlNewText(BAD_CAST tmp->value));
2648  }
2649
2650  tmp=getMap(boundingbox,"crs");
2651  if(tmp!=NULL)
2652    xmlNewProp(n,BAD_CAST "crs",BAD_CAST tmp->value);
2653
2654  tmp=getMap(boundingbox,"dimensions");
2655  if(tmp!=NULL)
2656    xmlNewProp(n,BAD_CAST "dimensions",BAD_CAST tmp->value);
2657
2658  xmlAddChild(n,lw);
2659  xmlAddChild(n,uc);
2660
2661}
2662
2663/**
2664 * Parse a BoundingBox string
2665 *
2666 * [OGC 06-121r3](http://portal.opengeospatial.org/files/?artifact_id=20040):
2667 *  10.2 Bounding box
2668 *
2669 *
2670 * Value is provided as : lowerCorner,upperCorner,crs,dimension
2671 * Exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84
2672 *
2673 * A map to store boundingbox informations should contain:
2674 *  - lowerCorner : double,double (minimum within this bounding box)
2675 *  - upperCorner : double,double (maximum within this bounding box)
2676 *  - crs : URI (Reference to definition of the CRS)
2677 *  - dimensions : int
2678 *
2679 * Note : support only 2D bounding box.
2680 *
2681 * @param value the char* containing the KVP bouding box
2682 * @return a map containing all the bounding box keys
2683 */
2684map* parseBoundingBox(const char* value){
2685  map *res=NULL;
2686  if(value!=NULL){
2687    char *cv,*cvp;
2688    cv=strtok_r((char*) value,",",&cvp);
2689    int cnt=0;
2690    int icnt=0;
2691    char *currentValue=NULL;
2692    while(cv){
2693      if(cnt<2)
2694        if(currentValue!=NULL){
2695          char *finalValue=(char*)malloc((strlen(currentValue)+strlen(cv)+1)*sizeof(char));
2696          sprintf(finalValue,"%s%s",currentValue,cv);
2697          switch(cnt){
2698          case 0:
2699            res=createMap("lowerCorner",finalValue);
2700            break;
2701          case 1:
2702            addToMap(res,"upperCorner",finalValue);
2703            icnt=-1;
2704            break;
2705          }
2706          cnt++;
2707          free(currentValue);
2708          currentValue=NULL;
2709          free(finalValue);
2710        }
2711        else{
2712          currentValue=(char*)malloc((strlen(cv)+2)*sizeof(char));
2713          sprintf(currentValue,"%s ",cv);
2714        }
2715      else
2716        if(cnt==2){
2717          addToMap(res,"crs",cv);
2718          cnt++;
2719        }
2720        else
2721          addToMap(res,"dimensions",cv);
2722      icnt++;
2723      cv=strtok_r(NULL,",",&cvp);
2724    }
2725  }
2726  return res;
2727}
2728
2729/**
2730 * Print an ows:BoundingBox XML document
2731 *
2732 * @param m the maps containing the settings of the main.cfg file
2733 * @param boundingbox the maps containing the boundingbox definition
2734 * @param file the file to print the BoundingBox (if NULL then print on stdout)
2735 * @see parseBoundingBox, printBoundingBox
2736 */
2737void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){
2738  if(file==NULL)
2739    rewind(stdout);
2740  xmlNodePtr n;
2741  xmlDocPtr doc;
2742  xmlNsPtr ns_ows,ns_xsi;
2743  xmlChar *xmlbuff;
2744  int buffersize;
2745  char *encoding=getEncoding(m);
2746  map *tmp;
2747  if(file==NULL){
2748    int pid=0;
2749    tmp=getMapFromMaps(m,"lenv","sid");
2750    if(tmp!=NULL)
2751      pid=atoi(tmp->value);
2752    if(pid==getpid()){
2753      printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
2754    }
2755    fflush(stdout);
2756  }
2757
2758  doc = xmlNewDoc(BAD_CAST "1.0");
2759  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
2760  ns_ows=usedNs[owsId];
2761  n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox");
2762  xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
2763  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
2764  ns_xsi=usedNs[xsiId];
2765  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");
2766  map *tmp1=getMap(boundingbox->content,"value");
2767  tmp=parseBoundingBox(tmp1->value);
2768  printBoundingBox(ns_ows,n,tmp);
2769  xmlDocSetRootElement(doc, n);
2770
2771  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2772  if(file==NULL)
2773    printf("%s",xmlbuff);
2774  else{
2775    fprintf(file,"%s",xmlbuff);
2776  }
2777
2778  if(tmp!=NULL){
2779    freeMap(&tmp);
2780    free(tmp);
2781  }
2782  xmlFree(xmlbuff);
2783  xmlFreeDoc(doc);
2784  xmlCleanupParser();
2785  zooXmlCleanupNs();
2786 
2787}
2788
2789/**
2790 * Print a StatusInfo XML document.
2791 * a statusInfo map should contain the following keys:
2792 *  * JobID corresponding to usid key from the lenv section
2793 *  * Status the current state (Succeeded,Failed,Accepted,Running)
2794 *  * PercentCompleted (optional) the percent completed
2795 *  * Message (optional) any messages the service may wish to share
2796 *
2797 * @param conf the maps containing the settings of the main.cfg file
2798 * @param statusInfo the map containing the statusInfo definition
2799 * @param req the WPS requests (GetResult, GetStatus or Dismiss)
2800 */
2801void printStatusInfo(maps* conf,map* statusInfo,char* req){
2802  rewind(stdout);
2803  xmlNodePtr n,n1;
2804  xmlDocPtr doc;
2805  xmlNsPtr ns;
2806  xmlChar *xmlbuff;
2807  int buffersize;
2808  char *encoding=getEncoding(conf);
2809  map *tmp;
2810  int pid=0;
2811  printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
2812
2813  map* version=getMapFromMaps(conf,"main","rversion");
2814  int vid=getVersionId(version->value);
2815
2816  doc = xmlNewDoc(BAD_CAST "1.0");
2817  n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1);
2818
2819  map* val=getMap(statusInfo,"JobID");
2820  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
2821  ns=usedNs[wpsId];
2822  n = xmlNewNode(ns, BAD_CAST "JobID");
2823  xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2824
2825  xmlAddChild(n1,n);
2826
2827  val=getMap(statusInfo,"Status");
2828  n = xmlNewNode(ns, BAD_CAST "Status");
2829  xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2830
2831  xmlAddChild(n1,n);
2832
2833  if(strncasecmp(val->value,"Failed",6)!=0 &&
2834     strncasecmp(val->value,"Succeeded",9)!=0){
2835    val=getMap(statusInfo,"PercentCompleted");
2836    if(val!=NULL){
2837      n = xmlNewNode(ns, BAD_CAST "PercentCompleted");
2838      xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2839      xmlAddChild(n1,n);
2840    }
2841
2842    val=getMap(statusInfo,"Message");
2843    if(val!=NULL){   
2844      xmlAddChild(n1,xmlNewComment(BAD_CAST val->value));
2845    }
2846  }
2847  xmlDocSetRootElement(doc, n1);
2848
2849  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2850  printf("%s",xmlbuff);
2851
2852  xmlFree(xmlbuff);
2853  xmlFreeDoc(doc);
2854  xmlCleanupParser();
2855  zooXmlCleanupNs();
2856 
2857}
2858
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