summaryrefslogtreecommitdiff
path: root/wrappers/python
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-10-26 17:09:52 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-10-26 17:09:52 +0200
commit516a25eb926a8b9a879e4f38c86d4dbb9b9e0948 (patch)
tree5e1adb12ebab7b6f770102a179afb2a7db9e479f /wrappers/python
parentb4be281671ecfe5c1e6f831614ca1dde48522cd7 (diff)
Client + Exports + Python: Add a function for getting the current server
Diffstat (limited to 'wrappers/python')
-rw-r--r--wrappers/python/eduvpn_common/loader.py1
-rw-r--r--wrappers/python/eduvpn_common/main.py18
-rw-r--r--wrappers/python/eduvpn_common/server.py16
3 files changed, 28 insertions, 7 deletions
diff --git a/wrappers/python/eduvpn_common/loader.py b/wrappers/python/eduvpn_common/loader.py
index 9463ab1..4b820bf 100644
--- a/wrappers/python/eduvpn_common/loader.py
+++ b/wrappers/python/eduvpn_common/loader.py
@@ -102,6 +102,7 @@ def initialize_functions(lib: CDLL) -> None:
c_char_p
], DataError
lib.GetDiscoServers.argtypes, lib.GetDiscoServers.restype = [c_char_p], DataError
+ lib.GetCurrentServer.argtypes, lib.GetCurrentServer.restype = [c_char_p], DataError
lib.GetSavedServers.argtypes, lib.GetSavedServers.restype = [c_char_p], DataError
lib.GoBack.argtypes, lib.GoBack.restype = [c_char_p], None
lib.InFSMState.argtypes, lib.InFSMState.restype = [c_void_p, c_int], int
diff --git a/wrappers/python/eduvpn_common/main.py b/wrappers/python/eduvpn_common/main.py
index 1467adb..a77015c 100644
--- a/wrappers/python/eduvpn_common/main.py
+++ b/wrappers/python/eduvpn_common/main.py
@@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple
from eduvpn_common.discovery import DiscoOrganizations, DiscoServers, get_disco_organizations, get_disco_servers
from eduvpn_common.event import EventHandler
from eduvpn_common.loader import initialize_functions, load_lib
-from eduvpn_common.server import Profiles, Server, get_servers
+from eduvpn_common.server import Profiles, Server, get_transition_server, get_servers
from eduvpn_common.state import State, StateType
from eduvpn_common.types import VPNStateChange, decode_res, encode_args, get_data_error
@@ -470,6 +470,22 @@ class EduVPN(object):
"""
return self.go_function(self.lib.InFSMState, state_id)
+ def get_current_server(self) -> Optional[Server]:
+ """Get the current server
+
+ :return: The current servers if there is any
+ :rtype: Optional[List[Servers]]
+ """
+ server, server_err = self.go_function(
+ self.lib.GetCurrentServer,
+ decode_func=lambda lib, x: get_data_error(lib, x, get_transition_server),
+ )
+
+ if server_err:
+ raise server_err
+
+ return server
+
def get_saved_servers(self) -> Optional[List[Server]]:
"""Get a list of saved servers
diff --git a/wrappers/python/eduvpn_common/server.py b/wrappers/python/eduvpn_common/server.py
index fc5711e..3a5ff69 100644
--- a/wrappers/python/eduvpn_common/server.py
+++ b/wrappers/python/eduvpn_common/server.py
@@ -245,9 +245,11 @@ def get_transition_server(lib: CDLL, ptr: c_void_p) -> Optional[Server]:
:return: The server if there is any
:rtype: Optional[Server]
"""
- server = get_server(cast(ptr, POINTER(cServer)))
- lib.FreeServer(ptr)
- return server
+ if ptr:
+ server = get_server(cast(ptr, POINTER(cServer)))
+ lib.FreeServer(ptr)
+ return server
+ return None
def get_transition_profiles(lib: CDLL, ptr: c_void_p) -> Optional[Profiles]:
@@ -261,9 +263,11 @@ def get_transition_profiles(lib: CDLL, ptr: c_void_p) -> Optional[Profiles]:
:return: The profiles if there is any
:rtype: Optional[Profiles]
"""
- profiles = get_profiles(cast(ptr, POINTER(cServerProfiles)))
- lib.FreeProfiles(ptr)
- return profiles
+ if ptr:
+ profiles = get_profiles(cast(ptr, POINTER(cServerProfiles)))
+ lib.FreeProfiles(ptr)
+ return profiles
+ return None
def get_servers(lib: CDLL, ptr: c_void_p) -> Optional[List[Server]]: