give the redirect location its own field

This implies a file version change.

Later in the project, we would want to upgrade existing files, but for
now, I assume the number of users be so close to zero that we can put
the burdon on them to lose their existing uploads once during upgrade.
parent c84bbaa4
......@@ -665,6 +665,16 @@ tus_touch(struct tus_file_core *fcore, VCL_DURATION expires)
tus_exp_touch(fcore);
}
static inline void
tus_file_fdisk_init(struct tus_file_disk *fdisk)
{
INIT_OBJ(fdisk, VMOD_TUS_FILE_DISK_MAGIC);
fdisk->guard_magic = VMOD_TUS_FILE_DISK_MAGIC;
fdisk->guard2_magic = VMOD_TUS_FILE_DISK_MAGIC;
fdisk->guard3_magic = VMOD_TUS_FILE_DISK_MAGIC;
fdisk->version = 2;
}
/* under tus_server mtx to protect tus_files */
struct tus_file_core *
tus_file_lookup(struct VPFX(tus_server) *srv, const char *url_path)
......@@ -679,10 +689,7 @@ tus_file_lookup(struct VPFX(tus_server) *srv, const char *url_path)
}
INIT_OBJ(&fcore, VMOD_TUS_FILE_CORE_MAGIC);
INIT_OBJ(&needle, VMOD_TUS_FILE_DISK_MAGIC);
needle.guard_magic = VMOD_TUS_FILE_DISK_MAGIC;
needle.guard2_magic = VMOD_TUS_FILE_DISK_MAGIC;
needle.version = 1;
tus_file_fdisk_init(&needle);
strcpy(needle.url_path, url_path);
needle.url_path_length = l;
......@@ -793,10 +800,8 @@ tus_file_new(VRT_CTX, struct VPFX(tus_server) *srv, enum tus_f_type type,
goto err;
}
INIT_OBJ(fdisk, VMOD_TUS_FILE_DISK_MAGIC);
fdisk->guard_magic = VMOD_TUS_FILE_DISK_MAGIC;
fdisk->guard2_magic = VMOD_TUS_FILE_DISK_MAGIC;
fdisk->version = 1;
tus_file_fdisk_init(fdisk);
fdisk->type = type;
fdisk->url_path_length = strlen(url_path);
......
......@@ -29,6 +29,9 @@ struct tus_file_disk {
char metadata[TUS_METADATA_MAX];
unsigned guard2_magic;
unsigned metadata_length;
char location[TUS_PATH_MAX];
unsigned guard3_magic;
unsigned location_length;
ssize_t upload_length; // -1 == defer
ssize_t upload_offset;
VCL_TIME upload_expires;
......@@ -64,10 +67,14 @@ tus_file_disk_err(const struct tus_file_disk *d)
return ("bad guard_magic");
if (d->guard2_magic != VMOD_TUS_FILE_DISK_MAGIC)
return ("bad guard2_magic");
if (d->version != 1)
return ("version != 1");
if (d->guard2_magic != VMOD_TUS_FILE_DISK_MAGIC)
return ("bad guard3_magic");
if (d->version != 2)
return ("version != 2");
if (strnlen(d->url_path, TUS_PATH_MAX) != d->url_path_length)
return ("url_path_length mismatch");
if (strnlen(d->location, TUS_PATH_MAX) != d->location_length)
return ("location_length mismatch");
if (strnlen(d->metadata, TUS_METADATA_MAX) != d->metadata_length)
return ("metadata_length mismatch");
return (NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment