loolwsd: refactored DocumentBroker
Change-Id: Ie7d9f46e49db8978541b4775fbf6d2578879a111 Reviewed-on: https://gerrit.libreoffice.org/23449 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
parent
18829fda3b
commit
66c8c0a300
2 changed files with 34 additions and 26 deletions
|
@ -27,10 +27,8 @@ class DocumentBroker
|
|||
public:
|
||||
|
||||
static
|
||||
std::shared_ptr<DocumentBroker> create(std::string uri, const std::string& childRoot)
|
||||
Poco::URI sanitizeURI(std::string uri)
|
||||
{
|
||||
Log::info("Creating DocumentBroker for uri: " + uri + ".");
|
||||
|
||||
// The URI of the document should be url-encoded.
|
||||
std::string decodedUri;
|
||||
Poco::URI::decode(uri, decodedUri);
|
||||
|
@ -47,10 +45,31 @@ public:
|
|||
throw std::runtime_error("Invalid URI.");
|
||||
}
|
||||
|
||||
std::string docKey;
|
||||
Poco::URI::encode(uriPublic.getPath(), "", docKey);
|
||||
return uriPublic;
|
||||
}
|
||||
|
||||
return std::shared_ptr<DocumentBroker>(new DocumentBroker(uriPublic, docKey, childRoot));
|
||||
/// Returns a document-specific key based
|
||||
/// on the URI of the document.
|
||||
static
|
||||
std::string getDocKey(const Poco::URI& uri)
|
||||
{
|
||||
// Keep the host as part of the key to close a potential security hole.
|
||||
std::string docKey;
|
||||
Poco::URI::encode(uri.getHost() + uri.getPath(), "", docKey);
|
||||
return docKey;
|
||||
}
|
||||
|
||||
DocumentBroker(const Poco::URI& uriPublic,
|
||||
const std::string& docKey,
|
||||
const std::string& childRoot) :
|
||||
_uriPublic(uriPublic),
|
||||
_docKey(docKey),
|
||||
_childRoot(childRoot),
|
||||
_sessionsCount(0)
|
||||
{
|
||||
assert(!_docKey.empty());
|
||||
assert(!_childRoot.empty());
|
||||
Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: [" + _docKey + "]");
|
||||
}
|
||||
|
||||
~DocumentBroker()
|
||||
|
@ -67,7 +86,8 @@ public:
|
|||
|
||||
if (_storage)
|
||||
{
|
||||
// Already loaded. Just return.
|
||||
// Already loaded. Only validate.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -122,20 +142,6 @@ public:
|
|||
return Poco::Path(_childRoot, _jailId).toString();
|
||||
}
|
||||
|
||||
private:
|
||||
DocumentBroker(const Poco::URI& uriPublic,
|
||||
const std::string& docKey,
|
||||
const std::string& childRoot) :
|
||||
_uriPublic(uriPublic),
|
||||
_docKey(docKey),
|
||||
_childRoot(childRoot),
|
||||
_sessionsCount(0)
|
||||
{
|
||||
assert(!_docKey.empty());
|
||||
assert(!_childRoot.empty());
|
||||
Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: [" + _docKey + "]");
|
||||
}
|
||||
|
||||
private:
|
||||
const Poco::URI _uriPublic;
|
||||
const std::string _docKey;
|
||||
|
|
|
@ -372,8 +372,9 @@ private:
|
|||
if (!format.empty())
|
||||
{
|
||||
Log::info("Conversion request for URI [" + fromPath + "].");
|
||||
auto docBroker = DocumentBroker::create(fromPath, LOOLWSD::ChildRoot);
|
||||
const auto docKey = docBroker->getDocKey();
|
||||
auto uriPublic = DocumentBroker::sanitizeURI(fromPath);
|
||||
const auto docKey = DocumentBroker::getDocKey(uriPublic);
|
||||
auto docBroker = std::make_shared<DocumentBroker>(uriPublic, docKey, LOOLWSD::ChildRoot);
|
||||
|
||||
// This lock could become a bottleneck.
|
||||
// In that case, we can use a pool and index by publicPath.
|
||||
|
@ -552,9 +553,9 @@ private:
|
|||
uri.erase(0, 1);
|
||||
}
|
||||
|
||||
auto docBroker = DocumentBroker::create(uri, LOOLWSD::ChildRoot);
|
||||
const auto docKey = docBroker->getDocKey();
|
||||
|
||||
const auto uriPublic = DocumentBroker::sanitizeURI(uri);
|
||||
const auto docKey = DocumentBroker::getDocKey(uriPublic);
|
||||
std::shared_ptr<DocumentBroker> docBroker;
|
||||
// This lock could become a bottleneck.
|
||||
// In that case, we can use a pool and index by publicPath.
|
||||
std::unique_lock<std::mutex> docBrokersLock(docBrokersMutex);
|
||||
|
@ -572,6 +573,7 @@ private:
|
|||
{
|
||||
// Set one we just created.
|
||||
Log::debug("New DocumentBroker for docKey [" + docKey + "].");
|
||||
docBroker = std::make_shared<DocumentBroker>(uriPublic, docKey, LOOLWSD::ChildRoot);
|
||||
docBrokers.emplace(docKey, docBroker);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue