Merge branch 'development' into LTS_development
# Conflicts: # src/controller/controller_api.cpp # src/controller/controller_api.h # src/controller/controller_storage.cpp
This commit is contained in:
commit
4bdcb24132
13 changed files with 421 additions and 471 deletions
|
@ -242,16 +242,22 @@ int main_loop(int argc, char ** argv){
|
|||
if (Controller::Storage["config"]["controller"]["username"]){
|
||||
Controller::conf.getOption("username", true)[0u] = Controller::Storage["config"]["controller"]["username"];
|
||||
}
|
||||
if (Controller::Storage["config"]["controller"]["prometheus"]){
|
||||
Controller::conf.getOption("prometheus", true)[0u] = Controller::Storage["config"]["controller"]["prometheus"];
|
||||
if (Controller::Storage["config"]["controller"].isMember("prometheus")){
|
||||
if (Controller::Storage["config"]["controller"]["prometheus"]){
|
||||
Controller::Storage["config"]["prometheus"] = Controller::Storage["config"]["controller"]["prometheus"];
|
||||
}
|
||||
Controller::Storage["config"]["controller"].removeMember("prometheus");
|
||||
}
|
||||
if (Controller::Storage["config"]["prometheus"]){
|
||||
Controller::conf.getOption("prometheus", true)[0u] = Controller::Storage["config"]["prometheus"];
|
||||
}
|
||||
if (Controller::Storage["config"].isMember("accesslog")){
|
||||
Controller::conf.getOption("accesslog", true)[0u] = Controller::Storage["config"]["accesslog"];
|
||||
}
|
||||
Controller::maxConnsPerIP = Controller::conf.getInteger("maxconnsperip");
|
||||
Controller::Storage["config"]["controller"]["prometheus"] = Controller::conf.getString("prometheus");
|
||||
Controller::Storage["config"]["prometheus"] = Controller::conf.getString("prometheus");
|
||||
Controller::Storage["config"]["accesslog"] = Controller::conf.getString("accesslog");
|
||||
Controller::prometheus = Controller::Storage["config"]["controller"]["prometheus"].asStringRef();
|
||||
Controller::prometheus = Controller::Storage["config"]["prometheus"].asStringRef();
|
||||
Controller::accesslog = Controller::Storage["config"]["accesslog"].asStringRef();
|
||||
{
|
||||
IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
|
@ -421,16 +427,7 @@ int main_loop(int argc, char ** argv){
|
|||
/*LTS-END*/
|
||||
//write config
|
||||
tthread::lock_guard<tthread::mutex> guard(Controller::logMutex);
|
||||
Controller::Storage.removeMember("log");
|
||||
jsonForEach(Controller::Storage["streams"], it) {
|
||||
it->removeMember("meta");
|
||||
}
|
||||
if ( !Controller::WriteFile(Controller::conf.getString("configFile"), Controller::Storage.toString())){
|
||||
std::cerr << "Error writing config " << Controller::conf.getString("configFile") << std::endl;
|
||||
std::cerr << "**Config**" << std::endl;
|
||||
std::cerr << Controller::Storage.toString() << std::endl;
|
||||
std::cerr << "**End config**" << std::endl;
|
||||
}
|
||||
Controller::writeConfigToDisk();
|
||||
//stop all child processes
|
||||
Util::Procs::StopAll();
|
||||
//give everything some time to print messages
|
||||
|
|
|
@ -19,66 +19,6 @@
|
|||
#include "controller_license.h"
|
||||
/*LTS-END*/
|
||||
|
||||
///\brief Check the submitted configuration and handle things accordingly.
|
||||
///\param in The new configuration.
|
||||
///\param out The location to store the resulting configuration.
|
||||
///
|
||||
/// \api
|
||||
/// `"config"` requests take the form of:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// {
|
||||
/// "controller": { //controller settings
|
||||
/// "interface": null, //interface to listen on. Defaults to all interfaces.
|
||||
/// "port": 4242, //port to listen on. Defaults to 4242.
|
||||
/// "username": null //username to drop privileges to. Defaults to root.
|
||||
/// },
|
||||
/// "protocols": [ //enabled connectors / protocols
|
||||
/// {
|
||||
/// "connector": "HTTP" //Name of the connector to enable
|
||||
/// //any required and/or optional settings may be given here as "name": "value" pairs inside this object.
|
||||
/// },
|
||||
/// //above structure repeated for all enabled connectors / protocols
|
||||
/// ],
|
||||
/// "serverid": "", //human-readable server identifier, optional.
|
||||
/// }
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// and are responded to as:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// {
|
||||
/// "controller": { //controller settings
|
||||
/// "interface": null, //interface to listen on. Defaults to all interfaces.
|
||||
/// "port": 4242, //port to listen on. Defaults to 4242.
|
||||
/// "username": null //username to drop privileges to. Defaults to root.
|
||||
/// },
|
||||
/// "protocols": [ //enabled connectors / protocols
|
||||
/// {
|
||||
/// "connector": "HTTP" //Name of the connector to enable
|
||||
/// //any required and/or optional settings may be given here as "name": "value" pairs inside this object.
|
||||
/// "online": 1 //boolean value indicating if the executable is running or not
|
||||
/// },
|
||||
/// //above structure repeated for all enabled connectors / protocols
|
||||
/// ],
|
||||
/// "serverid": "", //human-readable server identifier, as configured.
|
||||
/// "time": 1398982430, //current unix time
|
||||
/// "version": "2.0.2/8.0.1-23-gfeb9322/Generic_64" //currently running server version string
|
||||
/// }
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
void Controller::checkConfig(JSON::Value & in, JSON::Value & out){
|
||||
out = in;
|
||||
if (out.isMember("debug")){
|
||||
if (Util::Config::printDebugLevel != out["debug"].asInt()){
|
||||
Util::Config::printDebugLevel = out["debug"].asInt();
|
||||
INFO_MSG("Debug level set to %u", Util::Config::printDebugLevel);
|
||||
}
|
||||
}
|
||||
if (out.isMember("controller") && out["controller"].isMember("prometheus")){
|
||||
Controller::prometheus = out["controller"]["prometheus"].asStringRef();
|
||||
}
|
||||
if (out.isMember("accesslog")){
|
||||
Controller::accesslog = out["accesslog"].asStringRef();
|
||||
}
|
||||
}
|
||||
|
||||
///\brief Checks an authorization request for a given user.
|
||||
///\param Request The request to be parsed.
|
||||
///\param Response The location to store the generated response.
|
||||
|
@ -247,7 +187,6 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Controller::handleUDPAPI(void * np){
|
||||
Socket::UDPConnection uSock(true);
|
||||
if (!uSock.bind(4242, "localhost")){
|
||||
|
@ -271,55 +210,65 @@ void Controller::handleUDPAPI(void * np){
|
|||
}
|
||||
}
|
||||
|
||||
/// Local-only helper function that checks for duplicate protocols and removes them
|
||||
static void removeDuplicateProtocols(){
|
||||
JSON::Value & P = Controller::Storage["config"]["protocols"];
|
||||
std::set<std::string> ignores;
|
||||
ignores.insert("online");
|
||||
bool reloop = true;
|
||||
while (reloop){
|
||||
reloop = false;
|
||||
jsonForEach(P, it){
|
||||
jsonForEach(P, jt){
|
||||
if (it.num() == jt.num()){continue;}
|
||||
if ((*it).compareExcept(*jt, ignores)){
|
||||
jt.remove();
|
||||
reloop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (reloop){break;}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response){
|
||||
//Parse config and streams from the request.
|
||||
if (Request.isMember("config")){
|
||||
Controller::checkConfig(Request["config"], Controller::Storage["config"]);
|
||||
if (Request.isMember("config") && Request["config"].isObject()){
|
||||
const JSON::Value & in = Request["config"];
|
||||
JSON::Value & out = Controller::Storage["config"];
|
||||
if (in.isMember("debug")){
|
||||
out["debug"] = in["debug"];
|
||||
if (Util::Config::printDebugLevel != out["debug"].asInt()){
|
||||
Util::Config::printDebugLevel = out["debug"].asInt();
|
||||
INFO_MSG("Debug level set to %u", Util::Config::printDebugLevel);
|
||||
}
|
||||
}
|
||||
if (in.isMember("protocols")){
|
||||
out["protocols"] = in["protocols"];
|
||||
removeDuplicateProtocols();
|
||||
}
|
||||
if (in.isMember("controller")){
|
||||
out["controller"] = in["controller"];
|
||||
}
|
||||
if (in.isMember("serverid")){
|
||||
out["serverid"] = in["serverid"];
|
||||
}
|
||||
if (in.isMember("accesslog")){
|
||||
out["accesslog"] = in["accesslog"];
|
||||
Controller::accesslog = out["accesslog"].asStringRef();
|
||||
}
|
||||
if (in.isMember("prometheus")){
|
||||
out["prometheus"] = in["prometheus"];
|
||||
Controller::prometheus = out["prometheus"].asStringRef();
|
||||
}
|
||||
}
|
||||
if (Request.isMember("streams")){
|
||||
Controller::CheckStreams(Request["streams"], Controller::Storage["streams"]);
|
||||
}
|
||||
/*LTS-START*/
|
||||
///
|
||||
/// \api
|
||||
/// `"addstream"` requests (LTS-only) take the form of:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// {
|
||||
/// "streamname": {
|
||||
/// //Stream configuration - see the "streams" call for details on this format.
|
||||
/// }
|
||||
/// /// Optionally, repeat for more streams.
|
||||
/// }
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// These requests will add new streams or update existing streams with the same names, without touching other streams. In other words, this call can be used for incremental updates to the stream list instead of complete updates, like the "streams" call.
|
||||
/// Sending `"addstream"` or `"deletestream"` as part of your request will alter the `"streams"` response. As opposed to a full list of streams, this will now include a property `"incomplete list"` set to 1 and only include successfully added streams. As deletions cannot fail, these are never mentioned.
|
||||
///
|
||||
if (Request.isMember("addstream")){
|
||||
Controller::AddStreams(Request["addstream"], Controller::Storage["streams"]);
|
||||
}
|
||||
///
|
||||
/// \api
|
||||
/// `"deletestream"` requests (LTS-only) take the form of:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// {
|
||||
/// "streamname": {} //any contents in this object are ignored
|
||||
/// /// Optionally, repeat for more streams.
|
||||
/// }
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// OR
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// [
|
||||
/// "streamname",
|
||||
/// /// Optionally, repeat for more streams.
|
||||
/// ]
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// OR
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// "streamname"
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// These requests will remove the named stream(s), without touching other streams. In other words, this call can be used for incremental updates to the stream list instead of complete updates, like the "streams" call.
|
||||
/// Sending `"addstream"` or `"deletestream"` as part of your request will alter the `"streams"` response. As opposed to a full list of streams, this will now include a property `"incomplete list"` set to 1 and only include successfully added streams. As deletions cannot fail, these are never mentioned.
|
||||
///
|
||||
if (Request.isMember("deletestream")){
|
||||
//if array, delete all elements
|
||||
//if object, delete all entries
|
||||
|
@ -338,28 +287,6 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
|||
}
|
||||
}
|
||||
}
|
||||
///
|
||||
/// \api
|
||||
/// `"addprotocol"` requests (LTS-only) take the form of:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// {
|
||||
/// "connector": "HTTP" //Name of the connector to enable
|
||||
/// //any required and/or optional settings may be given here as "name": "value" pairs inside this object.
|
||||
/// }
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// OR
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// [
|
||||
/// {
|
||||
/// "connector": "HTTP" //Name of the connector to enable
|
||||
/// //any required and/or optional settings may be given here as "name": "value" pairs inside this object.
|
||||
/// }
|
||||
/// /// Optionally, repeat for more protocols.
|
||||
/// ]
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// These requests will add the given protocol configurations, without touching existing configurations. In other words, this call can be used for incremental updates to the protocols list instead of complete updates, like the "config" call.
|
||||
/// There is no response to this call.
|
||||
///
|
||||
if (Request.isMember("addprotocol")){
|
||||
if (Request["addprotocol"].isArray()){
|
||||
jsonForEach(Request["addprotocol"], it){
|
||||
|
@ -369,36 +296,17 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
|||
if (Request["addprotocol"].isObject()){
|
||||
Controller::Storage["config"]["protocols"].append(Request["addprotocol"]);
|
||||
}
|
||||
removeDuplicateProtocols();
|
||||
}
|
||||
///
|
||||
/// \api
|
||||
/// `"deleteprotocol"` requests (LTS-only) take the form of:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// {
|
||||
/// "connector": "HTTP" //Name of the connector to enable
|
||||
/// //any required and/or optional settings may be given here as "name": "value" pairs inside this object.
|
||||
/// }
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// OR
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// [
|
||||
/// {
|
||||
/// "connector": "HTTP" //Name of the connector to enable
|
||||
/// //any required and/or optional settings may be given here as "name": "value" pairs inside this object.
|
||||
/// }
|
||||
/// /// Optionally, repeat for more protocols.
|
||||
/// ]
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// These requests will remove the given protocol configurations (exact matches only), without touching other configurations. In other words, this call can be used for incremental updates to the protocols list instead of complete updates, like the "config" call.
|
||||
/// There is no response to this call.
|
||||
///
|
||||
if (Request.isMember("deleteprotocol")){
|
||||
std::set<std::string> ignores;
|
||||
ignores.insert("online");
|
||||
if (Request["deleteprotocol"].isArray() && Request["deleteprotocol"].size()){
|
||||
JSON::Value newProtocols;
|
||||
jsonForEach(Controller::Storage["config"]["protocols"], it){
|
||||
bool add = true;
|
||||
jsonForEach(Request["deleteprotocol"], pit){
|
||||
if (*it == *pit){
|
||||
if ((*it).compareExcept(*pit, ignores)){
|
||||
add = false;
|
||||
break;
|
||||
}
|
||||
|
@ -412,72 +320,34 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
|||
if (Request["deleteprotocol"].isObject()){
|
||||
JSON::Value newProtocols;
|
||||
jsonForEach(Controller::Storage["config"]["protocols"], it){
|
||||
if (*it != Request["deleteprotocol"]){
|
||||
if (!(*it).compareExcept(Request["deleteprotocol"], ignores)){
|
||||
newProtocols.append(*it);
|
||||
}
|
||||
}
|
||||
Controller::Storage["config"]["protocols"] = newProtocols;
|
||||
}
|
||||
}
|
||||
/*LTS-END*/
|
||||
if (Request.isMember("updateprotocol")){
|
||||
std::set<std::string> ignores;
|
||||
ignores.insert("online");
|
||||
if (Request["updateprotocol"].isArray() && Request["updateprotocol"].size() == 2){
|
||||
jsonForEach(Controller::Storage["config"]["protocols"], it){
|
||||
if ((*it).compareExcept(Request["updateprotocol"][0u], ignores)){
|
||||
(*it) = Request["updateprotocol"][1u];
|
||||
}
|
||||
}
|
||||
removeDuplicateProtocols();
|
||||
}else{
|
||||
FAIL_MSG("Cannot parse updateprotocol call: needs to be in the form [A, B]");
|
||||
}
|
||||
}
|
||||
|
||||
if (Request.isMember("capabilities")){
|
||||
Controller::checkCapable(capabilities);
|
||||
Response["capabilities"] = capabilities;
|
||||
}
|
||||
/// \todo Re-enable conversion API at some point.
|
||||
/*
|
||||
if (Request.isMember("conversion")){
|
||||
if (Request["conversion"].isMember("encoders")){
|
||||
Response["conversion"]["encoders"] = myConverter.getEncoders();
|
||||
}
|
||||
if (Request["conversion"].isMember("query")){
|
||||
if (Request["conversion"]["query"].isMember("path")){
|
||||
Response["conversion"]["query"] = myConverter.queryPath(Request["conversion"]["query"]["path"].asString());
|
||||
}else{
|
||||
Response["conversion"]["query"] = myConverter.queryPath("./");
|
||||
}
|
||||
}
|
||||
if (Request["conversion"].isMember("convert")){
|
||||
for (JSON::ObjIter it = Request["conversion"]["convert"].ObjBegin(); it != Request["conversion"]["convert"].ObjEnd(); it++){
|
||||
myConverter.startConversion(it->first,it->second);
|
||||
Controller::Log("CONV","Conversion " + it->second["input"].asString() + " to " + it->second["output"].asString() + " started.");
|
||||
}
|
||||
}
|
||||
if (Request["conversion"].isMember("status") || Request["conversion"].isMember("convert")){
|
||||
if (Request["conversion"].isMember("clear")){
|
||||
myConverter.clearStatus();
|
||||
}
|
||||
Response["conversion"]["status"] = myConverter.getStatus();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/// This takes a "browse" request, and fills in the response data.
|
||||
///
|
||||
/// \api
|
||||
/// `"browse"` requests take the form of:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// //A string, containing the path for which to discover contents. Empty means current working directory.
|
||||
/// "/tmp/example"
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// and are responded to as:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// [
|
||||
/// //The folder path
|
||||
/// "path":"/tmp/example"
|
||||
/// //An array of strings showing all files
|
||||
/// "files":
|
||||
/// ["file1.dtsc",
|
||||
/// "file2.mp3",
|
||||
/// "file3.exe"
|
||||
/// ]
|
||||
/// //An array of strings showing all subdirectories
|
||||
/// "subdirectories":[
|
||||
/// "folder1"
|
||||
/// ]
|
||||
/// ]
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
///
|
||||
|
||||
if(Request.isMember("browse")){
|
||||
if(Request["browse"] == ""){
|
||||
Request["browse"] = ".";
|
||||
|
@ -508,34 +378,11 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
|||
free(rpath);
|
||||
}
|
||||
|
||||
///
|
||||
/// \api
|
||||
/// `"save"` requests are always empty:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// {}
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// Sending this request will cause the controller to write out its currently active configuration to the configuration file it was loaded from (the default being `./config.json`).
|
||||
///
|
||||
if (Request.isMember("save")){
|
||||
if( Controller::WriteFile(Controller::conf.getString("configFile"), Controller::Storage.toString())){
|
||||
Controller::Log("CONF", "Config written to file on request through API");
|
||||
}else{
|
||||
Controller::Log("ERROR", "Config " + Controller::conf.getString("configFile") + " could not be written");
|
||||
}
|
||||
Controller::Log("CONF", "Writing config to file on request through API");
|
||||
Controller::writeConfigToDisk();
|
||||
}
|
||||
///
|
||||
/// \api
|
||||
/// `"ui_settings"` requests can take two forms. The first is the "set" form:
|
||||
/// ~~~~~~~~~~~~~~~{.js}
|
||||
/// {
|
||||
/// //Any data here
|
||||
/// }
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// The second is the "request" form, and takes any non-object as argument.
|
||||
/// When using the set form, this will write the given object verbatim into the controller storage.
|
||||
/// No matter which form is used, the current contents of the ui_settings object are always returned in the response.
|
||||
/// This API call is intended to store User Interface settings across sessions, and its contents are completely ignored by the controller itself. Besides the requirement of being an object, the contents are entirely free-form and may technically be used for any purpose.
|
||||
///
|
||||
|
||||
if (Request.isMember("ui_settings")){
|
||||
if (Request["ui_settings"].isObject()){
|
||||
Storage["ui_settings"] = Request["ui_settings"];
|
||||
|
@ -564,7 +411,6 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
|||
}
|
||||
#endif
|
||||
/*LTS-END*/
|
||||
/*LTS-START*/
|
||||
if (!Request.isMember("minimal") || Request.isMember("streams") || Request.isMember("addstream") || Request.isMember("deletestream")){
|
||||
if (!Request.isMember("streams") && (Request.isMember("addstream") || Request.isMember("deletestream"))){
|
||||
Response["streams"]["incomplete list"] = 1ll;
|
||||
|
@ -580,7 +426,7 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
|||
}
|
||||
}
|
||||
//sent current configuration, if not minimal or was changed/requested
|
||||
if (!Request.isMember("minimal") || Response.isMember("config")){
|
||||
if (!Request.isMember("minimal") || Request.isMember("config")){
|
||||
Response["config"] = Controller::Storage["config"];
|
||||
Response["config"]["version"] = PACKAGE_VERSION;
|
||||
/*LTS-START*/
|
||||
|
@ -610,9 +456,9 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
|||
/// ~~~~~~~~~~~~~~~
|
||||
/// It's possible to clear the stored logs by sending an empty `"clearstatlogs"` request.
|
||||
///
|
||||
if (Request.isMember("clearstatlogs") || !Request.isMember("minimal")){
|
||||
if (Request.isMember("clearstatlogs") || Request.isMember("log") || !Request.isMember("minimal")){
|
||||
tthread::lock_guard<tthread::mutex> guard(logMutex);
|
||||
if (!Request.isMember("minimal")){
|
||||
if (!Request.isMember("minimal") || Request.isMember("log")){
|
||||
Response["log"] = Controller::Storage["log"];
|
||||
}
|
||||
//clear log if requested
|
||||
|
@ -620,7 +466,6 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
|||
Controller::Storage["log"].null();
|
||||
}
|
||||
}
|
||||
/*LTS-END*/
|
||||
if (Request.isMember("clients")){
|
||||
if (Request["clients"].isArray()){
|
||||
for (unsigned int i = 0; i < Request["clients"].size(); ++i){
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <mist/json.h>
|
||||
|
||||
namespace Controller {
|
||||
void checkConfig(JSON::Value & in, JSON::Value & out);
|
||||
bool authorize(JSON::Value & Request, JSON::Value & Response, Socket::Connection & conn);
|
||||
int handleAPIConnection(Socket::Connection & conn);
|
||||
void handleAPICommands(JSON::Value & Request, JSON::Value & Response);
|
||||
|
|
|
@ -44,11 +44,11 @@ namespace Controller{
|
|||
#if DEBUG >= DLVL_DEVEL
|
||||
INFO_MSG("Verifying license against %llu: %s", now, currentLicense.toString().c_str());
|
||||
#endif
|
||||
if (currentLicense.isMember("user_msg") && currentLicense["user_msg"].asStringRef().size()){
|
||||
WARN_MSG("%s", currentLicense["user_msg"].asStringRef().c_str());
|
||||
}
|
||||
//The loop below is timechecker loop
|
||||
if (!currentLicense.isMember("valid_from") || !currentLicense.isMember("valid_till") || now < currentLicense["valid_from"].asInt() || now > currentLicense["valid_till"].asInt()){
|
||||
if (currentLicense.isMember("user_msg") && currentLicense["user_msg"].asStringRef().size()){
|
||||
FAIL_MSG("%s", currentLicense["user_msg"].asStringRef().c_str());
|
||||
}
|
||||
return false;//license is expired
|
||||
}
|
||||
if (RELEASE != currentLicense["release"].asStringRef() || PACKAGE_VERSION != currentLicense["version"].asStringRef()){
|
||||
|
|
|
@ -93,6 +93,23 @@ namespace Controller{
|
|||
close((long long int)err);
|
||||
}
|
||||
|
||||
/// Writes the current config to the location set in the configFile setting.
|
||||
/// On error, prints an error-level message and the config to stdout.
|
||||
void writeConfigToDisk(){
|
||||
JSON::Value tmp;
|
||||
std::set<std::string> skip;
|
||||
skip.insert("log");
|
||||
skip.insert("online");
|
||||
skip.insert("error");
|
||||
tmp.assignFrom(Controller::Storage, skip);
|
||||
if ( !Controller::WriteFile(Controller::conf.getString("configFile"), tmp.toString())){
|
||||
ERROR_MSG("Error writing config to %s", Controller::conf.getString("configFile").c_str());
|
||||
std::cout << "**Config**" << std::endl;
|
||||
std::cout << tmp.toString() << std::endl;
|
||||
std::cout << "**End config**" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes the current config to shared memory to be used in other processes
|
||||
/// \triggers
|
||||
/// The `"SYSTEM_START"` trigger is global, and is ran as soon as the server configuration is first stable. It has no payload. If cancelled,
|
||||
|
@ -103,13 +120,16 @@ namespace Controller{
|
|||
void writeConfig(){
|
||||
static JSON::Value writeConf;
|
||||
bool changed = false;
|
||||
if (writeConf["config"] != Storage["config"]){
|
||||
writeConf["config"] = Storage["config"];
|
||||
std::set<std::string> skip;
|
||||
skip.insert("online");
|
||||
skip.insert("error");
|
||||
if (!writeConf["config"].compareExcept(Storage["config"], skip)){
|
||||
writeConf["config"].assignFrom(Storage["config"], skip);
|
||||
VERYHIGH_MSG("Saving new config because of edit in server config structure");
|
||||
changed = true;
|
||||
}
|
||||
if (writeConf["streams"] != Storage["streams"]){
|
||||
writeConf["streams"] = Storage["streams"];
|
||||
if (!writeConf["streams"].compareExcept(Storage["streams"], skip)){
|
||||
writeConf["streams"].assignFrom(Storage["streams"], skip);
|
||||
VERYHIGH_MSG("Saving new config because of edit in streams");
|
||||
changed = true;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace Controller {
|
|||
|
||||
/// Write contents to Filename.
|
||||
bool WriteFile(std::string Filename, std::string contents);
|
||||
void writeConfigToDisk();
|
||||
|
||||
void handleMsg(void * err);
|
||||
|
||||
|
|
|
@ -59,10 +59,6 @@ void Controller::uplinkConnection(void * np) {
|
|||
if (inScan.hasMember("authorize") && inScan.getMember("authorize").hasMember("challenge")){
|
||||
uplink_chal = inScan.getMember("authorize").getMember("challenge").asString();
|
||||
}
|
||||
if (inScan.hasMember("config")) {
|
||||
curVal = inScan.getMember("config").asJSON();
|
||||
Controller::checkConfig(curVal, Controller::Storage["config"]);
|
||||
}
|
||||
if (inScan.hasMember("streams")) {
|
||||
curVal = inScan.getMember("streams").asJSON();
|
||||
Controller::CheckStreams(curVal, Controller::Storage["streams"]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue