From d8eae5827b2599bb1fb125aed47d73bf82d1ff10 Mon Sep 17 00:00:00 2001 From: Roland Stigge Date: Mon, 8 Jan 2018 16:57:47 +0100 Subject: Debian package, fix list xml --- src/webbox.cpp | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'src/webbox.cpp') diff --git a/src/webbox.cpp b/src/webbox.cpp index 71f023c..e991266 100644 --- a/src/webbox.cpp +++ b/src/webbox.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,25 @@ #define PROGRAMVERSION "1.0" #define BUFSIZE 1000000 +// XML special characters: +// < : < +// > : > +// & : & +// " : " +// ' : ' +// +// here:replace & +QString escapeXML(QString s) { + s.replace("&", "&"); + return s; +} + +// revert escapeXML(); +QString unescapeXML(QString s) { + s.replace("&", "&"); + return s; +} + // supported httpStatusCode: // 400 Bad Request // 403 Forbidden @@ -101,6 +121,8 @@ int main(int argc, char* argv[]) { QString path = webboxPath + pathInfo; +#if 0 + // only for debugging if (command == "diag") { FCGX_PutS("Content-Type: text/html\r\n\r\n", request.out); @@ -119,19 +141,28 @@ int main(int argc, char* argv[]) { FCGX_PutS("\r\n", request.out); } else +#endif if (command == "list") { FCGX_PutS("Content-Type: text/xml\r\n\r\n", request.out); - FCGX_PutS("\r\n", request.out); - QDir dir(path); - QFileInfoList dirEntryList = dir.entryInfoList(QDir::NoDot | QDir::AllEntries, QDir::DirsFirst | QDir::Name); + QFileInfoList dirEntryList = dir.entryInfoList(QDir::NoDot | QDir::AllEntries, QDir::DirsFirst | QDir::Name | QDir::IgnoreCase); + + QByteArray xmlData; + QXmlStreamWriter xmlWriter(&xmlData); + xmlWriter.writeStartDocument(); + xmlWriter.writeStartElement("list"); foreach(QFileInfo i, dirEntryList) { if (pathInfo != "/" || i.fileName() != "..") { // skip on ".." in "/" - FCGX_PutS(QString("%2\r\n").arg(i.isDir() ? "dir" : "file").arg(i.fileName()).toUtf8().data(), request.out); + xmlWriter.writeStartElement("listentry"); + xmlWriter.writeAttribute("type", i.isDir() ? "dir" : "file"); + xmlWriter.writeCharacters(i.fileName()); + xmlWriter.writeEndElement(); } } - FCGX_PutS("\r\n", request.out); + xmlWriter.writeEndElement(); // list + xmlWriter.writeEndDocument(); + FCGX_PutS(xmlData.data(), request.out); } else if (command == "title") { FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out); FCGX_PutS(getenv("WEBBOX_NAME"), request.out); -- cgit v1.2.3