source: branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c @ 896

Last change on this file since 896 was 896, checked in by knut, 5 years ago

Added some recent changes from trunk (r889), including some new utility functions and exception handling and new (conditional) definition of type bool. Added some new logic concerning Python and Mono environment and search paths. Fixed problem with Mono updateStatus function. Changed response_print.h to #include locale.h unconditionally and xlocale.h conditionally; xlocale.h is non-standard and can probably be dropped.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 74.0 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 
25extern "C" int yylex ();
26extern "C" int crlex ();
27
28#ifdef META_DB
29#include "ogrsf_frmts.h"
30#if GDAL_VERSION_MAJOR >= 2
31#include <gdal_priv.h>
32#endif
33#endif
34
35#ifdef USE_OTB
36#include "service_internal_otb.h"
37#endif
38
39#ifdef USE_R
40#include "service_internal_r.h"
41#endif
42
43#ifdef USE_HPC
44#include "service_internal_hpc.h"
45#endif
46
47#include "cgic.h"
48
49#include <libxml/tree.h>
50#include <libxml/xmlmemory.h>
51#include <libxml/parser.h>
52#include <libxml/xpath.h>
53#include <libxml/xpathInternals.h>
54
55#include "ulinet.h"
56
57#include <libintl.h>
58#include <locale.h>
59#include <string.h>
60
61#include "service.h"
62
63#include "service_internal.h"
64#include "server_internal.h"
65#include "response_print.h"
66#include "request_parser.h"
67#include "sqlapi.h"
68#ifdef WIN32
69#include "caching.h"
70extern wchar_t**_wenviron;
71#endif
72
73#ifdef META_DB
74#include "meta_sql.h"
75#endif
76
77#ifdef USE_PYTHON
78#include "service_internal_python.h"
79#endif
80
81#ifdef USE_SAGA
82#include "service_internal_saga.h"
83#endif
84
85#ifdef USE_JAVA
86#include "service_internal_java.h"
87#endif
88
89#ifdef USE_PHP
90#include "service_internal_php.h"
91#endif
92
93#ifdef USE_JS
94#include "service_internal_js.h"
95#endif
96
97#ifdef USE_RUBY
98#include "service_internal_ruby.h"
99#endif
100
101#ifdef USE_PERL
102#include "service_internal_perl.h"
103#endif
104
105#ifdef USE_MONO
106#include "service_internal_mono.h"
107#endif
108
109#ifdef USE_HPC
110#include "service_json.h"
111#include "service_callback.h"
112#endif
113
114#include <dirent.h>
115#include <signal.h>
116#ifndef WIN32
117#include <execinfo.h>
118#endif
119#include <unistd.h>
120#ifndef WIN32
121#include <dlfcn.h>
122#include <libgen.h>
123#else
124#include <windows.h>
125#include <direct.h>
126#include <sys/types.h>
127#include <sys/stat.h>
128#include <unistd.h>
129#define pid_t int;
130#endif
131#include <fcntl.h>
132#include <time.h>
133#include <stdarg.h>
134
135#include <libxml/tree.h>
136#include <libxml/parser.h>
137#include <libxml/xpath.h>
138#include <libxml/xpathInternals.h>
139
140#include <libxslt/xslt.h>
141#include <libxslt/xsltInternals.h>
142#include <libxslt/transform.h>
143#include <libxslt/xsltutils.h>
144
145#ifndef WIN32
146extern char **environ;
147#endif
148
149
150#ifdef WIN32
151extern "C"
152{
153  __declspec (dllexport) char *strcasestr (char const *a, char const *b)
154#ifndef USE_MS
155  {
156    char *x = zStrdup (a);
157    char *y = zStrdup (b);
158
159      x = _strlwr (x);
160      y = _strlwr (y);
161    char *pos = strstr (x, y);
162    char *ret = pos == NULL ? NULL : (char *) (a + (pos - x));
163      free (x);
164      free (y);
165      return ret;
166  };
167#else
168   ;
169#endif
170}
171#endif
172
173/**
174 * Translation function for zoo-kernel
175 */
176#define _(String) dgettext ("zoo-kernel",String)
177/**
178 * Translation function for zoo-service
179 */
180#define __(String) dgettext ("zoo-service",String)
181
182#ifdef WIN32
183#ifndef PROGRAMNAME
184#define PROGRAMNAME "zoo_loader.cgi"
185#endif
186#endif
187
188
189/**
190 * Replace a char by another one in a string
191 *
192 * @param str the string to update
193 * @param toReplace the char to replace
194 * @param toReplaceBy the char that will be used
195 */
196void
197translateChar (char *str, char toReplace, char toReplaceBy)
198{
199  int i = 0, len = strlen (str);
200  for (i = 0; i < len; i++)
201    {
202      if (str[i] == toReplace)
203        str[i] = toReplaceBy;
204    }
205}
206
207/**
208 * Dump back the final file fbkp1 to fbkp
209 *
210 * @param m the conf maps containing the main.cfg settings
211 * @param fbkp the string corresponding to the name of the file
212 * @param fbkp1 the string corresponding to the name of the file
213 */
214int dumpBackFinalFile(maps* m,char* fbkp,char* fbkp1)
215{
216  FILE *f2 = fopen (fbkp1, "rb");
217#ifndef RELY_ON_DB
218  semid lid = getShmLockId (m, 1);
219  if (lid < 0)
220    return -1;
221  lockShm (lid);
222#endif
223  FILE *f3 = fopen (fbkp, "wb+");
224  free (fbkp);
225  fseek (f2, 0, SEEK_END);
226  long flen = ftell (f2);
227  fseek (f2, 0, SEEK_SET);
228  char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char));
229  fread (tmps1, flen, 1, f2);
230#ifdef WIN32
231  /* knut: I think this block can be dropped; pchr may be NULL if result is not in XML format
232  char *pchr=strrchr(tmps1,'>');
233  flen=strlen(tmps1)-strlen(pchr)+1;
234  tmps1[flen]=0;
235  */
236#endif
237  fwrite (tmps1, 1, flen, f3);
238  fclose (f2);
239  fclose (f3);
240  free(tmps1);
241  return 1;
242}
243
244/**
245 * Recursivelly parse zcfg starting from the ZOO-Kernel cwd.
246 * Call the func function given in arguments after parsing the ZCFG file.
247 *
248 * @param m the conf maps containing the main.cfg settings
249 * @param r the registry containing profiles hierarchy
250 * @param n the root XML Node to add the sub-elements
251 * @param conf_dir the location of the main.cfg file (basically cwd)
252 * @param prefix the current prefix if any, or NULL
253 * @param saved_stdout the saved stdout identifier
254 * @param level the current level (number of sub-directories to reach the
255 * current path)
256 * @param func a pointer to a function having 4 parameters
257 *  (registry*, maps*, xmlNodePtr and service*).
258 * @see inheritance, readServiceFile
259 */
260int
261recursReaddirF ( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir, 
262                 char *prefix, int saved_stdout, int level, 
263                 void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) )
264{
265  struct dirent *dp;
266  int scount = 0;
267
268  if (conf_dir == NULL)
269    return 1;
270  DIR *dirp = opendir (conf_dir);
271  if (dirp == NULL)
272    {
273      if (level > 0)
274        return 1;
275      else
276        return -1;
277    }
278  char tmp1[25];
279  sprintf (tmp1, "sprefix_%d", level);
280  char levels[17];
281  sprintf (levels, "%d", level);
282  setMapInMaps (m, "lenv", "level", levels);
283  while ((dp = readdir (dirp)) != NULL)
284    if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.'
285        && strstr (dp->d_name, ".") == NULL)
286      {
287
288        char *tmp =
289          (char *) malloc ((strlen (conf_dir) + strlen (dp->d_name) + 2) *
290                           sizeof (char));
291        sprintf (tmp, "%s/%s", conf_dir, dp->d_name);
292
293        if (prefix != NULL)
294          {
295            prefix = NULL;
296          }
297        prefix = (char *) malloc ((strlen (dp->d_name) + 2) * sizeof (char));
298        sprintf (prefix, "%s.", dp->d_name);
299
300        //map* tmpMap=getMapFromMaps(m,"lenv",tmp1);
301
302        int res;
303        if (prefix != NULL)
304          {
305            setMapInMaps (m, "lenv", tmp1, prefix);
306            char levels1[17];
307            sprintf (levels1, "%d", level + 1);
308            setMapInMaps (m, "lenv", "level", levels1);
309            res =
310              recursReaddirF (m, r, doc, n, tmp, prefix, saved_stdout, level + 1,
311                              func);
312            sprintf (levels1, "%d", level);
313            setMapInMaps (m, "lenv", "level", levels1);
314            free (prefix);
315            prefix = NULL;
316          }
317        else
318          res = -1;
319        free (tmp);
320        if (res < 0)
321          {
322            return res;
323          }
324      }
325    else
326      {
327        char* extn = strstr(dp->d_name, ".zcfg");
328        if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5 && strlen(dp->d_name)>6)
329          {
330            int t;
331            char tmps1[1024];
332            memset (tmps1, 0, 1024);
333            snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name);
334
335            char *tmpsn = (char*)malloc((strlen(dp->d_name)-4)*sizeof(char));//zStrdup (dp->d_name);
336            memset (tmpsn, 0, strlen(dp->d_name)-4);
337            snprintf(tmpsn,strlen(dp->d_name)-4,"%s",dp->d_name);
338           
339            map* import = getMapFromMaps (m, IMPORTSERVICE, tmpsn);
340            if (import == NULL || import->value == NULL || zoo_path_compare(tmps1, import->value) != 0 ) { // service is not in [include] block
341              service *s1 = createService();
342              if (s1 == NULL)
343                {
344                  zDup2 (saved_stdout, fileno (stdout));
345                  errorException (m, _("Unable to allocate memory"),
346                                  "InternalError", NULL);
347                  return -1;
348                }
349  #ifdef DEBUG
350              fprintf (stderr, "#################\n%s\n#################\n",
351                       tmps1);
352  #endif
353              t = readServiceFile (m, tmps1, &s1, tmpsn);
354              free (tmpsn);
355              if (t < 0)
356                {
357                  map *tmp00 = getMapFromMaps (m, "lenv", "message");
358                  char tmp01[1024];
359                  if (tmp00 != NULL)
360                    sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"),
361                             dp->d_name, tmp00->value);
362                  else
363                    sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
364                             dp->d_name);
365                  zDup2 (saved_stdout, fileno (stdout));
366                  errorException (m, tmp01, "InternalError", NULL);
367                  return -1;
368                }
369  #ifdef DEBUG
370              dumpService (s1);
371              fflush (stdout);
372              fflush (stderr);
373  #endif
374              if(s1!=NULL)
375                inheritance(r,&s1);
376              func (r, m, doc, n, s1);
377              freeService (&s1);
378              free (s1);
379              scount++;
380            }
381          }
382      }
383  (void) closedir (dirp);
384  return 1;
385}
386
387/**
388 * Signal handling function which simply call exit(0).
389 *
390 * @param sig the signal number
391 */
392void
393donothing (int sig)
394{
395#ifdef DEBUG
396  fprintf (stderr, "Signal %d after the ZOO-Kernel returned result!\n", sig);
397#endif
398  exit (0);
399}
400
401/**
402 * Signal handling function which create an ExceptionReport node containing the
403 * information message corresponding to the signal number.
404 *
405 * @param sig the signal number
406 */
407void
408sig_handler (int sig)
409{
410 
411  char tmp[100];
412  const char *ssig;
413  switch (sig)
414    {
415    case SIGSEGV:
416      ssig = "SIGSEGV";
417      break;
418    case SIGTERM:
419      ssig = "SIGTERM";
420      break;
421    case SIGINT:
422      ssig = "SIGINT";
423      break;
424    case SIGILL:
425      ssig = "SIGILL";
426      break;
427    case SIGFPE:
428      ssig = "SIGFPE";
429      break;
430    case SIGABRT:
431      ssig = "SIGABRT";
432      break;
433    default:
434      ssig = "UNKNOWN";
435      break;
436    }
437  sprintf (tmp,
438           _
439           ("ZOO Kernel failed to process your request, receiving signal %d = %s "),
440           sig, ssig);
441  errorException (NULL, tmp, "InternalError", NULL);
442#ifdef DEBUG
443  fprintf (stderr, "Not this time!\n");
444#endif
445  exit (0);
446}
447
448/**
449 * Load a service provider and run the service function.
450 *
451 * @param myMap the conf maps containing the main.cfg settings
452 * @param s1 the service structure
453 * @param request_inputs map storing all the request parameters
454 * @param inputs the inputs maps
455 * @param ioutputs the outputs maps
456 * @param eres the result returned by the service execution
457 */
458void
459loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
460                   maps ** inputs, maps ** ioutputs, int *eres)
461{
462  char tmps1[1024];
463  char ntmp[1024];
464  maps *m = *myMap;
465  maps *request_output_real_format = *ioutputs;
466  maps *request_input_real_format = *inputs;
467  /**
468   * Extract serviceType to know what kind of service should be loaded
469   */
470  map *r_inputs = NULL;
471  map* cwdMap=getMapFromMaps(m,"main","servicePath");
472  if(cwdMap!=NULL){
473    sprintf(ntmp,"%s",cwdMap->value);
474  }else{
475#ifndef WIN32
476    getcwd (ntmp, 1024);
477#else
478    _getcwd (ntmp, 1024);
479#endif
480  }
481  r_inputs = getMap (s1->content, "serviceType");
482#ifdef DEBUG
483  fprintf (stderr, "LOAD A %s SERVICE PROVIDER \n", r_inputs->value);
484  fflush (stderr);
485#endif
486
487  map* libp = getMapFromMaps(m, "main", "libPath"); 
488  if (strlen (r_inputs->value) == 1
489      && strncasecmp (r_inputs->value, "C", 1) == 0)
490  {
491     if (libp != NULL && libp->value != NULL) {
492            r_inputs = getMap (s1->content, "ServiceProvider");
493                sprintf (tmps1, "%s/%s", libp->value, r_inputs->value);
494         }
495     else {     
496        r_inputs = getMap (request_inputs, "metapath");
497        if (r_inputs != NULL)
498          sprintf (tmps1, "%s/%s", ntmp, r_inputs->value);
499        else
500          sprintf (tmps1, "%s/", ntmp);
501         
502        char *altPath = zStrdup (tmps1);
503        r_inputs = getMap (s1->content, "ServiceProvider");
504        sprintf (tmps1, "%s/%s", altPath, r_inputs->value);
505        free (altPath);
506         }
507#ifdef DEBUG
508      fprintf (stderr, "Trying to load %s\n", tmps1);
509#endif
510#ifdef WIN32
511      HINSTANCE so =
512        LoadLibraryEx (tmps1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
513#else
514      void *so = dlopen (tmps1, RTLD_LAZY);
515#endif
516#ifdef WIN32
517      char* errstr = getLastErrorMessage();
518#else
519      char *errstr;
520      errstr = dlerror ();
521#endif
522#ifdef DEBUG
523          fprintf (stderr, "%s loaded (%s) \n", tmps1, errstr);
524#endif
525      if (so != NULL)
526        {
527#ifdef DEBUG
528          fprintf (stderr, "Library loaded %s \n", errstr);
529          fprintf (stderr, "Service Shared Object = %s\n", r_inputs->value);
530#endif
531          r_inputs = getMap (s1->content, "serviceType");
532#ifdef DEBUG
533          dumpMap (r_inputs);
534          fprintf (stderr, "%s\n", r_inputs->value);
535          fflush (stderr);
536#endif
537          if (strncasecmp (r_inputs->value, "C-FORTRAN", 9) == 0)
538            {
539              r_inputs = getMap (request_inputs, "Identifier");
540              char fname[1024];
541              sprintf (fname, "%s_", r_inputs->value);
542#ifdef DEBUG
543              fprintf (stderr, "Try to load function %s\n", fname);
544#endif
545#ifdef WIN32
546              typedef int (CALLBACK * execute_t) (char ***, char ***,
547                                                  char ***);
548              execute_t execute = (execute_t) GetProcAddress (so, fname);
549#else
550              typedef int (*execute_t) (char ***, char ***, char ***);
551              execute_t execute = (execute_t) dlsym (so, fname);
552#endif
553#ifdef DEBUG
554#ifdef WIN32
555                          errstr = getLastErrorMessage();
556#else
557              errstr = dlerror ();
558#endif
559              fprintf (stderr, "Function loaded %s\n", errstr);
560#endif
561
562              char main_conf[10][30][1024];
563              char inputs[10][30][1024];
564              char outputs[10][30][1024];
565              for (int i = 0; i < 10; i++)
566                {
567                  for (int j = 0; j < 30; j++)
568                    {
569                      memset (main_conf[i][j], 0, 1024);
570                      memset (inputs[i][j], 0, 1024);
571                      memset (outputs[i][j], 0, 1024);
572                    }
573                }
574              mapsToCharXXX (m, (char ***) main_conf);
575              mapsToCharXXX (request_input_real_format, (char ***) inputs);
576              mapsToCharXXX (request_output_real_format, (char ***) outputs);
577              *eres =
578                execute ((char ***) &main_conf[0], (char ***) &inputs[0],
579                         (char ***) &outputs[0]);
580#ifdef DEBUG
581              fprintf (stderr, "Function run successfully \n");
582#endif
583              charxxxToMaps ((char ***) &outputs[0],
584                             &request_output_real_format);
585            }
586          else
587            {
588#ifdef DEBUG
589#ifdef WIN32
590                          errstr = getLastErrorMessage();
591              fprintf (stderr, "Function %s failed to load because of %s\n",
592                       r_inputs->value, errstr);
593#endif
594#endif
595              r_inputs = getMapFromMaps (m, "lenv", "Identifier");
596#ifdef DEBUG
597              fprintf (stderr, "Try to load function %s\n", r_inputs->value);
598#endif
599              typedef int (*execute_t) (maps **, maps **, maps **);
600#ifdef WIN32
601              execute_t execute =
602                (execute_t) GetProcAddress (so, r_inputs->value);
603#else
604              execute_t execute = (execute_t) dlsym (so, r_inputs->value);
605#endif
606
607              if (execute == NULL)
608                {
609#ifdef WIN32
610                                  errstr = getLastErrorMessage();
611#else
612                  errstr = dlerror ();
613#endif
614                  char *tmpMsg =
615                    (char *) malloc (2048 + strlen (r_inputs->value));
616                  sprintf (tmpMsg,
617                           _
618                           ("Error occurred while running the %s function: %s"),
619                           r_inputs->value, errstr);
620                  errorException (m, tmpMsg, "InternalError", NULL);
621                  free (tmpMsg);
622#ifdef DEBUG
623                  fprintf (stderr, "Function %s error %s\n", r_inputs->value,
624                           errstr);
625#endif
626                  *eres = -1;
627                  return;
628                }
629
630#ifdef DEBUG
631#ifdef WIN32
632                          errstr = getLastErrorMessage();
633#else
634              errstr = dlerror ();
635#endif
636              fprintf (stderr, "Function loaded %s\n", errstr);
637#endif
638
639#ifdef DEBUG
640              fprintf (stderr, "Now run the function \n");
641              fflush (stderr);
642#endif
643              *eres =
644                execute (&m, &request_input_real_format,
645                         &request_output_real_format);
646#ifdef DEBUG
647              fprintf (stderr, "Function loaded and returned %d\n", eres);
648              fflush (stderr);
649#endif
650            }
651#ifdef WIN32
652          *ioutputs = dupMaps (&request_output_real_format);
653          FreeLibrary (so);
654#else
655          dlclose (so);
656#endif
657        }
658      else
659        {
660      /**
661       * Unable to load the specified shared library
662       */
663          char tmps[1024];
664#ifdef WIN32
665                  errstr = getLastErrorMessage();
666#else
667              errstr = dlerror ();
668#endif
669          sprintf (tmps, _("Unable to load C Library %s"), errstr);
670          errorException(m,tmps,"InternalError",NULL);
671          *eres = -1;
672        }
673    }
674  else
675
676#ifdef USE_HPC
677  if (strncasecmp (r_inputs->value, "HPC", 3) == 0)
678    {
679      *eres =
680        zoo_hpc_support (&m, request_inputs, s1,
681                            &request_input_real_format,
682                            &request_output_real_format);
683    }
684  else
685#endif
686
687#ifdef USE_SAGA
688  if (strncasecmp (r_inputs->value, "SAGA", 4) == 0)
689    {
690      *eres =
691        zoo_saga_support (&m, request_inputs, s1,
692                            &request_input_real_format,
693                            &request_output_real_format);
694    }
695  else
696#endif
697
698#ifdef USE_OTB
699  if (strncasecmp (r_inputs->value, "OTB", 3) == 0)
700    {
701      *eres =
702        zoo_otb_support (&m, request_inputs, s1,
703                            &request_input_real_format,
704                            &request_output_real_format);
705    }
706  else
707#endif
708#ifdef USE_PYTHON
709  if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0)
710    {             
711      *eres =
712        zoo_python_support (&m, request_inputs, s1,
713                            &request_input_real_format,
714                            &request_output_real_format);         
715    }
716  else
717#endif
718
719#ifdef USE_R
720  if (strncasecmp (r_inputs->value, "R", 6) == 0)
721    {     
722      *eres =
723        zoo_r_support (&m, request_inputs, s1,
724                            &request_input_real_format,
725                            &request_output_real_format);
726    }
727  else
728#endif
729
730#ifdef USE_JAVA
731  if (strncasecmp (r_inputs->value, "JAVA", 4) == 0)
732    {
733      *eres =
734        zoo_java_support (&m, request_inputs, s1, &request_input_real_format,
735                          &request_output_real_format);
736    }
737  else
738#endif
739
740#ifdef USE_PHP
741  if (strncasecmp (r_inputs->value, "PHP", 3) == 0)
742    {
743      *eres =
744        zoo_php_support (&m, request_inputs, s1, &request_input_real_format,
745                         &request_output_real_format);         
746    }
747  else
748#endif
749
750
751#ifdef USE_PERL
752  if (strncasecmp (r_inputs->value, "PERL", 4) == 0)
753    {
754      *eres =
755        zoo_perl_support (&m, request_inputs, s1, &request_input_real_format,
756                          &request_output_real_format);
757    }
758  else
759#endif
760
761#ifdef USE_JS
762  if (strncasecmp (r_inputs->value, "JS", 2) == 0)
763    {
764      *eres =
765        zoo_js_support (&m, request_inputs, s1, &request_input_real_format,
766                        &request_output_real_format);
767    }
768  else
769#endif
770
771#ifdef USE_RUBY
772  if (strncasecmp (r_inputs->value, "Ruby", 4) == 0)
773    {
774      *eres =
775        zoo_ruby_support (&m, request_inputs, s1, &request_input_real_format,
776                          &request_output_real_format);
777    }
778  else
779#endif
780
781#ifdef USE_MONO
782  if (strncasecmp (r_inputs->value, "Mono", 4) == 0)
783    {
784      *eres =
785        zoo_mono_support (&m, request_inputs, s1, &request_input_real_format,
786                          &request_output_real_format);
787    }
788  else
789#endif
790
791    {
792      char tmpv[1024];
793      sprintf (tmpv,
794               _
795               ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),
796               r_inputs->value);
797      errorException (m, tmpv, "InternalError", NULL);
798      *eres = -1;
799    }
800  *myMap = m;
801  *ioutputs = request_output_real_format; 
802}
803
804
805#ifdef WIN32
806/**
807 * createProcess function: create a new process after setting some env variables
808 */
809void
810createProcess (maps * m, map * request_inputs, service * s1, char *opts,
811               int cpid, maps * inputs, maps * outputs)
812{
813  STARTUPINFO si;
814  PROCESS_INFORMATION pi;
815  ZeroMemory (&si, sizeof (si));
816  si.cb = sizeof (si);
817  ZeroMemory (&pi, sizeof (pi));
818  char *tmp = (char *) malloc ((1024 + cgiContentLength) * sizeof (char));
819  char *tmpq = (char *) malloc ((1024 + cgiContentLength) * sizeof (char));
820  map *req = getMap (request_inputs, "request");
821  map *id = getMap (request_inputs, "identifier");
822  map *di = getMap (request_inputs, "DataInputs");
823
824  // The required size for the dataInputsKVP and dataOutputsKVP buffers
825  // may exceed cgiContentLength, hence a 2 kb extension. However, a
826  // better solution would be to have getMapsAsKVP() determine the required
827  // buffer size before allocating memory.     
828  char *dataInputsKVP = getMapsAsKVP (inputs, cgiContentLength + 2048, 0);
829  char *dataOutputsKVP = getMapsAsKVP (outputs, cgiContentLength + 2048, 1);
830#ifdef DEBUG
831  fprintf (stderr, "DATAINPUTSKVP %s\n", dataInputsKVP);
832  fprintf (stderr, "DATAOUTPUTSKVP %s\n", dataOutputsKVP);
833#endif
834  map *sid = getMapFromMaps (m, "lenv", "osid");
835  map *usid = getMapFromMaps (m, "lenv", "usid");
836  map *r_inputs = getMapFromMaps (m, "main", "tmpPath");
837  map *r_inputs1 = getMap (request_inputs, "metapath");
838 
839  int hasIn = -1;
840  if (r_inputs1 == NULL)
841    {
842      r_inputs1 = createMap ("metapath", "");
843      hasIn = 1;
844    }
845  map *r_inputs2 = getMap (request_inputs, "ResponseDocument");
846  if (r_inputs2 == NULL)
847    r_inputs2 = getMap (request_inputs, "RawDataOutput");
848  map *tmpPath = getMapFromMaps (m, "lenv", "cwd");
849
850  map *tmpReq = getMap (request_inputs, "xrequest");
851
852  if(r_inputs2 != NULL && tmpReq != NULL) {
853    const char key[] = "rfile=";
854    char* kvp = (char*) malloc((FILENAME_MAX + strlen(key))*sizeof(char));
855    char* filepath = kvp + strlen(key);
856    strncpy(kvp, key, strlen(key));
857    addToCache(m, tmpReq->value, tmpReq->value, "text/xml", strlen(tmpReq->value), 
858               filepath, FILENAME_MAX);
859    if (filepath == NULL) {
860      errorException( m, _("Unable to cache HTTP POST Execute request."), "InternalError", NULL); 
861      return;
862    }   
863    sprintf(tmp,"\"metapath=%s&%s&cgiSid=%s&usid=%s\"",
864            r_inputs1->value,kvp,sid->value,usid->value);
865    sprintf(tmpq,"metapath=%s&%s",
866            r_inputs1->value,kvp);
867    free(kvp); 
868  }
869  else if (r_inputs2 != NULL)
870    {
871      sprintf (tmp,
872               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s&usid=%s\"",
873               r_inputs1->value, req->value, id->value, dataInputsKVP,
874               r_inputs2->name, dataOutputsKVP, sid->value, usid->value);
875      sprintf (tmpq,
876               "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",
877               r_inputs1->value, req->value, id->value, dataInputsKVP,
878               r_inputs2->name, dataOutputsKVP);                   
879    }
880  else
881    {
882      sprintf (tmp,
883               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s&usid=%s\"",
884               r_inputs1->value, req->value, id->value, dataInputsKVP,
885               sid->value, usid->value);
886      sprintf (tmpq,
887               "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",
888               r_inputs1->value, req->value, id->value, dataInputsKVP,
889               sid->value);   
890    }
891
892  if (hasIn > 0)
893    {
894      freeMap (&r_inputs1);
895      free (r_inputs1);
896    }
897  char *tmp1 = zStrdup (tmp);
898  sprintf (tmp, "\"%s\" %s \"%s\"", PROGRAMNAME, tmp1, sid->value); 
899  free (dataInputsKVP);
900  free (dataOutputsKVP);
901#ifdef DEBUG
902  fprintf (stderr, "REQUEST IS : %s \n", tmp);
903#endif
904
905  usid = getMapFromMaps (m, "lenv", "usid");
906  if (usid != NULL && usid->value != NULL) {
907    SetEnvironmentVariable("USID", TEXT (usid->value));
908  }
909  SetEnvironmentVariable ("CGISID", TEXT (sid->value));
910  SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq));
911  // knut: Prevent REQUEST_METHOD=POST in background process call to cgic:main
912  // (process hangs when reading cgiIn):
913  SetEnvironmentVariable("REQUEST_METHOD", "GET");
914  SetEnvironmentVariable("CONTENT_TYPE", "text/plain");
915 
916  char clen[1000];
917  sprintf (clen, "%d", strlen (tmpq));
918  SetEnvironmentVariable ("CONTENT_LENGTH", TEXT (clen));
919
920  // ref. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx
921  if (!CreateProcess (NULL,     // No module name (use command line)
922                      TEXT (tmp),       // Command line
923                      NULL,     // Process handle not inheritable
924                      NULL,     // Thread handle not inheritable
925                      FALSE,    // Set handle inheritance to FALSE
926                      CREATE_NO_WINDOW, // Apache won't wait until the end
927                      NULL,     // Use parent's environment block
928                      NULL,     // Use parent's starting directory
929                      &si,      // Pointer to STARTUPINFO struct
930                      &pi)      // Pointer to PROCESS_INFORMATION struct
931    )
932    {
933#ifdef DEBUG
934      fprintf (stderr, "CreateProcess failed (%d).\n", GetLastError ());
935#endif
936      if (tmp != NULL) {
937        free(tmp);
938      }
939      if (tmpq != NULL) {
940        free(tmpq);
941      }         
942      return;
943    }
944  else
945    {
946#ifdef DEBUG
947      fprintf (stderr, "CreateProcess successful (%d).\n\n\n\n",
948               GetLastError ());
949#endif
950    }
951  CloseHandle (pi.hProcess);
952  CloseHandle (pi.hThread);
953 
954  if (tmp != NULL) {
955    free(tmp);
956  }
957  if (tmpq != NULL) {
958    free(tmpq);
959  }
960 
961#ifdef DEBUG
962  fprintf (stderr, "CreateProcess finished !\n");
963#endif
964}
965#endif
966
967/**
968 * Process the request.
969 *
970 * @param inputs the request parameters map
971 * @return 0 on sucess, other value on failure
972 * @see conf_read,recursReaddirF
973 */
974int
975runRequest (map ** inputs)
976{
977 
978#ifndef USE_GDB
979#ifndef WIN32
980  signal (SIGCHLD, SIG_IGN);
981#endif 
982  signal (SIGSEGV, sig_handler);
983  signal (SIGTERM, sig_handler);
984  signal (SIGINT, sig_handler);
985  signal (SIGILL, sig_handler);
986  signal (SIGFPE, sig_handler);
987  signal (SIGABRT, sig_handler);
988#endif
989
990 
991  map *r_inputs = NULL;
992  map *request_inputs = *inputs;
993  //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapToJson(request_inputs),JSON_C_TO_STRING_PLAIN));
994 
995#ifdef IGNORE_METAPATH
996  addToMap(request_inputs, "metapath", "");
997#endif 
998  maps *m = NULL;
999  char *REQUEST = NULL;
1000  /**
1001   * Parsing service specfic configuration file
1002   */
1003  m = (maps *) malloc (MAPS_SIZE);
1004  if (m == NULL)
1005    {
1006      return errorException (NULL, _("Unable to allocate memory"),
1007                             "InternalError", NULL);
1008    }
1009  m->child=NULL;
1010  char ntmp[1024];
1011#ifndef ETC_DIR
1012#ifndef WIN32
1013  getcwd (ntmp, 1024);
1014#else
1015  _getcwd (ntmp, 1024);
1016#endif
1017#else
1018  sprintf(ntmp,"%s",ETC_DIR);
1019#endif
1020  r_inputs = getMapOrFill (&request_inputs, "metapath", "");
1021
1022  char conf_file[10240];
1023  snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value);
1024#ifdef ETC_DIR
1025#ifndef WIN32
1026  getcwd (ntmp, 1024);
1027#else
1028  _getcwd (ntmp, 1024);
1029#endif
1030#endif
1031
1032  if (conf_read (conf_file, m) == 2)
1033    {
1034      errorException (NULL, _("Unable to load the main.cfg file."),
1035                      "InternalError", NULL);
1036      free (m);
1037      return 1;
1038    }
1039#ifdef DEBUG
1040  fprintf (stderr, "***** BEGIN MAPS\n");
1041  dumpMaps (m);
1042  fprintf (stderr, "***** END MAPS\n");
1043#endif
1044
1045  map *getPath = getMapFromMaps (m, "main", "gettextPath");
1046  if (getPath != NULL)
1047    {
1048      bindtextdomain ("zoo-kernel", getPath->value);
1049      bindtextdomain ("zoo-services", getPath->value);
1050    }
1051  else
1052    {
1053      bindtextdomain ("zoo-kernel", LOCALEDIR);
1054      bindtextdomain ("zoo-services", LOCALEDIR);
1055    }
1056
1057  /**
1058   * Manage our own error log file (usefull to separate standard apache debug
1059   * messages from the ZOO-Kernel ones but also for IIS users to avoid wrong
1060   * headers messages returned by the CGI due to wrong redirection of stderr)
1061   */
1062  FILE *fstde = NULL;
1063  map *fstdem = getMapFromMaps (m, "main", "logPath");
1064  if (fstdem != NULL)
1065    fstde = freopen (fstdem->value, "a+", stderr);
1066
1067  r_inputs = getMap (request_inputs, "language");
1068  if (r_inputs == NULL)
1069    r_inputs = getMap (request_inputs, "AcceptLanguages");
1070  if (r_inputs == NULL)
1071    r_inputs = getMapFromMaps (m, "main", "language");
1072  if (r_inputs != NULL)
1073    {
1074      if (isValidLang (m, r_inputs->value) < 0)
1075        {
1076          char tmp[1024];
1077          sprintf (tmp,
1078                   _
1079                   ("The value %s is not supported for the <language> parameter"),
1080                   r_inputs->value);
1081          errorException (m, tmp, "InvalidParameterValue", "language");
1082          freeMaps (&m);
1083          free (m);
1084          free (REQUEST);
1085          return 1;
1086
1087        }
1088      char *tmp = zStrdup (r_inputs->value);
1089      setMapInMaps (m, "main", "language", tmp);
1090#ifdef DEB
1091      char tmp2[12];
1092      sprintf (tmp2, "%s.utf-8", tmp);
1093      translateChar (tmp2, '-', '_');
1094      setlocale (LC_ALL, tmp2);
1095#else
1096      translateChar (tmp, '-', '_');
1097      setlocale (LC_ALL, tmp);
1098#endif
1099#ifndef WIN32
1100      setenv ("LC_ALL", tmp, 1);
1101#else
1102      char tmp1[13];
1103      sprintf (tmp1, "LC_ALL=%s", tmp);
1104      _putenv (tmp1);
1105#endif
1106      free (tmp);
1107    }
1108  else
1109    {
1110      setlocale (LC_ALL, "en_US");
1111#ifndef WIN32
1112      setenv ("LC_ALL", "en_US", 1);
1113#else
1114      char tmp1[13];
1115      sprintf (tmp1, "LC_ALL=en_US");
1116      _putenv (tmp1);
1117#endif
1118      setMapInMaps (m, "main", "language", "en-US");
1119    }
1120  setlocale (LC_NUMERIC, "C");
1121#ifndef WIN32
1122  setenv ("LC_NUMERIC", "C", 1);
1123#else
1124  char tmp1[17];
1125  sprintf (tmp1, "LC_NUMERIC=C");
1126  _putenv (tmp1);
1127#endif
1128  bind_textdomain_codeset ("zoo-kernel", "UTF-8");
1129  textdomain ("zoo-kernel");
1130  bind_textdomain_codeset ("zoo-services", "UTF-8");
1131  textdomain ("zoo-services");
1132
1133  map *lsoap = getMap (request_inputs, "soap");
1134  if (lsoap != NULL && strcasecmp (lsoap->value, "true") == 0)
1135    setMapInMaps (m, "main", "isSoap", "true");
1136  else
1137    setMapInMaps (m, "main", "isSoap", "false");
1138
1139  if(strlen(cgiServerName)>0)
1140    {
1141      char tmpUrl[1024];
1142       
1143      if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) {
1144        // Knut: check if non-empty instead of "on"?           
1145        if ( strncmp(cgiServerPort, "443", 3) == 0 ) { 
1146          sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
1147        }
1148        else {
1149          sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
1150        }
1151      }
1152      else {
1153        if ( strncmp(cgiServerPort, "80", 2) == 0 ) { 
1154          sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
1155        }
1156        else {
1157          sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
1158        }
1159      }
1160#ifdef DEBUG
1161      fprintf(stderr,"*** %s ***\n",tmpUrl);
1162#endif
1163      setMapInMaps(m,"main","serverAddress",tmpUrl);
1164    }
1165
1166  // CORS Support
1167  if(strncasecmp(cgiRequestMethod,"OPTIONS",7)==0){
1168    map* cors=getMapFromMaps(m,"main","cors");
1169    if(cors!=NULL && strncasecmp(cors->value,"true",4)==0){
1170      char *encoding=getEncoding(m);
1171      printHeaders(m);
1172      printf("Content-Type: text/plain; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
1173      printf(_("CORS is enabled.\r\n"));
1174      freeMaps (&m);
1175      free (m);
1176      fflush (stdout);
1177      return 3;
1178    }
1179  }
1180
1181  //Check for minimum inputs
1182  map* version=getMap(request_inputs,"version");
1183  if(version==NULL)
1184    version=getMapFromMaps(m,"main","version");
1185  setMapInMaps(m,"main","rversion",version->value);
1186  int vid=getVersionId(version->value);
1187  if(vid<0)
1188    vid=0;
1189  map* err=NULL;
1190  const char **vvr=(const char**)requests[vid];
1191  checkValidValue(request_inputs,&err,"request",vvr,1);
1192  const char *vvs[]={
1193    "WPS",
1194    NULL
1195  };
1196  if(err!=NULL){
1197    checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
1198    printExceptionReportResponse (m, err);
1199    freeMap(&err);
1200    free(err);
1201    if (count (request_inputs) == 1)
1202      {
1203        freeMap (&request_inputs);
1204        free (request_inputs);
1205      }
1206    freeMaps (&m);
1207    free (m);
1208    return 1;
1209  }
1210  checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
1211
1212  const char *vvv[]={
1213    "1.0.0",
1214    "2.0.0",
1215    NULL
1216  };
1217  r_inputs = getMap (request_inputs, "Request");
1218  if(r_inputs!=NULL)
1219    REQUEST = zStrdup (r_inputs->value);
1220  int reqId=-1;
1221  if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){
1222    checkValidValue(request_inputs,&err,"version",(const char**)vvv,1);
1223    int j=0;
1224    for(j=0;j<nbSupportedRequests;j++){
1225      if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){
1226        if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){
1227          checkValidValue(request_inputs,&err,"identifier",NULL,1);
1228          reqId=j+1;
1229          break;
1230        }
1231        else
1232          if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob && 
1233             strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){
1234            checkValidValue(request_inputs,&err,"jobid",NULL,1);
1235            reqId=j+1;
1236            break;
1237          }
1238      }else
1239        break;
1240    }
1241  }else{
1242    checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1);
1243    map* version1=getMap(request_inputs,"AcceptVersions");
1244    if(version1!=NULL){
1245      if(strstr(version1->value,schemas[1][0])!=NULL)
1246        addToMap(request_inputs,"version",schemas[1][0]);
1247      else
1248        addToMap(request_inputs,"version",version1->value);
1249      version=getMap(request_inputs,"version");
1250      setMapInMaps(m,"main","rversion",version->value);
1251      vid=getVersionId(version->value);
1252    }
1253  }
1254  if(err!=NULL){
1255    printExceptionReportResponse (m, err);
1256    freeMap(&err);
1257    free(err);
1258    if (count (request_inputs) == 1)
1259      {
1260        freeMap (&request_inputs);
1261        free (request_inputs);
1262      }
1263    free(REQUEST);
1264    freeMaps (&m);
1265    free (m);
1266    return 1;
1267  }
1268
1269  r_inputs = getMap (request_inputs, "serviceprovider");
1270  if (r_inputs == NULL)
1271    {
1272      addToMap (request_inputs, "serviceprovider", "");
1273    }
1274
1275  maps *request_output_real_format = NULL;
1276  map *tmpm = getMapFromMaps (m, "main", "serverAddress");
1277  if (tmpm != NULL)
1278    SERVICE_URL = zStrdup (tmpm->value);
1279  else
1280    SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL);
1281
1282
1283
1284  service *s1;
1285  int scount = 0;
1286#ifdef DEBUG
1287  dumpMap (r_inputs);
1288#endif
1289  char conf_dir[1024];
1290  int t;
1291  char tmps1[1024];
1292
1293  r_inputs = NULL;
1294  r_inputs = getMap (request_inputs, "metapath");
1295  map* cwdMap0=getMapFromMaps(m,"main","servicePath");
1296  if (r_inputs != NULL)
1297    if(cwdMap0!=NULL)
1298      snprintf (conf_dir, 1024, "%s/%s", cwdMap0->value, r_inputs->value);
1299    else
1300      snprintf (conf_dir, 1024, "%s/%s", ntmp, r_inputs->value);
1301  else
1302    if(cwdMap0!=NULL)
1303      snprintf (conf_dir, 1024, "%s", cwdMap0->value);
1304    else
1305      snprintf (conf_dir, 1024, "%s", ntmp);
1306  map* reg = getMapFromMaps (m, "main", "registry");
1307  registry* zooRegistry=NULL;
1308  if(reg!=NULL){
1309    int saved_stdout = zDup (fileno (stdout));
1310    zDup2 (fileno (stderr), fileno (stdout));
1311    if(createRegistry (m,&zooRegistry,reg->value)<0){
1312      map *message=getMapFromMaps(m,"lenv","message");
1313      map *type=getMapFromMaps(m,"lenv","type");
1314      zDup2 (saved_stdout, fileno (stdout));
1315      errorException (m, message->value,
1316                      type->value, NULL);
1317      return 0;
1318    }
1319    zDup2 (saved_stdout, fileno (stdout));
1320    zClose(saved_stdout);
1321  }
1322
1323  if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0)
1324    {
1325#ifdef DEBUG
1326      dumpMap (r_inputs);
1327#endif
1328      xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
1329      xmlNodePtr n=printGetCapabilitiesHeader(doc,m,(version!=NULL?version->value:"1.0.0"));
1330      /**
1331       * Here we need to close stdout to ensure that unsupported chars
1332       * has been found in the zcfg and then printed on stdout
1333       */
1334      int saved_stdout = zDup (fileno (stdout));
1335      zDup2 (fileno (stderr), fileno (stdout));
1336
1337      maps* imports = getMaps(m, IMPORTSERVICE);
1338      if (imports != NULL) {       
1339        map* zcfg = imports->content;
1340       
1341        while (zcfg != NULL) {
1342          if (zcfg->value != NULL) {
1343            service* svc = (service*) malloc(SERVICE_SIZE);
1344            if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) {
1345              // pass over silently
1346              zcfg = zcfg->next;
1347              continue;
1348            }
1349            inheritance(zooRegistry, &svc);
1350            printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc);
1351            freeService(&svc);
1352            free(svc);                             
1353          }
1354          zcfg = zcfg->next;
1355        }           
1356      }
1357
1358      if (int res =               
1359          recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0,
1360                          printGetCapabilitiesForProcess) < 0)
1361        {
1362          freeMaps (&m);
1363          free (m);
1364          if(zooRegistry!=NULL){
1365            freeRegistry(&zooRegistry);
1366            free(zooRegistry);
1367          }
1368          free (REQUEST);
1369          free (SERVICE_URL);
1370          fflush (stdout);
1371          return res;
1372        }
1373      fflush (stdout);
1374      zDup2 (saved_stdout, fileno (stdout));
1375#ifdef META_DB
1376      fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1);
1377      close_sql(m,0);
1378#endif     
1379      printDocument (m, doc, zGetpid ());
1380      freeMaps (&m);
1381      free (m);
1382      if(zooRegistry!=NULL){
1383        freeRegistry(&zooRegistry);
1384        free(zooRegistry);
1385      }
1386      free (REQUEST);
1387      free (SERVICE_URL);
1388      fflush (stdout);
1389      return 0;
1390    }
1391  else
1392    {
1393      r_inputs = getMap (request_inputs, "JobId");
1394      if(reqId>nbReqIdentifier){
1395        if (strncasecmp (REQUEST, "GetStatus", 9) == 0 ||
1396            strncasecmp (REQUEST, "GetResult", 9) == 0){
1397          runGetStatus(m,r_inputs->value,REQUEST);
1398#ifdef RELY_ON_DB
1399          map* dsNb=getMapFromMaps(m,"lenv","ds_nb");
1400          if(dsNb!=NULL && atoi(dsNb->value)>1)
1401            close_sql(m,1);
1402          close_sql(m,0);
1403#endif
1404         
1405          freeMaps (&m);
1406          free(m);
1407          if(zooRegistry!=NULL){
1408            freeRegistry(&zooRegistry);
1409            free(zooRegistry);
1410          }
1411          free (REQUEST);
1412          free (SERVICE_URL);
1413          return 0;
1414        }
1415        else
1416          if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){
1417            runDismiss(m,r_inputs->value);
1418            freeMaps (&m);
1419            free (m);
1420            if(zooRegistry!=NULL){
1421              freeRegistry(&zooRegistry);
1422              free(zooRegistry);
1423            }
1424            free (REQUEST);
1425            free (SERVICE_URL);
1426            return 0;
1427           
1428          }
1429        return 0;
1430      }
1431      if(reqId<=nbReqIdentifier){
1432        r_inputs = getMap (request_inputs, "Identifier");
1433
1434        struct dirent *dp;
1435        DIR *dirp = opendir (conf_dir);
1436        if (dirp == NULL)
1437          {
1438            errorException (m, _("The specified path does not exist."),
1439                            "InternalError", NULL);
1440            freeMaps (&m);
1441            free (m);
1442            if(zooRegistry!=NULL){
1443              freeRegistry(&zooRegistry);
1444              free(zooRegistry);
1445            }
1446            free (REQUEST);
1447            free (SERVICE_URL);
1448            return 0;
1449          }
1450        if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
1451          {
1452            /**
1453             * Loop over Identifier list
1454             */
1455            xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
1456            r_inputs = NULL;
1457            r_inputs = getMap (request_inputs, "version");
1458#ifdef DEBUG
1459            fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
1460            fflush(stderr);
1461#endif
1462            xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
1463                                          root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1);
1464
1465            r_inputs = getMap (request_inputs, "Identifier");
1466
1467            char *orig = zStrdup (r_inputs->value);
1468
1469            int saved_stdout = zDup (fileno (stdout));
1470            zDup2 (fileno (stderr), fileno (stdout));
1471            if (strcasecmp ("all", orig) == 0)
1472              {
1473                maps* imports = getMaps(m, IMPORTSERVICE); 
1474                if (imports != NULL) {       
1475                  map* zcfg = imports->content;
1476           
1477                  while (zcfg != NULL) {
1478                    if (zcfg->value != NULL) {
1479                      service* svc = (service*) malloc(SERVICE_SIZE);
1480                      if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) {
1481                        // pass over silently
1482                        zcfg = zcfg->next;
1483                        continue;
1484                      }
1485                      inheritance(zooRegistry, &svc);
1486#ifdef USE_HPC
1487                      addNestedOutputs(&svc);
1488#endif
1489
1490                      printDescribeProcessForProcess(zooRegistry, m, doc, n, svc);
1491                      freeService(&svc);
1492                      free(svc);                             
1493                    }
1494                    zcfg = zcfg->next;
1495                  }           
1496                }
1497 
1498                if (int res =
1499                    recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0,
1500                                    printDescribeProcessForProcess) < 0)
1501                  return res;
1502#ifdef META_DB
1503                fetchServicesFromDb(zooRegistry,m,doc,n,printDescribeProcessForProcess,0);
1504                close_sql(m,0);
1505#endif     
1506
1507              }
1508            else
1509              {
1510                char *saveptr;
1511                char *tmps = strtok_r (orig, ",", &saveptr);
1512
1513                char buff[256];
1514                char buff1[1024];
1515                while (tmps != NULL)
1516                  {
1517                    int hasVal = -1;
1518                    char *corig = zStrdup (tmps);
1519                    map* import = getMapFromMaps (m, IMPORTSERVICE, corig);   
1520                    if (import != NULL && import->value != NULL) 
1521                      {
1522#ifdef META_DB                 
1523                        service* s2=extractServiceFromDb(m,import->name,0);
1524                        if(s2==NULL){
1525#endif
1526                          s1 = createService();
1527                          t = readServiceFile (m, import->value, &s1, import->name);
1528               
1529                          if (t < 0) // failure reading zcfg
1530                            {
1531                              map *tmp00 = getMapFromMaps (m, "lenv", "message");
1532                              char tmp01[1024];
1533                              if (tmp00 != NULL)
1534                                sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value);
1535                              else
1536                                sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value);
1537                             
1538                              zDup2 (saved_stdout, fileno (stdout));
1539                              errorException (m, tmp01, "InternalError", NULL);
1540                             
1541                              freeMaps (&m);
1542                              free (m);
1543
1544                              if(zooRegistry!=NULL){
1545                                freeRegistry(&zooRegistry);
1546                                free(zooRegistry);
1547                              }
1548                              free (orig);
1549                              free (REQUEST);
1550                              closedir (dirp);
1551                              //xmlFreeDoc (doc);
1552                              xmlCleanupParser ();
1553                              zooXmlCleanupNs ();
1554                   
1555                              return 1;
1556                            }
1557#ifdef DEBUG
1558                          dumpService (s1);
1559#endif
1560                          inheritance(zooRegistry,&s1);
1561#ifdef USE_HPC
1562                          addNestedOutputs(&s1);
1563#endif
1564                          printDescribeProcessForProcess (zooRegistry, m, doc, n, s1);
1565                          freeService (&s1);
1566                          free (s1);
1567                          s1 = NULL;
1568                          scount++;
1569                          hasVal = 1;               
1570#ifdef META_DB
1571                        }
1572#endif
1573                      }
1574                    else if (strstr (corig, ".") != NULL)
1575                      {
1576
1577                        parseIdentifier (m, conf_dir, corig, buff1);
1578                        map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
1579                        if (tmpMap != NULL)
1580                          addToMap (request_inputs, "metapath", tmpMap->value);
1581                        map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
1582                        /**
1583                         * No support for dot in service name stored in metadb!?
1584                         #ifdef META_DB
1585                         service* s2=extractServiceFromDb(m,tmpMapI->value,0);
1586                         if(s2==NULL){
1587                         #endif
1588                        */
1589                        s1 = createService();
1590                        t = readServiceFile (m, buff1, &s1, tmpMapI->value);
1591                        if (t < 0)
1592                          {
1593                            map *tmp00 = getMapFromMaps (m, "lenv", "message");
1594                            char tmp01[1024];
1595                            if (tmp00 != NULL)
1596                              sprintf (tmp01,
1597                                       _
1598                                       ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
1599                                       tmps, tmp00->value);
1600                            else
1601                              sprintf (tmp01,
1602                                       _
1603                                       ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
1604                                       tmps);
1605                            zDup2 (saved_stdout, fileno (stdout));
1606                            errorException (m, tmp01, "InvalidParameterValue",
1607                                            "identifier");
1608                            freeMaps (&m);
1609                            free (m);
1610                            if(zooRegistry!=NULL){
1611                              freeRegistry(&zooRegistry);
1612                              free(zooRegistry);
1613                            }
1614                            free (REQUEST);
1615                            free (corig);
1616                            free (orig);
1617                            free (SERVICE_URL);
1618                            free (s1);
1619                            closedir (dirp);
1620                            //xmlFreeDoc (doc);
1621                            xmlCleanupParser ();
1622                            zooXmlCleanupNs ();
1623                            return 1;
1624                          }
1625#ifdef DEBUG
1626                        dumpService (s1);
1627#endif
1628                        inheritance(zooRegistry,&s1);
1629#ifdef USE_HPC
1630                        addNestedOutputs(&s1);
1631#endif
1632                        printDescribeProcessForProcess (zooRegistry, m, doc, n, s1);
1633                        freeService (&s1);
1634                        free (s1);
1635                        s1 = NULL;
1636                        scount++;
1637                        hasVal = 1;
1638                        setMapInMaps (m, "lenv", "level", "0");
1639                      }
1640                    else
1641                      {
1642#ifdef META_DB
1643                        _init_sql(m,"metadb");
1644                        //FAILED CONNECTING DB
1645                        if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){
1646                          fprintf(stderr,"ERROR CONNECTING METADB");
1647                        }
1648                        service* s2=extractServiceFromDb(m,corig,0);
1649                        if(s2!=NULL){
1650                          inheritance(zooRegistry,&s2);
1651#ifdef USE_HPC
1652                          addNestedOutputs(&s2);
1653#endif
1654                          printDescribeProcessForProcess (zooRegistry,m, doc, n, s2);
1655                          freeService (&s2);
1656                          free (s2);
1657                          s2 = NULL;
1658                          hasVal = 1;
1659                        }else /*TOTO*/{
1660#endif
1661                          memset (buff, 0, 256);
1662                          snprintf (buff, 256, "%s.zcfg", corig);
1663                          memset (buff1, 0, 1024);
1664#ifdef DEBUG
1665                          printf ("\n#######%s\n########\n", buff);
1666#endif
1667                          while ((dp = readdir (dirp)) != NULL)
1668                            {
1669                              if (strcasecmp (dp->d_name, buff) == 0)
1670                                {
1671                                  memset (buff1, 0, 1024);
1672                                  snprintf (buff1, 1024, "%s/%s", conf_dir,
1673                                            dp->d_name);
1674                                  s1 = createService();
1675                                  if (s1 == NULL)
1676                                    {
1677                                      zDup2 (saved_stdout, fileno (stdout));
1678                                      return errorException (m,
1679                                                             _
1680                                                             ("Unable to allocate memory"),
1681                                                             "InternalError",
1682                                                             NULL);
1683                                    }
1684#ifdef DEBUG_SERVICE_CONF
1685                                  fprintf
1686                                    (stderr,"#################\n(%s) %s\n#################\n",
1687                                     r_inputs->value, buff1);
1688#endif
1689                                  char *tmp0 = zStrdup (dp->d_name);
1690                                  tmp0[strlen (tmp0) - 5] = 0;
1691                                  t = readServiceFile (m, buff1, &s1, tmp0);
1692                                  free (tmp0);
1693                                  if (t < 0)
1694                                    {
1695                                      map *tmp00 =
1696                                        getMapFromMaps (m, "lenv", "message");
1697                                      char tmp01[1024];
1698                                      if (tmp00 != NULL)
1699                                        sprintf (tmp01,
1700                                                 _
1701                                                 ("Unable to parse the ZCFG file: %s (%s)"),
1702                                                 dp->d_name, tmp00->value);
1703                                      else
1704                                        sprintf (tmp01,
1705                                                 _
1706                                                 ("Unable to parse the ZCFG file: %s."),
1707                                                 dp->d_name);
1708                                      zDup2 (saved_stdout, fileno (stdout));
1709                                      errorException (m, tmp01, "InternalError",
1710                                                      NULL);
1711                                      freeMaps (&m);
1712                                      free (m);
1713                                      if(zooRegistry!=NULL){
1714                                        freeRegistry(&zooRegistry);
1715                                        free(zooRegistry);
1716                                      }
1717                                      free (orig);
1718                                      free (REQUEST);
1719                                      closedir (dirp);
1720                                      //xmlFreeDoc (doc);
1721                                      xmlCleanupParser ();
1722                                      zooXmlCleanupNs ();
1723                                      return 1;
1724                                    }
1725#ifdef DEBUG
1726                                  dumpService (s1);
1727#endif
1728                                  inheritance(zooRegistry,&s1);
1729#ifdef USE_HPC
1730                                  addNestedOutputs(&s1);
1731#endif
1732                                  /*json_object* jobj=serviceToJson(s1);
1733                                  const char* jsonStr=json_object_to_json_string_ext(jobj,JSON_C_TO_STRING_PLAIN);
1734                                  fprintf(stderr,"*** %s %d %s \n",__FILE__,__LINE__,jsonStr);*/
1735
1736                                  printDescribeProcessForProcess (zooRegistry,m, doc, n, s1);
1737                                  freeService (&s1);
1738                                  free (s1);
1739                                  s1 = NULL;
1740                                  scount++;
1741                                  hasVal = 1;
1742                                }
1743                            }
1744#ifdef META_DB
1745                        }
1746#endif
1747                      }               
1748                    if (hasVal < 0)
1749                      {
1750                        map *tmp00 = getMapFromMaps (m, "lenv", "message");
1751                        char tmp01[1024];
1752                        if (tmp00 != NULL)
1753                          sprintf (tmp01,
1754                                   _("Unable to parse the ZCFG file: %s (%s)"),
1755                                   buff, tmp00->value);
1756                        else
1757                          sprintf (tmp01,
1758                                   _("Unable to parse the ZCFG file: %s."),
1759                                   buff);
1760                        zDup2 (saved_stdout, fileno (stdout));
1761                        errorException (m, tmp01, "InvalidParameterValue",
1762                                        "Identifier");
1763                        freeMaps (&m);
1764                        free (m);
1765                        if(zooRegistry!=NULL){
1766                          freeRegistry(&zooRegistry);
1767                          free(zooRegistry);
1768                        }
1769                        free (orig);
1770                        free (REQUEST);
1771                        closedir (dirp);
1772                        //xmlFreeDoc (doc);
1773                        xmlCleanupParser ();
1774                        zooXmlCleanupNs ();
1775                        return 1;
1776                      }
1777                    rewinddir (dirp);
1778                    tmps = strtok_r (NULL, ",", &saveptr);
1779                    if (corig != NULL)
1780                      free (corig);
1781                  }
1782              }
1783            closedir (dirp);
1784            fflush (stdout);
1785            zDup2 (saved_stdout, fileno (stdout));
1786            free (orig);
1787            printDocument (m, doc, zGetpid ());
1788            freeMaps (&m);
1789            free (m);
1790            if(zooRegistry!=NULL){
1791              freeRegistry(&zooRegistry);
1792              free(zooRegistry);
1793            }
1794            free (REQUEST);
1795            free (SERVICE_URL);
1796            fflush (stdout);
1797#ifdef META_DB
1798            close_sql(m,0);
1799            //end_sql();
1800#endif
1801            return 0;
1802          }
1803        else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
1804          {
1805            map* version=getMapFromMaps(m,"main","rversion");
1806            int vid=getVersionId(version->value);           
1807            int len = 0;
1808            int j = 0;
1809            for(j=0;j<nbSupportedRequests;j++){
1810              if(requests[vid][j]!=NULL)
1811                len+=strlen(requests[vid][j])+2;
1812              else{
1813                len+=4;
1814                break;
1815              }
1816            }
1817            char *tmpStr=(char*)malloc(len*sizeof(char));
1818            int it=0;
1819            for(j=0;j<nbSupportedRequests;j++){
1820              if(requests[vid][j]!=NULL){
1821                if(it==0){
1822                  sprintf(tmpStr,"%s",requests[vid][j]);
1823                  it++;
1824                }else{
1825                  char *tmpS=zStrdup(tmpStr);
1826                  if(j+1<nbSupportedRequests && requests[vid][j+1]==NULL){
1827                    sprintf(tmpStr,"%s and %s",tmpS,requests[vid][j]);
1828                  }else{
1829                    sprintf(tmpStr,"%s, %s",tmpS,requests[vid][j]);
1830                 
1831                  }
1832                  free(tmpS);
1833                }
1834              }
1835              else{
1836                len+=4;
1837                break;
1838              }
1839            }
1840            char* message=(char*)malloc((61+len)*sizeof(char));
1841            sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr);
1842            errorException (m,_(message),"InvalidParameterValue", "request");
1843#ifdef DEBUG
1844            fprintf (stderr, "No request found %s", REQUEST);
1845#endif
1846            closedir (dirp);
1847            freeMaps (&m);
1848            free (m);
1849            if(zooRegistry!=NULL){
1850              freeRegistry(&zooRegistry);
1851              free(zooRegistry);
1852            }
1853            free (REQUEST);
1854            free (SERVICE_URL);
1855            fflush (stdout);
1856            return 0;
1857          }
1858        closedir (dirp);
1859      }
1860    }
1861
1862  map *postRequest = NULL;
1863  postRequest = getMap (request_inputs, "xrequest");
1864 
1865  if(vid==1 && postRequest==NULL){
1866    errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request"); 
1867    freeMaps (&m);
1868    free (m);
1869    if(zooRegistry!=NULL){
1870      freeRegistry(&zooRegistry);
1871      free(zooRegistry);
1872    }
1873    free (REQUEST);
1874    free (SERVICE_URL);
1875    fflush (stdout);
1876    return 0;
1877  }
1878  s1 = NULL;
1879 
1880  r_inputs = getMap (request_inputs, "Identifier");
1881  map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); 
1882  if (import != NULL && import->value != NULL) { 
1883    strncpy(tmps1, import->value, 1024);
1884    setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
1885    setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
1886  } 
1887  else {
1888    snprintf (tmps1, 1024, "%s/%s.zcfg", conf_dir, r_inputs->value);
1889#ifdef DEBUG
1890    fprintf (stderr, "Trying to load %s\n", tmps1);
1891#endif
1892    if (strstr (r_inputs->value, ".") != NULL)
1893      {
1894        char *identifier = zStrdup (r_inputs->value);
1895        parseIdentifier (m, conf_dir, identifier, tmps1);
1896        map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
1897        if (tmpMap != NULL)
1898          addToMap (request_inputs, "metapath", tmpMap->value);
1899        free (identifier);
1900      }
1901    else
1902      {
1903        setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
1904        setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
1905      }
1906  }
1907
1908  r_inputs = getMapFromMaps (m, "lenv", "Identifier");
1909 
1910#ifdef META_DB
1911  int metadb_id=_init_sql(m,"metadb");
1912  //FAILED CONNECTING DB
1913  if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){
1914    fprintf(stderr,"ERROR CONNECTING METADB\n");
1915  }
1916  if(metadb_id>=0)
1917    s1=extractServiceFromDb(m,r_inputs->value,0);
1918  //close_sql(m,0);
1919  if(s1!=NULL){
1920    inheritance(zooRegistry,&s1);
1921#ifdef USE_HPC
1922    addNestedOutputs(&s1);
1923#endif
1924    if(zooRegistry!=NULL){
1925      freeRegistry(&zooRegistry);
1926      free(zooRegistry);
1927    }
1928  }else /* Not found in MetaDB */{
1929#endif
1930    s1 = createService();
1931    if (s1 == NULL)
1932      {
1933        freeMaps (&m);
1934        free (m);
1935        if(zooRegistry!=NULL){
1936          freeRegistry(&zooRegistry);
1937          free(zooRegistry);
1938        }
1939        free (REQUEST);
1940        free (SERVICE_URL);
1941        return errorException (m, _("Unable to allocate memory"),
1942                               "InternalError", NULL);
1943      }
1944
1945    int saved_stdout = zDup (fileno (stdout));
1946    zDup2 (fileno (stderr), fileno (stdout));
1947    t = readServiceFile (m, tmps1, &s1, r_inputs->value);
1948    if(t>=0){
1949      inheritance(zooRegistry,&s1);
1950#ifdef USE_HPC
1951      addNestedOutputs(&s1);
1952#endif
1953    }
1954    if(zooRegistry!=NULL){
1955      freeRegistry(&zooRegistry);
1956      free(zooRegistry);
1957    }
1958    fflush (stdout);
1959    zDup2 (saved_stdout, fileno (stdout));
1960    if (t < 0)
1961      {
1962        char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value));
1963        sprintf (tmpMsg,
1964                 _
1965                 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."),
1966                 r_inputs->value);
1967        errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
1968        free (tmpMsg);
1969        free (s1);
1970        freeMaps (&m);
1971        free (m);
1972        free (REQUEST);
1973        free (SERVICE_URL);
1974        return 0;
1975      }
1976    zClose (saved_stdout);
1977#ifdef META_DB
1978  }
1979#endif
1980 
1981#ifdef DEBUG
1982  dumpService (s1);
1983#endif
1984  int j;
1985
1986
1987  /**
1988   * Create the input and output maps data structure
1989   */
1990  int i = 0;
1991  HINTERNET hInternet;
1992  HINTERNET res;
1993  hInternet = InternetOpen (
1994#ifndef WIN32
1995                            (LPCTSTR)
1996#endif
1997                            "ZooWPSClient\0",
1998                            INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1999
2000#ifndef WIN32
2001  if (!CHECK_INET_HANDLE (hInternet))
2002    fprintf (stderr, "WARNING : hInternet handle failed to initialize");
2003#endif
2004  maps *request_input_real_format = NULL;
2005  maps *tmpmaps = request_input_real_format;
2006
2007  if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){
2008    freeMaps (&m);
2009    free (m);
2010    free (REQUEST);
2011    free (SERVICE_URL);
2012    InternetCloseHandle (&hInternet);
2013    freeService (&s1);
2014    free (s1);
2015    return 0;
2016  }
2017  //InternetCloseHandle (&hInternet);
2018 
2019  // Define each env variable in runing environment
2020  maps *curs = getMaps (m, "env");
2021  if (curs != NULL)
2022    {
2023      map *mapcs = curs->content;
2024      while (mapcs != NULLMAP)
2025        {
2026#ifndef WIN32
2027          setenv (mapcs->name, mapcs->value, 1);
2028#ifdef DEBUG
2029          fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name,
2030                   mapcs->value);
2031#endif
2032#else
2033          if (mapcs->value[strlen (mapcs->value) - 2] == '\r')
2034            {
2035#ifdef DEBUG
2036              fprintf (stderr, "[ZOO: Env var finish with \r]\n");
2037#endif
2038              mapcs->value[strlen (mapcs->value) - 1] = 0;
2039            }
2040#ifdef DEBUG
2041          if (SetEnvironmentVariable (mapcs->name, mapcs->value) == 0)
2042            {
2043              fflush (stderr);
2044              fprintf (stderr, "setting variable... %s\n", "OK");
2045            }
2046          else
2047            {
2048              fflush (stderr);
2049              fprintf (stderr, "setting variable... %s\n", "OK");
2050            }
2051#else
2052          SetEnvironmentVariable (mapcs->name, mapcs->value);
2053#endif
2054          char *toto =
2055            (char *)
2056            malloc ((strlen (mapcs->name) + strlen (mapcs->value) +
2057                     2) * sizeof (char));
2058          sprintf (toto, "%s=%s", mapcs->name, mapcs->value);
2059          _putenv (toto);
2060#ifdef DEBUG
2061          fflush (stderr);
2062#endif
2063#endif
2064#ifdef DEBUG
2065          fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name,
2066                   mapcs->value);
2067          fflush (stderr);
2068#endif
2069          mapcs = mapcs->next;
2070        }
2071    }
2072
2073#ifdef DEBUG
2074  dumpMap (request_inputs);
2075#endif
2076
2077  map *status = getMap (request_inputs, "status");
2078  if(vid==0){
2079    // Need to check if we need to fork to load a status enabled
2080    r_inputs = NULL;
2081    map *store = getMap (request_inputs, "storeExecuteResponse");
2082    /**
2083     * 05-007r7 WPS 1.0.0 page 57 :
2084     * 'If status="true" and storeExecuteResponse is "false" then the service
2085     * shall raise an exception.'
2086     */
2087    if (status != NULL && strcmp (status->value, "true") == 0 &&
2088        store != NULL && strcmp (store->value, "false") == 0)
2089      {
2090        errorException (m,
2091                        _
2092                        ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."),
2093                        "InvalidParameterValue", "storeExecuteResponse");
2094        freeService (&s1);
2095        free (s1);
2096        freeMaps (&m);
2097        free (m);
2098       
2099        freeMaps (&request_input_real_format);
2100        free (request_input_real_format);
2101       
2102        freeMaps (&request_output_real_format);
2103        free (request_output_real_format);
2104
2105        free (REQUEST);
2106        free (SERVICE_URL);
2107        return 1;
2108      }
2109    r_inputs = getMap (request_inputs, "storeExecuteResponse");
2110  }else{
2111    // Define status depending on the WPS 2.0.0 mode attribute
2112    status = getMap (request_inputs, "mode");
2113    map* mode=getMap(s1->content,"mode");
2114    if(strcasecmp(status->value,"async")==0){
2115      if(mode!=NULL && strcasecmp(mode->value,"async")==0)
2116        addToMap(request_inputs,"status","true");
2117      else{
2118        if(mode!=NULL){
2119          // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61
2120          errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value); 
2121          fflush (stdout);
2122          freeMaps (&m);
2123          free (m);
2124          if(zooRegistry!=NULL){
2125            freeRegistry(&zooRegistry);
2126            free(zooRegistry);
2127          }
2128          freeMaps (&request_input_real_format);
2129          free (request_input_real_format);
2130          freeMaps (&request_output_real_format);
2131          free (request_output_real_format);
2132          free (REQUEST);
2133          free (SERVICE_URL);
2134          return 0;
2135        }else
2136          addToMap(request_inputs,"status","true");
2137      }
2138    }
2139    else{
2140      if(strcasecmp(status->value,"auto")==0){
2141        if(mode!=NULL){
2142          if(strcasecmp(mode->value,"async")==0)
2143            addToMap(request_inputs,"status","false");
2144          else
2145            addToMap(request_inputs,"status","true");
2146        }
2147        else
2148          addToMap(request_inputs,"status","false");
2149      }else
2150        addToMap(request_inputs,"status","false");
2151    }
2152    status = getMap (request_inputs, "status");
2153  }
2154
2155  int eres = SERVICE_STARTED;
2156  int cpid = zGetpid ();
2157
2158  // Create a map containing a copy of the request map
2159  maps *_tmpMaps = createMaps("request");
2160  addMapToMap(&_tmpMaps->content,request_inputs);
2161  addMapsToMaps (&m, _tmpMaps);
2162  freeMaps (&_tmpMaps);
2163  free (_tmpMaps);
2164  /**
2165   * Initialize the specific [lenv] section which contains runtime variables:
2166   *
2167   *  - usid : it is an universally unique identifier 
2168   *  - osid : it is an idenfitication number
2169   *  - sid : it is the process idenfitication number (OS)
2170   *  - uusid : it is an universally unique identifier
2171   *  - status : value between 0 and 100 to express the  completude of
2172   * the operations of the running service
2173   *  - message : is a string where you can store error messages, in case
2174   * service is failing, or o provide details on the ongoing operation.
2175   *  - cwd : the current working directory or servicePath if defined
2176   *  - soap : is a boolean value, true if the request was contained in a SOAP
2177   * Envelop
2178   *  - sessid : string storing the session identifier (only when cookie is
2179   * used)
2180   *  - cgiSid : only defined on Window platforms (for being able to identify
2181   * the created process)
2182   *
2183   */
2184  _tmpMaps = createMaps("lenv");
2185  char tmpBuff[100];
2186  struct ztimeval tp;
2187  if (zGettimeofday (&tp, NULL) == 0)
2188    sprintf (tmpBuff, "%i", (cpid + ((int) tp.tv_sec + (int) tp.tv_usec)));
2189  else
2190    sprintf (tmpBuff, "%i", (cpid + (int) time (NULL)));
2191  _tmpMaps->content = createMap ("osid", tmpBuff);
2192  sprintf (tmpBuff, "%i", cpid);
2193  addToMap (_tmpMaps->content, "sid", tmpBuff);
2194  char* tmpUuid=get_uuid();
2195  addToMap (_tmpMaps->content, "uusid", tmpUuid);
2196  addToMap (_tmpMaps->content, "usid", tmpUuid);
2197  free(tmpUuid);
2198  addToMap (_tmpMaps->content, "status", "0");
2199  if(cwdMap0!=NULL){
2200    addToMap (_tmpMaps->content, "cwd", cwdMap0->value);
2201    addToMap (_tmpMaps->content, "rcwd", ntmp);
2202  }
2203  else
2204    addToMap (_tmpMaps->content, "cwd", ntmp);
2205  addToMap (_tmpMaps->content, "message", _("No message provided"));
2206  map *ltmp = getMap (request_inputs, "soap");
2207  if (ltmp != NULL)
2208    addToMap (_tmpMaps->content, "soap", ltmp->value);
2209  else
2210    addToMap (_tmpMaps->content, "soap", "false");
2211
2212  // Parse the session file and add it to the main maps
2213  char* originalCookie=NULL;
2214  if (cgiCookie != NULL && strlen (cgiCookie) > 0)
2215    {
2216      int hasValidCookie = -1;
2217      char *tcook = originalCookie = zStrdup (cgiCookie);
2218      map *testing = getMapFromMaps (m, "main", "cookiePrefix");
2219      parseCookie(&m,originalCookie);
2220      map *sessId=getMapFromMaps(m,"cookies",(testing==NULL?"ID":testing->value));
2221      if (sessId!=NULL)
2222        {
2223          addToMap (_tmpMaps->content, "sessid", sessId->value);
2224          char session_file_path[1024];
2225          map *tmpPath = getMapFromMaps (m, "main", "sessPath");
2226          if (tmpPath == NULL)
2227            tmpPath = getMapFromMaps (m, "main", "tmpPath");
2228          char *tmp1 = strtok (tcook, ";");
2229          if (tmp1 != NULL)
2230            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
2231                     sessId->value);
2232          else
2233            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
2234                     sessId->value);
2235          free (tcook);
2236          maps *tmpSess = (maps *) malloc (MAPS_SIZE);
2237          tmpSess->child=NULL;
2238          struct stat file_status;
2239          int istat = stat (session_file_path, &file_status);
2240          if (istat == 0 && file_status.st_size > 0)
2241            {
2242              int saved_stdout = zDup (fileno (stdout));
2243              zDup2 (fileno (stderr), fileno (stdout));
2244              conf_read (session_file_path, tmpSess);
2245              addMapsToMaps (&m, tmpSess);
2246              freeMaps (&tmpSess);
2247              fflush(stdout);
2248              zDup2 (saved_stdout, fileno (stdout));
2249              zClose(saved_stdout);
2250            }
2251          free (tmpSess);
2252        }
2253    }
2254  addMapsToMaps (&m, _tmpMaps);
2255  freeMaps (&_tmpMaps);
2256  free (_tmpMaps);
2257  maps* bmap=NULL;
2258#ifdef DEBUG
2259  dumpMap (request_inputs);
2260#endif
2261  int ei = 1;
2262 
2263#ifdef WIN32
2264  LPVOID orig = GetEnvironmentStrings();
2265  LPTSTR s = (LPTSTR) orig;
2266#else
2267  char **orig = environ;
2268  char *s=*orig;
2269#endif
2270
2271  _tmpMaps = createMaps("renv");
2272if(orig!=NULL)
2273  for (; 
2274#ifdef WIN32
2275       *s;
2276       s++
2277#else
2278       s;
2279       ei++
2280#endif
2281       ) {
2282    if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){
2283      int len=strlen(s);
2284      char* tmpName=zStrdup(s);
2285      char* tmpValue=strstr(s,"=")+1;
2286      char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char));
2287      snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName);
2288      if(_tmpMaps->content == NULL)
2289        _tmpMaps->content = createMap (tmpName1,tmpValue);
2290      else
2291        addToMap (_tmpMaps->content,tmpName1,tmpValue);
2292      free(tmpName1);
2293      free(tmpName);
2294    }
2295#ifndef WIN32
2296    s = *(orig+ei);
2297#endif
2298  }
2299  if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){
2300    addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]);
2301  }
2302  addMapsToMaps (&m, _tmpMaps);
2303  freeMaps (&_tmpMaps);
2304  free (_tmpMaps);
2305#ifdef WIN32
2306  FreeEnvironmentStrings((LPCH)orig);
2307#endif
2308  if(postRequest!=NULL)
2309    setMapInMaps (m, "renv", "xrequest", postRequest->value);
2310  //dumpMaps(m);
2311#ifdef WIN32
2312  char *cgiSidL = NULL;
2313  if (getenv ("CGISID") != NULL)
2314    addToMap (request_inputs, "cgiSid", getenv ("CGISID"));
2315
2316  char* usidp;
2317  if ( (usidp = getenv("USID")) != NULL ) {
2318    setMapInMaps (m, "lenv", "usid", usidp);
2319  }
2320
2321  map *test1 = getMap (request_inputs, "cgiSid");
2322  if (test1 != NULL){
2323    cgiSid = zStrdup(test1->value);
2324    addToMap (request_inputs, "storeExecuteResponse", "true");
2325    addToMap (request_inputs, "status", "true");
2326    setMapInMaps (m, "lenv", "osid", test1->value);
2327    status = getMap (request_inputs, "status");
2328  }
2329  test1 = getMap (request_inputs, "usid");
2330  if (test1 != NULL){
2331    setMapInMaps (m, "lenv", "usid", test1->value);
2332    setMapInMaps (m, "lenv", "uusid", test1->value);
2333  }
2334#endif
2335
2336  char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog;
2337  FILE *f0, *f1;
2338  if (status != NULL)
2339    if (strcasecmp (status->value, "false") == 0)
2340      status = NULLMAP;
2341  if (status == NULLMAP)
2342    {
2343      if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
2344        freeService (&s1);
2345        free (s1);
2346        freeMaps (&m);
2347        free (m);
2348        free (REQUEST);
2349        free (SERVICE_URL);
2350        freeMaps (&request_input_real_format);
2351        free (request_input_real_format);
2352        freeMaps (&request_output_real_format);
2353        free (request_output_real_format);
2354        freeMaps (&tmpmaps);
2355        free (tmpmaps);
2356        return -1;
2357      }
2358      map* testMap=getMapFromMaps(m,"main","memory");
2359      if(testMap==NULL || strcasecmp(testMap->value,"load")!=0)
2360        dumpMapsValuesToFiles(&m,&request_input_real_format);
2361      loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
2362                         &request_output_real_format, &eres);     
2363
2364#ifdef META_DB
2365      close_sql(m,0);     
2366#endif     
2367    }
2368  else
2369    {
2370      int pid;
2371#ifdef DEBUG
2372      fprintf (stderr, "\nPID : %d\n", cpid);
2373#endif
2374#ifndef WIN32
2375      pid = fork ();
2376#else
2377      if (cgiSid == NULL)
2378        {
2379          createProcess (m, request_inputs, s1, NULL, cpid,
2380                         request_input_real_format,
2381                         request_output_real_format);
2382          pid = cpid;
2383        }
2384      else
2385        {
2386          pid = 0;
2387          cpid = atoi (cgiSid);
2388          updateStatus(m,0,_("Initializing"));
2389        }
2390#endif
2391      if (pid > 0)
2392        {
2393          //
2394          // dady :
2395          // set status to SERVICE_ACCEPTED
2396          //
2397#ifdef DEBUG
2398          fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
2399                   zGetpid ());
2400#endif
2401          eres = SERVICE_ACCEPTED;
2402        }
2403      else if (pid == 0)
2404        {
2405          eres = SERVICE_ACCEPTED;
2406          //
2407          // son : have to close the stdout, stdin and stderr to let the parent
2408          // process answer to http client.
2409          //
2410          map* usid = getMapFromMaps (m, "lenv", "uusid");
2411          map* tmpm = getMapFromMaps (m, "lenv", "osid");
2412          int cpid = atoi (tmpm->value);
2413          pid=cpid;
2414          r_inputs = getMapFromMaps (m, "main", "tmpPath");
2415          setMapInMaps (m, "lenv", "async","true");
2416          map* r_inputs1 = createMap("ServiceName", s1->name);
2417
2418          // Create the filename for the result file (.res)
2419          fbkpres =
2420            (char *)
2421            malloc ((strlen (r_inputs->value) +
2422                     strlen (usid->value) + 7) * sizeof (char));                   
2423          sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value);
2424          bmap = createMaps("status");
2425          bmap->content=createMap("usid",usid->value);
2426          addToMap(bmap->content,"sid",tmpm->value);
2427          addIntToMap(bmap->content,"pid",zGetpid());
2428         
2429          // Create PID file referencing the OS process identifier
2430          fbkpid =
2431            (char *)
2432            malloc ((strlen (r_inputs->value) +
2433                     strlen (usid->value) + 7) * sizeof (char));
2434          sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value);
2435          setMapInMaps (m, "lenv", "file.pid", fbkpid);
2436
2437          f0 = freopen (fbkpid, "w+",stdout);
2438          printf("%d",zGetpid());
2439          fflush(stdout);
2440
2441          // Create SID file referencing the semaphore name
2442          fbkp =
2443            (char *)
2444            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
2445                     strlen (usid->value) + 7) * sizeof (char));
2446          sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value);
2447          setMapInMaps (m, "lenv", "file.sid", fbkp);
2448          FILE* f2 = freopen (fbkp, "w+",stdout);
2449          printf("%s",tmpm->value);
2450          fflush(f2);
2451          free(fbkp);
2452
2453          fbkp =
2454            (char *)
2455            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
2456                     strlen (usid->value) + 7) * sizeof (char));
2457          sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value,
2458                   usid->value);
2459          setMapInMaps (m, "lenv", "file.responseInit", fbkp);
2460          flog =
2461            (char *)
2462            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
2463                     strlen (usid->value) + 13) * sizeof (char));
2464          sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
2465                   r_inputs1->value, usid->value);
2466          setMapInMaps (m, "lenv", "file.log", flog);
2467#ifdef DEBUG
2468          fprintf (stderr, "RUN IN BACKGROUND MODE \n");
2469          fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
2470                   zGetpid ());
2471          fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
2472#endif
2473          freopen (flog, "w+", stderr);
2474          fflush (stderr);
2475          f0 = freopen (fbkp, "w+", stdout);
2476          rewind (stdout);
2477#ifndef WIN32
2478          fclose (stdin);
2479#endif
2480#ifdef RELY_ON_DB
2481          init_sql(m);
2482          recordServiceStatus(m);
2483#endif
2484#ifdef USE_HPC
2485          invokeCallback(m,NULL,NULL,0,0);
2486#endif
2487          if(vid==0){
2488            //
2489            // set status to SERVICE_STARTED and flush stdout to ensure full
2490            // content was outputed (the file used to store the ResponseDocument).
2491            // Then, rewind stdout to restart writing from the begining of the file.
2492            // This way, the data will be updated at the end of the process run.
2493            //
2494            printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
2495                                  SERVICE_STARTED, request_input_real_format,
2496                                  request_output_real_format);
2497            fflush (stdout);
2498#ifdef RELY_ON_DB
2499            recordResponse(m,fbkp);
2500#endif
2501          }
2502
2503          fflush (stderr);
2504
2505          fbkp1 =
2506            (char *)
2507            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
2508                     strlen (usid->value) + 13) * sizeof (char));
2509          sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value,
2510                   r_inputs1->value, usid->value);
2511          setMapInMaps (m, "lenv", "file.responseFinal", fbkp1);
2512
2513          f1 = freopen (fbkp1, "w+", stdout);
2514
2515          map* serviceTypeMap=getMap(s1->content,"serviceType");
2516          if(serviceTypeMap!=NULL)
2517            setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value);
2518
2519          char *flenv =
2520            (char *)
2521            malloc ((strlen (r_inputs->value) + 
2522                     strlen (usid->value) + 12) * sizeof (char));
2523          sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value);
2524          maps* lenvMaps=getMaps(m,"lenv");
2525          dumpMapsToFile(lenvMaps,flenv,0);
2526          free(flenv);
2527
2528#ifdef USE_HPC
2529          invokeCallback(m,request_input_real_format,NULL,1,0);
2530#endif
2531          if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
2532            freeService (&s1);
2533            free (s1);
2534            fflush (stdout);
2535            fflush (stderr);
2536            fclose (f0);
2537            fclose (f1);
2538            if(dumpBackFinalFile(m,fbkp,fbkp1)<0)
2539              return -1;
2540#ifndef RELY_ON_DB
2541            dumpMapsToFile(bmap,fbkpres,1);
2542            removeShmLock (m, 1);
2543#else
2544            recordResponse(m,fbkp1);
2545#ifdef USE_HPC
2546            invokeCallback(m,NULL,NULL,7,0);
2547#endif
2548#endif
2549            zUnlink (fbkpid);
2550            unhandleStatus (m);
2551#ifdef RELY_ON_DB
2552#ifdef META_DB
2553            cleanupCallbackThreads();
2554            close_sql(m,1);
2555#endif
2556            close_sql(m,0);
2557#endif
2558            freeMaps (&m);
2559            free (m);
2560            free (REQUEST);
2561            free (SERVICE_URL);
2562            freeMaps (&request_input_real_format);
2563            free (request_input_real_format);
2564            freeMaps (&request_output_real_format);
2565            free (request_output_real_format);
2566            freeMaps (&tmpmaps);
2567            free (tmpmaps);
2568            return -1;
2569          }
2570          if(getMapFromMaps(m,"lenv","mapError")!=NULL){
2571            setMapInMaps(m,"lenv","message",_("Issue with geographic data"));
2572#ifdef USE_HPC
2573            invokeCallback(m,NULL,NULL,7,0);
2574#endif
2575            eres=-1;//SERVICE_FAILED;
2576          }else{
2577            map* testMap=getMapFromMaps(m,"main","memory");
2578            if(testMap==NULL || strcasecmp(testMap->value,"load")!=0)
2579              dumpMapsValuesToFiles(&m,&request_input_real_format);
2580            loadServiceAndRun (&m, s1, request_inputs,
2581                               &request_input_real_format,
2582                               &request_output_real_format, &eres);
2583          }
2584        }
2585      else
2586        {
2587          /**
2588           * error server don't accept the process need to output a valid
2589           * error response here !!!
2590           */
2591          eres = -1;
2592          errorException (m, _("Unable to run the child process properly"),
2593                          "InternalError", NULL);
2594        }
2595    }
2596       
2597#ifdef DEBUG
2598  fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
2599  dumpMaps (request_output_real_format);
2600  fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
2601#endif
2602  fflush(stdout);
2603  rewind(stdout);
2604
2605  //fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,eres); 
2606  if (eres != -1)
2607    outputResponse (s1, request_input_real_format,
2608                    request_output_real_format, request_inputs,
2609                    cpid, m, eres);
2610  fflush (stdout);
2611 
2612  /**
2613   * Ensure that if error occurs when freeing memory, no signal will return
2614   * an ExceptionReport document as the result was already returned to the
2615   * client.
2616   */
2617#ifndef USE_GDB
2618  signal (SIGSEGV, donothing);
2619  signal (SIGTERM, donothing);
2620  signal (SIGINT, donothing);
2621  signal (SIGILL, donothing);
2622  signal (SIGFPE, donothing);
2623  signal (SIGABRT, donothing);
2624#endif
2625
2626  if (((int) zGetpid ()) != cpid || cgiSid != NULL)
2627    {
2628      if (eres == SERVICE_SUCCEEDED)
2629#ifdef USE_HPC
2630        invokeCallback(m,NULL,request_output_real_format,5,1);
2631#endif
2632      fflush(stderr);
2633      fflush(stdout);
2634
2635      fclose (stdout);
2636
2637      fclose (f0);
2638      fclose (f1);
2639
2640      if(dumpBackFinalFile(m,fbkp,fbkp1)<0)
2641        return -1;
2642      zUnlink (fbkpid);
2643      switch(eres){
2644      default:
2645      case SERVICE_FAILED:
2646        setMapInMaps(bmap,"status","status",wpsStatus[1]);
2647        setMapInMaps(m,"lenv","fstate",wpsStatus[1]);
2648        break;
2649      case SERVICE_SUCCEEDED:
2650        setMapInMaps(bmap,"status","status",wpsStatus[0]);
2651        setMapInMaps(m,"lenv","fstate",wpsStatus[0]);
2652        break;
2653      }     
2654#ifndef RELY_ON_DB
2655      dumpMapsToFile(bmap,fbkpres,1);
2656      removeShmLock (m, 1);
2657#else
2658      recordResponse(m,fbkp1);
2659      if (eres == SERVICE_SUCCEEDED)
2660#ifdef USE_HPC
2661        invokeCallback(m,NULL,request_output_real_format,6,0);
2662#endif
2663#endif
2664      freeMaps(&bmap);
2665      free(bmap);
2666      zUnlink (fbkp1);
2667      unhandleStatus (m);
2668#ifdef RELY_ON_DB
2669#ifdef META_DB
2670      cleanupCallbackThreads();
2671      close_sql(m,1);
2672#endif
2673      close_sql(m,0);
2674      end_sql();
2675#endif
2676      free(fbkpid);
2677      free(fbkpres); 
2678      free (fbkp1);
2679      if(cgiSid!=NULL)
2680        free(cgiSid);
2681      //InternetCloseHandle (&hInternet);
2682      fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
2683      fflush(stderr);
2684      fclose (stderr);
2685      zUnlink (flog);
2686      free (flog);
2687    }
2688  else{
2689    //InternetCloseHandle (&hInternet); 
2690#ifdef META_DB
2691    close_sql(m,0);
2692#endif
2693  }
2694 
2695  freeService (&s1);
2696  free (s1);
2697  freeMaps (&m);
2698  free (m);
2699
2700  freeMaps (&request_input_real_format);
2701  free (request_input_real_format);
2702
2703  freeMaps (&request_output_real_format);
2704  free (request_output_real_format);
2705
2706  free (REQUEST);
2707  free (SERVICE_URL);
2708#ifdef DEBUG
2709  fprintf (stderr, "Processed response \n");
2710  fflush (stdout);
2711  fflush (stderr);
2712#endif
2713
2714  if (((int) zGetpid ()) != cpid || cgiSid != NULL)
2715    {
2716      exit (0);
2717    }
2718
2719  return 0;
2720}
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