diff options
author | 2006-11-15 19:46:23 +0000 | |
---|---|---|
committer | 2006-11-15 19:46:23 +0000 | |
commit | 523389a72bea619a53caa0ca2105386c648d2661 (patch) | |
tree | 9721694745dbe2711534209ef009744b264b1630 | |
parent | Fix unsigned long wraparound in python binding (diff) | |
download | libvirt-523389a72bea619a53caa0ca2105386c648d2661.tar.gz libvirt-523389a72bea619a53caa0ca2105386c648d2661.tar.bz2 libvirt-523389a72bea619a53caa0ca2105386c648d2661.zip |
Added virConfNew() and virConfSetValue() apis to virConf object
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/conf.c | 94 | ||||
-rw-r--r-- | src/conf.h | 4 |
3 files changed, 93 insertions, 11 deletions
@@ -1,3 +1,9 @@ +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 diff --git a/src/conf.c b/src/conf.c index 7d81f2dcb..18fa71907 100644 --- a/src/conf.c +++ b/src/conf.c @@ -144,16 +144,7 @@ virConfFreeValue(virConfValuePtr val) 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,8 +155,25 @@ virConfCreate(const char *filename) } 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); } @@ -785,6 +793,60 @@ virConfGetValue(virConfPtr conf, const char *setting) } /** + * 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. * @conf: the conf @@ -878,3 +940,13 @@ error: virBufferFree(buf); return(ret); } + + +/* + * Local variables: + * indent-tabs-mode: nil + * c-indent-level: 4 + * c-basic-offset: 4 + * tab-width: 4 + * End: + */ diff --git a/src/conf.h b/src/conf.h index fb2ebab38..3b83ba62c 100644 --- a/src/conf.h +++ b/src/conf.h @@ -50,6 +50,7 @@ struct _virConfValue { 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 @@ int virConfFree (virConfPtr conf); 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, |