diff options
author | Jens Georg <mail@jensge.org> | 2020-12-03 01:31:49 +0100 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2020-12-03 01:31:49 +0100 |
commit | 4a07c0bc2bd349c6506f7f7e10646db9042d2532 (patch) | |
tree | bbc75bd0aa40978a5dd1974a35be3e8c24d71069 | |
parent | fd64b9c52051db2e8433162ccebc71c785a4fd0a (diff) | |
download | gupnp-4a07c0bc2bd349c6506f7f7e10646db9042d2532.tar.gz |
Revert "wip"
This reverts commit f4616df9751f11e5d73e0fc0f4d488fbaaec7971.
Accidental push
-rw-r--r-- | libgupnp/gupnp-context-filter.c | 462 | ||||
-rw-r--r-- | libgupnp/gupnp-context-filter.h | 78 |
2 files changed, 0 insertions, 540 deletions
diff --git a/libgupnp/gupnp-context-filter.c b/libgupnp/gupnp-context-filter.c deleted file mode 100644 index d23e67d..0000000 --- a/libgupnp/gupnp-context-filter.c +++ /dev/null @@ -1,462 +0,0 @@ -/* - * Copyright (C) 2013 Intel Corporation. - * - * Author: Ludovic Ferrandis <ludovic.ferrandis@intel.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/** - * SECTION:gupnp-white-list - * @short_description: Class for network filtering. - * - * #GUPnPContextFilter handles network filtering. It provides API to manage a - * list of entries that will be used to filter networks. The #GUPnPContextFilter - * could be enabled or not. If it's enabled but the entries list is empty, it - * behaves as disabled. - * - * Since: 0.20.5 - */ - -#include <string.h> - -#include "gupnp-white-list.h" - -struct _GUPnPContextFilterPrivate { - gboolean enabled; - GList *entries; -}; -typedef struct _GUPnPContextFilterPrivate GUPnPContextFilterPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (GUPnPContextFilter, - gupnp_context_filter, - G_TYPE_OBJECT); - -enum -{ - PROP_0, - PROP_ENABLED, - PROP_ENTRIES -}; - -enum -{ - ENTRY_CHANGE, - ENABLED, - SIGNAL_LAST -}; - -static void -gupnp_context_filter_init (GUPnPContextFilter *list) -{ - GUPnPContextFilterPrivate *priv; - - priv = gupnp_context_filter_get_instance_private (list); - - priv->entries = NULL; -} - -static void -gupnp_context_filter_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GUPnPContextFilter *list; - GUPnPContextFilterPrivate *priv; - - list = GUPNP_CONTEXT_FILTER (object); - priv = gupnp_context_filter_get_instance_private (list); - - switch (property_id) { - case PROP_ENABLED: - priv->enabled = g_value_get_boolean (value); - break; - case PROP_ENTRIES: - priv->entries = g_value_get_pointer (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gupnp_context_filter_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GUPnPContextFilter *list; - GUPnPContextFilterPrivate *priv; - - list = GUPNP_CONTEXT_FILTER (object); - priv = gupnp_context_filter_get_instance_private (list); - - switch (property_id) { - case PROP_ENABLED: - g_value_set_boolean (value, priv->enabled); - break; - case PROP_ENTRIES: - g_value_set_pointer (value, priv->entries); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gupnp_context_filter_class_finalize (GObject *object) -{ - GUPnPContextFilter *list; - GObjectClass *object_class; - GUPnPContextFilterPrivate *priv; - - list = GUPNP_CONTEXT_FILTER (object); - priv = gupnp_context_filter_get_instance_private (list); - - g_list_free_full (priv->entries, g_free); - priv->entries = NULL; - - /* Call super */ - object_class = G_OBJECT_CLASS (gupnp_context_filter_parent_class); - object_class->finalize (object); -} - -static void -gupnp_context_filter_class_init (GUPnPContextFilterClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - - object_class->set_property = gupnp_context_filter_set_property; - object_class->get_property = gupnp_context_filter_get_property; - object_class->finalize = gupnp_context_filter_class_finalize; - - /** - * GUPnPContextFilter:enabled: - * - * Whether this white list is active or not. - * - * Since: 0.20.5 - **/ - g_object_class_install_property ( - object_class, - PROP_ENABLED, - g_param_spec_boolean ("enabled", - "Enabled", - "TRUE if the white list is active.", - FALSE, - G_PARAM_CONSTRUCT | G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - /** - * GUPnPContextFilter:entries: (type GList(utf8)) - * - * Whether this white list is active or not. - * - * Since: 0.20.5 - **/ - g_object_class_install_property ( - object_class, - PROP_ENTRIES, - g_param_spec_pointer ( - "entries", - "Entries", - "GList of strings that compose the white list.", - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); -} - -/** - * gupnp_context_filter_new: - * - * Create a new #GUPnPContextFilter. - * The white list is disabled by default. - * - * Returns: (transfer full): A new #GUPnPContextFilter object. - * - * Since: 0.20.5 - **/ -GUPnPContextFilter * -gupnp_context_filter_new (void) -{ - return g_object_new (GUPNP_TYPE_CONTEXT_FILTER, NULL); -} - -/** - * gupnp_context_filter_set_enabled: - * @context_filter: A #GUPnPContextFilter - * @enable: %TRUE to enable @context_filter, %FALSE otherwise - * - * Enable or disable the #GUPnPContextFilter to perform the network filtering. - * - * Since: 0.20.5 - **/ -void -gupnp_context_filter_set_enabled (GUPnPContextFilter *context_filter, - gboolean enable) -{ - GUPnPContextFilterPrivate *priv; - - g_return_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter)); - - priv = gupnp_context_filter_get_instance_private (context_filter); - priv->enabled = enable; - g_object_notify (G_OBJECT (context_filter), "enabled"); -} - -/** - * gupnp_context_filter_get_enabled: - * @context_filter: A #GUPnPContextFilter - * - * Return the status of the #GUPnPContextFilter - * - * Return value: %TRUE if @context_filter is enabled, %FALSE otherwise. - * - * Since: 0.20.5 - **/ -gboolean -gupnp_context_filter_get_enabled (GUPnPContextFilter *context_filter) -{ - GUPnPContextFilterPrivate *priv; - - g_return_val_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter), FALSE); - - priv = gupnp_context_filter_get_instance_private (context_filter); - - return priv->enabled; -} - -/** - * gupnp_context_filter_is_empty: - * @context_filter: A #GUPnPContextFilter - * - * Return the state of the entries list of #GUPnPContextFilter - * - * Return value: %TRUE if @context_filter is empty, %FALSE otherwise. - * - * Since: 0.20.5 - **/ -gboolean -gupnp_context_filter_is_empty (GUPnPContextFilter *context_filter) -{ - GUPnPContextFilterPrivate *priv; - - g_return_val_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter), TRUE); - - priv = gupnp_context_filter_get_instance_private (context_filter); - - return (priv->entries == NULL); -} - -/** - * gupnp_context_filter_add_entry: - * @context_filter: A #GUPnPContextFilter - * @entry: A value used to filter network - * - * Add @entry in the list of valid criteria used by @context_filter to - * filter networks. - * if @entry already exists, it won't be added a second time. - * - * Return value: %TRUE if @entry is added, %FALSE otherwise. - * - * Since: 0.20.5 - **/ -gboolean -gupnp_context_filter_add_entry (GUPnPContextFilter *context_filter, - const gchar *entry) -{ - GList *s_entry; - GUPnPContextFilterPrivate *priv; - - g_return_val_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter), FALSE); - g_return_val_if_fail ((entry != NULL), FALSE); - - priv = gupnp_context_filter_get_instance_private (context_filter); - - s_entry = g_list_find_custom (priv->entries, - entry, - (GCompareFunc) g_ascii_strcasecmp); - - if (s_entry == NULL) { - priv->entries = - g_list_prepend (priv->entries, g_strdup (entry)); - g_object_notify (G_OBJECT (context_filter), "entries"); - } - - return (s_entry == NULL); -} - -/** - * gupnp_context_filter_add_entryv: - * @context_filter: A #GUPnPContextFilter - * @entries: (array zero-terminated=1): A %NULL-terminated list of strings - * - * Add a list of entries to a #GUPnPContextFilter. This is a helper function to - * directly add a %NULL-terminated array of string usually aquired from - * commandline args. - * - * Since: 0.20.8 - */ -void -gupnp_context_filter_add_entryv (GUPnPContextFilter *context_filter, - gchar **entries) -{ - gchar *const *iter = entries; - - g_return_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter)); - g_return_if_fail ((entries != NULL)); - - for (; *iter != NULL; iter++) - gupnp_context_filter_add_entry (context_filter, *iter); -} - -/** - * gupnp_context_filter_remove_entry: - * @context_filter: A #GUPnPContextFilter - * @entry: A value to remove from the filter list. - * - * Remove @entry in the list of valid criteria used by @context_filter to - * filter networks. - * - * Return value: %TRUE if @entry is removed, %FALSE otherwise. - * - * Since: 0.20.5 - **/ -gboolean -gupnp_context_filter_remove_entry (GUPnPContextFilter *context_filter, - const gchar *entry) -{ - GList *s_entry; - GUPnPContextFilterPrivate *priv; - - g_return_val_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter), FALSE); - g_return_val_if_fail ((entry != NULL), FALSE); - - priv = gupnp_context_filter_get_instance_private (context_filter); - - s_entry = g_list_find_custom (priv->entries, - entry, - (GCompareFunc) g_ascii_strcasecmp); - - if (s_entry != NULL) { - priv->entries = g_list_remove_link (priv->entries, s_entry); - g_list_free_full (s_entry, g_free); - g_object_notify (G_OBJECT (context_filter), "entries"); - } - - return (s_entry != NULL); -} - -/** - * gupnp_context_filter_get_entries: - * @context_filter: A #GUPnPContextFilter - * - * Get the #GList of entries that compose the white list. Do not free - * - * Return value: (element-type utf8) (transfer none): a #GList of entries - * used to filter networks, interfaces,... or %NULL. - * Do not modify or free the list nor its elements. - * - * Since: 0.20.5 - **/ -GList * -gupnp_context_filter_get_entries (GUPnPContextFilter *context_filter) -{ - GUPnPContextFilterPrivate *priv; - - g_return_val_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter), NULL); - - priv = gupnp_context_filter_get_instance_private (context_filter); - - return priv->entries; -} - -/** - * gupnp_context_filter_clear: - * @context_filter: A #GUPnPContextFilter - * - * 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. - * - * Since: 0.20.5 - **/ -void -gupnp_context_filter_clear (GUPnPContextFilter *context_filter) -{ - GUPnPContextFilterPrivate *priv; - - g_return_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter)); - - priv = gupnp_context_filter_get_instance_private (context_filter); - g_list_free_full (priv->entries, g_free); - priv->entries = NULL; - g_object_notify (G_OBJECT (context_filter), "entries"); -} - -/** - * gupnp_context_filter_check_context: - * @context_filter: A #GUPnPContextFilter - * @context: A #GUPnPContext to test. - * - * It will check if the @context is allowed or not. The @context_filter will - *check all its entries againt #GUPnPContext interface, host ip and network - *fields information. This function doesn't take into account the - *@context_filter status (enabled or not). - * - * Return value: %TRUE if @context is matching the @context_filter criterias, - * %FALSE otherwise. - * - * Since: 0.20.5 - **/ -gboolean -gupnp_context_filter_check_context (GUPnPContextFilter *context_filter, - GUPnPContext *context) -{ - GSSDPClient *client; - GList *l; - const char *interface; - const char *host_ip; - const char *network; - gboolean match = FALSE; - GUPnPContextFilterPrivate *priv; - - g_return_val_if_fail (GUPNP_IS_CONTEXT_FILTER (context_filter), FALSE); - g_return_val_if_fail (GUPNP_IS_CONTEXT (context), FALSE); - - client = GSSDP_CLIENT (context); - priv = gupnp_context_filter_get_instance_private (context_filter); - - interface = gssdp_client_get_interface (client); - host_ip = gssdp_client_get_host_ip (client); - network = gssdp_client_get_network (client); - - l = priv->entries; - - while (l && !match) { - match = (interface && !strcmp (l->data, interface)) || - (host_ip && !strcmp (l->data, host_ip)) || - (network && !strcmp (l->data, network)); - - l = l->next; - } - - return match; -} diff --git a/libgupnp/gupnp-context-filter.h b/libgupnp/gupnp-context-filter.h deleted file mode 100644 index c74179b..0000000 --- a/libgupnp/gupnp-context-filter.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2013 Intel Corporation. - * - * Author: Ludovic Ferrandis <ludovic.ferrandis@intel.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef GUPNP_CONTEXT_FILTER_H -#define GUPNP_CONTEXT_FILTER_H - -#include "gupnp-context.h" -#include <glib.h> - -G_BEGIN_DECLS - -#define GUPNP_TYPE_CONTEXT_FILTER (gupnp_context_filter_get_type ()) - -G_DECLARE_DERIVABLE_TYPE (GUPnPContextFilter, - gupnp_context_filter, - GUPNP, - CONTEXT_FILTER, - GObject) - -struct _GUPnPContextFilterClass { - GObjectClass parent_class; -}; - -GUPnPContextFilter * -gupnp_context_filter_new (void); - -void -gupnp_context_filter_set_enabled (GUPnPContextFilter *context_filter, - gboolean enable); - -gboolean -gupnp_context_filter_get_enabled (GUPnPContextFilter *context_filter); - -gboolean -gupnp_context_filter_is_empty (GUPnPContextFilter *context_filter); - -gboolean -gupnp_context_filter_add_entry (GUPnPContextFilter *context_filter, - const gchar *entry); -void -gupnp_context_filter_add_entryv (GUPnPContextFilter *context_filter, - gchar **entries); - -gboolean -gupnp_context_filter_remove_entry (GUPnPContextFilter *context_filter, - const gchar *entry); - -GList * -gupnp_context_filter_get_entries (GUPnPContextFilter *context_filter); - -void -gupnp_context_filter_clear (GUPnPContextFilter *context_filter); - -gboolean -gupnp_context_filter_check_context (GUPnPContextFilter *context_filter, - GUPnPContext *context); - -G_END_DECLS - -#endif /* GUPNP_CONTEXT_FILTER_H */ |