From 5482182c80111c6da29628aff0d3007cd0054d2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Dembski?= <gymlet@gmx.de>
Date: Fri, 7 Jan 2011 12:21:16 +0100
Subject: [PATCH 1/2] Feature: Add the possibility to update timers via HTSP

---
 src/dvr/dvr.h    |  2 ++
 src/dvr/dvr_db.c | 20 ++++++++++++++++++++
 src/htsp.c       | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/src/dvr/dvr.h b/src/dvr/dvr.h
index 888fc986..ed22ea28 100644
--- a/src/dvr/dvr.h
+++ b/src/dvr/dvr.h
@@ -242,6 +242,8 @@ dvr_entry_t *dvr_entry_create(const char *dvr_config_name,
 			      epg_episode_t *ee, uint8_t content_type,
 			      dvr_prio_t pri);
 
+dvr_entry_t *dvr_entry_update(dvr_entry_t *de, const char* de_title, int de_start, int de_stop);
+
 void dvr_init(void);
 
 void dvr_autorec_init(void);
diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c
index c7933c62..e777066f 100644
--- a/src/dvr/dvr_db.c
+++ b/src/dvr/dvr_db.c
@@ -589,6 +589,26 @@ dvr_timer_expire(void *aux)
  
 }
 
+/**
+ *
+ */
+dvr_entry_t * 
+dvr_entry_update(dvr_entry_t *de, const char* de_title, int de_start, int de_stop) 
+{
+
+  de->de_title = strdup(de_title);
+  de->de_start = de_start;
+  de->de_stop = de_stop;
+
+  dvr_entry_save(de);
+  htsp_dvr_entry_update(de);
+  dvr_entry_notify(de);
+
+
+  tvhlog(LOG_INFO, "dvr", "\"%s\" on \"%s\": Updated Timer", de->de_title, de->de_channel->ch_name);
+
+  return de;
+}
 
 /**
  *
diff --git a/src/htsp.c b/src/htsp.c
index 9a49ad21..b71f4c3e 100644
--- a/src/htsp.c
+++ b/src/htsp.c
@@ -534,6 +534,45 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
   return out;
 }
 
+/**
+ * update a Dvrentry
+ */
+static htsmsg_t *
+htsp_method_updateDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
+{
+  htsmsg_t *out;
+  uint32_t dvrEntryId;
+  dvr_entry_t *de;
+  uint32_t start;
+  uint32_t stop;
+  const char *title = NULL;
+    
+  if(htsmsg_get_u32(in, "id", &dvrEntryId))
+    return htsp_error("Missing argument 'id'");
+
+  if(htsmsg_get_u32(in, "start", &start))
+    return htsp_error("Missing argument 'start'");
+  
+  if(htsmsg_get_u32(in, "stop", &stop))
+    return htsp_error("Missing argument 'stop'");
+
+  title = htsmsg_get_str(in, "title");
+  if (title == NULL)
+    return htsp_error("Missing argument 'title'");
+  
+
+  if( (de = dvr_entry_find_by_id(dvrEntryId)) == NULL) 
+    return htsp_error("id not found");
+
+  de = dvr_entry_update(de, title, start, stop);
+
+  //create response
+  out = htsmsg_create_map();
+  htsmsg_add_u32(out, "success", 1);
+  
+  return out;
+}
+
 /**
  * delete a Dvrentry
  */
@@ -925,6 +964,7 @@ struct {
   { "unsubscribe", htsp_method_unsubscribe, ACCESS_STREAMING},
   { "subscriptionChangeWeight", htsp_method_change_weight, ACCESS_STREAMING},
   { "addDvrEntry", htsp_method_addDvrEntry, ACCESS_RECORDER},
+  { "updateDvrEntry", htsp_method_updateDvrEntry, ACCESS_RECORDER},
   { "deleteDvrEntry", htsp_method_deleteDvrEntry, ACCESS_RECORDER},
   { "epgQuery", htsp_method_epgQuery, ACCESS_STREAMING},
 

From cc414cc6bc19e12368e3103bae8e2fd5ec99e583 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Dembski?= <gymlet@gmx.de>
Date: Fri, 7 Jan 2011 14:30:17 +0100
Subject: [PATCH 2/2] Change the dvr_entry_update function so that it will
 update the entry even if only one of start, stop or title has been send via
 htsp

---
 src/htsp.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/htsp.c b/src/htsp.c
index b71f4c3e..4429e6fb 100644
--- a/src/htsp.c
+++ b/src/htsp.c
@@ -549,20 +549,19 @@ htsp_method_updateDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
     
   if(htsmsg_get_u32(in, "id", &dvrEntryId))
     return htsp_error("Missing argument 'id'");
+  
+  if( (de = dvr_entry_find_by_id(dvrEntryId)) == NULL) 
+    return htsp_error("id not found");
 
   if(htsmsg_get_u32(in, "start", &start))
-    return htsp_error("Missing argument 'start'");
+    start = de->de_start;
   
   if(htsmsg_get_u32(in, "stop", &stop))
-    return htsp_error("Missing argument 'stop'");
+    stop = de->de_stop;
 
   title = htsmsg_get_str(in, "title");
   if (title == NULL)
-    return htsp_error("Missing argument 'title'");
-  
-
-  if( (de = dvr_entry_find_by_id(dvrEntryId)) == NULL) 
-    return htsp_error("id not found");
+    title = de->de_title;
 
   de = dvr_entry_update(de, title, start, stop);