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