[Libreoffice-commits] online.git: loolwsd/Common.hpp loolwsd/discovery.xml loolwsd/LOOLWSD.cpp
Henry Castro
hcastro at collabora.com
Tue Mar 15 15:35:43 UTC 2016
loolwsd/Common.hpp | 1
loolwsd/LOOLWSD.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++--
loolwsd/discovery.xml | 44 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 2 deletions(-)
New commits:
commit 8a2bd1127b025bd8b8713b3b5b38db511c7589e6
Author: Henry Castro <hcastro at collabora.com>
Date: Tue Mar 15 11:35:59 2016 -0400
loolwsd: WOPI, handle request discovery
diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index d6b7b3f..053ce94 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -36,6 +36,7 @@ constexpr int SMALL_MESSAGE_SIZE = READ_BUFFER_SIZE / 2;
static const std::string JailedDocumentRoot = "/user/docs/";
static const std::string CHILD_URI = "/loolws/child?";
+static const std::string LOLEAFLET_PATH = "/loleaflet/dist/loleaflet.html?";
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f98429b..fcb7da6 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -92,6 +92,13 @@ DEALINGS IN THE SOFTWARE.
#include <Poco/Util/OptionException.h>
#include <Poco/Util/OptionSet.h>
#include <Poco/Util/ServerApplication.h>
+#include <Poco/DOM/DOMParser.h>
+#include <Poco/DOM/DOMWriter.h>
+#include <Poco/SAX/InputSource.h>
+#include <Poco/DOM/AutoPtr.h>
+#include <Poco/DOM/Document.h>
+#include <Poco/DOM/NodeList.h>
+#include <Poco/DOM/Element.h>
#include "Admin.hpp"
#include "Auth.hpp"
@@ -148,6 +155,13 @@ using Poco::Util::MissingOptionException;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::ServerApplication;
+using Poco::XML::InputSource;
+using Poco::XML::AutoPtr;
+using Poco::XML::DOMParser;
+using Poco::XML::DOMWriter;
+using Poco::XML::Node;
+using Poco::XML::NodeList;
+using Poco::XML::Element;
std::map<std::string, std::shared_ptr<DocumentBroker>> LOOLWSD::DocBrokers;
std::mutex LOOLWSD::DocBrokersMutex;
@@ -329,7 +343,7 @@ private:
void handlePostRequest(HTTPServerRequest& request, HTTPServerResponse& response, const std::string& id)
{
- Log::info("Post request: " + request.getURI() + "]");
+ Log::info("Post request: [" + request.getURI() + "]");
StringTokenizer tokens(request.getURI(), "/?");
if (tokens.count() >= 2 && tokens[1] == "convert-to")
{
@@ -615,6 +629,37 @@ private:
}
}
+ void handleGetDiscovery(HTTPServerRequest& request, HTTPServerResponse& response)
+ {
+ DOMParser parser;
+ DOMWriter writer;
+ const std::string discoveryPath = Path(Application::instance().commandPath()).parent().toString() + "discovery.xml";
+ const std::string mediaType = "text/xml";
+ const std::string action = "action";
+ const std::string urlsrc = "urlsrc";
+ const std::string uriValue = "http://" + request.getHost() + LOLEAFLET_PATH;
+
+ InputSource inputSrc(discoveryPath);
+ AutoPtr<Poco::XML::Document> docXML = parser.parse(&inputSrc);
+ AutoPtr<NodeList> listNodes = docXML->getElementsByTagName(action);
+
+ for (unsigned long it = 0; it < listNodes->length(); it++)
+ {
+ static_cast<Element*>(listNodes->item(it))->setAttribute(urlsrc, uriValue);
+ }
+
+ std::ostringstream ostrXML;
+ writer.writeNode(ostrXML, docXML);
+
+ response.set("User-Agent", "LOOLWSD WOPI Agent");
+ response.setContentLength(ostrXML.str().length());
+ response.setContentType(mediaType);
+ response.setChunkedTransferEncoding(false);
+
+ std::ostream& ostr = response.send();
+ ostr << ostrXML.str();
+ }
+
public:
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override
@@ -629,7 +674,12 @@ public:
try
{
- if (!(request.find("Upgrade") != request.end() && Poco::icompare(request["Upgrade"], "websocket") == 0))
+ if (request.getMethod() == HTTPRequest::HTTP_GET && request.getURI() == "/hosting/discovery")
+ {
+ // http://server/hosting/discovery
+ handleGetDiscovery(request, response);
+ }
+ else if (!(request.find("Upgrade") != request.end() && Poco::icompare(request["Upgrade"], "websocket") == 0))
{
handlePostRequest(request, response, id);
}
diff --git a/loolwsd/discovery.xml b/loolwsd/discovery.xml
new file mode 100755
index 0000000..ac78c20
--- /dev/null
+++ b/loolwsd/discovery.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<wopi-discovery>
+ <net-zone name="external-http">
+ <app name=" ">
+ <action name="edit" ext="odt"/>
+ </app>
+ <app name="application/vnd.oasis.opendocument.presentation">
+ <action name="edit" ext="odp"/>
+ </app>
+ <app name="application/vnd.oasis.opendocument.spreadsheet">
+ <action name="edit" ext="ods"/>
+ </app>
+ <app name="application/vnd.oasis.opendocument.graphics">
+ <action name="edit" ext="odg"/>
+ </app>
+ <app name="application/msword">
+ <action name="edit" ext="doc"/>
+ </app>
+ <app name="application/vnd.lotus-wordpro">
+ <action name="edit" ext="lwp"/>
+ </app>
+ <app name="image/svg+xml">
+ <action name="edit" ext="svg"/>
+ </app>
+ <app name="application/vnd.ms-powerpoint">
+ <action name="edit" ext="pot"/>
+ </app>
+ <app name="application/vnd.ms-excel">
+ <action name="edit" ext="xla"/>
+ </app>
+ <app name="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
+ <action name="edit" ext="xlsx"/>
+ </app>
+ <app name="application/vnd.visio">
+ <action name="edit" ext="vsd"/>
+ </app>
+ <app name="application/vnd.wordperfect">
+ <action name="edit" ext="wpd"/>
+ </app>
+ <app name="application/vnd.wordperfect">
+ <action name="edit" ext="wpd"/>
+ </app>
+ </net-zone>
+</wopi-discovery>
More information about the Libreoffice-commits
mailing list