summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-29 15:55:45 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-29 15:55:45 +0200
commitf588641f09d5e3b774a3597ebbe80b92879dd655 (patch)
tree05b8bda7d64761e178a85d5dd0cb27b0e86f7311
parent85862b19ea13090d763f31054c3d8244c220704d (diff)
State: Add a deregister method for cleanup
-rw-r--r--exports/exports.go6
-rw-r--r--src/state.go8
-rw-r--r--wrappers/python/eduvpncommon/__init__.py1
-rw-r--r--wrappers/python/eduvpncommon/main.py5
4 files changed, 20 insertions, 0 deletions
diff --git a/exports/exports.go b/exports/exports.go
index 4e998bf..5a4d7b9 100644
--- a/exports/exports.go
+++ b/exports/exports.go
@@ -39,6 +39,12 @@ func Register(name *C.char, config_directory *C.char, stateCallback C.PythonCB)
return C.CString(ErrorToString(registerErr))
}
+//export Deregister
+func Deregister() {
+ state := eduvpn.GetVPNState()
+ state.Deregister()
+}
+
func ErrorToString(error error) string {
if error == nil {
return ""
diff --git a/src/state.go b/src/state.go
index c146e61..a48d13d 100644
--- a/src/state.go
+++ b/src/state.go
@@ -36,6 +36,14 @@ func (state *VPNState) Register(name string, directory string, stateCallback fun
return nil
}
+func (state *VPNState) Deregister() {
+ // Close the log file
+ state.CloseLog()
+
+ // Re-initialize everything
+ state = &VPNState{}
+}
+
func (state *VPNState) Connect(url string) (string, error) {
if state.Server == nil {
state.Server = &Server{}
diff --git a/wrappers/python/eduvpncommon/__init__.py b/wrappers/python/eduvpncommon/__init__.py
index faa311d..4c1872f 100644
--- a/wrappers/python/eduvpncommon/__init__.py
+++ b/wrappers/python/eduvpncommon/__init__.py
@@ -34,6 +34,7 @@ VPNStateChange = CFUNCTYPE(None, c_char_p, c_char_p, c_char_p)
# Exposed functions
lib.Connect.argtypes, lib.Connect.restype = [c_char_p], DataError
+lib.Deregister.argtypes, lib.Deregister.restype = [], None
lib.Register.argtypes, lib.Register.restype = [c_char_p, c_char_p, VPNStateChange], None
lib.GetOrganizationsList.argtypes, lib.GetOrganizationsList.restype = [], DataError
lib.GetServersList.argtypes, lib.GetServersList.restype = [], DataError
diff --git a/wrappers/python/eduvpncommon/main.py b/wrappers/python/eduvpncommon/main.py
index 9e1f25e..16d7baa 100644
--- a/wrappers/python/eduvpncommon/main.py
+++ b/wrappers/python/eduvpncommon/main.py
@@ -19,6 +19,8 @@ def Register(name, config_directory, state_callback):
err_string = GetPtrString(ptr_err)
return err_string
+def Deregister():
+ return lib.Deregister()
def GetDiscoServers():
servers, serversErr = GetDataError(lib.GetServersList())
@@ -52,6 +54,9 @@ class EduVPN(object):
self.config_directory = config_directory
register_callback(self)
+ def __del__(self):
+ Deregister()
+
def register(self) -> bool:
return Register(self.name, self.config_directory, callback_function) == ""