]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/condition.h
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / shared / condition.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <stdbool.h>
5 #include <stdio.h>
6
7 #include "list.h"
8 #include "macro.h"
9
10 typedef enum ConditionType {
11 CONDITION_ARCHITECTURE,
12 CONDITION_VIRTUALIZATION,
13 CONDITION_HOST,
14 CONDITION_KERNEL_COMMAND_LINE,
15 CONDITION_KERNEL_VERSION,
16 CONDITION_SECURITY,
17 CONDITION_CAPABILITY,
18 CONDITION_AC_POWER,
19
20 CONDITION_NEEDS_UPDATE,
21 CONDITION_FIRST_BOOT,
22
23 CONDITION_PATH_EXISTS,
24 CONDITION_PATH_EXISTS_GLOB,
25 CONDITION_PATH_IS_DIRECTORY,
26 CONDITION_PATH_IS_SYMBOLIC_LINK,
27 CONDITION_PATH_IS_MOUNT_POINT,
28 CONDITION_PATH_IS_READ_WRITE,
29 CONDITION_DIRECTORY_NOT_EMPTY,
30 CONDITION_FILE_NOT_EMPTY,
31 CONDITION_FILE_IS_EXECUTABLE,
32
33 CONDITION_NULL,
34
35 CONDITION_USER,
36 CONDITION_GROUP,
37
38 CONDITION_CONTROL_GROUP_CONTROLLER,
39
40 _CONDITION_TYPE_MAX,
41 _CONDITION_TYPE_INVALID = -1
42 } ConditionType;
43
44 typedef enum ConditionResult {
45 CONDITION_UNTESTED,
46 CONDITION_SUCCEEDED,
47 CONDITION_FAILED,
48 CONDITION_ERROR,
49 _CONDITION_RESULT_MAX,
50 _CONDITION_RESULT_INVALID = -1
51 } ConditionResult;
52
53 typedef struct Condition {
54 ConditionType type:8;
55
56 bool trigger:1;
57 bool negate:1;
58
59 ConditionResult result:6;
60
61 char *parameter;
62
63 LIST_FIELDS(struct Condition, conditions);
64 } Condition;
65
66 Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate);
67 void condition_free(Condition *c);
68 Condition* condition_free_list(Condition *c);
69
70 int condition_test(Condition *c);
71
72 void condition_dump(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t));
73 void condition_dump_list(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t));
74
75 const char* condition_type_to_string(ConditionType t) _const_;
76 ConditionType condition_type_from_string(const char *s) _pure_;
77
78 const char* assert_type_to_string(ConditionType t) _const_;
79 ConditionType assert_type_from_string(const char *s) _pure_;
80
81 const char* condition_result_to_string(ConditionResult r) _const_;
82 ConditionResult condition_result_from_string(const char *s) _pure_;
83
84 static inline bool condition_takes_path(ConditionType t) {
85 return IN_SET(t,
86 CONDITION_PATH_EXISTS,
87 CONDITION_PATH_EXISTS_GLOB,
88 CONDITION_PATH_IS_DIRECTORY,
89 CONDITION_PATH_IS_SYMBOLIC_LINK,
90 CONDITION_PATH_IS_MOUNT_POINT,
91 CONDITION_PATH_IS_READ_WRITE,
92 CONDITION_DIRECTORY_NOT_EMPTY,
93 CONDITION_FILE_NOT_EMPTY,
94 CONDITION_FILE_IS_EXECUTABLE,
95 CONDITION_NEEDS_UPDATE);
96 }