Skip to content

Commit 2106009

Browse files
committed
Updated library Brotli v1.0.1
1 parent b189368 commit 2106009

File tree

4 files changed

+52
-67
lines changed

4 files changed

+52
-67
lines changed

Diff for: Makefile.am

+18-18
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ moddir = @APACHE_MODULEDIR@
55
mod_LTLIBRARIES = mod_brotli.la
66

77
brotli_SOURCES = \
8-
brotli/common/dictionary.c \
9-
brotli/enc/backward_references.c \
10-
brotli/enc/backward_references_hq.c \
11-
brotli/enc/bit_cost.c \
12-
brotli/enc/block_splitter.c \
13-
brotli/enc/brotli_bit_stream.c \
14-
brotli/enc/cluster.c \
15-
brotli/enc/compress_fragment.c \
16-
brotli/enc/compress_fragment_two_pass.c \
17-
brotli/enc/dictionary_hash.c \
18-
brotli/enc/encode.c \
19-
brotli/enc/entropy_encode.c \
20-
brotli/enc/histogram.c \
21-
brotli/enc/literal_cost.c \
22-
brotli/enc/memory.c \
23-
brotli/enc/metablock.c \
24-
brotli/enc/static_dict.c \
25-
brotli/enc/utf8_util.c
8+
brotli/c/common/dictionary.c \
9+
brotli/c/enc/backward_references.c \
10+
brotli/c/enc/backward_references_hq.c \
11+
brotli/c/enc/bit_cost.c \
12+
brotli/c/enc/block_splitter.c \
13+
brotli/c/enc/brotli_bit_stream.c \
14+
brotli/c/enc/cluster.c \
15+
brotli/c/enc/compress_fragment.c \
16+
brotli/c/enc/compress_fragment_two_pass.c \
17+
brotli/c/enc/dictionary_hash.c \
18+
brotli/c/enc/encode.c \
19+
brotli/c/enc/entropy_encode.c \
20+
brotli/c/enc/histogram.c \
21+
brotli/c/enc/literal_cost.c \
22+
brotli/c/enc/memory.c \
23+
brotli/c/enc/metablock.c \
24+
brotli/c/enc/static_dict.c \
25+
brotli/c/enc/utf8_util.c
2626

2727
mod_brotli_la_SOURCES = mod_brotli.c $(brotli_SOURCES)
2828

Diff for: brotli

Submodule brotli updated 216 files

Diff for: configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ AC_SUBST(APACHE_LIBS)
8282
# Brotli
8383
BROTLI_CFLAGS=
8484
#BROTLI_CPPFLAGS="-I./brotli/include -std=c++11"
85-
BROTLI_CPPFLAGS="-I./brotli/include"
85+
BROTLI_CPPFLAGS="-I./brotli/c/include"
8686
BROTLI_LDFLAGS=
8787
BROTLI_LIBS=
8888

Diff for: mod_brotli.c

+32-47
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ brotli_set_window_size(cmd_parms *cmd, void *dummy, const char *arg)
120120
&brotli_module);
121121
int i = atoi(arg);
122122

123-
if (i < kBrotliMinWindowBits || i > kBrotliMaxWindowBits) {
123+
if (i < BROTLI_MIN_WINDOW_BITS || i > BROTLI_MAX_WINDOW_BITS) {
124124
return "BrotliWindowSize is not a valid range";
125125
}
126126

@@ -182,7 +182,6 @@ typedef struct brotli_ctx_t
182182
unsigned int filter_init:1;
183183
size_t bytes_in;
184184
size_t bytes_out;
185-
size_t ring_size;
186185
} brotli_ctx;
187186

188187
static apr_status_t
@@ -256,27 +255,35 @@ have_ssl_compression(request_rec *r)
256255
}
257256

258257
static apr_status_t
259-
brotli_compress(unsigned int last, unsigned int flush,
258+
brotli_compress(unsigned int operation,
259+
size_t len, const char *data,
260260
brotli_ctx *ctx, apr_pool_t *pool,
261261
struct apr_bucket_alloc_t *bucket_alloc)
262262
{
263-
uint8_t *out;
264-
size_t size;
263+
const uint8_t *next_in = (uint8_t *)data;
264+
size_t avail_in = len;
265265

266-
if (!BrotliEncoderWriteData(ctx->state, last, flush, &size, &out)) {
267-
return APR_EGENERAL;
268-
}
266+
while (avail_in >= 0) {
267+
uint8_t *next_out = NULL;
268+
size_t avail_out = 0;
269269

270-
ctx->bytes_out += size;
270+
if (!BrotliEncoderCompressStream(ctx->state, operation,
271+
&avail_in, &next_in,
272+
&avail_out, &next_out, NULL)) {
273+
return APR_EGENERAL;
274+
}
271275

272-
char *buffer = (char *)apr_palloc(pool, size);
273-
if (!buffer) {
274-
return APR_EGENERAL;
275-
}
276-
memcpy(buffer, out, size);
276+
if (BrotliEncoderHasMoreOutput(ctx->state)) {
277+
size_t size = 0;
278+
char *buffer = (char *)BrotliEncoderTakeOutput(ctx->state, &size);
279+
ctx->bytes_out += size;
277280

278-
apr_bucket *b = apr_bucket_heap_create(buffer, size, NULL, bucket_alloc);
279-
APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
281+
apr_bucket *b = apr_bucket_heap_create(buffer, size, NULL, bucket_alloc);
282+
APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
283+
} else if (avail_in == 0) {
284+
break;
285+
}
286+
}
280287

281288
return APR_SUCCESS;
282289
}
@@ -506,7 +513,7 @@ brotli_out_filter(ap_filter_t *f, apr_bucket_brigade *bb)
506513
uint32_t quality = (uint32_t)c->compressionlevel;
507514
uint32_t lgwin = (uint32_t)c->windowSize;
508515
if (len > 0) {
509-
while (len < (1 << (lgwin - 1)) && lgwin > kBrotliMinWindowBits) {
516+
while (len < (1 << (lgwin - 1)) && lgwin > BROTLI_MIN_WINDOW_BITS) {
510517
lgwin--;
511518
}
512519
}
@@ -516,7 +523,6 @@ brotli_out_filter(ap_filter_t *f, apr_bucket_brigade *bb)
516523

517524
ctx->bytes_in = 0;
518525
ctx->bytes_out = 0;
519-
ctx->ring_size = 0;
520526

521527
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(0485)
522528
"brotli encoder: quality: %d lgwin: %d", quality, lgwin);
@@ -583,8 +589,8 @@ brotli_out_filter(ap_filter_t *f, apr_bucket_brigade *bb)
583589

584590
if (APR_BUCKET_IS_EOS(e)) {
585591
/* flush the remaining data from the brotli buffers */
586-
apr_status_t rv = brotli_compress(1, 0, ctx, r->pool, f->c->bucket_alloc);
587-
ctx->ring_size = 0;
592+
apr_status_t rv = brotli_compress(BROTLI_OPERATION_FINISH, 0, NULL,
593+
ctx, r->pool, f->c->bucket_alloc);
588594
if (rv != APR_SUCCESS) {
589595
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(0554)
590596
"Brotli compress error");
@@ -667,33 +673,12 @@ brotli_out_filter(ap_filter_t *f, apr_bucket_brigade *bb)
667673

668674
/* write */
669675
if (len != 0) {
670-
size_t offset = 0, block_space = BrotliEncoderInputBlockSize(ctx->state);
671-
while (len != offset) {
672-
size_t copy_len = len - offset;
673-
674-
if ((ctx->ring_size + copy_len) > block_space) {
675-
copy_len = block_space - ctx->ring_size;
676-
}
677-
678-
if (copy_len > 0) {
679-
BrotliEncoderCopyInputToRingBuffer(ctx->state, copy_len,
680-
(const uint8_t *)data + offset);
681-
offset += copy_len;
682-
ctx->ring_size += copy_len;
683-
ctx->bytes_in += copy_len;
684-
}
685-
686-
if ((copy_len == block_space) || (copy_len == 0)) {
687-
/* flush the remaining data from the brotli buffers */
688-
apr_status_t rv = brotli_compress(0, 1, ctx, r->pool,
689-
f->c->bucket_alloc);
690-
ctx->ring_size = 0;
691-
if (rv != APR_SUCCESS) {
692-
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(0657)
693-
"Brotli compress error");
694-
return rv;
695-
}
696-
}
676+
apr_status_t rv = brotli_compress(BROTLI_OPERATION_PROCESS, len, data,
677+
ctx, r->pool, f->c->bucket_alloc);
678+
if (rv != APR_SUCCESS) {
679+
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(0657)
680+
"Brotli compress error");
681+
return APR_EGENERAL;
697682
}
698683
}
699684

0 commit comments

Comments
 (0)