XNetworking: wire UDP port change callbacks and UTF-16 security queries

(cherry picked from commit 64a33ec757c1da0963a6821cd59995b8efabe946)
This commit is contained in:
ashrafsdrop authored and local committed 2026-11-25 01:03:01 -06:00
1 parent 20e295f2fc
commit 4ae3490420
1 file changed
+85 -16
+85 -16
View File
@@ -79,6 +79,14 @@ extern "system" fn udp_port_result(_: This, block: *mut AsyncBlock, out: *mut u1
static SECURITY: u8 = 0;
fn wide(text: *const u16) -> Option<String> {
// SAFETY: the title passes a NUL-terminated UTF-16 string or null.
(!text.is_null()).then(|| unsafe {
let len = (0..).take_while(|&i| *text.add(i) != 0).count();
String::from_utf16_lossy(std::slice::from_raw_parts(text, len))
})
}
/// The allow list comes from the service: unreachable offline.
extern "system" fn security_info_async(
_: This,
@@ -91,6 +99,17 @@ extern "system" fn security_info_async(
);
xasync::finished(block, (&raw const SECURITY).cast(), UNREACHABLE)
}
extern "system" fn security_info_utf16_async(
_: This,
url: *const u16,
block: *mut AsyncBlock,
) -> HRESULT {
tracing::debug!(
url = wide(url).unwrap_or_default(),
"security information (utf16): offline"
);
xasync::finished(block, (&raw const SECURITY).cast(), UNREACHABLE)
}
extern "system" fn security_info_size(_: This, block: *mut AsyncBlock, out: *mut usize) -> HRESULT {
xasync::XAsyncGetResultSize(block, out)
}
@@ -124,7 +143,7 @@ extern "system" fn connectivity_hint(_: This, out: *mut ConnectivityHint) -> HRE
put(out, OFFLINE)
}
/// The hint never changes offline, so the callback never runs.
/// The hint and preferred port never change offline, so callbacks never run.
extern "system" fn register(
_: This,
_queue: *const c_void,
@@ -142,21 +161,21 @@ static VTABLE: Methods<18> = Methods([
missing::<0> as *const (),
add_ref as *const (),
add_ref as *const (),
udp_port as *const (), // 0x18
udp_port_async as *const (), // 0x20
udp_port_result as *const (), // 0x28
missing::<6> as *const (), // 0x30 port changed
missing::<7> as *const (), // 0x38
security_info_async as *const (), // 0x40
security_info_size as *const (), // 0x48
security_info_result as *const (), // 0x50
missing::<11> as *const (), // 0x58 the same for UTF-16 URLs
missing::<12> as *const (), // 0x60
missing::<13> as *const (), // 0x68
verify_certificate as *const (), // 0x70
connectivity_hint as *const (), // 0x78
register as *const (), // 0x80 hint changed (never)
unregister as *const (), // 0x88
udp_port as *const (), // 0x18
udp_port_async as *const (), // 0x20
udp_port_result as *const (), // 0x28
register as *const (), // 0x30 port changed (never)
unregister as *const (), // 0x38
security_info_async as *const (), // 0x40
security_info_size as *const (), // 0x48
security_info_result as *const (), // 0x50
security_info_utf16_async as *const (), // 0x58
security_info_size as *const (), // 0x60
security_info_result as *const (), // 0x68
verify_certificate as *const (), // 0x70
connectivity_hint as *const (), // 0x78
register as *const (), // 0x80 hint changed (never)
unregister as *const (), // 0x88
]);
#[cfg(test)]
@@ -192,6 +211,28 @@ mod tests {
assert_eq!(method::<Port>(&OBJECT, 0x28)(this, &mut b, &mut port), S_OK);
assert_eq!(port, 3074);
type Register = extern "system" fn(
This,
*const c_void,
*mut c_void,
*const c_void,
*mut u64,
) -> HRESULT;
type Unregister = extern "system" fn(This, u64, bool) -> bool;
let mut token = 0;
assert_eq!(
method::<Register>(&OBJECT, 0x30)(
this,
std::ptr::null(),
std::ptr::null_mut(),
std::ptr::null(),
&mut token,
),
S_OK
);
assert_ne!(token, 0);
assert!(method::<Unregister>(&OBJECT, 0x38)(this, token, false));
type Url = extern "system" fn(This, *const c_char, *mut AsyncBlock) -> HRESULT;
type Size = extern "system" fn(This, *mut AsyncBlock, *mut usize) -> HRESULT;
let mut b = block();
@@ -206,5 +247,33 @@ mod tests {
method::<Size>(&OBJECT, 0x48)(this, &mut b, &mut size),
UNREACHABLE
);
type UrlUtf16 = extern "system" fn(This, *const u16, *mut AsyncBlock) -> HRESULT;
let mut b = block();
let url_utf16: Vec<u16> = "https://example.invalid/\0".encode_utf16().collect();
assert_eq!(
method::<UrlUtf16>(&OBJECT, 0x58)(this, url_utf16.as_ptr(), &mut b),
S_OK
);
assert_eq!(xasync::XAsyncGetStatus(&mut b, true), UNREACHABLE);
let mut size = 0;
assert_eq!(
method::<Size>(&OBJECT, 0x60)(this, &mut b, &mut size),
UNREACHABLE
);
token = 0;
assert_eq!(
method::<Register>(&OBJECT, 0x80)(
this,
std::ptr::null(),
std::ptr::null_mut(),
std::ptr::null(),
&mut token,
),
S_OK
);
assert_ne!(token, 0);
assert!(method::<Unregister>(&OBJECT, 0x88)(this, token, false));
}
}