From 840a0ae05c9c9dc8f58747c4c48e0cfe84651207 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 8 Aug 2014 17:19:33 +0200 Subject: [PATCH] dbus: SAT>IP allow to block the server by IP address --- src/dbus.c | 3 ++ src/input/mpegts/satip/satip.c | 41 +++++++++++++++++++++++++ src/input/mpegts/satip/satip_frontend.c | 1 + src/input/mpegts/satip/satip_private.h | 1 + 4 files changed, 46 insertions(+) diff --git a/src/dbus.c b/src/dbus.c index 57ba1600..a827f6e7 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -227,6 +227,9 @@ dbus_reply_to_rpc(dbus_rpc_t *rpc, DBusMessage *msg, DBusConnection *conn) path = dbus_message_get_path(msg); if (path == NULL) return; + if (strncmp(path, "/org/tvheadend/", 15)) + return; + path += 14; if (!dbus_message_iter_init(msg, &args)) return; if (rpc->rpc_s64) { diff --git a/src/input/mpegts/satip/satip.c b/src/input/mpegts/satip/satip.c index 7c32efee..28cb2dc8 100644 --- a/src/input/mpegts/satip/satip.c +++ b/src/input/mpegts/satip/satip.c @@ -55,6 +55,46 @@ satip_device_dbus_notify( satip_device_t *sd, const char *sig_name ) #endif } +static void +satip_device_block( const char *addr, int block ) +{ + extern const idclass_t satip_device_class; + tvh_hardware_t *th; + satip_device_t *sd; + satip_frontend_t *lfe; + + pthread_mutex_lock(&global_lock); + TVH_HARDWARE_FOREACH(th) { + if (!idnode_is_instance(&th->th_id, &satip_device_class)) + continue; + sd = (satip_device_t *)th; + if (strcmp(sd->sd_info.addr, addr) == 0) { + sd->sd_dbus_block = block < 0 ? 0 : block; + if (block < 0) { + TAILQ_FOREACH(lfe, &sd->sd_frontends, sf_link) + mpegts_input_stop_all((mpegts_input_t *)lfe); + } + } + } + pthread_mutex_unlock(&global_lock); +} + +static char * +satip_device_addr( void *aux, const char *path, char *value ) +{ + if (strcmp(path, "/stop") == 0) { + satip_device_block(value, -1); + return strdup("ok"); + } else if (strcmp(path, "/disable") == 0) { + satip_device_block(value, 0); + return strdup("ok"); + } else if (strcmp(path, "/allow") == 0) { + satip_device_block(value, 1); + return strdup("ok"); + } + return strdup("err"); +} + /* * SAT-IP client */ @@ -978,6 +1018,7 @@ void satip_init ( str_list_t *clients ) { TAILQ_INIT(&satip_discoveries); satip_static_clients = clients; + dbus_register_rpc_str("satip_addr", NULL, satip_device_addr); satip_device_discovery_start(); } diff --git a/src/input/mpegts/satip/satip_frontend.c b/src/input/mpegts/satip/satip_frontend.c index 3413571e..d746de22 100644 --- a/src/input/mpegts/satip/satip_frontend.c +++ b/src/input/mpegts/satip/satip_frontend.c @@ -376,6 +376,7 @@ satip_frontend_is_enabled ( mpegts_input_t *mi, mpegts_mux_t *mm, lock_assert(&global_lock); if (!mpegts_input_is_enabled(mi, mm, reason)) return 0; + if (lfe->sf_device->sd_dbus_block) return 0; if (lfe->sf_type != DVB_TYPE_S) return 1; /* check if the position is enabled */ position = satip_satconf_get_position(lfe, mm); diff --git a/src/input/mpegts/satip/satip_private.h b/src/input/mpegts/satip/satip_private.h index 563d0fb4..595eecf5 100644 --- a/src/input/mpegts/satip/satip_private.h +++ b/src/input/mpegts/satip/satip_private.h @@ -81,6 +81,7 @@ struct satip_device int sd_sig_scale; int sd_pids0; int sd_pilot_on; + int sd_dbus_block; pthread_mutex_t sd_tune_mutex; };