diff options
| author | Andrew Dunham <[email protected]> | 2014-09-04 18:07:13 -0700 |
|---|---|---|
| committer | Andrew Dunham <[email protected]> | 2014-09-04 19:02:05 -0700 |
| commit | c4ede3d585982af32e51c0ccc3a6b7f98f3b7ad7 (patch) | |
| tree | 42834d59ccdbdb43580c9a1945a5331109df1d48 /src | |
| parent | Merge pull request #35 from Kroisse/master (diff) | |
| download | rust-openssl-c4ede3d585982af32e51c0ccc3a6b7f98f3b7ad7.tar.xz rust-openssl-c4ede3d585982af32e51c0ccc3a6b7f98f3b7ad7.zip | |
Allow getting the compression used in a connection
Diffstat (limited to 'src')
| -rw-r--r-- | src/ssl/ffi.rs | 4 | ||||
| -rw-r--r-- | src/ssl/mod.rs | 16 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/ssl/ffi.rs b/src/ssl/ffi.rs index 4677c189..d53d3c36 100644 --- a/src/ssl/ffi.rs +++ b/src/ssl/ffi.rs @@ -4,6 +4,7 @@ use libc::{c_int, c_void, c_long, c_ulong, c_char}; pub type SSL_CTX = c_void; pub type SSL_METHOD = c_void; +pub type COMP_METHOD = c_void; pub type SSL = c_void; pub type BIO = c_void; pub type BIO_METHOD = c_void; @@ -145,12 +146,15 @@ extern "C" { pub fn SSL_write(ssl: *mut SSL, buf: *const c_void, num: c_int) -> c_int; pub fn SSL_get_ex_data_X509_STORE_CTX_idx() -> c_int; pub fn SSL_get_SSL_CTX(ssl: *mut SSL) -> *mut SSL_CTX; + pub fn SSL_get_current_compression(ssl: *mut SSL) -> *const COMP_METHOD; pub fn BIO_s_mem() -> *const BIO_METHOD; pub fn BIO_new(type_: *const BIO_METHOD) -> *mut BIO; pub fn BIO_free_all(a: *mut BIO); pub fn BIO_read(b: *mut BIO, buf: *mut c_void, len: c_int) -> c_int; pub fn BIO_write(b: *mut BIO, buf: *const c_void, len: c_int) -> c_int; + + pub fn SSL_COMP_get_name(comp: *const COMP_METHOD) -> *const c_char; } #[cfg(target_os = "win32")] diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index 7c9b2d60..125efdcb 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -3,6 +3,7 @@ use std::io::{IoResult, IoError, EndOfFile, Stream, Reader, Writer}; use std::mem; use std::ptr; use std::rt::mutex::NativeMutex; +use std::string; use sync::one::{Once, ONCE_INIT}; use ssl::error::{SslError, SslSessionClosed, StreamError}; @@ -500,6 +501,21 @@ impl<S: Stream> SslStream<S> { } Ok(()) } + + /// Get the compression currently in use. The result will be + /// either None, indicating no compression is in use, or a string + /// with the compression name. + pub fn get_compression(&self) -> Option<String> { + let ptr = unsafe { ffi::SSL_get_current_compression(self.ssl.ssl) }; + if ptr == ptr::null() { + return None; + } + + let meth = unsafe { ffi::SSL_COMP_get_name(ptr) }; + let s = unsafe { string::raw::from_buf(meth as *const u8) }; + + Some(s) + } } impl<S: Stream> Reader for SslStream<S> { |