From b4d744a80aa79d45f8a46119920abc1279ad4f20 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 21 Jun 2022 16:52:55 +0200 Subject: State: Add functions for getting/setting a connection identifier e.g. the uuid of the connection in case of NetworkManager on Linux --- wrappers/python/src/__init__.py | 2 ++ wrappers/python/src/main.py | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'wrappers/python') diff --git a/wrappers/python/src/__init__.py b/wrappers/python/src/__init__.py index c96a1b2..bc9b3df 100644 --- a/wrappers/python/src/__init__.py +++ b/wrappers/python/src/__init__.py @@ -61,6 +61,8 @@ lib.CancelOAuth.argtypes, lib.CancelOAuth.restype = [c_char_p], c_void_p lib.SetProfileID.argtypes, lib.SetProfileID.restype = [c_char_p, c_char_p], c_void_p lib.SetConnected.argtypes, lib.SetConnected.restype = [c_char_p], c_void_p lib.SetDisconnected.argtypes, lib.SetDisconnected.restype = [c_char_p], c_void_p +lib.GetIdentifier.argtypes, lib.GetIdentifier.restype = [c_char_p], DataError +lib.SetIdentifier.argtypes, lib.SetIdentifier.restype = [c_char_p, c_char_p], c_void_p lib.FreeString.argtypes, lib.FreeString.restype = [c_void_p], None diff --git a/wrappers/python/src/main.py b/wrappers/python/src/main.py index 47e2893..687f40f 100644 --- a/wrappers/python/src/main.py +++ b/wrappers/python/src/main.py @@ -105,6 +105,20 @@ def SetDisconnected(name: str) -> str: return err_string +def SetIdentifier(name: str, identifier: str) -> str: + name_bytes = name.encode("utf-8") + identifier_bytes = identifier.encode("utf-8") + ptr_err = lib.SetIdentifier(name_bytes, identifier_bytes) + err_string = GetPtrString(ptr_err) + return err_string + + +def GetIdentifier(name: str) -> Tuple[str, str]: + name_bytes = name.encode("utf-8") + identifier, identifier_err = GetDataError(lib.GetIdentifier(name_bytes)) + return identifier, identifier_err + + # This has to be global as otherwise the callback is not alive callback_function = None @@ -189,8 +203,12 @@ class EduVPN(object): if config_err: raise Exception(config_err) + def set_connected(self) -> None: + connect_err = SetConnected(self.name) return config, config_type + if connect_err: + raise Exception(connect_err) def set_disconnected(self) -> None: disconnect_err = SetDisconnected(self.name) @@ -198,11 +216,19 @@ class EduVPN(object): if disconnect_err: raise Exception(disconnect_err) - def set_connected(self) -> None: - connect_err = SetConnected(self.name) + def get_identifier(self) -> str: + identifier, identifier_err = GetIdentifier(self.name) - if connect_err: - raise Exception(connect_err) + if identifier_err: + raise Exception(identifier_err) + + return identifier + + def set_identifier(self, identifier: str) -> None: + identifier_err = SetIdentifier(self.name, identifier) + + if identifier_err: + raise Exception(identifier_err) @property def event(self) -> EventHandler: -- cgit v1.2.3