From 444c0ae39c5d575062e2cb365eb9b0a7b4b65562 Mon Sep 17 00:00:00 2001
From: Chris Tallon <chris@vomp.tv>
Date: Fri, 8 Jan 2016 15:26:44 +0000
Subject: [PATCH] Add recording reset-resume call

---
 handler.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 handler.h |  1 +
 2 files changed, 47 insertions(+)
 mode change 100644 => 100755 handler.h

diff --git a/handler.c b/handler.c
index 2af3c2c..9690bc8 100755
--- a/handler.c
+++ b/handler.c
@@ -76,6 +76,7 @@ int jsonserver_request_handler(struct mg_connection *conn)
   else if (!strcmp(wvrequest, "recmove")) success = jsonserver_recmove(js, postData);
   else if (!strcmp(wvrequest, "recrename")) success = jsonserver_recrename(js, postData);
   else if (!strcmp(wvrequest, "recstop")) success = jsonserver_recstop(js, postData);
+  else if (!strcmp(wvrequest, "recresetresume")) success = jsonserver_recresetresume(js, postData);
   else if (!strcmp(wvrequest, "channellist")) success = jsonserver_channellist(js);
   else if (!strcmp(wvrequest, "channelschedule")) success = jsonserver_channelschedule(js, postData);
   else if (!strcmp(wvrequest, "getscheduleevent")) success = jsonserver_getscheduleevent(js, postData);
@@ -800,6 +801,51 @@ bool jsonserver_recrename(Json::Value& js, const char* postData)
   return true;
 }
 
+bool jsonserver_recresetresume(Json::Value& js, const char* postData)
+{
+  Log* log = Log::getInstance();
+  log->log("JSONServer", Log::DEBUG, "recresetresume");
+
+  char reqfilename[1000];
+  int mgv1 = mg_get_var(postData, strlen(postData), "filename", reqfilename, 1000);
+  if (mgv1 == -1)
+  {
+    log->log("JSONServer", Log::ERR, "Could not decode filename");
+    js["Result"] = false;
+    js["Error"] = "Could not decode filename";
+    return true;
+  }
+
+  log->log("JSONServer", Log::DEBUG, "%s", reqfilename);
+
+  cRecordings Recordings;
+  Recordings.Load(); // probably have to do this
+  cRecording *recording = Recordings.GetByName(reqfilename);
+
+  if (!recording)
+  {
+    js["Result"] = false;
+    js["Error"] = "Could not find recording to reset resume";
+    return true;
+  }
+
+  log->log("JSONServer", Log::DEBUG, "Reset resume for: %s", recording->Name());
+
+  cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording());
+  if (ResumeFile.Read() >= 0)
+  {
+    ResumeFile.Delete();
+    js["Result"] = true;
+    return true;
+  }
+  else
+  {
+    js["Result"] = false;
+    js["Error"] = "Recording has no resume point";
+    return true;
+  }
+}
+
 bool jsonserver_channellist(Json::Value& js)
 {
   Log* log = Log::getInstance();
diff --git a/handler.h b/handler.h
old mode 100644
new mode 100755
index 4d39a25..32ce1e6
--- a/handler.h
+++ b/handler.h
@@ -17,6 +17,7 @@ bool jsonserver_recdel(Json::Value& js, const char* postData);
 bool jsonserver_recmove(Json::Value& js, const char* postData);
 bool jsonserver_recrename(Json::Value& js, const char* postData);
 bool jsonserver_recstop(Json::Value& js, const char* postData);
+bool jsonserver_recresetresume(Json::Value& js, const char* postData);
 bool jsonserver_channellist(Json::Value& js);
 bool jsonserver_channelschedule(Json::Value& js, const char* postData);
 bool jsonserver_getscheduleevent(Json::Value& js, const char* postData);
-- 
2.39.5