diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-09-08 02:23:18 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-09-08 19:58:25 +0200 |
commit | e591c3147e3c504611ff612e8918018125ffa2eb (patch) | |
tree | d4004f33ddc2c7f9f70d95d0244b93ac27b9eb76 /gui | |
parent | c2871f4aece61b939e0e6c8d7a94677fb055620a (diff) |
[bug] pass json as bytes to go side
Diffstat (limited to 'gui')
-rw-r--r-- | gui/backend.go | 8 | ||||
-rw-r--r-- | gui/handlers.cpp | 4 | ||||
-rw-r--r-- | gui/main.cpp | 8 | ||||
-rw-r--r-- | gui/providers/providers.json | 24 |
4 files changed, 36 insertions, 8 deletions
diff --git a/gui/backend.go b/gui/backend.go index 5fa6134..a1dafe8 100644 --- a/gui/backend.go +++ b/gui/backend.go @@ -7,6 +7,7 @@ package main import ( "C" + "log" "unsafe" "0xacab.org/leap/bitmask-vpn/pkg/backend" @@ -53,8 +54,11 @@ func SubscribeToEvent(event string, f unsafe.Pointer) { } //export InitializeBitmaskContext -func InitializeBitmaskContext() { - opts := &backend.InitOpts{} +func InitializeBitmaskContext(provider string, jsonPtr unsafe.Pointer, jsonLen C.int) { + log.Println("DEBUG: provider=", provider) + json := C.GoBytes(jsonPtr, jsonLen) + log.Println("DEBUG: json=", string(json)) + opts := backend.InitOptsFromJSON(provider, string(json)) backend.InitializeBitmaskContext(opts) } diff --git a/gui/handlers.cpp b/gui/handlers.cpp index 71e5d38..4910aa2 100644 --- a/gui/handlers.cpp +++ b/gui/handlers.cpp @@ -8,7 +8,9 @@ GoString toGoStr(QString s) { - char *c = s.toLocal8Bit().data(); + // TODO verify that it's more correct + // char *c = s.toLocal8Bit().data(); + const char *c = s.toUtf8().constData(); return (GoString){c, (long int)strlen(c)}; } diff --git a/gui/main.cpp b/gui/main.cpp index 8c7de4f..4ba9dd6 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -145,8 +145,14 @@ int main(int argc, char **argv) { GoString statusChangedEvt = {stCh, (long int)strlen(stCh)}; SubscribeToEvent(statusChangedEvt, (void *)onStatusChanged); + QJsonValue defaultProvider = providers->json().object().value("default"); + /* we send json as bytes because it breaks as a simple string */ + QString QProvidersJSON(providers->json().toJson(QJsonDocument::Compact)); + /* let the Go side initialize its internal state */ - InitializeBitmaskContext(); + InitializeBitmaskContext( + toGoStr(defaultProvider.toString()), + (char*)QProvidersJSON.toUtf8().data(), strlen(QProvidersJSON.toUtf8().data())); /* if requested, enable web api for controlling the VPN */ if (webAPI) { diff --git a/gui/providers/providers.json b/gui/providers/providers.json index 7ba0ef9..f0132f5 100644 --- a/gui/providers/providers.json +++ b/gui/providers/providers.json @@ -1,4 +1,20 @@ -[ - {"name": "provider1", "url": "https://example.com"}, - {"name": "provider2", "url": "https://foobar.com"} -] +{ + "default": "demolib", + "providers": [ + { + "name": "demolib", + "applicationName": "DemoLib", + "binaryName": "demo-lib", + "auth": "sip", + "providerURL": "vpnlib.bitmask.net", + "tosURL": "https://libraryvpn.org/", + "helpURL": "https://libraryvpn.org/", + "askForDonations": "false", + "donateURL": "", + "apiURL": "https://api.vpnlib.bitmask.net:4430/", + "geolocationAPI": "https://getmyip.vpnlib.bitmask.net/json", + "caCertString": "-----BEGIN CERTIFICATE-----\nMIIBQzCB6aADAgECAgEBMAoGCCqGSM49BAMCMBcxFTATBgNVBAMTDExFQVAgUm9v\ndCBDQTAeFw0yMDA4MDYxOTA3NDRaFw0yNTA4MDYxOTEyNDRaMBcxFTATBgNVBAMT\nDExFQVAgUm9vdCBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABIG5POr4cAdK\nkTavKpSJr8nW1V7HLpr27qKaShpk1TUy5ipaAlusmavGLxKsPE+i3AMlvf/f6ch3\n1MjAtIf5rYujJjAkMA4GA1UdDwEB/wQEAwICpDASBgNVHRMBAf8ECDAGAQH/AgEB\nMAoGCCqGSM49BAMCA0kAMEYCIQDXj280LNZbSbi0Y2WvtQrJBUw4wdm8qAeOeuH7\n6XiLEwIhAPBRsmst/ujcChsG2t6LpG+p8s4rfIfh8YLo/4qrcc5p\n-----END CERTIFICATE-----", + "timeStamp": "2020-09-08 01:01:08" + } + ] +}
\ No newline at end of file |