Changeset 741 for branches


Ignore:
Timestamp:
Oct 7, 2015, 8:41:43 AM (8 years ago)
Author:
david
Message:
 
Location:
branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel
Files:
5 added
17 edited

Legend:

Unmodified
Added
Removed
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/Makefile.in

    r677 r741  
    3838zoo_zcfg.o: zoo_zcfg.c service.h
    3939        g++ ${GLIB_CPPFLAGS} ${XML2CFLAGS} -c zoo_zcfg.c
     40
     41logger.o: logger.c
     42        gcc -c logger.c
     43
     44zoo_json.o: zoo_json.c service.h
     45        g++ ${JSON_CPPFLAGS} ${XML2CFLAGS} -c zoo_json.c
     46
     47zoo_amqp.o: zoo_amqp.c
     48        g++ ${CFLAGS} -c zoo_amqp.c
    4049
    4150request_parser.o: request_parser.c request_parser.h
     
    94103
    95104zoo_service_loader.o: zoo_service_loader.c service.h
    96         g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
     105        g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${JSON_CPPFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
    97106
    98107libzoo_service.${EXT}: version.h service_internal.o service.o sqlapi.o
    99108        gcc -shared  ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS}  service_internal.o service.o sqlapi.o -lfcgi ${GDAL_LIBS}
    100109
    101 zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o  ulinet.o zoo_zcfg.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
    102         g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
    103         g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o zoo_zcfg.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}
     110zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_json.o zoo_amqp.o zoo_loader.c zoo_service_loader.o  ulinet.o zoo_zcfg.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${RABBITMQ_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
     111        g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${JSON_CPPFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
     112        g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${RABBITMQ_FILE}  ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o zoo_json.o zoo_zcfg.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}
     113
     114zoo_fpm: version.h libzoo_service.${EXT} logger.o zoo_json.o zoo_amqp.o zoo_fpm.c zoo_service_loader.o  ulinet.o zoo_zcfg.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${RABBITMQ_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
     115        g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${JSON_CPPFLAGS} ${CFLAGS} -c zoo_fpm.c  -fno-common -DPIC -o zoo_fpm.o
     116        g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} logger.o zoo_fpm.o zoo_service_loader.o ${RABBITMQ_FILE}  ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o zoo_json.o zoo_zcfg.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_fpm -L. ${LDFLAGS}
     117
    104118
    105119zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE}
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/ZOOMakefile.opts.in

    r677 r741  
    5555RUBY_FILE=@RUBY_FILE@
    5656
     57JSON_LDFLAGS=@JSON_LDFLAGS@
     58JSON_CPPFLAGS=@JSON_CPPFLAGS@
     59
     60RABBITMQ_LDFLAGS=@RABBITMQ_LDFLAGS@
     61RABBITMQ_CPPFLAGS=@RABBITMQ_CPPFLAGS@
     62RABBITMQ_FILE=@RABBITMQ_FILE@
     63
    5764JS_ENABLED=@JS_ENABLED@
    5865JSCFLAGS=@JS_CPPFLAGS@
     
    96103SAGA_FILE=@SAGA_FILE@
    97104
    98 CFLAGS=@RELY_ON_DB@ @DEB_DEF@ -fpic ${GLIB_CPPFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
    99 LDFLAGS=-lzoo_service @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${GLIB_LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto -luuid ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS}
     105CFLAGS= @RELY_ON_DB@ @DEB_DEF@ -fpic ${GLIB_CPPFLAGS} ${YAML_CFLAGS} ${GDAL_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} ${RABBITMQ_CPPFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
     106LDFLAGS=-lzoo_service @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${GLIB_LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${JSON_LDFLAGS} ${RABBITMQ_LDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto -luuid ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS}
    100107
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/caching.c

    r642 r741  
    215215            fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char));
    216216            if(fcontent == NULL){
    217               return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
     217              return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL,NULL);
    218218            }
    219219            size_t dwRead;
     
    233233            tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
    234234            if(tmpMap->value==NULL){
    235               return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
     235              return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL,NULL);
    236236            }
    237237            memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
     
    277277void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){
    278278  hInternet->waitingRequests[hInternet->nb]=strdup(url);
    279   hInternet->ihandle[hInternet->nb].header=NULL;
     279  //hInternet->ihandle[hInternet->nb].header=NULL;
    280280  if(req)
    281281    InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
     
    304304 */
    305305int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){
    306   char* fcontent;
     306  char* fcontent = NULL;
    307307  char* cached=isInCache(*m,url);
    308308  char *mimeType=NULL;
     
    338338    }
    339339
    340   }else{   
     340  }else{
    341341    addRequestToQueue(m,hInternet,url,true);
    342342    return 0;
    343343  }
    344344  if(fsize==0){
    345     return errorException(*m, _("Unable to download the file."), "InternalError",NULL);
     345    return errorException(*m, _("Unable to download the file."), "InternalError",NULL,NULL);
    346346  }
    347347  if(mimeType!=NULL){
     
    354354
    355355  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
    356   if(tmpMap->value==NULL)
    357     return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
     356 
     357 if(tmpMap->value==NULL || fcontent == NULL)
     358    return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL,NULL);
    358359  memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
     360
     361 
     362 
     363 
     364  //if(tmpMap->value==NULL)
     365    //return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL,NULL);
     366  //memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
    359367
    360368  char ltmp1[256];
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/configure.ac

    r677 r741  
    5858AC_SUBST([RELY_ON_DB])
    5959
     60
     61AC_ARG_WITH([rabbitmq],
     62    [AS_HELP_STRING([--with-rabbittmq], [asynchronous requests management with rabbitmq  ])],
     63    [AMQP="-DAMQP"], [AMQP=""])
     64
     65if test -z "$AMQP"
     66then
     67    RABBITMQ_LDFLAGS=""
     68    RABBITMQ_CPPFLAGS=""
     69    RABBITMQ_FILE=""
     70else
     71    AC_CHECK_LIB([rabbitmq], [main])
     72    RABBITMQ_LDFLAGS=`pkg-config --libs librabbitmq`
     73    RABBITMQ_CPPFLAGS="-DAMQP" `pkg-config --cflags librabbitmq`
     74    RABBITMQ_FILE="zoo_amqp.o"
     75    RELY_ON_DB="-DRELY_ON_DB"
     76    AC_SUBST([RELY_ON_DB])
     77fi
     78AC_SUBST([RABBITMQ_LDFLAGS])
     79AC_SUBST([RABBITMQ_CPPFLAGS])
     80AC_SUBST([RABBITMQ_FILE])
    6081
    6182# ===========================================================================
     
    418439        LIBS_SAVE="$LIBS"
    419440        LIBS="$PYTHON_LDFLAGS"
    420         PY_LIB=`$PYTHONCONFIG --libs | sed -e 's/^.*\(python2\..\)$/\1/'`
    421         AC_CHECK_LIB([$PY_LIB], [PyObject_CallObject], [], [AC_MSG_ERROR([could not find libpython])], [])
     441        #PY_LIB=`$PYTHONCONFIG --libs | sed -e 's/^.*\(python2\..\)$/\1/'`
     442        #PY_LIB=`$PYTHONCONFIG --libs`
     443        #AC_CHECK_LIB([$PY_LIB], [PyObject_CallObject], [], [AC_MSG_ERROR([could not find libpython])], [])
    422444        AC_SUBST([PYTHON_CPPFLAGS])
    423445        AC_SUBST([PYTHON_LDFLAGS])
     
    598620AC_SUBST([JAVA_FILE])
    599621
     622
     623# ===========================================================================
     624# Detect if json-c is available
     625# ===========================================================================
     626
     627AC_CHECK_LIB([json-c], [main])
     628JSON_LDFLAGS=`pkg-config --libs json-c`
     629JSON_CPPFLAGS=`pkg-config --cflags json-c`
     630
     631AC_SUBST([JSON_LDFLAGS])
     632AC_SUBST([JSON_CPPFLAGS])
     633
     634
    600635# ===========================================================================
    601636# Detect if ruby is installed
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/request_parser.c

    r654 r741  
    9292                       _("The maximum allowed occurrences for <%s> (%i) was exceeded."),
    9393                       mi->name, atoi (testMap->value));
    94               errorException (m, emsg, "InternalError", NULL);
     94              errorException (m, emsg, "InternalError", NULL,NULL);
    9595              return -1;
    9696            }
     
    113113                           ("ZOO-Kernel was unable to load your data for %s position %s."),
    114114                           mi->name, tmpMap->value);
    115                   errorException (m, emsg, "InternalError", NULL);
     115                  errorException (m, emsg, "InternalError", NULL,NULL);
    116116                  return -1;
    117117                }
     
    124124                       ("The maximum allowed occurrences for <%s> is one."),
    125125                       mi->name);
    126               errorException (m, emsg, "InternalError", NULL);
     126              errorException (m, emsg, "InternalError", NULL,NULL);
    127127              return -1;
    128128            }
     
    213213        free(cursor_input);
    214214        return errorException (*main_conf, _("Unable to allocate memory."),
    215                                "InternalError", NULL);
     215                               "InternalError", NULL,NULL);
    216216      }
    217217    int i = 0;
     
    224224            free(cursor_input);
    225225            return errorException (*main_conf, _("Unable to allocate memory."),
    226                                    "InternalError", NULL);
     226                                   "InternalError", NULL,NULL);
    227227          }
    228228        snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken);
     
    261261                    return errorException (*main_conf,
    262262                                           _("Unable to allocate memory."),
    263                                            "InternalError", NULL);
     263                                           "InternalError", NULL,NULL);
    264264                  }
    265265                tmpmaps->name = zStrdup (tmpn);
     
    316316                                 tmpv1 + 1);
    317317                        free(cursor_input);
    318                         return errorException (*main_conf, emsg, "InternalError", NULL);
     318                        return errorException (*main_conf, emsg, "InternalError", NULL,NULL);
    319319                      }
    320320                    addToMap (tmpmaps->content, tmpn1, tmpx2);
    321                     {
    322321                      if (loadRemoteFile
    323322                          (&*main_conf, &tmpmaps->content, hInternet, tmpx2) < 0)
    324323                        {
    325324                          free(cursor_input);
    326                           return errorException (*main_conf, "Unable to fetch any ressource", "InternalError", NULL);
     325                          return errorException (*main_conf, "Unable to fetch any ressource", "InternalError", NULL,NULL);
    327326                        }
    328                       }
     327                     
    329328                    free (tmpx2);
    330329                    addIntToMap (tmpmaps->content, "Order", hInternet->nb);
     
    350349                          {
    351350                            free(cursor_input);
    352                             return errorException (*main_conf, "Unable to append maps", "InternalError", NULL);
     351                            return errorException (*main_conf, "Unable to append maps", "InternalError", NULL,NULL);
    353352                          }
    354353                      }
     
    402401          free(cursor_output);
    403402          return errorException (*main_conf, _("Unable to allocate memory"),
    404                                  "InternalError", NULL);
     403                                 "InternalError", NULL,NULL);
    405404        }
    406405      int i = 0;
     
    413412              free(cursor_output);
    414413              return errorException (*main_conf, _("Unable to allocate memory"),
    415                                      "InternalError", NULL);
     414                                     "InternalError", NULL,NULL);
    416415            }
    417416          snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s",
     
    440439                                                 _
    441440                                                 ("Unable to allocate memory."),
    442                                                  "InternalError", NULL);
     441                                                 "InternalError", NULL,NULL);
    443442                        }
    444443                      tmp_output->name = zStrdup (tmpc);
     
    536535                                                 _
    537536                                                 ("Unable to allocate memory."),
    538                                                  "InternalError", NULL);
     537                                                 "InternalError", NULL,NULL);
    539538                        }
    540539                      tmpmaps->name = zStrdup ((char *) val);
     
    561560                                                 _
    562561                                                 ("Unable to allocate memory."),
    563                                                  "InternalError", NULL);
     562                                                 "InternalError", NULL,NULL);
    564563                        }
    565564                      tmpmaps->name = zStrdup ("missingIndetifier");
     
    613612                                                             _("Unable to add a request in the queue."),
    614613                                                             "InternalError",
    615                                                              NULL);
     614                                                             NULL,NULL);
    616615                                    }
    617616                                  addIntToMap (tmpmaps->content, "Order", hInternet->nb);
     
    665664                                                             ("Unable to allocate memory."),
    666665                                                             "InternalError",
    667                                                              NULL);
     666                                                             NULL,NULL);
    668667                                    }
    669668                                  snprintf (has,
     
    675674                              xmlFree (val);
    676675                            }
    677                           hInternet->ihandle[hInternet->nb].header = NULL;
    678                           hInternet->ihandle[hInternet->nb].header =
    679                             curl_slist_append (hInternet->ihandle
    680                                                [hInternet->nb].header,
    681                                                has);
    682                           if (has != NULL)
    683                             free (has);
     676                if (has != NULL){
     677                            hInternet->ihandle[hInternet->nb].header = NULL;
     678                            hInternet->ihandle[hInternet->nb].header =
     679                              curl_slist_append (hInternet->ihandle
     680                                                 [hInternet->nb].header,
     681                                                 has);
     682                            free (has);
     683                }
    684684                        }
    685685                      else
     
    781781                                                           ("Unable to allocate memory."),
    782782                                                           "InternalError",
    783                                                            NULL);
     783                                                           NULL,NULL);
    784784                                  }
    785785                                size_t bRead;
     
    951951                                  xmlDocDumpFormatMemoryEnc (doc1, &mv,
    952952                                                             &buffersize,
    953                                                              "utf-8", 1);
     953                                                             "utf-8", 0);
    954954                                  char size[1024];
    955955                                  sprintf (size, "%d", buffersize);
     
    966966                                    xmlDocDumpFormatMemoryEnc (doc1, &mv,
    967967                                                               &buffersize,
    968                                                                "utf-8", 1);
    969                                     char size[1024];
    970                                     sprintf (size, "%d", buffersize);
    971                                     addToMap (tmpmaps->content, "size",
    972                                               size);
    973                                     xmlFreeDoc (doc2);
     968                                                               "utf-8", 0);
     969                                    addIntToMap(tmpmaps->content, "size",buffersize);
     970                    xmlFreeDoc (doc2);
    974971                                    xmlFreeDoc (doc1);
    975972                                  }
     
    10241021                                               _("Unable to append maps to maps."),
    10251022                                               "InternalError",
    1026                                                NULL);
     1023                                               NULL,NULL);
    10271024                      }
    10281025                  }
     
    11131110            {
    11141111              return errorException (*main_conf, _("Unable to allocate memory."),
    1115                                      "InternalError", NULL);
     1112                                     "InternalError", NULL,NULL);
    11161113            }
    11171114          tmpmaps->name = zStrdup ("unknownIdentifier");
     
    12051202                                     _
    12061203                                     ("Unable to allocate memory."),
    1207                                      "InternalError", NULL);
     1204                                     "InternalError", NULL,NULL);
    12081205            }
    12091206            tmpmaps->name = zStrdup ("unknownIdentifier");
     
    12921289                                     _
    12931290                                     ("Duplicate <Output> elements in WPS Execute request"),
    1294                                      "InternalError", NULL);
     1291                                     "InternalError", NULL,NULL);
    12951292            }
    12961293            else {
     
    13201317 * @return 0 on success, -1 on failure
    13211318 */
    1322 int xmlParseRequest(maps** main_conf,const char* post,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet){
     1319int xmlParseRequest(maps** main_conf,const char* post,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet,struct cgi_env *cgi){
    13231320
    13241321  map* version=getMapFromMaps(*main_conf,"main","rversion");
     
    13261323
    13271324  xmlInitParser ();
    1328   xmlDocPtr doc = xmlParseMemory (post, cgiContentLength);
     1325  xmlDocPtr doc = xmlParseMemory (post, cgi->cgiContentLength);
    13291326
    13301327  /**
     
    14281425 * @see kvpParseOutputs,kvpParseInputs,xmlParseRequest
    14291426 */
    1430 int parseRequest(maps** main_conf,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet){
     1427int parseRequest(maps** main_conf,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet,struct cgi_env *cgi){
    14311428  map *postRequest = NULL;
    14321429  postRequest = getMap (*request_inputs, "xrequest");
     
    14431440    {
    14441441      //Parse XML request
    1445       if(xmlParseRequest(main_conf,postRequest->value,request_inputs,s,inputs,outputs,hInternet)<0){
     1442      if(xmlParseRequest(main_conf,postRequest->value,request_inputs,s,inputs,outputs,hInternet,cgi)<0){
    14461443        return -1;
    14471444      }
     
    14651462 * @see runHttpRequests
    14661463 */
    1467 int validateRequest(maps** main_conf,service* s,map* original_request, maps** request_inputs,maps** request_outputs,HINTERNET* hInternet){
    1468 
     1464int validateRequest(maps** main_conf,service* s,map* original_request, maps** request_inputs,maps** request_outputs,HINTERNET* hInternet,struct cgi_env * cgi){
     1465  fprintf(stderr,"STEP 1 VALIDATE \n");
     1466 
    14691467  runHttpRequests (main_conf, request_inputs, hInternet);
     1468fprintf(stderr,"STEP 2 VALIDATE \n");
     1469 
    14701470  InternetCloseHandle (hInternet);
    1471 
     1471  fprintf(stderr,"STEP 3 VALIDATE \n");
     1472               
    14721473  map* errI=NULL;
    14731474  char *dfv = addDefaultValues (request_inputs, s->inputs, *main_conf, 0,&errI);
     
    14911492              addToMap (tmpe, "locator", ptr->name);
    14921493              addToMap (tmpe, "text", tmps);
    1493               printExceptionReportResponse (*main_conf, tmpe);
     1494              printExceptionReportResponse (*main_conf, tmpe,NULL);
    14941495              freeMap (&tmpe);
    14951496              free (tmpe);
     
    14991500      ptr = ptr->next;
    15001501    }
    1501 
     1502fprintf(stderr,"STEP 4 VALIDATE \n");
     1503  dumpMaps(*request_outputs);
    15021504  map* errO=NULL;
    15031505  char *dfv1 =
    15041506    addDefaultValues (request_outputs, s->outputs, *main_conf, 1,&errO);
     1507    fprintf(stderr,"STEP 4 - 1 VALIDATE \n");
     1508 
    15051509  if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0)
    15061510    {
     
    15261530          }
    15271531        }
     1532    fprintf(stderr,"STEP 4 - 2 VALIDATE \n");
     1533 
    15281534      if (strcmp (dfv1, "") != 0)
    15291535        {
     
    15531559          }
    15541560        }
    1555       printExceptionReportResponse (*main_conf, tmpe);
     1561    fprintf(stderr,"STEP 4 - 3 VALIDATE \n");
     1562 
     1563      printExceptionReportResponse (*main_conf, tmpe,NULL);
    15561564      if(errI!=NULL){
    15571565        freeMap(&errI);
     
    15671575    }
    15681576  maps *tmpReqI = *request_inputs;
     1577  fprintf(stderr,"STEP 5 VALIDATE \n");
     1578 
    15691579  while (tmpReqI != NULL)
    15701580    {
     
    15721582      if (getMap (tmpReqI->content, "isFile") != NULL)
    15731583        {
    1574           if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) ==
     1584          if (cgiFormFileName (tmpReqI->name, name, sizeof (name),&cgi) ==
    15751585              cgiFormSuccess)
    15761586            {
     
    15861596              int got, t;
    15871597              map *path = getMapFromMaps (*main_conf, "main", "tmpPath");
    1588               cgiFormFileSize (tmpReqI->name, &size);
     1598              cgiFormFileSize (tmpReqI->name, &size,&cgi);
    15891599              cgiFormFileContentType (tmpReqI->name, contentType,
    1590                                       sizeof (contentType));
    1591               if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess)
     1600                                      sizeof (contentType),&cgi);
     1601              if (cgiFormFileOpen (tmpReqI->name, &file,&cgi) == cgiFormSuccess)
    15921602                {
    15931603                  t = -1;
     
    16431653      tmpReqI = tmpReqI->next;
    16441654    }
    1645 
     1655fprintf(stderr,"STEP FINAL VALIDATE \n");
     1656 
    16461657  ensureDecodedBase64 (request_inputs);
    16471658  return 1;
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/request_parser.h

    r677 r741  
    4444  int xmlParseInputs(maps**,service*,maps**,xmlDocPtr,xmlNodeSet*,HINTERNET*);
    4545  int xmlParseOutputs(maps**,map**,maps**,xmlDocPtr,xmlNodePtr,bool);
    46   int xmlParseRequest(maps**,const char*,map**,service*,maps**,maps**,HINTERNET*);
    47   int parseRequest(maps**,map**,service*,maps**,maps**,HINTERNET*);
     46  int xmlParseRequest(maps**,const char*,map**,service*,maps**,maps**,HINTERNET*,struct cgi_env *);
     47  int parseRequest(maps**,map**,service*,maps**,maps**,HINTERNET*,struct cgi_env *);
    4848  void checkValidValue(map*,map**,const char*,const char**,int);
    49   int validateRequest(maps**,service*,map*,maps**,maps**,HINTERNET*);
     49  int validateRequest(maps**,service*,map*,maps**,maps**,HINTERNET*,struct cgi_env *);
    5050
    5151#ifdef __cplusplus
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.c

    r677 r741  
    9393 * @param m the map containing the headers informations
    9494 */
    95 void printHeaders(maps* m){
     95void printHeaders(maps* m,FCGX_Stream *out){
    9696  maps *_tmp=getMaps(m,"headers");
    9797  if(_tmp!=NULL){
    9898    map* _tmp1=_tmp->content;
    9999    while(_tmp1!=NULL){
    100       printf("%s: %s\r\n",_tmp1->name,_tmp1->value);
     100      FCGX_FPrintF(out,"%s: %s\r\n", _tmp1->name, _tmp1->value);
    101101      _tmp1=_tmp1->next;
    102102    }
     
    14451445 * @param outputs the outputs generated by the service
    14461446 */
    1447 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
     1447void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs,FCGX_Stream * out){
    14481448  xmlNsPtr ns,ns_ows,ns_xlink;
    14491449  xmlNodePtr nr,n,nc,nc1=NULL,nc3;
     
    15401540      hasStoredExecuteResponse=true;
    15411541    }
    1542 
    15431542    nc = xmlNewNode(ns, BAD_CAST "Process");
    15441543    map* tmp2=getMap(serv->content,"processVersion");
     
    15481547    map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
    15491548    printDescription(nc,ns_ows,tmpI->value,serv->content,0);
    1550 
    15511549    xmlAddChild(n,nc);
    15521550
     
    16951693    if(lid<0){
    16961694      /* If the lock failed */
    1697       errorException(m,_("Lock failed."),"InternalError",NULL);
     1695      errorException(m,_("Lock failed."),"InternalError",NULL,out);
    16981696      xmlFreeDoc(doc);
    16991697      xmlCleanupParser();
     
    17101708        sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path);
    17111709
    1712         errorException(m,tmpMsg,"InternalError",NULL);
     1710        errorException(m,tmpMsg,"InternalError",NULL,out);
    17131711        xmlFreeDoc(doc);
    17141712        xmlCleanupParser();
     
    17381736#endif
    17391737  }
    1740   printDocument(m,doc,pid);
     1738  printDocument(m,doc,pid,out);
    17411739
    17421740  xmlCleanupParser();
     
    17511749 * @param pid the process identifier linked to a service
    17521750 */
    1753 void printDocument(maps* m, xmlDocPtr doc,int pid){
     1751void printDocument(maps* m, xmlDocPtr doc,int pid,FCGX_Stream * out){
    17541752  char *encoding=getEncoding(m);
    17551753  if(pid==getpid()){
    1756     printHeaders(m);
    1757     printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
    1758   }
    1759   fflush(stdout);
     1754    printHeaders(m,out);
     1755    FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
     1756  }
    17601757  xmlChar *xmlbuff;
    17611758  int buffersize;
     
    17651762   */
    17661763  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    1767   printf("%s",xmlbuff);
    1768   fflush(stdout);
     1764  if (out != NULL){
     1765    FCGX_FPrintF(out,(char *)xmlbuff);
     1766    FCGX_FFlush(out);
     1767  }
    17691768  /*
    17701769   * Free associated memory.
     
    20992098 * @param s the map containing the text,code,locator keys
    21002099 */
    2101 void printExceptionReportResponse(maps* m,map* s){
     2100void printExceptionReportResponse(maps* m,map* s,FCGX_Stream * out){
    21022101  if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
    21032102    return;
     
    21352134    if(tmpSid!=NULL){
    21362135      if( getpid()==atoi(tmpSid->value) ){
    2137         printHeaders(m);
    2138         printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
    2139       }
     2136        printHeaders(m,out);
     2137    FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
     2138          }
    21402139    }
    21412140    else{
    2142       printHeaders(m);
    2143       printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
     2141      printHeaders(m,out);
     2142      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
    21442143    }
    21452144  }else{
    2146     printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
    2147   }
     2145    FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
     2146    }
    21482147  n=createExceptionReportNode(m,s,1);
    21492148  xmlDocSetRootElement(doc, n);
    21502149  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    2151   printf("%s",xmlbuff);
    2152   fflush(stdout);
     2150  FCGX_FPrintF(out,"%s",xmlbuff);
     2151  FCGX_FFlush(out);
     2152
    21532153  xmlFreeDoc(doc);
    21542154  xmlFree(xmlbuff);
     
    21612161/**
    21622162 * Create an OWS ExceptionReport Node.
    2163  *
     2163 * FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
    21642164 * @param m the conf maps
    21652165 * @param s the map containing the text,code,locator keys
     
    22412241 * @param locator the potential locator
    22422242 */
    2243 int errorException(maps *m, const char *message, const char *errorcode, const char *locator)
     2243int errorException(maps *m, const char *message, const char *errorcode, const char *locator,FCGX_Stream * out)
    22442244{
    22452245  map* errormap = createMap("text", message);
     
    22492249  else
    22502250    addToMap(errormap,"locator", "NULL");
    2251   printExceptionReportResponse(m,errormap);
     2251  printExceptionReportResponse(m,errormap,out);
    22522252  freeMap(&errormap);
    22532253  free(errormap);
     
    22672267 */
    22682268void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
    2269                     map* request_inputs1,int cpid,maps* m,int res){
     2269                    map* request_inputs1,int cpid,maps* m,int res,FCGX_Stream * out){
    22702270#ifdef DEBUG
    22712271  dumpMaps(request_inputs);
     
    22782278    asRaw=1;
    22792279  map* version=getMapFromMaps(m,"main","rversion");
    2280   int vid=getVersionId(version->value);
    2281  
    2282   maps* tmpSess=getMaps(m,"senv");
     2280   int vid=getVersionId(version->value);
     2281   maps* tmpSess=getMaps(m,"senv");
    22832282  if(tmpSess!=NULL){
    22842283    map *_tmp=getMapFromMaps(m,"lenv","cookie");
    22852284    char* sessId=NULL;
    22862285    if(_tmp!=NULL){
    2287       printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
    2288       printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
     2286      FCGX_FPrintF(out,"Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
     2287      FCGX_FPrintF(out,"P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
    22892288      char session_file_path[100];
    22902289      char *tmp1=strtok(_tmp->value,";");
     
    23142313      char tmpMsg[1024];
    23152314      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
    2316       errorException(m,tmpMsg,"InternalError",NULL);
     2315      errorException(m,tmpMsg,"InternalError",NULL,out);
    23172316
    23182317      return;
     
    23232322    }
    23242323  }
    2325  
    23262324  if(res==SERVICE_FAILED){
    23272325    map *lenv;
     
    23362334      sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service."));
    23372335    }
    2338     errorException(m,tmp0,"InternalError",NULL);
     2336    errorException(m,tmp0,"InternalError",NULL,out);
    23392337    free(tmp0);
    23402338    return;
    23412339  }
    2342 
    23432340  if(res==SERVICE_ACCEPTED && vid==1){
    23442341    map* statusInfo=createMap("Status","Accepted");
    23452342    map *usid=getMapFromMaps(m,"lenv","usid");
    23462343    addToMap(statusInfo,"JobID",usid->value);
    2347     printStatusInfo(m,statusInfo,"Execute");
     2344    printStatusInfo(m,statusInfo,"Execute",out);
    23482345    freeMap(&statusInfo);
    23492346    free(statusInfo);
    23502347    return;
    23512348  }
    2352 
    23532349  map *tmp1=getMapFromMaps(m,"main","tmpPath");
    23542350  if(asRaw==0){
     
    24112407              getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
    24122408            }
    2413                
    24142409            file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
    24152410            sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
     
    24222417              char tmpMsg[1024];
    24232418              sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
    2424               errorException(m,tmpMsg,"InternalError",NULL);
     2419              errorException(m,tmpMsg,"InternalError",NULL,out);
    24252420              free(file_name);
    24262421              free(file_path);
     
    24282423            }
    24292424            free(file_path);
    2430 
    24312425            toto=getMap(tmpI->content,"value");
    24322426            if(strcasecmp(format,"BoundingBoxData")!=0){
     
    24382432                  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
    24392433            }else{
    2440               printBoundingBoxDocument(m,tmpI,ofile);
     2434              printBoundingBoxDocument(m,tmpI,ofile,out);
    24412435            }
    24422436            fclose(ofile);
    24432437
    24442438          }
    2445           map *tmp2=getMapFromMaps(m,"main","tmpUrl");
     2439      map *tmp2=getMapFromMaps(m,"main","tmpUrl");
    24462440          map *tmp3=getMapFromMaps(m,"main","serverAddress");
    24472441          char *file_url;
     
    24732467    dumpMaps(m);
    24742468#endif
     2469
    24752470    printProcessResponse(m,request_inputs1,cpid,
    24762471                         s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
    24772472                         request_inputs,
    2478                          request_outputs);
     2473                         request_outputs,out);
     2474
    24792475  }
    24802476  else{
     
    24922488    elements* e=getElements(s->outputs,tmpI->name);
    24932489    if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
    2494       printBoundingBoxDocument(m,tmpI,NULL);
     2490      printBoundingBoxDocument(m,tmpI,NULL,out);
    24952491    }else{
    24962492      map *gfile=getMap(tmpI->content,"generated_file");
     
    25062502        char tmpMsg[1024];
    25072503        sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name);
    2508         errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
     2504        errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput",out);
    25092505        return;
    25102506      }
    25112507      map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
    25122508      if(fname!=NULL)
    2513         printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
     2509      FCGX_FPrintF(out,"Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
    25142510      map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
    25152511      if(rs!=NULL)
    2516         printf("Content-Length: %s\r\n",rs->value);
    2517       printHeaders(m);
     2512      FCGX_FPrintF(out,"Content-Length: %s\r\n",rs->value);
     2513      printHeaders(m,out);
    25182514      char mime[1024];
    25192515      map* mi=getMap(tmpI->content,"mimeType");
     
    25242520#endif
    25252521      map* en=getMap(tmpI->content,"encoding");
    2526       if(mi!=NULL && en!=NULL)
    2527         sprintf(mime,
    2528                 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
    2529                 mi->value,en->value);
    2530       else
    2531         if(mi!=NULL)
    2532           sprintf(mime,
    2533                   "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
    2534                   mi->value);
    2535         else
    2536           sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
    2537       printf("%s",mime);
    2538       if(rs!=NULL)
    2539         fwrite(toto->value,1,atoi(rs->value),stdout);
    2540       else
    2541         fwrite(toto->value,1,strlen(toto->value),stdout);
     2522      if(mi!=NULL && en!=NULL){
     2523        sprintf(mime,"Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",mi->value,en->value);
     2524      }
     2525      else {
     2526        if(mi!=NULL)
     2527            sprintf(mime,"Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",mi->value);
     2528        else
     2529            sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
     2530      }
     2531      FCGX_FPrintF(out,"%s",mime);
     2532      if(rs!=NULL){
     2533        FCGX_PutStr(toto->value,atoi(rs->value),out);
     2534      }
     2535      else {
     2536        FCGX_PutStr(toto->value,strlen (toto->value),out);
     2537      }
     2538    FCGX_FFlush(out);
    25422539#ifdef DEBUG
    25432540      dumpMap(toto);
     
    26592656 * @see parseBoundingBox, printBoundingBox
    26602657 */
    2661 void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){
    2662   if(file==NULL)
    2663     rewind(stdout);
     2658void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file,FCGX_Stream * out){
    26642659  xmlNodePtr n;
    26652660  xmlDocPtr doc;
     
    26752670      pid=atoi(tmp->value);
    26762671    if(pid==getpid()){
    2677       printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
    2678     }
    2679     fflush(stdout);
     2672     
     2673      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
     2674    }
     2675    FCGX_FFlush(out);
    26802676  }
    26812677
     
    26952691  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    26962692  if(file==NULL)
    2697     printf("%s",xmlbuff);
     2693   FCGX_FPrintF(out,"%s",xmlbuff);
    26982694  else{
    26992695    fprintf(file,"%s",xmlbuff);
     
    27232719 * @param req the WPS requests (GetResult, GetStatus or Dismiss)
    27242720 */
    2725 void printStatusInfo(maps* conf,map* statusInfo,char* req){
    2726   rewind(stdout);
     2721void printStatusInfo(maps* conf,map* statusInfo,char* req,FCGX_Stream * out){
     2722  //rewind(stdout);
    27272723  xmlNodePtr n,n1;
    27282724  xmlDocPtr doc;
     
    27332729  map *tmp;
    27342730  int pid=0;
    2735   printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
     2731 
     2732  FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
    27362733
    27372734  map* version=getMapFromMaps(conf,"main","rversion");
    27382735  int vid=getVersionId(version->value);
    2739 
    27402736  doc = xmlNewDoc(BAD_CAST "1.0");
    27412737  n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1);
     
    27722768
    27732769  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    2774   printf("%s",xmlbuff);
    2775 
     2770  FCGX_FPrintF(out,"%s",xmlbuff);
    27762771  xmlFree(xmlbuff);
    27772772  xmlFreeDoc(doc);
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.h

    r677 r741  
    2525#ifndef ZOO_RESPONSE_PRINT_H
    2626#define ZOO_RESPONSE_PRINT_H 1
     27
     28#include <fcgiapp.h>
    2729
    2830#pragma once
     
    6971#include <direct.h>
    7072#endif
    71 #include <stdio.h>
     73
    7274#include <time.h>
    7375#include <ctype.h>
     
    201203  void zooXmlCleanupDocs();
    202204 
    203   void printExceptionReportResponse(maps*,map*);
     205  void printExceptionReportResponse(maps*,map*,FCGX_Stream *);
    204206  xmlNodePtr createExceptionReportNode(maps*,map*,int);
    205   void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*);
     207  void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*,FCGX_Stream *);
    206208  xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*,const char*,int);
    207209  xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*,const char*);
     
    209211  void printDescribeProcessForProcess(maps*,xmlNodePtr,service*);
    210212  void printFullDescription(int,elements*,const char*,xmlNsPtr,xmlNsPtr,xmlNodePtr,int);
    211   void printDocument(maps*,xmlDocPtr,int);
     213  void printDocument(maps*,xmlDocPtr,int,FCGX_Stream *);
    212214  void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int);
    213215  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*,int);
    214216  map* parseBoundingBox(const char*);
    215217  void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
    216   void printBoundingBoxDocument(maps*,maps*,FILE*);
     218  void printBoundingBoxDocument(maps*,maps*,FILE*,FCGX_Stream *);
    217219  void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
    218   void printStatusInfo(maps*,map*,char*);
    219 
    220   void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
    221 
    222   int errorException(maps *, const char *, const char *, const char*);
     220  void printStatusInfo(maps*,map*,char*,FCGX_Stream *);
     221
     222  void outputResponse(service*,maps*,maps*,map*,int,maps*,int,FCGX_Stream *);
     223
     224  int errorException(maps *, const char *, const char *, const char*,FCGX_Stream *);
    223225
    224226  xmlNodePtr soapEnvelope(maps*,xmlNodePtr);
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/server_internal.c

    r657 r741  
    850850 * @param req the request (GetStatus / GetResult)
    851851 */
    852 void runGetStatus(maps* conf,char* pid,char* req){
     852void runGetStatus(maps* conf,char* pid,char* req,FCGX_Stream* out){
    853853  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
    854854  char *sid=getStatusId(conf,pid);
    855855  if(sid==NULL){
    856856    errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"),
    857                     "NoSuchJob", pid);
     857                    "NoSuchJob", pid,out);
    858858  }else{
    859859    map* statusInfo=createMap("JobID",pid);
     
    861861      if(strncasecmp(req,"GetResult",strlen(req))==0){
    862862        errorException (conf, _("The result for the requested JobID has not yet been generated. "),
    863                         "ResultNotReady", pid);
     863                        "ResultNotReady", pid,out);
    864864        return;
    865865      }
     
    885885        if(result!=NULL){
    886886          char *encoding=getEncoding(conf);
    887           fprintf(stdout,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
    888           fprintf(stdout,"%s",result);
    889           fflush(stdout);
     887      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
     888      FCGX_FPrintF(out,"%s",result);
     889      FCGX_FFlush(out);
    890890          freeMap(&statusInfo);
    891891          free(statusInfo);
     
    893893        }else{
    894894          errorException (conf, _("The result for the requested JobID has not yet been generated. "),
    895                           "ResultNotReady", pid);
     895                          "ResultNotReady", pid,out);
    896896          freeMap(&statusInfo);
    897897          free(statusInfo);
     
    914914        }
    915915    }
    916     printStatusInfo(conf,statusInfo,req);
     916    printStatusInfo(conf,statusInfo,req,out);
    917917    freeMap(&statusInfo);
    918918    free(statusInfo);
     
    927927 * @param pid the service identifier (usid key from the [lenv] section)
    928928 */
    929 void runDismiss(maps* conf,char* pid){
     929void runDismiss(maps* conf,char* pid,FCGX_Stream* out){
    930930  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
    931931  char *sid=getStatusId(conf,pid);
    932932  if(sid==NULL){
    933933    errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"),
    934                     "NoSuchJob", pid);
     934                    "NoSuchJob", pid,out);
    935935  }else{
    936936    // We should send the Dismiss request to the target host if it differs
     
    967967          if(unlink(fileName)!=0){
    968968            errorException (conf, _("The job cannot be removed, a file cannot be removed"),
    969                             "NoApplicableCode", NULL);
     969                            "NoApplicableCode", NULL,out);
    970970            return;
    971971          }
     
    978978    map* statusInfo=createMap("JobID",pid);
    979979    addToMap(statusInfo,"Status","Dismissed");
    980     printStatusInfo(conf,statusInfo,"Dismiss");
     980    printStatusInfo(conf,statusInfo,"Dismiss",out);
    981981    free(statusInfo);
    982982  }
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/server_internal.h

    r654 r741  
    3131#include <openssl/bio.h>
    3232#include <openssl/buffer.h>
    33 
     33#include <fcgiapp.h>
    3434extern   int conf_read(const char*,maps*);
    3535
     
    5252  void parseIdentifier(maps*,char*,char*,char*);
    5353  void dumpMapsValuesToFiles(maps**,maps**);
    54   void runDismiss(maps*,char*);
    55   void runGetStatus(maps*,char*,char*);
     54  void runDismiss(maps*,char*,FCGX_Stream*);
     55  void runGetStatus(maps*,char*,char*,FCGX_Stream*);
    5656
    5757  int isValidLang(maps*,const char*);
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/service_internal.c

    r654 r741  
    2323 */
    2424
    25 #include "fcgi_stdio.h"
    2625#include "service_internal.h"
    2726#ifdef USE_MS
     
    293292
    294293#include <windows.h>
    295 #include <fcgi_stdio.h>
     294//#include <fcgi_stdio.h>
    296295#include <stdio.h>
    297296#include <conio.h>
     
    689688    VSILFILE * fichier=VSIFOpenL(dataSource,"rb");
    690689    VSIStatBuf file_status;
    691     VSIStat(dataSource, &file_status);
     690    VSIStatL(dataSource,&file_status);
     691    //file_status.st_size = 2500;
    692692    if(fichier==NULL){
    693693      char tmp[1024];
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/service_internal.h

    r677 r741  
    2626#define ZOO_SERVICE_INTERNAL_H 1
    2727
     28
     29#include <fcgiapp.h>
     30
    2831#pragma once
    2932
     
    3740#define TIME_SIZE 40
    3841
    39 #include <libintl.h>
     42//#include <libintl.h>
    4043#include <locale.h>
    4144/**
     
    6568#define ZOO_LOCK_MAX_RETRY 10
    6669
    67 #include <sys/stat.h>
    68 #include <sys/types.h>
     70//#include <sys/stat.h>
     71//#include <sys/types.h>
     72
    6973#ifndef WIN32
    7074#include <sys/ipc.h>
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/sqlapi.c

    r654 r741  
    2929
    3030#include "sqlapi.h"
    31 #include <fcgi_stdio.h>
     31//#include <fcgi_stdio.h>
    3232#include <stdlib.h>
    3333
     
    183183    sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s',NULL);",schema->value,uusid->value,filename,type);
    184184  execSql(conf,sqlQuery);
     185  free(sqlQuery);
    185186  cleanUpResultSet(conf);
    186187}
     
    206207          uusid->value,sid->value,osid->value);
    207208  execSql(conf,sqlQuery);
     209  free(sqlQuery);
    208210  cleanUpResultSet(conf);
    209211}
     
    229231  sprintf(sqlQuery,"INSERT INTO %s.responses (content,uuid) VALUES ($$%s$$,$$%s$$);",schema->value,tmps,sid->value);
    230232  execSql(conf,sqlQuery);
     233  free(sqlQuery);
     234  free(tmps);
    231235  cleanUpResultSet(conf);
    232236}
     
    250254  execSql(conf,sqlQuery);
    251255  cleanUpResultSet(conf);
     256  free(sqlQuery);
    252257  return 0;
    253258}
     
    280285  }
    281286  cleanUpResultSet(conf);
     287  free(sqlQuery);
    282288  return (char*)tmp1;
    283289}
     
    316322    tmp1=NULL;
    317323  cleanUpResultSet(conf);
     324  free(sqlQuery);
    318325  return (char*)tmp1;
    319326}
     
    338345  cleanUpResultSet(conf);
    339346  close_sql(conf);
     347  free(sqlQuery);
    340348  end_sql();
    341349}
     
    363371  cleanUpResultSet(conf);
    364372  close_sql(conf);
     373  free(sqlQuery);
    365374  end_sql();
    366375}
     
    397406  if(hasRes<0)
    398407    tmp1=NULL;
     408  free(sqlQuery);
    399409  return (char*)tmp1;
    400410}
     
    429439  if(hasRes<0)
    430440    addToMap(statusInfo,"Status","Failed");
     441  free(sqlQuery);
    431442  return;
    432443}
     
    460471  }
    461472  cleanUpResultSet(conf);
     473  free(sqlQuery);
    462474  return res;
    463475}
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/ulinet.h

    r630 r741  
    2626#define _ULINET_H
    2727
    28 #include "fcgi_stdio.h"
     28//#include "fcgi_stdio.h"
    2929#include <stdlib.h>
    3030#include <fcntl.h>
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_loader.c

    r677 r741  
    1 /*
     1/**
    22 * Author : Gérald FENOY
    33 *
     
    3030 */
    3131#ifndef WIN32
     32/*
    3233#include "fcgio.h"
    33 #include "fcgi_config.h"
    34 #include "fcgi_stdio.h"
    35 #endif
     34#include "fcgi_config.h"
     35*/
     36//#include <stdio.h>
     37#include <unistd.h>
     38#include <fcgiapp.h>
     39#endif
     40#include <sys/wait.h>
     41#include <pthread.h>
    3642#include <sys/types.h>
    3743#include <unistd.h>
    3844#include "service_internal.h"
    39 #include "response_print.h"
    40 #include "zoo_zcfg.h"
    41 
    4245#ifdef WIN32
    4346#include "windows.h"
     
    4548#endif
    4649
    47 extern "C" {
     50extern "C"
     51{
    4852#include "cgic.h"
    4953#include <libxml/tree.h>
     
    5256#include <libxml/xpath.h>
    5357#include <libxml/xpathInternals.h>
     58
     59#include <string.h>
     60
     61#include <stdlib.h>
     62#include <glib.h>
     63#include <sys/stat.h>
     64#include <ctype.h>
     65
    5466}
    55 
    56 #include "service_internal.h"
     67#include "response_print.h"
     68#include "zoo_zcfg.h"
     69#include "zoo_json.h"
     70#include "zoo_amqp.h"
     71//#include "zoo_sql.h"
     72#include "server_internal.h"
    5773#include "request_parser.h"
    58 
    59 int runRequest(map**);
     74void
     75loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
     76                   maps ** inputs, maps ** ioutputs, int *eres,FCGX_Stream *out, FCGX_Stream *err);
     77
     78xmlXPathObjectPtr extractFromDoc (xmlDocPtr, const char *);
     79int runRequest (map **,struct cgi_env **,FCGX_Request *);
    6080
    6181using namespace std;
     
    6888#endif
    6989
    70 /**
    71  * Main entry point for cgic.
    72  * @return 0 on sucess.
    73  */
    74 int cgiMain(){
    75   /**
    76    * We'll use cgiOut as the default output (stdout) to produce plain text
    77    * response.
    78    */
    79   dup2(fileno(cgiOut),fileno(stdout));
     90
     91static void PrintEnv(FCGX_Stream *out, char *label, char **envp)
     92{
     93    FCGX_FPrintF(out, "%s:<br>\n<pre>\n", label);
     94    for( ; *envp != NULL; envp++) {
     95        FCGX_FPrintF(out, "%s\n", *envp);
     96    }
     97    FCGX_FPrintF(out, "</pre><p>\n");
     98}
     99
     100#define PATH_SOCKET "/tmp/zoo.sock"
     101#define THREAD_COUNT 50
     102static int counts[THREAD_COUNT];
     103
     104
     105int process(FCGX_Request *request){
     106
     107      int pid = getpid();
     108      struct cgi_env *cgi;
     109      cgi = (struct cgi_env*)malloc(sizeof(struct cgi_env));
     110      cgiMain_init (NULL, NULL,&cgi,request);
     111      char *strQuery = NULL;
     112      if (cgi->cgiQueryString != NULL)
     113        strQuery = zStrdup (cgi->cgiQueryString);
     114      map *tmpMap = NULL;
     115
     116      if (strncmp (cgi->cgiContentType, "text/xml", 8) == 0 ||
     117          strncasecmp (cgi->cgiRequestMethod, "post", 4) == 0)
     118        {
     119          if (cgi->cgiContentLength == 0)
     120            {
     121              char *post_data = NULL;
     122              int i = 0;
     123              int ch = FCGX_GetChar(request->in);
     124              while (ch != -1){
     125                {
     126                  i++;
     127                  if (post_data == NULL)
     128                    {
     129                    post_data=(char*)malloc(sizeof(char));
     130                    post_data[i-1] = (char) ch;
     131                    }
     132                  else
     133                    {
     134                    post_data=(char*)realloc(post_data,i*sizeof(char));
     135                    post_data[i-1] = (char) ch;
     136                    }
     137                  ch = FCGX_GetChar(request->in);
     138                  if (ch == -1 ){
     139                    post_data=(char*)realloc(post_data,(i + 1)*sizeof(char));
     140                    post_data[i] = '\0';
     141                    }
     142                }
     143                cgi->cgiContentLength = i;
     144              if (post_data == NULL && (strQuery == NULL || strlen (strQuery) == 0))
     145                {
     146                  return errorException (NULL,
     147                                         "ZOO-Kernel failed to process your request cause the request was emtpty.",
     148                                         "InternalError", NULL,request->out);
     149                }
     150              else
     151                {
     152                  if (strQuery == NULL || strlen (strQuery) == 0)
     153                    tmpMap = createMap ("request", post_data);
     154                }
     155              if (post_data != NULL)
     156                free (post_data);
     157                }
     158            }
     159          else
     160            {
     161              char *post_data = new char[cgi->cgiContentLength + 1];
     162              int r = FCGX_GetStr(post_data,cgi->cgiContentLength,request->in);
     163              if ( r > 0)
     164                {
     165                  post_data[r] = '\0';
     166                  cgi->cgiContentLength = r;
     167                  tmpMap = createMap ("request", post_data);
     168                }
     169              else
     170                {
     171                  post_data[0] = '\0';
     172                  char **array, **arrayStep;
     173                  if (cgiFormEntries (&array,&cgi) != cgiFormSuccess)
     174                    {
     175                      return 1;
     176                    }
     177                  arrayStep = array;
     178                  while (*arrayStep)
     179                    {
     180                      char *ivalue = new char[cgi->cgiContentLength];
     181                      cgiFormStringNoNewlines (*arrayStep, ivalue,
     182                                               cgi->cgiContentLength,&cgi);
     183                      char *tmpValueFinal =
     184                        (char *)
     185                        malloc ((strlen (*arrayStep) + strlen (ivalue) +
     186                                 1) * sizeof (char));
     187                      sprintf (tmpValueFinal, "%s=%s", *arrayStep, ivalue);
     188                      if (strlen (post_data) == 0)
     189                        {
     190                          sprintf (post_data, "%s", tmpValueFinal);
     191                        }
     192                      else
     193                        {
     194                          char *tmp = zStrdup (post_data);
     195                          sprintf (post_data, "%s&%s", tmp, tmpValueFinal);
     196                          free (tmp);
     197                        }
     198                      free (tmpValueFinal);
    80199#ifdef DEBUG
    81   fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
    82   fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n");
    83   fflush(cgiOut);
    84   fprintf (stderr, "Addr:%s\n", cgiRemoteAddr);
    85   fprintf (stderr, "RequestMethod: (%s) %d %d\n", cgiRequestMethod,strncasecmp(cgiRequestMethod,"post",4),strncmp(cgiContentType,"text/xml",8)==0 || strncasecmp(cgiRequestMethod,"post",4)==0);
    86   fprintf (stderr, "Request: %s\n", cgiQueryString);
    87   fprintf (stderr, "ContentType: %s\n", cgiContentType);
    88   fprintf (stderr, "ContentLength: %d\n", cgiContentLength);
    89   fflush(stderr);
    90 #endif
    91 
    92 
    93   init_services_conf ("/var/www/zoo-wps/cgi-bin","/var/www/zoo-wps/registry/");
    94 
    95 
    96   char *strQuery=NULL;
    97   if(cgiQueryString!=NULL)
    98     strQuery=zStrdup(cgiQueryString);
    99   map* tmpMap=NULL;
    100 
    101   if(strncmp(cgiContentType,"text/xml",8)==0 ||
    102      strncasecmp(cgiRequestMethod,"post",4)==0){
    103     if(cgiContentLength==0){
    104        char *buffer=new char[2];
    105        char *res=NULL;
    106        int r=0;
    107        while((r=fread(buffer,sizeof(char),1,cgiIn))){
    108          buffer[1]=0;
    109          if(res==NULL){
    110            res=(char*)malloc(2*sizeof(char));
    111            sprintf(res,"%s",buffer);
    112          }
    113          else{
    114            res=(char*)realloc(res,(cgiContentLength+2)*sizeof(char));
    115            memcpy(res + cgiContentLength, buffer, sizeof(char));
    116            res[cgiContentLength+1]=0;
    117          }
    118          cgiContentLength+=r;
    119        }
    120        delete[] buffer;
    121        if(res!=NULL && (strQuery==NULL || strlen(strQuery)==0))
    122          tmpMap=createMap("request",res);
    123        if(res!=NULL)
    124          free(res);
    125     }else{
    126       char *buffer=new char[cgiContentLength+1];
    127       if(fread(buffer,sizeof(char),cgiContentLength,cgiIn)>0){
    128         buffer[cgiContentLength]=0;
    129         tmpMap=createMap("request",buffer);
    130       }else{
    131         buffer[0]=0;
    132         char **array, **arrayStep;
    133         if (cgiFormEntries(&array) != cgiFormSuccess) {
    134           return 1;
    135         }
    136         arrayStep = array;
    137         while (*arrayStep) {
    138           char *ivalue=new char[cgiContentLength];
    139           cgiFormStringNoNewlines(*arrayStep, ivalue, cgiContentLength);
    140           char* tmpValueFinal=(char*) malloc((strlen(*arrayStep)+strlen(ivalue)+2)*sizeof(char));       
    141           sprintf(tmpValueFinal,"%s=%s",*arrayStep,ivalue);
    142 
    143           if(strlen(buffer)==0){               
    144             sprintf(buffer,"%s",tmpValueFinal);
    145           }else{               
    146             char *tmp=zStrdup(buffer);
    147             sprintf(buffer,"%s&%s",tmp,tmpValueFinal);
    148             free(tmp);
    149           }       
    150           free(tmpValueFinal);
     200                      fprintf (stderr, "(( \n %s \n %s \n ))", *arrayStep,
     201                               ivalue);
     202#endif
     203                      delete[]ivalue;
     204                      arrayStep++;
     205                    }
     206                  if (tmpMap != NULL)
     207                    addToMap (tmpMap, "request", post_data);
     208                  else
     209                    tmpMap = createMap ("request", post_data);
     210                }
     211              delete[]post_data;
     212            }
     213        }
     214      else
     215        {
    151216#ifdef DEBUG
    152           fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,ivalue);
    153 #endif
    154           delete[]ivalue;
    155           arrayStep++;
    156         }       
    157         if(tmpMap!=NULL)
    158           addToMap(tmpMap,"request",buffer);
    159         else
    160           tmpMap=createMap("request",buffer);
    161       }
    162       delete[]buffer;
    163     }   
    164   }
    165   else{
     217          dumpMap (tmpMap);
     218#endif
     219       
     220       char **array, **arrayStep;
     221          if (cgiFormEntries (&array,&cgi) != cgiFormSuccess)
     222            {
     223              return 1;
     224            }
     225          arrayStep = array;
     226          while (*arrayStep)
     227            {
     228              char *value = new char[cgi->cgiContentLength];
     229              cgiFormStringNoNewlines (*arrayStep, value, cgi->cgiContentLength,&cgi);
    166230#ifdef DEBUG
    167     dumpMap(tmpMap);
    168 #endif
    169     char **array, **arrayStep;
    170     if (cgiFormEntries(&array) != cgiFormSuccess) {
    171       return 1;
    172     }
    173     arrayStep = array;
    174     while (*arrayStep) {
    175       char *value=new char[cgiContentLength];
    176       cgiFormStringNoNewlines(*arrayStep, value, cgiContentLength);
    177 #ifdef DEBUG
    178       fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
    179 #endif
     231              fprintf (stderr, "(( \n %s \n %s \n ))", *arrayStep, value);
     232#endif
     233              if (tmpMap != NULL)
     234                addToMap (tmpMap, *arrayStep, value);
     235              else
     236                tmpMap = createMap (*arrayStep, value);
     237              arrayStep++;
     238              delete[]value;
     239            }
     240          cgiStringArrayFree (array);
     241        }
     242
    180243#ifdef WIN32
    181       char* tmp = url_decode(value);
    182       if(tmpMap!=NULL)         
    183         addToMap(tmpMap,*arrayStep,tmp);
    184       else             
    185         tmpMap=createMap(*arrayStep,tmp);
    186       free(tmp);
    187 #else
    188       if(tmpMap!=NULL)
    189         addToMap(tmpMap,*arrayStep,value);
    190       else
    191         tmpMap=createMap(*arrayStep,value);
    192 #endif 
    193       arrayStep++;
    194       delete[]value;
    195     }
    196     cgiStringArrayFree(array);
    197   }
    198 
    199 #ifdef WIN32
    200   map *tmpReq=getMap(tmpMap,"rfile");
    201   if(tmpReq!=NULL){
    202     FILE *lf=fopen(tmpReq->value,"r");
    203     fseek(lf,0,SEEK_END);
    204     long flen=ftell(lf);
    205     fseek(lf,0,SEEK_SET);
    206     char *buffer=(char*)malloc((flen+1)*sizeof(char));
    207     fread(buffer,flen,1,lf);
    208     fclose(lf);
    209     addToMap(tmpMap,"request",buffer);
    210     free(buffer);
    211     cgiContentLength=flen+9;
    212   }
     244      map *tmpReq = getMap (tmpMap, "rfile");
     245      if (tmpReq != NULL)
     246        {
     247          FILE *lf = fopen (tmpReq->value, "r");
     248          fseek (lf, 0, SEEK_END);
     249          long flen = ftell (lf);
     250          fseek (lf, 0, SEEK_SET);
     251          char *buffer = (char *) malloc ((flen + 1) * sizeof (char));
     252          fread (buffer, flen, 1, lf);
     253          fclose (lf);
     254          addToMap (tmpMap, "request", buffer);
     255          free (buffer);
     256          cgiContentLength = flen + 9;
     257        }
    213258#endif
    214259  /**
     
    217262   * one.
    218263   */
    219   if(strncasecmp(cgiRequestMethod,"post",4)==0 ||
    220      (count(tmpMap)==1 && strncmp(tmpMap->value,"<",1)==0)
     264      if (strncasecmp (cgi->cgiRequestMethod, "post", 4) == 0 ||
     265          (count (tmpMap) == 1 && strncmp (tmpMap->value, "<", 1) == 0)
    221266#ifdef WIN32
    222      ||tmpReq!=NULL
    223 #endif
    224      ){
     267          || tmpReq != NULL
     268#endif
     269        )
     270        {
    225271    /**
    226272     * Store the original XML request in xrequest map
    227273     */
    228     map* t1=getMap(tmpMap,"request");
    229     if(t1!=NULL && strncasecmp(t1->value,"<",1)==0) {
    230       addToMap(tmpMap,"xrequest",t1->value);
    231       xmlInitParser();
    232       xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);
     274          map *t1 = getMap (tmpMap, "request");
     275          if (t1 != NULL && strncasecmp (t1->value, "<", 1) == 0)
     276            {
     277              addToMap (tmpMap, "xrequest", t1->value);
     278              xmlInitParser ();
     279              xmlDocPtr doc = xmlParseMemory (t1->value, cgi->cgiContentLength);
     280              {
     281                xmlXPathObjectPtr reqptr = extractFromDoc (doc,
     282                                                           "/*[local-name()='Envelope']/*[local-name()='Body']/*");
     283                if (reqptr != NULL)
     284                  {
     285                    xmlNodeSet *req = reqptr->nodesetval;
     286                    if (req != NULL && req->nodeNr == 1)
     287                      {
     288                        addToMap (tmpMap, "soap", "true");
     289                        for (int k = 0; k < req->nodeNr; k++)
     290                          {
     291                            //xmlNsPtr ns=xmlNewNs(req->nodeTab[k],BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
     292                            xmlDocSetRootElement (doc, req->nodeTab[k]);
     293                            xmlChar *xmlbuff;
     294                            int buffersize;
     295                            xmlDocDumpFormatMemoryEnc (doc, &xmlbuff,
     296                                                       &buffersize, "utf-8",
     297                                                       1);
     298                            addToMap (tmpMap, "xrequest", (char *) xmlbuff);
     299                            xmlFree (xmlbuff);
     300                          }
     301                      }
     302                    xmlXPathFreeObject (reqptr);
     303                  }
     304              }
     305
     306              xmlNodePtr cur = xmlDocGetRootElement (doc);
     307              char *tval;
     308              tval = NULL;
     309              tval = (char *) xmlGetProp (cur, BAD_CAST "service");
     310              if (tval != NULL)
     311                {
     312                  addToMap (tmpMap, "service", tval);
     313                  xmlFree (tval);
     314                }
     315              tval = NULL;
     316              tval = (char *) xmlGetProp (cur, BAD_CAST "language");
     317              if (tval != NULL)
     318                {
     319                  addToMap (tmpMap, "language", tval);
     320                  xmlFree (tval);
     321                }
     322              const char *requests[3] =
     323                { "GetCapabilities", "DescribeProcess", "Execute" };
     324              for (int j = 0; j < 3; j++)
     325                {
     326                  char tt[128];
     327                  sprintf (tt, "/*[local-name()='%s']", requests[j]);
     328                  xmlXPathObjectPtr reqptr = extractFromDoc (doc, tt);
     329                  if (reqptr != NULL)
     330                    {
     331                      xmlNodeSet *req = reqptr->nodesetval;
     332#ifdef DEBUG
     333                      fprintf (stderr, "%i", req->nodeNr);
     334#endif
     335                      if (req != NULL && req->nodeNr == 1)
     336                        {
     337                          if (t1->value != NULL)
     338                            free (t1->value);
     339                          t1->value = zStrdup (requests[j]);
     340                          j = 2;
     341                        }
     342                      xmlXPathFreeObject (reqptr);
     343                    }
     344                }
     345              if (strncasecmp (t1->value, "GetCapabilities", 15) == 0)
     346                {
     347                  xmlXPathObjectPtr versptr =
     348                    extractFromDoc (doc, "/*/*/*[local-name()='Version']");
     349                  xmlNodeSet *vers = versptr->nodesetval;
     350                  xmlChar *content = xmlNodeListGetString (doc,
     351                                                           vers->
     352                                                           nodeTab
     353                                                           [0]->xmlChildrenNode,
     354                                                           1);
     355                  addToMap (tmpMap, "version", (char *) content);
     356                  xmlXPathFreeObject (versptr);
     357                  xmlFree (content);
     358                }
     359              else
     360                {
     361                  tval = NULL;
     362                  tval = (char *) xmlGetProp (cur, BAD_CAST "version");
     363                  if (tval != NULL)
     364                    {
     365                      addToMap (tmpMap, "version", tval);
     366                      xmlFree (tval);
     367                    }
     368                  tval = (char *) xmlGetProp (cur, BAD_CAST "language");
     369                  if (tval != NULL)
     370                    {
     371                      addToMap (tmpMap, "language", tval);
     372                      xmlFree (tval);
     373                    }
     374                  xmlXPathObjectPtr idptr =
     375                    extractFromDoc (doc, "/*/*[local-name()='Identifier']");
     376                  if (idptr != NULL)
     377                    {
     378                      xmlNodeSet *id = idptr->nodesetval;
     379                      if (id != NULL)
     380                        {
     381                          char *identifiers = NULL;
     382                          identifiers =
     383                            (char *) calloc (cgi->cgiContentLength, sizeof (char));
     384                          identifiers[0] = 0;
     385                          for (int k = 0; k < id->nodeNr; k++)
     386                            {
     387                              xmlChar *content = xmlNodeListGetString (doc,
     388                                                                       id->nodeTab
     389                                                                       [k]->
     390                                                                       xmlChildrenNode,
     391                                                                       1);
     392                              if (strlen (identifiers) > 0)
     393                                {
     394                                  char *tmp = zStrdup (identifiers);
     395                                  snprintf (identifiers,
     396                                            strlen (tmp) +
     397                                            xmlStrlen (content) + 2, "%s,%s",
     398                                            tmp, content);
     399                                  free (tmp);
     400                                }
     401                              else
     402                                {
     403                                  snprintf (identifiers,
     404                                            xmlStrlen (content) + 1, "%s",
     405                                            content);
     406                                }
     407                              xmlFree (content);
     408                            }
     409                          xmlXPathFreeObject (idptr);
     410                          addToMap (tmpMap, "Identifier", identifiers);
     411                          free (identifiers);
     412                        }
     413                    }
     414                }
     415              xmlFreeDoc (doc);
     416              xmlCleanupParser ();
     417            }
     418          else
     419            {
     420              freeMap (&tmpMap);
     421              free (tmpMap);
     422              tmpMap = createMap ("not_valid", "true");
     423            }
     424
     425          char *token, *saveptr;
     426          token = strtok_r (cgi->cgiQueryString, "&", &saveptr);
     427          while (token != NULL)
     428            {
     429              char *token1, *saveptr1;
     430              char *name = NULL;
     431              char *value = NULL;
     432              token1 = strtok_r (token, "=", &saveptr1);
     433              while (token1 != NULL)
     434                {
     435                  if (name == NULL)
     436                    name = zStrdup (token1);
     437                  else
     438                    value = zStrdup (token1);
     439                  token1 = strtok_r (NULL, "=", &saveptr1);
     440                }
     441              addToMap (tmpMap, name, value);
     442              free (name);
     443              free (value);
     444              name = NULL;
     445              value = NULL;
     446              token = strtok_r (NULL, "&", &saveptr);
     447            }
     448
     449        }
     450
     451      if (strncasecmp (cgi->cgiContentType, "multipart/form-data", 19) == 0)
     452        {
     453          map *tmp = getMap (tmpMap, "dataInputs");
     454          if (tmp != NULL)
     455            {
     456              addToMap (tmpMap, "dataInputs",
     457                        strstr (strQuery, "dataInputs=") + 11);
     458            }
     459        }
     460
     461      if (strQuery != NULL)
     462        free (strQuery);
     463/*
     464      json_object *obj;
     465      maptojson(&obj,tmpMap);
     466      fprintf(stderr,"%s\n",json_object_to_json_string(obj));
     467      fflush(stderr);
     468  */   
     469      runRequest (&tmpMap,&cgi,request);
     470
     471  /**
     472   * Required but can't be made after executing a process using POST requests.
     473   */
     474      if ( /*strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && */ tmpMap != NULL)
     475        {
     476          freeMap (&tmpMap);
     477          free (tmpMap);
     478        }
     479        // a verifier fait planter
     480      cgiFreeResources (&cgi);
     481
     482      FCGX_Finish_r(request);
     483      return 0;
     484}
     485
     486
     487
     488int
     489main (int argc, char *argv[])
     490{
     491 int debug_flag = 0;
     492 int background_flag = 0;
     493 char *file_value = NULL;
     494 int index;
     495 int c;
     496 opterr = 0;
     497 while ((c = getopt (argc, argv, "dbhf:")) != -1)
     498      switch (c)
    233499      {
    234         xmlXPathObjectPtr reqptr=extractFromDoc(doc,"/*[local-name()='Envelope']/*[local-name()='Body']/*");
    235         if(reqptr!=NULL){
    236           xmlNodeSet* req=reqptr->nodesetval;
    237           if(req!=NULL && req->nodeNr==1){
    238             addToMap(tmpMap,"soap","true");
    239             for(int k=0;k < req->nodeNr;k++){
    240               xmlDocSetRootElement(doc, req->nodeTab[k]);
    241               xmlChar *xmlbuff;
    242               int buffersize;
    243               xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "utf-8", 1);
    244               addToMap(tmpMap,"xrequest",(char*)xmlbuff);
    245               xmlFree(xmlbuff);
    246             }
    247           }
    248           xmlXPathFreeObject(reqptr);
    249         }
     500      case 'd':
     501        debug_flag = 1;
     502        break;
     503      case 'b':
     504        background_flag = 1;
     505        break;
     506      case 'h':
     507        fprintf(stderr,"TODO: need to print help\n");
     508        fflush(stderr);
     509        return 0;
     510      case 'f':
     511        file_value = optarg;
     512        break;
     513      case '?':
     514        if (optopt == 'f')
     515          fprintf (stderr, "Option -%c requires an argument.\n", optopt);
     516        else if (isprint (optopt))
     517          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
     518        else
     519          fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
     520        return 1;
     521      default:
     522        abort ();
    250523      }
    251524
    252       xmlNodePtr cur = xmlDocGetRootElement(doc);
    253       char *tval;
    254       tval=NULL;
    255       tval = (char*) xmlGetProp(cur,BAD_CAST "service");
    256       if(tval!=NULL){
    257         addToMap(tmpMap,"service",tval);
    258         xmlFree(tval);
    259       }
    260       tval=NULL;
    261       tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    262       if(tval!=NULL){
    263         addToMap(tmpMap,"language",tval);
    264         xmlFree(tval);
    265       }
    266       const char* requests[3]={"GetCapabilities","DescribeProcess","Execute"};
    267       for(int j=0;j<3;j++){
    268         char tt[128];
    269         sprintf(tt,"/*[local-name()='%s']",requests[j]);
    270         xmlXPathObjectPtr reqptr=extractFromDoc(doc,tt);
    271         if(reqptr!=NULL){
    272           xmlNodeSet* req=reqptr->nodesetval;
    273 #ifdef DEBUG
    274           fprintf(stderr,"%i",req->nodeNr);
    275 #endif
    276           if(req!=NULL && req->nodeNr==1){
    277             if(t1->value!=NULL)
    278               free(t1->value);
    279             t1->value=zStrdup(requests[j]);
    280             j=2;
    281           }
    282           xmlXPathFreeObject(reqptr);
    283         }
    284       }
    285       if(strncasecmp(t1->value,"GetCapabilities",15)==0){
    286         xmlXPathObjectPtr versptr=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
    287         xmlNodeSet* vers=versptr->nodesetval;
    288         if(vers!=NULL && vers->nodeTab!=NULL && vers->nodeTab[0]!=NULL){
    289           xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);
    290           addToMap(tmpMap,"version",(char*)content);
    291           xmlFree(content);
    292         }
    293         if(cur->ns){
    294           addToMap(tmpMap,"wps_schemas",(char*)cur->ns->href);
    295           int j=0;
    296           for(j=0;j<2;j++)
    297             if(strncasecmp(schemas[j][2],(char*)cur->ns->href,strlen(schemas[j][2]))==0){
    298               char vers[6];
    299               sprintf(vers,"%d.0.0",j+1);
    300               addToMap(tmpMap,"version",(char*)vers);
    301             }
    302         }
    303         xmlXPathFreeObject(versptr);
    304       }else{
    305         tval=NULL;
    306         tval = (char*) xmlGetProp(cur,BAD_CAST "version");
    307         if(tval!=NULL){
    308           addToMap(tmpMap,"version",tval);
    309           xmlFree(tval);
    310         }
    311         tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    312         if(tval!=NULL){
    313           addToMap(tmpMap,"language",tval);
    314           xmlFree(tval);
    315         }
    316         xmlXPathObjectPtr idptr=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
    317         if(idptr!=NULL){
    318           xmlNodeSet* id=idptr->nodesetval;
    319           if(id!=NULL){
    320             char* identifiers=NULL;
    321             identifiers=(char*)calloc(cgiContentLength,sizeof(char));
    322             identifiers[0]=0;
    323             for(int k=0;k<id->nodeNr;k++){
    324               xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
    325               if(strlen(identifiers)>0){
    326                 char *tmp=zStrdup(identifiers);
    327                 snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content);
    328                 free(tmp);
    329               }
    330               else{
    331                 snprintf(identifiers,xmlStrlen(content)+1,"%s",content);
    332               }
    333               xmlFree(content);
    334             }
    335             xmlXPathFreeObject(idptr);
    336             addToMap(tmpMap,"Identifier",identifiers);
    337             free(identifiers);
    338           }
    339         }else{
    340           idptr=extractFromDoc(doc,"/*/*[local-name()='JobID']");
    341           if(idptr!=NULL){
    342             xmlNodeSet* id=idptr->nodesetval;
    343             if(id!=NULL){
    344               char* identifiers=NULL;
    345               identifiers=(char*)calloc(cgiContentLength,sizeof(char));
    346               identifiers[0]=0;
    347               for(int k=0;k<id->nodeNr;k++){
    348                 xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
    349                 if(strlen(identifiers)>0){
    350                   char *tmp=zStrdup(identifiers);
    351                   snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content);
    352                   free(tmp);
    353                 }
    354                 else{
    355                   snprintf(identifiers,xmlStrlen(content)+1,"%s",content);
    356                 }
    357                 xmlFree(content);
    358               }
    359               xmlXPathFreeObject(idptr);
    360               addToMap(tmpMap,"JobID",identifiers);
    361               free(identifiers);
    362             }
    363         }
    364         }
    365       }
    366       xmlFreeDoc(doc);
    367       xmlCleanupParser();
    368     }else{
    369       freeMap(&tmpMap);
    370       free(tmpMap);
    371       tmpMap=createMap("not_valid","true");
    372     }
    373 
    374     char *token,*saveptr;
    375     token=strtok_r(cgiQueryString,"&",&saveptr);
    376     while(token!=NULL){
    377       char *token1,*saveptr1;
    378       char *name=NULL;
    379       char *value=NULL;
    380       token1=strtok_r(token,"=",&saveptr1);
    381       while(token1!=NULL){
    382         if(name==NULL)
    383           name=zStrdup(token1);
    384         else
    385           value=zStrdup(token1);
    386         token1=strtok_r(NULL,"=",&saveptr1);
    387       }   
    388       //addToMap(tmpMap,name,value);
    389           /* knut: strtok(_r) ignores delimiter bytes at start and end of string;
    390            * it will return non-empty string or NULL, e.g. "metapath=" yields value=NULL.
    391            * This modification sets value="" instead of NULL.
    392            */
    393           addToMap(tmpMap,name, value != NULL ? value : "");
    394 
    395       free(name);
    396       free(value);
    397       name=NULL;
    398       value=NULL;
    399       token=strtok_r(NULL,"&",&saveptr);
    400     }
    401    
    402   }
    403 
    404   if(strncasecmp(cgiContentType,"multipart/form-data",19)==0){
    405     map* tmp=getMap(tmpMap,"dataInputs");
    406     if(tmp!=NULL){
    407       addToMap(tmpMap,"dataInputs",strstr(strQuery,"dataInputs=")+11);
    408     }
    409   }
    410 
    411   if(strQuery!=NULL)
    412     free(strQuery);
    413 
     525
     526  maps *conf;
     527  conf = (maps *) malloc (MAPS_SIZE);
    414528 
    415   runRequest(&tmpMap);
    416 
    417   if(tmpMap!=NULL){
    418     freeMap(&tmpMap);
    419     free(tmpMap);
    420   }
     529  int ret = conf_read (file_value, conf);
     530  if ( ret == 2){
     531    //a verifier mais conf_read ne renvoie jamais 0
     532    fprintf(stderr,"Erreur lors de la lecture de %s\n",file_value);
     533    return 1;
     534  }
     535/*
     536 json_object *jobj;
     537  mapstojson(&jobj,conf);
     538  fprintf (stderr,"The json object created: %s\n",json_object_to_json_string(jobj));
     539    freeMaps(&conf);
     540 
     541  maps *conf_tmp;
     542  jsontomaps(jobj,&conf_tmp);
     543  dumpMaps(conf_tmp);
     544   return 1;
     545*/
     546  char *rootDir;
     547  map *m_rootDir = getMapFromMaps (conf, "server", "rootDir");
     548  if (m_rootDir == NULL){
     549    fprintf(stderr,"Configuration error: rootDir");
     550    return 2;
     551  }
     552  else {
     553   rootDir = (char*)malloc((strlen(m_rootDir->value) +1)*sizeof(char*));
     554   strncpy(rootDir,m_rootDir->value,strlen(m_rootDir->value));
     555   rootDir[strlen(m_rootDir->value)] = '\0';
     556   //freeMap(&m_rootDir);
     557  }
     558
     559char *regDir;
     560  map *m_regDir = getMapFromMaps (conf, "main", "registry");
     561  if (m_regDir == NULL){
     562    fprintf(stderr,"Configuration error: regDir");
     563    return 2;
     564  }
     565  else {
     566   regDir = (char*)malloc((strlen(m_regDir->value) +1)*sizeof(char*));
     567   strncpy(regDir,m_regDir->value,strlen(m_regDir->value));
     568   regDir[strlen(m_regDir->value)] = '\0';
     569  }
     570
     571
     572
     573  int req_worker;
     574  map *m_req_worker = getMapFromMaps (conf, "server", "req_worker");
     575  if (m_req_worker == NULL){
     576    fprintf(stderr,"Configuration error: req.worker not found\n");
     577    return 2;
     578  }
     579  else {
     580    req_worker=atoi(m_req_worker->value);
     581    //freeMap(&m_req_worker);
     582    if (req_worker == 0){
     583        fprintf(stderr,"Configuration error: req.worker\n");
     584        return 2;
     585    }
     586  }
     587 
     588  int async_worker;
     589  map *m_async_worker = getMapFromMaps (conf, "server", "async_worker"); 
     590  if (m_async_worker == NULL){
     591    fprintf(stderr,"Configuration error: async_worker not found");
     592    return 2;
     593  }
     594  else {
     595    async_worker = atoi(m_async_worker->value);
     596    //freeMap(&m_async_worker);
     597    if (async_worker == 0){
     598        fprintf(stderr,"Configuration error: req_worker");
     599        return 2;
     600    }
     601  }
     602
     603  int max_requests;
     604  map *m_max_requests = getMapFromMaps (conf, "server", "max_requests");
     605  if (m_max_requests == NULL){
     606    fprintf(stderr,"Configuration error: max_requests");
     607    return 2;
     608  }
     609  else {
     610    max_requests = atoi(m_max_requests->value);
     611    //freeMap(&m_max_requests);
     612    if (max_requests == 0){
     613        fprintf(stderr,"Configuration error: max_requests");
     614        return 2;
     615    }
     616  }
     617
     618  map *m_listen = getMapFromMaps (conf, "server", "listen");
     619  char *listen;
     620  if (m_listen == NULL){
     621    fprintf(stderr,"Configuration error: listen not found");
     622    return 2;
     623  }
     624  else {
     625    listen = (char *)malloc((strlen(m_listen->value) +1)*sizeof(char*));
     626    strncpy(listen,m_listen->value,strlen(m_listen->value));
     627    listen[strlen(m_listen->value)] = '\0';
     628    //freeMap(&m_listen);
     629  }
     630  int listen_owner;
     631  map *m_listen_owner = getMapFromMaps (conf, "server", "listen_owner");
     632  if (m_listen_owner == NULL){
     633    fprintf(stderr,"Configuration error: listen_owner");
     634    return 2;
     635  }
     636  else {
     637    listen_owner = atoi(m_listen_owner->value);
     638    //freeMap(&m_listen_owner);
     639    if (listen_owner == 0){
     640        fprintf(stderr,"Configuration error: listen_owner");
     641        return 2;
     642    }
     643  }
     644
     645  int listen_group;
     646  map *m_listen_group = getMapFromMaps (conf, "server", "listen_group");
     647  if (m_listen_group == NULL){
     648    fprintf(stderr,"Configuration error: listen_group");
     649    return 2;
     650  }
     651  else {
     652    listen_group = atoi(m_listen_group->value);
     653    //freeMap(&m_listen_group);
     654    if (listen_group == 0){
     655        fprintf(stderr,"Configuration error: listen_group");
     656        return 2;
     657    }
     658  }
     659
     660  char * listen_mode;
     661  map *m_listen_mode = getMapFromMaps (conf, "server", "listen_mode");
     662  if (m_listen_mode == NULL){
     663    fprintf(stderr,"Configuration error: listen_mode");
     664    return 2;
     665  }
     666  else {
     667    listen_mode = (char *)malloc((strlen(m_listen_mode->value) +1)*sizeof(char*));
     668    strncpy(listen_mode,m_listen_mode->value,strlen(m_listen_mode->value));
     669    listen_mode[strlen(m_listen_mode->value)] = '\0';
     670    //freeMap(&m_listen_mode);
     671  }
     672
     673  int listen_queue;
     674  map *m_listen_queue = getMapFromMaps (conf, "server", "listen_queue");
     675  if (m_listen_queue == NULL){
     676    fprintf(stderr,"Configuration error: listen_queue");
     677    return 2;
     678  }
     679  else {
     680    listen_queue = atoi(m_listen_queue->value);
     681    //freeMap(&m_listen_queue);
     682    if (listen_queue == 0){
     683        fprintf(stderr,"Configuration error: listen_queue");
     684        return 2;
     685    }
     686  }
     687
     688  int id_user;
     689  map *m_user = getMapFromMaps (conf, "server", "uid");
     690  if (m_user == NULL){
     691    fprintf(stderr,"Configuration error: id_user");
     692    return 2;
     693  }
     694  else {
     695    id_user = atoi(m_user->value);
     696    //freeMap(&m_user);
     697    if (id_user == 0){
     698        fprintf(stderr,"Configuration error: id_user");
     699        return 2;
     700    }
     701  }
     702
     703
     704  int id_group;
     705  map *m_group = getMapFromMaps (conf, "server", "gid");
     706  if (m_group == NULL){
     707    fprintf(stderr,"Configuration error: gid");
     708    return 2;
     709  }
     710  else {
     711    id_group = atoi(m_group->value);
     712    //freeMap(&m_group);
     713    if (id_group == 0){
     714        fprintf(stderr,"Configuration error: id_group");
     715        return 2;
     716    }
     717  }
     718
     719
     720  char * amqp_host;
     721  map * m_amqp_host = getMapFromMaps (conf, "rabbitmq", "host");
     722  if (m_amqp_host == NULL){
     723    fprintf(stderr,"Configuration error: [rabbitmq] host");
     724    return 2;
     725  }
     726  else {
     727    amqp_host = (char *)malloc((strlen(m_amqp_host->value) +1)*sizeof(char*));
     728    strncpy(amqp_host,m_amqp_host->value,strlen(m_amqp_host->value));
     729    amqp_host[strlen(m_amqp_host->value)] = '\0';
     730 }
     731
     732  int amqp_port;
     733  map *m_amqp_port = getMapFromMaps (conf, "rabbitmq", "port");
     734  if (m_amqp_port == NULL){
     735    fprintf(stderr,"Configuration error: [rabbitmq] port");
     736    return 2;
     737  }
     738  else {
     739    amqp_port = atoi(m_amqp_port->value);
     740    if (amqp_port == 0){
     741        fprintf(stderr,"Configuration error: [rabbitmq] port");
     742        return 2;
     743    }
     744  }
     745
     746  char * amqp_user;
     747  map * m_amqp_user = getMapFromMaps (conf, "rabbitmq", "user");
     748  if (m_amqp_user == NULL){
     749    fprintf(stderr,"Configuration error: [rabbitmq] user");
     750    return 2;
     751  }
     752  else {
     753    amqp_user = (char *)malloc((strlen(m_amqp_user->value) +1)*sizeof(char*));
     754    strncpy(amqp_user,m_amqp_user->value,strlen(m_amqp_user->value));
     755    amqp_user[strlen(m_amqp_user->value)] = '\0';
     756 }
     757
     758  char * amqp_passwd;
     759  map * m_amqp_passwd = getMapFromMaps (conf, "rabbitmq", "passwd");
     760  if (m_amqp_passwd == NULL){
     761    fprintf(stderr,"Configuration error: [rabbitmq] passwd");
     762    return 2;
     763  }
     764  else {
     765    amqp_passwd = (char *)malloc((strlen(m_amqp_passwd->value) +1)*sizeof(char*));
     766    strncpy(amqp_passwd,m_amqp_passwd->value,strlen(m_amqp_passwd->value));
     767    amqp_passwd[strlen(m_amqp_passwd->value)] = '\0';
     768 }
     769
     770  char * amqp_exchange;
     771  map * m_amqp_exchange = getMapFromMaps (conf, "rabbitmq", "exchange");
     772  if (m_amqp_exchange == NULL){
     773    fprintf(stderr,"Configuration error: [rabbitmq] exchange");
     774    return 2;
     775  }
     776  else {
     777    amqp_exchange = (char *)malloc((strlen(m_amqp_exchange->value) +1)*sizeof(char*));
     778    strncpy(amqp_exchange,m_amqp_exchange->value,strlen(m_amqp_exchange->value));
     779    amqp_exchange[strlen(m_amqp_exchange->value)] = '\0';
     780 }
     781
     782  char * amqp_routingkey;
     783  map * m_amqp_routingkey = getMapFromMaps (conf, "rabbitmq", "routingkey");
     784  if (m_amqp_routingkey == NULL){
     785    fprintf(stderr,"Configuration error: [amqp] routingkey");
     786    return 2;
     787  }
     788  else {
     789    amqp_routingkey = (char *)malloc((strlen(m_amqp_routingkey->value) +1)*sizeof(char*));
     790    strncpy(amqp_routingkey,m_amqp_routingkey->value,strlen(m_amqp_routingkey->value));
     791    amqp_routingkey[strlen(m_amqp_routingkey->value)] = '\0';
     792 }
     793
     794  char * amqp_queue;
     795  map * m_amqp_queue = getMapFromMaps (conf, "rabbitmq", "queue");
     796  if (m_amqp_queue == NULL){
     797    fprintf(stderr,"Configuration error: [rabbitmq] queue");
     798    return 2;
     799  }
     800  else {
     801    amqp_queue = (char *)malloc((strlen(m_amqp_queue->value) +1)*sizeof(char*));
     802    strncpy(amqp_queue,m_amqp_queue->value,strlen(m_amqp_queue->value));
     803    amqp_queue[strlen(m_amqp_queue->value)] = '\0';
     804 }
     805/*
     806  char * status_user;
     807  map * m_status_user = getMapFromMaps (conf, "status", "user");
     808  if (m_status_user == NULL){
     809    fprintf(stderr,"Configuration error: [status] user");
     810    return 2;
     811  }
     812  else {
     813    status_user = (char *)malloc((strlen(m_status_user->value) +1)*sizeof(char*));
     814    strncpy(status_user,m_status_user->value,strlen(m_status_user->value));
     815    status_user[strlen(m_status_user->value)] = '\0';
     816  }
     817
     818
     819  char * status_passwd;
     820  map * m_status_passwd = getMapFromMaps (conf, "status", "passwd");
     821  if (m_status_passwd == NULL){
     822    fprintf(stderr,"Configuration error: [status] passwd");
     823    return 2;
     824  }
     825  else {
     826    status_passwd = (char *)malloc((strlen(m_status_passwd->value) +1)*sizeof(char*));
     827    strncpy(status_passwd,m_status_passwd->value,strlen(m_status_passwd->value));
     828    status_passwd[strlen(m_status_passwd->value)] = '\0';
     829  }
     830
     831  char * status_bdd;
     832  map * m_status_bdd = getMapFromMaps (conf, "status", "bdd");
     833  if (m_status_bdd == NULL){
     834    fprintf(stderr,"Configuration error: [status] bdd");
     835    return 2;
     836  }
     837  else {
     838    status_bdd = (char *)malloc((strlen(m_status_bdd->value) +1)*sizeof(char*));
     839    strncpy(status_bdd,m_status_bdd->value,strlen(m_status_bdd->value));
     840    status_bdd[strlen(m_status_bdd->value)] = '\0';
     841  }
     842
     843  char * status_host;
     844  map * m_status_host = getMapFromMaps (conf, "status", "host");
     845  if (m_status_host == NULL){
     846    fprintf(stderr,"Configuration error: [status] host");
     847    return 2;
     848  }
     849  else {
     850    status_host = (char *)malloc((strlen(m_status_host->value) +1)*sizeof(char*));
     851    strncpy(status_host,m_status_host->value,strlen(m_status_host->value));
     852    status_host[strlen(m_status_host->value)] = '\0';
     853  }
     854
     855  int status_port;
     856  map *m_status_port = getMapFromMaps (conf, "status", "port");
     857  if (m_status_port == NULL){
     858    fprintf(stderr,"Configuration error: [status] port");
     859    return 2;
     860  }
     861  else {
     862    status_port = atoi(m_status_port->value);
     863    if (status_port == 0){
     864        fprintf(stderr,"Configuration error: [status] port");
     865        return 2;
     866    }
     867  }
     868  */
     869  int sock = FCGX_OpenSocket(listen, listen_queue);
     870  init_services_conf (rootDir,regDir);
     871 
     872  ret = chown(listen, listen_owner, listen_group);
     873  if (ret != 0){
     874    fprintf(stderr,"Change owner error on : %s\n",listen);
     875    return 3;
     876  }
     877  /*
     878  ret = setgid(id_group);
     879  if (ret != 0){
     880    fprintf(stderr,"Change gid error\n");
     881    return 3;
     882  }
     883
     884  ret = setuid(id_user);
     885  if (ret != 0){
     886    fprintf(stderr,"Change uid error\n");
     887    return 3;
     888  }
     889*/
     890
     891#ifdef AMQP
     892  init_amqp(amqp_host,amqp_port,amqp_user, amqp_passwd, amqp_exchange, amqp_routingkey,amqp_queue);
     893#endif
     894
     895  int fork_status = fork();
     896  if (fork_status == 0){
     897    //child
     898    int master_sync= getpid();
     899    fprintf(stderr,"Master sync%d\n",getpid());
     900    FCGX_Init();
     901    FCGX_Request request;
     902    FCGX_InitRequest(&request, sock, 0);
     903    int i;
     904    int count_request = 0;
     905    for (i = 0; i< req_worker; i++){
     906        fork_status = fork();
     907        if (fork_status == 0){
     908            fprintf(stderr,"child sync %d \n",getpid());
     909            fflush(stderr);
     910            break;
     911        }
     912    }
     913    while(1){
     914        /* mode synchrone */
     915        if (master_sync != getpid()){
     916            while(FCGX_Accept_r(&request) == 0){
     917                process(&request);
     918                count_request ++;
     919                if (count_request >= max_requests){
     920                    fprintf(stderr,"Max request stop process\n");
     921                    fflush(stderr);
     922                    exit(0);
     923                }
     924            }
     925        }
     926        else {
     927            wait(0);
     928            fprintf(stderr,"Master sync %d\n",getpid());
     929            fprintf(stderr,"New sync Child\n");
     930            fflush(stderr);
     931            fork();
     932        }
     933    }
     934  }
     935  while(1);
     936 
    421937  return 0;
    422 
    423938}
     939 
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_service_loader.c

    r677 r741  
    3232#endif
    3333
    34 #include "cgic.h"
     34//#include "cgic.h"
    3535
    3636extern "C"
     
    4545#include "ulinet.h"
    4646
    47 #include <libintl.h>
     47//#include <libintl.h>
    4848#include <locale.h>
    4949#include <string.h>
     
    5656#include "request_parser.h"
    5757#include "sqlapi.h"
     58#include "zoo_amqp.h"
     59#include "zoo_json.h"
    5860
    5961#ifdef USE_PYTHON
     
    237239           ("ZOO Kernel failed to process your request, receiving signal %d = %s"),
    238240           sig, ssig);
    239   errorException (NULL, tmp, "InternalError", NULL);
     241  errorException (NULL, tmp, "InternalError", NULL,NULL);
    240242#ifdef DEBUG
    241243  fprintf (stderr, "Not this time!\n");
     
    256258void
    257259loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
    258                    maps ** inputs, maps ** ioutputs, int *eres)
     260                   maps ** inputs, maps ** ioutputs, int *eres,FCGX_Stream *out, FCGX_Stream *err)
    259261{
    260262  char tmps1[1024];
     
    386388              typedef int (*execute_t) (maps **, maps **, maps **);
    387389
    388               fprintf(stderr,"%s \n",s1->name);
    389390#ifdef WIN32
    390391              execute_t execute =
     
    407408                           ("Error occured while running the %s function: %s"),
    408409                           s1->name, errstr);
    409                   errorException (m, tmpMsg, "InternalError", NULL);
     410                  errorException (m, tmpMsg, "InternalError", NULL,out);
    410411                  free (tmpMsg);
    411412#ifdef DEBUG
     
    457458#endif
    458459          sprintf (tmps, _("Unable to load C Library %s"), errstr);
    459           errorException(m,tmps,"InternalError",NULL);
     460          errorException(m,tmps,"InternalError",NULL,out);
    460461          *eres = -1;
    461462        }
     
    553554               ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),
    554555               r_inputs->value);
    555       errorException (m, tmpv, "InternalError", NULL);
     556      errorException (m, tmpv, "InternalError", NULL,out);
    556557      *eres = -1;
    557558    }
     559   fflush(stderr);
    558560  *myMap = m;
    559561  *ioutputs = request_output_real_format;
     
    728730 */
    729731int
    730 runRequest (map ** inputs)
     732runRequest (map ** inputs,struct cgi_env ** c,FCGX_Request *request)
    731733{
    732 
     734struct cgi_env *cgi = *c;
     735char *cgiSid = cgi->cgiSid;
    733736#ifndef USE_GDB
    734737#ifndef WIN32
     
    757760    {
    758761      return errorException (m, _("Unable to allocate memory."),
    759                              "InternalError", NULL);
     762                             "InternalError", NULL,request->out);
    760763    }
    761764  char ntmp[1024];
     
    772775    {
    773776      errorException (NULL, _("Unable to load the main.cfg file."),
    774                       "InternalError", NULL);
     777                      "InternalError", NULL,request->out);
    775778      free (m);
    776779      return 1;
     
    819822                   ("The value %s is not supported for the <language> parameter"),
    820823                   r_inputs->value);
    821           errorException (m, tmp, "InvalidParameterValue", "language");
     824          errorException (m, tmp, "InvalidParameterValue", "language",request->out);
    822825          freeMaps (&m);
    823826          free (m);
     
    870873    setMapInMaps (m, "main", "isSoap", "false");
    871874
    872   if(strlen(cgiServerName)>0)
     875  if(strlen(cgi->cgiServerName)>0)
    873876    {
    874877      char tmpUrl[1024];
    875878       
    876879      if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"?           
    877         if ( strncmp(cgiServerPort, "443", 3) == 0 ) {
    878           sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
     880        if ( strncmp(cgi->cgiServerPort, "443", 3) == 0 ) {
     881          sprintf(tmpUrl, "https://%s%s", cgi->cgiServerName, cgi->cgiScriptName);
    879882        }
    880883        else {
    881           sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
     884          sprintf(tmpUrl, "https://%s:%s%s", cgi->cgiServerName, cgi->cgiServerPort, cgi->cgiScriptName);
    882885        }
    883886      }
    884887      else {
    885         if ( strncmp(cgiServerPort, "80", 2) == 0 ) {
    886           sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
     888        if ( strncmp(cgi->cgiServerPort, "80", 2) == 0 ) {
     889          sprintf(tmpUrl, "http://%s%s", cgi->cgiServerName, cgi->cgiScriptName);
    887890        }
    888891        else {
    889           sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
     892          sprintf(tmpUrl, "http://%s:%s%s", cgi->cgiServerName, cgi->cgiServerPort, cgi->cgiScriptName);
    890893        }
    891894      }
     
    913916  if(err!=NULL){
    914917    checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
    915     printExceptionReportResponse (m, err);
     918    printExceptionReportResponse (m, err,request->out);
    916919    freeMap(&err);
    917920    free(err);
     
    969972  }
    970973  if(err!=NULL){
    971     printExceptionReportResponse (m, err);
     974    printExceptionReportResponse (m, err,request->out);
    972975    freeMap(&err);
    973976    free(err);
     
    10241027      xmlNodePtr n=printGetCapabilitiesHeader(doc,m,(version!=NULL?version->value:"1.0.0"));
    10251028      CapabilitiesAllProcess(m,n);
     1029     
    10261030      /**
    10271031       * Here we need to close stdout to ensure that unsupported chars
    10281032       * has been found in the zcfg and then printed on stdout
    10291033       */
    1030       /*
    1031       int saved_stdout = dup (fileno (stdout));
    1032       dup2 (fileno (stderr), fileno (stdout));
    1033       if (int res =               
    1034           recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
    1035                           printGetCapabilitiesForProcess) < 0)
    1036         {
    1037           freeMaps (&m);
    1038           free (m);
    1039           if(zooRegistry!=NULL){
    1040             freeRegistry(&zooRegistry);
    1041             free(zooRegistry);
    1042           }
    1043           free (REQUEST);
    1044           free (SERVICE_URL);
    1045           fflush (stdout);
    1046           return res;
    1047         }
    1048       fflush (stdout);
    1049       dup2 (saved_stdout, fileno (stdout));
    1050       */
    1051       printDocument (m, doc, getpid ());
     1034      printDocument (m, doc, getpid (),request->out);
    10521035      freeMaps (&m);
    10531036      free (m);
    1054       /*
    1055       if(zooRegistry!=NULL){
    1056         freeRegistry(&zooRegistry);
    1057         free(zooRegistry);
    1058       }
    1059 */
    10601037      free (REQUEST);
    10611038      free (SERVICE_URL);
    1062       fflush (stdout);
    10631039      return 0;
    10641040    }
     
    10691045        if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 ||
    10701046            strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){
    1071           runGetStatus(m,r_inputs->value,REQUEST);
     1047          runGetStatus(m,r_inputs->value,REQUEST,request->out);
    10721048          freeMaps (&m);
    10731049          free (m);
     
    10781054        else
    10791055          if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){
    1080             runDismiss(m,r_inputs->value);
     1056            runDismiss(m,r_inputs->value,request->out);
    10811057            freeMaps (&m);
    10821058            free (m);
     
    10911067        r_inputs = getMap (request_inputs, "Identifier");
    10921068
    1093         struct dirent *dp;
    1094         DIR *dirp = opendir (conf_dir);
    1095         if (dirp == NULL)
    1096           {
    1097             errorException (m, _("The specified path path does not exist."),
    1098                             "InvalidParameterValue", conf_dir);
    1099             freeMaps (&m);
    1100             free (m);
    1101             free (REQUEST);
    1102             free (SERVICE_URL);
    1103             return 0;
    1104           }
    11051069        if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
    11061070          {
     
    11191083
    11201084        DescribeProcess(m,n,orig);
    1121             fflush (stdout);
    11221085        int saved_stdout;
    1123             dup2 (saved_stdout, fileno (stdout));
    11241086            free (orig);
    1125             printDocument (m, doc, getpid ());
     1087            printDocument (m, doc, getpid (),request->out);
    11261088            freeMaps (&m);
    11271089            free (m);
    11281090            free (REQUEST);
    11291091            free (SERVICE_URL);
    1130             fflush (stdout);
    11311092            return 0;
    11321093          }
    11331094        else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
    11341095          {
    1135             map* version=getMapFromMaps(m,"main","rversion");
     1096        map* version=getMapFromMaps(m,"main","rversion");
    11361097            int vid=getVersionId(version->value);
    11371098            int len,j=0;
     
    11691130            char* message=(char*)malloc((61+len)*sizeof(char));
    11701131            sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr);
    1171             errorException (m,_(message),"InvalidParameterValue", "request");
     1132            errorException (m,_(message),"InvalidParameterValue", "request",request->out);
    11721133#ifdef DEBUG
    11731134            fprintf (stderr, "No request found %s", REQUEST);
    11741135#endif
    1175             closedir (dirp);
    11761136            freeMaps (&m);
    11771137            free (m);
    11781138            free (REQUEST);
    11791139            free (SERVICE_URL);
    1180             fflush (stdout);
    11811140            return 0;
    11821141          }
    1183         closedir (dirp);
    11841142      }
    11851143    }
     
    11871145  map *postRequest = NULL;
    11881146  postRequest = getMap (request_inputs, "xrequest");
    1189 
     1147/*
    11901148  if(vid==1 && postRequest==NULL){
    1191     errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request"); 
     1149    errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request",request->out); 
    11921150    freeMaps (&m);
    11931151    free (m);
    11941152    free (REQUEST);
    11951153    free (SERVICE_URL);
    1196     fflush (stdout);
    11971154    return 0;
    11981155  }
    1199  
     1156  */
    12001157  s1 = NULL;
    12011158  r_inputs = getMap (request_inputs, "Identifier");
    12021159  s1 = search_service (r_inputs->value);
    1203  int saved_stdout = dup (fileno (stdout));
     1160 int saved_stdout;// = dup (fileno (stdout));
    12041161 
    12051162 
     
    12111168               ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."),
    12121169               r_inputs->value);
    1213       errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
     1170      errorException (m, tmpMsg, "InvalidParameterValue", "identifier",request->out);
    12141171      free (tmpMsg);
    12151172      freeMaps (&m);
     
    12191176      return 0;
    12201177    }
    1221   close (saved_stdout);
     1178  setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
     1179  setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
     1180
    12221181
    12231182#ifdef DEBUG
     
    12481207
    12491208
    1250   if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){
     1209  if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){
    12511210    freeMaps (&m);
    12521211    free (m);
     
    13341293                        _
    13351294                        ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."),
    1336                         "InvalidParameterValue", "storeExecuteResponse");
    1337         //freeService (&s1);
    1338         free (s1);
     1295                        "InvalidParameterValue", "storeExecuteResponse",request->out);
    13391296        freeMaps (&m);
    13401297        free (m);
     
    13611318        if(mode!=NULL){
    13621319          // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61
    1363           errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value); 
    1364           fflush (stdout);
     1320          errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value,request->out); 
    13651321          freeMaps (&m);
    13661322          free (m);
     
    14401396
    14411397  // Parse the session file and add it to the main maps
    1442   if (cgiCookie != NULL && strlen (cgiCookie) > 0)
     1398  if (cgi->cgiCookie != NULL && strlen (cgi->cgiCookie) > 0)
    14431399    {
    14441400      int hasValidCookie = -1;
    1445       char *tcook = zStrdup (cgiCookie);
     1401      char *tcook = zStrdup (cgi->cgiCookie);
    14461402      char *tmp = NULL;
    14471403      map *testing = getMapFromMaps (m, "main", "cookiePrefix");
     
    14561412          sprintf (tmp, "%s=", testing->value);
    14571413        }
    1458       if (strstr (cgiCookie, ";") != NULL)
     1414      if (strstr (cgi->cgiCookie, ";") != NULL)
    14591415        {
    14601416          char *token, *saveptr;
    1461           token = strtok_r (cgiCookie, ";", &saveptr);
     1417          token = strtok_r (cgi->cgiCookie, ";", &saveptr);
    14621418          while (token != NULL)
    14631419            {
     
    14741430      else
    14751431        {
    1476           if (strstr (cgiCookie, "=") != NULL
    1477               && strcasestr (cgiCookie, tmp) != NULL)
     1432          if (strstr (cgi->cgiCookie, "=") != NULL
     1433              && strcasestr (cgi->cgiCookie, tmp) != NULL)
    14781434            {
    1479               tcook = zStrdup (cgiCookie);
     1435              tcook = zStrdup (cgi->cgiCookie);
    14801436              hasValidCookie = 1;
    14811437            }
     
    14981454          else
    14991455            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
    1500                      strstr (cgiCookie, "=") + 1);
     1456                     strstr (cgi->cgiCookie, "=") + 1);
    15011457          free (tcook);
    15021458          maps *tmpSess = (maps *) malloc (MAPS_SIZE);
     
    15391495    }
    15401496#endif
     1497
    15411498  char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog;
    15421499  FILE *f0, *f1;
     
    15461503  if (status == NULLMAP)
    15471504    {
    1548       if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
    1549         free (s1);
     1505      if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){
    15501506        freeMaps (&m);
    15511507        free (m);
     
    15601516        return -1;
    15611517      }
    1562 
     1518       fflush(stderr);
    15631519      loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
    1564                          &request_output_real_format, &eres);
    1565     }
    1566   else
    1567     {
     1520                         &request_output_real_format, &eres,request->out,request->err);
     1521    }
     1522  else
     1523    {
     1524       
     1525        eres = SERVICE_ACCEPTED;
     1526        vid = 1;
     1527       
     1528#ifdef AMQP
     1529
     1530
     1531    eres = SERVICE_ACCEPTED;
     1532    json_object *msg_jobj = json_object_new_object();
     1533    json_object *maps_obj;
     1534    mapstojson(&maps_obj,m);
     1535    json_object_object_add(msg_jobj,"maps",maps_obj);
     1536
     1537
     1538    json_object *req_format_jobj;
     1539    mapstojson(&req_format_jobj,request_input_real_format);
     1540    json_object_object_add(msg_jobj,"request_input_real_format",req_format_jobj);
     1541
     1542    json_object *req_jobj;
     1543    maptojson(&req_jobj,request_inputs);
     1544    json_object_object_add(msg_jobj,"request_inputs",req_jobj);
     1545
     1546 
     1547    dumpMaps(request_output_real_format);
     1548    json_object *outputs_jobj;
     1549    mapstojson(&outputs_jobj,request_output_real_format);
     1550    json_object_object_add(msg_jobj,"request_output_real_format",outputs_jobj);
     1551 
     1552    bind_amqp();
     1553
     1554    if ( (send_msg(json_object_to_json_string(msg_jobj),"application/json") != 0) ){     
     1555        eres = SERVICE_FAILED;
     1556    }
     1557    close_amqp();
     1558    json_object_put(msg_jobj);
     1559   
     1560    init_sql(m);
     1561    recordServiceStatus(m);
     1562
     1563
     1564
     1565       
     1566#else
    15681567      int pid;
    15691568#ifdef DEBUG
     
    16871686            printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
    16881687                                  SERVICE_STARTED, request_input_real_format,
    1689                                   request_output_real_format);
    1690             fflush (stdout);
     1688                                  request_output_real_format,request->out);
     1689
    16911690#ifdef RELY_ON_DB
    16921691            recordResponse(m,fbkp);
     
    17051704          f1 = freopen (fbkp1, "w+", stdout);
    17061705
    1707           if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
    1708             //freeService (&s1);
    1709             free (s1);
     1706          if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){
    17101707            freeMaps (&m);
    17111708            free (m);
     
    17181715            freeMaps (&tmpmaps);
    17191716            free (tmpmaps);
    1720             fflush (stdout);
    17211717            fflush (stderr);
    17221718            unhandleStatus (m);
    17231719            return -1;
    17241720          }
     1721     
    17251722          loadServiceAndRun (&m, s1, request_inputs,
    17261723                             &request_input_real_format,
    1727                              &request_output_real_format, &eres);
     1724                             &request_output_real_format, &eres,request->out,request->err);
    17281725
    17291726        }
     
    17361733          eres = -1;
    17371734          errorException (m, _("Unable to run the child process properly"),
    1738                           "InternalError", NULL);
     1735                          "InternalError", NULL,request->out);
    17391736        }
    1740     }
     1737
     1738#endif
     1739
     1740    }
     1741
     1742
     1743
    17411744
    17421745#ifdef DEBUG
     
    17461749    outputResponse (s1, request_input_real_format,
    17471750                    request_output_real_format, request_inputs,
    1748                     cpid, m, eres);
    1749   fflush (stdout);
     1751                    cpid, m, eres,request->out);
     1752  //fflush (stdout);
    17501753 
     1754
    17511755  /**
    17521756   * Ensure that if error occurs when freeing memory, no signal will return
     
    18191823      free (tmps1);
    18201824    }
    1821 
    1822   //freeService (&s1);
    1823   free (s1);
    18241825  freeMaps (&m);
    18251826  free (m);
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_zcfg.c

    r678 r741  
    269269#ifdef DEBUG
    270270      dumpService (s1);
    271       fflush (stdout);
    272271      fflush (stderr);
    273272#endif
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