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

Last change on this file since 851 was 851, checked in by djay, 7 years ago

Invoke callback asynchronously. Still the ZOO-Kernel has still to wait for every requests to finish before stoping its execution.

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