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
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();
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
* *************************************************************************/
goto error;
}
+ htsp_file_update_stats(hf, r);
+
rep = htsmsg_create_map();
htsmsg_add_bin(rep, "data", m, r);
free(m);
#include "notify.h"
#include "atomic.h"
#include "input.h"
+#include "intlconv.h"
#include "dbus.h"
struct th_subscription_list subscriptions;
}
#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
* *************************************************************************/
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,
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 */