Changeset 587 for trunk


Ignore:
Timestamp:
Feb 18, 2015, 1:31:59 PM (10 years ago)
Author:
knut
Message:

Implemented asynchronous HTTP POST Execute requests on Windows platform (via caching). Fixed bug that caused only the last output variable in a HTTP POST Execute request to be returned. Modified the addToCache function so that the path of the cached file can be retrieved. Changed the parsing of KVPs in zoo_loader.c so that keys with missing values (e.g. "metapath=") are assigned the empty string instead of NULL (avoids segmentation fault in some situations). Added conditional definition of ZEND_DEBUG in service_internal_php.c. Deallocation of memory in function createProcess. In zoo_loader.c, applied url_decode to CGI form string (WIN32 only, but should check if this should apply to other platforms as well).

Location:
trunk/zoo-project/zoo-kernel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r585 r587  
    35113511 * @param mimeType the content mimeType
    35123512 * @param length the content size
    3513  */
    3514 void addToCache(maps* conf,char* request,char* content,char* mimeType,int length){
     3513 * @param filepath a buffer for storing the path of the cached file; may be NULL
     3514 * @param max_path the size of the allocated filepath buffer 
     3515 */
     3516void addToCache(maps* conf,char* request,char* content,char* mimeType,int length,
     3517                char* filepath, size_t max_path){
    35153518  map* tmp=getMapFromMaps(conf,"main","cacheDir");
    35163519  if(tmp!=NULL){
     
    35243527    FILE* fo=fopen(fname,"w+");
    35253528    if(fo==NULL){
    3526       fprintf (stderr, "Failed to open %s for writting: %s\n",fname, strerror(errno));
     3529#ifdef DEBUG           
     3530      fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno));
     3531#endif
     3532      filepath = NULL; 
    35273533      return;
    35283534    }
    35293535    fwrite(content,sizeof(char),length,fo);
    35303536    fclose(fo);
     3537       
     3538        if (filepath != NULL) {
     3539                strncpy(filepath, fname, max_path);
     3540        }       
    35313541
    35323542    sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
     
    35413551    free(fname);
    35423552  }
     3553  else {
     3554          filepath = NULL;
     3555  }       
    35433556}
    35443557
     
    36653678            }
    36663679            addToMap(content->content,sname,ltmp1);
    3667             addToCache(*m,tmp1->value,fcontent,mimeType,fsize);
     3680            addToCache(*m,tmp1->value,fcontent,mimeType,fsize, NULL, 0);
    36683681            free(fcontent);
    36693682            free(mimeType);
     
    37673780  addToMap(*content,"size",ltmp1);
    37683781  if(cached==NULL){
    3769     addToCache(*m,url,fcontent,mimeType,fsize);
     3782    addToCache(*m,url,fcontent,mimeType,fsize, NULL, 0);
    37703783  }
    37713784  else{
  • trunk/zoo-project/zoo-kernel/service_internal.h

    r580 r587  
    212212  xmlNodePtr soapEnvelope(maps*,xmlNodePtr);
    213213  int checkForSoapEnvelope(xmlDocPtr);
    214 
    215   void addToCache(maps*,char*,char*,char*,int);
     214 
     215  void addToCache(maps*,char*,char*,char*,int,char*,size_t);
    216216  char* isInCache(maps*,char*);
    217217  int runHttpRequests(maps**,maps**,HINTERNET*);
  • trunk/zoo-project/zoo-kernel/service_internal_php.c

    r586 r587  
    2626  #define NO_FCGI_DEFINES
    2727#endif
     28
     29#ifndef ZEND_DEBUG
     30  #define ZEND_DEBUG 0
     31#endif 
    2832 
    2933#include "service_internal_php.h"
  • trunk/zoo-project/zoo-kernel/zoo_loader.c

    r554 r587  
    173173      fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
    174174#endif
     175#ifdef WIN32
     176      char* tmp = url_decode(value);
     177      if(tmpMap!=NULL)         
     178        addToMap(tmpMap,*arrayStep,tmp);
     179      else             
     180        tmpMap=createMap(*arrayStep,tmp);
     181      free(tmp);
     182#else
    175183      if(tmpMap!=NULL)
    176         addToMap(tmpMap,*arrayStep,value);
     184        addToMap(tmpMap,*arrayStep,value);
    177185      else
    178         tmpMap=createMap(*arrayStep,value);
     186        tmpMap=createMap(*arrayStep,value);
     187#endif 
    179188      arrayStep++;
    180189      delete[]value;
     
    330339      token1=strtok_r(token,"=",&saveptr1);
    331340      while(token1!=NULL){
    332         if(name==NULL)
    333           name=zStrdup(token1);
    334         else
    335           value=zStrdup(token1);
    336         token1=strtok_r(NULL,"=",&saveptr1);
    337       }
    338       addToMap(tmpMap,name,value);
     341        if(name==NULL)
     342          name=zStrdup(token1);
     343        else
     344          value=zStrdup(token1);
     345        token1=strtok_r(NULL,"=",&saveptr1);
     346      }
     347      //addToMap(tmpMap,name,value);
     348          /* knut: strtok(_r) ignores delimiter bytes at start and end of string;
     349           * it will return non-empty string or NULL, e.g. "metapath=" yields value=NULL.
     350           * This modification sets value="" instead of NULL.
     351           */
     352          addToMap(tmpMap,name, value != NULL ? value : "");
     353
    339354      free(name);
    340355      free(value);
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r584 r587  
    751751
    752752  map *tmpReq = getMap (request_inputs, "xrequest");
    753   if (r_inputs2 != NULL)
     753 
     754  if(r_inputs2 != NULL && tmpReq != NULL) {
     755        const char key[] = "rfile=";
     756        char* kvp = (char*) malloc((FILENAME_MAX + strlen(key))*sizeof(char));
     757        char* filepath = kvp + strlen(key);
     758        strncpy(kvp, key, strlen(key));
     759        addToCache(m, tmpReq->value, tmpReq->value, "text/xml", strlen(tmpReq->value),
     760                   filepath, FILENAME_MAX);                               
     761    if (filepath == NULL) {
     762        errorException( m, _("Unable to cache HTTP POST Execute request."), "InternalError", NULL); 
     763                return;
     764    }   
     765        sprintf(tmp,"\"metapath=%s&%s&cgiSid=%s",
     766                r_inputs1->value,kvp,sid->value);
     767    sprintf(tmpq,"metapath=%s&%s",
     768                r_inputs1->value,kvp);
     769        free(kvp);             
     770  }
     771  else if (r_inputs2 != NULL)
    754772    {
    755773      sprintf (tmp,
    756                "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"",
     774               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s",
    757775               r_inputs1->value, req->value, id->value, dataInputsKVP,
    758776               r_inputs2->name, dataOutputsKVP, sid->value);
     
    760778               "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",
    761779               r_inputs1->value, req->value, id->value, dataInputsKVP,
    762                r_inputs2->name, dataOutputsKVP);
     780               r_inputs2->name, dataOutputsKVP);                   
    763781    }
    764782  else
    765783    {
    766784      sprintf (tmp,
    767                "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"",
     785               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s",
    768786               r_inputs1->value, req->value, id->value, dataInputsKVP,
    769787               sid->value);
     
    771789               "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",
    772790               r_inputs1->value, req->value, id->value, dataInputsKVP,
    773                sid->value);
     791               sid->value);   
    774792    }
    775793
     
    780798    }
    781799  char *tmp1 = zStrdup (tmp);
    782   sprintf (tmp, "\"%s\" %s \"%s\"", PROGRAMNAME, tmp1, sid->value);
     800  sprintf (tmp, "\"%s\" %s \"%s\"", PROGRAMNAME, tmp1, sid->value); 
    783801  free (dataInputsKVP);
    784802  free (dataOutputsKVP);
     
    794812  SetEnvironmentVariable ("CGISID", TEXT (sid->value));
    795813  SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq));
     814  // knut: Prevent REQUEST_METHOD=POST in background process call to cgic:main (process hangs when reading cgiIn):
     815  SetEnvironmentVariable("REQUEST_METHOD", "GET");
     816 
    796817  char clen[1000];
    797818  sprintf (clen, "%d", strlen (tmpq));
     
    813834      fprintf (stderr, "CreateProcess failed (%d).\n", GetLastError ());
    814835#endif
     836      if (tmp != NULL) {
     837        free(tmp);
     838      }
     839      if (tmpq != NULL) {
     840        free(tmpq);
     841      }         
    815842      return;
    816843    }
     
    818845    {
    819846#ifdef DEBUG
    820       fprintf (stderr, "CreateProcess successfull (%d).\n\n\n\n",
     847      fprintf (stderr, "CreateProcess successful (%d).\n\n\n\n",
    821848               GetLastError ());
    822849#endif
     
    824851  CloseHandle (pi.hProcess);
    825852  CloseHandle (pi.hThread);
     853 
     854  if (tmp != NULL) {
     855    free(tmp);
     856  }
     857  if (tmpq != NULL) {
     858    free(tmpq);
     859  }
     860 
    826861#ifdef DEBUG
    827862  fprintf (stderr, "CreateProcess finished !\n");
     
    13671402                             "InternalError", NULL);
    13681403    }
     1404
    13691405  r_inputs = getMap (request_inputs, "MetaPath");
    13701406  if (r_inputs != NULL)
     
    28212857                    while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE)
    28222858                      cur1 = cur1->next;
     2859                                 
     2860                                        if (request_output_real_format == NULL)
     2861                                          request_output_real_format = dupMaps (&tmpmaps);
     2862                                        else
     2863                                          addMapsToMaps (&request_output_real_format, tmpmaps);
    28232864                  }
    2824               }
    2825             if (request_output_real_format == NULL)
    2826               request_output_real_format = dupMaps (&tmpmaps);
    2827             else
    2828               addMapsToMaps (&request_output_real_format, tmpmaps);
    2829             if (tmpmaps != NULL)
    2830               {
    2831                 freeMaps (&tmpmaps);
    2832                 free (tmpmaps);
    2833                 tmpmaps = NULL;
    28342865              }
    28352866          }
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