Changeset 682


Ignore:
Timestamp:
Jun 26, 2015, 2:07:46 PM (4 years ago)
Author:
djay
Message:

Fix GetResult? and POST asynchronous requests on Windows. Prevent CONTENT_TYPE=text/xml before creating the process using CreateProcess?. Revert modifications made r587 for using url_decode directly inside zoo_loader.c, the url_decode call should be in kvpParseInputs (from request_parser.c), indeed, there should not be any decoding required in other cases than Execute requests. Fix issue in mapsFromPyDict, small changes in mapFromPyDict to fix parsing result value (only) for Python 3.

Location:
trunk/zoo-project
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/HISTORY.txt

    r676 r682  
    11Version 1.5.0-dev
     2  * Fix asynchronous POST request on WIN32 platforms
    23  * Add utils/registry service
    34  * Initial support for WPS 2.0.0 including the Dismiss extension
  • trunk/zoo-project/zoo-kernel/response_print.c

    r680 r682  
    17451745  }
    17461746 
    1747   if(vid==0 && hasStoredExecuteResponse==true && status!=SERVICE_STARTED && status!=SERVICE_ACCEPTED){
     1747  if(vid==0 &&
     1748     hasStoredExecuteResponse==true
     1749     && status!=SERVICE_STARTED
     1750#ifndef WIN32
     1751     && status!=SERVICE_ACCEPTED
     1752#endif
     1753     ){
    17481754#ifndef RELY_ON_DB
    17491755    semid lid=acquireLock(m);//,1);
     
    23342340  map* version=getMapFromMaps(m,"main","rversion");
    23352341  int vid=getVersionId(version->value);
    2336  
     2342
    23372343  maps* tmpSess=getMaps(m,"senv");
    23382344  if(tmpSess!=NULL){
     
    23752381    else{
    23762382      fclose(teste);
    2377       dumpMapsToFile(tmpSess,session_file_path);
     2383      dumpMapsToFile(tmpSess,session_file_path,1);
    23782384    }
    23792385  }
     
    24412447          elements* in=getElements(s->outputs,tmpI->name);
    24422448          char *format=NULL;
    2443           if(in!=NULL){
    2444             format=strdup(in->format);
     2449          if(in!=NULL && in->format!=NULL){
     2450            format=zStrdup(in->format);
    24452451          }else
    2446             format=strdup("LiteralData");
     2452            format=zStrdup("LiteralData");
    24472453          if(strcasecmp(format,"BoundingBoxData")==0){
    24482454            addToMap(tmpI->content,"extension","xml");
     
    24662472              getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
    24672473            }
    2468                
     2474
    24692475            file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
    24702476            sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
     
    24722478            file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
    24732479            sprintf(file_path,"%s/%s",tmp1->value,file_name);
    2474    
     2480
    24752481            FILE *ofile=fopen(file_path,"wb");
    24762482            if(ofile==NULL){
     
    24982504
    24992505          }
     2506
    25002507          map *tmp2=getMapFromMaps(m,"main","tmpUrl");
    25012508          map *tmp3=getMapFromMaps(m,"main","serverAddress");
     
    25092516            sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
    25102517          }
     2518
    25112519          addToMap(tmpI->content,"Reference",file_url);
    25122520          free(format);
    25132521          free(file_name);
    2514           free(file_url);       
     2522          free(file_url);
    25152523         
    25162524        }
  • trunk/zoo-project/zoo-kernel/server_internal.c

    r680 r682  
    7272#endif
    7373  sprintf(res,"%s",rest);
     74#ifdef WIN32
     75  RpcStringFree(&rest);
     76#endif
    7477  return res;
    7578}
     
    895898        if(result!=NULL){
    896899          char *encoding=getEncoding(conf);
    897           fprintf(stdout,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
    898           fprintf(stdout,"%s",result);
     900          printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
     901          printf("%s",result);
    899902          fflush(stdout);
    900903          freeMap(&statusInfo);
  • trunk/zoo-project/zoo-kernel/service.c

    r680 r682  
    8787 * @param file_path the full path to the file name to store the map
    8888 */
    89 void dumpMapsToFile(maps* m,char* file_path){
     89void dumpMapsToFile(maps* m,char* file_path,int limit){
    9090  FILE* file=fopen(file_path,"w+");
    9191  maps* tmp=m;
     92  int cnt=0;
    9293  while(tmp!=NULL){
    9394    fprintf(file,"[%s]\n",tmp->name);
     
    9596    fflush(file);
    9697    tmp=tmp->next;
     98    cnt++;
     99    if(limit>=0 && cnt==limit)
     100      tmp=NULL;
    97101  }
    98102  fflush(file);
  • trunk/zoo-project/zoo-kernel/service.h

    r680 r682  
    271271  ZOO_DLL_EXPORT void dumpMap(map*);
    272272  ZOO_DLL_EXPORT void dumpMaps(maps* m);
    273   ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // Not required
    274   ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*);
     273  ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // (used only internally)
     274  ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*,int);
    275275  ZOO_DLL_EXPORT map* createMap(const char*,const char*);
    276276  ZOO_DLL_EXPORT int count(map*);
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r624 r682  
    523523maps* mapsFromPyDict(PyDictObject* t){
    524524  maps* res=NULL;
    525   maps* cursor=res;
     525  maps* cursor=NULL;
    526526  PyObject* list=PyDict_Keys((PyObject*)t);
    527527  int nb=PyList_Size(list);
    528528  int i;
     529  PyObject* key;
     530  PyObject* value;
    529531  for(i=0;i<nb;i++){
    530532#ifdef DEBUG
    531533    fprintf(stderr,">> parsing maps %d\n",i);
    532534#endif
    533     PyObject* key=PyList_GetItem(list,i);
    534     PyObject* value=PyDict_GetItem((PyObject*)t,key);
     535    key=PyList_GetItem(list,i);
     536    value=PyDict_GetItem((PyObject*)t,key);
    535537#ifdef DEBUG
    536538    fprintf(stderr,">> DEBUG VALUES : %s => %s\n",
     
    538540#endif
    539541    cursor=(maps*)malloc(MAPS_SIZE);
    540     cursor->name=PyString_AsString(key);
     542    cursor->name=zStrdup(PyString_AsString(key));
    541543    cursor->content=mapFromPyDict((PyDictObject*)value);
    542544#ifdef DEBUG
     
    572574  int nb=PyList_Size(list);
    573575  int i;
     576  PyObject* key;
     577  PyObject* value;
    574578  for(i=0;i<nb;i++){
    575     PyObject* key=PyList_GetItem(list,i);
    576     PyObject* value=PyDict_GetItem((PyObject*)t,key);
     579    key=PyList_GetItem(list,i);
     580    value=PyDict_GetItem((PyObject*)t,key);
    577581#ifdef DEBUG
    578582    fprintf(stderr,">> DEBUG VALUES : %s => %s\n",
     
    584588      Py_ssize_t size;
    585589#if PY_MAJOR_VERSION >= 3
    586       buffer=_PyUnicode_AsStringAndSize(value,&size);
     590      if(PyBytes_Check(value)){
     591        size=PyBytes_Size(value);
     592        buffer=PyBytes_AsString(value);
     593      }
     594      else
     595        if(PyUnicode_Check(value) && PyUnicode_READY(value) == 0){
     596          buffer=PyUnicode_AsUTF8AndSize(value,&size);
     597        }
     598        else{
     599          fprintf(stderr,"Unsupported return value.");
     600          return NULL;
     601        }
    587602#else
    588603      PyString_AsStringAndSize(value,&buffer,&size);
  • trunk/zoo-project/zoo-kernel/zoo_loader.c

    r680 r682  
    2929 * Specific includes
    3030 */
    31 #ifndef WIN32
    3231#include "fcgio.h"
    3332#include "fcgi_config.h"
    3433#include "fcgi_stdio.h"
    35 #endif
    3634#include <sys/types.h>
    3735#include <unistd.h>
    3836#include "service_internal.h"
    3937#include "response_print.h"
    40 
    41 
    42 #ifdef WIN32
    43 #include "windows.h"
    44 #define strtok_r strtok_s
    45 #endif
    4638
    4739extern "C" {
     
    5446}
    5547
     48#ifdef WIN32
     49#include "windows.h"
     50#define strtok_r strtok_s
     51#endif
     52
    5653#include "service_internal.h"
    5754#include "request_parser.h"
    58 
    59 #ifdef WIN32
    60 #include "server_internal.h"
    61 #endif
    6255
    6356int runRequest(map**);
     
    178171      fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
    179172#endif
    180 #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
    188173      if(tmpMap!=NULL)
    189174        addToMap(tmpMap,*arrayStep,value);
    190175      else
    191176        tmpMap=createMap(*arrayStep,value);
    192 #endif 
    193177      arrayStep++;
    194178      delete[]value;
     
    206190    char *buffer=(char*)malloc((flen+1)*sizeof(char));
    207191    fread(buffer,flen,1,lf);
     192    char *pchr=strrchr(buffer,'>');
     193    cgiContentLength=strlen(buffer)-strlen(pchr)+1;
     194    buffer[cgiContentLength]=0;
    208195    fclose(lf);
    209196    addToMap(tmpMap,"request",buffer);
    210197    free(buffer);
    211     cgiContentLength=flen+9;
    212198  }
    213199#endif
     
    387373      }   
    388374      //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 
     375      /* knut: strtok(_r) ignores delimiter bytes at start and end of string;
     376       * it will return non-empty string or NULL, e.g. "metapath=" yields value=NULL.
     377       * This modification sets value="" instead of NULL.
     378       */
     379      addToMap(tmpMap,name, value != NULL ? value : "");
    395380      free(name);
    396381      free(value);
     
    412397    free(strQuery);
    413398
    414  
    415399  runRequest(&tmpMap);
    416400
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r680 r682  
    734734    strncpy(kvp, key, strlen(key));
    735735    addToCache(m, tmpReq->value, tmpReq->value, "text/xml", strlen(tmpReq->value),
    736                filepath, FILENAME_MAX);                           
     736               filepath, FILENAME_MAX);
    737737    if (filepath == NULL) {
    738738      errorException( m, _("Unable to cache HTTP POST Execute request."), "InternalError", NULL); 
     
    787787  SetEnvironmentVariable ("CGISID", TEXT (sid->value));
    788788  SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq));
    789   // knut: Prevent REQUEST_METHOD=POST in background process call to cgic:main (process hangs when reading cgiIn):
     789  // knut: Prevent REQUEST_METHOD=POST in background process call to cgic:main
     790  // (process hangs when reading cgiIn):
    790791  SetEnvironmentVariable("REQUEST_METHOD", "GET");
     792  SetEnvironmentVariable("CONTENT_TYPE", "text/plain");
    791793 
    792794  char clen[1000];
     
    794796  SetEnvironmentVariable ("CONTENT_LENGTH", TEXT (clen));
    795797
     798  // ref. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx
    796799  if (!CreateProcess (NULL,     // No module name (use command line)
    797800                      TEXT (tmp),       // Command line
     
    17981801   * Initialize the specific [lenv] section which contains runtime variables:
    17991802   *
    1800    *  - usid : it is an unique identification number
     1803   *  - usid : it is an universally unique identifier 
     1804   *  - osid : it is an idenfitication number
    18011805   *  - sid : it is the process idenfitication number (OS)
    1802    *  - uusid : it is an universally unique identification number
     1806   *  - uusid : it is an universally unique identifier
    18031807   *  - status : value between 0 and 100 to express the  completude of
    18041808   * the operations of the running service
     
    19311935  map *test1 = getMap (request_inputs, "cgiSid");
    19321936  if (test1 != NULL){
    1933       cgiSid = test1->value;
    1934       addToMap (request_inputs, "storeExecuteResponse", "true");
    1935       addToMap (request_inputs, "status", "true");
    1936       setMapInMaps (m, "lenv", "sid", test1->value);
    1937       status = getMap (request_inputs, "status");
    1938     }
     1937    cgiSid = zStrdup(test1->value);
     1938    addToMap (request_inputs, "storeExecuteResponse", "true");
     1939    addToMap (request_inputs, "status", "true");
     1940    setMapInMaps (m, "lenv", "osid", test1->value);
     1941    status = getMap (request_inputs, "status");
     1942  }
    19391943  test1 = getMap (request_inputs, "usid");
    19401944  if (test1 != NULL){
     
    21292133                             &request_input_real_format,
    21302134                             &request_output_real_format, &eres);
    2131 
    21322135        }
    21332136      else
     
    21822185      lockShm (lid);
    21832186#endif
    2184       fclose(f0);
    21852187      FILE *f3 = fopen (fbkp, "wb+");
    21862188      free (fbkp);
     
    22062208      }
    22072209#ifndef RELY_ON_DB
    2208       dumpMapsToFile(bmap,fbkpres);
     2210      dumpMapsToFile(bmap,fbkpres,1);
    22092211      removeShmLock (m, 1);
    22102212#else
     
    22212223      free (fbkp1);
    22222224      free (tmps1);
     2225      if(cgiSid!=NULL)
     2226        free(cgiSid);
    22232227    }
    22242228
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