[Libreoffice-commits] online.git: common/Common.hpp net/Socket.cpp test/WopiTestServer.hpp wsd/FileServer.cpp wsd/LOOLWSD.cpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon May 20 11:30:27 UTC 2019


 common/Common.hpp       |    4 +-
 net/Socket.cpp          |    2 -
 test/WopiTestServer.hpp |   42 ++++++++++++++---------------
 wsd/FileServer.cpp      |   52 ++++++++++++++++++------------------
 wsd/LOOLWSD.cpp         |   68 ++++++++++++++++++++++++------------------------
 5 files changed, 84 insertions(+), 84 deletions(-)

New commits:
commit 046ab32e46831f0f44d912e69f0079c1c7f9d4f7
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon May 20 12:11:38 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon May 20 12:30:01 2019 +0100

    Use compile-time rather than run-time string concatenation.
    
    Saves some time & space.
    
    Change-Id: If1e62056447fb7e8f26e8cf107451876adf3fecb

diff --git a/common/Common.hpp b/common/Common.hpp
index af37a77dd..f1ccc4c61 100644
--- a/common/Common.hpp
+++ b/common/Common.hpp
@@ -40,10 +40,10 @@ constexpr const char LO_JAIL_SUBPATH[] = "lo";
 constexpr const char CAPABILITIES_END_POINT[] = "/hosting/capabilities";
 
 /// The HTTP response User-Agent.
-constexpr const char* HTTP_AGENT_STRING = "LOOLWSD HTTP Agent " LOOLWSD_VERSION;
+#define HTTP_AGENT_STRING "LOOLWSD HTTP Agent " LOOLWSD_VERSION
 
 /// The WOPI User-Agent.
-constexpr const char* WOPI_AGENT_STRING = "LOOLWSD WOPI Agent " LOOLWSD_VERSION;
+#define WOPI_AGENT_STRING "LOOLWSD WOPI Agent " LOOLWSD_VERSION
 
 // The client port number, both loolwsd and the kits have this.
 extern int ClientPortNumber;
diff --git a/net/Socket.cpp b/net/Socket.cpp
index fb7e701ee..c1225877a 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -296,7 +296,7 @@ void SocketPoll::clientRequestWebsocketUpgrade(const std::shared_ptr<StreamSocke
         "Cache-Control:no-cache\r\n"
         "Pragma:no-cache\r\n"
         "Sec-WebSocket-Version:13\r\n"
-        "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
+        "User-Agent: " WOPI_AGENT_STRING "\r\n"
         "\r\n";
     socket->send(oss.str());
     websocketHandler->onConnect(socket);
diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp
index 237957ba2..8d5fb4bdf 100644
--- a/test/WopiTestServer.hpp
+++ b/test/WopiTestServer.hpp
@@ -132,11 +132,11 @@ protected:
 
             std::ostringstream oss;
             oss << "HTTP/1.1 200 OK\r\n"
-                << "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
-                << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-                << "Content-Length: " << responseString.size() << "\r\n"
-                << "Content-Type: " << mimeType << "\r\n"
-                << "\r\n"
+                "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+                "User-Agent: " WOPI_AGENT_STRING "\r\n"
+                "Content-Length: " << responseString.size() << "\r\n"
+                "Content-Type: " << mimeType << "\r\n"
+                "\r\n"
                 << responseString;
 
             socket->send(oss.str());
@@ -155,11 +155,11 @@ protected:
 
             std::ostringstream oss;
             oss << "HTTP/1.1 200 OK\r\n"
-                << "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
-                << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-                << "Content-Length: " << _fileContent.size() << "\r\n"
-                << "Content-Type: " << mimeType << "\r\n"
-                << "\r\n"
+                "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+                "User-Agent: " WOPI_AGENT_STRING "\r\n"
+                "Content-Length: " << _fileContent.size() << "\r\n"
+                "Content-Type: " << mimeType << "\r\n"
+                "\r\n"
                 << _fileContent;
 
             socket->send(oss.str());
@@ -189,11 +189,11 @@ protected:
 
             std::ostringstream oss;
             oss << "HTTP/1.1 200 OK\r\n"
-                << "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
-                << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-                << "Content-Length: " << content.size() << "\r\n"
-                << "Content-Type: application/json\r\n"
-                << "\r\n"
+                "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+                "User-Agent: " WOPI_AGENT_STRING "\r\n"
+                "Content-Length: " << content.size() << "\r\n"
+                "Content-Type: application/json\r\n"
+                "\r\n"
                 << content;
 
             socket->send(oss.str());
@@ -216,9 +216,9 @@ protected:
                 {
                     std::ostringstream oss;
                     oss << "HTTP/1.1 409 Conflict\r\n"
-                        << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-                        << "\r\n"
-                        << "{\"LOOLStatusCode\":" << static_cast<int>(LOOLStatusCode::DocChanged) << "}";
+                        "User-Agent: " WOPI_AGENT_STRING "\r\n"
+                        "\r\n"
+                        "{\"LOOLStatusCode\":" << static_cast<int>(LOOLStatusCode::DocChanged) << "}";
 
                     socket->send(oss.str());
                     socket->shutdown();
@@ -235,9 +235,9 @@ protected:
 
             std::ostringstream oss;
             oss << "HTTP/1.1 200 OK\r\n"
-                << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-                << "\r\n"
-                << "{\"LastModifiedTime\": \"" << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::ISO8601_FRAC_FORMAT) << "\" }";
+                "User-Agent: " WOPI_AGENT_STRING "\r\n"
+                "\r\n"
+                "{\"LastModifiedTime\": \"" << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::ISO8601_FRAC_FORMAT) << "\" }";
 
             socket->send(oss.str());
             socket->shutdown();
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 1e549018c..707e0b33d 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -356,13 +356,13 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
                     Poco::DateTime now;
                     Poco::DateTime later(now.utcTime(), int64_t(1000)*1000 * 60 * 60 * 24 * 128);
                     oss << "HTTP/1.1 304 Not Modified\r\n"
-                        << "Date: " << Poco::DateTimeFormatter::format(
+                        "Date: " << Poco::DateTimeFormatter::format(
                             now, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
-                        << "Expires: " << Poco::DateTimeFormatter::format(
+                        "Expires: " << Poco::DateTimeFormatter::format(
                             later, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
-                        << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-                        << "Cache-Control: max-age=11059200\r\n"
-                        << "\r\n";
+                        "User-Agent: " WOPI_AGENT_STRING "\r\n"
+                        "Cache-Control: max-age=11059200\r\n"
+                        "\r\n";
                     socket->send(oss.str());
                     socket->shutdown();
                     return;
@@ -438,16 +438,16 @@ void FileServerRequestHandler::sendError(int errorCode, const Poco::Net::HTTPReq
     const std::string& path = requestUri.getPath();
     std::ostringstream oss;
     oss << "HTTP/1.1 " << errorCode << "\r\n"
-        << "Content-Type: text/html charset=UTF-8\r\n"
-        << "Date: " << Util::getHttpTimeNow() << "\r\n"
-        << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
+        "Content-Type: text/html charset=UTF-8\r\n"
+        "Date: " << Util::getHttpTimeNow() << "\r\n"
+        "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
         << extraHeader
         << "\r\n";
     if (!shortMessage.empty())
     {
         oss << "<h1>Error: " << shortMessage << "</h1>"
-            << "<p>" << longMessage << " " << path << "</p>"
-            << "<p>Please contact your system administrator.</p>";
+            "<p>" << longMessage << " " << path << "</p>"
+            "<p>Please contact your system administrator.</p>";
     }
     socket->send(oss.str());
 }
@@ -660,27 +660,27 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
 
     std::ostringstream oss;
     oss << "HTTP/1.1 200 OK\r\n"
-        << "Date: " << Util::getHttpTimeNow() << "\r\n"
-        << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
-        << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-        << "Cache-Control:max-age=11059200\r\n"
-        << "ETag: \"" LOOLWSD_VERSION_HASH "\"\r\n"
-        << "Content-Length: " << preprocess.size() << "\r\n"
-        << "Content-Type: " << mimeType << "\r\n"
-        << "X-Content-Type-Options: nosniff\r\n"
-        << "X-XSS-Protection: 1; mode=block\r\n"
-        << "Referrer-Policy: no-referrer\r\n";
+        "Date: " << Util::getHttpTimeNow() << "\r\n"
+        "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
+        "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
+        "Cache-Control:max-age=11059200\r\n"
+        "ETag: \"" LOOLWSD_VERSION_HASH "\"\r\n"
+        "Content-Length: " << preprocess.size() << "\r\n"
+        "Content-Type: " << mimeType << "\r\n"
+        "X-Content-Type-Options: nosniff\r\n"
+        "X-XSS-Protection: 1; mode=block\r\n"
+        "Referrer-Policy: no-referrer\r\n";
 
     // Document signing: if endpoint URL is configured, whitelist that for
     // iframe purposes.
     std::ostringstream cspOss;
     cspOss << "Content-Security-Policy: default-src 'none'; "
-           << "frame-src 'self' blob: " << documentSigningURL << "; "
-           << "connect-src 'self' " << host << "; "
-           << "script-src 'unsafe-inline' 'self'; "
-           << "style-src 'self' 'unsafe-inline'; "
-           << "font-src 'self' data:; "
-           << "object-src blob:; ";
+           "frame-src 'self' blob: " << documentSigningURL << "; "
+           "connect-src 'self' " << host << "; "
+           "script-src 'unsafe-inline' 'self'; "
+           "style-src 'self' 'unsafe-inline'; "
+           "font-src 'self' data:; "
+           "object-src blob:; ";
 
     // Frame ancestors: Allow loolwsd host, wopi host and anything configured.
     std::string configFrameAncestor = config.getString("net.frame_ancestors", "");
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 2bb4b37dc..69e74114a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2034,10 +2034,10 @@ private:
             LOG_ERR("Looks like SSL/TLS traffic on plain http port");
             std::ostringstream oss;
             oss << "HTTP/1.1 400\r\n"
-                << "Date: " << Util::getHttpTimeNow() << "\r\n"
-                << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-                << "Content-Length: 0\r\n"
-                << "\r\n";
+                "Date: " << Util::getHttpTimeNow() << "\r\n"
+                "User-Agent: " WOPI_AGENT_STRING "\r\n"
+                "Content-Length: 0\r\n"
+                "\r\n";
             socket->send(oss.str());
             socket->shutdown();
             return;
@@ -2133,10 +2133,10 @@ private:
                     // Bad request.
                     std::ostringstream oss;
                     oss << "HTTP/1.1 400\r\n"
-                        << "Date: " << Util::getHttpTimeNow() << "\r\n"
-                        << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-                        << "Content-Length: 0\r\n"
-                        << "\r\n";
+                        "Date: " << Util::getHttpTimeNow() << "\r\n"
+                        "User-Agent: " WOPI_AGENT_STRING "\r\n"
+                        "Content-Length: 0\r\n"
+                        "\r\n";
                     socket->send(oss.str());
                     socket->shutdown();
                     return;
@@ -2197,11 +2197,11 @@ private:
 
         std::ostringstream oss;
         oss << "HTTP/1.1 200 OK\r\n"
-            << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
-            << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-            << "Content-Length: " << responseString.size() << "\r\n"
-            << "Content-Type: " << mimeType << "\r\n"
-            << "\r\n";
+            "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
+            "User-Agent: " WOPI_AGENT_STRING "\r\n"
+            "Content-Length: " << responseString.size() << "\r\n"
+            "Content-Type: " << mimeType << "\r\n"
+            "\r\n";
 
         if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET)
         {
@@ -2241,12 +2241,12 @@ private:
         // TODO: Refactor this to some common handler.
         std::ostringstream oss;
         oss << "HTTP/1.1 200 OK\r\n"
-            << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
-            << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-            << "Content-Length: " << xml.size() << "\r\n"
-            << "Content-Type: text/xml\r\n"
-            << "X-Content-Type-Options: nosniff\r\n"
-            << "\r\n"
+            "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
+            "User-Agent: " WOPI_AGENT_STRING "\r\n"
+            "Content-Length: " << xml.size() << "\r\n"
+            "Content-Type: text/xml\r\n"
+            "X-Content-Type-Options: nosniff\r\n"
+            "\r\n"
             << xml;
 
         std::shared_ptr<StreamSocket> socket = _socket.lock();
@@ -2263,12 +2263,12 @@ private:
 
         std::ostringstream oss;
         oss << "HTTP/1.1 200 OK\r\n"
-            << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
-            << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-            << "Content-Length: " << capabilities.size() << "\r\n"
-            << "Content-Type: application/json\r\n"
-            << "X-Content-Type-Options: nosniff\r\n"
-            << "\r\n"
+            "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
+            "User-Agent: " WOPI_AGENT_STRING "\r\n"
+            "Content-Length: " << capabilities.size() << "\r\n"
+            "Content-Type: application/json\r\n"
+            "X-Content-Type-Options: nosniff\r\n"
+            "\r\n"
             << capabilities;
 
         auto socket = _socket.lock();
@@ -2285,11 +2285,11 @@ private:
 
         std::ostringstream oss;
         oss << "HTTP/1.1 200 OK\r\n"
-            << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
-            << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
-            << "Content-Length: " << responseString.size() << "\r\n"
-            << "Content-Type: " << mimeType << "\r\n"
-            << "\r\n";
+            "Last-Modified: " << Util::getHttpTimeNow() << "\r\n"
+            "User-Agent: " WOPI_AGENT_STRING "\r\n"
+            "Content-Length: " << responseString.size() << "\r\n"
+            "Content-Type: " << mimeType << "\r\n"
+            "\r\n";
 
         if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET)
         {
@@ -2345,10 +2345,10 @@ private:
                 LOG_TRC("Conversion not allowed from this address");
                 std::ostringstream oss;
                 oss << "HTTP/1.1 403\r\n"
-                    << "Date: " << Util::getHttpTimeNow() << "\r\n"
-                    << "User-Agent: " << HTTP_AGENT_STRING << "\r\n"
-                    << "Content-Length: 0\r\n"
-                    << "\r\n";
+                    "Date: " << Util::getHttpTimeNow() << "\r\n"
+                    "User-Agent: " HTTP_AGENT_STRING "\r\n"
+                    "Content-Length: 0\r\n"
+                    "\r\n";
                 socket->send(oss.str());
                 socket->shutdown();
                 return;


More information about the Libreoffice-commits mailing list