1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include "import-util.h"
25 int import_url_last_component(const char *url, char **ret) {
29 e = strchrnul(url, '?');
31 while (e > url && e[-1] == '/')
35 while (p > url && p[-1] != '/')
41 s = strndup(p, e - p);
50 int import_url_change_last_component(const char *url, const char *suffix, char **ret) {
57 e = strchrnul(url, '?');
59 while (e > url && e[-1] == '/')
62 while (e > url && e[-1] != '/')
68 s = new(char, (e - url) + strlen(suffix) + 1);
72 strcpy(mempcpy(s, url, e - url), suffix);
77 static const char* const import_verify_table[_IMPORT_VERIFY_MAX] = {
78 [IMPORT_VERIFY_NO] = "no",
79 [IMPORT_VERIFY_CHECKSUM] = "checksum",
80 [IMPORT_VERIFY_SIGNATURE] = "signature",
83 DEFINE_STRING_TABLE_LOOKUP(import_verify, ImportVerify);
85 int tar_strip_suffixes(const char *name, char **ret) {
89 e = endswith(name, ".tar");
91 e = endswith(name, ".tar.xz");
93 e = endswith(name, ".tar.gz");
95 e = endswith(name, ".tar.bz2");
97 e = endswith(name, ".tgz");
104 s = strndup(name, e - name);
112 int raw_strip_suffixes(const char *p, char **ret) {
114 static const char suffixes[] =
123 _cleanup_free_ char *q = NULL;
131 bool changed = false;
133 NULSTR_FOREACH(sfx, suffixes) {
136 e = endswith(q, sfx);
153 bool dkr_name_is_valid(const char *name) {
154 const char *slash, *p;
159 slash = strchr(name, '/');
163 if (!filename_is_valid(slash + 1))
166 p = strndupa(name, slash - name);
167 if (!filename_is_valid(p))
173 bool dkr_id_is_valid(const char *id) {
175 if (!filename_is_valid(id))
178 if (!in_charset(id, "0123456789abcdef"))