-#ifdef HAVE_LIBZ
-static void
-common_zlib_deflate(conn_t * conn, void *buf, size_t len)
-{
- char outbuf[READBUF_SIZE];
- int ret, have;
- z_stream *outstream = &((zlib_stream_t *) conn->stream)->outstream;
- outstream->next_in = buf;
- outstream->avail_in = len;
- outstream->next_out = (Bytef *) outbuf;
- outstream->avail_out = sizeof(outbuf);
-
- ret = deflate(outstream, Z_SYNC_FLUSH);
- if(ret != Z_OK)
- {
- /* deflate error */
- close_conn(conn, WAIT_PLAIN, "Deflate failed: %s", zError(ret));
- return;
- }
- if(outstream->avail_out == 0)
- {
- /* avail_out empty */
- close_conn(conn, WAIT_PLAIN, "error compressing data, avail_out == 0");
- return;
- }
- if(outstream->avail_in != 0)
- {
- /* avail_in isn't empty... */
- close_conn(conn, WAIT_PLAIN, "error compressing data, avail_in != 0");
- return;
- }
- have = sizeof(outbuf) - outstream->avail_out;
- conn_mod_write(conn, outbuf, have);
-}
-
-static void
-common_zlib_inflate(conn_t * conn, void *buf, size_t len)
-{
- char outbuf[READBUF_SIZE];
- int ret, have = 0;
- ((zlib_stream_t *) conn->stream)->instream.next_in = buf;
- ((zlib_stream_t *) conn->stream)->instream.avail_in = len;
- ((zlib_stream_t *) conn->stream)->instream.next_out = (Bytef *) outbuf;
- ((zlib_stream_t *) conn->stream)->instream.avail_out = sizeof(outbuf);
-
- while(((zlib_stream_t *) conn->stream)->instream.avail_in)
- {
- ret = inflate(&((zlib_stream_t *) conn->stream)->instream, Z_NO_FLUSH);
- if(ret != Z_OK)
- {
- if(!strncmp("ERROR ", buf, 6))
- {
- close_conn(conn, WAIT_PLAIN, "Received uncompressed ERROR");
- return;
- }
- close_conn(conn, WAIT_PLAIN, "Inflate failed: %s", zError(ret));
- return;
- }
- have = sizeof(outbuf) - ((zlib_stream_t *) conn->stream)->instream.avail_out;
-
- if(((zlib_stream_t *) conn->stream)->instream.avail_in)
- {
- conn_plain_write(conn, outbuf, have);
- have = 0;
- ((zlib_stream_t *) conn->stream)->instream.next_out = (Bytef *) outbuf;
- ((zlib_stream_t *) conn->stream)->instream.avail_out = sizeof(outbuf);
- }
- }
- if(have == 0)
- return;
-
- conn_plain_write(conn, outbuf, have);
-}
-#endif
-