Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-tus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-tus
Commits
16e8d1e4
Unverified
Commit
16e8d1e4
authored
Sep 17, 2020
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move metadata handling code
parent
0343fec3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
60 deletions
+89
-60
tus_file.c
src/tus_file.c
+59
-0
tus_file.h
src/tus_file.h
+10
-10
tus_request.c
src/tus_request.c
+17
-0
tus_response.c
src/tus_response.c
+3
-50
No files found.
src/tus_file.c
View file @
16e8d1e4
...
...
@@ -41,6 +41,7 @@
#include <vtim.h>
#include <vrnd.h>
#include "tus_b64.h"
#include "tus_file.h"
#include "tus_blob.h"
#include "tus_hdr.h"
...
...
@@ -1033,3 +1034,61 @@ tus_file_sync(struct tus_file_core *fcore)
return
;
AZ
(
fdatasync
(
fcore
->
fd
));
}
static
inline
const
char
*
tus_meta_find
(
const
char
*
meta
,
const
char
*
key
,
size_t
l
,
const
char
**
vp
,
size_t
*
vlp
)
{
const
char
*
v
,
*
ve
;
while
(
meta
!=
NULL
&&
*
meta
!=
'\0'
)
{
if
(
strncmp
(
meta
,
key
,
l
)
==
0
)
{
v
=
meta
+
l
;
if
(
*
v
==
'\0'
||
*
v
==
','
||
(
v
[
0
]
==
' '
&&
v
[
1
]
==
','
))
return
(
meta
);
if
(
*
v
==
' '
)
{
v
++
;
if
(
vp
!=
NULL
)
*
vp
=
v
;
if
(
vlp
!=
NULL
)
{
ve
=
strchr
(
v
,
','
);
if
(
ve
!=
NULL
)
*
vlp
=
ve
-
v
;
else
*
vlp
=
strlen
(
v
);
}
return
(
meta
);
}
}
meta
=
strchr
(
meta
,
','
);
if
(
meta
!=
NULL
)
meta
++
;
}
return
(
NULL
);
}
VCL_BOOL
tus_file_meta
(
VRT_CTX
,
const
struct
tus_file_disk
*
fdisk
,
const
char
*
k
,
VCL_BLOB
*
b
)
{
const
char
*
meta
,
*
v
=
NULL
;
size_t
kl
=
strlen
(
k
),
vl
=
0
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
fdisk
,
VMOD_TUS_FILE_DISK_MAGIC
);
meta
=
fdisk
->
metadata
;
if
(
b
==
NULL
)
return
(
tus_meta_find
(
meta
,
k
,
kl
,
NULL
,
NULL
)
!=
NULL
);
meta
=
tus_meta_find
(
meta
,
k
,
kl
,
&
v
,
&
vl
);
if
(
meta
==
NULL
)
return
(
0
);
*
b
=
tus_b64_decode
(
ctx
,
v
,
vl
);
return
(
1
);
}
src/tus_file.h
View file @
16e8d1e4
...
...
@@ -151,8 +151,7 @@ void
tus_file_rename_base
(
struct
tus_file_core
*
fcore
,
const
char
*
basename
);
#endif
const
char
*
tus_file_final_urls
(
VRT_CTX
,
const
struct
tus_file_core
*
fcore
,
const
char
*
pfx
);
tus_file_final_urls
(
VRT_CTX
,
const
struct
tus_file_core
*
,
const
char
*
);
struct
concat_embryo
{
unsigned
magic
;
...
...
@@ -165,14 +164,15 @@ struct concat_embryo {
ssize_t
upload_length
;
};
struct
concat_embryo
*
tus_file_final_concat
(
struct
VPFX
(
tus_server
)
*
srv
,
struct
concat_embryo
*
embryo
,
const
char
*
spec
);
struct
concat_embryo
*
tus_file_final_concat
(
struct
VPFX
(
tus_server
)
*
,
struct
concat_embryo
*
,
const
char
*
);
VCL_BLOB
tus_concat_hash
(
VRT_CTX
,
const
struct
VPFX
(
tus_server
)
*
,
const
struct
tus_concat
*
);
struct
tus_file_core
*
tus_file_final_birth
(
struct
tus_file_core
*
fcore
,
struct
concat_embryo
*
embryo
);
void
tus_file_final_abort
(
struct
concat_embryo
*
embryo
);
VCL_BOOL
tus_file_done
(
struct
tus_file_core
*
,
struct
tus_file_disk
*
,
const
char
*
);
struct
tus_file_core
*
tus_file_final_birth
(
struct
tus_file_core
*
,
struct
concat_embryo
*
);
void
tus_file_final_abort
(
struct
concat_embryo
*
);
VCL_BOOL
tus_file_done
(
struct
tus_file_core
*
,
struct
tus_file_disk
*
,
const
char
*
);
void
tus_file_sync
(
struct
tus_file_core
*
);
VCL_BOOL
tus_file_meta
(
VRT_CTX
,
const
struct
tus_file_disk
*
,
const
char
*
,
VCL_BLOB
*
);
src/tus_request.c
View file @
16e8d1e4
...
...
@@ -45,6 +45,23 @@
#include "tus_stv.h"
#include "tus_hex.h"
/* ------------------------------------------------------------
* from https://github.com/varnishcache/varnish-cache/pull/3407
*/
#define vct_ishdrval(x) (((x) >= 0x20 && (x) != 0x7f) || (x) == 0x09)
static
inline
VCL_BOOL
validhdr
(
const
char
*
p
)
{
AN
(
p
);
for
(;
*
p
!=
'\0'
;
p
++
)
if
(
!
vct_ishdrval
(
*
p
))
return
(
0
);
return
(
1
);
}
/* ------------------------------------------------------------
*/
enum
met_e
{
...
...
src/tus_response.c
View file @
16e8d1e4
...
...
@@ -37,7 +37,6 @@
#include "vcc_tus_if.h"
#include "tus_checksums.h"
#include "tus_b64.h"
#include "tus_file.h"
#include "tus_servers.h"
#include "tus_hdr.h"
...
...
@@ -235,49 +234,12 @@ tus_done(VRT_CTX, const struct VPFX(tus_server) *tussrv,
return
(
tus_file_done
(
fcore
,
fdisk
,
url
));
}
static
inline
const
char
*
tus_meta_find
(
const
char
*
meta
,
const
char
*
key
,
size_t
l
,
const
char
**
vp
,
size_t
*
vlp
)
{
const
char
*
v
,
*
ve
;
while
(
meta
!=
NULL
&&
*
meta
!=
'\0'
)
{
if
(
strncmp
(
meta
,
key
,
l
)
==
0
)
{
v
=
meta
+
l
;
if
(
*
v
==
'\0'
||
*
v
==
','
||
(
v
[
0
]
==
' '
&&
v
[
1
]
==
','
))
return
(
meta
);
if
(
*
v
==
' '
)
{
v
++
;
if
(
vp
!=
NULL
)
*
vp
=
v
;
if
(
vlp
!=
NULL
)
{
ve
=
strchr
(
v
,
','
);
if
(
ve
!=
NULL
)
*
vlp
=
ve
-
v
;
else
*
vlp
=
strlen
(
v
);
}
return
(
meta
);
}
}
meta
=
strchr
(
meta
,
','
);
if
(
meta
!=
NULL
)
meta
++
;
}
return
(
NULL
);
}
VCL_BOOL
tus_meta
(
VRT_CTX
,
const
struct
tus_response
*
resp
,
const
char
*
k
,
VCL_BLOB
*
b
)
{
const
struct
tus_file_core
*
fcore
;
const
struct
tus_file_disk
*
fdisk
;
const
char
*
meta
,
*
v
=
NULL
;
size_t
kl
=
strlen
(
k
),
vl
=
0
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
resp
,
VMOD_TUS_RESPONSE_MAGIC
);
fcore
=
resp
->
fcore
;
...
...
@@ -285,18 +247,9 @@ tus_meta(VRT_CTX, const struct tus_response *resp, const char *k, VCL_BLOB *b)
return
(
0
);
CHECK_OBJ_NOTNULL
(
fcore
,
VMOD_TUS_FILE_CORE_MAGIC
);
fdisk
=
fcore
->
disk
;
CHECK_OBJ_NOTNULL
(
fdisk
,
VMOD_TUS_FILE_DISK_MAGIC
);
meta
=
fdisk
->
metadata
;
if
(
b
==
NULL
)
return
(
tus_meta_find
(
meta
,
k
,
kl
,
NULL
,
NULL
)
!=
NULL
);
meta
=
tus_meta_find
(
meta
,
k
,
kl
,
&
v
,
&
vl
);
if
(
meta
==
NULL
)
if
(
fdisk
==
NULL
)
return
(
0
);
CHECK_OBJ_NOTNULL
(
fdisk
,
VMOD_TUS_FILE_DISK_MAGIC
);
*
b
=
tus_b64_decode
(
ctx
,
v
,
vl
);
return
(
1
);
return
(
tus_file_meta
(
ctx
,
fdisk
,
k
,
b
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment