Exemple #1
0
ni_bool_t
ni_objectmodel_save_state(const char *filename)
{
	xml_document_t *doc;
	ni_bool_t rv = FALSE;
	FILE *fp = NULL;

	ni_debug_objectmodel("saving server state to %s", filename);

	doc = xml_document_new();
	if (!ni_objectmodel_save_state_xml(doc->root, __ni_objectmodel_server))
		goto done;

	fp = ni_file_open(filename, "w", 0600);
	if (xml_document_print(doc, fp) < 0) {
		ni_error("%s: unable to write server state to %s", __func__, filename);
		goto done;
	}

	rv = TRUE;

done:
	if (fp)
		fclose(fp);
	xml_document_free(doc);
	return rv;
}
Exemple #2
0
xml_document_t *
xml_process_document(xml_reader_t *xr)
{
	xml_document_t *doc;
	xml_node_t *root;

	doc = xml_document_new();

	root = xml_document_root(doc);

	/* Note! We do not deal with properly formatted XML documents here.
	 * Specifically, we do not expect them to have a document header. */
	if (!xml_process_element_nested(xr, root, 0)) {
		xml_document_free(doc);
		return NULL;
	}
	return doc;
}
Exemple #3
0
unsigned int
ni_compat_generate_interfaces(xml_document_array_t *array, ni_compat_ifconfig_t *ifcfg)
{
	xml_document_t *config_doc;
	unsigned int i;

	if (!ifcfg)
		return 0;

	for (i = 0; i < ifcfg->netdev_array.count; ++i) {
		ni_compat_netdev_t *compat = ifcfg->netdev_array.data[i];

		config_doc = xml_document_new();
		ni_compat_generate_ifcfg(compat, config_doc);
		xml_document_array_append(array, config_doc);
	}

	return i;
}
Exemple #4
0
ni_iaid_map_t *
ni_iaid_map_load(const char *filename)
{
	ni_iaid_map_t *map;
	const char *type;
	ni_buffer_t buff;
	struct stat stb;
	ssize_t len;

	if (!(map = ni_iaid_map_new())) {
		ni_error("unable to allocate memory for iaid map: %m");
		return NULL;
	}

	if (filename) {
		type = "given";
		if (!ni_string_dup(&map->file, filename)) {
			ni_error("unable to copy %s iaid map file name (%s): %m", type, filename);
			goto failure;
		}

		if (!ni_iaid_map_open(map)) {
			ni_error("unable to open %s iaid map file name (%s): %m", type, map->file);
			goto failure;
		}
	} else {
		type = "default";
		if (!ni_iaid_map_set_default_file(&map->file)) {
			ni_error("unable to construct %s iaid map file name: %m", type);
			goto failure;
		}

		if (!ni_iaid_map_open(map)) {
			ni_debug_readwrite("unable to open %s iaid map file name (%s): %m", type, map->file);

			type = "fallback";
			if (!ni_iaid_map_set_fallback_file(&map->file)) {
				ni_error("unable to construct %s iaid map file name: %m", type);
				goto failure;
			}
			
			if (!ni_iaid_map_open(map)) {
				ni_error("unable to open iaid map file name (%s): %m", map->file);
				goto failure;
			}
		}
	}

	if (!ni_iaid_map_lock(map)) {
		ni_error("unable to lock %s iaid map file name (%s): %m", type, map->file);
		goto failure;
	}

	if (fstat(map->fd, &stb) < 0)
		stb.st_size = BUFSIZ;

	ni_buffer_init_dynamic(&buff, stb.st_size + 1);
	do {
		if (!ni_buffer_tailroom(&buff))
			ni_buffer_ensure_tailroom(&buff, BUFSIZ);

		do {
			 len = read(map->fd, ni_buffer_tail(&buff), ni_buffer_tailroom(&buff));
			 if (len > 0)
				 ni_buffer_push_tail(&buff, len);
		} while (len < 0 && errno == EINTR);
	} while (len > 0);

	if (len < 0) {
		ni_error("unable to read %s iaid map file name (%s): %m", type, map->file);
	} else {
		map->doc = xml_document_from_buffer(&buff, map->file);
		ni_buffer_destroy(&buff);
		if (!map->doc) {
			map->doc = xml_document_new();
			ni_warn("unable to parse %s iaid map file name (%s): %m", type, map->file);
		}
		return map;
	}

failure:
	ni_iaid_map_free(map);
	return NULL;
}