diff options
| author | Roland Stigge <stigge@antcom.de> | 2018-01-08 16:57:47 +0100 | 
|---|---|---|
| committer | Roland Stigge <stigge@antcom.de> | 2018-01-08 16:57:47 +0100 | 
| commit | d8eae5827b2599bb1fb125aed47d73bf82d1ff10 (patch) | |
| tree | 97c835f8580e4eb102185b2a7cbbe9c2e559db5f /src | |
| parent | 34f772d353839b5febcc0cad2a54e29716dcb6c8 (diff) | |
Debian package, fix list xml
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 3 | ||||
| -rw-r--r-- | src/webbox.cpp | 41 | 
2 files changed, 38 insertions, 6 deletions
| diff --git a/src/Makefile b/src/Makefile index e960f67..d7f3847 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,6 @@ +ARCH=$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)  TARGET=query -CPPFLAGS=-Wall -O2 -fPIC -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtCore +CPPFLAGS=-Wall -O2 -fPIC -I/usr/include/$(ARCH)/qt5 -I/usr/include/$(ARCH)/qt5/QtCore  LDFLAGS=-Wall -O2 -fPIC -lstdc++ -lfcgi -lQt5Core  OBJS=webbox.o 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 <QDir>  #include <QFileInfo>  #include <QXmlStreamReader> +#include <QXmlStreamWriter>  #include <QDateTime>  #include <QProcess>  #include <QTemporaryFile> @@ -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("</body></html>\r\n", request.out);  		} else +#endif  		if (command == "list") {  			FCGX_PutS("Content-Type: text/xml\r\n\r\n", request.out); -			FCGX_PutS("<list>\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("<listentry type=\"%1\">%2</listentry>\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("</list>\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); | 
