diff options
| author | Yuval Adam <_@yuv.al> | 2018-07-06 17:11:13 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2018-07-06 17:11:13 +0300 |
| commit | c4b1c00c419c14e641e46f9f40cbf6d301c998b4 (patch) | |
| tree | c661cbed7b3bd3e7f39c1b4d7aedcd2de84d53ee /src | |
| parent | 25b213dad9945ea990320a9e0996134a523d58e5 (diff) | |
Might as well work but going another waylibupnp
Diffstat (limited to 'src')
| -rw-r--r-- | src/upnp.rs | 67 |
1 files changed, 59 insertions, 8 deletions
diff --git a/src/upnp.rs b/src/upnp.rs index b142258..20c7989 100644 --- a/src/upnp.rs +++ b/src/upnp.rs @@ -3,19 +3,70 @@ extern crate libc; use self::libc::{uint32_t, uint16_t, uint8_t, c_char, c_uchar, c_int, c_void}; use std::ptr; -pub type GSSDPClient = *mut c_void; +#[allow(dead_code)] +#[derive(Debug)] +#[repr(C)] +enum EventType { + ControlActionRequest, + ControlActionComplete, + ControlGetVarRequest, + ControlGetVarComplete, + DiscoveryAdvertisementAlive, + DiscoveryAdvertisementByebye, + DiscoverySearchResult, + DiscoverySearchTimeout, + SubscriptionRequest, + Received, + RenewalComplete, + SubscribeComplete, + UnsubscribeComplete, + AutorenewalFailed, + SubscriptionExpired, +} + +const LINE_SIZE: usize = 180; + +#[repr(C)] +struct Discovery { + err_code: libc::c_int, + expires: libc::c_int, + device_id: [libc::c_char; LINE_SIZE], + device_type: [libc::c_char; LINE_SIZE], + service_type: [libc::c_char; LINE_SIZE], + service_ver: [libc::c_char; LINE_SIZE], + location: [libc::c_char; LINE_SIZE], + os: [libc::c_char; LINE_SIZE], + date: [libc::c_char; LINE_SIZE], + ext: [libc::c_char; LINE_SIZE], + dest_addr: *mut libc::sockaddr_in, +} + +type ClientHandle = libc::c_int; + +type ClientCallbackPtr = extern "C" fn(event_type: EventType, + event: *const libc::c_void, + cookie: *mut libc::c_void); -#[link(name = "gssdp-1.0")] -extern { - pub fn gssdp_client_new(main_context: *mut c_void, iface: *const c_char, error: *mut c_void) -> GSSDPClient; - pub fn gssdp_client_get_interface(client: *mut GSSDPClient) -> *const c_char; +#[link(name = "upnp")] +extern "C" { + fn UpnpInit(hostIp: *const libc::c_char, destPort: libc::c_ushort) -> libc::c_int; + fn UpnpRegisterClient(callback: ClientCallbackPtr, + cookie: *mut libc::c_void, + handle: *mut ClientHandle) + -> libc::c_int; + fn UpnpUnRegisterClient(handle: ClientHandle) -> libc::c_int; + fn UpnpSearchAsync(handle: ClientHandle, + maxAttempts: libc::c_int, + target: *const libc::c_char, + cookie: *const libc::c_void) + -> libc::c_int; } pub fn discover() { println!("Discovering..."); unsafe { - let mut client = gssdp_client_new(ptr::null_mut(), ptr::null(), ptr::null_mut()); - let iface = gssdp_client_get_interface(&client); + let err = UpnpInit(ptr::null(), 0); + let target = CString::new("ssdp:all"); + UpnpSearchAsync(self.handle.client, 1, target.as_ptr(), cookie); } - println!("Using interface: {}", iface); } |
