Deleted Added
full compact
compress.c (92555) compress.c (98675)
1/*
2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
5 * Interface to packet compression for ssh.
6 *
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
12 */
13
14#include "includes.h"
1/*
2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
5 * Interface to packet compression for ssh.
6 *
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
12 */
13
14#include "includes.h"
15RCSID("$OpenBSD: compress.c,v 1.17 2001/12/29 21:56:01 stevesk Exp $");
15RCSID("$OpenBSD: compress.c,v 1.19 2002/03/18 17:31:54 provos Exp $");
16
17#include "log.h"
18#include "buffer.h"
19#include "zlib.h"
20#include "compress.h"
21
16
17#include "log.h"
18#include "buffer.h"
19#include "zlib.h"
20#include "compress.h"
21
22static z_stream incoming_stream;
23static z_stream outgoing_stream;
22z_stream incoming_stream;
23z_stream outgoing_stream;
24static int compress_init_send_called = 0;
25static int compress_init_recv_called = 0;
24static int compress_init_send_called = 0;
25static int compress_init_recv_called = 0;
26static int inflate_failed = 0;
27static int deflate_failed = 0;
26
27/*
28 * Initializes compression; level is compression level from 1 to 9
29 * (as in gzip).
30 */
31
32void
33buffer_compress_init_send(int level)

--- 23 unchanged lines hidden (view full) ---

57 debug("compress outgoing: raw data %lu, compressed %lu, factor %.2f",
58 outgoing_stream.total_in, outgoing_stream.total_out,
59 outgoing_stream.total_in == 0 ? 0.0 :
60 (double) outgoing_stream.total_out / outgoing_stream.total_in);
61 debug("compress incoming: raw data %lu, compressed %lu, factor %.2f",
62 incoming_stream.total_out, incoming_stream.total_in,
63 incoming_stream.total_out == 0 ? 0.0 :
64 (double) incoming_stream.total_in / incoming_stream.total_out);
28
29/*
30 * Initializes compression; level is compression level from 1 to 9
31 * (as in gzip).
32 */
33
34void
35buffer_compress_init_send(int level)

--- 23 unchanged lines hidden (view full) ---

59 debug("compress outgoing: raw data %lu, compressed %lu, factor %.2f",
60 outgoing_stream.total_in, outgoing_stream.total_out,
61 outgoing_stream.total_in == 0 ? 0.0 :
62 (double) outgoing_stream.total_out / outgoing_stream.total_in);
63 debug("compress incoming: raw data %lu, compressed %lu, factor %.2f",
64 incoming_stream.total_out, incoming_stream.total_in,
65 incoming_stream.total_out == 0 ? 0.0 :
66 (double) incoming_stream.total_in / incoming_stream.total_out);
65 if (compress_init_recv_called == 1)
67 if (compress_init_recv_called == 1 && inflate_failed == 0)
66 inflateEnd(&incoming_stream);
68 inflateEnd(&incoming_stream);
67 if (compress_init_send_called == 1)
69 if (compress_init_send_called == 1 && deflate_failed == 0)
68 deflateEnd(&outgoing_stream);
69}
70
71/*
72 * Compresses the contents of input_buffer into output_buffer. All packets
73 * compressed using this function will form a single compressed data stream;
74 * however, data will be flushed at the end of every call so that each
75 * output_buffer can be decompressed independently (but in the appropriate

--- 25 unchanged lines hidden (view full) ---

101 status = deflate(&outgoing_stream, Z_PARTIAL_FLUSH);
102 switch (status) {
103 case Z_OK:
104 /* Append compressed data to output_buffer. */
105 buffer_append(output_buffer, buf,
106 sizeof(buf) - outgoing_stream.avail_out);
107 break;
108 default:
70 deflateEnd(&outgoing_stream);
71}
72
73/*
74 * Compresses the contents of input_buffer into output_buffer. All packets
75 * compressed using this function will form a single compressed data stream;
76 * however, data will be flushed at the end of every call so that each
77 * output_buffer can be decompressed independently (but in the appropriate

--- 25 unchanged lines hidden (view full) ---

103 status = deflate(&outgoing_stream, Z_PARTIAL_FLUSH);
104 switch (status) {
105 case Z_OK:
106 /* Append compressed data to output_buffer. */
107 buffer_append(output_buffer, buf,
108 sizeof(buf) - outgoing_stream.avail_out);
109 break;
110 default:
111 deflate_failed = 1;
109 fatal("buffer_compress: deflate returned %d", status);
110 /* NOTREACHED */
111 }
112 } while (outgoing_stream.avail_out == 0);
113}
114
115/*
116 * Uncompresses the contents of input_buffer into output_buffer. All packets

--- 27 unchanged lines hidden (view full) ---

144 case Z_BUF_ERROR:
145 /*
146 * Comments in zlib.h say that we should keep calling
147 * inflate() until we get an error. This appears to
148 * be the error that we get.
149 */
150 return;
151 default:
112 fatal("buffer_compress: deflate returned %d", status);
113 /* NOTREACHED */
114 }
115 } while (outgoing_stream.avail_out == 0);
116}
117
118/*
119 * Uncompresses the contents of input_buffer into output_buffer. All packets

--- 27 unchanged lines hidden (view full) ---

147 case Z_BUF_ERROR:
148 /*
149 * Comments in zlib.h say that we should keep calling
150 * inflate() until we get an error. This appears to
151 * be the error that we get.
152 */
153 return;
154 default:
155 inflate_failed = 1;
152 fatal("buffer_uncompress: inflate returned %d", status);
153 /* NOTREACHED */
154 }
155 }
156}
156 fatal("buffer_uncompress: inflate returned %d", status);
157 /* NOTREACHED */
158 }
159 }
160}