@@ -1572,16 +1572,34 @@ impl SslContextBuilder {
15721572 ///
15731573 /// This can be used to provide data to callbacks registered with the context. Use the
15741574 /// `SslContext::new_ex_index` method to create an `Index`.
1575+ // FIXME should return a result
15751576 #[ corresponds( SSL_CTX_set_ex_data ) ]
15761577 pub fn set_ex_data < T > ( & mut self , index : Index < SslContext , T > , data : T ) {
15771578 self . set_ex_data_inner ( index, data) ;
15781579 }
15791580
15801581 fn set_ex_data_inner < T > ( & mut self , index : Index < SslContext , T > , data : T ) -> * mut c_void {
1582+ match self . ex_data_mut ( index) {
1583+ Some ( v) => {
1584+ * v = data;
1585+ ( v as * mut T ) . cast ( )
1586+ }
1587+ _ => unsafe {
1588+ let data = Box :: into_raw ( Box :: new ( data) ) as * mut c_void ;
1589+ ffi:: SSL_CTX_set_ex_data ( self . as_ptr ( ) , index. as_raw ( ) , data) ;
1590+ data
1591+ } ,
1592+ }
1593+ }
1594+
1595+ fn ex_data_mut < T > ( & mut self , index : Index < SslContext , T > ) -> Option < & mut T > {
15811596 unsafe {
1582- let data = Box :: into_raw ( Box :: new ( data) ) as * mut c_void ;
1583- ffi:: SSL_CTX_set_ex_data ( self . as_ptr ( ) , index. as_raw ( ) , data) ;
1584- data
1597+ let data = ffi:: SSL_CTX_get_ex_data ( self . as_ptr ( ) , index. as_raw ( ) ) ;
1598+ if data. is_null ( ) {
1599+ None
1600+ } else {
1601+ Some ( & mut * data. cast ( ) )
1602+ }
15851603 }
15861604 }
15871605
@@ -2965,15 +2983,19 @@ impl SslRef {
29652983 ///
29662984 /// This can be used to provide data to callbacks registered with the context. Use the
29672985 /// `Ssl::new_ex_index` method to create an `Index`.
2986+ // FIXME should return a result
29682987 #[ corresponds( SSL_set_ex_data ) ]
29692988 pub fn set_ex_data < T > ( & mut self , index : Index < Ssl , T > , data : T ) {
2970- unsafe {
2971- let data = Box :: new ( data) ;
2972- ffi:: SSL_set_ex_data (
2973- self . as_ptr ( ) ,
2974- index. as_raw ( ) ,
2975- Box :: into_raw ( data) as * mut c_void ,
2976- ) ;
2989+ match self . ex_data_mut ( index) {
2990+ Some ( v) => * v = data,
2991+ None => unsafe {
2992+ let data = Box :: new ( data) ;
2993+ ffi:: SSL_set_ex_data (
2994+ self . as_ptr ( ) ,
2995+ index. as_raw ( ) ,
2996+ Box :: into_raw ( data) as * mut c_void ,
2997+ ) ;
2998+ } ,
29772999 }
29783000 }
29793001
0 commit comments