2016-03-10 20:42:33 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2016-03-12 18:29:17 -06:00
|
|
|
#ifndef INCLUDED_DOCUMENTBROKER_HPP
|
|
|
|
#define INCLUDED_DOCUMENTBROKER_HPP
|
2016-03-10 20:42:33 -06:00
|
|
|
|
|
|
|
#include <atomic>
|
2016-03-25 21:56:18 -05:00
|
|
|
#include <memory>
|
2016-03-10 20:42:33 -06:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
|
2016-03-25 21:56:18 -05:00
|
|
|
#include <Poco/URI.h>
|
|
|
|
|
|
|
|
#include <Util.hpp>
|
|
|
|
|
|
|
|
// Forwards.
|
|
|
|
class StorageBase;
|
|
|
|
class TileCache;
|
2016-03-10 20:42:33 -06:00
|
|
|
|
2016-03-12 18:29:17 -06:00
|
|
|
/// DocumentBroker is responsible for setting up a document
|
|
|
|
/// in jail and brokering loading it from Storage
|
|
|
|
/// and saving it back.
|
2016-03-10 20:42:33 -06:00
|
|
|
/// Contains URI, physical path, etc.
|
2016-03-12 18:29:17 -06:00
|
|
|
class DocumentBroker
|
2016-03-10 20:42:33 -06:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
static
|
2016-03-23 07:41:18 -05:00
|
|
|
Poco::URI sanitizeURI(std::string uri);
|
2016-03-19 17:49:36 -05:00
|
|
|
|
|
|
|
/// Returns a document-specific key based
|
|
|
|
/// on the URI of the document.
|
|
|
|
static
|
2016-03-23 07:41:18 -05:00
|
|
|
std::string getDocKey(const Poco::URI& uri);
|
2016-03-12 18:29:17 -06:00
|
|
|
|
2016-03-19 17:49:36 -05:00
|
|
|
DocumentBroker(const Poco::URI& uriPublic,
|
|
|
|
const std::string& docKey,
|
2016-03-23 07:41:18 -05:00
|
|
|
const std::string& childRoot);
|
2016-03-12 18:29:17 -06:00
|
|
|
|
|
|
|
~DocumentBroker()
|
|
|
|
{
|
2016-03-25 21:56:18 -05:00
|
|
|
Log::info() << "~DocumentBroker [" << _uriPublic.toString()
|
|
|
|
<< "] destroyed with " << _sessionsCount
|
|
|
|
<< " sessions." << Log::end;
|
2016-03-12 18:29:17 -06:00
|
|
|
}
|
|
|
|
|
2016-03-23 07:41:18 -05:00
|
|
|
void validate(const Poco::URI& uri);
|
2016-03-21 18:12:00 -05:00
|
|
|
|
2016-03-12 18:29:17 -06:00
|
|
|
/// Loads a document from the public URI into the jail.
|
2016-03-23 07:41:18 -05:00
|
|
|
bool load(const std::string& jailId);
|
2016-03-12 18:29:17 -06:00
|
|
|
|
2016-03-23 07:41:18 -05:00
|
|
|
bool save();
|
2016-03-10 21:01:34 -06:00
|
|
|
|
2016-03-10 20:42:33 -06:00
|
|
|
Poco::URI getPublicUri() const { return _uriPublic; }
|
|
|
|
Poco::URI getJailedUri() const { return _uriJailed; }
|
2016-03-12 18:29:17 -06:00
|
|
|
const std::string& getJailId() const { return _jailId; }
|
|
|
|
const std::string& getDocKey() const { return _docKey; }
|
2016-03-13 09:04:54 -05:00
|
|
|
unsigned decSessions() { return --_sessionsCount; }
|
|
|
|
unsigned incSessions() { return ++_sessionsCount; }
|
2016-03-14 10:53:31 -05:00
|
|
|
unsigned getSessionsCount() { return _sessionsCount; }
|
2016-03-25 21:56:18 -05:00
|
|
|
TileCache& tileCache() { return *_tileCache; }
|
2016-03-10 20:42:33 -06:00
|
|
|
|
2016-03-23 07:41:18 -05:00
|
|
|
std::string getJailRoot() const;
|
2016-03-12 19:14:32 -06:00
|
|
|
|
2016-03-10 20:42:33 -06:00
|
|
|
private:
|
|
|
|
const Poco::URI _uriPublic;
|
2016-03-12 18:29:17 -06:00
|
|
|
const std::string _docKey;
|
2016-03-12 19:14:32 -06:00
|
|
|
const std::string _childRoot;
|
2016-03-12 18:29:17 -06:00
|
|
|
Poco::URI _uriJailed;
|
|
|
|
std::string _jailId;
|
2016-03-21 18:12:00 -05:00
|
|
|
std::string _filename;
|
2016-03-10 21:01:34 -06:00
|
|
|
std::unique_ptr<StorageBase> _storage;
|
2016-03-25 21:56:18 -05:00
|
|
|
std::unique_ptr<TileCache> _tileCache;
|
2016-03-12 18:29:17 -06:00
|
|
|
std::mutex _mutex;
|
2016-03-13 09:04:54 -05:00
|
|
|
std::atomic<unsigned> _sessionsCount;
|
2016-03-10 20:42:33 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|