summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2023-04-24 16:53:11 +0300
committerTimo Teräs <timo.teras@iki.fi>2023-04-24 16:53:11 +0300
commit5e5d2008d9f37e12788860d3c7996d712b25df5f (patch)
treec5b780d1b4f1d99929bf80a0a7b83a3cadfcfdb8
parentdcdc0901b4e849b805c5395142539cc03ecd2193 (diff)
downloadapk-tools-5e5d2008d9f37e12788860d3c7996d712b25df5f.tar.gz
apk-tools-5e5d2008d9f37e12788860d3c7996d712b25df5f.tar.bz2
apk-tools-5e5d2008d9f37e12788860d3c7996d712b25df5f.tar.xz
apk-tools-5e5d2008d9f37e12788860d3c7996d712b25df5f.zip
libfetch, apk: display warning for permanent redirects during init
fixes #10776
-rw-r--r--libfetch/fetch.c1
-rw-r--r--libfetch/fetch.h4
-rw-r--r--libfetch/http.c2
-rw-r--r--src/apk.c14
4 files changed, 21 insertions, 0 deletions
diff --git a/libfetch/fetch.c b/libfetch/fetch.c
index 68d920c..efee05f 100644
--- a/libfetch/fetch.c
+++ b/libfetch/fetch.c
@@ -39,6 +39,7 @@
#include "fetch.h"
#include "common.h"
+fetch_redirect_t fetchRedirectMethod;
auth_t fetchAuthMethod;
int fetchLastErrCode;
char fetchLastErrString[MAXERRSTRING];
diff --git a/libfetch/fetch.h b/libfetch/fetch.h
index 0c07c05..15c60e9 100644
--- a/libfetch/fetch.h
+++ b/libfetch/fetch.h
@@ -164,6 +164,10 @@ char *fetchUnquoteFilename(struct url *);
void fetchConnectionCacheInit(int, int);
void fetchConnectionCacheClose(void);
+/* Redirects */
+typedef void (*fetch_redirect_t)(int, const struct url *, const struct url *);
+extern fetch_redirect_t fetchRedirectMethod;
+
/* Authentication */
typedef int (*auth_t)(struct url *);
extern auth_t fetchAuthMethod;
diff --git a/libfetch/http.c b/libfetch/http.c
index 51f1316..4f761f9 100644
--- a/libfetch/http.c
+++ b/libfetch/http.c
@@ -1062,6 +1062,8 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
}
new->offset = url->offset;
new->length = url->length;
+ if (fetchRedirectMethod)
+ fetchRedirectMethod(conn->err, url, new);
break;
case hdr_transfer_encoding:
/* XXX weak test*/
diff --git a/src/apk.c b/src/apk.c
index 1926ade..b5aed6f 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -474,6 +474,18 @@ static int remove_empty_strings(int count, char **args)
return j;
}
+static void fetch_redirect(int code, const struct url *cur, const struct url *next)
+{
+ switch (code) {
+ case 301: // Moved Permanently
+ case 308: // Permanent Redirect
+ char *url = fetchStringifyURL(next);
+ apk_warn(&ctx.out, "Permanently redirected to %s", url);
+ free(url);
+ break;
+ }
+}
+
int main(int argc, char **argv)
{
void *applet_ctx = NULL;
@@ -507,6 +519,7 @@ int main(int argc, char **argv)
apk_crypto_init();
setup_automatic_flags(&ctx);
fetchTimeout = 60;
+ fetchRedirectMethod = fetch_redirect;
fetchConnectionCacheInit(32, 4);
r = parse_options(argc, argv, applet, applet_ctx, &ctx);
@@ -594,6 +607,7 @@ int main(int argc, char **argv)
apk_string_array_resize(&args, argc);
memcpy(args->item, argv, argc * sizeof(*argv));
+ fetchRedirectMethod = NULL;
r = applet->main(applet_ctx, &ctx, args);
signal(SIGINT, SIG_IGN);