summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2020-12-03 01:31:35 +0100
committerJens Georg <mail@jensge.org>2020-12-03 01:31:35 +0100
commitfd64b9c52051db2e8433162ccebc71c785a4fd0a (patch)
tree2de3b1d291cdc4b845c4f2810615faf8d0a81e39
parent4a19b4ce01dc963de040743b23649a42a8bed5b8 (diff)
downloadgupnp-fd64b9c52051db2e8433162ccebc71c785a4fd0a.tar.gz
Revert "white_list -> context_filter"
This reverts commit 312fd2eac51349c5b1535bf93a48033d09a77d49. Accidental push
-rw-r--r--libgupnp/gupnp-context-filter.c12
-rw-r--r--libgupnp/gupnp-context-manager.c174
-rw-r--r--libgupnp/gupnp-context-manager.h10
-rw-r--r--libgupnp/gupnp.h13
-rw-r--r--libgupnp/meson.build2
-rw-r--r--tests/test-white-list.c57
6 files changed, 129 insertions, 139 deletions
diff --git a/libgupnp/gupnp-context-filter.c b/libgupnp/gupnp-context-filter.c
index c3debac..d23e67d 100644
--- a/libgupnp/gupnp-context-filter.c
+++ b/libgupnp/gupnp-context-filter.c
@@ -20,7 +20,7 @@
*/
/**
- * SECTION:gupnp-context-filter
+ * SECTION:gupnp-white-list
* @short_description: Class for network filtering.
*
* #GUPnPContextFilter handles network filtering. It provides API to manage a
@@ -31,10 +31,10 @@
* Since: 0.20.5
*/
-#include "gupnp-context-filter.h"
-
#include <string.h>
+#include "gupnp-white-list.h"
+
struct _GUPnPContextFilterPrivate {
gboolean enabled;
GList *entries;
@@ -151,7 +151,7 @@ gupnp_context_filter_class_init (GUPnPContextFilterClass *klass)
/**
* GUPnPContextFilter:enabled:
*
- * Whether this context filter is active or not.
+ * Whether this white list is active or not.
*
* Since: 0.20.5
**/
@@ -160,7 +160,7 @@ gupnp_context_filter_class_init (GUPnPContextFilterClass *klass)
PROP_ENABLED,
g_param_spec_boolean ("enabled",
"Enabled",
- "TRUE if the context filter is active.",
+ "TRUE if the white list is active.",
FALSE,
G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
@@ -394,7 +394,7 @@ gupnp_context_filter_get_entries (GUPnPContextFilter *context_filter)
*
* Remove all entries from #GList that compose the white list.
* The list is now empty. Even if #GUPnPContextFilter is enabled, it will have
- * the same behavior as if it was disabled.
+ *the same behavior as if it was disabled.
*
* Since: 0.20.5
**/
diff --git a/libgupnp/gupnp-context-manager.c b/libgupnp/gupnp-context-manager.c
index 4f78bf4..c6e34a0 100644
--- a/libgupnp/gupnp-context-manager.c
+++ b/libgupnp/gupnp-context-manager.c
@@ -72,9 +72,9 @@ struct _GUPnPContextManagerPrivate {
GUPnPContextManager *impl;
GList *objects; /* control points and root devices */
- GList *filtered; /* Filtered contexts */
+ GList *blacklisted; /* Blacklisted Context */
- GUPnPContextFilter *context_filter;
+ GUPnPWhiteList *white_list;
};
typedef struct _GUPnPContextManagerPrivate GUPnPContextManagerPrivate;
@@ -82,13 +82,12 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GUPnPContextManager,
gupnp_context_manager,
G_TYPE_OBJECT);
-enum
-{
+enum {
PROP_0,
PROP_PORT,
PROP_SOCKET_FAMILY,
PROP_UDA_VERSION,
- PROP_CONTEXT_FILTER
+ PROP_WHITE_LIST
};
enum {
@@ -119,19 +118,19 @@ on_context_available (GUPnPContextManager *manager,
GUPnPContext *context,
G_GNUC_UNUSED gpointer *user_data)
{
- GUPnPContextFilter *context_filter;
+ GUPnPWhiteList *white_list;
GUPnPContextManagerPrivate *priv;
gboolean enabled = TRUE;
priv = gupnp_context_manager_get_instance_private (manager);
- context_filter = priv->context_filter;
+ white_list = priv->white_list;
/* Try to catch the notification, only if the white list
* is enabled, not empty and the context doesn't match */
- if (!gupnp_context_filter_is_empty (context_filter) &&
- gupnp_context_filter_get_enabled (context_filter) &&
- !gupnp_context_filter_check_context (context_filter, context)) {
+ if (!gupnp_white_list_is_empty (white_list) &&
+ gupnp_white_list_get_enabled (white_list) &&
+ !gupnp_white_list_check_context (white_list, context)) {
/* If the conext doesn't match, block the notification
* and disable the context */
g_signal_stop_emission_by_name (manager, "context-available");
@@ -141,8 +140,8 @@ on_context_available (GUPnPContextManager *manager,
enabled = FALSE;
/* Save it in case we need to re-enable it */
- priv->filtered =
- g_list_prepend (priv->filtered, g_object_ref (context));
+ priv->blacklisted = g_list_prepend (priv->blacklisted,
+ g_object_ref (context));
}
/* Ignore the boot-id handling for UDA 1.0 */
@@ -177,7 +176,7 @@ on_context_unavailable (GUPnPContextManager *manager,
G_GNUC_UNUSED gpointer *user_data)
{
GList *l;
- GList *filtered_context;
+ GList *black;
GUPnPContextManagerPrivate *priv;
priv = gupnp_context_manager_get_instance_private (manager);
@@ -218,14 +217,14 @@ on_context_unavailable (GUPnPContextManager *manager,
}
}
- filtered_context = g_list_find (priv->filtered, context);
+ black = g_list_find (priv->blacklisted, context);
- if (filtered_context != NULL) {
+ if (black != NULL) {
g_signal_stop_emission_by_name (manager, "context-unavailable");
- g_object_unref (filtered_context->data);
- priv->filtered =
- g_list_delete_link (priv->filtered, filtered_context);
+ g_object_unref (black->data);
+ priv->blacklisted = g_list_delete_link (priv->blacklisted,
+ black);
} else {
/* When UDA 1.0, ignore boot-id handling */
if (priv->uda_version > GSSDP_UDA_VERSION_1_0) {
@@ -251,20 +250,20 @@ on_context_unavailable (GUPnPContextManager *manager,
}
static void
-gupnp_context_manager_filter_context (GUPnPContextFilter *context_filter,
+gupnp_context_manager_filter_context (GUPnPWhiteList *white_list,
GUPnPContextManager *manager,
gboolean check)
{
GList *next;
GList *obj;
- GList *iter;
+ GList *blk;
gboolean match;
GUPnPContextManagerPrivate *priv;
priv = gupnp_context_manager_get_instance_private (manager);
obj = priv->objects;
- iter = priv->filtered;
+ blk = priv->blacklisted;
while (obj != NULL) {
/* If the white list is empty, treat it as disabled */
@@ -280,9 +279,8 @@ gupnp_context_manager_filter_context (GUPnPContextFilter *context_filter,
property, &context,
NULL);
- match = gupnp_context_filter_check_context (
- context_filter,
- context);
+ match = gupnp_white_list_check_context (white_list,
+ context);
} else {
/* Re-activate all context, if needed */
match = TRUE;
@@ -304,67 +302,65 @@ gupnp_context_manager_filter_context (GUPnPContextFilter *context_filter,
obj = obj->next;
}
- while (iter != NULL) {
+ while (blk != NULL) {
/* If the white list is empty, treat it as disabled */
if (check)
/* Filter out context */
- match = gupnp_context_filter_check_context (
- context_filter,
- iter->data);
+ match = gupnp_white_list_check_context (white_list,
+ blk->data);
else
/* Re-activate all context, if needed */
match = TRUE;
if (!match) {
- iter = iter->next;
+ blk = blk->next;
continue;
}
- next = iter->next;
- g_object_set (iter->data, "active", TRUE, NULL);
+ next = blk->next;
+ g_object_set (blk->data, "active", TRUE, NULL);
- g_signal_emit_by_name (manager,
- "context-available",
- iter->data);
+ g_signal_emit_by_name (manager, "context-available", blk->data);
- g_object_unref (iter->data);
- priv->filtered = g_list_delete_link (priv->filtered, iter);
- iter = next;
+ g_object_unref (blk->data);
+ priv->blacklisted = g_list_delete_link (priv->blacklisted,
+ blk);
+ blk = next;
}
}
static void
-on_context_filter_change_cb (GUPnPContextFilter *context_filter,
- GParamSpec *pspec,
- gpointer user_data)
+on_white_list_change_cb (GUPnPWhiteList *white_list,
+ GParamSpec *pspec,
+ gpointer user_data)
{
GUPnPContextManager *manager = GUPNP_CONTEXT_MANAGER (user_data);
gboolean enabled;
gboolean is_empty;
- enabled = gupnp_context_filter_get_enabled (context_filter);
- is_empty = gupnp_context_filter_is_empty (context_filter);
+ enabled = gupnp_white_list_get_enabled (white_list);
+ is_empty = gupnp_white_list_is_empty (white_list);
if (enabled)
- gupnp_context_manager_filter_context (context_filter,
+ gupnp_context_manager_filter_context (white_list,
manager,
!is_empty);
}
static void
-on_context_filter_enabled_cb (GUPnPContextFilter *context_filter,
- GParamSpec *pspec,
- gpointer user_data)
+on_white_list_enabled_cb (GUPnPWhiteList *white_list,
+ GParamSpec *pspec,
+ gpointer user_data)
{
GUPnPContextManager *manager = GUPNP_CONTEXT_MANAGER (user_data);
gboolean enabled;
gboolean is_empty;
- enabled = gupnp_context_filter_get_enabled (context_filter);
- is_empty = gupnp_context_filter_is_empty (context_filter);
+ enabled = gupnp_white_list_get_enabled (white_list);
+ is_empty = gupnp_white_list_is_empty (white_list);
if (!is_empty)
- gupnp_context_manager_filter_context (context_filter,
+ gupnp_context_manager_filter_context (white_list,
manager,
enabled);
}
@@ -376,17 +372,13 @@ gupnp_context_manager_init (GUPnPContextManager *manager)
priv = gupnp_context_manager_get_instance_private (manager);
- priv->context_filter = gupnp_context_filter_new ();
+ priv->white_list = gupnp_white_list_new ();
- g_signal_connect_after (priv->context_filter,
- "notify::entries",
- G_CALLBACK (on_context_filter_change_cb),
- manager);
+ g_signal_connect_after (priv->white_list, "notify::entries",
+ G_CALLBACK (on_white_list_change_cb), manager);
- g_signal_connect_after (priv->context_filter,
- "notify::enabled",
- G_CALLBACK (on_context_filter_enabled_cb),
- manager);
+ g_signal_connect_after (priv->white_list, "notify::enabled",
+ G_CALLBACK (on_white_list_enabled_cb), manager);
priv->boot_id = time(NULL);
}
@@ -440,8 +432,8 @@ gupnp_context_manager_get_property (GObject *object,
case PROP_UDA_VERSION:
g_value_set_enum (value, priv->uda_version);
break;
- case PROP_CONTEXT_FILTER:
- g_value_set_object (value, priv->context_filter);
+ case PROP_WHITE_LIST:
+ g_value_set_object (value, priv->white_list);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -453,29 +445,32 @@ static void
gupnp_context_manager_dispose (GObject *object)
{
GUPnPContextManager *manager;
- GUPnPContextFilter *filter;
+ GUPnPWhiteList *wl;
GObjectClass *object_class;
GUPnPContextManagerPrivate *priv;
manager = GUPNP_CONTEXT_MANAGER (object);
priv = gupnp_context_manager_get_instance_private (manager);
- filter = priv->context_filter;
+ wl = priv->white_list;
- g_signal_handlers_disconnect_by_func (filter,
- on_context_filter_enabled_cb,
+ g_signal_handlers_disconnect_by_func (wl,
+ on_white_list_enabled_cb,
manager);
- g_signal_handlers_disconnect_by_func (filter,
- on_context_filter_change_cb,
+ g_signal_handlers_disconnect_by_func (wl,
+ on_white_list_change_cb,
NULL);
g_list_free_full (priv->objects, g_object_unref);
priv->objects = NULL;
- g_list_free_full (priv->filtered, g_object_unref);
- priv->filtered = NULL;
+ g_list_free_full (priv->blacklisted, g_object_unref);
+ priv->blacklisted = NULL;
- g_clear_object (&filter);
+ if (wl) {
+ g_object_unref (wl);
+ priv->white_list = NULL;
+ }
/* Call super */
object_class = G_OBJECT_CLASS (gupnp_context_manager_parent_class);
@@ -552,23 +547,24 @@ gupnp_context_manager_class_init (GUPnPContextManagerClass *klass)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
- /**
- * GUPnPContextManager:context-filter:
+ /**
+ * GUPnPContextManager:white-list:
*
* The white list to use.
**/
- g_object_class_install_property (
- object_class,
- PROP_CONTEXT_FILTER,
- g_param_spec_object ("context-filter",
- "Context Filter",
- "The Context Filter to use",
- GUPNP_TYPE_CONTEXT_FILTER,
- G_PARAM_READABLE | G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB));
-
- /**
+ g_object_class_install_property
+ (object_class,
+ PROP_WHITE_LIST,
+ g_param_spec_object ("white-list",
+ "White List",
+ "The white list to use",
+ GUPNP_TYPE_WHITE_LIST,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ /**
* GUPnPContextManager::context-available:
* @context_manager: The #GUPnPContextManager that received the signal
* @context: The now available #GUPnPContext
@@ -818,16 +814,16 @@ gupnp_context_manager_get_port (GUPnPContextManager *manager)
}
/**
- * gupnp_context_manager_get_context_filter:
+ * gupnp_context_manager_get_white_list:
* @manager: A #GUPnPContextManager
*
- * Get the #GUPnPContextFilter associated with @manager.
+ * Get the #GUPnPWhiteList associated with @manager.
*
- * Returns: (transfer none): The #GUPnPContextFilter asssociated with this
+ * Returns: (transfer none): The #GUPnPWhiteList asssociated with this
* context manager.
*/
-GUPnPContextFilter *
-gupnp_context_manager_get_context_filter (GUPnPContextManager *manager)
+GUPnPWhiteList *
+gupnp_context_manager_get_white_list (GUPnPContextManager *manager)
{
GUPnPContextManagerPrivate *priv;
@@ -835,7 +831,7 @@ gupnp_context_manager_get_context_filter (GUPnPContextManager *manager)
priv = gupnp_context_manager_get_instance_private (manager);
- return priv->context_filter;
+ return priv->white_list;
}
/**
diff --git a/libgupnp/gupnp-context-manager.h b/libgupnp/gupnp-context-manager.h
index a4860ce..9c39715 100644
--- a/libgupnp/gupnp-context-manager.h
+++ b/libgupnp/gupnp-context-manager.h
@@ -24,11 +24,11 @@
#ifndef GUPNP_CONTEXT_MANAGER_H
#define GUPNP_CONTEXT_MANAGER_H
-#include "gupnp-context-filter.h"
+#include <glib.h>
#include "gupnp-context.h"
-#include "gupnp-control-point.h"
#include "gupnp-root-device.h"
-#include <glib.h>
+#include "gupnp-control-point.h"
+#include "gupnp-white-list.h"
G_BEGIN_DECLS
@@ -76,8 +76,8 @@ gupnp_context_manager_manage_root_device
guint
gupnp_context_manager_get_port (GUPnPContextManager *manager);
-GUPnPContextFilter *
-gupnp_context_manager_get_context_filter (GUPnPContextManager *manager);
+GUPnPWhiteList *
+gupnp_context_manager_get_white_list (GUPnPContextManager *manager);
GSocketFamily
gupnp_context_manager_get_socket_family (GUPnPContextManager *manager);
diff --git a/libgupnp/gupnp.h b/libgupnp/gupnp.h
index bc23c1e..606cc03 100644
--- a/libgupnp/gupnp.h
+++ b/libgupnp/gupnp.h
@@ -20,21 +20,20 @@
*/
#include <libgupnp/gupnp-acl.h>
-#include <libgupnp/gupnp-context-filter.h>
-#include <libgupnp/gupnp-context-manager.h>
#include <libgupnp/gupnp-context.h>
+#include <libgupnp/gupnp-context-manager.h>
#include <libgupnp/gupnp-control-point.h>
+#include <libgupnp/gupnp-error.h>
+#include <libgupnp/gupnp-device.h>
#include <libgupnp/gupnp-device-info.h>
#include <libgupnp/gupnp-device-proxy.h>
-#include <libgupnp/gupnp-device.h>
-#include <libgupnp/gupnp-error.h>
#include <libgupnp/gupnp-resource-factory.h>
#include <libgupnp/gupnp-root-device.h>
+#include <libgupnp/gupnp-service.h>
#include <libgupnp/gupnp-service-info.h>
#include <libgupnp/gupnp-service-introspection.h>
#include <libgupnp/gupnp-service-proxy.h>
-#include <libgupnp/gupnp-service.h>
-#include <libgupnp/gupnp-types.h>
-#include <libgupnp/gupnp-uuid.h>
#include <libgupnp/gupnp-white-list.h>
#include <libgupnp/gupnp-xml-doc.h>
+#include <libgupnp/gupnp-types.h>
+#include <libgupnp/gupnp-uuid.h>
diff --git a/libgupnp/meson.build b/libgupnp/meson.build
index b783f9d..fb0f77d 100644
--- a/libgupnp/meson.build
+++ b/libgupnp/meson.build
@@ -61,7 +61,6 @@ headers = files(
'gupnp-types.h',
'gupnp-uuid.h',
'gupnp-white-list.h',
- 'gupnp-context-filter.h',
'gupnp-xml-doc.h'
)
install_headers(headers, subdir : 'gupnp-1.2/libgupnp')
@@ -85,7 +84,6 @@ sources = files(
'gupnp-simple-context-manager.c',
'gupnp-types.c',
'gupnp-white-list.c',
- 'gupnp-context-filter.c',
'gupnp-xml-doc.c',
'gvalue-util.c',
'http-headers.c',
diff --git a/tests/test-white-list.c b/tests/test-white-list.c
index 185120a..037ca1c 100644
--- a/tests/test-white-list.c
+++ b/tests/test-white-list.c
@@ -154,87 +154,84 @@ print_wl_entry(gpointer data, gpointer user_data)
}
static void
-print_context_filter_entries (GUPnPContextFilter *wl)
+print_white_list_entries(GUPnPWhiteList *wl)
{
GList *list;
g_print ("\t\tWhite List Entries:\n");
- list = gupnp_context_filter_get_entries (wl);
+ list = gupnp_white_list_get_entries(wl);
g_list_foreach (list, print_wl_entry, NULL);
g_print ("\n");
}
static gboolean
-change_context_filter (gpointer user_data)
+change_white_list(gpointer user_data)
{
GUPnPContextManager *context_manager = user_data;
- GUPnPContextFilter *context_filter;
+ GUPnPWhiteList *white_list;
static int tomato = 0;
g_print ("\nChange White List:\n");
g_print ("\t Action number %d:\n", tomato);
- context_filter =
- gupnp_context_manager_get_context_filter (context_manager);
+ white_list = gupnp_context_manager_get_white_list(context_manager);
switch (tomato) {
case 0:
g_print ("\t Add Entry eth0\n\n");
- gupnp_context_filter_add_entry (context_filter, "eth0");
- print_context_filter_entries (context_filter);
+ gupnp_white_list_add_entry(white_list, "eth0");
+ print_white_list_entries (white_list);
break;
case 1:
g_print ("\t Enable WL\n\n");
- gupnp_context_filter_set_enabled (context_filter, TRUE);
+ gupnp_white_list_set_enabled (white_list, TRUE);
break;
case 2:
g_print ("\t Add Entry 127.0.0.1\n\n");
- gupnp_context_filter_add_entry (context_filter, "127.0.0.1");
- print_context_filter_entries (context_filter);
+ gupnp_white_list_add_entry(white_list, "127.0.0.1");
+ print_white_list_entries (white_list);
break;
case 3:
g_print ("\t Add Entry eth5\n\n");
- gupnp_context_filter_add_entry (context_filter, "eth5");
- print_context_filter_entries (context_filter);
+ gupnp_white_list_add_entry(white_list, "eth5");
+ print_white_list_entries (white_list);
break;
case 4:
g_print ("\t Remove Entry eth5\n\n");
- gupnp_context_filter_remove_entry (context_filter, "eth5");
- print_context_filter_entries (context_filter);
+ gupnp_white_list_remove_entry(white_list, "eth5");
+ print_white_list_entries (white_list);
break;
case 5:
g_print ("\t Clear all entries\n\n");
- gupnp_context_filter_clear (context_filter);
- print_context_filter_entries (context_filter);
+ gupnp_white_list_clear(white_list);
+ print_white_list_entries (white_list);
break;
case 6:
g_print ("\t Add Entry wlan2\n\n");
- gupnp_context_filter_add_entry (context_filter, "wlan2");
- print_context_filter_entries (context_filter);
+ gupnp_white_list_add_entry(white_list, "wlan2");
+ print_white_list_entries(white_list);
break;
case 7:
g_print ("\t Disable WL\n\n");
- gupnp_context_filter_set_enabled (context_filter, FALSE);
+ gupnp_white_list_set_enabled (white_list, FALSE);
break;
case 8:
g_print ("\t Enable WL\n\n");
- gupnp_context_filter_set_enabled (context_filter, TRUE);
+ gupnp_white_list_set_enabled (white_list, TRUE);
break;
case 9:
g_print ("\t Connect to wlan0\n\n");
- g_timeout_add_seconds (35,
- change_context_filter,
- context_manager);
+ g_timeout_add_seconds (35, change_white_list, context_manager);
break;
case 10:
g_print ("\t Add Entry wlan0\n\n");
- gupnp_context_filter_add_entry (context_filter, "wlan0");
- print_context_filter_entries (context_filter);
+ gupnp_white_list_add_entry(white_list, "wlan0");
+ print_white_list_entries (white_list);
break;
//~ case 11:
- //~ g_print ("\t Enable WL\n");
- //~ gupnp_context_filter_enable(context_filter, FALSE);
- //~ break;
+ //~ g_print ("\t Enable WL\n");
+ //~ gupnp_white_list_enable(white_list, FALSE);
+ //~ break;
default:
break;
}
@@ -269,7 +266,7 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
main_loop = g_main_loop_new (NULL, FALSE);
- id = g_timeout_add_seconds (5, change_context_filter, cm);
+ id = g_timeout_add_seconds (5, change_white_list, cm);
#ifndef G_OS_WIN32
/* Hook the handler for SIGTERM */