summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-10-18 18:29:10 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-10-18 18:29:10 +0200
commit6aced56a28fa52e4796aa1aa139e4323b4154aca (patch)
tree56bf7af557317b553c6c30db2ec8d20090b6336d
parentcc057e07579f290eb1db8bdf348cb2e5ba760ab3 (diff)
Client: Move to its own package
-rw-r--r--client/client.go (renamed from client.go)2
-rw-r--r--client/client_test.go (renamed from client_test.go)2
-rw-r--r--client/fsm.go (renamed from fsm.go)2
-rw-r--r--cmd/cli/main.go24
-rw-r--r--docs/src/api/go/README.md6
-rw-r--r--exports/disco.go10
-rw-r--r--exports/exports.go41
-rw-r--r--exports/servers.go12
8 files changed, 49 insertions, 50 deletions
diff --git a/client.go b/client/client.go
index 39ff109..4cf95cd 100644
--- a/client.go
+++ b/client/client.go
@@ -1,4 +1,4 @@
-package eduvpn
+package client
import (
"errors"
diff --git a/client_test.go b/client/client_test.go
index 583553b..68a6be0 100644
--- a/client_test.go
+++ b/client/client_test.go
@@ -1,4 +1,4 @@
-package eduvpn
+package client
import (
"errors"
diff --git a/fsm.go b/client/fsm.go
index e476c83..f8d2a1c 100644
--- a/fsm.go
+++ b/client/fsm.go
@@ -1,4 +1,4 @@
-package eduvpn
+package client
import (
"errors"
diff --git a/cmd/cli/main.go b/cmd/cli/main.go
index 68ebe8d..497e354 100644
--- a/cmd/cli/main.go
+++ b/cmd/cli/main.go
@@ -6,9 +6,9 @@ import (
"os/exec"
"strings"
- eduvpn "github.com/eduvpn/eduvpn-common"
- "github.com/eduvpn/eduvpn-common/internal/server"
+ "github.com/eduvpn/eduvpn-common/client"
"github.com/eduvpn/eduvpn-common/types"
+ "github.com/eduvpn/eduvpn-common/internal/server"
)
type ServerTypes int8
@@ -35,7 +35,7 @@ func openBrowser(url interface{}) {
}
// Ask for a profile in the command line
-func sendProfile(state *eduvpn.Client, data interface{}) {
+func sendProfile(state *client.Client, data interface{}) {
fmt.Printf("Multiple VPN profiles found. Please select a profile by entering e.g. 1")
serverProfiles, ok := data.(*server.ServerProfileInfo)
@@ -77,22 +77,22 @@ func sendProfile(state *eduvpn.Client, data interface{}) {
// If we ask for a profile, we send the profile using command line input
// Note that this has an additional argument, the vpn state which was wrapped into this callback function below
func stateCallback(
- state *eduvpn.Client,
- oldState eduvpn.FSMStateID,
- newState eduvpn.FSMStateID,
+ state *client.Client,
+ oldState client.FSMStateID,
+ newState client.FSMStateID,
data interface{},
) {
- if newState == eduvpn.STATE_OAUTH_STARTED {
+ if newState == client.STATE_OAUTH_STARTED {
openBrowser(data)
}
- if newState == eduvpn.STATE_ASK_PROFILE {
+ if newState == client.STATE_ASK_PROFILE {
sendProfile(state, data)
}
}
// Get a config for Institute Access or Secure Internet Server
-func getConfig(state *eduvpn.Client, url string, serverType ServerTypes) (string, string, error) {
+func getConfig(state *client.Client, url string, serverType ServerTypes) (string, string, error) {
if !strings.HasPrefix(url, "http") {
url = "https://" + url
}
@@ -119,13 +119,13 @@ func getConfig(state *eduvpn.Client, url string, serverType ServerTypes) (string
// Get a config for a single server, Institute Access or Secure Internet
func printConfig(url string, serverType ServerTypes) {
- state := &eduvpn.Client{}
+ state := &client.Client{}
registerErr := state.Register(
- "org.eduvpn.app.linux",
+ "org.client.app.linux",
"configs",
"en",
- func(old eduvpn.FSMStateID, new eduvpn.FSMStateID, data interface{}) {
+ func(old client.FSMStateID, new client.FSMStateID, data interface{}) {
stateCallback(state, old, new, data)
},
true,
diff --git a/docs/src/api/go/README.md b/docs/src/api/go/README.md
index 1202cf2..2b71f99 100644
--- a/docs/src/api/go/README.md
+++ b/docs/src/api/go/README.md
@@ -2,11 +2,11 @@
The API that has no additional wrapper code is the Go API. To begin to use the Go library in a Go client you first need to import it:
```go
-import "github.com/eduvpn/eduvpn-common"
+import "github.com/eduvpn/eduvpn-common/client"
```
-This brings the library into scope using the eduvpn-common prefix.
+This brings the client library into scope using the client prefix.
-The documentation to then use this API is online at [pkg.go.dev](https://pkg.go.dev/github.com/eduvpn/eduvpn-common).
+The documentation to then use this API and the rest is online at [pkg.go.dev](https://pkg.go.dev/github.com/eduvpn/eduvpn-common).
[We also provide an example](./example.md).
diff --git a/exports/disco.go b/exports/disco.go
index 3058334..6db0e86 100644
--- a/exports/disco.go
+++ b/exports/disco.go
@@ -42,12 +42,12 @@ import "C"
import (
"unsafe"
- eduvpn "github.com/eduvpn/eduvpn-common"
+ "github.com/eduvpn/eduvpn-common/client"
"github.com/eduvpn/eduvpn-common/types"
)
func getCPtrDiscoOrganization(
- state *eduvpn.Client,
+ state *client.Client,
organization *types.DiscoveryOrganization,
) *C.discoveryOrganization {
returnedStruct := (*C.discoveryOrganization)(
@@ -61,7 +61,7 @@ func getCPtrDiscoOrganization(
}
func getCPtrDiscoOrganizations(
- state *eduvpn.Client,
+ state *client.Client,
organizations *types.DiscoveryOrganizations,
) (C.size_t, **C.discoveryOrganization) {
totalOrganizations := C.size_t(len(organizations.List))
@@ -82,7 +82,7 @@ func getCPtrDiscoOrganizations(
}
func getCPtrDiscoServer(
- state *eduvpn.Client,
+ state *client.Client,
server *types.DiscoveryServer,
) *C.discoveryServer {
returnedStruct := (*C.discoveryServer)(
@@ -104,7 +104,7 @@ func getCPtrDiscoServer(
}
func getCPtrDiscoServers(
- state *eduvpn.Client,
+ state *client.Client,
servers *types.DiscoveryServers,
) (C.size_t, **C.discoveryServer) {
totalServers := C.size_t(len(servers.List))
diff --git a/exports/exports.go b/exports/exports.go
index 63ef830..6407da4 100644
--- a/exports/exports.go
+++ b/exports/exports.go
@@ -17,38 +17,37 @@ import (
"fmt"
"unsafe"
+ "github.com/eduvpn/eduvpn-common/client"
"github.com/eduvpn/eduvpn-common/types"
-
- eduvpn "github.com/eduvpn/eduvpn-common"
)
var P_StateCallbacks map[string]C.PythonCB
-var VPNStates map[string]*eduvpn.Client
+var VPNStates map[string]*client.Client
func GetStateData(
- state *eduvpn.Client,
- stateID eduvpn.FSMStateID,
+ state *client.Client,
+ stateID client.FSMStateID,
data interface{},
) unsafe.Pointer {
switch stateID {
- case eduvpn.STATE_NO_SERVER:
+ case client.STATE_NO_SERVER:
return (unsafe.Pointer)(getTransitionDataServers(state, data))
- case eduvpn.STATE_OAUTH_STARTED:
+ case client.STATE_OAUTH_STARTED:
if converted, ok := data.(string); ok {
return (unsafe.Pointer)(C.CString(converted))
}
- case eduvpn.STATE_ASK_LOCATION:
+ case client.STATE_ASK_LOCATION:
return (unsafe.Pointer)(getTransitionSecureLocations(data))
- case eduvpn.STATE_ASK_PROFILE:
+ case client.STATE_ASK_PROFILE:
return (unsafe.Pointer)(getTransitionProfiles(data))
- case eduvpn.STATE_DISCONNECTED:
+ case client.STATE_DISCONNECTED:
return (unsafe.Pointer)(getTransitionServer(state, data))
- case eduvpn.STATE_DISCONNECTING:
+ case client.STATE_DISCONNECTING:
return (unsafe.Pointer)(getTransitionServer(state, data))
- case eduvpn.STATE_CONNECTING:
+ case client.STATE_CONNECTING:
return (unsafe.Pointer)(getTransitionServer(state, data))
- case eduvpn.STATE_CONNECTED:
+ case client.STATE_CONNECTED:
return (unsafe.Pointer)(getTransitionServer(state, data))
default:
return nil
@@ -57,10 +56,10 @@ func GetStateData(
}
func StateCallback(
- state *eduvpn.Client,
+ state *client.Client,
name string,
- old_state eduvpn.FSMStateID,
- new_state eduvpn.FSMStateID,
+ old_state client.FSMStateID,
+ new_state client.FSMStateID,
data interface{},
) {
P_StateCallback, exists := P_StateCallbacks[name]
@@ -76,7 +75,7 @@ func StateCallback(
// data_c gets freed by the wrapper
}
-func GetVPNState(name string) (*eduvpn.Client, error) {
+func GetVPNState(name string) (*client.Client, error) {
state, exists := VPNStates[name]
if !exists || state == nil {
@@ -97,10 +96,10 @@ func Register(
nameStr := C.GoString(name)
state, stateErr := GetVPNState(nameStr)
if stateErr != nil {
- state = &eduvpn.Client{}
+ state = &client.Client{}
}
if VPNStates == nil {
- VPNStates = make(map[string]*eduvpn.Client)
+ VPNStates = make(map[string]*client.Client)
}
if P_StateCallbacks == nil {
P_StateCallbacks = make(map[string]C.PythonCB)
@@ -111,7 +110,7 @@ func Register(
nameStr,
C.GoString(config_directory),
C.GoString(language),
- func(old eduvpn.FSMStateID, new eduvpn.FSMStateID, data interface{}) {
+ func(old client.FSMStateID, new client.FSMStateID, data interface{}) {
StateCallback(state, nameStr, old, new, data)
},
debug != 0,
@@ -401,7 +400,7 @@ func InFSMState(name *C.char, checkState C.int) C.int {
if stateErr != nil {
return C.int(0)
}
- inStateBool := state.InFSMState(eduvpn.FSMStateID(checkState))
+ inStateBool := state.InFSMState(client.FSMStateID(checkState))
if inStateBool {
return C.int(1)
}
diff --git a/exports/servers.go b/exports/servers.go
index 175c835..57e1be1 100644
--- a/exports/servers.go
+++ b/exports/servers.go
@@ -52,7 +52,7 @@ import "C"
import (
"unsafe"
- eduvpn "github.com/eduvpn/eduvpn-common"
+ "github.com/eduvpn/eduvpn-common/client"
"github.com/eduvpn/eduvpn-common/internal/server"
)
@@ -162,7 +162,7 @@ func freeCListStrings(allStrings **C.char, totalStrings C.size_t) {
// Function for getting the server,
// It gets the main state as a pointer as we need to convert some string maps to localized strings
// It gets the base information for a server as well
-func getCPtrServer(state *eduvpn.Client, base *eduvpn.ServerBase) *C.server {
+func getCPtrServer(state *client.Client, base *client.ServerBase) *C.server {
// Allocation using malloc and the size of the struct
server := (*C.server)(C.malloc(C.size_t(unsafe.Sizeof(C.server{}))))
// String allocation and translate the display name
@@ -212,7 +212,7 @@ func FreeServer(info *C.server) {
// Get the C ptr to the servers, returns the length in size_t and the double pointer to the struct
func getCPtrServers(
- state *eduvpn.Client,
+ state *client.Client,
serverMap map[string]*server.InstituteAccessServer,
) (C.size_t, **C.server) {
totalServers := C.size_t(len(serverMap))
@@ -263,7 +263,7 @@ func FreeServers(cServers *C.servers) {
// Return the servers as a C struct pointer
// It takes the state as a pointer as we need to translate some strings
// It also takes the servers as a pointer that belongs to the main state or gathered from the callback
-func getSavedServersWithOptions(state *eduvpn.Client, servers *server.Servers) *C.servers {
+func getSavedServersWithOptions(state *client.Client, servers *server.Servers) *C.servers {
// Allocate the struct that we will return
// With the size of the c struct
returnedStruct := (*C.servers)(C.malloc(C.size_t(unsafe.Sizeof(C.servers{}))))
@@ -306,7 +306,7 @@ func GetSavedServers(name *C.char) (*C.servers, *C.error) {
// This function takes the state as input which is the main state
// It also takes the data as an interface and if it has the servers type gets the data as a c struct otherwise nil
-func getTransitionDataServers(state *eduvpn.Client, data interface{}) *C.servers {
+func getTransitionDataServers(state *client.Client, data interface{}) *C.servers {
if converted, ok := data.(server.Servers); ok {
return getSavedServersWithOptions(state, &converted)
}
@@ -335,7 +335,7 @@ func getTransitionProfiles(data interface{}) *C.serverProfiles {
return nil
}
-func getTransitionServer(state *eduvpn.Client, data interface{}) *C.server {
+func getTransitionServer(state *client.Client, data interface{}) *C.server {
if server, ok := data.(server.Server); ok {
base, baseErr := server.GetBase()
if baseErr != nil {