mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
journal-remote: replace extract_first_word() with simple strchr()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user