chiark / gitweb /
When mangling names, optionally emit a warning (#8400)
[elogind.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 #if 0 /// UNNEEDED by elogind
31 #endif // 0
32 typedef enum UnitNameFlags {
33         UNIT_NAME_PLAIN = 1,      /* Allow foo.service */
34         UNIT_NAME_INSTANCE = 2,   /* Allow foo@bar.service */
35         UNIT_NAME_TEMPLATE = 4,   /* Allow foo@.service */
36         UNIT_NAME_ANY = UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE,
37 } UnitNameFlags;
38
39 bool unit_name_is_valid(const char *n, UnitNameFlags flags) _pure_;
40 bool unit_prefix_is_valid(const char *p) _pure_;
41 bool unit_instance_is_valid(const char *i) _pure_;
42 bool unit_suffix_is_valid(const char *s) _pure_;
43
44 #if 0 /// UNNEEDED by elogind
45 static inline int unit_prefix_and_instance_is_valid(const char *p) {
46         /* For prefix+instance and instance the same rules apply */
47         return unit_instance_is_valid(p);
48 }
49
50 int unit_name_to_prefix(const char *n, char **prefix);
51 int unit_name_to_instance(const char *n, char **instance);
52 int unit_name_to_prefix_and_instance(const char *n, char **ret);
53 #endif // 0
54
55 UnitType unit_name_to_type(const char *n) _pure_;
56
57 #if 0 /// UNNEEDED by elogind
58 int unit_name_change_suffix(const char *n, const char *suffix, char **ret);
59 #endif // 0
60
61 int unit_name_build(const char *prefix, const char *instance, const char *suffix, char **ret);
62
63 #if 0 /// UNNEEDED by elogind
64 char *unit_name_escape(const char *f);
65 int unit_name_unescape(const char *f, char **ret);
66 int unit_name_path_escape(const char *f, char **ret);
67 int unit_name_path_unescape(const char *f, char **ret);
68
69 int unit_name_replace_instance(const char *f, const char *i, char **ret);
70
71 int unit_name_template(const char *f, char **ret);
72
73 int unit_name_from_path(const char *path, const char *suffix, char **ret);
74 int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret);
75 int unit_name_to_path(const char *name, char **ret);
76
77 typedef enum UnitNameMangle {
78         UNIT_NAME_MANGLE_GLOB = 1,
79         UNIT_NAME_MANGLE_WARN = 2,
80 } UnitNameMangle;
81
82 int unit_name_mangle_with_suffix(const char *name, UnitNameMangle flags, const char *suffix, char **ret);
83
84 static inline int unit_name_mangle(const char *name, UnitNameMangle flags, char **ret) {
85         return unit_name_mangle_with_suffix(name, flags, ".service", ret);
86 }
87
88 int slice_build_parent_slice(const char *slice, char **ret);
89 #endif // 0
90 int slice_build_subslice(const char *slice, const char*name, char **subslice);
91 bool slice_name_is_valid(const char *name);
92 #if 0 /// UNNEEDED by elogind
93 #endif // 0