chore: Split into SSV and P4PillonDebugLib in 2 files
This commit is contained in:
parent
9c1e06915e
commit
ec1e147e91
167
src/main.rs
167
src/main.rs
@ -1,166 +1,7 @@
|
||||
extern crate libc;
|
||||
|
||||
use libc::{ c_char, c_int, c_void, c_ushort, size_t };
|
||||
use std::ffi::{ CStr, CString };
|
||||
use std::ptr;
|
||||
|
||||
#[link(name = "p4pillondebuglib")]
|
||||
extern "C" {
|
||||
fn hello() -> *const c_char;
|
||||
fn helloName(name: *const c_char) -> *const c_char;
|
||||
fn helloPtr(result: *mut c_char);
|
||||
fn helloPtrPtr(result: *mut *mut c_char, size: *mut size_t);
|
||||
fn helloVoidPtrPtr(result: *mut *mut c_void, size: *mut size_t);
|
||||
fn add(a: c_int, b: c_int) -> c_int;
|
||||
fn addPtr(a: c_int, b: c_int, result: *mut c_int);
|
||||
fn fillHexValues(result: *mut *mut c_void, size: *mut size_t);
|
||||
}
|
||||
|
||||
#[link(name = "ssvlux64")]
|
||||
extern "C" {
|
||||
fn SSV_InitLIB2(pcRepSesamIni: *const c_char) -> c_ushort;
|
||||
fn SSV_LireCartePS(NomRessourcePS: *const c_char, NomRessourceLecteur: *const c_char, CodePorteurPS: *const c_char, ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||
fn SSV_LireConfig(ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||
}
|
||||
|
||||
fn ssv_init_lib_2() {
|
||||
let ini = CString::new("/etc/opt/santesocial/fsv/1.40.13/conf/sesam.ini").expect("CString::new failed");
|
||||
unsafe {
|
||||
let result = SSV_InitLIB2(ini.as_ptr());
|
||||
println!("SSV_InitLIB2 result: {}", result);
|
||||
}
|
||||
}
|
||||
|
||||
fn ssv_lire_carte_ps() {
|
||||
let resource_ps = CString::new("PS").expect("CString::new failed");
|
||||
let resource_reader = CString::new("TRANSPA1").expect("CString::new failed");
|
||||
let card_number = CString::new("1234567890").expect("CString::new failed");
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
let result = SSV_LireCartePS(
|
||||
resource_ps.as_ptr(),
|
||||
resource_reader.as_ptr(),
|
||||
card_number.as_ptr(),
|
||||
&mut buffer,
|
||||
&mut size
|
||||
);
|
||||
println!("SSV_LireCartePS result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ssv_lire_config() {
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
let result = SSV_LireConfig(&mut buffer, &mut size);
|
||||
println!("SSV_LireConfig result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
mod p4pillondebuglib_demo;
|
||||
mod ssvlib_demo;
|
||||
|
||||
fn main() {
|
||||
|
||||
unsafe {
|
||||
let c_str = hello();
|
||||
let r_str: &str = CStr::from_ptr(c_str).to_str().unwrap();
|
||||
println!("{} from C", r_str);
|
||||
}
|
||||
|
||||
let name = CString::new("John").expect("CString::new failed");
|
||||
unsafe {
|
||||
let c_str = helloName(name.as_ptr());
|
||||
let r_str = CStr::from_ptr(c_str).to_str().expect("Conversion failed");
|
||||
println!("{} from C with name", r_str);
|
||||
|
||||
libc::free(c_str as *mut c_void);
|
||||
}
|
||||
|
||||
let mut buffer: [c_char; 50] = [0; 50];
|
||||
unsafe {
|
||||
helloPtr(buffer.as_mut_ptr());
|
||||
let c_str = CStr::from_ptr(buffer.as_ptr());
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Ptr", r_str);
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_char = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
helloPtrPtr(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let c_str = CStr::from_ptr(buffer);
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Ptr Ptr (size: {})", r_str, size);
|
||||
|
||||
libc::free(buffer as *mut c_void);
|
||||
}
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
helloVoidPtrPtr(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let c_str = CStr::from_ptr(buffer as *const c_char);
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Void Ptr Ptr (size: {})", r_str, size);
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let result = add(1, 2);
|
||||
println!("Result of 1 + 2 = {}", result);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let mut result = 0;
|
||||
addPtr(1, 2, &mut result);
|
||||
println!("Result Ptr of 1 + 2 = {}", result);
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
fillHexValues(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
ssv_init_lib_2();
|
||||
ssv_lire_carte_ps();
|
||||
ssv_lire_config();
|
||||
|
||||
p4pillondebuglib_demo::demo();
|
||||
ssvlib_demo::demo();
|
||||
}
|
||||
|
101
src/p4pillondebuglib_demo.rs
Normal file
101
src/p4pillondebuglib_demo.rs
Normal file
@ -0,0 +1,101 @@
|
||||
extern crate libc;
|
||||
|
||||
use libc::{ c_char, c_int, c_void, size_t };
|
||||
use std::ffi::{ CStr, CString };
|
||||
use std::ptr;
|
||||
|
||||
#[link(name = "p4pillondebuglib")]
|
||||
extern "C" {
|
||||
fn hello() -> *const c_char;
|
||||
fn helloName(name: *const c_char) -> *const c_char;
|
||||
fn helloPtr(result: *mut c_char);
|
||||
fn helloPtrPtr(result: *mut *mut c_char, size: *mut size_t);
|
||||
fn helloVoidPtrPtr(result: *mut *mut c_void, size: *mut size_t);
|
||||
fn add(a: c_int, b: c_int) -> c_int;
|
||||
fn addPtr(a: c_int, b: c_int, result: *mut c_int);
|
||||
fn fillHexValues(result: *mut *mut c_void, size: *mut size_t);
|
||||
}
|
||||
|
||||
pub fn demo() {
|
||||
println!("------- Demo for the P4PillonDebugLib ---");
|
||||
|
||||
unsafe {
|
||||
let c_str = hello();
|
||||
let r_str: &str = CStr::from_ptr(c_str).to_str().unwrap();
|
||||
println!("{} from C", r_str);
|
||||
}
|
||||
|
||||
let name = CString::new("John").expect("CString::new failed");
|
||||
unsafe {
|
||||
let c_str = helloName(name.as_ptr());
|
||||
let r_str = CStr::from_ptr(c_str).to_str().expect("Conversion failed");
|
||||
println!("{} from C with name", r_str);
|
||||
|
||||
libc::free(c_str as *mut c_void);
|
||||
}
|
||||
|
||||
let mut buffer: [c_char; 50] = [0; 50];
|
||||
unsafe {
|
||||
helloPtr(buffer.as_mut_ptr());
|
||||
let c_str = CStr::from_ptr(buffer.as_ptr());
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Ptr", r_str);
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_char = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
helloPtrPtr(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let c_str = CStr::from_ptr(buffer);
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Ptr Ptr (size: {})", r_str, size);
|
||||
|
||||
libc::free(buffer as *mut c_void);
|
||||
}
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
helloVoidPtrPtr(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let c_str = CStr::from_ptr(buffer as *const c_char);
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Void Ptr Ptr (size: {})", r_str, size);
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let result = add(1, 2);
|
||||
println!("Result of 1 + 2 = {}", result);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let mut result = 0;
|
||||
addPtr(1, 2, &mut result);
|
||||
println!("Result Ptr of 1 + 2 = {}", result);
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
fillHexValues(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
println!("-----------------------------------------");
|
||||
}
|
78
src/ssvlib_demo.rs
Normal file
78
src/ssvlib_demo.rs
Normal file
@ -0,0 +1,78 @@
|
||||
extern crate libc;
|
||||
|
||||
use libc::{ c_char, c_void, c_ushort, size_t };
|
||||
use std::ffi::CString;
|
||||
use std::ptr;
|
||||
|
||||
#[link(name = "ssvlux64")]
|
||||
extern "C" {
|
||||
fn SSV_InitLIB2(pcRepSesamIni: *const c_char) -> c_ushort;
|
||||
fn SSV_LireCartePS(NomRessourcePS: *const c_char, NomRessourceLecteur: *const c_char, CodePorteurPS: *const c_char, ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||
fn SSV_LireConfig(ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||
}
|
||||
|
||||
fn ssv_init_lib_2() {
|
||||
let ini = CString::new("/etc/opt/santesocial/fsv/1.40.13/conf/sesam.ini").expect("CString::new failed");
|
||||
unsafe {
|
||||
let result = SSV_InitLIB2(ini.as_ptr());
|
||||
println!("SSV_InitLIB2 result: {}", result);
|
||||
}
|
||||
}
|
||||
|
||||
fn ssv_lire_carte_ps() {
|
||||
let resource_ps = CString::new("PS").expect("CString::new failed");
|
||||
let resource_reader = CString::new("TRANSPA1").expect("CString::new failed");
|
||||
let card_number = CString::new("1234567890").expect("CString::new failed");
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
let result = SSV_LireCartePS(
|
||||
resource_ps.as_ptr(),
|
||||
resource_reader.as_ptr(),
|
||||
card_number.as_ptr(),
|
||||
&mut buffer,
|
||||
&mut size
|
||||
);
|
||||
println!("SSV_LireCartePS result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ssv_lire_config() {
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
let result = SSV_LireConfig(&mut buffer, &mut size);
|
||||
println!("SSV_LireConfig result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn demo() {
|
||||
println!("------- Demo for the SSV library --------");
|
||||
|
||||
ssv_init_lib_2();
|
||||
ssv_lire_carte_ps();
|
||||
ssv_lire_config();
|
||||
|
||||
println!("-----------------------------------------");
|
||||
}
|
Loading…
Reference in New Issue
Block a user