mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
refactor: update session extension flow
This commit is contained in:
19 files changed
+927
-419
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use crate::Vpn;
|
||||
use log::{debug, info, trace, warn};
|
||||
use std::ffi::{c_char, c_int, c_void};
|
||||
use std::ffi::{c_char, c_int, c_long, c_void};
|
||||
|
||||
/// ConnectOptions struct for FFI, the field names and order must match the C definition.
|
||||
#[repr(C)]
|
||||
@@ -38,10 +38,24 @@ pub(crate) struct ConnectOptions {
|
||||
pub no_xmlpost: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct VpnSessionInfoRaw {
|
||||
pub auth_expiration: c_long,
|
||||
pub lifetime_secs: c_int,
|
||||
pub user_expires: c_long,
|
||||
pub lifetime_warning_prior: c_int,
|
||||
pub lifetime_warning_message: *const c_char,
|
||||
pub allow_extend_session: c_int,
|
||||
}
|
||||
|
||||
#[link(name = "vpn")]
|
||||
unsafe extern "C" {
|
||||
#[link_name = "vpn_connect"]
|
||||
fn vpn_connect(options: *const ConnectOptions, callback: extern "C" fn(i32, *mut c_void)) -> c_int;
|
||||
fn vpn_connect(
|
||||
options: *const ConnectOptions,
|
||||
callback: extern "C" fn(i32, *const VpnSessionInfoRaw, *mut c_void),
|
||||
) -> c_int;
|
||||
|
||||
#[link_name = "vpn_disconnect"]
|
||||
fn vpn_disconnect();
|
||||
@@ -56,9 +70,9 @@ pub(crate) fn disconnect() {
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn on_vpn_connected(pipe_fd: i32, vpn: *mut c_void) {
|
||||
extern "C" fn on_vpn_connected(pipe_fd: i32, session_info: *const VpnSessionInfoRaw, vpn: *mut c_void) {
|
||||
let vpn = unsafe { &*(vpn as *const Vpn) };
|
||||
vpn.on_connected(pipe_fd);
|
||||
vpn.on_connected(pipe_fd, crate::vpn::session_info_from_raw(session_info));
|
||||
}
|
||||
|
||||
// Logger used in the C code.
|
||||
|
||||
@@ -51,7 +51,18 @@ static void setup_tun_handler(void *_vpninfo)
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
on_vpn_connected(g_cmd_pipe_fd, g_user_data);
|
||||
vpn_session_info session_info = {
|
||||
.auth_expiration = (long)openconnect_get_auth_expiration(_vpninfo),
|
||||
.lifetime_secs = openconnect_get_gp_session_lifetime(_vpninfo),
|
||||
.user_expires = (long)openconnect_get_gp_user_expires(_vpninfo),
|
||||
.lifetime_warning_prior =
|
||||
openconnect_get_gp_lifetime_notify_prior(_vpninfo),
|
||||
.lifetime_warning_message =
|
||||
openconnect_get_gp_lifetime_notify_message(_vpninfo),
|
||||
.allow_extend_session =
|
||||
openconnect_get_gp_allow_extend_session(_vpninfo),
|
||||
};
|
||||
on_vpn_connected(g_cmd_pipe_fd, &session_info, g_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef void (*vpn_connected_callback)(int cmd_pipe_fd, void *user_data);
|
||||
typedef struct vpn_session_info {
|
||||
long auth_expiration;
|
||||
int lifetime_secs;
|
||||
long user_expires;
|
||||
int lifetime_warning_prior;
|
||||
const char *lifetime_warning_message;
|
||||
int allow_extend_session;
|
||||
} vpn_session_info;
|
||||
|
||||
typedef void (*vpn_connected_callback)(int cmd_pipe_fd,
|
||||
const vpn_session_info *session_info,
|
||||
void *user_data);
|
||||
|
||||
typedef struct vpn_options {
|
||||
void *user_data;
|
||||
|
||||
Reference in new issue
Block a user