diff options
Diffstat (limited to 'wrappers/python/src/discovery.py')
| -rw-r--r-- | wrappers/python/src/discovery.py | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/wrappers/python/src/discovery.py b/wrappers/python/src/discovery.py index 80c08cf..a1b87ea 100644 --- a/wrappers/python/src/discovery.py +++ b/wrappers/python/src/discovery.py @@ -1,4 +1,4 @@ -from . import lib, cDiscoveryOrganizations +from . import lib, cDiscoveryOrganizations, cDiscoveryServers, get_ptr_list_strings from ctypes import cast, POINTER @@ -9,6 +9,9 @@ class DiscoOrganization: self.secure_internet_home = secure_internet_home self.keyword_list = keyword_list + def __str__(self): + return self.display_name + class DiscoOrganizations: def __init__(self, version, organizations): @@ -16,6 +19,37 @@ class DiscoOrganizations: self.organizations = organizations +class DiscoServer: + def __init__( + self, + authentication_url_template, + base_url, + country_code, + display_name, + keyword_list, + public_keys, + server_type, + support_contacts, + ): + self.authentication_url_template = authentication_url_template + self.base_url = base_url + self.country_code = country_code + self.display_name = display_name + self.keyword_list = keyword_list + self.public_keys = public_keys + self.server_type = server_type + self.support_contacts = support_contacts + + def __str__(self): + return self.display_name + + +class DiscoServers: + def __init__(self, version, servers): + self.version = version + self.servers = servers + + def get_disco_organization(ptr): if not ptr: return None @@ -28,6 +62,55 @@ def get_disco_organization(ptr): return DiscoOrganization(display_name, org_id, secure_internet_home, keyword_list) +def get_disco_server(ptr): + if not ptr: + return None + + current_server = ptr.contents + authentication_url_template = current_server.authentication_url_template.decode( + "utf-8" + ) + base_url = current_server.base_url.decode("utf-8") + country_code = current_server.country_code.decode("utf-8") + display_name = current_server.display_name.decode("utf-8") + keyword_list = current_server.keyword_list.decode("utf-8") + public_keys = get_ptr_list_strings( + current_server.public_key_list, current_server.total_public_keys + ) + server_type = current_server.server_type.decode("utf-8") + support_contacts = get_ptr_list_strings( + current_server.support_contact, current_server.total_support_contact + ) + return DiscoServer( + authentication_url_template, + base_url, + country_code, + display_name, + keyword_list, + public_keys, + server_type, + support_contacts, + ) + + +def get_disco_servers(ptr): + if ptr: + svrs = cast(ptr, POINTER(cDiscoveryServers)).contents + + servers = [] + + if svrs.servers: + for i in range(svrs.total_servers): + current = get_disco_server(svrs.servers[i]) + + if current is None: + continue + servers.append(current) + lib.FreeDiscoServers(ptr) + return DiscoServers(svrs.version, servers) + return None + + def get_disco_organizations(ptr): if ptr: orgs = cast(ptr, POINTER(cDiscoveryOrganizations)).contents |
