+Wed Nov 15 15:52:01 EST 2006 Daniel Berrange <berrange@redhat.com>
+
+ * src/conf.c, src/conf.h: Add two new APIs virConfNew() and
+ virConfSetValue() for creating & populating new config objects
+ in memory instead of from a file
+
Wed Nov 15 15:42:01 EST 2006 Daniel Berrange <berrange@redhat.com>
* python/libvir.c, python/libvirt_wrap.h, python/types.h: Ensure
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;
}
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);
}
return(NULL);
}
+/**
+ * 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. The passed in 'value' will be owned by the conf object upon return
+ * of this method, even in case of error. It should not be referenced again
+ * by the caller.
+ *
+ * Returns 0 on success, or -1 on failure.
+ */
+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)))) {
+ virConfFreeValue(value);
+ return (-1);
+ }
+ cur->next = NULL;
+ cur->comment = NULL;
+ if (!(cur->name = strdup(setting))) {
+ virConfFreeValue(value);
+ 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.
virBufferFree(buf);
return(ret);
}
+
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
typedef struct _virConf virConf;
typedef virConf *virConfPtr;
+virConfPtr virConfNew (void);
virConfPtr virConfReadFile (const char *filename);
virConfPtr virConfReadMem (const char *memory,
int len);
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,