]> git.vomp.tv Git - jsonserver.git/commitdiff
Make SSL cert filename part of config. Fix a shutdown segfault
authorChris Tallon <chris@vomp.tv>
Sat, 12 Dec 2015 14:59:20 +0000 (14:59 +0000)
committerChris Tallon <chris@vomp.tv>
Sat, 12 Dec 2015 14:59:20 +0000 (14:59 +0000)
jsonserver.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 9cb6717..28ab6ca
@@ -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)