chiark / gitweb /
Cleaned up more unneeded types and functions.
[elogind.git] / src / basic / unit-name.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <stdbool.h>
25
26 #include "macro.h"
27
28 #define UNIT_NAME_MAX 256
29
30 typedef enum UnitType UnitType;
31 // UNNEEDED typedef enum UnitLoadState UnitLoadState;
32 // UNNNEEDED typedef enum UnitDependency UnitDependency;
33
34 enum UnitType {
35         UNIT_SERVICE = 0,
36         UNIT_SOCKET,
37         UNIT_BUSNAME,
38         UNIT_TARGET,
39         UNIT_SNAPSHOT,
40         UNIT_DEVICE,
41         UNIT_MOUNT,
42         UNIT_AUTOMOUNT,
43         UNIT_SWAP,
44         UNIT_TIMER,
45         UNIT_PATH,
46         UNIT_SLICE,
47         UNIT_SCOPE,
48         _UNIT_TYPE_MAX,
49         _UNIT_TYPE_INVALID = -1
50 };
51
52 /// UNNEEDED by elogind
53 #if 0
54 enum UnitLoadState {
55         UNIT_STUB = 0,
56         UNIT_LOADED,
57         UNIT_NOT_FOUND,
58         UNIT_ERROR,
59         UNIT_MERGED,
60         UNIT_MASKED,
61         _UNIT_LOAD_STATE_MAX,
62         _UNIT_LOAD_STATE_INVALID = -1
63 };
64
65 enum UnitDependency {
66         /* Positive dependencies */
67         UNIT_REQUIRES,
68         UNIT_REQUIRES_OVERRIDABLE,
69         UNIT_REQUISITE,
70         UNIT_REQUISITE_OVERRIDABLE,
71         UNIT_WANTS,
72         UNIT_BINDS_TO,
73         UNIT_PART_OF,
74
75         /* Inverse of the above */
76         UNIT_REQUIRED_BY,             /* inverse of 'requires' is 'required_by' */
77         UNIT_REQUIRED_BY_OVERRIDABLE, /* inverse of 'requires_overridable' is 'required_by_overridable' */
78         UNIT_REQUISITE_OF,            /* inverse of 'requisite' is 'requisite_of' */
79         UNIT_REQUISITE_OF_OVERRIDABLE,/* inverse of 'requisite_overridable' is 'requisite_of_overridable' */
80         UNIT_WANTED_BY,               /* inverse of 'wants' */
81         UNIT_BOUND_BY,                /* inverse of 'binds_to' */
82         UNIT_CONSISTS_OF,             /* inverse of 'part_of' */
83
84         /* Negative dependencies */
85         UNIT_CONFLICTS,               /* inverse of 'conflicts' is 'conflicted_by' */
86         UNIT_CONFLICTED_BY,
87
88         /* Order */
89         UNIT_BEFORE,                  /* inverse of 'before' is 'after' and vice versa */
90         UNIT_AFTER,
91
92         /* On Failure */
93         UNIT_ON_FAILURE,
94
95         /* Triggers (i.e. a socket triggers a service) */
96         UNIT_TRIGGERS,
97         UNIT_TRIGGERED_BY,
98
99         /* Propagate reloads */
100         UNIT_PROPAGATES_RELOAD_TO,
101         UNIT_RELOAD_PROPAGATED_FROM,
102
103         /* Joins namespace of */
104         UNIT_JOINS_NAMESPACE_OF,
105
106         /* Reference information for GC logic */
107         UNIT_REFERENCES,              /* Inverse of 'references' is 'referenced_by' */
108         UNIT_REFERENCED_BY,
109
110         _UNIT_DEPENDENCY_MAX,
111         _UNIT_DEPENDENCY_INVALID = -1
112 };
113 #endif // 0
114
115 typedef enum UnitNameFlags {
116         UNIT_NAME_PLAIN = 1,      /* Allow foo.service */
117         UNIT_NAME_INSTANCE = 2,   /* Allow foo@bar.service */
118         UNIT_NAME_TEMPLATE = 4,   /* Allow foo@.service */
119         UNIT_NAME_ANY = UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE,
120 } UnitNameFlags;
121
122 bool unit_name_is_valid(const char *n, UnitNameFlags flags) _pure_;
123 bool unit_prefix_is_valid(const char *p) _pure_;
124 bool unit_instance_is_valid(const char *i) _pure_;
125 bool unit_suffix_is_valid(const char *s) _pure_;
126
127 static inline int unit_prefix_and_instance_is_valid(const char *p) {
128         /* For prefix+instance and instance the same rules apply */
129         return unit_instance_is_valid(p);
130 }
131
132 // UNNEEDED int unit_name_to_prefix(const char *n, char **prefix);
133 // UNNEEDED int unit_name_to_instance(const char *n, char **instance);
134 // UNNEEDED int unit_name_to_prefix_and_instance(const char *n, char **ret);
135
136 UnitType unit_name_to_type(const char *n) _pure_;
137
138 // UNNEEDED int unit_name_change_suffix(const char *n, const char *suffix, char **ret);
139
140 int unit_name_build(const char *prefix, const char *instance, const char *suffix, char **ret);
141
142 char *unit_name_escape(const char *f);
143 int unit_name_unescape(const char *f, char **ret);
144 int unit_name_path_escape(const char *f, char **ret);
145 int unit_name_path_unescape(const char *f, char **ret);
146
147 // UNNEEDED int unit_name_replace_instance(const char *f, const char *i, char **ret);
148
149 // UNNEEDED int unit_name_template(const char *f, char **ret);
150
151 int unit_name_from_path(const char *path, const char *suffix, char **ret);
152 // UNNEEDED int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret);
153 // UNNEEDED int unit_name_to_path(const char *name, char **ret);
154
155 char *unit_dbus_path_from_name(const char *name);
156 int unit_name_from_dbus_path(const char *path, char **name);
157
158 // UNNEEDED const char* unit_dbus_interface_from_type(UnitType t);
159 // UNNEEDED const char *unit_dbus_interface_from_name(const char *name);
160
161 /// UNNEEDED by elogind
162 #if 0
163 typedef enum UnitNameMangle {
164         UNIT_NAME_NOGLOB,
165         UNIT_NAME_GLOB,
166 } UnitNameMangle;
167
168 int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret);
169
170 static inline int unit_name_mangle(const char *name, UnitNameMangle allow_globs, char **ret) {
171         return unit_name_mangle_with_suffix(name, allow_globs, ".service", ret);
172 }
173 #endif // 0
174
175 // UNNEEDED int slice_build_parent_slice(const char *slice, char **ret);
176 int slice_build_subslice(const char *slice, const char*name, char **subslice);
177 bool slice_name_is_valid(const char *name);
178
179 const char *unit_type_to_string(UnitType i) _const_;
180 UnitType unit_type_from_string(const char *s) _pure_;
181
182 // UNNEEDED const char *unit_load_state_to_string(UnitLoadState i) _const_;
183 // UNNEEDED UnitLoadState unit_load_state_from_string(const char *s) _pure_;
184
185 // UNNEEDED const char *unit_dependency_to_string(UnitDependency i) _const_;
186 // UNNEEDED UnitDependency unit_dependency_from_string(const char *s) _pure_;