| 149 | | _sx_buffer_alloc_margin(sc->wbuf, 0, buf->len); |
| 150 | | memcpy(sc->wbuf->data + sc->wbuf->len, buf->data, buf->len); |
| 151 | | sc->wbuf->len += buf->len; |
| | 149 | _sx_buffer_alloc_margin(sc->wbuf, 0, buf->len); |
| | 150 | memcpy(sc->wbuf->data + sc->wbuf->len, buf->data, buf->len); |
| | 151 | sc->wbuf->len += buf->len; |
| 158 | | sc->wstrm.avail_in = sc->wbuf->len; |
| 159 | | sc->wstrm.next_in = sc->wbuf->data; |
| 160 | | /* deflate() on write buffer until there is data to compress */ |
| 161 | | do { |
| 162 | | /* make place for deflated data */ |
| 163 | | _sx_buffer_alloc_margin(buf, 0, sc->wbuf->len + SX_COMPRESS_CHUNK); |
| 164 | | |
| 165 | | sc->wstrm.avail_out = sc->wbuf->len + SX_COMPRESS_CHUNK; |
| 166 | | sc->wstrm.next_out = buf->data + buf->len; |
| 167 | | |
| 168 | | ret = deflate(&(sc->wstrm), Z_SYNC_FLUSH); |
| 169 | | assert(ret != Z_STREAM_ERROR); |
| 170 | | |
| 171 | | buf->len += sc->wbuf->len + SX_COMPRESS_CHUNK - sc->wstrm.avail_out; |
| 172 | | |
| 173 | | } while (sc->wstrm.avail_out == 0); |
| 174 | | |
| 175 | | if(ret != Z_OK || sc->wstrm.avail_in != 0) { |
| | 158 | sc->wstrm.avail_in = sc->wbuf->len; |
| | 159 | sc->wstrm.next_in = sc->wbuf->data; |
| | 160 | /* deflate() on write buffer until there is data to compress */ |
| | 161 | do { |
| | 162 | /* make place for deflated data */ |
| | 163 | _sx_buffer_alloc_margin(buf, 0, sc->wbuf->len + SX_COMPRESS_CHUNK); |
| | 164 | |
| | 165 | sc->wstrm.avail_out = sc->wbuf->len + SX_COMPRESS_CHUNK; |
| | 166 | sc->wstrm.next_out = buf->data + buf->len; |
| | 167 | |
| | 168 | ret = deflate(&(sc->wstrm), Z_SYNC_FLUSH); |
| | 169 | assert(ret != Z_STREAM_ERROR); |
| | 170 | |
| | 171 | buf->len += sc->wbuf->len + SX_COMPRESS_CHUNK - sc->wstrm.avail_out; |
| | 172 | |
| | 173 | } while (sc->wstrm.avail_out == 0); |
| | 174 | |
| | 175 | if(ret != Z_OK || sc->wstrm.avail_in != 0) { |
| 210 | | _sx_buffer_alloc_margin(sc->rbuf, 0, buf->len); |
| 211 | | memcpy(sc->rbuf->data + sc->rbuf->len, buf->data, buf->len); |
| 212 | | sc->rbuf->len += buf->len; |
| | 210 | _sx_buffer_alloc_margin(sc->rbuf, 0, buf->len); |
| | 211 | memcpy(sc->rbuf->data + sc->rbuf->len, buf->data, buf->len); |
| | 212 | sc->rbuf->len += buf->len; |
| 219 | | sc->rstrm.avail_in = sc->rbuf->len; |
| 220 | | sc->rstrm.next_in = sc->rbuf->data; |
| 221 | | /* run inflate() on read buffer while able to fill the output buffer */ |
| 222 | | do { |
| 223 | | /* make place for inflated data */ |
| 224 | | _sx_buffer_alloc_margin(buf, 0, SX_COMPRESS_CHUNK); |
| 225 | | |
| 226 | | sc->rstrm.avail_out = SX_COMPRESS_CHUNK; |
| 227 | | sc->rstrm.next_out = buf->data + buf->len; |
| 228 | | |
| 229 | | ret = inflate(&(sc->rstrm), Z_SYNC_FLUSH); |
| 230 | | assert(ret != Z_STREAM_ERROR); |
| 231 | | switch (ret) { |
| 232 | | case Z_NEED_DICT: |
| 233 | | case Z_DATA_ERROR: |
| 234 | | case Z_MEM_ERROR: |
| 235 | | /* throw an error */ |
| 236 | | _sx_gen_error(sxe, SX_ERR_COMPRESS, "compression error", "Error during decompression"); |
| 237 | | _sx_event(s, event_ERROR, (void *) &sxe); |
| 238 | | |
| 239 | | _sx_error(s, stream_err_INVALID_XML, "Error during decompression"); |
| 240 | | _sx_close(s); |
| 241 | | |
| 242 | | return -2; |
| 243 | | } |
| 244 | | |
| 245 | | buf->len += SX_COMPRESS_CHUNK - sc->rstrm.avail_out; |
| 246 | | |
| 247 | | } while (sc->rstrm.avail_out == 0); |
| 248 | | |
| 249 | | sc->rbuf->len = sc->rstrm.avail_in; |
| 250 | | sc->rbuf->data = sc->rstrm.next_in; |
| | 219 | sc->rstrm.avail_in = sc->rbuf->len; |
| | 220 | sc->rstrm.next_in = sc->rbuf->data; |
| | 221 | /* run inflate() on read buffer while able to fill the output buffer */ |
| | 222 | do { |
| | 223 | /* make place for inflated data */ |
| | 224 | _sx_buffer_alloc_margin(buf, 0, SX_COMPRESS_CHUNK); |
| | 225 | |
| | 226 | sc->rstrm.avail_out = SX_COMPRESS_CHUNK; |
| | 227 | sc->rstrm.next_out = buf->data + buf->len; |
| | 228 | |
| | 229 | ret = inflate(&(sc->rstrm), Z_SYNC_FLUSH); |
| | 230 | assert(ret != Z_STREAM_ERROR); |
| | 231 | switch (ret) { |
| | 232 | case Z_NEED_DICT: |
| | 233 | case Z_DATA_ERROR: |
| | 234 | case Z_MEM_ERROR: |
| | 235 | /* throw an error */ |
| | 236 | _sx_gen_error(sxe, SX_ERR_COMPRESS, "compression error", "Error during decompression"); |
| | 237 | _sx_event(s, event_ERROR, (void *) &sxe); |
| | 238 | |
| | 239 | _sx_error(s, stream_err_INVALID_XML, "Error during decompression"); |
| | 240 | _sx_close(s); |
| | 241 | |
| | 242 | return -2; |
| | 243 | } |
| | 244 | |
| | 245 | buf->len += SX_COMPRESS_CHUNK - sc->rstrm.avail_out; |
| | 246 | |
| | 247 | } while (sc->rstrm.avail_out == 0); |
| | 248 | |
| | 249 | sc->rbuf->len = sc->rstrm.avail_in; |
| | 250 | sc->rbuf->data = sc->rstrm.next_in; |