diff options
Diffstat (limited to 'exports')
| -rw-r--r-- | exports/exports.go | 40 | ||||
| -rw-r--r-- | exports/server.h | 47 | ||||
| -rw-r--r-- | exports/servers.go | 44 |
3 files changed, 88 insertions, 43 deletions
diff --git a/exports/exports.go b/exports/exports.go index d9ec122..a11c0fa 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -3,6 +3,7 @@ package main /* #include <stdlib.h> #include "error.h" +#include "server.h" typedef long long int (*ReadRxBytes)(); typedef struct token { @@ -11,6 +12,8 @@ typedef struct token { unsigned long long int expired; } token; +typedef void (*UpdateToken)(const char* name, server* srv, token* tok); + typedef struct configData { const char* config; const char* config_type; @@ -23,6 +26,12 @@ static long long int get_read_rx_bytes(ReadRxBytes read) { return read(); } + +static void update_token(UpdateToken func, const char* name, server* srv, token* tok) +{ + func(name, srv, tok); +} + static int call_callback(PythonCB callback, const char *name, int oldstate, int newstate, void* data) { return callback(name, oldstate, newstate, data); @@ -34,6 +43,8 @@ import ( "time" "unsafe" + "github.com/eduvpn/eduvpn-common/internal/log" + "github.com/eduvpn/eduvpn-common/internal/server" "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/go-errors/errors" @@ -145,6 +156,28 @@ func Register( return getError(registerErr) } +//export SetTokenUpdater +func SetTokenUpdater(name *C.char, updater C.UpdateToken) *C.error { + nameStr := C.GoString(name) + state, stateErr := GetVPNState(nameStr) + if stateErr != nil { + return getError(stateErr) + } + state.SetTokenUpdater(func(srv server.Server, tok oauth.Token) { + b, err := srv.Base() + if err != nil { + log.Logger.Warningf("No server base found for token updating with error: %v", err) + return + } + cName := C.CString(nameStr) + cSrv := getCPtrServer(state, b) + cTok := cToken(tok) + C.update_token(updater, cName, cSrv, cTok) + FreeString(cName) + }) + return nil +} + //export Deregister func Deregister(name *C.char) *C.error { nameStr := C.GoString(name) @@ -284,6 +317,13 @@ func cConfig(config *client.ConfigData) *C.configData { return cConf } +//export FreeTokens +func FreeTokens(tokens *C.token) { + C.free(unsafe.Pointer(tokens.access)) + C.free(unsafe.Pointer(tokens.refresh)) + C.free(unsafe.Pointer(tokens)) +} + //export FreeConfig func FreeConfig(config *C.configData) { C.free(unsafe.Pointer(config.config)) diff --git a/exports/server.h b/exports/server.h new file mode 100644 index 0000000..4bc8a16 --- /dev/null +++ b/exports/server.h @@ -0,0 +1,47 @@ +#ifndef SERVER_H +#define SERVER_H + +// The struct for a single server profile +typedef struct serverProfile { + const char* id; + const char* display_name; + //const char* proto_list; + int default_gateway; +} serverProfile; + +// The struct for all server profiles +typedef struct serverProfiles { + int current; + serverProfile** profiles; + size_t total_profiles; +} serverProfiles; + +// The struct for server locations +typedef struct serverLocations { + const char** locations; + size_t total_locations; +} serverLocations; + +// The struct for a single server +typedef struct server { + const char* identifier; + const char* display_name; + const char* server_type; + const char* country_code; + const char** support_contact; + size_t total_support_contact; + serverLocations* locations; + serverProfiles* profiles; + unsigned long long int expire_time; +} server; + +// The struct for all servers +typedef struct servers { + server** custom_servers; + size_t total_custom; + server** institute_servers; + size_t total_institute; + server* secure_internet_server; +} servers; + +#endif /* GRANDPARENT_H */ diff --git a/exports/servers.go b/exports/servers.go index 662808c..73b8b6c 100644 --- a/exports/servers.go +++ b/exports/servers.go @@ -4,49 +4,7 @@ package main // for free and size_t #include <stdlib.h> #include "error.h" - -// The struct for a single server profile -typedef struct serverProfile { - const char* id; - const char* display_name; - //const char* proto_list; - int default_gateway; -} serverProfile; - -// The struct for all server profiles -typedef struct serverProfiles { - int current; - serverProfile** profiles; - size_t total_profiles; -} serverProfiles; - -// The struct for server locations -typedef struct serverLocations { - const char** locations; - size_t total_locations; -} serverLocations; - -// The struct for a single server -typedef struct server { - const char* identifier; - const char* display_name; - const char* server_type; - const char* country_code; - const char** support_contact; - size_t total_support_contact; - serverLocations* locations; - serverProfiles* profiles; - unsigned long long int expire_time; -} server; - -// The struct for all servers -typedef struct servers { - server** custom_servers; - size_t total_custom; - server** institute_servers; - size_t total_institute; - server* secure_internet_server; -} servers; +#include "server.h" */ import "C" |
