]> git.vomp.tv Git - jsonserver.git/commitdiff
Fix: Don't call cPlugin::ConfigDirectory on non-main thread
authorChris Tallon <chris@vomp.tv>
Wed, 20 Nov 2019 17:54:56 +0000 (17:54 +0000)
committerChris Tallon <chris@vomp.tv>
Wed, 20 Nov 2019 17:54:56 +0000 (17:54 +0000)
httpdclient.c
httpdclient.h
jsonserver.c
vdrclient.c
vdrclient.h

index e85af175b96e603660a2ae327e43fb97cd1d1c0a..00083c1a932347246db0c30922d4d6adc2be3f15 100644 (file)
 std::shared_ptr<spd::logger> HTTPDClient::logger;
 struct MHD_Daemon* HTTPDClient::httpdserver = NULL;
 std::string HTTPDClient::docRoot;
+std::string HTTPDClient::configDir;
 
-bool HTTPDClient::StartServer(std::string _docRoot, int port)
+bool HTTPDClient::StartServer(std::string _docRoot, int port, const char* _configDir)
 {
   docRoot = _docRoot;
+  configDir = std::string(_configDir);
 
   logger = spd::get("jsonserver_spdlog");
 
@@ -78,7 +80,7 @@ void HTTPDClient::connection_notify(void *cls, struct MHD_Connection* mhd_connec
 {
   if (toe == MHD_CONNECTION_NOTIFY_STARTED)
   {
-    *socket_context = (void*)new HTTPDClient(mhd_connection);
+    *socket_context = (void*)new HTTPDClient(mhd_connection, configDir);
   }
   else if (toe == MHD_CONNECTION_NOTIFY_CLOSED)
   {
@@ -172,8 +174,8 @@ int HTTPDClient::handle_connection(void* cls, struct MHD_Connection* mhd_connect
 
 // End of static callbacks, now for the client object itself
 
-HTTPDClient::HTTPDClient(struct MHD_Connection* _mhd_connection)
-: postprocessor(NULL), url(NULL), mhd_connection(_mhd_connection)
+HTTPDClient::HTTPDClient(struct MHD_Connection* _mhd_connection, const std::string& _configDir)
+: postprocessor(NULL), url(NULL), mhd_connection(_mhd_connection), vdrclient(_configDir)
 {
 //  printf("HTTPDClient created %p\n", this);
 }
index d161188ba530389e0a96d2c8254def82a2fa89fb..0721780db510e42258c3820facbcb12acbce5246 100644 (file)
@@ -19,7 +19,7 @@ namespace spd = spdlog;
 class HTTPDClient
 {
   public:
-    static bool StartServer(std::string docRoot, int port);
+    static bool StartServer(std::string docRoot, int port, const char* configDir);
     static void StopServer();
 
     // static callbacks from libmicrohttpd
@@ -40,8 +40,9 @@ class HTTPDClient
     static std::shared_ptr<spd::logger> logger;
     static struct MHD_Daemon* httpdserver;
     static std::string docRoot;
+    static std::string configDir;
 
-    HTTPDClient(struct MHD_Connection*);
+    HTTPDClient(struct MHD_Connection*, const std::string& configDir);
     ~HTTPDClient();
 
     void setUrl(const char* url);
index 38039fdd61800c56aa29f90e4d421e87c4463efc..3a68e4ac13b05802d10449beca8afc0c245a73a1 100644 (file)
@@ -168,7 +168,7 @@ bool cPluginJsonserver::Start(void)
     return false;
   }
 
-  if (!HTTPDClient::StartServer(cfgDocRoot, cfgPort))
+  if (!HTTPDClient::StartServer(cfgDocRoot, cfgPort, configDir))
   {
     logger->critical("Main: Failed to start MHD");
     dsyslog("jsonserver: Failed to start MHD");
index b1d2a8a769d4228b599990a81559a2876005938d..47bdf66f93e3d7863b4c5831df696da0245975cd 100644 (file)
@@ -26,7 +26,8 @@ critical
   always be done in the sequence Timers, Channels, Recordings, Schedules.
 */
 
-VDRClient::VDRClient()
+VDRClient::VDRClient(const std::string& _configDir)
+: configDir(_configDir)
 {
   logger = spd::get("jsonserver_spdlog");
 }
@@ -1487,7 +1488,6 @@ bool VDRClient::epgfilterdel(PFMap& postFields, Json::Value& js) // RETHROWS
         js["Error"] = "Filter file format error";
         return true;
       }
-      logger->debug("loop: {} {}", c, p);
       if ((c == channel) && (p == programme))
       {
         setting.remove(x);
@@ -1546,7 +1546,6 @@ bool VDRClient::epgfilterget(PFMap& postFields, Json::Value& js) // RETHROWS
         js["Error"] = "Filter file format error";
         return true;
       }
-      logger->debug("loop: {} {}", c, p);
       Json::Value oneFilter;
       oneFilter["c"] = c;
       oneFilter["p"] = p;
@@ -1736,14 +1735,7 @@ std::string VDRClient::getVarString(PFMap& postFields, const char* paramName) //
 
 bool VDRClient::loadEpgFilter(libconfig::Config& epgFilter)
 {
-  const char* configDir = cPlugin::ConfigDirectory("jsonserver");
-  if (!configDir)
-  {
-    logger->error("loadEpgFilter: Error: Could not get config dir from VDR");
-    return false;
-  }
-
-  std::string epgFilterFile(std::string(configDir) + std::string("/epgfilter.conf"));
+  std::string epgFilterFile(configDir + std::string("/epgfilter.conf"));
   FILE* fp = fopen(epgFilterFile.c_str(), "a");
   if (!fp)
   {
@@ -1788,14 +1780,7 @@ bool VDRClient::loadEpgFilter(libconfig::Config& epgFilter)
 
 bool VDRClient::saveEpgFilter(libconfig::Config& epgFilter)
 {
-  const char* configDir = cPlugin::ConfigDirectory("jsonserver");
-  if (!configDir)
-  {
-    logger->error("saveEpgFilter: Error: Could not get config dir from VDR");
-    return false;
-  }
-
-  std::string epgFilterFile(std::string(configDir) + std::string("/epgfilter.conf"));
+  std::string epgFilterFile(configDir + std::string("/epgfilter.conf"));
   try
   {
     epgFilter.writeFile(epgFilterFile.c_str());
index 0c2eb34c198dfaf942225a5c6132f354740fcb39..b49c8b85433b6420a86ce45f8d565468cbfdc1ad 100644 (file)
@@ -22,12 +22,14 @@ class VDRClient
   typedef std::map<std::string, std::string> PFMap;
 
   public:
-    VDRClient();
+    VDRClient(const std::string& configDir);
     ~VDRClient();
 
     bool process(std::string& request, PFMap& postFields, std::string& returnData);
 
   private:
+    const std::string& configDir;
+
     std::shared_ptr<spd::logger> logger;
     bool gettime(PFMap& postFields, Json::Value& returnJSON);
     bool diskstats(PFMap& postFields, Json::Value& returnJSON);