Changeset 12514


Ignore:
Timestamp:
2006-08-24T11:16:05+12:00 (18 years ago)
Author:
kjdon
Message:

Added Stefan's fileupload code to replace use of cgicc by depositor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/cgiwrapper.cpp

    r12400 r12514  
    2626#include "gsdlconf.h"
    2727#include "cgiwrapper.h"
    28 #include "cgiutils.h"
    2928#include "recptconfig.h"
    3029#include "fileutil.h"
     30#include "cgiutils.h"
    3131#include <stdlib.h>
    3232#include <assert.h>
     
    4242#  include <fstream>
    4343#endif
    44 
    45 #include "cgicc/Cgicc.h"
    46 
    47 using namespace cgicc;
    48 extern Cgicc* formData;
    49 
    5044
    5145#ifdef USE_FASTCGI
     
    452446// should equal "".
    453447void cgiwrapper (receptionist &recpt, text_t collection) {
    454  
    455448  int numrequests = 0;
    456449  bool debug = false;
     
    468461#endif
    469462
    470   // get the query string if it is not being run as a fastcgi
    471   // script
    472   text_t argstr = g_EmptyText;
    473   cgiargsclass args;
    474   char *aURIStr;
    475   if (!isfastcgi) {
    476    
    477     // Iterate through the vector, and synthesis argstr
    478     bool first = true;
    479 
    480     for(const_form_iterator iter = formData->getElements().begin();
    481     iter != formData->getElements().end();
    482     ++iter) {
    483      
    484       const char* name_cstr = iter->getName().c_str();
    485       const char* value_cstr = iter->getValue().c_str();
    486       // the args have been decoded and as we are building up the argument
    487       // string again, we need to re encode them
    488       text_t value_textt = cgi_safe(value_cstr);
    489       const char * safe_value_cstr = value_textt.getcstr();
    490       if (first) {
    491     argstr = name_cstr;
    492     argstr.append("=");
    493     argstr.append(safe_value_cstr);
    494     first = false;
    495       }
    496       else {
    497     argstr.append("&");
    498     argstr.append(name_cstr);
    499     argstr.append("=");
    500     argstr.append(safe_value_cstr);
    501       }
    502       delete [] safe_value_cstr;
    503     }   
    504   }
    505  
    506   if (debug) {
    507     cout << "Configuring Greenstone...\n";
    508     cout << flush;
    509   }
    510 
     463  // we need gsdlhome to do fileupload stuff, so moved this configure stuff before the get argstr stuff
    511464  // init stuff - we can't output error pages directly with
    512465  // fastcgi so the pages are stored until we can output them
     
    540493    page_errorcollect (gsdlhome, errorpage, debug);
    541494  }
     495  // get the query string if it is not being run as a fastcgi
     496  // script
     497  text_t argstr = g_EmptyText;
     498  fileupload_tmap fileuploads;
     499  cgiargsclass args;
     500  char *aURIStr;
     501  if (!isfastcgi) {
     502    char *request_method_str = getenv("REQUEST_METHOD");
     503    char *content_length_str = getenv("CONTENT_LENGTH");
     504    if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
     505    content_length_str != NULL)  {
     506      // POST form data
     507      long content_length = (content_length_str ? atoi(content_length_str) : 0);
     508      if (content_length > 0) {
     509    long length = content_length;
     510    unsigned char * buffer = new unsigned char[content_length];
     511    char c;
     512    int i=0;
     513    do {
     514      cin.get(c);
     515      if (cin.eof()) break;
     516      buffer[i] = c;
     517      ++i;
     518      --length;
     519    } while (length > 0);
     520   
     521    argstr.setcarr((char *)buffer, content_length);     
     522    text_t content_type;
     523    char *content_type_str = getenv("CONTENT_TYPE");
     524    if (content_type_str) content_type = content_type_str;
     525    argstr = parse_post_data(content_type, argstr, fileuploads, gsdlhome);
     526      }
     527    } else {
     528      aURIStr = getenv("QUERY_STRING");
     529      if ((request_method_str != NULL && strcmp(request_method_str, "GET") == 0)
     530      || aURIStr != NULL) {
     531    // GET form data
     532    if (aURIStr != NULL) argstr = aURIStr;
     533      } else {
     534    // debugging from command line
     535    debug = true;
     536      }
     537    }
     538  }
     539
     540  if (debug) {
     541    cout << "Configuring Greenstone...\n";
     542    cout << flush;
     543  }
     544
    542545
    543546  if (errorpage.empty()) {
     
    672675      // parse the cgi arguments and produce the resulting page if there
    673676      // has been no errors so far
    674       if (!recpt.parse_cgi_args (argstr, args, errout, fastcgienv)) {
     677      if (!recpt.parse_cgi_args (argstr, fileuploads, args, errout, fastcgienv)) {
    675678    errout.close ();
    676679    page_errorparseargs(gsdlhome, debug, errorpage);
     
    691694#endif
    692695    }
    693 
     696    // clean up any files that were uploaded
     697    fileupload_tmap::const_iterator this_file = fileuploads.begin();
     698    fileupload_tmap::const_iterator end_file = fileuploads.end();
     699    while (this_file != end_file)
     700      {
     701    if (file_exists((*this_file).second.tmp_name))
     702      {
     703        char *thefile = (*this_file).second.tmp_name.getcstr();
     704        unlink(thefile);
     705        delete [] thefile;
     706      }
     707    ++this_file;
     708      }
     709   
    694710    // there was an error, output the error page
    695711    if (!errorpage.empty()) {
Note: See TracChangeset for help on using the changeset viewer.