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 "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;
|
|
|
|
struct _virConfValue {
|
2017-10-17 15:05:47 +00:00
|
|
|
virConfType type; /* the virConfType */
|
2021-03-11 07:16:13 +00:00
|
|
|
virConfValue *next; /* next element if in a list */
|
2017-10-17 15:05:47 +00:00
|
|
|
long long l; /* very long integer */
|
|
|
|
char *str; /* pointer to 0 terminated string */
|
2021-03-11 07:16:13 +00:00
|
|
|
virConfValue *list; /* list of a list */
|
2006-08-29 22:27:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-03-11 07:16:13 +00:00
|
|
|
* virConf *:
|
2006-08-29 22:27:07 +00:00
|
|
|
* a pointer to a parsed configuration file
|
|
|
|
*/
|
|
|
|
typedef struct _virConf virConf;
|
|
|
|
|
2014-02-05 14:09:59 +00:00
|
|
|
typedef int (*virConfWalkCallback)(const char* name,
|
2021-03-11 07:16:13 +00:00
|
|
|
virConfValue *value,
|
2014-02-05 14:09:59 +00:00
|
|
|
void *opaque);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virConf *virConfNew(void);
|
|
|
|
virConf *virConfReadFile(const char *filename, unsigned int flags);
|
|
|
|
virConf *virConfReadString(const char *memory,
|
2017-08-07 15:12:02 +00:00
|
|
|
unsigned int flags);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfFree(virConf *conf);
|
2019-10-15 12:47:50 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virConf, virConfFree);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virConfFreeValue(virConfValue *val);
|
2022-01-14 09:28:52 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virConfValue, virConfFreeValue);
|
2021-03-11 07:16:13 +00:00
|
|
|
virConfValue *virConfGetValue(virConf *conf,
|
2015-08-17 12:42:03 +00:00
|
|
|
const char *setting);
|
2016-07-07 15:52:47 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virConfType virConfGetValueType(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueString(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
char **value);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueStringList(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
bool compatString,
|
|
|
|
char ***values);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueBool(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
bool *value);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueInt(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
int *value);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueUInt(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
unsigned int *value);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueSizeT(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
size_t *value);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueSSizeT(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
ssize_t *value);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueLLong(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
long long *value);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfGetValueULLong(virConf *conf,
|
2016-07-07 15:52:47 +00:00
|
|
|
const char *setting,
|
|
|
|
unsigned long long *value);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfSetValue(virConf *conf,
|
2015-08-17 12:42:03 +00:00
|
|
|
const char *setting,
|
2022-01-14 09:11:42 +00:00
|
|
|
virConfValue **value);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virConfWalk(virConf *conf,
|
2014-02-05 14:09:59 +00:00
|
|
|
virConfWalkCallback callback,
|
|
|
|
void *opaque);
|
2015-08-17 12:42:03 +00:00
|
|
|
int virConfWriteFile(const char *filename,
|
2021-03-11 07:16:13 +00:00
|
|
|
virConf *conf);
|
2015-08-17 12:42:03 +00:00
|
|
|
int virConfWriteMem(char *memory,
|
|
|
|
int *len,
|
2021-03-11 07:16:13 +00:00
|
|
|
virConf *conf);
|
|
|
|
int virConfLoadConfig(virConf **conf, const char *name);
|