2012-01-02 15:03:19 -07:00
|
|
|
/*
|
|
|
|
|
* virtypedparam.h: managing typed parameters
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2011-2012 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* 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 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 18:06:23 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2012-01-02 15:03:19 -07:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-06-18 11:13:08 -05:00
|
|
|
#pragma once
|
2012-01-02 15:03:19 -07:00
|
|
|
|
2019-06-18 11:13:08 -05:00
|
|
|
#include "internal.h"
|
|
|
|
|
#include "virenum.h"
|
2012-01-02 15:03:19 -07:00
|
|
|
|
2023-04-19 10:29:14 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* VIR_TYPED_PARAM_UNSIGNED:
|
|
|
|
|
*
|
|
|
|
|
* Special typed parameter type only used with virTypedParamsValidate to
|
|
|
|
|
* indicate that both VIR_TYPED_PARAM_UINT and VIR_TYPED_PARAM_ULLONG types
|
|
|
|
|
* are acceptable for given value.
|
|
|
|
|
*/
|
|
|
|
|
#define VIR_TYPED_PARAM_UNSIGNED (VIR_TYPED_PARAM_LAST + 1)
|
2015-06-16 01:42:06 +03:00
|
|
|
/**
|
|
|
|
|
* VIR_TYPED_PARAM_MULTIPLE:
|
|
|
|
|
*
|
|
|
|
|
* Flag indicating that the params has multiple occurrences of the parameter.
|
|
|
|
|
* Only used as a flag for @type argument of the virTypedParamsValidate.
|
|
|
|
|
*/
|
2019-06-18 11:13:08 -05:00
|
|
|
#define VIR_TYPED_PARAM_MULTIPLE (1U << 31)
|
2015-06-16 01:42:06 +03:00
|
|
|
|
2020-01-09 10:39:55 +00:00
|
|
|
G_STATIC_ASSERT(!(VIR_TYPED_PARAM_LAST & VIR_TYPED_PARAM_MULTIPLE));
|
2015-06-16 01:42:06 +03:00
|
|
|
|
2016-02-02 15:33:30 +01:00
|
|
|
typedef struct _virTypedParameterRemoteValue virTypedParameterRemoteValue;
|
|
|
|
|
struct _virTypedParameterRemoteValue {
|
|
|
|
|
int type;
|
|
|
|
|
union {
|
|
|
|
|
int i; /* exempt from syntax-check */
|
|
|
|
|
unsigned int ui;
|
|
|
|
|
long long int l;
|
|
|
|
|
unsigned long long int ul;
|
|
|
|
|
double d;
|
|
|
|
|
char b;
|
|
|
|
|
char *s;
|
|
|
|
|
} remote_typed_param_value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct _virTypedParameterRemote {
|
|
|
|
|
char *field;
|
|
|
|
|
virTypedParameterRemoteValue value;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-22 11:54:35 +02:00
|
|
|
int
|
|
|
|
|
virTypedParamValidateType(virTypedParameterPtr param,
|
|
|
|
|
unsigned int expected_type)
|
|
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2016-02-02 15:33:30 +01:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
int
|
|
|
|
|
virTypedParamsValidate(virTypedParameterPtr params,
|
|
|
|
|
int nparams,
|
|
|
|
|
/* const char *name, int type ... */ ...)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
|
2012-01-02 15:03:19 -07:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
bool
|
|
|
|
|
virTypedParamsCheck(virTypedParameterPtr params,
|
|
|
|
|
int nparams,
|
|
|
|
|
const char **names,
|
|
|
|
|
int nnames);
|
2013-05-06 12:04:06 +02:00
|
|
|
|
2015-06-16 01:42:08 +03:00
|
|
|
int
|
|
|
|
|
virTypedParamsGetStringList(virTypedParameterPtr params,
|
|
|
|
|
int nparams,
|
|
|
|
|
const char *name,
|
|
|
|
|
const char ***values);
|
2024-09-27 10:55:00 +02:00
|
|
|
size_t
|
2015-06-16 01:42:08 +03:00
|
|
|
virTypedParamsFilter(virTypedParameterPtr params,
|
|
|
|
|
int nparams,
|
|
|
|
|
const char *name,
|
2024-09-27 12:56:34 +02:00
|
|
|
int type,
|
2015-06-16 01:42:08 +03:00
|
|
|
virTypedParameterPtr **ret)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2015-06-16 01:42:08 +03:00
|
|
|
|
2023-04-18 13:43:56 +02:00
|
|
|
int
|
|
|
|
|
virTypedParamsGetUnsigned(virTypedParameterPtr params,
|
|
|
|
|
int nparams,
|
|
|
|
|
const char *name,
|
|
|
|
|
unsigned long long *value);
|
2015-06-16 01:42:08 +03:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
int
|
|
|
|
|
virTypedParameterAssign(virTypedParameterPtr param,
|
|
|
|
|
const char *name,
|
|
|
|
|
int type, /* TYPE arg */ ...)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2012-01-02 15:03:19 -07:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
int
|
|
|
|
|
virTypedParamsReplaceString(virTypedParameterPtr *params,
|
|
|
|
|
int *nparams,
|
|
|
|
|
const char *name,
|
|
|
|
|
const char *value);
|
2013-05-21 15:11:56 +02:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
void
|
|
|
|
|
virTypedParamsCopy(virTypedParameterPtr *dst,
|
|
|
|
|
virTypedParameterPtr src,
|
|
|
|
|
int nparams);
|
2013-06-07 16:34:13 +02:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
char *
|
|
|
|
|
virTypedParameterToString(virTypedParameterPtr param);
|
2013-06-06 18:54:48 +02:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
void
|
|
|
|
|
virTypedParamsRemoteFree(struct _virTypedParameterRemote *remote_params_val,
|
|
|
|
|
unsigned int remote_params_len);
|
2016-02-02 13:19:35 +01:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
int
|
|
|
|
|
virTypedParamsDeserialize(struct _virTypedParameterRemote *remote_params,
|
|
|
|
|
unsigned int remote_params_len,
|
|
|
|
|
int limit,
|
|
|
|
|
virTypedParameterPtr *params,
|
|
|
|
|
int *nparams);
|
2016-01-28 17:27:42 +01:00
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
int
|
|
|
|
|
virTypedParamsSerialize(virTypedParameterPtr params,
|
|
|
|
|
int nparams,
|
|
|
|
|
int limit,
|
|
|
|
|
struct _virTypedParameterRemote **remote_params_val,
|
|
|
|
|
unsigned int *remote_params_len,
|
|
|
|
|
unsigned int flags);
|
2016-02-02 14:13:15 +01:00
|
|
|
|
2026-04-22 14:36:22 +02:00
|
|
|
char *
|
|
|
|
|
virTypedParamDebugstr(virTypedParameterPtr param);
|
|
|
|
|
|
2019-06-18 11:13:08 -05:00
|
|
|
#define VIR_TYPED_PARAMS_DEBUG(params, nparams) \
|
2017-11-03 13:09:47 +01:00
|
|
|
do { \
|
|
|
|
|
int _i; \
|
|
|
|
|
if (!params) \
|
|
|
|
|
break; \
|
|
|
|
|
for (_i = 0; _i < (nparams); _i++) { \
|
2026-04-22 14:36:22 +02:00
|
|
|
g_autofree char *_debugstr = virTypedParamDebugstr((params) + _i); \
|
|
|
|
|
VIR_DEBUG("%s", _debugstr); \
|
2017-11-03 13:09:47 +01:00
|
|
|
} \
|
2013-06-06 18:54:48 +02:00
|
|
|
} while (0)
|
2019-09-19 09:20:49 +02:00
|
|
|
|
|
|
|
|
typedef struct _virTypedParamList virTypedParamList;
|
|
|
|
|
|
2023-04-19 12:52:20 +02:00
|
|
|
void
|
|
|
|
|
virTypedParamListFree(virTypedParamList *list);
|
2019-10-15 14:47:50 +02:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virTypedParamList, virTypedParamListFree);
|
2023-04-18 15:20:09 +02:00
|
|
|
virTypedParamList *virTypedParamListNew(void);
|
2019-09-19 09:20:49 +02:00
|
|
|
|
2023-04-18 16:19:58 +02:00
|
|
|
int
|
|
|
|
|
virTypedParamListSteal(virTypedParamList *list,
|
|
|
|
|
virTypedParameterPtr *par,
|
|
|
|
|
int *npar);
|
2019-09-19 09:20:49 +02:00
|
|
|
|
2023-04-18 15:45:31 +02:00
|
|
|
int
|
|
|
|
|
virTypedParamListFetch(virTypedParamList *list,
|
|
|
|
|
virTypedParameterPtr *par,
|
|
|
|
|
size_t *npar)
|
|
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
|
|
|
|
|
2022-05-18 10:46:52 +02:00
|
|
|
virTypedParamList *
|
|
|
|
|
virTypedParamListFromParams(virTypedParameterPtr *params,
|
|
|
|
|
size_t nparams);
|
|
|
|
|
|
2023-04-18 15:30:16 +02:00
|
|
|
void
|
|
|
|
|
virTypedParamListConcat(virTypedParamList *to,
|
|
|
|
|
virTypedParamList **fromptr);
|
|
|
|
|
|
2023-04-18 16:52:30 +02:00
|
|
|
void
|
2023-04-19 12:52:20 +02:00
|
|
|
virTypedParamListAddInt(virTypedParamList *list,
|
|
|
|
|
int value,
|
|
|
|
|
const char *namefmt,
|
|
|
|
|
...)
|
2023-04-18 16:52:30 +02:00
|
|
|
G_GNUC_PRINTF(3, 4);
|
|
|
|
|
void
|
2023-04-19 12:52:20 +02:00
|
|
|
virTypedParamListAddUInt(virTypedParamList *list,
|
|
|
|
|
unsigned int value,
|
|
|
|
|
const char *namefmt,
|
|
|
|
|
...)
|
2023-04-18 16:52:30 +02:00
|
|
|
G_GNUC_PRINTF(3, 4);
|
|
|
|
|
void
|
2023-04-19 12:52:20 +02:00
|
|
|
virTypedParamListAddLLong(virTypedParamList *list,
|
|
|
|
|
long long value,
|
|
|
|
|
const char *namefmt,
|
|
|
|
|
...)
|
2023-04-18 16:52:30 +02:00
|
|
|
G_GNUC_PRINTF(3, 4);
|
|
|
|
|
void
|
2023-04-19 12:52:20 +02:00
|
|
|
virTypedParamListAddULLong(virTypedParamList *list,
|
|
|
|
|
unsigned long long value,
|
|
|
|
|
const char *namefmt,
|
|
|
|
|
...)
|
2023-04-18 16:52:30 +02:00
|
|
|
G_GNUC_PRINTF(3, 4);
|
|
|
|
|
void
|
2023-04-18 13:30:02 +02:00
|
|
|
virTypedParamListAddUnsigned(virTypedParamList *list,
|
|
|
|
|
unsigned long long value,
|
|
|
|
|
const char *namefmt,
|
|
|
|
|
...)
|
|
|
|
|
G_GNUC_PRINTF(3, 4);
|
|
|
|
|
void
|
2023-04-19 12:52:20 +02:00
|
|
|
virTypedParamListAddString(virTypedParamList *list,
|
|
|
|
|
const char *value,
|
|
|
|
|
const char *namefmt,
|
|
|
|
|
...)
|
2023-04-18 16:52:30 +02:00
|
|
|
G_GNUC_PRINTF(3, 4);
|
|
|
|
|
void
|
2023-04-19 12:52:20 +02:00
|
|
|
virTypedParamListAddBoolean(virTypedParamList *list,
|
|
|
|
|
bool value,
|
|
|
|
|
const char *namefmt,
|
|
|
|
|
...)
|
2023-04-18 16:52:30 +02:00
|
|
|
G_GNUC_PRINTF(3, 4);
|
|
|
|
|
void
|
2023-04-19 12:52:20 +02:00
|
|
|
virTypedParamListAddDouble(virTypedParamList *list,
|
|
|
|
|
double value,
|
|
|
|
|
const char *namefmt,
|
|
|
|
|
...)
|
2023-04-18 16:52:30 +02:00
|
|
|
G_GNUC_PRINTF(3, 4);
|