]> git.vomp.tv Git - jsonserver.git/commitdiff
EPG search call
authorChris Tallon <chris@vomp.tv>
Wed, 5 Jul 2017 19:55:20 +0000 (20:55 +0100)
committerChris Tallon <chris@vomp.tv>
Wed, 5 Jul 2017 19:55:20 +0000 (20:55 +0100)
handler.c
handler.h

index cb2acce343aa01fb33834d95425713ceca52954c..4b047b1c49b862b98eb32c4cf7c70beb53edbc89 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -89,6 +89,7 @@ int jsonserver_request_handler(struct mg_connection *conn)
   else if (!strcmp(wvrequest, "tunersstatus")) success = jsonserver_tunersstatus(js, postData);
   else if (!strcmp(wvrequest, "epgsearchsame")) success = jsonserver_epgsearchsame(js, postData);
   else if (!strcmp(wvrequest, "epgdownload")) success = jsonserver_epgdownload(js, postData);
+  else if (!strcmp(wvrequest, "epgsearch")) success = jsonserver_epgsearch(js, postData);
 
   if (!success) return 0; // the specific handler failed badly
 
@@ -1747,3 +1748,78 @@ bool jsonserver_epgdownload(Json::Value& js, const char* postData)
   js["Events"] = jsevents;
   return true;
 }
+
+bool jsonserver_epgsearch(Json::Value& js, const char* postData)
+{
+  Log* log = Log::getInstance();
+  log->log("JSONServer", Log::DEBUG, "epgsearch '%s'", postData);
+
+  char searchfor[1024]; int mgv1 = mg_get_var(postData, strlen(postData), "searchfor", searchfor, 1024);
+
+  if (mgv1 == -1)
+  {
+    log->log("JSONServer", Log::ERR, "request mgvs: %i", mgv1);
+    js["Result"] = false;
+    js["Error"] = "Bad request parameters";
+    return true;
+  }
+
+  log->log("JSONServer", Log::DEBUG, "search for: %s", searchfor);
+
+  cSchedulesLock MutexLock;
+  const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
+
+  if (!Schedules)
+  {
+    log->log("JSONServer", Log::ERR, "Could not get Schedules object");
+    js["Result"] = false;
+    js["Error"] = "Internal schedules error (1)";
+    return true;
+  }
+
+  Json::Value jsevents(Json::arrayValue);
+
+  for (cChannel* channel = Channels.First(); channel; channel = Channels.Next(channel))
+  {
+    if (channel->GroupSep()) continue;
+
+    const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
+    if (!Schedule) continue;
+
+    bool foundtitle;
+    bool founddescription;
+    for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
+    {
+      foundtitle = false;
+      founddescription = false;
+
+      if (event->Title() && strcasestr(event->Title(), searchfor)) foundtitle = true;
+
+      if (!foundtitle && event->Description())
+        if (strcasestr(event->Description(), searchfor)) founddescription = true;
+
+      if (foundtitle || founddescription)
+      {
+        Json::Value oneEvent;
+        oneEvent["ChannelNumber"] = channel->Number();
+        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() : "";
+        if (founddescription)
+          oneEvent["FoundInDesc"] = true;
+        else
+          oneEvent["FoundInDesc"] = false;
+        jsevents.append(oneEvent);
+      }
+    }
+  }
+
+  js["Result"] = true;
+  js["Events"] = jsevents;
+  return true;
+}
index c7836b85f74b0105e522da62425f029e1de577b1..92fb10dfef41d7bd27184dee0f30febe013ece6a 100644 (file)
--- a/handler.h
+++ b/handler.h
@@ -30,6 +30,7 @@ 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);
 bool jsonserver_epgdownload(Json::Value& js, const char* postData);
+bool jsonserver_epgsearch(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);