source: trunk/zoo-project/zoo-kernel/zoo_service_loader.c @ 601

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

Implemented default result file extensions for many MIME types, based on Apache's mime.types list. Added file mimetypes.h. Made function printIOType more general with respect to media content. Rewrote the XML parsing of the <ResponseDocument?> block in Execute requests to fix problem caused by one output variable inheriting properties from another. Minor memory allocation modification in zoo_loader.c.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 112.4 KB
Line 
1/**
2 * Author : Gérald FENOY
3 *
4 *  Copyright 2008-2013 GeoLabs SARL. All rights reserved.
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
26
27extern "C" int yylex ();
28extern "C" int crlex ();
29
30#ifdef USE_OTB
31#include "service_internal_otb.h"
32#else
33#define length(x) (sizeof(x) / sizeof(x[0]))
34#endif
35
36#include "cgic.h"
37
38extern "C"
39{
40#include <libxml/tree.h>
41#include <libxml/xmlmemory.h>
42#include <libxml/parser.h>
43#include <libxml/xpath.h>
44#include <libxml/xpathInternals.h>
45}
46
47#include "ulinet.h"
48
49#include <libintl.h>
50#include <locale.h>
51#include <string.h>
52
53#include "service.h"
54
55#include "service_internal.h"
56
57#ifdef USE_PYTHON
58#include "service_internal_python.h"
59#endif
60
61#ifdef USE_JAVA
62#include "service_internal_java.h"
63#endif
64
65#ifdef USE_PHP
66#include "service_internal_php.h"
67#endif
68
69#ifdef USE_JS
70#include "service_internal_js.h"
71#endif
72
73#ifdef USE_RUBY
74#include "service_internal_ruby.h"
75#endif
76
77#ifdef USE_PERL
78#include "service_internal_perl.h"
79#endif
80
81#include <dirent.h>
82#include <signal.h>
83#include <unistd.h>
84#ifndef WIN32
85#include <dlfcn.h>
86#include <libgen.h>
87#else
88#include <windows.h>
89#include <direct.h>
90#include <sys/types.h>
91#include <sys/stat.h>
92#include <unistd.h>
93#define pid_t int;
94#endif
95#include <fcntl.h>
96#include <time.h>
97#include <stdarg.h>
98
99#ifdef WIN32
100extern "C"
101{
102  __declspec (dllexport) char *strcasestr (char const *a, char const *b)
103#ifndef USE_MS
104  {
105    char *x = zStrdup (a);
106    char *y = zStrdup (b);
107
108      x = _strlwr (x);
109      y = _strlwr (y);
110    char *pos = strstr (x, y);
111    char *ret = pos == NULL ? NULL : (char *) (a + (pos - x));
112      free (x);
113      free (y);
114      return ret;
115  };
116#else
117   ;
118#endif
119}
120#endif
121
122#define _(String) dgettext ("zoo-kernel",String)
123#define __(String) dgettext ("zoo-service",String)
124
125#ifdef WIN32
126  #ifndef PROGRAMNAME
127    #define PROGRAMNAME "zoo_loader.cgi"
128  #endif
129#endif
130
131extern int getServiceFromFile (maps *, const char *, service **);
132
133int
134readServiceFile (maps * conf, char *file, service ** service, char *name)
135{
136  int t = getServiceFromFile (conf, file, service);
137#ifdef YAML
138  if (t < 0)
139    {
140      t = getServiceFromYAML (conf, file, service, name);
141    }
142#endif
143  return t;
144}
145
146void
147translateChar (char *str, char toReplace, char toReplaceBy)
148{
149  int i = 0, len = strlen (str);
150  for (i = 0; i < len; i++)
151    {
152      if (str[i] == toReplace)
153        str[i] = toReplaceBy;
154    }
155}
156
157/**
158 * Create (or append to) an array valued maps
159 * value = "["",""]"
160 */
161int
162appendMapsToMaps (maps * m, maps * mo, maps * mi, elements * elem)
163{
164  maps *tmpMaps = getMaps (mo, mi->name);
165  map *tmap = getMapType (tmpMaps->content);
166  elements *el = getElements (elem, mi->name);
167  int hasEl = 1;
168  if (el == NULL)
169    hasEl = -1;
170  if (tmap == NULL)
171    {
172      if (hasEl > 0)
173        tmap = getMapType (el->defaults->content);
174    }
175
176  map *testMap = NULL;
177  if (hasEl > 0)
178    {
179      testMap = getMap (el->content, "maxOccurs");
180    }
181  else
182    {
183      testMap = createMap ("maxOccurs", "unbounded");
184    }
185
186  if (testMap != NULL)
187    {
188      if (strncasecmp (testMap->value, "unbounded", 9) != 0
189          && atoi (testMap->value) > 1)
190        {
191          addMapsArrayToMaps (&mo, mi, tmap->name);
192          map* nb=getMapFromMaps(mo,mi->name,"length");
193          if (nb!=NULL && atoi(nb->value)>atoi(testMap->value))
194            {
195              char emsg[1024];
196              sprintf (emsg,
197                       _("You set maximum occurences for <%s> as %i but you tried to use it more than the limit you set. Please correct your ZCFG file or your request."),
198                       mi->name, atoi (testMap->value));
199              errorException (m, emsg, "InternalError", NULL);
200              return -1;
201            }
202        }
203      else
204        {
205          if (strncasecmp (testMap->value, "unbounded", 9) == 0)
206            {
207              if (hasEl < 0)
208                {
209                  freeMap (&testMap);
210                  free (testMap);
211                }
212              if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0)
213                {
214                  char emsg[1024];
215                  map *tmpMap = getMap (mi->content, "length");
216                  sprintf (emsg,
217                           _
218                           ("ZOO-Kernel was unable to load your data for %s position %s."),
219                           mi->name, tmpMap->value);
220                  errorException (m, emsg, "InternalError", NULL);
221                  return -1;
222                }
223            }
224          else
225            {
226              char emsg[1024];
227              sprintf (emsg,
228                       _
229                       ("You set maximum occurences for <%s> to one but you tried to use it more than once. Please correct your ZCFG file or your request."),
230                       mi->name);
231              errorException (m, emsg, "InternalError", NULL);
232              return -1;
233            }
234        }
235    }
236  return 0;
237}
238
239int
240recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix,
241                int saved_stdout, int level, void (func) (maps *, xmlNodePtr,
242                                                          service *))
243{
244  struct dirent *dp;
245  int scount = 0;
246
247  if (conf_dir == NULL)
248    return 1;
249  DIR *dirp = opendir (conf_dir);
250  if (dirp == NULL)
251    {
252      if (level > 0)
253        return 1;
254      else
255        return -1;
256    }
257  char tmp1[25];
258  sprintf (tmp1, "sprefix_%d", level);
259  char levels[17];
260  sprintf (levels, "%d", level);
261  setMapInMaps (m, "lenv", "level", levels);
262  while ((dp = readdir (dirp)) != NULL)
263    if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.'
264        && strstr (dp->d_name, ".") == NULL)
265      {
266
267        char *tmp =
268          (char *) malloc ((strlen (conf_dir) + strlen (dp->d_name) + 2) *
269                           sizeof (char));
270        sprintf (tmp, "%s/%s", conf_dir, dp->d_name);
271
272        if (prefix != NULL)
273          {
274            prefix = NULL;
275          }
276        prefix = (char *) malloc ((strlen (dp->d_name) + 2) * sizeof (char));
277        sprintf (prefix, "%s.", dp->d_name);
278
279        //map* tmpMap=getMapFromMaps(m,"lenv",tmp1);
280
281        int res;
282        if (prefix != NULL)
283          {
284            setMapInMaps (m, "lenv", tmp1, prefix);
285            char levels1[17];
286            sprintf (levels1, "%d", level + 1);
287            setMapInMaps (m, "lenv", "level", levels1);
288            res =
289              recursReaddirF (m, n, tmp, prefix, saved_stdout, level + 1,
290                              func);
291            sprintf (levels1, "%d", level);
292            setMapInMaps (m, "lenv", "level", levels1);
293            free (prefix);
294            prefix = NULL;
295          }
296        else
297          res = -1;
298        free (tmp);
299        if (res < 0)
300          {
301            return res;
302          }
303      }
304    else
305      {
306        char* extn = strstr(dp->d_name, ".zcfg");
307        if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5)
308          {
309            int t;
310            char tmps1[1024];
311            memset (tmps1, 0, 1024);
312            snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name);
313            service *s1 = (service *) malloc (SERVICE_SIZE);
314            if (s1 == NULL)
315              {
316                dup2 (saved_stdout, fileno (stdout));
317                errorException (m, _("Unable to allocate memory."),
318                                "InternalError", NULL);
319                return -1;
320              }
321#ifdef DEBUG
322            fprintf (stderr, "#################\n%s\n#################\n",
323                     tmps1);
324#endif
325            char *tmpsn = zStrdup (dp->d_name);
326            tmpsn[strlen (tmpsn) - 5] = 0;
327            t = readServiceFile (m, tmps1, &s1, tmpsn);
328            free (tmpsn);
329            if (t < 0)
330              {
331                map *tmp00 = getMapFromMaps (m, "lenv", "message");
332                char tmp01[1024];
333                if (tmp00 != NULL)
334                  sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"),
335                           dp->d_name, tmp00->value);
336                else
337                  sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
338                           dp->d_name);
339                dup2 (saved_stdout, fileno (stdout));
340                errorException (m, tmp01, "InternalError", NULL);
341                return -1;
342              }
343#ifdef DEBUG
344            dumpService (s1);
345            fflush (stdout);
346            fflush (stderr);
347#endif
348            func (m, n, s1);
349            freeService (&s1);
350            free (s1);
351            scount++;
352          }
353      }
354  (void) closedir (dirp);
355  return 1;
356}
357
358xmlXPathObjectPtr
359extractFromDoc (xmlDocPtr doc, const char *search)
360{
361  xmlXPathContextPtr xpathCtx;
362  xmlXPathObjectPtr xpathObj;
363  xpathCtx = xmlXPathNewContext (doc);
364  xpathObj = xmlXPathEvalExpression (BAD_CAST search, xpathCtx);
365  xmlXPathFreeContext (xpathCtx);
366  return xpathObj;
367}
368
369void
370donothing (int sig)
371{
372#ifdef DEBUG
373  fprintf (stderr, "Signal %d after the ZOO-Kernel returned result !\n", sig);
374#endif
375  exit (0);
376}
377
378void
379sig_handler (int sig)
380{
381  char tmp[100];
382  const char *ssig;
383  switch (sig)
384    {
385    case SIGSEGV:
386      ssig = "SIGSEGV";
387      break;
388    case SIGTERM:
389      ssig = "SIGTERM";
390      break;
391    case SIGINT:
392      ssig = "SIGINT";
393      break;
394    case SIGILL:
395      ssig = "SIGILL";
396      break;
397    case SIGFPE:
398      ssig = "SIGFPE";
399      break;
400    case SIGABRT:
401      ssig = "SIGABRT";
402      break;
403    default:
404      ssig = "UNKNOWN";
405      break;
406    }
407  sprintf (tmp,
408           _
409           ("ZOO Kernel failed to process your request receiving signal %d = %s"),
410           sig, ssig);
411  errorException (NULL, tmp, "InternalError", NULL);
412#ifdef DEBUG
413  fprintf (stderr, "Not this time!\n");
414#endif
415  exit (0);
416}
417
418void
419loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
420                   maps ** inputs, maps ** ioutputs, int *eres)
421{
422  char tmps1[1024];
423  char ntmp[1024];
424  maps *m = *myMap;
425  maps *request_output_real_format = *ioutputs;
426  maps *request_input_real_format = *inputs;
427  /**
428   * Extract serviceType to know what kind of service should be loaded
429   */
430  map *r_inputs = NULL;
431#ifndef WIN32
432  getcwd (ntmp, 1024);
433#else
434  _getcwd (ntmp, 1024);
435#endif
436  r_inputs = getMap (s1->content, "serviceType");
437#ifdef DEBUG
438  fprintf (stderr, "LOAD A %s SERVICE PROVIDER \n", r_inputs->value);
439  fflush (stderr);
440#endif
441  if (strlen (r_inputs->value) == 1
442      && strncasecmp (r_inputs->value, "C", 1) == 0)
443    {
444      r_inputs = getMap (request_inputs, "metapath");
445      if (r_inputs != NULL)
446        sprintf (tmps1, "%s/%s", ntmp, r_inputs->value);
447      else
448        sprintf (tmps1, "%s/", ntmp);
449      char *altPath = zStrdup (tmps1);
450      r_inputs = getMap (s1->content, "ServiceProvider");
451      sprintf (tmps1, "%s/%s", altPath, r_inputs->value);
452      free (altPath);
453#ifdef DEBUG
454      fprintf (stderr, "Trying to load %s\n", tmps1);
455#endif
456#ifdef WIN32
457      HINSTANCE so =
458        LoadLibraryEx (tmps1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
459#else
460      void *so = dlopen (tmps1, RTLD_LAZY);
461#endif
462#ifdef WIN32
463      char* errstr = getLastErrorMessage();
464#else
465      char *errstr;
466      errstr = dlerror ();
467#endif
468#ifdef DEBUG
469          fprintf (stderr, "%s loaded (%s) \n", tmps1, errstr);
470#endif
471      if (so != NULL)
472        {
473#ifdef DEBUG
474          fprintf (stderr, "Library loaded %s \n", errstr);
475          fprintf (stderr, "Service Shared Object = %s\n", r_inputs->value);
476#endif
477          r_inputs = getMap (s1->content, "serviceType");
478#ifdef DEBUG
479          dumpMap (r_inputs);
480          fprintf (stderr, "%s\n", r_inputs->value);
481          fflush (stderr);
482#endif
483          if (strncasecmp (r_inputs->value, "C-FORTRAN", 9) == 0)
484            {
485              r_inputs = getMap (request_inputs, "Identifier");
486              char fname[1024];
487              sprintf (fname, "%s_", r_inputs->value);
488#ifdef DEBUG
489              fprintf (stderr, "Try to load function %s\n", fname);
490#endif
491#ifdef WIN32
492              typedef int (CALLBACK * execute_t) (char ***, char ***,
493                                                  char ***);
494              execute_t execute = (execute_t) GetProcAddress (so, fname);
495#else
496              typedef int (*execute_t) (char ***, char ***, char ***);
497              execute_t execute = (execute_t) dlsym (so, fname);
498#endif
499#ifdef DEBUG
500#ifdef WIN32
501                          errstr = getLastErrorMessage();
502#else
503              errstr = dlerror ();
504#endif
505              fprintf (stderr, "Function loaded %s\n", errstr);
506#endif
507
508              char main_conf[10][30][1024];
509              char inputs[10][30][1024];
510              char outputs[10][30][1024];
511              for (int i = 0; i < 10; i++)
512                {
513                  for (int j = 0; j < 30; j++)
514                    {
515                      memset (main_conf[i][j], 0, 1024);
516                      memset (inputs[i][j], 0, 1024);
517                      memset (outputs[i][j], 0, 1024);
518                    }
519                }
520              mapsToCharXXX (m, (char ***) main_conf);
521              mapsToCharXXX (request_input_real_format, (char ***) inputs);
522              mapsToCharXXX (request_output_real_format, (char ***) outputs);
523              *eres =
524                execute ((char ***) &main_conf[0], (char ***) &inputs[0],
525                         (char ***) &outputs[0]);
526#ifdef DEBUG
527              fprintf (stderr, "Function run successfully \n");
528#endif
529              charxxxToMaps ((char ***) &outputs[0],
530                             &request_output_real_format);
531            }
532          else
533            {
534#ifdef DEBUG
535#ifdef WIN32
536                          errstr = getLastErrorMessage();
537              fprintf (stderr, "Function %s failed to load because of %s\n",
538                       r_inputs->value, errstr);
539#endif
540#endif
541              r_inputs = getMapFromMaps (m, "lenv", "Identifier");
542#ifdef DEBUG
543              fprintf (stderr, "Try to load function %s\n", r_inputs->value);
544#endif
545              typedef int (*execute_t) (maps **, maps **, maps **);
546#ifdef WIN32
547              execute_t execute =
548                (execute_t) GetProcAddress (so, r_inputs->value);
549#else
550              execute_t execute = (execute_t) dlsym (so, r_inputs->value);
551#endif
552
553              if (execute == NULL)
554                {
555#ifdef WIN32
556                                  errstr = getLastErrorMessage();
557#else
558                  errstr = dlerror ();
559#endif
560                  char *tmpMsg =
561                    (char *) malloc (2048 + strlen (r_inputs->value));
562                  sprintf (tmpMsg,
563                           _
564                           ("Error occured while running the %s function: %s"),
565                           r_inputs->value, errstr);
566                  errorException (m, tmpMsg, "InternalError", NULL);
567                  free (tmpMsg);
568#ifdef DEBUG
569                  fprintf (stderr, "Function %s error %s\n", r_inputs->value,
570                           errstr);
571#endif
572                  *eres = -1;
573                  return;
574                }
575
576#ifdef DEBUG
577#ifdef WIN32
578                          errstr = getLastErrorMessage();
579#else
580              errstr = dlerror ();
581#endif
582              fprintf (stderr, "Function loaded %s\n", errstr);
583#endif
584
585#ifdef DEBUG
586              fprintf (stderr, "Now run the function \n");
587              fflush (stderr);
588#endif
589              *eres =
590                execute (&m, &request_input_real_format,
591                         &request_output_real_format);
592#ifdef DEBUG
593              fprintf (stderr, "Function loaded and returned %d\n", eres);
594              fflush (stderr);
595#endif
596            }
597#ifdef WIN32
598          *ioutputs = dupMaps (&request_output_real_format);
599          FreeLibrary (so);
600#else
601          dlclose (so);
602#endif
603        }
604      else
605        {
606      /**
607       * Unable to load the specified shared library
608       */
609          char tmps[1024];
610#ifdef WIN32
611                  errstr = getLastErrorMessage();
612#else
613              errstr = dlerror ();
614#endif
615          sprintf (tmps, _("C Library can't be loaded %s"), errstr);
616          errorException(m,tmps,"InternalError",NULL);
617          *eres = -1;
618        }
619    }
620  else
621
622#ifdef USE_OTB
623  if (strncasecmp (r_inputs->value, "OTB", 6) == 0)
624    {
625      *eres =
626        zoo_otb_support (&m, request_inputs, s1,
627                            &request_input_real_format,
628                            &request_output_real_format);
629    }
630  else
631#endif
632
633#ifdef USE_PYTHON
634  if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0)
635    {
636      *eres =
637        zoo_python_support (&m, request_inputs, s1,
638                            &request_input_real_format,
639                            &request_output_real_format);
640    }
641  else
642#endif
643
644#ifdef USE_JAVA
645  if (strncasecmp (r_inputs->value, "JAVA", 4) == 0)
646    {
647      *eres =
648        zoo_java_support (&m, request_inputs, s1, &request_input_real_format,
649                          &request_output_real_format);
650    }
651  else
652#endif
653
654#ifdef USE_PHP
655  if (strncasecmp (r_inputs->value, "PHP", 3) == 0)
656    {
657      *eres =
658        zoo_php_support (&m, request_inputs, s1, &request_input_real_format,
659                         &request_output_real_format);
660    }
661  else
662#endif
663
664
665#ifdef USE_PERL
666  if (strncasecmp (r_inputs->value, "PERL", 4) == 0)
667    {
668      *eres =
669        zoo_perl_support (&m, request_inputs, s1, &request_input_real_format,
670                          &request_output_real_format);
671    }
672  else
673#endif
674
675#ifdef USE_JS
676  if (strncasecmp (r_inputs->value, "JS", 2) == 0)
677    {
678      *eres =
679        zoo_js_support (&m, request_inputs, s1, &request_input_real_format,
680                        &request_output_real_format);
681    }
682  else
683#endif
684
685#ifdef USE_RUBY
686  if (strncasecmp (r_inputs->value, "Ruby", 4) == 0)
687    {
688      *eres =
689        zoo_ruby_support (&m, request_inputs, s1, &request_input_real_format,
690                          &request_output_real_format);
691    }
692  else
693#endif
694
695    {
696      char tmpv[1024];
697      sprintf (tmpv,
698               _
699               ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),
700               r_inputs->value);
701      errorException (m, tmpv, "InternalError", NULL);
702      *eres = -1;
703    }
704  *myMap = m;
705  *ioutputs = request_output_real_format;
706}
707
708
709#ifdef WIN32
710/**
711 * createProcess function: create a new process after setting some env variables
712 */
713void
714createProcess (maps * m, map * request_inputs, service * s1, char *opts,
715               int cpid, maps * inputs, maps * outputs)
716{
717  STARTUPINFO si;
718  PROCESS_INFORMATION pi;
719  ZeroMemory (&si, sizeof (si));
720  si.cb = sizeof (si);
721  ZeroMemory (&pi, sizeof (pi));
722  char *tmp = (char *) malloc ((1024 + cgiContentLength) * sizeof (char));
723  char *tmpq = (char *) malloc ((1024 + cgiContentLength) * sizeof (char));
724  map *req = getMap (request_inputs, "request");
725  map *id = getMap (request_inputs, "identifier");
726  map *di = getMap (request_inputs, "DataInputs");
727
728  // The required size for the dataInputsKVP and dataOutputsKVP buffers
729  // may exceed cgiContentLength, hence a 2 kb extension. However, a
730  // better solution would be to have getMapsAsKVP() determine the required
731  // buffer size before allocating memory.     
732  char *dataInputsKVP = getMapsAsKVP (inputs, cgiContentLength + 2048, 0);
733  char *dataOutputsKVP = getMapsAsKVP (outputs, cgiContentLength + 2048, 1);
734#ifdef DEBUG
735  fprintf (stderr, "DATAINPUTSKVP %s\n", dataInputsKVP);
736  fprintf (stderr, "DATAOUTPUTSKVP %s\n", dataOutputsKVP);
737#endif
738  map *sid = getMapFromMaps (m, "lenv", "sid");
739  map *r_inputs = getMapFromMaps (m, "main", "tmpPath");
740  map *r_inputs1 = getMap (request_inputs, "metapath");
741  int hasIn = -1;
742  if (r_inputs1 == NULL)
743    {
744      r_inputs1 = createMap ("metapath", "");
745      hasIn = 1;
746    }
747  map *r_inputs2 = getMap (request_inputs, "ResponseDocument");
748  if (r_inputs2 == NULL)
749    r_inputs2 = getMap (request_inputs, "RawDataOutput");
750  map *tmpPath = getMapFromMaps (m, "lenv", "cwd");
751
752  map *tmpReq = getMap (request_inputs, "xrequest");
753 
754  if(r_inputs2 != NULL && tmpReq != NULL) {
755        const char key[] = "rfile=";
756        char* kvp = (char*) malloc((FILENAME_MAX + strlen(key))*sizeof(char));
757        char* filepath = kvp + strlen(key);
758        strncpy(kvp, key, strlen(key));
759        addToCache(m, tmpReq->value, tmpReq->value, "text/xml", strlen(tmpReq->value), 
760                   filepath, FILENAME_MAX);                               
761    if (filepath == NULL) {
762        errorException( m, _("Unable to cache HTTP POST Execute request."), "InternalError", NULL); 
763                return;
764    }   
765        sprintf(tmp,"\"metapath=%s&%s&cgiSid=%s",
766                r_inputs1->value,kvp,sid->value);
767    sprintf(tmpq,"metapath=%s&%s",
768                r_inputs1->value,kvp);
769        free(kvp);             
770  }
771  else if (r_inputs2 != NULL)
772    {
773      sprintf (tmp,
774               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s",
775               r_inputs1->value, req->value, id->value, dataInputsKVP,
776               r_inputs2->name, dataOutputsKVP, sid->value);
777      sprintf (tmpq,
778               "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",
779               r_inputs1->value, req->value, id->value, dataInputsKVP,
780               r_inputs2->name, dataOutputsKVP);                   
781    }
782  else
783    {
784      sprintf (tmp,
785               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s",
786               r_inputs1->value, req->value, id->value, dataInputsKVP,
787               sid->value);
788      sprintf (tmpq,
789               "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",
790               r_inputs1->value, req->value, id->value, dataInputsKVP,
791               sid->value);   
792    }
793
794  if (hasIn > 0)
795    {
796      freeMap (&r_inputs1);
797      free (r_inputs1);
798    }
799  char *tmp1 = zStrdup (tmp);
800  sprintf (tmp, "\"%s\" %s \"%s\"", PROGRAMNAME, tmp1, sid->value); 
801  free (dataInputsKVP);
802  free (dataOutputsKVP);
803#ifdef DEBUG
804  fprintf (stderr, "REQUEST IS : %s \n", tmp);
805#endif
806
807  map* usid = getMapFromMaps (m, "lenv", "usid");
808  if (usid != NULL && usid->value != NULL) {
809    SetEnvironmentVariable("USID", TEXT (usid->value));
810  }
811
812  SetEnvironmentVariable ("CGISID", TEXT (sid->value));
813  SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq));
814  // knut: Prevent REQUEST_METHOD=POST in background process call to cgic:main (process hangs when reading cgiIn):
815  SetEnvironmentVariable("REQUEST_METHOD", "GET");
816 
817  char clen[1000];
818  sprintf (clen, "%d", strlen (tmpq));
819  SetEnvironmentVariable ("CONTENT_LENGTH", TEXT (clen));
820
821  if (!CreateProcess (NULL,     // No module name (use command line)
822                      TEXT (tmp),       // Command line
823                      NULL,     // Process handle not inheritable
824                      NULL,     // Thread handle not inheritable
825                      FALSE,    // Set handle inheritance to FALSE
826                      CREATE_NO_WINDOW, // Apache won't wait until the end
827                      NULL,     // Use parent's environment block
828                      NULL,     // Use parent's starting directory
829                      &si,      // Pointer to STARTUPINFO struct
830                      &pi)      // Pointer to PROCESS_INFORMATION struct
831    )
832    {
833#ifdef DEBUG
834      fprintf (stderr, "CreateProcess failed (%d).\n", GetLastError ());
835#endif
836      if (tmp != NULL) {
837        free(tmp);
838      }
839      if (tmpq != NULL) {
840        free(tmpq);
841      }         
842      return;
843    }
844  else
845    {
846#ifdef DEBUG
847      fprintf (stderr, "CreateProcess successful (%d).\n\n\n\n",
848               GetLastError ());
849#endif
850    }
851  CloseHandle (pi.hProcess);
852  CloseHandle (pi.hThread);
853 
854  if (tmp != NULL) {
855    free(tmp);
856  }
857  if (tmpq != NULL) {
858    free(tmpq);
859  }
860 
861#ifdef DEBUG
862  fprintf (stderr, "CreateProcess finished !\n");
863#endif
864}
865#endif
866
867int
868runRequest (map ** inputs)
869{
870
871#ifndef USE_GDB
872#ifndef WIN32
873  signal (SIGCHLD, SIG_IGN);
874#endif 
875  signal (SIGSEGV, sig_handler);
876  signal (SIGTERM, sig_handler);
877  signal (SIGINT, sig_handler);
878  signal (SIGILL, sig_handler);
879  signal (SIGFPE, sig_handler);
880  signal (SIGABRT, sig_handler);
881#endif
882
883  map *r_inputs = NULL;
884  map *request_inputs = *inputs;
885  maps *m = NULL;
886  char *REQUEST = NULL;
887  /**
888   * Parsing service specfic configuration file
889   */
890  m = (maps *) malloc (MAPS_SIZE);
891  if (m == NULL)
892    {
893      return errorException (m, _("Unable to allocate memory."),
894                             "InternalError", NULL);
895    }
896  char ntmp[1024];
897#ifndef WIN32
898  getcwd (ntmp, 1024);
899#else
900  _getcwd (ntmp, 1024);
901#endif
902  r_inputs = getMapOrFill (&request_inputs, "metapath", "");
903
904
905  char conf_file[10240];
906  snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value);
907  if (conf_read (conf_file, m) == 2)
908    {
909      errorException (NULL, _("Unable to load the main.cfg file."),
910                      "InternalError", NULL);
911      free (m);
912      return 1;
913    }
914#ifdef DEBUG
915  fprintf (stderr, "***** BEGIN MAPS\n");
916  dumpMaps (m);
917  fprintf (stderr, "***** END MAPS\n");
918#endif
919
920  map *getPath = getMapFromMaps (m, "main", "gettextPath");
921  if (getPath != NULL)
922    {
923      bindtextdomain ("zoo-kernel", getPath->value);
924      bindtextdomain ("zoo-services", getPath->value);
925    }
926  else
927    {
928      bindtextdomain ("zoo-kernel", "/usr/share/locale/");
929      bindtextdomain ("zoo-services", "/usr/share/locale/");
930    }
931
932
933  /**
934   * Manage our own error log file (usefull to separate standard apache debug
935   * messages from the ZOO-Kernel ones but also for IIS users to avoid wrong
936   * headers messages returned by the CGI due to wrong redirection of stderr)
937   */
938  FILE *fstde = NULL;
939  map *fstdem = getMapFromMaps (m, "main", "logPath");
940  if (fstdem != NULL)
941    fstde = freopen (fstdem->value, "a+", stderr);
942
943  r_inputs = getMap (request_inputs, "language");
944  if (r_inputs == NULL)
945    r_inputs = getMapFromMaps (m, "main", "language");
946  if (r_inputs != NULL)
947    {
948      if (isValidLang (m, r_inputs->value) < 0)
949        {
950          char tmp[1024];
951          sprintf (tmp,
952                   _
953                   ("The value %s is not supported for the <language> parameter"),
954                   r_inputs->value);
955          errorException (m, tmp, "InvalidParameterValue", "language");
956          freeMaps (&m);
957          free (m);
958          free (REQUEST);
959          return 1;
960
961        }
962      char *tmp = zStrdup (r_inputs->value);
963      setMapInMaps (m, "main", "language", tmp);
964#ifdef DEB
965      char tmp2[12];
966      sprintf (tmp2, "%s.utf-8", tmp);
967      translateChar (tmp2, '-', '_');
968      setlocale (LC_ALL, tmp2);
969#else
970      translateChar (tmp, '-', '_');
971      setlocale (LC_ALL, tmp);
972#endif
973#ifndef WIN32
974      setenv ("LC_ALL", tmp, 1);
975#else
976      char tmp1[12];
977      sprintf (tmp1, "LC_ALL=%s", tmp);
978      putenv (tmp1);
979#endif
980      free (tmp);
981    }
982  else
983    {
984      setlocale (LC_ALL, "en_US");
985#ifndef WIN32
986      setenv ("LC_ALL", "en_US", 1);
987#else
988      char tmp1[12];
989      sprintf (tmp1, "LC_ALL=en_US");
990      putenv (tmp1);
991#endif
992      setMapInMaps (m, "main", "language", "en-US");
993    }
994  setlocale (LC_NUMERIC, "en_US");
995  bind_textdomain_codeset ("zoo-kernel", "UTF-8");
996  textdomain ("zoo-kernel");
997  bind_textdomain_codeset ("zoo-services", "UTF-8");
998  textdomain ("zoo-services");
999
1000  map *lsoap = getMap (request_inputs, "soap");
1001  if (lsoap != NULL && strcasecmp (lsoap->value, "true") == 0)
1002    setMapInMaps (m, "main", "isSoap", "true");
1003  else
1004    setMapInMaps (m, "main", "isSoap", "false");
1005
1006  if(strlen(cgiServerName)>0)
1007  {
1008    char tmpUrl[1024];
1009       
1010        if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"?         
1011                if ( strncmp(cgiServerPort, "443", 3) == 0 ) { 
1012                        sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
1013                }
1014                else {
1015                        sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
1016                }
1017        }
1018        else {
1019                if ( strncmp(cgiServerPort, "80", 2) == 0 ) { 
1020                        sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
1021                }
1022                else {
1023                        sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
1024                }
1025        }
1026#ifdef DEBUG
1027    fprintf(stderr,"*** %s ***\n",tmpUrl);
1028#endif
1029    setMapInMaps(m,"main","serverAddress",tmpUrl);
1030  }
1031
1032  /**
1033   * Check for minimum inputs
1034   */
1035  map* err=NULL;
1036  const char *vvr[]={
1037    "GetCapabilities",
1038    "DescribeProcess",
1039    "Execute",
1040    NULL
1041  };
1042  checkValidValue(request_inputs,&err,"Request",(const char**)vvr,1);
1043  const char *vvs[]={
1044    "WPS",
1045    NULL
1046  };
1047  if(err!=NULL){
1048    checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
1049    printExceptionReportResponse (m, err);
1050    freeMap(&err);
1051    free(err);
1052    if (count (request_inputs) == 1)
1053      {
1054        freeMap (&request_inputs);
1055        free (request_inputs);
1056      }
1057    freeMaps (&m);
1058    free (m);
1059    return 1;
1060  }
1061  checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
1062  const char *vvv[]={
1063    "1.0.0",
1064    NULL
1065  };
1066  r_inputs = getMap (request_inputs, "Request");
1067  REQUEST = zStrdup (r_inputs->value);
1068  if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){
1069    checkValidValue(request_inputs,&err,"version",(const char**)vvv,1);
1070    checkValidValue(request_inputs,&err,"identifier",NULL,1);
1071  }else{
1072    checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1);
1073  }
1074  if(err!=NULL){
1075    printExceptionReportResponse (m, err);
1076    freeMap(&err);
1077    free(err);
1078    if (count (request_inputs) == 1)
1079      {
1080        freeMap (&request_inputs);
1081        free (request_inputs);
1082      }
1083    free(REQUEST);
1084    freeMaps (&m);
1085    free (m);
1086    return 1;
1087  }
1088
1089  r_inputs = getMap (request_inputs, "serviceprovider");
1090  if (r_inputs == NULL)
1091    {
1092      addToMap (request_inputs, "serviceprovider", "");
1093    }
1094
1095
1096  maps *request_output_real_format = NULL;
1097  map *tmpm = getMapFromMaps (m, "main", "serverAddress");
1098  if (tmpm != NULL)
1099    SERVICE_URL = zStrdup (tmpm->value);
1100  else
1101    SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL);
1102
1103  service *s1;
1104  int scount = 0;
1105#ifdef DEBUG
1106  dumpMap (r_inputs);
1107#endif
1108  char conf_dir[1024];
1109  int t;
1110  char tmps1[1024];
1111
1112  r_inputs = NULL;
1113  r_inputs = getMap (request_inputs, "metapath");
1114  if (r_inputs != NULL)
1115    snprintf (conf_dir, 1024, "%s/%s", ntmp, r_inputs->value);
1116  else
1117    snprintf (conf_dir, 1024, "%s", ntmp);
1118
1119  if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0)
1120    {
1121#ifdef DEBUG
1122      dumpMap (r_inputs);
1123#endif
1124      xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
1125      r_inputs = NULL;
1126      //r_inputs = getMap (request_inputs, "ServiceProvider");
1127      xmlNodePtr n=printGetCapabilitiesHeader(doc,m);
1128      /**
1129       * Here we need to close stdout to ensure that unsupported chars
1130       * has been found in the zcfg and then printed on stdout
1131       */
1132      int saved_stdout = dup (fileno (stdout));
1133      dup2 (fileno (stderr), fileno (stdout));
1134      if (int res =               
1135          recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,
1136                          printGetCapabilitiesForProcess) < 0)
1137        {
1138          freeMaps (&m);
1139          free (m);
1140          free (REQUEST);
1141          free (SERVICE_URL);
1142          fflush (stdout);
1143          return res;
1144        }
1145      dup2 (saved_stdout, fileno (stdout));
1146      printDocument (m, doc, getpid ());
1147      freeMaps (&m);
1148      free (m);
1149      free (REQUEST);
1150      free (SERVICE_URL);
1151      fflush (stdout);
1152      return 0;
1153    }
1154  else
1155    {
1156      r_inputs = getMap (request_inputs, "Identifier");
1157
1158      struct dirent *dp;
1159      DIR *dirp = opendir (conf_dir);
1160      if (dirp == NULL)
1161        {
1162          errorException (m, _("The specified path path doesn't exist."),
1163                          "InvalidParameterValue", conf_dir);
1164          freeMaps (&m);
1165          free (m);
1166          free (REQUEST);
1167          free (SERVICE_URL);
1168          return 0;
1169        }
1170      if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
1171        {
1172          /**
1173           * Loop over Identifier list
1174           */
1175          xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
1176          r_inputs = NULL;
1177          xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
1178                                        "ProcessDescriptions");
1179
1180          r_inputs = getMap (request_inputs, "Identifier");
1181
1182          char *orig = zStrdup (r_inputs->value);
1183
1184          int saved_stdout = dup (fileno (stdout));
1185          dup2 (fileno (stderr), fileno (stdout));
1186          if (strcasecmp ("all", orig) == 0)
1187            {
1188              if (int res =
1189                  recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,
1190                                  printDescribeProcessForProcess) < 0)
1191                return res;
1192            }
1193          else
1194            {
1195              char *saveptr;
1196              char *tmps = strtok_r (orig, ",", &saveptr);
1197
1198              char buff[256];
1199              char buff1[1024];
1200              while (tmps != NULL)
1201                {
1202                  int hasVal = -1;
1203                  char *corig = zStrdup (tmps);
1204                  if (strstr (corig, ".") != NULL)
1205                    {
1206
1207                      parseIdentifier (m, conf_dir, corig, buff1);
1208                      map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
1209                      if (tmpMap != NULL)
1210                        addToMap (request_inputs, "metapath", tmpMap->value);
1211                      map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
1212
1213                      s1 = (service *) malloc (SERVICE_SIZE);
1214                      t = readServiceFile (m, buff1, &s1, tmpMapI->value);
1215                      if (t < 0)
1216                        {
1217                          map *tmp00 = getMapFromMaps (m, "lenv", "message");
1218                          char tmp01[1024];
1219                          if (tmp00 != NULL)
1220                            sprintf (tmp01,
1221                                     _
1222                                     ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
1223                                     tmps, tmp00->value);
1224                          else
1225                            sprintf (tmp01,
1226                                     _
1227                                     ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
1228                                     tmps);
1229                          dup2 (saved_stdout, fileno (stdout));
1230                          errorException (m, tmp01, "InvalidParameterValue",
1231                                          "identifier");
1232                          freeMaps (&m);
1233                          free (m);
1234                          free (REQUEST);
1235                          free (corig);
1236                          free (orig);
1237                          free (SERVICE_URL);
1238                          free (s1);
1239                          closedir (dirp);
1240                          xmlFreeDoc (doc);
1241                          xmlCleanupParser ();
1242                          zooXmlCleanupNs ();
1243                          return 1;
1244                        }
1245#ifdef DEBUG
1246                      dumpService (s1);
1247#endif
1248                      printDescribeProcessForProcess (m, n, s1);
1249                      freeService (&s1);
1250                      free (s1);
1251                      s1 = NULL;
1252                      scount++;
1253                      hasVal = 1;
1254                      setMapInMaps (m, "lenv", "level", "0");
1255                    }
1256                  else
1257                    {
1258                      memset (buff, 0, 256);
1259                      snprintf (buff, 256, "%s.zcfg", corig);
1260                      memset (buff1, 0, 1024);
1261#ifdef DEBUG
1262                      printf ("\n#######%s\n########\n", buff);
1263#endif
1264                      while ((dp = readdir (dirp)) != NULL)
1265                        {
1266                          if (strcasecmp (dp->d_name, buff) == 0)
1267                            {
1268                              memset (buff1, 0, 1024);
1269                              snprintf (buff1, 1024, "%s/%s", conf_dir,
1270                                        dp->d_name);
1271                              s1 = (service *) malloc (SERVICE_SIZE);
1272                              if (s1 == NULL)
1273                                {
1274                                  dup2 (saved_stdout, fileno (stdout));
1275                                  return errorException (m,
1276                                                         _
1277                                                         ("Unable to allocate memory."),
1278                                                         "InternalError",
1279                                                         NULL);
1280                                }
1281#ifdef DEBUG
1282                              printf
1283                                ("#################\n(%s) %s\n#################\n",
1284                                 r_inputs->value, buff1);
1285#endif
1286                              char *tmp0 = zStrdup (dp->d_name);
1287                              tmp0[strlen (tmp0) - 5] = 0;
1288                              t = readServiceFile (m, buff1, &s1, tmp0);
1289                              free (tmp0);
1290                              if (t < 0)
1291                                {
1292                                  map *tmp00 =
1293                                    getMapFromMaps (m, "lenv", "message");
1294                                  char tmp01[1024];
1295                                  if (tmp00 != NULL)
1296                                    sprintf (tmp01,
1297                                             _
1298                                             ("Unable to parse the ZCFG file: %s (%s)"),
1299                                             dp->d_name, tmp00->value);
1300                                  else
1301                                    sprintf (tmp01,
1302                                             _
1303                                             ("Unable to parse the ZCFG file: %s."),
1304                                             dp->d_name);
1305                                  dup2 (saved_stdout, fileno (stdout));
1306                                  errorException (m, tmp01, "InternalError",
1307                                                  NULL);
1308                                  freeMaps (&m);
1309                                  free (m);
1310                                  free (orig);
1311                                  free (REQUEST);
1312                                  closedir (dirp);
1313                                  xmlFreeDoc (doc);
1314                                  xmlCleanupParser ();
1315                                  zooXmlCleanupNs ();
1316                                  return 1;
1317                                }
1318#ifdef DEBUG
1319                              dumpService (s1);
1320#endif
1321                              printDescribeProcessForProcess (m, n, s1);
1322                              freeService (&s1);
1323                              free (s1);
1324                              s1 = NULL;
1325                              scount++;
1326                              hasVal = 1;
1327                            }
1328                        }
1329                    }
1330                  if (hasVal < 0)
1331                    {
1332                      map *tmp00 = getMapFromMaps (m, "lenv", "message");
1333                      char tmp01[1024];
1334                      if (tmp00 != NULL)
1335                        sprintf (tmp01,
1336                                 _("Unable to parse the ZCFG file: %s (%s)"),
1337                                 buff, tmp00->value);
1338                      else
1339                        sprintf (tmp01,
1340                                 _("Unable to parse the ZCFG file: %s."),
1341                                 buff);
1342                      dup2 (saved_stdout, fileno (stdout));
1343                      errorException (m, tmp01, "InvalidParameterValue",
1344                                      "Identifier");
1345                      freeMaps (&m);
1346                      free (m);
1347                      free (orig);
1348                      free (REQUEST);
1349                      closedir (dirp);
1350                      xmlFreeDoc (doc);
1351                      xmlCleanupParser ();
1352                      zooXmlCleanupNs ();
1353                      return 1;
1354                    }
1355                  rewinddir (dirp);
1356                  tmps = strtok_r (NULL, ",", &saveptr);
1357                  if (corig != NULL)
1358                    free (corig);
1359                }
1360            }
1361          closedir (dirp);
1362          fflush (stdout);
1363          dup2 (saved_stdout, fileno (stdout));
1364          free (orig);
1365          printDocument (m, doc, getpid ());
1366          freeMaps (&m);
1367          free (m);
1368          free (REQUEST);
1369          free (SERVICE_URL);
1370          fflush (stdout);
1371          return 0;
1372        }
1373      else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
1374        {
1375          errorException (m,
1376                          _
1377                          ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."),
1378                          "InvalidParameterValue", "request");
1379#ifdef DEBUG
1380          fprintf (stderr, "No request found %s", REQUEST);
1381#endif
1382          closedir (dirp);
1383          freeMaps (&m);
1384          free (m);
1385          free (REQUEST);
1386          free (SERVICE_URL);
1387          fflush (stdout);
1388          return 0;
1389        }
1390      closedir (dirp);
1391    }
1392
1393  s1 = NULL;
1394  s1 = (service *) malloc (SERVICE_SIZE);
1395  if (s1 == NULL)
1396    {
1397      freeMaps (&m);
1398      free (m);
1399      free (REQUEST);
1400      free (SERVICE_URL);
1401      return errorException (m, _("Unable to allocate memory."),
1402                             "InternalError", NULL);
1403    }
1404
1405  r_inputs = getMap (request_inputs, "MetaPath");
1406  if (r_inputs != NULL)
1407    snprintf (tmps1, 1024, "%s/%s", ntmp, r_inputs->value);
1408  else
1409    snprintf (tmps1, 1024, "%s/", ntmp);
1410  r_inputs = getMap (request_inputs, "Identifier");
1411  char *ttmp = zStrdup (tmps1);
1412  snprintf (tmps1, 1024, "%s/%s.zcfg", ttmp, r_inputs->value);
1413  free (ttmp);
1414#ifdef DEBUG
1415  fprintf (stderr, "Trying to load %s\n", tmps1);
1416#endif
1417  if (strstr (r_inputs->value, ".") != NULL)
1418    {
1419      char *identifier = zStrdup (r_inputs->value);
1420      parseIdentifier (m, conf_dir, identifier, tmps1);
1421      map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
1422      if (tmpMap != NULL)
1423        addToMap (request_inputs, "metapath", tmpMap->value);
1424      free (identifier);
1425    }
1426  else
1427    {
1428      setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
1429      setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
1430    }
1431
1432  r_inputs = getMapFromMaps (m, "lenv", "Identifier");
1433  int saved_stdout = dup (fileno (stdout));
1434  dup2 (fileno (stderr), fileno (stdout));
1435  t = readServiceFile (m, tmps1, &s1, r_inputs->value);
1436  fflush (stdout);
1437  dup2 (saved_stdout, fileno (stdout));
1438  if (t < 0)
1439    {
1440      char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value));
1441      sprintf (tmpMsg,
1442               _
1443               ("The value for <identifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),
1444               r_inputs->value);
1445      errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
1446      free (tmpMsg);
1447      free (s1);
1448      freeMaps (&m);
1449      free (m);
1450      free (REQUEST);
1451      free (SERVICE_URL);
1452      return 0;
1453    }
1454  close (saved_stdout);
1455
1456#ifdef DEBUG
1457  dumpService (s1);
1458#endif
1459  int j;
1460
1461
1462  /**
1463   * Create the input and output maps data structure
1464   */
1465  int i = 0;
1466  HINTERNET hInternet;
1467  HINTERNET res;
1468  hInternet = InternetOpen (
1469#ifndef WIN32
1470                             (LPCTSTR)
1471#endif
1472                             "ZooWPSClient\0",
1473                             INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1474
1475#ifndef WIN32
1476  if (!CHECK_INET_HANDLE (hInternet))
1477    fprintf (stderr, "WARNING : hInternet handle failed to initialize");
1478#endif
1479  maps *request_input_real_format = NULL;
1480  maps *tmpmaps = request_input_real_format;
1481  map *postRequest = NULL;
1482  postRequest = getMap (request_inputs, "xrequest");
1483  if (postRequest == NULLMAP)
1484    {
1485    /**
1486     * Parsing outputs provided as KVP
1487     */
1488      r_inputs = NULL;
1489#ifdef DEBUG
1490      fprintf (stderr, "OUTPUT Parsing ... \n");
1491#endif
1492      r_inputs = getMap (request_inputs, "ResponseDocument");
1493      if (r_inputs == NULL)
1494        r_inputs = getMap (request_inputs, "RawDataOutput");
1495
1496#ifdef DEBUG
1497      fprintf (stderr, "OUTPUT Parsing ... \n");
1498#endif
1499      if (r_inputs != NULL)
1500        {
1501#ifdef DEBUG
1502          fprintf (stderr, "OUTPUT Parsing start now ... \n");
1503#endif
1504          char cursor_output[10240];
1505          char *cotmp = zStrdup (r_inputs->value);
1506          snprintf (cursor_output, 10240, "%s", cotmp);
1507          free (cotmp);
1508          j = 0;
1509
1510      /**
1511       * Put each Output into the outputs_as_text array
1512       */
1513          char *pToken;
1514          maps *tmp_output = NULL;
1515#ifdef DEBUG
1516          fprintf (stderr, "OUTPUT [%s]\n", cursor_output);
1517#endif
1518          pToken = strtok (cursor_output, ";");
1519          char **outputs_as_text = (char **) malloc (128 * sizeof (char *));
1520          if (outputs_as_text == NULL)
1521            {
1522              return errorException (m, _("Unable to allocate memory"),
1523                                     "InternalError", NULL);
1524            }
1525          i = 0;
1526          while (pToken != NULL)
1527            {
1528#ifdef DEBUG
1529              fprintf (stderr, "***%s***\n", pToken);
1530              fflush (stderr);
1531              fprintf (stderr, "***%s***\n", pToken);
1532#endif
1533              outputs_as_text[i] =
1534                (char *) malloc ((strlen (pToken) + 1) * sizeof (char));
1535              if (outputs_as_text[i] == NULL)
1536                {
1537                  return errorException (m, _("Unable to allocate memory"),
1538                                         "InternalError", NULL);
1539                }
1540              snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s",
1541                        pToken);
1542              pToken = strtok (NULL, ";");
1543              i++;
1544            }
1545          for (j = 0; j < i; j++)
1546            {
1547              char *tmp = zStrdup (outputs_as_text[j]);
1548              free (outputs_as_text[j]);
1549              char *tmpc;
1550              tmpc = strtok (tmp, "@");
1551              int k = 0;
1552              while (tmpc != NULL)
1553                {
1554                  if (k == 0)
1555                    {
1556                      if (tmp_output == NULL)
1557                        {
1558                          tmp_output = (maps *) malloc (MAPS_SIZE);
1559                          if (tmp_output == NULL)
1560                            {
1561                              return errorException (m,
1562                                                     _
1563                                                     ("Unable to allocate memory."),
1564                                                     "InternalError", NULL);
1565                            }
1566                          tmp_output->name = zStrdup (tmpc);
1567                          tmp_output->content = NULL;
1568                          tmp_output->next = NULL;
1569                        }
1570                    }
1571                  else
1572                    {
1573                      char *tmpv = strstr (tmpc, "=");
1574                      char tmpn[256];
1575                      memset (tmpn, 0, 256);
1576                      strncpy (tmpn, tmpc,
1577                               (strlen (tmpc) -
1578                                strlen (tmpv)) * sizeof (char));
1579                      tmpn[strlen (tmpc) - strlen (tmpv)] = 0;
1580#ifdef DEBUG
1581                      fprintf (stderr, "OUTPUT DEF [%s]=[%s]\n", tmpn,
1582                               tmpv + 1);
1583#endif
1584                      if (tmp_output->content == NULL)
1585                        {
1586                          tmp_output->content = createMap (tmpn, tmpv + 1);
1587                          tmp_output->content->next = NULL;
1588                        }
1589                      else
1590                        addToMap (tmp_output->content, tmpn, tmpv + 1);
1591                    }
1592                  k++;
1593#ifdef DEBUG
1594                  fprintf (stderr, "***%s***\n", tmpc);
1595#endif
1596                  tmpc = strtok (NULL, "@");
1597                }
1598              if (request_output_real_format == NULL)
1599                request_output_real_format = dupMaps (&tmp_output);
1600              else
1601                addMapsToMaps (&request_output_real_format, tmp_output);
1602              freeMaps (&tmp_output);
1603              free (tmp_output);
1604              tmp_output = NULL;
1605#ifdef DEBUG
1606              dumpMaps (tmp_output);
1607              fflush (stderr);
1608#endif
1609              free (tmp);
1610            }
1611          free (outputs_as_text);
1612        }
1613
1614
1615    /**
1616     * Parsing inputs provided as KVP
1617     */
1618      r_inputs = getMap (request_inputs, "DataInputs");
1619#ifdef DEBUG
1620      fprintf (stderr, "DATA INPUTS [%s]\n", r_inputs->value);
1621#endif
1622      char cursor_input[40960];
1623      if (r_inputs != NULL){
1624        snprintf (cursor_input, 40960, "%s", r_inputs->value);
1625        j = 0;
1626
1627        /**
1628         * Put each DataInputs into the inputs_as_text array
1629         */
1630        char *tmp1 = zStrdup (cursor_input);
1631        char *pToken;
1632        pToken = strtok (cursor_input, ";");
1633        if (pToken != NULL && strncasecmp (pToken, tmp1, strlen (tmp1)) == 0)
1634          {
1635            char *tmp2 = url_decode (tmp1);
1636            snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s",
1637                      tmp2);
1638            free (tmp2);
1639            pToken = strtok (cursor_input, ";");
1640          }
1641        free (tmp1);
1642       
1643        char **inputs_as_text = (char **) malloc (100 * sizeof (char *));
1644        if (inputs_as_text == NULL)
1645          {
1646            return errorException (m, _("Unable to allocate memory."),
1647                                   "InternalError", NULL);
1648          }
1649        i = 0;
1650        while (pToken != NULL)
1651          {
1652#ifdef DEBUG
1653            fprintf (stderr, "***%s***\n", pToken);
1654            fflush (stderr);
1655            fprintf (stderr, "***%s***\n", pToken);
1656#endif
1657            inputs_as_text[i] =
1658              (char *) malloc ((strlen (pToken) + 1) * sizeof (char));
1659            if (inputs_as_text[i] == NULL)
1660              {
1661                return errorException (m, _("Unable to allocate memory."),
1662                                       "InternalError", NULL);
1663              }
1664            snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken);
1665            pToken = strtok (NULL, ";");
1666            i++;
1667          }
1668       
1669        for (j = 0; j < i; j++)
1670          {
1671            char *tmp = zStrdup (inputs_as_text[j]);
1672            free (inputs_as_text[j]);
1673            char *tmpc;
1674            tmpc = strtok (tmp, "@");
1675            while (tmpc != NULL)
1676              {
1677#ifdef DEBUG
1678                fprintf (stderr, "***\n***%s***\n", tmpc);
1679#endif
1680                char *tmpv = strstr (tmpc, "=");
1681                char tmpn[256];
1682                memset (tmpn, 0, 256);
1683                if (tmpv != NULL)
1684                  {
1685                    strncpy (tmpn, tmpc,
1686                             (strlen (tmpc) - strlen (tmpv)) * sizeof (char));
1687                    tmpn[strlen (tmpc) - strlen (tmpv)] = 0;
1688                  }
1689                else
1690                  {
1691                    strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char));
1692                    tmpn[strlen (tmpc)] = 0;
1693                  }
1694#ifdef DEBUG
1695                fprintf (stderr, "***\n*** %s = %s ***\n", tmpn, tmpv + 1);
1696#endif
1697                if (tmpmaps == NULL)
1698                  {
1699                    tmpmaps = (maps *) malloc (MAPS_SIZE);
1700                    if (tmpmaps == NULL)
1701                      {
1702                        return errorException (m,
1703                                               _("Unable to allocate memory."),
1704                                               "InternalError", NULL);
1705                      }
1706                    tmpmaps->name = zStrdup (tmpn);
1707                    if (tmpv != NULL)
1708                      {
1709                        char *tmpvf = url_decode (tmpv + 1);
1710                        tmpmaps->content = createMap ("value", tmpvf);
1711                        free (tmpvf);
1712                      }
1713                    else
1714                      tmpmaps->content = createMap ("value", "Reference");
1715                    tmpmaps->next = NULL;
1716                  }
1717                tmpc = strtok (NULL, "@");
1718                while (tmpc != NULL)
1719                  {
1720#ifdef DEBUG
1721                    fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n",
1722                             tmpc);
1723#endif
1724                    char *tmpv1 = strstr (tmpc, "=");
1725#ifdef DEBUG
1726                    fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
1727                             tmpv1 + 1);
1728#endif
1729                    char tmpn1[1024];
1730                    memset (tmpn1, 0, 1024);
1731                    if (tmpv1 != NULL)
1732                      {
1733                        strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1));
1734                        tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0;
1735                        addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
1736                      }
1737                    else
1738                      {
1739                        strncpy (tmpn1, tmpc, strlen (tmpc));
1740                        tmpn1[strlen (tmpc)] = 0;
1741                        map *lmap = getLastMap (tmpmaps->content);
1742                        char *tmpValue =
1743                          (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) *
1744                                           sizeof (char));
1745                        sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc);
1746                        free (lmap->value);
1747                        lmap->value = zStrdup (tmpValue);
1748                        free (tmpValue);
1749                        tmpc = strtok (NULL, "@");
1750                        continue;
1751                      }
1752#ifdef DEBUG
1753                    fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n",
1754                             tmpn1);
1755                    fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
1756                             tmpv1 + 1);
1757#endif
1758                    if (strcmp (tmpn1, "xlink:href") != 0)
1759                      addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
1760                    else if (tmpv1 != NULL)
1761                      {
1762                        char *tmpx2 = url_decode (tmpv1 + 1);
1763                        if (strncasecmp (tmpx2, "http://", 7) != 0 &&
1764                            strncasecmp (tmpx2, "ftp://", 6) != 0 &&
1765                            strncasecmp (tmpx2, "https://", 8) != 0)
1766                          {
1767                            char emsg[1024];
1768                            sprintf (emsg,
1769                                     _
1770                                     ("Unable to find a valid protocol to download the remote file %s"),
1771                                     tmpv1 + 1);
1772                            errorException (m, emsg, "InternalError", NULL);
1773                            freeMaps (&m);
1774                            free (m);
1775                            free (REQUEST);
1776                            free (SERVICE_URL);
1777                            InternetCloseHandle (&hInternet);
1778                            freeService (&s1);
1779                            free (s1);
1780                            return 0;
1781                          }
1782#ifdef DEBUG
1783                        fprintf (stderr,
1784                                 "REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",
1785                                 tmpv1 + 1);
1786#endif
1787                        addToMap (tmpmaps->content, tmpn1, tmpx2);
1788#ifndef WIN32
1789                        if (CHECK_INET_HANDLE (hInternet))
1790#endif
1791                          {
1792                            if (loadRemoteFile
1793                                (&m, &tmpmaps->content, &hInternet, tmpx2) < 0)
1794                              {
1795                                freeMaps (&m);
1796                                free (m);
1797                                free (REQUEST);
1798                                free (SERVICE_URL);
1799                                InternetCloseHandle (&hInternet);
1800                                freeService (&s1);
1801                                free (s1);
1802                                return 0;
1803                              }
1804                          }
1805                        free (tmpx2);
1806                        addToMap (tmpmaps->content, "Reference", tmpv1 + 1);
1807                      }
1808                    tmpc = strtok (NULL, "@");
1809                  }
1810#ifdef DEBUG
1811                dumpMaps (tmpmaps);
1812                fflush (stderr);
1813#endif
1814                if (request_input_real_format == NULL)
1815                  request_input_real_format = dupMaps (&tmpmaps);
1816                else
1817                  {
1818                    maps *testPresence =
1819                      getMaps (request_input_real_format, tmpmaps->name);
1820                    if (testPresence != NULL)
1821                      {
1822                        elements *elem =
1823                          getElements (s1->inputs, tmpmaps->name);
1824                        if (elem != NULL)
1825                          {
1826                            if (appendMapsToMaps
1827                                (m, request_input_real_format, tmpmaps,
1828                                 elem) < 0)
1829                              {
1830                                freeMaps (&m);
1831                                free (m);
1832                                free (REQUEST);
1833                                free (SERVICE_URL);
1834                                InternetCloseHandle (&hInternet);
1835                                freeService (&s1);
1836                                free (s1);
1837                                return 0;
1838                              }
1839                          }
1840                      }
1841                    else
1842                      addMapsToMaps (&request_input_real_format, tmpmaps);
1843                  }
1844                freeMaps (&tmpmaps);
1845                free (tmpmaps);
1846                tmpmaps = NULL;
1847                free (tmp);
1848              }
1849          }
1850        free (inputs_as_text);
1851      }
1852    }
1853  else
1854    {
1855    /**
1856     * Parse XML request
1857     */
1858      xmlInitParser ();
1859#ifdef DEBUG
1860      fflush (stderr);
1861      fprintf (stderr, "BEFORE %s\n", postRequest->value);
1862      fflush (stderr);
1863#endif
1864      xmlDocPtr doc = xmlParseMemory (postRequest->value, cgiContentLength);
1865#ifdef DEBUG
1866      fprintf (stderr, "AFTER\n");
1867      fflush (stderr);
1868#endif
1869
1870    /**
1871     * Parse every Input in DataInputs node.
1872     */
1873      xmlXPathObjectPtr tmpsptr =
1874        extractFromDoc (doc, "/*/*/*[local-name()='Input']");
1875      xmlNodeSet *tmps = tmpsptr->nodesetval;
1876#ifdef DEBUG
1877      fprintf (stderr, "*****%d*****\n", tmps->nodeNr);
1878#endif
1879      for (int k = 0; k < tmps->nodeNr; k++)
1880        {
1881          maps *tmpmaps = NULL;
1882          xmlNodePtr cur = tmps->nodeTab[k];
1883          if (tmps->nodeTab[k]->type == XML_ELEMENT_NODE)
1884            {
1885        /**
1886         * A specific Input node.
1887         */
1888#ifdef DEBUG
1889              fprintf (stderr, "= element 0 node \"%s\"\n", cur->name);
1890#endif
1891              xmlNodePtr cur2 = cur->children;
1892              while (cur2 != NULL)
1893                {
1894                  while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
1895                    cur2 = cur2->next;
1896                  if (cur2 == NULL)
1897                    break;
1898          /**
1899           * Indentifier
1900           */
1901                  if (xmlStrncasecmp
1902                      (cur2->name, BAD_CAST "Identifier",
1903                       xmlStrlen (cur2->name)) == 0)
1904                    {
1905                      xmlChar *val =
1906                        xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1);
1907                      if (tmpmaps == NULL)
1908                        {
1909                          tmpmaps = (maps *) malloc (MAPS_SIZE);
1910                          if (tmpmaps == NULL)
1911                            {
1912                              return errorException (m,
1913                                                     _
1914                                                     ("Unable to allocate memory."),
1915                                                     "InternalError", NULL);
1916                            }
1917                          tmpmaps->name = zStrdup ((char *) val);
1918                          tmpmaps->content = NULL;
1919                          tmpmaps->next = NULL;
1920                        }
1921                      xmlFree (val);
1922                    }
1923          /**
1924           * Title, Asbtract
1925           */
1926                  if (xmlStrncasecmp
1927                      (cur2->name, BAD_CAST "Title",
1928                       xmlStrlen (cur2->name)) == 0
1929                      || xmlStrncasecmp (cur2->name, BAD_CAST "Abstract",
1930                                         xmlStrlen (cur2->name)) == 0)
1931                    {
1932                      xmlChar *val =
1933                        xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1);
1934                      if (tmpmaps == NULL)
1935                        {
1936                          tmpmaps = (maps *) malloc (MAPS_SIZE);
1937                          if (tmpmaps == NULL)
1938                            {
1939                              return errorException (m,
1940                                                     _
1941                                                     ("Unable to allocate memory."),
1942                                                     "InternalError", NULL);
1943                            }
1944                          tmpmaps->name = zStrdup ("missingIndetifier");
1945                          tmpmaps->content =
1946                            createMap ((char *) cur2->name, (char *) val);
1947                          tmpmaps->next = NULL;
1948                        }
1949                      else
1950                        {
1951                          if (tmpmaps->content != NULL)
1952                            addToMap (tmpmaps->content,
1953                                      (char *) cur2->name, (char *) val);
1954                          else
1955                            tmpmaps->content =
1956                              createMap ((char *) cur2->name, (char *) val);
1957                        }
1958#ifdef DEBUG
1959                      dumpMaps (tmpmaps);
1960#endif
1961                      xmlFree (val);
1962                    }
1963          /**
1964           * InputDataFormChoice (Reference or Data ?)
1965           */
1966                  if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0)
1967                    {
1968            /**
1969             * Get every attribute from a Reference node
1970             * mimeType, encoding, schema, href, method
1971             * Header and Body gesture should be added here
1972             */
1973#ifdef DEBUG
1974                      fprintf (stderr, "REFERENCE\n");
1975#endif
1976                      const char *refs[5] =
1977                        { "mimeType", "encoding", "schema", "method",
1978                        "href"
1979                      };
1980                      for (int l = 0; l < 5; l++)
1981                        {
1982#ifdef DEBUG
1983                          fprintf (stderr, "*** %s ***", refs[l]);
1984#endif
1985                          xmlChar *val = xmlGetProp (cur2, BAD_CAST refs[l]);
1986                          if (val != NULL && xmlStrlen (val) > 0)
1987                            {
1988                              if (tmpmaps->content != NULL)
1989                                addToMap (tmpmaps->content, refs[l],
1990                                          (char *) val);
1991                              else
1992                                tmpmaps->content =
1993                                  createMap (refs[l], (char *) val);
1994                              map *ltmp = getMap (tmpmaps->content, "method");
1995                              if (l == 4)
1996                                {
1997                                  if (!
1998                                      (ltmp != NULL
1999                                       && strncmp (ltmp->value, "POST",
2000                                                   4) == 0)
2001                                      && CHECK_INET_HANDLE (hInternet))
2002                                    {
2003                                      if (loadRemoteFile
2004                                          (&m, &tmpmaps->content, &hInternet,
2005                                           (char *) val) != 0)
2006                                        {
2007                                          freeMaps (&m);
2008                                          free (m);
2009                                          free (REQUEST);
2010                                          free (SERVICE_URL);
2011                                          InternetCloseHandle (&hInternet);
2012                                          freeService (&s1);
2013                                          free (s1);
2014                                          return 0;
2015                                        }
2016                                    }
2017                                }
2018                            }
2019#ifdef DEBUG
2020                          fprintf (stderr, "%s\n", val);
2021#endif
2022                          xmlFree (val);
2023                        }
2024#ifdef POST_DEBUG
2025                      fprintf (stderr,
2026                               "Parse Header and Body from Reference \n");
2027#endif
2028                      xmlNodePtr cur3 = cur2->children;
2029                      /*      HINTERNET hInternetP;
2030                         hInternetP=InternetOpen(
2031                         #ifndef WIN32
2032                         (LPCTSTR)
2033                         #endif
2034                         "ZooWPSClient\0",
2035                         INTERNET_OPEN_TYPE_PRECONFIG,
2036                         NULL,NULL, 0); */
2037                      //hInternet.ihandle[hInternet.nb].header=NULL;
2038                      while (cur3 != NULL)
2039                        {
2040                          while (cur3 != NULL
2041                                 && cur3->type != XML_ELEMENT_NODE)
2042                            cur3 = cur3->next;
2043                          if (cur3 == NULL)
2044                            break;
2045                          if (xmlStrcasecmp (cur3->name, BAD_CAST "Header") ==
2046                              0)
2047                            {
2048                              const char *ha[2];
2049                              ha[0] = "key";
2050                              ha[1] = "value";
2051                              int hai;
2052                              char *has;
2053                              char *key;
2054                              for (hai = 0; hai < 2; hai++)
2055                                {
2056                                  xmlChar *val =
2057                                    xmlGetProp (cur3, BAD_CAST ha[hai]);
2058#ifdef POST_DEBUG
2059                                  fprintf (stderr, "%s = %s\n", ha[hai],
2060                                           (char *) val);
2061#endif
2062                                  if (hai == 0)
2063                                    {
2064                                      key = zStrdup ((char *) val);
2065                                    }
2066                                  else
2067                                    {
2068                                      has =
2069                                        (char *)
2070                                        malloc ((4 + xmlStrlen (val) +
2071                                                 strlen (key)) *
2072                                                sizeof (char));
2073                                      if (has == NULL)
2074                                        {
2075                                          return errorException (m,
2076                                                                 _
2077                                                                 ("Unable to allocate memory."),
2078                                                                 "InternalError",
2079                                                                 NULL);
2080                                        }
2081                                      snprintf (has,
2082                                                (3 + xmlStrlen (val) +
2083                                                 strlen (key)), "%s: %s", key,
2084                                                (char *) val);
2085                                      free (key);
2086#ifdef POST_DEBUG
2087                                      fprintf (stderr, "%s\n", has);
2088#endif
2089                                    }
2090                                  xmlFree (val);
2091                                }
2092                              hInternet.ihandle[hInternet.nb].header =
2093                                curl_slist_append (hInternet.ihandle
2094                                                   [hInternet.nb].header,
2095                                                   has);
2096                              if (has != NULL)
2097                                free (has);
2098                            }
2099                          else
2100                            {
2101#ifdef POST_DEBUG
2102                              fprintf (stderr,
2103                                       "Try to fetch the body part of the request ...\n");
2104#endif
2105                              if (xmlStrcasecmp (cur3->name, BAD_CAST "Body")
2106                                  == 0)
2107                                {
2108#ifdef POST_DEBUG
2109                                  fprintf (stderr, "Body part found !!!\n",
2110                                           (char *) cur3->content);
2111#endif
2112                                  char *tmp =
2113                                    (char *) malloc (cgiContentLength +
2114                                                     1 * sizeof (char));
2115                                  memset (tmp, 0, cgiContentLength);
2116                                  xmlNodePtr cur4 = cur3->children;
2117                                  while (cur4 != NULL)
2118                                    {
2119                                      while (cur4->type != XML_ELEMENT_NODE)
2120                                        cur4 = cur4->next;
2121                                      xmlDocPtr bdoc =
2122                                        xmlNewDoc (BAD_CAST "1.0");
2123                                      bdoc->encoding =
2124                                        xmlCharStrdup ("UTF-8");
2125                                      xmlDocSetRootElement (bdoc, cur4);
2126                                      xmlChar *btmps;
2127                                      int bsize;
2128                                      xmlDocDumpMemory (bdoc, &btmps, &bsize);
2129#ifdef POST_DEBUG
2130                                      fprintf (stderr,
2131                                               "Body part found !!! %s %s\n",
2132                                               tmp, (char *) btmps);
2133#endif
2134                                      if (btmps != NULL)
2135                                        sprintf (tmp, "%s", (char *) btmps);
2136                                      xmlFree (btmps);
2137                                      cur4 = cur4->next;
2138                                      xmlFreeDoc (bdoc);
2139                                    }
2140                                  map *btmp =
2141                                    getMap (tmpmaps->content, "href");
2142                                  if (btmp != NULL)
2143                                    {
2144#ifdef POST_DEBUG
2145                                      fprintf (stderr, "%s %s\n", btmp->value,
2146                                               tmp);
2147                                      curl_easy_setopt (hInternet.handle,
2148                                                        CURLOPT_VERBOSE, 1);
2149#endif
2150                                      hInternet.
2151                                        waitingRequests[hInternet.nb] =
2152                                        strdup (tmp);
2153                                      InternetOpenUrl (&hInternet,
2154                                                       btmp->value,
2155                                                       hInternet.waitingRequests
2156                                                       [hInternet.nb],
2157                                                       strlen
2158                                                       (hInternet.waitingRequests
2159                                                        [hInternet.nb]),
2160                                                       INTERNET_FLAG_NO_CACHE_WRITE,
2161                                                       0);
2162                                    }
2163                                  free (tmp);
2164                                }
2165                              else
2166                                if (xmlStrcasecmp
2167                                    (cur3->name,
2168                                     BAD_CAST "BodyReference") == 0)
2169                                {
2170                                  xmlChar *val =
2171                                    xmlGetProp (cur3, BAD_CAST "href");
2172                                  HINTERNET bInternet, res1;
2173                                  bInternet = InternetOpen (
2174#ifndef WIN32
2175                                                             (LPCTSTR)
2176#endif
2177                                                             "ZooWPSClient\0",
2178                                                             INTERNET_OPEN_TYPE_PRECONFIG,
2179                                                             NULL, NULL, 0);
2180                                  if (!CHECK_INET_HANDLE (hInternet))
2181                                    fprintf (stderr,
2182                                             "WARNING : hInternet handle failed to initialize");
2183#ifdef POST_DEBUG
2184                                  curl_easy_setopt (bInternet.handle,
2185                                                    CURLOPT_VERBOSE, 1);
2186#endif
2187                                  bInternet.waitingRequests[0] =
2188                                    strdup ((char *) val);
2189                                  res1 =
2190                                    InternetOpenUrl (&bInternet,
2191                                                     bInternet.waitingRequests
2192                                                     [0], NULL, 0,
2193                                                     INTERNET_FLAG_NO_CACHE_WRITE,
2194                                                     0);
2195                                  processDownloads (&bInternet);
2196                                  char *tmp =
2197                                    (char *)
2198                                    malloc ((bInternet.ihandle[0].nDataLen +
2199                                             1) * sizeof (char));
2200                                  if (tmp == NULL)
2201                                    {
2202                                      return errorException (m,
2203                                                             _
2204                                                             ("Unable to allocate memory."),
2205                                                             "InternalError",
2206                                                             NULL);
2207                                    }
2208                                  size_t bRead;
2209                                  InternetReadFile (bInternet.ihandle[0],
2210                                                    (LPVOID) tmp,
2211                                                    bInternet.
2212                                                    ihandle[0].nDataLen,
2213                                                    &bRead);
2214                                  tmp[bInternet.ihandle[0].nDataLen] = 0;
2215                                  InternetCloseHandle (&bInternet);
2216                                  map *btmp =
2217                                    getMap (tmpmaps->content, "href");
2218                                  if (btmp != NULL)
2219                                    {
2220#ifdef POST_DEBUG
2221                                      fprintf (stderr, "%s %s\n", btmp->value,
2222                                               tmp);
2223#endif
2224                                      hInternet.
2225                                        waitingRequests[hInternet.nb] =
2226                                        strdup (tmp);
2227                                      res =
2228                                        InternetOpenUrl (&hInternet,
2229                                                         btmp->value,
2230                                                         hInternet.waitingRequests
2231                                                         [hInternet.nb],
2232                                                         strlen
2233                                                         (hInternet.waitingRequests
2234                                                          [hInternet.nb]),
2235                                                         INTERNET_FLAG_NO_CACHE_WRITE,
2236                                                         0);
2237                                    }
2238                                  free (tmp);
2239                                }
2240                            }
2241                          cur3 = cur3->next;
2242                        }
2243#ifdef POST_DEBUG
2244                      fprintf (stderr,
2245                               "Header and Body was parsed from Reference \n");
2246#endif
2247#ifdef DEBUG
2248                      dumpMap (tmpmaps->content);
2249                      fprintf (stderr, "= element 2 node \"%s\" = (%s)\n",
2250                               cur2->name, cur2->content);
2251#endif
2252                    }
2253                  else if (xmlStrcasecmp (cur2->name, BAD_CAST "Data") == 0)
2254                    {
2255#ifdef DEBUG
2256                      fprintf (stderr, "DATA\n");
2257#endif
2258                      xmlNodePtr cur4 = cur2->children;
2259                      while (cur4 != NULL)
2260                        {
2261                          while (cur4 != NULL
2262                                 && cur4->type != XML_ELEMENT_NODE)
2263                            cur4 = cur4->next;
2264                          if (cur4 == NULL)
2265                            break;
2266                          if (xmlStrcasecmp
2267                              (cur4->name, BAD_CAST "LiteralData") == 0)
2268                            {
2269                /**
2270                 * Get every attribute from a LiteralData node
2271                 * dataType , uom
2272                 */
2273                              char *list[2];
2274                              list[0] = zStrdup ("dataType");
2275                              list[1] = zStrdup ("uom");
2276                              for (int l = 0; l < 2; l++)
2277                                {
2278#ifdef DEBUG
2279                                  fprintf (stderr, "*** LiteralData %s ***",
2280                                           list[l]);
2281#endif
2282                                  xmlChar *val =
2283                                    xmlGetProp (cur4, BAD_CAST list[l]);
2284                                  if (val != NULL
2285                                      && strlen ((char *) val) > 0)
2286                                    {
2287                                      if (tmpmaps->content != NULL)
2288                                        addToMap (tmpmaps->content, list[l],
2289                                                  (char *) val);
2290                                      else
2291                                        tmpmaps->content =
2292                                          createMap (list[l], (char *) val);
2293#ifdef DEBUG
2294                                      fprintf (stderr, "%s\n", val);
2295#endif
2296                                    }
2297                                  xmlFree (val);
2298                                  free (list[l]);
2299                                }
2300                            }
2301                          else
2302                            if (xmlStrcasecmp
2303                                (cur4->name, BAD_CAST "ComplexData") == 0)
2304                            {
2305                /**
2306                 * Get every attribute from a Reference node
2307                 * mimeType, encoding, schema
2308                 */
2309                              const char *coms[3] =
2310                                { "mimeType", "encoding", "schema" };
2311                              for (int l = 0; l < 3; l++)
2312                                {
2313#ifdef DEBUG
2314                                  fprintf (stderr, "*** ComplexData %s ***\n",
2315                                           coms[l]);
2316#endif
2317                                  xmlChar *val =
2318                                    xmlGetProp (cur4, BAD_CAST coms[l]);
2319                                  if (val != NULL
2320                                      && strlen ((char *) val) > 0)
2321                                    {
2322                                      if (tmpmaps->content != NULL)
2323                                        addToMap (tmpmaps->content, coms[l],
2324                                                  (char *) val);
2325                                      else
2326                                        tmpmaps->content =
2327                                          createMap (coms[l], (char *) val);
2328#ifdef DEBUG
2329                                      fprintf (stderr, "%s\n", val);
2330#endif
2331                                    }
2332                                  xmlFree (val);
2333                                }
2334                            }
2335
2336                          map *test = getMap (tmpmaps->content, "encoding");
2337
2338                          if (test == NULL)
2339                            { 
2340                              if (tmpmaps->content != NULL)
2341                                addToMap (tmpmaps->content, "encoding",
2342                                          "utf-8");
2343                              else
2344                                tmpmaps->content =
2345                                  createMap ("encoding", "utf-8");
2346                              test = getMap (tmpmaps->content, "encoding");
2347                            }
2348
2349                          if (strcasecmp (test->value, "base64") != 0)
2350                            { 
2351                              xmlChar *mv = xmlNodeListGetString (doc,
2352                                                                  cur4->
2353                                                                  xmlChildrenNode,
2354                                                                  1);
2355                              map *ltmp =
2356                                getMap (tmpmaps->content, "mimeType");
2357                              if (mv == NULL
2358                                  ||
2359                                  (xmlStrcasecmp
2360                                   (cur4->name, BAD_CAST "ComplexData") == 0
2361                                   && (ltmp == NULL
2362                                       || strncasecmp (ltmp->value,
2363                                                       "text/xml", 8) == 0)))
2364                                {
2365                                  xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0");
2366                                  int buffersize;
2367                                  xmlNodePtr cur5 = cur4->children;
2368                                  while (cur5 != NULL
2369                                         && cur5->type != XML_ELEMENT_NODE
2370                                         && cur5->type !=
2371                                         XML_CDATA_SECTION_NODE)
2372                                    cur5 = cur5->next;
2373                                  if (cur5 != NULL
2374                                      && cur5->type != XML_CDATA_SECTION_NODE)
2375                                    {
2376                                      xmlDocSetRootElement (doc1, cur5);
2377                                      xmlDocDumpFormatMemoryEnc (doc1, &mv,
2378                                                                 &buffersize,
2379                                                                 "utf-8", 1);
2380                                      char size[1024];
2381                                      sprintf (size, "%d", buffersize);
2382                                      addToMap (tmpmaps->content, "size",
2383                                                size);
2384                                      xmlFreeDoc (doc1);
2385                                    }                                                                   
2386                                }
2387                              if (mv != NULL)
2388                                {
2389                                  addToMap (tmpmaps->content, "value",
2390                                            (char *) mv);
2391                                  xmlFree (mv);
2392                                }
2393                            }
2394                          else
2395                            {
2396                              xmlChar *tmp = xmlNodeListGetRawString (doc,
2397                                                                      cur4->xmlChildrenNode,
2398                                                                      0);
2399                              addToMap (tmpmaps->content, "value",
2400                                        (char *) tmp);
2401                              map *tmpv = getMap (tmpmaps->content, "value");
2402                              char *res = NULL;
2403                              char *curs = tmpv->value;
2404                              for (int i = 0; i <= strlen (tmpv->value) / 64;
2405                                   i++)
2406                                {
2407                                  if (res == NULL)
2408                                    res =
2409                                      (char *) malloc (67 * sizeof (char));
2410                                  else
2411                                    res =
2412                                      (char *) realloc (res,
2413                                                        (((i + 1) * 65) +
2414                                                         i) * sizeof (char));
2415                                  int csize = i * 65;
2416                                  strncpy (res + csize, curs, 64);
2417                                  if (i == xmlStrlen (tmp) / 64)
2418                                    strcat (res, "\n\0");
2419                                  else
2420                                    {
2421                                      strncpy (res + (((i + 1) * 64) + i),
2422                                               "\n\0", 2);
2423                                      curs += 64;
2424                                    }
2425                                }
2426                              free (tmpv->value);
2427                              tmpv->value = zStrdup (res);
2428                              free (res);
2429                              xmlFree (tmp);
2430                            }
2431                          cur4 = cur4->next;
2432                        }
2433                    }
2434#ifdef DEBUG
2435                  fprintf (stderr, "cur2 next \n");
2436                  fflush (stderr);
2437#endif
2438                  cur2 = cur2->next;
2439                }
2440#ifdef DEBUG
2441              fprintf (stderr, "ADD MAPS TO REQUEST MAPS !\n");
2442              fflush (stderr);
2443#endif
2444
2445              {
2446                maps *testPresence =
2447                  getMaps (request_input_real_format, tmpmaps->name);
2448                if (testPresence != NULL)
2449                  {
2450                    elements *elem = getElements (s1->inputs, tmpmaps->name);
2451                    if (elem != NULL)
2452                      {
2453                        if (appendMapsToMaps
2454                            (m, request_input_real_format, tmpmaps, elem) < 0)
2455                          {
2456                            freeMaps (&m);
2457                            free (m);
2458                            free (REQUEST);
2459                            free (SERVICE_URL);
2460                            InternetCloseHandle (&hInternet);
2461                            freeService (&s1);
2462                            free (s1);
2463                            return 0;
2464                          }
2465                      }
2466                  }
2467                else
2468                  addMapsToMaps (&request_input_real_format, tmpmaps);
2469              }
2470
2471#ifdef DEBUG
2472              fprintf (stderr, "******TMPMAPS*****\n");
2473              dumpMaps (tmpmaps);
2474              fprintf (stderr, "******REQUESTMAPS*****\n");
2475              dumpMaps (request_input_real_format);
2476#endif
2477              freeMaps (&tmpmaps);
2478              free (tmpmaps);
2479              tmpmaps = NULL;
2480            }
2481#ifdef DEBUG
2482          dumpMaps (tmpmaps);
2483#endif
2484        }
2485#ifdef DEBUG
2486      fprintf (stderr, "Search for response document node\n");
2487#endif
2488      xmlXPathFreeObject (tmpsptr);
2489
2490      tmpsptr =
2491        extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']");
2492      bool asRaw = false;
2493      tmps = tmpsptr->nodesetval;
2494      if (tmps->nodeNr == 0)
2495        {
2496          xmlXPathFreeObject (tmpsptr);
2497          tmpsptr =
2498            extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']");
2499          tmps = tmpsptr->nodesetval;
2500          asRaw = true;
2501        }
2502#ifdef DEBUG
2503      fprintf (stderr, "*****%d*****\n", tmps->nodeNr);
2504#endif
2505      if (asRaw == true)
2506        {
2507          addToMap (request_inputs, "RawDataOutput", "");
2508          xmlNodePtr cur0 = tmps->nodeTab[0];
2509          if (cur0->type == XML_ELEMENT_NODE)
2510            {
2511
2512              maps *tmpmaps = (maps *) malloc (MAPS_SIZE);
2513              if (tmpmaps == NULL)
2514                {
2515                  return errorException (m, _("Unable to allocate memory."),
2516                                         "InternalError", NULL);
2517                }
2518              tmpmaps->name = zStrdup ("unknownIdentifier");
2519              tmpmaps->content = NULL;
2520              tmpmaps->next = NULL;
2521
2522        /**
2523         * Get every attribute from a RawDataOutput node
2524         * mimeType, encoding, schema, uom
2525         */
2526              const char *outs[4] =
2527                { "mimeType", "encoding", "schema", "uom" };
2528              for (int l = 0; l < 4; l++)
2529                {
2530#ifdef DEBUG
2531                  fprintf (stderr, "*** %s ***\t", outs[l]);
2532#endif
2533                  xmlChar *val = xmlGetProp (cur0, BAD_CAST outs[l]);
2534                  if (val != NULL)
2535                    {
2536                      if (strlen ((char *) val) > 0)
2537                        {
2538                          if (tmpmaps->content != NULL)
2539                            addToMap (tmpmaps->content, outs[l],
2540                                      (char *) val);
2541                          else
2542                            tmpmaps->content =
2543                              createMap (outs[l], (char *) val);
2544                        }
2545                      xmlFree (val);
2546                    }
2547                }
2548              xmlNodePtr cur2 = cur0->children;
2549              while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
2550                cur2 = cur2->next;
2551              while (cur2 != NULL)
2552                {
2553                  if (xmlStrncasecmp
2554                      (cur2->name, BAD_CAST "Identifier",
2555                       xmlStrlen (cur2->name)) == 0)
2556                    {
2557                      xmlChar *val =
2558                        xmlNodeListGetString (NULL, cur2->xmlChildrenNode, 1);
2559                      free (tmpmaps->name);
2560                      tmpmaps->name = zStrdup ((char *) val);
2561                      xmlFree (val);
2562                    }
2563                  cur2 = cur2->next;
2564                  while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
2565                    cur2 = cur2->next;
2566                }
2567              if (request_output_real_format == NULL)
2568                request_output_real_format = dupMaps (&tmpmaps);
2569              else
2570                addMapsToMaps (&request_output_real_format, tmpmaps);
2571              if (tmpmaps != NULL)
2572                {
2573                  freeMaps (&tmpmaps);
2574                  free (tmpmaps);
2575                  tmpmaps = NULL;
2576                }
2577            }
2578        }
2579      else
2580          {
2581                addToMap (request_inputs, "ResponseDocument", "");
2582                       
2583                xmlNodePtr cur = tmps->nodeTab[0]; // only one ResponseDocument node
2584                if (cur->type == XML_ELEMENT_NODE) {
2585                /**
2586                 * Get every attribute: storeExecuteResponse, lineage, status
2587                 */
2588                        //map* attributes = NULL;
2589                        const char *ress[3] =
2590                          { "storeExecuteResponse", "lineage", "status" };
2591                        xmlChar *val;
2592                        for (int l = 0; l < 3; l++)
2593                        {
2594        #ifdef DEBUG
2595                                fprintf (stderr, "*** %s ***\t", ress[l]);
2596        #endif
2597                                val = xmlGetProp (cur, BAD_CAST ress[l]);
2598                                if (val != NULL && strlen ((char *) val) > 0)
2599                                {
2600                                /*
2601                                        if (attributes == NULL) {
2602                                                attributes = createMap (ress[l], (char *) val);
2603                                        }
2604                                        else {
2605                                                addToMap (attributes, ress[l], (char *) val);
2606                                        }
2607                                */             
2608                                        addToMap (request_inputs, ress[l], (char *) val);
2609                                  }
2610        #ifdef DEBUG
2611                                fprintf (stderr, "%s\n", val);
2612        #endif
2613                                xmlFree (val);
2614                        }
2615                       
2616                        xmlNodePtr cur1 = cur->children;               
2617                        while (cur1 != NULL) // iterate over Output nodes
2618                        {
2619                                if (cur1->type != XML_ELEMENT_NODE || 
2620                                        xmlStrncasecmp(cur1->name, BAD_CAST "Output", 
2621                                                                   xmlStrlen (cur1->name)) != 0) {
2622                                        cur1 = cur1->next;
2623                                        continue;
2624                                }
2625                               
2626                                maps *tmpmaps = (maps *) malloc (MAPS_SIZE); // one per Output node
2627                                if (tmpmaps == NULL) {
2628                                        return errorException (m,
2629                                                                                   _
2630                                                                                   ("Unable to allocate memory."),
2631                                                                                   "InternalError", NULL);
2632                                }
2633                                tmpmaps->name = zStrdup ("unknownIdentifier");
2634                                tmpmaps->content = NULL;
2635                                tmpmaps->next = NULL;
2636                               
2637                                xmlNodePtr elems = cur1->children;
2638                               
2639                                while (elems != NULL) {
2640                               
2641                                        /**
2642                                         * Identifier
2643                                         */             
2644                                        if (xmlStrncasecmp
2645                                                (elems->name, BAD_CAST "Identifier",
2646                                                 xmlStrlen (elems->name)) == 0)
2647                                        {                       
2648                                                xmlChar *val =
2649                                                  xmlNodeListGetString (doc, elems->xmlChildrenNode, 1);
2650                                               
2651                                                free(tmpmaps->name);
2652                                                tmpmaps->name = zStrdup ((char *) val); 
2653                                                if (tmpmaps->content == NULL) {
2654                                                        tmpmaps->content = createMap("Identifier", zStrdup ((char *) val));
2655                                                }
2656                                                else {
2657                                                        addToMap(tmpmaps->content, "Identifier", zStrdup ((char *) val));
2658                                                }
2659                                         
2660                                                map* tt = getMap (request_inputs, "ResponseDocument");                           
2661                                                if (strlen(tt->value) == 0) {
2662                                                  addToMap (request_inputs, "ResponseDocument",
2663                                                                        (char *) val);                                                 
2664                                                }       
2665                                                else {
2666                                                        char* tmp = (char*) malloc((strlen(tt->value) + 1 
2667                                                                                                + strlen((char*) val) + 1) * sizeof(char));
2668                                                        sprintf (tmp, "%s;%s", tt->value, (char *) val);
2669                                                        free(tt->value);
2670                                                        tt->value = tmp;       
2671                                                }       
2672                                                xmlFree (val);
2673                                        }                               
2674                                        /**
2675                                         * Title, Abstract
2676                                         */
2677                                        else if (xmlStrncasecmp(elems->name, BAD_CAST "Title",
2678                                                                                        xmlStrlen (elems->name)) == 0
2679                                                  || xmlStrncasecmp(elems->name, BAD_CAST "Abstract",
2680                                                                                 xmlStrlen (elems->name)) == 0)
2681                                        {
2682                                                xmlChar *val =
2683                                                        xmlNodeListGetString (doc, elems->xmlChildrenNode, 1);
2684                                                       
2685                                                if (tmpmaps->content == NULL) {
2686                                                        tmpmaps->content = createMap((char*) elems->name, zStrdup ((char *) val));
2687                                                }
2688                                                else {
2689                                                        addToMap(tmpmaps->content, (char*) elems->name, zStrdup ((char *) val));
2690                                                }
2691                                                xmlFree (val);
2692                                        }
2693                                        elems = elems->next;
2694                                }
2695                               
2696                                /**
2697                                 * Get every attribute from an Output node:
2698                                 * mimeType, encoding, schema, uom, asReference
2699                                 */
2700                                const char *outs[5] =
2701                                          { "mimeType", "encoding", "schema", "uom", "asReference" };
2702                                         
2703                                for (int l = 0; l < 5; l++) {
2704        #ifdef DEBUG
2705                                        fprintf (stderr, "*** %s ***\t", outs[l]);
2706        #endif
2707                                        xmlChar *val = xmlGetProp (cur1, BAD_CAST outs[l]);                             
2708                                        if (val != NULL && xmlStrlen(val) > 0) {
2709                                                if (tmpmaps->content != NULL) {
2710                                                        addToMap (tmpmaps->content, outs[l], (char *) val);
2711                                                }                         
2712                                                else {
2713                                                        tmpmaps->content = createMap (outs[l], (char *) val);
2714                                                }       
2715                                        }
2716        #ifdef DEBUG
2717                                        fprintf (stderr, "%s\n", val);
2718        #endif
2719                                        xmlFree (val);
2720                                }
2721                               
2722                                if (request_output_real_format == NULL) {
2723                                        request_output_real_format = tmpmaps;
2724                                }       
2725                                else if (getMaps(request_output_real_format, tmpmaps->name) != NULL) {
2726                                        return errorException (m,
2727                                                                                   _
2728                                                                                   ("Duplicate <Output> elements in WPS Execute request"),
2729                                                                                   "InternalError", NULL);
2730                                }
2731                                else {
2732                                        maps* mptr = request_output_real_format;
2733                                        while (mptr->next != NULL) {
2734                                                mptr = mptr->next;
2735                                        }
2736                                        mptr->next = tmpmaps;   
2737                                }                                       
2738                                cur1 = cur1->next;
2739                        }                       
2740                }
2741          } 
2742      xmlXPathFreeObject (tmpsptr);
2743      xmlFreeDoc (doc);
2744      xmlCleanupParser ();
2745    }
2746
2747  runHttpRequests (&m, &request_input_real_format, &hInternet);
2748
2749  //  if(CHECK_INET_HANDLE(hInternet))
2750  InternetCloseHandle (&hInternet);
2751
2752#ifdef DEBUG
2753  fprintf (stderr, "\n%d\n", __LINE__);
2754  fflush (stderr);
2755  dumpMaps (request_input_real_format);
2756  dumpMaps (request_output_real_format);
2757  dumpMap (request_inputs);
2758  fprintf (stderr, "\n%d\n", __LINE__);
2759  fflush (stderr);
2760#endif
2761
2762  /**
2763   * Ensure that each requested arguments are present in the request
2764   * DataInputs and ResponseDocument / RawDataOutput
2765   */
2766  map* errI=NULL;
2767#ifdef DEBUG 
2768  dumpMaps(request_input_real_format);
2769#endif 
2770  char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0,&errI);
2771#ifdef DEBUG 
2772  dumpMaps(request_input_real_format);
2773#endif 
2774  maps *ptr = request_input_real_format;
2775  while (ptr != NULL)
2776    {
2777      map *tmp0 = getMap (ptr->content, "size");
2778      map *tmp1 = getMap (ptr->content, "maximumMegabytes");
2779      if (tmp1 != NULL && tmp0 != NULL)
2780        {
2781          float i = atof (tmp0->value) / 1048576.0;
2782          if (i >= atoi (tmp1->value))
2783            {
2784              char tmps[1024];
2785              map *tmpe = createMap ("code", "FileSizeExceeded");
2786              snprintf (tmps, 1024,
2787                        _
2788                        ("The <%s> parameter has a limited size (%sMB) defined in ZOO ServicesProvider configuration file but the reference you provided exceed this limitation (%fMB), please correct your query or the ZOO Configuration file."),
2789                        ptr->name, tmp1->value, i);
2790              addToMap (tmpe, "locator", ptr->name);
2791              addToMap (tmpe, "text", tmps);
2792              printExceptionReportResponse (m, tmpe);
2793              freeService (&s1);
2794              free (s1);
2795              freeMap (&tmpe);
2796              free (tmpe);
2797              freeMaps (&m);
2798              free (m);
2799              free (REQUEST);
2800              free (SERVICE_URL);
2801              freeMaps (&request_input_real_format);
2802              free (request_input_real_format);
2803              freeMaps (&request_output_real_format);
2804              free (request_output_real_format);
2805              freeMaps (&tmpmaps);
2806              free (tmpmaps);
2807              return 1;
2808            }
2809        }
2810      ptr = ptr->next;
2811    }
2812
2813  map* errO=NULL;
2814  char *dfv1 =
2815    addDefaultValues (&request_output_real_format, s1->outputs, m, 1,&errO);
2816  if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0)
2817    {
2818      char tmps[1024];
2819      map *tmpe = NULL;
2820      if (strcmp (dfv, "") != 0)
2821        {
2822          tmpe = createMap ("code", "MissingParameterValue");
2823          int nb=0;
2824          int length=1;
2825          map* len=getMap(errI,"length");
2826          if(len!=NULL)
2827            length=atoi(len->value);
2828          for(nb=0;nb<length;nb++){
2829            map* errp=getMapArray(errI,"value",nb);
2830            snprintf (tmps, 1024,
2831                      _
2832                      ("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."),
2833                      errp->value);
2834            setMapArray (tmpe, "locator", nb , errp->value);
2835            setMapArray (tmpe, "text", nb , tmps);
2836            setMapArray (tmpe, "code", nb , "MissingParameterValue");
2837          }
2838        }
2839      if (strcmp (dfv1, "") != 0)
2840        {
2841          int ilength=0;
2842          if(tmpe==NULL)
2843            tmpe = createMap ("code", "InvalidParameterValue");
2844          else{
2845            map* len=getMap(tmpe,"length");
2846            if(len!=NULL)
2847              ilength=atoi(len->value);
2848          }
2849          int nb=0;
2850          int length=1;
2851          map* len=getMap(errO,"length");
2852          if(len!=NULL)
2853            length=atoi(len->value);
2854          for(nb=0;nb<length;nb++){
2855            map* errp=getMapArray(errO,"value",nb);
2856            snprintf (tmps, 1024,
2857                      _
2858                      ("The <%s> argument was specified as %s identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."),
2859                      errp->value,
2860                      ((getMap(request_inputs,"RawDataOutput")!=NULL)?"RawDataOutput":"ResponseDocument"));
2861            setMapArray (tmpe, "locator", nb+ilength , errp->value);
2862            setMapArray (tmpe, "text", nb+ilength , tmps);
2863            setMapArray (tmpe, "code", nb+ilength , "InvalidParameterValue");
2864          }
2865        }
2866      printExceptionReportResponse (m, tmpe);
2867      freeService (&s1);
2868      free (s1);
2869      freeMap (&tmpe);
2870      free (tmpe);
2871      freeMaps (&m);
2872      free (m);
2873      free (REQUEST);
2874      free (SERVICE_URL);
2875      freeMaps (&request_input_real_format);
2876      free (request_input_real_format);
2877      freeMaps (&request_output_real_format);
2878      free (request_output_real_format);
2879      freeMaps (&tmpmaps);
2880      free (tmpmaps);
2881      if(errI!=NULL){
2882        freeMap(&errI);
2883        free(errI);
2884      }
2885      if(errO!=NULL){
2886        freeMap(&errO);
2887        free(errO);
2888      }
2889      return 1;
2890    }
2891  maps *tmpReqI = request_input_real_format;
2892  while (tmpReqI != NULL)
2893    {
2894      char name[1024];
2895      if (getMap (tmpReqI->content, "isFile") != NULL)
2896        {
2897          if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) ==
2898              cgiFormSuccess)
2899            {
2900              int BufferLen = 1024;
2901              cgiFilePtr file;
2902              int targetFile;
2903              char storageNameOnServer[2048];
2904              char fileNameOnServer[64];
2905              char contentType[1024];
2906              char buffer[1024];
2907              char *tmpStr = NULL;
2908              int size;
2909              int got, t;
2910              map *path = getMapFromMaps (m, "main", "tmpPath");
2911              cgiFormFileSize (tmpReqI->name, &size);
2912              cgiFormFileContentType (tmpReqI->name, contentType,
2913                                      sizeof (contentType));
2914              if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess)
2915                {
2916                  t = -1;
2917                  while (1)
2918                    {
2919                      tmpStr = strstr (name + t + 1, "\\");
2920                      if (NULL == tmpStr)
2921                        tmpStr = strstr (name + t + 1, "/");
2922                      if (NULL != tmpStr)
2923                        t = (int) (tmpStr - name);
2924                      else
2925                        break;
2926                    }
2927                  strcpy (fileNameOnServer, name + t + 1);
2928
2929                  sprintf (storageNameOnServer, "%s/%s", path->value,
2930                           fileNameOnServer);
2931#ifdef DEBUG
2932                  fprintf (stderr, "Name on server %s\n",
2933                           storageNameOnServer);
2934                  fprintf (stderr, "fileNameOnServer: %s\n",
2935                           fileNameOnServer);
2936#endif
2937                  targetFile =
2938                    open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,
2939                          S_IRWXU | S_IRGRP | S_IROTH);
2940                  if (targetFile < 0)
2941                    {
2942#ifdef DEBUG
2943                      fprintf (stderr, "could not create the new file,%s\n",
2944                               fileNameOnServer);
2945#endif
2946                    }
2947                  else
2948                    {
2949                      while (cgiFormFileRead (file, buffer, BufferLen, &got)
2950                             == cgiFormSuccess)
2951                        {
2952                          if (got > 0)
2953                            write (targetFile, buffer, got);
2954                        }
2955                    }
2956                  addToMap (tmpReqI->content, "lref", storageNameOnServer);
2957                  cgiFormFileClose (file);
2958                  close (targetFile);
2959#ifdef DEBUG
2960                  fprintf (stderr, "File \"%s\" has been uploaded",
2961                           fileNameOnServer);
2962#endif
2963                }
2964            }
2965        }
2966      tmpReqI = tmpReqI->next;
2967    }
2968
2969  ensureDecodedBase64 (&request_input_real_format);
2970
2971#ifdef DEBUG
2972  fprintf (stderr, "REQUEST_INPUTS\n");
2973  dumpMaps (request_input_real_format);
2974  fprintf (stderr, "REQUEST_OUTPUTS\n");
2975  dumpMaps (request_output_real_format);
2976#endif
2977
2978  maps *curs = getMaps (m, "env");
2979  if (curs != NULL)
2980    {
2981      map *mapcs = curs->content;
2982      while (mapcs != NULLMAP)
2983        {
2984#ifndef WIN32
2985          setenv (mapcs->name, mapcs->value, 1);
2986#else
2987#ifdef DEBUG
2988          fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name,
2989                   mapcs->value);
2990#endif
2991          if (mapcs->value[strlen (mapcs->value) - 2] == '\r')
2992            {
2993#ifdef DEBUG
2994              fprintf (stderr, "[ZOO: Env var finish with \r]\n");
2995#endif
2996              mapcs->value[strlen (mapcs->value) - 1] = 0;
2997            }
2998#ifdef DEBUG
2999          if (SetEnvironmentVariable (mapcs->name, mapcs->value) == 0)
3000            {
3001              fflush (stderr);
3002              fprintf (stderr, "setting variable... %s\n", "OK");
3003            }
3004          else
3005            {
3006              fflush (stderr);
3007              fprintf (stderr, "setting variable... %s\n", "OK");
3008            }
3009#else
3010
3011
3012          SetEnvironmentVariable (mapcs->name, mapcs->value);
3013#endif
3014          char *toto =
3015            (char *)
3016            malloc ((strlen (mapcs->name) + strlen (mapcs->value) +
3017                     2) * sizeof (char));
3018          sprintf (toto, "%s=%s", mapcs->name, mapcs->value);
3019          putenv (toto);
3020#ifdef DEBUG
3021          fflush (stderr);
3022#endif
3023#endif
3024#ifdef DEBUG
3025          fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name,
3026                   mapcs->value);
3027          fflush (stderr);
3028#endif
3029          mapcs = mapcs->next;
3030        }
3031    }
3032
3033#ifdef DEBUG
3034  dumpMap (request_inputs);
3035#endif
3036
3037  /**
3038   * Need to check if we need to fork to load a status enabled
3039   */
3040  r_inputs = NULL;
3041  map *store = getMap (request_inputs, "storeExecuteResponse");
3042  map *status = getMap (request_inputs, "status");
3043  /**
3044   * 05-007r7 WPS 1.0.0 page 57 :
3045   * 'If status="true" and storeExecuteResponse is "false" then the service
3046   * shall raise an exception.'
3047   */
3048  if (status != NULL && strcmp (status->value, "true") == 0 &&
3049      store != NULL && strcmp (store->value, "false") == 0)
3050    {
3051      errorException (m,
3052                      _
3053                      ("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."),
3054                      "InvalidParameterValue", "storeExecuteResponse");
3055      freeService (&s1);
3056      free (s1);
3057      freeMaps (&m);
3058      free (m);
3059
3060      freeMaps (&request_input_real_format);
3061      free (request_input_real_format);
3062
3063      freeMaps (&request_output_real_format);
3064      free (request_output_real_format);
3065
3066      free (REQUEST);
3067      free (SERVICE_URL);
3068      return 1;
3069    }
3070  r_inputs = getMap (request_inputs, "storeExecuteResponse");
3071  int eres = SERVICE_STARTED;
3072  int cpid = getpid ();
3073
3074  /**
3075   * Initialize the specific [lenv] section which contains runtime variables:
3076   *
3077   *  - usid : it is an unique identification number
3078   *  - sid : it is the process idenfitication number (OS)
3079   *  - status : value between 0 and 100 to express the  completude of
3080   * the operations of the running service
3081   *  - message : is a string where you can store error messages, in case
3082   * service is failing, or o provide details on the ongoing operation.
3083   *  - cwd : is the current working directory
3084   *  - soap : is a boolean value, true if the request was contained in a SOAP
3085   * Envelop
3086   *  - sessid : string storing the session identifier (only when cookie is
3087   * used)
3088   *  - cgiSid : only defined on Window platforms (for being able to identify
3089   * the created process)
3090   *
3091   */
3092  maps *_tmpMaps = (maps *) malloc (MAPS_SIZE);
3093  _tmpMaps->name = zStrdup ("lenv");
3094  char tmpBuff[100];
3095  semid lid = getShmLockId (NULL, 1);
3096  lockShm (lid);
3097  struct ztimeval tp;
3098  if (zGettimeofday (&tp, NULL) == 0)
3099    sprintf (tmpBuff, "%i", (cpid + ((int) tp.tv_sec + (int) tp.tv_usec)));
3100  else
3101    sprintf (tmpBuff, "%i", (cpid + (int) time (NULL)));
3102  unlockShm (lid);
3103  removeShmLock (NULL, 1);
3104  _tmpMaps->content = createMap ("usid", tmpBuff);
3105  _tmpMaps->next = NULL;
3106  sprintf (tmpBuff, "%i", cpid);
3107  addToMap (_tmpMaps->content, "sid", tmpBuff);
3108  addToMap (_tmpMaps->content, "status", "0");
3109  addToMap (_tmpMaps->content, "cwd", ntmp);
3110  addToMap (_tmpMaps->content, "message", _("No message provided"));
3111  map *ltmp = getMap (request_inputs, "soap");
3112  if (ltmp != NULL)
3113    addToMap (_tmpMaps->content, "soap", ltmp->value);
3114  else
3115    addToMap (_tmpMaps->content, "soap", "false");
3116  if (cgiCookie != NULL && strlen (cgiCookie) > 0)
3117    {
3118      int hasValidCookie = -1;
3119      char *tcook = zStrdup (cgiCookie);
3120      char *tmp = NULL;
3121      map *testing = getMapFromMaps (m, "main", "cookiePrefix");
3122      if (testing == NULL)
3123        {
3124          tmp = zStrdup ("ID=");
3125        }
3126      else
3127        {
3128          tmp =
3129            (char *) malloc ((strlen (testing->value) + 2) * sizeof (char));
3130          sprintf (tmp, "%s=", testing->value);
3131        }
3132      if (strstr (cgiCookie, ";") != NULL)
3133        {
3134          char *token, *saveptr;
3135          token = strtok_r (cgiCookie, ";", &saveptr);
3136          while (token != NULL)
3137            {
3138              if (strcasestr (token, tmp) != NULL)
3139                {
3140                  if (tcook != NULL)
3141                    free (tcook);
3142                  tcook = zStrdup (token);
3143                  hasValidCookie = 1;
3144                }
3145              token = strtok_r (NULL, ";", &saveptr);
3146            }
3147        }
3148      else
3149        {
3150          if (strstr (cgiCookie, "=") != NULL
3151              && strcasestr (cgiCookie, tmp) != NULL)
3152            {
3153              tcook = zStrdup (cgiCookie);
3154              hasValidCookie = 1;
3155            }
3156          if (tmp != NULL)
3157            {
3158              free (tmp);
3159            }
3160        }
3161      if (hasValidCookie > 0)
3162        {
3163          addToMap (_tmpMaps->content, "sessid", strstr (tcook, "=") + 1);
3164          char session_file_path[1024];
3165          map *tmpPath = getMapFromMaps (m, "main", "sessPath");
3166          if (tmpPath == NULL)
3167            tmpPath = getMapFromMaps (m, "main", "tmpPath");
3168          char *tmp1 = strtok (tcook, ";");
3169          if (tmp1 != NULL)
3170            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
3171                     strstr (tmp1, "=") + 1);
3172          else
3173            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
3174                     strstr (cgiCookie, "=") + 1);
3175          free (tcook);
3176          maps *tmpSess = (maps *) malloc (MAPS_SIZE);
3177          struct stat file_status;
3178          int istat = stat (session_file_path, &file_status);
3179          if (istat == 0 && file_status.st_size > 0)
3180            {
3181              conf_read (session_file_path, tmpSess);
3182              addMapsToMaps (&m, tmpSess);
3183              freeMaps (&tmpSess);
3184              free (tmpSess);
3185            }
3186        }
3187    }
3188  addMapsToMaps (&m, _tmpMaps);
3189  freeMaps (&_tmpMaps);
3190  free (_tmpMaps);
3191
3192#ifdef DEBUG
3193  dumpMap (request_inputs);
3194#endif
3195#ifdef WIN32
3196  char *cgiSidL = NULL;
3197  if (getenv ("CGISID") != NULL)
3198    addToMap (request_inputs, "cgiSid", getenv ("CGISID"));
3199
3200  char* usidp;
3201  if ( (usidp = getenv("USID")) != NULL ) {
3202    setMapInMaps (m, "lenv", "usid", usidp);
3203  }
3204
3205  map *test1 = getMap (request_inputs, "cgiSid");
3206  if (test1 != NULL)
3207    {
3208      cgiSid = test1->value;
3209      addToMap (request_inputs, "storeExecuteResponse", "true");
3210      addToMap (request_inputs, "status", "true");
3211      setMapInMaps (m, "lenv", "sid", test1->value);
3212      status = getMap (request_inputs, "status");
3213    }
3214#endif
3215  char *fbkp, *fbkp1;
3216  FILE *f0, *f1;
3217  if (status != NULL)
3218    if (strcasecmp (status->value, "false") == 0)
3219      status = NULLMAP;
3220  if (status == NULLMAP)
3221    {
3222      loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
3223                         &request_output_real_format, &eres);
3224    }
3225  else
3226    {
3227      int pid;
3228#ifdef DEBUG
3229      fprintf (stderr, "\nPID : %d\n", cpid);
3230#endif
3231
3232#ifndef WIN32
3233      pid = fork ();
3234#else
3235      if (cgiSid == NULL)
3236        {
3237          createProcess (m, request_inputs, s1, NULL, cpid,
3238                         request_input_real_format,
3239                         request_output_real_format);
3240          pid = cpid;
3241        }
3242      else
3243        {
3244          pid = 0;
3245          cpid = atoi (cgiSid);
3246        }
3247#endif
3248      if (pid > 0)
3249        {
3250      /**
3251       * dady :
3252       * set status to SERVICE_ACCEPTED
3253       */
3254#ifdef DEBUG
3255          fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
3256                   getpid ());
3257#endif
3258          eres = SERVICE_ACCEPTED;
3259        }
3260      else if (pid == 0)
3261        {
3262      /**
3263       * son : have to close the stdout, stdin and stderr to let the parent
3264       * process answer to http client.
3265       */
3266#ifndef WIN32
3267          zSleep (1);
3268#endif
3269          r_inputs = getMapFromMaps (m, "lenv", "usid");
3270          int cpid = atoi (r_inputs->value);
3271          r_inputs = getMapFromMaps (m, "main", "tmpPath");
3272          map *r_inputs1 = getMap (s1->content, "ServiceProvider");
3273          fbkp =
3274            (char *)
3275            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
3276                     1024) * sizeof (char));
3277          sprintf (fbkp, "%s/%s_%d.xml", r_inputs->value, r_inputs1->value,
3278                   cpid);
3279          char *flog =
3280            (char *)
3281            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
3282                     1024) * sizeof (char));
3283          sprintf (flog, "%s/%s_%d_error.log", r_inputs->value,
3284                   r_inputs1->value, cpid);
3285#ifdef DEBUG
3286          fprintf (stderr, "RUN IN BACKGROUND MODE \n");
3287          fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
3288                   getpid ());
3289          fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
3290#endif
3291          freopen (flog, "w+", stderr);
3292          semid lid = getShmLockId (m, 1);
3293          fflush (stderr);
3294          if (lid < 0)
3295            {
3296              fprintf (stderr, "ERROR %s %d\n", __FILE__, __LINE__);
3297              fflush (stderr);
3298              return -1;
3299            }
3300          else
3301            {
3302              if (lockShm (lid) < 0)
3303                {
3304                  fprintf (stderr, "ERROR %s %d\n", __FILE__, __LINE__);
3305                  fflush (stderr);
3306                  return -1;
3307                }
3308              fflush (stderr);
3309            }
3310          f0 = freopen (fbkp, "w+", stdout);
3311          rewind (stdout);
3312#ifndef WIN32
3313          fclose (stdin);
3314#endif
3315          free (flog);
3316      /**
3317       * set status to SERVICE_STARTED and flush stdout to ensure full
3318       * content was outputed (the file used to store the ResponseDocument).
3319       * The rewind stdout to restart writing from the bgining of the file,
3320       * this way the data will be updated at the end of the process run.
3321       */
3322          printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
3323                                SERVICE_STARTED, request_input_real_format,
3324                                request_output_real_format);
3325          fflush (stdout);
3326          unlockShm (lid);
3327          fflush (stderr);
3328          fbkp1 =
3329            (char *)
3330            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
3331                     1024) * sizeof (char));
3332          sprintf (fbkp1, "%s/%s_final_%d.xml", r_inputs->value,
3333                   r_inputs1->value, cpid);
3334          f1 = freopen (fbkp1, "w+", stdout);
3335          loadServiceAndRun (&m, s1, request_inputs,
3336                             &request_input_real_format,
3337                             &request_output_real_format, &eres);
3338        }
3339      else
3340        {
3341      /**
3342       * error server don't accept the process need to output a valid
3343       * error response here !!!
3344       */
3345          eres = -1;
3346          errorException (m, _("Unable to run the child process properly"),
3347                          "InternalError", NULL);
3348        }
3349    }
3350
3351#ifdef DEBUG
3352  dumpMaps (request_output_real_format);
3353#endif
3354  if (eres != -1)
3355    outputResponse (s1, request_input_real_format,
3356                    request_output_real_format, request_inputs,
3357                    cpid, m, eres);
3358  fflush (stdout);
3359  /**
3360   * Ensure that if error occurs when freeing memory, no signal will return
3361   * an ExceptionReport document as the result was already returned to the
3362   * client.
3363   */
3364#ifndef USE_GDB
3365  signal (SIGSEGV, donothing);
3366  signal (SIGTERM, donothing);
3367  signal (SIGINT, donothing);
3368  signal (SIGILL, donothing);
3369  signal (SIGFPE, donothing);
3370  signal (SIGABRT, donothing);
3371#endif
3372  if (((int) getpid ()) != cpid || cgiSid != NULL)
3373    {
3374      fclose (stdout);
3375      fclose (stderr);
3376    /**
3377     * Dump back the final file fbkp1 to fbkp
3378     */
3379      fclose (f0);
3380      fclose (f1);
3381      FILE *f2 = fopen (fbkp1, "rb");
3382      semid lid = getShmLockId (m, 1);
3383      if (lid < 0)
3384        return -1;
3385      lockShm (lid);
3386      FILE *f3 = fopen (fbkp, "wb+");
3387      free (fbkp);
3388      fseek (f2, 0, SEEK_END);
3389      long flen = ftell (f2);
3390      fseek (f2, 0, SEEK_SET);
3391      char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char));
3392      fread (tmps1, flen, 1, f2);
3393      fwrite (tmps1, 1, flen, f3);
3394      fclose (f2);
3395      fclose (f3);
3396      unlockShm (lid);
3397      unlink (fbkp1);
3398      free (fbkp1);
3399      free (tmps1);
3400      unhandleStatus (m);
3401    }
3402
3403  freeService (&s1);
3404  free (s1);
3405  freeMaps (&m);
3406  free (m);
3407
3408  freeMaps (&request_input_real_format);
3409  free (request_input_real_format);
3410
3411  freeMaps (&request_output_real_format);
3412  free (request_output_real_format);
3413
3414  free (REQUEST);
3415  free (SERVICE_URL);
3416#ifdef DEBUG
3417  fprintf (stderr, "Processed response \n");
3418  fflush (stdout);
3419  fflush (stderr);
3420#endif
3421
3422  if (((int) getpid ()) != cpid || cgiSid != NULL)
3423    {
3424      exit (0);
3425    }
3426
3427  return 0;
3428}
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