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 f343f231..c991b566 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}; @@ -501,6 +502,21 @@ impl SslStream { } 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 { + 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 Reader for SslStream {