2018-08-11 Fred Gleason <fredg@paravelsystems.com>

* Fixed regressions in 'RDFormPost' that broke audio importation.
This commit is contained in:
Fred Gleason 2018-08-12 01:18:14 +00:00
parent 3d99fb9a87
commit c92bfd2f6c
3 changed files with 32 additions and 36 deletions

View File

@ -17365,3 +17365,5 @@
2018-08-11 Fred Gleason <fredg@paravelsystems.com> 2018-08-11 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in rddbmgr(8) that could cause segfaults when * Fixed a bug in rddbmgr(8) that could cause segfaults when
determining the current schema verion. determining the current schema verion.
2018-08-11 Fred Gleason <fredg@paravelsystems.com>
* Fixed regressions in 'RDFormPost' that broke audio importation.

View File

@ -24,14 +24,11 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <syslog.h>
#include <rdconf.h> #include <rdconf.h>
#include <rdweb.h> #include <rdweb.h>
#include <rdformpost.h> #include <rdformpost.h>
//Added by qt3to4:
#include <Q3TextStream>
RDFormPost::RDFormPost(RDFormPost::Encoding encoding,unsigned maxsize, RDFormPost::RDFormPost(RDFormPost::Encoding encoding,unsigned maxsize,
bool auto_delete) bool auto_delete)
@ -506,25 +503,17 @@ void RDFormPost::LoadUrlEncoding(char first)
void RDFormPost::LoadMultipartEncoding(char first) void RDFormPost::LoadMultipartEncoding(char first)
{ {
// //
// Create Stream Readers // Create Stream Reader
// //
if((post_stream=fdopen(0,"r"))==NULL) { if((post_stream=fdopen(0,"r"))==NULL) {
post_error=RDFormPost::ErrorInternal; post_error=RDFormPost::ErrorInternal;
return; return;
} }
QFile *file=new QFile();
if(!file->open(QIODevice::ReadOnly,post_stream)) {
delete file;
post_error=RDFormPost::ErrorInternal;
return;
}
post_text_reader=new Q3TextStream(file);
post_text_reader->setEncoding(Q3TextStream::UnicodeUTF8);
// //
// Get Separator Line // Get Separator Line
// //
post_separator=first+post_text_reader->readLine(); post_separator=first+QString::fromUtf8(GetLine()).trimmed();
// //
// Read Mime Parts // Read Mime Parts
@ -539,10 +528,6 @@ void RDFormPost::LoadMultipartEncoding(char first)
post_values[name]=value; post_values[name]=value;
post_filenames[name]=is_file; post_filenames[name]=is_file;
} while(again); } while(again);
delete post_text_reader;
delete file;
post_error=RDFormPost::ErrorOk; post_error=RDFormPost::ErrorOk;
} }
@ -560,7 +545,8 @@ bool RDFormPost::GetMimePart(QString *name,QString *value,bool *is_file)
// Headers // Headers
// //
do { do {
line=post_text_reader->readLine(); // line=post_text_reader->readLine();
line=QString::fromUtf8(GetLine());
QStringList f0=line.split(":"); QStringList f0=line.split(":");
if(f0.size()==2) { if(f0.size()==2) {
if(f0[0].lower()=="content-disposition") { if(f0[0].lower()=="content-disposition") {
@ -580,30 +566,28 @@ bool RDFormPost::GetMimePart(QString *name,QString *value,bool *is_file)
} }
} }
} }
} while(!line.stripWhiteSpace().isEmpty()); } while(!line.trimmed().isEmpty());
// //
// Value // Value
// //
if(*is_file) { if(*is_file) {
char *data=NULL; QByteArray data;
size_t n=0; data=GetLine();
line=QString::fromUtf8(data).trimmed();
n=getline(&data,&n,post_stream);
line=QString(data).stripWhiteSpace();
while(!line.contains(post_separator)) { while(!line.contains(post_separator)) {
write(fd,data,n); write(fd,data,data.length());
n=getline(&data,&n,post_stream); data=GetLine();
line=QString(data).stripWhiteSpace(); line=QString::fromUtf8(data).trimmed();
} }
free(data);
} }
else { else {
line=post_text_reader->readLine(); line=QString::fromUtf8(GetLine());
while(!line.contains(post_separator)) { while((!line.isEmpty())&&(!line.contains(post_separator))) {
*value+=line; *value+=line;
line=post_text_reader->readLine(); line=QString::fromUtf8(GetLine());
} }
*value=value->trimmed();
} }
if(fd>=0) { if(fd>=0) {
@ -611,5 +595,17 @@ bool RDFormPost::GetMimePart(QString *name,QString *value,bool *is_file)
close(fd); close(fd);
} }
return line.right(2)!="--"; return line.trimmed().right(2)!="--";
}
QByteArray RDFormPost::GetLine() const
{
char *data=NULL;
size_t n=0;
n=getline(&data,&n,post_stream);
QByteArray ret(data,n);
free(data);
return ret;
} }

View File

@ -2,7 +2,7 @@
// //
// Handle POST data from an HTML form. // Handle POST data from an HTML form.
// //
// (C) Copyright 2009,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2009-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as // it under the terms of the GNU General Public License version 2 as
@ -26,7 +26,6 @@
#include <qdatastream.h> #include <qdatastream.h>
#include <qstring.h> #include <qstring.h>
#include <qstringlist.h> #include <qstringlist.h>
#include <q3textstream.h>
#include <qvariant.h> #include <qvariant.h>
#include <qhostaddress.h> #include <qhostaddress.h>
@ -67,6 +66,7 @@ class RDFormPost
void LoadUrlEncoding(char first); void LoadUrlEncoding(char first);
void LoadMultipartEncoding(char first); void LoadMultipartEncoding(char first);
bool GetMimePart(QString *name,QString *value,bool *is_file); bool GetMimePart(QString *name,QString *value,bool *is_file);
QByteArray GetLine() const;
QHostAddress post_client_address; QHostAddress post_client_address;
RDFormPost::Encoding post_encoding; RDFormPost::Encoding post_encoding;
RDFormPost::Error post_error; RDFormPost::Error post_error;
@ -77,10 +77,8 @@ class RDFormPost
unsigned post_content_length; unsigned post_content_length;
QString post_content_type; QString post_content_type;
char *post_data; char *post_data;
QString post_separator; QString post_separator;
FILE *post_stream; FILE *post_stream;
Q3TextStream *post_text_reader;
}; };