[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp discovery.xml loleaflet/src wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp

2020-07-27 Thread Tomaž Vajngerl (via logerrit)
 common/Session.cpp   |1 +
 common/Session.hpp   |   11 ++-
 discovery.xml|2 +-
 loleaflet/src/control/Control.Menubar.js |   22 +++---
 loleaflet/src/control/Toolbar.js |2 +-
 wsd/ClientSession.cpp|   16 +++-
 wsd/ClientSession.hpp|3 ++-
 wsd/DocumentBroker.cpp   |4 
 wsd/LOOLWSD.cpp  |7 ++-
 wsd/LOOLWSD.hpp  |   19 +--
 10 files changed, 72 insertions(+), 15 deletions(-)

New commits:
commit ca00470722ec7a7a7b190ca36a1f71da06ed6847
Author: Tomaž Vajngerl 
AuthorDate: Mon Jul 27 11:27:00 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Mon Jul 27 16:40:12 2020 +0200

allow saving a PDF, add "view_comment" state

This adds a "view_comment" in addition to "view" and "edit" state
into discovery.xml. In case it is enabled, the filters let the
comment commands through to core.

In addition add "Save Comment" menu action to allow saving the
comments, which is enabled when in "read-only" with "view_comment"
mode.

Change-Id: I3ab3dbee93ee2167ae96adea7025fc0b385f8201
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/99473
Tested-by: Jenkins CollaboraOffice 
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/common/Session.cpp b/common/Session.cpp
index cdccea9d6..14ecb6276 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -52,6 +52,7 @@ Session::Session(const 
std::shared_ptr ,
 _lastActivityTime(std::chrono::steady_clock::now()),
 _isCloseFrame(false),
 _isReadOnly(readOnly),
+_isAllowChangeComments(false),
 _docPassword(""),
 _haveDocPassword(false),
 _isDocPasswordProtected(false),
diff --git a/common/Session.hpp b/common/Session.hpp
index b42cc38e3..e88a59d89 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -76,9 +76,15 @@ public:
 const std::string& getName() const { return _name; }
 bool isDisconnected() const { return _disconnected; }
 
-virtual void setReadOnly(bool bVal = true) { _isReadOnly = bVal; }
+virtual void setReadOnly(bool bValue = true) { _isReadOnly = bValue; }
 bool isReadOnly() const { return _isReadOnly; }
 
+void setAllowChangeComments(bool bValue = true)
+{
+_isAllowChangeComments = bValue;
+}
+bool isAllowChangeComments() const { return _isAllowChangeComments; }
+
 /// overridden to prepend client ids on messages by the Kit
 virtual bool sendBinaryFrame(const char* buffer, int length);
 virtual bool sendTextFrame(const char* buffer, const int length);
@@ -249,6 +255,9 @@ private:
 /// Whether the session is opened as readonly
 bool _isReadOnly;
 
+/// If the session is read-only, are comments allowed
+bool _isAllowChangeComments;
+
 /// The actual URL, also in the child, even if the child never accesses 
that.
 std::string _docURL;
 
diff --git a/discovery.xml b/discovery.xml
index b694f97d3..b0ea602d4 100644
--- a/discovery.xml
+++ b/discovery.xml
@@ -306,7 +306,7 @@
 
 
 
-
+
 
 
 
diff --git a/loleaflet/src/control/Control.Menubar.js 
b/loleaflet/src/control/Control.Menubar.js
index 0e8c8e561..bbe8e3132 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -254,6 +254,7 @@ L.Control.Menubar = L.Control.extend({
{name: _UNO('.uno:PickList', 'presentation'), id: 
'file', type: 'menu', menu: [
{name: _UNO('.uno:Save', 'presentation'), id: 
'save', type: 'action'},
{name: _UNO('.uno:SaveAs', 'presentation'), id: 
'saveas', type: 'action'},
+   {name: _('Save Comments'), id: 'savecomments', 
type: 'action'},
{name: _('Share...'), id:'shareas', type: 
'action'},
{name: _UNO('.uno:Print', 'presentation'), id: 
'print', type: 'action'},
{name: _('See revision history'), id: 
'rev-history', type: 'action'},
@@ -725,15 +726,16 @@ L.Control.Menubar = L.Control.extend({
commandStates: {},
 
// Only these menu options will be visible in readonly mode
-   allowedReadonlyMenus: ['file', 'downloadas', 'view', 'help'],
+   allowedReadonlyMenus: ['file', 'downloadas', 'view', 'insert', 
'help'],
 
allowedViewModeActions: [
-   'shareas', 'print', // file menu
+   'savecomments', 'shareas', 'print', // file menu
'downloadas-pdf', 'downloadas-odt', 'downloadas-doc', 
'downloadas-docx', 'downloadas-rtf', 'downloadas-epub', // file menu
'downloadas-odp', 

[Libreoffice-commits] online.git: common/Session.cpp common/StringVector.cpp common/StringVector.hpp kit/ChildSession.cpp test/WhiteBoxTests.cpp wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/LOOLWS

2020-06-01 Thread Ashod Nakashian (via logerrit)
 common/Session.cpp  |2 -
 common/StringVector.cpp |   73 +---
 common/StringVector.hpp |   71 --
 kit/ChildSession.cpp|   12 +++
 test/WhiteBoxTests.cpp  |3 +
 wsd/ClientSession.cpp   |2 -
 wsd/DocumentBroker.cpp  |2 -
 wsd/LOOLWSD.cpp |3 -
 8 files changed, 69 insertions(+), 99 deletions(-)

New commits:
commit 784b7dc39d880448e5599c19e65798d7207a412a
Author: Ashod Nakashian 
AuthorDate: Sun May 31 14:16:58 2020 -0400
Commit: Ashod Nakashian 
CommitDate: Tue Jun 2 01:39:37 2020 +0200

wsd: optimize StringVector

StringVector is heavily used for tokenization
and benefits from inlining of small functions.

Also, cat doesn't need to be slower than necessary.

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

diff --git a/common/Session.cpp b/common/Session.cpp
index 0b3499a05..204573e0f 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -200,7 +200,7 @@ void Session::parseDocOptions(const StringVector& tokens, 
int& part, std::string
 if (getTokenString(tokens[offset], "options", _docOptions))
 {
 if (tokens.size() > offset + 1)
-_docOptions += tokens.cat(std::string(" "), offset + 1);
+_docOptions += tokens.cat(' ', offset + 1);
 }
 }
 }
diff --git a/common/StringVector.cpp b/common/StringVector.cpp
index aab884881..2fef5aa0b 100644
--- a/common/StringVector.cpp
+++ b/common/StringVector.cpp
@@ -17,7 +17,7 @@ StringVector::StringVector(const std::string& string, const 
std::vector= _tokens.size())
 {
@@ -28,76 +28,7 @@ std::string StringVector::operator[](size_t index) const
 return _string.substr(token._index, token._length);
 }
 
-size_t StringVector::size() const { return _tokens.size(); }
-
-bool StringVector::empty() const { return _tokens.empty(); }
-
-std::vector::const_iterator StringVector::begin() const { return 
_tokens.begin(); }
-
-std::vector::iterator StringVector::begin() { return 
_tokens.begin(); }
-
-std::vector::const_iterator StringVector::end() const { return 
_tokens.end(); }
-
-std::vector::iterator StringVector::end() { return _tokens.end(); 
}
-
-std::vector::iterator 
StringVector::erase(std::vector::const_iterator it)
-{
-return _tokens.erase(it);
-}
-
-void StringVector::push_back(const std::string& string)
-{
-StringToken token;
-token._index = _string.length();
-token._length = string.length();
-_tokens.push_back(token);
-_string += string;
-}
-
-std::string StringVector::getParam(const StringToken& token) const
-{
-return _string.substr(token._index, token._length);
-}
-
-std::string StringVector::cat(const std::string& separator, size_t offset) 
const
-{
-std::string ret;
-bool first = true;
-
-if (offset >= _tokens.size())
-{
-return ret;
-}
-
-for (auto it = _tokens.begin() + offset; it != _tokens.end(); ++it)
-{
-if (first)
-{
-first = false;
-}
-else
-{
-ret += separator;
-}
-
-ret += getParam(*it);
-}
-
-return ret;
-}
-
-bool StringVector::equals(size_t index, const char* string) const
-{
-if (index >= _tokens.size())
-{
-return false;
-}
-
-const StringToken& token = _tokens[index];
-return _string.compare(token._index, token._length, string) == 0;
-}
-
-bool StringVector::equals(size_t index, const StringVector& other, size_t 
otherIndex)
+bool StringVector::equals(std::size_t index, const StringVector& other, 
std::size_t otherIndex)
 {
 if (index >= _tokens.size())
 {
diff --git a/common/StringVector.hpp b/common/StringVector.hpp
index 154060bf1..fa0e94491 100644
--- a/common/StringVector.hpp
+++ b/common/StringVector.hpp
@@ -17,12 +17,12 @@
  */
 struct StringToken
 {
-size_t _index;
-size_t _length;
+std::size_t _index;
+std::size_t _length;
 
 StringToken() = default;
 
-StringToken(size_t index, size_t length)
+StringToken(std::size_t index, std::size_t length)
 : _index(index),
 _length(length)
 {
@@ -45,35 +45,74 @@ public:
 explicit StringVector(const std::string& string, const 
std::vector& tokens);
 
 /// Unlike std::vector, gives an empty string if index is unexpected.
-std::string operator[](size_t index) const;
+std::string operator[](std::size_t index) const;
 
-size_t size() const;
+std::size_t size() const { return _tokens.size(); }
 
-bool empty() const;
+bool empty() const { return _tokens.empty(); }
 
-std::vector::const_iterator begin() const;
+std::vector::const_iterator begin() const { return 
_tokens.begin(); }
 
-std::vector::iterator begin();
+std::vector::iterator begin() { return 

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

2020-05-25 Thread Michael Meeks (via logerrit)
 common/Session.cpp |1 +
 wsd/ClientSession.cpp  |2 +-
 wsd/DocumentBroker.cpp |6 +++---
 3 files changed, 5 insertions(+), 4 deletions(-)

New commits:
commit 87d039e00aed9ddc132f3984d3cb4000360c2c85
Author: Michael Meeks 
AuthorDate: Mon May 25 09:57:29 2020 +0100
Commit: Michael Meeks 
CommitDate: Mon May 25 12:37:40 2020 +0200

IO stats - handle convert-to case, and initiailize all temporaries.

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

diff --git a/common/Session.cpp b/common/Session.cpp
index ef8deea25..58d7c0b6b 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -264,6 +264,7 @@ void Session::getIOStats(uint64_t , uint64_t )
 if (!_protocol)
 {
 LOG_TRC("ERR - missing protocol " << getName() << ": Get IO stats.");
+sent = 0; recv = 0;
 return;
 }
 
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 369bed08d..20b1ed011 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1730,7 +1730,7 @@ void ClientSession::dumpState(std::ostream& os)
 
 if (_protocol)
 {
-uint64_t sent, recv;
+uint64_t sent = 0, recv = 0;
 _protocol->getIOStats(sent, recv);
 os << "\n\t\tsent/keystroke: " << (double)sent/_keyEvents << "bytes";
 }
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 3293dea94..717adec15 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -357,7 +357,7 @@ void DocumentBroker::pollThread()
 (now - lastBWUpdateTime).count() >= COMMAND_TIMEOUT_MS)
 {
 lastBWUpdateTime = now;
-uint64_t sent, recv;
+uint64_t sent = 0, recv = 0;
 getIOStats(sent, recv);
 
 uint64_t deltaSent = 0, deltaRecv = 0;
@@ -2232,7 +2232,7 @@ void DocumentBroker::getIOStats(uint64_t , uint64_t 
)
 assertCorrectThread();
 for (const auto& sessionIt : _sessions)
 {
-uint64_t s, r;
+uint64_t s = 0, r = 0;
 sessionIt.second->getIOStats(s, r);
 sent += s;
 recv += r;
@@ -2378,7 +2378,7 @@ void DocumentBroker::dumpState(std::ostream& os)
 {
 std::unique_lock lock(_mutex);
 
-uint64_t sent, recv;
+uint64_t sent = 0, recv = 0;
 getIOStats(sent, recv);
 
 auto now = std::chrono::steady_clock::now();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp kit/Kit.cpp loleaflet/js loleaflet/src wsd/ClientSession.cpp wsd/protocol.txt

2020-04-29 Thread Marco Cecchetti (via logerrit)
 common/Session.cpp   |5 +
 common/Session.hpp   |5 +
 kit/Kit.cpp  |4 
 loleaflet/js/global.js   |   17 +
 loleaflet/src/core/Socket.js |4 
 loleaflet/src/map/Map.js |6 ++
 wsd/ClientSession.cpp|5 +
 wsd/protocol.txt |5 -
 8 files changed, 46 insertions(+), 5 deletions(-)

New commits:
commit 255d24ba8fc8669b4197887e69bd4406af4cba14
Author: Marco Cecchetti 
AuthorDate: Mon Apr 20 21:26:21 2020 +0200
Commit: Marco Cecchetti 
CommitDate: Wed Apr 29 13:18:49 2020 +0200

forward the device form factor of the client on a new view request

This patch allows the lok core to know about the device form facor of
the client requesting the creation of a new view, immediately instead
of a later time.
When a request for a new view is sent a 'deviceFormFactor' parameter
is appended to the message.
This parameter can have one of the following values: 'desktop',
'tablet','mobile' and is forwarded to the lok core.

Change-Id: I21739ddb8c43c960164b3c625e4cf0a80f4616a4
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92691
Tested-by: Marco Cecchetti 
Reviewed-by: Marco Cecchetti 

diff --git a/common/Session.cpp b/common/Session.cpp
index e7f551979..ef8deea25 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -184,6 +184,11 @@ void Session::parseDocOptions(const StringVector& tokens, 
int& part, std::string
 doctemplate = value;
 ++offset;
 }
+else if (name == "deviceFormFactor")
+{
+_deviceFormFactor = value;
+++offset;
+}
 }
 
 Util::mapAnonymized(_userId, _userIdAnonym);
diff --git a/common/Session.hpp b/common/Session.hpp
index 3e5f4c89b..402223963 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -197,6 +197,8 @@ public:
 _canonicalViewId = map.getCanonicalId(_watermarkText);
 }
 
+const std::string& getDeviceFormFactor() const { return _deviceFormFactor; 
}
+
 protected:
 Session(const std::shared_ptr ,
 const std::string& name, const std::string& id, bool readonly);
@@ -288,6 +290,9 @@ private:
 
 /// the canonical id unique to the set of rendering properties of this 
session
 int _canonicalViewId;
+
+/// The form factor of the device where the client is running: desktop, 
tablet, mobile.
+std::string _deviceFormFactor;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index b5409ca68..52cd43f8c 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -1675,11 +1675,15 @@ private:
 const std::string& docPassword = session->getDocPassword();
 const bool haveDocPassword = session->getHaveDocPassword();
 const std::string& lang = session->getLang();
+const std::string& deviceFormFactor = session->getDeviceFormFactor();
 
 std::string options;
 if (!lang.empty())
 options = "Language=" + lang;
 
+if (!deviceFormFactor.empty())
+options += ",DeviceFormFactor=" + deviceFormFactor;
+
 if (!_loKitDocument)
 {
 // This is the first time we are loading the document
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index c2935ab96..07ae23ad9 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -158,9 +158,21 @@
},
isDesktop: function() {
return !L.Browser.mobile;
+   },
+   getDeviceFormFactor: function() {
+   if (window.mode.isMobile())
+   return 'mobile';
+   else if (window.mode.isTablet())
+   return 'tablet';
+   else if (window.mode.isDesktop())
+   return 'desktop';
+   else
+   return null;
}
};
 
+   global.deviceFormFactor = window.mode.getDeviceFormFactor();
+
document.addEventListener('contextmenu', function(e) {
if (e.preventDefault) {
e.preventDefault();
@@ -548,6 +560,11 @@
}
// renderingOptions?
}
+
+   if (window.deviceFormFactor) {
+   msg += ' deviceFormFactor=' + 
window.deviceFormFactor;
+   }
+
global.socket.send(msg);
}
};
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index fdd0b2db6..f6ba2a5c1 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -187,12 +187,16 @@ L.Socket = L.Class.extend({
if 

[Libreoffice-commits] online.git: common/Session.cpp

2020-03-19 Thread Miklos Vajna (via logerrit)
 common/Session.cpp |6 ++
 1 file changed, 6 insertions(+)

New commits:
commit d6fe0979b71ecc864257ff4595d2ffd27cc449d0
Author: Miklos Vajna 
AuthorDate: Thu Mar 19 09:12:33 2020 +0100
Commit: Michael Meeks 
CommitDate: Thu Mar 19 11:50:54 2020 +0100

common: handle missing protocol in Session::getIOStats()

This sometimes causes unit-integration to fail and now is consistent
with other member functions of Session that handle missing protocol.

Change-Id: I43c7fcae964cfcb5911ff57d63bd4cb569e6b97c
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90732
Tested-by: Michael Meeks 
Reviewed-by: Michael Meeks 

diff --git a/common/Session.cpp b/common/Session.cpp
index d24b615a9..859cd011e 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -257,6 +257,12 @@ void Session::handleMessage(const std::vector )
 
 void Session::getIOStats(uint64_t , uint64_t )
 {
+if (!_protocol)
+{
+LOG_TRC("ERR - missing protocol " << getName() << ": Get IO stats.");
+return;
+}
+
 _protocol->getIOStats(sent, recv);
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp net/Socket.hpp net/WebSocketHandler.hpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2020-03-16 Thread Miklos Vajna (via logerrit)
 common/Session.cpp   |2 +-
 net/Socket.hpp   |4 ++--
 net/WebSocketHandler.hpp |6 +++---
 wsd/DocumentBroker.cpp   |2 +-
 wsd/LOOLWSD.cpp  |4 ++--
 5 files changed, 9 insertions(+), 9 deletions(-)

New commits:
commit cd42700054646d6f9c2bc89769fb9e05f829776c
Author: Miklos Vajna 
AuthorDate: Mon Mar 16 10:34:12 2020 +0100
Commit: Miklos Vajna 
CommitDate: Mon Mar 16 11:55:19 2020 +0100

Rework the somewhat odd sendTextMessage() interface

It took both an std::string and a length. Take a char* and a length
instead.

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

diff --git a/common/Session.cpp b/common/Session.cpp
index 15dbe86d7..d24b615a9 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -221,7 +221,7 @@ void Session::shutdown(bool goingAway, const std::string& 
statusMessage)
 {
 // skip the queue; FIXME: should we flush SessionClient's queue ?
 std::string closeMsg = "close: " + statusMessage;
-_protocol->sendTextMessage(closeMsg, closeMsg.size());
+_protocol->sendTextMessage(closeMsg.c_str(), closeMsg.size());
 _protocol->shutdown(goingAway, statusMessage);
 }
 }
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 1e632516e..a6395b9b4 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -395,7 +395,7 @@ public:
 /// Clear all external references
 virtual void dispose() { _msgHandler.reset(); }
 
-virtual int sendTextMessage(const std::string , const size_t len, bool 
flush = false) const = 0;
+virtual int sendTextMessage(const char* msg, const size_t len, bool flush 
= false) const = 0;
 virtual int sendBinaryMessage(const char *data, const size_t len, bool 
flush = false) const = 0;
 virtual void shutdown(bool goingAway = false, const std::string 
 = "") = 0;
 
@@ -410,7 +410,7 @@ class SimpleSocketHandler : public ProtocolHandlerInterface
 {
 public:
 SimpleSocketHandler() {}
-int sendTextMessage(const std::string &, const size_t, bool) const 
override { return 0; }
+int sendTextMessage(const char*, const size_t, bool) const override { 
return 0; }
 int sendBinaryMessage(const char *, const size_t , bool ) const override   
  { return 0; }
 void shutdown(bool, const std::string &) override {}
 void getIOStats(uint64_t &, uint64_t &) override {}
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 3a01fea17..43d710ea4 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -519,13 +519,13 @@ public:
 /// Sends a WebSocket Text message.
 int sendMessage(const std::string& msg) const
 {
-return sendTextMessage(msg, msg.size());
+return sendTextMessage(msg.c_str(), msg.size());
 }
 
 /// Implementation of the ProtocolHandlerInterface.
-int sendTextMessage(const std::string , const size_t len, bool flush = 
false) const override
+int sendTextMessage(const char* msg, const size_t len, bool flush = false) 
const override
 {
-return sendMessage(msg.data(), len, WSOpCode::Text, flush);
+return sendMessage(msg, len, WSOpCode::Text, flush);
 }
 
 /// Implementation of the ProtocolHandlerInterface.
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 8b0c883c0..8c229fd18 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1512,7 +1512,7 @@ std::shared_ptr 
DocumentBroker::createNewClientSession(
 {
 const std::string statusReady = "statusindicator: ready";
 LOG_TRC("Sending to Client [" << statusReady << "].");
-ws->sendTextMessage(statusReady, statusReady.size());
+ws->sendTextMessage(statusReady.c_str(), statusReady.size());
 }
 
 // In case of WOPI, if this session is not set as readonly, it might 
be set so
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index a06687788..ecceaca34 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1763,7 +1763,7 @@ static std::shared_ptr
 {
 LOG_WRN("DocBroker with docKey [" << docKey << "] that is marked 
to be destroyed. Rejecting client request.");
 std::string msg("error: cmd=load kind=docunloading");
-proto->sendTextMessage(msg, msg.size());
+proto->sendTextMessage(msg.data(), msg.size());
 proto->shutdown(true, "error: cmd=load kind=docunloading");
 return nullptr;
 }
@@ -1782,7 +1782,7 @@ static std::shared_ptr
 // Indicate to the client that we're connecting to the docbroker.
 const std::string statusConnect = "statusindicator: connect";
 LOG_TRC("Sending to Client [" << statusConnect << "].");
-proto->sendTextMessage(statusConnect, statusConnect.size());
+proto->sendTextMessage(statusConnect.data(), statusConnect.size());
 
 if 

[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp kit/ChildSession.cpp kit/ChildSession.hpp kit/Kit.cpp net/Socket.cpp net/Socket.hpp net/SslSocket.hpp net/WebSocketHandler.hpp t

2020-03-11 Thread Michael Meeks (via logerrit)
 common/Session.cpp  |   50 +++---
 common/Session.hpp  |   38 +++--
 kit/ChildSession.cpp|   14 ++---
 kit/ChildSession.hpp|   22 +---
 kit/Kit.cpp |   12 ++--
 net/Socket.cpp  |8 +-
 net/Socket.hpp  |  109 ++--
 net/SslSocket.hpp   |2 
 net/WebSocketHandler.hpp|   63 +++
 test/UnitWOPIVersionRestore.cpp |1 
 tools/WebSocketDump.cpp |2 
 wsd/ClientSession.cpp   |   44 +++-
 wsd/ClientSession.hpp   |   21 ---
 wsd/DocumentBroker.cpp  |   20 ---
 wsd/DocumentBroker.hpp  |   11 ++--
 wsd/LOOLWSD.cpp |   53 +++
 wsd/TestStubs.cpp   |8 +-
 17 files changed, 332 insertions(+), 146 deletions(-)

New commits:
commit e924625cc1af8736505f363fc525d20a6373bb95
Author: Michael Meeks 
AuthorDate: Fri Mar 6 17:43:46 2020 +
Commit: Michael Meeks 
CommitDate: Wed Mar 11 16:48:03 2020 +0100

re-factor: Socket / WebSocketHandler.

Essentially we want to be able to separate low-level socket code
for eg. TCP vs. UDS, from Protocol handling: eg. WebSocketHandler
and client sessions themselves which handle and send messages
which now implement the simple MessageHandlerInterface.

Some helpful renaming too:

s/SocketHandlerInterface/ProtocolHandlerInterface/

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

diff --git a/common/Session.cpp b/common/Session.cpp
index 4b4c563d6..15dbe86d7 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -44,7 +44,9 @@ using namespace LOOLProtocol;
 using Poco::Exception;
 using std::size_t;
 
-Session::Session(const std::string& name, const std::string& id, bool 
readOnly) :
+Session::Session(const std::shared_ptr ,
+ const std::string& name, const std::string& id, bool 
readOnly) :
+MessageHandlerInterface(protocol),
 _id(id),
 _name(name),
 _disconnected(false),
@@ -65,14 +67,26 @@ Session::~Session()
 
 bool Session::sendTextFrame(const char* buffer, const int length)
 {
+if (!_protocol)
+{
+LOG_TRC("ERR - missing protocol " << getName() << ": Send: [" << 
getAbbreviatedMessage(buffer, length) << "].");
+return false;
+}
+
 LOG_TRC(getName() << ": Send: [" << getAbbreviatedMessage(buffer, length) 
<< "].");
-return sendMessage(buffer, length, WSOpCode::Text) >= length;
+return _protocol->sendTextMessage(buffer, length) >= length;
 }
 
 bool Session::sendBinaryFrame(const char *buffer, int length)
 {
+if (!_protocol)
+{
+LOG_TRC("ERR - missing protocol " << getName() << ": Send: " << 
std::to_string(length) << " binary bytes.");
+return false;
+}
+
 LOG_TRC(getName() << ": Send: " << std::to_string(length) << " binary 
bytes.");
-return sendMessage(buffer, length, WSOpCode::Binary) >= length;
+return _protocol->sendBinaryMessage(buffer, length) >= length;
 }
 
 void Session::parseDocOptions(const StringVector& tokens, int& part, 
std::string& timestamp, std::string& doctemplate)
@@ -196,15 +210,20 @@ void Session::disconnect()
 }
 }
 
-void Session::shutdown(const WebSocketHandler::StatusCodes statusCode, const 
std::string& statusMessage)
+void Session::shutdown(bool goingAway, const std::string& statusMessage)
 {
-LOG_TRC("Shutting down WS [" << getName() << "] with statusCode [" <<
-static_cast(statusCode) << "] and reason [" << 
statusMessage << "].");
+LOG_TRC("Shutting down WS [" << getName() << "] " <<
+(goingAway ? "going" : "normal") <<
+" and reason [" << statusMessage << "].");
 
 // See protocol.txt for this application-level close frame.
-sendMessage("close: " + statusMessage);
-
-WebSocketHandler::shutdown(statusCode, statusMessage);
+if (_protocol)
+{
+// skip the queue; FIXME: should we flush SessionClient's queue ?
+std::string closeMsg = "close: " + statusMessage;
+_protocol->sendTextMessage(closeMsg, closeMsg.size());
+_protocol->shutdown(goingAway, statusMessage);
+}
 }
 
 void Session::handleMessage(const std::vector )
@@ -238,21 +257,12 @@ void Session::handleMessage(const std::vector )
 
 void Session::getIOStats(uint64_t , uint64_t )
 {
-std::shared_ptr socket = getSocket().lock();
-if (socket)
-socket->getIOStats(sent, recv);
-else
-{
-sent = 0;
-recv = 0;
-}
+_protocol->getIOStats(sent, recv);
 }
 
 void Session::dumpState(std::ostream& os)
 {
-WebSocketHandler::dumpState(os);
-
-os <<   "\t\tid: " << _id
+os << "\t\tid: " << _id
<< "\n\t\tname: " << _name

[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp

2020-03-07 Thread Michael Meeks (via logerrit)
 common/Session.cpp |7 ---
 common/Session.hpp |3 ---
 2 files changed, 10 deletions(-)

New commits:
commit 019f268ffd6f87471c52b5d15e040fb7a086c24e
Author: Michael Meeks 
AuthorDate: Thu Mar 5 22:15:13 2020 +
Commit: Michael Meeks 
CommitDate: Sat Mar 7 11:28:08 2020 +0100

handleDisconnect - unused.

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

diff --git a/common/Session.cpp b/common/Session.cpp
index 3e15330e9..4b4c563d6 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -196,13 +196,6 @@ void Session::disconnect()
 }
 }
 
-bool Session::handleDisconnect()
-{
-_disconnected = true;
-shutdown();
-return false;
-}
-
 void Session::shutdown(const WebSocketHandler::StatusCodes statusCode, const 
std::string& statusMessage)
 {
 LOG_TRC("Shutting down WS [" << getName() << "] with statusCode [" <<
diff --git a/common/Session.hpp b/common/Session.hpp
index ec552f9d7..6b5e93322 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -97,9 +97,6 @@ public:
 /// Invoked when we want to disconnect a session.
 virtual void disconnect();
 
-/// Called to handle disconnection command from socket.
-virtual bool handleDisconnect();
-
 /// clean & normal shutdown
 void shutdownNormal(const std::string& statusMessage = "")
 { shutdown(WebSocketHandler::StatusCodes::NORMAL_CLOSE, 
statusMessage); }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp kit/Kit.cpp net/WebSocketHandler.hpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2020-03-05 Thread Michael Meeks (via logerrit)
 common/Session.cpp   |2 +-
 common/Session.hpp   |2 +-
 kit/Kit.cpp  |4 ++--
 net/WebSocketHandler.hpp |   28 
 wsd/DocumentBroker.cpp   |4 ++--
 wsd/LOOLWSD.cpp  |2 +-
 6 files changed, 15 insertions(+), 27 deletions(-)

New commits:
commit f70e627795b09522d61185ac38d6ecdced9aca23
Author: Michael Meeks 
AuthorDate: Thu Mar 5 18:55:00 2020 +
Commit: Michael Meeks 
CommitDate: Thu Mar 5 20:28:48 2020 +0100

WebSocket - simplify handleMessage for now.

WebSocketHandler handles this complexity for us now, and for the
forseeable future. Simplify to prepare for larger re-factor.

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

diff --git a/common/Session.cpp b/common/Session.cpp
index a0cdabe41..3e15330e9 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -214,7 +214,7 @@ void Session::shutdown(const WebSocketHandler::StatusCodes 
statusCode, const std
 WebSocketHandler::shutdown(statusCode, statusMessage);
 }
 
-void Session::handleMessage(bool /*fin*/, WSOpCode /*code*/, std::vector 
)
+void Session::handleMessage(const std::vector )
 {
 try
 {
diff --git a/common/Session.hpp b/common/Session.hpp
index 093234a2d..ec552f9d7 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -92,7 +92,7 @@ public:
 return (buffer != nullptr ? sendTextFrame(buffer, std::strlen(buffer)) 
: false);
 }
 
-virtual void handleMessage(bool fin, WSOpCode code, std::vector 
) override;
+virtual void handleMessage(const std::vector ) override;
 
 /// Invoked when we want to disconnect a session.
 virtual void disconnect();
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 883efa6fc..188e95586 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -1802,7 +1802,7 @@ private:
 vect.assign(data, data + size);
 
 // TODO this is probably wrong...
-session->handleMessage(/* fin = */ false, 
WSOpCode::Binary, vect);
+session->handleMessage(vect);
 return true;
 }
 }
@@ -2093,7 +2093,7 @@ public:
 }
 
 protected:
-void handleMessage(bool /*fin*/, WSOpCode /*code*/, std::vector& 
data) override
+void handleMessage(const std::vector& data) override
 {
 std::string message(data.data(), data.size());
 
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index f18927a22..130f81b69 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -39,7 +39,6 @@ private:
 #if !MOBILEAPP
 bool _isMasking;
 bool _inFragmentBlock;
-bool _isManualDefrag;
 #endif
 
 protected:
@@ -62,7 +61,7 @@ public:
 /// defragmentation should be handled inside message 
handler (true) or the message handler
 /// should be called after all fragments of a message were 
received and the message
 /// was defragmented (false).
-WebSocketHandler(bool isClient = false, bool isMasking = true, bool 
isManualDefrag = false)
+WebSocketHandler(bool isClient = false, bool isMasking = true)
 : _lastPingSentTime(std::chrono::steady_clock::now())
 , _pingTimeUs(0)
 , _shuttingDown(false)
@@ -70,7 +69,6 @@ public:
 #if !MOBILEAPP
 , _isMasking(isClient && isMasking)
 , _inFragmentBlock(false)
-, _isManualDefrag(isManualDefrag)
 #endif
 {
 }
@@ -91,7 +89,6 @@ public:
 #if !MOBILEAPP
 , _isMasking(false)
 , _inFragmentBlock(false)
-, _isManualDefrag(false)
 #endif
 {
 upgradeToWebSocket(request);
@@ -367,27 +364,18 @@ public:
 
 if (fin)
 {
-//If is final fragment then process the accumulated message.
-handleMessage(fin, code, _wsPayload);
+// If is final fragment then process the accumulated message.
+handleMessage(_wsPayload);
 _inFragmentBlock = false;
 }
 else
 {
-if (_isManualDefrag)
-{
-//If the user wants to process defragmentation on its own then 
let him process it.
-handleMessage(fin, code, _wsPayload);
-_inFragmentBlock = true;
-}
-else
-{
-_inFragmentBlock = true;
-//If is not final fragment then wait for next fragment.
-return false;
-}
+_inFragmentBlock = true;
+// If is not final fragment then wait for next fragment.
+return false;
 }
 #else
-handleMessage(true, WSOpCode::Binary, _wsPayload);
+handleMessage(_wsPayload);
 
 #endif
 
@@ -627,7 +615,7 @@ protected:
 }
 
 /// To be overriden to handle the websocket 

[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp kit/Kit.cpp wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2020-01-06 Thread Michael Meeks (via logerrit)
 common/Session.cpp |   17 
 common/Session.hpp |   51 -
 kit/Kit.cpp|   32 +++---
 wsd/ClientSession.cpp  |   20 +--
 wsd/ClientSession.hpp  |2 -
 wsd/DocumentBroker.cpp |5 
 wsd/DocumentBroker.hpp |3 +-
 7 files changed, 72 insertions(+), 58 deletions(-)

New commits:
commit 9cef0f385df831c6958bed475ff7ab4919fcb49a
Author: Michael Meeks 
AuthorDate: Thu Jan 2 21:11:54 2020 +
Commit: Jan Holesovsky 
CommitDate: Mon Jan 6 13:52:29 2020 +0100

watermarking: create SessionMap template to canonicalize views.

Use a fully reliable uniqueness check, rather than a hash, and get
simpler ids as a bonus. Fetch view data from the session itself
rather than passing it in too.

Change-Id: Ibcd625156b5a98eb280e35d6537b5c8c026d0197
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/86150
Reviewed-by: Mert Tümer 
Tested-by: Mert Tümer 

diff --git a/common/Session.cpp b/common/Session.cpp
index 1e4c76573..37f3a5952 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -255,23 +255,6 @@ void Session::getIOStats(uint64_t , uint64_t )
 }
 }
 
-void Session::setHash(const std::string& text)
- {
-unsigned int hash = 0x811C9DC5;
-unsigned int prime = 0x1000193;
-
-if (!text.empty())
-{
-   for (unsigned int i = 0; i < text.length(); ++i)
-   {
-   hash += hash ^ text[i];
-   hash *= prime;
-   }
-}
-_hash = abs(static_cast(hash));
- }
-
-
 void Session::dumpState(std::ostream& os)
 {
 WebSocketHandler::dumpState(os);
diff --git a/common/Session.hpp b/common/Session.hpp
index d06d18a44..6a3f7cfea 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -14,7 +14,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 
 #include 
 #include 
@@ -28,6 +30,39 @@
 #include "TileCache.hpp"
 #include "WebSocketHandler.hpp"
 
+class Session;
+
+template
+class SessionMap : public std::map >
+{
+std::map _canonicalIds;
+public:
+SessionMap() {
+static_assert(std::is_base_of::value, "sessions must have 
base of Session");
+}
+/// Generate a unique key for this set of view properties
+int getCanonicalId(const std::string )
+{
+if (viewProps.empty())
+return 0;
+for (auto  : _canonicalIds) {
+if (it.first == viewProps)
+return it.second;
+}
+size_t id = _canonicalIds.size() + 1;
+_canonicalIds[viewProps] = id;
+return id;
+}
+std::shared_ptr findByCanonicalId(int id)
+{
+for (auto  : *this) {
+if (it.second->getCanonicalViewId() == id)
+return it.second;
+}
+return std::shared_ptr();
+}
+};
+
 /// Base class of a WebSocket session.
 class Session : public WebSocketHandler
 {
@@ -121,11 +156,11 @@ public:
 
 const std::string& getJailedFilePathAnonym() const { return 
_jailedFilePathAnonym; }
 
-int getHash() { return _hash; }
-
-void setHash(const std::string& text);
-
-void setHash(const int hash) { _hash = hash; };
+int  getCanonicalViewId() { return _canonicalViewId; }
+template void recalcCanonicalViewId(SessionMap )
+{
+_canonicalViewId = map.getCanonicalId(_watermarkText);
+}
 
 protected:
 Session(const std::string& name, const std::string& id, bool readonly);
@@ -218,10 +253,8 @@ private:
 /// Language for the document based on what the user has in the UI.
 std::string _lang;
 
-/// Hash for normalizedViewId which is basically an identity for the tile 
to
-/// choose what to render on and send it to its subscribers
-/// it is the close-to-unique integer representation of a string like 
Watermarks etc.
-int _hash;
+/// the canonical id unique to the set of rendering properties of this 
session
+int _canonicalViewId;
 };
 
 #endif
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 4ad74b258..f2930d923 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -948,6 +948,20 @@ public:
 return;
 }
 
+// Find a session matching our view / render settings.
+const auto session = 
_sessions.findByCanonicalId(tileCombined.getNormalizedViewId());
+if (!session)
+{
+LOG_ERR("Session is not found. Maybe exited after rendering 
request.");
+return;
+}
+
+#ifdef FIXME_RENDER_SETTINGS
+// if necessary select a suitable rendering view eg. with 'show 
non-printing chars'
+if (tileCombined.getNormalizedViewId())
+_loKitDocument->setView(session->getViewId());
+#endif
+
 // Render the whole area
 const double area = pixmapWidth * pixmapHeight;
 auto start = std::chrono::system_clock::now();
@@ -972,16 +986,6 @@ public:
 const int pixelWidth = tileCombined.getWidth();
 const int 

[Libreoffice-commits] online.git: common/Session.cpp

2019-11-22 Thread Miklos Vajna (via logerrit)
 common/Session.cpp |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 204cff5c192eeb60205c6c33914ed506c529780a
Author: Miklos Vajna 
AuthorDate: Fri Nov 22 14:11:00 2019 +0100
Commit: Miklos Vajna 
CommitDate: Fri Nov 22 14:11:00 2019 +0100

Avoid UB in Session::setHash()

Ubsan says that signed integer overflow is happening here:

#0 0xec344a in Session::setHash(std::__cxx11::basic_string, std::allocator > const&) common/Session.cpp:267:17
#1 0x918b54 in DocumentBroker::load(std::shared_ptr 
const&, std::__cxx11::basic_string, 
std::allocator > const&) wsd/DocumentBroker.cpp:682:18
...
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
common/Session.cpp:267:17 in

(While running unit_wopi_watermark.)

Change-Id: Idcb1692f6d5d0df8be35dc557d2d72a345acbcf4

diff --git a/common/Session.cpp b/common/Session.cpp
index 9495cc99a..1e4c76573 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -257,8 +257,8 @@ void Session::getIOStats(uint64_t , uint64_t )
 
 void Session::setHash(const std::string& text)
  {
-int hash = 0x811C9DC5;
-int prime = 0x1000193;
+unsigned int hash = 0x811C9DC5;
+unsigned int prime = 0x1000193;
 
 if (!text.empty())
 {
@@ -268,7 +268,7 @@ void Session::setHash(const std::string& text)
hash *= prime;
}
 }
-_hash = abs(hash);
+_hash = abs(static_cast(hash));
  }
 
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: common/Session.cpp net/WebSocketHandler.hpp wsd/ClientSession.cpp wsd/LOOLWSD.cpp

2018-10-24 Thread Libreoffice Gerrit user
 common/Session.cpp   |2 +-
 net/WebSocketHandler.hpp |   13 -
 wsd/ClientSession.cpp|2 +-
 wsd/LOOLWSD.cpp  |8 
 4 files changed, 18 insertions(+), 7 deletions(-)

New commits:
commit 22fac18fcd17c1cf927da50690cd188b01a245e2
Author: Miklos Vajna 
AuthorDate: Wed Oct 24 09:35:46 2018 +0200
Commit: Miklos Vajna 
CommitDate: Wed Oct 24 09:36:13 2018 +0200

WebSocket: make members private

All of them were protected, but only _socket was used actually. Add a
protected setter/getter for that field.

diff --git a/common/Session.cpp b/common/Session.cpp
index 34c608924..1c37e5ba2 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -234,7 +234,7 @@ void Session::handleMessage(bool /*fin*/, WSOpCode 
/*code*/, std::vector &
 
 void Session::getIOStats(uint64_t , uint64_t )
 {
-std::shared_ptr socket = _socket.lock();
+std::shared_ptr socket = getSocket().lock();
 if (socket)
 socket->getIOStats(sent, recv);
 else
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index f9abbae42..fcb9d3660 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -26,7 +26,7 @@
 
 class WebSocketHandler : public SocketHandlerInterface
 {
-protected:
+private:
 /// The socket that owns us (we can't own it).
 std::weak_ptr _socket;
 
@@ -38,6 +38,7 @@ protected:
 bool _isClient;
 bool _isMasking;
 
+protected:
 struct WSFrameMask
 {
 static const unsigned char Fin = 0x80;
@@ -517,6 +518,16 @@ protected:
 {
 }
 
+std::weak_ptr& getSocket()
+{
+return _socket;
+}
+
+void setSocket(const std::weak_ptr& socket)
+{
+_socket = socket;
+}
+
 void dumpState(std::ostream& os) override;
 
 private:
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index a764a951e..762b5a907 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1206,7 +1206,7 @@ void ClientSession::dumpState(std::ostream& os)
<< "\n\t\tisAttached: " << _isAttached
<< "\n\t\tkeyEvents: " << _keyEvents;
 
-std::shared_ptr socket = _socket.lock();
+std::shared_ptr socket = getSocket().lock();
 if (socket)
 {
 uint64_t sent, recv;
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index c2d47ebb1..95d362547 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1743,13 +1743,13 @@ private:
 /// Keep our socket around ...
 void onConnect(const std::shared_ptr& socket) override
 {
-_socket = socket;
+setSocket(socket);
 LOG_TRC("#" << socket->getFD() << " Prisoner connected.");
 }
 
 void onDisconnect() override
 {
-std::shared_ptr socket = _socket.lock();
+std::shared_ptr socket = getSocket().lock();
 if (socket)
 LOG_TRC("#" << socket->getFD() << " Prisoner connection 
disconnected.");
 else
@@ -1782,7 +1782,7 @@ private:
 return;
 }
 
-std::shared_ptr socket = _socket.lock();
+std::shared_ptr socket = getSocket().lock();
 
 Poco::MemoryInputStream message(>_inBuffer[0],
 socket->_inBuffer.size());;
@@ -1873,7 +1873,7 @@ private:
 return;
 
 const std::string abbr = getAbbreviatedMessage(data);
-std::shared_ptr socket = _socket.lock();
+std::shared_ptr socket = getSocket().lock();
 if (socket)
 LOG_TRC("#" << socket->getFD() << " Prisoner message [" << abbr << 
"].");
 else
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp

2018-01-15 Thread Tor Lillqvist
 common/Session.cpp |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

New commits:
commit e834526983521fc503fe259533fde8be531f59bd
Author: Tor Lillqvist 
Date:   Mon Jan 15 14:21:49 2018 +0200

Add FIXME

diff --git a/common/Session.cpp b/common/Session.cpp
index 6070955c..0a9f9c3a 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -86,7 +86,9 @@ void Session::parseDocOptions(const std::vector& 
tokens, int& part,
 
 for (size_t i = offset; i < tokens.size(); ++i)
 {
-// FIXME use any kind of startsWith() instead of find(...) == 0
+// FIXME use Util::startsWith() instead of all these find(...) == 0
+// FIXME or use the getToken* functions, isn't this exactly what they 
are for?
+
 if (tokens[i].find("url=") == 0)
 {
 _docURL = tokens[i].substr(strlen("url="));
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp kit/ChildSession.cpp kit/ChildSession.hpp kit/Kit.cpp test/WhiteBoxTests.cpp wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/Doc

2017-09-07 Thread Marco Cecchetti
 common/Session.cpp |6 ++
 common/Session.hpp |3 +
 kit/ChildSession.cpp   |6 +-
 kit/ChildSession.hpp   |4 +
 kit/Kit.cpp|  143 +++--
 test/WhiteBoxTests.cpp |3 -
 wsd/ClientSession.cpp  |7 ++
 wsd/ClientSession.hpp  |1 
 wsd/DocumentBroker.cpp |3 +
 wsd/Storage.cpp|4 +
 wsd/Storage.hpp|4 +
 wsd/reference.txt  |4 +
 12 files changed, 180 insertions(+), 8 deletions(-)

New commits:
commit dee39a562c6fd8f1eed3567e7f9e518f1d599bd7
Author: Marco Cecchetti 
Date:   Mon Sep 4 15:40:04 2017 +0200

support for rendering a watermark on each tile

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

diff --git a/common/Session.cpp b/common/Session.cpp
index 97933c83..c58eb3f0 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -136,6 +136,12 @@ void Session::parseDocOptions(const 
std::vector& tokens, int& part,
 _lang = tokens[i].substr(strlen("lang="));
 ++offset;
 }
+else if (tokens[i].find("watermarkText=") == 0)
+{
+const std::string watermarkText = 
tokens[i].substr(strlen("watermarkText="));
+Poco::URI::decode(watermarkText, _watermarkText);
+++offset;
+}
 }
 
 if (tokens.size() > offset)
diff --git a/common/Session.hpp b/common/Session.hpp
index 5a154ee1..99961848 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -157,6 +157,9 @@ protected:
 /// Extra info per user, mostly mail, avatar, links, etc.
 std::string _userExtraInfo;
 
+/// In case a watermark has to be rendered on each tile.
+std::string _watermarkText;
+
 /// Language for the document based on what the user has in the UI.
 std::string _lang;
 };
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 553f6dbf..56075790 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -329,7 +329,8 @@ bool ChildSession::loadDocument(const char * /*buffer*/, 
int /*length*/, const s
 
 std::unique_lock lock(Mutex);
 
-bool loaded = _docManager.onLoad(getId(), _jailedFilePath, _userName, 
_docPassword, renderOpts, _haveDocPassword, _lang);
+bool loaded = _docManager.onLoad(getId(), _jailedFilePath, _userName,
+_docPassword, renderOpts, _haveDocPassword, _lang, _watermarkText);
 if (!loaded || _viewId < 0)
 {
 LOG_ERR("Failed to get LoKitDocument instance.");
@@ -400,7 +401,8 @@ bool ChildSession::sendFontRendering(const char* 
/*buffer*/, int /*length*/, con
 std::memcpy(output.data(), response.data(), response.size());
 
 Timestamp timestamp;
-int width, height;
+// renderFont use a default font size (25) when width and height are 0
+int width = 0, height = 0;
 unsigned char* ptrFont = nullptr;
 
 {
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index 446ffca4..c3af96ec 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -37,7 +37,8 @@ public:
 const std::string& docPassword,
 const std::string& renderOpts,
 const bool haveDocPassword,
-const std::string& lang) = 0;
+const std::string& lang,
+const std::string& watermarkText) = 0;
 
 /// Unload a client session, which unloads the document
 /// if it is the last and only.
@@ -143,6 +144,7 @@ public:
 const std::string& getViewUserId() const { return _userId; }
 const std::string& getViewUserName() const { return _userName; }
 const std::string& getViewUserExtraInfo() const { return _userExtraInfo; }
+const std::string& getWatermarkText() const { return _watermarkText; }
 void updateSpeed();
 int getSpeed();
 
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index a5a2be25..63ebdbe1 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -479,6 +479,119 @@ public:
 }
 };
 
+class Watermark
+{
+public:
+Watermark(std::shared_ptr loKitDoc, std::string text)
+: _loKitDoc(loKitDoc)
+, _text(text)
+, _font("Liberation Sans")
+, _width(0)
+, _height(0)
+, _color{64, 64, 64}
+, _alphaLevel(0.2)
+, _pixmap(nullptr)
+{
+}
+
+~Watermark()
+{
+if (_pixmap)
+std::free(_pixmap);
+}
+
+void blending(unsigned char* tilePixmap,
+   int offsetX, int offsetY,
+   int tilesPixmapWidth, int tilesPixmapHeight,
+   int tileWidth, int tileHeight,
+   LibreOfficeKitTileMode mode)
+{
+// set requested watermark size a little bit smaller than tile size
+int width = tileWidth * 0.9;
+int height = tileHeight * 

[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-06-02 Thread Michael Meeks
 common/Session.cpp |   12 
 common/Session.hpp |2 ++
 net/Socket.hpp |   16 
 wsd/DocumentBroker.cpp |   19 +++
 wsd/DocumentBroker.hpp |2 ++
 5 files changed, 43 insertions(+), 8 deletions(-)

New commits:
commit 3101fa510d4f86301d81ae76a64b7c780ae69e19
Author: Michael Meeks 
Date:   Thu Jun 1 03:40:01 2017 +0100

Accumulate I/O stats per document.

Change-Id: Ie2f5647e65070ddd828f048820efd38b600f9133

diff --git a/common/Session.cpp b/common/Session.cpp
index 44293a18..97933c83 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -203,6 +203,18 @@ void Session::handleMessage(bool /*fin*/, WSOpCode 
/*code*/, std::vector &
 }
 }
 
+void Session::getIOStats(uint64_t , uint64_t )
+{
+auto socket = _socket.lock();
+if (socket)
+socket->getIOStats(sent, recv);
+else
+{
+sent = 0;
+recv = 0;
+}
+}
+
 void Session::dumpState(std::ostream& os)
 {
 WebSocketHandler::dumpState(os);
diff --git a/common/Session.hpp b/common/Session.hpp
index 63872c08..5a154ee1 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -82,6 +82,8 @@ public:
 void closeFrame() { _isCloseFrame = true; };
 bool isCloseFrame() const { return _isCloseFrame; }
 
+void getIOStats(uint64_t , uint64_t );
+
 protected:
 Session(const std::string& name, const std::string& id, bool readonly);
 virtual ~Session();
diff --git a/net/Socket.hpp b/net/Socket.hpp
index a7cc426d..4c410d23 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -818,6 +818,12 @@ public:
 return socket;
 }
 
+void getIOStats(uint64_t , uint64_t )
+{
+sent = _bytesSent;
+recv = _bytesRecvd;
+}
+
 protected:
 
 /// Called when a polling event is received.
@@ -947,12 +953,6 @@ protected:
 
 void dumpState(std::ostream& os) override;
 
-void getStats(uint64_t , uint64_t )
-{
-sent = _bytesSent;
-recv = _bytesRecvd;
-}
-
 protected:
 /// Client handling the actual data.
 std::shared_ptr _socketHandler;
@@ -966,8 +966,8 @@ protected:
 std::vector< char > _inBuffer;
 std::vector< char > _outBuffer;
 
-std::atomic _bytesSent;
-std::atomic _bytesRecvd;
+uint64_t _bytesSent;
+uint64_t _bytesRecvd;
 
 // To be able to access _inBuffer and _outBuffer.
 // TODO we probably need accessors to the _inBuffer & _outBuffer
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index d92df509..ac7db55f 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1430,10 +1430,27 @@ void DocumentBroker::updateLastActivityTime()
 Admin::instance().updateLastActivityTime(_docKey);
 }
 
+void DocumentBroker::getIOStats(uint64_t , uint64_t )
+{
+sent = 0;
+recv = 0;
+assertCorrectThread();
+for (const auto& sessionIt : _sessions)
+{
+uint64_t s, r;
+sessionIt.second->getIOStats(s, r);
+sent += s;
+recv += r;
+}
+}
+
 void DocumentBroker::dumpState(std::ostream& os)
 {
 std::unique_lock lock(_mutex);
 
+uint64_t sent, recv;
+getIOStats(sent, recv);
+
 os << " Broker: " << _filename << " pid: " << getPid();
 if (_markToDestroy)
 os << " *** Marked to destroy ***";
@@ -1443,6 +1460,8 @@ void DocumentBroker::dumpState(std::ostream& os)
 os << "\n  loaded in: " << _loadDuration.count() << "ms";
 else
 os << "\n  still loading...";
+os << "\n  sent: " << sent;
+os << "\n  recv?: " << recv;
 os << "\n  modified?: " << _isModified;
 os << "\n  jail id: " << _jailId;
 os << "\n  filename: " << _filename;
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 1329fcb1..2c244fe1 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -367,6 +367,8 @@ private:
 /// associated with this document.
 void pollThread();
 
+void getIOStats(uint64_t , uint64_t );
+
 private:
 const std::string _uriOrig;
 const Poco::URI _uriPublic;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp common/Util.cpp common/Util.hpp kit/ChildSession.cpp kit/ChildSession.hpp kit/Kit.cpp kit/Kit.hpp loleaflet/src wsd/ClientSessio

2017-05-28 Thread Ashod Nakashian
 common/Session.cpp|   10 --
 common/Session.hpp|3 +++
 common/Util.cpp   |   23 ++-
 common/Util.hpp   |3 +++
 kit/ChildSession.cpp  |2 +-
 kit/ChildSession.hpp  |1 +
 kit/Kit.cpp   |   11 +++
 kit/Kit.hpp   |   28 +---
 loleaflet/src/map/Map.js  |2 +-
 loleaflet/src/map/handler/Map.WOPI.js |1 +
 wsd/ClientSession.cpp |   11 +--
 wsd/ClientSession.hpp |1 +
 wsd/DocumentBroker.cpp|3 +++
 wsd/Storage.cpp   |4 +++-
 wsd/Storage.hpp   |4 
 15 files changed, 92 insertions(+), 15 deletions(-)

New commits:
commit da2d3cbc92bf76f0d29b67eab493f2f350d1b63c
Author: Ashod Nakashian 
Date:   Sun May 28 12:20:49 2017 -0400

wsd: support per-user links and commands

userextrainfo is a json array that contains
extra user-specific links.

Currently 'avatar' is assumed to hold the
image url for the user's avatar.

'mail' and other links can also be added.

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

diff --git a/common/Session.cpp b/common/Session.cpp
index d29613db..44293a18 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -99,16 +99,22 @@ void Session::parseDocOptions(const 
std::vector& tokens, int& part,
 }
 else if (tokens[i].find("authorid=") == 0)
 {
-std::string userId = tokens[i].substr(strlen("authorid="));
+const std::string userId = tokens[i].substr(strlen("authorid="));
 Poco::URI::decode(userId, _userId);
 ++offset;
 }
 else if (tokens[i].find("author=") == 0)
 {
-std::string userName = tokens[i].substr(strlen("author="));
+const std::string userName = tokens[i].substr(strlen("author="));
 Poco::URI::decode(userName, _userName);
 ++offset;
 }
+else if (tokens[i].find("authorextrainfo=") == 0)
+{
+const std::string userExtraInfo= 
tokens[i].substr(strlen("authorextrainfo="));
+Poco::URI::decode(userExtraInfo, _userExtraInfo);
+++offset;
+}
 else if (tokens[i].find("readonly=") == 0)
 {
 _isReadOnly = tokens[i].substr(strlen("readonly=")) != "0";
diff --git a/common/Session.hpp b/common/Session.hpp
index b67466e3..63872c08 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -152,6 +152,9 @@ protected:
 /// Name of the user to whom the session belongs to
 std::string _userName;
 
+/// Extra info per user, mostly mail, avatar, links, etc.
+std::string _userExtraInfo;
+
 /// Language for the document based on what the user has in the UI.
 std::string _lang;
 };
diff --git a/common/Util.cpp b/common/Util.cpp
index 66d917d8..a94457e8 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -39,6 +39,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -340,7 +343,25 @@ namespace Util
 std::string UniqueId()
 {
 static std::atomic_int counter(0);
-return std::to_string(Poco::Process::id()) + "/" + 
std::to_string(counter++);
+return std::to_string(Poco::Process::id()) + '/' + 
std::to_string(counter++);
+}
+
+std::map JsonToMap(const std::string& jsonString)
+{
+Poco::JSON::Parser parser;
+const auto result = parser.parse(jsonString);
+const auto& json = result.extract();
+
+std::vector names;
+json->getNames(names);
+
+std::map map;
+for (const auto& name : names)
+{
+map[name] = json->get(name).toString();
+}
+
+return map;
 }
 }
 
diff --git a/common/Util.hpp b/common/Util.hpp
index 8c720774..0fbf794d 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -121,6 +121,9 @@ namespace Util
 /// Return a string that is unique across processes and calls.
 std::string UniqueId();
 
+// Extract all json entries into a map.
+std::map JsonToMap(const std::string& 
jsonString);
+
 /// Trim spaces from the left. Just spaces.
 inline std::string& ltrim(std::string& s)
 {
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 2ed065ab..d9b670ac 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -489,7 +489,7 @@ void insertUserNames(const std::map& 
viewInfo, std::string& json)
 int viewId = 

[Libreoffice-commits] online.git: common/Session.cpp loleaflet/src wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-05-21 Thread Ashod Nakashian
 common/Session.cpp   |3 -
 loleaflet/src/core/Socket.js |9 +---
 wsd/DocumentBroker.cpp   |   88 ++-
 wsd/DocumentBroker.hpp   |4 +
 4 files changed, 46 insertions(+), 58 deletions(-)

New commits:
commit 407c538f046f9245661a77e2452779c465b75087
Author: Ashod Nakashian 
Date:   Sun May 21 19:13:55 2017 -0400

Correctly send termination reason to clients

Fixes the case when the client reconnects on idle
disconnection (because it never got the 'close: idle'
message).

Also, show informative message to users in this case
instead of grey screen.

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

diff --git a/common/Session.cpp b/common/Session.cpp
index d8756689..d29613db 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -164,8 +164,7 @@ void Session::shutdown(const WebSocketHandler::StatusCodes 
statusCode, const std
 static_cast(statusCode) << "] and reason [" << 
statusMessage << "].");
 
 // See protocol.txt for this application-level close frame.
-const std::string msg = "close: " + statusMessage;
-sendTextFrame(msg.data(), msg.size());
+sendMessage("close: " + statusMessage);
 
 WebSocketHandler::shutdown(statusCode, statusMessage);
 }
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 1047c4b7..4db52fef 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -228,6 +228,9 @@ L.Socket = L.Class.extend({
if (textMsg === 'ownertermination') {
msg = _('Session terminated by document owner');
}
+   else if (textMsg === 'idle') {
+   msg = _('Session terminated due to idleness');
+   }
else if (textMsg === 'shuttingdown') {
msg = _('Server is shutting down for 
maintenance (auto-saving)');
}
@@ -301,11 +304,7 @@ L.Socket = L.Class.extend({
this._map.fire('postMessage', {msgId: 
'Session_Closed'});
}
 
-   if (textMsg === 'idle') {
-   this._map._active = false;
-   }
-
-   if (textMsg === 'ownertermination') {
+   if (textMsg === 'idle' || textMsg === 
'ownertermination') {
this._map.remove();
}
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 956a2fe6..7d807acb 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -224,6 +224,7 @@ void DocumentBroker::pollThread()
 static const bool AutoSaveEnabled = !std::getenv("LOOL_NO_AUTOSAVE");
 static const size_t IdleDocTimeoutSecs = LOOLWSD::getConfigValue(
   
"per_document.idle_timeout_secs", 3600);
+std::string closeReason = "stopped";
 
 // Main polling loop goodness.
 while (!_stop && _poll->continuePolling() && !TerminationFlag)
@@ -241,30 +242,8 @@ void DocumentBroker::pollThread()
 
 if (ShutdownRequestFlag)
 {
-// Shutting down the server: notify clients, save, and stop.
-static const std::string msg("close: recycling");
-
-// First copy into local container, since removeSession
-// will erase from _sessions, but will leave the last.
-std::map sessions = 
_sessions;
-for (const auto& pair : sessions)
-{
-std::shared_ptr session = pair.second;
-try
-{
-// Notify the client and disconnect.
-session->sendMessage(msg);
-
session->shutdown(WebSocketHandler::StatusCodes::ENDPOINT_GOING_AWAY, 
"recycling");
-
-// Remove session, save, and mark to destroy.
-removeSession(session->getId(), true);
-}
-catch (const std::exception& exc)
-{
-LOG_WRN("Error while shutting down client [" <<
-session->getName() << "]: " << exc.what());
-}
-}
+closeReason = "recycling";
+shutdownClients(closeReason);
 }
 else if (AutoSaveEnabled && !_stop &&
  std::chrono::duration_cast(now - 
last30SecCheckTime).count() >= 30)
@@ -282,6 +261,7 @@ void DocumentBroker::pollThread()
 {
 LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
 " DocumentBroker for 

[Libreoffice-commits] online.git: common/Session.cpp wsd/Exceptions.hpp

2017-05-14 Thread Ashod Nakashian
 common/Session.cpp |4 ++--
 wsd/Exceptions.hpp |2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 47c01440ba794d2ea953d6ac1b80f7e42769f4e6
Author: Ashod Nakashian 
Date:   Sun May 14 22:59:58 2017 -0400

wsd: logs

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

diff --git a/common/Session.cpp b/common/Session.cpp
index 69696fb3..d8756689 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -64,13 +64,13 @@ Session::~Session()
 
 bool Session::sendTextFrame(const char* buffer, const int length)
 {
-LOG_TRC(getName() << ": Send: " << getAbbreviatedMessage(buffer, length));
+LOG_TRC(getName() << ": Send: [" << getAbbreviatedMessage(buffer, length) 
<< "].");
 return sendMessage(buffer, length, WSOpCode::Text) >= length;
 }
 
 bool Session::sendBinaryFrame(const char *buffer, int length)
 {
-LOG_TRC(getName() << ": Send: " << std::to_string(length) << " bytes.");
+LOG_TRC(getName() << ": Send: " << std::to_string(length) << " binary 
bytes.");
 return sendMessage(buffer, length, WSOpCode::Binary) >= length;
 }
 
diff --git a/wsd/Exceptions.hpp b/wsd/Exceptions.hpp
index 11c9de59..2c4905a6 100644
--- a/wsd/Exceptions.hpp
+++ b/wsd/Exceptions.hpp
@@ -50,7 +50,7 @@ public:
 using BadRequestException::BadRequestException;
 };
 
-/// An authorization exception that is means to signify,
+/// An authorization exception that is meant to signify,
 /// and translate into, an HTTP unauthorized error.
 class UnauthorizedRequestException : public LoolException
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp kit/ChildSession.cpp kit/ChildSession.hpp kit/Kit.cpp loleaflet/src test/WhiteBoxTests.cpp wsd/ClientSession.cpp wsd/protocol.tx

2017-03-24 Thread Jan Holesovsky
 common/Session.cpp   |6 ++
 common/Session.hpp   |   13 -
 kit/ChildSession.cpp |2 +-
 kit/ChildSession.hpp |3 ++-
 kit/Kit.cpp  |   16 +++-
 loleaflet/src/core/Socket.js |3 +++
 test/WhiteBoxTests.cpp   |3 ++-
 wsd/ClientSession.cpp|5 +
 wsd/protocol.txt |5 -
 9 files changed, 42 insertions(+), 14 deletions(-)

New commits:
commit 9f17050a7d4e1b5124a108dce3cce7001bf3deeb
Author: Jan Holesovsky 
Date:   Fri Mar 24 12:34:32 2017 +0100

Pass the locale settings from loleaflet to wsd/kit.

Change-Id: Ie530db73cfbdb62787f16eae0f4b07fbf8b8acb4

diff --git a/common/Session.cpp b/common/Session.cpp
index 78161f11..4c5c40cb 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -87,6 +87,7 @@ void Session::parseDocOptions(const std::vector& 
tokens, int& part,
 
 for (size_t i = offset; i < tokens.size(); ++i)
 {
+// FIXME use any kind of startsWith() instead of find(...) == 0
 if (tokens[i].find("url=") == 0)
 {
 _docURL = tokens[i].substr(strlen("url="));
@@ -120,6 +121,11 @@ void Session::parseDocOptions(const 
std::vector& tokens, int& part,
 _haveDocPassword = true;
 ++offset;
 }
+else if (tokens[i].find("lang=") == 0)
+{
+_lang = tokens[i].substr(strlen("lang="));
+++offset;
+}
 }
 
 if (tokens.size() > offset)
diff --git a/common/Session.hpp b/common/Session.hpp
index d12a7042..c8f2e63b 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -116,19 +116,19 @@ private:
 std::mutex _mutex;
 
 protected:
-// The actual URL, also in the child, even if the child never accesses 
that.
+/// The actual URL, also in the child, even if the child never accesses 
that.
 std::string _docURL;
 
-// The Jailed document path.
+/// The Jailed document path.
 std::string _jailedFilePath;
 
-// Password provided, if any, to open the document
+/// Password provided, if any, to open the document
 std::string _docPassword;
 
-// If password is provided or not
+/// If password is provided or not
 bool _haveDocPassword;
 
-// Whether document is password protected
+/// Whether document is password protected
 bool _isDocPasswordProtected;
 
 /// Document options: a JSON string, containing options (rendering, also 
possibly load in the future).
@@ -139,6 +139,9 @@ protected:
 
 /// Name of the user to whom the session belongs to
 std::string _userName;
+
+/// Language for the document based on what the user has in the UI.
+std::string _lang;
 };
 
 #endif
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index de84a398..f62fe306 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -326,7 +326,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, 
int /*length*/, const s
 
 std::unique_lock lock(Mutex);
 
-bool loaded = _docManager.onLoad(getId(), _jailedFilePath, _userName, 
_docPassword, renderOpts, _haveDocPassword);
+bool loaded = _docManager.onLoad(getId(), _jailedFilePath, _userName, 
_docPassword, renderOpts, _haveDocPassword, _lang);
 if (!loaded || _viewId < 0)
 {
 LOG_ERR("Failed to get LoKitDocument instance.");
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index da609b58..ce47ed4c 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -35,7 +35,8 @@ public:
 const std::string& userName,
 const std::string& docPassword,
 const std::string& renderOpts,
-const bool haveDocPassword) = 0;
+const bool haveDocPassword,
+const std::string& lang) = 0;
 
 /// Unload a client session, which unloads the document
 /// if it is the last and only.
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 9886a8c5..58f79b28 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -907,7 +907,8 @@ private:
 const std::string& userName,
 const std::string& docPassword,
 const std::string& renderOpts,
-const bool haveDocPassword) override
+const bool haveDocPassword,
+const std::string& lang) override
 {
 std::unique_lock lock(_mutex);
 
@@ -936,7 +937,7 @@ private:
 
 try
 {
-if (!load(session, uri, userName, docPassword, renderOpts, 
haveDocPassword))
+if (!load(session, uri, userName, docPassword, renderOpts, 
haveDocPassword, lang))
 {
 return false;
 }
@@ -1126,7 +1127,8 @@ private:
 const std::string& userName,
 const std::string& docPassword,
 

[Libreoffice-commits] online.git: common/Session.cpp

2017-02-07 Thread Miklos Vajna
 common/Session.cpp |1 -
 1 file changed, 1 deletion(-)

New commits:
commit 98b02fb9c40796b7b5c24f1d2291462c930f8649
Author: Miklos Vajna 
Date:   Tue Feb 7 09:08:25 2017 +0100

common: unused using declaration in Session

Change-Id: I0122b6ad6f5d0e47a2b3c153cdd5e65a7adc6040

diff --git a/common/Session.cpp b/common/Session.cpp
index 6c24684..e30dce1 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -46,7 +46,6 @@ using namespace LOOLProtocol;
 using Poco::Exception;
 using Poco::Net::Socket;
 using Poco::Net::WebSocket;
-using Poco::StringTokenizer;
 
 Session::Session(const std::string& name, const std::string& id, const 
std::shared_ptr& ws) :
 _id(id),
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp

2017-01-17 Thread Miklos Vajna
 common/Session.cpp |1 -
 1 file changed, 1 deletion(-)

New commits:
commit 4b980530e58e76ba653b4bf855d3af73d35f604d
Author: Miklos Vajna 
Date:   Tue Jan 17 09:58:40 2017 +0100

common: remove unused using declaration

Change-Id: I51d4d1f555ed5508370e4b9a7b8f04f266a2ca4a

diff --git a/common/Session.cpp b/common/Session.cpp
index 75b5e4b..03df779 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -44,7 +44,6 @@
 using namespace LOOLProtocol;
 
 using Poco::Exception;
-using Poco::IOException;
 using Poco::Net::Socket;
 using Poco::Net::WebSocket;
 using Poco::StringTokenizer;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp kit/ChildSession.cpp wsd/ClientSession.cpp

2016-12-31 Thread Ashod Nakashian
 common/Session.cpp|2 --
 kit/ChildSession.cpp  |1 +
 wsd/ClientSession.cpp |2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

New commits:
commit 3a5be2926bafb0f433fd9059c2b75a1bd623ffc0
Author: Ashod Nakashian 
Date:   Wed Dec 21 18:21:48 2016 -0500

wsd: log WS incoming messages only once

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

diff --git a/common/Session.cpp b/common/Session.cpp
index afebb3b..c409a57 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -228,8 +228,6 @@ bool Session::handleInput(const char *buffer, int length)
 length = replace->size();
 }
 
-LOG_TRC(getName() << ": Recv: " << getAbbreviatedMessage(buffer, 
length));
-
 return _handleInput(buffer, length);
 }
 catch (const Exception& exc)
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index cd1f404..90d6367 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -74,6 +74,7 @@ void ChildSession::disconnect()
 
 bool ChildSession::_handleInput(const char *buffer, 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);
 
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index faa0ba4..f26fff3 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -77,9 +77,9 @@ void ClientSession::bridgePrisonerSession()
 
 bool ClientSession::_handleInput(const char *buffer, 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);
-Log::trace(getName() + ": handling [" + firstLine + "].");
 
 auto docBroker = getDocumentBroker();
 if (!docBroker)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp kit/ChildSession.cpp kit/ChildSession.hpp wsd/ClientSession.cpp wsd/PrisonerSession.cpp wsd/TileCache.cpp

2016-12-12 Thread Ashod Nakashian
 common/Session.cpp  |   10 +++---
 common/Session.hpp  |   39 +--
 kit/ChildSession.cpp|2 +-
 kit/ChildSession.hpp|8 ++--
 wsd/ClientSession.cpp   |2 +-
 wsd/PrisonerSession.cpp |2 +-
 wsd/TileCache.cpp   |4 +---
 7 files changed, 10 insertions(+), 57 deletions(-)

New commits:
commit 477ca6f414090941d66392d0b3081eb2d8b1f6c2
Author: Ashod Nakashian 
Date:   Mon Dec 12 20:18:25 2016 -0500

loolwsd: cleanup the Sessions

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

diff --git a/common/Session.cpp b/common/Session.cpp
index f2c68ec..0e51de5 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -49,14 +49,10 @@ using Poco::Net::Socket;
 using Poco::Net::WebSocket;
 using Poco::StringTokenizer;
 
-Session::Session(const std::string& id, const Kind kind,
- std::shared_ptr ws) :
+Session::Session(const std::string& name, const std::string& id, const 
std::shared_ptr& ws) :
 _id(id),
-_kind(kind),
-_kindString(kind == Kind::ToClient ? "ToClient" :
-kind == Kind::ToMaster ? "ToMaster" : "ToPrisoner"),
-_name(_kindString + '-' + id),
-_ws(std::move(ws)),
+_name(name),
+_ws(ws),
 _disconnected(false),
 _isActive(true),
 _lastActivityTime(std::chrono::steady_clock::now()),
diff --git a/common/Session.hpp b/common/Session.hpp
index 617348a..8277c5e 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -32,17 +32,6 @@
 class Session
 {
 public:
-/// We have three kinds of Websocket sessions
-/// 1) Between the master loolwsd server to the end-user LOOL client
-/// 2) Between the master loolwsd server and a jailed child process, in 
the master process
-/// 3) Ditto, in the jailed process
-enum class Kind
-{
-ToClient,
-ToPrisoner,
-ToMaster
-};
-
 const std::string& getId() const { return _id; }
 const std::string& getName() const { return _name; }
 bool isDisconnected() const { return _disconnected; }
@@ -77,13 +66,10 @@ public:
 void closeFrame() { _isCloseFrame = true; };
 bool isCloseFrame() const { return _isCloseFrame; }
 
-Kind getKind() const { return _kind; }
-
 bool isHeadless() const { return _ws == nullptr; }
 
 protected:
-Session(const std::string& id, const Kind kind,
-std::shared_ptr ws);
+Session(const std::string& name, const std::string& id, const 
std::shared_ptr& ws);
 virtual ~Session();
 
 /// Parses the options of the "load" command, shared between 
MasterProcessSession::loadDocument() and ChildProcessSession::loadDocument().
@@ -107,12 +93,6 @@ private:
 /// A session ID specific to an end-to-end connection (from user to lokit).
 const std::string _id;
 
-// Our kind signifies to what we are connected to.
-const Kind _kind;
-
-// The kind cached as a string.
-const std::string _kindString;
-
 /// A readable name that identifies our peer and ID.
 const std::string _name;
 
@@ -158,23 +138,6 @@ protected:
 std::string _userName;
 };
 
-template 
-inline std::basic_ostream& operator<<(std::basic_ostream& stream, Session::Kind kind)
-{
-switch (kind)
-{
-case Session::Kind::ToClient:
-return stream << "TO_CLIENT";
-case Session::Kind::ToPrisoner:
-return stream << "TO_PRISONER";
-case Session::Kind::ToMaster:
-return stream << "TO_MASTER";
-default:
-assert(false);
-return stream << "UNK_" + std::to_string(static_cast(kind));
-}
-}
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 9df2b56..cd1f404 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -37,7 +37,7 @@ std::recursive_mutex ChildSession::Mutex;
 ChildSession::ChildSession(const std::string& id,
const std::string& jailId,
IDocumentManager& docManager) :
-Session(id, Kind::ToMaster, nullptr),
+Session("ToMaster-" + id, id, nullptr),
 _jailId(jailId),
 _docManager(docManager),
 _viewId(-1),
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index 19005ac..c41426a 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -35,8 +35,7 @@ public:
 const std::string& userName,
 const std::string& docPassword,
 const std::string& renderOpts,
-const bool haveDocPassword)
-= 0;
+const bool haveDocPassword) = 0;
 
 /// Unload a client session, which unloads the document
 /// if it is the last and only.
@@ -94,10 

[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp common/Unit.hpp kit/ChildSession.cpp kit/ChildSession.hpp test/UnitFuzz.cpp wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/Pris

2016-12-12 Thread Ashod Nakashian
 common/Session.cpp  |   30 +++---
 common/Session.hpp  |   18 +-
 common/Unit.hpp |4 ++--
 kit/ChildSession.cpp|4 ++--
 kit/ChildSession.hpp|2 +-
 test/UnitFuzz.cpp   |2 +-
 wsd/ClientSession.cpp   |2 +-
 wsd/ClientSession.hpp   |2 +-
 wsd/PrisonerSession.cpp |2 +-
 wsd/PrisonerSession.hpp |3 ++-
 wsd/QueueHandler.hpp|4 ++--
 wsd/SenderQueue.hpp |4 ++--
 wsd/TileCache.cpp   |2 +-
 13 files changed, 40 insertions(+), 39 deletions(-)

New commits:
commit e60bc28a0059c25f3c30bd06dcdae8a391641ecc
Author: Ashod Nakashian 
Date:   Mon Dec 12 19:53:58 2016 -0500

loolwsd: LOOLSession -> Session

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

diff --git a/common/Session.cpp b/common/Session.cpp
index 5ead325..f2c68ec 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -49,7 +49,7 @@ using Poco::Net::Socket;
 using Poco::Net::WebSocket;
 using Poco::StringTokenizer;
 
-LOOLSession::LOOLSession(const std::string& id, const Kind kind,
+Session::Session(const std::string& id, const Kind kind,
  std::shared_ptr ws) :
 _id(id),
 _kind(kind),
@@ -67,11 +67,11 @@ LOOLSession::LOOLSession(const std::string& id, const Kind 
kind,
 {
 }
 
-LOOLSession::~LOOLSession()
+Session::~Session()
 {
 }
 
-bool LOOLSession::sendTextFrame(const char* buffer, const int length)
+bool Session::sendTextFrame(const char* buffer, const int length)
 {
 LOG_TRC(getName() << ": Send: " << getAbbreviatedMessage(buffer, length));
 try
@@ -89,14 +89,14 @@ bool LOOLSession::sendTextFrame(const char* buffer, const 
int length)
 }
 catch (const Exception& exc)
 {
-LOG_ERR("LOOLSession::sendTextFrame: Exception: " << exc.displayText() 
<<
+LOG_ERR("Session::sendTextFrame: Exception: " << exc.displayText() <<
 (exc.nested() ? "( " + exc.nested()->displayText() + ")" : 
""));
 }
 
 return false;
 }
 
-bool LOOLSession::sendBinaryFrame(const char *buffer, int length)
+bool Session::sendBinaryFrame(const char *buffer, int length)
 {
 LOG_TRC(getName() << ": Send: " << std::to_string(length) << " bytes.");
 try
@@ -114,14 +114,14 @@ bool LOOLSession::sendBinaryFrame(const char *buffer, int 
length)
 }
 catch (const Exception& exc)
 {
-LOG_ERR("LOOLSession::sendBinaryFrame: Exception: " << 
exc.displayText() <<
+LOG_ERR("Session::sendBinaryFrame: Exception: " << exc.displayText() <<
 (exc.nested() ? "( " + exc.nested()->displayText() + ")" : 
""));
 }
 
 return false;
 }
 
-void LOOLSession::parseDocOptions(const StringTokenizer& tokens, int& part, 
std::string& timestamp)
+void Session::parseDocOptions(const StringTokenizer& tokens, int& part, 
std::string& timestamp)
 {
 // First token is the "load" command itself.
 size_t offset = 1;
@@ -178,7 +178,7 @@ void LOOLSession::parseDocOptions(const StringTokenizer& 
tokens, int& part, std:
 }
 }
 
-void LOOLSession::disconnect()
+void Session::disconnect()
 {
 try
 {
@@ -190,19 +190,19 @@ void LOOLSession::disconnect()
 }
 catch (const IOException& exc)
 {
-LOG_ERR("LOOLSession::disconnect: Exception: " << exc.displayText() <<
+LOG_ERR("Session::disconnect: Exception: " << exc.displayText() <<
 (exc.nested() ? " (" + exc.nested()->displayText() + ")" : 
""));
 }
 }
 
-bool LOOLSession::handleDisconnect()
+bool Session::handleDisconnect()
 {
 _disconnected = true;
 IoUtil::shutdownWebSocket(_ws);
 return false;
 }
 
-void LOOLSession::shutdown(Poco::UInt16 statusCode, const std::string& 
statusMessage)
+void Session::shutdown(Poco::UInt16 statusCode, const std::string& 
statusMessage)
 {
 if (_ws)
 {
@@ -213,13 +213,13 @@ void LOOLSession::shutdown(Poco::UInt16 statusCode, const 
std::string& statusMes
 }
 catch (const Poco::Exception )
 {
-LOG_WRN("LOOLSession::shutdown LOOLWebSocket: Exception: " <<
+LOG_WRN("Session::shutdown LOOLWebSocket: Exception: " <<
 exc.displayText() << (exc.nested() ? " (" + 
exc.nested()->displayText() + ")" : ""));
 }
 }
 }
 
-bool LOOLSession::handleInput(const char *buffer, int length)
+bool Session::handleInput(const char *buffer, int length)
 {
 assert(buffer != nullptr);
 
@@ -238,14 +238,14 @@ bool LOOLSession::handleInput(const char *buffer, int 
length)
 }
 catch (const Exception& exc)
 {
-LOG_ERR("LOOLSession::handleInput: Exception while handling [" <<
+LOG_ERR("Session::handleInput: Exception while handling [" <<
 getAbbreviatedMessage(buffer, length) <<
  

[Libreoffice-commits] online.git: common/Session.cpp common/UnitHTTP.hpp

2016-12-01 Thread Miklos Vajna
 common/Session.cpp  |1 -
 common/UnitHTTP.hpp |1 -
 2 files changed, 2 deletions(-)

New commits:
commit dd1dbaa7370c8d71d03499dc5ea160301ee3160e
Author: Miklos Vajna 
Date:   Fri Dec 2 08:16:40 2016 +0100

common: clean up redundant initializers for members

Change-Id: I7ee177acdc2521bc5b2d9fd0b0d3fa4947d6f2e2

diff --git a/common/Session.cpp b/common/Session.cpp
index 36bf79c..e1a3f36 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -60,7 +60,6 @@ LOOLSession::LOOLSession(const std::string& id, const Kind 
kind,
 _isActive(true),
 _lastActivityTime(std::chrono::steady_clock::now()),
 _isCloseFrame(false),
-_mutex(),
 _docPassword(""),
 _haveDocPassword(false),
 _isDocPasswordProtected(false)
diff --git a/common/UnitHTTP.hpp b/common/UnitHTTP.hpp
index 7765e47..e70af89 100644
--- a/common/UnitHTTP.hpp
+++ b/common/UnitHTTP.hpp
@@ -74,7 +74,6 @@ public:
 UnitHTTPServerRequest(UnitHTTPServerResponse& inResponse,
   const std::string& uri) :
 _response(inResponse),
-_clientAddress(),
 _serverAddress(MasterPortNumber)
 {
 setURI(uri);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits