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

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

Give the capability to store the main.cfg file in sysconfdir and the services in servicePath if defined in the [main] section.

  • Property svn:keywords set to Id
File size: 83.2 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 information
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 information 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 information
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      map* cwdMap=getMapFromMaps(m,"main","servicePath");
1549      struct stat myFileInfo;
1550      int statRes;
1551      char file_path[1024];
1552      if(cwdMap!=NULL){
1553        sprintf(file_path,"%s/GetStatus.zcfg",cwdMap->value);
1554      }else{
1555        char ntmp[1024];
1556#ifndef WIN32
1557        getcwd(ntmp,1024);
1558#else
1559        _getcwd(ntmp,1024);
1560#endif
1561        sprintf(file_path,"%s/GetStatus.zcfg",ntmp);
1562      }
1563      fprintf(stderr,"%s \n",file_path);
1564      statRes=stat(file_path,&myFileInfo);
1565      if(statRes==0){
1566        char currentSid[128];
1567        map* tmpm=getMap(tmp_maps->content,"rewriteUrl");
1568        map *tmp_lenv=NULL;
1569        tmp_lenv=getMapFromMaps(m,"lenv","usid");
1570        if(tmp_lenv==NULL)
1571          sprintf(currentSid,"%i",pid);
1572        else
1573          sprintf(currentSid,"%s",tmp_lenv->value);
1574        if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){
1575          sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
1576        }else{
1577          if(strlen(tmpm->value)>0)
1578            if(strcasecmp(tmpm->value,"true")!=0)
1579              sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid);
1580            else
1581              sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid);
1582          else
1583            sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
1584        }
1585      }else{
1586        int lpid;
1587        map* tmpm2=getMapFromMaps(m,"lenv","usid");
1588        map* tmpm3=getMap(tmp_maps->content,"tmpUrl");
1589        if(tmpm1!=NULL && tmpm3!=NULL){
1590          if( strncasecmp( tmpm3->value, "http://", 7) == 0 ||
1591              strncasecmp( tmpm3->value, "https://", 8 ) == 0 ){
1592            sprintf(url,"%s/%s_%s.xml",tmpm3->value,service,tmpm2->value);
1593          }else
1594            sprintf(url,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
1595        }
1596      }
1597      if(tmpm1!=NULL){
1598        sprintf(tmp,"%s",tmpm1->value);
1599      }
1600      int lpid;
1601      map* tmpm2=getMapFromMaps(m,"lenv","usid");
1602      tmpm1=getMapFromMaps(m,"main","TmpPath");
1603      sprintf(stored_path,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
1604    }
1605
1606    xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
1607    map* test=getMap(request,"storeExecuteResponse");
1608    if(test!=NULL && strcasecmp(test->value,"true")==0){
1609      xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
1610      hasStoredExecuteResponse=true;
1611    }
1612
1613    nc = xmlNewNode(ns, BAD_CAST "Process");
1614    map* tmp2=getMap(serv->content,"processVersion");
1615    if(tmp2!=NULL)
1616      xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value);
1617    else
1618      xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST "1");
1619 
1620    map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
1621    printDescription(nc,ns_ows,tmpI->value,serv->content,0);
1622
1623    xmlAddChild(n,nc);
1624
1625    nc = xmlNewNode(ns, BAD_CAST "Status");
1626    const struct tm *tm;
1627    size_t len;
1628    time_t now;
1629    char *tmp1;
1630    map *tmpStatus;
1631 
1632    now = time ( NULL );
1633    tm = localtime ( &now );
1634
1635    tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
1636
1637    len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
1638
1639    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
1640
1641    char sMsg[2048];
1642    switch(status){
1643    case SERVICE_SUCCEEDED:
1644      nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
1645      sprintf(sMsg,_("The service \"%s\" ran successfully."),serv->name);
1646      nc3=xmlNewText(BAD_CAST sMsg);
1647      xmlAddChild(nc1,nc3);
1648      break;
1649    case SERVICE_STARTED:
1650      nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
1651      tmpStatus=getMapFromMaps(m,"lenv","status");
1652      xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value);
1653      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);
1654      nc3=xmlNewText(BAD_CAST sMsg);
1655      xmlAddChild(nc1,nc3);
1656      break;
1657    case SERVICE_ACCEPTED:
1658      nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted");
1659      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);
1660      nc3=xmlNewText(BAD_CAST sMsg);
1661      xmlAddChild(nc1,nc3);
1662      break;
1663    case SERVICE_FAILED:
1664      nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
1665      map *errorMap;
1666      map *te;
1667      te=getMapFromMaps(m,"lenv","code");
1668      if(te!=NULL)
1669        errorMap=createMap("code",te->value);
1670      else
1671        errorMap=createMap("code","NoApplicableCode");
1672      te=getMapFromMaps(m,"lenv","message");
1673      if(te!=NULL)
1674        addToMap(errorMap,"text",_ss(te->value));
1675      else
1676        addToMap(errorMap,"text",_("No more information available"));
1677      nc3=createExceptionReportNode(m,errorMap,0);
1678      freeMap(&errorMap);
1679      free(errorMap);
1680      xmlAddChild(nc1,nc3);
1681      break;
1682    default :
1683      printf(_("error code not know : %i\n"),status);
1684      //exit(1);
1685      break;
1686    }
1687    xmlAddChild(nc,nc1);
1688    xmlAddChild(n,nc);
1689    free(tmp1);
1690
1691#ifdef DEBUG
1692    fprintf(stderr,"printProcessResponse %d\n",__LINE__);
1693#endif
1694
1695    map* lineage=getMap(request,"lineage");
1696    if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){
1697      nc = xmlNewNode(ns, BAD_CAST "DataInputs");
1698      maps* mcursor=inputs;
1699      elements* scursor=NULL;
1700      while(mcursor!=NULL /*&& scursor!=NULL*/){
1701        scursor=getElements(serv->inputs,mcursor->name);
1702        printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input",vid);
1703        mcursor=mcursor->next;
1704      }
1705      xmlAddChild(n,nc);
1706
1707      nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
1708      mcursor=outputs;
1709      scursor=NULL;
1710      while(mcursor!=NULL){
1711        scursor=getElements(serv->outputs,mcursor->name);
1712        printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
1713        mcursor=mcursor->next;
1714      }
1715      xmlAddChild(n,nc);
1716    }
1717  }
1718
1719  /**
1720   * Display the process output only when requested !
1721   */
1722  if(status==SERVICE_SUCCEEDED){
1723    if(vid==0){
1724      nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
1725    }
1726    maps* mcursor=outputs;
1727    elements* scursor=serv->outputs;
1728    map* testResponse=getMap(request,"RawDataOutput");
1729    if(testResponse==NULL)
1730      testResponse=getMap(request,"ResponseDocument");
1731    while(mcursor!=NULL){
1732      map* tmp0=getMap(mcursor->content,"inRequest");
1733      scursor=getElements(serv->outputs,mcursor->name);
1734      if(scursor!=NULL){
1735        if(testResponse==NULL || tmp0==NULL){
1736          if(vid==0)
1737            printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1738          else
1739            printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1740        }
1741        else
1742
1743          if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){
1744            if(vid==0)
1745              printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1746            else
1747              printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1748          }
1749      }else
1750        /**
1751         * In case there was no definition found in the ZCFG file but
1752         * present in the service code
1753         */
1754        if(vid==0)
1755          printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1756        else
1757          printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
1758      mcursor=mcursor->next;
1759    }
1760    if(vid==0)
1761      xmlAddChild(n,nc);
1762  }
1763 
1764  if(vid==0 && 
1765     hasStoredExecuteResponse==true 
1766     && status!=SERVICE_STARTED
1767#ifndef WIN32
1768     && status!=SERVICE_ACCEPTED
1769#endif
1770     ){
1771#ifndef RELY_ON_DB
1772    semid lid=acquireLock(m);//,1);
1773    if(lid<0){
1774      /* If the lock failed */
1775      errorException(m,_("Lock failed."),"InternalError",NULL);
1776      xmlFreeDoc(doc);
1777      xmlCleanupParser();
1778      zooXmlCleanupNs();
1779      return;
1780    }
1781    else{
1782#endif
1783      /* We need to write the ExecuteResponse Document somewhere */
1784      FILE* output=fopen(stored_path,"w");
1785      if(output==NULL){
1786        /* If the file cannot be created return an ExceptionReport */
1787        char tmpMsg[1024];
1788        sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path);
1789
1790        errorException(m,tmpMsg,"InternalError",NULL);
1791        xmlFreeDoc(doc);
1792        xmlCleanupParser();
1793        zooXmlCleanupNs();
1794#ifndef RELY_ON_DB
1795        unlockShm(lid);
1796#endif
1797        return;
1798      }
1799      xmlChar *xmlbuff;
1800      int buffersize;
1801      xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1);
1802      fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output);
1803      xmlFree(xmlbuff);
1804      fclose(output);
1805#ifndef RELY_ON_DB
1806#ifdef DEBUG
1807      fprintf(stderr,"UNLOCK %s %d !\n",__FILE__,__LINE__);
1808#endif
1809      unlockShm(lid);
1810      map* v=getMapFromMaps(m,"lenv","sid");
1811      // Remove the lock when running as a normal task
1812      if(getpid()==atoi(v->value)){
1813        removeShmLock (m, 1);
1814      }
1815    }
1816#endif
1817  }
1818  printDocument(m,doc,pid);
1819
1820  xmlCleanupParser();
1821  zooXmlCleanupNs();
1822}
1823
1824/**
1825 * Print a XML document.
1826 *
1827 * @param m the conf maps containing the main.cfg settings
1828 * @param doc the XML document
1829 * @param pid the process identifier linked to a service
1830 */
1831void printDocument(maps* m, xmlDocPtr doc,int pid){
1832  char *encoding=getEncoding(m);
1833  if(pid==getpid()){
1834    printHeaders(m);
1835    printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
1836  }
1837  fflush(stdout);
1838  xmlChar *xmlbuff;
1839  int buffersize;
1840  /*
1841   * Dump the document to a buffer and print it on stdout
1842   * for demonstration purposes.
1843   */
1844  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
1845  printf("%s",xmlbuff);
1846  fflush(stdout);
1847  /*
1848   * Free associated memory.
1849   */
1850  xmlFree(xmlbuff);
1851  xmlFreeDoc(doc);
1852  xmlCleanupParser();
1853  zooXmlCleanupNs();
1854}
1855
1856/**
1857 * Print a XML document.
1858 *
1859 * @param doc the XML document (unused)
1860 * @param nc the XML node to add the output definition
1861 * @param ns_wps the wps XML namespace
1862 * @param ns_ows the ows XML namespace
1863 * @param e the output elements
1864 * @param m the conf maps containing the main.cfg settings
1865 * @param type the type (unused)
1866 */
1867void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){
1868  xmlNodePtr nc1;
1869  nc1=xmlNewNode(ns_wps, BAD_CAST type);
1870  map *tmp=NULL; 
1871  if(e!=NULL && e->defaults!=NULL)
1872    tmp=e->defaults->content;
1873  else{
1874    /*
1875    dumpElements(e);
1876    */
1877    return;
1878  }
1879  while(tmp!=NULL){
1880    if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0
1881       || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0
1882       || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0
1883       || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0)
1884    xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
1885    tmp=tmp->next;
1886  }
1887  tmp=getMap(e->defaults->content,"asReference");
1888  if(tmp==NULL)
1889    xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false");
1890
1891  tmp=e->content;
1892
1893  printDescription(nc1,ns_ows,m->name,e->content,0);
1894
1895  xmlAddChild(nc,nc1);
1896
1897}
1898
1899/**
1900 * Generate XML nodes describing inputs or outputs metadata.
1901 *
1902 * @param doc the XML document
1903 * @param nc the XML node to add the definition
1904 * @param ns_wps the wps namespace
1905 * @param ns_ows the ows namespace
1906 * @param ns_xlink the xlink namespace
1907 * @param e the output elements
1908 * @param m the conf maps containing the main.cfg settings
1909 * @param type the type
1910 */
1911void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){
1912
1913  xmlNodePtr nc1,nc2,nc3;
1914  nc1=xmlNewNode(ns_wps, BAD_CAST type);
1915  map *tmp=NULL;
1916  if(e!=NULL)
1917    tmp=e->content;
1918  else
1919    tmp=m->content;
1920
1921  if(vid==0){
1922    nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
1923    if(e!=NULL)
1924      nc3=xmlNewText(BAD_CAST e->name);
1925    else
1926      nc3=xmlNewText(BAD_CAST m->name);
1927   
1928    xmlAddChild(nc2,nc3);
1929    xmlAddChild(nc1,nc2);
1930 
1931    xmlAddChild(nc,nc1);
1932
1933    if(e!=NULL)
1934      tmp=getMap(e->content,"Title");
1935    else
1936      tmp=getMap(m->content,"Title");
1937   
1938    if(tmp!=NULL){
1939      nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
1940      nc3=xmlNewText(BAD_CAST _ss(tmp->value));
1941      xmlAddChild(nc2,nc3); 
1942      xmlAddChild(nc1,nc2);
1943    }
1944
1945    if(e!=NULL)
1946      tmp=getMap(e->content,"Abstract");
1947    else
1948      tmp=getMap(m->content,"Abstract");
1949
1950    if(tmp!=NULL){
1951      nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
1952      nc3=xmlNewText(BAD_CAST _ss(tmp->value));
1953      xmlAddChild(nc2,nc3); 
1954      xmlAddChild(nc1,nc2);
1955      xmlAddChild(nc,nc1);
1956    }
1957  }else{
1958    xmlNewProp(nc1,BAD_CAST "id",BAD_CAST (e!=NULL?e->name:m->name));
1959  }
1960
1961  /**
1962   * IO type Reference or full Data ?
1963   */
1964  map *tmpMap=getMap(m->content,"Reference");
1965  if(tmpMap==NULL){
1966    nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
1967    if(e!=NULL){
1968      if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
1969        nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
1970      else
1971        if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
1972          nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
1973        else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)
1974          nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
1975        else
1976          nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
1977    }
1978    else {
1979      map* tmpV=getMapFromMaps(m,"format","value");
1980      if(tmpV!=NULL)
1981        nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
1982      else
1983        nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
1984    } 
1985    tmp=m->content;
1986
1987    while(tmp!=NULL){
1988      if(strcasecmp(tmp->name,"mimeType")==0 ||
1989         strcasecmp(tmp->name,"encoding")==0 ||
1990         strcasecmp(tmp->name,"schema")==0 ||
1991         strcasecmp(tmp->name,"datatype")==0 ||
1992         strcasecmp(tmp->name,"uom")==0) {
1993       
1994        if(vid==0)
1995          xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
1996        else{
1997          if(strcasecmp(tmp->name,"datatype")==0)
1998            xmlNewProp(nc2,BAD_CAST "mimeType",BAD_CAST "text/plain");
1999          else
2000            if(strcasecmp(tmp->name,"uom")!=0)
2001              xmlNewProp(nc2,BAD_CAST tmp->name,BAD_CAST tmp->value);
2002        }
2003      }
2004      if(vid==0)
2005        xmlAddChild(nc2,nc3);
2006      tmp=tmp->next;
2007    }
2008    if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {
2009      map* bb=getMap(m->content,"value");
2010      if(bb!=NULL) {
2011        map* tmpRes=parseBoundingBox(bb->value);
2012        printBoundingBox(ns_ows,nc3,tmpRes);
2013        freeMap(&tmpRes);
2014        free(tmpRes);
2015      }
2016    }
2017    else {
2018      if(e!=NULL)
2019        tmp=getMap(e->defaults->content,"mimeType");
2020      else
2021        tmp=NULL;
2022       
2023      map* tmp1=getMap(m->content,"encoding");
2024      map* tmp2=getMap(m->content,"mimeType");
2025      map* tmp3=getMap(m->content,"value");
2026      int hasValue=1;
2027      if(tmp3==NULL){
2028        tmp3=createMap("value","");
2029        hasValue=-1;
2030      }
2031
2032      if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 )     // if encoding is base64
2033          ||                                                           // or if
2034          ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL       //  mime type is not text
2035                              &&                                       //  nor
2036                              strstr(tmp2->value,"xml") == NULL        //  xml
2037                              &&                                       // nor
2038                              strstr(tmp2->value,"javascript") == NULL // javascript
2039                              &&
2040                              strstr(tmp2->value,"json") == NULL
2041                              &&
2042                              strstr(tmp2->value,"ecmascript") == NULL
2043                              &&
2044                              // include for backwards compatibility,
2045                              // although correct mime type is ...kml+xml:
2046                              strstr(tmp2->value,"google-earth.kml") == NULL                                                    )
2047            )
2048          ) {                                                    // then       
2049        map* rs=getMap(m->content,"size");                       // obtain size
2050        bool isSized=true;
2051        if(rs==NULL){
2052          char tmp1[1024];
2053          sprintf(tmp1,"%ld",strlen(tmp3->value));
2054          rs=createMap("size",tmp1);
2055          isSized=false;
2056        }
2057         
2058        xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));  // base 64 encode in XML
2059               
2060        if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) {
2061          xmlAttrPtr ap = xmlHasProp((vid==0?nc3:nc2), BAD_CAST "encoding");
2062          if (ap != NULL) {
2063            xmlRemoveProp(ap);
2064          }                     
2065          xmlNewProp((vid==0?nc3:nc2),BAD_CAST "encoding",BAD_CAST "base64");
2066        }
2067               
2068        if(!isSized){
2069          freeMap(&rs);
2070          free(rs);
2071        }
2072      }
2073      else if (tmp2!=NULL) {                                 // else (text-based format)
2074        if(strstr(tmp2->value, "javascript") != NULL ||      //    if javascript put code in CDATA block
2075           strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader)
2076           strstr(tmp2->value, "ecmascript") != NULL
2077           ) {
2078          xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
2079        }   
2080        else {                                                     // else
2081          if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
2082              // include for backwards compatibility,
2083              // although correct mime type is ...kml+xml:                 
2084              strstr(tmp2->value, "google-earth.kml") != NULL
2085              ) { 
2086                         
2087            int li=zooXmlAddDoc(tmp3->value);
2088            xmlDocPtr doc = iDocs[li];
2089            xmlNodePtr ir = xmlDocGetRootElement(doc);
2090            xmlAddChild((vid==0?nc3:nc2),ir);
2091          }
2092          else                                                     // else     
2093            xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));    //   add text node
2094        }
2095        xmlAddChild(nc2,nc3);
2096      }
2097      else {
2098        xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));
2099      }
2100         
2101      if(hasValue<0) {
2102        freeMap(&tmp3);
2103        free(tmp3);
2104      }
2105    }
2106  }
2107  else { // Reference
2108    tmpMap=getMap(m->content,"Reference");
2109    nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference");
2110    if(strcasecmp(type,"Output")==0)
2111      xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value);
2112    else
2113      xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value);
2114   
2115    tmp=m->content;
2116    while(tmp!=NULL) {
2117      if(strcasecmp(tmp->name,"mimeType")==0 ||
2118         strcasecmp(tmp->name,"encoding")==0 ||
2119         strcasecmp(tmp->name,"schema")==0 ||
2120         strcasecmp(tmp->name,"datatype")==0 ||
2121         strcasecmp(tmp->name,"uom")==0){
2122
2123        if(strcasecmp(tmp->name,"datatype")==0)
2124          xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
2125        else
2126          xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
2127      }
2128      tmp=tmp->next;
2129      xmlAddChild(nc2,nc3);
2130    }
2131  }
2132  xmlAddChild(nc1,nc2);
2133  xmlAddChild(nc,nc1);
2134}
2135
2136/**
2137 * Create XML node with basic ows metadata information (Identifier,Title,Abstract)
2138 *
2139 * @param root the root XML node to add the description
2140 * @param ns_ows the ows XML namespace
2141 * @param identifier the identifier to use
2142 * @param amap the map containing the ows metadata information
2143 */
2144void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap,int vid=0){
2145  xmlNodePtr nc2;
2146  if(vid==0){
2147    nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
2148    xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
2149    xmlAddChild(root,nc2);
2150  }
2151  map* tmp=amap;
2152  const char *tmp2[2];
2153  tmp2[0]="Title";
2154  tmp2[1]="Abstract";
2155  int j=0;
2156  for(j=0;j<2;j++){
2157    map* tmp1=getMap(tmp,tmp2[j]);
2158    if(tmp1!=NULL){
2159      nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]);
2160      xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value)));
2161      xmlAddChild(root,nc2);
2162    }
2163  }
2164  if(vid==1){
2165    nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
2166    xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
2167    xmlAddChild(root,nc2);
2168  }
2169}
2170
2171/**
2172 * Print an OWS ExceptionReport Document and HTTP headers (when required)
2173 * depending on the code.
2174 * Set hasPrinted value to true in the [lenv] section.
2175 *
2176 * @param m the maps containing the settings of the main.cfg file
2177 * @param s the map containing the text,code,locator keys
2178 */
2179void printExceptionReportResponse(maps* m,map* s){
2180  if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
2181    return;
2182  int buffersize;
2183  xmlDocPtr doc;
2184  xmlChar *xmlbuff;
2185  xmlNodePtr n;
2186
2187  zooXmlCleanupNs();
2188  doc = xmlNewDoc(BAD_CAST "1.0");
2189  maps* tmpMap=getMaps(m,"main");
2190  char *encoding=getEncoding(tmpMap);
2191  const char *exceptionCode;
2192 
2193  map* tmp=getMap(s,"code");
2194  if(tmp!=NULL){
2195    if(strcmp(tmp->value,"OperationNotSupported")==0 ||
2196       strcmp(tmp->value,"NoApplicableCode")==0)
2197      exceptionCode="501 Not Implemented";
2198    else
2199      if(strcmp(tmp->value,"MissingParameterValue")==0 ||
2200         strcmp(tmp->value,"InvalidUpdateSequence")==0 ||
2201         strcmp(tmp->value,"OptionNotSupported")==0 ||
2202         strcmp(tmp->value,"VersionNegotiationFailed")==0 ||
2203         strcmp(tmp->value,"InvalidParameterValue")==0)
2204        exceptionCode="400 Bad request";
2205      else
2206        exceptionCode="501 Internal Server Error";
2207  }
2208  else
2209    exceptionCode="501 Internal Server Error";
2210
2211  if(m!=NULL){
2212    map *tmpSid=getMapFromMaps(m,"lenv","sid");
2213    if(tmpSid!=NULL){
2214      if( getpid()==atoi(tmpSid->value) ){
2215        printHeaders(m);
2216        printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2217      }
2218    }
2219    else{
2220      printHeaders(m);
2221      printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2222    }
2223  }else{
2224    printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
2225  }
2226  n=createExceptionReportNode(m,s,1);
2227  xmlDocSetRootElement(doc, n);
2228  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2229  printf("%s",xmlbuff);
2230  fflush(stdout);
2231  xmlFreeDoc(doc);
2232  xmlFree(xmlbuff);
2233  xmlCleanupParser();
2234  zooXmlCleanupNs();
2235  if(m!=NULL)
2236    setMapInMaps(m,"lenv","hasPrinted","true");
2237}
2238
2239/**
2240 * Create an OWS ExceptionReport Node.
2241 *
2242 * @param m the conf maps
2243 * @param s the map containing the text,code,locator keys
2244 * @param use_ns (0/1) choose if you want to generate an ExceptionReport or
2245 *  ows:ExceptionReport node respectively
2246 * @return the ExceptionReport/ows:ExceptionReport node
2247 */
2248xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){
2249 
2250  xmlNsPtr ns,ns_xsi;
2251  xmlNodePtr n,nc,nc1;
2252
2253  int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows");
2254  ns=usedNs[nsid];
2255  if(use_ns==0){
2256    ns=NULL;
2257  }
2258  n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
2259  map* version=getMapFromMaps(m,"main","rversion");
2260  int vid=-1;
2261  if(version!=NULL)
2262    vid=getVersionId(version->value);
2263  if(vid<0)
2264    vid=0;
2265  if(use_ns==1){
2266    xmlNewNs(n,BAD_CAST schemas[vid][1],BAD_CAST"ows");
2267    int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
2268    ns_xsi=usedNs[xsiId];
2269    char tmp[1024];
2270    sprintf(tmp,"%s %s",schemas[vid][1],schemas[vid][5]);
2271    xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp);
2272  }
2273
2274
2275  addLangAttr(n,m);
2276  xmlNewProp(n,BAD_CAST "version",BAD_CAST schemas[vid][6]);
2277 
2278  int length=1;
2279  int cnt=0;
2280  map* len=getMap(s,"length");
2281  if(len!=NULL)
2282    length=atoi(len->value);
2283  for(cnt=0;cnt<length;cnt++){
2284    nc = xmlNewNode(ns, BAD_CAST "Exception");
2285   
2286    map* tmp=getMapArray(s,"code",cnt);
2287    if(tmp==NULL)
2288      tmp=getMap(s,"code");
2289    if(tmp!=NULL)
2290      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value);
2291    else
2292      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode");
2293   
2294    tmp=getMapArray(s,"locator",cnt);
2295    if(tmp==NULL)
2296      tmp=getMap(s,"locator");
2297    if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0)
2298      xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value);
2299
2300    tmp=getMapArray(s,"text",cnt);
2301    nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
2302    if(tmp!=NULL){
2303      xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
2304      xmlAddChild(nc1,txt);
2305    }
2306    else{
2307      xmlNodeSetContent(nc1, BAD_CAST _("No debug message available"));
2308    }
2309    xmlAddChild(nc,nc1);
2310    xmlAddChild(n,nc);
2311  }
2312  return n;
2313}
2314
2315/**
2316 * Print an OWS ExceptionReport.
2317 *
2318 * @param m the conf maps
2319 * @param message the error message
2320 * @param errorcode the error code
2321 * @param locator the potential locator
2322 */
2323int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 
2324{
2325  map* errormap = createMap("text", message);
2326  addToMap(errormap,"code", errorcode);
2327  if(locator!=NULL)
2328    addToMap(errormap,"locator", locator);
2329  else
2330    addToMap(errormap,"locator", "NULL");
2331  printExceptionReportResponse(m,errormap);
2332  freeMap(&errormap);
2333  free(errormap);
2334  return -1;
2335}
2336
2337/**
2338 * Generate the output response (RawDataOutput or ResponseDocument)
2339 *
2340 * @param s the service structure containing the metadata information
2341 * @param request_inputs the inputs provided to the service for execution
2342 * @param request_outputs the outputs updated by the service execution
2343 * @param request_inputs1 the map containing the HTTP request
2344 * @param cpid the process identifier attached to a service execution
2345 * @param m the conf maps containing the main.cfg settings
2346 * @param res the value returned by the service execution
2347 */
2348void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
2349                    map* request_inputs1,int cpid,maps* m,int res){
2350#ifdef DEBUG
2351  dumpMaps(request_inputs);
2352  dumpMaps(request_outputs);
2353  fprintf(stderr,"printProcessResponse\n");
2354#endif
2355  map* toto=getMap(request_inputs1,"RawDataOutput");
2356  int asRaw=0;
2357  if(toto!=NULL)
2358    asRaw=1;
2359  map* version=getMapFromMaps(m,"main","rversion");
2360  int vid=getVersionId(version->value);
2361
2362  maps* tmpSess=getMaps(m,"senv");
2363  if(tmpSess!=NULL){
2364    map *_tmp=getMapFromMaps(m,"lenv","cookie");
2365    char* sessId=NULL;
2366    if(_tmp!=NULL){
2367      printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
2368      printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
2369      char session_file_path[100];
2370      char *tmp1=strtok(_tmp->value,";");
2371      if(tmp1!=NULL)
2372        sprintf(session_file_path,"%s",strstr(tmp1,"=")+1);
2373      else
2374        sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1);
2375      sessId=strdup(session_file_path);
2376    }else{
2377      maps* t=getMaps(m,"senv");
2378      map*p=t->content;
2379      while(p!=NULL){
2380        if(strstr(p->name,"ID")!=NULL){
2381          sessId=strdup(p->value);
2382          break;
2383        }
2384        p=p->next;
2385      }
2386    }
2387    char session_file_path[1024];
2388    map *tmpPath=getMapFromMaps(m,"main","sessPath");
2389    if(tmpPath==NULL)
2390      tmpPath=getMapFromMaps(m,"main","tmpPath");
2391    sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId);
2392    FILE* teste=fopen(session_file_path,"w");
2393    if(teste==NULL){
2394      char tmpMsg[1024];
2395      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
2396      errorException(m,tmpMsg,"InternalError",NULL);
2397
2398      return;
2399    }
2400    else{
2401      fclose(teste);
2402      dumpMapsToFile(tmpSess,session_file_path,1);
2403    }
2404  }
2405 
2406  if(res==SERVICE_FAILED){
2407    map *lenv;
2408    lenv=getMapFromMaps(m,"lenv","message");
2409    char *tmp0;
2410    if(lenv!=NULL){
2411      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));
2412      sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value);
2413    }
2414    else{
2415      tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char));
2416      sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service."));
2417    }
2418    errorException(m,tmp0,"InternalError",NULL);
2419    free(tmp0);
2420    return;
2421  }
2422
2423  if(res==SERVICE_ACCEPTED && vid==1){
2424    map* statusInfo=createMap("Status","Accepted");
2425    map *usid=getMapFromMaps(m,"lenv","usid");
2426    addToMap(statusInfo,"JobID",usid->value);
2427    printStatusInfo(m,statusInfo,"Execute");
2428    freeMap(&statusInfo);
2429    free(statusInfo);
2430    return;
2431  }
2432
2433  map *tmp1=getMapFromMaps(m,"main","tmpPath");
2434  if(asRaw==0){
2435#ifdef DEBUG
2436    fprintf(stderr,"REQUEST_OUTPUTS FINAL\n");
2437    dumpMaps(request_outputs);
2438#endif
2439    maps* tmpI=request_outputs;
2440    map* usid=getMapFromMaps(m,"lenv","usid");
2441    int itn=0;
2442    while(tmpI!=NULL){
2443#ifdef USE_MS
2444      map* testMap=getMap(tmpI->content,"useMapserver");       
2445#endif
2446      map *gfile=getMap(tmpI->content,"generated_file");
2447      char *file_name;
2448      if(gfile!=NULL){
2449        gfile=getMap(tmpI->content,"expected_generated_file");
2450        if(gfile==NULL){
2451          gfile=getMap(tmpI->content,"generated_file");
2452        }
2453        readGeneratedFile(m,tmpI->content,gfile->value);           
2454        file_name=(char*)malloc((strlen(gfile->value)+strlen(tmp1->value)+1)*sizeof(char));
2455        for(int i=0;i<strlen(gfile->value);i++)
2456          file_name[i]=gfile->value[i+strlen(tmp1->value)];
2457      }
2458
2459      toto=getMap(tmpI->content,"asReference");
2460#ifdef USE_MS
2461      if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL)
2462#else
2463      if(toto!=NULL && strcasecmp(toto->value,"true")==0)
2464#endif
2465        {
2466          elements* in=getElements(s->outputs,tmpI->name);
2467          char *format=NULL;
2468          if(in!=NULL && in->format!=NULL){
2469            format=zStrdup(in->format);
2470          }else
2471            format=zStrdup("LiteralData");
2472          if(strcasecmp(format,"BoundingBoxData")==0){
2473            addToMap(tmpI->content,"extension","xml");
2474            addToMap(tmpI->content,"mimeType","text/xml");
2475            addToMap(tmpI->content,"encoding","UTF-8");
2476            addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
2477          }
2478
2479          if(gfile==NULL) {
2480            map *ext=getMap(tmpI->content,"extension");
2481            char *file_path;
2482            char file_ext[32];
2483
2484            if( ext != NULL && ext->value != NULL) {
2485              strncpy(file_ext, ext->value, 32);
2486            }
2487            else {
2488              // Obtain default file extension (see mimetypes.h).             
2489              // If the MIME type is not recognized, txt is used as the default extension
2490              map* mtype=getMap(tmpI->content,"mimeType");
2491              getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
2492            }
2493
2494            file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
2495            sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
2496            itn++;
2497            file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
2498            sprintf(file_path,"%s/%s",tmp1->value,file_name);
2499
2500            FILE *ofile=fopen(file_path,"wb");
2501            if(ofile==NULL){
2502              char tmpMsg[1024];
2503              sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
2504              errorException(m,tmpMsg,"InternalError",NULL);
2505              free(file_name);
2506              free(file_path);
2507              return;
2508            }
2509            free(file_path);
2510
2511            toto=getMap(tmpI->content,"value");
2512            if(strcasecmp(format,"BoundingBoxData")!=0){
2513              map* size=getMap(tmpI->content,"size");
2514              if(size!=NULL && toto!=NULL)
2515                fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
2516              else
2517                if(toto!=NULL && toto->value!=NULL)
2518                  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
2519            }else{
2520              printBoundingBoxDocument(m,tmpI,ofile);
2521            }
2522            fclose(ofile);
2523
2524          }
2525
2526          map *tmp2=getMapFromMaps(m,"main","tmpUrl");
2527          map *tmp3=getMapFromMaps(m,"main","serverAddress");
2528          char *file_url;
2529          if(strncasecmp(tmp2->value,"http://",7)==0 ||
2530             strncasecmp(tmp2->value,"https://",8)==0){
2531            file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
2532            sprintf(file_url,"%s/%s",tmp2->value,file_name);
2533          }else{
2534            file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
2535            sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
2536          }
2537
2538          addToMap(tmpI->content,"Reference",file_url);
2539          free(format);
2540          free(file_name);
2541          free(file_url);
2542         
2543        }
2544#ifdef USE_MS
2545      else{
2546        if(testMap!=NULL){
2547          setReferenceUrl(m,tmpI);
2548        }
2549      }
2550#endif
2551      tmpI=tmpI->next;
2552    }
2553#ifdef DEBUG
2554    fprintf(stderr,"SERVICE : %s\n",s->name);
2555    dumpMaps(m);
2556#endif
2557    printProcessResponse(m,request_inputs1,cpid,
2558                         s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
2559                         request_inputs,
2560                         request_outputs);
2561  }
2562  else{
2563    /**
2564     * We get the requested output or fallback to the first one if the
2565     * requested one is not present in the resulting outputs maps.
2566     */
2567    maps* tmpI=NULL;
2568    map* tmpIV=getMap(request_inputs1,"RawDataOutput");
2569    if(tmpIV!=NULL){
2570      tmpI=getMaps(request_outputs,tmpIV->value);
2571    }
2572    if(tmpI==NULL)
2573      tmpI=request_outputs;
2574    elements* e=getElements(s->outputs,tmpI->name);
2575    if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
2576      printBoundingBoxDocument(m,tmpI,NULL);
2577    }else{
2578      map *gfile=getMap(tmpI->content,"generated_file");
2579      if(gfile!=NULL){
2580        gfile=getMap(tmpI->content,"expected_generated_file");
2581        if(gfile==NULL){
2582          gfile=getMap(tmpI->content,"generated_file");
2583        }
2584        readGeneratedFile(m,tmpI->content,gfile->value);
2585      }
2586      toto=getMap(tmpI->content,"value");
2587      if(toto==NULL){
2588        char tmpMsg[1024];
2589        sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name);
2590        errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
2591        return;
2592      }
2593      map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
2594      if(fname!=NULL)
2595        printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
2596      map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
2597      if(rs!=NULL)
2598        printf("Content-Length: %s\r\n",rs->value);
2599      printHeaders(m);
2600      char mime[1024];
2601      map* mi=getMap(tmpI->content,"mimeType");
2602#ifdef DEBUG
2603      fprintf(stderr,"SERVICE OUTPUTS\n");
2604      dumpMaps(request_outputs);
2605      fprintf(stderr,"SERVICE OUTPUTS\n");
2606#endif
2607      map* en=getMap(tmpI->content,"encoding");
2608      if(mi!=NULL && en!=NULL)
2609        sprintf(mime,
2610                "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
2611                mi->value,en->value);
2612      else
2613        if(mi!=NULL)
2614          sprintf(mime,
2615                  "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
2616                  mi->value);
2617        else
2618          sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
2619      printf("%s",mime);
2620      if(rs!=NULL)
2621        fwrite(toto->value,1,atoi(rs->value),stdout);
2622      else
2623        fwrite(toto->value,1,strlen(toto->value),stdout);
2624#ifdef DEBUG
2625      dumpMap(toto);
2626#endif
2627    }
2628  }
2629}
2630
2631/**
2632 * Create required XML nodes for boundingbox and update the current XML node
2633 *
2634 * @param ns_ows the ows XML namespace
2635 * @param n the XML node to update
2636 * @param boundingbox the map containing the boundingbox definition
2637 */
2638void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){
2639
2640  xmlNodePtr lw=NULL,uc=NULL;
2641
2642  map* tmp=getMap(boundingbox,"value");
2643
2644  tmp=getMap(boundingbox,"lowerCorner");
2645  if(tmp!=NULL){
2646    lw=xmlNewNode(ns_ows,BAD_CAST "LowerCorner");
2647    xmlAddChild(lw,xmlNewText(BAD_CAST tmp->value));
2648  }
2649
2650  tmp=getMap(boundingbox,"upperCorner");
2651  if(tmp!=NULL){
2652    uc=xmlNewNode(ns_ows,BAD_CAST "UpperCorner");
2653    xmlAddChild(uc,xmlNewText(BAD_CAST tmp->value));
2654  }
2655
2656  tmp=getMap(boundingbox,"crs");
2657  if(tmp!=NULL)
2658    xmlNewProp(n,BAD_CAST "crs",BAD_CAST tmp->value);
2659
2660  tmp=getMap(boundingbox,"dimensions");
2661  if(tmp!=NULL)
2662    xmlNewProp(n,BAD_CAST "dimensions",BAD_CAST tmp->value);
2663
2664  xmlAddChild(n,lw);
2665  xmlAddChild(n,uc);
2666
2667}
2668
2669/**
2670 * Parse a BoundingBox string
2671 *
2672 * [OGC 06-121r3](http://portal.opengeospatial.org/files/?artifact_id=20040):
2673 *  10.2 Bounding box
2674 *
2675 *
2676 * Value is provided as : lowerCorner,upperCorner,crs,dimension
2677 * Exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84
2678 *
2679 * A map to store boundingbox information should contain:
2680 *  - lowerCorner : double,double (minimum within this bounding box)
2681 *  - upperCorner : double,double (maximum within this bounding box)
2682 *  - crs : URI (Reference to definition of the CRS)
2683 *  - dimensions : int
2684 *
2685 * Note : support only 2D bounding box.
2686 *
2687 * @param value the char* containing the KVP bouding box
2688 * @return a map containing all the bounding box keys
2689 */
2690map* parseBoundingBox(const char* value){
2691  map *res=NULL;
2692  if(value!=NULL){
2693    char *cv,*cvp;
2694    cv=strtok_r((char*) value,",",&cvp);
2695    int cnt=0;
2696    int icnt=0;
2697    char *currentValue=NULL;
2698    while(cv){
2699      if(cnt<2)
2700        if(currentValue!=NULL){
2701          char *finalValue=(char*)malloc((strlen(currentValue)+strlen(cv)+1)*sizeof(char));
2702          sprintf(finalValue,"%s%s",currentValue,cv);
2703          switch(cnt){
2704          case 0:
2705            res=createMap("lowerCorner",finalValue);
2706            break;
2707          case 1:
2708            addToMap(res,"upperCorner",finalValue);
2709            icnt=-1;
2710            break;
2711          }
2712          cnt++;
2713          free(currentValue);
2714          currentValue=NULL;
2715          free(finalValue);
2716        }
2717        else{
2718          currentValue=(char*)malloc((strlen(cv)+2)*sizeof(char));
2719          sprintf(currentValue,"%s ",cv);
2720        }
2721      else
2722        if(cnt==2){
2723          addToMap(res,"crs",cv);
2724          cnt++;
2725        }
2726        else
2727          addToMap(res,"dimensions",cv);
2728      icnt++;
2729      cv=strtok_r(NULL,",",&cvp);
2730    }
2731  }
2732  return res;
2733}
2734
2735/**
2736 * Print an ows:BoundingBox XML document
2737 *
2738 * @param m the maps containing the settings of the main.cfg file
2739 * @param boundingbox the maps containing the boundingbox definition
2740 * @param file the file to print the BoundingBox (if NULL then print on stdout)
2741 * @see parseBoundingBox, printBoundingBox
2742 */
2743void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){
2744  if(file==NULL)
2745    rewind(stdout);
2746  xmlNodePtr n;
2747  xmlDocPtr doc;
2748  xmlNsPtr ns_ows,ns_xsi;
2749  xmlChar *xmlbuff;
2750  int buffersize;
2751  char *encoding=getEncoding(m);
2752  map *tmp;
2753  if(file==NULL){
2754    int pid=0;
2755    tmp=getMapFromMaps(m,"lenv","sid");
2756    if(tmp!=NULL)
2757      pid=atoi(tmp->value);
2758    if(pid==getpid()){
2759      printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
2760    }
2761    fflush(stdout);
2762  }
2763
2764  doc = xmlNewDoc(BAD_CAST "1.0");
2765  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
2766  ns_ows=usedNs[owsId];
2767  n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox");
2768  xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
2769  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
2770  ns_xsi=usedNs[xsiId];
2771  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");
2772  map *tmp1=getMap(boundingbox->content,"value");
2773  tmp=parseBoundingBox(tmp1->value);
2774  printBoundingBox(ns_ows,n,tmp);
2775  xmlDocSetRootElement(doc, n);
2776
2777  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2778  if(file==NULL)
2779    printf("%s",xmlbuff);
2780  else{
2781    fprintf(file,"%s",xmlbuff);
2782  }
2783
2784  if(tmp!=NULL){
2785    freeMap(&tmp);
2786    free(tmp);
2787  }
2788  xmlFree(xmlbuff);
2789  xmlFreeDoc(doc);
2790  xmlCleanupParser();
2791  zooXmlCleanupNs();
2792 
2793}
2794
2795/**
2796 * Print a StatusInfo XML document.
2797 * a statusInfo map should contain the following keys:
2798 *  * JobID corresponding to usid key from the lenv section
2799 *  * Status the current state (Succeeded,Failed,Accepted,Running)
2800 *  * PercentCompleted (optional) the percent completed
2801 *  * Message (optional) any messages the service may wish to share
2802 *
2803 * @param conf the maps containing the settings of the main.cfg file
2804 * @param statusInfo the map containing the statusInfo definition
2805 * @param req the WPS requests (GetResult, GetStatus or Dismiss)
2806 */
2807void printStatusInfo(maps* conf,map* statusInfo,char* req){
2808  rewind(stdout);
2809  xmlNodePtr n,n1;
2810  xmlDocPtr doc;
2811  xmlNsPtr ns;
2812  xmlChar *xmlbuff;
2813  int buffersize;
2814  char *encoding=getEncoding(conf);
2815  map *tmp;
2816  int pid=0;
2817  printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
2818
2819  map* version=getMapFromMaps(conf,"main","rversion");
2820  int vid=getVersionId(version->value);
2821
2822  doc = xmlNewDoc(BAD_CAST "1.0");
2823  n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1);
2824
2825  map* val=getMap(statusInfo,"JobID");
2826  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
2827  ns=usedNs[wpsId];
2828  n = xmlNewNode(ns, BAD_CAST "JobID");
2829  xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2830
2831  xmlAddChild(n1,n);
2832
2833  val=getMap(statusInfo,"Status");
2834  n = xmlNewNode(ns, BAD_CAST "Status");
2835  xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2836
2837  xmlAddChild(n1,n);
2838
2839  if(strncasecmp(val->value,"Failed",6)!=0 &&
2840     strncasecmp(val->value,"Succeeded",9)!=0){
2841    val=getMap(statusInfo,"PercentCompleted");
2842    if(val!=NULL){
2843      n = xmlNewNode(ns, BAD_CAST "PercentCompleted");
2844      xmlAddChild(n,xmlNewText(BAD_CAST val->value));
2845      xmlAddChild(n1,n);
2846    }
2847
2848    val=getMap(statusInfo,"Message");
2849    if(val!=NULL){   
2850      xmlAddChild(n1,xmlNewComment(BAD_CAST val->value));
2851    }
2852  }
2853  xmlDocSetRootElement(doc, n1);
2854
2855  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
2856  printf("%s",xmlbuff);
2857
2858  xmlFree(xmlbuff);
2859  xmlFreeDoc(doc);
2860  xmlCleanupParser();
2861  zooXmlCleanupNs();
2862 
2863}
2864
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