summaryrefslogtreecommitdiffstats
path: root/src/basic/escape.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* escape: add flags argument to quote_command_line()Lennart Poettering2021-11-111-1/+1
| | | | That way, we can reuse the call at one more place (see later patch).
* Merge pull request #20186 from keszybz/coverity-fixesLuca Boccassi2021-07-091-4/+5
|\ | | | | Coverity fixes
| * tree-wide: make cunescape*() functions return ssize_tZbigniew Jędrzejewski-Szmek2021-07-091-4/+5
| | | | | | | | | | Strictly speaking, we are returning the size of a memory chunk of arbitrary size, so ssize_t is more appropriate than int.
* | basic/escape: add helper for quoting command linesZbigniew Jędrzejewski-Szmek2021-07-091-0/+1
|/
* basic/escape: allow truncation mode where "…" is always appendedZbigniew Jędrzejewski-Szmek2021-05-051-0/+1
| | | | | | | | | | | So far we would append "…" or "..." when the string was wider than the specified output width. But let's add a mode where the caller knows that the string being passed is already truncated. The condition for jumping back in utf8_escape_non_printable_full() was off-by-one. But we only jumped to that label after doing a check with a stronger condition, so I think it didn't matter. Now it matters because we'd output the forced ellipsis one column too early.
* basic/escape: flagsify xescape_full()Zbigniew Jędrzejewski-Szmek2021-05-051-3/+7
|
* basic/escape: add mode where empty arguments are still shown as ""Zbigniew Jędrzejewski-Szmek2021-05-051-0/+1
| | | | | For variables, FOO= is OK. But when quoting positional arguments, we want to use something with quotes ("", '', or even $'') for an empty string.
* Flagsify EscapeStyle and make ESCAPE_BACKSLASH_ONELINE implicitZbigniew Jędrzejewski-Szmek2021-04-011-10/+7
| | | | | | | | | | | | I want to tweak behaviour further, and that'll be easier when "style" is converted to a bitfield. Some callers used ESCAPE_BACKSLASH_ONELINE, and others not. But the ones that didn't, simply didn't care, because the argument was assumed to be one-line anyway (e.g. a service name). In environment-generator, this could make a difference. But I think it's better to escape the newlines there too. So newlines are now always escaped, to simplify the code and the test matrix.
* tree-wide: fix typoYu Watanabe2020-11-251-1/+1
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* basic/escape: use consistent location for "*" in function declarationsZbigniew Jędrzejewski-Szmek2020-08-311-7/+7
| | | | | | I think it's nicer to move it to the left, since the function is already a pointer by itself, and it just happens to return a pointer, and the two concepts are completely separate.
* shared/escape: add new escape style with \n\t escapedZbigniew Jędrzejewski-Szmek2020-04-091-2/+7
|
* escape: introduce UNESCAPE_ACCEPT_NUL flagYu Watanabe2020-01-271-3/+4
|
* escape: make cunescape() and cunescape_length() inlineYu Watanabe2020-01-271-2/+6
|
* Add 8bit-version of get_process_cmdline() and use in cgroup-show.cZbigniew Jędrzejewski-Szmek2019-05-221-0/+1
| | | | | | | | | | | This restores show_pid_array() output in legacy locales on the console. Only one call to get_process_cmdline() is changed, all others retain utf8-only mode. This affects systemd-cgls, systemctl status, etc, when working locally. Calls to get_process_cmdline() that cross a process boundary always use utf8. It's the callers responsibility to convert this to some encoding that they use. This means that we always pass utf8 over the bus.
* basic/escape: add truncation to xescape tooZbigniew Jędrzejewski-Szmek2019-05-221-1/+4
| | | | | This does for ASCII and non-unicode encodings what utf8_escape_non_printable_full() does for utf8-based encodings.
* missing: move char{16,32}_t definitions to missing_type.hYu Watanabe2018-12-041-1/+1
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* basic/journal-importer: do not write non-unicode char to logZbigniew Jędrzejewski-Szmek2018-05-311-1/+1
| | | | | The type of cescape_char() is changed to int to make it easier to use in "%.*s". We know the value is between 1 and 4, so size_t is overkill.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* Use "dollar-single-quotes" to escape shell-sensitive stringsZbigniew Jędrzejewski-Szmek2017-06-201-3/+20
| | | | | | | | | | | | | | | | | | | | | | | | | Also called "ANSI-C Quoting" in info:(bash) ANSI-C Quoting. The escaping rules are a POSIX proposal, and are described in http://austingroupbugs.net/view.php?id=249. There's a lot of back-and-forth on the details of escaping of control characters, but we'll be only using a small subset of the syntax that is common to all proposals and is widely supported. Unfortunately dash and fish and maybe some other shells do not support it (see the man page patch for a list). This allows environment variables to be safely exported using show-environment and imported into the shell. Shells which do not support this syntax will have to do something like export $(systemctl show-environment|grep -v '=\$') or whatever is appropriate in their case. I think csh and fish do not support the A=B syntax anyway, so the change is moot for them. Fixes #5536. v2: - also escape newlines (which currently disallowed in shell values, so this doesn't really matter), and tabs (as $'\t'), and ! (as $'!'). This way quoted output can be included directly in both interactive and noninteractive bash.
* Merge pull request #2589 from keszybz/resolve-tool-2Lennart Poettering2016-02-131-0/+1
|\ | | | | Better support of OPENPGPKEY, CAA, TLSA packets and tests
| * resolve: parse CAA recordsZbigniew Jędrzejewski-Szmek2016-02-131-0/+1
| |
* | tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
|/ | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* utf8.[ch] et al: use char32_t and char16_t instead of int, int32_t, int16_tShawn Landden2016-01-271-1/+3
| | | | | | | | | | | | rework C11 utf8.[ch] to use char32_t instead of uint32_t when referring to unicode chars, to make things more expressive. [ @zonque: * rebased to current master * use AC_CHECK_DECLS to detect availibility of char{16,32}_t * make utf8_encoded_to_unichar() return int ]
* basic/escape: merge utf8 and non-utf8 paths in cunescape_oneZbigniew Jędrzejewski-Szmek2016-01-181-1/+1
| | | | | | | | | | | | | | | | | | | Not every byte sequence is valid utf8. We allow escaping of non-utf8 sequences in strings by using octal and hexadecimal escape sequences (\123 and \0xAB) for bytes at or above 128. Users of cunescape_one could infer whether such use occured when they received an answer between 128 and 256 in *ret (a non-ascii one byte character). But this is subtle and misleading: the comments were wrong, because ascii is a subset of unicode, so c != 0 did not mean non-unicode, but rather ascii-subset-of-unicode-or-raw-byte. This was all rather confusing, so make the "single byte" condition explicit. I'm not convinced that allowing non-utf8 sequences to be produced is useful in all cases where we allow it (e.g. in config files), but that behaviour is unchanged, just made more explicit. This also fixes an (invalid) gcc warning about unitialized variable (*ret_unicode) in callers of cunescape_one.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-0/+4
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* escape: add cescape_length() call as generalization of cescape()Lennart Poettering2015-11-231-0/+1
|
* tree-wide: sort includes in *.hThomas Hindoe Paaboel Andersen2015-11-181-1/+1
| | | | | This is a continuation of the previous include sort patch, which only sorted for .c files.
* util: split out escaping code into escape.[ch]Lennart Poettering2015-10-241-0/+48
This really deserves its own file, given how much code this is now.