]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
htsp: add subscription entry also for DVR files, fixes #3854
authorJaroslav Kysela <perex@perex.cz>
Mon, 11 Sep 2017 12:20:53 +0000 (14:20 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 18 Sep 2017 13:13:49 +0000 (15:13 +0200)
src/htsp_server.c
src/subscriptions.c
src/subscriptions.h
src/webui/webui.c

index b1fe329d42400d93ebc42ebfcb495edd2f1f6927..1db4cd1e8d101bc0d6b188d298a6f8f67be99b14 100644 (file)
@@ -240,6 +240,7 @@ typedef struct htsp_file {
   int hf_fd;          // Our file descriptor
   char *hf_path;      // For logging
   uint32_t  hf_de_id; // Associated dvr entry
+  th_subscription_t *hf_subscription;
 } htsp_file_t;
 
 #define HTSP_DEFAULT_QUEUE_DEPTH 500000
@@ -728,6 +729,17 @@ htsp_file_open(htsp_connection_t *htsp, const char *path, int fd, dvr_entry_t *d
   hf->hf_id = ++htsp->htsp_file_id;
   hf->hf_path = strdup(path);
   hf->hf_de_id = de ? idnode_get_short_uuid(&de->de_id) : 0;
+
+  if (de) {
+    const char *charset = de->de_config ? de->de_config->dvr_charset_id : NULL;
+
+    hf->hf_subscription =
+      subscription_create_from_file("HTSP", charset, path,
+                                    htsp->htsp_peername,
+                                    htsp->htsp_granted_access->aa_representative,
+                                    htsp->htsp_clientname);
+  }
+
   LIST_INSERT_HEAD(&htsp->htsp_files, hf, hf_link);
 
   htsmsg_t *rep = htsmsg_create_map();
@@ -765,12 +777,24 @@ static void
 htsp_file_destroy(htsp_file_t *hf)
 {
   tvhdebug(LS_HTSP, "Closed opened file %s", hf->hf_path);
+  LIST_REMOVE(hf, hf_link);
+  if (hf->hf_subscription)
+    subscription_unsubscribe(hf->hf_subscription, UNSUBSCRIBE_FINAL);
   free(hf->hf_path);
   close(hf->hf_fd);
-  LIST_REMOVE(hf, hf_link);
   free(hf);
 }
 
+static void
+htsp_file_update_stats(htsp_file_t *hf, size_t len)
+{
+  th_subscription_t *ts = hf->hf_subscription;
+  if (ts) {
+    subscription_add_bytes_in(ts, len);
+    subscription_add_bytes_out(ts, len);
+  }
+}
+
 /* **************************************************************************
  * Output message generators
  * *************************************************************************/
@@ -2787,6 +2811,8 @@ htsp_method_file_read(htsp_connection_t *htsp, htsmsg_t *in)
     goto error;
   }
 
+  htsp_file_update_stats(hf, r);
+
   rep = htsmsg_create_map();
   htsmsg_add_bin(rep, "data", m, r);
   free(m);
index 03da4b1e78ffbc11a7337b2717db0094449d2573..17a654bd0012eef5b7f61e8bdc3e159038e5f898 100644 (file)
@@ -41,6 +41,7 @@
 #include "notify.h"
 #include "atomic.h"
 #include "input.h"
+#include "intlconv.h"
 #include "dbus.h"
 
 struct th_subscription_list subscriptions;
@@ -960,6 +961,39 @@ subscription_create_from_mux(profile_chain_t *prch,
 }
 #endif
 
+/**
+ *
+ */
+th_subscription_t *
+subscription_create_from_file(const char *name,
+                              const char *charset,
+                              const char *filename,
+                             const char *hostname,
+                             const char *username,
+                             const char *client)
+{
+  th_subscription_t *ts;
+  char *str, *url;
+
+  ts = subscription_create(NULL, 1, name,
+                           SUBSCRIPTION_NONE, NULL,
+                           hostname, username, client);
+  if (ts == NULL)
+    return NULL;
+  str = intlconv_to_utf8safestr(charset, filename, strlen(filename) * 3);
+  if (str == NULL)
+    str = intlconv_to_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
+                                  filename, strlen(filename) * 3);
+  if (str == NULL)
+    str = strdup("error");
+  url = malloc(strlen(str) + 7 + 1);
+  strcpy(url, "file://");
+  strcat(url, str);
+  ts->ths_dvrfile = url;
+  free(str);
+  return ts;
+}
+
 /* **************************************************************************
  * Status monitoring
  * *************************************************************************/
index 330f3bddb013b987457569aeda778ea74b7fb1a6..a79962615acbcd4d03b455dbb41d1d87d78256f7 100644 (file)
@@ -197,6 +197,14 @@ subscription_create_from_mux(struct profile_chain *prch,
                              int *error);
 #endif
 
+th_subscription_t *
+subscription_create_from_file(const char *name,
+                              const char *charset,
+                              const char *filename,
+                              const char *hostname,
+                              const char *username,
+                              const char *client);
+
 th_subscription_t *subscription_create(struct profile_chain *prch,
                                        int weight, const char *name,
                                       int flags, streaming_ops_t *ops,
index e9d03c9fc8b2ced3bc4d6d4a807807ebf59d56aa..ed74849bd09f8e0f3f5c26eeaa6a0a5f724fc7e1 100644 (file)
@@ -1694,32 +1694,19 @@ page_dvrfile_preop(http_connection_t *hc, off_t file_start,
                    size_t content_len, void *opaque)
 {
   page_dvrfile_priv_t *priv = opaque;
-  char *str, *basename;
   dvr_entry_t *de;
 
   pthread_mutex_lock(&global_lock);
   priv->tcp_id = http_stream_preop(hc);
   priv->sub = NULL;
   if (priv->tcp_id && !hc->hc_no_output && content_len > 64*1024) {
-    priv->sub = subscription_create(NULL, 1, "HTTP",
-                                    SUBSCRIPTION_NONE, NULL,
-                                    hc->hc_peer_ipstr, hc->hc_username,
-                                    http_arg_get(&hc->hc_args, "User-Agent"));
+    priv->sub = subscription_create_from_file("HTTP", priv->charset,
+                                              priv->fname, hc->hc_peer_ipstr,
+                                              hc->hc_username,
+                                              http_arg_get(&hc->hc_args, "User-Agent"));
     if (priv->sub == NULL) {
       http_stream_postop(priv->tcp_id);
       priv->tcp_id = NULL;
-    } else {
-      str = intlconv_to_utf8safestr(priv->charset, priv->fname, strlen(priv->fname) * 3);
-      if (str == NULL)
-        str = intlconv_to_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
-                                      priv->fname, strlen(priv->fname) * 3);
-      if (str == NULL)
-        str = strdup("error");
-      basename = malloc(strlen(str) + 7 + 1);
-      strcpy(basename, "file://");
-      strcat(basename, str);
-      priv->sub->ths_dvrfile = basename;
-      free(str);
     }
   }
   /* Play count + 1 when write access */