/**
 * gupnp_white_list_check_context:
 * @white_list: A #GUPnPWhiteList
 * @context: A #GUPnPContext to test.
 *
 * It will check if the @context is allowed or not. The @white_list will check
 * all its entries againt #GUPnPContext interface, host ip and network fields
 * information. This function doesn't take into account the @white_list status
 * (enabled or not).
 *
 * Return value: %TRUE if @context is matching the @white_list criterias,
 * %FALSE otherwise.
 *
 * Since: 0.20.5
 **/
gboolean
gupnp_white_list_check_context (GUPnPWhiteList *white_list,
                                GUPnPContext *context)
{
        GSSDPClient  *client;
        GList *l;
        const char *interface;
        const char *host_ip;
        const char *network;
        gboolean match = FALSE;

        g_return_val_if_fail (GUPNP_IS_WHITE_LIST (white_list), FALSE);
        g_return_val_if_fail (GUPNP_IS_CONTEXT (context), FALSE);

        client = GSSDP_CLIENT (context);

        interface = gssdp_client_get_interface (client);
        host_ip = gssdp_client_get_host_ip (client);
        network = gssdp_client_get_network (client);

        l = white_list->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;
}
示例#2
0
static void
on_service_property_changed (CMService   *cm_service,
                             const gchar *name,
                             GVariant    *value)
{
        CMServiceState new_state;
        const gchar *state_str;

        if (g_strcmp0 (name, "Name") == 0) {
                g_free (cm_service->name);
                g_variant_get (value, "s", &cm_service->name);

                if (cm_service->context != NULL &&
                    g_strcmp0 (cm_service->name,
                               gssdp_client_get_network (GSSDP_CLIENT (cm_service->context))) != 0)
                        g_object_set (G_OBJECT (cm_service->context),
                                               "network",
                                               cm_service->name,
                                               NULL);

        } else if (g_strcmp0 (name, "Ethernet") == 0) {
                g_free (cm_service->iface);
                g_variant_lookup (value, "Interface", "s", &cm_service->iface);

                if (cm_service->context != NULL &&
                    g_strcmp0 (cm_service->iface,
                               gssdp_client_get_interface (GSSDP_CLIENT (cm_service->context))) != 0) {
                        service_context_delete (cm_service);
                        service_context_create (cm_service);
                }

        } else if (g_strcmp0 (name, "State") == 0) {
                state_str = g_variant_get_string (value, 0);

                if ((g_strcmp0 (state_str, "online") == 0) ||
                    (g_strcmp0 (state_str, "ready") == 0))
                        new_state = CM_SERVICE_STATE_ACTIVE;
                else
                        new_state = CM_SERVICE_STATE_INACTIVE;

                service_context_update (cm_service, new_state);
        }
}