[Libreoffice-commits] online.git: loolwsd/FileServer.hpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
Pranav Kant
pranavk at collabora.com
Mon Mar 21 14:35:40 UTC 2016
loolwsd/FileServer.hpp | 19 +++++++++----------
loolwsd/LOOLWSD.cpp | 11 +++++++++++
loolwsd/LOOLWSD.hpp | 1 +
3 files changed, 21 insertions(+), 10 deletions(-)
New commits:
commit a5f8ba44a2b9bb26ec9196a306f9f1b4d60afc79
Author: Pranav Kant <pranavk at collabora.com>
Date: Sun Mar 20 19:37:24 2016 +0530
loolwsd: Allow specifying custom file server root
By default, use git directory root.
Change-Id: I4ee1173c43f313de3abb1732e6a7401169896189
diff --git a/loolwsd/FileServer.hpp b/loolwsd/FileServer.hpp
index 9c62e41..102ace1 100644
--- a/loolwsd/FileServer.hpp
+++ b/loolwsd/FileServer.hpp
@@ -32,6 +32,7 @@
#include <Poco/Util/Timer.h>
#include "Common.hpp"
+#include "LOOLWSD.hpp"
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPRequestHandler;
@@ -55,8 +56,8 @@ public:
std::vector<std::string> requestSegments;
requestUri.getPathSegments(requestSegments);
- // FIXME: We might want to package all dist files from leaflet to some other dir (?)
- const std::string loleafletPath = Poco::Path(Application::instance().commandPath()).parent().parent().toString() + "loleaflet";
+ // TODO: We might want to package all files from leaflet to some other dir and restrict
+ // file serving to it (?)
const std::string endPoint = requestSegments[requestSegments.size() - 1];
if (request.getMethod() == HTTPRequest::HTTP_GET)
@@ -79,7 +80,7 @@ public:
Poco::Net::HTTPCookie cookie("jwt", jwtToken);
response.addCookie(cookie);
response.setContentType(htmlMimeType);
- response.sendFile(loleafletPath + "/debug/document/" + endPoint, htmlMimeType);
+ response.sendFile(LOOLWSD::FileServerRoot + requestUri.getPath(), htmlMimeType);
}
else
{
@@ -87,12 +88,12 @@ public:
throw Poco::Net::NotAuthenticatedException("Wrong credentials.");
}
}
- else if (requestSegments.size() > 1 && requestSegments[0] == "dist")
+ else
{
const std::string filePath = requestUri.getPath();
const std::size_t extPoint = endPoint.find_last_of(".");
if (extPoint == std::string::npos)
- return;
+ throw Poco::FileNotFoundException("Invalid file.");
const std::string fileType = endPoint.substr(extPoint + 1);
std::string mimeType;
@@ -100,15 +101,13 @@ public:
mimeType = "application/javascript";
else if (fileType == "css")
mimeType = "text/css";
+ else if (fileType == "html")
+ mimeType = "text/html";
else
mimeType = "text/plain";
response.setContentType(mimeType);
- response.sendFile(loleafletPath + request.getURI(), mimeType);
- }
- else
- {
- throw Poco::FileNotFoundException("");
+ response.sendFile(LOOLWSD::FileServerRoot + requestUri.getPath(), mimeType);
}
}
}
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ba30f41..eb499cc 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -935,6 +935,7 @@ std::string LOOLWSD::SysTemplate;
std::string LOOLWSD::LoTemplate;
std::string LOOLWSD::ChildRoot;
std::string LOOLWSD::LoSubPath = "lo";
+std::string LOOLWSD::FileServerRoot;
int LOOLWSD::NumPreSpawnedChildren = 10;
bool LOOLWSD::DoTest = false;
@@ -1009,6 +1010,11 @@ void LOOLWSD::defineOptions(OptionSet& optionSet)
.repeatable(false)
.argument("relative path"));
+ optionSet.addOption(Option("fileserverroot", "", "Path to the directory that should be considered root for the file server (default: '../loleaflet/').")
+ .required(false)
+ .repeatable(false)
+ .argument("directory"));
+
optionSet.addOption(Option("numprespawns", "", "Number of child processes to keep started in advance and waiting for new clients.")
.required(false)
.repeatable(false)
@@ -1045,6 +1051,8 @@ void LOOLWSD::handleOption(const std::string& optionName, const std::string& val
ChildRoot = value;
else if (optionName == "losubpath")
LoSubPath = value;
+ else if (optionName == "fileserverroot")
+ FileServerRoot = value;
else if (optionName == "numprespawns")
NumPreSpawnedChildren = std::stoi(value);
else if (optionName == "test")
@@ -1140,6 +1148,9 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
else if (ChildRoot[ChildRoot.size() - 1] != Path::separator())
ChildRoot += Path::separator();
+ if (FileServerRoot.empty())
+ FileServerRoot = Path(Application::instance().commandPath()).parent().parent().toString();
+
if (ClientPortNumber == MASTER_PORT_NUMBER)
throw IncompatibleOptionsException("port");
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 3fc2531..5504888 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -44,6 +44,7 @@ public:
static std::string LoTemplate;
static std::string ChildRoot;
static std::string LoSubPath;
+ static std::string FileServerRoot;
//static Auth AuthAgent;
static const std::string PIDLOG;
More information about the Libreoffice-commits
mailing list