From: Yu Watanabe Date: Tue, 11 Feb 2025 07:36:12 +0000 (+0900) Subject: journal-remote: replace extract_first_word() with simple strchr() X-Git-Tag: v258-rc1~1328^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8c7e4e0d5ef9602e5bbae3405d0dc303d17e1bc7;p=thirdparty%2Fsystemd.git journal-remote: replace extract_first_word() with simple strchr() --- diff --git a/src/journal-remote/journal-compression-util.c b/src/journal-remote/journal-compression-util.c index 4def84b2bd7..80710d6fec8 100644 --- a/src/journal-remote/journal-compression-util.c +++ b/src/journal-remote/journal-compression-util.c @@ -36,7 +36,7 @@ int config_parse_compression( } for (const char *p = rvalue;;) { - _cleanup_free_ char *algorithm = NULL, *word = NULL; + _cleanup_free_ char *word = NULL; int level = -1; r = extract_first_word(&p, &word, NULL, 0); @@ -46,25 +46,23 @@ int config_parse_compression( return 1; if (parse_level) { - const char *q = word; - r = extract_first_word(&q, &algorithm, ":", 0); - if (r < 0) - return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); - if (!isempty(q)) { + char *q = strchr(word, ':'); + if (q) { + *q++ = '\0'; + r = safe_atoi(q, &level); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, - "Compression level %s should be positive, ignoring.", q); + "Compression level must be positive, ignoring: %s", q); continue; } } - } else - algorithm = TAKE_PTR(word); + } - Compression c = compression_lowercase_from_string(algorithm); + Compression c = compression_lowercase_from_string(word); if (c < 0 || !compression_supported(c)) { log_syntax(unit, LOG_WARNING, filename, line, c, - "Compression=%s is not supported on a system, ignoring.", algorithm); + "Compression algorithm '%s' is not supported on the system, ignoring.", word); continue; } diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 15704c4396c..05ba7a6989c 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -503,28 +503,25 @@ static int update_content_encoding(Uploader *u, const char *accept_encoding) { assert(u); for (const char *p = accept_encoding;;) { - _cleanup_free_ char *encoding_value = NULL, *alg = NULL; - Compression algorithm; - CURLcode code; + _cleanup_free_ char *word = NULL; - r = extract_first_word(&p, &encoding_value, ",", 0); + r = extract_first_word(&p, &word, ",", 0); if (r < 0) - return log_error_errno(r, "Failed to extract Accept-Encoding header value: %m"); + return log_error_errno(r, "Failed to parse Accept-Encoding header value: %m"); if (r == 0) return 0; - const char *q = encoding_value; - r = extract_first_word(&q, &alg, ";", 0); - if (r < 0) - return log_error_errno(r, "Failed to extract compression algorithm from Accept-Encoding header: %m"); + /* Cut the quality value waiting. */ + char *q = strchr(word, ';'); + if (q) + *q = '\0'; - algorithm = compression_lowercase_from_string(alg); - if (algorithm <= 0 || !compression_supported(algorithm)) { - continue; - } + Compression c = compression_lowercase_from_string(word); + if (c <= 0 || !compression_supported(c)) + continue; /* unsupported or invalid algorithm. */ FOREACH_ARRAY(opt, arg_compression.opts, arg_compression.size) { - if (opt->algorithm != algorithm) + if (opt->algorithm != c) continue; _cleanup_free_ char *header = strjoin("Content-Encoding: ", compression_lowercase_to_string(u->compression.algorithm)); @@ -548,6 +545,7 @@ static int update_content_encoding(Uploader *u, const char *accept_encoding) { u->header = l; } + CURLcode code; easy_setopt(u->easy, CURLOPT_HTTPHEADER, u->header, LOG_ERR, return -EXFULL); u->compression = *opt; return 0;