From 68c976107df332dbd07fded5b51c6e8e615a8bf8 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 8 Mar 2022 15:26:37 -0800 Subject: [PATCH] Import and Export Profile --- go.mod | 2 +- go.sum | 4 ++-- lib.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 50510fb..90c1a10 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index d1284f6..3987103 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/lib.go b/lib.go index 6830ab6..512ea8e 100644 --- a/lib.go +++ b/lib.go @@ -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()