summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exports/servers.go22
-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
4 files changed, 50 insertions, 7 deletions
diff --git a/exports/servers.go b/exports/servers.go
index 36763b4..381c0dd 100644
--- a/exports/servers.go
+++ b/exports/servers.go
@@ -305,6 +305,28 @@ func GetSavedServers(name *C.char) (*C.servers, *C.error) {
return servers, nil
}
+
+//export GetCurrentServer
+// This function takes the name as input which is the name of the client
+// It gets the state by name and then returns the current server as a c struct belonging to it
+func GetCurrentServer(name *C.char) (*C.server, *C.error) {
+ nameStr := C.GoString(name)
+ state, stateErr := GetVPNState(nameStr)
+ if stateErr != nil {
+ return nil, getError(stateErr)
+ }
+ server, serverErr := state.Servers.GetCurrentServer()
+ if serverErr != nil {
+ return nil, getError(serverErr)
+ }
+ base, baseErr := server.GetBase()
+ if baseErr != nil {
+ return nil, getError(baseErr)
+ }
+ cServer := getCPtrServer(state, base)
+ return cServer, nil
+}
+
// This function takes the state as input which is the main state
// It also takes the data as an interface and if it has the servers type gets the data as a c struct otherwise nil
func getTransitionDataServers(state *client.Client, data interface{}) *C.servers {
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]]: