diff options
author | Alexander Færøy <ahf@torproject.org> | 2017-04-17 14:57:37 +0200 |
---|---|---|
committer | Alexander Færøy <ahf@torproject.org> | 2017-04-17 14:57:37 +0200 |
commit | 3c4459bcbf1d3a9da4a8b3a8bfed10d2e045af74 (patch) | |
tree | 2024be186cba95ece1fd6d7681568f741d12bf1f /src/or/buffers.c | |
parent | 44cb86adbe2e9b9fef7bf5fd64b52a8e44441be5 (diff) | |
download | tor-3c4459bcbf1d3a9da4a8b3a8bfed10d2e045af74.tar.gz tor-3c4459bcbf1d3a9da4a8b3a8bfed10d2e045af74.zip |
Refactor the streaming compression code.
This patch refactors our streaming compression code to allow us to
extend it with non-zlib/non-gzip based compression schemas.
See https://bugs.torproject.org/21663
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index e559f80a1e..3490ce48a8 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -2088,11 +2088,11 @@ fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len) } /** Compress on uncompress the <b>data_len</b> bytes in <b>data</b> using the - * zlib state <b>state</b>, appending the result to <b>buf</b>. If + * compression state <b>state</b>, appending the result to <b>buf</b>. If * <b>done</b> is true, flush the data in the state and finish the * compression/uncompression. Return -1 on failure, 0 on success. */ int -write_to_buf_zlib(buf_t *buf, tor_zlib_state_t *state, +write_to_buf_zlib(buf_t *buf, tor_compress_state_t *state, const char *data, size_t data_len, int done) { @@ -2108,20 +2108,22 @@ write_to_buf_zlib(buf_t *buf, tor_zlib_state_t *state, } next = CHUNK_WRITE_PTR(buf->tail); avail = old_avail = CHUNK_REMAINING_CAPACITY(buf->tail); - switch (tor_zlib_process(state, &next, &avail, &data, &data_len, done)) { - case TOR_ZLIB_DONE: + switch (tor_compress_process(state, &next, &avail, + &data, &data_len, done)) { + case TOR_COMPRESS_DONE: over = 1; break; - case TOR_ZLIB_ERR: + case TOR_COMPRESS_ERROR: return -1; - case TOR_ZLIB_OK: + case TOR_COMPRESS_OK: if (data_len == 0) over = 1; break; - case TOR_ZLIB_BUF_FULL: + case TOR_COMPRESS_BUFFER_FULL: if (avail) { - /* Zlib says we need more room (ZLIB_BUF_FULL). Start a new chunk - * automatically, whether were going to or not. */ + /* The compression module says we need more room + * (TOR_COMPRESS_BUFFER_FULL). Start a new chunk automatically, + * whether were going to or not. */ need_new_chunk = 1; } break; |