<commit_before>/*
 * libvirt-sandbox-config-network.c: libvirt sandbox configuration
 *
 * Copyright (C) 2011 Red Hat, Inc.
 *
 * 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.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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
 *
 * Author: <NAME> <<EMAIL>>
 */

#include <config.h>
#include <string.h>

#include "libvirt-sandbox/libvirt-sandbox.h"

/**
 * SECTION: libvirt-sandbox-config-network
 * @short_description: Kernel ramdisk configuration details
 * @include: libvirt-sandbox/libvirt-sandbox.h
 *
 * Provides an object to store information about a kernel ramdisk
 *
 * The GVirSandboxConfigNetwork object stores the information required
 * to build a kernel ramdisk to use when booting a virtual machine
 * as a sandbox.
 */

#define GVIR_SANDBOX_CONFIG_NETWORK_GET_PRIVATE(obj)                    \
    (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK, GVirSandboxConfigNetworkPrivate))

struct _GVirSandboxConfigNetworkPrivate
{
    gboolean dhcp;
    gchar *source;
    gchar *mac;
    GList *routes;
    GList *addrs;
};

G_DEFINE_TYPE(GVirSandboxConfigNetwork, gvir_sandbox_config_network, G_TYPE_OBJECT);


enum {
    PROP_0,
    PROP_DHCP,
    PROP_SOURCE,
    PROP_MAC,
};

enum {
    LAST_SIGNAL
};

//static gint signals[LAST_SIGNAL];


static void gvir_sandbox_config_network_get_property(GObject *object,
                                                     guint prop_id,
                                                     GValue *value,
                                                     GParamSpec *pspec)
{
    GVirSandboxConfigNetwork *config = GVIR_SANDBOX_CONFIG_NETWORK(object);
    GVirSandboxConfigNetworkPrivate *priv = config->priv;

    switch (prop_id) {
    case PROP_DHCP:
        g_value_set_boolean(value, priv->dhcp);
        break;

    case PROP_SOURCE:
        g_value_set_string(value, priv->source);
        break;

    case PROP_MAC:
        g_value_set_string(value, priv->mac);
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}


static void gvir_sandbox_config_network_set_property(GObject *object,
                                                     guint prop_id,
                                                     const GValue *value,
                                                     GParamSpec *pspec)
{
    GVirSandboxConfigNetwork *config = GVIR_SANDBOX_CONFIG_NETWORK(object);
    GVirSandboxConfigNetworkPrivate *priv = config->priv;

    switch (prop_id) {
    case PROP_DHCP:
        priv->dhcp = g_value_get_boolean(value);
        break;

    case PROP_SOURCE:
        g_free(priv->source);
        priv->source = g_value_dup_string(value);
        break;

    case PROP_MAC:
        g_free(priv->mac);
        priv->mac = g_value_dup_string(value);
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}


static void gvir_sandbox_config_network_finalize(GObject *object)
{
    GVirSandboxConfigNetwork *config = GVIR_SANDBOX_CONFIG_NETWORK(object);
    GVirSandboxConfigNetworkPrivate *priv = config->priv;

    g_free(priv->source);
    g_free(priv->mac);
    g_list_foreach(priv->addrs, (GFunc)g_object_unref, NULL);
    g_list_foreach(priv->routes, (GFunc)g_object_unref, NULL);

    G_OBJECT_CLASS(gvir_sandbox_config_network_parent_class)->finalize(object);
}


static void gvir_sandbox_config_network_class_init(GVirSandboxConfigNetworkClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS(klass);

    object_class->finalize = gvir_sandbox_config_network_finalize;
    object_class->get_property = gvir_sandbox_config_network_get_property;
    object_class->set_property = gvir_sandbox_config_network_set_property;

    g_object_class_install_property(object_class,
                                    PROP_DHCP,
                                    g_param_spec_boolean("dhcp",
                                                         "DHCP",
                                                         "Enable DHCP",
                                                         TRUE,
                                                         G_PARAM_READABLE |
                                                         G_PARAM_WRITABLE |
                                                         G_PARAM_STATIC_NAME |
                                                         G_PARAM_STATIC_NICK |
                                                         G_PARAM_STATIC_BLURB));
    g_object_class_install_property(object_class,
                                    PROP_SOURCE,
                                    g_param_spec_string("source",
                                                        "Source",
                                                        "Source network",<commit_msg>GVirSandboxConfigNetwork: Fix small finalize() leak<commit_after>/*
 * libvirt-sandbox-config-network.c: libvirt sandbox configuration
 *
 * Copyright (C) 2011 Red Hat, Inc.
 *
 * 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.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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
 *
 * Author: <NAME> <<EMAIL>>
 */

#include <config.h>
#include <string.h>

#include "libvirt-sandbox/libvirt-sandbox.h"

/**
 * SECTION: libvirt-sandbox-config-network
 * @short_description: Kernel ramdisk configuration details
 * @include: libvirt-sandbox/libvirt-sandbox.h
 *
 * Provides an object to store information about a kernel ramdisk
 *
 * The GVirSandboxConfigNetwork object stores the information required
 * to build a kernel ramdisk to use when booting a virtual machine
 * as a sandbox.
 */

#define GVIR_SANDBOX_CONFIG_NETWORK_GET_PRIVATE(obj)                    \
    (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK, GVirSandboxConfigNetworkPrivate))

struct _GVirSandboxConfigNetworkPrivate
{
    gboolean dhcp;
    gchar *source;
    gchar *mac;
    GList *routes;
    GList *addrs;
};

G_DEFINE_TYPE(GVirSandboxConfigNetwork, gvir_sandbox_config_network, G_TYPE_OBJECT);


enum {
    PROP_0,
    PROP_DHCP,
    PROP_SOURCE,
    PROP_MAC,
};

enum {
    LAST_SIGNAL
};

//static gint signals[LAST_SIGNAL];


static void gvir_sandbox_config_network_get_property(GObject *object,
                                                     guint prop_id,
                                                     GValue *value,
                                                     GParamSpec *pspec)
{
    GVirSandboxConfigNetwork *config = GVIR_SANDBOX_CONFIG_NETWORK(object);
    GVirSandboxConfigNetworkPrivate *priv = config->priv;

    switch (prop_id) {
    case PROP_DHCP:
        g_value_set_boolean(value, priv->dhcp);
        break;

    case PROP_SOURCE:
        g_value_set_string(value, priv->source);
        break;

    case PROP_MAC:
        g_value_set_string(value, priv->mac);
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}


static void gvir_sandbox_config_network_set_property(GObject *object,
                                                     guint prop_id,
                                                     const GValue *value,
                                                     GParamSpec *pspec)
{
    GVirSandboxConfigNetwork *config = GVIR_SANDBOX_CONFIG_NETWORK(object);
    GVirSandboxConfigNetworkPrivate *priv = config->priv;

    switch (prop_id) {
    case PROP_DHCP:
        priv->dhcp = g_value_get_boolean(value);
        break;

    case PROP_SOURCE:
        g_free(priv->source);
        priv->source = g_value_dup_string(value);
        break;

    case PROP_MAC:
        g_free(priv->mac);
        priv->mac = g_value_dup_string(value);
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}


static void gvir_sandbox_config_network_finalize(GObject *object)
{
    GVirSandboxConfigNetwork *config = GVIR_SANDBOX_CONFIG_NETWORK(object);
    GVirSandboxConfigNetworkPrivate *priv = config->priv;

    g_free(priv->source);
    g_free(priv->mac);
    g_list_foreach(priv->addrs, (GFunc)g_object_unref, NULL);
    g_list_free(priv->addrs);
    g_list_foreach(priv->routes, (GFunc)g_object_unref, NULL);
    g_list_free(priv->routes);

    G_OBJECT_CLASS(gvir_sandbox_config_network_parent_class)->finalize(object);
}


static void gvir_sandbox_config_network_class_init(GVirSandboxConfigNetworkClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS(klass);

    object_class->finalize = gvir_sandbox_config_network_finalize;
    object_class->get_property = gvir_sandbox_config_network_get_property;
    object_class->set_property = gvir_sandbox_config_network_set_property;

    g_object_class_install_property(object_class,
                                    PROP_DHCP,
                                    g_param_spec_boolean("dhcp",
                                                         "DHCP",
                                                         "Enable DHCP",
                                                         TRUE,
                                                         G_PARAM_READABLE |
                                                         G_PARAM_WRITABLE |
                                                         G_PARAM_STATIC_NAME |
                                                         G_PARAM_STATIC_NICK |
                                                         G_PARAM_STATIC_BLURB));
    g_object_class_install_property(object_class,
                                    PROP_SOURCE,
                                    g_param_spec_string("source",
                                                        "Source",
                                                        "Source network",
{'fraction_non_alphanumeric': 0.06893725525908387, 'fraction_numerical': 0.0032783899462708313, 'mean_word_length': 1.9529443398763109, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 72, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3741814', 'n_tokens_mistral': 3142, 'n_tokens_neox': 2932, 'n_words': 673}