Ignore:
Timestamp:
Oct 7, 2015, 8:41:43 AM (9 years ago)
Author:
david
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
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