diff options
| -rw-r--r-- | exports/servers.go | 9 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/server.py | 29 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/types.py | 1 |
3 files changed, 35 insertions, 4 deletions
diff --git a/exports/servers.go b/exports/servers.go index 381c0dd..b785201 100644 --- a/exports/servers.go +++ b/exports/servers.go @@ -34,6 +34,7 @@ typedef struct server { const char* country_code; const char** support_contact; size_t total_support_contact; + serverLocations* locations; serverProfiles* profiles; unsigned long long int expire_time; } server; @@ -168,9 +169,12 @@ func getCPtrServer(state *client.Client, base *client.ServerBase) *C.server { // String allocation and translate the display name identifier := base.URL countryCode := "" + // A secure internet server has multiple locations + locations := []string{} if base.Type == "secure_internet" { identifier = state.Servers.SecureInternetHomeServer.HomeOrganizationID countryCode = state.Servers.SecureInternetHomeServer.CurrentLocation + locations = state.Discovery.GetSecureLocationList() } server.identifier = C.CString(identifier) @@ -181,6 +185,10 @@ func getCPtrServer(state *client.Client, base *client.ServerBase) *C.server { server.total_support_contact, server.support_contact = getCPtrListStrings( base.SupportContact, ) + locationsStruct := (*C.serverLocations)(C.malloc(C.size_t(unsafe.Sizeof(C.servers{})))) + locationsStruct.total_locations, locationsStruct.locations = getCPtrListStrings(locations) + server.locations = locationsStruct + profiles := base.GetValidProfiles(state.SupportsWireguard) server.profiles = getCPtrProfiles(&profiles) // No endtime is given if we get servers when it has been partially initialised @@ -205,6 +213,7 @@ func FreeServer(info *C.server) { // Free arrays freeCListStrings(info.support_contact, info.total_support_contact) + FreeSecureLocations(info.locations) FreeProfiles(info.profiles) // Free the struct itself diff --git a/wrappers/python/eduvpn_common/server.py b/wrappers/python/eduvpn_common/server.py index 3a5ff69..8509ff9 100644 --- a/wrappers/python/eduvpn_common/server.py +++ b/wrappers/python/eduvpn_common/server.py @@ -112,6 +112,7 @@ class SecureInternetServer(Server): :param: org_id: str: The organization ID of the Secure Internet Server as returned by Discovery :param: display_name: str: The display name of the server :param: support_contact: List[str]: The list of support contacts of the server + :param: locations: List[str]: The list of secure internet locations :param: profiles: Profiles: The list of profiles that the server has :param: expire_time: int: The expiry time in a Unix timestamp :param: country_code: str: The country code of the server @@ -121,6 +122,7 @@ class SecureInternetServer(Server): org_id: str, display_name: str, support_contact: List[str], + locations: List[str], profiles: Profiles, expire_time: int, country_code: str, @@ -128,6 +130,7 @@ class SecureInternetServer(Server): super().__init__(org_id, display_name, profiles, expire_time) self.org_id = org_id self.support_contact = support_contact + self.locations = locations self.country_code = country_code @property @@ -155,6 +158,25 @@ def get_type_for_str(type_str: str) -> Type[Server]: return InstituteServer +def get_locations_from_ptr(ptr) -> List[str]: + """Get the locations from the Go shared library and convert it to a Python usable structure + + :param ptr: The pointer to the List[str] locations as returned by the Go library + + :meta private: + + :return: Locations if there are any + :rtype: List[str] + """ + if not ptr: + return [] + locations = cast(ptr, POINTER(cServerLocations)).contents + location_list = [] + for i in range(locations.total_locations): + location_list.append(locations.locations[i].decode("utf-8")) + return location_list + + def get_profiles(ptr) -> Optional[Profiles]: """Get the profiles from the Go shared library and convert it to a Python usable structure @@ -211,6 +233,7 @@ def get_server(ptr, _type: Optional[str] = None) -> Optional[Server]: support_contact = [] for i in range(current_server.total_support_contact): support_contact.append(current_server.support_contact[i].decode("utf-8")) + locations = get_locations_from_ptr(current_server.locations) profiles = get_profiles(current_server.profiles) if profiles is None: profiles = Profiles([], 0) @@ -219,6 +242,7 @@ def get_server(ptr, _type: Optional[str] = None) -> Optional[Server]: identifier, display_name, support_contact, + locations, profiles, current_server.expire_time, current_server.country_code.decode("utf-8"), @@ -319,10 +343,7 @@ def get_locations(lib: CDLL, ptr: c_void_p) -> Optional[List[str]]: :rtype: Optional[List[str]] """ if ptr: - locations = cast(ptr, POINTER(cServerLocations)).contents - location_list = [] - for i in range(locations.total_locations): - location_list.append(locations.locations[i].decode("utf-8")) + location_list = get_locations_from_ptr(ptr) lib.FreeSecureLocations(ptr) return location_list return None diff --git a/wrappers/python/eduvpn_common/types.py b/wrappers/python/eduvpn_common/types.py index 8ebae6a..a6eda43 100644 --- a/wrappers/python/eduvpn_common/types.py +++ b/wrappers/python/eduvpn_common/types.py @@ -128,6 +128,7 @@ class cServer(Structure): ("country_code", c_char_p), ("support_contact", POINTER(c_char_p)), ("total_support_contact", c_size_t), + ("locations", POINTER(cServerLocations)), ("profiles", POINTER(cServerProfiles)), ("expire_time", c_ulonglong), ] |
