chiark / gitweb /
conf-parser: minor optimization in config_parse_string()
[elogind.git] / src / shared / 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 typedef enum UnitLoadState UnitLoadState;
32
33 enum UnitType {
34         UNIT_SERVICE = 0,
35         UNIT_SOCKET,
36         UNIT_BUSNAME,
37         UNIT_TARGET,
38         UNIT_SNAPSHOT,
39         UNIT_DEVICE,
40         UNIT_MOUNT,
41         UNIT_AUTOMOUNT,
42         UNIT_SWAP,
43         UNIT_TIMER,
44         UNIT_PATH,
45         UNIT_SLICE,
46         UNIT_SCOPE,
47         _UNIT_TYPE_MAX,
48         _UNIT_TYPE_INVALID = -1
49 };
50
51 enum UnitLoadState {
52         UNIT_STUB = 0,
53         UNIT_LOADED,
54         UNIT_NOT_FOUND,
55         UNIT_ERROR,
56         UNIT_MERGED,
57         UNIT_MASKED,
58         _UNIT_LOAD_STATE_MAX,
59         _UNIT_LOAD_STATE_INVALID = -1
60 };
61
62 const char *unit_type_to_string(UnitType i) _const_;
63 UnitType unit_type_from_string(const char *s) _pure_;
64
65 const char *unit_load_state_to_string(UnitLoadState i) _const_;
66 UnitLoadState unit_load_state_from_string(const char *s) _pure_;
67
68 int unit_name_to_instance(const char *n, char **instance);
69 char* unit_name_to_prefix(const char *n);
70 char* unit_name_to_prefix_and_instance(const char *n);
71
72 enum template_valid {
73         TEMPLATE_INVALID,
74         TEMPLATE_VALID,
75 };
76
77 bool unit_name_is_valid(const char *n, enum template_valid template_ok) _pure_;
78 bool unit_prefix_is_valid(const char *p) _pure_;
79 bool unit_instance_is_valid(const char *i) _pure_;
80
81 UnitType unit_name_to_type(const char *n) _pure_;
82
83 char *unit_name_change_suffix(const char *n, const char *suffix);
84
85 char *unit_name_build(const char *prefix, const char *instance, const char *suffix);
86
87 char *unit_name_escape(const char *f);
88 char *unit_name_unescape(const char *f);
89 char *unit_name_path_escape(const char *f);
90 char *unit_name_path_unescape(const char *f);
91
92 bool unit_name_is_template(const char *n) _pure_;
93 bool unit_name_is_instance(const char *n) _pure_;
94
95 char *unit_name_replace_instance(const char *f, const char *i);
96
97 char *unit_name_template(const char *f);
98
99 char *unit_name_from_path(const char *path, const char *suffix);
100 char *unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix);
101 char *unit_name_to_path(const char *name);
102
103 char *unit_dbus_path_from_name(const char *name);
104 int unit_name_from_dbus_path(const char *path, char **name);
105
106 enum unit_name_mangle {
107         MANGLE_NOGLOB,
108         MANGLE_GLOB,
109 };
110
111 char *unit_name_mangle(const char *name, enum unit_name_mangle allow_globs);
112 char *unit_name_mangle_with_suffix(const char *name, enum unit_name_mangle allow_globs, const char *suffix);
113
114 int build_subslice(const char *slice, const char*name, char **subslice);