[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2020-09-28 Thread Miklos Vajna (via logerrit)
 wsd/ClientSession.cpp |6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

New commits:
commit e080b8af04eff9a36ee81a5a4747a31f992ab71d
Author: Miklos Vajna 
AuthorDate: Mon Sep 28 09:07:43 2020 +0200
Commit: Miklos Vajna 
CommitDate: Mon Sep 28 09:33:18 2020 +0200

ClientSession: clean up copy&paste

dialogevent and formfieldevent has the same handler, do that at a single
place.

Change-Id: I4e0f7b36484f6ef65539616c0fe81a331c9caa98
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/103529
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 44b3f0271..cb26a8f64 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -687,7 +687,7 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 docBroker->saveAsToStorage(getId(), "", wopiFilename, true);
 return true;
 }
-else if (tokens.equals(0, "dialogevent"))
+else if (tokens.equals(0, "dialogevent") || tokens.equals(0, 
"formfieldevent"))
 {
 return forwardToChild(firstLine, docBroker);
 }
@@ -695,10 +695,6 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 {
 return forwardToChild(std::string(buffer, length), docBroker);
 }
-else if (tokens.equals(0, "formfieldevent"))
-{
-return forwardToChild(firstLine, docBroker);
-}
 else if (tokens[0] == "outlinestate" ||
  tokens[0] == "downloadas" ||
  tokens[0] == "getchildid" ||
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2020-08-24 Thread Samuel Mehrbrodt (via logerrit)
 wsd/ClientSession.cpp  |6 ++
 wsd/DocumentBroker.cpp |7 +++
 wsd/DocumentBroker.hpp |5 +
 3 files changed, 18 insertions(+)

New commits:
commit 8c602e179e8afe44f2a1fe513bdc7640cd57ed2a
Author: Samuel Mehrbrodt 
AuthorDate: Mon Aug 17 11:00:38 2020 +0200
Commit: Samuel Mehrbrodt 
CommitDate: Mon Aug 24 14:34:10 2020 +0200

Revert "Revert "Don't update modified status after saving to storage fails""

This reverts commit e83e36bd9b96fe38ac1f53f56d9754e26bd131e0.

Unit test failure was fixed

Change-Id: I2176368278725c1711df3b23eef95de6526c68d5
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/100859
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Samuel Mehrbrodt 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 7c4ac6fdb..60733a0c5 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1317,6 +1317,12 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 StringVector stateTokens(Util::tokenize(tokens[1], '='));
 if (stateTokens.size() == 2 && stateTokens.equals(0, 
".uno:ModifiedStatus"))
 {
+// When the document is saved internally, but saving to storage 
failed,
+// don't update the client's modified status
+// (otherwise client thinks document is unmodified b/c saving was 
successful)
+if (!docBroker->isLastStorageSaveSuccessful())
+return false;
+
 docBroker->setModified(stateTokens.equals(1, "true"));
 }
 else
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a5e62fcc4..4218b9fb4 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -176,6 +176,7 @@ DocumentBroker::DocumentBroker(ChildType type,
 _docKey(docKey),
 _docId(Util::encodeId(DocBrokerId++, 3)),
 _documentChangedInStorage(false),
+_lastStorageSaveSuccessful(true),
 _lastSaveTime(std::chrono::steady_clock::now()),
 _lastSaveRequestTime(std::chrono::steady_clock::now() - 
std::chrono::milliseconds(COMMAND_TIMEOUT_MS)),
 _markToDestroy(false),
@@ -1049,6 +1050,11 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId, bool su
 assert(_storage && _tileCache);
 const StorageBase::SaveResult storageSaveResult = 
_storage->saveLocalFileToStorage(
 auth, it->second->getCookies(), *_lockCtx, saveAsPath, saveAsFilename, 
isRename);
+// Storage save is considered successful when either storage returns OK or 
the document on the storage
+// was changed and it was used to overwrite local changes
+_lastStorageSaveSuccessful
+= storageSaveResult.getResult() == StorageBase::SaveResult::OK ||
+storageSaveResult.getResult() == StorageBase::SaveResult::DOC_CHANGED;
 if (storageSaveResult.getResult() == StorageBase::SaveResult::OK)
 {
 #if !MOBILEAPP
@@ -2474,6 +2480,7 @@ void DocumentBroker::dumpState(std::ostream& os)
 os << "\n  last saved: " << Util::getSteadyClockAsString(_lastSaveTime);
 os << "\n  last save request: " << 
Util::getSteadyClockAsString(_lastSaveRequestTime);
 os << "\n  last save response: " << 
Util::getSteadyClockAsString(_lastSaveResponseTime);
+os << "\n  last storage save was successful: " << 
isLastStorageSaveSuccessful();
 os << "\n  last modified: " << 
Util::getHttpTime(_documentLastModifiedTime);
 os << "\n  file last modified: " << 
Util::getHttpTime(_lastFileModifiedTime);
 if (_limitLifeSeconds)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index b8e176b3c..e59a2d6b4 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -175,6 +175,8 @@ public:
 
 bool isDocumentChangedInStorage() { return _documentChangedInStorage; }
 
+bool isLastStorageSaveSuccessful() { return _lastStorageSaveSuccessful; }
+
 /// Save the document to Storage if it needs persisting.
 bool saveToStorage(const std::string& sesionId, bool success, const 
std::string& result = "", bool force = false);
 
@@ -404,6 +406,9 @@ private:
 /// for user's command to act.
 bool _documentChangedInStorage;
 
+/// Indicates whether the last saveToStorage operation was successful.
+bool _lastStorageSaveSuccessful;
+
 /// The last time we tried saving, regardless of whether the
 /// document was modified and saved or not.
 std::chrono::steady_clock::time_point _lastSaveTime;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2020-08-13 Thread Tamás Zolnai (via logerrit)
 wsd/ClientSession.cpp  |6 --
 wsd/DocumentBroker.cpp |3 ---
 wsd/DocumentBroker.hpp |5 -
 3 files changed, 14 deletions(-)

New commits:
commit e83e36bd9b96fe38ac1f53f56d9754e26bd131e0
Author: Tamás Zolnai 
AuthorDate: Thu Aug 13 17:29:17 2020 +0200
Commit: Tamás Zolnai 
CommitDate: Thu Aug 13 17:35:02 2020 +0200

Revert "Don't update modified status after saving to storage fails"

The reverted change breaks unit-wopi-documentconflict test.

This reverts commit 494a5221f5bb959f2cce19bc3dd662ac22027e0c.

Change-Id: I3e89a6e6526e9388e4dc6a1ea8f8d8832e8cb169
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/100678
Tested-by: Tamás Zolnai 
Reviewed-by: Tamás Zolnai 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 0ed783f72..a3fa8e078 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1317,12 +1317,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 StringVector stateTokens(Util::tokenize(tokens[1], '='));
 if (stateTokens.size() == 2 && stateTokens.equals(0, 
".uno:ModifiedStatus"))
 {
-// When the document is saved internally, but saving to storage 
failed,
-// don't update the client's modified status
-// (otherwise client thinks document is unmodified b/c saving was 
successful)
-if (!docBroker->isLastStorageSaveSuccessful())
-return false;
-
 docBroker->setModified(stateTokens.equals(1, "true"));
 }
 else
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index f89ed6953..a5e62fcc4 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -176,7 +176,6 @@ DocumentBroker::DocumentBroker(ChildType type,
 _docKey(docKey),
 _docId(Util::encodeId(DocBrokerId++, 3)),
 _documentChangedInStorage(false),
-_lastStorageSaveSuccessful(true),
 _lastSaveTime(std::chrono::steady_clock::now()),
 _lastSaveRequestTime(std::chrono::steady_clock::now() - 
std::chrono::milliseconds(COMMAND_TIMEOUT_MS)),
 _markToDestroy(false),
@@ -1050,7 +1049,6 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId, bool su
 assert(_storage && _tileCache);
 const StorageBase::SaveResult storageSaveResult = 
_storage->saveLocalFileToStorage(
 auth, it->second->getCookies(), *_lockCtx, saveAsPath, saveAsFilename, 
isRename);
-_lastStorageSaveSuccessful = storageSaveResult.getResult() == 
StorageBase::SaveResult::OK;
 if (storageSaveResult.getResult() == StorageBase::SaveResult::OK)
 {
 #if !MOBILEAPP
@@ -2476,7 +2474,6 @@ void DocumentBroker::dumpState(std::ostream& os)
 os << "\n  last saved: " << Util::getSteadyClockAsString(_lastSaveTime);
 os << "\n  last save request: " << 
Util::getSteadyClockAsString(_lastSaveRequestTime);
 os << "\n  last save response: " << 
Util::getSteadyClockAsString(_lastSaveResponseTime);
-os << "\n  last storage save was successful: " << 
isLastStorageSaveSuccessful();
 os << "\n  last modified: " << 
Util::getHttpTime(_documentLastModifiedTime);
 os << "\n  file last modified: " << 
Util::getHttpTime(_lastFileModifiedTime);
 if (_limitLifeSeconds)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index e59a2d6b4..b8e176b3c 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -175,8 +175,6 @@ public:
 
 bool isDocumentChangedInStorage() { return _documentChangedInStorage; }
 
-bool isLastStorageSaveSuccessful() { return _lastStorageSaveSuccessful; }
-
 /// Save the document to Storage if it needs persisting.
 bool saveToStorage(const std::string& sesionId, bool success, const 
std::string& result = "", bool force = false);
 
@@ -406,9 +404,6 @@ private:
 /// for user's command to act.
 bool _documentChangedInStorage;
 
-/// Indicates whether the last saveToStorage operation was successful.
-bool _lastStorageSaveSuccessful;
-
 /// The last time we tried saving, regardless of whether the
 /// document was modified and saved or not.
 std::chrono::steady_clock::time_point _lastSaveTime;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2020-08-13 Thread Samuel Mehrbrodt (via logerrit)
 wsd/ClientSession.cpp  |6 ++
 wsd/DocumentBroker.cpp |3 +++
 wsd/DocumentBroker.hpp |5 +
 3 files changed, 14 insertions(+)

New commits:
commit 494a5221f5bb959f2cce19bc3dd662ac22027e0c
Author: Samuel Mehrbrodt 
AuthorDate: Wed Aug 5 12:41:57 2020 +0200
Commit: Samuel Mehrbrodt 
CommitDate: Thu Aug 13 09:39:30 2020 +0200

Don't update modified status after saving to storage fails

Otherwise client gets a notification that document is unmodified.
This should not happen, as the document in the storage has not been updated
and so it should be considered as modified until saving to storage succeeds.

Change-Id: I6918f97d96a546ce086f622854f4cbeed48d54ae
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/100162
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index a3fa8e078..0ed783f72 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1317,6 +1317,12 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 StringVector stateTokens(Util::tokenize(tokens[1], '='));
 if (stateTokens.size() == 2 && stateTokens.equals(0, 
".uno:ModifiedStatus"))
 {
+// When the document is saved internally, but saving to storage 
failed,
+// don't update the client's modified status
+// (otherwise client thinks document is unmodified b/c saving was 
successful)
+if (!docBroker->isLastStorageSaveSuccessful())
+return false;
+
 docBroker->setModified(stateTokens.equals(1, "true"));
 }
 else
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a5e62fcc4..f89ed6953 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -176,6 +176,7 @@ DocumentBroker::DocumentBroker(ChildType type,
 _docKey(docKey),
 _docId(Util::encodeId(DocBrokerId++, 3)),
 _documentChangedInStorage(false),
+_lastStorageSaveSuccessful(true),
 _lastSaveTime(std::chrono::steady_clock::now()),
 _lastSaveRequestTime(std::chrono::steady_clock::now() - 
std::chrono::milliseconds(COMMAND_TIMEOUT_MS)),
 _markToDestroy(false),
@@ -1049,6 +1050,7 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId, bool su
 assert(_storage && _tileCache);
 const StorageBase::SaveResult storageSaveResult = 
_storage->saveLocalFileToStorage(
 auth, it->second->getCookies(), *_lockCtx, saveAsPath, saveAsFilename, 
isRename);
+_lastStorageSaveSuccessful = storageSaveResult.getResult() == 
StorageBase::SaveResult::OK;
 if (storageSaveResult.getResult() == StorageBase::SaveResult::OK)
 {
 #if !MOBILEAPP
@@ -2474,6 +2476,7 @@ void DocumentBroker::dumpState(std::ostream& os)
 os << "\n  last saved: " << Util::getSteadyClockAsString(_lastSaveTime);
 os << "\n  last save request: " << 
Util::getSteadyClockAsString(_lastSaveRequestTime);
 os << "\n  last save response: " << 
Util::getSteadyClockAsString(_lastSaveResponseTime);
+os << "\n  last storage save was successful: " << 
isLastStorageSaveSuccessful();
 os << "\n  last modified: " << 
Util::getHttpTime(_documentLastModifiedTime);
 os << "\n  file last modified: " << 
Util::getHttpTime(_lastFileModifiedTime);
 if (_limitLifeSeconds)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index b8e176b3c..e59a2d6b4 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -175,6 +175,8 @@ public:
 
 bool isDocumentChangedInStorage() { return _documentChangedInStorage; }
 
+bool isLastStorageSaveSuccessful() { return _lastStorageSaveSuccessful; }
+
 /// Save the document to Storage if it needs persisting.
 bool saveToStorage(const std::string& sesionId, bool success, const 
std::string& result = "", bool force = false);
 
@@ -404,6 +406,9 @@ private:
 /// for user's command to act.
 bool _documentChangedInStorage;
 
+/// Indicates whether the last saveToStorage operation was successful.
+bool _lastStorageSaveSuccessful;
+
 /// The last time we tried saving, regardless of whether the
 /// document was modified and saved or not.
 std::chrono::steady_clock::time_point _lastSaveTime;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2020-07-15 Thread Mike Kaganski (via logerrit)
 wsd/ClientSession.cpp |   97 ++
 1 file changed, 36 insertions(+), 61 deletions(-)

New commits:
commit 27521418675fc3ad6e688a08f24b70f1d336e77b
Author: Mike Kaganski 
AuthorDate: Wed Jul 15 14:07:23 2020 +0300
Commit: Mike Kaganski 
CommitDate: Wed Jul 15 14:53:16 2020 +0200

Restructure ClientSession::_handleInput to check tokens once

This allows to avoid redundancy, and makes it explicit which token
is handled where.

Change-Id: Ibc7ed7617f7f511cb8346e2e82281c3a3fdac9a7
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98821
Tested-by: Jenkins CollaboraOffice 
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 293fff67d..0f5a09b2c 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -395,66 +395,6 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 
 return loadDocument(buffer, length, tokens, docBroker);
 }
-else if (tokens[0] != "canceltiles" &&
- tokens[0] != "tileprocessed" &&
- tokens[0] != "clientzoom" &&
- tokens[0] != "clientvisiblearea" &&
- tokens[0] != "outlinestate" &&
- tokens[0] != "commandvalues" &&
- tokens[0] != "closedocument" &&
- tokens[0] != "versionrestore" &&
- tokens[0] != "downloadas" &&
- tokens[0] != "getchildid" &&
- tokens[0] != "gettextselection" &&
- tokens[0] != "paste" &&
- tokens[0] != "insertfile" &&
- tokens[0] != "key" &&
- tokens[0] != "textinput" &&
- tokens[0] != "windowkey" &&
- tokens[0] != "mouse" &&
- tokens[0] != "windowmouse" &&
- tokens[0] != "windowgesture" &&
- tokens[0] != "partpagerectangles" &&
- tokens[0] != "ping" &&
- tokens[0] != "renderfont" &&
- tokens[0] != "requestloksession" &&
- tokens[0] != "resetselection" &&
- tokens[0] != "save" &&
- tokens[0] != "saveas" &&
- tokens[0] != "savetostorage" &&
- tokens[0] != "selectgraphic" &&
- tokens[0] != "selecttext" &&
- tokens[0] != "windowselecttext" &&
- tokens[0] != "setclientpart" &&
- tokens[0] != "selectclientpart" &&
- tokens[0] != "moveselectedclientparts" &&
- tokens[0] != "setpage" &&
- tokens[0] != "status" &&
- tokens[0] != "statusupdate" &&
- tokens[0] != "tile" &&
- tokens[0] != "tilecombine" &&
- tokens[0] != "uno" &&
- tokens[0] != "useractive" &&
- tokens[0] != "userinactive" &&
- tokens[0] != "paintwindow" &&
- tokens[0] != "windowcommand" &&
- tokens[0] != "signdocument" &&
- tokens[0] != "asksignaturestatus" &&
- tokens[0] != "uploadsigneddocument" &&
- tokens[0] != "exportsignanduploaddocument" &&
- tokens[0] != "rendershapeselection" &&
- tokens[0] != "removesession" &&
- tokens[0] != "renamefile" &&
- tokens[0] != "resizewindow" &&
- tokens[0] != "removetextcontext" &&
- tokens[0] != "dialogevent" &&
- tokens[0] != "completefunction" &&
- tokens[0] != "formfieldevent")
-{
-LOG_ERR("Session [" << getId() << "] got unknown command [" << 
tokens[0] << "].");
-sendTextFrameAndLogError("error: cmd=" + tokens[0] + " kind=unknown");
-return false;
-}
 else if (getDocURL().empty())
 {
 sendTextFrameAndLogError("error: cmd=" + tokens[0] + " 
kind=nodocloaded");
@@ -746,7 +686,37 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 {
 return forwardToChild(firstLine, docBroker);
 }
-else
+else if (tokens[0] == "outlinestate" ||
+ tokens[0] == "downloadas" ||
+ tokens[0] == "getchildid" ||
+ tokens[0] == "gettextselection" ||
+ tokens[0] == "paste" ||
+ tokens[0] == "insertfile" ||
+ tokens[0] == "key" ||
+ tokens[0] == "textinput" ||
+ tokens[0] == "windowkey" ||
+ tokens[0] == "mouse" ||
+ tokens[0] == "windowmouse" ||
+ tokens[0] == "windowgesture" ||
+ tokens[0] == "requestloksession" ||
+ tokens[0] == "resetselection" ||
+ tokens[0] == "saveas" ||
+ tokens[0] == "selectgraphic" ||
+ tokens[0] == "selecttext" ||
+ tokens[0] == "windowselecttext" ||
+ tokens[0] == "setpage" ||
+ tokens[0] == "uno" ||
+ tokens[0] == "useractive" ||
+ tokens[0] == "userinactive" ||
+ tokens[0] == "paintwindow" ||
+ 

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/TileCache.cpp

2020-06-30 Thread Ashod Nakashian (via logerrit)
 wsd/ClientSession.cpp |2 +-
 wsd/TileCache.cpp |5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

New commits:
commit a77208ddfba03faf2df575d9a43cc21d65f93fd0
Author: Ashod Nakashian 
AuthorDate: Tue Jun 9 22:24:13 2020 -0400
Commit: Ashod Nakashian 
CommitDate: Wed Jul 1 07:40:54 2020 +0200

wsd: prefer emplace_back where possible

emplace_back avoids copy-construction when
the argument is a temporary instance created
at call-site.

Change-Id: I127fddd308d710af9ea65a86db1b03347e9c3d87
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96829
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 26f9e9c8b..5f79a07fa 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1574,7 +1574,7 @@ void ClientSession::enqueueSendMessage(const 
std::shared_ptr& data)
 
 void ClientSession::addTileOnFly(const TileDesc& tile)
 {
-_tilesOnFly.push_back({tile.generateID(), 
std::chrono::steady_clock::now()});
+_tilesOnFly.emplace_back(tile.generateID(), 
std::chrono::steady_clock::now());
 }
 
 void ClientSession::clearTilesOnFly()
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index 12231a383..4e9773499 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -589,9 +589,8 @@ void TileCache::ensureCacheSize()
 WidSize(TileWireId w, size_t s) : _wid(w), _size(s) {}
 };
 std::vector wids;
-for (auto &it : _cache)
-wids.push_back(WidSize(it.first.getWireId(),
-   itemCacheSize(it.second)));
+for (const auto& it : _cache)
+wids.emplace_back(it.first.getWireId(), itemCacheSize(it.second));
 std::sort(wids.begin(), wids.end(),
   [](const WidSize &a, const WidSize &b) { return a._wid < b._wid; 
});
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/ProxyProtocol.cpp

2020-05-12 Thread Michael Meeks (via logerrit)
 wsd/ClientSession.cpp |   19 +--
 wsd/ClientSession.hpp |8 +++-
 wsd/ProxyProtocol.cpp |   10 +-
 3 files changed, 29 insertions(+), 8 deletions(-)

New commits:
commit e600721abee7eb6aba7fab58fbcbe2e7910da1b4
Author: Michael Meeks 
AuthorDate: Tue May 12 23:52:25 2020 +0100
Commit: Michael Meeks 
CommitDate: Wed May 13 02:01:59 2020 +0200

Proxy: use much more obscure session IDs.

Change-Id: I1220216b88aaa3c9a0bc58ed5bf4b20b4214d997
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/94090
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Michael Meeks 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 3991c3d92..369bed08d 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -35,6 +35,11 @@ using namespace LOOLProtocol;
 
 using Poco::Path;
 
+// rotates regularly
+const int ClipboardTokenLengthBytes = 16;
+// home-use, disabled by default.
+const int ProxyAccessTokenLengthBytes = 32;
+
 static std::mutex GlobalSessionMapMutex;
 static std::unordered_map> 
GlobalSessionMap;
 
@@ -188,7 +193,8 @@ void ClientSession::rotateClipboardKey(bool notifyClient)
 return;
 
 _clipboardKeys[1] = _clipboardKeys[0];
-_clipboardKeys[0] = Util::rng::getHardRandomHexString(16);
+_clipboardKeys[0] = Util::rng::getHardRandomHexString(
+ClipboardTokenLengthBytes);
 LOG_TRC("Clipboard key on [" << getId() << "] set to " << 
_clipboardKeys[0] <<
 " last was " << _clipboardKeys[1]);
 if (notifyClient)
@@ -1719,7 +1725,8 @@ void ClientSession::dumpState(std::ostream& os)
<< "\n\t\tisTextDocument: " << _isTextDocument
<< "\n\t\tclipboardKeys[0]: " << _clipboardKeys[0]
<< "\n\t\tclipboardKeys[1]: " << _clipboardKeys[1]
-   << "\n\t\tclip sockets: " << _clipSockets.size();
+   << "\n\t\tclip sockets: " << _clipSockets.size()
+   << "\n\t\tproxy access:: " << _proxyAccess;
 
 if (_protocol)
 {
@@ -1733,6 +1740,14 @@ void ClientSession::dumpState(std::ostream& os)
 
 }
 
+const std::string &ClientSession::getOrCreateProxyAccess()
+{
+if (_proxyAccess.size() <= 0)
+_proxyAccess = Util::rng::getHardRandomHexString(
+ProxyAccessTokenLengthBytes);
+return _proxyAccess;
+}
+
 void ClientSession::handleTileInvalidation(const std::string& message,
 const std::shared_ptr& docBroker)
 {
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 865649c30..c7d4e66ed 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -171,6 +171,9 @@ public:
 /// Generate and rotate a new clipboard hash, sending it if appropriate
 void rotateClipboardKey(bool notifyClient);
 
+/// Generate an access token for this session via proxy protocol.
+const std::string &getOrCreateProxyAccess();
+
 private:
 std::shared_ptr client_from_this()
 {
@@ -282,8 +285,11 @@ private:
 /// Sockets to send binary selection content to
 std::vector> _clipSockets;
 
-///Time when loading of view started
+/// Time when loading of view started
 std::chrono::steady_clock::time_point _viewLoadStart;
+
+/// Secure session id token for proxyprotocol authentication
+std::string _proxyAccess;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/ProxyProtocol.cpp b/wsd/ProxyProtocol.cpp
index 7a5ef1b4c..9f25a47b4 100644
--- a/wsd/ProxyProtocol.cpp
+++ b/wsd/ProxyProtocol.cpp
@@ -55,17 +55,17 @@ void DocumentBroker::handleProxyRequest(
 LOOLWSD::checkDiskSpaceAndWarnClients(true);
 LOOLWSD::checkSessionLimitsAndWarnClients();
 
-LOG_TRC("proxy: Returning sessionId " << clientSession->getId());
+const std::string &sessionId = clientSession->getOrCreateProxyAccess();
+LOG_TRC("proxy: Returning sessionId " << sessionId);
 
 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: " << clientSession->getId().size() << "\r\n"
+"Content-Length: " << sessionId.size() << "\r\n"
 "Content-Type: application/json\r\n"
 "X-Content-Type-Options: nosniff\r\n"
-"\r\n"
-<< clientSession->getId();
+"\r\n" << sessionId;
 
 socket->send(oss.str());
 socket->shutdown();
@@ -77,7 +77,7 @@ void DocumentBroker::handleProxyRequest(
 LOG_TRC("proxy: find session for " << _docKey << " with id " << 
sessionId);
 for (const auto &it : _sessions)
 {
-if (it.second->getId() == sessionId)
+if (it.second->getOrCreateProxyAccess() == sessionId)
 {
 clientSession = it.second;
 break;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailma

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2020-05-05 Thread Jan Holesovsky (via logerrit)
 wsd/ClientSession.cpp  |6 --
 wsd/DocumentBroker.cpp |   11 ---
 wsd/DocumentBroker.hpp |4 ++--
 wsd/LOOLWSD.cpp|3 +++
 4 files changed, 17 insertions(+), 7 deletions(-)

New commits:
commit 8325deaf2224a211243fe8c011e4afcfe17d7529
Author: Jan Holesovsky 
AuthorDate: Tue May 5 19:38:04 2020 +0200
Commit: Jan Holesovsky 
CommitDate: Tue May 5 22:56:55 2020 +0200

nocaps: Make the convert-to work too.

And also compile out ConvertToBroker in mobile apps, it is not
needed there, otherwise it wouldn't compile due to the added check for
nocaps.

Change-Id: I20fe7e3b702e4a1782640a2d0e71a40b1517beb6
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93510
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Jan Holesovsky 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index c31db7317..c4c6ec7cb 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1210,13 +1210,15 @@ bool ClientSession::handleKitToClientMessage(const 
char* buffer, const int lengt
 
 // URI constructor implicitly decodes when it gets std::string as param
 Poco::URI resultURL(encodedURL);
-if (resultURL.getScheme() == "file")
+
+// Prepend the jail path in the normal (non-nocaps) case
+if (resultURL.getScheme() == "file" && !LOOLWSD::NoCapsForKit)
 {
 std::string relative(resultURL.getPath());
 if (relative.size() > 0 && relative[0] == '/')
 relative = relative.substr(1);
 
-// Rewrite file:// URLs, as they are visible to the outside world.
+// Rewrite file:// URLs to be visible to the outside world.
 const Path path(docBroker->getJailRoot(), relative);
 if (Poco::File(path).exists())
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index e0e8369a9..a81864506 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -2239,6 +2239,7 @@ void DocumentBroker::getIOStats(uint64_t &sent, uint64_t 
&recv)
 }
 }
 
+#if !MOBILEAPP
 static std::atomic NumConverters;
 
 size_t ConvertToBroker::getInstanceCount()
@@ -2260,7 +2261,6 @@ ConvertToBroker::ConvertToBroker(const std::string& uri,
 _limitLifeSeconds = limit_convert_secs;
 }
 
-#if !MOBILEAPP
 bool ConvertToBroker::startConversion(SocketDisposition &disposition, const 
std::string &id)
 {
 std::shared_ptr docBroker = 
std::static_pointer_cast(shared_from_this());
@@ -2308,7 +2308,6 @@ bool ConvertToBroker::startConversion(SocketDisposition 
&disposition, const std:
 });
 return true;
 }
-#endif
 
 void ConvertToBroker::dispose()
 {
@@ -2347,7 +2346,12 @@ void ConvertToBroker::setLoaded()
 // FIXME: Check for security violations.
 Poco::Path toPath(getPublicUri().getPath());
 toPath.setExtension(_format);
-const std::string toJailURL = "file://" + 
std::string(JAILED_DOCUMENT_ROOT) + toPath.getFileName();
+
+// file:///user/docs/filename.ext normally, 
file:user/docs/filename.ext in the nocaps case
+const std::string toJailURL = "file://" +
+(LOOLWSD::NoCapsForKit? getJailRoot(): "") +
+std::string(JAILED_DOCUMENT_ROOT) + toPath.getFileName();
+
 std::string encodedTo;
 Poco::URI::encode(toJailURL, "", encodedTo);
 
@@ -2359,6 +2363,7 @@ void ConvertToBroker::setLoaded()
 
 _clientSession->handleMessage(saveasRequest);
 }
+#endif
 
 std::vector> 
DocumentBroker::getSessionsTestOnlyUnsafe()
 {
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 40784b204..f8c2ccea2 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -442,6 +442,7 @@ private:
 static std::atomic DocBrokerId;
 };
 
+#if !MOBILEAPP
 class ConvertToBroker : public DocumentBroker
 {
 const std::string _format;
@@ -457,10 +458,8 @@ public:
 const std::string& sOptions);
 virtual ~ConvertToBroker();
 
-#if !MOBILEAPP
 /// Move socket to this broker for response & do conversion
 bool startConversion(SocketDisposition &disposition, const std::string 
&id);
-#endif
 
 /// Called when removed from the DocBrokers list
 void dispose() override;
@@ -474,5 +473,6 @@ public:
 /// Cleanup path and its parent
 static void removeFile(const std::string &uri);
 };
+#endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 60d3c0376..3b770cf03 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -3434,7 +3434,10 @@ public:
   << "[ " << DocBrokers.size() << " ]:\n";
 for (auto &i : DocBrokers)
 i.second->dumpState(os);
+
+#if !MOBILEAPP
 os << "Converter count: " << ConvertToBroker::getInstanceCount() << 
"\n";
+#endif
 
 Socket::InhibitThreadChecks = false;
 SocketPoll::InhibitThreadChecks = false;
___
Libreoffice-commits mailing list
libreoffice-comm...@lis

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2020-03-18 Thread Miklos Vajna (via logerrit)
 wsd/ClientSession.cpp |3 +++
 1 file changed, 3 insertions(+)

New commits:
commit f32c1f2febf7d3a3bdf0c7b0afa70d69a24cc761
Author: Miklos Vajna 
AuthorDate: Wed Mar 18 09:20:31 2020 +0100
Commit: Miklos Vajna 
CommitDate: Wed Mar 18 15:17:02 2020 +0100

wsd: improve lifecycle in ClientSession::onDisconnect()

Once unit-bad-doc-load completes (with success in exitTest()), sometimes
we have an error during shutdown.

The reason seems to be that ClientSession::onDisconnect() calls
DocumentBroker::removeSession(), which may delete the ClientSession, so
by time time isCloseFrame() is called, we have trouble.

Fix the problem by keeping a reference to self before calling
removeSession().

Change-Id: If5b409822563ba5a45d453329516671065d8f054
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90681
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 29e420dad..f336eeec0 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1638,6 +1638,9 @@ void ClientSession::onDisconnect()
 docBroker->assertCorrectThread();
 const std::string docKey = docBroker->getDocKey();
 
+// Keep self alive, so that our own dtor runs only at the end of this 
function. Without this,
+// removeSession() may destroy us and then we can't call our own member 
functions anymore.
+std::shared_ptr session = client_from_this();
 try
 {
 // Connection terminated. Destroy session.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2019-11-20 Thread Tor Lillqvist (via logerrit)
 wsd/ClientSession.cpp |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit c6497bda19387d93d63b5e103cccaa6968438ceb
Author: Tor Lillqvist 
AuthorDate: Wed Nov 20 18:19:33 2019 +0200
Commit: Tor Lillqvist 
CommitDate: Wed Nov 20 17:26:09 2019 +0100

No need to "rescue" the clipboard in the iOS app

Change-Id: I805c14f2405eeed39127bdac29d7c93374ddc942
Reviewed-on: https://gerrit.libreoffice.org/83340
Reviewed-by: Tor Lillqvist 
Tested-by: Tor Lillqvist 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 5e3b23547..e0ba29bb2 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -142,10 +142,11 @@ bool ClientSession::disconnectFromKit()
 {
 setState(SessionState::WAIT_DISCONNECT);
 
+#ifndef IOS
 LOG_TRC("request/rescue clipboard on disconnect for " << getId());
 // rescue clipboard before shutdown.
 docBroker->forwardToChild(getId(), "getclipboard");
-
+#endif
 // handshake nicely; so wait for 'disconnected'
 docBroker->forwardToChild(getId(), "disconnect");
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp

2019-08-16 Thread Ashod Nakashian (via logerrit)
 wsd/ClientSession.cpp  |   24 +++-
 wsd/DocumentBroker.cpp |1 -
 2 files changed, 15 insertions(+), 10 deletions(-)

New commits:
commit 6d94b35c35bd30e10963bc64bea9ca4e1e253a81
Author: Ashod Nakashian 
AuthorDate: Tue Aug 13 20:03:40 2019 -0400
Commit: Ashod Nakashian 
CommitDate: Sat Aug 17 04:44:51 2019 +0200

wsd: block save of read-only documents

WSD is responsible for checking permissions,
as we do with DisableCopy and DisablePrint,
but until now we allowed saving even on
read-only documents.

The reason, it seems, was that when we failed
to save a document due to disk space, we
set documents as read-only. So presumably
we still had to allow saving, so users
preserve their latest changes when the disk
has some free space. Meanwhile, we didn't
let users make further changes. At least
this seems to be a reasonable explanation.

Unfortunately this meant that we allowed
saving when the user had no permission,
or the document was loaded as read-only.

Now we no longer mark documents that fail
to save due to disk-space limitation as
read-only, and instead expect the client
to notify the user and (possibly) block
further edits. And read-only documents,
or users without write permission, are
no longer allowed to get saved.

This change makes sure that the ctrl+s
shortcut respects the read-only flag,
while we allow clients to disable
the default handler and decide what to
do (although now they cannot force saving
when the user has no permission, something
they could do previously).

Change-Id: I16c3b75fd3e54435d750948a25afd6f71c9f963b
Reviewed-on: https://gerrit.libreoffice.org/77594
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 5dbcaa7d0..56f2a3443 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -499,16 +499,23 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 }
 else if (tokens[0] == "save")
 {
-int dontTerminateEdit = 1;
-if (tokens.size() > 1)
-getTokenInteger(tokens[1], "dontTerminateEdit", dontTerminateEdit);
+if (isReadOnly())
+{
+LOG_WRN("The document is read-only, cannot save.");
+}
+else
+{
+int dontTerminateEdit = 1;
+if (tokens.size() > 1)
+getTokenInteger(tokens[1], "dontTerminateEdit", 
dontTerminateEdit);
 
-// Don't save unmodified docs by default, or when read-only.
-int dontSaveIfUnmodified = 1;
-if (!isReadOnly() && tokens.size() > 2)
-getTokenInteger(tokens[2], "dontSaveIfUnmodified", 
dontSaveIfUnmodified);
+// Don't save unmodified docs by default.
+int dontSaveIfUnmodified = 1;
+if (tokens.size() > 2)
+getTokenInteger(tokens[2], "dontSaveIfUnmodified", 
dontSaveIfUnmodified);
 
-docBroker->sendUnoSave(getId(), dontTerminateEdit != 0, 
dontSaveIfUnmodified != 0);
+docBroker->sendUnoSave(getId(), dontTerminateEdit != 0, 
dontSaveIfUnmodified != 0);
+}
 }
 else if (tokens[0] == "savetostorage")
 {
@@ -1003,7 +1010,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 #endif
 
 const auto& tokens = payload->tokens();
-
 if (tokens[0] == "unocommandresult:")
 {
 const std::string stringMsg(buffer, length);
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 5105e426d..026bdda08 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -975,7 +975,6 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 // Make everyone readonly and tell everyone that storage is low on 
diskspace.
 for (const auto& sessionIt : _sessions)
 {
-sessionIt.second->setReadOnly();
 sessionIt.second->sendTextFrame("error: cmd=storage 
kind=savediskfull");
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2019-08-07 Thread Tor Lillqvist (via logerrit)
 wsd/ClientSession.cpp  |2 ++
 wsd/DocumentBroker.cpp |4 +++-
 wsd/LOOLWSD.cpp|4 
 3 files changed, 9 insertions(+), 1 deletion(-)

New commits:
commit c1ebc62c3a8e5d088e5d3910bacc60690a0454b6
Author: Tor Lillqvist 
AuthorDate: Wed Aug 7 14:40:27 2019 +0300
Commit: Tor Lillqvist 
CommitDate: Wed Aug 7 14:41:37 2019 +0300

Fix build for MOBILEAPP

The iOS app does not work any longer, though. Hits an assertion failure.

Change-Id: Ia135c12a79427e5c2b6c3c98adef4c354d1ceb68

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 4cdc3fea2..c24f04f57 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1252,8 +1252,10 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 if (!empty)
 {
 oss.write(&payload->data()[header], payload->size() - header);
+#if !MOBILEAPP
 socket->setSocketBufferSize(std::min(payload->size() + 256,
  
size_t(Socket::MaximumSendBufferSize)));
+#endif
 }
 socket->send(oss.str());
 socket->shutdown();
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index be1794eb7..be154d537 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -275,12 +275,12 @@ void DocumentBroker::pollThread()
 uint64_t adminSent = 0;
 uint64_t adminRecv = 0;
 auto lastBWUpdateTime = std::chrono::steady_clock::now();
-auto last30SecCheckTime = std::chrono::steady_clock::now();
 auto lastClipboardHashUpdateTime = std::chrono::steady_clock::now();
 
 int limit_load_secs = 
LOOLWSD::getConfigValue("per_document.limit_load_secs", 100);
 auto loadDeadline = std::chrono::steady_clock::now() + 
std::chrono::seconds(limit_load_secs);
 #endif
+auto last30SecCheckTime = std::chrono::steady_clock::now();
 
 // Main polling loop goodness.
 while (!_stop && _poll->continuePolling() && !TerminationFlag)
@@ -1585,8 +1585,10 @@ bool DocumentBroker::lookupSendClipboardTag(const 
std::shared_ptr
 << "X-Content-Type-Options: nosniff\r\n"
 << "\r\n";
 oss.write(saved->c_str(), saved->length());
+#if !MOBILEAPP
 socket->setSocketBufferSize(std::min(saved->length() + 256,
  
size_t(Socket::MaximumSendBufferSize)));
+#endif
 socket->send(oss.str());
 socket->shutdown();
 LOG_INF("Found and queued clipboard response for send of size " << 
saved->length());
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 978df..1e7febb0b 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1946,6 +1946,8 @@ private:
 }
 };
 
+#if !MOBILEAPP
+
 /// For clipboard setting
 class ClipboardPartHandler : public PartHandler
 {
@@ -1964,6 +1966,8 @@ public:
 }
 };
 
+#endif
+
 /// Handles incoming connections and dispatches to the appropriate handler.
 class ClientRequestDispatcher : public SocketHandlerInterface
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2019-05-30 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |   24 +---
 1 file changed, 21 insertions(+), 3 deletions(-)

New commits:
commit 5663817bab022bf8c81066858d52aa931c520211
Author: Eduard Ardeleanu 
AuthorDate: Fri May 24 09:57:06 2019 +0300
Commit: Jan Holesovsky 
CommitDate: Thu May 30 13:49:40 2019 +0200

detecting password protected files on convertTo

Fail-fast when a file cannot be converted, using convertTo REST API, if the 
file is password protected and the password wasn't received.

Change-Id: I32d807bcecbbe72a38a70fec74caf13638803e1d
Reviewed-on: https://gerrit.libreoffice.org/72891
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 575515756..42e3fa2c4 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -692,6 +692,8 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 return false;
 }
 
+const bool isConvertTo = static_cast(_saveAsSocket);
+
 #if !MOBILEAPP
 LOOLWSD::dumpOutgoingTrace(docBroker->getJailId(), getId(), firstLine);
 #endif
@@ -748,13 +750,30 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 errorKind == "passwordrequired:to-modify" ||
 errorKind == "wrongpassword")
 {
-forwardToClient(payload);
+if (isConvertTo)
+{
+Poco::Net::HTTPResponse response;
+
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED);
+response.set("X-ERROR-KIND", errorKind);
+_saveAsSocket->send(response);
+
+// Conversion failed, cleanup fake session.
+LOG_TRC("Removing save-as ClientSession after 
conversion error.");
+// Remove us.
+docBroker->removeSession(getId());
+// Now terminate.
+docBroker->stop("Aborting saveas handler.");
+}
+else
+{
+forwardToClient(payload);
+}
 return false;
 }
 }
 else
 {
-LOG_WRN("Other than load failure: " << errorKind);
+LOG_WRN(errorCommand << " error failure: " << errorKind);
 }
 }
 }
@@ -786,7 +805,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 #if !MOBILEAPP
 else if (tokens.size() == 3 && tokens[0] == "saveas:")
 {
-bool isConvertTo = static_cast(_saveAsSocket);
 
 std::string encodedURL;
 if (!getTokenString(tokens[1], "url", encodedURL))
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2019-05-23 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |   11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

New commits:
commit bf88897c47e6f21d638ff738adcb462e744e6fd7
Author: Michael Meeks 
AuthorDate: Thu May 23 17:55:01 2019 +0100
Commit: Michael Meeks 
CommitDate: Thu May 23 17:55:38 2019 +0100

Make renamefile more careful.

Change-Id: If39353fc01ea48d8e0077b228a6281839dde5c87

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 576e64f59..575515756 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -217,8 +217,10 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 
 return true;
 }
-else if (tokens[0] == "versionrestore") {
-if (tokens[1] == "prerestore") {
+else if (tokens[0] == "versionrestore")
+{
+if (tokens.size() > 1 && tokens[1] == "prerestore")
+{
 // green signal to WOPI host to restore the version *after* saving
 // any unsaved changes, if any, to the storage
 docBroker->closeDocument("versionrestore: prerestore_ack");
@@ -375,9 +377,10 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 else
 LOG_WRN("Readonly session '" << getId() << "' trying to kill 
another view");
 }
-else if (tokens[0] == "renamefile") {
+else if (tokens[0] == "renamefile")
+{
 std::string encodedWopiFilename;
-if (!getTokenString(tokens[1], "filename", encodedWopiFilename))
+if (tokens.size() < 2 || !getTokenString(tokens[1], "filename", 
encodedWopiFilename))
 {
 LOG_ERR("Bad syntax for: " << firstLine);
 sendTextFrame("error: cmd=renamefile kind=syntax");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/protocol.txt

2019-05-23 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |   11 ---
 wsd/protocol.txt  |5 +
 2 files changed, 13 insertions(+), 3 deletions(-)

New commits:
commit 24b9d6008d43e1f1f7dd90fb160fb217a2dc2c6d
Author: Michael Meeks 
AuthorDate: Thu May 23 12:11:58 2019 +0100
Commit: Michael Meeks 
CommitDate: Thu May 23 12:13:11 2019 +0100

Don't allow readonly views to removesession on editors.

Change-Id: I5c00b83d5a3a5fc59f7c722b9ed7f9753b2b0dc8

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index df68df351..576e64f59 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -366,9 +366,14 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 return true;
 }
 else if (tokens[0] == "removesession") {
-std::string sessionId = Util::encodeId(std::stoi(tokens[1]), 4);
-docBroker->broadcastMessage(firstLine);
-docBroker->removeSession(sessionId);
+if (tokens.size() > 1 && (_isDocumentOwner || !isReadOnly()))
+{
+std::string sessionId = Util::encodeId(std::stoi(tokens[1]), 4);
+docBroker->broadcastMessage(firstLine);
+docBroker->removeSession(sessionId);
+}
+else
+LOG_WRN("Readonly session '" << getId() << "' trying to kill 
another view");
 }
 else if (tokens[0] == "renamefile") {
 std::string encodedWopiFilename;
diff --git a/wsd/protocol.txt b/wsd/protocol.txt
index e1c229665..e1e4f64f8 100644
--- a/wsd/protocol.txt
+++ b/wsd/protocol.txt
@@ -236,6 +236,11 @@ rendershapeselection mimetype=
 Request rendering of selected shapes into an SVG format.
 By now only SVG mimetype is handled (image/svg+xml)
 
+removesession 
+
+Requests the removal of a given view from the document. Lower
+privilege views cannot remove higher ones, eg. a readonly view
+can't remove an editor.
 
 server -> client
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2019-05-17 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

New commits:
commit 8be093ed671eaf58124ebfc0404d241ee56d64de
Author: Michael Meeks 
AuthorDate: Fri May 17 14:26:07 2019 +0100
Commit: Michael Meeks 
CommitDate: Fri May 17 14:27:47 2019 +0100

Tolerate empty first lines.

Change-Id: Ib9aaf82560fc3f5adaa97f40a3de5f3946c6f65d

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 596c1c757..df68df351 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -87,6 +87,12 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 return false;
 }
 
+if (tokens.size() < 1)
+{
+sendTextFrame("error: cmd=empty kind=unknown");
+return false;
+}
+
 LOOLWSD::dumpIncomingTrace(docBroker->getJailId(), getId(), firstLine);
 
 if (LOOLProtocol::tokenIndicatesUserInteraction(tokens[0]))
@@ -97,7 +103,7 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 }
 if (tokens[0] == "loolclient")
 {
-if (tokens.size() < 1)
+if (tokens.size() < 2)
 {
 sendTextFrame("error: cmd=loolclient kind=badprotocolversion");
 return false;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2019-03-20 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

New commits:
commit c8285addec2c1a60a5e68105ab1fa37fde2d04df
Author: Jan Holesovsky 
AuthorDate: Wed Mar 20 08:50:14 2019 +0100
Commit: Jan Holesovsky 
CommitDate: Wed Mar 20 08:50:14 2019 +0100

Kill some extra whitespace.

Change-Id: If0899266ab0ca0d3717fce6eff3a8fca0b4f90ea

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 9eb5cef36..f2b602955 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -801,11 +801,11 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 // Rewrite file:// URLs, as they are visible to the outside world.
 const Path path(docBroker->getJailRoot(), relative);
 if (Poco::File(path).exists())
-{   
-// Encode path for special characters (i.e '%') since 
Poco::URI::setPath implicitly decodes the input param 
+{
+// Encode path for special characters (i.e '%') since 
Poco::URI::setPath implicitly decodes the input param
 std::string encodedPath;
 Poco::URI::encode(path.toString(), "", encodedPath);
-
+
 resultURL.setPath(encodedPath);
 }
 else
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/TestStubs.cpp wsd/TileCache.cpp wsd/TileCache.hpp

2019-03-02 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |   35 ---
 wsd/ClientSession.hpp  |   13 -
 wsd/DocumentBroker.cpp |9 +++--
 wsd/TestStubs.cpp  |7 ---
 wsd/TileCache.cpp  |   28 +++-
 wsd/TileCache.hpp  |6 --
 6 files changed, 22 insertions(+), 76 deletions(-)

New commits:
commit 829e94b779afad5bc6192e54868ecbf17a61633f
Author: Michael Meeks 
AuthorDate: Sat Mar 2 19:26:08 2019 +0100
Commit: Michael Meeks 
CommitDate: Sat Mar 2 21:42:34 2019 +0100

TileCache: remove redundant, expensive tracking in ClientSession.

No need for all these call outs. removeOutdatedTileSubscriptions can't,

Expect it is quicker now and more reliable to trace the tiles being
rendered and count the waiters.

Change-Id: I9724c7f38cf888b35c628857c0f11b51e74613ca

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index c0a02b806..c3d5b9a83 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1315,39 +1315,4 @@ void ClientSession::traceTileBySend(const TileDesc& 
tile, bool deduplicated)
 addTileOnFly(tile);
 }
 
-void ClientSession::traceSubscribeToTile(const std::string& cacheName)
-{
-_tilesBeingRendered.insert(cacheName);
-}
-
-void ClientSession::traceUnSubscribeToTile(const std::string& cacheName)
-{
-_tilesBeingRendered.erase(cacheName);
-}
-
-void ClientSession::removeOutdatedTileSubscriptions()
-{
-const std::shared_ptr docBroker = getDocumentBroker();
-if(!docBroker)
-return;
-
-auto iterator = _tilesBeingRendered.begin();
-while(iterator != _tilesBeingRendered.end())
-{
-double elapsedTime = 
docBroker->tileCache().getTileBeingRenderedElapsedTimeMs(*iterator);
-if(elapsedTime < 0.0 && elapsedTime > 200.0)
-{
-LOG_INF("Tracked TileBeingRendered was dropped because of time 
out.");
-_tilesBeingRendered.erase(iterator);
-}
-else
-++iterator;
-}
-}
-
-void ClientSession::clearTileSubscription()
-{
-_tilesBeingRendered.clear();
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 827a0f857..8db5b3718 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 
 class DocumentBroker;
 
@@ -130,14 +129,6 @@ public:
 /// Call this method anytime when a new tile is sent to the client
 void traceTileBySend(const TileDesc& tile, bool deduplicated = false);
 
-/// Trask tiles what we a subscription to
-void traceSubscribeToTile(const std::string& tileCacheName);
-void traceUnSubscribeToTile(const std::string& tileCacheName);
-void removeOutdatedTileSubscriptions();
-void clearTileSubscription();
-
-size_t getTilesBeingRenderedCount() const {return 
_tilesBeingRendered.size();}
-
 /// Clear wireId map anytime when client visible area changes (visible 
area, zoom, part number)
 void resetWireIdMap();
 
@@ -227,10 +218,6 @@ private:
 /// TileID's of the sent tiles. Push by sending and pop by tileprocessed 
message from the client.
 std::list> 
_tilesOnFly;
 
-/// Names of tiles requested from kit, which this session is subsrcibed to
-/// Track only non-thumbnail tiles (getId() == -1)
-std::unordered_set _tilesBeingRendered;
-
 /// Requested tiles are stored in this list, before we can send them to 
the client
 std::deque _requestedTiles;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 8f058bd2c..888500de8 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1462,9 +1462,6 @@ void DocumentBroker::sendRequestedTiles(const 
std::shared_ptr& se
 tilesOnFlyUpperLimit = 200; // Have a big number here to get all tiles 
requested by file openning
 }
 
-
-// Update client's tilesBeingRendered list
-session->removeOutdatedTileSubscriptions();
 // Drop tiles which we are waiting for too long
 session->removeOutdatedTilesOnFly();
 
@@ -1475,7 +1472,8 @@ void DocumentBroker::sendRequestedTiles(const 
std::shared_ptr& se
 {
 size_t delayedTiles = 0;
 std::vector tilesNeedsRendering;
-while(session->getTilesOnFlyCount() + 
session->getTilesBeingRenderedCount() < tilesOnFlyUpperLimit &&
+size_t beingRendered = 
_tileCache->countTilesBeingRenderedForSession(session);
+while(session->getTilesOnFlyCount() + beingRendered < 
tilesOnFlyUpperLimit &&
   !requestedTiles.empty() &&
   // If we delayed all tiles we don't send any tile (we will when 
next tileprocessed message arrives)
   delayedTiles < requestedTiles.size())
@@ -1516,6 +1514,7 @@ void DocumentBroker::sendRequestedTiles(const 
std::shared_ptr& se
 _debugRenderedTileCount++;
 }
 tileCache().subscribeToTileRendering(tile, session);
+

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2019-03-01 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |5 -
 wsd/DocumentBroker.cpp |   13 +
 wsd/DocumentBroker.hpp |   18 --
 wsd/LOOLWSD.cpp|3 ++-
 4 files changed, 31 insertions(+), 8 deletions(-)

New commits:
commit 2d473222e4cad399b131345395d6506b26e0e134
Author: Michael Meeks 
AuthorDate: Fri Mar 1 22:25:44 2019 +0100
Commit: Michael Meeks 
CommitDate: Fri Mar 1 22:34:29 2019 +0100

tdf#123482 - cleanup convert-to folder more reliably.

Change-Id: I029bb4136984e05485e462c92da80b92b00fdebc

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 49623636a..c0a02b806 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -856,11 +856,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 
 // Now terminate.
 docBroker->stop("Finished saveas handler.");
-
-// Remove file and directory
-Poco::Path path = docBroker->getDocKey();
-Poco::File(path).remove();
-Poco::File(path.makeParent()).remove();
 }
 
 return true;
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 974fe7f3c..8f058bd2c 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1850,6 +1851,18 @@ void DocumentBroker::getIOStats(uint64_t &sent, uint64_t 
&recv)
 }
 }
 
+ConvertToBroker::~ConvertToBroker()
+{
+if (!_uriOrig.empty())
+{
+// Remove source file and directory
+Poco::Path path = _uriOrig;
+Poco::File(path).remove();
+Poco::File(path.makeParent()).remove();
+FileUtil::removeFile(_uriOrig);
+}
+}
+
 void DocumentBroker::dumpState(std::ostream& os)
 {
 std::unique_lock lock(_mutex);
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 46c300df1..bde8b24e4 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -223,7 +223,7 @@ public:
const Poco::URI& uriPublic,
const std::string& docKey);
 
-~DocumentBroker();
+virtual ~DocumentBroker();
 
 /// Start processing events
 void startThread();
@@ -400,8 +400,9 @@ private:
 /// Sum the I/O stats from all connected sessions
 void getIOStats(uint64_t &sent, uint64_t &recv);
 
-private:
+protected:
 const std::string _uriOrig;
+private:
 const Poco::URI _uriPublic;
 /// URL-based key. May be repeated during the lifetime of WSD.
 const std::string _docKey;
@@ -469,6 +470,19 @@ private:
 static std::atomic DocBrokerId;
 };
 
+class ConvertToBroker : public DocumentBroker
+{
+public:
+/// Construct DocumentBroker with URI and docKey
+ConvertToBroker(const std::string& uri,
+const Poco::URI& uriPublic,
+const std::string& docKey)
+: DocumentBroker(uri, uriPublic, docKey)
+{
+}
+virtual ~ConvertToBroker();
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 26321eead..b135fd6bf 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -593,6 +593,7 @@ public:
 if (!params.has("filename"))
 return;
 
+// FIXME: needs wrapping - until then - keep in sync with 
~ConvertToBroker
 Path tempPath = _convertTo? 
Path::forDirectory(Poco::TemporaryFile::tempName("/tmp/convert-to") + "/") :
 
Path::forDirectory(Poco::TemporaryFile::tempName() + "/");
 File(tempPath).createDirectories();
@@ -2365,7 +2366,7 @@ private:
 std::unique_lock 
docBrokersLock(DocBrokersMutex);
 
 LOG_DBG("New DocumentBroker for docKey [" << docKey << 
"].");
-auto docBroker = 
std::make_shared(fromPath, uriPublic, docKey);
+auto docBroker = 
std::make_shared(fromPath, uriPublic, docKey);
 
 cleanupDocBrokers();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/Storage.hpp

2018-11-21 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |   16 +++---
 wsd/DocumentBroker.cpp |   54 -
 wsd/Storage.hpp|   47 ++
 3 files changed, 82 insertions(+), 35 deletions(-)

New commits:
commit 2751f2aebadf5a69ae0f548c31c51f4e4b4323d6
Author: Miklos Vajna 
AuthorDate: Wed Nov 21 09:07:52 2018 +0100
Commit: Miklos Vajna 
CommitDate: Wed Nov 21 09:08:00 2018 +0100

WopiStorage::WOPIFileInfo: make members private

Change-Id: I62b709acf856b86a8880a517f45152abfa6e32b2

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 20819f83c..7d4b0b438 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -196,7 +196,7 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 {
 // If this session is the owner of the file & 'EnableOwnerTermination' 
feature
 // is turned on by WOPI, let it close all sessions
-if (_isDocumentOwner && _wopiFileInfo && 
_wopiFileInfo->_enableOwnerTermination)
+if (_isDocumentOwner && _wopiFileInfo && 
_wopiFileInfo->getEnableOwnerTermination())
 {
 LOG_DBG("Session [" << getId() << "] requested owner termination");
 docBroker->closeDocument("ownertermination");
@@ -567,12 +567,12 @@ bool ClientSession::filterMessage(const std::string& 
message) const
 std::string id;
 if (getTokenString(tokens[2], "id", id))
 {
-if (id == "print" && _wopiFileInfo && _wopiFileInfo->_disablePrint)
+if (id == "print" && _wopiFileInfo && 
_wopiFileInfo->getDisablePrint())
 {
 allowed = false;
 LOG_WRN("WOPI host has disabled print for this session");
 }
-else if (id == "export" && _wopiFileInfo && 
_wopiFileInfo->_disableExport)
+else if (id == "export" && _wopiFileInfo && 
_wopiFileInfo->getDisableExport())
 {
 allowed = false;
 LOG_WRN("WOPI host has disabled export for this session");
@@ -586,7 +586,7 @@ bool ClientSession::filterMessage(const std::string& 
message) const
 }
 else if (tokens[0] == "gettextselection" || tokens[0] == ".uno:Copy")
 {
-if (_wopiFileInfo && _wopiFileInfo->_disableCopy)
+if (_wopiFileInfo && _wopiFileInfo->getDisableCopy())
 {
 allowed = false;
 LOG_WRN("WOPI host has disabled copying from the document");
@@ -884,9 +884,9 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 if (unoStatePair.first == ".uno:TrackChanges")
 {
 if ((unoStatePair.second == "true" &&
- _wopiFileInfo && 
_wopiFileInfo->_disableChangeTrackingRecord == 
WopiStorage::WOPIFileInfo::TriState::True) ||
+ _wopiFileInfo && 
_wopiFileInfo->getDisableChangeTrackingRecord() == 
WopiStorage::WOPIFileInfo::TriState::True) ||
 (unoStatePair.second == "false" &&
- _wopiFileInfo && 
_wopiFileInfo->_disableChangeTrackingRecord == 
WopiStorage::WOPIFileInfo::TriState::False))
+ _wopiFileInfo && 
_wopiFileInfo->getDisableChangeTrackingRecord() == 
WopiStorage::WOPIFileInfo::TriState::False))
 {
 // Toggle the TrackChanges state.
 LOG_DBG("Forcing " << unoStatePair.first << " toggle 
per user settings.");
@@ -896,9 +896,9 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 else if (unoStatePair.first == ".uno:ShowTrackedChanges")
 {
 if ((unoStatePair.second == "true" &&
- _wopiFileInfo && 
_wopiFileInfo->_disableChangeTrackingShow == 
WopiStorage::WOPIFileInfo::TriState::True) ||
+ _wopiFileInfo && 
_wopiFileInfo->getDisableChangeTrackingShow() == 
WopiStorage::WOPIFileInfo::TriState::True) ||
 (unoStatePair.second == "false" &&
- _wopiFileInfo && 
_wopiFileInfo->_disableChangeTrackingShow == 
WopiStorage::WOPIFileInfo::TriState::False))
+ _wopiFileInfo && 
_wopiFileInfo->getDisableChangeTrackingShow() == 
WopiStorage::WOPIFileInfo::TriState::False))
 {
 // Toggle the ShowTrackChanges state.
 LOG_DBG("Forcing " << unoStatePair.first << " toggle 
per user settings.");
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index c14e5a111..2b51934e1 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -493,12 +493,12 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 if (wopiStorage != nullptr)
 {
 std::unique_ptr wopifileinfo = 
wopiStorage->getWOPIFileInfo(session->getAuthorization());
-userId = 

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-11-07 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |5 +
 1 file changed, 5 insertions(+)

New commits:
commit a0f83bd9b915ef3ea6dbdb9ed5ef39ead548276e
Author: Michael Meeks 
AuthorDate: Thu Nov 8 02:35:44 2018 +
Commit: Michael Meeks 
CommitDate: Thu Nov 8 02:36:08 2018 +

Convert-to - cleanup after ourselves.

Change-Id: I85de9721ac1b33d053b59fc36fc7c307206a0888

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 762b5a907..9101c7237 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -854,6 +854,11 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 
 // Now terminate.
 docBroker->stop("Finished saveas handler.");
+
+// Remove file and directory
+Poco::Path path = docBroker->getDocKey();
+Poco::File(path).remove();
+Poco::File(path.makeParent()).remove();
 }
 
 return true;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp

2018-08-23 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |   20 
 wsd/ClientSession.hpp |5 +++--
 2 files changed, 19 insertions(+), 6 deletions(-)

New commits:
commit 185b933353c670ef4639ada323ed2f803f209e70
Author: Tamás Zolnai 
AuthorDate: Thu Aug 23 13:27:47 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Thu Aug 23 13:44:39 2018 +0200

Go back using list for tilesOnFly

It can handle duplicates which we need to have.

Change-Id: Ia4cd813dd173bc538dd27953c4886d460b5b1c49

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 406e24255..588a17ad5 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -343,8 +343,15 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 return false;
 }
 
-size_t retValue = _tilesOnFly.erase(tileID);
-if(retValue == 0)
+auto iter = std::find_if(_tilesOnFly.begin(), _tilesOnFly.end(),
+[&tileID](const std::pair& curTile)
+{
+return curTile.first == tileID;
+});
+
+if(iter != _tilesOnFly.end())
+_tilesOnFly.erase(iter);
+else
 LOG_WRN("Tileprocessed message with an unknown tile ID");
 
 docBroker->sendRequestedTiles(shared_from_this());
@@ -1041,7 +1048,7 @@ Authorization ClientSession::getAuthorization() const
 
 void ClientSession::addTileOnFly(const TileDesc& tile)
 {
-_tilesOnFly.insert({generateTileID(tile), 
std::chrono::steady_clock::now()});
+_tilesOnFly.push_back({generateTileID(tile), 
std::chrono::steady_clock::now()});
 }
 
 void ClientSession::clearTilesOnFly()
@@ -1051,14 +1058,19 @@ void ClientSession::clearTilesOnFly()
 
 void ClientSession::removeOutdatedTilesOnFly()
 {
-for(auto tileIter = _tilesOnFly.begin(); tileIter != _tilesOnFly.end(); 
++tileIter)
+// Check only the beginning of the list, tiles are ordered by timestamp
+bool continueLoop = true;
+while(!_tilesOnFly.empty() && continueLoop)
 {
+auto tileIter = _tilesOnFly.begin();
 double elapsedTimeMs = 
std::chrono::duration_cast(std::chrono::steady_clock::now()
 - tileIter->second).count();
 if(elapsedTimeMs > 3000)
 {
 LOG_WRN("Tracker tileID was dropped because of time out. 
Tileprocessed message did not arrive");
 _tilesOnFly.erase(tileIter);
 }
+else
+continueLoop = false;
 }
 }
 
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 6f55494b2..b4835cfd9 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -19,7 +19,8 @@
 #include 
 #include 
 #include 
-#include 
+#include 
+#include 
 #include 
 
 class DocumentBroker;
@@ -232,7 +233,7 @@ private:
 bool _isTextDocument;
 
 /// TileID's of the sent tiles. Push by sending and pop by tileprocessed 
message from the client.
-std::unordered_map 
_tilesOnFly;
+std::list> 
_tilesOnFly;
 
 /// Names of tiles requested from kit, which this session is subsrcibed to
 /// Track only non-thumbnail tiles (getId() == -1)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-08-23 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 3bd7c6b5084bb2505cf0f2629450974e68b8c050
Author: Tamás Zolnai 
AuthorDate: Thu Aug 23 13:04:48 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Thu Aug 23 13:04:48 2018 +0200

Fix previous commit

Change-Id: I7d3bce0132d124e52f7885c8cb3c26acc6f7b41d

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 99ed308ea..406e24255 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1051,7 +1051,7 @@ void ClientSession::clearTilesOnFly()
 
 void ClientSession::removeOutdatedTilesOnFly()
 {
-for(auto tileIter = _tilesOnFly.begin(); tileIter != _tilesOnFly.begin(); 
++tileIter)
+for(auto tileIter = _tilesOnFly.begin(); tileIter != _tilesOnFly.end(); 
++tileIter)
 {
 double elapsedTimeMs = 
std::chrono::duration_cast(std::chrono::steady_clock::now()
 - tileIter->second).count();
 if(elapsedTimeMs > 3000)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp

2018-08-23 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |   26 --
 wsd/ClientSession.hpp  |4 +++-
 wsd/DocumentBroker.cpp |2 ++
 3 files changed, 25 insertions(+), 7 deletions(-)

New commits:
commit 759d1fe72294b22669f19dabf28a4fcf4922af8c
Author: Tamás Zolnai 
AuthorDate: Thu Aug 23 12:46:49 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Thu Aug 23 12:47:52 2018 +0200

Drop too old tileID's from tiles-on-fly list

So we can avoid that tile sending stop working because server is
waiting for tileprocessed messages which will not arrive.

Change-Id: I545346c50d49340999608aadac32b5190ede43c5

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 4635bd57f..99ed308ea 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -52,7 +52,6 @@ ClientSession::ClientSession(const std::string& id,
 _tileWidthTwips(0),
 _tileHeightTwips(0),
 _isTextDocument(false),
-_tilesOnFly(0),
 _tilesBeingRendered(0)
 {
 const size_t curConnections = ++LOOLWSD::NumConnections;
@@ -343,10 +342,9 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 sendTextFrame("error: cmd=tileprocessed kind=syntax");
 return false;
 }
-auto iter = std::find(_tilesOnFly.begin(), _tilesOnFly.end(), tileID);
-if(iter != _tilesOnFly.end())
-_tilesOnFly.erase(iter);
-else
+
+size_t retValue = _tilesOnFly.erase(tileID);
+if(retValue == 0)
 LOG_WRN("Tileprocessed message with an unknown tile ID");
 
 docBroker->sendRequestedTiles(shared_from_this());
@@ -1043,7 +1041,7 @@ Authorization ClientSession::getAuthorization() const
 
 void ClientSession::addTileOnFly(const TileDesc& tile)
 {
-_tilesOnFly.push_back(generateTileID(tile));
+_tilesOnFly.insert({generateTileID(tile), 
std::chrono::steady_clock::now()});
 }
 
 void ClientSession::clearTilesOnFly()
@@ -1051,6 +1049,19 @@ void ClientSession::clearTilesOnFly()
 _tilesOnFly.clear();
 }
 
+void ClientSession::removeOutdatedTilesOnFly()
+{
+for(auto tileIter = _tilesOnFly.begin(); tileIter != _tilesOnFly.begin(); 
++tileIter)
+{
+double elapsedTimeMs = 
std::chrono::duration_cast(std::chrono::steady_clock::now()
 - tileIter->second).count();
+if(elapsedTimeMs > 3000)
+{
+LOG_WRN("Tracker tileID was dropped because of time out. 
Tileprocessed message did not arrive");
+_tilesOnFly.erase(tileIter);
+}
+}
+}
+
 void ClientSession::onDisconnect()
 {
 LOG_INF(getName() << " Disconnected, current number of connections: " << 
LOOLWSD::NumConnections);
@@ -1245,7 +1256,10 @@ void ClientSession::removeOutdatedTileSubscriptions()
 {
 double elapsedTime = 
docBroker->tileCache().getTileBeingRenderedElapsedTimeMs(*iterator);
 if(elapsedTime < 0.0 && elapsedTime > 5000.0)
+{
+LOG_WRN("Tracked TileBeingRendered was dropped because of time 
out.");
 _tilesBeingRendered.erase(iterator);
+}
 else
 ++iterator;
 }
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 7e7fef7ab..6f55494b2 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 class DocumentBroker;
@@ -125,6 +126,7 @@ public:
 void addTileOnFly(const TileDesc& tile);
 void clearTilesOnFly();
 size_t getTilesOnFlyCount() const { return _tilesOnFly.size(); }
+void removeOutdatedTilesOnFly();
 
 Util::Rectangle getVisibleArea() const { return _clientVisibleArea; }
 int getTileWidthInTwips() const { return _tileWidthTwips; }
@@ -230,7 +232,7 @@ private:
 bool _isTextDocument;
 
 /// TileID's of the sent tiles. Push by sending and pop by tileprocessed 
message from the client.
-std::list _tilesOnFly;
+std::unordered_map 
_tilesOnFly;
 
 /// Names of tiles requested from kit, which this session is subsrcibed to
 /// Track only non-thumbnail tiles (getId() == -1)
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index b01d0753b..310eac031 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1378,6 +1378,8 @@ void DocumentBroker::sendRequestedTiles(const 
std::shared_ptr& se
 
 // Update client's tilesBeingRendered list
 session->removeOutdatedTileSubscriptions();
+// Drop tiles which we are waiting for too long
+session->removeOutdatedTilesOnFly();
 
 // All tiles were processed on client side what we sent last time, so we 
can send a new banch of tiles
 // which was invalidated / requested in the meantime
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/TestStubs.cpp

2018-08-22 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |5 +++--
 wsd/ClientSession.hpp |   16 +++-
 wsd/TestStubs.cpp |2 +-
 3 files changed, 11 insertions(+), 12 deletions(-)

New commits:
commit 3ca4421eb73d17d8dc84fb46284d1746db078988
Author: Tamás Zolnai 
AuthorDate: Wed Aug 22 23:20:27 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Wed Aug 22 23:20:27 2018 +0200

Updated deduplicated tiles wireID

Change-Id: Ia901d8831792de1bee6b21017be02fa1e744e2ee

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index b5494a539..4635bd57f 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1198,7 +1198,7 @@ void ClientSession::resetWireIdMap()
 _oldWireIds.clear();
 }
 
-void ClientSession::traceTileBySend(const TileDesc& tile)
+void ClientSession::traceTileBySend(const TileDesc& tile, bool deduplicated)
 {
 const std::string tileID = generateTileID(tile);
 
@@ -1220,7 +1220,8 @@ void ClientSession::traceTileBySend(const TileDesc& tile)
 }
 
 // Record that the tile is sent
-addTileOnFly(tile);
+if (!deduplicated)
+addTileOnFly(tile);
 }
 
 void ClientSession::traceSubscribeToTile(const std::string& cacheName)
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index bebf985e0..7e7fef7ab 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -86,15 +86,13 @@ public:
 LOG_TRC(getName() << " enqueueing client message " << data->id());
 size_t sizeBefore = _senderQueue.size();
 size_t newSize = _senderQueue.enqueue(data);
-if(sizeBefore != newSize)
+
+// Track sent tile
+const std::string command = data->firstToken();
+if (command == "tile:")
 {
-// Track sent tile
-const std::string command = data->firstToken();
-if (command == "tile:")
-{
-const TileDesc tile = TileDesc::parse(data->firstLine());
-traceTileBySend(tile);
-}
+const TileDesc tile = TileDesc::parse(data->firstLine());
+traceTileBySend(tile, sizeBefore == newSize);
 }
 }
 
@@ -134,7 +132,7 @@ public:
 
 /// This method updates internal data related to sent tiles (wireID and 
tiles-on-fly)
 /// Call this method anytime when a new tile is sent to the client
-void traceTileBySend(const TileDesc& tile);
+void traceTileBySend(const TileDesc& tile, bool deduplicated = false);
 
 /// Trask tiles what we a subscription to
 void traceSubscribeToTile(const std::string& tileCacheName);
diff --git a/wsd/TestStubs.cpp b/wsd/TestStubs.cpp
index 038c2f9de..af4231e5d 100644
--- a/wsd/TestStubs.cpp
+++ b/wsd/TestStubs.cpp
@@ -20,7 +20,7 @@
 void DocumentBroker::assertCorrectThread() const {}
 
 
-void ClientSession::traceTileBySend(const TileDesc& /*tile*/) {}
+void ClientSession::traceTileBySend(const TileDesc& /*tile*/, bool 
/*deduplicated = false*/) {}
 
 void ClientSession::traceSubscribeToTile(const std::string& /*tileCacheName*/) 
{};
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/SenderQueue.hpp

2018-08-20 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |5 -
 wsd/ClientSession.hpp  |2 --
 wsd/DocumentBroker.cpp |1 -
 wsd/SenderQueue.hpp|9 -
 4 files changed, 17 deletions(-)

New commits:
commit 7d98b5f01567af9625eaacbf25da671362a27c56
Author: Tamás Zolnai 
AuthorDate: Mon Aug 20 15:03:57 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Mon Aug 20 15:13:59 2018 +0200

Revert "Get back "Cancel tiles also in wsd's senderqueue""

This reverts commit f1a385be98aba7191de79606d1cfdfa6973dfc39.

It's not easy, it can interfere the tile tracking.

Change-Id: I1e4ec9b4d66e5e912873f673fd5cb71ba55a9332
Reviewed-on: https://gerrit.libreoffice.org/59326
Reviewed-by: Tamás Zolnai 
Tested-by: Tamás Zolnai 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 3f27a435c..90e099d38 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1001,11 +1001,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 return forwardToClient(payload);
 }
 
-void ClientSession::cancelTilesInQueue()
-{
-_senderQueue.cancelTiles();
-}
-
 bool ClientSession::forwardToClient(const std::shared_ptr& payload)
 {
 if (isCloseFrame())
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 4037d81a2..997058f68 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -99,8 +99,6 @@ public:
 }
 }
 
-void cancelTilesInQueue();
-
 /// Set the save-as socket which is used to send convert-to results.
 void setSaveAsSocket(const std::shared_ptr& socket)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index cf5c8eb84..be5c3aae4 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1448,7 +1448,6 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 // Clear tile requests
 session->clearTilesOnFly();
 session->getRequestedTiles() = boost::none;
-session->cancelTilesInQueue();
 
 session->clearTileSubscription();
 
diff --git a/wsd/SenderQueue.hpp b/wsd/SenderQueue.hpp
index 927e3e735..fc3464b3f 100644
--- a/wsd/SenderQueue.hpp
+++ b/wsd/SenderQueue.hpp
@@ -84,15 +84,6 @@ public:
 }
 }
 
-void cancelTiles()
-{
-std::remove_if(_queue.begin(), _queue.end(),
-[](const queue_item_t& cur)
-{
-return cur->firstToken() == "tile:";
-});
-}
-
 private:
 /// Deduplicate messages based on the new one.
 /// Returns true if the new message should be
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/SenderQueue.hpp

2018-08-17 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |5 +
 wsd/ClientSession.hpp  |2 ++
 wsd/DocumentBroker.cpp |1 +
 wsd/SenderQueue.hpp|9 +
 4 files changed, 17 insertions(+)

New commits:
commit f1a385be98aba7191de79606d1cfdfa6973dfc39
Author: Tamás Zolnai 
AuthorDate: Fri Aug 17 23:36:47 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Fri Aug 17 23:47:10 2018 +0200

Get back "Cancel tiles also in wsd's senderqueue"

This reverts commit ec8b7bc012503559841c96c5a16c13798c103387.

Change-Id: I0a4f3f529c86522261085d4feec45e4b56a7e0e6

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 90e099d38..3f27a435c 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1001,6 +1001,11 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 return forwardToClient(payload);
 }
 
+void ClientSession::cancelTilesInQueue()
+{
+_senderQueue.cancelTiles();
+}
+
 bool ClientSession::forwardToClient(const std::shared_ptr& payload)
 {
 if (isCloseFrame())
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 997058f68..4037d81a2 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -99,6 +99,8 @@ public:
 }
 }
 
+void cancelTilesInQueue();
+
 /// Set the save-as socket which is used to send convert-to results.
 void setSaveAsSocket(const std::shared_ptr& socket)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index be5c3aae4..cf5c8eb84 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1448,6 +1448,7 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 // Clear tile requests
 session->clearTilesOnFly();
 session->getRequestedTiles() = boost::none;
+session->cancelTilesInQueue();
 
 session->clearTileSubscription();
 
diff --git a/wsd/SenderQueue.hpp b/wsd/SenderQueue.hpp
index fc3464b3f..927e3e735 100644
--- a/wsd/SenderQueue.hpp
+++ b/wsd/SenderQueue.hpp
@@ -84,6 +84,15 @@ public:
 }
 }
 
+void cancelTiles()
+{
+std::remove_if(_queue.begin(), _queue.end(),
+[](const queue_item_t& cur)
+{
+return cur->firstToken() == "tile:";
+});
+}
+
 private:
 /// Deduplicate messages based on the new one.
 /// Returns true if the new message should be
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/LOOLWSD.cpp

2018-08-15 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp |   43 
 wsd/ClientSession.hpp |   12 
 wsd/LOOLWSD.cpp   |   67 +-
 3 files changed, 9 insertions(+), 113 deletions(-)

New commits:
commit 4dd62d4dd2d2b467a70c5735b91d691522769834
Author: Tor Lillqvist 
AuthorDate: Thu Jul 12 15:50:04 2018 +0300
Commit: Tor Lillqvist 
CommitDate: Wed Aug 15 15:01:03 2018 +0300

Revert "Add a cache of "thumbnails" (PNG images) generated using the 
convert-to API"

No need to keep such a cache here. The consumer of previews
(thumbnails) in question does it itself (Nextcloud).

This reverts commit 405b66c8db71c314c2d26c4b18e9d74806c76bf1

Change-Id: Iad16212ccbc875fe4f6d041e2fceef7eaea1d1bb

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index b11331dc8..90e099d38 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -14,7 +14,6 @@
 #include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
@@ -38,14 +37,10 @@ using Poco::StringTokenizer;
 ClientSession::ClientSession(const std::string& id,
  const std::shared_ptr& docBroker,
  const Poco::URI& uriPublic,
- const bool readOnly,
- const bool creatingPngThumbnail,
- const std::string& thumbnailFile) :
+ const bool readOnly) :
 Session("ToClient-" + id, id, readOnly),
 _docBroker(docBroker),
 _uriPublic(uriPublic),
-_creatingPngThumbnail(creatingPngThumbnail),
-_thumbnailFile(thumbnailFile),
 _isDocumentOwner(false),
 _isAttached(false),
 _isViewLoaded(false),
@@ -60,7 +55,6 @@ ClientSession::ClientSession(const std::string& id,
 _tilesOnFly(0),
 _tilesBeingRendered(0)
 {
-assert(!creatingPngThumbnail || thumbnailFile != "");
 const size_t curConnections = ++LOOLWSD::NumConnections;
 LOG_INF("ClientSession ctor [" << getName() << "], current number of 
connections: " << curConnections);
 }
@@ -840,41 +834,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 response.set("Content-Disposition", "attachment; 
filename=\"" + fileName + "\"");
 
 HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType, 
response);
-
-if (_creatingPngThumbnail)
-{
-// Save the created PNG "thumbnail" under a name 
constructed from the SHA1 of
-// the document contents.
-
-// FIXME: We could first try to simply hardlink the result 
as the thumbnail.
-
-
Poco::File(Poco::Path(_thumbnailFile).parent()).createDirectories();
-std::ofstream thumbnail(_thumbnailFile, std::ios::binary);
-
-if (thumbnail.is_open() && thumbnail.good())
-{
-std::ifstream result(resultURL.getPath(), 
std::ios::binary);
-if (result.is_open() && result.good())
-{
-Poco::StreamCopier::copyStream(result, thumbnail);
-if (!result.bad() && thumbnail.good())
-{
-LOG_TRC("Created cached thumbnail " << 
_thumbnailFile);
-}
-else
-{
-thumbnail.close();
-unlink(_thumbnailFile.c_str());
-}
-}
-}
-else
-{
-if (thumbnail.is_open())
-thumbnail.close();
-unlink(_thumbnailFile.c_str());
-}
-}
 }
 
 // Conversion is done, cleanup this fake session.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index ae8a6937d..997058f68 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -32,9 +32,7 @@ public:
 ClientSession(const std::string& id,
   const std::shared_ptr& docBroker,
   const Poco::URI& uriPublic,
-  const bool isReadOnly = false,
-  const bool creatingPngThumbnail = false,
-  const std::string& thumbnailFile = "");
+  const bool isReadOnly = false);
 
 virtual ~ClientSession();
 
@@ -199,14 +197,6 @@ private:
 /// URI with which client made request to us
 const Poco::URI _uriPublic;
 
-/// True iff this is a convert-to operation creating a PNG. We assume all 
such PNGs will be
-/// usable as "thumbnails" for the document.
-const bool _creatingPngThumbnail;
-
-/// The pathname of the thumbnail file being created. Valid only if 

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/SenderQueue.hpp wsd/TileCache.cpp

2018-07-31 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |5 +
 wsd/ClientSession.hpp  |2 ++
 wsd/DocumentBroker.cpp |1 +
 wsd/SenderQueue.hpp|9 +
 wsd/TileCache.cpp  |5 +++--
 5 files changed, 20 insertions(+), 2 deletions(-)

New commits:
commit 0bb96131c495dfe1d98ebbfe01df5c4268d16de8
Author: Tamás Zolnai 
AuthorDate: Tue Jul 31 13:03:05 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Tue Jul 31 13:18:44 2018 +0200

Cancel tiles also in wsd's senderqueue

Change-Id: I683b3cacee2f87d0dc0f28ad9ac3e122bcd043f1

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index b421d3304..886a3dcec 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1040,6 +1040,11 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 return forwardToClient(payload);
 }
 
+void ClientSession::cancelTilesInQueue()
+{
+_senderQueue.cancelTiles();
+}
+
 bool ClientSession::forwardToClient(const std::shared_ptr& payload)
 {
 if (isCloseFrame())
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index fe565a672..8d434f44a 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -100,6 +100,8 @@ public:
 }
 }
 
+void cancelTilesInQueue();
+
 /// Set the save-as socket which is used to send convert-to results.
 void setSaveAsSocket(const std::shared_ptr& socket)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 84ad69a15..e6ead209a 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1445,6 +1445,7 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 // Clear tile requests
 session->clearTilesOnFly();
 session->getRequestedTiles() = boost::none;
+session->cancelTilesInQueue();
 
 const std::string canceltiles = tileCache().cancelTiles(session);
 if (!canceltiles.empty())
diff --git a/wsd/SenderQueue.hpp b/wsd/SenderQueue.hpp
index fc3464b3f..927e3e735 100644
--- a/wsd/SenderQueue.hpp
+++ b/wsd/SenderQueue.hpp
@@ -84,6 +84,15 @@ public:
 }
 }
 
+void cancelTiles()
+{
+std::remove_if(_queue.begin(), _queue.end(),
+[](const queue_item_t& cur)
+{
+return cur->firstToken() == "tile:";
+});
+}
+
 private:
 /// Deduplicate messages based on the new one.
 /// Returns true if the new message should be
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index f80f64a1c..efa68e4ba 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -529,7 +529,7 @@ std::string TileCache::cancelTiles(const 
std::shared_ptr &subscri
 
 assertCorrectThread();
 
-const ClientSession* sub = subscriber.get();
+ClientSession* sub = subscriber.get();
 
 std::ostringstream oss;
 
@@ -564,7 +564,8 @@ std::string TileCache::cancelTiles(const 
std::shared_ptr &subscri
 ++it;
 }
 
-subscriber->clearSubscription();
+if(sub)
+sub->clearSubscription();
 const std::string canceltiles = oss.str();
 return canceltiles.empty() ? canceltiles : "canceltiles " + canceltiles;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-07-15 Thread Pranav Kant
 wsd/ClientSession.cpp |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 6f8b15dfa81f1146bc144e806e2de5273432ab43
Author: Pranav Kant 
Date:   Mon Jul 16 10:34:24 2018 +0530

wsd: missing include

Change-Id: I561db86b4b46f1cff0d9f0c744c556d9ec74291f

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 353b73263..0cd76c9f8 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/LOOLWSD.cpp

2018-07-12 Thread Tor Lillqvist
 wsd/ClientSession.cpp |   43 -
 wsd/ClientSession.hpp |   12 -
 wsd/LOOLWSD.cpp   |   64 --
 3 files changed, 110 insertions(+), 9 deletions(-)

New commits:
commit 405b66c8db71c314c2d26c4b18e9d74806c76bf1
Author: Tor Lillqvist 
Date:   Thu Jul 12 15:50:04 2018 +0300

Add a cache of "thumbnails" (PNG images) generated using the convert-to API

When asked to "convert" a document to a PNG image, i.e. what one can
call a thumbnail, check if we have a cached PNG for the same docuemnt
already, and in that case return it.

When we have done such a convert-to operation to PNG, save the result
in the cache for later re-use.

This change adds no thumbnail cache cleanup mechanism. That will have
to be implemented separately using a cron job or whatever.

There are further improvement possibilities: For instance, if the
document is of a type that contains an embedded thumbnail (like ODF),
just extract and return that. For ODF that embedded thumbnail even
already is in PNG format.

Change-Id: I882efe97acc1d81041dc7a4ccb222995940e4836
Reviewed-on: https://gerrit.libreoffice.org/57345
Reviewed-by: Tor Lillqvist 
Tested-by: Tor Lillqvist 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index ee2a3f941..353b73263 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -13,6 +13,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -35,15 +36,20 @@ using Poco::StringTokenizer;
 ClientSession::ClientSession(const std::string& id,
  const std::shared_ptr& docBroker,
  const Poco::URI& uriPublic,
- const bool readOnly) :
+ const bool readOnly,
+ const bool creatingPngThumbnail,
+ const std::string& thumbnailFile) :
 Session("ToClient-" + id, id, readOnly),
 _docBroker(docBroker),
 _uriPublic(uriPublic),
+_creatingPngThumbnail(creatingPngThumbnail),
+_thumbnailFile(thumbnailFile),
 _isDocumentOwner(false),
 _isAttached(false),
 _isViewLoaded(false),
 _keyEvents(1)
 {
+assert(!creatingPngThumbnail || thumbnailFile != "");
 const size_t curConnections = ++LOOLWSD::NumConnections;
 LOG_INF("ClientSession ctor [" << getName() << "], current number of 
connections: " << curConnections);
 }
@@ -722,6 +728,41 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 response.set("Content-Disposition", "attachment; 
filename=\"" + fileName + "\"");
 
 HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType, 
response);
+
+if (_creatingPngThumbnail)
+{
+// Save the created PNG "thumbnail" under a name 
constructed from the SHA1 of
+// the document contents.
+
+// FIXME: We could first try to simply hardlink the result 
as the thumbnail.
+
+
Poco::File(Poco::Path(_thumbnailFile).parent()).createDirectories();
+std::ofstream thumbnail(_thumbnailFile, std::ios::binary);
+
+if (thumbnail.is_open() && thumbnail.good())
+{
+std::ifstream result(resultURL.getPath(), 
std::ios::binary);
+if (result.is_open() && result.good())
+{
+Poco::StreamCopier::copyStream(result, thumbnail);
+if (!result.bad() && thumbnail.good())
+{
+LOG_TRC("Created cached thumbnail " << 
_thumbnailFile);
+}
+else
+{
+thumbnail.close();
+unlink(_thumbnailFile.c_str());
+}
+}
+}
+else
+{
+if (thumbnail.is_open())
+thumbnail.close();
+unlink(_thumbnailFile.c_str());
+}
+}
 }
 
 // Conversion is done, cleanup this fake session.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 2366ca78b..df7faa45f 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -26,7 +26,9 @@ public:
 ClientSession(const std::string& id,
   const std::shared_ptr& docBroker,
   const Poco::URI& uriPublic,
-  const bool isReadOnly = false);
+  const bool isReadOnly = false,
+  const bool creatingPngThumbnail = false,
+  const std::string& thumbnail

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-07-11 Thread Tor Lillqvist
 wsd/ClientSession.cpp |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit 1c09d4a6074d9320cd321832f83466fddaf72cd5
Author: Tor Lillqvist 
Date:   Wed Jul 11 12:32:29 2018 +0300

Improve logging a bit

Log all error: cases in ClientSession::handleKitToClientMessage(), not
just the case of cmd=load with kind= some password failure.

Change-Id: I53c959068f5642ae41157e8feb14fd34fc59dc9a

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 337221f1d..ee2a3f941 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -619,15 +619,19 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 {
 if (errorCommand == "load")
 {
+LOG_WRN("Document load failed: " << errorKind);
 if (errorKind == "passwordrequired:to-view" ||
 errorKind == "passwordrequired:to-modify" ||
 errorKind == "wrongpassword")
 {
 forwardToClient(payload);
-LOG_WRN("Document load failed: " << errorKind);
 return false;
 }
 }
+else
+{
+LOG_WRN("Other than load failure: " << errorKind);
+}
 }
 }
 else if (tokens[0] == "curpart:" && tokens.size() == 2)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-06-14 Thread Jan Holesovsky
 wsd/ClientSession.cpp |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit b65894b28777505c611156a11e6b6377a04ead91
Author: Jan Holesovsky 
Date:   Wed Apr 25 13:46:23 2018 +0200

Avoid crash in the non-wopi case.

Change-Id: I87aff462dab4abca0235622493f720eacbc39f03
Reviewed-on: https://gerrit.libreoffice.org/53448
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 70ee741fa..337221f1d 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -750,9 +750,9 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 if (unoStatePair.first == ".uno:TrackChanges")
 {
 if ((unoStatePair.second == "true" &&
- _wopiFileInfo->_disableChangeTrackingRecord == 
WopiStorage::WOPIFileInfo::TriState::True) ||
+ _wopiFileInfo && 
_wopiFileInfo->_disableChangeTrackingRecord == 
WopiStorage::WOPIFileInfo::TriState::True) ||
 (unoStatePair.second == "false" &&
- _wopiFileInfo->_disableChangeTrackingRecord == 
WopiStorage::WOPIFileInfo::TriState::False))
+ _wopiFileInfo && 
_wopiFileInfo->_disableChangeTrackingRecord == 
WopiStorage::WOPIFileInfo::TriState::False))
 {
 // Toggle the TrackChanges state.
 LOG_DBG("Forcing " << unoStatePair.first << " toggle 
per user settings.");
@@ -762,9 +762,9 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 else if (unoStatePair.first == ".uno:ShowTrackedChanges")
 {
 if ((unoStatePair.second == "true" &&
- _wopiFileInfo->_disableChangeTrackingShow == 
WopiStorage::WOPIFileInfo::TriState::True) ||
+ _wopiFileInfo && 
_wopiFileInfo->_disableChangeTrackingShow == 
WopiStorage::WOPIFileInfo::TriState::True) ||
 (unoStatePair.second == "false" &&
- _wopiFileInfo->_disableChangeTrackingShow == 
WopiStorage::WOPIFileInfo::TriState::False))
+ _wopiFileInfo && 
_wopiFileInfo->_disableChangeTrackingShow == 
WopiStorage::WOPIFileInfo::TriState::False))
 {
 // Toggle the ShowTrackChanges state.
 LOG_DBG("Forcing " << unoStatePair.first << " toggle 
per user settings.");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.cpp wsd/Storage.hpp

2018-06-14 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |   35 +++
 wsd/DocumentBroker.cpp |   13 -
 wsd/DocumentBroker.hpp |9 +
 wsd/Storage.cpp|   20 +---
 wsd/Storage.hpp|   24 
 5 files changed, 93 insertions(+), 8 deletions(-)

New commits:
commit b3bdd5786d48da4b4073d05b9eddba9d242ac6bf
Author: Ashod Nakashian 
Date:   Tue Apr 24 12:09:37 2018 -0400

wsd: support optional forcing tracking changes at load

Since changing the tracking state is done by toggling,
we need to wait to get the current state at load time
before we can tell whether we need to toggle it or not.

Change-Id: Ib5a2639b2acf3874c191971eedf9a3bebcefebad
Reviewed-on: https://gerrit.libreoffice.org/53415
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 8203b2a34..70ee741fa 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -19,6 +19,7 @@
 
 #include "DocumentBroker.hpp"
 #include "LOOLWSD.hpp"
+#include "Storage.hpp"
 #include 
 #include 
 #include 
@@ -738,6 +739,40 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 {
 docBroker->setModified(stateTokens[1] == "true");
 }
+else
+{
+// Set the initial settings per the user's request.
+const std::pair unoStatePair = 
LOOLProtocol::split(tokens[1], '=');
+
+if (!docBroker->isInitialSettingSet(unoStatePair.first))
+{
+docBroker->setInitialSetting(unoStatePair.first);
+if (unoStatePair.first == ".uno:TrackChanges")
+{
+if ((unoStatePair.second == "true" &&
+ _wopiFileInfo->_disableChangeTrackingRecord == 
WopiStorage::WOPIFileInfo::TriState::True) ||
+(unoStatePair.second == "false" &&
+ _wopiFileInfo->_disableChangeTrackingRecord == 
WopiStorage::WOPIFileInfo::TriState::False))
+{
+// Toggle the TrackChanges state.
+LOG_DBG("Forcing " << unoStatePair.first << " toggle 
per user settings.");
+forwardToChild("uno .uno:TrackChanges", docBroker);
+}
+}
+else if (unoStatePair.first == ".uno:ShowTrackedChanges")
+{
+if ((unoStatePair.second == "true" &&
+ _wopiFileInfo->_disableChangeTrackingShow == 
WopiStorage::WOPIFileInfo::TriState::True) ||
+(unoStatePair.second == "false" &&
+ _wopiFileInfo->_disableChangeTrackingShow == 
WopiStorage::WOPIFileInfo::TriState::False))
+{
+// Toggle the ShowTrackChanges state.
+LOG_DBG("Forcing " << unoStatePair.first << " toggle 
per user settings.");
+forwardToChild("uno .uno:ShowTrackedChanges", 
docBroker);
+}
+}
+}
+}
 }
 
 if (!_isDocPasswordProtected)
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 1006dc2dc..4d465a39d 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -502,12 +502,13 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 wopiInfo->set("HidePrintOption", wopifileinfo->_hidePrintOption);
 wopiInfo->set("HideSaveOption", wopifileinfo->_hideSaveOption);
 wopiInfo->set("HideExportOption", wopifileinfo->_hideExportOption);
-wopiInfo->set("HideChangeTrackingControls", 
wopifileinfo->_hideChangeTrackingControls);
 wopiInfo->set("DisablePrint", wopifileinfo->_disablePrint);
 wopiInfo->set("DisableExport", wopifileinfo->_disableExport);
 wopiInfo->set("DisableCopy", wopifileinfo->_disableCopy);
 wopiInfo->set("DisableInactiveMessages", 
wopifileinfo->_disableInactiveMessages);
 wopiInfo->set("UserCanNotWriteRelative", 
wopifileinfo->_userCanNotWriteRelative);
+if (wopifileinfo->_hideChangeTrackingControls != 
WopiStorage::WOPIFileInfo::TriState::Unset)
+wopiInfo->set("HideChangeTrackingControls", 
wopifileinfo->_hideChangeTrackingControls == 
WopiStorage::WOPIFileInfo::TriState::True);
 
 std::ostringstream ossWopiInfo;
 wopiInfo->stringify(ossWopiInfo);
@@ -1447,6 +1448,16 @@ void DocumentBroker::setModified(const bool value)
 _tileCache->setUnsavedChanges(value);
 }
 
+bool DocumentBroker::isInitialSettingSet(const std::string& name) const
+{
+return _isInitialStateSet.find(name) != _isInitialStateSet.end();
+}
+
+void DocumentBroker::setInitialSetting(const std::string& name)
+{
+_isInitialStateSet.emplace(name);
+}
+
 bool DocumentBroker::forwardToChild(const std::string& viewId, const 
std::string& messag

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-06-14 Thread Ashod Nakashian
 wsd/ClientSession.cpp |5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

New commits:
commit d3d4812583a1feb9cb2fe4d1aafcd9c20f362cae
Author: Ashod Nakashian 
Date:   Wed Feb 28 09:20:55 2018 -0500

wsd: localize variables

Change-Id: I411e435fa2360423b4c48d087eb501b942cc637d
Reviewed-on: https://gerrit.libreoffice.org/52419
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 00833bd05..8203b2a34 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -834,16 +834,13 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 
 bool ClientSession::forwardToClient(const std::shared_ptr& payload)
 {
-const auto& message = payload->abbr();
-
 if (isCloseFrame())
 {
-LOG_TRC(getName() << ": peer began the closing handshake. Dropping 
forward message [" << message << "].");
+LOG_TRC(getName() << ": peer began the closing handshake. Dropping 
forward message [" << payload->abbr() << "].");
 return true;
 }
 
 enqueueSendMessage(payload);
-
 return true;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-04-13 Thread Tamás Zolnai
 wsd/ClientSession.cpp |   21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

New commits:
commit 347c0705c20b98a787bb59902f57b6df0e104bb0
Author: Tamás Zolnai 
Date:   Thu Apr 12 20:28:54 2018 +0200

Update dumper code to handle new payload for invalidatecursor

Change-Id: Ibfe129ce4db9ff33d409fb6ebabfb3a435b64829
Reviewed-on: https://gerrit.libreoffice.org/52796
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 12f30a8e5..00833bd05 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -781,16 +781,23 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 else if (tokens[0] == "invalidatecursor:")
 {
 assert(firstLine.size() == 
static_cast(length));
-StringTokenizer firstLineTokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+
+const size_t index = firstLine.find_first_of('{');
+const std::string stringJSON = firstLine.substr(index);
+Poco::JSON::Parser parser;
+const Poco::Dynamic::Var result = parser.parse(stringJSON);
+const auto& object = result.extract();
+const std::string rectangle = object->get("rectangle").toString();
+StringTokenizer rectangleTokens(rectangle, ",", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 int x = 0, y = 0, w = 0, h = 0;
-if (firstLineTokens.count() > 2 &&
-stringToInteger(firstLineTokens[1], x) &&
-stringToInteger(firstLineTokens[2], y))
+if (rectangleTokens.count() > 2 &&
+stringToInteger(rectangleTokens[0], x) &&
+stringToInteger(rectangleTokens[1], y))
 {
-if (firstLineTokens.count() > 3)
+if (rectangleTokens.count() > 3)
 {
-stringToInteger(firstLineTokens[3], w);
-stringToInteger(firstLineTokens[4], h);
+stringToInteger(rectangleTokens[2], w);
+stringToInteger(rectangleTokens[3], h);
 }
 
 docBroker->invalidateCursor(x, y, w, h);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-02-23 Thread Ashod Nakashian
 wsd/ClientSession.cpp |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

New commits:
commit 7c2c0062e34c7da6686046e5e9392501353657ec
Author: Ashod Nakashian 
Date:   Wed Feb 21 20:41:47 2018 -0500

wsd: always avoid saving readonly files

Otherwise saving is bound to fail, causing other
errors, which is nonsensical since there is nothing
to save to begin with.

Change-Id: Icb65a4a3b277b3175aadbe5107b294b24a399e7b
Reviewed-on: https://gerrit.libreoffice.org/50148
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 47e2f631..12f30a8e 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -237,11 +237,12 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 else if (tokens[0] == "save")
 {
 int dontTerminateEdit = 1;
-int dontSaveIfUnmodified = 1;
 if (tokens.size() > 1)
 getTokenInteger(tokens[1], "dontTerminateEdit", dontTerminateEdit);
 
-if (tokens.size() > 2)
+// Don't save unmodified docs by default, or when read-only.
+int dontSaveIfUnmodified = 1;
+if (!isReadOnly() && tokens.size() > 2)
 getTokenInteger(tokens[2], "dontSaveIfUnmodified", 
dontSaveIfUnmodified);
 
 docBroker->sendUnoSave(getId(), dontTerminateEdit != 0, 
dontSaveIfUnmodified != 0);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2018-02-07 Thread Pranav Kant
 wsd/ClientSession.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit bd7b2b833c064a64d830d1b032cb8c98e85cd2a9
Author: Pranav Kant 
Date:   Fri Feb 2 13:08:25 2018 +0530

wsd: Don't request closing here, just stop the broker

Asking the doc broker to close means that it will save the current
document to storage before shutting down. But we don't want that because
storing the current document to storage means overwriting the document
which has been changed underneath us.

Change-Id: I8df45d2f0cf3f65936dc3030f483e52fd1703146
Reviewed-on: https://gerrit.libreoffice.org/49134
Reviewed-by: pranavk 
Tested-by: pranavk 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 8d727247..d94a8467 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -190,7 +190,7 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 LOG_DBG("Document marked as changed in storage and user ["
 << getUserId() << ", " << getUserName()
 << "] wants to refresh the document for all.");
-docBroker->closeDocument("documentconflict " + getUserName());
+docBroker->stop("documentconflict " + getUserName());
 }
 
 return true;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2018-01-15 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |2 +-
 wsd/DocumentBroker.cpp |   30 ++
 wsd/DocumentBroker.hpp |2 +-
 wsd/LOOLWSD.cpp|4 ++--
 4 files changed, 22 insertions(+), 16 deletions(-)

New commits:
commit b5baf3672fab052e5d7457fdb3a8c60c8fa70107
Author: Ashod Nakashian 
Date:   Sun Jan 14 20:49:11 2018 -0500

wsd: stop DocBroker using only stop() member

Now always given a proper reason too.

Also, stop polling thread and cleanup when
failing to acquire/spawn a child process.

Change-Id: I7ddee01dd47b8ee72f2d9134c0f1b264634d8611
Reviewed-on: https://gerrit.libreoffice.org/47886
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 061504c3..f644ae2c 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -716,7 +716,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 docBroker->removeSession(getId());
 
 // Now terminate.
-docBroker->stop();
+docBroker->stop("Finished saveas handler.");
 }
 
 return true;
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 44574aab..28a4920d 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -198,7 +198,7 @@ void DocumentBroker::pollThread()
   
_threadStart).count() > timeoutMs)
 break;
 
-// Nominal time between retries, lest we  busy-loop. getNewChild could 
also wait, so don't double that here.
+// Nominal time between retries, lest we busy-loop. getNewChild could 
also wait, so don't double that here.
 
std::this_thread::sleep_for(std::chrono::milliseconds(CHILD_REBALANCE_INTERVAL_MS
 / 10));
 }
 while (!_stop && _poll->continuePolling() && !TerminationFlag && 
!ShutdownRequestFlag);
@@ -209,14 +209,21 @@ void DocumentBroker::pollThread()
 LOG_ERR("Failed to get new child.");
 
 // FIXME: need to notify all clients and shut this down ...
+// FIXME: return something good down the websocket ...
 #if 0
 const std::string msg = SERVICE_UNAVAILABLE_INTERNAL_ERROR;
 ws.sendMessage(msg);
 // abnormal close frame handshake
 ws.shutdown(WebSocketHandler::StatusCodes::ENDPOINT_GOING_AWAY);
 #endif
-// FIXME: return something good down the websocket ...
-_stop = true;
+stop("Failed to get new child.");
+
+// Stop to mark it done and cleanup.
+_poll->stop();
+_poll->removeSockets();
+
+// Async cleanup.
+LOOLWSD::doHousekeeping();
 
 LOG_INF("Finished docBroker polling thread for docKey [" << _docKey << 
"].");
 return;
@@ -269,8 +276,7 @@ void DocumentBroker::pollThread()
 if (ShutdownRequestFlag)
 {
 autoSave(true);
-_closeReason = "recycling";
-_stop = true;
+stop("recycling");
 }
 else if (AutoSaveEnabled && !_stop &&
  std::chrono::duration_cast(now - 
last30SecCheckTime).count() >= 30)
@@ -288,8 +294,7 @@ void DocumentBroker::pollThread()
 {
 LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
 " DocumentBroker for docKey [" << getDocKey() << "].");
-_closeReason = (idle ? "idle" : "dead");
-_stop = true;
+stop(idle ? "idle" : "dead");
 }
 }
 
@@ -374,8 +379,10 @@ void DocumentBroker::joinThread()
 _poll->joinThread();
 }
 
-void DocumentBroker::stop()
+void DocumentBroker::stop(const std::string& reason)
 {
+LOG_DBG("Closing DocumentBroker for docKey [" << _docKey << "] with 
reason: " << reason);
+_closeReason = reason; // used later in the polling loop
 _stop = true;
 _poll->wakeup();
 }
@@ -1553,7 +1560,7 @@ void DocumentBroker::terminateChild(const std::string& 
closeReason)
 
 LOG_INF("Terminating doc [" << _docKey << "] with reason: " << 
closeReason);
 
-// Close all running sessions
+// Close all running sessions first.
 shutdownClients(closeReason);
 
 if (_childProcess)
@@ -1566,7 +1573,7 @@ void DocumentBroker::terminateChild(const std::string& 
closeReason)
 _childProcess->close(false);
 }
 
-_stop = true;
+stop(closeReason);
 }
 
 void DocumentBroker::closeDocument(const std::string& reason)
@@ -1574,8 +1581,7 @@ void DocumentBroker::closeDocument(const std::string& 
reason)
 assertCorrectThread();
 
 LOG_DBG("Closing DocumentBroker for docKey [" << _docKey << "] with 
reason: " << reason);
-_closeReason = reason; // used later in the polling loop
-stop();
+stop(reason);
 }
 
 void DocumentBroker::broadcastMessage(const std::string& message)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 0b8153ad..1e8e0746 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/Document

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp wsd/TestStubs.cpp

2018-01-14 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |9 +++--
 wsd/DocumentBroker.cpp |   29 +
 wsd/DocumentBroker.hpp |2 +-
 wsd/LOOLWSD.cpp|2 +-
 wsd/TestStubs.cpp  |2 +-
 5 files changed, 23 insertions(+), 21 deletions(-)

New commits:
commit d53ce5511dfe7989954f5ec4f882799607a6b662
Author: Ashod Nakashian 
Date:   Sun Jan 14 11:16:10 2018 -0500

wsd: const and cosmetics

Non-functional changes.

Change-Id: I7c52386e2f870d29fd62c6dae6f37f4a58c2396b
Reviewed-on: https://gerrit.libreoffice.org/47882
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 5b0881bf..9fdf8ba7 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -586,8 +586,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 
 // Save to Storage and log result.
-std::string id = getId();
-docBroker->saveToStorage(id, success, result);
+docBroker->saveToStorage(getId(), success, result);
 
 if (!isCloseFrame())
 forwardToClient(payload);
@@ -714,8 +713,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 LOG_TRC("Removing save-as ClientSession after conversion.");
 
 // Remove us.
-std::string id = getId();
-docBroker->removeSession(id);
+docBroker->removeSession(getId());
 
 // Now terminate.
 docBroker->stop();
@@ -876,8 +874,7 @@ void ClientSession::onDisconnect()
 
 // We issue a force-save when last editable (non-readonly) session is 
going away
 // and defer destroying the last session and the docBroker.
-std::string id = getId();
-docBroker->removeSession(id, true);
+docBroker->removeSession(getId(), true);
 }
 catch (const UnauthorizedRequestException& exc)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 97ef771f..deb2cfc9 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -177,7 +177,7 @@ void DocumentBroker::startThread()
 _poll->startThread();
 }
 
-void DocumentBroker::assertCorrectThread()
+void DocumentBroker::assertCorrectThread() const
 {
 _poll->assertCorrectThread();
 }
@@ -226,15 +226,15 @@ void DocumentBroker::pollThread()
 _childProcess->setDocumentBroker(shared_from_this());
 LOG_INF("Doc [" << _docKey << "] attached to child [" << 
_childProcess->getPid() << "].");
 
-auto last30SecCheckTime = std::chrono::steady_clock::now();
-
 static const bool AutoSaveEnabled = !std::getenv("LOOL_NO_AUTOSAVE");
 static const size_t IdleDocTimeoutSecs = LOOLWSD::getConfigValue(
   
"per_document.idle_timeout_secs", 3600);
+
 // Used to accumulate B/W deltas.
 uint64_t adminSent = 0;
 uint64_t adminRecv = 0;
 auto lastBWUpdateTime = std::chrono::steady_clock::now();
+auto last30SecCheckTime = std::chrono::steady_clock::now();
 
 // Main polling loop goodness.
 while (!_stop && _poll->continuePolling() && !TerminationFlag)
@@ -254,7 +254,7 @@ void DocumentBroker::pollThread()
// connection drop transiently reduces 
this.
(sent > adminSent ? (sent - adminSent): 
uint64_t(0)),
(recv > adminRecv ? (recv - adminRecv): 
uint64_t(0)));
-LOG_INF("Doc [" << _docKey << "] added sent: " << sent << " recv: 
" << recv << " bytes to totals");
+LOG_DBG("Doc [" << _docKey << "] added sent: " << sent << " recv: 
" << recv << " bytes to totals");
 adminSent = sent;
 adminRecv = recv;
 }
@@ -263,7 +263,7 @@ void DocumentBroker::pollThread()
 std::chrono::duration_cast
 (now - _lastSaveRequestTime).count() <= COMMAND_TIMEOUT_MS)
 {
-// We are saving, nothing more to do but wait.
+// We are saving, nothing more to do but wait (until we save or we 
timeout).
 continue;
 }
 
@@ -668,6 +668,7 @@ bool DocumentBroker::saveToStorage(const std::string& 
sessionId,
 LOG_TRC("Document will be saved forcefully to storage.");
 _storage->forceSave();
 }
+
 const bool res = saveToStorageInternal(sessionId, success, result);
 
 // If marked to destroy, or session is disconnected, remove.
@@ -1071,14 +1072,18 @@ size_t DocumentBroker::removeSessionInternal(const 
std::string& id)
 // Remove. The caller must have a reference to the session
 // in question, lest we destroy from underneith them.
 _sessions.erase(it);
-
 const auto count = _sessions.size();
-LOG_TRC("Removed " << (readonly ? "readonly" : "non-readonly") <<
-

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2017-10-25 Thread Pranav Kant
 wsd/ClientSession.cpp |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

New commits:
commit 6e86fefc4eba5546096f4c4d974ffc65d11570ae
Author: Pranav Kant 
Date:   Wed Oct 25 13:16:57 2017 -0700

tdf#99744: Check if params exist before accessing them

Change-Id: I5a36281f281b5d1fa4a8b7a3551ce1d49c2efaad

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index e19f3352..df6df09c 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -236,8 +236,12 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 else if (tokens[0] == "saveas")
 {
 std::string newFileName, path;
-getTokenString(tokens[1], "fileName", newFileName);
-getTokenString(tokens[2], "path", path);
+if (tokens.size() > 1)
+getTokenString(tokens[1], "fileName", newFileName);
+
+if (tokens.size() > 2)
+getTokenString(tokens[2], "path", path);
+
 docBroker->saveFileAs(getId(), newFileName, path);
 }
 else if (tokens[0] == "save")
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2017-08-17 Thread Pranav Kant
 wsd/ClientSession.cpp |   12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

New commits:
commit 10bfd18e973cbe4662411c449724a50c4f82faa0
Author: Pranav Kant 
Date:   Thu Aug 17 20:03:30 2017 +0530

Decode the headers before creating Authorization object

Change-Id: I0da0b4112ac46d2407d2cd308b21ee1dee9d68de
Reviewed-on: https://gerrit.libreoffice.org/41258
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 77e05744..6a9a88d5 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -778,13 +778,21 @@ Authorization ClientSession::getAuthorization() const
 for (auto& param: queryParams)
 {
 if (param.first == "access_token")
-return Authorization(Authorization::Type::Token, param.second);
+{
+std::string decodedToken;
+Poco::URI::decode(param.second, decodedToken);
+return Authorization(Authorization::Type::Token, decodedToken);
+}
 }
 
 for (auto& param: queryParams)
 {
 if (param.first == "access_header")
-return Authorization(Authorization::Type::Header, param.second);
+{
+std::string decodedHeader;
+Poco::URI::decode(param.second, decodedHeader);
+return Authorization(Authorization::Type::Header, decodedHeader);
+}
 }
 
 return Authorization();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2017-06-07 Thread Jan Holesovsky
 wsd/ClientSession.cpp |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

New commits:
commit ca39f61330c0e30740bd6743884cf365074478e7
Author: Jan Holesovsky 
Date:   Wed Jun 7 16:32:58 2017 +0200

Don't crash on Shift+reload.

Change-Id: I1706fc0ff748fa74f2d2b29f103c167acf36c706
Reviewed-on: https://gerrit.libreoffice.org/38516
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 125b24ee..5cdcaaf3 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -561,7 +561,10 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 // Save to Storage and log result.
 std::string id = getId();
 docBroker->saveToStorage(id, success, result);
-forwardToClient(payload);
+
+if (!isCloseFrame())
+forwardToClient(payload);
+
 return true;
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/reference.txt

2017-05-25 Thread Pranav Kant
 wsd/ClientSession.cpp |4 ++--
 wsd/reference.txt |8 +++-
 2 files changed, 5 insertions(+), 7 deletions(-)

New commits:
commit 1a1ab5fd5751f9d6353bb91be918e96cf9c53b90
Author: Pranav Kant 
Date:   Thu May 25 14:11:33 2017 +0530

wsd: Only disable copying when DisableCopy is mentioned

Earlier, DisableCopy was a misnomer disabling both copy and paste. Now
it only disables copy from the document but allows pasting into the
document.

Change-Id: I8ddfdd493918331276f0656468d3b94c4283fa4d

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 387f7629..4a886a43 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -420,12 +420,12 @@ bool ClientSession::filterMessage(const std::string& 
message) const
 LOG_WRN("No value of id in downloadas message");
 }
 }
-else if (tokens[0] == "gettextselection" || tokens[0] == "paste" || 
tokens[0] == "insertfile")
+else if (tokens[0] == "gettextselection")
 {
 if (_wopiFileInfo && _wopiFileInfo->_disableCopy)
 {
 allowed = false;
-LOG_WRN("WOPI host has disabled copying to/from the document");
+LOG_WRN("WOPI host has disabled copying from the document");
 }
 }
 else if (isReadOnly())
diff --git a/wsd/reference.txt b/wsd/reference.txt
index e1af6d4b..5c706621 100644
--- a/wsd/reference.txt
+++ b/wsd/reference.txt
@@ -41,11 +41,9 @@ DisableExport
HideExportOption is assumed to be true
 
 DisableCopy
-   Disables copy/paste from/to the document in libreoffice online backend.
-   However, it is still possible to do an "internal" cut/copy/paste i.e
-   copy from the document and paste to the same document view. The context
-   menu options pertaining to cut/copy/paste would be renamed to 'Internal
-   Cut/Copy/Paste' when this option is mentioned.
+   Disables copying from the document in libreoffice online
+   backend. Pasting into the document would still be possible.
+   However, it is still possible to do an "internal" cut/copy/paste.
 
 EnableOwnerTermination
If set to true, it allows the document owner (the one with OwnerId =
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.cpp wsd/Storage.hpp

2017-05-19 Thread Jan Holesovsky
 wsd/ClientSession.cpp  |1 
 wsd/DocumentBroker.cpp |   19 -
 wsd/DocumentBroker.hpp |1 
 wsd/Storage.cpp|   46 ++-
 wsd/Storage.hpp|   52 +++--
 5 files changed, 21 insertions(+), 98 deletions(-)

New commits:
commit 9db41725f423f00f95db4b68d70827d24f80bb6c
Author: Jan Holesovsky 
Date:   Fri May 19 10:32:24 2017 +0200

Revert "wsd: use WOPI host instance ID to support hostname aliases"

Turns out this introduces two calls to the CheckFileInfo which is not really
what we should be doing; instead, let's do a kind of cannonicalization in 
the
WOPI host directly.

This reverts commit ec2fd0844f997f9a7347229e282daeb8dc4471bc.

Change-Id: I311bf8a45b706ed9a4d8cd00db0a990ac6d461b4

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 479bc2b9..105b30d3 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -737,6 +737,7 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 
 std::string ClientSession::getAccessToken() const
 {
+std::string accessToken;
 Poco::URI::QueryParameters queryParams = _uriPublic.getQueryParameters();
 for (auto& param: queryParams)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 66a5de80..e5924f87 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -102,7 +102,15 @@ Poco::URI DocumentBroker::sanitizeURI(const std::string& 
uri)
 
 std::string DocumentBroker::getDocKey(const Poco::URI& uri)
 {
-return StorageBase::getUniqueDocId(uri);
+// If multiple host-names are used to access us, then
+// we force same document (when opened from
+// alias hosts) to load as separate documents and sharing doesn't
+// work. Worse, saving overwrites one another.
+// But we also do not want different WOPI hosts using the same path
+// for some file getting shared across WOPI hosts
+std::string docKey;
+Poco::URI::encode(uri.getHost() + ":" + std::to_string(uri.getPort()) + 
uri.getPath(), "", docKey);
+return docKey;
 }
 
 /// The Document Broker Poll - one of these in a thread per document
@@ -401,7 +409,6 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 LOG_ERR("Failed to create Storage instance for [" << _docKey << "] 
in " << jailPath.toString());
 return false;
 }
-
 firstInstance = true;
 }
 
@@ -416,14 +423,6 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 std::unique_ptr wopifileinfo = 
wopiStorage->getWOPIFileInfo(session->getAccessToken());
 userid = wopifileinfo->_userid;
 username = wopifileinfo->_username;
-if (firstInstance)
-{
-_hostInstanceId = wopifileinfo->_hostInstanceId;
-}
-else if (!_hostInstanceId.empty() && _hostInstanceId != 
wopifileinfo->_hostInstanceId)
-{
-throw UnauthorizedRequestException("Unauthorized WOPI host.");
-}
 
 if (!wopifileinfo->_userCanWrite)
 {
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 8ac67ee2..46481cba 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -369,7 +369,6 @@ private:
 Poco::URI _uriJailed;
 std::string _jailId;
 std::string _filename;
-std::string _hostInstanceId;
 
 /// The last time we tried saving, regardless of whether the
 /// document was modified and saved or not.
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 0c31e53c..12f0a49e 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -125,7 +125,7 @@ void StorageBase::initialize()
 #endif
 }
 
-bool StorageBase::isLocalhost(const std::string& targetHost)
+bool isLocalhost(const std::string& targetHost)
 {
 std::string targetAddress;
 try
@@ -202,7 +202,7 @@ std::unique_ptr StorageBase::create(const 
Poco::URI& uri, const std
 {
 LOG_INF("Public URI [" << uri.toString() << "] considered WOPI.");
 const auto& targetHost = uri.getHost();
-if (isWopiHostAuthorized(targetHost))
+if (WopiHosts.match(targetHost) || isLocalhost(targetHost))
 {
 return std::unique_ptr(new WopiStorage(uri, jailRoot, 
jailPath));
 }
@@ -213,39 +213,6 @@ std::unique_ptr StorageBase::create(const 
Poco::URI& uri, const std
 throw BadRequestException("No Storage configured or invalid URI.");
 }
 
-std::string StorageBase::getUniqueDocId(const Poco::URI& uri)
-{
-std::string docId;
-if (uri.isRelative() || uri.getScheme() == "file")
-{
-Poco::URI::encode(uri.getPath(), "", docId);
-}
-else if (WopiEnabled)
-{
-const auto& targetHost = uri.getHost();
-if (isWopiHostAuthorized(targetHost))
-{
-std::string accessToken;
-Poco::URI::QueryParameters queryParams = uri.getQueryParameters();
-for (auto& param:

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2017-05-16 Thread Pranav Kant
 wsd/ClientSession.cpp |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 1449d81671ff9563bd494526b4316fc0d6a8d893
Author: Pranav Kant 
Date:   Wed May 17 10:29:53 2017 +0530

wsd: Don't filter out 'save' command

Fallback from 1cb75cbcb8c87481bf341c5ac058a36c13529dc8

Change-Id: I47c8a470e5f4ab4d48859365d4435ae79c5fa82d

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 8ce4c327..479bc2b9 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -133,6 +133,7 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
  tokens[0] != "renderfont" &&
  tokens[0] != "requestloksession" &&
  tokens[0] != "resetselection" &&
+ tokens[0] != "save" &&
  tokens[0] != "saveas" &&
  tokens[0] != "selectgraphic" &&
  tokens[0] != "selecttext" &&
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.cpp wsd/Storage.hpp

2017-05-16 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |1 
 wsd/DocumentBroker.cpp |   19 +
 wsd/DocumentBroker.hpp |1 
 wsd/Storage.cpp|   46 ---
 wsd/Storage.hpp|   52 +
 5 files changed, 98 insertions(+), 21 deletions(-)

New commits:
commit ec2fd0844f997f9a7347229e282daeb8dc4471bc
Author: Ashod Nakashian 
Date:   Tue May 16 16:38:44 2017 -0400

wsd: use WOPI host instance ID to support hostname aliases

The docKey creation moved to Storage where we first
invoke WOPI (if/when it's a WOPI-hosted doc and WOPI enabled)
and see if the user has access to the document at all.
If they do, we expect the server to give us a
unique ID to use for identifying the host regardless
of hostname aliases.

If a unique ID is not returned (i.e. empty or missing)
we use the hostname and port in its place as fallback.
This will break hostname aliases, but it will still work.

Change-Id: I407b0087395f9df6ad9cc6e037570487999be4a4
Reviewed-on: https://gerrit.libreoffice.org/37697
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 5a0af025..8ce4c327 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -736,7 +736,6 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 
 std::string ClientSession::getAccessToken() const
 {
-std::string accessToken;
 Poco::URI::QueryParameters queryParams = _uriPublic.getQueryParameters();
 for (auto& param: queryParams)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index e5924f87..66a5de80 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -102,15 +102,7 @@ Poco::URI DocumentBroker::sanitizeURI(const std::string& 
uri)
 
 std::string DocumentBroker::getDocKey(const Poco::URI& uri)
 {
-// If multiple host-names are used to access us, then
-// we force same document (when opened from
-// alias hosts) to load as separate documents and sharing doesn't
-// work. Worse, saving overwrites one another.
-// But we also do not want different WOPI hosts using the same path
-// for some file getting shared across WOPI hosts
-std::string docKey;
-Poco::URI::encode(uri.getHost() + ":" + std::to_string(uri.getPort()) + 
uri.getPath(), "", docKey);
-return docKey;
+return StorageBase::getUniqueDocId(uri);
 }
 
 /// The Document Broker Poll - one of these in a thread per document
@@ -409,6 +401,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 LOG_ERR("Failed to create Storage instance for [" << _docKey << "] 
in " << jailPath.toString());
 return false;
 }
+
 firstInstance = true;
 }
 
@@ -423,6 +416,14 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 std::unique_ptr wopifileinfo = 
wopiStorage->getWOPIFileInfo(session->getAccessToken());
 userid = wopifileinfo->_userid;
 username = wopifileinfo->_username;
+if (firstInstance)
+{
+_hostInstanceId = wopifileinfo->_hostInstanceId;
+}
+else if (!_hostInstanceId.empty() && _hostInstanceId != 
wopifileinfo->_hostInstanceId)
+{
+throw UnauthorizedRequestException("Unauthorized WOPI host.");
+}
 
 if (!wopifileinfo->_userCanWrite)
 {
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 46481cba..8ac67ee2 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -369,6 +369,7 @@ private:
 Poco::URI _uriJailed;
 std::string _jailId;
 std::string _filename;
+std::string _hostInstanceId;
 
 /// The last time we tried saving, regardless of whether the
 /// document was modified and saved or not.
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index e07ffd55..bdaeab56 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -124,7 +124,7 @@ void StorageBase::initialize()
 #endif
 }
 
-bool isLocalhost(const std::string& targetHost)
+bool StorageBase::isLocalhost(const std::string& targetHost)
 {
 std::string targetAddress;
 try
@@ -201,7 +201,7 @@ std::unique_ptr StorageBase::create(const 
Poco::URI& uri, const std
 {
 LOG_INF("Public URI [" << uri.toString() << "] considered WOPI.");
 const auto& targetHost = uri.getHost();
-if (WopiHosts.match(targetHost) || isLocalhost(targetHost))
+if (isWopiHostAuthorized(targetHost))
 {
 return std::unique_ptr(new WopiStorage(uri, jailRoot, 
jailPath));
 }
@@ -212,6 +212,39 @@ std::unique_ptr StorageBase::create(const 
Poco::URI& uri, const std
 throw BadRequestException("No Storage configured or invalid URI.");
 }
 
+std::string StorageBase::getUniqueDocId(const Poco::URI& uri)
+{
+std::string docId;
+if (uri.isRelative() || uri.getScheme() == "file")
+{

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/Storage.cpp wsd/Storage.hpp

2017-05-12 Thread Jan Holesovsky
 wsd/ClientSession.cpp  |   13 +
 wsd/ClientSession.hpp  |7 +
 wsd/DocumentBroker.cpp |   31 ++-
 wsd/Storage.cpp|   65 +
 wsd/Storage.hpp|   23 +
 5 files changed, 90 insertions(+), 49 deletions(-)

New commits:
commit 95e892168ce3b6e56ded62bb9ce2c02ada627dba
Author: Jan Holesovsky 
Date:   Fri May 12 17:42:03 2017 +0200

wsd: When connecting new sessions, always use the original URI...

...but in combination with the appropriate session's access_token to always
authenticate against the same instance of the WOPI host.

Change-Id: Ic94dfa8fcb226a2d134272b22edc1f8f76c24e34

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 55b17d64..5ef70522 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -726,6 +726,19 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 return true;
 }
 
+std::string ClientSession::getAccessToken() const
+{
+std::string accessToken;
+Poco::URI::QueryParameters queryParams = _uriPublic.getQueryParameters();
+for (auto& param: queryParams)
+{
+if (param.first == "access_token")
+return param.second;
+}
+
+return std::string();
+}
+
 void ClientSession::onDisconnect()
 {
 LOG_INF(getName() << " Disconnected, current number of connections: " << 
LOOLWSD::NumConnections);
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 22fad016..8c791c88 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -90,8 +90,15 @@ public:
 
 /// Exact URI (including query params - access tokens etc.) with which
 /// client made the request to us
+///
+/// Note: This URI is unsafe - when connecting to existing sessions, we 
must
+/// ignore everything but the access_token, and use the access_token with
+/// the URI of the initial request.
 const Poco::URI& getPublicUri() const { return _uriPublic; }
 
+/// The access token of this session.
+std::string getAccessToken() const;
+
 /// Set WOPI fileinfo object
 void setWopiFileInfo(std::unique_ptr& 
wopiFileInfo) { _wopiFileInfo = std::move(wopiFileInfo); }
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 21f6965f..bb7b9c5e 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -383,9 +383,6 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 return false;
 }
 
-const Poco::URI& uriPublic = session->getPublicUri();
-LOG_DBG("Loading from URI: " << uriPublic.toString());
-
 _jailId = jailId;
 
 // The URL is the publicly visible one, not visible in the chroot jail.
@@ -402,7 +399,9 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 {
 // Pass the public URI to storage as it needs to load using the token
 // and other storage-specific data provided in the URI.
-LOG_DBG("Creating new storage instance for URI [" << 
uriPublic.toString() << "].");
+const Poco::URI& uriPublic = session->getPublicUri();
+LOG_DBG("Loading, and creating new storage instance for URI [" << 
uriPublic.toString() << "].");
+
 _storage = StorageBase::create(uriPublic, jailRoot, 
jailPath.toString());
 if (_storage == nullptr)
 {
@@ -421,8 +420,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 WopiStorage* wopiStorage = dynamic_cast(_storage.get());
 if (wopiStorage != nullptr)
 {
-std::unique_ptr wopifileinfo =
- wopiStorage->getWOPIFileInfo(uriPublic);
+std::unique_ptr wopifileinfo = 
wopiStorage->getWOPIFileInfo(session->getAccessToken());
 userid = wopifileinfo->_userid;
 username = wopifileinfo->_username;
 
@@ -473,8 +471,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 LocalStorage* localStorage = 
dynamic_cast(_storage.get());
 if (localStorage != nullptr)
 {
-std::unique_ptr localfileinfo =
-  
localStorage->getLocalFileInfo(uriPublic);
+std::unique_ptr localfileinfo = 
localStorage->getLocalFileInfo();
 userid = localfileinfo->_userid;
 username = localfileinfo->_username;
 }
@@ -488,7 +485,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 const auto fileInfo = _storage->getFileInfo();
 if (!fileInfo.isValid())
 {
-LOG_ERR("Invalid fileinfo for URI [" << uriPublic.toString() << "].");
+LOG_ERR("Invalid fileinfo for URI [" << 
session->getPublicUri().toString() << "].");
 return false;
 }
 
@@ -509,7 +506,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 fileInfo._modifiedTime != Zero &&
 _documentLastModifiedTime != fileInfo._modifiedTime)
 {
-LOG

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp

2017-04-20 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |4 ++--
 wsd/ClientSession.hpp  |6 +++---
 wsd/DocumentBroker.cpp |2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

New commits:
commit 7019ca8c257b6f4e4b91988243da12236c9de94a
Author: Ashod Nakashian 
Date:   Thu Apr 20 22:17:08 2017 -0400

wsd: ClientSession's isLoaded -> isViewLoaded

Not to confuse with the DocumentBroker isLoaded,
this is view-specific. Except for the first view,
which is identical to the document being loaded,
subsequent view loadings are independent from,
though follow, document loading.

Change-Id: I0f21016fa84bf507ca4bc0e7a6c7d0d76b033c60
Reviewed-on: https://gerrit.libreoffice.org/36761
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 8be60603..11db33af 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -38,7 +38,7 @@ ClientSession::ClientSession(const std::string& id,
 _uriPublic(uriPublic),
 _isDocumentOwner(false),
 _isAttached(false),
-_isLoaded(false)
+_isViewLoaded(false)
 {
 const size_t curConnections = ++LOOLWSD::NumConnections;
 LOG_INF("ClientSession ctor [" << getName() << "], current number of 
connections: " << curConnections);
@@ -632,7 +632,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens[0] == "status:")
 {
-setLoaded();
+setViewLoaded();
 docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 81c55c70..b0eefecf 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -39,8 +39,8 @@ public:
 void setAttached() { _isAttached = true; }
 
 /// Returns true if this session has loaded a view (i.e. we got status 
message).
-bool isLoaded() const { return _isLoaded; }
-void setLoaded() { _isLoaded = true; }
+bool isViewLoaded() const { return _isViewLoaded; }
+void setViewLoaded() { _isViewLoaded = true; }
 
 const std::string getUserId() const { return _userId; }
 const std::string getUserName() const {return _userName; }
@@ -148,7 +148,7 @@ private:
 bool _isAttached;
 
 /// If we have loaded a view.
-bool _isLoaded;
+bool _isViewLoaded;
 
 /// Wopi FileInfo object
 std::unique_ptr _wopiFileInfo;
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index fd3a6ea9..a2b90d50 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1216,7 +1216,7 @@ void DocumentBroker::destroyIfLastEditor(const 
std::string& id)
 for (const auto& it : _sessions)
 {
 if (it.second->getId() != id &&
-it.second->isLoaded() &&
+it.second->isViewLoaded() &&
 !it.second->isReadOnly())
 {
 // Found another editable.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp

2017-04-19 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |4 +++-
 wsd/ClientSession.hpp  |   10 +-
 wsd/DocumentBroker.cpp |1 +
 3 files changed, 13 insertions(+), 2 deletions(-)

New commits:
commit f326a058d41f6a0cc334f8458d98ca68cc40f189
Author: Ashod Nakashian 
Date:   Thu Apr 20 00:08:13 2017 -0400

wsd: rely only on loaded sessions for saving

If a session is not loaded, it might never
do so. We should skip them when deciding
whether to save using a disconnecting
session or rely on another.

This is to avoid failing to save when
the remaining sessions never really load
the document at all, and are therefore useless.

Change-Id: I4e7127e12960a31e9f66e835bb63fb2347390711
Reviewed-on: https://gerrit.libreoffice.org/36710
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 414f8b94..8be60603 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -37,7 +37,8 @@ ClientSession::ClientSession(const std::string& id,
 _docBroker(docBroker),
 _uriPublic(uriPublic),
 _isDocumentOwner(false),
-_isAttached(false)
+_isAttached(false),
+_isLoaded(false)
 {
 const size_t curConnections = ++LOOLWSD::NumConnections;
 LOG_INF("ClientSession ctor [" << getName() << "], current number of 
connections: " << curConnections);
@@ -631,6 +632,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens[0] == "status:")
 {
+setLoaded();
 docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 396f45c9..81c55c70 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -34,10 +34,14 @@ public:
 
 void setReadOnly() override;
 
-/// Returns true if a document is loaded (i.e. we got status message).
+/// Returns true if this session is added to a DocBroker.
 bool isAttached() const { return _isAttached; }
 void setAttached() { _isAttached = true; }
 
+/// Returns true if this session has loaded a view (i.e. we got status 
message).
+bool isLoaded() const { return _isLoaded; }
+void setLoaded() { _isLoaded = true; }
+
 const std::string getUserId() const { return _userId; }
 const std::string getUserName() const {return _userName; }
 void setUserId(const std::string& userId) { _userId = userId; }
@@ -140,8 +144,12 @@ private:
 /// The socket to which the converted (saveas) doc is sent.
 std::shared_ptr _saveAsSocket;
 
+/// If we are added to a DocBroker.
 bool _isAttached;
 
+/// If we have loaded a view.
+bool _isLoaded;
+
 /// Wopi FileInfo object
 std::unique_ptr _wopiFileInfo;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 31ab6598..bb76ea33 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1218,6 +1218,7 @@ void DocumentBroker::destroyIfLastEditor(const 
std::string& id)
 for (const auto& it : _sessions)
 {
 if (it.second->getId() != id &&
+it.second->isLoaded() &&
 !it.second->isReadOnly())
 {
 // Found another editable.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2017-04-16 Thread Ashod Nakashian
 wsd/ClientSession.cpp |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 651e462ef0ef89cabf61863be9e766caa5f11d59
Author: Ashod Nakashian 
Date:   Sun Apr 16 22:58:34 2017 -0400

wsd: logs

Change-Id: I43f8e3732c6948c8214b21a506cb2e5ba56bd2ad
Reviewed-on: https://gerrit.libreoffice.org/36599
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index d1140668..414f8b94 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -60,7 +60,7 @@ SocketHandlerInterface::SocketOwnership 
ClientSession::handleIncomingMessage()
 
 bool ClientSession::_handleInput(const char *buffer, int length)
 {
-LOG_TRC(getName() << ": handling [" << getAbbreviatedMessage(buffer, 
length) << "].");
+LOG_TRC(getName() << ": handling incoming [" << 
getAbbreviatedMessage(buffer, length) << "].");
 const std::string firstLine = getFirstLine(buffer, length);
 const auto tokens = LOOLProtocol::tokenize(firstLine.data(), 
firstLine.size());
 
@@ -486,7 +486,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 {
 const auto payload = std::make_shared(buffer, length, 
Message::Dir::Out);
 
-LOG_TRC(getName() + ": handling [" << payload->abbr() << "].");
+LOG_TRC(getName() + ": handling kit-to-client [" << payload->abbr() << 
"].");
 const std::string& firstLine = payload->firstLine();
 
 const auto docBroker = _docBroker.lock();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2017-04-11 Thread Miklos Vajna
 wsd/ClientSession.cpp |9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

New commits:
commit 08989a12acbe0ca3e40130f4d4af11fdbdd4118d
Author: Miklos Vajna 
Date:   Tue Apr 11 22:09:32 2017 +0200

wsd: avoid use-after-free in ClientSession

Commit 1e1f23716c9ee3ce880d1d927945386cf5400293 fixed this already by
introducing by-value parameters, but
8a1f321c8492d6c2824317c7e4be1a3bdfa81665 broke it. Fix this again, this
time more explicitly.

Change-Id: If29250ac2e99855796935b5cc05ccb222f8a4ad5
Reviewed-on: https://gerrit.libreoffice.org/36436
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 2af75d21..d1140668 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -523,7 +523,8 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 
 // Save to Storage and log result.
-docBroker->saveToStorage(getId(), success, result);
+std::string id = getId();
+docBroker->saveToStorage(id, success, result);
 return true;
 }
 }
@@ -604,7 +605,8 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 LOG_TRC("Removing save-as ClientSession after conversion.");
 
 // Remove us.
-docBroker->removeSession(getId());
+std::string id = getId();
+docBroker->removeSession(id);
 
 // Now terminate.
 docBroker->stop();
@@ -736,7 +738,8 @@ void ClientSession::onDisconnect()
 
 // We issue a force-save when last editable (non-readonly) session is 
going away
 // and defer destroying the last session and the docBroker.
-docBroker->removeSession(getId(), true);
+std::string id = getId();
+docBroker->removeSession(id, true);
 }
 catch (const UnauthorizedRequestException& exc)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-04-09 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |3 +--
 wsd/DocumentBroker.cpp |   10 ++
 wsd/DocumentBroker.hpp |2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)

New commits:
commit fa2e2869cfbd5bea7a080be2bff244cdfdbfe084
Author: Ashod Nakashian 
Date:   Sun Apr 9 18:37:27 2017 -0400

wsd: logging cleanups

Change-Id: Ia06bc5b1e0090c8198ac4ba2b88d5e57f8e2b168
Reviewed-on: https://gerrit.libreoffice.org/36327
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 883b30b1..2af75d21 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -446,8 +446,7 @@ void ClientSession::setReadOnly()
 int ClientSession::getPollEvents(std::chrono::steady_clock::time_point /* now 
*/,
  int & /* timeoutMaxMs */)
 {
-LOG_TRC(getName() << " ClientSession: has queued writes? "
-<< _senderQueue.size());
+LOG_TRC(getName() << " ClientSession has " << _senderQueue.size() << " 
write message(s) queued.");
 int events = POLLIN;
 if (_senderQueue.size())
 events |= POLLOUT;
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 6f827175..33f88ef7 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -471,10 +471,12 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 else
 {
 // Check if document has been modified by some external action
-LOG_DBG("Timestamp now: " << 
Poco::DateTimeFormatter::format(Poco::DateTime(fileInfo._modifiedTime),
- 
Poco::DateTimeFormat::ISO8601_FORMAT));
-if (_documentLastModifiedTime != Poco::Timestamp::fromEpochTime(0) &&
-fileInfo._modifiedTime != Poco::Timestamp::fromEpochTime(0) &&
+LOG_TRC("Document modified time: " <<
+
Poco::DateTimeFormatter::format(Poco::DateTime(fileInfo._modifiedTime),
+
Poco::DateTimeFormat::ISO8601_FORMAT));
+static const Poco::Timestamp Zero(Poco::Timestamp::fromEpochTime(0));
+if (_documentLastModifiedTime != Zero &&
+fileInfo._modifiedTime != Zero &&
 _documentLastModifiedTime != fileInfo._modifiedTime)
 {
 LOG_ERR("Document has been modified behind our back, URI [" << 
uriPublic.toString() << "].");
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 88fa2b6e..20bdc496 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -152,7 +152,7 @@ public:
 {
 if (_ws)
 {
-LOG_TRC("DocBroker to Child: " << data);
+LOG_TRC("Send DocBroker to Child message: [" << data << "].");
 _ws->sendMessage(data);
 return true;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp

2017-04-09 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |4 ++--
 wsd/DocumentBroker.cpp |9 +
 2 files changed, 11 insertions(+), 2 deletions(-)

New commits:
commit 679a39eb0b2272c56173ef2febd5281b152b1e45
Author: Ashod Nakashian 
Date:   Sun Apr 9 19:41:29 2017 -0400

wsd: send recycling message to clients before going down

Change-Id: I388ca55524983d554fabf247bb3baee23010657d
Reviewed-on: https://gerrit.libreoffice.org/36329
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 7ad8df31..883b30b1 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -769,8 +769,8 @@ void ClientSession::onDisconnect()
 }
 else
 {
-static const std::string msg("close: recycling");
-sendMessage(msg);
+LOG_TRC("Server recycling.");
+closeFrame();
 shutdown(WebSocketHandler::StatusCodes::ENDPOINT_GOING_AWAY);
 }
 }
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index f7bbd9f1..6f827175 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -254,6 +254,15 @@ void DocumentBroker::pollThread()
 _poll->continuePolling() << ", TerminationFlag: " << 
TerminationFlag <<
 ", ShutdownRequestFlag: " << ShutdownRequestFlag << ".");
 
+if (ShutdownRequestFlag)
+{
+static const std::string msg("close: recycling");
+for (const auto& pair : _sessions)
+{
+pair.second->sendMessage(msg);
+}
+}
+
 // Terminate properly while we can.
 //TODO: pass some sensible reason.
 terminateChild("", false);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/LOOLWSD.cpp

2017-03-25 Thread Ashod Nakashian
 wsd/ClientSession.cpp |6 +++---
 wsd/LOOLWSD.cpp   |2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 1c5896f302befd2cede6098148d676cd678b91cf
Author: Ashod Nakashian 
Date:   Sun Mar 26 00:50:51 2017 -0400

wsd: count connections symmetrically

ClientSession::onDisconnect might not always be
called. The disymmetry between incrementing in
the ctor and decrementing in onDisconnect always
ran the risk of mismatch and leaking connection
counts, eventually blocking new clients.

Change-Id: I39ec65016984c0cddd0e16cfbf201049ced53713
Reviewed-on: https://gerrit.libreoffice.org/35713
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index fbc50b98..40d78f1d 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -47,7 +47,8 @@ ClientSession::ClientSession(const std::string& id,
 
 ClientSession::~ClientSession()
 {
-LOG_INF("~ClientSession dtor [" << getName() << "].");
+const size_t curConnections = --LOOLWSD::NumConnections;
+LOG_INF("~ClientSession dtor [" << getName() << "], current number of 
connections: " << curConnections);
 
 stop();
 }
@@ -726,8 +727,7 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 
 void ClientSession::onDisconnect()
 {
-const size_t curConnections = --LOOLWSD::NumConnections;
-LOG_INF(getName() << " Disconnected, current # of connections: " << 
curConnections);
+LOG_INF(getName() << " Disconnected, current number of connections: " << 
LOOLWSD::NumConnections);
 
 const auto docBroker = getDocumentBroker();
 LOG_CHECK_RET(docBroker && "Null DocumentBroker instance", );
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index eaa02fcb..df3382a0 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1285,7 +1285,7 @@ static std::shared_ptr 
findOrCreateDocBroker(WebSocketHandler& w
 static_assert(MAX_DOCUMENTS > 0, "MAX_DOCUMENTS must be positive");
 if (DocBrokers.size() + 1 > MAX_DOCUMENTS)
 {
-LOG_ERR("Maximum number of open documents reached.");
+LOG_ERR("Maximum number of open documents of " << MAX_DOCUMENTS << 
" reached.");
 shutdownLimitReached(ws);
 return nullptr;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-03-25 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |2 -
 wsd/ClientSession.hpp  |1 
 wsd/DocumentBroker.cpp |   62 ++---
 wsd/DocumentBroker.hpp |   15 ---
 4 files changed, 15 insertions(+), 65 deletions(-)

New commits:
commit d3a8106cda570fb8881139dc4347e02247036664
Author: Ashod Nakashian 
Date:   Sat Mar 25 14:19:17 2017 -0400

wsd: remove NewSessions

Sessions are now added to the DocBroker
_sessions map and loaded from the poll
thread first before processing their
messages.

Since messages are not read from the
sockets outside of the poll thread,
there is no reason to queue them
at all. The only exception is when
messages are passed directly
to ClientSession during convert-to
requests. That will be handled
separately (for now convert-to test
fails).

Change-Id: I798166b9e45b5707a33d31137e01a32ce63630b1
Reviewed-on: https://gerrit.libreoffice.org/35705
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 73e4cb5b..fbc50b98 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -38,6 +38,7 @@ ClientSession::ClientSession(const std::string& id,
 _uriPublic(uriPublic),
 _isReadOnly(readOnly),
 _isDocumentOwner(false),
+_isLoaded(false),
 _stop(false)
 {
 const size_t curConnections = ++LOOLWSD::NumConnections;
@@ -632,7 +633,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens[0] == "status:")
 {
-_isLoaded = true;
 docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 19aee2af..c027f4b3 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -37,6 +37,7 @@ public:
 
 /// Returns true if a document is loaded (i.e. we got status message).
 bool isLoaded() const { return _isLoaded; }
+void setLoaded() { _isLoaded = true; }
 
 const std::string getUserId() const { return _userId; }
 void setUserId(const std::string& userId) { _userId = userId; }
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index eb204b8d..fe0372e7 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -211,41 +211,20 @@ void DocumentBroker::pollThread()
 // Main polling loop goodness.
 while (!_stop && !TerminationFlag && !ShutdownRequestFlag)
 {
-while (true)
+// First, load new sessions.
+for (const auto& pair : _sessions)
 {
-std::unique_lock lock(_mutex);
-if (_newSessions.empty())
-break;
-
-NewSession& newSession = _newSessions.front();
 try
 {
-addSession(newSession._session);
-
-// now send the queued messages
-for (std::string message : newSession._messages)
-{
-// provide the jailed document path to the 'load' message
-assert(!_uriJailed.empty());
-std::vector tokens = 
LOOLProtocol::tokenize(message);
-if (tokens.size() > 1 && tokens[1] == "load")
-{
-// The json options must come last.
-message = tokens[0] + ' ' + tokens[1] + ' ' + 
tokens[2];
-message += " jail=" + _uriJailed.toString() + ' ';
-message += Poco::cat(std::string(" "), tokens.begin() 
+ 3, tokens.end());
-}
-
-LOG_DBG("Sending a queued message: " + message);
-_childProcess->sendTextFrame(message);
-}
+auto& session = pair.second;
+if (!session->isLoaded())
+addSession(session);
 }
 catch (const std::exception& exc)
 {
 LOG_ERR("Error while adding new session to doc [" << _docKey 
<< "]: " << exc.what());
+//TODO: Send failure to client and remove session.
 }
-
-_newSessions.pop_front();
 }
 
 _poll->poll(SocketPoll::DefaultPollTimeoutMs);
@@ -740,10 +719,10 @@ size_t 
DocumentBroker::queueSession(std::shared_ptr& session)
 {
 Util::assertIsLocked(_mutex);
 
-_newSessions.push_back(NewSession(session));
+_sessions.emplace(session->getId(), session);
 _poll->wakeup();
 
-return _sessions.size() + _newSessions.size();
+return _sessions.size();
 }
 
 size_t DocumentBroker::addSession(const std::shared_ptr& 
session)
@@ -778,12 +757,9 @@ size_t DocumentBroker::addSession(const 
std::shared_ptr& session)
 _markToDestroy = false;
 _stop = false;
 
-const auto id = session->getId();
-if (!_sessions.emplace(id, session).second)
-{
-LOG_WRN("Docum

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2017-03-16 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |4 ++--
 wsd/ClientSession.hpp  |   30 +++---
 wsd/DocumentBroker.cpp |1 +
 wsd/LOOLWSD.cpp|   46 ++
 4 files changed, 20 insertions(+), 61 deletions(-)

New commits:
commit 5aedff24229bee65a5c0fd7154dce3f65e95567c
Author: Ashod Nakashian 
Date:   Thu Mar 16 22:42:02 2017 -0400

wsd: convert-to functional again

Change-Id: Ibfdec5e898ccb7f851a09fb3fb5eae85ca20f482
Reviewed-on: https://gerrit.libreoffice.org/35307
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 1f179ed4..268dc05c 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -414,7 +414,7 @@ bool ClientSession::filterMessage(const std::string& 
message) const
 {
 // By default, don't allow anything
 allowed = false;
-if (tokens[0] == "userinactive" || tokens[0] == "useractive")
+if (tokens[0] == "userinactive" || tokens[0] == "useractive" || 
tokens[0] == "saveas")
 {
 allowed = true;
 }
@@ -503,7 +503,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 const auto& object = parsedJSON.extract();
 if (object->get("commandName").toString() == ".uno:Save")
 {
-bool success = object->get("success").toString() == "true";
+const bool success = object->get("success").toString() == 
"true";
 std::string result;
 if (object->has("result"))
 {
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index c18e5cee..794ca06d 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -89,24 +89,24 @@ public:
 _senderQueue.stop();
 }
 
-/**
- * Return the URL of the saved-as document when it's ready. If called
- * before it's ready, the call blocks till then.
- */
-std::string getSaveAsUrl(const unsigned timeoutMs)
+void setSaveAsSocket(const std::shared_ptr& socket)
 {
-const auto payload = _saveAsQueue.get(timeoutMs);
-if (payload.empty())
-{
-throw std::runtime_error("Timed-out while getting save-as URL.");
-}
-
-return std::string(payload.data(), payload.size());
+_saveAsSocket = socket;
 }
 
 void setSaveAsUrl(const std::string& url)
 {
-_saveAsQueue.put(url);
+Poco::URI resultURL(url);
+LOG_TRC("Save-as URL: " << resultURL.toString());
+
+if (!resultURL.getPath().empty())
+{
+const std::string mimeType = "application/octet-stream";
+std::string encodedFilePath;
+Poco::URI::encode(resultURL.getPath(), "", encodedFilePath);
+LOG_TRC("Sending file: " << encodedFilePath);
+HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType);
+}
 }
 
 std::shared_ptr getDocumentBroker() const { return 
_docBroker.lock(); }
@@ -164,8 +164,8 @@ private:
 /// Whether this session is the owner of currently opened document
 bool _isDocumentOwner;
 
-/// Store URLs of completed 'save as' documents.
-MessageQueue _saveAsQueue;
+/// The socket to which the converted (saveas) doc is sent.
+std::shared_ptr _saveAsSocket;
 
 bool _isLoaded;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a4153ffb..e6ddb30c 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -478,6 +478,7 @@ bool DocumentBroker::load(std::shared_ptr& 
session, const std::st
 bool DocumentBroker::saveToStorage(const std::string& sessionId,
bool success, const std::string& result)
 {
+LOG_TRC("Saving to storage docKey [" << _docKey << "] for session [" << 
sessionId << "]: " << result);
 const bool res = saveToStorageInternal(sessionId, success, result);
 
 // If marked to destroy, then this was the last session.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index fac23b22..a4e34062 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1598,47 +1598,6 @@ private:
 void performWrites() override
 {
 LOG_ERR("performWrites");
-auto socket = _socket.lock();
-
-// Send it back to the client.
-try
-{
-Poco::URI 
resultURL(_clientSession->getSaveAsUrl(COMMAND_TIMEOUT_MS));
-LOG_TRC("Save-as URL: " << resultURL.toString());
-
-if (!resultURL.getPath().empty())
-{
-const std::string mimeType = "application/octet-stream";
-std::string encodedFilePath;
-URI::encode(resultURL.getPath(), "", encodedFilePath);
-LOG_TRC("Sending file: " << encodedFilePath);
-HttpHelper::sendFile(socket, encodedFilePath, mimeType);
-}
-}
-catch (const std::exception& ex)
- 

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/LOOLWSD.cpp

2017-03-16 Thread Ashod Nakashian
 wsd/ClientSession.cpp |8 +++-
 wsd/LOOLWSD.cpp   |   29 -
 2 files changed, 3 insertions(+), 34 deletions(-)

New commits:
commit f9664bb36981e34bf2e9f270bfc2bee7d65df36b
Author: Ashod Nakashian 
Date:   Wed Mar 15 10:45:42 2017 -0400

wsd: send recylcing message to clients on shutdown

Change-Id: Ibeb37b801e388fa33671a3c7df564c8ed86d9b71
Reviewed-on: https://gerrit.libreoffice.org/35306
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 64212a48..1f179ed4 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -736,11 +736,9 @@ void ClientSession::onDisconnect()
 }
 else
 {
-#if 0 // loolnb
-std::lock_guard lock(ClientWebSocketsMutex);
-LOG_TRC("Capturing Client WS for [" << _id << "]");
-// ClientWebSockets.push_back(ws); //FIXME
-#endif
+static const std::string msg("close: recycling");
+sendFrame(msg);
+shutdown(WebSocketHandler::StatusCodes::ENDPOINT_GOING_AWAY);
 }
 }
 catch (const std::exception& exc)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index c12d7e60..fac23b22 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -179,12 +179,6 @@ static std::atomic OutstandingForks(0);
 static std::map > DocBrokers;
 static std::mutex DocBrokersMutex;
 
-#if 0 // loolnb
-/// Used when shutting down to notify them all that the server is recycling.
-static std::vector > ClientWebSockets;
-static std::mutex ClientWebSocketsMutex;
-#endif
-
 extern "C" { void dump_state(void); /* easy for gdb */ }
 
 #if ENABLE_DEBUG
@@ -2589,29 +2583,6 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 FileUtil::removeFile(path, true);
 }
 
-if (isShuttingDown())
-{
-#if 0 // loolnb
-// At this point there should be no other thread, but...
-std::lock_guard lock(ClientWebSocketsMutex);
-
-LOG_INF("Notifying clients that we are recycling.");
-static const std::string msg("close: recycling");
-for (auto& ws : ClientWebSockets)
-{
-try
-{
-ws->sendFrame(msg.data(), msg.size());
-ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY);
-}
-catch (const std::exception& ex)
-{
-LOG_ERR("Error while notifying client of recycle: " << 
ex.what());
-}
-}
-#endif
-}
-
 // Finally, we no longer need SSL.
 if (LOOLWSD::isSSLEnabled())
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/LOOLWSD.cpp

2017-03-16 Thread Jan Holesovsky
 wsd/ClientSession.cpp |6 --
 wsd/LOOLWSD.cpp   |   16 +---
 2 files changed, 5 insertions(+), 17 deletions(-)

New commits:
commit b384867b3fdf460b78917695b50d5ded8e99cc66
Author: Jan Holesovsky 
Date:   Thu Mar 16 11:33:35 2017 +0100

Fix limiting of the connections.

Change-Id: I9ff0aec168fd971599248fee177bf51b134e3e58

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 5ca126d..459754d 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -39,7 +39,8 @@ ClientSession::ClientSession(const std::string& id,
 _isDocumentOwner(false),
 _stop(false)
 {
-LOG_INF("ClientSession ctor [" << getName() << "].");
+const size_t curConnections = ++LOOLWSD::NumConnections;
+LOG_INF("ClientSession ctor [" << getName() << "], current number of 
connections: " << curConnections);
 }
 
 ClientSession::~ClientSession()
@@ -680,7 +681,8 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 
 void ClientSession::onDisconnect()
 {
-LOG_INF(getName() << " Disconnected.");
+const size_t curConnections = --LOOLWSD::NumConnections;
+LOG_INF(getName() << " Disconnected, current # of connections: " << 
curConnections);
 
 const auto docBroker = getDocumentBroker();
 LOG_CHECK_RET(docBroker && "Null DocumentBroker instance", );
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index be63345..9c5fb00 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1718,22 +1718,9 @@ private:
 void onConnect(const std::weak_ptr& socket) override
 {
 _id = LOOLWSD::GenSessionId();
-_connectionNum = ++LOOLWSD::NumConnections;
-LOG_TRC("Connected connection #" << _connectionNum << " of " <<
-MAX_CONNECTIONS << " max as session [" << _id << "].");
-
 _socket = socket;
 }
 
-void onDisconnect() override
-{
-// FIXME: Move to ClientSession (ideally, wrap in ConnectionCounter 
object
-// to wrap this global NumConnections).
-const size_t curConnections = --LOOLWSD::NumConnections;
-LOG_TRC("Disconnected connection #" << _connectionNum << " (of " <<
-(curConnections + 1) << ") as session [" << _id << "].");
-}
-
 /// Called after successful socket reads.
 void handleIncomingMessage() override
 {
@@ -2215,7 +2202,7 @@ private:
 // First Upgrade.
 WebSocketHandler ws(_socket, request);
 
-if (_connectionNum > MAX_CONNECTIONS)
+if (LOOLWSD::NumConnections >= MAX_CONNECTIONS)
 {
 LOG_ERR("Limit on maximum number of connections of " << 
MAX_CONNECTIONS << " reached.");
 shutdownLimitReached(ws);
@@ -2279,7 +2266,6 @@ private:
 // The socket that owns us (we can't own it).
 std::weak_ptr _socket;
 std::string _id;
-size_t _connectionNum;
 };
 
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp

2017-01-25 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |   10 --
 wsd/DocumentBroker.cpp |   10 --
 2 files changed, 12 insertions(+), 8 deletions(-)

New commits:
commit 6fe933b46678f3bf52a63f51890ac4c900989d3b
Author: Ashod Nakashian 
Date:   Wed Jan 25 20:55:39 2017 -0500

wsd: take lock to forward messages to clients

Change-Id: I15888e4a5c35511c21f1e2d2bdd25ecbb16e80b9
Reviewed-on: https://gerrit.libreoffice.org/33568
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 742bb07..63db162 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -583,13 +583,10 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens.size() == 2 && tokens[0] == "statechanged:")
 {
-if (docBroker)
+StringTokenizer stateTokens(tokens[1], "=", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+if (stateTokens.count() == 2 && stateTokens[0] == 
".uno:ModifiedStatus")
 {
-StringTokenizer stateTokens(tokens[1], "=", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-if (stateTokens.count() == 2 && stateTokens[0] == 
".uno:ModifiedStatus")
-{
-docBroker->setModified(stateTokens[1] == "true");
-}
+docBroker->setModified(stateTokens[1] == "true");
 }
 }
 
@@ -652,6 +649,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 stringToInteger(firstLineTokens[3], w);
 stringToInteger(firstLineTokens[4], h);
 }
+
 docBroker->invalidateCursor(x, y, w, h);
 }
 else
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 7b3ee4c..91f3ce4 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -759,8 +759,6 @@ bool DocumentBroker::handleInput(const std::vector& 
payload)
 
 void DocumentBroker::invalidateTiles(const std::string& tiles)
 {
-std::unique_lock lock(_mutex);
-
 // Remove from cache.
 _tileCache->invalidateTiles(tiles);
 }
@@ -904,6 +902,9 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 const auto tile = TileDesc::parse(firstLine);
 const auto buffer = payload.data();
 const auto offset = firstLine.size() + 1;
+
+std::unique_lock lock(_mutex);
+
 tileCache().saveTileAndNotify(tile, buffer + offset, length - 
offset);
 }
 else
@@ -931,6 +932,9 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 const auto tileCombined = TileCombined::parse(firstLine);
 const auto buffer = payload.data();
 auto offset = firstLine.size() + 1;
+
+std::unique_lock lock(_mutex);
+
 for (const auto& tile : tileCombined.getTiles())
 {
 tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize());
@@ -1015,6 +1019,8 @@ bool DocumentBroker::forwardToClient(const 
std::shared_ptr& payload)
 std::string sid;
 if (LOOLProtocol::parseNameValuePair(payload->forwardToken(), name, sid, 
'-') && name == "client")
 {
+std::unique_lock lock(_mutex);
+
 const auto it = _sessions.find(sid);
 if (it != _sessions.end())
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2017-01-25 Thread Ashod Nakashian
 wsd/ClientSession.cpp |   22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

New commits:
commit b8edc135a7ce72631da8efefd78cd3cbc287c469
Author: Ashod Nakashian 
Date:   Sun Jan 22 23:19:04 2017 -0500

wsd: use Message object to handle responses back to clients

Change-Id: I5ddb32bbd7290c27308199f40f0ed286a869eafd
Reviewed-on: https://gerrit.libreoffice.org/33441
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 6437d00..742bb07 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -477,9 +477,10 @@ void ClientSession::senderThread()
 
 bool ClientSession::handleKitToClientMessage(const char* buffer, const int 
length)
 {
-LOG_TRC(getName() + ": handling [" << getAbbreviatedMessage(buffer, 
length) << "].");
-const std::string firstLine = getFirstLine(buffer, length);
-StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | 
StringTokenizer::TOK_TRIM);
+const auto payload = std::make_shared(buffer, length, 
Message::Dir::Out);
+
+LOG_TRC(getName() + ": handling [" << payload->abbr() << "].");
+const std::string& firstLine = payload->firstLine();
 
 const auto docBroker = _docBroker.lock();
 if (!docBroker)
@@ -490,6 +491,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 
 LOOLWSD::dumpOutgoingTrace(docBroker->getJailId(), getId(), firstLine);
 
+const auto& tokens = payload->tokens();
 if (tokens[0] == "unocommandresult:")
 {
 const std::string stringMsg(buffer, length);
@@ -536,7 +538,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 errorKind == "passwordrequired:to-modify" ||
 errorKind == "wrongpassword")
 {
-const auto payload = std::make_shared(buffer, 
length, Message::Dir::Out);
 forwardToClient(payload);
 LOG_WRN("Document load failed: " << errorKind);
 return false;
@@ -544,13 +545,13 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 }
 }
-else if (tokens[0] == "curpart:" && tokens.count() == 2)
+else if (tokens[0] == "curpart:" && tokens.size() == 2)
 {
 //TODO: Should forward to client?
 int curPart;
 return getTokenInteger(tokens[1], "part", curPart);
 }
-else if (tokens.count() == 2 && tokens[0] == "saveas:")
+else if (tokens.size() == 2 && tokens[0] == "saveas:")
 {
 std::string url;
 if (!getTokenString(tokens[1], "url", url))
@@ -580,7 +581,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 setSaveAsUrl(url);
 return true;
 }
-else if (tokens.count() == 2 && tokens[0] == "statechanged:")
+else if (tokens.size() == 2 && tokens[0] == "statechanged:")
 {
 if (docBroker)
 {
@@ -604,7 +605,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 docBroker->setLoaded();
 
 // Forward the status response to the client.
-const auto payload = std::make_shared(buffer, length, 
Message::Dir::Out);
 return forwardToClient(payload);
 }
 else if (tokens[0] == "commandvalues:")
@@ -628,7 +628,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens[0] == "partpagerectangles:")
 {
-if (tokens.count() > 1 && !tokens[1].empty())
+if (tokens.size() > 1 && !tokens[1].empty())
 {
 docBroker->tileCache().saveTextFile(std::string(buffer, 
length), "partpagerectangles.txt");
 }
@@ -662,7 +662,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 else if (tokens[0] == "renderfont:")
 {
 std::string font, text;
-if (tokens.count() < 3 ||
+if (tokens.size() < 3 ||
 !getTokenString(tokens[1], "font", font))
 {
 LOG_ERR("Bad syntax for: " << firstLine);
@@ -672,7 +672,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 getTokenString(tokens[2], "char", text);
 assert(firstLine.size() < 
static_cast(length));
 docBroker->tileCache().saveRendering(font+text, "font", buffer + 
firstLine.size() + 1, length - firstLine.size() - 1);
-const auto payload = std::make_shared(buffer, length, 
Message::Dir::Out);
 return forwardToClient(payload);
 }
 }
@@ -682,7 +681,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 
 // Forward everything else.
-const auto payload = std::make_shared(bu

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp

2017-01-22 Thread Ashod Nakashian
 wsd/ClientSession.cpp |   29 -
 wsd/ClientSession.hpp |   11 +++
 2 files changed, 15 insertions(+), 25 deletions(-)

New commits:
commit 664f602555dac15a6333943b8f9a0d21f29f659d
Author: Ashod Nakashian 
Date:   Sat Jan 21 22:32:00 2017 -0500

wsd: cleanup ClientSession

Change-Id: Ia5d138ed7baf4c26982e93157d82e332cd049a60
Reviewed-on: https://gerrit.libreoffice.org/33435
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 87bc072..12b8fb8 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -37,8 +37,6 @@ ClientSession::ClientSession(const std::string& id,
 _uriPublic(uriPublic),
 _isReadOnly(readOnly),
 _isDocumentOwner(false),
-_loadPart(-1),
-_isLoadRequested(false),
 _stop(false)
 {
 LOG_INF("ClientSession ctor [" << getName() << "].");
@@ -57,11 +55,6 @@ ClientSession::~ClientSession()
 }
 }
 
-bool ClientSession::isLoaded() const
-{
-return _isLoadRequested && gotStatus();
-}
-
 bool ClientSession::_handleInput(const char *buffer, int length)
 {
 LOG_TRC(getName() << ": handling [" << getAbbreviatedMessage(buffer, 
length) << "].");
@@ -239,7 +232,8 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/,
 try
 {
 std::string timestamp;
-parseDocOptions(tokens, _loadPart, timestamp);
+int loadPart = -1;
+parseDocOptions(tokens, loadPart, timestamp);
 
 std::ostringstream oss;
 oss << "load";
@@ -257,21 +251,22 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/,
 oss << " author=" + encodedUserName;
 }
 
-if (_loadPart >= 0)
-oss << " part=" + std::to_string(_loadPart);
+if (loadPart >= 0)
+{
+oss << " part=" << loadPart;
+}
 
 if (_haveDocPassword)
+{
 oss << " password=" << _docPassword;
+}
 
 if (!_docOptions.empty())
-oss << " options=" << _docOptions;
-
-const auto loadRequest = oss.str();
-if (forwardToChild(loadRequest, docBroker))
 {
-_isLoadRequested = true;
-return true;
+oss << " options=" << _docOptions;
 }
+
+return forwardToChild(oss.str(), docBroker);
 }
 catch (const Poco::SyntaxException&)
 {
@@ -607,7 +602,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens[0] == "status:")
 {
-_gotStatus = true;
+_isLoaded = true;
 docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 96fd0f7..706fae1 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -34,10 +34,8 @@ public:
 void setReadOnly();
 bool isReadOnly() const { return _isReadOnly; }
 
-/// Returns true if we've got status message.
-bool gotStatus() const { return _gotStatus; }
-
-bool isLoaded() const;
+/// Returns true if a document is loaded (i.e. we got status message).
+bool isLoaded() const { return _isLoaded; }
 
 const std::string getUserId() const { return _userId; }
 void setUserId(const std::string& userId) { _userId = userId; }
@@ -165,10 +163,7 @@ private:
 /// Store URLs of completed 'save as' documents.
 MessageQueue _saveAsQueue;
 
-int _loadPart;
-
-bool _isLoadRequested;
-bool _gotStatus;
+bool _isLoaded;
 
 /// Wopi FileInfo object
 std::unique_ptr _wopiFileInfo;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/PrisonerSession.cpp wsd/PrisonerSession.hpp

2017-01-22 Thread Ashod Nakashian
 wsd/ClientSession.cpp   |   21 ++---
 wsd/ClientSession.hpp   |7 +++
 wsd/DocumentBroker.cpp  |   13 +
 wsd/PrisonerSession.cpp |   31 ---
 wsd/PrisonerSession.hpp |   10 --
 5 files changed, 26 insertions(+), 56 deletions(-)

New commits:
commit 1f3d9ee457148fcc9eff3fbd3da66002010eb8bb
Author: Ashod Nakashian 
Date:   Sat Jan 21 20:31:22 2017 -0500

wsd: ClientSession now encapsulates PrisonerSession

No need to expose PrisonerSession via ClientSession
when the marshalling of messages can be done by
ClientSession directly.

PrisonerSession can now be removed altogether.

Change-Id: I131e41f5d9ae50be7244fb92a6f391a757502111
Reviewed-on: https://gerrit.libreoffice.org/33431
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 3bc76de..63ca129 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -43,6 +43,7 @@ ClientSession::ClientSession(const std::string& id,
 {
 LOG_INF("ClientSession ctor [" << getName() << "].");
 
+_peer = std::make_shared(*this, docBroker);
 _senderThread = std::thread([this]{ senderThread(); });
 }
 
@@ -62,21 +63,6 @@ bool ClientSession::isLoaded() const
 return _isLoadRequested && _peer && _peer->gotStatus();
 }
 
-void ClientSession::bridgePrisonerSession()
-{
-auto docBroker = getDocumentBroker();
-if (docBroker)
-{
-_peer = std::make_shared(shared_from_this(), 
docBroker);
-}
-else
-{
-const std::string msg = "No valid DocBroker while bridging Prisoner 
Session for " + getName();
-LOG_ERR(msg);
-throw std::runtime_error(msg);
-}
-}
-
 bool ClientSession::_handleInput(const char *buffer, int length)
 {
 LOG_TRC(getName() << ": handling [" << getAbbreviatedMessage(buffer, 
length) << "].");
@@ -495,4 +481,9 @@ void ClientSession::senderThread()
 LOG_DBG(getName() << " SenderThread finished");
 }
 
+bool ClientSession::handleKitToClientMessage(const char* data, const int size)
+{
+return _peer->handleInput(data, size);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 5d97d70..b6211a7 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -37,16 +37,15 @@ public:
 
 bool isLoaded() const;
 
-/// Create and connect Prisoner Session between DocumentBroker and us.
-void bridgePrisonerSession();
-std::shared_ptr getPeer() const { return _peer; }
-
 const std::string getUserId() const { return _userId; }
 void setUserId(const std::string& userId) { _userId = userId; }
 void setUserName(const std::string& userName) { _userName = userName; }
 void setDocumentOwner(const bool documentOwner) { _isDocumentOwner = 
documentOwner; }
 bool isDocumentOwner() const { return _isDocumentOwner; }
 
+/// Handle kit-to-client message.
+bool handleKitToClientMessage(const char* data, const int size);
+
 using Session::sendTextFrame;
 
 bool sendBinaryFrame(const char* buffer, int length) override
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 1d699a2..38d13c1 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -651,9 +651,6 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 const std::string aMessage = "session " + id + ' ' + _docKey;
 _childProcess->sendTextFrame(aMessage);
 
-// Now we are ready to bridge between the kit and client.
-session->bridgePrisonerSession();
-
 // Tell the admin console about this new doc
 Admin::instance().addDoc(_docKey, getPid(), getFilename(), id);
 
@@ -1032,15 +1029,7 @@ bool DocumentBroker::forwardToClient(const std::string& 
prefix, const std::vecto
 const auto it = _sessions.find(sid);
 if (it != _sessions.end())
 {
-const auto peer = it->second->getPeer();
-if (peer)
-{
-return peer->handleInput(data, size);
-}
-else
-{
-LOG_WRN("Client session [" << sid << "] has no peer to forward 
message: " << message);
-}
+return it->second->handleKitToClientMessage(data, size);
 }
 else
 {
diff --git a/wsd/PrisonerSession.cpp b/wsd/PrisonerSession.cpp
index d05a9a6..9a2b0cf 100644
--- a/wsd/PrisonerSession.cpp
+++ b/wsd/PrisonerSession.cpp
@@ -32,9 +32,9 @@ using namespace LOOLProtocol;
 using Poco::Path;
 using Poco::StringTokenizer;
 
-PrisonerSession::PrisonerSession(std::shared_ptr clientSession,
+PrisonerSession::PrisonerSession(ClientSession& clientSession,
  std::shared_ptr docBroker) :
-Session("ToPrisoner-" + clientSession->getId(), clientSession->getId(), 
nullptr),
+Session("ToPrisoner-" + clientSession.getId(), clientSession.getId(), 
nullptr),
 _docBroke

[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/TileCache.cpp wsd/TileCache.hpp

2017-01-17 Thread Jan Holesovsky
 wsd/ClientSession.cpp |8 
 wsd/TileCache.cpp |   13 +++--
 wsd/TileCache.hpp |5 -
 3 files changed, 15 insertions(+), 11 deletions(-)

New commits:
commit 91bf720ba39a912b6f2fe647841ac54f1e909c25
Author: Jan Holesovsky 
Date:   Tue Jan 17 16:42:31 2017 +0100

Fix error handling in reading of the cached values.

Change-Id: I9f56f09786feb11326707d19cc0367a027ebefff

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index f24a525..ca09eeb 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -307,8 +307,8 @@ bool ClientSession::getCommandValues(const char *buffer, 
int length, StringToken
 return sendTextFrame("error: cmd=commandvalues kind=syntax");
 }
 
-const std::string cmdValues = 
docBroker->tileCache().getTextFile("cmdValues" + command + ".txt");
-if (cmdValues.size() > 0)
+std::string cmdValues;
+if (docBroker->tileCache().getTextFile("cmdValues" + command + ".txt", 
cmdValues))
 {
 return sendTextFrame(cmdValues);
 }
@@ -319,8 +319,8 @@ bool ClientSession::getCommandValues(const char *buffer, 
int length, StringToken
 bool ClientSession::getPartPageRectangles(const char *buffer, int length,
   const 
std::shared_ptr& docBroker)
 {
-const std::string partPageRectangles = 
docBroker->tileCache().getTextFile("partpagerectangles.txt");
-if (partPageRectangles.size() > 0)
+std::string partPageRectangles;
+if (docBroker->tileCache().getTextFile("partpagerectangles.txt", 
partPageRectangles))
 {
 return sendTextFrame(partPageRectangles);
 }
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index 4de0fa2..4e784f5 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -55,9 +55,10 @@ TileCache::TileCache(const std::string& docURL,
 << "] modifiedTime=" << (modifiedTime.raw()/100)
 << " getLastModified()=" << (getLastModified().raw()/100) 
<< Log::end;
 File directory(_cacheDir);
+std::string unsaved;
 if (directory.exists() &&
 (getLastModified() < modifiedTime ||
- getTextFile("unsaved.txt") != ""))
+ getTextFile("unsaved.txt", unsaved)))
 {
 // Document changed externally or modifications were not saved after 
all. Cache not useful.
 FileUtil::removeFile(_cacheDir, true);
@@ -222,7 +223,7 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, 
const char *data, const
 }
 }
 
-std::string TileCache::getTextFile(const std::string& fileName)
+bool TileCache::getTextFile(const std::string& fileName, std::string& content)
 {
 const std::string fullFileName =  _cacheDir + "/" + fileName;
 
@@ -230,7 +231,7 @@ std::string TileCache::getTextFile(const std::string& 
fileName)
 if (!textStream.is_open())
 {
 Log::info("Could not open " + fullFileName);
-return "";
+return false;
 }
 
 std::vector buffer;
@@ -244,10 +245,10 @@ std::string TileCache::getTextFile(const std::string& 
fileName)
 if (buffer.size() > 0 && buffer.back() == '\n')
 buffer.pop_back();
 
-std::string result = std::string(buffer.data(), buffer.size());
-Log::info("Read '" + LOOLProtocol::getAbbreviatedMessage(result.c_str(), 
result.size()) + "' from " + fullFileName);
+content = std::string(buffer.data(), buffer.size());
+Log::info("Read '" + LOOLProtocol::getAbbreviatedMessage(content.c_str(), 
content.size()) + "' from " + fullFileName);
 
-return result;
+return true;
 }
 
 void TileCache::saveTextFile(const std::string& text, const std::string& 
fileName)
diff --git a/wsd/TileCache.hpp b/wsd/TileCache.hpp
index af9b8f2..96b5a5b 100644
--- a/wsd/TileCache.hpp
+++ b/wsd/TileCache.hpp
@@ -49,7 +49,10 @@ public:
 
 void saveTileAndNotify(const TileDesc& tile, const char* data, const 
size_t size);
 
-std::string getTextFile(const std::string& fileName);
+/// Get the content of a cache file.
+/// @param content Valid only when the call returns true.
+/// @return true when the file actually exists
+bool getTextFile(const std::string& fileName, std::string& content);
 
 // Save some text into a file in the cache directory
 void saveTextFile(const std::string& text, const std::string& fileName);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/PrisonerSession.cpp wsd/PrisonerSession.hpp

2017-01-15 Thread Ashod Nakashian
 wsd/ClientSession.cpp   |   11 ++-
 wsd/ClientSession.hpp   |4 
 wsd/DocumentBroker.cpp  |1 +
 wsd/PrisonerSession.cpp |4 +++-
 wsd/PrisonerSession.hpp |4 
 5 files changed, 22 insertions(+), 2 deletions(-)

New commits:
commit 05620be4c5d0369d160ac79f4eaee00013229324
Author: Ashod Nakashian 
Date:   Wed Jan 11 16:45:14 2017 -0500

wsd: autosave on disconnecting based on loaded sessions only

When a client disconnects, we autosave only when there
are no other sessions. The idea being that it'd be
wasteful to save on every client disconnect, so long
that we have a later chance of saving.

This doesn't hold, however, when the only other
remaining session is one that had just connected
and hasn't loaded a view yet. WSD wouldn't
know about this, but when unloading the
disconnecting session, Kit will exit the process
as the last view is gone, losing all unsaved changes.

This patch tracks the sessions in WSD that have
loaded a view and takes that into account when
deciding to autosave on disconnect or not, thereby
fixing this corner case that may result in data loss.

Change-Id: I699721f2d710128ed4db65943b9357dff54380f5
Reviewed-on: https://gerrit.libreoffice.org/33126
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 9715f32..f24a525 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -38,6 +38,7 @@ ClientSession::ClientSession(const std::string& id,
 _isReadOnly(readOnly),
 _isDocumentOwner(false),
 _loadPart(-1),
+_isLoadRequested(false),
 _stop(false)
 {
 LOG_INF("ClientSession ctor [" << getName() << "].");
@@ -57,7 +58,11 @@ ClientSession::~ClientSession()
 {
 _senderThread.join();
 }
+}
 
+bool ClientSession::isLoaded() const
+{
+return _isLoadRequested && _peer && _peer->gotStatus();
 }
 
 void ClientSession::bridgePrisonerSession()
@@ -279,7 +284,11 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/, StringT
 oss << " options=" << _docOptions;
 
 const auto loadRequest = oss.str();
-return forwardToChild(loadRequest, docBroker);
+if (forwardToChild(loadRequest, docBroker))
+{
+_isLoadRequested = true;
+return true;
+}
 }
 catch (const Poco::SyntaxException&)
 {
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 7952029..c946a94 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -35,6 +35,8 @@ public:
 void setReadOnly();
 bool isReadOnly() const { return _isReadOnly; }
 
+bool isLoaded() const;
+
 /// Create and connect Prisoner Session between DocumentBroker and us.
 void bridgePrisonerSession();
 std::shared_ptr getPeer() const { return _peer; }
@@ -147,6 +149,8 @@ private:
 
 int _loadPart;
 
+bool _isLoadRequested;
+
 /// Wopi FileInfo object
 std::unique_ptr _wopiFileInfo;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 7d7bfee..f1db30b 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -949,6 +949,7 @@ bool DocumentBroker::startDestroy(const std::string& id)
 for (const auto& it : _sessions)
 {
 if (it.second->getId() != id &&
+it.second->isLoaded() &&
 !it.second->isReadOnly())
 {
 // Found another editable.
diff --git a/wsd/PrisonerSession.cpp b/wsd/PrisonerSession.cpp
index 1848413..16cb760 100644
--- a/wsd/PrisonerSession.cpp
+++ b/wsd/PrisonerSession.cpp
@@ -37,7 +37,8 @@ 
PrisonerSession::PrisonerSession(std::shared_ptr clientSession,
 Session("ToPrisoner-" + clientSession->getId(), clientSession->getId(), 
nullptr),
 _docBroker(std::move(docBroker)),
 _peer(clientSession),
-_curPart(0)
+_curPart(0),
+_gotStatus(false)
 {
 LOG_INF("PrisonerSession ctor [" << getName() << "].");
 }
@@ -170,6 +171,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
 }
 else if (tokens[0] == "status:")
 {
+_gotStatus = true;
 _docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/PrisonerSession.hpp b/wsd/PrisonerSession.hpp
index 4085fb3..5a333a2 100644
--- a/wsd/PrisonerSession.hpp
+++ b/wsd/PrisonerSession.hpp
@@ -27,6 +27,9 @@ public:
 
 virtual ~PrisonerSession();
 
+/// Returns true if we've got status message.
+bool gotStatus() const { return _gotStatus; }
+
 private:
 /// Handle messages from the Kit to the client.
 virtual bool _handleInput(const char* buffer, int length) override;
@@ -38,6 +41,7 @@ private:
 std::shared_ptr _docBroker;
 std::weak_ptr _peer;
 int _curPart;
+bool _gotStatus;
 };
 
 #endif
___
Libreoffice-commit

[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2016-12-31 Thread Ashod Nakashian
 wsd/ClientSession.cpp |   20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

New commits:
commit ba90ea304c9680ade84e586fc09be7c338d82770
Author: Ashod Nakashian 
Date:   Wed Dec 21 18:27:37 2016 -0500

wsd: ClientSession logs updated

Change-Id: I4ec664ebd7eadbe3763ee18eb511662de6453ebb
Reviewed-on: https://gerrit.libreoffice.org/32552
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index f26fff3..9715f32 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -40,14 +40,14 @@ ClientSession::ClientSession(const std::string& id,
 _loadPart(-1),
 _stop(false)
 {
-Log::info("ClientSession ctor [" + getName() + "].");
+LOG_INF("ClientSession ctor [" << getName() << "].");
 
 _senderThread = std::thread([this]{ senderThread(); });
 }
 
 ClientSession::~ClientSession()
 {
-Log::info("~ClientSession dtor [" + getName() + "].");
+LOG_INF("~ClientSession dtor [" << getName() << "].");
 
 // Release the save-as queue.
 _saveAsQueue.put("");
@@ -77,14 +77,14 @@ void ClientSession::bridgePrisonerSession()
 
 bool ClientSession::_handleInput(const char *buffer, int length)
 {
-LOG_TRC(getName() + ": handling [" << getAbbreviatedMessage(buffer, 
length) << "].");
+LOG_TRC(getName() << ": handling [" << getAbbreviatedMessage(buffer, 
length) << "].");
 const std::string firstLine = getFirstLine(buffer, length);
 StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | 
StringTokenizer::TOK_TRIM);
 
 auto docBroker = getDocumentBroker();
 if (!docBroker)
 {
-Log::error("No DocBroker found. Terminating session " + getName());
+LOG_ERR("No DocBroker found. Terminating session " << getName());
 return false;
 }
 
@@ -183,7 +183,7 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 // is turned on by WOPI, let it close all sessions
 if (_isDocumentOwner && _wopiFileInfo && 
_wopiFileInfo->_enableOwnerTermination)
 {
-LOG_DBG("Session [" + getId() + "] requested owner termination");
+LOG_DBG("Session [" << getId() << "] requested owner termination");
 docBroker->closeDocument("ownertermination");
 }
 
@@ -247,7 +247,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/, StringT
 return false;
 }
 
-Log::info("Requesting document load from child.");
+LOG_INF("Requesting document load from child.");
 try
 {
 std::string timestamp;
@@ -363,7 +363,7 @@ bool ClientSession::sendTile(const char * /*buffer*/, int 
/*length*/, StringToke
 }
 catch (const std::exception& exc)
 {
-Log::error(std::string("Failed to process tile command: ") + 
exc.what() + ".");
+LOG_ERR("Failed to process tile command: " << exc.what());
 return sendTextFrame("error: cmd=tile kind=invalid");
 }
 
@@ -380,7 +380,7 @@ bool ClientSession::sendCombinedTiles(const char* 
/*buffer*/, int /*length*/, St
 }
 catch (const std::exception& exc)
 {
-Log::error(std::string("Failed to process tilecombine command: ") + 
exc.what() + ".");
+LOG_ERR("Failed to process tilecombine command: " << exc.what());
 return sendTextFrame("error: cmd=tile kind=invalid");
 }
 
@@ -458,7 +458,7 @@ void ClientSession::setReadOnly()
 
 void ClientSession::senderThread()
 {
-LOG_DBG(getName() + " SenderThread started");
+LOG_DBG(getName() << " SenderThread started");
 
 while (!stopping())
 {
@@ -485,7 +485,7 @@ void ClientSession::senderThread()
 }
 }
 
-LOG_DBG(getName() + " SenderThread finished");
+LOG_DBG(getName() << " SenderThread finished");
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/ClientSession.cpp

2016-12-18 Thread Ashod Nakashian
 wsd/ClientSession.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 5a987bea9091814e76264238a81199e56e0dff06
Author: Ashod Nakashian 
Date:   Thu Dec 15 09:01:23 2016 -0500

loolwsd: better to poll less frequently

Change-Id: I8ad44d132f11d32247f48583151c650e98856f82
Reviewed-on: https://gerrit.libreoffice.org/32153
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index c97ef64..16348db 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -470,7 +470,7 @@ void ClientSession::senderThread()
 while (!stopping())
 {
 std::shared_ptr item;
-if (_senderQueue.waitDequeue(item, 
static_cast(POLL_TIMEOUT_MS)))
+if (_senderQueue.waitDequeue(item, 
static_cast(COMMAND_TIMEOUT_MS)))
 {
 const std::vector& data = item->data();
 try
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits