mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Add libplist conversion
This commit is contained in:
@@ -12,6 +12,8 @@ once_cell = "1.21.1"
|
||||
tokio = { version = "1.44.1", features = ["full"] }
|
||||
libc = "0.2.171"
|
||||
openssl-sys = { version = "0.9", features = ["vendored"] }
|
||||
plist = "1.7.1"
|
||||
plist_plus = { version = "0.2.6", features = ["vendored"] }
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = "0.28.0"
|
||||
|
||||
@@ -12,6 +12,7 @@ fn main() {
|
||||
)
|
||||
.with_language(cbindgen::Language::C)
|
||||
.with_sys_include("sys/socket.h")
|
||||
.with_sys_include("plist/plist.h")
|
||||
.generate()
|
||||
.expect("Unable to generate bindings")
|
||||
.write_to_file("idevice.h");
|
||||
|
||||
@@ -6,7 +6,7 @@ project(IdeviceFFI C)
|
||||
|
||||
# Set the paths
|
||||
set(HEADER_FILE ${CMAKE_SOURCE_DIR}/../idevice.h)
|
||||
set(STATIC_LIB ${CMAKE_SOURCE_DIR}/target/release/libidevice_ffi.a)
|
||||
set(STATIC_LIB ${CMAKE_SOURCE_DIR}/../../target/release/libidevice_ffi.a)
|
||||
set(EXAMPLES_DIR ${CMAKE_SOURCE_DIR}/../examples)
|
||||
|
||||
# Find all C example files
|
||||
@@ -30,6 +30,31 @@ foreach(EXAMPLE_FILE ${EXAMPLE_SOURCES})
|
||||
# Link OpenSSL
|
||||
target_link_libraries(${EXAMPLE_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
|
||||
|
||||
# libplist
|
||||
|
||||
if( APPLE )
|
||||
# use static linking
|
||||
pkg_search_module(PLIST REQUIRED libplist-2.0)
|
||||
find_library( LIBPLIST libplist-2.0.a REQUIRED )
|
||||
message( STATUS "(Static linking) LIBPLIST " ${LIBPLIST} )
|
||||
target_link_libraries ( ${EXAMPLE_NAME} PRIVATE ${LIBPLIST} )
|
||||
elseif( WIN32)
|
||||
pkg_search_module(PLIST REQUIRED libplist-2.0)
|
||||
find_library( LIBPLIST ${PLIST_LIBRARIES} PATH ${PLIST_LIBDIR} )
|
||||
target_link_libraries ( ${EXAMPLE_NAME} PRIVATE ${LIBPLIST} )
|
||||
else ()
|
||||
pkg_search_module(PLIST libplist>=2.0)
|
||||
if(NOT PLIST_FOUND)
|
||||
pkg_search_module(PLIST REQUIRED libplist-2.0)
|
||||
endif()
|
||||
find_library( LIBPLIST ${PLIST_LIBRARIES} PATH ${PLIST_LIBDIR} )
|
||||
target_link_libraries ( ${EXAMPLE_NAME} PUBLIC ${LIBPLIST} )
|
||||
endif()
|
||||
if ( PLIST_FOUND )
|
||||
message( STATUS "found libplist-${PLIST_VERSION}" )
|
||||
endif()
|
||||
target_include_directories( ${EXAMPLE_NAME} PRIVATE ${PLIST_INCLUDE_DIRS} )
|
||||
|
||||
# Bulk-link common macOS system frameworks
|
||||
if(APPLE)
|
||||
target_link_libraries(${EXAMPLE_NAME} PRIVATE
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::{
|
||||
};
|
||||
|
||||
use libc::{sockaddr_in, sockaddr_in6};
|
||||
use plist::Value;
|
||||
|
||||
use crate::IdeviceErrorCode;
|
||||
|
||||
@@ -75,3 +76,11 @@ pub(crate) fn c_addr_to_rust(addr: *const libc::sockaddr) -> Result<IpAddr, Idev
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn plist_to_libplist(v: &Value) -> plist_plus::Plist {
|
||||
let buf = Vec::new();
|
||||
let mut writer = std::io::BufWriter::new(buf);
|
||||
plist::to_writer_xml(&mut writer, v).unwrap();
|
||||
let buf = String::from_utf8(writer.into_inner().unwrap()).unwrap();
|
||||
plist_plus::Plist::from_xml(buf).unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user