Ignore:
Timestamp:
May 7, 2019, 2:17:08 PM (5 years ago)
Author:
djay
Message:

Merge prototype-v0 branch in trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r889 r917  
    2626extern "C" int crlex ();
    2727
     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
    2835#ifdef USE_OTB
    2936#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"
    3045#endif
    3146
     
    5570#endif
    5671
     72#ifdef META_DB
     73#include "meta_sql.h"
     74#endif
     75
    5776#ifdef USE_PYTHON
    5877#include "service_internal_python.h"
     
    87106#endif
    88107
     108#ifdef USE_CALLBACK
     109#include "service_json.h"
     110#include "service_callback.h"
     111#endif
     112
    89113#include <dirent.h>
    90114#include <signal.h>
     115#ifndef WIN32
     116#include <execinfo.h>
     117#endif
    91118#include <unistd.h>
    92119#ifndef WIN32
     
    105132#include <stdarg.h>
    106133
     134#include <libxml/tree.h>
     135#include <libxml/parser.h>
     136#include <libxml/xpath.h>
     137#include <libxml/xpathInternals.h>
     138
     139#include <libxslt/xslt.h>
     140#include <libxslt/xsltInternals.h>
     141#include <libxslt/transform.h>
     142#include <libxslt/xsltutils.h>
     143
    107144#ifndef WIN32
    108145extern char **environ;
     146#endif
     147
     148
     149#ifdef WIN32
     150extern "C"
     151{
     152  __declspec (dllexport) char *strcasestr (char const *a, char const *b)
     153#ifndef USE_MS
     154  {
     155    char *x = zStrdup (a);
     156    char *y = zStrdup (b);
     157
     158      x = _strlwr (x);
     159      y = _strlwr (y);
     160    char *pos = strstr (x, y);
     161    char *ret = pos == NULL ? NULL : (char *) (a + (pos - x));
     162      free (x);
     163      free (y);
     164      return ret;
     165  };
     166#else
     167   ;
     168#endif
     169}
    109170#endif
    110171
     
    119180
    120181#ifdef WIN32
    121   #ifndef PROGRAMNAME
    122     #define PROGRAMNAME "zoo_loader.cgi"
    123   #endif
     182#ifndef PROGRAMNAME
     183#define PROGRAMNAME "zoo_loader.cgi"
     184#endif
    124185#endif
    125186
     
    159220  lockShm (lid);
    160221#endif
    161   FILE *f3 = fopen (fbkp, "wb+"); 
    162   free (fbkp); 
     222  FILE *f3 = fopen (fbkp, "wb+");
     223  free (fbkp);
    163224  fseek (f2, 0, SEEK_END);
    164225  long flen = ftell (f2);
    165226  fseek (f2, 0, SEEK_SET);
    166227  char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char));
    167   fread (tmps1, flen, 1, f2); 
     228  fread (tmps1, flen, 1, f2);
    168229#ifdef WIN32
    169230  /* knut: I think this block can be dropped; pchr may be NULL if result is not in XML format
    170   char *pchr=strrchr(tmps1,'>');   
    171   flen=strlen(tmps1)-strlen(pchr)+1; 
    172   tmps1[flen]=0; 
     231  char *pchr=strrchr(tmps1,'>');
     232  flen=strlen(tmps1)-strlen(pchr)+1;
     233  tmps1[flen]=0;
    173234  */
    174 #endif 
     235#endif
    175236  fwrite (tmps1, 1, flen, f3);
     237  fclose (f2);
     238  fclose (f3);
    176239  free(tmps1);
    177   fclose (f2);
    178   fclose (f3); 
    179240  return 1;
    180241}
     
    197258 */
    198259int
    199 recursReaddirF ( maps * m, registry *r, xmlNodePtr n, char *conf_dir,
     260recursReaddirF ( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir,
    200261                 char *prefix, int saved_stdout, int level,
    201                  void (func) (registry *, maps *, xmlNodePtr, service *) )
     262                 void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) )
    202263{
    203264  struct dirent *dp;
     
    246307            setMapInMaps (m, "lenv", "level", levels1);
    247308            res =
    248               recursReaddirF (m, r, n, tmp, prefix, saved_stdout, level + 1,
     309              recursReaddirF (m, r, doc, n, tmp, prefix, saved_stdout, level + 1,
    249310                              func);
    250311            sprintf (levels1, "%d", level);
     
    264325      {
    265326        char* extn = strstr(dp->d_name, ".zcfg");
    266         if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5)
     327        if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5 && strlen(dp->d_name)>6)
    267328          {
    268329            int t;
     
    271332            snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name);
    272333
    273             char *tmpsn = zStrdup (dp->d_name);
    274             tmpsn[strlen (tmpsn) - 5] = 0;
     334            char *tmpsn = (char*)malloc((strlen(dp->d_name)-4)*sizeof(char));//zStrdup (dp->d_name);
     335            memset (tmpsn, 0, strlen(dp->d_name)-4);
     336            snprintf(tmpsn,strlen(dp->d_name)-4,"%s",dp->d_name);
    275337           
    276338            map* import = getMapFromMaps (m, IMPORTSERVICE, tmpsn);
    277339            if (import == NULL || import->value == NULL || zoo_path_compare(tmps1, import->value) != 0 ) { // service is not in [include] block
    278               service *s1 = (service *) malloc (SERVICE_SIZE);
     340              service *s1 = createService();
    279341              if (s1 == NULL)
    280342                {
    281                   dup2 (saved_stdout, fileno (stdout));
     343                  zDup2 (saved_stdout, fileno (stdout));
    282344                  errorException (m, _("Unable to allocate memory"),
    283345                                  "InternalError", NULL);
     
    300362                    sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
    301363                             dp->d_name);
    302                   dup2 (saved_stdout, fileno (stdout));
     364                  zDup2 (saved_stdout, fileno (stdout));
    303365                  errorException (m, tmp01, "InternalError", NULL);
    304366                  return -1;
     
    309371              fflush (stderr);
    310372  #endif
    311         inheritance(r,&s1);
    312               func (r, m, n, s1);
     373              if(s1!=NULL)
     374                inheritance(r,&s1);
     375              func (r, m, doc, n, s1);
    313376              freeService (&s1);
    314377              free (s1);
     
    344407sig_handler (int sig)
    345408{
     409 
    346410  char tmp[100];
    347411  const char *ssig;
     
    372436  sprintf (tmp,
    373437           _
    374            ("ZOO Kernel failed to process your request, receiving signal %d = %s"),
     438           ("ZOO Kernel failed to process your request, receiving signal %d = %s "),
    375439           sig, ssig);
    376440  errorException (NULL, tmp, "InternalError", NULL);
     
    420484#endif
    421485
    422   map* libp = getMapFromMaps(m, "main", "libPath");
    423 
     486  map* libp = getMapFromMaps(m, "main", "libPath"); 
    424487  if (strlen (r_inputs->value) == 1
    425488      && strncasecmp (r_inputs->value, "C", 1) == 0)
     
    610673  else
    611674
     675#ifdef USE_HPC
     676  if (strncasecmp (r_inputs->value, "HPC", 3) == 0)
     677    {
     678      *eres =
     679        zoo_hpc_support (&m, request_inputs, s1,
     680                            &request_input_real_format,
     681                            &request_output_real_format);
     682    }
     683  else
     684#endif
     685
    612686#ifdef USE_SAGA
    613   if (strncasecmp (r_inputs->value, "SAGA", 6) == 0)
     687  if (strncasecmp (r_inputs->value, "SAGA", 4) == 0)
    614688    {
    615689      *eres =
     
    622696
    623697#ifdef USE_OTB
    624   if (strncasecmp (r_inputs->value, "OTB", 6) == 0)
     698  if (strncasecmp (r_inputs->value, "OTB", 3) == 0)
    625699    {
    626700      *eres =
     
    633707#ifdef USE_PYTHON
    634708  if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0)
     709    {             
     710      *eres =
     711        zoo_python_support (&m, request_inputs, s1,
     712                            &request_input_real_format,
     713                            &request_output_real_format);         
     714    }
     715  else
     716#endif
     717
     718#ifdef USE_R
     719  if (strncasecmp (r_inputs->value, "R", 6) == 0)
    635720    {     
    636721      *eres =
    637         zoo_python_support (&m, request_inputs, s1,
     722        zoo_r_support (&m, request_inputs, s1,
    638723                            &request_input_real_format,
    639724                            &request_output_real_format);
     
    713798    }
    714799  *myMap = m;
    715   *ioutputs = request_output_real_format;
     800  *ioutputs = request_output_real_format; 
    716801}
    717802
     
    902987#endif
    903988
     989 
    904990  map *r_inputs = NULL;
    905991  map *request_inputs = *inputs;
     992  //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapToJson(request_inputs),JSON_C_TO_STRING_PLAIN));
     993 
    906994#ifdef IGNORE_METAPATH
    907995  addToMap(request_inputs, "metapath", "");
     
    9351023#ifdef ETC_DIR
    9361024#ifndef WIN32
    937     getcwd (ntmp, 1024);
     1025  getcwd (ntmp, 1024);
    9381026#else
    939     _getcwd (ntmp, 1024);
     1027  _getcwd (ntmp, 1024);
    9401028#endif
    9411029#endif
     
    10131101      char tmp1[13];
    10141102      sprintf (tmp1, "LC_ALL=%s", tmp);
    1015       putenv (tmp1);
     1103      _putenv (tmp1);
    10161104#endif
    10171105      free (tmp);
     
    10251113      char tmp1[13];
    10261114      sprintf (tmp1, "LC_ALL=en_US");
    1027       putenv (tmp1);
     1115      _putenv (tmp1);
    10281116#endif
    10291117      setMapInMaps (m, "main", "language", "en-US");
     
    10351123  char tmp1[17];
    10361124  sprintf (tmp1, "LC_NUMERIC=C");
    1037   putenv (tmp1);
     1125  _putenv (tmp1);
    10381126#endif
    10391127  bind_textdomain_codeset ("zoo-kernel", "UTF-8");
     
    11271215  };
    11281216  r_inputs = getMap (request_inputs, "Request");
    1129   REQUEST = zStrdup (r_inputs->value);
     1217  if(r_inputs!=NULL)
     1218    REQUEST = zStrdup (r_inputs->value);
    11301219  int reqId=-1;
    11311220  if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){
     
    11341223    for(j=0;j<nbSupportedRequests;j++){
    11351224      if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){
    1136         if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(REQUEST))==0){
     1225        if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){
    11371226          checkValidValue(request_inputs,&err,"identifier",NULL,1);
    11381227          reqId=j+1;
     
    11411230        else
    11421231          if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob &&
    1143              strncasecmp(REQUEST,requests[vid][j+1],strlen(REQUEST))==0){
     1232             strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){
    11441233            checkValidValue(request_inputs,&err,"jobid",NULL,1);
    11451234            reqId=j+1;
     
    12171306  registry* zooRegistry=NULL;
    12181307  if(reg!=NULL){
    1219     int saved_stdout = dup (fileno (stdout));
    1220     dup2 (fileno (stderr), fileno (stdout));
     1308#ifndef WIN32
     1309    int saved_stdout = zDup (fileno (stdout));
     1310    zDup2 (fileno (stderr), fileno (stdout));
     1311#endif
    12211312    if(createRegistry (m,&zooRegistry,reg->value)<0){
    12221313      map *message=getMapFromMaps(m,"lenv","message");
    12231314      map *type=getMapFromMaps(m,"lenv","type");
    1224       dup2 (saved_stdout, fileno (stdout));
     1315#ifndef WIN32
     1316      zDup2 (saved_stdout, fileno (stdout));
     1317#endif
    12251318      errorException (m, message->value,
    12261319                      type->value, NULL);
    12271320      return 0;
    12281321    }
    1229     dup2 (saved_stdout, fileno (stdout));
    1230     close(saved_stdout);
     1322#ifndef WIN32
     1323    zDup2 (saved_stdout, fileno (stdout));
     1324    zClose(saved_stdout);
     1325#endif
    12311326  }
    12321327
     
    12421337       * has been found in the zcfg and then printed on stdout
    12431338       */
    1244       int saved_stdout = dup (fileno (stdout));
    1245       dup2 (fileno (stderr), fileno (stdout));
     1339      int saved_stdout = zDup (fileno (stdout));
     1340      zDup2 (fileno (stderr), fileno (stdout));
    12461341
    12471342      maps* imports = getMaps(m, IMPORTSERVICE);
     
    12581353            }
    12591354            inheritance(zooRegistry, &svc);
    1260             printGetCapabilitiesForProcess(zooRegistry, m, n, svc);
     1355            printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc);
    12611356            freeService(&svc);
    12621357            free(svc);                             
     
    12671362
    12681363      if (int res =               
    1269           recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
     1364          recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0,
    12701365                          printGetCapabilitiesForProcess) < 0)
    12711366        {
     
    12821377        }
    12831378      fflush (stdout);
    1284       dup2 (saved_stdout, fileno (stdout));
    1285       printDocument (m, doc, getpid ());
     1379      zDup2 (saved_stdout, fileno (stdout));
     1380#ifdef META_DB
     1381      fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1);
     1382      close_sql(m,0);
     1383#endif     
     1384      printDocument (m, doc, zGetpid ());
    12861385      freeMaps (&m);
    12871386      free (m);
     
    12991398      r_inputs = getMap (request_inputs, "JobId");
    13001399      if(reqId>nbReqIdentifier){
    1301         if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 ||
    1302             strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){
     1400        if (strncasecmp (REQUEST, "GetStatus", 9) == 0 ||
     1401            strncasecmp (REQUEST, "GetResult", 9) == 0){
    13031402          runGetStatus(m,r_inputs->value,REQUEST);
     1403#ifdef RELY_ON_DB
     1404          map* dsNb=getMapFromMaps(m,"lenv","ds_nb");
     1405          if(dsNb!=NULL && atoi(dsNb->value)>1)
     1406            close_sql(m,1);
     1407          close_sql(m,0);
     1408#endif
     1409         
    13041410          freeMaps (&m);
    1305           free (m);
     1411          free(m);
    13061412          if(zooRegistry!=NULL){
    13071413            freeRegistry(&zooRegistry);
     
    13551461            r_inputs = NULL;
    13561462            r_inputs = getMap (request_inputs, "version");
     1463#ifdef DEBUG
     1464            fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
     1465            fflush(stderr);
     1466#endif
    13571467            xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
    13581468                                          root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1);
     
    13621472            char *orig = zStrdup (r_inputs->value);
    13631473
    1364             int saved_stdout = dup (fileno (stdout));
    1365             dup2 (fileno (stderr), fileno (stdout));
     1474            int saved_stdout = zDup (fileno (stdout));
     1475            zDup2 (fileno (stderr), fileno (stdout));
    13661476            if (strcasecmp ("all", orig) == 0)
    13671477              {
     
    13791489                      }
    13801490                      inheritance(zooRegistry, &svc);
    1381                       printDescribeProcessForProcess(zooRegistry, m, n, svc);
     1491#ifdef USE_HPC
     1492                      addNestedOutputs(&svc);
     1493#endif
     1494
     1495                      printDescribeProcessForProcess(zooRegistry, m, doc, n, svc);
    13821496                      freeService(&svc);
    13831497                      free(svc);                             
     
    13881502 
    13891503                if (int res =
    1390                     recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
     1504                    recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0,
    13911505                                    printDescribeProcessForProcess) < 0)
    13921506                  return res;
     1507#ifdef META_DB
     1508                fetchServicesFromDb(zooRegistry,m,doc,n,printDescribeProcessForProcess,0);
     1509                close_sql(m,0);
     1510#endif     
     1511
    13931512              }
    13941513            else
     
    14061525                    if (import != NULL && import->value != NULL)
    14071526                      {
    1408                         s1 = (service *) malloc (SERVICE_SIZE);
    1409                         t = readServiceFile (m, import->value, &s1, import->name);
     1527#ifdef META_DB                 
     1528                        service* s2=extractServiceFromDb(m,import->name,0);
     1529                        if(s2==NULL){
     1530#endif
     1531                          s1 = createService();
     1532                          t = readServiceFile (m, import->value, &s1, import->name);
    14101533               
    1411                         if (t < 0) // failure reading zcfg
    1412                           {
    1413                             map *tmp00 = getMapFromMaps (m, "lenv", "message");
    1414                             char tmp01[1024];
    1415                             if (tmp00 != NULL)
    1416                               sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value);
    1417                             else
    1418                               sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value);
    1419 
    1420                             dup2 (saved_stdout, fileno (stdout));
    1421                             errorException (m, tmp01, "InternalError", NULL);
    1422            
    1423                             freeMaps (&m);
    1424                             free (m);
    1425 
    1426                             if(zooRegistry!=NULL){
    1427                               freeRegistry(&zooRegistry);
    1428                               free(zooRegistry);
     1534                          if (t < 0) // failure reading zcfg
     1535                            {
     1536                              map *tmp00 = getMapFromMaps (m, "lenv", "message");
     1537                              char tmp01[1024];
     1538                              if (tmp00 != NULL)
     1539                                sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value);
     1540                              else
     1541                                sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value);
     1542                             
     1543                              zDup2 (saved_stdout, fileno (stdout));
     1544                              errorException (m, tmp01, "InternalError", NULL);
     1545                             
     1546                              freeMaps (&m);
     1547                              free (m);
     1548
     1549                              if(zooRegistry!=NULL){
     1550                                freeRegistry(&zooRegistry);
     1551                                free(zooRegistry);
     1552                              }
     1553                              free (orig);
     1554                              free (REQUEST);
     1555                              closedir (dirp);
     1556                              //xmlFreeDoc (doc);
     1557                              xmlCleanupParser ();
     1558                              zooXmlCleanupNs ();
     1559                   
     1560                              return 1;
    14291561                            }
    1430                             free (orig);
    1431                             free (REQUEST);
    1432                             closedir (dirp);
    1433                             xmlFreeDoc (doc);
    1434                             xmlCleanupParser ();
    1435                             zooXmlCleanupNs ();
    1436                    
    1437                             return 1;
    1438                           }
    1439 #ifdef DEBUG
    1440                         dumpService (s1);
    1441 #endif
    1442 
    1443                         inheritance(zooRegistry,&s1);
    1444                         printDescribeProcessForProcess (zooRegistry,m, n, s1);
    1445                         freeService (&s1);
    1446                         free (s1);
    1447                         s1 = NULL;
    1448                         scount++;
    1449                         hasVal = 1;               
    1450                     }
     1562#ifdef DEBUG
     1563                          dumpService (s1);
     1564#endif
     1565                          inheritance(zooRegistry,&s1);
     1566#ifdef USE_HPC
     1567                          addNestedOutputs(&s1);
     1568#endif
     1569                          printDescribeProcessForProcess (zooRegistry, m, doc, n, s1);
     1570                          freeService (&s1);
     1571                          free (s1);
     1572                          s1 = NULL;
     1573                          scount++;
     1574                          hasVal = 1;               
     1575#ifdef META_DB
     1576                        }
     1577#endif
     1578                      }
    14511579                    else if (strstr (corig, ".") != NULL)
    14521580                      {
     
    14571585                          addToMap (request_inputs, "metapath", tmpMap->value);
    14581586                        map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
    1459 
    1460                         s1 = (service *) malloc (SERVICE_SIZE);
     1587                        /**
     1588                         * No support for dot in service name stored in metadb!?
     1589                         #ifdef META_DB
     1590                         service* s2=extractServiceFromDb(m,tmpMapI->value,0);
     1591                         if(s2==NULL){
     1592                         #endif
     1593                        */
     1594                        s1 = createService();
    14611595                        t = readServiceFile (m, buff1, &s1, tmpMapI->value);
    14621596                        if (t < 0)
     
    14741608                                       ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
    14751609                                       tmps);
    1476                             dup2 (saved_stdout, fileno (stdout));
     1610                            zDup2 (saved_stdout, fileno (stdout));
    14771611                            errorException (m, tmp01, "InvalidParameterValue",
    14781612                                            "identifier");
     
    14891623                            free (s1);
    14901624                            closedir (dirp);
    1491                             xmlFreeDoc (doc);
     1625                            //xmlFreeDoc (doc);
    14921626                            xmlCleanupParser ();
    14931627                            zooXmlCleanupNs ();
     
    14981632#endif
    14991633                        inheritance(zooRegistry,&s1);
    1500                         printDescribeProcessForProcess (zooRegistry,m, n, s1);
     1634#ifdef USE_HPC
     1635                        addNestedOutputs(&s1);
     1636#endif
     1637                        printDescribeProcessForProcess (zooRegistry, m, doc, n, s1);
    15011638                        freeService (&s1);
    15021639                        free (s1);
     
    15081645                    else
    15091646                      {
    1510                         memset (buff, 0, 256);
    1511                         snprintf (buff, 256, "%s.zcfg", corig);
    1512                         memset (buff1, 0, 1024);
    1513 #ifdef DEBUG
    1514                         printf ("\n#######%s\n########\n", buff);
    1515 #endif
    1516                         while ((dp = readdir (dirp)) != NULL)
    1517                           {
    1518                             if (strcasecmp (dp->d_name, buff) == 0)
    1519                               {
    1520                                 memset (buff1, 0, 1024);
    1521                                 snprintf (buff1, 1024, "%s/%s", conf_dir,
    1522                                           dp->d_name);
    1523                                 s1 = (service *) malloc (SERVICE_SIZE);
    1524                                 if (s1 == NULL)
    1525                                   {
    1526                                     dup2 (saved_stdout, fileno (stdout));
    1527                                     return errorException (m,
    1528                                                            _
    1529                                                            ("Unable to allocate memory"),
    1530                                                            "InternalError",
    1531                                                            NULL);
    1532                                   }
     1647#ifdef META_DB
     1648                        _init_sql(m,"metadb");
     1649                        //FAILED CONNECTING DB
     1650                        if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){
     1651                          fprintf(stderr,"ERROR CONNECTING METADB");
     1652                        }
     1653                        service* s2=extractServiceFromDb(m,corig,0);
     1654                        if(s2!=NULL){
     1655                          inheritance(zooRegistry,&s2);
     1656#ifdef USE_HPC
     1657                          addNestedOutputs(&s2);
     1658#endif
     1659                          printDescribeProcessForProcess (zooRegistry,m, doc, n, s2);
     1660                          freeService (&s2);
     1661                          free (s2);
     1662                          s2 = NULL;
     1663                          hasVal = 1;
     1664                        }else /*TOTO*/{
     1665#endif
     1666                          memset (buff, 0, 256);
     1667                          snprintf (buff, 256, "%s.zcfg", corig);
     1668                          memset (buff1, 0, 1024);
     1669#ifdef DEBUG
     1670                          printf ("\n#######%s\n########\n", buff);
     1671#endif
     1672                          while ((dp = readdir (dirp)) != NULL)
     1673                            {
     1674                              if (strcasecmp (dp->d_name, buff) == 0)
     1675                                {
     1676                                  memset (buff1, 0, 1024);
     1677                                  snprintf (buff1, 1024, "%s/%s", conf_dir,
     1678                                            dp->d_name);
     1679                                  s1 = createService();
     1680                                  if (s1 == NULL)
     1681                                    {
     1682                                      zDup2 (saved_stdout, fileno (stdout));
     1683                                      return errorException (m,
     1684                                                             _
     1685                                                             ("Unable to allocate memory"),
     1686                                                             "InternalError",
     1687                                                             NULL);
     1688                                    }
    15331689#ifdef DEBUG_SERVICE_CONF
    1534                                 fprintf
    1535                                   (stderr,"#################\n(%s) %s\n#################\n",
    1536                                    r_inputs->value, buff1);
    1537 #endif
    1538                                 char *tmp0 = zStrdup (dp->d_name);
    1539                                 tmp0[strlen (tmp0) - 5] = 0;
    1540                                 t = readServiceFile (m, buff1, &s1, tmp0);
    1541                                 free (tmp0);
    1542                                 if (t < 0)
    1543                                   {
    1544                                     map *tmp00 =
    1545                                       getMapFromMaps (m, "lenv", "message");
    1546                                     char tmp01[1024];
    1547                                     if (tmp00 != NULL)
    1548                                       sprintf (tmp01,
    1549                                                _
    1550                                                ("Unable to parse the ZCFG file: %s (%s)"),
    1551                                                dp->d_name, tmp00->value);
    1552                                     else
    1553                                       sprintf (tmp01,
    1554                                                _
    1555                                                ("Unable to parse the ZCFG file: %s."),
    1556                                                dp->d_name);
    1557                                     dup2 (saved_stdout, fileno (stdout));
    1558                                     errorException (m, tmp01, "InternalError",
    1559                                                     NULL);
    1560                                     freeMaps (&m);
    1561                                     free (m);
    1562                                     if(zooRegistry!=NULL){
    1563                                       freeRegistry(&zooRegistry);
    1564                                       free(zooRegistry);
     1690                                  fprintf
     1691                                    (stderr,"#################\n(%s) %s\n#################\n",
     1692                                     r_inputs->value, buff1);
     1693#endif
     1694                                  char *tmp0 = zStrdup (dp->d_name);
     1695                                  tmp0[strlen (tmp0) - 5] = 0;
     1696                                  t = readServiceFile (m, buff1, &s1, tmp0);
     1697                                  free (tmp0);
     1698                                  if (t < 0)
     1699                                    {
     1700                                      map *tmp00 =
     1701                                        getMapFromMaps (m, "lenv", "message");
     1702                                      char tmp01[1024];
     1703                                      if (tmp00 != NULL)
     1704                                        sprintf (tmp01,
     1705                                                 _
     1706                                                 ("Unable to parse the ZCFG file: %s (%s)"),
     1707                                                 dp->d_name, tmp00->value);
     1708                                      else
     1709                                        sprintf (tmp01,
     1710                                                 _
     1711                                                 ("Unable to parse the ZCFG file: %s."),
     1712                                                 dp->d_name);
     1713                                      zDup2 (saved_stdout, fileno (stdout));
     1714                                      errorException (m, tmp01, "InternalError",
     1715                                                      NULL);
     1716                                      freeMaps (&m);
     1717                                      free (m);
     1718                                      if(zooRegistry!=NULL){
     1719                                        freeRegistry(&zooRegistry);
     1720                                        free(zooRegistry);
     1721                                      }
     1722                                      free (orig);
     1723                                      free (REQUEST);
     1724                                      closedir (dirp);
     1725                                      //xmlFreeDoc (doc);
     1726                                      xmlCleanupParser ();
     1727                                      zooXmlCleanupNs ();
     1728                                      return 1;
    15651729                                    }
    1566                                     free (orig);
    1567                                     free (REQUEST);
    1568                                     closedir (dirp);
    1569                                     xmlFreeDoc (doc);
    1570                                     xmlCleanupParser ();
    1571                                     zooXmlCleanupNs ();
    1572                                     return 1;
    1573                                   }
    1574 #ifdef DEBUG
    1575                                 dumpService (s1);
    1576 #endif
    1577                                 inheritance(zooRegistry,&s1);
    1578                                 printDescribeProcessForProcess (zooRegistry,m, n, s1);
    1579                                 freeService (&s1);
    1580                                 free (s1);
    1581                                 s1 = NULL;
    1582                                 scount++;
    1583                                 hasVal = 1;
    1584                               }
    1585                           }
    1586                       }
     1730#ifdef DEBUG
     1731                                  dumpService (s1);
     1732#endif
     1733                                  inheritance(zooRegistry,&s1);
     1734#ifdef USE_HPC
     1735                                  addNestedOutputs(&s1);
     1736#endif
     1737                                  /*json_object* jobj=serviceToJson(s1);
     1738                                  const char* jsonStr=json_object_to_json_string_ext(jobj,JSON_C_TO_STRING_PLAIN);
     1739                                  fprintf(stderr,"*** %s %d %s \n",__FILE__,__LINE__,jsonStr);*/
     1740
     1741                                  printDescribeProcessForProcess (zooRegistry,m, doc, n, s1);
     1742                                  freeService (&s1);
     1743                                  free (s1);
     1744                                  s1 = NULL;
     1745                                  scount++;
     1746                                  hasVal = 1;
     1747                                }
     1748                            }
     1749#ifdef META_DB
     1750                        }
     1751#endif
     1752                      }               
    15871753                    if (hasVal < 0)
    15881754                      {
     
    15971763                                   _("Unable to parse the ZCFG file: %s."),
    15981764                                   buff);
    1599                         dup2 (saved_stdout, fileno (stdout));
     1765                        zDup2 (saved_stdout, fileno (stdout));
    16001766                        errorException (m, tmp01, "InvalidParameterValue",
    16011767                                        "Identifier");
     
    16091775                        free (REQUEST);
    16101776                        closedir (dirp);
     1777                        if (corig != NULL)
     1778                          free (corig);
    16111779                        xmlFreeDoc (doc);
    16121780                        xmlCleanupParser ();
     
    16181786                    if (corig != NULL)
    16191787                      free (corig);
    1620                   }
     1788                  }               
    16211789              }
    16221790            closedir (dirp);
    16231791            fflush (stdout);
    1624             dup2 (saved_stdout, fileno (stdout));
     1792            zDup2 (saved_stdout, fileno (stdout));
    16251793            free (orig);
    1626             printDocument (m, doc, getpid ());
     1794            printDocument (m, doc, zGetpid ());
    16271795            freeMaps (&m);
    16281796            free (m);
     
    16341802            free (SERVICE_URL);
    16351803            fflush (stdout);
     1804#ifdef META_DB
     1805            close_sql(m,0);
     1806            //end_sql();
     1807#endif
    16361808            return 0;
    16371809          }
     
    16401812            map* version=getMapFromMaps(m,"main","rversion");
    16411813            int vid=getVersionId(version->value);           
    1642                 int len = 0;
    1643                 int j = 0;
     1814            int len = 0;
     1815            int j = 0;
    16441816            for(j=0;j<nbSupportedRequests;j++){
    16451817              if(requests[vid][j]!=NULL)
     
    17121884  }
    17131885  s1 = NULL;
    1714   s1 = (service *) malloc (SERVICE_SIZE);
    1715   if (s1 == NULL)
    1716     {
    1717       freeMaps (&m);
    1718       free (m);
    1719       if(zooRegistry!=NULL){
    1720         freeRegistry(&zooRegistry);
    1721         free(zooRegistry);
    1722       }
    1723       free (REQUEST);
    1724       free (SERVICE_URL);
    1725       return errorException (m, _("Unable to allocate memory"),
    1726                              "InternalError", NULL);
    1727     }
    1728 
     1886 
    17291887  r_inputs = getMap (request_inputs, "Identifier");
    1730 
    17311888  map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value);
    17321889  if (import != NULL && import->value != NULL) {
    1733       strncpy(tmps1, import->value, 1024);
    1734       setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
    1735       setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
     1890    strncpy(tmps1, import->value, 1024);
     1891    setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
     1892    setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
    17361893  }
    17371894  else {
     
    17571914
    17581915  r_inputs = getMapFromMaps (m, "lenv", "Identifier");
    1759   int saved_stdout = dup (fileno (stdout));
    1760   dup2 (fileno (stderr), fileno (stdout));
    1761   t = readServiceFile (m, tmps1, &s1, r_inputs->value);
    1762   inheritance(zooRegistry,&s1);
    1763   if(zooRegistry!=NULL){
    1764     freeRegistry(&zooRegistry);
    1765     free(zooRegistry);
     1916 
     1917#ifdef META_DB
     1918  int metadb_id=_init_sql(m,"metadb");
     1919  //FAILED CONNECTING DB
     1920  if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){
     1921    fprintf(stderr,"ERROR CONNECTING METADB\n");
    17661922  }
    1767   fflush (stdout);
    1768   dup2 (saved_stdout, fileno (stdout));
    1769   if (t < 0)
    1770     {
    1771       char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value));
    1772       sprintf (tmpMsg,
    1773                _
    1774                ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."),
    1775                r_inputs->value);
    1776       errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
    1777       free (tmpMsg);
    1778       free (s1);
    1779       freeMaps (&m);
    1780       free (m);
    1781       free (REQUEST);
    1782       free (SERVICE_URL);
    1783       return 0;
    1784     }
    1785   close (saved_stdout);
    1786 
     1923  if(metadb_id>=0)
     1924    s1=extractServiceFromDb(m,r_inputs->value,0);
     1925  //close_sql(m,0);
     1926  if(s1!=NULL){
     1927    inheritance(zooRegistry,&s1);
     1928#ifdef USE_HPC
     1929    addNestedOutputs(&s1);
     1930#endif
     1931    if(zooRegistry!=NULL){
     1932      freeRegistry(&zooRegistry);
     1933      free(zooRegistry);
     1934    }
     1935  }else /* Not found in MetaDB */{
     1936#endif
     1937    s1 = createService();
     1938    if (s1 == NULL)
     1939      {
     1940        freeMaps (&m);
     1941        free (m);
     1942        if(zooRegistry!=NULL){
     1943          freeRegistry(&zooRegistry);
     1944          free(zooRegistry);
     1945        }
     1946        free (REQUEST);
     1947        free (SERVICE_URL);
     1948        return errorException (m, _("Unable to allocate memory"),
     1949                               "InternalError", NULL);
     1950      }
     1951
     1952    int saved_stdout = zDup (fileno (stdout));
     1953    zDup2 (fileno (stderr), fileno (stdout));
     1954    t = readServiceFile (m, tmps1, &s1, r_inputs->value);
     1955    if(t>=0){
     1956      inheritance(zooRegistry,&s1);
     1957#ifdef USE_HPC
     1958      addNestedOutputs(&s1);
     1959#endif
     1960    }
     1961    if(zooRegistry!=NULL){
     1962      freeRegistry(&zooRegistry);
     1963      free(zooRegistry);
     1964    }
     1965    fflush (stdout);
     1966    zDup2 (saved_stdout, fileno (stdout));
     1967    if (t < 0)
     1968      {
     1969        char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value));
     1970        sprintf (tmpMsg,
     1971                 _
     1972                 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."),
     1973                 r_inputs->value);
     1974        errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
     1975        free (tmpMsg);
     1976        free (s1);
     1977        freeMaps (&m);
     1978        free (m);
     1979        free (REQUEST);
     1980        free (SERVICE_URL);
     1981        return 0;
     1982      }
     1983    zClose (saved_stdout);
     1984#ifdef META_DB
     1985  }
     1986#endif
     1987 
    17871988#ifdef DEBUG
    17881989  dumpService (s1);
     
    18212022    return 0;
    18222023  }
    1823 
     2024  //InternetCloseHandle (&hInternet);
     2025 
    18242026  // Define each env variable in runing environment
    18252027  maps *curs = getMaps (m, "env");
     
    18622064                     2) * sizeof (char));
    18632065          sprintf (toto, "%s=%s", mapcs->name, mapcs->value);
    1864           putenv (toto);
     2066          _putenv (toto);
    18652067#ifdef DEBUG
    18662068          fflush (stderr);
    18672069#endif
    18682070#endif
     2071
    18692072#ifdef DEBUG
    18702073          fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name,
     
    19592162
    19602163  int eres = SERVICE_STARTED;
    1961   int cpid = getpid ();
    1962 
     2164  int cpid = zGetpid ();
     2165
     2166  // Create a map containing a copy of the request map
     2167  maps *_tmpMaps = createMaps("request");
     2168  addMapToMap(&_tmpMaps->content,request_inputs);
     2169  addMapsToMaps (&m, _tmpMaps);
     2170  freeMaps (&_tmpMaps);
     2171  free (_tmpMaps);
    19632172  /**
    19642173   * Initialize the specific [lenv] section which contains runtime variables:
     
    19812190   *
    19822191   */
    1983   maps *_tmpMaps = createMaps("lenv");
     2192  _tmpMaps = createMaps("lenv");
    19842193  char tmpBuff[100];
    19852194  struct ztimeval tp;
     
    20092218    addToMap (_tmpMaps->content, "soap", "false");
    20102219
    2011   // Parse the session file and add it to the main maps
     2220  // Parse the session file and add it to the main maps
     2221  char* originalCookie=NULL;
    20122222  if (cgiCookie != NULL && strlen (cgiCookie) > 0)
    20132223    {
    20142224      int hasValidCookie = -1;
    2015       char *tcook = zStrdup (cgiCookie);
    2016       char *tmp = NULL;
     2225      char *tcook = originalCookie = zStrdup (cgiCookie);
    20172226      map *testing = getMapFromMaps (m, "main", "cookiePrefix");
    2018       if (testing == NULL)
     2227      parseCookie(&m,originalCookie);
     2228      map *sessId=getMapFromMaps(m,"cookies",(testing==NULL?"ID":testing->value));
     2229      if (sessId!=NULL)
    20192230        {
    2020           tmp = zStrdup ("ID=");
    2021         }
    2022       else
    2023         {
    2024           tmp =
    2025             (char *) malloc ((strlen (testing->value) + 2) * sizeof (char));
    2026           sprintf (tmp, "%s=", testing->value);
    2027         }
    2028       if (strstr (cgiCookie, ";") != NULL)
    2029         {
    2030           char *token, *saveptr;
    2031           token = strtok_r (cgiCookie, ";", &saveptr);
    2032           while (token != NULL)
    2033             {
    2034               if (strcasestr (token, tmp) != NULL)
    2035                 {
    2036                   if (tcook != NULL)
    2037                     free (tcook);
    2038                   tcook = zStrdup (token);
    2039                   hasValidCookie = 1;
    2040                 }
    2041               token = strtok_r (NULL, ";", &saveptr);
    2042             }
    2043         }
    2044       else
    2045         {
    2046           if (strstr (cgiCookie, "=") != NULL
    2047               && strcasestr (cgiCookie, tmp) != NULL)
    2048             {
    2049               tcook = zStrdup (cgiCookie);
    2050               hasValidCookie = 1;
    2051             }
    2052           if (tmp != NULL)
    2053             {
    2054               free (tmp);
    2055             }
    2056         }
    2057       if (hasValidCookie > 0)
    2058         {
    2059           addToMap (_tmpMaps->content, "sessid", strstr (tcook, "=") + 1);
     2231          addToMap (_tmpMaps->content, "sessid", sessId->value);
    20602232          char session_file_path[1024];
    20612233          map *tmpPath = getMapFromMaps (m, "main", "sessPath");
     
    20652237          if (tmp1 != NULL)
    20662238            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
    2067                      strstr (tmp1, "=") + 1);
     2239                     sessId->value);
    20682240          else
    20692241            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
    2070                      strstr (cgiCookie, "=") + 1);
     2242                     sessId->value);
    20712243          free (tcook);
    20722244          maps *tmpSess = (maps *) malloc (MAPS_SIZE);
     
    20762248          if (istat == 0 && file_status.st_size > 0)
    20772249            {
     2250              int saved_stdout = zDup (fileno (stdout));
     2251              zDup2 (fileno (stderr), fileno (stdout));
    20782252              conf_read (session_file_path, tmpSess);
    20792253              addMapsToMaps (&m, tmpSess);
    20802254              freeMaps (&tmpSess);
     2255              fflush(stdout);
     2256              zDup2 (saved_stdout, fileno (stdout));
     2257              zClose(saved_stdout);
    20812258            }
    20822259          free (tmpSess);
     
    20912268#endif
    20922269  int ei = 1;
    2093   char *s =
     2270 
    20942271#ifdef WIN32
    2095     GetEnvironmentStrings();
     2272  LPVOID orig = GetEnvironmentStrings();
     2273  LPTSTR s = (LPTSTR) orig;
    20962274#else
    2097     *environ;
    2098 #endif
     2275  char **orig = environ;
     2276  char *s=*orig;
     2277#endif
     2278
    20992279  _tmpMaps = createMaps("renv");
    2100   for (; s; ei++) {
    2101     char* tmpName=zStrdup(s);
    2102     char* tmpValue=strstr(s,"=")+1;
    2103     tmpName[strlen(tmpName)-strlen(tmpValue)-1]=0;
    2104     if(_tmpMaps->content == NULL)
    2105       _tmpMaps->content = createMap (tmpName,tmpValue);
    2106     else
    2107       addToMap (_tmpMaps->content,tmpName,tmpValue);
    2108     free(tmpName);
    2109     s = *(environ+ei);
     2280if(orig!=NULL)
     2281  for (;
     2282#ifdef WIN32
     2283       *s;
     2284       s++
     2285#else
     2286       s;
     2287       ei++
     2288#endif
     2289       ) {
     2290    if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){
     2291      int len=strlen(s);
     2292      char* tmpName=zStrdup(s);
     2293      char* tmpValue=strstr(s,"=")+1;
     2294      char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char));
     2295      snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName);
     2296      if(_tmpMaps->content == NULL)
     2297        _tmpMaps->content = createMap (tmpName1,tmpValue);
     2298      else
     2299        addToMap (_tmpMaps->content,tmpName1,tmpValue);
     2300      free(tmpName1);
     2301      free(tmpName);
     2302    }
     2303#ifndef WIN32
     2304    s = *(orig+ei);
     2305#endif
     2306  }
     2307  if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){
     2308    addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]);
    21102309  }
    21112310  addMapsToMaps (&m, _tmpMaps);
    21122311  freeMaps (&_tmpMaps);
    21132312  free (_tmpMaps);
    2114 
     2313#ifdef WIN32
     2314  FreeEnvironmentStrings((LPCH)orig);
     2315#endif
     2316  if(postRequest!=NULL)
     2317    setMapInMaps (m, "renv", "xrequest", postRequest->value);
     2318  //dumpMaps(m);
    21152319#ifdef WIN32
    21162320  char *cgiSidL = NULL;
     
    21602364        return -1;
    21612365      }
     2366      map* testMap=getMapFromMaps(m,"main","memory");
     2367      if(testMap==NULL || strcasecmp(testMap->value,"load")!=0)
     2368        dumpMapsValuesToFiles(&m,&request_input_real_format);
    21622369      loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
    2163                          &request_output_real_format, &eres);
     2370                         &request_output_real_format, &eres);     
     2371
     2372#ifdef META_DB
     2373      close_sql(m,0);     
     2374#endif     
    21642375    }
    21652376  else
     
    21692380      fprintf (stderr, "\nPID : %d\n", cpid);
    21702381#endif
    2171 
    21722382#ifndef WIN32
    21732383      pid = fork ();
     
    21752385      if (cgiSid == NULL)
    21762386        {
    2177           createProcess (m, request_inputs, s1, NULL, cpid,
    2178                         request_input_real_format,
    2179                         request_output_real_format);
    2180           pid = cpid;
     2387          createProcess (m, request_inputs, s1, NULL, cpid,
     2388                        request_input_real_format,
     2389                        request_output_real_format);
     2390          pid = cpid;
    21812391        }
    21822392      else
    21832393        {
    2184           pid = 0;
    2185           cpid = atoi (cgiSid);
     2394          pid = 0;
     2395          cpid = atoi (cgiSid);
    21862396          updateStatus(m,0,_("Initializing"));
    21872397        }
    21882398#endif
    21892399      if (pid > 0)
    2190         {
    2191           /**
    2192            * dady :
    2193            * set status to SERVICE_ACCEPTED
    2194            */
    2195 #ifdef DEBUG
    2196           fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
    2197                    getpid ());
    2198 #endif
    2199           eres = SERVICE_ACCEPTED;
    2200         }
     2400        {
     2401          //
     2402          // dady :
     2403          // set status to SERVICE_ACCEPTED
     2404          //
     2405#ifdef DEBUG
     2406          fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
     2407                   zGetpid ());
     2408#endif
     2409          eres = SERVICE_ACCEPTED;
     2410        }
    22012411      else if (pid == 0)
    2202         {
    2203           /**
    2204            * son : have to close the stdout, stdin and stderr to let the parent
    2205            * process answer to http client.
    2206            */
     2412        {
     2413          eres = SERVICE_ACCEPTED;
     2414          //
     2415          // son : have to close the stdout, stdin and stderr to let the parent
     2416          // process answer to http client.
     2417          //
    22072418          map* usid = getMapFromMaps (m, "lenv", "uusid");
    2208           map* tmpm = getMapFromMaps (m, "lenv", "osid");
    2209           int cpid = atoi (tmpm->value);
    2210           r_inputs = getMapFromMaps (m, "main", "tmpPath");
     2419          map* tmpm = getMapFromMaps (m, "lenv", "osid");
     2420          int cpid = atoi (tmpm->value);
     2421          pid=cpid;
     2422          r_inputs = getMapFromMaps (m, "main", "tmpPath");
     2423          setMapInMaps (m, "lenv", "async","true");
    22112424          map* r_inputs1 = createMap("ServiceName", s1->name);
    22122425
    22132426          // Create the filename for the result file (.res)
    2214           fbkpres =
    2215             (char *)
    2216             malloc ((strlen (r_inputs->value) +
    2217                      strlen (usid->value) + 7) * sizeof (char));                   
    2218           sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value);
     2427          fbkpres =
     2428            (char *)
     2429            malloc ((strlen (r_inputs->value) +
     2430                     strlen (usid->value) + 7) * sizeof (char));                   
     2431          sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value);
    22192432          bmap = createMaps("status");
    22202433          bmap->content=createMap("usid",usid->value);
    22212434          addToMap(bmap->content,"sid",tmpm->value);
    2222           addIntToMap(bmap->content,"pid",getpid());
    2223                  
     2435          addIntToMap(bmap->content,"pid",zGetpid());
     2436         
    22242437          // Create PID file referencing the OS process identifier
    2225           fbkpid =
    2226             (char *)
    2227             malloc ((strlen (r_inputs->value) +
    2228                      strlen (usid->value) + 7) * sizeof (char));
    2229           sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value);
     2438          fbkpid =
     2439            (char *)
     2440            malloc ((strlen (r_inputs->value) +
     2441                     strlen (usid->value) + 7) * sizeof (char));
     2442          sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value);
    22302443          setMapInMaps (m, "lenv", "file.pid", fbkpid);
    22312444
    2232           f0 = freopen (fbkpid, "w+",stdout);
    2233           printf("%d",getpid());
     2445          f0 = freopen (fbkpid, "w+",stdout);
     2446          printf("%d",zGetpid());
    22342447          fflush(stdout);
    22352448
    22362449          // Create SID file referencing the semaphore name
    2237           fbkp =
    2238             (char *)
    2239             malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
    2240                      strlen (usid->value) + 7) * sizeof (char));
    2241           sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value);
     2450          fbkp =
     2451            (char *)
     2452            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
     2453                     strlen (usid->value) + 7) * sizeof (char));
     2454          sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value);
    22422455          setMapInMaps (m, "lenv", "file.sid", fbkp);
    2243           FILE* f2 = freopen (fbkp, "w+",stdout);
     2456          FILE* f2 = freopen (fbkp, "w+",stdout);
    22442457          printf("%s",tmpm->value);
    22452458          fflush(f2);
    22462459          free(fbkp);
    22472460
    2248           fbkp =
    2249             (char *)
    2250             malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
    2251                      strlen (usid->value) + 7) * sizeof (char));
    2252           sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value,
    2253                    usid->value);
     2461          fbkp =
     2462            (char *)
     2463            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
     2464                     strlen (usid->value) + 7) * sizeof (char));
     2465          sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value,
     2466                   usid->value);
    22542467          setMapInMaps (m, "lenv", "file.responseInit", fbkp);
    2255           flog =
    2256             (char *)
    2257             malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
    2258                      strlen (usid->value) + 13) * sizeof (char));
    2259           sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
    2260                    r_inputs1->value, usid->value);
     2468          flog =
     2469            (char *)
     2470            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
     2471                     strlen (usid->value) + 13) * sizeof (char));
     2472          sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
     2473                   r_inputs1->value, usid->value);
    22612474          setMapInMaps (m, "lenv", "file.log", flog);
    22622475#ifdef DEBUG
    2263           fprintf (stderr, "RUN IN BACKGROUND MODE \n");
    2264           fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
    2265                    getpid ());
    2266           fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
    2267 #endif
    2268           freopen (flog, "w+", stderr);
    2269           fflush (stderr);
     2476          fprintf (stderr, "RUN IN BACKGROUND MODE \n");
     2477          fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
     2478                   zGetpid ());
     2479          fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
     2480#endif
     2481          freopen (flog, "w+", stderr);
     2482          fflush (stderr);
    22702483          f0 = freopen (fbkp, "w+", stdout);
    22712484          rewind (stdout);
     
    22772490          recordServiceStatus(m);
    22782491#endif
     2492#ifdef USE_CALLBACK
     2493          invokeCallback(m,NULL,NULL,0,0);
     2494#endif
    22792495          if(vid==0){
    2280             /**
    2281              * set status to SERVICE_STARTED and flush stdout to ensure full
    2282              * content was outputed (the file used to store the ResponseDocument).
    2283              * The rewind stdout to restart writing from the bgining of the file,
    2284              * this way the data will be updated at the end of the process run.
    2285              */
     2496            //
     2497            // set status to SERVICE_STARTED and flush stdout to ensure full
     2498            // content was outputed (the file used to store the ResponseDocument).
     2499            // Then, rewind stdout to restart writing from the begining of the file.
     2500            // This way, the data will be updated at the end of the process run.
     2501            //
    22862502            printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
    22872503                                  SERVICE_STARTED, request_input_real_format,
     
    22932509          }
    22942510
    2295           fflush (stderr);
    2296 
    2297           fbkp1 =
    2298             (char *)
    2299             malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
    2300                      strlen (usid->value) + 13) * sizeof (char));
    2301           sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value,
    2302                    r_inputs1->value, usid->value);
     2511          fflush (stderr);
     2512
     2513          fbkp1 =
     2514            (char *)
     2515            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
     2516                     strlen (usid->value) + 13) * sizeof (char));
     2517          sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value,
     2518                   r_inputs1->value, usid->value);
    23032519          setMapInMaps (m, "lenv", "file.responseFinal", fbkp1);
    23042520
    2305           f1 = freopen (fbkp1, "w+", stdout);
    2306 
     2521          f1 = freopen (fbkp1, "w+", stdout);
     2522
     2523          map* serviceTypeMap=getMap(s1->content,"serviceType");
     2524          if(serviceTypeMap!=NULL)
     2525            setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value);
     2526
     2527          char *flenv =
     2528            (char *)
     2529            malloc ((strlen (r_inputs->value) +
     2530                     strlen (usid->value) + 12) * sizeof (char));
     2531          sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value);
     2532          maps* lenvMaps=getMaps(m,"lenv");
     2533          dumpMapsToFile(lenvMaps,flenv,0);
     2534          free(flenv);
     2535
     2536#ifdef USE_CALLBACK
     2537          invokeCallback(m,request_input_real_format,NULL,1,0);
     2538#endif
    23072539          if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
    23082540            freeService (&s1);
    23092541            free (s1);
     2542            fflush (stdout);
     2543            fflush (stderr);
    23102544            fclose (f0);
    23112545            fclose (f1);
    23122546            if(dumpBackFinalFile(m,fbkp,fbkp1)<0)
    23132547              return -1;
    2314             unlink (fbkpid);           
     2548#ifndef RELY_ON_DB
     2549            dumpMapsToFile(bmap,fbkpres,1);
     2550            removeShmLock (m, 1);
     2551#else
     2552            recordResponse(m,fbkp1);
     2553#ifdef USE_CALLBACK
     2554            invokeCallback(m,NULL,NULL,7,0);
     2555#endif
     2556#endif
     2557            zUnlink (fbkpid);
    23152558            unhandleStatus (m);
     2559#ifdef RELY_ON_DB
     2560#ifdef META_DB
     2561            cleanupCallbackThreads();
     2562            close_sql(m,1);
     2563#endif
     2564            close_sql(m,0);
     2565#endif
    23162566            freeMaps (&m);
    23172567            free (m);
     
    23242574            freeMaps (&tmpmaps);
    23252575            free (tmpmaps);
    2326             fflush (stdout);
    2327             fflush (stderr);
    23282576            return -1;
    23292577          }
    2330           loadServiceAndRun (&m, s1, request_inputs,
    2331                              &request_input_real_format,
    2332                              &request_output_real_format, &eres);
    2333         }
     2578          if(getMapFromMaps(m,"lenv","mapError")!=NULL){
     2579            setMapInMaps(m,"lenv","message",_("Issue with geographic data"));
     2580#ifdef USE_CALLBACK
     2581            invokeCallback(m,NULL,NULL,7,0);
     2582#endif
     2583            eres=-1;//SERVICE_FAILED;
     2584          }else{
     2585            map* testMap=getMapFromMaps(m,"main","memory");
     2586            if(testMap==NULL || strcasecmp(testMap->value,"load")!=0)
     2587              dumpMapsValuesToFiles(&m,&request_input_real_format);
     2588            loadServiceAndRun (&m, s1, request_inputs,
     2589                               &request_input_real_format,
     2590                               &request_output_real_format, &eres);
     2591          }
     2592        }
    23342593      else
    23352594        {
     
    23382597           * error response here !!!
    23392598           */
    2340           eres = -1;
    2341           errorException (m, _("Unable to run the child process properly"),
    2342                           "InternalError", NULL);
     2599          eres = -1;
     2600          errorException (m, _("Unable to run the child process properly"),
     2601                          "InternalError", NULL);
    23432602        }
    23442603    }
    2345 
    2346 #ifdef DEBUG
     2604       
     2605#ifdef DEBUG
     2606  fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
    23472607  dumpMaps (request_output_real_format);
    2348 #endif
    2349 
     2608  fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
     2609#endif
     2610  fflush(stdout);
     2611  rewind(stdout);
     2612
     2613  //fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,eres); 
    23502614  if (eres != -1)
    23512615    outputResponse (s1, request_input_real_format,
     
    23532617                    cpid, m, eres);
    23542618  fflush (stdout);
    2355 
     2619 
    23562620  /**
    23572621   * Ensure that if error occurs when freeing memory, no signal will return
     
    23672631  signal (SIGABRT, donothing);
    23682632#endif
    2369   if (((int) getpid ()) != cpid || cgiSid != NULL)
    2370     {     
     2633
     2634  if (((int) zGetpid ()) != cpid || cgiSid != NULL)
     2635    {
     2636      if (eres == SERVICE_SUCCEEDED)
     2637#ifdef USE_CALLBACK
     2638        invokeCallback(m,NULL,request_output_real_format,5,1);
     2639#endif
     2640      fflush(stderr);
     2641      fflush(stdout);
     2642
    23712643      fclose (stdout);
    2372       fclose (stderr);
    23732644
    23742645      fclose (f0);
    23752646      fclose (f1);
    2376          
    2377           if (dumpBackFinalFile(m, fbkp, fbkp1) < 0)
    2378                   return -1;
    2379        
    2380       unlink (fbkpid);   
     2647
     2648      if(dumpBackFinalFile(m,fbkp,fbkp1)<0)
     2649        return -1;
     2650      zUnlink (fbkpid);
    23812651      switch(eres){
    23822652      default:
     
    23902660        break;
    23912661      }     
    2392 #ifndef RELY_ON_DB       
     2662#ifndef RELY_ON_DB
    23932663      dumpMapsToFile(bmap,fbkpres,1);
    23942664      removeShmLock (m, 1);
    23952665#else
    23962666      recordResponse(m,fbkp1);
     2667      if (eres == SERVICE_SUCCEEDED)
     2668#ifdef USE_CALLBACK
     2669        invokeCallback(m,NULL,request_output_real_format,6,0);
     2670#endif
    23972671#endif
    23982672      freeMaps(&bmap);
    23992673      free(bmap);
    2400       unlink (fbkp1);
    2401       unlink (flog);
     2674      zUnlink (fbkp1);
    24022675      unhandleStatus (m);
     2676#ifdef RELY_ON_DB
     2677#ifdef META_DB
     2678      cleanupCallbackThreads();
     2679      close_sql(m,1);
     2680#endif
     2681      close_sql(m,0);
     2682      end_sql();
     2683#endif
    24032684      free(fbkpid);
    24042685      free(fbkpres);
    2405       free (flog);           
    24062686      free (fbkp1);
    2407       // free (tmps1); // tmps1 is stack memory and should not be freed
    24082687      if(cgiSid!=NULL)
    24092688        free(cgiSid);
    2410     }
    2411 
     2689      //InternetCloseHandle (&hInternet);
     2690      fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
     2691      fflush(stderr);
     2692      fclose (stderr);
     2693      zUnlink (flog);
     2694      free (flog);
     2695    }
     2696  else{
     2697    //InternetCloseHandle (&hInternet); 
     2698#ifdef META_DB
     2699    close_sql(m,0);
     2700#endif
     2701  }
     2702 
    24122703  freeService (&s1);
    24132704  free (s1);
     
    24292720#endif
    24302721
    2431   if (((int) getpid ()) != cpid || cgiSid != NULL)
     2722  if (((int) zGetpid ()) != cpid || cgiSid != NULL)
    24322723    {
    24332724      exit (0);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

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