]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
9e2f7c11 | 3 | |
e82f30d1 LP |
4 | #include "string-util.h" |
5 | ||
303ee601 | 6 | typedef int (*SpecifierCallback)(char specifier, const void *data, const void *userdata, char **ret); |
9e2f7c11 LP |
7 | |
8 | typedef struct Specifier { | |
9 | const char specifier; | |
10 | const SpecifierCallback lookup; | |
303ee601 | 11 | const void *data; |
9e2f7c11 LP |
12 | } Specifier; |
13 | ||
06536492 | 14 | int specifier_printf(const char *text, size_t max_length, const Specifier table[], const void *userdata, char **ret); |
9e2f7c11 | 15 | |
303ee601 | 16 | int specifier_string(char specifier, const void *data, const void *userdata, char **ret); |
d848b9cb | 17 | |
303ee601 ZJS |
18 | int specifier_machine_id(char specifier, const void *data, const void *userdata, char **ret); |
19 | int specifier_boot_id(char specifier, const void *data, const void *userdata, char **ret); | |
20 | int specifier_host_name(char specifier, const void *data, const void *userdata, char **ret); | |
e97708fa | 21 | int specifier_short_host_name(char specifier, const void *data, const void *userdata, char **ret); |
303ee601 | 22 | int specifier_kernel_release(char specifier, const void *data, const void *userdata, char **ret); |
268f5a54 LP |
23 | int specifier_architecture(char specifier, const void *data, const void *userdata, char **ret); |
24 | int specifier_os_id(char specifier, const void *data, const void *userdata, char **ret); | |
25 | int specifier_os_version_id(char specifier, const void *data, const void *userdata, char **ret); | |
26 | int specifier_os_build_id(char specifier, const void *data, const void *userdata, char **ret); | |
27 | int specifier_os_variant_id(char specifier, const void *data, const void *userdata, char **ret); | |
9a515f0a LP |
28 | int specifier_os_image_id(char specifier, const void *data, const void *userdata, char **ret); |
29 | int specifier_os_image_version(char specifier, const void *data, const void *userdata, char **ret); | |
e82f30d1 | 30 | |
303ee601 ZJS |
31 | int specifier_group_name(char specifier, const void *data, const void *userdata, char **ret); |
32 | int specifier_group_id(char specifier, const void *data, const void *userdata, char **ret); | |
33 | int specifier_user_name(char specifier, const void *data, const void *userdata, char **ret); | |
34 | int specifier_user_id(char specifier, const void *data, const void *userdata, char **ret); | |
35 | int specifier_user_home(char specifier, const void *data, const void *userdata, char **ret); | |
36 | int specifier_user_shell(char specifier, const void *data, const void *userdata, char **ret); | |
36444d22 | 37 | |
303ee601 ZJS |
38 | int specifier_tmp_dir(char specifier, const void *data, const void *userdata, char **ret); |
39 | int specifier_var_tmp_dir(char specifier, const void *data, const void *userdata, char **ret); | |
b294e594 | 40 | |
2824aa07 | 41 | /* Typically, in places where one of the above specifier is to be resolved the other similar ones are to be |
e93387f3 YW |
42 | * resolved, too. Hence let's define common macros for the relevant array entries. |
43 | * | |
44 | * COMMON_SYSTEM_SPECIFIERS: | |
45 | * %a: the native userspace architecture | |
9a515f0a | 46 | * %A: the OS image version, according to /etc/os-release |
e93387f3 YW |
47 | * %b: the boot ID of the running system |
48 | * %B: the OS build ID, according to /etc/os-release | |
49 | * %H: the hostname of the running system | |
50 | * %l: the short hostname of the running system | |
51 | * %m: the machine ID of the running system | |
9a515f0a | 52 | * %M: the OS image ID, according to /etc/os-release |
e93387f3 YW |
53 | * %o: the OS ID according to /etc/os-release |
54 | * %v: the kernel version | |
55 | * %w: the OS version ID, according to /etc/os-release | |
56 | * %W: the OS variant ID, according to /etc/os-release | |
57 | * | |
58 | * COMMON_CREDS_SPECIFIERS: | |
59 | * %g: the groupname of the running user | |
60 | * %G: the GID of the running user | |
61 | * %u: the username of the running user | |
62 | * %U: the UID of the running user | |
63 | * | |
64 | * COMMON_TMP_SPECIFIERS: | |
65 | * %T: the temporary directory (e.g. /tmp, or $TMPDIR, $TEMP, $TMP) | |
66 | * %V: the temporary directory for large, persistent stuff (e.g. /var/tmp, or $TMPDIR, $TEMP, $TMP) | |
67 | */ | |
68 | ||
2824aa07 | 69 | #define COMMON_SYSTEM_SPECIFIERS \ |
e93387f3 | 70 | { 'a', specifier_architecture, NULL }, \ |
9a515f0a | 71 | { 'A', specifier_os_image_version,NULL }, \ |
2824aa07 | 72 | { 'b', specifier_boot_id, NULL }, \ |
e93387f3 | 73 | { 'B', specifier_os_build_id, NULL }, \ |
2824aa07 LP |
74 | { 'H', specifier_host_name, NULL }, \ |
75 | { 'l', specifier_short_host_name, NULL }, \ | |
e93387f3 | 76 | { 'm', specifier_machine_id, NULL }, \ |
9a515f0a | 77 | { 'M', specifier_os_image_id, NULL }, \ |
2824aa07 | 78 | { 'o', specifier_os_id, NULL }, \ |
e93387f3 | 79 | { 'v', specifier_kernel_release, NULL }, \ |
2824aa07 | 80 | { 'w', specifier_os_version_id, NULL }, \ |
2824aa07 LP |
81 | { 'W', specifier_os_variant_id, NULL } |
82 | ||
83 | #define COMMON_CREDS_SPECIFIERS \ | |
84 | { 'g', specifier_group_name, NULL }, \ | |
85 | { 'G', specifier_group_id, NULL }, \ | |
e93387f3 YW |
86 | { 'u', specifier_user_name, NULL }, \ |
87 | { 'U', specifier_user_id, NULL } | |
2824aa07 LP |
88 | |
89 | #define COMMON_TMP_SPECIFIERS \ | |
90 | { 'T', specifier_tmp_dir, NULL }, \ | |
91 | { 'V', specifier_var_tmp_dir, NULL } | |
92 | ||
e82f30d1 LP |
93 | static inline char* specifier_escape(const char *string) { |
94 | return strreplace(string, "%", "%%"); | |
95 | } | |
96 | ||
97 | int specifier_escape_strv(char **l, char ***ret); | |
2caed041 LP |
98 | |
99 | /* A generic specifier table consisting of COMMON_SYSTEM_SPECIFIERS and COMMON_TMP_SPECIFIERS */ | |
100 | extern const Specifier system_and_tmp_specifier_table[]; |