source: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c @ 512

Last change on this file since 512 was 512, checked in by david, 10 years ago

-loading files configuration on startup
-devel version with probably a lot of leak
-using temporarily glib to store services

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