From 330a3173ba528bd95f33247e78a507c5b8162055 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Fri, 7 Jun 2013 20:50:21 +0100 Subject: [PATCH] Timer del rewrite --- handler.c | 150 ++++++++++++++++++++++++------------------------------ 1 file changed, 67 insertions(+), 83 deletions(-) diff --git a/handler.c b/handler.c index 7416b27..a32a88b 100644 --- a/handler.c +++ b/handler.c @@ -841,7 +841,8 @@ bool jsonserver_timerlist(Json::Value& js) oneTimer["Day"] = (int)timer->Day(); oneTimer["WeekDays"] = timer->WeekDays(); oneTimer["Name"] = timer->File(); - + oneTimer["ToText"] = (const char *)timer->ToText(true); + const cEvent* event = timer->Event(); if (event) { @@ -852,7 +853,6 @@ bool jsonserver_timerlist(Json::Value& js) int channelNumber = timer->Channel()->Number(); int aroundTime = timer->StartTime() + 1; log->log("JSONServer", Log::DEBUG, "%i", aroundTime); - //((timer->StopTime() - timer->StartTime()) / 2); const cEvent* eventAround = jsonserver_getEvent(js, channelNumber, 0, aroundTime); if (eventAround) @@ -873,72 +873,6 @@ bool jsonserver_timerlist(Json::Value& js) return true; } -bool jsonserver_timerdel(Json::Value& js, const char* postData) -{ - Log* log = Log::getInstance(); - log->log("JSONServer", Log::DEBUG, "timerdel"); - - char sdelChannel[15]; int mgv1 = mg_get_var(postData, strlen(postData), "delchannel", sdelChannel, 15); - char sdelWeekdays[15]; int mgv2 = mg_get_var(postData, strlen(postData), "delweekdays", sdelWeekdays, 15); - char sdelDay[15]; int mgv3 = mg_get_var(postData, strlen(postData), "delday", sdelDay, 15); - char sdelStart[15]; int mgv4 = mg_get_var(postData, strlen(postData), "delstart", sdelStart, 15); - char sdelStop[15]; int mgv5 = mg_get_var(postData, strlen(postData), "delstop", sdelStop, 15); - - if ( (mgv1 == -1) || (mgv2 == -1) || (mgv3 == -1) || (mgv4 == -1) || (mgv5 == -1) ) - { - log->log("JSONServer", Log::ERR, "request mgvs: %i %i %i %i %i", mgv1, mgv2, mgv3, mgv4, mgv5); - js["Result"] = false; - js["Error"] = "Bad request parameters"; - return true; - } - - int delChannel = atoi(sdelChannel); - int delWeekdays = atoi(sdelWeekdays); - int delDay = atoi(sdelDay); - int delStart = atoi(sdelStart); - int delStop = atoi(sdelStop); - - cTimer* ti = NULL; - for (ti = Timers.First(); ti; ti = Timers.Next(ti)) - { - if ( (ti->Channel()->Number() == delChannel) - && ((ti->WeekDays() && (ti->WeekDays() == delWeekdays)) || (!ti->WeekDays() && (ti->Day() == delDay))) - && (ti->StartTime() == delStart) - && (ti->StopTime() == delStop) ) - break; - } - - if (!ti) - { - log->log("JSONServer", Log::ERR, "Could not find timer"); - js["Result"] = false; - js["Error"] = "Could not find timer"; - return true; - } - - if (Timers.BeingEdited()) - { - log->log("JSONServer", Log::ERR, "Unable to delete timer - timers being edited at VDR"); - js["Result"] = false; - js["Error"] = "Timers being edited at VDR"; - return true; - } - - if (ti->Recording()) - { - log->log("JSONServer", Log::ERR, "Unable to delete timer - timer is running"); - js["Result"] = false; - js["Error"] = "Timer is running"; - return true; - } - - Timers.Del(ti); - Timers.SetModified(); - js["Result"] = true; - - return true; -} - bool jsonserver_timerset(Json::Value& js, const char* postData) { Log* log = Log::getInstance(); @@ -984,33 +918,26 @@ bool jsonserver_timersetactive(Json::Value& js, const char* postData) Log* log = Log::getInstance(); log->log("JSONServer", Log::DEBUG, "timersetactive"); - char tChannelID[30]; int mgv1 = mg_get_var(postData, strlen(postData), "ChannelID", tChannelID, 30); - char tStartTime[15]; int mgv2 = mg_get_var(postData, strlen(postData), "StartTime", tStartTime, 15); - char tStopTime[15]; int mgv3 = mg_get_var(postData, strlen(postData), "StopTime", tStopTime, 15); - char tNewActive[15]; int mgv4 = mg_get_var(postData, strlen(postData), "SetActive", tNewActive, 15); + char tToText[1024]; int mgv1 = mg_get_var(postData, strlen(postData), "ToText", tToText, 1024); + char tNewActive[15]; int mgv2 = mg_get_var(postData, strlen(postData), "SetActive", tNewActive, 15); - if ( (mgv1 == -1) || (mgv2 == -1) || (mgv3 == -1) || (mgv4 == -1) ) + if ( (mgv1 == -1) || (mgv2 == -1) ) { - log->log("JSONServer", Log::ERR, "request mgvs: %i %i %i %i", mgv1, mgv2, mgv3, mgv4); + log->log("JSONServer", Log::ERR, "request mgvs: %i %i", mgv1, mgv2); js["Result"] = false; js["Error"] = "Bad request parameters"; return true; } - log->log("JSONServer", Log::DEBUG, "timersetactive: %s %s %s %s", tChannelID, tStartTime, tStopTime, tNewActive); - - int StartTime = atoi(tStartTime); - int StopTime = atoi(tStopTime); + log->log("JSONServer", Log::DEBUG, "timersetactive: %s %s", tToText, tNewActive); cTimer *timer; int numTimers = Timers.Count(); for (int i = 0; i < numTimers; i++) { timer = Timers.Get(i); - if ( (strcmp(timer->Channel()->GetChannelID().ToString(), tChannelID) == 0) - && (timer->StartTime() == StartTime) - && (timer->StopTime() == StopTime) - ) + + if (strcmp(timer->ToText(true), tToText) == 0) { // Found @@ -1028,9 +955,12 @@ bool jsonserver_timersetactive(Json::Value& js, const char* postData) js["Error"] = "Bad request parameters"; return true; } + + js["ToText"] = (const char*)timer->ToText(true); + js["Result"] = true; + Timers.SetModified(); - js["Result"] = true; return true; } } @@ -1039,3 +969,57 @@ bool jsonserver_timersetactive(Json::Value& js, const char* postData) js["Error"] = "Timer not found"; return true; } + +bool jsonserver_timerdel(Json::Value& js, const char* postData) +{ + Log* log = Log::getInstance(); + log->log("JSONServer", Log::DEBUG, "timerdel"); + + char tToText[1024]; int mgv1 = mg_get_var(postData, strlen(postData), "ToText", tToText, 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, "timerdel: %s", tToText); + + if (Timers.BeingEdited()) + { + log->log("JSONServer", Log::ERR, "Unable to delete timer - timers being edited at VDR"); + js["Result"] = false; + js["Error"] = "Timers being edited at VDR"; + return true; + } + + cTimer* ti = NULL; + for (ti = Timers.First(); ti; ti = Timers.Next(ti)) + { + if (strcmp(ti->ToText(true), tToText) == 0) + { + // Found + + if (ti->Recording()) + { + log->log("JSONServer", Log::ERR, "Unable to delete timer - timer is running"); + js["Result"] = false; + js["Error"] = "Timer is running"; + return true; + } + + // delete + + Timers.Del(ti); + Timers.SetModified(); + js["Result"] = true; + return true; + } + } + + js["Result"] = false; + js["Error"] = "Timer not found"; + return true; +} -- 2.39.5