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