diff --git a/README.md b/README.md index 5b45042..69d286c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ -# zsync-curl +## farm-ng notes!! + +This is a patched version of zsync-curl that makes -u override the URL in the .zsync file instead of overriding +the referer of the URL. That is important for downloading from AWS which uses a random URL for the real file +every time because of the access token system. The releases within this repo are built manually on the relevant +device itself. + +## zsync-curl Partial/differential file download client over HTTP(S). diff --git a/src/client.c b/src/client.c index 6d97d09..84e2c49 100644 --- a/src/client.c +++ b/src/client.c @@ -230,7 +230,7 @@ static void **append_ptrlist(int *n, void **p, void *a) { * This is avoided when we just want to parse the zsync file since it avoids * creating a temporary file and doing the extra work. */ -struct zsync_state *read_zsync_control_file(char *p, const char *fn, int readBlockSums) { +struct zsync_state *read_zsync_control_file(char *p, const char *fn, int readBlockSums, const char* urlOverride) { FILE *f; struct zsync_state *zs; char *lastpath = NULL; @@ -257,7 +257,7 @@ struct zsync_state *read_zsync_control_file(char *p, const char *fn, int readBlo } /* Read the .zsync */ - if ((zs = zsync_begin(f, readBlockSums)) == NULL) { + if ((zs = zsync_begin(f, readBlockSums, urlOverride)) == NULL) { exit(1); } @@ -603,6 +603,7 @@ int main(int argc, char **argv) { char *filename = NULL; long long local_used; char *zfname = NULL; + char *urlOverride = NULL; time_t mtime; static struct option long_options[] = { @@ -654,7 +655,7 @@ int main(int argc, char **argv) { no_progress = 1; break; case 'u': - referer = strdup(optarg); + urlOverride = strdup(optarg); break; case 'I': http_ssl_insecure = 1; @@ -698,7 +699,7 @@ int main(int argc, char **argv) { } /* STEP 1: Read the zsync control file */ - if ((zs = read_zsync_control_file(argv[optind], zfname, justCheckForUpdates ? 0 : 1)) == NULL) + if ((zs = read_zsync_control_file(argv[optind], zfname, justCheckForUpdates ? 0 : 1, urlOverride)) == NULL) exit(1); /* Get eventual filename for output, and filename to write to while working */ diff --git a/src/libzsync/zsync.c b/src/libzsync/zsync.c index 1fa18c9..7c494fc 100644 --- a/src/libzsync/zsync.c +++ b/src/libzsync/zsync.c @@ -137,7 +137,7 @@ static char **append_ptrlist(int *n, char **p, char *a) { } /* Constructor */ -struct zsync_state *zsync_begin(FILE * f, int readBlockSums) { +struct zsync_state *zsync_begin(FILE * f, int readBlockSums, const char* urlOverride) { /* Defaults for the checksum bytes and sequential matches properties of the * rcksum_state. These are the defaults from versions of zsync before these * were variable. */ @@ -158,6 +158,9 @@ struct zsync_state *zsync_begin(FILE * f, int readBlockSums) { /* Any non-zero defaults here. */ zs->mtime = -1; + if (urlOverride) + zs->url = (char **)append_ptrlist(&(zs->nurl), zs->url, strdup(urlOverride)); + for (;;) { char buf[1024]; char *p = NULL; @@ -202,7 +205,8 @@ struct zsync_state *zsync_begin(FILE * f, int readBlockSums) { zs->zfilename = strdup(p); } else if (!strcmp(buf, "URL")) { - zs->url = (char **)append_ptrlist(&(zs->nurl), zs->url, strdup(p)); + if (!urlOverride) + zs->url = (char **)append_ptrlist(&(zs->nurl), zs->url, strdup(p)); } else if (!strcmp(buf, "Z-URL")) { zs->zurl = (char **)append_ptrlist(&(zs->nzurl), zs->zurl, strdup(p)); diff --git a/src/libzsync/zsync.h b/src/libzsync/zsync.h index 019ab6f..5dbb582 100644 --- a/src/libzsync/zsync.h +++ b/src/libzsync/zsync.h @@ -18,7 +18,7 @@ struct zsync_state; /* zsync_begin - load a zsync file and return data structure to use for the rest of the process. * readBlockSums should be 0 whenever we just want to parse the zsync file */ -struct zsync_state* zsync_begin(FILE* cf, int readBlockSums); +struct zsync_state* zsync_begin(FILE* cf, int readBlockSums, const char* urlOverride); /* zsync_hint_decompress - if it returns non-zero, this suggests that * compressed seed files should be decompressed */