2006-08-29 22:27:07 +00:00
|
|
|
/**
|
|
|
|
* conf.h: parser for a subset of the Python encoded Xen configuration files
|
|
|
|
*
|
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
|
|
|
*
|
|
|
|
* See COPYING.LIB for the License of this software
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIR_CONF_H__
|
|
|
|
#define __VIR_CONF_H__
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConfType:
|
|
|
|
* one of the possible type for a value from the configuration file
|
|
|
|
*
|
|
|
|
* TODO: we probably need a float too.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
VIR_CONF_NONE = 0, /* undefined */
|
|
|
|
VIR_CONF_LONG = 1, /* a long int */
|
|
|
|
VIR_CONF_STRING = 2, /* a string */
|
|
|
|
VIR_CONF_LIST = 3 /* a list */
|
|
|
|
} virConfType;
|
|
|
|
|
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
|
|
|
static inline const char *
|
|
|
|
virConfTypeName (virConfType t)
|
|
|
|
{
|
|
|
|
switch (t) {
|
|
|
|
case VIR_CONF_LONG:
|
|
|
|
return "long";
|
|
|
|
case VIR_CONF_STRING:
|
|
|
|
return "string";
|
|
|
|
case VIR_CONF_LIST:
|
|
|
|
return "list";
|
|
|
|
default:
|
|
|
|
return "*unexpected*";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-29 22:27:07 +00:00
|
|
|
/**
|
|
|
|
* virConfValue:
|
|
|
|
* a value from the configuration file
|
|
|
|
*/
|
|
|
|
typedef struct _virConfValue virConfValue;
|
|
|
|
typedef virConfValue *virConfValuePtr;
|
|
|
|
|
|
|
|
struct _virConfValue {
|
|
|
|
virConfType type; /* the virConfType */
|
|
|
|
virConfValuePtr next; /* next element if in a list */
|
|
|
|
long l; /* long integer */
|
|
|
|
char *str; /* pointer to 0 terminated string */
|
|
|
|
virConfValuePtr list; /* list of a list */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConfPtr:
|
|
|
|
* a pointer to a parsed configuration file
|
|
|
|
*/
|
|
|
|
typedef struct _virConf virConf;
|
|
|
|
typedef virConf *virConfPtr;
|
|
|
|
|
2007-03-09 20:47:12 +00:00
|
|
|
virConfPtr __virConfNew (void);
|
|
|
|
virConfPtr __virConfReadFile (const char *filename);
|
|
|
|
virConfPtr __virConfReadMem (const char *memory,
|
2008-04-10 16:54:54 +00:00
|
|
|
int len);
|
2007-03-09 20:47:12 +00:00
|
|
|
int __virConfFree (virConfPtr conf);
|
2008-05-29 19:20:22 +00:00
|
|
|
void __virConfFreeValue (virConfValuePtr val);
|
2006-08-29 22:27:07 +00:00
|
|
|
|
2007-03-09 20:47:12 +00:00
|
|
|
virConfValuePtr __virConfGetValue (virConfPtr conf,
|
2008-04-10 16:54:54 +00:00
|
|
|
const char *setting);
|
2007-03-09 20:47:12 +00:00
|
|
|
int __virConfSetValue (virConfPtr conf,
|
2008-04-10 16:54:54 +00:00
|
|
|
const char *setting,
|
|
|
|
virConfValuePtr value);
|
2007-03-09 20:47:12 +00:00
|
|
|
int __virConfWriteFile (const char *filename,
|
2008-04-10 16:54:54 +00:00
|
|
|
virConfPtr conf);
|
2007-03-09 20:47:12 +00:00
|
|
|
int __virConfWriteMem (char *memory,
|
2008-04-10 16:54:54 +00:00
|
|
|
int *len,
|
|
|
|
virConfPtr conf);
|
2006-08-29 22:27:07 +00:00
|
|
|
|
2008-05-29 19:20:22 +00:00
|
|
|
#define virConfNew() __virConfNew()
|
|
|
|
#define virConfReadFile(f) __virConfReadFile((f))
|
|
|
|
#define virConfReadMem(m,l) __virConfReadMem((m),(l))
|
|
|
|
#define virConfFree(c) __virConfFree((c))
|
|
|
|
#define virConfFreeValue(v) __virConfFreeValue((v))
|
|
|
|
#define virConfGetValue(c,s) __virConfGetValue((c),(s))
|
|
|
|
#define virConfSetValue(c,s,v) __virConfSetValue((c),(s),(v))
|
|
|
|
#define virConfWriteFile(f,c) __virConfWriteFile((f),(c))
|
|
|
|
#define virConfWriteMem(m,l,c) __virConfWriteMem((m),(l),(c))
|
2007-03-09 20:47:12 +00:00
|
|
|
|
2006-08-29 22:27:07 +00:00
|
|
|
#endif /* __VIR_CONF_H__ */
|