diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-03-22 14:42:20 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-03-22 14:42:20 +0100 |
| commit | 22f9d7bafc60f56259e74df98e544b5820cfca5b (patch) | |
| tree | fdc4886d035d04623666cb3132f3054bda77e889 /wrappers/python/eduvpncommon/__init__.py | |
| parent | eb5a1f2e9d47530c1896f49a2c4e7ffc82bcce4f (diff) | |
Save a local copy of the disco list
Diffstat (limited to 'wrappers/python/eduvpncommon/__init__.py')
| -rw-r--r-- | wrappers/python/eduvpncommon/__init__.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/wrappers/python/eduvpncommon/__init__.py b/wrappers/python/eduvpncommon/__init__.py index b79c980..ff329a0 100644 --- a/wrappers/python/eduvpncommon/__init__.py +++ b/wrappers/python/eduvpncommon/__init__.py @@ -19,10 +19,30 @@ _libfile = f"{_lib_prefixes[_os]}{_libname}{_lib_suffixes[_os]}" # Library should have been copied to the lib/ folder lib = cdll.LoadLibrary(str(pathlib.Path(__file__).parent / "lib" / _libfile)) +class DataError(Structure): + _fields_ = [('data', c_void_p), + ('error', c_void_p)] + VPNStateChange = CFUNCTYPE(None, c_char_p, c_char_p, c_char_p) # Exposed functions 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 # We have to use c_void_p instead of c_char_p to free it properly # See https://stackoverflow.com/questions/13445568/python-ctypes-how-to-free-memory-getting-invalid-pointer-error lib.FreeString.argtypes, lib.FreeString.restype = [c_void_p], None + +def GetPtrString(ptr): + if ptr: + string = cast(ptr, c_char_p).value + lib.FreeString(ptr) + if string: + return string.decode() + return "" + + +def GetDataError(data_error): + data = GetPtrString(data_error.data) + error = GetPtrString(data_error.error) + return data, error |
