Skip to content

Commit

Permalink
Replace winapi with windows-sys (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
DBLouis authored Aug 21, 2023
1 parent 16e7f87 commit 3dc0872
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ openssl-probe = { version = "0.1.2", optional = true }

[target.'cfg(target_env = "msvc")'.dependencies]
schannel = "0.1.13"
winapi = { version = '0.3', features = ['libloaderapi', 'wincrypt'] }
windows-sys = { version = "0.48", features = ["Win32_System_LibraryLoader", "Win32_Security_Cryptography"] }

[dev-dependencies]
mio = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion curl-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ features = ["no_log_capture"]
openssl-sys = { version = "0.9.64", optional = true }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winsock2", "ws2def"] }
windows-sys = { version = "0.48", features = ["Win32_Networking_WinSock"] }

[target.'cfg(target_env = "msvc")'.build-dependencies]
vcpkg = "0.2"
Expand Down
4 changes: 2 additions & 2 deletions curl-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use libc::{c_char, c_double, c_int, c_long, c_short, c_uint, c_void, size_t, tim
#[cfg(unix)]
pub use libc::fd_set;
#[cfg(windows)]
use winapi::shared::ws2def::SOCKADDR;
pub use windows_sys::Win32::Networking::WinSock::FD_SET as fd_set;
#[cfg(windows)]
pub use winapi::um::winsock2::fd_set;
use windows_sys::Win32::Networking::WinSock::SOCKADDR;

#[cfg(target_env = "msvc")]
#[doc(hidden)]
Expand Down
19 changes: 7 additions & 12 deletions src/easy/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@ use libc::c_void;
mod win {
use schannel::cert_context::ValidUses;
use schannel::cert_store::CertStore;
use std::ffi::CString;
use std::ffi::*;
use std::mem;
use std::ptr;
use winapi::ctypes::*;
use winapi::um::libloaderapi::*;
use winapi::um::wincrypt::*;
use windows_sys::Win32::Security::Cryptography::*;
use windows_sys::Win32::System::LibraryLoader::*;

fn lookup(module: &str, symbol: &str) -> Option<*const c_void> {
unsafe {
let symbol = CString::new(symbol).unwrap();
let mut mod_buf: Vec<u16> = module.encode_utf16().collect();
mod_buf.push(0);
let handle = GetModuleHandleW(mod_buf.as_mut_ptr());
let n = GetProcAddress(handle, symbol.as_ptr());
if n == ptr::null_mut() {
None
} else {
Some(n as *const c_void)
}
GetProcAddress(handle, symbol.as_ptr()).map(|n| n as *const c_void)
}
}

Expand Down Expand Up @@ -104,7 +97,9 @@ mod win {
match valid_uses {
ValidUses::All => {}
ValidUses::Oids(ref oids) => {
let oid = szOID_PKIX_KP_SERVER_AUTH.to_owned();
let oid = CStr::from_ptr(szOID_PKIX_KP_SERVER_AUTH as *const _)
.to_string_lossy()
.into_owned();
if !oids.contains(&oid) {
continue;
}
Expand Down

0 comments on commit 3dc0872

Please sign in to comment.