@@ -294,6 +294,18 @@ impl WebSocketState {
294
294
// Input was fully consumed.
295
295
return AppLayerResult :: ok ( ) ;
296
296
}
297
+
298
+ fn use_extension ( & mut self , hv : & [ u8 ] ) {
299
+ let iter = hv. split ( |c| * c == b';' ) ;
300
+ for sub in iter {
301
+ if let Ok ( ( _, val) ) = parser:: parse_cli_max_win ( sub) {
302
+ self . c2s_dec = Some ( Decompress :: new_with_window_bits ( false , val) ) ;
303
+ }
304
+ if let Ok ( ( _, val) ) = parser:: parse_srv_max_win ( sub) {
305
+ self . s2c_dec = Some ( Decompress :: new_with_window_bits ( false , val) ) ;
306
+ }
307
+ }
308
+ }
297
309
}
298
310
299
311
// C exports.
@@ -316,10 +328,35 @@ pub unsafe extern "C" fn rs_websocket_probing_parser(
316
328
return ALPROTO_UNKNOWN ;
317
329
}
318
330
319
- extern "C" fn rs_websocket_state_new ( _orig_state : * mut c_void , _orig_proto : AppProto ) -> * mut c_void {
331
+ // Extern functions operating on HTTP2.
332
+ extern "C" {
333
+ pub fn Http1GetDataForWebsocket (
334
+ orig_state : * mut std:: os:: raw:: c_void , new_state : * mut std:: os:: raw:: c_void ,
335
+ ) ;
336
+ }
337
+
338
+ #[ no_mangle]
339
+ pub unsafe extern "C" fn SCWebSocketUseExtension (
340
+ state : * mut c_void , input : * const u8 , input_len : u32 ,
341
+ ) {
342
+ if !input. is_null ( ) {
343
+ let slice = build_slice ! ( input, input_len as usize ) ;
344
+ let state = cast_pointer ! ( state, WebSocketState ) ;
345
+ state. use_extension ( slice) ;
346
+ }
347
+ }
348
+
349
+ extern "C" fn rs_websocket_state_new ( orig_state : * mut c_void , orig_proto : AppProto ) -> * mut c_void {
320
350
let state = WebSocketState :: new ( ) ;
321
351
let boxed = Box :: new ( state) ;
322
- return Box :: into_raw ( boxed) as * mut c_void ;
352
+ let r = Box :: into_raw ( boxed) as * mut c_void ;
353
+ if !orig_state. is_null ( ) && orig_proto == ALPROTO_HTTP1 as u16 {
354
+ //we could check ALPROTO_HTTP1 == orig_proto
355
+ unsafe {
356
+ Http1GetDataForWebsocket ( orig_state, r) ;
357
+ }
358
+ }
359
+ return r;
323
360
}
324
361
325
362
unsafe extern "C" fn rs_websocket_state_free ( state : * mut c_void ) {
0 commit comments