summaryrefslogtreecommitdiff
path: root/wrappers/python/src/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'wrappers/python/src/__init__.py')
-rw-r--r--wrappers/python/src/__init__.py73
1 files changed, 64 insertions, 9 deletions
diff --git a/wrappers/python/src/__init__.py b/wrappers/python/src/__init__.py
index ece4b46..ca07143 100644
--- a/wrappers/python/src/__init__.py
+++ b/wrappers/python/src/__init__.py
@@ -5,6 +5,7 @@ import pathlib
import platform
from typing import Tuple, Optional
import json
+from typing import List
_lib_prefixes = defaultdict(
lambda: "lib",
@@ -40,11 +41,10 @@ class ErrorLevel(Enum):
ERR_OTHER = 0
ERR_INFO = 1
+
class cServerLocations(Structure):
- _fields_ = [
- ("locations", POINTER(c_char_p)),
- ("total_locations", c_size_t)
- ]
+ _fields_ = [("locations", POINTER(c_char_p)), ("total_locations", c_size_t)]
+
class cDiscoveryOrganization(Structure):
_fields_ = [
@@ -54,6 +54,7 @@ class cDiscoveryOrganization(Structure):
("keyword_list", c_char_p),
]
+
class cDiscoveryOrganizations(Structure):
_fields_ = [
("version", c_ulonglong),
@@ -61,6 +62,30 @@ class cDiscoveryOrganizations(Structure):
("total_organizations", c_size_t),
]
+
+class cDiscoveryServer(Structure):
+ _fields_ = [
+ ("authentication_url_template", c_char_p),
+ ("base_url", c_char_p),
+ ("country_code", c_char_p),
+ ("display_name", c_char_p),
+ ("keyword_list", c_char_p),
+ ("public_key_list", POINTER(c_char_p)),
+ ("total_public_keys", c_size_t),
+ ("server_type", c_char_p),
+ ("support_contact", POINTER(c_char_p)),
+ ("total_support_contact", c_size_t),
+ ]
+
+
+class cDiscoveryServers(Structure):
+ _fields_ = [
+ ("version", c_ulonglong),
+ ("servers", POINTER(POINTER(cDiscoveryServer))),
+ ("total_servers", c_size_t),
+ ]
+
+
class cServerProfile(Structure):
_fields_ = [
("identifier", c_char_p),
@@ -68,6 +93,7 @@ class cServerProfile(Structure):
("default_gateway", c_int),
]
+
class cServerProfiles(Structure):
_fields_ = [
("current", c_int),
@@ -75,10 +101,12 @@ class cServerProfiles(Structure):
("total_profiles", c_size_t),
]
+
class cServer(Structure):
_fields_ = [
("identifier", c_char_p),
("display_name", c_char_p),
+ ("server_type", c_char_p),
("country_code", c_char_p),
("support_contact", POINTER(c_char_p)),
("total_support_contact", c_size_t),
@@ -86,6 +114,7 @@ class cServer(Structure):
("expire_time", c_ulonglong),
]
+
class cServers(Structure):
_fields_ = [
("custom_servers", POINTER(POINTER(cServer))),
@@ -95,6 +124,7 @@ class cServers(Structure):
("secure_internet", POINTER(cServer)),
]
+
class DataError(Structure):
_fields_ = [("data", c_void_p), ("error", c_void_p)]
@@ -104,9 +134,17 @@ VPNStateChange = CFUNCTYPE(None, c_char_p, c_int, c_int, c_void_p)
# Exposed functions
# 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.RemoveSecureInternet.argtypes, lib.RemoveSecureInternet.restype = [c_char_p], c_void_p
-lib.RemoveInstituteAccess.argtypes, lib.RemoveInstituteAccess.restype = [c_char_p, c_char_p], c_void_p
-lib.RemoveCustomServer.argtypes, lib.RemoveCustomServer.restype = [c_char_p, c_char_p], c_void_p
+lib.RemoveSecureInternet.argtypes, lib.RemoveSecureInternet.restype = [
+ c_char_p
+], c_void_p
+lib.RemoveInstituteAccess.argtypes, lib.RemoveInstituteAccess.restype = [
+ c_char_p,
+ c_char_p,
+], c_void_p
+lib.RemoveCustomServer.argtypes, lib.RemoveCustomServer.restype = [
+ c_char_p,
+ c_char_p,
+], c_void_p
lib.GetConfigSecureInternet.argtypes, lib.GetConfigSecureInternet.restype = [
c_char_p,
c_char_p,
@@ -132,7 +170,7 @@ lib.Register.argtypes, lib.Register.restype = [
lib.GetDiscoOrganizations.argtypes, lib.GetDiscoOrganizations.restype = [
c_char_p
], c_void_p
-lib.GetDiscoServers.argtypes, lib.GetDiscoServers.restype = [c_char_p], DataError
+lib.GetDiscoServers.argtypes, lib.GetDiscoServers.restype = [c_char_p], c_void_p
lib.GoBack.argtypes, lib.GoBack.restype = [c_char_p], None
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
@@ -150,9 +188,14 @@ lib.SetDisconnected.argtypes, lib.SetDisconnected.restype = [c_char_p, c_int], c
lib.SetSearchServer.argtypes, lib.SetSearchServer.restype = [c_char_p], c_void_p
lib.ShouldRenewButton.argtypes, lib.ShouldRenewButton.restype = [], int
lib.RenewSession.argtypes, lib.RenewSession.restype = [c_char_p], c_void_p
+lib.FreeProfiles.argtypes, lib.FreeProfiles.restype = [c_void_p], None
lib.FreeSecureLocations.argtypes, lib.FreeSecureLocations.restype = [c_void_p], None
lib.FreeString.argtypes, lib.FreeString.restype = [c_void_p], None
-lib.FreeDiscoOrganizations.argtypes, lib.FreeDiscoOrganizations.restype = [c_void_p], None
+lib.FreeDiscoOrganizations.argtypes, lib.FreeDiscoOrganizations.restype = [
+ c_void_p
+], None
+lib.FreeDiscoServers.argtypes, lib.FreeDiscoServers.restype = [c_void_p], None
+lib.FreeServer.argtypes, lib.FreeServer.restype = [c_void_p], None
lib.FreeServers.argtypes, lib.FreeServers.restype = [c_void_p], None
lib.InFSMState.argtypes, lib.InFSMState.restype = [c_void_p, c_int], int
lib.GetSavedServers.argtypes, lib.GetSavedServers.restype = [c_char_p], c_void_p
@@ -186,6 +229,17 @@ def get_ptr_string(ptr: c_void_p) -> str:
return ""
+def get_ptr_list_strings(
+ strings: POINTER(c_char_p), total_strings: c_size_t
+) -> List[str]:
+ if strings:
+ strings_list = []
+ for i in range(total_strings):
+ strings_list.append(strings[i].decode("utf-8"))
+ return strings_list
+ return []
+
+
def get_ptr_error(ptr: c_void_p) -> Optional[WrappedError]:
error_string = get_ptr_string(ptr)
@@ -224,6 +278,7 @@ def get_data_error(data_error: DataError) -> Tuple[str, str]:
def get_bool(boolInt: c_int) -> bool:
return boolInt == 1
+
decode_map = {
c_int: get_bool,
c_void_p: get_error,