[Libvir] [Patch 1/4] Xen inactive domains: config file APIs
Daniel P. Berrange
berrange at redhat.com
Mon Sep 4 00:29:55 UTC 2006
This patch adds an extra API to the config file management API. This API lets
you add a new config parameter to the file. Previously you could only modify
existing values, not define extra ones. It also exposes an API for creating
a new empty config file record, which is needed if you're creating a brand
new config file, rathre than processing an existing one.
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
-------------- next part --------------
Index: src/conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/conf.c,v
retrieving revision 1.3
diff -u -r1.3 conf.c
--- src/conf.c 3 Sep 2006 17:46:32 -0000 1.3
+++ src/conf.c 4 Sep 2006 01:15:07 -0000
@@ -144,16 +144,7 @@
free(val);
}
-/**
- * virConfCreate:
- * @filename: the name to report errors
- *
- * Create a configuration internal structure
- *
- * Returns a pointer or NULL in case of error.
- */
-static virConfPtr
-virConfCreate(const char *filename)
+virConfPtr virConfNew(void)
{
virConfPtr ret;
@@ -164,12 +155,29 @@
}
memset(ret, 0, sizeof(virConf));
- ret->filename = filename;
+ ret->filename = NULL;
return(ret);
}
/**
+ * virConfCreate:
+ * @filename: the name to report errors
+ *
+ * Create a configuration internal structure
+ *
+ * Returns a pointer or NULL in case of error.
+ */
+static virConfPtr
+virConfCreate(const char *filename)
+{
+ virConfPtr ret = virConfNew();
+ if (ret)
+ ret->filename = filename;
+ return(ret);
+}
+
+/**
* virConfAddEntry:
* @conf: the conf structure
* @name: name of the entry or NULL for comment
@@ -785,6 +793,56 @@
}
/**
+ * virConfGetValue:
+ * @conf: a configuration file handle
+ * @entry: the name of the entry
+ * @value: the new configuration value
+ *
+ * Set (or replace) the value associated to this entry in the configuration
+ * file.
+ *
+ * Returns 0 on success, or -1 on failure. Upon success, the passed in
+ * value will be owned by the conf object & should not be freed.
+ */
+int virConfSetValue (virConfPtr conf,
+ const char *setting,
+ virConfValuePtr value) {
+ virConfEntryPtr cur, prev = NULL;
+
+ cur = conf->entries;
+ while (cur != NULL) {
+ if ((cur->name != NULL) && (!strcmp(cur->name, setting))) {
+ break;
+ }
+ prev = cur;
+ cur = cur->next;
+ }
+ if (!cur) {
+ if (!(cur = malloc(sizeof(virConfEntry))))
+ return (-1);
+ cur->next = NULL;
+ cur->comment = NULL;
+ if (!(cur->name = strdup(setting))) {
+ free(cur);
+ return (-1);
+ }
+ cur->value = value;
+ if (prev) {
+ prev->next = cur;
+ } else {
+ conf->entries = cur;
+ }
+ } else {
+ if (cur->value) {
+ virConfFreeValue(cur->value);
+ }
+ cur->value = value;
+ }
+ return (0);
+}
+
+
+/**
* virConfWriteFile:
* @filename: the path to the configuration file.
* @conf: the conf
Index: src/conf.h
===================================================================
RCS file: /data/cvs/libvirt/src/conf.h,v
retrieving revision 1.1
diff -u -r1.1 conf.h
--- src/conf.h 29 Aug 2006 22:27:07 -0000 1.1
+++ src/conf.h 4 Sep 2006 01:15:07 -0000
@@ -50,6 +50,7 @@
typedef struct _virConf virConf;
typedef virConf *virConfPtr;
+virConfPtr virConfNew (void);
virConfPtr virConfReadFile (const char *filename);
virConfPtr virConfReadMem (const char *memory,
int len);
@@ -57,6 +58,9 @@
virConfValuePtr virConfGetValue (virConfPtr conf,
const char *setting);
+int virConfSetValue (virConfPtr conf,
+ const char *setting,
+ virConfValuePtr value);
int virConfWriteFile (const char *filename,
virConfPtr conf);
int virConfWriteMem (char *memory,
More information about the libvir-list
mailing list