]> git.proxmox.com Git - swtpm.git/blame - src/swtpm/options.h
swtpm: Support unsigned int option
[swtpm.git] / src / swtpm / options.h
CommitLineData
f163b202
SB
1/*
2 * options.h -- Option parsing
3 *
4 * (c) Copyright IBM Corporation 2014.
5 *
6 * Author: Stefan Berger <stefanb@us.ibm.com>
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
12 * met:
13 *
14 * Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * Neither the names of the IBM Corporation nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _SWTPM_OPTIONS_H
39#define _SWTPM_OPTIONS_H
40
41#include <stdbool.h>
42
43enum OptionType {
44 OPT_TYPE_STRING,
45 OPT_TYPE_INT,
a1677841 46 OPT_TYPE_UINT,
f163b202
SB
47 OPT_TYPE_BOOLEAN,
48};
49
50typedef struct {
51 enum OptionType type;
52 const char *name;
53 union {
54 char *string;
55 int integer;
a1677841 56 unsigned int uinteger;
f163b202
SB
57 bool boolean;
58 }u;
59} OptionValue;
60
61typedef struct {
62 size_t n_options;
63 OptionValue *options;
64} OptionValues;
65
66typedef struct {
67 const char *name;
68 enum OptionType type;
69} OptionDesc;
70
71#define END_OPTION_DESC \
72 { \
73 .name = NULL, \
74 }
75
76OptionValues *options_parse(char *opts, const OptionDesc optdesc[],
77 char **error);
78void option_values_free(OptionValues *ov);
337247ef
SB
79const char *option_get_string(OptionValues *ovs, const char *name,
80 const char *def);
81int option_get_int(OptionValues *ovs, const char *name, int def);
a1677841 82unsigned int option_get_uint(OptionValues *ovs, const char *name, unsigned int def);
337247ef 83bool option_get_bool(OptionValues *ovs, const char *name, bool def);
f163b202
SB
84
85#endif /* _SWTPM_OPTIONS_H */