Support OA_LEN for VC#4035

parent 5307d73e
...@@ -34,6 +34,7 @@ struct tus_concat { ...@@ -34,6 +34,7 @@ struct tus_concat {
unsigned magic; unsigned magic;
#define TUS_CONCAT_MAGIC 0x105c0ca7 #define TUS_CONCAT_MAGIC 0x105c0ca7
unsigned n; unsigned n;
uint64_t len; // filled by tus_objgetattr()
struct tus_file_core *cores[]; struct tus_file_core *cores[];
// dynamically sized // dynamically sized
}; };
...@@ -40,6 +40,28 @@ ...@@ -40,6 +40,28 @@
#include "tus_concat.h" #include "tus_concat.h"
#include "tus_stv.h" #include "tus_stv.h"
/* from varnish-cache vend.h */
static __inline void
vbe32enc(void *pp, uint32_t u)
{
uint8_t *p = (uint8_t *)pp;
p[0] = (u >> 24) & 0xff;
p[1] = (u >> 16) & 0xff;
p[2] = (u >> 8) & 0xff;
p[3] = u & 0xff;
}
static __inline void
vbe64enc(void *pp, uint64_t u)
{
uint8_t *p = (uint8_t *)pp;
vbe32enc(p, (uint32_t)(u >> 32));
vbe32enc(p + 4, (uint32_t)(u & 0xffffffffU));
}
static void static void
tus_objfree(struct worker *wrk, struct objcore *oc); tus_objfree(struct worker *wrk, struct objcore *oc);
static int static int
...@@ -216,13 +238,34 @@ tus_objextend(struct worker *wrk, struct objcore *oc, ssize_t l) ...@@ -216,13 +238,34 @@ tus_objextend(struct worker *wrk, struct objcore *oc, ssize_t l)
static const void * static const void *
tus_objgetattr(struct worker *wrk, struct objcore *oc, tus_objgetattr(struct worker *wrk, struct objcore *oc,
enum obj_attr attr, ssize_t *len) enum obj_attr attr, ssize_t *len)
{ {
struct tus_file_core *fcore;
struct tus_concat *c;
unsigned i;
uint64_t l;
(void) wrk; (void) wrk;
(void) oc;
(void) attr; CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
(void) len; assert(oc->stobj->stevedore == &stv_tus);
CAST_OBJ_NOTNULL(c, oc->stobj->priv, TUS_CONCAT_MAGIC);
switch (attr) {
case OA_LEN:
l = 0;
for (i = 0; i < c->n; i++) {
fcore = c->cores[i];
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
l += fcore->len;
}
vbe64enc(&c->len, l);
*len = sizeof(c->len);
return (&c->len);
default:
INCOMPL(); INCOMPL();
}
} }
static void * static void *
......
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