Esempio n. 1
0
ni_bool_t
ni_iaid_map_set(ni_iaid_map_t *map, const char *name, unsigned int iaid)
{
	xml_node_t *root, *node = NULL;
	const char *attr;

	if (!(root = ni_iaid_map_root_node(map)) || ni_string_empty(name))
		return FALSE;

	while ((node = ni_iaid_map_next_node(root, node))) {
		attr = xml_node_get_attr(node, NI_CONFIG_DEFAULT_IAID_DEVICE);
		if (!ni_string_eq(name, attr))
			continue;

		xml_node_set_uint(node, iaid);
		return TRUE;
	}

	if ((node = xml_node_new(NI_CONFIG_DEFAULT_IAID_NODE, root))) {
		xml_node_add_attr(node, NI_CONFIG_DEFAULT_IAID_DEVICE, name);
		xml_node_set_uint(node, iaid);
		return TRUE;
	}
	return FALSE;
}
Esempio n. 2
0
/*
 * Get the state of a dbus object as XML.
 * We do this by going via the dbus representation, which is a bit of a waste of
 * time but at least that saves me from writing lots of code, and it makes sure
 * that we have one canonical mapping.
 * In fact, this is a lot like doing a Properties.GetAll call...
 */
static ni_bool_t
ni_objectmodel_save_object_state_xml(const ni_dbus_object_t *object, xml_node_t *parent)
{
	const ni_dbus_service_t *service;
	xml_node_t *object_node;
	unsigned int i;
	int rv = TRUE;

	object_node = xml_node_new("object", parent);
	xml_node_add_attr(object_node, "path", object->path);

	for (i = 0; rv && (service = object->interfaces[i]) != NULL; ++i) {
		ni_dbus_variant_t dict = NI_DBUS_VARIANT_INIT;
		xml_node_t *prop_node;

		ni_dbus_variant_init_dict(&dict);
		rv = ni_dbus_object_get_properties_as_dict(object, service, &dict, NULL);
		if (rv && dict.array.len != 0) {
			/* serialize as XML */
			prop_node = ni_dbus_xml_deserialize_properties(__ni_objectmodel_schema, service->name, &dict, object_node);
			if (!prop_node)
				rv = FALSE;
		}
		ni_dbus_variant_destroy(&dict);
	}

	return rv;
}
Esempio n. 3
0
xml_token_type_t
xml_get_tag_attributes(xml_reader_t *xr, xml_node_t *node)
{
	ni_stringbuf_t tokenValue, attrName, attrValue;
	xml_token_type_t token;

	ni_stringbuf_init(&tokenValue);
	ni_stringbuf_init(&attrName);
	ni_stringbuf_init(&attrValue);

	token = xml_get_token(xr, &tokenValue);
	while (1) {
		if (token == RightAngle || token == RightAngleQ || token == RightAngleSlash)
			break;

		if (token != Identifier) {
			xml_parse_error(xr, "Unexpected token in tag attributes");
			token = None;
			break;
		}

		ni_stringbuf_move(&attrName, &tokenValue);

		token = xml_get_token(xr, &tokenValue);
		if (token != Equals) {
			xml_node_add_attr(node, attrName.string, NULL);
			continue;
		}

		token = xml_get_token(xr, &tokenValue);
		if (token != QuotedString) {
			xml_parse_error(xr, "Attribute value not a quoted string!");
			token = None;
			break;
		}

		xml_debug("  attr %s=%s\n", attrName.string, tokenValue.string);
		xml_node_add_attr(node, attrName.string, tokenValue.string);

		token = xml_get_token(xr, &tokenValue);
	}

	ni_stringbuf_destroy(&tokenValue);
	ni_stringbuf_destroy(&attrName);
	ni_stringbuf_destroy(&attrValue);
	return token;
}
Esempio n. 4
0
/*
 * Helper function for creating <name> elements for ns->describe()
 */
static xml_node_t *
__describe(const ni_objectmodel_ns_t *ns, xml_node_t *parent)
{
	xml_node_t *node = xml_node_new("name", parent);

	xml_node_add_attr(node, "namespace", ns->name);
	return node;
}
Esempio n. 5
0
/*
 * Clone an XML node and all its descendants
 */
xml_node_t *
xml_node_clone(const xml_node_t *src, xml_node_t *parent)
{
	xml_node_t *dst, *child;
	const ni_var_t *attr;
	unsigned int i;

	dst = xml_node_new(src->name, parent);
	ni_string_dup(&dst->cdata, src->cdata);

	for (i = 0, attr = src->attrs.data; i < src->attrs.count; ++i, ++attr)
		xml_node_add_attr(dst, attr->name, attr->value);

	for (child = src->children; child; child = child->next)
		xml_node_clone(child, dst);

	dst->location = xml_location_clone(src->location);
	return dst;
}
Esempio n. 6
0
File: compat.c Progetto: mchf/wicked
static xml_node_t *
ni_compat_generate_ifcfg(const ni_compat_netdev_t *compat, xml_document_t *doc)
{
	xml_node_t *ifnode, *namenode;

	ifnode = xml_node_new("interface", doc->root);

	namenode = xml_node_new("name", ifnode);
	if (compat->identify.hwaddr.type == NI_IFTYPE_ETHERNET) {
		xml_node_add_attr(namenode, "namespace", "ethernet");
		xml_node_new_element("permanent-address", namenode,
				ni_link_address_print(&compat->identify.hwaddr));
	} else {
		xml_node_set_cdata(namenode, compat->dev->name);
	}

	__ni_compat_generate_ifcfg(ifnode, compat);
	return ifnode;
}