[gupnp/wip/phako/remove-white-list: 2/3] all: white_list -> context_filter




commit a37e8f2f7ede48ef707638846ae7ee964bc0bb26
Author: Jens Georg <mail jensge org>
Date:   Tue Jul 6 01:20:38 2021 +0200

    all: white_list -> context_filter

 examples/test-white-list.c       |  61 +++++++------
 libgupnp/gupnp-context-manager.c | 190 +++++++++++++++++++++------------------
 libgupnp/gupnp-context-manager.h |  11 ++-
 3 files changed, 145 insertions(+), 117 deletions(-)
---
diff --git a/examples/test-white-list.c b/examples/test-white-list.c
index 41ff014..31fea5f 100644
--- a/examples/test-white-list.c
+++ b/examples/test-white-list.c
@@ -160,85 +160,88 @@ print_wl_entry(gpointer data, gpointer user_data)
 }
 
 static void
-print_white_list_entries(GUPnPWhiteList *wl)
+print_context_filter_entries (GUPnPContextFilter *wl)
 {
         GList *list;
 
-        g_print ("\t\tWhite List Entries:\n");
-        list = gupnp_white_list_get_entries(wl);
+        g_print ("\t\tContext filter Entries:\n");
+        list = gupnp_context_filter_get_entries (wl);
         g_list_foreach (list, print_wl_entry, NULL);
         g_print ("\n");
 }
 
 
 static gboolean
-change_white_list(gpointer user_data)
+change_context_filter (gpointer user_data)
 {
         GUPnPContextManager *context_manager = user_data;
-        GUPnPWhiteList *white_list;
+        GUPnPContextFilter *context_filter;
         static int tomato = 0;
 
-        g_print ("\nChange White List:\n");
+        g_print ("\nChange Context filter:\n");
         g_print ("\t Action number %d:\n", tomato);
 
-        white_list = gupnp_context_manager_get_white_list(context_manager);
+        context_filter =
+                gupnp_context_manager_get_context_filter (context_manager);
 
         switch (tomato) {
         case 0:
                 g_print ("\t Add Entry eth0\n\n");
-                gupnp_white_list_add_entry(white_list, "eth0");
-                print_white_list_entries (white_list);
+                gupnp_context_filter_add_entry (context_filter, "eth0");
+                print_context_filter_entries (context_filter);
                 break;
         case 1:
                 g_print ("\t Enable WL\n\n");
-                gupnp_white_list_set_enabled (white_list, TRUE);
+                gupnp_context_filter_set_enabled (context_filter, TRUE);
                 break;
         case 2:
                 g_print ("\t Add Entry 127.0.0.1\n\n");
-                gupnp_white_list_add_entry(white_list, "127.0.0.1");
-                print_white_list_entries (white_list);
+                gupnp_context_filter_add_entry (context_filter, "127.0.0.1");
+                print_context_filter_entries (context_filter);
                 break;
         case 3:
                 g_print ("\t Add Entry eth5\n\n");
-                gupnp_white_list_add_entry(white_list, "eth5");
-                print_white_list_entries (white_list);
+                gupnp_context_filter_add_entry (context_filter, "eth5");
+                print_context_filter_entries (context_filter);
                 break;
         case 4:
                 g_print ("\t Remove Entry eth5\n\n");
-                gupnp_white_list_remove_entry(white_list, "eth5");
-                print_white_list_entries (white_list);
+                gupnp_context_filter_remove_entry (context_filter, "eth5");
+                print_context_filter_entries (context_filter);
                 break;
         case 5:
                 g_print ("\t Clear all entries\n\n");
-                gupnp_white_list_clear(white_list);
-                print_white_list_entries (white_list);
+                gupnp_context_filter_clear (context_filter);
+                print_context_filter_entries (context_filter);
                 break;
         case 6:
                 g_print ("\t Add Entry wlan2\n\n");
-                gupnp_white_list_add_entry(white_list, "wlan2");
-                print_white_list_entries(white_list);
+                gupnp_context_filter_add_entry (context_filter, "wlan2");
+                print_context_filter_entries (context_filter);
                 break;
         case 7:
                 g_print ("\t Disable WL\n\n");
-                gupnp_white_list_set_enabled (white_list, FALSE);
+                gupnp_context_filter_set_enabled (context_filter, FALSE);
                 break;
         case 8:
                 g_print ("\t Enable WL\n\n");
-                gupnp_white_list_set_enabled (white_list, TRUE);
+                gupnp_context_filter_set_enabled (context_filter, TRUE);
                 break;
         case 9:
                 g_print ("\t Connect to wlan0\n\n");
-                g_timeout_add_seconds (35, change_white_list, context_manager);
+                g_timeout_add_seconds (35,
+                                       change_context_filter,
+                                       context_manager);
                 break;
         case 10:
                 g_print ("\t Add Entry wlan0\n\n");
-                gupnp_white_list_add_entry(white_list, "wlan0");
-                print_white_list_entries (white_list);
+                gupnp_context_filter_add_entry (context_filter, "wlan0");
+                print_context_filter_entries (context_filter);
                 break;
         //~ case 11:
-                //~ g_print ("\t Enable WL\n");
-                //~ gupnp_white_list_enable(white_list, FALSE);
-                //~ break;
+        //~ g_print ("\t Enable WL\n");
+        //~ gupnp_context_filter_enable(context_filter, FALSE);
+        //~ break;
         default:
                 break;
         }
@@ -270,7 +273,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_white_list, cm);
+        id = g_timeout_add_seconds (5, change_context_filter, cm);
 
 #ifndef G_OS_WIN32
         g_unix_signal_add (SIGINT, unix_signal_handler, NULL);
diff --git a/libgupnp/gupnp-context-manager.c b/libgupnp/gupnp-context-manager.c
index 19c485d..534899d 100644
--- a/libgupnp/gupnp-context-manager.c
+++ b/libgupnp/gupnp-context-manager.c
@@ -60,9 +60,9 @@ struct _GUPnPContextManagerPrivate {
         GUPnPContextManager *impl;
 
         GList *objects; /* control points and root devices */
-        GList *blacklisted; /* Blacklisted Context */
+        GList *filtered; /* Filtered contexts */
 
-        GUPnPWhiteList *white_list;
+        GUPnPContextFilter *context_filter;
 };
 typedef struct _GUPnPContextManagerPrivate GUPnPContextManagerPrivate;
 
@@ -70,12 +70,13 @@ 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_WHITE_LIST
+        PROP_CONTEXT_FILTER
 };
 
 enum {
@@ -106,19 +107,19 @@ on_context_available (GUPnPContextManager    *manager,
                       GUPnPContext           *context,
                       G_GNUC_UNUSED gpointer *user_data)
 {
-        GUPnPWhiteList *white_list;
+        GUPnPContextFilter *context_filter;
         GUPnPContextManagerPrivate *priv;
         gboolean enabled = TRUE;
 
         priv = gupnp_context_manager_get_instance_private (manager);
 
-        white_list = priv->white_list;
+        context_filter = priv->context_filter;
 
         /* Try to catch the notification, only if the white list
          * is enabled, not empty and the context doesn't match */
-        if (!gupnp_white_list_is_empty (white_list) &&
-            gupnp_white_list_get_enabled (white_list) &&
-            !gupnp_white_list_check_context (white_list, context)) {
+        if (!gupnp_context_filter_is_empty (context_filter) &&
+            gupnp_context_filter_get_enabled (context_filter) &&
+            !gupnp_context_filter_check_context (context_filter, context)) {
                 /* If the context doesn't match, block the notification
                  * and disable the context */
                 g_signal_stop_emission_by_name (manager, "context-available");
@@ -128,8 +129,8 @@ on_context_available (GUPnPContextManager    *manager,
                 enabled = FALSE;
 
                 /* Save it in case we need to re-enable it */
-                priv->blacklisted = g_list_prepend (priv->blacklisted,
-                                                    g_object_ref (context));
+                priv->filtered =
+                        g_list_prepend (priv->filtered, g_object_ref (context));
         }
 
         /* Ignore the boot-id handling for UDA 1.0 */
@@ -164,7 +165,7 @@ on_context_unavailable (GUPnPContextManager    *manager,
                         G_GNUC_UNUSED gpointer *user_data)
 {
         GList *l;
-        GList *black;
+        GList *filtered_context;
         GUPnPContextManagerPrivate *priv;
 
         priv = gupnp_context_manager_get_instance_private (manager);
@@ -205,14 +206,14 @@ on_context_unavailable (GUPnPContextManager    *manager,
                 }
         }
 
-        black = g_list_find (priv->blacklisted, context);
+        filtered_context = g_list_find (priv->filtered, context);
 
-        if (black != NULL) {
+        if (filtered_context != NULL) {
                 g_signal_stop_emission_by_name (manager, "context-unavailable");
 
-                g_object_unref (black->data);
-                priv->blacklisted = g_list_delete_link (priv->blacklisted,
-                                                        black);
+                g_object_unref (filtered_context->data);
+                priv->filtered =
+                        g_list_delete_link (priv->filtered, filtered_context);
         } else {
                 /* When UDA 1.0, ignore boot-id handling */
                 if (priv->uda_version > GSSDP_UDA_VERSION_1_0) {
@@ -238,20 +239,20 @@ on_context_unavailable (GUPnPContextManager    *manager,
 }
 
 static void
-gupnp_context_manager_filter_context (GUPnPWhiteList *white_list,
+gupnp_context_manager_filter_context (GUPnPContextFilter *context_filter,
                                       GUPnPContextManager *manager,
                                       gboolean check)
 {
         GList *next;
         GList *obj;
-        GList *blk;
+        GList *iter;
         gboolean match;
         GUPnPContextManagerPrivate *priv;
 
         priv = gupnp_context_manager_get_instance_private (manager);
 
         obj = priv->objects;
-        blk = priv->blacklisted;
+        iter = priv->filtered;
 
         while (obj != NULL) {
                 /* If the white list is empty, treat it as disabled */
@@ -267,8 +268,9 @@ gupnp_context_manager_filter_context (GUPnPWhiteList *white_list,
                                       property, &context,
                                       NULL);
 
-                        match = gupnp_white_list_check_context (white_list,
-                                                                context);
+                        match = gupnp_context_filter_check_context (
+                                context_filter,
+                                context);
                 } else {
                         /* Re-activate all context, if needed */
                         match = TRUE;
@@ -290,65 +292,67 @@ gupnp_context_manager_filter_context (GUPnPWhiteList *white_list,
                 obj = obj->next;
         }
 
-        while (blk != NULL) {
+        while (iter != NULL) {
                 /* If the white list is empty, treat it as disabled */
                 if (check)
                         /* Filter out context */
-                        match = gupnp_white_list_check_context (white_list,
-                                                                blk->data);
+                        match = gupnp_context_filter_check_context (
+                                context_filter,
+                                iter->data);
                 else
                         /* Re-activate all context, if needed */
                         match = TRUE;
 
                 if (!match) {
-                        blk = blk->next;
+                        iter = iter->next;
                         continue;
                 }
 
-                next = blk->next;
-                g_object_set (blk->data, "active", TRUE, NULL);
+                next = iter->next;
+                g_object_set (iter->data, "active", TRUE, NULL);
 
-                g_signal_emit_by_name (manager, "context-available", blk->data);
+                g_signal_emit_by_name (manager,
+                                       "context-available",
+                                       iter->data);
 
-                g_object_unref (blk->data);
-                priv->blacklisted = g_list_delete_link (priv->blacklisted,
-                                                        blk);
-                blk = next;
+                g_object_unref (iter->data);
+                priv->filtered = g_list_delete_link (priv->filtered, iter);
+                iter = next;
         }
 }
 
 static void
-on_white_list_change_cb (GUPnPWhiteList *white_list,
-                         GParamSpec *pspec,
-                         gpointer user_data)
+on_context_filter_change_cb (GUPnPContextFilter *context_filter,
+                             GParamSpec *pspec,
+                             gpointer user_data)
 {
         GUPnPContextManager *manager = GUPNP_CONTEXT_MANAGER (user_data);
         gboolean enabled;
         gboolean is_empty;
 
-        enabled = gupnp_white_list_get_enabled (white_list);
-        is_empty = gupnp_white_list_is_empty (white_list);
+        enabled = gupnp_context_filter_get_enabled (context_filter);
+        is_empty = gupnp_context_filter_is_empty (context_filter);
 
         if (enabled)
-                gupnp_context_manager_filter_context (white_list,
+                gupnp_context_manager_filter_context (context_filter,
                                                       manager,
                                                       !is_empty);
 }
 
 static void
-on_white_list_enabled_cb (GUPnPWhiteList *white_list,
-                          GParamSpec *pspec,
-                          gpointer user_data)
+on_context_filter_enabled_cb (GUPnPContextFilter *context_filter,
+                              GParamSpec *pspec,
+                              gpointer user_data)
 {
         GUPnPContextManager *manager = GUPNP_CONTEXT_MANAGER (user_data);
         gboolean enabled;
         gboolean is_empty;
 
-        enabled = gupnp_white_list_get_enabled (white_list);
-        is_empty = gupnp_white_list_is_empty (white_list);
+        enabled = gupnp_context_filter_get_enabled (context_filter);
+        is_empty = gupnp_context_filter_is_empty (context_filter);
 
         if (!is_empty)
-                gupnp_context_manager_filter_context (white_list,
+                gupnp_context_manager_filter_context (context_filter,
                                                       manager,
                                                       enabled);
 }
@@ -360,13 +364,17 @@ gupnp_context_manager_init (GUPnPContextManager *manager)
 
         priv = gupnp_context_manager_get_instance_private (manager);
 
-        priv->white_list = gupnp_white_list_new ();
+        priv->context_filter = gupnp_context_filter_new ();
 
-        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::entries",
+                                G_CALLBACK (on_context_filter_change_cb),
+                                manager);
 
-        g_signal_connect_after (priv->white_list, "notify::enabled",
-                                G_CALLBACK (on_white_list_enabled_cb), manager);
+        g_signal_connect_after (priv->context_filter,
+                                "notify::enabled",
+                                G_CALLBACK (on_context_filter_enabled_cb),
+                                manager);
         priv->boot_id = time(NULL);
 }
 
@@ -420,8 +428,8 @@ gupnp_context_manager_get_property (GObject    *object,
         case PROP_UDA_VERSION:
                 g_value_set_enum (value, priv->uda_version);
                 break;
-        case PROP_WHITE_LIST:
-                g_value_set_object (value, priv->white_list);
+        case PROP_CONTEXT_FILTER:
+                g_value_set_object (value, priv->context_filter);
                 break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -433,32 +441,29 @@ static void
 gupnp_context_manager_dispose (GObject *object)
 {
         GUPnPContextManager *manager;
-        GUPnPWhiteList *wl;
+        GUPnPContextFilter *filter;
         GObjectClass *object_class;
         GUPnPContextManagerPrivate *priv;
 
         manager = GUPNP_CONTEXT_MANAGER (object);
         priv = gupnp_context_manager_get_instance_private (manager);
 
-        wl = priv->white_list;
+        filter = priv->context_filter;
 
-        g_signal_handlers_disconnect_by_func (wl,
-                                              on_white_list_enabled_cb,
+        g_signal_handlers_disconnect_by_func (filter,
+                                              on_context_filter_enabled_cb,
                                               manager);
 
-        g_signal_handlers_disconnect_by_func (wl,
-                                              on_white_list_change_cb,
+        g_signal_handlers_disconnect_by_func (filter,
+                                              on_context_filter_change_cb,
                                               NULL);
 
         g_list_free_full (priv->objects, g_object_unref);
         priv->objects = NULL;
-        g_list_free_full (priv->blacklisted, g_object_unref);
-        priv->blacklisted = NULL;
+        g_list_free_full (priv->filtered, g_object_unref);
+        priv->filtered = NULL;
 
-        if (wl) {
-                g_object_unref (wl);
-                priv->white_list = NULL;
-        }
+        g_clear_object (&filter);
 
         /* Call super */
         object_class = G_OBJECT_CLASS (gupnp_context_manager_parent_class);
@@ -535,24 +540,23 @@ gupnp_context_manager_class_init (GUPnPContextManagerClass *klass)
                                     G_PARAM_CONSTRUCT_ONLY |
                                     G_PARAM_STATIC_STRINGS));
 
-         /**
-         * GUPnPContextManager:white-list:
+        /**
+         * GUPnPContextManager:context-filter:
          *
          * The white list to use.
          **/
-        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));
-
-       /**
+        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));
+
+        /**
          * GUPnPContextManager::context-available:
          * @context_manager: The #GUPnPContextManager that received the signal
          * @context: The now available #GUPnPContext
@@ -802,16 +806,16 @@ gupnp_context_manager_get_port (GUPnPContextManager *manager)
 }
 
 /**
- * gupnp_context_manager_get_white_list:
+ * gupnp_context_manager_get_context_filter:
  * @manager: A #GUPnPContextManager
  *
- * Get the #GUPnPWhiteList associated with @manager.
+ * Get the #GUPnPContextFilter associated with @manager.
  *
- * Returns: (transfer none):  The #GUPnPWhiteList asssociated with this
+ * Returns: (transfer none):  The #GUPnPContextFilter asssociated with this
  * context manager.
  */
-GUPnPWhiteList *
-gupnp_context_manager_get_white_list (GUPnPContextManager *manager)
+GUPnPContextFilter *
+gupnp_context_manager_get_context_filter (GUPnPContextManager *manager)
 {
         GUPnPContextManagerPrivate *priv;
 
@@ -819,7 +823,23 @@ gupnp_context_manager_get_white_list (GUPnPContextManager *manager)
 
         priv = gupnp_context_manager_get_instance_private (manager);
 
-        return priv->white_list;
+        return priv->context_filter;
+}
+
+/**
+ * gupnp_context_manager_get_white_list:
+ * @manager: A #GUPnPContextManager
+ *
+ * Get the #GUPnPContextFilter associated with @manager.
+ *
+ * Returns: (transfer none):  The #GUPnPContextFilter asssociated with this
+ * context manager.
+ * Deprecated: 1.4.0: Use gupnp_context_manager_get_context_filter() instead.
+ */
+GUPnPWhiteList *
+gupnp_context_manager_get_white_list (GUPnPContextManager *manager)
+{
+        return gupnp_context_manager_get_context_filter (manager);
 }
 
 /**
diff --git a/libgupnp/gupnp-context-manager.h b/libgupnp/gupnp-context-manager.h
index 403f65f..dadeebc 100644
--- a/libgupnp/gupnp-context-manager.h
+++ b/libgupnp/gupnp-context-manager.h
@@ -11,11 +11,12 @@
 #ifndef GUPNP_CONTEXT_MANAGER_H
 #define GUPNP_CONTEXT_MANAGER_H
 
-#include <glib.h>
+#include "gupnp-context-filter.h"
 #include "gupnp-context.h"
-#include "gupnp-root-device.h"
 #include "gupnp-control-point.h"
+#include "gupnp-root-device.h"
 #include "gupnp-white-list.h"
+#include <glib.h>
 
 G_BEGIN_DECLS
 
@@ -63,8 +64,12 @@ gupnp_context_manager_manage_root_device
 guint
 gupnp_context_manager_get_port          (GUPnPContextManager *manager);
 
+GUPnPContextFilter *
+gupnp_context_manager_get_context_filter (GUPnPContextManager *manager);
+
+G_GNUC_DEPRECATED_FOR (gupnp_context_manager_get_context_filter)
 GUPnPWhiteList *
-gupnp_context_manager_get_white_list    (GUPnPContextManager *manager);
+gupnp_context_manager_get_white_list (GUPnPContextManager *manager);
 
 GSocketFamily
 gupnp_context_manager_get_socket_family (GUPnPContextManager *manager);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]