Line data Source code
1 : import 'dart:collection';
2 : import 'dart:convert';
3 : import 'dart:ffi';
4 : import 'dart:io';
5 : import 'dart:isolate';
6 : import 'package:cwtch/cwtch/cwtchNotifier.dart';
7 : import 'package:path/path.dart' as path;
8 :
9 : import 'package:ffi/ffi.dart';
10 : import 'package:cwtch/cwtch/cwtch.dart';
11 :
12 : import '../config.dart';
13 :
14 : import "package:path/path.dart" show dirname, join;
15 :
16 : /////////////////////
17 : /// Cwtch API ///
18 : /////////////////////
19 :
20 : typedef start_cwtch_function = Int8 Function(Pointer<Utf8> str, Int32 length, Pointer<Utf8> str2, Int32 length2);
21 : typedef StartCwtchFn = int Function(Pointer<Utf8> dir, int len, Pointer<Utf8> tor, int torLen);
22 :
23 : typedef void_from_void_funtion = Void Function();
24 : typedef VoidFromVoidFunction = void Function();
25 :
26 : typedef free_function = Void Function(Pointer<Utf8>);
27 : typedef FreeFn = void Function(Pointer<Utf8>);
28 :
29 : typedef void_from_string_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
30 : typedef VoidFromStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
31 : typedef VoidFromStringFn = void Function(Pointer<Utf8>, int);
32 :
33 : typedef void_from_string_string_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
34 : typedef VoidFromStringStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
35 :
36 : typedef void_from_string_string_string_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
37 : typedef VoidFromStringStringStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
38 :
39 : // DownloadFile
40 : typedef void_from_string_int_string_string_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
41 : typedef VoidFromStringIntStringStringStringFn = void Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
42 :
43 : typedef void_from_string_int_string_string_string_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
44 : typedef VoidFromStringIntStringStringStringStringFn = void Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
45 :
46 : typedef void_from_string_string_int_int_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int64, Int64);
47 : typedef VoidFromStringStringIntIntFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int, int);
48 :
49 : typedef void_from_string_bool_bool_bool = Void Function(Pointer<Utf8>, Int32, Bool, Bool, Bool);
50 : typedef VoidFromStringBoolBoolBool = void Function(Pointer<Utf8>, int, bool, bool, bool);
51 :
52 : typedef void_from_string_string_byte_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int8);
53 : typedef VoidFromStringStringByteFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int);
54 :
55 : typedef void_from_string_string_byte_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int8, Pointer<Utf8>, Int32);
56 : typedef VoidFromStringStringByteStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int, Pointer<Utf8>, int);
57 :
58 : typedef string_from_string_string_byte_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int8);
59 : typedef StringFromStringStringByteFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int);
60 :
61 : typedef string_to_void_function = Void Function(Pointer<Utf8> str, Int32 length);
62 : typedef StringFn = void Function(Pointer<Utf8> dir, int);
63 :
64 : typedef string_string_to_void_function = Void Function(Pointer<Utf8> str, Int32 length, Pointer<Utf8> str2, Int32 length2);
65 : typedef StringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
66 :
67 : typedef string_string_to_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length, Pointer<Utf8> str2, Int32 length2);
68 : typedef StringFromStringStringFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
69 :
70 : typedef string_int_to_void_function = Void Function(Pointer<Utf8> str, Int32 length, Int32 handle);
71 : typedef VoidFromStringIntFn = void Function(Pointer<Utf8>, int, int);
72 :
73 : typedef get_json_blob_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length);
74 : typedef GetJsonBlobStringFn = Pointer<Utf8> Function(Pointer<Utf8> str, int len);
75 :
76 : typedef get_json_blob_from_string_int_string_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32);
77 : typedef GetJsonBlobFromStrIntStrFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int);
78 :
79 : //func GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, message_index C.int) *C.char {
80 : typedef get_json_blob_from_str_str_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int32);
81 : typedef GetJsonBlobFromStrStrIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int);
82 :
83 : typedef get_json_blob_from_str_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32);
84 : typedef GetJsonBlobFromStrIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int);
85 :
86 : typedef get_json_blob_from_str_str_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
87 : typedef GetJsonBlobFromStrStrFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
88 :
89 : typedef get_json_blob_from_str_int_int_str_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Int32, Pointer<Utf8>, Int32);
90 : typedef GetJsonBlobFromStrIntIntStrFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int, int, Pointer<Utf8>, int);
91 :
92 : typedef get_json_blob_from_str_int_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Int32);
93 : typedef GetJsonBlobFromStrIntIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int, int);
94 :
95 : typedef get_json_blob_from_str_int_int_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Int32, Int32);
96 : typedef GetJsonBlobFromStrIntIntIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int, int, int);
97 :
98 : typedef get_json_blob_from_str_int_string_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32);
99 : typedef GetJsonBlobFromStrIntStringFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int);
100 :
101 : // func c_GetMessagesByContentHash(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, contenthash_ptr *C.char, contenthash_len C.int) *C.char
102 : typedef get_json_blob_from_str_str_str_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
103 : typedef GetJsonBlobFromStrStrStrFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
104 :
105 : typedef void_from_string_int_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32);
106 : typedef VoidFromStringIntStringFn = void Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int);
107 :
108 : typedef void_from_string_int_string_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
109 : typedef VoidFromStringIntStringStringFn = void Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
110 :
111 : typedef void_from_string_int_int_int_string_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Int32, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
112 : typedef VoidFromStringIntIntIntStringStringFn = void Function(Pointer<Utf8>, int, int, int, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
113 :
114 : typedef void_from_string_int_int_function = Void Function(Pointer<Utf8>, Int32, Int32, Int32);
115 : typedef VoidFromStringIntIntFn = void Function(Pointer<Utf8>, int, int, int);
116 :
117 : typedef appbus_events_function = Pointer<Utf8> Function();
118 : typedef AppbusEventsFn = Pointer<Utf8> Function();
119 :
120 : typedef void_to_string = Pointer<Utf8> Function();
121 : typedef StringFromVoid = Pointer<Utf8> Function();
122 :
123 : const String UNSUPPORTED_OS = "unsupported-os";
124 :
125 : class CwtchFfi implements Cwtch {
126 : late DynamicLibrary library;
127 : late CwtchNotifier cwtchNotifier;
128 : late Isolate cwtchIsolate;
129 : ReceivePort _receivePort = ReceivePort();
130 : bool _isL10nInit = false;
131 : String _assetsDir = path.join(Directory.current.path, "data", "flutter_assets");
132 : String _cwtchDir = "";
133 :
134 0 : static String getLibraryPath() {
135 0 : if (Platform.isWindows) {
136 : return "libCwtch.dll";
137 0 : } else if (Platform.isLinux) {
138 : return "libCwtch.so";
139 0 : } else if (Platform.isMacOS) {
140 0 : if (Abi.current() == Abi.macosX64) {
141 : return "libCwtch.x64.dylib";
142 : } else {
143 : return "libCwtch.arm64.dylib";
144 : }
145 : } else {
146 : return UNSUPPORTED_OS;
147 : }
148 : }
149 :
150 0 : CwtchFfi(CwtchNotifier _cwtchNotifier) {
151 0 : String libraryPath = getLibraryPath();
152 0 : if (libraryPath == UNSUPPORTED_OS) {
153 0 : print("OS ${Platform.operatingSystem} not supported by cwtch/ffi");
154 : // emergency, ideally the app stays on splash and just posts the error till user closes
155 0 : exit(0);
156 : }
157 0 : library = DynamicLibrary.open(libraryPath);
158 0 : cwtchNotifier = _cwtchNotifier;
159 0 : cwtchNotifier.setMessageSeenCallback((String profile, int conversation, DateTime time) => {this.SetConversationAttribute(profile, conversation, LastMessageSeenTimeKey, time.toIso8601String())});
160 : }
161 :
162 : // ignore: non_constant_identifier_names
163 0 : Future<void> Start() async {
164 : String home = "";
165 : String bundledTor = "";
166 0 : Map<String, String> envVars = Platform.environment;
167 0 : if (Platform.isLinux) {
168 0 : home = envVars['HOME'] ?? "";
169 : if (EnvironmentConfig.TEST_MODE) {
170 0 : _cwtchDir = envVars['CWTCH_HOME']!;
171 : } else {
172 0 : _cwtchDir = envVars['CWTCH_HOME'] ?? path.join(envVars['HOME']!, ".cwtch");
173 : }
174 :
175 0 : if (await File("linux/Tor/tor").exists()) {
176 : bundledTor = "linux/Tor/tor";
177 0 : } else if (await File("lib/Tor/tor").exists()) {
178 : bundledTor = "lib/Tor/tor";
179 0 : } else if (await File(path.join(home, ".local/lib/cwtch/Tor/tor")).exists()) {
180 0 : bundledTor = path.join(home, ".local/lib/cwtch/Tor/tor");
181 0 : _assetsDir = path.join(home, ".local", "share", "cwtch", "data", "flutter_assets");
182 0 : } else if (await File("/usr/lib/cwtch/Tor/tor").exists()) {
183 : bundledTor = "/usr/lib/cwtch/Tor/tor";
184 0 : _assetsDir = path.join("usr", "share", "cwtch", "data", "flutter_assets");
185 : } else {
186 : bundledTor = "tor";
187 : }
188 0 : } else if (Platform.isWindows) {
189 0 : _cwtchDir = envVars['CWTCH_DIR'] ?? path.join(envVars['UserProfile']!, ".cwtch");
190 0 : String currentTor = path.join(Directory.current.absolute.path, "Tor\\Tor\\tor.exe");
191 0 : if (await File(currentTor).exists()) {
192 : bundledTor = currentTor;
193 0 : _assetsDir = path.join(Directory.current.absolute.path, "data", "flutter_assets");
194 : } else {
195 0 : String exeDir = path.dirname(Platform.resolvedExecutable);
196 0 : bundledTor = path.join(exeDir, "Tor\\Tor\\tor.exe");
197 0 : _assetsDir = path.join(exeDir, "data", "flutter_assets");
198 : }
199 0 : } else if (Platform.isMacOS) {
200 0 : _cwtchDir = envVars['CWTCH_HOME'] ?? path.join(envVars['HOME']!, "Library/Application Support/Cwtch");
201 0 : _assetsDir = "/Applications/Cwtch.app/Contents/Frameworks/App.framework/Versions/Current/Resources/flutter_assets/";
202 0 : if (await File("macos/Tor/tor").exists()) {
203 : bundledTor = "macos/Tor/tor";
204 0 : } else if (await File("Cwtch.app/Contents/MacOS/Tor/tor").exists()) {
205 : bundledTor = "Cwtch.app/Contents/MacOS/Tor/tor";
206 0 : _assetsDir = "Cwtch.app/Contents/Frameworks/App.framework/Versions/Current/Resources/flutter_assets/";
207 0 : } else if (await File("/Applications/Cwtch.app/Contents/MacOS/Tor/tor").exists()) {
208 : bundledTor = "/Applications/Cwtch.app/Contents/MacOS/Tor/tor";
209 0 : } else if (await File("/Volumes/Cwtch/Cwtch.app/Contents/MacOS/Tor/tor").exists()) {
210 : bundledTor = "/Volumes/Cwtch/Cwtch.app/Contents/MacOS/Tor/tor";
211 0 : } else if (await File("/Applications/Tor Browser.app/Contents/MacOS/Tor/tor").exists()) {
212 : bundledTor = "/Applications/Tor Browser.app/Contents/MacOS/Tor/tor";
213 0 : print("We couldn't find Tor in the Cwtch app directory, however we can fall back to the Tor Browser binary");
214 : } else {
215 0 : var splitPath = path.split(dirname(Platform.script.path));
216 0 : if (splitPath[0] == "/" && splitPath[1] == "Applications") {
217 0 : var appName = splitPath[2];
218 0 : print("We're running in /Applications in a non standard app name: $appName");
219 0 : if (await File("/Applications/$appName/Contents/MacOS/Tor/tor").exists()) {
220 0 : bundledTor = "/Applications/$appName/Contents/MacOS/Tor/tor";
221 : }
222 : }
223 : }
224 : }
225 :
226 : // the first Cwtch MacOS release (1.2) accidently was a dev build
227 : // we need to temporarily remedy this for a release or two then delete
228 : // if macOs and release build and no profile and is dev profile
229 : // copy dev profile to release profile
230 0 : if (Platform.isMacOS && EnvironmentConfig.BUILD_VER != dev_version) {
231 0 : var devProfileExists = await Directory(path.join(_cwtchDir, "dev", "profiles")).exists();
232 0 : var releaseProfileExists = await Directory(path.join(_cwtchDir, "profiles")).exists();
233 : if (devProfileExists && !releaseProfileExists) {
234 0 : print("MacOS one time dev -> release profile migration...");
235 0 : await Process.run("cp", ["-r", "-p", path.join(_cwtchDir, "dev", "profiles"), _cwtchDir]);
236 0 : await Process.run("cp", ["-r", "-p", path.join(_cwtchDir, "dev", "SALT"), _cwtchDir]);
237 0 : await Process.run("cp", ["-r", "-p", path.join(_cwtchDir, "dev", "ui.globals"), _cwtchDir]);
238 : }
239 : }
240 :
241 0 : if (EnvironmentConfig.BUILD_VER == dev_version) {
242 0 : _cwtchDir = path.join(_cwtchDir, "dev");
243 : }
244 :
245 0 : print("StartCwtch( cwtchdir: $_cwtchDir, torPath: $bundledTor )");
246 :
247 0 : var startCwtchC = library.lookup<NativeFunction<start_cwtch_function>>("c_StartCwtch");
248 : // ignore: non_constant_identifier_names
249 : final StartCwtch = startCwtchC.asFunction<StartCwtchFn>();
250 :
251 0 : final utf8CwtchDir = _cwtchDir.toNativeUtf8();
252 0 : StartCwtch(utf8CwtchDir, utf8CwtchDir.length, bundledTor.toNativeUtf8(), bundledTor.length);
253 0 : malloc.free(utf8CwtchDir);
254 :
255 : // Spawn an isolate to listen to events from libcwtch-go and then dispatch them when received on main thread to cwtchNotifier
256 0 : cwtchIsolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort);
257 0 : _receivePort.listen((message) {
258 0 : var env = jsonDecode(message);
259 0 : cwtchNotifier.handleMessage(env["EventType"], env["Data"]);
260 : });
261 : }
262 :
263 0 : String getAssetsDir() {
264 0 : return _assetsDir;
265 : }
266 :
267 0 : Future<String> getCwtchDir() async {
268 0 : return _cwtchDir;
269 : }
270 :
271 : // Called on object being disposed to (presumably on app close) to close the isolate that's listening to libcwtch-go events
272 0 : @override
273 : void dispose() {
274 0 : EnvironmentConfig.debugLog("tearing down cwtch FFI isolate");
275 0 : library.close();
276 0 : cwtchIsolate.kill(priority: Isolate.immediate);
277 : }
278 :
279 : // Entry point for an isolate to listen to a stream of events pulled from libcwtch-go and return them on the sendPort
280 0 : static void _checkAppbusEvents(SendPort sendPort) async {
281 0 : var stream = pollAppbusEvents();
282 0 : await for (var value in stream) {
283 0 : sendPort.send(value);
284 : }
285 0 : print("checkAppBusEvents finished...");
286 : }
287 :
288 : // Steam of appbus events. Call blocks in libcwtch-go GetAppbusEvent. Static so the isolate can use it
289 0 : static Stream<String> pollAppbusEvents() async* {
290 : late DynamicLibrary library = DynamicLibrary.open(getLibraryPath());
291 :
292 0 : var getAppbusEventC = library.lookup<NativeFunction<appbus_events_function>>("c_GetAppBusEvent");
293 : // ignore: non_constant_identifier_names
294 : final GetAppbusEvent = getAppbusEventC.asFunction<AppbusEventsFn>();
295 :
296 : // Embedded Version of _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved
297 0 : var free = library.lookup<NativeFunction<free_function>>("c_FreePointer");
298 : final Free = free.asFunction<FreeFn>();
299 :
300 : // ignore: non_constant_identifier_names
301 0 : final GetAppBusEvent = () {
302 : // ignore: non_constant_identifier_names
303 0 : Pointer<Utf8> result = GetAppbusEvent();
304 0 : String event = result.toDartString();
305 0 : Free(result);
306 : return event;
307 : };
308 :
309 : while (true) {
310 0 : final event = GetAppBusEvent();
311 :
312 0 : if (event.startsWith("{\"EventType\":\"Shutdown\"")) {
313 0 : print("Shutting down isolate thread: $event");
314 : return;
315 : }
316 : yield event;
317 : }
318 : }
319 :
320 : // ignore: non_constant_identifier_names
321 0 : Future<dynamic> CreateProfile(String nick, String pass, bool autostart) async {
322 0 : var createProfileC = library.lookup<NativeFunction<string_from_string_string_byte_function>>("c_CreateProfile");
323 : // ignore: non_constant_identifier_names
324 : final CreateProfile = createProfileC.asFunction<StringFromStringStringByteFn>();
325 0 : final utf8nick = nick.toNativeUtf8();
326 0 : final ut8pass = pass.toNativeUtf8();
327 0 : Pointer<Utf8> resultUnsafe = CreateProfile(utf8nick, utf8nick.length, ut8pass, ut8pass.length, autostart ? 1 : 0);
328 0 : String resultSafe = resultUnsafe.toDartString();
329 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(resultUnsafe);
330 0 : malloc.free(utf8nick);
331 0 : malloc.free(ut8pass);
332 : return resultSafe;
333 : }
334 :
335 : // ignore: non_constant_identifier_names
336 0 : void ActivatePeerEngine(String profile) {
337 0 : var activatePeerEngineC = library.lookup<NativeFunction<string_to_void_function>>("c_ActivatePeerEngine");
338 : final ActivatePeerEngine = activatePeerEngineC.asFunction<StringFn>();
339 0 : final ut8profile = profile.toNativeUtf8();
340 0 : ActivatePeerEngine(ut8profile, ut8profile.length);
341 0 : malloc.free(ut8profile);
342 : }
343 :
344 : // ignore: non_constant_identifier_names
345 0 : void DeactivatePeerEngine(String profile) {
346 0 : var deactivatePeerEngineC = library.lookup<NativeFunction<string_to_void_function>>("c_DeactivatePeerEngine");
347 : final DeactivatePeerEngine = deactivatePeerEngineC.asFunction<StringFn>();
348 0 : final ut8profile = profile.toNativeUtf8();
349 0 : DeactivatePeerEngine(ut8profile, ut8profile.length);
350 0 : malloc.free(ut8profile);
351 : }
352 :
353 : // ignore: non_constant_identifier_names
354 0 : void LoadProfiles(String pass) {
355 0 : var loadProfileC = library.lookup<NativeFunction<string_to_void_function>>("c_LoadProfiles");
356 : // ignore: non_constant_identifier_names
357 : final LoadProfiles = loadProfileC.asFunction<StringFn>();
358 0 : final ut8pass = pass.toNativeUtf8();
359 0 : LoadProfiles(ut8pass, ut8pass.length);
360 0 : malloc.free(ut8pass);
361 : }
362 :
363 : // ignore: non_constant_identifier_names
364 0 : Future<String> GetMessage(String profile, int handle, int index) async {
365 0 : var getMessageC = library.lookup<NativeFunction<get_json_blob_from_str_int_int_function>>("c_GetMessage");
366 : // ignore: non_constant_identifier_names
367 : final GetMessage = getMessageC.asFunction<GetJsonBlobFromStrIntIntFn>();
368 0 : final utf8profile = profile.toNativeUtf8();
369 0 : Pointer<Utf8> jsonMessageBytes = GetMessage(utf8profile, utf8profile.length, handle, index);
370 0 : String jsonMessage = jsonMessageBytes.toDartString();
371 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
372 0 : malloc.free(utf8profile);
373 : return jsonMessage;
374 : }
375 :
376 : // ignore: non_constant_identifier_names
377 0 : Future<dynamic> GetMessages(String profile, int handle, int index, int count) async {
378 0 : var getMessagesC = library.lookup<NativeFunction<get_json_blob_from_str_int_int_int_function>>("c_GetMessages");
379 : // ignore: non_constant_identifier_names
380 : final GetMessages = getMessagesC.asFunction<GetJsonBlobFromStrIntIntIntFn>();
381 0 : final utf8profile = profile.toNativeUtf8();
382 0 : Pointer<Utf8> jsonMessageBytes = GetMessages(utf8profile, utf8profile.length, handle, index, count);
383 0 : String jsonMessage = jsonMessageBytes.toDartString();
384 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
385 0 : malloc.free(utf8profile);
386 :
387 : return jsonMessage;
388 : }
389 :
390 0 : @override
391 : // ignore: non_constant_identifier_names
392 : void AcceptContact(String profileOnion, int contactHandle) {
393 0 : var acceptContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_AcceptConversation");
394 : // ignore: non_constant_identifier_names
395 : final AcceptContact = acceptContact.asFunction<VoidFromStringIntFn>();
396 0 : final u1 = profileOnion.toNativeUtf8();
397 0 : AcceptContact(u1, u1.length, contactHandle);
398 0 : malloc.free(u1);
399 : }
400 :
401 0 : @override
402 : // ignore: non_constant_identifier_names
403 : void BlockContact(String profileOnion, int contactHandle) {
404 0 : var blockContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_BlockConversation");
405 : // ignore: non_constant_identifier_names
406 : final BlockContact = blockContact.asFunction<VoidFromStringIntFn>();
407 0 : final u1 = profileOnion.toNativeUtf8();
408 0 : BlockContact(u1, u1.length, contactHandle);
409 0 : malloc.free(u1);
410 : }
411 :
412 0 : @override
413 : // ignore: non_constant_identifier_names
414 : void UnblockContact(String profileOnion, int contactHandle) {
415 0 : var unblockContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_UnblockConversation");
416 : // ignore: non_constant_identifier_names
417 : final UnblockContact = unblockContact.asFunction<VoidFromStringIntFn>();
418 0 : final u1 = profileOnion.toNativeUtf8();
419 0 : UnblockContact(u1, u1.length, contactHandle);
420 0 : malloc.free(u1);
421 : }
422 :
423 0 : @override
424 : // ignore: non_constant_identifier_names
425 : Future<dynamic> SendMessage(String profileOnion, int contactHandle, String message) async {
426 0 : var sendMessage = library.lookup<NativeFunction<get_json_blob_from_string_int_string_function>>("c_SendMessage");
427 : // ignore: non_constant_identifier_names
428 : final SendMessage = sendMessage.asFunction<GetJsonBlobFromStrIntStrFn>();
429 0 : final u1 = profileOnion.toNativeUtf8();
430 0 : final u3 = message.toNativeUtf8();
431 0 : Pointer<Utf8> jsonMessageBytes = SendMessage(u1, u1.length, contactHandle, u3, u3.length);
432 0 : String jsonMessage = jsonMessageBytes.toDartString();
433 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
434 0 : malloc.free(u1);
435 0 : malloc.free(u3);
436 : return jsonMessage;
437 : }
438 :
439 0 : @override
440 : // ignore: non_constant_identifier_names
441 : Future<dynamic> SendInvitation(String profileOnion, int contactHandle, int target) async {
442 0 : var sendInvitation = library.lookup<NativeFunction<get_json_blob_from_str_int_int_function>>("c_SendInviteMessage");
443 : // ignore: non_constant_identifier_names
444 : final SendInvitation = sendInvitation.asFunction<GetJsonBlobFromStrIntIntFn>();
445 0 : final u1 = profileOnion.toNativeUtf8();
446 0 : Pointer<Utf8> jsonMessageBytes = SendInvitation(u1, u1.length, contactHandle, target);
447 0 : String jsonMessage = jsonMessageBytes.toDartString();
448 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
449 0 : malloc.free(u1);
450 : return jsonMessage;
451 : }
452 :
453 0 : @override
454 : // ignore: non_constant_identifier_names
455 : Future<dynamic> ShareFile(String profileOnion, int contactHandle, String filepath) async {
456 0 : var shareFile = library.lookup<NativeFunction<get_json_blob_from_string_int_string_function>>("c_ShareFile");
457 : // ignore: non_constant_identifier_names
458 : final ShareFile = shareFile.asFunction<GetJsonBlobFromStrIntStrFn>();
459 0 : final u1 = profileOnion.toNativeUtf8();
460 0 : final u3 = filepath.toNativeUtf8();
461 0 : Pointer<Utf8> jsonMessageBytes = ShareFile(u1, u1.length, contactHandle, u3, u3.length);
462 0 : String jsonMessage = jsonMessageBytes.toDartString();
463 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
464 0 : malloc.free(u1);
465 0 : malloc.free(u3);
466 : return jsonMessage;
467 : }
468 :
469 0 : @override
470 : // ignore: non_constant_identifier_names
471 : void DownloadFile(String profileOnion, int contactHandle, String filepath, String manifestpath, String filekey) {
472 0 : var dlFile = library.lookup<NativeFunction<void_from_string_int_string_string_string_function>>("c_DownloadFileDefaultLimit");
473 : // ignore: non_constant_identifier_names
474 : final DownloadFile = dlFile.asFunction<VoidFromStringIntStringStringStringFn>();
475 0 : final u1 = profileOnion.toNativeUtf8();
476 0 : final u3 = filepath.toNativeUtf8();
477 0 : final u4 = manifestpath.toNativeUtf8();
478 0 : final u5 = filekey.toNativeUtf8();
479 0 : DownloadFile(u1, u1.length, contactHandle, u3, u3.length, u4, u4.length, u5, u5.length);
480 0 : malloc.free(u1);
481 0 : malloc.free(u3);
482 0 : malloc.free(u4);
483 0 : malloc.free(u5);
484 : }
485 :
486 0 : @override
487 : // ignore: non_constant_identifier_names
488 : void CreateDownloadableFile(String profileOnion, int contactHandle, String filenameSuggestion, String filekey, String manifestPath) {
489 : // android only - do nothing
490 : }
491 :
492 : // ignore: non_constant_identifier_names
493 0 : void ExportPreviewedFile(String sourceFile, String suggestion) {
494 : // android only - do nothing
495 : }
496 :
497 0 : @override
498 : // ignore: non_constant_identifier_names
499 : void CheckDownloadStatus(String profileOnion, String fileKey) {
500 0 : var checkDownloadStatus = library.lookup<NativeFunction<string_string_to_void_function>>("c_CheckDownloadStatus");
501 : // ignore: non_constant_identifier_names
502 : final CheckDownloadStatus = checkDownloadStatus.asFunction<VoidFromStringStringFn>();
503 0 : final u1 = profileOnion.toNativeUtf8();
504 0 : final u2 = fileKey.toNativeUtf8();
505 0 : CheckDownloadStatus(u1, u1.length, u2, u2.length);
506 0 : malloc.free(u1);
507 0 : malloc.free(u2);
508 : }
509 :
510 0 : @override
511 : // ignore: non_constant_identifier_names
512 : void VerifyOrResumeDownload(String profileOnion, int contactHandle, String filekey) {
513 0 : var fn = library.lookup<NativeFunction<void_from_string_int_string_function>>("c_VerifyOrResumeDownloadDefaultLimit");
514 : // ignore: non_constant_identifier_names
515 : final VerifyOrResumeDownload = fn.asFunction<VoidFromStringIntStringFn>();
516 0 : final u1 = profileOnion.toNativeUtf8();
517 0 : final u3 = filekey.toNativeUtf8();
518 0 : VerifyOrResumeDownload(u1, u1.length, contactHandle, u3, u3.length);
519 0 : malloc.free(u1);
520 0 : malloc.free(u3);
521 : }
522 :
523 0 : @override
524 : // ignore: non_constant_identifier_names
525 : void ResetTor() {
526 0 : var resetTor = library.lookup<NativeFunction<Void Function()>>("c_ResetTor");
527 : // ignore: non_constant_identifier_names
528 : final ResetTor = resetTor.asFunction<void Function()>();
529 0 : ResetTor();
530 : }
531 :
532 0 : @override
533 : // ignore: non_constant_identifier_names
534 : Future<dynamic> ImportBundle(String profileOnion, String bundle) async {
535 0 : var importBundle = library.lookup<NativeFunction<string_string_to_string_function>>("c_ImportBundle");
536 : // ignore: non_constant_identifier_names
537 : final ImportBundle = importBundle.asFunction<StringFromStringStringFn>();
538 0 : final u1 = profileOnion.toNativeUtf8();
539 0 : final u2 = bundle.toNativeUtf8();
540 0 : Pointer<Utf8> responsePtr = ImportBundle(u1, u1.length, u2, u2.length);
541 0 : String response = responsePtr.toDartString();
542 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(responsePtr);
543 0 : malloc.free(u1);
544 0 : malloc.free(u2);
545 : return response;
546 : }
547 :
548 0 : @override
549 : // ignore: non_constant_identifier_names
550 : void CreateGroup(String profileOnion, String server, String groupName) {
551 0 : var createGroup = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_StartGroup");
552 : // ignore: non_constant_identifier_names
553 : final CreateGroup = createGroup.asFunction<VoidFromStringStringStringFn>();
554 0 : final u1 = profileOnion.toNativeUtf8();
555 0 : final u3 = server.toNativeUtf8();
556 0 : final u2 = groupName.toNativeUtf8();
557 0 : CreateGroup(u1, u1.length, u2, u2.length, u3, u3.length);
558 :
559 0 : malloc.free(u1);
560 0 : malloc.free(u2);
561 0 : malloc.free(u3);
562 : }
563 :
564 0 : @override
565 : // ignore: non_constant_identifier_names
566 : void ArchiveConversation(String profileOnion, int handle) {
567 0 : var archiveConversation = library.lookup<NativeFunction<string_int_to_void_function>>("c_ArchiveConversation");
568 : // ignore: non_constant_identifier_names
569 : final ArchiveConversation = archiveConversation.asFunction<VoidFromStringIntFn>();
570 0 : final u1 = profileOnion.toNativeUtf8();
571 0 : ArchiveConversation(u1, u1.length, handle);
572 0 : malloc.free(u1);
573 : }
574 :
575 0 : @override
576 : // ignore: non_constant_identifier_names
577 : void DeleteContact(String profileOnion, int handle) {
578 0 : var deleteContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_DeleteConversation");
579 : // ignore: non_constant_identifier_names
580 : final DeleteContact = deleteContact.asFunction<VoidFromStringIntFn>();
581 0 : final u1 = profileOnion.toNativeUtf8();
582 0 : DeleteContact(u1, u1.length, handle);
583 0 : malloc.free(u1);
584 : }
585 :
586 0 : @override
587 : // ignore: non_constant_identifier_names
588 : void DeleteProfile(String onion, String currentPassword) {
589 0 : var deleteprofile = library.lookup<NativeFunction<string_string_to_void_function>>("c_DeleteProfile");
590 : // ignore: non_constant_identifier_names
591 : final DeleteProfile = deleteprofile.asFunction<VoidFromStringStringFn>();
592 0 : final u1 = onion.toNativeUtf8();
593 0 : final u2 = currentPassword.toNativeUtf8();
594 0 : DeleteProfile(u1, u1.length, u2, u2.length);
595 0 : malloc.free(u1);
596 0 : malloc.free(u2);
597 : }
598 :
599 0 : @override
600 : // ignore: non_constant_identifier_names
601 : void SetProfileAttribute(String profile, String key, String val) {
602 0 : var setProfileAttribute = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_SetProfileAttribute");
603 : // ignore: non_constant_identifier_names
604 : final SetProfileAttribute = setProfileAttribute.asFunction<VoidFromStringStringStringFn>();
605 0 : final u1 = profile.toNativeUtf8();
606 0 : final u2 = key.toNativeUtf8();
607 0 : final u3 = val.toNativeUtf8();
608 0 : SetProfileAttribute(u1, u1.length, u2, u2.length, u3, u3.length);
609 0 : malloc.free(u1);
610 0 : malloc.free(u2);
611 0 : malloc.free(u3);
612 : }
613 :
614 0 : @override
615 : // ignore: non_constant_identifier_names
616 : void SetConversationAttribute(String profile, int contact, String key, String val) {
617 0 : var setContactAttribute = library.lookup<NativeFunction<void_from_string_int_string_string_function>>("c_SetConversationAttribute");
618 : // ignore: non_constant_identifier_names
619 : final SetContactAttribute = setContactAttribute.asFunction<VoidFromStringIntStringStringFn>();
620 0 : final u1 = profile.toNativeUtf8();
621 0 : final u3 = key.toNativeUtf8();
622 0 : final u4 = val.toNativeUtf8();
623 0 : SetContactAttribute(u1, u1.length, contact, u3, u3.length, u4, u4.length);
624 0 : malloc.free(u1);
625 0 : malloc.free(u3);
626 0 : malloc.free(u4);
627 : }
628 :
629 0 : @override
630 : // ignore: non_constant_identifier_names
631 : void SetMessageAttribute(String profile, int conversation, int channel, int message, String key, String val) {
632 0 : var setMessageAttribute = library.lookup<NativeFunction<void_from_string_int_int_int_string_string_function>>("c_UpdateMessageAttribute");
633 : // ignore: non_constant_identifier_names
634 : final SetMessageAttribute = setMessageAttribute.asFunction<VoidFromStringIntIntIntStringStringFn>();
635 0 : final u1 = profile.toNativeUtf8();
636 0 : final u3 = key.toNativeUtf8();
637 0 : final u4 = val.toNativeUtf8();
638 0 : SetMessageAttribute(u1, u1.length, conversation, channel, message, u3, u3.length, u4, u4.length);
639 0 : malloc.free(u1);
640 0 : malloc.free(u3);
641 0 : malloc.free(u4);
642 : }
643 :
644 0 : @override
645 : // ignore: non_constant_identifier_names
646 : void LoadServers(String password) {
647 0 : var loadServers = library.lookup<NativeFunction<string_to_void_function>>("c_LoadServers");
648 : // ignore: non_constant_identifier_names
649 : final LoadServers = loadServers.asFunction<StringFn>();
650 0 : final u1 = password.toNativeUtf8();
651 0 : LoadServers(u1, u1.length);
652 0 : malloc.free(u1);
653 : }
654 :
655 0 : @override
656 : // ignore: non_constant_identifier_names
657 : void CreateServer(String password, String description, bool autostart) {
658 0 : var createServer = library.lookup<NativeFunction<void_from_string_string_byte_function>>("c_CreateServer");
659 : // ignore: non_constant_identifier_names
660 : final CreateServer = createServer.asFunction<VoidFromStringStringByteFn>();
661 0 : final u1 = password.toNativeUtf8();
662 0 : final u2 = description.toNativeUtf8();
663 0 : CreateServer(u1, u1.length, u2, u2.length, autostart ? 1 : 0);
664 0 : malloc.free(u1);
665 0 : malloc.free(u2);
666 : }
667 :
668 0 : @override
669 : // ignore: non_constant_identifier_names
670 : void DeleteServer(String serverOnion, String password) {
671 0 : var deleteServer = library.lookup<NativeFunction<string_string_to_void_function>>("c_DeleteServer");
672 : // ignore: non_constant_identifier_names
673 : final DeleteServer = deleteServer.asFunction<VoidFromStringStringFn>();
674 0 : final u1 = serverOnion.toNativeUtf8();
675 0 : final u2 = password.toNativeUtf8();
676 0 : DeleteServer(u1, u1.length, u2, u2.length);
677 0 : malloc.free(u1);
678 0 : malloc.free(u2);
679 : }
680 :
681 0 : @override
682 : // ignore: non_constant_identifier_names
683 : void LaunchServers() {
684 0 : var launchServers = library.lookup<NativeFunction<Void Function()>>("c_LaunchServers");
685 : // ignore: non_constant_identifier_names
686 : final LaunchServers = launchServers.asFunction<void Function()>();
687 0 : LaunchServers();
688 : }
689 :
690 0 : @override
691 : // ignore: non_constant_identifier_names
692 : void LaunchServer(String serverOnion) {
693 0 : var launchServer = library.lookup<NativeFunction<string_to_void_function>>("c_LaunchServer");
694 : // ignore: non_constant_identifier_names
695 : final LaunchServer = launchServer.asFunction<StringFn>();
696 0 : final u1 = serverOnion.toNativeUtf8();
697 0 : LaunchServer(u1, u1.length);
698 0 : malloc.free(u1);
699 : }
700 :
701 0 : @override
702 : // ignore: non_constant_identifier_names
703 : void StopServer(String serverOnion) {
704 0 : var shutdownServer = library.lookup<NativeFunction<string_to_void_function>>("c_StopServer");
705 : // ignore: non_constant_identifier_names
706 : final ShutdownServer = shutdownServer.asFunction<StringFn>();
707 0 : final u1 = serverOnion.toNativeUtf8();
708 0 : ShutdownServer(u1, u1.length);
709 0 : malloc.free(u1);
710 : }
711 :
712 0 : @override
713 : // ignore: non_constant_identifier_names
714 : void StopServers() {
715 0 : var shutdownServers = library.lookup<NativeFunction<Void Function()>>("c_StopServers");
716 : // ignore: non_constant_identifier_names
717 : final ShutdownServers = shutdownServers.asFunction<void Function()>();
718 0 : ShutdownServers();
719 : }
720 :
721 0 : @override
722 : // ignore: non_constant_identifier_names
723 : void DestroyServers() {
724 0 : var destroyServers = library.lookup<NativeFunction<Void Function()>>("c_DestroyServers");
725 : // ignore: non_constant_identifier_names
726 : final DestroyServers = destroyServers.asFunction<void Function()>();
727 0 : DestroyServers();
728 : }
729 :
730 0 : @override
731 : // ignore: non_constant_identifier_names
732 : void SetServerAttribute(String serverOnion, String key, String val) {
733 0 : var setServerAttribute = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_SetServerAttribute");
734 : // ignore: non_constant_identifier_names
735 : final SetServerAttribute = setServerAttribute.asFunction<VoidFromStringStringStringFn>();
736 0 : final u1 = serverOnion.toNativeUtf8();
737 0 : final u2 = key.toNativeUtf8();
738 0 : final u3 = val.toNativeUtf8();
739 0 : SetServerAttribute(u1, u1.length, u2, u2.length, u3, u3.length);
740 0 : malloc.free(u1);
741 0 : malloc.free(u2);
742 0 : malloc.free(u3);
743 : }
744 :
745 0 : @override
746 : // ignore: non_constant_identifier_names
747 : void LoadHybridGroups(String password) {
748 0 : var loadGroups = library.lookup<NativeFunction<string_to_void_function>>("c_LoadHybridGroups");
749 : // ignore: non_constant_identifier_names
750 : final LoadGroups = loadGroups.asFunction<StringFn>();
751 0 : final u1 = password.toNativeUtf8();
752 0 : LoadGroups(u1, u1.length);
753 0 : malloc.free(u1);
754 : }
755 :
756 0 : @override
757 : // ignore: non_constant_identifier_names
758 : void CreateHybridGroup(String password, String description, bool autostart, String groupAdmin) {
759 0 : var createGroup = library.lookup<NativeFunction<void_from_string_string_byte_string_function>>("c_CreateHybridGroup");
760 : // ignore: non_constant_identifier_names
761 : final CreateGroup = createGroup.asFunction<VoidFromStringStringByteStringFn>();
762 0 : final u1 = password.toNativeUtf8();
763 0 : final u2 = description.toNativeUtf8();
764 0 : final u3 = groupAdmin.toNativeUtf8();
765 0 : CreateGroup(u1, u1.length, u2, u2.length, autostart ? 1 : 0, u3, u3.length);
766 0 : malloc.free(u1);
767 0 : malloc.free(u2);
768 0 : malloc.free(u3);
769 : }
770 :
771 0 : @override
772 : // ignore: non_constant_identifier_names
773 : void DeleteHybridGroup(String groupOnion, String password) {
774 0 : var deleteGroup = library.lookup<NativeFunction<string_string_to_void_function>>("c_DeleteHybridGroup");
775 : // ignore: non_constant_identifier_names
776 : final DeleteGroup = deleteGroup.asFunction<VoidFromStringStringFn>();
777 0 : final u1 = groupOnion.toNativeUtf8();
778 0 : final u2 = password.toNativeUtf8();
779 0 : DeleteGroup(u1, u1.length, u2, u2.length);
780 0 : malloc.free(u1);
781 0 : malloc.free(u2);
782 : }
783 :
784 0 : @override
785 : // ignore: non_constant_identifier_names
786 : void LaunchHybridGroups() {
787 0 : var launchGroups = library.lookup<NativeFunction<Void Function()>>("c_LaunchHybridGroups");
788 : // ignore: non_constant_identifier_names
789 : final LaunchGroups = launchGroups.asFunction<void Function()>();
790 0 : LaunchGroups();
791 : }
792 :
793 0 : @override
794 : // ignore: non_constant_identifier_names
795 : void LaunchHybridGroup(String groupOnion) {
796 0 : var launchGroup = library.lookup<NativeFunction<string_to_void_function>>("c_LaunchHybridGroup");
797 : // ignore: non_constant_identifier_names
798 : final LaunchGroup = launchGroup.asFunction<StringFn>();
799 0 : final u1 = groupOnion.toNativeUtf8();
800 0 : LaunchGroup(u1, u1.length);
801 0 : malloc.free(u1);
802 : }
803 :
804 0 : @override
805 : // ignore: non_constant_identifier_names
806 : void StopHybridGroup(String groupOnion) {
807 0 : var shutdownGroup = library.lookup<NativeFunction<string_to_void_function>>("c_StopHybridGroup");
808 : // ignore: non_constant_identifier_names
809 : final ShutdownGroup = shutdownGroup.asFunction<StringFn>();
810 0 : final u1 = groupOnion.toNativeUtf8();
811 0 : ShutdownGroup(u1, u1.length);
812 0 : malloc.free(u1);
813 : }
814 :
815 0 : @override
816 : // ignore: non_constant_identifier_names
817 : void StopHybridGroups() {
818 0 : var shutdownGroups = library.lookup<NativeFunction<Void Function()>>("c_StopHybridGroups");
819 : // ignore: non_constant_identifier_names
820 : final ShutdownGroups = shutdownGroups.asFunction<void Function()>();
821 0 : ShutdownGroups();
822 : }
823 :
824 0 : @override
825 : // ignore: non_constant_identifier_names
826 : void DestroyHybridGroups() {
827 0 : var destroyGroups = library.lookup<NativeFunction<Void Function()>>("c_DestroyHybridGroups");
828 : // ignore: non_constant_identifier_names
829 : final DestroyGroups = destroyGroups.asFunction<void Function()>();
830 0 : DestroyGroups();
831 : }
832 :
833 0 : @override
834 : // ignore: non_constant_identifier_names
835 : void SetHybridGroupAttribute(String groupOnion, String key, String val) {
836 0 : var setGroupAttribute = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_SetHybridGroupAttribute");
837 : // ignore: non_constant_identifier_names
838 : final SetGroupAttribute = setGroupAttribute.asFunction<VoidFromStringStringStringFn>();
839 0 : final u1 = groupOnion.toNativeUtf8();
840 0 : final u2 = key.toNativeUtf8();
841 0 : final u3 = val.toNativeUtf8();
842 0 : SetGroupAttribute(u1, u1.length, u2, u2.length, u3, u3.length);
843 0 : malloc.free(u1);
844 0 : malloc.free(u2);
845 0 : malloc.free(u3);
846 : }
847 :
848 0 : @override
849 : // ignore: non_constant_identifier_names
850 : void ChangeGroupMode(String profile, int conversation, String mode) {
851 0 : var changeGroupMode = library.lookup<NativeFunction<void_from_string_int_string_function>>("c_ChangeGroupMode");
852 : // ignore: non_constant_identifier_names
853 : final ChangeGroupMode = changeGroupMode.asFunction<VoidFromStringIntStringFn>();
854 0 : final u1 = profile.toNativeUtf8();
855 0 : final u3 = mode.toNativeUtf8();
856 0 : ChangeGroupMode(u1, u1.length, conversation, u3, u3.length);
857 0 : malloc.free(u1);
858 0 : malloc.free(u3);
859 : }
860 :
861 0 : @override
862 : // ignore: non_constant_identifier_names
863 : void ChangeGroupMask(String profile, int conversation, String mode) {
864 0 : var changeGroupMask = library.lookup<NativeFunction<void_from_string_int_string_function>>("c_ChangeGroupMask");
865 : // ignore: non_constant_identifier_names
866 : final ChangeGroupMask = changeGroupMask.asFunction<VoidFromStringIntStringFn>();
867 0 : final u1 = profile.toNativeUtf8();
868 0 : final u3 = mode.toNativeUtf8();
869 0 : ChangeGroupMask(u1, u1.length, conversation, u3, u3.length);
870 0 : malloc.free(u1);
871 0 : malloc.free(u3);
872 : }
873 :
874 0 : @override
875 : // ignore: non_constant_identifier_names
876 : void ChangeRole(String profile, int conversation, String handle, String role) {
877 0 : var changeRole = library.lookup<NativeFunction<void_from_string_int_string_string_function>>("c_ChangeRole");
878 : // ignore: non_constant_identifier_names
879 : final ChangeRole = changeRole.asFunction<VoidFromStringIntStringStringFn>();
880 0 : final u1 = profile.toNativeUtf8();
881 0 : final u3 = handle.toNativeUtf8();
882 0 : final u4 = role.toNativeUtf8();
883 0 : ChangeRole(u1, u1.length, conversation, u3, u3.length, u4, u4.length);
884 0 : malloc.free(u1);
885 0 : malloc.free(u3);
886 0 : malloc.free(u4);
887 : }
888 :
889 0 : @override
890 : // ignore: non_constant_identifier_names
891 : void InviteMember(String profile, int conversation, String handle) {
892 0 : var inviteMember = library.lookup<NativeFunction<void_from_string_int_string_function>>("c_InviteMember");
893 : // ignore: non_constant_identifier_names
894 : final InviteMember = inviteMember.asFunction<VoidFromStringIntStringFn>();
895 0 : final u1 = profile.toNativeUtf8();
896 0 : final u3 = handle.toNativeUtf8();
897 0 : InviteMember(u1, u1.length, conversation, u3, u3.length);
898 0 : malloc.free(u1);
899 0 : malloc.free(u3);
900 : }
901 :
902 0 : @override
903 : // ignore: non_constant_identifier_names
904 : void KickMember(String profile, int conversation, String handle) {
905 0 : var kickMember = library.lookup<NativeFunction<void_from_string_int_string_function>>("c_KickMember");
906 : // ignore: non_constant_identifier_names
907 : final KickMember = kickMember.asFunction<VoidFromStringIntStringFn>();
908 0 : final u1 = profile.toNativeUtf8();
909 0 : final u3 = handle.toNativeUtf8();
910 0 : KickMember(u1, u1.length, conversation, u3, u3.length);
911 0 : malloc.free(u1);
912 0 : malloc.free(u3);
913 : }
914 :
915 0 : @override
916 : // ignore: non_constant_identifier_names
917 : void ModerateMessage(String profile, int conversation, String signature, String action) {
918 0 : var moderateMessage = library.lookup<NativeFunction<void_from_string_int_string_string_function>>("c_ModerateMessage");
919 : // ignore: non_constant_identifier_names
920 : final ModerateMessage = moderateMessage.asFunction<VoidFromStringIntStringStringFn>();
921 0 : final u1 = profile.toNativeUtf8();
922 0 : final u3 = signature.toNativeUtf8();
923 0 : final u4 = action.toNativeUtf8();
924 0 : ModerateMessage(u1, u1.length, conversation, u3, u3.length, u4, u4.length);
925 0 : malloc.free(u1);
926 0 : malloc.free(u3);
927 0 : malloc.free(u4);
928 : }
929 :
930 0 : @override
931 : // ignore: non_constant_identifier_names
932 : void UpdateGroupMetadata(String profileOnion, int conversation, String name, String attr1, String attr2, String attr3) {
933 0 : var updateGroupMetadata = library.lookup<NativeFunction<void_from_string_int_string_string_string_string_function>>("c_UpdateGroupMetadata");
934 : // ignore: non_constant_identifier_names
935 : final UpdateGroupMetadata = updateGroupMetadata.asFunction<VoidFromStringIntStringStringStringStringFn>();
936 0 : final u1 = profileOnion.toNativeUtf8();
937 0 : final u3 = name.toNativeUtf8();
938 0 : final u4 = attr1.toNativeUtf8();
939 0 : final u5 = attr2.toNativeUtf8();
940 0 : final u6 = attr3.toNativeUtf8();
941 0 : UpdateGroupMetadata(u1, u1.length, conversation, u3, u3.length, u4, u4.length, u5, u5.length, u6, u6.length);
942 0 : malloc.free(u1);
943 0 : malloc.free(u3);
944 0 : malloc.free(u4);
945 0 : malloc.free(u5);
946 0 : malloc.free(u6);
947 : }
948 :
949 0 : @override
950 : // ignore: non_constant_identifier_names
951 : void UpdateGroupPicture(String profile, int conversation, String filePath) {
952 0 : var updateGroupPicture = library.lookup<NativeFunction<void_from_string_int_string_function>>("c_UpdateGroupPicture");
953 : // ignore: non_constant_identifier_names
954 : final UpdateGroupPicture = updateGroupPicture.asFunction<VoidFromStringIntStringFn>();
955 0 : final u1 = profile.toNativeUtf8();
956 0 : final u3 = filePath.toNativeUtf8();
957 0 : UpdateGroupPicture(u1, u1.length, conversation, u3, u3.length);
958 0 : malloc.free(u1);
959 0 : malloc.free(u3);
960 : }
961 :
962 0 : @override
963 : // ignore: non_constant_identifier_names
964 : Future<void> Shutdown() async {
965 0 : var shutdown = library.lookup<NativeFunction<void_from_void_funtion>>("c_ShutdownCwtch");
966 : // ignore: non_constant_identifier_names
967 :
968 : // Shutdown Cwtch + Tor...
969 : // ignore: non_constant_identifier_names
970 : final Shutdown = shutdown.asFunction<VoidFromVoidFunction>();
971 0 : Shutdown();
972 :
973 : // Kill our Isolate
974 0 : cwtchIsolate.kill(priority: Isolate.immediate);
975 0 : print("Isolate killed");
976 :
977 0 : _receivePort.close();
978 0 : print("Receive Port Closed");
979 : }
980 :
981 0 : @override
982 : // ignore: non_constant_identifier_names
983 : Future GetMessageByContentHash(String profile, int handle, String contentHash) async {
984 0 : var getMessagesByContentHashC = library.lookup<NativeFunction<get_json_blob_from_str_int_string_function>>("c_GetMessageByContentHash");
985 : // ignore: non_constant_identifier_names
986 : final GetMessagesByContentHash = getMessagesByContentHashC.asFunction<GetJsonBlobFromStrIntStringFn>();
987 0 : final utf8profile = profile.toNativeUtf8();
988 0 : final utf8contentHash = contentHash.toNativeUtf8();
989 0 : Pointer<Utf8> jsonMessageBytes = GetMessagesByContentHash(utf8profile, utf8profile.length, handle, utf8contentHash, utf8contentHash.length);
990 0 : String jsonMessage = jsonMessageBytes.toDartString();
991 :
992 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
993 0 : malloc.free(utf8profile);
994 0 : malloc.free(utf8contentHash);
995 : return jsonMessage;
996 : }
997 :
998 : // ignore: non_constant_identifier_names
999 : // Incredibly dangerous function which invokes a free in libCwtch, should only be used
1000 : // as documented in `MEMORY.md` in libCwtch repo.
1001 0 : void _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(Pointer<Utf8> ptr) {
1002 0 : var free = library.lookup<NativeFunction<free_function>>("c_FreePointer");
1003 : final Free = free.asFunction<FreeFn>();
1004 0 : Free(ptr);
1005 : }
1006 :
1007 0 : @override
1008 : String? defaultDownloadPath() {
1009 0 : Map<String, String> envVars = Platform.environment;
1010 0 : String nominalPath = path.join(envVars[Platform.isWindows ? 'UserProfile' : 'HOME']!, "Downloads");
1011 0 : if (Directory(nominalPath).existsSync() == false) {
1012 0 : return Directory.current.path;
1013 : }
1014 : return nominalPath;
1015 : }
1016 :
1017 0 : @override
1018 : // ignore: non_constant_identifier_names
1019 : Future<String> GetMessageByID(String profile, int handle, int index) async {
1020 0 : var getMessageC = library.lookup<NativeFunction<get_json_blob_from_str_int_int_function>>("c_GetMessageById");
1021 : // ignore: non_constant_identifier_names
1022 : final GetMessage = getMessageC.asFunction<GetJsonBlobFromStrIntIntFn>();
1023 0 : final utf8profile = profile.toNativeUtf8();
1024 0 : Pointer<Utf8> jsonMessageBytes = GetMessage(utf8profile, utf8profile.length, handle, index);
1025 0 : String jsonMessage = jsonMessageBytes.toDartString();
1026 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
1027 0 : malloc.free(utf8profile);
1028 : return jsonMessage;
1029 : }
1030 :
1031 0 : @override
1032 : // ignore: non_constant_identifier_names
1033 : void ChangePassword(String profile, String pass, String newpass, String newpassAgain) {
1034 0 : var changePasswordC = library.lookup<NativeFunction<void_from_string_string_string_string_function>>("c_ChangePassword");
1035 : // ignore: non_constant_identifier_names
1036 : final ChangePasswordFn = changePasswordC.asFunction<VoidFromStringStringStringStringFn>();
1037 0 : final utf8profile = profile.toNativeUtf8();
1038 0 : final utf8pass = pass.toNativeUtf8();
1039 0 : final utf8newpass = newpass.toNativeUtf8();
1040 0 : final utf8newpasssagain = newpassAgain.toNativeUtf8();
1041 0 : ChangePasswordFn(utf8profile, utf8profile.length, utf8pass, utf8pass.length, utf8newpass, utf8newpass.length, utf8newpasssagain, utf8newpasssagain.length);
1042 0 : malloc.free(utf8profile);
1043 0 : malloc.free(utf8pass);
1044 0 : malloc.free(utf8newpass);
1045 0 : malloc.free(utf8newpasssagain);
1046 : }
1047 :
1048 0 : @override
1049 : bool isL10nInit() {
1050 0 : return _isL10nInit;
1051 : }
1052 :
1053 0 : @override
1054 : void l10nInit(String notificationSimple, String notificationConversationInfo) {
1055 0 : cwtchNotifier.l10nInit(notificationSimple, notificationConversationInfo);
1056 0 : _isL10nInit = true;
1057 : }
1058 :
1059 0 : @override
1060 : // ignore: non_constant_identifier_names
1061 : void ExportProfile(String profile, String file) {
1062 0 : final utf8profile = profile.toNativeUtf8();
1063 0 : final utf8file = file.toNativeUtf8();
1064 0 : var exportProfileC = library.lookup<NativeFunction<void_from_string_string_function>>("c_ExportProfile");
1065 : // ignore: non_constant_identifier_names
1066 : final ExportProfileFn = exportProfileC.asFunction<VoidFromStringStringFn>();
1067 0 : ExportProfileFn(utf8profile, utf8profile.length, utf8file, utf8file.length);
1068 0 : malloc.free(utf8profile);
1069 0 : malloc.free(utf8file);
1070 : }
1071 :
1072 0 : @override
1073 : // ignore: non_constant_identifier_names
1074 : Future<String> ImportProfile(String file, String pass) async {
1075 0 : final utf8pass = pass.toNativeUtf8();
1076 0 : final utf8file = file.toNativeUtf8();
1077 0 : var exportProfileC = library.lookup<NativeFunction<string_string_to_string_function>>("c_ImportProfile");
1078 : // ignore: non_constant_identifier_names
1079 : final ExportProfileFn = exportProfileC.asFunction<StringFromStringStringFn>();
1080 0 : Pointer<Utf8> result = ExportProfileFn(utf8file, utf8file.length, utf8pass, utf8pass.length);
1081 0 : String importResult = result.toDartString();
1082 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(result);
1083 0 : malloc.free(utf8pass);
1084 0 : malloc.free(utf8file);
1085 : return importResult;
1086 : }
1087 :
1088 0 : @override
1089 : Future<String> GetDebugInfo() async {
1090 0 : var getDebugInfo = library.lookup<NativeFunction<void_to_string>>("c_GetDebugInfo");
1091 : final GetDebugInfo = getDebugInfo.asFunction<StringFromVoid>();
1092 0 : Pointer<Utf8> result = GetDebugInfo();
1093 0 : String debugResult = result.toDartString();
1094 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(result);
1095 : return debugResult;
1096 : }
1097 :
1098 0 : @override
1099 : Future<String> GetSharedFiles(String profile, int handle) async {
1100 0 : var getSharedFiles = library.lookup<NativeFunction<get_json_blob_from_str_int_function>>("c_GetSharedFiles");
1101 : final GetSharedFiles = getSharedFiles.asFunction<GetJsonBlobFromStrIntFn>();
1102 0 : final utf8profile = profile.toNativeUtf8();
1103 0 : Pointer<Utf8> jsonMessageBytes = GetSharedFiles(utf8profile, utf8profile.length, handle);
1104 0 : String jsonMessage = jsonMessageBytes.toDartString();
1105 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
1106 0 : malloc.free(utf8profile);
1107 : return jsonMessage;
1108 : }
1109 :
1110 0 : @override
1111 : void RestartSharing(String profile, String filekey) {
1112 0 : var restartSharingC = library.lookup<NativeFunction<void_from_string_string_function>>("c_RestartFileShare");
1113 : // ignore: non_constant_identifier_names
1114 : final RestartSharing = restartSharingC.asFunction<VoidFromStringStringFn>();
1115 0 : final utf8profile = profile.toNativeUtf8();
1116 0 : final ut8filekey = filekey.toNativeUtf8();
1117 0 : RestartSharing(utf8profile, utf8profile.length, ut8filekey, ut8filekey.length);
1118 0 : malloc.free(utf8profile);
1119 0 : malloc.free(ut8filekey);
1120 : }
1121 :
1122 0 : @override
1123 : void StopSharing(String profile, String filekey) {
1124 0 : var stopSharingC = library.lookup<NativeFunction<void_from_string_string_function>>("c_StopFileShare");
1125 : // ignore: non_constant_identifier_names
1126 : final StopSharing = stopSharingC.asFunction<VoidFromStringStringFn>();
1127 0 : final utf8profile = profile.toNativeUtf8();
1128 0 : final ut8filekey = filekey.toNativeUtf8();
1129 0 : StopSharing(utf8profile, utf8profile.length, ut8filekey, ut8filekey.length);
1130 0 : malloc.free(utf8profile);
1131 0 : malloc.free(ut8filekey);
1132 : }
1133 :
1134 0 : @override
1135 : void DeleteServerInfo(String profile, String handle) {
1136 0 : var deleteServerInfoC = library.lookup<NativeFunction<void_from_string_string_function>>("c_DeleteServerInfo");
1137 : // ignore: non_constant_identifier_names
1138 : final StopSharing = deleteServerInfoC.asFunction<VoidFromStringStringFn>();
1139 0 : final utf8profile = profile.toNativeUtf8();
1140 0 : final ut8handle = handle.toNativeUtf8();
1141 0 : StopSharing(utf8profile, utf8profile.length, ut8handle, ut8handle.length);
1142 0 : malloc.free(utf8profile);
1143 0 : malloc.free(ut8handle);
1144 : }
1145 :
1146 0 : @override
1147 : void UpdateSettings(String json) {
1148 0 : var updateSettings = library.lookup<NativeFunction<string_to_void_function>>("c_UpdateSettings");
1149 : // ignore: non_constant_identifier_names
1150 : final UpdateSettingsFn = updateSettings.asFunction<VoidFromStringFn>();
1151 0 : final u1 = json.toNativeUtf8();
1152 0 : UpdateSettingsFn(u1, u1.length);
1153 0 : malloc.free(u1);
1154 : }
1155 :
1156 0 : @override
1157 : bool IsManagedGroupsCompiled() {
1158 : return true;
1159 : return library.providesSymbol("c_LoadManagedGroups");
1160 : }
1161 :
1162 0 : @override
1163 : bool IsServersCompiled() {
1164 0 : return library.providesSymbol("c_LoadServers");
1165 : }
1166 :
1167 0 : @override
1168 : Future<String> SummarizeConversation(String profile, int conversation) async {
1169 0 : if (!library.providesSymbol("c_Summarize")) {
1170 0 : return Future.value("");
1171 : }
1172 0 : var summarize = library.lookup<NativeFunction<get_json_blob_from_str_int_function>>("c_Summarize");
1173 : // ignore: non_constant_identifier_names
1174 : final SummarizeFn = summarize.asFunction<GetJsonBlobFromStrIntFn>();
1175 0 : final utf8profile = profile.toNativeUtf8();
1176 0 : Pointer<Utf8> jsonMessageBytes = SummarizeFn(utf8profile, utf8profile.length, conversation);
1177 0 : String jsonMessage = jsonMessageBytes.toDartString();
1178 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
1179 0 : malloc.free(utf8profile);
1180 : return jsonMessage;
1181 : }
1182 :
1183 0 : @override
1184 : Future<String> TranslateMessage(String profile, int conversation, int message, String language) async {
1185 0 : if (!library.providesSymbol("c_Translate")) {
1186 0 : return Future.value("");
1187 : }
1188 0 : var translate = library.lookup<NativeFunction<get_json_blob_from_str_int_int_str_function>>("c_Translate");
1189 : // ignore: non_constant_identifier_names
1190 : final TranslateFn = translate.asFunction<GetJsonBlobFromStrIntIntStrFn>();
1191 0 : final utf8profile = profile.toNativeUtf8();
1192 0 : final utf8lang = language.toNativeUtf8();
1193 0 : Pointer<Utf8> jsonMessageBytes = TranslateFn(utf8profile, utf8profile.length, conversation, message, utf8lang, utf8lang.length);
1194 0 : String jsonMessage = jsonMessageBytes.toDartString();
1195 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
1196 0 : malloc.free(utf8profile);
1197 0 : malloc.free(utf8lang);
1198 : return jsonMessage;
1199 : }
1200 :
1201 0 : @override
1202 : bool IsBlodeuweddSupported() {
1203 0 : if (library.providesSymbol("c_Translate")) {
1204 : return true;
1205 : }
1206 : return false;
1207 : }
1208 :
1209 0 : @override
1210 : Future<String?> GetProfileAttribute(String profile, String key) {
1211 0 : var getProfileAttributeC = library.lookup<NativeFunction<get_json_blob_from_str_str_function>>("c_GetProfileAttribute");
1212 : // ignore: non_constant_identifier_names
1213 : final GetProfileAttribute = getProfileAttributeC.asFunction<GetJsonBlobFromStrStrFn>();
1214 0 : final utf8profile = profile.toNativeUtf8();
1215 0 : final utf8key = key.toNativeUtf8();
1216 0 : Pointer<Utf8> jsonMessageBytes = GetProfileAttribute(utf8profile, utf8profile.length, utf8key, utf8key.length);
1217 0 : String jsonMessage = jsonMessageBytes.toDartString();
1218 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
1219 0 : malloc.free(utf8profile);
1220 0 : malloc.free(utf8key);
1221 :
1222 : try {
1223 0 : dynamic attributeResult = json.decode(jsonMessage);
1224 0 : if (attributeResult["Exists"]) {
1225 0 : return Future.value(attributeResult["Value"]);
1226 : }
1227 : } catch (e) {
1228 0 : EnvironmentConfig.debugLog("error getting profile attribute: $e");
1229 : }
1230 :
1231 0 : return Future.value(null);
1232 : }
1233 :
1234 0 : @override
1235 : Future<String?> GetConversationAttribute(String profile, int conversation, String key) {
1236 0 : var getConversationAttributeC = library.lookup<NativeFunction<get_json_blob_from_str_int_string_function>>("c_GetConversationAttribute");
1237 : // ignore: non_constant_identifier_names
1238 : final GetConversationAttribute = getConversationAttributeC.asFunction<GetJsonBlobFromStrIntStringFn>();
1239 0 : final utf8profile = profile.toNativeUtf8();
1240 0 : final utf8key = key.toNativeUtf8();
1241 0 : Pointer<Utf8> jsonMessageBytes = GetConversationAttribute(utf8profile, utf8profile.length, conversation, utf8key, utf8key.length);
1242 0 : String jsonMessage = jsonMessageBytes.toDartString();
1243 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
1244 0 : malloc.free(utf8profile);
1245 0 : malloc.free(utf8key);
1246 :
1247 : try {
1248 0 : dynamic attributeResult = json.decode(jsonMessage);
1249 0 : if (attributeResult["Exists"]) {
1250 0 : return Future.value(attributeResult["Value"]);
1251 : }
1252 : } catch (e) {
1253 0 : EnvironmentConfig.debugLog("error getting profile attribute: $e");
1254 : }
1255 :
1256 0 : return Future.value(null);
1257 : }
1258 :
1259 0 : @override
1260 : void AttemptReconnection(String profile, String onion) {
1261 : // ignore: non_constant_identifier_names
1262 0 : var peerWithOnionC = library.lookup<NativeFunction<void_from_string_string_function>>("c_PeerWithOnion");
1263 : final PeerWithOnionF = peerWithOnionC.asFunction<VoidFromStringStringFn>();
1264 0 : final utf8profile = profile.toNativeUtf8();
1265 0 : final utf8onion = onion.toNativeUtf8();
1266 0 : PeerWithOnionF(utf8profile, utf8profile.length, utf8onion, utf8onion.length);
1267 0 : malloc.free(utf8profile);
1268 0 : malloc.free(utf8onion);
1269 : }
1270 :
1271 0 : @override
1272 : void AttemptReconnectionServer(String profile, String onion) {
1273 : // ignore: non_constant_identifier_names
1274 0 : var queueJoinServerC = library.lookup<NativeFunction<void_from_string_string_function>>("c_QueueJoinServer");
1275 : final QueueJoinServerC = queueJoinServerC.asFunction<VoidFromStringStringFn>();
1276 0 : final utf8profile = profile.toNativeUtf8();
1277 0 : final utf8onion = onion.toNativeUtf8();
1278 0 : QueueJoinServerC(utf8profile, utf8profile.length, utf8onion, utf8onion.length);
1279 0 : malloc.free(utf8profile);
1280 0 : malloc.free(utf8onion);
1281 : }
1282 :
1283 0 : @override
1284 : void DisconnectFromPeer(String profile, String onion) {
1285 : // ignore: non_constant_identifier_names
1286 0 : var disconnectFromPeerC = library.lookup<NativeFunction<void_from_string_string_function>>("c_DisconnectFromPeer");
1287 : final DisconnectFromPeerC = disconnectFromPeerC.asFunction<VoidFromStringStringFn>();
1288 0 : final utf8profile = profile.toNativeUtf8();
1289 0 : final utf8onion = onion.toNativeUtf8();
1290 0 : DisconnectFromPeerC(utf8profile, utf8profile.length, utf8onion, utf8onion.length);
1291 0 : malloc.free(utf8profile);
1292 0 : malloc.free(utf8onion);
1293 : }
1294 :
1295 0 : @override
1296 : void DisconnectFromServer(String profile, String onion) {
1297 : // ignore: non_constant_identifier_names
1298 0 : var disconnectFromServerC = library.lookup<NativeFunction<void_from_string_string_function>>("c_DisconnectFromServer");
1299 : final DisconnectFromServerC = disconnectFromServerC.asFunction<VoidFromStringStringFn>();
1300 0 : final utf8profile = profile.toNativeUtf8();
1301 0 : final utf8onion = onion.toNativeUtf8();
1302 0 : DisconnectFromServerC(utf8profile, utf8profile.length, utf8onion, utf8onion.length);
1303 0 : malloc.free(utf8profile);
1304 0 : malloc.free(utf8onion);
1305 : }
1306 :
1307 0 : @override
1308 : Future<String> SearchConversations(String profile, String pattern) async {
1309 0 : var searchConversationsC = library.lookup<NativeFunction<string_string_to_string_function>>("c_SearchConversations");
1310 : // ignore: non_constant_identifier_names
1311 : final SearchConversations = searchConversationsC.asFunction<StringFromStringStringFn>();
1312 0 : final utf8profile = profile.toNativeUtf8();
1313 0 : final utf8pattern = pattern.toNativeUtf8();
1314 0 : EnvironmentConfig.debugLog("Searching for $profile $pattern");
1315 0 : Pointer<Utf8> searchIDRaw = SearchConversations(utf8profile, utf8profile.length, utf8pattern, utf8pattern.length);
1316 0 : String searchID = searchIDRaw.toDartString();
1317 0 : _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(searchIDRaw);
1318 0 : malloc.free(utf8profile);
1319 0 : malloc.free(utf8pattern);
1320 : return searchID;
1321 : }
1322 :
1323 0 : @override
1324 : Future<HashMap<String, String>> PlatformChannelInfo() {
1325 0 : return Future.value(HashMap<String, String>());
1326 : }
1327 :
1328 0 : @override
1329 : Future<void> ConfigureConnections(String profile, bool listen, bool peers, bool servers) async {
1330 0 : var configureConnections = library.lookup<NativeFunction<void_from_string_bool_bool_bool>>("c_ConfigureConnections");
1331 : // ignore: non_constant_identifier_names
1332 : final ConfigureConnections = configureConnections.asFunction<VoidFromStringBoolBoolBool>();
1333 0 : final utf8profile = profile.toNativeUtf8();
1334 0 : ConfigureConnections(utf8profile, utf8profile.length, listen, peers, servers);
1335 0 : malloc.free(utf8profile);
1336 : return;
1337 : }
1338 :
1339 0 : @override
1340 : void PublishServerUpdate(String profile) {
1341 0 : var publishServerUpdate = library.lookup<NativeFunction<string_to_void_function>>("c_PublishServerUpdate");
1342 : // ignore: non_constant_identifier_names
1343 : final PublishServerUpdate = publishServerUpdate.asFunction<StringFn>();
1344 0 : final utf8profile = profile.toNativeUtf8();
1345 0 : PublishServerUpdate(utf8profile, utf8profile.length);
1346 0 : malloc.free(utf8profile);
1347 : }
1348 :
1349 0 : @override
1350 : bool IsLoaded() {
1351 0 : bool check = library.providesSymbol("c_UpdateSettings");
1352 0 : EnvironmentConfig.debugLog("Checking that the FFI Interface is Correctly Loaded... $check");
1353 : return check;
1354 : }
1355 : }
|