[Libreoffice-commits] online.git: 2 commits - common/Log.hpp configure.ac wsd/LOOLWSD.cpp

Tor Lillqvist tml at collabora.com
Fri Jul 13 14:50:42 UTC 2018


 common/Log.hpp  |    2 +-
 configure.ac    |    2 +-
 wsd/LOOLWSD.cpp |   48 ++++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 44 insertions(+), 8 deletions(-)

New commits:
commit b4192de6faf54d8b337c59ea52198f40f36e2506
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Jul 13 17:49:21 2018 +0300

    Output '|' before the source file name in LOG_END(), too, like in LOG_BODY()
    
    Change-Id: I57d825d03321992d680670f3560e951bc0cb2005

diff --git a/common/Log.hpp b/common/Log.hpp
index a26c68148..bfd1da8bd 100644
--- a/common/Log.hpp
+++ b/common/Log.hpp
@@ -226,7 +226,7 @@ namespace Log
 #define LOG_FTL(X) do { auto& l_ = Log::logger(); if (l_.fatal()) { LOG_BODY_(FATAL, "FTL", X); } } while (false)
 #define LOG_SFL(X) do { auto& l_ = Log::logger(); if (l_.error()) { LOG_BODY_(FATAL, "FTL", X << " (" << Util::symbolicErrno(errno) << ": " << std::strerror(errno) << ")"); } } while (false)
 
-#define LOG_END(l) do { l << __FILE__ << ':' << __LINE__; l.flush(); } while (false)
+#define LOG_END(l) do { l << " | " << __FILE__ << ':' << __LINE__; l.flush(); } while (false)
 
 #define LOG_CHECK(X) do { if (!(X)) { LOG_ERR("Check failed. Expected (" #X ")."); } } while (false)
 #define LOG_CHECK_RET(X, RET) do { if (!(X)) { LOG_ERR("Check failed. Expected (" #X ")."); return RET; } } while (false)
commit 3a9e536dfab71f6999a39d7371a9dd8844815ae7
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Jul 12 17:46:03 2018 +0300

    When asked to convert to PNG, look for an embedded ODF thumbnail first
    
    Change-Id: Ib777572fe5f79b1cfdd95ec3a7f84484a13ae145

diff --git a/configure.ac b/configure.ac
index 421fdd686..823378d6e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -332,7 +332,7 @@ else
 fi
 AC_SUBST(ENABLE_SUPPORT_KEY)
 
-LIBS="$LIBS -lPocoNet${POCO_DEBUG_SUFFIX} -lPocoUtil${POCO_DEBUG_SUFFIX} -lPocoJSON${POCO_DEBUG_SUFFIX} -lPocoFoundation${POCO_DEBUG_SUFFIX} -lPocoXML${POCO_DEBUG_SUFFIX} -lPocoNetSSL${POCO_DEBUG_SUFFIX} -lPocoCrypto${POCO_DEBUG_SUFFIX}"
+LIBS="$LIBS -lPocoNet${POCO_DEBUG_SUFFIX} -lPocoUtil${POCO_DEBUG_SUFFIX} -lPocoJSON${POCO_DEBUG_SUFFIX} -lPocoFoundation${POCO_DEBUG_SUFFIX} -lPocoXML${POCO_DEBUG_SUFFIX} -lPocoNetSSL${POCO_DEBUG_SUFFIX} -lPocoCrypto${POCO_DEBUG_SUFFIX} -lPocoZip${POCO_DEBUG_SUFFIX}"
 
 AC_CHECK_HEADERS([LibreOfficeKit/LibreOfficeKit.h],
                  [],
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 1854d8cc2..3b47fac4e 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -91,6 +91,8 @@
 #include <Poco/Util/OptionSet.h>
 #include <Poco/Util/ServerApplication.h>
 #include <Poco/Util/XMLConfiguration.h>
+#include <Poco/Zip/ZipArchive.h>
+#include <Poco/Zip/ZipStream.h>
 
 #include "Admin.hpp"
 #include "Auth.hpp"
@@ -2058,15 +2060,49 @@ private:
                 std::string thumbnailFile;
                 if (format == "png")
                 {
-                    // Check whether we already have a cached "thumbnail" for this document.
-
-                    // FIXME: We could here check if the document is such that already contains an
-                    // easily extractable thumbnail, like Thubnails/thumbnail.png in ODF documents,
-                    // and extract and return that.
-
                     std::ifstream istr(fromPath, std::ios::binary);
                     if (istr.is_open() && istr.good())
                     {
+                        // Check whether it is an ODF document with an embedded PNG thumbnail.
+
+                        try
+                        {
+                            Poco::Zip::ZipArchive zip(istr);
+                            auto thumbnailHeader = zip.findHeader("Thumbnails/thumbnail.png");
+                            if (thumbnailHeader != zip.headerEnd() && thumbnailHeader->second.isFile())
+                            {
+                                Poco::Zip::ZipStreamBuf thumbnailStreamBuf(istr, thumbnailHeader->second, true);
+                                std::istream thumbnailStream(&thumbnailStreamBuf);
+                                if (thumbnailStream.good())
+                                {
+                                    std::string png;
+                                    Poco::StreamCopier::copyToString(thumbnailStream, png);
+                                    if (!thumbnailStream.bad())
+                                    {
+                                        LOG_TRC("Extracted thumbnail from ODF document");
+
+                                        response.set("Content-Disposition", "attachment; filename=\"thumbnail.png\"");
+                                        response.setContentType("image/png");
+                                        response.setContentLength(png.size());
+                                        socket->send(response);
+                                        socket->send(png.data(), png.size(), true);
+
+                                        return;
+                                    }
+                                }
+                            }
+                        }
+                        catch (Poco::Exception&)
+                        {
+                        }
+
+                        // Close and re-open istr after the Zip stuff above to get it into a known
+                        // good state.
+                        istr.close();
+                        istr.open(fromPath, std::ios::binary);
+
+                        // Look for cached thumbnail.
+
                         Poco::SHA1Engine sha1;
                         Poco::DigestOutputStream dos(sha1);
                         Poco::StreamCopier::copyStream(istr, dos);


More information about the Libreoffice-commits mailing list