2016-04-13 09:10:02 -05: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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <ftw.h>
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
|
2016-04-13 09:10:02 -05:00
|
|
|
#include <cassert>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <Poco/Net/HTTPClientSession.h>
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include <Poco/Net/HTTPResponse.h>
|
2016-04-13 09:10:02 -05:00
|
|
|
#include <Poco/Net/HTTPServerRequest.h>
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include <Poco/StringTokenizer.h>
|
|
|
|
#include <Poco/Timestamp.h>
|
|
|
|
|
|
|
|
#include "Common.hpp"
|
2016-11-24 08:56:06 -06:00
|
|
|
#include "Protocol.hpp"
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include "Log.hpp"
|
|
|
|
#include "Unit.hpp"
|
|
|
|
#include "Util.hpp"
|
2016-04-13 09:10:02 -05:00
|
|
|
|
|
|
|
#define UNIT_URI "/loolwsd/unit-font"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// interrogate the vcl/ fontmanager for its hook ...
|
|
|
|
std::string getFontList()
|
|
|
|
{
|
2016-12-22 08:04:07 -06:00
|
|
|
void *me = dlopen(nullptr,RTLD_NOW);
|
2016-04-13 09:10:02 -05:00
|
|
|
typedef const char *(GetFontsFn)(void);
|
|
|
|
GetFontsFn *fn = reinterpret_cast<GetFontsFn *>(
|
|
|
|
dlsym(me, "unit_online_get_fonts"));
|
|
|
|
if (fn)
|
|
|
|
return std::string(fn());
|
|
|
|
else
|
|
|
|
return std::string("can't find unit_online_get_fonts hook");
|
|
|
|
}
|
|
|
|
|
2016-11-10 02:47:25 -06:00
|
|
|
std::string readFontList(const std::shared_ptr<LOOLWebSocket> &socket)
|
2016-04-13 09:10:02 -05:00
|
|
|
{
|
|
|
|
int flags;
|
2016-11-25 03:46:01 -06:00
|
|
|
char buffer[100 * 1000];
|
2016-04-13 09:10:02 -05:00
|
|
|
|
2016-11-25 03:46:01 -06:00
|
|
|
int length = socket->receiveFrame(buffer, sizeof (buffer), flags);
|
2016-04-13 09:10:02 -05:00
|
|
|
if (length > 0)
|
|
|
|
{
|
2016-11-25 03:46:01 -06:00
|
|
|
assert(length<(int)sizeof(buffer));
|
|
|
|
buffer[length] = '\0';
|
|
|
|
return std::string(buffer);
|
2016-04-13 09:10:02 -05:00
|
|
|
}
|
2016-11-25 03:46:01 -06:00
|
|
|
else
|
|
|
|
return std::string("read failure");
|
2016-04-13 09:10:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inside the WSD process
|
|
|
|
class UnitPrefork : public UnitWSD
|
|
|
|
{
|
|
|
|
std::string _fontsKit;
|
|
|
|
std::string _fontsBroker;
|
|
|
|
public:
|
|
|
|
UnitPrefork()
|
|
|
|
{
|
|
|
|
setHasKitHooks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void check()
|
|
|
|
{
|
|
|
|
if (!_fontsKit.length() || !_fontsBroker.length())
|
|
|
|
return; // defer till we have all the data.
|
|
|
|
if (_fontsKit != _fontsBroker)
|
|
|
|
{
|
2016-05-21 09:28:22 -05:00
|
|
|
std::cerr << "Error - font list mismatch" << std::endl;
|
2016-04-13 09:10:02 -05:00
|
|
|
std::cerr << "Kit : '" << _fontsKit << "' vs. Broker : '" << _fontsBroker << "'" << std::endl;
|
2016-12-22 03:27:30 -06:00
|
|
|
exitTest(TestResult::Failed);
|
2016-04-13 09:10:02 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Poco::StringTokenizer tokens(_fontsKit, "\n");
|
|
|
|
if (tokens.count() > 0)
|
2016-05-21 09:28:22 -05:00
|
|
|
std::cerr << " " << tokens[0] << std::endl;
|
2016-04-13 09:10:02 -05:00
|
|
|
|
2016-12-22 03:27:30 -06:00
|
|
|
exitTest(TestResult::Ok);
|
2016-04-13 09:10:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 02:47:25 -06:00
|
|
|
virtual void newChild(const std::shared_ptr<LOOLWebSocket> &socket) override
|
2016-04-13 09:10:02 -05:00
|
|
|
{
|
|
|
|
Log::info("Fetching font list from kit");
|
|
|
|
socket->sendFrame("unit-getfontlist: \n",
|
|
|
|
sizeof("unit-getfontlist: \n") - 1);
|
|
|
|
_fontsKit = readFontList(socket);
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool filterHandleRequest(
|
|
|
|
TestRequest type,
|
|
|
|
Poco::Net::HTTPServerRequest& request,
|
|
|
|
Poco::Net::HTTPServerResponse& response) override
|
|
|
|
{
|
2016-12-22 03:27:30 -06:00
|
|
|
if (type == UnitWSD::TestRequest::Prisoner &&
|
2016-04-13 09:10:02 -05:00
|
|
|
request.getURI().find(UNIT_URI) == 0)
|
|
|
|
{
|
2016-11-10 02:47:25 -06:00
|
|
|
auto ws = std::make_shared<LOOLWebSocket>(request, response);
|
2016-04-13 09:10:02 -05:00
|
|
|
_fontsBroker = readFontList(ws);
|
|
|
|
check();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Inside the forkit & kit processes
|
|
|
|
class UnitKitPrefork : public UnitKit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UnitKitPrefork()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called in the forkit after forking the kit
|
|
|
|
virtual void launchedKit(int /* pid */) override
|
|
|
|
{
|
|
|
|
// Open websocket connection between the child process and WSD.
|
2016-05-04 06:06:34 -05:00
|
|
|
Poco::Net::HTTPClientSession cs("127.0.0.1", MasterPortNumber);
|
2016-04-13 09:10:02 -05:00
|
|
|
cs.setTimeout(0);
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET,
|
|
|
|
std::string(UNIT_URI));
|
|
|
|
Poco::Net::HTTPResponse response;
|
2016-11-10 02:47:25 -06:00
|
|
|
auto ws = std::make_shared<LOOLWebSocket>(cs, request, response);
|
2016-04-13 09:10:02 -05:00
|
|
|
ws->setReceiveTimeout(0);
|
|
|
|
Log::info("Fetching font list from forkit");
|
|
|
|
std::string fontListMsg = getFontList() + "\n";
|
|
|
|
ws->sendFrame(fontListMsg.c_str(), fontListMsg.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called from WSD and handled inside the kit.
|
2016-11-10 02:47:25 -06:00
|
|
|
virtual bool filterKitMessage(const std::shared_ptr<LOOLWebSocket> &ws,
|
2016-04-13 09:10:02 -05:00
|
|
|
std::string &message) override
|
|
|
|
{
|
2016-10-08 12:12:16 -05:00
|
|
|
const std::string token = LOOLProtocol::getFirstToken(message);
|
2016-04-13 09:10:02 -05:00
|
|
|
if (token == "unit-getfontlist:")
|
|
|
|
{
|
2016-10-08 12:12:16 -05:00
|
|
|
const std::string fontListReply = getFontList() + "\n";
|
2016-04-13 09:10:02 -05:00
|
|
|
ws->sendFrame(fontListReply.c_str(), fontListReply.length());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase *unit_create_wsd(void)
|
|
|
|
{
|
|
|
|
return new UnitPrefork();
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase *unit_create_kit(void)
|
|
|
|
{
|
|
|
|
return new UnitKitPrefork();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|