37 char *ns = NULL, *to = NULL, *from = NULL, *version = NULL;
55 _sx_debug(
ZONE,
"compress requested on already compressed channel, dropping packet");
78 if(s->
ns != NULL) ns = strdup(s->
ns);
93 if(ns != NULL) free(ns);
94 if(to != NULL) free(to);
95 if(from != NULL) free(from);
96 if(version != NULL) free(version);
105 _sx_debug(
ZONE,
"server can't handle compression, business as usual");
151 memcpy(sc->wbuf->data + sc->wbuf->len, buf->
data, buf->
len);
152 sc->wbuf->len += buf->
len;
158 if(sc->wbuf->len > 0) {
159 sc->wstrm.avail_in = sc->wbuf->len;
160 sc->wstrm.next_in = sc->wbuf->data;
166 sc->wstrm.avail_out = sc->wbuf->len + SX_COMPRESS_CHUNK;
167 sc->wstrm.next_out = buf->
data + buf->
len;
169 ret = deflate(&(sc->wstrm), Z_SYNC_FLUSH);
170 assert(ret != Z_STREAM_ERROR);
172 buf->
len += sc->wbuf->len + SX_COMPRESS_CHUNK - sc->wstrm.avail_out;
174 }
while (sc->wstrm.avail_out == 0);
176 if(ret != Z_OK || sc->wstrm.avail_in != 0) {
187 sc->wbuf->len = sc->wstrm.avail_in;
188 sc->wbuf->data = sc->wstrm.next_in;
212 memcpy(sc->rbuf->data + sc->rbuf->len, buf->
data, buf->
len);
213 sc->rbuf->len += buf->
len;
219 if(sc->rbuf->len > 0) {
220 sc->rstrm.avail_in = sc->rbuf->len;
221 sc->rstrm.next_in = sc->rbuf->data;
227 sc->rstrm.avail_out = SX_COMPRESS_CHUNK;
228 sc->rstrm.next_out = buf->
data + buf->
len;
230 ret = inflate(&(sc->rstrm), Z_SYNC_FLUSH);
231 assert(ret != Z_STREAM_ERROR);
246 buf->
len += SX_COMPRESS_CHUNK - sc->rstrm.avail_out;
248 }
while (sc->rstrm.avail_out == 0);
250 sc->rbuf->len = sc->rstrm.avail_in;
251 sc->rbuf->data = sc->rstrm.next_in;
257 if(sc->rbuf->len > 0)
267 _sx_compress_conn_t sc;
275 sc = (_sx_compress_conn_t) calloc(1,
sizeof(
struct _sx_compress_conn_st));
278 sc->rstrm.zalloc = Z_NULL;
279 sc->rstrm.zfree = Z_NULL;
280 sc->rstrm.opaque = Z_NULL;
281 sc->rstrm.avail_in = 0;
282 sc->rstrm.next_in = Z_NULL;
283 inflateInit(&(sc->rstrm));
285 sc->wstrm.zalloc = Z_NULL;
286 sc->wstrm.zfree = Z_NULL;
287 sc->wstrm.opaque = Z_NULL;
288 deflateInit(&(sc->wstrm), Z_DEFAULT_COMPRESSION);
318 inflateEnd(&(sc->rstrm));
319 deflateEnd(&(sc->wstrm));
347 assert((
int) (p != NULL));
348 assert((
int) (s != NULL));
352 _sx_debug(
ZONE,
"wrong conn type or state for client compress");