2012-12-12 16:35:35 +00:00
|
|
|
/*
|
|
|
|
* virconf.h: parser for a subset of the Python encoded Xen configuration files
|
2006-08-29 22:27:07 +00:00
|
|
|
*
|
Detect heap allocation failure; factor out some duplication.
* qemud/qemud.c (tls_port, tcp_port, mdns_name, tls_allowed_ip_list):
(tls_allowed_dn_list): Remove "const", now that we free these.
(unix_sock_rw_mask): Rename from unix_sock_rw_perms, so that
the latter name can be used as a local string variable, so that the
variable name matches the config attribute name.
(unix_sock_ro_mask): Rename from unix_sock_ro_perms, likewise.
(remoteCheckDN, remoteCheckAccess): Adapt to const removal.
(qemudDispatchServer): Check for heap allocation failure.
(remoteConfigGetStringList): New function, based on code from Dan Berrangé.
(CHECK_TYPE): Remove macro.
(checkType): New function.
(GET_CONF_INT, GET_CONF_STR): New macros.
(remoteReadConfigFile): Use new macros to avoid duplication and to
check for allocation failure.
* src/conf.h (virConfTypeName): New static inline function.
2007-11-30 15:43:42 +00:00
|
|
|
* Copyright (C) 2006, 2007 Red Hat, Inc.
|
2006-08-29 22:27:07 +00:00
|
|
|
*
|
2012-07-27 09:39:53 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 09:39:53 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2006-08-29 22:27:07 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#pragma once
|
2006-08-29 22:27:07 +00:00
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#include "virutil.h"
|
|
|
|
#include "virenum.h"
|
2014-12-09 13:53:28 +00:00
|
|
|
|
2006-08-29 22:27:07 +00:00
|
|
|
/**
|
|
|
|
* virConfType:
|
|
|
|
* one of the possible type for a value from the configuration file
|
|
|
|
*
|
|
|
|
* TODO: we probably need a float too.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2014-12-09 13:53:28 +00:00
|
|
|
VIR_CONF_NONE = 0, /* undefined */
|
2016-07-15 15:36:32 +00:00
|
|
|
VIR_CONF_LLONG, /* a long long int */
|
|
|
|
VIR_CONF_ULLONG, /* an unsigned long long int */
|
2014-12-09 13:53:28 +00:00
|
|
|
VIR_CONF_STRING, /* a string */
|
|
|
|
VIR_CONF_LIST, /* a list */
|
|
|
|
VIR_CONF_LAST, /* sentinel */
|
2006-08-29 22:27:07 +00:00
|
|
|
} virConfType;
|
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virConf);
|
2014-12-09 13:53:28 +00:00
|
|
|
|
2009-06-19 12:34:30 +00:00
|
|
|
typedef enum {
|
2010-09-22 20:41:38 +00:00
|
|
|
VIR_CONF_FLAG_VMX_FORMAT = 1, /* allow ':', '.' and '-' in names for compatibility
|
|
|
|
with VMware VMX configuration file, but restrict
|
2009-06-22 11:54:49 +00:00
|
|
|
allowed value types to string only */
|
2014-02-05 14:09:59 +00:00
|
|
|
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 */
|
2009-06-19 12:34:30 +00:00
|
|
|
} virConfFlags;
|
|
|
|
|
2006-08-29 22:27:07 +00:00
|
|
|
/**
|
|
|
|
* virConfValue:
|
|
|
|
* a value from the configuration file
|
|
|
|
*/
|
|
|
|
typedef struct _virConfValue virConfValue;
|
|
|
|
typedef virConfValue *virConfValuePtr;
|
|
|
|
|
|
|
|
struct _virConfValue {
|
2017-10-17 15:05:47 +00:00
|
|
|
virConfType type; /* the virConfType */
|
|
|
|
virConfValuePtr next; /* next element if in a list */
|
|
|
|
long long l; /* very long integer */
|
|
|
|
char *str; /* pointer to 0 terminated string */
|
|
|
|
virConfValuePtr list; /* list of a list */
|
2006-08-29 22:27:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConfPtr:
|
|
|
|
* a pointer to a parsed configuration file
|
|
|
|
*/
|
|
|
|
typedef struct _virConf virConf;
|
|
|
|
typedef virConf *virConfPtr;
|
|
|
|
|
2014-02-05 14:09:59 +00:00
|
|
|
typedef int (*virConfWalkCallback)(const char* name,
|
|
|
|
virConfValuePtr value,
|
|
|
|
void *opaque);
|
|
|
|
|
2015-08-17 12:42:03 +00:00
|
|
|
virConfPtr virConfNew(void);
|
|
|
|
virConfPtr virConfReadFile(const char *filename, unsigned int flags);
|
2017-08-07 15:12:02 +00:00
|
|
|
virConfPtr virConfReadString(const char *memory,
|
|
|
|
unsigned int flags);
|
2015-08-17 12:42:03 +00:00
|
|
|
int virConfFree(virConfPtr conf);
|
|
|
|
void virConfFreeValue(virConfValuePtr val);
|
|
|
|
virConfValuePtr virConfGetValue(virConfPtr conf,
|
|
|
|
const char *setting);
|
2016-07-07 15:52:47 +00:00
|
|
|
|
|
|
|
virConfType virConfGetValueType(virConfPtr conf,
|
|
|
|
const char *setting);
|
|
|
|
int virConfGetValueString(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
char **value);
|
|
|
|
int virConfGetValueStringList(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
bool compatString,
|
|
|
|
char ***values);
|
|
|
|
int virConfGetValueBool(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
bool *value);
|
|
|
|
int virConfGetValueInt(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
int *value);
|
|
|
|
int virConfGetValueUInt(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
unsigned int *value);
|
|
|
|
int virConfGetValueSizeT(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
size_t *value);
|
|
|
|
int virConfGetValueSSizeT(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
ssize_t *value);
|
|
|
|
int virConfGetValueLLong(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
long long *value);
|
|
|
|
int virConfGetValueULLong(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
unsigned long long *value);
|
|
|
|
|
2015-08-17 12:42:03 +00:00
|
|
|
int virConfSetValue(virConfPtr conf,
|
|
|
|
const char *setting,
|
|
|
|
virConfValuePtr value);
|
2014-02-05 14:09:59 +00:00
|
|
|
int virConfWalk(virConfPtr conf,
|
|
|
|
virConfWalkCallback callback,
|
|
|
|
void *opaque);
|
2015-08-17 12:42:03 +00:00
|
|
|
int virConfWriteFile(const char *filename,
|
|
|
|
virConfPtr conf);
|
|
|
|
int virConfWriteMem(char *memory,
|
|
|
|
int *len,
|
|
|
|
virConfPtr conf);
|
2015-10-12 14:09:53 +00:00
|
|
|
int virConfLoadConfig(virConfPtr *conf, const char *name);
|