From d4b9f1dc559022d03a73b94e4132493c31eb96df Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 13 Oct 2021 18:24:07 -0700 Subject: [PATCH] lib/cwtch new servers api coverage and Set[Profile/Contact]Attribute --- .../kotlin/im/cwtch/flwtch/FlwtchWorker.kt | 40 +++++++ lib/cwtch/cwtch.dart | 19 ++++ lib/cwtch/ffi.dart | 107 ++++++++++++++++++ lib/cwtch/gomobile.dart | 54 +++++++++ 4 files changed, 220 insertions(+) diff --git a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt index f4ef3152..3a7e9bc8 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt @@ -291,10 +291,50 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) : val groupHandle = (a.get("groupHandle") as? String) ?: "" Cwtch.rejectInvite(profile, groupHandle) } + "SetProfileAttribute" -> { + val profile = (a.get("ProfileOnion") as? String) ?: "" + val key = (a.get("Key") as? String) ?: "" + val v = (a.get("Val") as? String) ?: "" + Cwtch.setProfileAttribute(profile, key, v) + } + "SetContactAttribute" -> { + val profile = (a.get("ProfileOnion") as? String) ?: "" + val contact = (a.get("Contact") as? String) ?: "" + val key = (a.get("Key") as? String) ?: "" + val v = (a.get("Val") as? String) ?: "" + Cwtch.setContactAttribute(profile, contact, key, v) + } "Shutdown" -> { Cwtch.shutdownCwtch(); return Result.success() } + "LoadServers" -> { + val password = (a.get("Password") as? String) ?: "" + Cwtch.loadServers(password) + } + "CreateServer" -> { + val password = (a.get("Password") as? String) ?: "" + Cwtch.createServer(password) + } + "DeleteServer" -> { + val serverOnion = (a.get("ServerOnion") as? String) ?: "" + val password = (a.get("Password") as? String) ?: "" + Cwtch.deleteServer(serverOnion, password) + } + "LaunchServers" -> { + Cwtch.launchServers() + } + "LaunchServer" -> { + val serverOnion = (a.get("ServerOnion") as? String) ?: "" + Cwtch.launchServer(serverOnion) + } + "ShutdownServer" -> { + val serverOnion = (a.get("ServerOnion") as? String) ?: "" + Cwtch.shutdownServer(serverOnion) + } + "ShutdownServers" -> { + Cwtch.shutdownServers() + } else -> return Result.failure() } return Result.success() diff --git a/lib/cwtch/cwtch.dart b/lib/cwtch/cwtch.dart index 0df9c0b0..be2c466b 100644 --- a/lib/cwtch/cwtch.dart +++ b/lib/cwtch/cwtch.dart @@ -63,6 +63,25 @@ abstract class Cwtch { void SetGroupAttribute(String profile, String groupHandle, String key, String value); // ignore: non_constant_identifier_names void RejectInvite(String profileOnion, String groupHandle); + // ignore: non_constant_identifier_names + void SetProfileAttribute(String profile, String key, String val); + // ignore: non_constant_identifier_names + void SetContactAttribute(String profile, String contact, String key, String val); + + // ignore: non_constant_identifier_names + void LoadServers(String password); + // ignore: non_constant_identifier_names + void CreateServer(String password); + // ignore: non_constant_identifier_names + void DeleteServer(String serverOnion, String password); + // ignore: non_constant_identifier_names + void LaunchServers(); + // ignore: non_constant_identifier_names + void LaunchServer(String serverOnion); + // ignore: non_constant_identifier_names + void ShutdownServer(String serverOnion); + // ignore: non_constant_identifier_names + void ShutdownServers(); // ignore: non_constant_identifier_names void Shutdown(); diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 6b7cb552..8a76bb2d 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -530,6 +530,113 @@ class CwtchFfi implements Cwtch { malloc.free(u2); } + @override + // ignore: non_constant_identifier_names + void SetProfileAttribute(String profile, String key, String val) { + var setProfileAttribute = library.lookup>("c_SetProfileAttribute"); + // ignore: non_constant_identifier_names + final SetProfileAttribute = setProfileAttribute.asFunction(); + final u1 = profile.toNativeUtf8(); + final u2 = key.toNativeUtf8(); + final u3 = key.toNativeUtf8(); + SetProfileAttribute(u1, u1.length, u2, u2.length, u3, u3.length); + malloc.free(u1); + malloc.free(u2); + malloc.free(u3); + } + + @override + // ignore: non_constant_identifier_names + void SetContactAttribute(String profile, String contact, String key, String val) { + var setContactAttribute = library.lookup>("c_SetContactAttribute"); + // ignore: non_constant_identifier_names + final SetContactAttribute = setContactAttribute.asFunction(); + final u1 = profile.toNativeUtf8(); + final u2 = contact.toNativeUtf8(); + final u3 = key.toNativeUtf8(); + final u4 = key.toNativeUtf8(); + SetContactAttribute(u1, u1.length, u2, u2.length, u3, u3.length, u4, u4.length); + malloc.free(u1); + malloc.free(u2); + malloc.free(u3); + malloc.free(u4); + } + + @override + // ignore: non_constant_identifier_names + void LoadServers(String password) { + var loadServers = library.lookup>("c_LoadServers"); + // ignore: non_constant_identifier_names + final LoadServers = loadServers.asFunction(); + final u1 = password.toNativeUtf8(); + LoadServers(u1, u1.length); + malloc.free(u1); + } + + @override + // ignore: non_constant_identifier_names + void CreateServer(String password) { + var createServer = library.lookup>("c_CreateServer"); + // ignore: non_constant_identifier_names + final CreateServer = createServer.asFunction(); + final u1 = password.toNativeUtf8(); + CreateServer(u1, u1.length); + malloc.free(u1); + } + + @override + // ignore: non_constant_identifier_names + void DeleteServer(String serverOnion, String password) { + var deleteServer = library.lookup>("c_DeleteServer"); + // ignore: non_constant_identifier_names + final DeleteServer = deleteServer.asFunction(); + final u1 = serverOnion.toNativeUtf8(); + final u2 = password.toNativeUtf8(); + DeleteServer(u1, u1.length, u2, u2.length); + malloc.free(u1); + malloc.free(u2); + } + + @override + // ignore: non_constant_identifier_names + void LaunchServers() { + var launchServers = library.lookup>("c_LaunchServers"); + // ignore: non_constant_identifier_names + final LaunchServers = launchServers.asFunction(); + LaunchServers(); + } + + @override + // ignore: non_constant_identifier_names + void LaunchServer(String serverOnion) { + var launchServer = library.lookup>("c_LaunchServer"); + // ignore: non_constant_identifier_names + final LaunchServer = launchServer.asFunction(); + final u1 = serverOnion.toNativeUtf8(); + LaunchServer(u1, u1.length); + malloc.free(u1); + } + + @override + // ignore: non_constant_identifier_names + void ShutdownServer(String serverOnion) { + var shutdownServer = library.lookup>("c_ShutdownServer"); + // ignore: non_constant_identifier_names + final ShutdownServer = shutdownServer.asFunction(); + final u1 = serverOnion.toNativeUtf8(); + ShutdownServer(u1, u1.length); + malloc.free(u1); + } + + @override + // ignore: non_constant_identifier_names + void ShutdownServers() { + var shutdownServers = library.lookup>("c_ShutdownServers"); + // ignore: non_constant_identifier_names + final ShutdownServers = shutdownServers.asFunction(); + ShutdownServers(); + } + @override // ignore: non_constant_identifier_names Future Shutdown() async { diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index bf73813e..ab436570 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -202,6 +202,60 @@ class CwtchGomobile implements Cwtch { } @override + // ignore: non_constant_identifier_names + void SetProfileAttribute(String profile, String key, String val) { + cwtchPlatform.invokeMethod("SetProfileAttribute", {"ProfileOnion": profile, "Key": key, "Val": val}); + } + + @override + // ignore: non_constant_identifier_names + void SetContactAttribute(String profile, String contact, String key, String val) { + cwtchPlatform.invokeMethod("SetContactAttribute", {"ProfileOnion": profile, "Contact": contact, "Key": key, "Val": val}); + } + + @override + // ignore: non_constant_identifier_names + void LoadServers(String password) { + cwtchPlatform.invokeMethod("LoadServers", {"Password": password}); + } + + @override + // ignore: non_constant_identifier_names + void CreateServer(String password) { + cwtchPlatform.invokeMethod("CreateServer", {"Password": password}); + } + + @override + // ignore: non_constant_identifier_names + void DeleteServer(String serverOnion, String password) { + cwtchPlatform.invokeMethod("DeleteServer", {"ServerOnion": serverOnion, "Password": password}); + } + + @override + // ignore: non_constant_identifier_names + void LaunchServers() { + cwtchPlatform.invokeMethod("LaunchServers", {}); + } + + @override + // ignore: non_constant_identifier_names + void LaunchServer(String serverOnion) { + cwtchPlatform.invokeMethod("LaunchServer", {"ServerOnion": serverOnion}); + } + + @override + // ignore: non_constant_identifier_names + void ShutdownServer(String serverOnion) { + cwtchPlatform.invokeMethod("ShutdownServer", {"ServerOnion": serverOnion}); + } + + @override + // ignore: non_constant_identifier_names + void ShutdownServers() { + cwtchPlatform.invokeMethod("ShutdownServers", {}); + } + + @override Future Shutdown() async { print("gomobile.dart Shutdown"); cwtchPlatform.invokeMethod("Shutdown", {});