if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
return NULL;
NEXT;
+ } else if (ctxt->conf->flags & VIR_CONF_FLAG_LXC_FORMAT) {
+ base = ctxt->cur;
+ /* LXC config format doesn't support comments after the value */
+ while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR)))
+ NEXT;
+ /* Reverse to exclude the trailing blanks from the value */
+ while ((ctxt->cur > base) && (c_isblank(CUR)))
+ ctxt->cur--;
+ if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
+ return NULL;
}
return ret;
}
virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a value"));
return NULL;
}
- if ((CUR == '"') || (CUR == '\'')) {
+ if ((CUR == '"') || (CUR == '\'') ||
+ (ctxt->conf->flags & VIR_CONF_FLAG_LXC_FORMAT)) {
type = VIR_CONF_STRING;
str = virConfParseString(ctxt);
if (str == NULL)
while ((ctxt->cur < ctxt->end) &&
(c_isalnum(CUR) || (CUR == '_') ||
((ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) &&
- ((CUR == ':') || (CUR == '.') || (CUR == '-')))))
+ ((CUR == ':') || (CUR == '.') || (CUR == '-'))) ||
+ ((ctxt->conf->flags & VIR_CONF_FLAG_LXC_FORMAT) &&
+ (CUR == '.'))))
NEXT;
if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
return NULL;
return 0;
}
+/**
+ * virConfWalk:
+ * @conf: a configuration file handle
+ * @callback: the function to call to process each entry
+ * @data: obscure data passed to callback
+ *
+ * Walk over all entries of the configuration file and run the callback
+ * for each with entry name, value and the obscure data.
+ *
+ * Returns 0 on success, or -1 on failure.
+ */
+int virConfWalk(virConfPtr conf,
+ virConfWalkCallback callback,
+ void *opaque)
+{
+ virConfEntryPtr cur;
+
+ if (!conf)
+ return 0;
+
+ cur = conf->entries;
+ while (cur != NULL) {
+ if (cur->name && cur->value &&
+ callback(cur->name, cur->value, opaque) < 0)
+ return -1;
+ cur = cur->next;
+ }
+ return 0;
+}
/**
* virConfWriteFile:
VIR_CONF_FLAG_VMX_FORMAT = 1, /* allow ':', '.' and '-' in names for compatibility
with VMware VMX configuration file, but restrict
allowed value types to string only */
+ VIR_CONF_FLAG_LXC_FORMAT = 2, /* allow '.' in names for compatibility with LXC
+ configuration file, restricts allowed value types
+ to string only and don't expect quotes for values */
} virConfFlags;
static inline const char *
typedef struct _virConf virConf;
typedef virConf *virConfPtr;
+typedef int (*virConfWalkCallback)(const char* name,
+ virConfValuePtr value,
+ void *opaque);
+
virConfPtr virConfNew (void);
virConfPtr virConfReadFile (const char *filename, unsigned int flags);
virConfPtr virConfReadMem (const char *memory,
int virConfSetValue (virConfPtr conf,
const char *setting,
virConfValuePtr value);
+int virConfWalk(virConfPtr conf,
+ virConfWalkCallback callback,
+ void *opaque);
int virConfWriteFile (const char *filename,
virConfPtr conf);
int virConfWriteMem (char *memory,