Polish based on Flexelint analysis

parent 5ea6e972
...@@ -52,6 +52,7 @@ libvmod_tus_la_SOURCES += \ ...@@ -52,6 +52,7 @@ libvmod_tus_la_SOURCES += \
tus_file.h \ tus_file.h \
tus_file_exp.c \ tus_file_exp.c \
tus_file_exp.h \ tus_file_exp.h \
tus_file_exp_setup.h \
tus_hdr.c \ tus_hdr.c \
tus_hdr.h \ tus_hdr.h \
tus_hex.c \ tus_hex.c \
......
...@@ -136,6 +136,8 @@ tus_chksum_init(VRT_CTX) { ...@@ -136,6 +136,8 @@ tus_chksum_init(VRT_CTX) {
int int
tus_chksum_fini(VRT_CTX) { tus_chksum_fini(VRT_CTX) {
(void) ctx;
#define HENUM(t, b) if (digest_ ## t != NULL) \ #define HENUM(t, b) if (digest_ ## t != NULL) \
vmod_blobdigest->digest__fini(&digest_ ## t); vmod_blobdigest->digest__fini(&digest_ ## t);
#include "tbl_hash_enum.h" #include "tbl_hash_enum.h"
......
...@@ -47,13 +47,16 @@ ...@@ -47,13 +47,16 @@
#include "tus_hex.h" #include "tus_hex.h"
#include "tus_file_exp.h" #include "tus_file_exp.h"
VSPLAY_GENERATE(tus_files, tus_file_core, entry, tus_file_cmp); VSPLAY_GENERATE(tus_files, tus_file_core, entry, tus_file_cmp)
#define TUS_FILE_PFX "tus_" #define TUS_FILE_PFX "tus_"
#define TUS_FILE_RAND 16 #define TUS_FILE_RAND 16
#define TUS_FILE_SUFF "_XXXXXX" #define TUS_FILE_SUFF "_XXXXXX"
static uintmax_t header_size; static uintmax_t header_size;
static unsigned tus_file_ref(struct tus_file_core *);
static unsigned tus_file_unref(struct tus_file_core *);
/* /*
* ------------------------------------------------------------ * ------------------------------------------------------------
...@@ -101,7 +104,7 @@ tus_file_final_concat_parse(const char *spec) ...@@ -101,7 +104,7 @@ tus_file_final_concat_parse(const char *spec)
spec = strchr(spec, ' '); spec = strchr(spec, ' ');
} }
VSB_bcat(vsb, "\0", 1); VSB_bcat(vsb, "\0", 1);
VSB_finish(vsb); AZ(VSB_finish(vsb));
return (vsb); return (vsb);
...@@ -114,14 +117,13 @@ struct concat_embryo * ...@@ -114,14 +117,13 @@ struct concat_embryo *
tus_file_final_concat(struct VPFX(tus_server) *srv, tus_file_final_concat(struct VPFX(tus_server) *srv,
struct concat_embryo *embryo, const char *spec) struct concat_embryo *embryo, const char *spec)
{ {
struct tus_file_core *part, *parts[MAX_CONCAT]; struct tus_file_core *part, *parts[MAX_CONCAT] = {NULL};
struct tus_concat *concat; struct tus_concat *concat;
const struct tus_file_disk *pdisk; const struct tus_file_disk *pdisk;
struct vsb *vsb; struct vsb *vsb;
unsigned i, n = 0; unsigned i, n = 0;
struct timespec ts; struct timespec ts;
ssize_t length = 0; ssize_t length = 0;
int errno;
size_t l, ml; size_t l, ml;
vsb = tus_file_final_concat_parse(spec); vsb = tus_file_final_concat_parse(spec);
...@@ -155,6 +157,7 @@ tus_file_final_concat(struct VPFX(tus_server) *srv, ...@@ -155,6 +157,7 @@ tus_file_final_concat(struct VPFX(tus_server) *srv,
ts.tv_sec += READY_TIMEOUT; ts.tv_sec += READY_TIMEOUT;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
part = parts[i]; part = parts[i];
AN(part);
pdisk = part->disk; pdisk = part->disk;
AN(pdisk); AN(pdisk);
if (part->ptr != NULL) { if (part->ptr != NULL) {
...@@ -485,13 +488,13 @@ void ...@@ -485,13 +488,13 @@ void
tus_file_del(struct tus_file_core **fcorep) tus_file_del(struct tus_file_core **fcorep)
{ {
struct tus_file_core *fcore; struct tus_file_core *fcore;
const struct tus_file_core *remove; const struct tus_file_core *rm;
TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC); TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC);
remove = VSPLAY_REMOVE(tus_files, tus_server_files(fcore->server), rm = VSPLAY_REMOVE(tus_files, tus_server_files(fcore->server),
fcore); fcore);
assert (remove == fcore); assert (rm == fcore);
tus_exp_delete(fcore); tus_exp_delete(fcore);
(void) tus_file_unref_locked(fcore); (void) tus_file_unref_locked(fcore);
...@@ -502,8 +505,9 @@ void ...@@ -502,8 +505,9 @@ void
tus_file_shutdown(struct VPFX(tus_server) *srv) tus_file_shutdown(struct VPFX(tus_server) *srv)
{ {
struct tus_file_core *fcore; struct tus_file_core *fcore;
struct tus_files *files = tus_server_files(srv);
VSPLAY_FOREACH(fcore, tus_files, tus_server_files(srv)) { VSPLAY_FOREACH(fcore, tus_files, files) {
REPLACE(fcore->filename, NULL); // prevent unlink REPLACE(fcore->filename, NULL); // prevent unlink
AZ(pthread_mutex_lock(&fcore->mtx)); AZ(pthread_mutex_lock(&fcore->mtx));
tus_file_del(&fcore); tus_file_del(&fcore);
...@@ -547,7 +551,7 @@ tus_file_rename_base(struct tus_file_core *fcore, const char *basename) ...@@ -547,7 +551,7 @@ tus_file_rename_base(struct tus_file_core *fcore, const char *basename)
} }
#endif #endif
unsigned static unsigned
tus_file_ref(struct tus_file_core *fcore) tus_file_ref(struct tus_file_core *fcore)
{ {
unsigned r; unsigned r;
...@@ -572,7 +576,8 @@ tus_file_unref_locked(struct tus_file_core *fcore) ...@@ -572,7 +576,8 @@ tus_file_unref_locked(struct tus_file_core *fcore)
tus_file_fini(fcore); tus_file_fini(fcore);
return (r); return (r);
} }
unsigned
static unsigned
tus_file_unref(struct tus_file_core *fcore) tus_file_unref(struct tus_file_core *fcore)
{ {
...@@ -698,7 +703,7 @@ tus_file_load(struct VPFX(tus_server) *srv) ...@@ -698,7 +703,7 @@ tus_file_load(struct VPFX(tus_server) *srv)
} }
static void static void
tus_touch(struct tus_file_core *fcore, VCL_DURATION expires) tus_touch(const struct tus_file_core *fcore, VCL_DURATION expires)
{ {
struct tus_file_disk *fdisk; struct tus_file_disk *fdisk;
VCL_TIME t = VTIM_real(); VCL_TIME t = VTIM_real();
...@@ -759,7 +764,7 @@ tus_name_rnd(struct vsb *vsb) ...@@ -759,7 +764,7 @@ tus_name_rnd(struct vsb *vsb)
char rnd[TUS_FILE_RAND]; char rnd[TUS_FILE_RAND];
struct vrt_blob b; struct vrt_blob b;
VRND_RandomCrypto(rnd, sizeof rnd); AZ(VRND_RandomCrypto(rnd, sizeof rnd));
b.type = 0x1055; b.type = 0x1055;
b.blob = rnd; b.blob = rnd;
b.len = sizeof rnd; b.len = sizeof rnd;
...@@ -778,7 +783,7 @@ tus_file_new(VRT_CTX, struct VPFX(tus_server) *srv, enum tus_f_type type, ...@@ -778,7 +783,7 @@ tus_file_new(VRT_CTX, struct VPFX(tus_server) *srv, enum tus_f_type type,
struct vsb vsb_path[1]; struct vsb vsb_path[1];
const char *path; const char *path;
const char *filename; // relative to base const char *filename; // relative to base
int fd = -1; int fd;
size_t l; size_t l;
if (id != NULL) { if (id != NULL) {
...@@ -988,12 +993,17 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore) ...@@ -988,12 +993,17 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
} }
VCL_BOOL VCL_BOOL
tus_file_done(struct tus_file_core *fcore, struct tus_file_disk *fdisk, const char *url) tus_file_done(struct tus_file_core *fcore, struct tus_file_disk *fdisk,
const char *url)
{ {
int fd, need_truncate; int fd, need_truncate;
size_t l = strlen(url); size_t l;
if (url == NULL)
return (0);
if (l >= TUS_PATH_MAX) l = strlen(url);
if (l == 0 || l >= TUS_PATH_MAX)
return (0); return (0);
need_truncate = (fdisk->location_length == 0); need_truncate = (fdisk->location_length == 0);
......
...@@ -128,10 +128,10 @@ tus_file_cmp(const struct tus_file_core *a, ...@@ -128,10 +128,10 @@ tus_file_cmp(const struct tus_file_core *a,
CHECK_TUS_FILE_DISK(aa); CHECK_TUS_FILE_DISK(aa);
CHECK_TUS_FILE_DISK(bb); CHECK_TUS_FILE_DISK(bb);
return (strcmp(aa->url_path, bb->url_path)); return (strcmp(aa->url_path, bb->url_path));
}; }
VSPLAY_HEAD(tus_files, tus_file_core); VSPLAY_HEAD(tus_files, tus_file_core);
VSPLAY_PROTOTYPE(tus_files, tus_file_core, entry, tus_file_cmp); VSPLAY_PROTOTYPE(tus_files, tus_file_core, entry, tus_file_cmp)
// tus_file.c // tus_file.c
void tus_file_init(void); void tus_file_init(void);
...@@ -143,8 +143,6 @@ struct tus_file_core *tus_file_new(VRT_CTX, struct VPFX(tus_server) *, ...@@ -143,8 +143,6 @@ struct tus_file_core *tus_file_new(VRT_CTX, struct VPFX(tus_server) *,
struct tus_file_core *tus_file_lookup(struct VPFX(tus_server) *, const char *); struct tus_file_core *tus_file_lookup(struct VPFX(tus_server) *, const char *);
unsigned tus_body_to_file(VRT_CTX, struct tus_file_core *); unsigned tus_body_to_file(VRT_CTX, struct tus_file_core *);
void tus_file_mmap(struct tus_file_core *); void tus_file_mmap(struct tus_file_core *);
unsigned tus_file_ref(struct tus_file_core *);
unsigned tus_file_unref(struct tus_file_core *);
#ifdef BAD_IDEA #ifdef BAD_IDEA
void void
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "tus_file.h" #include "tus_file.h"
#include "tus_file_exp.h" #include "tus_file_exp.h"
#include "tus_file_exp_setup.h"
struct tus_exp { struct tus_exp {
unsigned magic; unsigned magic;
...@@ -62,7 +63,7 @@ fcore_when(const void *p) ...@@ -62,7 +63,7 @@ fcore_when(const void *p)
return (fdisk->upload_expires); return (fdisk->upload_expires);
} }
void * static void *
tus_exp_thread(void *p) tus_exp_thread(void *p)
{ {
struct VPFX(tus_server) *srv; struct VPFX(tus_server) *srv;
...@@ -72,11 +73,11 @@ tus_exp_thread(void *p) ...@@ -72,11 +73,11 @@ tus_exp_thread(void *p)
vtim_real now, when, t; vtim_real now, when, t;
CAST_OBJ_NOTNULL(e, p, TUS_EXP_MAGIC); CAST_OBJ_NOTNULL(e, p, TUS_EXP_MAGIC);
pthread_mutex_lock(&e->mtx); AZ(pthread_mutex_lock(&e->mtx));
while (! e->die) { while (! e->die) {
fcore = VBH_root(e->heap); fcore = VBH_root(e->heap);
if (fcore == NULL) { if (fcore == NULL) {
pthread_cond_wait(&e->cond, &e->mtx); AZ(pthread_cond_wait(&e->cond, &e->mtx));
continue; continue;
} }
...@@ -93,7 +94,7 @@ tus_exp_thread(void *p) ...@@ -93,7 +94,7 @@ tus_exp_thread(void *p)
continue; continue;
} }
pthread_mutex_unlock(&e->mtx); AZ(pthread_mutex_unlock(&e->mtx));
srv = fcore->server; srv = fcore->server;
tus_server_lock(srv); tus_server_lock(srv);
...@@ -101,9 +102,9 @@ tus_exp_thread(void *p) ...@@ -101,9 +102,9 @@ tus_exp_thread(void *p)
tus_file_del(&fcore); tus_file_del(&fcore);
tus_server_unlock(srv); tus_server_unlock(srv);
pthread_mutex_lock(&e->mtx); AZ(pthread_mutex_lock(&e->mtx));
} }
pthread_mutex_unlock(&e->mtx); AZ(pthread_mutex_unlock(&e->mtx));
return (NULL); return (NULL);
} }
...@@ -114,10 +115,10 @@ tus_exp_delete(const struct tus_file_core *fcore) ...@@ -114,10 +115,10 @@ tus_exp_delete(const struct tus_file_core *fcore)
CHECK_OBJ_NOTNULL(e, TUS_EXP_MAGIC); CHECK_OBJ_NOTNULL(e, TUS_EXP_MAGIC);
pthread_mutex_lock(&e->mtx); AZ(pthread_mutex_lock(&e->mtx));
assert(fcore->exp_idx != VBH_NOIDX); assert(fcore->exp_idx != VBH_NOIDX);
VBH_delete(e->heap, fcore->exp_idx); VBH_delete(e->heap, fcore->exp_idx);
pthread_mutex_unlock(&e->mtx); AZ(pthread_mutex_unlock(&e->mtx));
} }
void void
...@@ -127,11 +128,11 @@ tus_exp_insert(struct tus_file_core *fcore) ...@@ -127,11 +128,11 @@ tus_exp_insert(struct tus_file_core *fcore)
CHECK_OBJ_NOTNULL(e, TUS_EXP_MAGIC); CHECK_OBJ_NOTNULL(e, TUS_EXP_MAGIC);
pthread_mutex_lock(&e->mtx); AZ(pthread_mutex_lock(&e->mtx));
VBH_insert(e->heap, fcore); VBH_insert(e->heap, fcore);
if (VBH_root(e->heap) == fcore) if (VBH_root(e->heap) == fcore)
pthread_cond_signal(&e->cond); AZ(pthread_cond_signal(&e->cond));
pthread_mutex_unlock(&e->mtx); AZ(pthread_mutex_unlock(&e->mtx));
} }
void void
...@@ -141,9 +142,9 @@ tus_exp_touch(const struct tus_file_core *fcore) ...@@ -141,9 +142,9 @@ tus_exp_touch(const struct tus_file_core *fcore)
CHECK_OBJ_NOTNULL(e, TUS_EXP_MAGIC); CHECK_OBJ_NOTNULL(e, TUS_EXP_MAGIC);
pthread_mutex_lock(&e->mtx); AZ(pthread_mutex_lock(&e->mtx));
VBH_reorder(e->heap, fcore->exp_idx); VBH_reorder(e->heap, fcore->exp_idx);
pthread_mutex_unlock(&e->mtx); AZ(pthread_mutex_unlock(&e->mtx));
} }
static int static int
......
/*-
* Copyright 2020 UPLEX Nils Goroll Systemoptimierung
* All rights reserved.
*
* Author: Nils Goroll <nils.goroll@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
struct tus_exp *tus_file_exp_new(void);
void tus_file_exp_destroy(struct tus_exp **);
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include "tus_hdr.h"
const char * const hdr_resum = "\016Tus-Resumable:"; const char * const hdr_resum = "\016Tus-Resumable:";
const char * const hdr_vers = "\014Tus-Version:"; const char * const hdr_vers = "\014Tus-Version:";
const char * const hdr_ext = "\016Tus-Extension:"; const char * const hdr_ext = "\016Tus-Extension:";
......
...@@ -41,7 +41,7 @@ hexnibble(unsigned char n) ...@@ -41,7 +41,7 @@ hexnibble(unsigned char n)
return (n < 0xa ? '0' + n : 'a' + n - 0xa); return (n < 0xa ? '0' + n : 'a' + n - 0xa);
} }
VCL_STRING static VCL_STRING
tus_hex_buf(char * buf, size_t bufl, VCL_BLOB b) tus_hex_buf(char * buf, size_t bufl, VCL_BLOB b)
{ {
VCL_STRING r = buf; VCL_STRING r = buf;
......
...@@ -26,6 +26,5 @@ ...@@ -26,6 +26,5 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
VCL_STRING tus_hex_buf(char *, size_t, VCL_BLOB);
VCL_STRING tus_hex(VRT_CTX, VCL_BLOB); VCL_STRING tus_hex(VRT_CTX, VCL_BLOB);
void tus_vsbhex(struct vsb *, VCL_BLOB); void tus_vsbhex(struct vsb *, VCL_BLOB);
...@@ -64,6 +64,7 @@ validhdr(const char *p) ...@@ -64,6 +64,7 @@ validhdr(const char *p)
/* ------------------------------------------------------------ /* ------------------------------------------------------------
*/ */
/*lint -esym(749, met_e::_MET_MAX) */
enum met_e { enum met_e {
_INVALID = 0, _INVALID = 0,
#define MET(x) x, #define MET(x) x,
...@@ -82,7 +83,7 @@ parse_met(const char *s) ...@@ -82,7 +83,7 @@ parse_met(const char *s)
// everything for a tus upload to the backend is complete // everything for a tus upload to the backend is complete
static VCL_BOOL static VCL_BOOL
tus_request_complete(VRT_CTX, const struct VPFX(tus_server) *srv, tus_request_complete(VRT_CTX, const struct VPFX(tus_server) *srv,
struct tus_concat *c, struct tus_file_disk *fdisk) struct tus_concat *c, const struct tus_file_disk *fdisk)
{ {
VCL_BLOB b = NULL; VCL_BLOB b = NULL;
struct vsb vsb[1]; struct vsb vsb[1];
...@@ -163,7 +164,7 @@ tus_meta_key_unique(struct test_meta *this, size_t l) ...@@ -163,7 +164,7 @@ tus_meta_key_unique(struct test_meta *this, size_t l)
// from vmod_blob base64.c // from vmod_blob base64.c
#define ILL ((int8_t) 127) #define ILL ((int8_t) 127)
#define PAD ((int8_t) 126) #define PAD ((int8_t) 126)
const int8_t i64[256] = { static const int8_t i64[256] = {
ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
...@@ -368,6 +369,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -368,6 +369,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
} }
if (m == GET) { if (m == GET) {
AN(fdisk);
if (fdisk->location_length > 0) { if (fdisk->location_length > 0) {
/* done file */ /* done file */
r->fcore = fcore; r->fcore = fcore;
...@@ -449,10 +451,6 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -449,10 +451,6 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
r->status = 415; r->status = 415;
return (0); return (0);
} }
if (fcore == NULL) {
r->status = 404;
return (0);
}
if (off != fdisk->upload_offset) { if (off != fdisk->upload_offset) {
r->status = 409; r->status = 409;
return (0); return (0);
......
...@@ -44,9 +44,8 @@ ...@@ -44,9 +44,8 @@
const unsigned s_MULT = 1000; const unsigned s_MULT = 1000;
const unsigned s_OPTIONS = 1; const unsigned s_OPTIONS = 1;
const unsigned s_HEAD = 2;
const char * const allow = "POST, GET, HEAD, PATCH, DELETE, OPTIONS"; static const char * const allow = "POST, GET, HEAD, PATCH, DELETE, OPTIONS";
static VCL_BYTES static VCL_BYTES
tus_upload_length(const struct VPFX(tus_server) *tussrv, tus_upload_length(const struct VPFX(tus_server) *tussrv,
...@@ -91,7 +90,7 @@ tus_cors(VCL_HTTP r, unsigned status, const char *origin) ...@@ -91,7 +90,7 @@ tus_cors(VCL_HTTP r, unsigned status, const char *origin)
void void
tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv, tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
struct tus_response *resp) const struct tus_response *resp)
{ {
const struct tus_file_disk *fdisk = NULL; const struct tus_file_disk *fdisk = NULL;
const struct tus_file_core *fcore = NULL; const struct tus_file_core *fcore = NULL;
...@@ -161,10 +160,8 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv, ...@@ -161,10 +160,8 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
if (resp->origin != NULL && *resp->origin != '\0') if (resp->origin != NULL && *resp->origin != '\0')
tus_cors(r, resp->status, resp->origin); tus_cors(r, resp->status, resp->origin);
if (tussrv) { http_PrintfHeader(r, "Tus-Max-Size: %ju",
http_PrintfHeader(r, "Tus-Max-Size: %ju", tus_upload_length(tussrv, fcore));
tus_upload_length(tussrv, fcore));
}
while (fdisk) { while (fdisk) {
AN(fcore); AN(fcore);
......
...@@ -38,7 +38,7 @@ struct tus_response { ...@@ -38,7 +38,7 @@ struct tus_response {
void void
tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv, tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
struct tus_response *resp); const struct tus_response *resp);
VCL_BOOL VCL_BOOL
tus_done(VRT_CTX, const struct VPFX(tus_server) *tussrv, tus_done(VRT_CTX, const struct VPFX(tus_server) *tussrv,
const struct tus_response *resp, const char *url); const struct tus_response *resp, const char *url);
...@@ -47,4 +47,3 @@ tus_meta(VRT_CTX, const struct tus_response *resp, const char *k, VCL_BLOB *b); ...@@ -47,4 +47,3 @@ tus_meta(VRT_CTX, const struct tus_response *resp, const char *k, VCL_BLOB *b);
extern const unsigned s_MULT; extern const unsigned s_MULT;
extern const unsigned s_OPTIONS; extern const unsigned s_OPTIONS;
extern const unsigned s_HEAD;
...@@ -36,7 +36,7 @@ struct tus_exp; ...@@ -36,7 +36,7 @@ struct tus_exp;
struct vmod_blobdigest_digest; struct vmod_blobdigest_digest;
// tus_servers.c // tus_servers.c
const char * tus_server_name(struct VPFX(tus_server) *); const char * tus_server_name(const struct VPFX(tus_server) *);
struct tus_files *tus_server_files(struct VPFX(tus_server) *); struct tus_files *tus_server_files(struct VPFX(tus_server) *);
int tus_server_basefd(const struct VPFX(tus_server) *); int tus_server_basefd(const struct VPFX(tus_server) *);
const char * tus_server_basedir(const struct VPFX(tus_server) *); const char * tus_server_basedir(const struct VPFX(tus_server) *);
......
...@@ -33,15 +33,14 @@ ...@@ -33,15 +33,14 @@
#include "vcc_tus_if.h" #include "vcc_tus_if.h"
#include "tus_file.h" #include "tus_file.h"
#include "tus_server.h"
#include "tus_servers.h" #include "tus_servers.h"
struct tus_servers tus_servers[1] = { VSPLAY_INITIALIZER(tus_servers) }; struct tus_servers tus_servers[1] = { VSPLAY_INITIALIZER(tus_servers) };
VSPLAY_GENERATE(tus_servers, VPFX(tus_server), entry, tus_server_cmp); VSPLAY_GENERATE(tus_servers, VPFX(tus_server), entry, tus_server_cmp)
const char * const char *
tus_server_name(struct VPFX(tus_server) *s) tus_server_name(const struct VPFX(tus_server) *s)
{ {
CHECK_OBJ_NOTNULL(s, VMOD_TUS_SERVER_MAGIC); CHECK_OBJ_NOTNULL(s, VMOD_TUS_SERVER_MAGIC);
......
...@@ -64,5 +64,5 @@ tus_server_cmp(const struct VPFX(tus_server) *a, ...@@ -64,5 +64,5 @@ tus_server_cmp(const struct VPFX(tus_server) *a,
return (strcmp(a->vcl_name, b->vcl_name)); return (strcmp(a->vcl_name, b->vcl_name));
} }
VSPLAY_HEAD(tus_servers, VPFX(tus_server)); VSPLAY_HEAD(tus_servers, VPFX(tus_server));
struct tus_servers tus_servers[1]; extern struct tus_servers tus_servers[1];
VSPLAY_PROTOTYPE(tus_servers, VPFX(tus_server), entry, tus_server_cmp); VSPLAY_PROTOTYPE(tus_servers, VPFX(tus_server), entry, tus_server_cmp)
...@@ -57,7 +57,7 @@ static void * ...@@ -57,7 +57,7 @@ static void *
tus_objsetattr(struct worker *wrk, struct objcore *oc, tus_objsetattr(struct worker *wrk, struct objcore *oc,
enum obj_attr attr, ssize_t len, const void *ptr); enum obj_attr attr, ssize_t len, const void *ptr);
const struct obj_methods obj_tus = { static const struct obj_methods obj_tus = {
.objfree = tus_objfree, .objfree = tus_objfree,
.objiterator = tus_objiterator, .objiterator = tus_objiterator,
.objgetspace = tus_objgetspace, .objgetspace = tus_objgetspace,
...@@ -76,10 +76,9 @@ tus_allocobj(struct worker *wrk, const struct stevedore *stv, ...@@ -76,10 +76,9 @@ tus_allocobj(struct worker *wrk, const struct stevedore *stv,
(void) oc; (void) oc;
(void) l; (void) l;
INCOMPL(); INCOMPL();
return (0); // USELESS
} }
const struct stevedore stv_tus = { static const struct stevedore stv_tus = {
.magic = STEVEDORE_MAGIC, .magic = STEVEDORE_MAGIC,
.name = "tus", .name = "tus",
...@@ -150,10 +149,13 @@ tus_objiterator(struct worker *wrk, struct objcore *oc, ...@@ -150,10 +149,13 @@ tus_objiterator(struct worker *wrk, struct objcore *oc,
int r = -1; int r = -1;
(void) wrk; (void) wrk;
(void) final;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
assert(oc->stobj->stevedore == &stv_tus); assert(oc->stobj->stevedore == &stv_tus);
CAST_OBJ_NOTNULL(c, oc->stobj->priv, TUS_CONCAT_MAGIC); CAST_OBJ_NOTNULL(c, oc->stobj->priv, TUS_CONCAT_MAGIC);
oc = NULL;
(void) oc; // flexelint
for (i = 0; i < c->n; i++) { for (i = 0; i < c->n; i++) {
fcore = c->cores[i]; fcore = c->cores[i];
...@@ -195,7 +197,6 @@ tus_objgetspace(struct worker *wrk, struct objcore *oc, ...@@ -195,7 +197,6 @@ tus_objgetspace(struct worker *wrk, struct objcore *oc,
(void) sz; (void) sz;
(void) ptr; (void) ptr;
INCOMPL(); INCOMPL();
return (0); // USELESS
} }
static void static void
...@@ -216,7 +217,6 @@ enum obj_attr attr, ssize_t *len) ...@@ -216,7 +217,6 @@ enum obj_attr attr, ssize_t *len)
(void) attr; (void) attr;
(void) len; (void) len;
INCOMPL(); INCOMPL();
return (NULL); // USELESS
} }
static void * static void *
...@@ -229,7 +229,6 @@ enum obj_attr attr, ssize_t len, const void *ptr) ...@@ -229,7 +229,6 @@ enum obj_attr attr, ssize_t len, const void *ptr)
(void) len; (void) len;
(void) ptr; (void) ptr;
INCOMPL(); INCOMPL();
return (NULL); // USELESS
} }
// helper // helper
......
...@@ -41,8 +41,16 @@ main(int argc, char **argv) { ...@@ -41,8 +41,16 @@ main(int argc, char **argv) {
void *dlhdl; void *dlhdl;
char buf[256]; char buf[256];
const struct vmod_data *d; const struct vmod_data *d;
const char *name = argv[1]; const char *name;
const char *file = argv[2]; const char *file;
if (argc < 3) {
fprintf(stderr, "need 2 arguments\n");
return (1);
}
name = argv[1];
file = argv[2];
dlhdl = dlopen(file, RTLD_LAZY | RTLD_LOCAL); dlhdl = dlopen(file, RTLD_LAZY | RTLD_LOCAL);
...@@ -57,7 +65,7 @@ main(int argc, char **argv) { ...@@ -57,7 +65,7 @@ main(int argc, char **argv) {
return (1); return (1);
} }
printf(d->proto); printf("%s",d->proto);
printf("\nstatic const struct vmod_data import_%s = {\n", buf); printf("\nstatic const struct vmod_data import_%s = {\n", buf);
printf("\t.name =\t\t\"%s\",\n", d->name); printf("\t.name =\t\t\"%s\",\n", d->name);
printf("\t.file_id =\t\"%s\",\n", d->file_id); printf("\t.file_id =\t\"%s\",\n", d->file_id);
......
...@@ -46,12 +46,9 @@ ...@@ -46,12 +46,9 @@
#include "tus_response.h" #include "tus_response.h"
#include "tus_request.h" #include "tus_request.h"
#include "tus_blob.h" #include "tus_blob.h"
#include "tus_file_exp_setup.h"
// tus_file_exp.c static unsigned refcnt = 0;
struct tus_exp *tus_file_exp_new(void);
void tus_file_exp_destroy(struct tus_exp **ep);
unsigned refcnt = 0;
/* ============================================================ /* ============================================================
* vmod init/fini * vmod init/fini
...@@ -131,7 +128,7 @@ tus_dir_chk(const char *dir) ...@@ -131,7 +128,7 @@ tus_dir_chk(const char *dir)
return (0); return (0);
} }
int static int
tus_basefd(const char *dir) tus_basefd(const char *dir)
{ {
if (tus_dir_chk(dir)) { if (tus_dir_chk(dir)) {
...@@ -158,7 +155,8 @@ tus_schemeauth_valid(const char *schemeauth, const char **p) ...@@ -158,7 +155,8 @@ tus_schemeauth_valid(const char *schemeauth, const char **p)
*p += 3; *p += 3;
if (**p == '\0') if (**p == '\0')
return (0); return (0);
if ((*p = strchr(*p, '/'))) *p = strchr(*p, '/');
if (*p)
return (0); return (0);
return (1); return (1);
} }
...@@ -322,8 +320,8 @@ static const struct vmod_priv_methods priv_task_methods[1] = {{ ...@@ -322,8 +320,8 @@ static const struct vmod_priv_methods priv_task_methods[1] = {{
.fini = tus_task_free .fini = tus_task_free
}}; }};
struct tus_response * static struct tus_response *
tus_task_new(VRT_CTX, struct VPFX(tus_server) *tussrv) tus_task_new(VRT_CTX, const struct VPFX(tus_server) *tussrv)
{ {
struct tus_response *r; struct tus_response *r;
struct vmod_priv *task; struct vmod_priv *task;
...@@ -351,8 +349,8 @@ tus_task_new(VRT_CTX, struct VPFX(tus_server) *tussrv) ...@@ -351,8 +349,8 @@ tus_task_new(VRT_CTX, struct VPFX(tus_server) *tussrv)
return (r); return (r);
} }
struct tus_response * static struct tus_response *
tus_task_use(VRT_CTX, struct VPFX(tus_server) *tussrv) tus_task_use(VRT_CTX, const struct VPFX(tus_server) *tussrv)
{ {
struct tus_response *r; struct tus_response *r;
struct vmod_priv *task; struct vmod_priv *task;
...@@ -487,8 +485,7 @@ VCL_BOOL tus_server_done(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -487,8 +485,7 @@ VCL_BOOL tus_server_done(VRT_CTX, struct VPFX(tus_server) *tussrv,
if (args->valid_location) if (args->valid_location)
url = args->location; url = args->location;
tus_done(ctx, tussrv, r, url); return (tus_done(ctx, tussrv, r, url));
return (0);
} }
VCL_BOOL VCL_BOOL
......
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