]> git.vomp.tv Git - jsonserver.git/commitdiff
Add call to search for same programme on another channel
authorChris Tallon <chris@vomp.tv>
Wed, 28 Jun 2017 14:11:25 +0000 (15:11 +0100)
committerChris Tallon <chris@vomp.tv>
Wed, 28 Jun 2017 14:11:25 +0000 (15:11 +0100)
handler.c
handler.h
jsonserver.c

index 0286d26ffbe13ded2a3c7c1d189b90e76b1d9d63..1876f41912c4b31bad0b29f86d14dbdc77a08330 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -87,7 +87,8 @@ int jsonserver_request_handler(struct mg_connection *conn)
   else if (!strcmp(wvrequest, "timerisrecording")) success = jsonserver_timerisrecording(js, postData);
   else if (!strcmp(wvrequest, "timeredit")) success = jsonserver_timeredit(js, postData);
   else if (!strcmp(wvrequest, "tunersstatus")) success = jsonserver_tunersstatus(js, postData);
-  
+  else if (!strcmp(wvrequest, "epgsearchsame")) success = jsonserver_epgsearchsame(js, postData);
+
   if (!success) return 0; // the specific handler failed badly
 
   // Now js will be filled
@@ -1640,3 +1641,61 @@ bool jsonserver_tunersstatus(Json::Value& js, const char* postData)
   js["Result"] = true;
   return true;
 }
+
+
+bool jsonserver_epgsearchsame(Json::Value& js, const char* postData)
+{
+  Log* log = Log::getInstance();
+  log->log("JSONServer", Log::DEBUG, "epgsearchsame");
+
+  char sAtTime[15];  int mgv1 = mg_get_var(postData, strlen(postData), "time", sAtTime, 15);
+  char sTitle[1024]; int mgv2 = mg_get_var(postData, strlen(postData), "title", sTitle, 1024);
+
+  if ( (mgv1 == -1) || (mgv2 == -1) )
+  {
+    log->log("JSONServer", Log::ERR, "request mgvs: %i %i", mgv1, mgv2);
+    js["Result"] = false;
+    js["Error"] = "Bad request parameters";
+    return true;
+  }
+
+  int atTime = atoi(sAtTime);
+  log->log("JSONServer", Log::DEBUG, "request time: %i, title: %s", atTime, sTitle);
+
+
+
+  cSchedulesLock SchedulesLock;
+  const cSchedules *schedules = cSchedules::Schedules(SchedulesLock);
+  if (!schedules)
+  {
+    js["Result"] = false;
+    return true;
+  }
+
+  Json::Value jsevents(Json::arrayValue);
+
+  const cEvent *event;
+  for (cSchedule *schedule = schedules->First(); (schedule != NULL); schedule = schedules->Next(schedule))
+  {
+    event = schedule->GetEventAround(atTime);
+    if (!event) continue; // nothing found on this schedule(channel)
+
+    if (!strcmp(event->Title(), sTitle))
+    {
+      Json::Value oneEvent;
+      oneEvent["ChannelID"] = (const char*)event->ChannelID().ToString();
+      oneEvent["ID"] = event->EventID();
+      oneEvent["Time"] = (Json::UInt)event->StartTime();
+      oneEvent["Duration"] = event->Duration();
+      oneEvent["Title"] = event->Title() ? event->Title() : "";
+      oneEvent["ShortText"] = event->ShortText() ? event->ShortText() : "";
+      oneEvent["HasTimer"] = event->HasTimer();
+      //oneEvent["Description"] = event->Description() ? event->Description() : "";
+      jsevents.append(oneEvent);
+    }
+  }
+
+  js["Events"] = jsevents;
+  js["Result"] = true;
+  return true;
+}
index f68c7f119df7464dd7e02de0212cdd4d896fcad0..f7e1f57b3d02e9ba0f82731556636236f66c35a4 100644 (file)
--- a/handler.h
+++ b/handler.h
@@ -28,6 +28,7 @@ bool jsonserver_timersetactive(Json::Value& js, const char* postData);
 bool jsonserver_timerisrecording(Json::Value& js, const char* postData);
 bool jsonserver_timeredit(Json::Value& js, const char* postData);
 bool jsonserver_tunersstatus(Json::Value& js, const char* postData);
+bool jsonserver_epgsearchsame(Json::Value& js, const char* postData);
 
 const cEvent* jsonserver_getEvent(Json::Value& js, int channelNumber, int eventID, int aroundTime);
 cTimer* jsonserver_findTimer(const char* rChannelID, const char* rName, const char* rStartTime, const char* rStopTime, const char* rWeekDays);
index 28ab6ca417d2193a9970a6c72ae9ec3b1604f1bb..8d1cbb86d399eb1af3bbcd7798f083093adf8ba9 100644 (file)
@@ -201,9 +201,9 @@ void cPluginJsonserver::Stop(void)
   // Stop any background activities the plugin is performing.
   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;
+  if (cfgDocRoot) { delete[] cfgDocRoot; cfgDocRoot = NULL; }
+  if (cfgPort) { delete[] cfgPort; cfgPort = NULL; }
+  if (cfgSSLFilename) { delete[] cfgSSLFilename; cfgSSLFilename = NULL; }
 }
 
 void cPluginJsonserver::Housekeeping(void)