Changeset 331


Ignore:
Timestamp:
Sep 2, 2011, 11:20:31 PM (4 years ago)
Author:
djay
Message:

Add the multi-part request support.

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

Legend:

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

    r329 r331  
    7676#endif
    7777
     78  char *strQuery=strdup(cgiQueryString);
    7879  map* tmpMap=NULL;
    7980
     
    107108        buffer[cgiContentLength]=0;
    108109        tmpMap=createMap("request",buffer);
     110        fprintf(stderr,"%s\n",tmpMap->value);
    109111      }else{
    110112        buffer[0]=0;
     
    141143  }
    142144  else{
     145    dumpMap(tmpMap);
    143146    char **array, **arrayStep;
    144147    if (cgiFormEntries(&array) != cgiFormSuccess) {
     
    179182     */
    180183    map* t1=getMap(tmpMap,"request");
    181     if(t1!=NULL){
     184    if(t1!=NULL && strncasecmp(t1->value,"<",1)==0){
    182185      addToMap(tmpMap,"xrequest",t1->value);
    183186      xmlInitParser();
     
    281284      xmlFreeDoc(doc);
    282285      xmlCleanupParser();
     286    }else{
     287      freeMap(&tmpMap);
     288      free(tmpMap);
     289      tmpMap=createMap("not_valid","true");
    283290    }
    284291
     
    297304        token1=strtok_r(NULL,"=",&saveptr1);
    298305      }
    299       if(strcasecmp(name,"metapath")==0)
    300         addToMap(tmpMap,name,value);
     306      addToMap(tmpMap,name,value);
    301307      free(name);
    302308      free(value);
     309      name=NULL;
     310      value=NULL;
    303311      token=strtok_r(NULL,"&",&saveptr);
    304312    }
    305313   
    306314  }
     315
     316
     317  if(strncasecmp(cgiContentType,"multipart/form-data",19)==0){
     318      map* tmp=getMap(tmpMap,"dataInputs");
     319      if(tmp!=NULL){
     320        addToMap(tmpMap,"dataInputs",strstr(strQuery,"dataInputs=")+11);
     321      }
     322    }
    307323
    308324  runRequest(tmpMap);
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r328 r331  
    742742#endif
    743743  int saved_stdout = dup(fileno(stdout));
    744     dup2(fileno(stderr),fileno(stdout));
     744  dup2(fileno(stderr),fileno(stdout));
    745745  t=getServiceFromFile(tmps1,&s1);
    746746  fflush(stdout);
     
    16451645               */
    16461646              else if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
    1647                  xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
     1647                      xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
    16481648                xmlChar *val=
    16491649                  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
     
    17331733  }
    17341734
     1735  maps* tmpReqI=request_input_real_format;
     1736  while(tmpReqI!=NULL){
     1737    char name[1024];
     1738    if(getMap(tmpReqI->content,"isFile")!=NULL){
     1739      if (cgiFormFileName(tmpReqI->name, name, sizeof(name)) == cgiFormSuccess) {
     1740        int BufferLen=1024;
     1741        cgiFilePtr file;
     1742        int targetFile;
     1743        mode_t mode;
     1744        char storageNameOnServer[2048];
     1745        char fileNameOnServer[64];
     1746        char contentType[1024];
     1747        char buffer[BufferLen];
     1748        char *tmpStr=NULL;
     1749        int size;
     1750        int got,t;
     1751        map *path=getMapFromMaps(m,"main","tmpPath");
     1752        cgiFormFileSize(tmpReqI->name, &size);
     1753        cgiFormFileContentType(tmpReqI->name, contentType, sizeof(contentType));
     1754        if (cgiFormFileOpen(tmpReqI->name, &file) == cgiFormSuccess) {
     1755          t=-1;
     1756          while(1){
     1757            tmpStr=strstr(name+t+1,"\\");
     1758            if(NULL==tmpStr)
     1759              tmpStr=strstr(name+t+1,"/");
     1760            if(NULL!=tmpStr)
     1761              t=(int)(tmpStr-name);
     1762            else
     1763              break;
     1764          }
     1765          strcpy(fileNameOnServer,name+t+1);
     1766         
     1767          sprintf(storageNameOnServer,"%s/%s",path->value,fileNameOnServer);
     1768          fprintf(stderr,"Name on server %s\n",storageNameOnServer);
     1769          fprintf(stderr,"fileNameOnServer: %s\n",fileNameOnServer);
     1770          mode=S_IRWXU|S_IRGRP|S_IROTH;
     1771          targetFile = open (storageNameOnServer,O_RDWR|O_CREAT|O_TRUNC,mode);
     1772          if(targetFile<0){
     1773            fprintf(stderr,"could not create the new file,%s\n",fileNameOnServer);         
     1774          }else{
     1775            while (cgiFormFileRead(file, buffer, BufferLen, &got) ==cgiFormSuccess){
     1776              if(got>0)
     1777                write(targetFile,buffer,got);
     1778            }
     1779          }
     1780          addToMap(tmpReqI->content,"lref",storageNameOnServer);
     1781          cgiFormFileClose(file);
     1782          close(targetFile);
     1783          fprintf(stderr,"File \"%s\" has been uploaded",fileNameOnServer);
     1784        }
     1785      }
     1786    }
     1787    tmpReqI=tmpReqI->next;
     1788  }
     1789
    17351790  ensureDecodedBase64(&request_input_real_format);
    17361791
     
    18621917  char *cgiSidL=NULL;
    18631918  if(getenv("CGISID")!=NULL)
    1864         addToMap(request_inputs,"cgiSid",getenv("CGISID"));
     1919    addToMap(request_inputs,"cgiSid",getenv("CGISID"));
    18651920  map* test1=getMap(request_inputs,"cgiSid");
    18661921  if(test1!=NULL){
     
    19592014#ifdef DEBUG
    19602015  dumpMaps(request_output_real_format);
    1961   fprintf(stderr,"Function loaded and returned %d\n",*eres);
    1962   fflush(stderr);
    19632016#endif
    19642017  if(eres!=-1)
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