[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - wsd/Storage.cpp

Pranav Kant pranavk at collabora.co.uk
Tue Jun 20 11:47:37 UTC 2017


 wsd/Storage.cpp |   54 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 22 deletions(-)

New commits:
commit ae8077f65d48c6e9497b040c31dde710900d5dc1
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed May 31 22:52:54 2017 +0530

    Factor out iso8601 to Poco::Timestamp parsing
    
    Change-Id: I627a7b6b72899371e880e461685f99a86a858232
    (cherry picked from commit cf968e6768696872b30d51f027959489e9ca0d16)
    Reviewed-on: https://gerrit.libreoffice.org/38525
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index f67513ef..2bef868c 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -424,6 +424,25 @@ void addStorageDebugCookie(Poco::Net::HTTPRequest& request)
 #endif
 }
 
+Poco::Timestamp iso8601ToTimestamp(const std::string& iso8601Time)
+{
+    Poco::Timestamp timestamp = Poco::Timestamp::fromEpochTime(0);
+    try
+    {
+        int timeZoneDifferential;
+        Poco::DateTime dateTime;
+        Poco::DateTimeParser::parse(Poco::DateTimeFormat::ISO8601_FRAC_FORMAT, iso8601Time, dateTime, timeZoneDifferential);
+        timestamp = dateTime.timestamp();
+    }
+    catch (const Poco::SyntaxException& exc)
+    {
+        LOG_WRN("Time [" << iso8601Time << "] is in invalid format: " << exc.displayText() <<
+                (exc.nested() ? " (" + exc.nested()->displayText() + ")" : ""));
+    }
+
+    return timestamp;
+}
+
 } // anonymous namespace
 
 std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const std::string& accessToken)
@@ -526,28 +545,7 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const st
         throw UnauthorizedRequestException("Access denied. WOPI::CheckFileInfo failed on: " + uriObject.toString());
     }
 
-    Poco::Timestamp modifiedTime = Poco::Timestamp::fromEpochTime(0);
-    if (lastModifiedTime != "")
-    {
-        Poco::DateTime dateTime;
-        int timeZoneDifferential;
-        bool valid = false;
-        try
-        {
-            Poco::DateTimeParser::parse(Poco::DateTimeFormat::ISO8601_FRAC_FORMAT, lastModifiedTime, dateTime, timeZoneDifferential);
-            valid = true;
-        }
-        catch (const Poco::SyntaxException& exc)
-        {
-            LOG_WRN("LastModifiedTime property [" << lastModifiedTime << "] was invalid format: " << exc.displayText() <<
-                    (exc.nested() ? " (" + exc.nested()->displayText() + ")" : ""));
-        }
-        if (valid)
-        {
-            modifiedTime = dateTime.timestamp();
-        }
-    }
-
+    modifiedTime = iso8601ToTimestamp(lastModifiedTime);
     _fileInfo = FileInfo({filename, ownerId, modifiedTime, size});
 
     return std::unique_ptr<WopiStorage::WOPIFileInfo>(new WOPIFileInfo({userId, userName, userExtraInfo, canWrite, postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption, enableOwnerTermination, disablePrint, disableExport, disableCopy, callDuration}));
@@ -657,6 +655,18 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const std::string& a
         if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK)
         {
             saveResult = StorageBase::SaveResult::OK;
+            const auto index = oss.str().find_first_of('{');
+            if (index != std::string::npos)
+            {
+                const std::string stringJSON = oss.str().substr(index);
+                Poco::JSON::Parser parser;
+                const auto result = parser.parse(stringJSON);
+                const auto& object = result.extract<Poco::JSON::Object::Ptr>();
+
+                std::string lastModifiedTime;
+                getWOPIValue(object, "LastFileModifiedTime", lastModifiedTime);
+                _fileInfo._modifiedTime = iso8601ToTimestamp(lastModifiedTime);
+            }
         }
         else if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_REQUESTENTITYTOOLARGE)
         {


More information about the Libreoffice-commits mailing list