summaryrefslogtreecommitdiffhomepage
path: root/src/webbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webbox.cpp')
-rw-r--r--src/webbox.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/webbox.cpp b/src/webbox.cpp
index 4575551..8f85332 100644
--- a/src/webbox.cpp
+++ b/src/webbox.cpp
@@ -290,6 +290,116 @@ int main(int argc, char* argv[]) {
}
}
}
+ } else if (command == "delete") { // POST!
+ QString contentLengthString(FCGX_GetParam("CONTENT_LENGTH", request.envp));
+ bool ok;
+ int contentLength = contentLengthString.toInt(&ok);
+
+ if (!ok) {
+ FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
+ FCGX_PutS(QString("Bad content length").toUtf8().data(), request.out);
+ } else {
+ QByteArray content(contentLength, 0);
+
+ int result = FCGX_GetStr(content.data(), content.size(), request.in);
+ if (result != content.size()) {
+ FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
+ FCGX_PutS(QString("Read error (%1/%2)").arg(result).arg(content.size()).toUtf8().data(), request.out);
+ } else {
+ QXmlStreamReader xml(content);
+
+ QString response = "";
+
+ while (!xml.atEnd()) {
+ while (xml.readNextStartElement()) {
+ if (xml.name() == "files") {
+ while (xml.readNextStartElement()) {
+ if (xml.name() == "file") {
+ QString filename = xml.readElementText();
+
+ QFileInfo fileInfo(path + "/" + filename);
+ if (fileInfo.isDir()) {
+ QDir dir(path);
+ if (!dir.rmdir(filename)) {
+ response += QString("Error on removing directory %1<br/>").arg(filename);
+ }
+ } else if (fileInfo.isFile()) {
+ QFile file(path + "/" + filename);
+ if (!file.remove()) {
+ response += QString("Error on removing file %1<br/>").arg(filename);
+ }
+ } else {
+ response += QString("Error: %1 is neither file nor directory.<br/>").arg(filename);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (response == "") {
+ response = "OK";
+ }
+
+ FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
+ FCGX_PutS(response.toUtf8().data(), request.out);
+ }
+ }
+ } else if (command == "move") { // POST!
+ QString contentLengthString(FCGX_GetParam("CONTENT_LENGTH", request.envp));
+ bool ok;
+ int contentLength = contentLengthString.toInt(&ok);
+
+ if (!ok) {
+ FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
+ FCGX_PutS(QString("Bad content length").toUtf8().data(), request.out);
+ } else {
+ QByteArray content(contentLength, 0);
+
+ int result = FCGX_GetStr(content.data(), content.size(), request.in);
+ if (result != content.size()) {
+ FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
+ FCGX_PutS(QString("Read error (%1/%2)").arg(result).arg(content.size()).toUtf8().data(), request.out);
+ } else {
+ QXmlStreamReader xml(content);
+
+ QString response = "";
+ QString targetDir;
+
+ while (!xml.atEnd()) {
+ while (xml.readNextStartElement()) {
+ if (xml.name() == "request") {
+ while (xml.readNextStartElement()) {
+ if (xml.name() == "target") {
+ targetDir = xml.readElementText();
+ } else if (xml.name() == "file") {
+ QString filename = xml.readElementText();
+
+ QFileInfo fileInfo(path + "/" + filename);
+ if (fileInfo.isDir()) {
+ response += QString("Note: Moving directory %1 not supported.<br/>").arg(filename);
+ } else if (fileInfo.isFile()) {
+ QFile file(path + "/" + filename);
+ if (!file.rename(path + "/" + targetDir + "/" + filename)) {
+ response += QString("Error on moving file %1<br/>").arg(filename);
+ }
+ } else {
+ response += QString("Error: %1 is neither file nor directory.<br/>").arg(filename);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (response == "") {
+ response = "OK";
+ }
+
+ FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
+ FCGX_PutS(response.toUtf8().data(), request.out);
+ }
+ }
} else if (command == "upload") { // POST!
QString contentLengthString(FCGX_GetParam("CONTENT_LENGTH", request.envp));
bool ok;