]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
b77c08e0 TG |
2 | #pragma once |
3 | ||
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2010 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
10 | under the terms of the GNU Lesser General Public License as published by | |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | Lesser General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU Lesser General Public License | |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
21 | ***/ | |
22 | ||
23 | #include <stdbool.h> | |
24 | #include <stdio.h> | |
25 | ||
26 | #include "list.h" | |
27 | #include "macro.h" | |
28 | ||
29 | typedef enum ConditionType { | |
651c3318 LP |
30 | CONDITION_ARCHITECTURE, |
31 | CONDITION_VIRTUALIZATION, | |
32 | CONDITION_HOST, | |
33 | CONDITION_KERNEL_COMMAND_LINE, | |
34 | CONDITION_SECURITY, | |
35 | CONDITION_CAPABILITY, | |
36 | CONDITION_AC_POWER, | |
37 | ||
38 | CONDITION_NEEDS_UPDATE, | |
39 | CONDITION_FIRST_BOOT, | |
59fccdc5 | 40 | |
b77c08e0 TG |
41 | CONDITION_PATH_EXISTS, |
42 | CONDITION_PATH_EXISTS_GLOB, | |
43 | CONDITION_PATH_IS_DIRECTORY, | |
44 | CONDITION_PATH_IS_SYMBOLIC_LINK, | |
45 | CONDITION_PATH_IS_MOUNT_POINT, | |
46 | CONDITION_PATH_IS_READ_WRITE, | |
47 | CONDITION_DIRECTORY_NOT_EMPTY, | |
48 | CONDITION_FILE_NOT_EMPTY, | |
49 | CONDITION_FILE_IS_EXECUTABLE, | |
59fccdc5 | 50 | |
651c3318 | 51 | CONDITION_NULL, |
59fccdc5 | 52 | |
c465a29f FS |
53 | CONDITION_USER, |
54 | CONDITION_GROUP, | |
55 | ||
b77c08e0 TG |
56 | _CONDITION_TYPE_MAX, |
57 | _CONDITION_TYPE_INVALID = -1 | |
58 | } ConditionType; | |
59 | ||
cc50ef13 LP |
60 | typedef enum ConditionResult { |
61 | CONDITION_UNTESTED, | |
62 | CONDITION_SUCCEEDED, | |
63 | CONDITION_FAILED, | |
64 | CONDITION_ERROR, | |
65 | _CONDITION_RESULT_MAX, | |
66 | _CONDITION_RESULT_INVALID = -1 | |
67 | } ConditionResult; | |
592fd144 | 68 | |
b77c08e0 | 69 | typedef struct Condition { |
59fccdc5 | 70 | ConditionType type:8; |
b77c08e0 TG |
71 | |
72 | bool trigger:1; | |
73 | bool negate:1; | |
74 | ||
59fccdc5 LP |
75 | ConditionResult result:6; |
76 | ||
b77c08e0 | 77 | char *parameter; |
b77c08e0 TG |
78 | |
79 | LIST_FIELDS(struct Condition, conditions); | |
80 | } Condition; | |
81 | ||
82 | Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate); | |
83 | void condition_free(Condition *c); | |
447021aa | 84 | Condition* condition_free_list(Condition *c); |
b77c08e0 | 85 | |
d1bddcec LP |
86 | int condition_test(Condition *c); |
87 | ||
59fccdc5 LP |
88 | void condition_dump(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t)); |
89 | void condition_dump_list(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t)); | |
b77c08e0 TG |
90 | |
91 | const char* condition_type_to_string(ConditionType t) _const_; | |
59fccdc5 LP |
92 | ConditionType condition_type_from_string(const char *s) _pure_; |
93 | ||
94 | const char* assert_type_to_string(ConditionType t) _const_; | |
95 | ConditionType assert_type_from_string(const char *s) _pure_; | |
cc50ef13 LP |
96 | |
97 | const char* condition_result_to_string(ConditionResult r) _const_; | |
98 | ConditionResult condition_result_from_string(const char *s) _pure_; |