]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/escape.h
basic: add log_level argument to timezone_is_valid
[thirdparty/systemd.git] / src / basic / escape.h
CommitLineData
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
4f5dd394
LP
8***/
9
4f5dd394 10#include <inttypes.h>
11c3a366
TA
11#include <stddef.h>
12#include <stdint.h>
71d35b6b 13#include <sys/types.h>
c932fb71 14#include <uchar.h>
4f5dd394 15
11c3a366 16#include "string-util.h"
c932fb71 17#include "missing.h"
11c3a366 18
4f5dd394
LP
19/* What characters are special in the shell? */
20/* must be escaped outside and inside double-quotes */
21#define SHELL_NEED_ESCAPE "\"\\`$"
804ee07c
ZJS
22
23/* Those that can be escaped or double-quoted.
24 *
25 * Stricly speaking, ! does not need to be escaped, except in interactive
26 * mode, but let's be extra nice to the user and quote ! in case this
27 * output is ever used in interactive mode. */
28#define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;!"
29
30/* Note that we assume control characters would need to be escaped too in
31 * addition to the "special" characters listed here, if they appear in the
32 * string. Current users disallow control characters. Also '"' shall not
33 * be escaped.
34 */
35#define SHELL_NEED_ESCAPE_POSIX "\\\'"
4f5dd394
LP
36
37typedef enum UnescapeFlags {
38 UNESCAPE_RELAX = 1,
39} UnescapeFlags;
40
804ee07c
ZJS
41typedef enum EscapeStyle {
42 ESCAPE_BACKSLASH = 1,
43 ESCAPE_POSIX = 2,
44} EscapeStyle;
45
4f5dd394 46char *cescape(const char *s);
a5ef3638 47char *cescape_length(const char *s, size_t n);
4f5dd394
LP
48size_t cescape_char(char c, char *buf);
49
50int cunescape(const char *s, UnescapeFlags flags, char **ret);
51int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret);
52int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret);
c932fb71 53int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit);
4f5dd394
LP
54
55char *xescape(const char *s, const char *bad);
95052df3 56char *octescape(const char *s, size_t len);
4f5dd394
LP
57
58char *shell_escape(const char *s, const char *bad);
804ee07c 59char* shell_maybe_quote(const char *s, EscapeStyle style);