mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
decompress_data is now cleaner, isn't it?
This commit is contained in:
parent
6fae43511c
commit
b0ea7cd7c1
@ -1051,42 +1051,10 @@ http_send_header(struct socket *socket)
|
||||
#undef POST_BUFFER_SIZE
|
||||
|
||||
|
||||
/* This function decompresses the data block given in @data (if it was
|
||||
* compressed), which is long @len bytes. The decompressed data block is given
|
||||
* back to the world as the return value and its length is stored into
|
||||
* @new_len. After this function returns, the caller will discard all the @len
|
||||
* input bytes, so this function must use all of them unless an error occurs.
|
||||
*
|
||||
* In this function, value of either http->chunk_remaining or http->length is
|
||||
* being changed (it depends on if chunked mode is used or not).
|
||||
*
|
||||
* Note that the function is still a little esotheric for me. Don't take it
|
||||
* lightly and don't mess with it without grave reason! If you dare to touch
|
||||
* this without testing the changes on slashdot, freshmeat and cvsweb
|
||||
* (including revision history), don't dare to send me any patches! ;) --pasky
|
||||
*
|
||||
* This function gotta die. */
|
||||
static unsigned char *
|
||||
decompress_data(struct connection *conn, unsigned char *data, int len,
|
||||
int *new_len)
|
||||
{
|
||||
struct http_connection_info *http = conn->info;
|
||||
enum { NORMAL, FINISHING } state = NORMAL;
|
||||
int *length_of_block;
|
||||
unsigned char *output = NULL;
|
||||
|
||||
if (http->length == LEN_CHUNKED) {
|
||||
if (http->chunk_remaining == CHUNK_ZERO_SIZE)
|
||||
state = FINISHING;
|
||||
length_of_block = &http->chunk_remaining;
|
||||
} else {
|
||||
length_of_block = &http->length;
|
||||
if (!*length_of_block) {
|
||||
/* Going to finish this decoding bussiness. */
|
||||
state = FINISHING;
|
||||
}
|
||||
}
|
||||
|
||||
*new_len = 0; /* new_len must be zero if we would ever return NULL */
|
||||
|
||||
if (!conn->stream) {
|
||||
@ -1094,20 +1062,7 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
|
||||
if (!conn->stream) return NULL;
|
||||
}
|
||||
|
||||
output = decode_encoded_buffer(conn->stream, conn->content_encoding, data, len, new_len);
|
||||
|
||||
if (*length_of_block > 0) {
|
||||
*length_of_block -= len;
|
||||
}
|
||||
/* http->length is 0 at the end of block for all modes: keep-alive,
|
||||
* non-keep-alive and chunked */
|
||||
if (!http->length) {
|
||||
/* That's all, folks - let's finish this. */
|
||||
state = FINISHING;
|
||||
}
|
||||
|
||||
if (state == FINISHING) shutdown_connection_stream(conn);
|
||||
return output;
|
||||
return decode_encoded_buffer(conn->stream, conn->content_encoding, data, len, new_len);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -1240,9 +1195,9 @@ read_chunked_http_data(struct connection *conn, struct read_buffer *rb)
|
||||
int_upper_bound(&len, rb->length);
|
||||
conn->received += len;
|
||||
|
||||
if (http->chunk_remaining > 0) http->chunk_remaining -= len;
|
||||
if (conn->content_encoding == ENCODING_NONE) {
|
||||
data_len = len;
|
||||
if (http->chunk_remaining > 0) http->chunk_remaining -= len;
|
||||
if (add_fragment(conn->cached, conn->from, rb->data, len) == 1)
|
||||
conn->tries = 0;
|
||||
} else {
|
||||
@ -1252,6 +1207,7 @@ read_chunked_http_data(struct connection *conn, struct read_buffer *rb)
|
||||
conn->tries = 0;
|
||||
|
||||
if (data) mem_free(data);
|
||||
if (zero || !http->length) shutdown_connection_stream(conn);
|
||||
}
|
||||
|
||||
conn->from += data_len;
|
||||
@ -1306,10 +1262,10 @@ read_normal_http_data(struct connection *conn, struct read_buffer *rb)
|
||||
}
|
||||
|
||||
conn->received += len;
|
||||
if (http->length > 0) http->length -= len;
|
||||
|
||||
if (conn->content_encoding == ENCODING_NONE) {
|
||||
data_len = len;
|
||||
if (http->length > 0) http->length -= len;
|
||||
if (add_fragment(conn->cached, conn->from, rb->data, data_len) == 1)
|
||||
conn->tries = 0;
|
||||
} else {
|
||||
@ -1319,6 +1275,7 @@ read_normal_http_data(struct connection *conn, struct read_buffer *rb)
|
||||
conn->tries = 0;
|
||||
|
||||
if (data) mem_free(data);
|
||||
if (!http->length) shutdown_connection_stream(conn);
|
||||
}
|
||||
|
||||
conn->from += data_len;
|
||||
|
Loading…
Reference in New Issue
Block a user