@@ -35,6 +35,9 @@ use crate::private::mutex::{Mutex, RawMutex};
3535pub struct CHttpsSslConfig ( pub httpd_ssl_config_t ) ;
3636
3737
38+ #[ cfg( all( esp_idf_esp_tls_server_sni_hook, esp_idf_comp_esp_http_server_enabled) ) ]
39+ use super :: sni:: * ;
40+
3841#[ derive( Copy , Clone , Debug ) ]
3942pub struct Configuration {
4043 pub http_port : u16 ,
@@ -92,7 +95,7 @@ impl From<&Configuration> for Newtype<httpd_config_t> {
9295 }
9396}
9497
95- #[ derive( Debug ) ]
98+ #[ cfg_attr ( not ( esp_idf_esp_tls_server_sni_hook ) , derive( Debug ) ) ]
9699pub struct SslConfiguration < ' a > {
97100 pub http_configuration : Configuration ,
98101 pub client_verify_cert : Option < & ' a str > ,
@@ -103,17 +106,40 @@ pub struct SslConfiguration<'a> {
103106 #[ cfg( esp_idf_version_major = "5" ) ]
104107 pub use_secure_element : bool ,
105108 pub session_tickets : bool ,
109+
110+ #[ cfg( esp_idf_esp_tls_server_sni_hook) ]
111+ pub sni : Option < Box < dyn SNICB < ' a > > > ,
106112}
107113
114+ #[ cfg( esp_idf_esp_tls_server_sni_hook) ]
115+ impl < ' a > Debug for SslConfiguration < ' a > {
116+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> core:: fmt:: Result {
117+
118+ let sni_s = if self . sni . is_some ( ) {
119+ "Some(..)"
120+ } else { "None" } ;
121+
122+ f. write_fmt ( format_args ! (
123+ "SslConfiguration {{ http_configuration = {:?}, client_verify_cert = {:?}, cacert = {:?}, prvtkey = {:?}, transport_mode_secure = {:?}, session_tickets = {:?}, use_secure_element = {:?}, sni = {:?} }}" ,
124+ self . http_configuration,
125+ self . client_verify_cert,
126+ self . cacert,
127+ self . prvtkey,
128+ self . transport_mode_secure,
129+ self . use_secure_element,
130+ self . session_tickets,
131+ sni_s
132+ ) )
133+ }
134+ }
135+
136+
108137impl < ' a > From < & SslConfiguration < ' a > > for Newtype < httpd_config_t > {
109138 fn from ( conf : & SslConfiguration < ' a > ) -> Self {
110139 Self :: from ( & conf. http_configuration )
111140 }
112141}
113142
114-
115-
116-
117143#[ cfg( esp_idf_version_major = "5" ) ]
118144impl < ' a > From < & SslConfiguration < ' a > > for CHttpsSslConfig {
119145 fn from ( conf : & SslConfiguration ) -> Self {
@@ -137,6 +163,10 @@ impl<'a> From<&SslConfiguration<'a>> for CHttpsSslConfig {
137163 port_insecure : conf. http_configuration . http_port ,
138164 session_tickets : conf. session_tickets ,
139165 user_cb : None ,
166+ #[ cfg( esp_idf_esp_tls_server_sni_hook) ]
167+ sni_callback : Some ( sni_trampoline) ,
168+ #[ cfg( esp_idf_esp_tls_server_sni_hook) ]
169+ sni_callback_p_info : conf. sni . as_ref ( ) . map ( |cb| cb as * const _ as * mut c_types:: c_void ) . unwrap_or ( ptr:: null_mut ( ) as _ ) ,
140170 } )
141171 }
142172}
@@ -163,7 +193,11 @@ impl<'a> From<&SslConfiguration<'a>> for CHttpsSslConfig {
163193 port_insecure : conf. http_configuration . http_port ,
164194 use_secure_element : false ,
165195 session_tickets : conf. session_tickets ,
166- user_cb : None
196+ user_cb : None ,
197+ #[ cfg( esp_idf_esp_tls_server_sni_hook) ]
198+ sni_callback : Some ( sni_trampoline) ,
199+ #[ cfg( esp_idf_esp_tls_server_sni_hook) ]
200+ sni_callback_p_info : conf. sni . as_ref ( ) . map ( |cb| cb as * const _ as * mut c_types:: c_void ) . unwrap_or ( ptr:: null_mut ( ) as _ ) ,
167201 } )
168202 }
169203}
@@ -176,7 +210,12 @@ impl<'a> Default for SslConfiguration<'a> {
176210 cacert : None ,
177211 prvtkey : None ,
178212 transport_mode_secure : true ,
179- session_tickets : false
213+ session_tickets : false ,
214+ #[ cfg( esp_idf_version_major = "5" ) ]
215+ use_secure_element : false ,
216+
217+ #[ cfg( esp_idf_esp_tls_server_sni_hook) ]
218+ sni : None
180219 }
181220 }
182221}
@@ -219,7 +258,6 @@ impl Drop for CHttpsSslConfig {
219258 }
220259}
221260
222-
223261#[ allow( non_upper_case_globals) ]
224262impl From < Newtype < c_types:: c_uint > > for Method {
225263 fn from ( method : Newtype < c_types:: c_uint > ) -> Self {
0 commit comments