diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/webbox.cpp | 60 | 
1 files changed, 55 insertions, 5 deletions
| diff --git a/src/webbox.cpp b/src/webbox.cpp index b5d35c2..190d7e7 100644 --- a/src/webbox.cpp +++ b/src/webbox.cpp @@ -7,6 +7,8 @@  #include <QFileInfo>  #include <QXmlStreamReader>  #include <QDateTime> +#include <QProcess> +#include <QTemporaryFile>  #define PROGRAMVERSION "1.0"  #define BUFSIZE 1000000 @@ -218,6 +220,16 @@ int main(int argc, char* argv[]) {  					QXmlStreamReader xml(content);  					QByteArray zipData; +					QStringList argumentList; +					QTemporaryFile tempfile(QDir::tempPath() + "/webboxXXXXXX.zip"); +					tempfile.open(); +					QFileInfo fileInfo(tempfile); +					QString tempfilePath = fileInfo.absolutePath(); +					QString tempfileName = fileInfo.fileName(); +					tempfile.close(); +					tempfile.remove(); + +					argumentList << tempfileName; // zip filename  					while (!xml.atEnd()) {  						while (xml.readNextStartElement()) { @@ -226,17 +238,55 @@ int main(int argc, char* argv[]) {  									if (xml.name() == "file") {  										QString filename = xml.readElementText(); -										zipData.append(filename.toUtf8()); // TBD +										argumentList.append(path + filename); // add parts  									}  								}  							}  						}  					} -					FCGX_PutS(QString("Content-Disposition: attachment; filename=\"%1\"\r\n").arg("webbox-download.zip").toUtf8().data(), request.out); -					FCGX_PutS("Content-Type: application/octet-stream\r\n\r\n", request.out); -					 -					FCGX_PutStr(zipData.data(), zipData.size(), request.out); +					QProcess process; +					process.setWorkingDirectory(tempfilePath); +					process.setProgram("/usr/bin/zip"); +					process.setArguments(argumentList); +					process.start(); +					process.waitForFinished(); + +					QString debugText = process.readAll(); +					process.setReadChannel(QProcess::StandardError); +					debugText += process.readAll(); + +					if (process.state() != QProcess::NotRunning || +					    process.exitCode() != 0 || +					    process.exitStatus() != QProcess::NormalExit) +					{ +						FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out); +						FCGX_PutS(QString("Error running process: %1 %2 %3 %4 %5 %6 %7"). +							  arg(process.state()). +							  arg(process.exitCode()). +							  arg(process.exitStatus()). +							  arg(tempfilePath). +							  arg(tempfileName). +							  arg(argumentList[0]). +							  arg(debugText).toUtf8().data(), request.out); +					} else { + +						QFile tempfile(tempfilePath + "/" + tempfileName); +						if (!tempfile.open(QIODevice::ReadOnly)) { +							FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out); +							FCGX_PutS(QString("Error reading file").toUtf8().data(), request.out); +						} else { +							zipData = tempfile.readAll(); + +							FCGX_PutS(QString("Content-Disposition: attachment; filename=\"%1\"\r\n").arg("webbox-download.zip").toUtf8().data(), request.out); +							FCGX_PutS("Content-Type: application/octet-stream\r\n\r\n", request.out); +							 +							FCGX_PutStr(zipData.data(), zipData.size(), request.out); +						} + +						tempfile.close(); +						tempfile.remove(); +					}  				}  			}  		} else if (command == "upload") { // POST! | 
