version 1.7, 2006/11/16 01:33:51 |
version 1.8, 2007/05/21 11:35:16 |
Line 82 deflate_global(data, size, decomp, out) |
|
Line 82 deflate_global(data, size, decomp, out) |
|
u_int8_t *output; |
u_int8_t *output; |
u_int32_t count, result; |
u_int32_t count, result; |
int error, i = 0, j; |
int error, i = 0, j; |
struct deflate_buf buf[ZBUF]; |
struct deflate_buf *buf, *tmp; |
|
size_t len, old_len; |
|
|
bzero(&zbuf, sizeof(z_stream)); |
len = ZBUF; |
for (j = 0; j < ZBUF; j++) |
buf = malloc(len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); |
|
if (buf == NULL) |
|
return 0; |
|
|
|
memset(&zbuf, 0, sizeof(z_stream)); |
|
for (j = 0; j < len; j++) |
buf[j].flag = 0; |
buf[j].flag = 0; |
|
|
zbuf.next_in = data; /* data that is going to be processed */ |
zbuf.next_in = data; /* data that is going to be processed */ |
Line 133 deflate_global(data, size, decomp, out) |
|
Line 139 deflate_global(data, size, decomp, out) |
|
goto bad; |
goto bad; |
else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) |
else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) |
goto end; |
goto end; |
else if (zbuf.avail_out == 0 && i < (ZBUF - 1)) { |
else if (zbuf.avail_out == 0) { |
|
if (i == (len-1)) { |
|
old_len = i; |
|
len += ZBUF; |
|
tmp = realloc(buf,len*sizeof(struct deflate_buf), |
|
M_CRYPTO_DATA, M_NOWAIT); |
|
if (tmp == NULL) |
|
goto bad; |
|
buf = tmp; |
|
for (j = old_len; j < len; j++) |
|
buf[j].flag = 0; |
|
} |
/* we need more output space, allocate size */ |
/* we need more output space, allocate size */ |
buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); |
buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); |
if (buf[i].out == NULL) |
if (buf[i].out == NULL) |
|
|
output = *out; |
output = *out; |
for (j = 0; buf[j].flag != 0; j++) { |
for (j = 0; buf[j].flag != 0; j++) { |
if (count > buf[j].size) { |
if (count > buf[j].size) { |
bcopy(buf[j].out, *out, buf[j].size); |
memcpy(buf[j].out, *out, buf[j].size); |
*out += buf[j].size; |
*out += buf[j].size; |
FREE(buf[j].out, M_CRYPTO_DATA); |
free(buf[j].out, M_CRYPTO_DATA); |
count -= buf[j].size; |
count -= buf[j].size; |
} else { |
} else { |
/* it should be the last buffer */ |
/* it should be the last buffer */ |
bcopy(buf[j].out, *out, count); |
memcpy(buf[j].out, *out, count); |
*out += count; |
*out += count; |
FREE(buf[j].out, M_CRYPTO_DATA); |
free(buf[j].out, M_CRYPTO_DATA); |
count = 0; |
count = 0; |
} |
} |
} |
} |
|
free(buf, M_CRYPTO_DATA); |
*out = output; |
*out = output; |
return result; |
return result; |
|
|
bad: |
bad: |
*out = NULL; |
*out = NULL; |
for (j = 0; buf[j].flag != 0; j++) |
for (j = 0; buf[j].flag != 0; j++) |
FREE(buf[j].out, M_CRYPTO_DATA); |
free(buf[j].out, M_CRYPTO_DATA); |
|
free(buf, M_CRYPTO_DATA); |
if (decomp) |
if (decomp) |
inflateEnd(&zbuf); |
inflateEnd(&zbuf); |
else |
else |