]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
4f5dd394 LP |
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 | ||
4f5dd394 | 23 | #include <inttypes.h> |
11c3a366 TA |
24 | #include <stddef.h> |
25 | #include <stdint.h> | |
71d35b6b | 26 | #include <sys/types.h> |
c932fb71 | 27 | #include <uchar.h> |
4f5dd394 | 28 | |
11c3a366 | 29 | #include "string-util.h" |
c932fb71 | 30 | #include "missing.h" |
11c3a366 | 31 | |
4f5dd394 LP |
32 | /* What characters are special in the shell? */ |
33 | /* must be escaped outside and inside double-quotes */ | |
34 | #define SHELL_NEED_ESCAPE "\"\\`$" | |
804ee07c ZJS |
35 | |
36 | /* Those that can be escaped or double-quoted. | |
37 | * | |
38 | * Stricly speaking, ! does not need to be escaped, except in interactive | |
39 | * mode, but let's be extra nice to the user and quote ! in case this | |
40 | * output is ever used in interactive mode. */ | |
41 | #define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;!" | |
42 | ||
43 | /* Note that we assume control characters would need to be escaped too in | |
44 | * addition to the "special" characters listed here, if they appear in the | |
45 | * string. Current users disallow control characters. Also '"' shall not | |
46 | * be escaped. | |
47 | */ | |
48 | #define SHELL_NEED_ESCAPE_POSIX "\\\'" | |
4f5dd394 LP |
49 | |
50 | typedef enum UnescapeFlags { | |
51 | UNESCAPE_RELAX = 1, | |
52 | } UnescapeFlags; | |
53 | ||
804ee07c ZJS |
54 | typedef enum EscapeStyle { |
55 | ESCAPE_BACKSLASH = 1, | |
56 | ESCAPE_POSIX = 2, | |
57 | } EscapeStyle; | |
58 | ||
4f5dd394 | 59 | char *cescape(const char *s); |
a5ef3638 | 60 | char *cescape_length(const char *s, size_t n); |
4f5dd394 LP |
61 | size_t cescape_char(char c, char *buf); |
62 | ||
63 | int cunescape(const char *s, UnescapeFlags flags, char **ret); | |
64 | int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret); | |
65 | int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret); | |
c932fb71 | 66 | int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit); |
4f5dd394 LP |
67 | |
68 | char *xescape(const char *s, const char *bad); | |
95052df3 | 69 | char *octescape(const char *s, size_t len); |
4f5dd394 LP |
70 | |
71 | char *shell_escape(const char *s, const char *bad); | |
804ee07c | 72 | char* shell_maybe_quote(const char *s, EscapeStyle style); |