Skip to content

Commit

Permalink
Add farmng version
Browse files Browse the repository at this point in the history
  • Loading branch information
ologic-t committed May 16, 2023
1 parent e0a7bbb commit b1fe65e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
9 changes: 5 additions & 4 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
8 changes: 6 additions & 2 deletions src/libzsync/zsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/libzsync/zsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit b1fe65e

Please sign in to comment.