diff options
| -rw-r--r-- | exports/exports.go | 23 | ||||
| -rw-r--r-- | state.go | 11 | ||||
| -rw-r--r-- | wrappers/python/src/__init__.py | 2 | ||||
| -rw-r--r-- | wrappers/python/src/main.py | 34 |
4 files changed, 66 insertions, 4 deletions
diff --git a/exports/exports.go b/exports/exports.go index 79b3606..17a9a9b 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -151,6 +151,29 @@ func SetProfileID(name *C.char, data *C.char) *C.char { return C.CString(ErrorToString(profileErr)) } +//export GetIdentifier +func GetIdentifier(name *C.char) (*C.char, *C.char) { + nameStr := C.GoString(name) + state, stateErr := GetVPNState(nameStr) + if stateErr != nil { + return C.CString(""), C.CString(ErrorToString(stateErr)) + } + identifier := state.GetIdentifier() + return C.CString(identifier), C.CString("") +} + +//export SetIdentifier +func SetIdentifier(name *C.char, identifier *C.char) *C.char { + nameStr := C.GoString(name) + identifierStr := C.GoString(identifier) + state, stateErr := GetVPNState(nameStr) + if stateErr != nil { + return C.CString(ErrorToString(stateErr)) + } + state.SetIdentifier(identifierStr) + return C.CString("") +} + //export SetDisconnected func SetDisconnected(name *C.char) *C.char { nameStr := C.GoString(name) @@ -27,6 +27,9 @@ type VPNState struct { // Whether to enable debugging Debug bool `json:"-"` + + // Serialized connection identifier + Identifier string `json:"identifier"` } func (state *VPNState) Register(name string, directory string, stateCallback func(string, string, string), debug bool) error { @@ -194,6 +197,14 @@ func (state *VPNState) SetProfileID(profileID string) error { return nil } +func (state *VPNState) GetIdentifier() string { + return state.Identifier +} + +func (state *VPNState) SetIdentifier(identifier string) { + state.Identifier = identifier +} + func (state *VPNState) SetConnected() error { if !state.FSM.HasTransition(fsm.CONNECTED) { return fsm.WrongStateTransitionError{Got: state.FSM.Current, Want: fsm.CONNECTED}.CustomError() diff --git a/wrappers/python/src/__init__.py b/wrappers/python/src/__init__.py index c96a1b2..bc9b3df 100644 --- a/wrappers/python/src/__init__.py +++ b/wrappers/python/src/__init__.py @@ -61,6 +61,8 @@ lib.CancelOAuth.argtypes, lib.CancelOAuth.restype = [c_char_p], c_void_p lib.SetProfileID.argtypes, lib.SetProfileID.restype = [c_char_p, c_char_p], c_void_p lib.SetConnected.argtypes, lib.SetConnected.restype = [c_char_p], c_void_p lib.SetDisconnected.argtypes, lib.SetDisconnected.restype = [c_char_p], c_void_p +lib.GetIdentifier.argtypes, lib.GetIdentifier.restype = [c_char_p], DataError +lib.SetIdentifier.argtypes, lib.SetIdentifier.restype = [c_char_p, c_char_p], c_void_p lib.FreeString.argtypes, lib.FreeString.restype = [c_void_p], None diff --git a/wrappers/python/src/main.py b/wrappers/python/src/main.py index 47e2893..687f40f 100644 --- a/wrappers/python/src/main.py +++ b/wrappers/python/src/main.py @@ -105,6 +105,20 @@ def SetDisconnected(name: str) -> str: return err_string +def SetIdentifier(name: str, identifier: str) -> str: + name_bytes = name.encode("utf-8") + identifier_bytes = identifier.encode("utf-8") + ptr_err = lib.SetIdentifier(name_bytes, identifier_bytes) + err_string = GetPtrString(ptr_err) + return err_string + + +def GetIdentifier(name: str) -> Tuple[str, str]: + name_bytes = name.encode("utf-8") + identifier, identifier_err = GetDataError(lib.GetIdentifier(name_bytes)) + return identifier, identifier_err + + # This has to be global as otherwise the callback is not alive callback_function = None @@ -189,8 +203,12 @@ class EduVPN(object): if config_err: raise Exception(config_err) + def set_connected(self) -> None: + connect_err = SetConnected(self.name) return config, config_type + if connect_err: + raise Exception(connect_err) def set_disconnected(self) -> None: disconnect_err = SetDisconnected(self.name) @@ -198,11 +216,19 @@ class EduVPN(object): if disconnect_err: raise Exception(disconnect_err) - def set_connected(self) -> None: - connect_err = SetConnected(self.name) + def get_identifier(self) -> str: + identifier, identifier_err = GetIdentifier(self.name) - if connect_err: - raise Exception(connect_err) + if identifier_err: + raise Exception(identifier_err) + + return identifier + + def set_identifier(self, identifier: str) -> None: + identifier_err = SetIdentifier(self.name, identifier) + + if identifier_err: + raise Exception(identifier_err) @property def event(self) -> EventHandler: |
