From 35fd106ddeb18f8c636982f3b2016ec8fd848fff Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 12 Dec 2015 14:59:20 +0000 Subject: [PATCH] Make SSL cert filename part of config. Fix a shutdown segfault --- jsonserver.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) mode change 100644 => 100755 jsonserver.c diff --git a/jsonserver.c b/jsonserver.c old mode 100644 new mode 100755 index 9cb6717..28ab6ca --- a/jsonserver.c +++ b/jsonserver.c @@ -25,6 +25,8 @@ private: Config* config; char* cfgDocRoot; char* cfgPort; + char* cfgSSLFilename; + bool mgRunning; public: cPluginJsonserver(void); virtual ~cPluginJsonserver(); @@ -58,6 +60,8 @@ cPluginJsonserver::cPluginJsonserver(void) log = NULL; cfgDocRoot = NULL; cfgPort = NULL; + cfgSSLFilename = NULL; + mgRunning = false; } cPluginJsonserver::~cPluginJsonserver() @@ -153,6 +157,18 @@ bool cPluginJsonserver::Start(void) cfgPort = new char[5]; strcpy(cfgPort, "8005"); } + + char* cfgSSLFilename = config->getValueString("General", "SSL PEM File"); + if (!cfgSSLFilename) + { + log->log("Main", Log::ALERT, "Config General / SSL PEM File not found - can't run!"); + dsyslog("jsonserver: ERROR: Config: SSL PEM not found"); + delete log; + delete config; + log = NULL; + config = NULL; + return false; + } // Make Mongoose options const char *options[] = @@ -162,7 +178,7 @@ bool cPluginJsonserver::Start(void) "num_threads", "5", "listening_ports", "8005s", - "ssl_certificate", "/opt/jsonserver/sslcert.pem", + "ssl_certificate", cfgSSLFilename, // "auth_domain", "VDRWeb", @@ -176,15 +192,18 @@ bool cPluginJsonserver::Start(void) mg = mg_start(&callbacks, NULL, options); log->log("JSONServer", Log::INFO, "Mongoose started"); + mgRunning = true; return true; } void cPluginJsonserver::Stop(void) { // Stop any background activities the plugin is performing. - mg_stop(mg); + if (mgRunning) mg_stop(mg); + mgRunning = false; if (cfgDocRoot) delete[] cfgDocRoot; cfgDocRoot = NULL; if (cfgPort) delete[] cfgPort; cfgPort = NULL; + if (cfgSSLFilename) delete[] cfgSSLFilename; cfgSSLFilename = NULL; } void cPluginJsonserver::Housekeeping(void) -- 2.39.5