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

Last change on this file since 902 was 902, checked in by djay, 5 years ago

Make Callback and HPC support independent.

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