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

Last change on this file since 788 was 788, checked in by knut, 7 years ago

Implemented support for PHP 7: The Zend API for PHP 7/PHPNG is substantially different from older versions. Therefore, an alternative implementation of zoo_php_support is provided in the new source file service_internal_php7.c. Presently the Zoo kernel can be built with support for either PHP 7 or older versions, see the makefiles (for Windows) nmake.opt and makefile.vc. Other makefiles have not been updated.

Fixed problem with ambiguous symbol in service_conf.y. Fixed problem with conversion of line endings yielding extra bytes in _getStatusFile on Windows platforms. Removed call to free() stack memory in zoo_service_loader.c. Fixed issue with size of structs in service.h.

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