Files
spark/src/lib/md/vendor/OnixsUtils.cpp
T
2019-08-28 19:04:08 -04:00

69 lines
2.3 KiB
C++

#ifndef WIN32
#include "OnixsUtils.h"
#include "lib/logging/logging.h"
#include "lib/config/config.h"
#include "lib/config/protos/MarketData.pb.h"
namespace bts {
namespace md {
// The onixs checksum includes the line endings as \r\n
// to avoid the possibility of git mangling the line endings we store
// an array of lines instead of a single string and restore the lines
// when we write it out in MDP3main.cpp
const char * onixs_license[] = {
"<license version=\"1.0\">",
" <type>production</type>",
" <customer>",
" <name>Blue Trading Systems OF 9420-2</name>",
" </customer>",
" <period>",
" <since>2019-05-02</since>",
" <till>2020-05-13</till>",
" </period>",
" <products>",
" <product id=\"4\" name=\"CME Market Data Handler for C++\" />",
" <product id=\"7\" name=\"ICE iMpact Multicast Price Feed Handler for C++\" />",
" <product id=\"67\" name=\"Eurex Market and Reference Data Interfaces (EMDI, RDI) Handler for C++\" />",
" </products>",
" <checksum>5E50A1DACD94D7C1BECD316EEAE5AB02</checksum>",
"</license>",
};
OnixsTemplLicense onixs_create_temporary_license() {
const auto& options = config::get<OnixsOptions>();
OnixsTemplLicense linfo;
linfo.path = options.onixs_license();
if (linfo.path == "{default}") {
linfo.path = boost::filesystem::path {os::bts_data_path()} / "licenses";
auto ident = boost::filesystem::unique_path("%%%%-%%%%-%%%%-%%%%.lic");
linfo.license = { linfo.path / ident };
}
if (linfo.license) {
boost::system::error_code ignore;
boost::filesystem::create_directories(linfo.path, ignore);
auto temp = linfo.license.value();
std::ofstream out(temp.c_str(), std::ios::out | std::ios::binary);
if (out.good()) {
for (const char* line : onixs_license) {
if (line != onixs_license[0]) out << "\r\n";
out << line;
}
}
else {
LOG(md,Warn, "Licensing error. Failed to write to '{}'. Please ensure it is writeable.", linfo.path);
}
}
return linfo;
}
void onixs_destroy_temporary_license(const OnixsTemplLicense& lic) {
if (lic.license) {
boost::system::error_code ignore;
boost::filesystem::remove(lic.license.value(), ignore);
}
}
}} //namespace
#endif