|
Packit |
a07778 |
/*
|
|
Packit |
a07778 |
* libvirt-gconfig-domain-smartcard-passthrough.c: libvirt domain smartcard passthrough configuration
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Copyright (C) 2012 Red Hat, Inc.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
a07778 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a07778 |
* License as published by the Free Software Foundation; either
|
|
Packit |
a07778 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
a07778 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a07778 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a07778 |
* Lesser General Public License for more details.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a07778 |
* License along with this library. If not, see
|
|
Packit |
a07778 |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Author: Alexander Larsson <alexl@redhat.com>
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include <config.h>
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include "libvirt-gconfig/libvirt-gconfig.h"
|
|
Packit |
a07778 |
#include "libvirt-gconfig/libvirt-gconfig-private.h"
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#define GVIR_CONFIG_DOMAIN_SMARTCARD_PASSTHROUGH_GET_PRIVATE(obj) \
|
|
Packit |
a07778 |
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_SMARTCARD_PASSTHROUGH, GVirConfigDomainSmartcardPassthroughPrivate))
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
struct _GVirConfigDomainSmartcardPassthroughPrivate
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
gboolean unused;
|
|
Packit |
a07778 |
};
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainSmartcardPassthrough, gvir_config_domain_smartcard_passthrough, GVIR_CONFIG_TYPE_DOMAIN_SMARTCARD);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_config_domain_smartcard_passthrough_class_init(GVirConfigDomainSmartcardPassthroughClass *klass G_GNUC_UNUSED)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_config_domain_smartcard_passthrough_init(GVirConfigDomainSmartcardPassthrough *smartcard)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
smartcard->priv = GVIR_CONFIG_DOMAIN_SMARTCARD_PASSTHROUGH_GET_PRIVATE(smartcard);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
GVirConfigDomainSmartcardPassthrough *gvir_config_domain_smartcard_passthrough_new(void)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GVirConfigObject *object;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_SMARTCARD_PASSTHROUGH,
|
|
Packit |
a07778 |
"smartcard", NULL);
|
|
Packit |
a07778 |
gvir_config_object_set_attribute(object, "mode", "passthrough", NULL);
|
|
Packit |
a07778 |
return GVIR_CONFIG_DOMAIN_SMARTCARD_PASSTHROUGH(object);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
GVirConfigDomainSmartcardPassthrough *gvir_config_domain_smartcard_passthrough_new_from_xml(const gchar *xml,
|
|
Packit |
a07778 |
GError **error)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GVirConfigObject *object;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_SMARTCARD_PASSTHROUGH,
|
|
Packit |
a07778 |
"smartcard", NULL, xml, error);
|
|
Packit |
a07778 |
if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "mode"), "passthrough") != 0) {
|
|
Packit |
a07778 |
g_object_unref(G_OBJECT(object));
|
|
Packit |
a07778 |
return NULL;
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
return GVIR_CONFIG_DOMAIN_SMARTCARD_PASSTHROUGH(object);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void prepend_prop(xmlNodePtr node, xmlAttrPtr prop)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
if (node->properties == NULL) {
|
|
Packit |
a07778 |
node->properties = prop;
|
|
Packit |
a07778 |
} else {
|
|
Packit |
a07778 |
prop->next = node->properties;
|
|
Packit |
a07778 |
node->properties->prev = prop;
|
|
Packit |
a07778 |
node->properties = prop;
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
void
|
|
Packit |
a07778 |
gvir_config_domain_smartcard_passthrough_set_source(GVirConfigDomainSmartcardPassthrough *smartcard,
|
|
Packit |
a07778 |
GVirConfigDomainChardevSource *source)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
xmlNodePtr smartcard_node;
|
|
Packit |
a07778 |
xmlNodePtr source_node;
|
|
Packit |
a07778 |
xmlNodePtr child;
|
|
Packit |
a07778 |
xmlAttrPtr attr;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SMARTCARD_PASSTHROUGH(smartcard));
|
|
Packit |
a07778 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CHARDEV_SOURCE(source));
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
smartcard_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(smartcard));
|
|
Packit |
a07778 |
source_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(source));
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
g_return_if_fail((smartcard_node != NULL) && (source_node != NULL));
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
for (child = source_node->children; child != NULL; child = child->next) {
|
|
Packit |
a07778 |
xmlUnlinkNode(child);
|
|
Packit |
a07778 |
xmlAddChild(smartcard_node, child);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
for (attr = source_node->properties; attr != NULL; attr = attr->next) {
|
|
Packit |
a07778 |
xmlAttrPtr new_attr;
|
|
Packit |
a07778 |
new_attr = xmlCopyProp(smartcard_node, attr);
|
|
Packit |
a07778 |
prepend_prop(smartcard_node, new_attr);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
}
|