int config_parse_strv(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { char *** sv = data, *w, *state; size_t l; int r; assert(filename); assert(lvalue); assert(rvalue); assert(data); if (isempty(rvalue)) { char **empty; /* Empty assignment resets the list. As a special rule * we actually fill in a real empty array here rather * than NULL, since some code wants to know if * something was set at all... */ empty = strv_new(NULL, NULL); if (!empty) return log_oom(); strv_free(*sv); *sv = empty; return 0; } FOREACH_WORD_QUOTED(w, l, rvalue, state) { _cleanup_free_ char *n; n = cunescape_length(w, l); if (!n) return log_oom(); if (!utf8_is_valid(n)) { log_syntax(unit, LOG_ERR, filename, line, EINVAL, "String is not UTF-8 clean, ignoring: %s", rvalue); continue; } r = strv_extend(sv, n); if (r < 0) return log_oom(); }
int pull_find_old_etags( const char *url, const char *image_root, int dt, const char *prefix, const char *suffix, char ***etags) { _cleanup_free_ char *escaped_url = NULL; _cleanup_closedir_ DIR *d = NULL; _cleanup_strv_free_ char **l = NULL; struct dirent *de; int r; assert(url); assert(etags); if (!image_root) image_root = "/var/lib/machines"; escaped_url = xescape(url, FILENAME_ESCAPE); if (!escaped_url) return -ENOMEM; d = opendir(image_root); if (!d) { if (errno == ENOENT) { *etags = NULL; return 0; } return -errno; } FOREACH_DIRENT_ALL(de, d, return -errno) { const char *a, *b; char *u; if (de->d_type != DT_UNKNOWN && de->d_type != dt) continue; if (prefix) { a = startswith(de->d_name, prefix); if (!a) continue; } else a = de->d_name; a = startswith(a, escaped_url); if (!a) continue; a = startswith(a, "."); if (!a) continue; if (suffix) { b = endswith(de->d_name, suffix); if (!b) continue; } else b = strchr(de->d_name, 0); if (a >= b) continue; r = cunescape_length(a, b - a, 0, &u); if (r < 0) return r; if (!http_etag_is_valid(u)) { free(u); continue; } r = strv_consume(&l, u); if (r < 0) return r; } *etags = l; l = NULL; return 0; }