Changeset 12794


Ignore:
Timestamp:
2006-09-20T15:26:17+12:00 (18 years ago)
Author:
davidb
Message:

Changes to make depositor action work under Windows. Main change is to
make sure 'standard input' is in binary mode before MIME multi-part posts
are parsed.

Location:
trunk/gsdl/src/recpt
Files:
3 edited

Legend:

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

    r12579 r12794  
    8181      break;
    8282    }
     83
    8384    first++;
    8485  }
     86
    8587  return first;
    8688}
     
    109111      text_t tmp_name = md5data(filedata);
    110112      tmp_name = filename_cat(gsdlhome, "tmp", tmp_name);
     113
    111114      char *tmp_name_c = tmp_name.getcstr();
    112115
     
    133136      // size has yet to be implemented
    134137      fu.size = filedata.size();
     138
    135139      fu.tmp_name = tmp_name;
    136140      fileuploads[argname] = fu;
     
    155159  if (findword(content_type_begin, content_type_end, "multipart/form-data") == content_type_end) {
    156160    // a simple post request
     161
    157162    return raw_post_data;
    158163
     
    179184    // first get the boundary from content-type
    180185    text_t::iterator boundary_begin = findword(content_type_begin, content_type_end, "boundary=");
    181     if (boundary_begin+9 < content_type_end) boundary_begin += 9;
     186    if (boundary_begin+9 < content_type_end)
     187      {
     188    // skip over "boundary=" part of string
     189    boundary_begin += 9;
     190      }
    182191    else {
    183192      // error
     193      cerr << "Error: malformed boundary? '" <<  boundary_begin << "'" << endl;
    184194      return "";
    185195    }
    186196    text_t boundary = substr(boundary_begin, getline(boundary_begin, content_type_end, false));
    187197    int boundary_len = boundary.size();
     198
    188199
    189200    text_t argname, argdata, filename, filedata, filetype;
     
    195206      // get the next available line (including the trailing <CRLF>
    196207      text_t line = substr(data_here, getline(data_here, data_end, true));
     208
    197209      data_here += line.size();
    198210      text_t::iterator line_begin = line.begin();
     
    245257    else argdata += line;
    246258      }
     259
    247260    }
    248261
     
    672685    const cgiarginfo *info = argsinfo.getarginfo((*this_file).first);
    673686    if (info != NULL) {
     687
    674688      if ((*info).fileupload && (file_exists((*this_file).second.tmp_name))) {
     689
    675690    args.setargfile((*this_file).first, (*this_file).second);
    676691      }
  • trunk/gsdl/src/recpt/cgiwrapper.cpp

    r12514 r12794  
    2424 *********************************************************************/
    2525
     26#include <stdio.h>
     27#ifdef __WIN32__
     28#include <fcntl.h>
     29#endif
     30
    2631#include "gsdlconf.h"
    2732#include "cgiwrapper.h"
     
    507512      long content_length = (content_length_str ? atoi(content_length_str) : 0);
    508513      if (content_length > 0) {
     514#ifdef __WIN32__
     515    // On Windows it is important that standard input be read in binary
     516    // mode, otherwise end of line "<CR><LF>" is turned into <LF> only
     517    // which breaks the MIME standard (and our parsing code!)
     518
     519    int result = _setmode( _fileno( stdin ), _O_BINARY );
     520    if( result == -1 ) {
     521      cerr << "Warning: Failed to set standard input to binary mode." << endl;
     522      cerr << "         Parsing of multi-part MIME will most likely fail" << endl;
     523    }
     524#endif
     525
    509526    long length = content_length;
    510527    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    
     528
     529    int chars_read = fread(buffer,1,content_length,stdin);
     530
     531    if (chars_read != content_length) {
     532      cerr << "Warning: mismatch between CONTENT_LENGTH and data read from standard in" << endl;
     533    }
     534
    521535    argstr.setcarr((char *)buffer, content_length);     
     536
    522537    text_t content_type;
    523538    char *content_type_str = getenv("CONTENT_TYPE");
  • trunk/gsdl/src/recpt/depositoraction.cpp

    r12576 r12794  
    270270
    271271  fileupload_t *fileupload = args.getargfile("di1userfileinfo");
     272
    272273  if (fileupload != NULL) {
     274
    273275    if (!(*fileupload).tmp_name.empty() && file_exists((*fileupload).tmp_name)) {
    274276      // create the timestamp
    275277      time_t timestamp = time(NULL);
    276278      text_t timestamp_str(timestamp);
     279
    277280      args["di1timestamp"] = timestamp_str;
    278281
     
    634637    cerr << "Unable to copy " << tmpfile << " to " << filename << endl;
    635638      }
    636       cerr << "*** filename = " << filename_textt << endl;
    637639     
    638640      //write the metadata file
Note: See TracChangeset for help on using the changeset viewer.