mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
.
This commit is contained in:
parent
f7934972ea
commit
f8bf91426b
1 changed files with 122 additions and 125 deletions
|
@ -1,17 +1,15 @@
|
||||||
mod ext {
|
use std::ffi::{CStr, CString};
|
||||||
|
use std::os::raw::c_char;
|
||||||
|
|
||||||
use std::ffi::{CStr, CString};
|
use crate::{AuthInfo, ZeroIDC};
|
||||||
use std::os::raw::c_char;
|
|
||||||
|
|
||||||
use crate::{AuthInfo, ZeroIDC};
|
#[no_mangle]
|
||||||
|
pub extern "C" fn zeroidc_new(
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn zeroidc_new(
|
|
||||||
issuer: *const c_char,
|
issuer: *const c_char,
|
||||||
client_id: *const c_char,
|
client_id: *const c_char,
|
||||||
auth_endpoint: *const c_char,
|
auth_endpoint: *const c_char,
|
||||||
web_listen_port: u16,
|
web_listen_port: u16,
|
||||||
) -> *mut ZeroIDC {
|
) -> *mut ZeroIDC {
|
||||||
if issuer.is_null() {
|
if issuer.is_null() {
|
||||||
println!("issuer is null");
|
println!("issuer is null");
|
||||||
return std::ptr::null_mut();
|
return std::ptr::null_mut();
|
||||||
|
@ -44,42 +42,42 @@ mod ext {
|
||||||
return std::ptr::null_mut();
|
return std::ptr::null_mut();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn zeroidc_delete(ptr: *mut ZeroIDC) {
|
pub extern "C" fn zeroidc_delete(ptr: *mut ZeroIDC) {
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
Box::from_raw(ptr);
|
Box::from_raw(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn zeroidc_start(ptr: *mut ZeroIDC) {
|
pub extern "C" fn zeroidc_start(ptr: *mut ZeroIDC) {
|
||||||
let idc = unsafe {
|
let idc = unsafe {
|
||||||
assert!(!ptr.is_null());
|
assert!(!ptr.is_null());
|
||||||
&mut *ptr
|
&mut *ptr
|
||||||
};
|
};
|
||||||
idc.start();
|
idc.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn zeroidc_stop(ptr: *mut ZeroIDC) {
|
pub extern "C" fn zeroidc_stop(ptr: *mut ZeroIDC) {
|
||||||
let idc = unsafe {
|
let idc = unsafe {
|
||||||
assert!(!ptr.is_null());
|
assert!(!ptr.is_null());
|
||||||
&mut *ptr
|
&mut *ptr
|
||||||
};
|
};
|
||||||
idc.stop();
|
idc.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn zeroidc_get_auth_info(
|
pub extern "C" fn zeroidc_get_auth_info(
|
||||||
ptr: *mut ZeroIDC,
|
ptr: *mut ZeroIDC,
|
||||||
csrf_token: *const c_char,
|
csrf_token: *const c_char,
|
||||||
nonce: *const c_char,
|
nonce: *const c_char,
|
||||||
) -> *mut AuthInfo {
|
) -> *mut AuthInfo {
|
||||||
let idc = unsafe {
|
let idc = unsafe {
|
||||||
assert!(!ptr.is_null());
|
assert!(!ptr.is_null());
|
||||||
&mut *ptr
|
&mut *ptr
|
||||||
|
@ -108,25 +106,24 @@ mod ext {
|
||||||
Some(a) => Box::into_raw(Box::new(a)),
|
Some(a) => Box::into_raw(Box::new(a)),
|
||||||
None => std::ptr::null_mut(),
|
None => std::ptr::null_mut(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn zeroidc_auth_info_delete(ptr: *mut AuthInfo) {
|
pub extern "C" fn zeroidc_auth_info_delete(ptr: *mut AuthInfo) {
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
Box::from_raw(ptr);
|
Box::from_raw(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn zeroidc_get_auth_url(ptr: *mut AuthInfo) -> *const c_char {
|
pub extern "C" fn zeroidc_get_auth_url(ptr: *mut AuthInfo) -> *const c_char {
|
||||||
let ai = unsafe {
|
let ai = unsafe {
|
||||||
assert!(!ptr.is_null());
|
assert!(!ptr.is_null());
|
||||||
&mut *ptr
|
&mut *ptr
|
||||||
};
|
};
|
||||||
let s = CString::new(ai.url.to_string()).unwrap();
|
let s = CString::new(ai.url.to_string()).unwrap();
|
||||||
return s.as_ptr();
|
return s.as_ptr();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue