]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/unit-name.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / unit-name.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 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
25 #include "macro.h"
26 #include "unit-def.h"
27
28 #define UNIT_NAME_MAX 256
29
30 typedef enum UnitNameFlags {
31 UNIT_NAME_PLAIN = 1, /* Allow foo.service */
32 UNIT_NAME_INSTANCE = 2, /* Allow foo@bar.service */
33 UNIT_NAME_TEMPLATE = 4, /* Allow foo@.service */
34 UNIT_NAME_ANY = UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE,
35 } UnitNameFlags;
36
37 bool unit_name_is_valid(const char *n, UnitNameFlags flags) _pure_;
38 bool unit_prefix_is_valid(const char *p) _pure_;
39 bool unit_instance_is_valid(const char *i) _pure_;
40 bool unit_suffix_is_valid(const char *s) _pure_;
41
42 static inline int unit_prefix_and_instance_is_valid(const char *p) {
43 /* For prefix+instance and instance the same rules apply */
44 return unit_instance_is_valid(p);
45 }
46
47 int unit_name_to_prefix(const char *n, char **prefix);
48 int unit_name_to_instance(const char *n, char **instance);
49 int unit_name_to_prefix_and_instance(const char *n, char **ret);
50
51 UnitType unit_name_to_type(const char *n) _pure_;
52
53 int unit_name_change_suffix(const char *n, const char *suffix, char **ret);
54
55 int unit_name_build(const char *prefix, const char *instance, const char *suffix, char **ret);
56
57 char *unit_name_escape(const char *f);
58 int unit_name_unescape(const char *f, char **ret);
59 int unit_name_path_escape(const char *f, char **ret);
60 int unit_name_path_unescape(const char *f, char **ret);
61
62 int unit_name_replace_instance(const char *f, const char *i, char **ret);
63
64 int unit_name_template(const char *f, char **ret);
65
66 int unit_name_from_path(const char *path, const char *suffix, char **ret);
67 int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret);
68 int unit_name_to_path(const char *name, char **ret);
69
70 typedef enum UnitNameMangle {
71 UNIT_NAME_NOGLOB,
72 UNIT_NAME_GLOB,
73 } UnitNameMangle;
74
75 int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret);
76
77 static inline int unit_name_mangle(const char *name, UnitNameMangle allow_globs, char **ret) {
78 return unit_name_mangle_with_suffix(name, allow_globs, ".service", ret);
79 }
80
81 int slice_build_parent_slice(const char *slice, char **ret);
82 int slice_build_subslice(const char *slice, const char*name, char **subslice);
83 bool slice_name_is_valid(const char *name);