Import and Export Profile

This commit is contained in:
Sarah Jamie Lewis 2022-03-08 15:26:37 -08:00
parent c2874db3c0
commit 68c976107d
3 changed files with 50 additions and 3 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go
go 1.15
require (
cwtch.im/cwtch v0.15.2
cwtch.im/cwtch v0.16.0
git.openprivacy.ca/cwtch.im/server v1.4.2
git.openprivacy.ca/openprivacy/connectivity v1.8.1
git.openprivacy.ca/openprivacy/log v1.0.3

4
go.sum
View File

@ -11,8 +11,8 @@ cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqCl
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
cwtch.im/cwtch v0.14.9/go.mod h1:/fLuoYLY/7JHw6RojFojpd245CiOcU24QpWqzh9FRDI=
cwtch.im/cwtch v0.15.2 h1:hGeLP3K2olqYevIGYYPY/x5TguQFwWb7X4pd6SHYON4=
cwtch.im/cwtch v0.15.2/go.mod h1:lG9e5RUib+SbX2XsjWtHKJWz9geoIglSAq55LrCm8Io=
cwtch.im/cwtch v0.16.0 h1:gHSbt73K1gE5crOdEjMjl9hv6zyNnsMVreRkEU9r6kY=
cwtch.im/cwtch v0.16.0/go.mod h1:lG9e5RUib+SbX2XsjWtHKJWz9geoIglSAq55LrCm8Io=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=

47
lib.go
View File

@ -998,6 +998,52 @@ func ChangePassword(profileOnion string, oldPassword string, newPassword string,
}
}
//export c_ExportProfile
func c_ExportProfile(profile_ptr *C.char, profile_len C.int, file_ptr *C.char, file_len C.int) {
profileOnion := C.GoStringN(profile_ptr, profile_len)
file := C.GoStringN(file_ptr, file_len)
ExportProfile(profileOnion, file)
}
// ExportProfile provides a wrapper around profile.ExportProfile
func ExportProfile(profileOnion string, file string) {
profile := application.GetPeer(profileOnion)
profile.Export(file)
}
//export c_ExportProfile
func c_Import(profile_ptr *C.char, profile_len C.int, file_ptr *C.char, file_len C.int) {
profileOnion := C.GoStringN(profile_ptr, profile_len)
file := C.GoStringN(file_ptr, file_len)
ExportProfile(profileOnion, file)
}
//export c_ImportProfile
func c_ImportProfile(file_ptr *C.char, file_len C.int, passwordPtr *C.char, passwordLen C.int) *C.char {
password := C.GoStringN(passwordPtr, passwordLen)
exportedCwtchFile := C.GoStringN(file_ptr, file_len)
return C.CString(ImportProfile(exportedCwtchFile, password))
}
// ImportProfile is a wrapper around application.ImportProfile
func ImportProfile(exportedCwtchFile string, pass string) string {
_, err := application.ImportProfile(exportedCwtchFile, pass)
if err == nil {
return ""
}
return err.Error()
}
//export c_SetMessageAttribute
func c_SetMessageAttribute(profile_ptr *C.char, profile_len C.int, conversation_id C.int, channel_id C.int, message_id C.int, key_ptr *C.char, key_len C.int, val_ptr *C.char, val_len C.int) {
profileOnion := C.GoStringN(profile_ptr, profile_len)
key := C.GoStringN(key_ptr, key_len)
value := C.GoStringN(val_ptr, val_len)
SetMessageAttribute(profileOnion, int(conversation_id), int(channel_id), int(message_id), key, value)
}
//export c_ShutdownCwtch
func c_ShutdownCwtch() {
ShutdownCwtch()
@ -1107,6 +1153,7 @@ func DeleteServer(onion string, currentPassword string) {
}
}
//export c_LaunchServers
func c_LaunchServers() {
LaunchServers()