summaryrefslogtreecommitdiff
path: root/wrappers
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-02-14 11:41:12 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 12:26:11 +0200
commitd306d7b27ee1df60bf32f03b6160856e78d1b02c (patch)
tree17ead8a0b05fe02817c5be954782fdb53c5fb7ac /wrappers
parentabe952080b01be4524fd03462236b6a3e63589f8 (diff)
Expose list retrieval by returning a JSON string
Signed-off-by: jwijenbergh <jeroenwijenbergh@protonmail.com>
Diffstat (limited to 'wrappers')
-rw-r--r--wrappers/python/eduvpncommon/__init__.py3
-rw-r--r--wrappers/python/eduvpncommon/discovery.py23
2 files changed, 24 insertions, 2 deletions
diff --git a/wrappers/python/eduvpncommon/__init__.py b/wrappers/python/eduvpncommon/__init__.py
index e9d0284..b14b2af 100644
--- a/wrappers/python/eduvpncommon/__init__.py
+++ b/wrappers/python/eduvpncommon/__init__.py
@@ -28,3 +28,6 @@ class GoSlice(Structure):
return GoSlice((c_char * len(bs))(*bs), len(bs), len(bs))
+class DataError(Structure):
+ _fields_ = [('data', c_void_p),
+ ('error', c_int64)]
diff --git a/wrappers/python/eduvpncommon/discovery.py b/wrappers/python/eduvpncommon/discovery.py
index 3ae967b..d7fa73b 100644
--- a/wrappers/python/eduvpncommon/discovery.py
+++ b/wrappers/python/eduvpncommon/discovery.py
@@ -1,11 +1,30 @@
-from . import lib, GoSlice
+from . import lib, GoSlice, DataError
from ctypes import *
from enum import Enum
-#lib.GetOrganizationsList.argtypes, lib.GetOrganizationsList.restype = [], c_uint64
+# 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.GetOrganizationsList.argtypes, lib.GetOrganizationsList.restype = [], DataError
+lib.FreeString.argtypes, lib.FreeString.restype = [c_void_p], None
+
lib.Verify.argtypes, lib.Verify.restype = [GoSlice, GoSlice, GoSlice, c_uint64], c_int64
lib.InsecureTestingSetExtraKey.argtypes, lib.InsecureTestingSetExtraKey.restype = [GoSlice], None
+class RequestErrorCode(Enum):
+ ErrRequestFileError = 1 # The request for the file has failed.
+ ErrVerifySigError = 2 # The signature failed to verify.
+ Unknown = -1 # Other unknown error.
+
+def getOrganizationsList():
+ dataError = lib.GetOrganizationsList()
+ ptr = dataError.data
+ err = dataError.error
+ body = None
+ if not err:
+ body = cast(ptr, c_char_p).value
+ lib.FreeString(ptr)
+ return body
+
class VerifyErrorCode(Enum):
ErrUnknownExpectedFileName = 1 # Unknown expected file name specified. The signature has not been verified.