]> git.proxmox.com Git - swtpm.git/blame - src/swtpm/options.h
initial check-in
[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,
46 OPT_TYPE_BOOLEAN,
47};
48
49typedef struct {
50 enum OptionType type;
51 const char *name;
52 union {
53 char *string;
54 int integer;
55 bool boolean;
56 }u;
57} OptionValue;
58
59typedef struct {
60 size_t n_options;
61 OptionValue *options;
62} OptionValues;
63
64typedef struct {
65 const char *name;
66 enum OptionType type;
67} OptionDesc;
68
69#define END_OPTION_DESC \
70 { \
71 .name = NULL, \
72 }
73
74OptionValues *options_parse(char *opts, const OptionDesc optdesc[],
75 char **error);
76void option_values_free(OptionValues *ov);
77const char *option_get_string(OptionValues *ovs, const char *name);
78int option_get_int(OptionValues *ovs, const char *name);
79bool option_get_bool(OptionValues *ovs, const char *name);
80
81#endif /* _SWTPM_OPTIONS_H */
82