Use Ksync sync backend
This commit is contained in:
1 parent
6118cfc0ec
commit
cfe51468b7
14 files changed
+238
-174
No files matched your search
@@ -189,6 +189,10 @@ KRYON_WEB_SRCS := $(KRYON_SRCS)
|
||||
KRYON_WINDOWS_SRCS := $(filter-out $(KRYON_DIR)/src/file_dialog/file_dialog.c,$(KRYON_SRCS))
|
||||
KRYON_CLICK_SRCS := $(filter-out $(KRYON_DIR)/src/file_dialog/file_dialog.c,$(KRYON_SRCS))
|
||||
KRYON_INCLUDE := -I$(KRYON_DIR)/include
|
||||
KRYON_SYNC_DIR := $(if $(wildcard $(KRYON_DIR)/src/ksync/ksync_sync.c),ksync,lyra)
|
||||
KRYON_SYNC_ACCOUNT_C := $(if $(filter ksync,$(KRYON_SYNC_DIR)),$(KRYON_DIR)/src/ksync/ksync_account.c,$(KRYON_DIR)/src/lyra/lyra_account.c)
|
||||
KRYON_SYNC_C := $(if $(filter ksync,$(KRYON_SYNC_DIR)),$(KRYON_DIR)/src/ksync/ksync_sync.c,$(KRYON_DIR)/src/lyra/lyra_sync.c)
|
||||
KRYON_SYNC_ACCOUNT_H := $(if $(filter ksync,$(KRYON_SYNC_DIR)),$(KRYON_DIR)/include/ksync_account.h,$(KRYON_DIR)/include/lyra_account.h)
|
||||
KRYON_ALLOW_ICON_REGEN ?= 0
|
||||
KRYON_ICON_ASSETS_DEPS := $(if $(filter 1,$(KRYON_ALLOW_ICON_REGEN)),$(KRYON_ICON_STAMP) $(KRYON_DIR)/scripts/embed-icons.sh,)
|
||||
KRYON_VENDOR_BUILD_DIR := $(NATIVE_VENDOR_BUILD_DIR)
|
||||
@@ -584,17 +588,17 @@ $(LOCALE_KEYS_TEST): tests/locale_keys_test.c $(LOCALE_FILES) | $(TEST_BIN_DIR)
|
||||
-o $@ \
|
||||
tests/locale_keys_test.c
|
||||
|
||||
$(SYNC_URL_TEST): tests/sync_url_test.c src/storage/sync_client.c src/storage/sync_client.h $(KRYON_DIR)/src/lyra/lyra_sync.c $(KRYON_DIR)/src/lyra/lyra_account.c $(CURL_PROTOCOL_CHECK) $(LIBOQS_A) | $(TEST_BIN_DIR)
|
||||
$(SYNC_URL_TEST): tests/sync_url_test.c src/storage/sync_client.c src/storage/sync_client.h $(KRYON_SYNC_C) $(KRYON_SYNC_ACCOUNT_C) $(CURL_PROTOCOL_CHECK) $(LIBOQS_A) | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -Wno-unused-function -std=c99 -D_DEFAULT_SOURCE -DINBE_SYNC_CLIENT_TESTS -DHAS_LIBOQS=1 -ffunction-sections -fdata-sections \
|
||||
-Isrc/storage -Isrc -Isrc/core $(KRYON_INCLUDE) $(KRYON_CURL_CFLAGS) $(LIBOQS_INCLUDE) -o $@ \
|
||||
tests/sync_url_test.c src/storage/sync_client.c $(KRYON_DIR)/src/lyra/lyra_sync.c $(KRYON_DIR)/src/lyra/lyra_account.c \
|
||||
tests/sync_url_test.c src/storage/sync_client.c $(KRYON_SYNC_C) $(KRYON_SYNC_ACCOUNT_C) \
|
||||
$(LIBOQS_A) -Wl,--gc-sections $(KRYON_CURL_LDLIBS) $(NATIVE_SYSTEM_LDLIBS)
|
||||
|
||||
$(SYNC_ACCOUNT_TEST): tests/sync_account_test.c tests/test_locale_stub.c $(KRY_GEN_DIR)/src/storage/sync_account.c src/storage/sync_account.h $(KRYON_DIR)/src/lyra/lyra_account.c $(KRYON_DIR)/include/lyra_account.h src/storage/storage.c $(KRY_GEN_DIR)/src/storage/storage_sessions.c $(KRY_GEN_DIR)/src/storage/sync_review.c $(KRY_GEN_DIR)/src/storage/db_impl.c $(KRY_GEN_DIR)/src/storage/import_impl.c src/storage/storage.h src/storage/db.h src/storage/import.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(LIBOQS_A) | $(TEST_BIN_DIR)
|
||||
$(SYNC_ACCOUNT_TEST): tests/sync_account_test.c tests/test_locale_stub.c $(KRY_GEN_DIR)/src/storage/sync_account.c src/storage/sync_account.h $(KRYON_SYNC_ACCOUNT_C) $(KRYON_SYNC_ACCOUNT_H) src/storage/storage.c $(KRY_GEN_DIR)/src/storage/storage_sessions.c $(KRY_GEN_DIR)/src/storage/sync_review.c $(KRY_GEN_DIR)/src/storage/db_impl.c $(KRY_GEN_DIR)/src/storage/import_impl.c src/storage/storage.h src/storage/db.h src/storage/import.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(LIBOQS_A) | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -D_GNU_SOURCE -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -DHAS_LIBOQS=1 -ffunction-sections -fdata-sections \
|
||||
-Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/practices -Isrc/practices/whm -Isrc/practices/meditation -Isrc/storage -Isrc/platform/android -Isrc/third_party $(KRYON_INCLUDE) -I$(KRY_GEN_DIR) -I$(KRY_GEN_DIR)/src $(LIBOQS_INCLUDE) $(SQLITE_INCLUDE) \
|
||||
-o $@ \
|
||||
tests/sync_account_test.c tests/test_locale_stub.c $(KRY_GEN_DIR)/src/storage/sync_account.c $(KRYON_DIR)/src/lyra/lyra_account.c src/storage/storage.c $(KRY_GEN_DIR)/src/storage/storage_sessions.c $(KRY_GEN_DIR)/src/storage/sync_review.c $(KRY_GEN_DIR)/src/storage/db_impl.c $(KRY_GEN_DIR)/src/storage/import_impl.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
tests/sync_account_test.c tests/test_locale_stub.c $(KRY_GEN_DIR)/src/storage/sync_account.c $(KRYON_SYNC_ACCOUNT_C) src/storage/storage.c $(KRY_GEN_DIR)/src/storage/storage_sessions.c $(KRY_GEN_DIR)/src/storage/sync_review.c $(KRY_GEN_DIR)/src/storage/db_impl.c $(KRY_GEN_DIR)/src/storage/import_impl.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
$(LIBOQS_A) -Wl,--gc-sections $(NATIVE_SYSTEM_LDLIBS)
|
||||
|
||||
$(SYNC_REVIEW_TEST): tests/sync_review_test.c tests/test_locale_stub.c src/storage/storage.c $(KRY_GEN_DIR)/src/storage/storage_sessions.c $(KRY_GEN_DIR)/src/storage/sync_review.c $(KRY_GEN_DIR)/src/storage/db_impl.c $(KRY_GEN_DIR)/src/storage/import_impl.c src/storage/storage.h src/storage/db.h src/storage/import.h $(KRY_GEN_DIR)/src/screens/habits_screen.c src/screens/habits_screen.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) | $(TEST_BIN_DIR)
|
||||
|
||||
@@ -203,7 +203,7 @@ uninstalled.
|
||||
## Notes
|
||||
|
||||
Inbe stores app data locally in SQLite. Optional sync can mirror user-owned
|
||||
data through a Lyra-compatible sync server.
|
||||
data through a Ksync-compatible sync server.
|
||||
|
||||
## Support
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Changed
|
||||
---
|
||||
- Move shared Lyra sync protocol code into Flint and simplify Inbe sync client wiring.
|
||||
- Move shared Ksync sync protocol code into Flint and simplify Inbe sync client wiring.
|
||||
@@ -131,7 +131,8 @@
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const exportedKey = keyText.value.trim();
|
||||
if (!exportedKey.startsWith("lyra-account-key-v1") &&
|
||||
if (!exportedKey.startsWith("ksync-account-key-v1") &&
|
||||
!exportedKey.startsWith("lyra-account-key-v1") &&
|
||||
!exportedKey.startsWith("inbe-sync-key-v1") &&
|
||||
!exportedKey.startsWith("account-key-v1")) {
|
||||
setStatus("error", "Upload the exported account key file.");
|
||||
|
||||
@@ -131,7 +131,8 @@
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const exportedKey = keyText.value.trim();
|
||||
if (!exportedKey.startsWith("lyra-account-key-v1") &&
|
||||
if (!exportedKey.startsWith("ksync-account-key-v1") &&
|
||||
!exportedKey.startsWith("lyra-account-key-v1") &&
|
||||
!exportedKey.startsWith("inbe-sync-key-v1") &&
|
||||
!exportedKey.startsWith("account-key-v1")) {
|
||||
setStatus("error", "Upload the exported account key file.");
|
||||
|
||||
+28
-28
@@ -66,8 +66,8 @@ static g_sync_events_url: [256] char
|
||||
|
||||
#if !WEB {
|
||||
static g_sync_mutex: KryMutex = KRY_MUTEX_INIT
|
||||
static g_sync_result: InbeSyncWorkerResult = {0, LYRA_SYNC_OK, 0}
|
||||
static g_social_result: InbeSocialWorkerResult = {0, LYRA_SYNC_OK, "", "", "", ""}
|
||||
static g_sync_result: InbeSyncWorkerResult = {0, KSYNC_SYNC_OK, 0}
|
||||
static g_social_result: InbeSocialWorkerResult = {0, KSYNC_SYNC_OK, "", "", "", ""}
|
||||
static g_sync_events_running: int = 0
|
||||
} #else {
|
||||
static g_sync_events_retry_at: double = 0.0
|
||||
@@ -171,10 +171,10 @@ app_social_fetch :: (url: const char*, practice: const char*, metric: const char
|
||||
action: const char*, action_value: const char*,
|
||||
requests_json: char*, requests_size: size_t,
|
||||
friends_json: char*, friends_size: size_t,
|
||||
leaderboard_json: char*, leaderboard_size: size_t) -> LyraSyncResult #private {
|
||||
result: LyraSyncResult = LYRA_SYNC_INVALID_URL
|
||||
friends_result: LyraSyncResult = LYRA_SYNC_REQUEST_FAILED
|
||||
leaderboard_result: LyraSyncResult = LYRA_SYNC_REQUEST_FAILED
|
||||
leaderboard_json: char*, leaderboard_size: size_t) -> KsyncSyncResult #private {
|
||||
result: KsyncSyncResult = KSYNC_SYNC_INVALID_URL
|
||||
friends_result: KsyncSyncResult = KSYNC_SYNC_REQUEST_FAILED
|
||||
leaderboard_result: KsyncSyncResult = KSYNC_SYNC_REQUEST_FAILED
|
||||
|
||||
if requests_json != nil && requests_size > 0 {
|
||||
snprintf(requests_json, requests_size, "{\"incoming\":[],\"outgoing\":[]}")
|
||||
@@ -186,37 +186,37 @@ app_social_fetch :: (url: const char*, practice: const char*, metric: const char
|
||||
snprintf(leaderboard_json, leaderboard_size, "{\"rows\":[]}")
|
||||
}
|
||||
if url == nil || url[0] == '\0' {
|
||||
return LYRA_SYNC_INVALID_URL
|
||||
return KSYNC_SYNC_INVALID_URL
|
||||
}
|
||||
|
||||
if action != nil && strcmp(action, "send") == 0 {
|
||||
result = sync_client_send_friend_request(url, action_value)
|
||||
if result != LYRA_SYNC_OK {
|
||||
if result != KSYNC_SYNC_OK {
|
||||
return result
|
||||
}
|
||||
} else if action != nil && strcmp(action, "accept") == 0 {
|
||||
result = sync_client_accept_friend_request(url, action_value)
|
||||
if result != LYRA_SYNC_OK {
|
||||
if result != KSYNC_SYNC_OK {
|
||||
return result
|
||||
}
|
||||
} else if action != nil && strcmp(action, "decline") == 0 {
|
||||
result = sync_client_decline_friend_request(url, action_value)
|
||||
if result != LYRA_SYNC_OK {
|
||||
if result != KSYNC_SYNC_OK {
|
||||
return result
|
||||
}
|
||||
} else if action != nil && strcmp(action, "remove") == 0 {
|
||||
result = sync_client_remove_friend(url, action_value)
|
||||
if result != LYRA_SYNC_OK {
|
||||
if result != KSYNC_SYNC_OK {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
result = sync_client_get_friend_requests(url, requests_json, requests_size)
|
||||
if result != LYRA_SYNC_OK {
|
||||
if result != KSYNC_SYNC_OK {
|
||||
return result
|
||||
}
|
||||
friends_result = sync_client_get_friends(url, friends_json, friends_size)
|
||||
if friends_result != LYRA_SYNC_OK {
|
||||
if friends_result != KSYNC_SYNC_OK {
|
||||
return friends_result
|
||||
}
|
||||
leaderboard_result = sync_client_get_friend_stats(url, "inbe", practice,
|
||||
@@ -286,12 +286,12 @@ app_social_apply_result :: (app: InbeApp*, requests_json: const char*,
|
||||
#if !WEB {
|
||||
app_sync_worker :: (userdata: void*) -> void* #private {
|
||||
args := (InbeSyncWorkerArgs*)userdata
|
||||
result: LyraSyncResult = LYRA_SYNC_INVALID_URL
|
||||
result: KsyncSyncResult = KSYNC_SYNC_INVALID_URL
|
||||
changed := 0
|
||||
|
||||
if args != nil {
|
||||
result = sync_client_sync(args->url)
|
||||
changed = result == LYRA_SYNC_OK && storage_last_sync_changed()
|
||||
changed = result == KSYNC_SYNC_OK && storage_last_sync_changed()
|
||||
free(args)
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ app_social_apply_result :: (app: InbeApp*, requests_json: const char*,
|
||||
|
||||
app_social_worker :: (userdata: void*) -> void* #private {
|
||||
args := (InbeSocialWorkerArgs*)userdata
|
||||
result: LyraSyncResult = LYRA_SYNC_INVALID_URL
|
||||
result: KsyncSyncResult = KSYNC_SYNC_INVALID_URL
|
||||
requests_json: [8192] char
|
||||
friends_json: [8192] char
|
||||
leaderboard_json: [8192] char
|
||||
@@ -350,7 +350,7 @@ app_social_apply_result :: (app: InbeApp*, requests_json: const char*,
|
||||
return nil
|
||||
}
|
||||
while 1 {
|
||||
result: LyraSyncResult
|
||||
result: KsyncSyncResult
|
||||
|
||||
sync_lock()
|
||||
if g_sync.sync_running {
|
||||
@@ -362,11 +362,11 @@ app_social_apply_result :: (app: InbeApp*, requests_json: const char*,
|
||||
|
||||
result = sync_client_wait_for_remote_event(args->url)
|
||||
sync_lock()
|
||||
if result == LYRA_SYNC_OK {
|
||||
if result == KSYNC_SYNC_OK {
|
||||
g_sync.remote_sync_due = 1
|
||||
}
|
||||
sync_unlock()
|
||||
if result != LYRA_SYNC_OK {
|
||||
if result != KSYNC_SYNC_OK {
|
||||
KrySleepSeconds(2)
|
||||
}
|
||||
}
|
||||
@@ -391,7 +391,7 @@ app_collect_finished_sync :: () #private {
|
||||
return
|
||||
}
|
||||
} #else {
|
||||
result: LyraSyncResult
|
||||
result: KsyncSyncResult
|
||||
changed := 0
|
||||
|
||||
if sync_client_web_poll_remote_event() {
|
||||
@@ -406,7 +406,7 @@ app_collect_finished_sync :: () #private {
|
||||
g_sync.sync_running = 0
|
||||
}
|
||||
|
||||
if result == LYRA_SYNC_OK {
|
||||
if result == KSYNC_SYNC_OK {
|
||||
TraceLog(LOG_INFO, "SYNC: background sync complete changed=%d", changed)
|
||||
app_queue_social_refresh()
|
||||
if changed {
|
||||
@@ -414,7 +414,7 @@ app_collect_finished_sync :: () #private {
|
||||
}
|
||||
} else {
|
||||
TraceLog(LOG_WARNING, "SYNC: background sync failed result=%d name=%s",
|
||||
result, GetLyraSyncResultName(result))
|
||||
result, GetKsyncSyncResultName(result))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,7 +671,7 @@ app_apply_pending_social_refresh :: (app: InbeApp*) #private {
|
||||
friends_json: [8192] char
|
||||
leaderboard_json: [8192] char
|
||||
leaderboard_key: [96] char
|
||||
result: LyraSyncResult
|
||||
result: KsyncSyncResult
|
||||
|
||||
app_social_leaderboard_key(leaderboard_key, sizeof(leaderboard_key),
|
||||
app->profile_leaderboard_practice,
|
||||
@@ -685,14 +685,14 @@ app_apply_pending_social_refresh :: (app: InbeApp*) #private {
|
||||
requests_json, sizeof(requests_json),
|
||||
friends_json, sizeof(friends_json),
|
||||
leaderboard_json, sizeof(leaderboard_json))
|
||||
if result == LYRA_SYNC_OK {
|
||||
if result == KSYNC_SYNC_OK {
|
||||
app_social_apply_result(app, requests_json, friends_json,
|
||||
leaderboard_json, leaderboard_key)
|
||||
} else {
|
||||
TraceLog(LOG_WARNING, "SYNC: social refresh failed result=%d name=%s",
|
||||
result, GetLyraSyncResultName(result))
|
||||
result, GetKsyncSyncResultName(result))
|
||||
}
|
||||
if result == LYRA_SYNC_OK {
|
||||
if result == KSYNC_SYNC_OK {
|
||||
app_social_pop_action(action, sizeof(action), action_value,
|
||||
sizeof(action_value))
|
||||
}
|
||||
@@ -728,9 +728,9 @@ app_collect_finished_social_refresh :: (app: InbeApp*) #private {
|
||||
if !finished {
|
||||
return
|
||||
}
|
||||
if result != LYRA_SYNC_OK {
|
||||
if result != KSYNC_SYNC_OK {
|
||||
TraceLog(LOG_WARNING, "SYNC: social refresh failed result=%d name=%s",
|
||||
result, GetLyraSyncResultName(result))
|
||||
result, GetKsyncSyncResultName(result))
|
||||
return
|
||||
}
|
||||
app_social_apply_result(app, requests_json, friends_json,
|
||||
|
||||
@@ -331,17 +331,17 @@ server_connected :: (app: InbeApp*) -> int #private {
|
||||
return strcmp(saved_normalized, url) == 0
|
||||
}
|
||||
|
||||
result_key :: (result: LyraSyncResult) -> const char* #private {
|
||||
if result == LYRA_SYNC_OK {
|
||||
result_key :: (result: KsyncSyncResult) -> const char* #private {
|
||||
if result == KSYNC_SYNC_OK {
|
||||
return "sync_connected"
|
||||
}
|
||||
if result == LYRA_SYNC_INVALID_URL {
|
||||
if result == KSYNC_SYNC_INVALID_URL {
|
||||
return "sync_server_url_invalid"
|
||||
}
|
||||
if result == LYRA_SYNC_NO_ACCOUNT {
|
||||
if result == KSYNC_SYNC_NO_ACCOUNT {
|
||||
return "sync_no_account"
|
||||
}
|
||||
if result == LYRA_SYNC_AUTH_FAILED {
|
||||
if result == KSYNC_SYNC_AUTH_FAILED {
|
||||
return "sync_auth_failed"
|
||||
}
|
||||
return "sync_failed"
|
||||
@@ -369,7 +369,7 @@ create_account :: (app: InbeApp*, account: InbeSyncAccount*) -> int #private {
|
||||
}
|
||||
|
||||
run_connect :: (app: InbeApp*) #private {
|
||||
result: LyraSyncResult
|
||||
result: KsyncSyncResult
|
||||
url: [sizeof(app->sync_server_url)] char
|
||||
|
||||
if app == nil {
|
||||
@@ -382,7 +382,7 @@ run_connect :: (app: InbeApp*) #private {
|
||||
|
||||
storage_set_setting_text(sync_server_url_key, url)
|
||||
result = sync_client_sync(url)
|
||||
if result == LYRA_SYNC_OK {
|
||||
if result == KSYNC_SYNC_OK {
|
||||
app_request_social_refresh(app)
|
||||
if storage_sync_review_clear_if_no_visible_diff() {
|
||||
app_reload_after_import(app, 0)
|
||||
@@ -413,7 +413,7 @@ logout :: (app: InbeApp*) #private {
|
||||
|
||||
clear_remote_confirmed :: (app: InbeApp*) {
|
||||
account: InbeSyncAccount
|
||||
result: LyraSyncResult
|
||||
result: KsyncSyncResult
|
||||
url: [sizeof(app->sync_server_url)] char
|
||||
|
||||
if app == nil {
|
||||
@@ -426,7 +426,7 @@ clear_remote_confirmed :: (app: InbeApp*) {
|
||||
|
||||
if server_normalize(app, url, sizeof(url)) {
|
||||
result = sync_client_delete_account(url)
|
||||
if result != LYRA_SYNC_OK {
|
||||
if result != KSYNC_SYNC_OK {
|
||||
TraceLog(LOG_WARNING, "SYNC: remote account delete failed: %d", result)
|
||||
}
|
||||
} else {
|
||||
@@ -972,7 +972,7 @@ draw_alias_modal :: (app: InbeApp*) -> int {
|
||||
|
||||
TraceLog(LOG_INFO, "SYNC: saving alias @%s with %s",
|
||||
app->sync_alias_input, url)
|
||||
if alias_result == LYRA_SYNC_OK {
|
||||
if alias_result == KSYNC_SYNC_OK {
|
||||
TraceLog(LOG_INFO, "SYNC: alias saved @%s", app->sync_alias_input)
|
||||
result = 1
|
||||
} else {
|
||||
|
||||
@@ -4,15 +4,38 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include("ksync_account.h")
|
||||
#include "ksync_account.h"
|
||||
#else
|
||||
#include "lyra_account.h"
|
||||
#define KSYNC_PUBLIC_ID_HEX_SIZE LYRA_PUBLIC_ID_HEX_SIZE
|
||||
#define KSYNC_PUBLIC_KEY_HEX_SIZE LYRA_PUBLIC_KEY_HEX_SIZE
|
||||
#define KSYNC_PRIVATE_KEY_HEX_SIZE LYRA_PRIVATE_KEY_HEX_SIZE
|
||||
#define KSYNC_ACCOUNT_EXPORT_TEXT_SIZE LYRA_ACCOUNT_EXPORT_TEXT_SIZE
|
||||
#define KsyncAccount LyraAccount
|
||||
#define IsKsyncAccountAvailable IsLyraAccountAvailable
|
||||
#define HasKsyncAccountValues HasLyraAccountValues
|
||||
#define CreateKsyncAccount CreateLyraAccount
|
||||
#define ValidateKsyncAccount ValidateLyraAccount
|
||||
#define ParseKsyncAccountText ParseLyraAccountText
|
||||
#define ExportKsyncAccountText ExportLyraAccountText
|
||||
#define ImportKsyncAccountFile ImportLyraAccountFile
|
||||
#define ExportKsyncAccountFile ExportLyraAccountFile
|
||||
#define KsyncSha256Hex LyraSha256Hex
|
||||
#define SignKsyncAccountHex SignLyraAccountHex
|
||||
#endif
|
||||
#else
|
||||
#include "ksync_account.h"
|
||||
#endif
|
||||
|
||||
enum {
|
||||
INBE_SYNC_PUBLIC_ID_HEX_SIZE = LYRA_PUBLIC_ID_HEX_SIZE,
|
||||
INBE_SYNC_PUBLIC_KEY_HEX_SIZE = LYRA_PUBLIC_KEY_HEX_SIZE,
|
||||
INBE_SYNC_PRIVATE_KEY_HEX_SIZE = LYRA_PRIVATE_KEY_HEX_SIZE
|
||||
INBE_SYNC_PUBLIC_ID_HEX_SIZE = KSYNC_PUBLIC_ID_HEX_SIZE,
|
||||
INBE_SYNC_PUBLIC_KEY_HEX_SIZE = KSYNC_PUBLIC_KEY_HEX_SIZE,
|
||||
INBE_SYNC_PRIVATE_KEY_HEX_SIZE = KSYNC_PRIVATE_KEY_HEX_SIZE
|
||||
};
|
||||
|
||||
typedef LyraAccount InbeSyncAccount;
|
||||
typedef KsyncAccount InbeSyncAccount;
|
||||
|
||||
typedef enum InbeSyncAccountSaveResult {
|
||||
INBE_SYNC_ACCOUNT_SAVE_FAILED = 0,
|
||||
|
||||
@@ -26,7 +26,7 @@ static sync_private_key_key: const char* = "sync_private_key"
|
||||
static sync_account_alias_key: const char* = "sync_account_alias"
|
||||
|
||||
account_has_values :: (account: const InbeSyncAccount*) -> int #private {
|
||||
return HasLyraAccountValues(account)
|
||||
return HasKsyncAccountValues(account)
|
||||
}
|
||||
|
||||
sync_account_write_and_reset :: (account: const InbeSyncAccount*) #private {
|
||||
@@ -46,11 +46,11 @@ sync_account_same_owner :: (owner: const char*, account: const InbeSyncAccount*)
|
||||
}
|
||||
|
||||
sync_sha256_hex :: (data: const uint8_t*, len: size_t, out_hex: [65] char) {
|
||||
LyraSha256Hex(data, len, out_hex)
|
||||
KsyncSha256Hex(data, len, out_hex)
|
||||
}
|
||||
|
||||
sync_account_available :: () -> int {
|
||||
return IsLyraAccountAvailable()
|
||||
return IsKsyncAccountAvailable()
|
||||
}
|
||||
|
||||
sync_account_load :: (account: InbeSyncAccount*) -> int {
|
||||
@@ -85,7 +85,7 @@ sync_account_generate :: (account: InbeSyncAccount*) -> int {
|
||||
return 0
|
||||
}
|
||||
memset(account, 0, sizeof(*account))
|
||||
return CreateLyraAccount(account)
|
||||
return CreateKsyncAccount(account)
|
||||
}
|
||||
|
||||
sync_account_import_private_key_preview :: (account: InbeSyncAccount*,
|
||||
@@ -95,7 +95,7 @@ sync_account_import_private_key_preview :: (account: InbeSyncAccount*,
|
||||
return 0
|
||||
}
|
||||
memset(account, 0, sizeof(*account))
|
||||
if !ImportLyraAccountFile(filename, account) {
|
||||
if !ImportKsyncAccountFile(filename, account) {
|
||||
TraceLog(LOG_WARNING, "SYNC: Private key import failed: invalid key file")
|
||||
return 0
|
||||
}
|
||||
@@ -135,13 +135,13 @@ sync_account_clear :: () -> int {
|
||||
|
||||
sync_account_export_private_key :: (account: const InbeSyncAccount*,
|
||||
filename: const char*) -> int {
|
||||
body: [LYRA_ACCOUNT_EXPORT_TEXT_SIZE] char = {0}
|
||||
body: [KSYNC_ACCOUNT_EXPORT_TEXT_SIZE] char = {0}
|
||||
len: int
|
||||
|
||||
if !account_has_values(account) || filename == nil || filename[0] == '\0' {
|
||||
return 0
|
||||
}
|
||||
if !ExportLyraAccountText(account, body, sizeof(body)) {
|
||||
if !ExportKsyncAccountText(account, body, sizeof(body)) {
|
||||
return 0
|
||||
}
|
||||
len = (int)strlen(body)
|
||||
@@ -174,6 +174,6 @@ sync_account_sign_hex :: (message: const uint8_t*, message_len: size_t,
|
||||
if !sync_account_load(&account) {
|
||||
return 0
|
||||
}
|
||||
return SignLyraAccountHex(&account, message, message_len, out_signature_hex,
|
||||
return SignKsyncAccountHex(&account, message, message_len, out_signature_hex,
|
||||
out_size)
|
||||
}
|
||||
+98
-98
@@ -71,7 +71,7 @@ sync_log_http_failure(const char *step, long status, const char *response)
|
||||
}
|
||||
|
||||
static int sync_load_valid_auth_token(char *out, size_t out_size);
|
||||
static LyraSyncResult sync_client_bearer_request(const char *base_url,
|
||||
static KsyncSyncResult sync_client_bearer_request(const char *base_url,
|
||||
const char *method,
|
||||
const char *path,
|
||||
const char *body,
|
||||
@@ -81,25 +81,25 @@ static LyraSyncResult sync_client_bearer_request(const char *base_url,
|
||||
int
|
||||
sync_client_url_valid(const char *url)
|
||||
{
|
||||
return IsLyraSyncURLValid(url);
|
||||
return IsKsyncSyncURLValid(url);
|
||||
}
|
||||
|
||||
int
|
||||
sync_client_normalize_url(const char *input, char *out, size_t out_size)
|
||||
{
|
||||
return NormalizeLyraSyncURL(input, out, out_size);
|
||||
return NormalizeKsyncSyncURL(input, out, out_size);
|
||||
}
|
||||
|
||||
static int
|
||||
sync_buffer_append(SyncBuffer *buffer, const void *data, size_t bytes)
|
||||
{
|
||||
return AppendLyraSyncBuffer((LyraSyncBuffer *)buffer, data, bytes);
|
||||
return AppendKsyncSyncBuffer((KsyncSyncBuffer *)buffer, data, bytes);
|
||||
}
|
||||
|
||||
static int
|
||||
sync_buffer_append_json_string(SyncBuffer *buffer, const char *text)
|
||||
{
|
||||
return AppendLyraSyncBufferJSONString((LyraSyncBuffer *)buffer, text);
|
||||
return AppendKsyncSyncBufferJSONString((KsyncSyncBuffer *)buffer, text);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -210,13 +210,13 @@ sync_client_test_friend_request_body(const char *target, char *out, size_t out_s
|
||||
static void
|
||||
sync_join_url(char *out, size_t out_size, const char *base_url, const char *path)
|
||||
{
|
||||
JoinLyraSyncURL(out, out_size, base_url, path);
|
||||
JoinKsyncSyncURL(out, out_size, base_url, path);
|
||||
}
|
||||
|
||||
static int
|
||||
sync_join_ws_url(char *out, size_t out_size, const char *base_url, const char *path)
|
||||
{
|
||||
return JoinLyraSyncWebSocketURL(out, out_size, base_url, path);
|
||||
return JoinKsyncSyncWebSocketURL(out, out_size, base_url, path);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -232,7 +232,7 @@ sync_build_message(const char *method, const char *path, const char *nonce_hex,
|
||||
sync_sha256_hex((const uint8_t *)body, strlen(body), body_hash);
|
||||
if(body_hash[0] == '\0')
|
||||
return 0;
|
||||
len = snprintf(out, out_size, "inbe-sync-v1\n%s\n%s\n%s\n%s\n",
|
||||
len = snprintf(out, out_size, "ksync-sync-v1\n%s\n%s\n%s\n%s\n",
|
||||
method, path, body_hash, nonce_hex);
|
||||
return len > 0 && (size_t)len < out_size;
|
||||
}
|
||||
@@ -620,7 +620,7 @@ EM_JS(int, sync_websocket_start_js, (const char *url_ptr, const char *token_ptr)
|
||||
}
|
||||
Module.__inbeSyncWebSocketUrl = url;
|
||||
try {
|
||||
const ws = new WebSocket(url, ["inbe-sync-v1", "bearer." + token]);
|
||||
const ws = new WebSocket(url, ["ksync-sync-v1", "bearer." + token]);
|
||||
Module.__inbeSyncWebSocket = ws;
|
||||
ws.onopen = function() {
|
||||
Module.__inbeSyncWebSocketRetryAt = 0;
|
||||
@@ -719,7 +719,7 @@ typedef struct WebSyncJob {
|
||||
char *payload;
|
||||
char *response_text;
|
||||
long status;
|
||||
LyraSyncResult result;
|
||||
KsyncSyncResult result;
|
||||
int retried_auth;
|
||||
} WebSyncJob;
|
||||
|
||||
@@ -825,9 +825,9 @@ web_sync_start_login(const char *nonce_hex)
|
||||
signature_hex, sizeof(signature_hex)))
|
||||
return 0;
|
||||
sync_join_url(url, sizeof(url), g_web_sync.base_url, INBE_LOGIN_PATH);
|
||||
snprintf(user_header, sizeof(user_header), "X-Inbe-User: %s",
|
||||
snprintf(user_header, sizeof(user_header), "X-Ksync-User: %s",
|
||||
g_web_sync.account.public_id);
|
||||
snprintf(signature_header, sizeof(signature_header), "X-Inbe-Signature: %s",
|
||||
snprintf(signature_header, sizeof(signature_header), "X-Ksync-Signature: %s",
|
||||
signature_hex);
|
||||
headers[0] = "Content-Type: application/json";
|
||||
headers[1] = user_header;
|
||||
@@ -854,7 +854,7 @@ web_sync_start_sync(void)
|
||||
return 0;
|
||||
}
|
||||
sync_join_url(url, sizeof(url), g_web_sync.base_url, INBE_SYNC_PATH);
|
||||
snprintf(user_header, sizeof(user_header), "X-Inbe-User: %s",
|
||||
snprintf(user_header, sizeof(user_header), "X-Ksync-User: %s",
|
||||
g_web_sync.account.public_id);
|
||||
snprintf(auth_header, sizeof(auth_header), "Authorization: Bearer %s", token);
|
||||
headers[0] = "Content-Type: application/json";
|
||||
@@ -890,7 +890,7 @@ sync_client_web_sync_start(const char *base_url)
|
||||
if(!sync_account_load(&g_web_sync.account))
|
||||
return 0;
|
||||
snprintf(g_web_sync.base_url, sizeof(g_web_sync.base_url), "%s", base_url);
|
||||
g_web_sync.result = LYRA_SYNC_OK;
|
||||
g_web_sync.result = KSYNC_SYNC_OK;
|
||||
|
||||
if(sync_load_valid_auth_token(token, sizeof(token)))
|
||||
return web_sync_start_sync();
|
||||
@@ -907,13 +907,13 @@ sync_client_web_sync_start(const char *base_url)
|
||||
}
|
||||
|
||||
int
|
||||
sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
sync_client_web_sync_poll(KsyncSyncResult *result, int *changed)
|
||||
{
|
||||
SyncBuffer response = {0};
|
||||
int poll;
|
||||
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_OK;
|
||||
*result = KSYNC_SYNC_OK;
|
||||
if(changed != NULL)
|
||||
*changed = 0;
|
||||
if(g_web_sync.state == WEB_SYNC_IDLE)
|
||||
@@ -924,7 +924,7 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
return 0;
|
||||
if(poll == 2) {
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_REQUEST_FAILED;
|
||||
*result = KSYNC_SYNC_REQUEST_FAILED;
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
}
|
||||
@@ -932,14 +932,14 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
if(g_web_sync.state == WEB_SYNC_WAIT_CHALLENGE) {
|
||||
char nonce_hex[65];
|
||||
if(g_web_sync.status != 200 ||
|
||||
!FindLyraSyncJSONString(response.data, "nonce", nonce_hex,
|
||||
!FindKsyncSyncJSONString(response.data, "nonce", nonce_hex,
|
||||
sizeof(nonce_hex)) ||
|
||||
strlen(nonce_hex) != 64) {
|
||||
sync_log_http_failure("challenge", g_web_sync.status, response.data);
|
||||
if(result != NULL)
|
||||
*result = g_web_sync.status == 401
|
||||
? LYRA_SYNC_AUTH_FAILED
|
||||
: LYRA_SYNC_CHALLENGE_FAILED;
|
||||
? KSYNC_SYNC_AUTH_FAILED
|
||||
: KSYNC_SYNC_CHALLENGE_FAILED;
|
||||
free(response.data);
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
@@ -947,7 +947,7 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
free(response.data);
|
||||
if(!web_sync_start_login(nonce_hex)) {
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_SIGN_FAILED;
|
||||
*result = KSYNC_SYNC_SIGN_FAILED;
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
}
|
||||
@@ -962,7 +962,7 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
if(g_web_sync.status == 401) {
|
||||
sync_log_http_failure("login auth", g_web_sync.status, response.data);
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_AUTH_FAILED;
|
||||
*result = KSYNC_SYNC_AUTH_FAILED;
|
||||
free(response.data);
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
@@ -970,17 +970,17 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
if(g_web_sync.status < 200 || g_web_sync.status >= 300) {
|
||||
sync_log_http_failure("login", g_web_sync.status, response.data);
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_REQUEST_FAILED;
|
||||
*result = KSYNC_SYNC_REQUEST_FAILED;
|
||||
free(response.data);
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
}
|
||||
expires_in = FindLyraSyncJSONInt64(response.data, "expires_in_seconds", 3600);
|
||||
if(!FindLyraSyncJSONString(response.data, "auth_token", token,
|
||||
expires_in = FindKsyncSyncJSONInt64(response.data, "expires_in_seconds", 3600);
|
||||
if(!FindKsyncSyncJSONString(response.data, "auth_token", token,
|
||||
sizeof(token))) {
|
||||
sync_log_http_failure("login payload", g_web_sync.status, response.data);
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_PAYLOAD_FAILED;
|
||||
*result = KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
free(response.data);
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
@@ -997,7 +997,7 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
free(response.data);
|
||||
if(!web_sync_start_sync()) {
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_PAYLOAD_FAILED;
|
||||
*result = KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
}
|
||||
@@ -1015,14 +1015,14 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
return 0;
|
||||
}
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_AUTH_FAILED;
|
||||
*result = KSYNC_SYNC_AUTH_FAILED;
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
}
|
||||
if(g_web_sync.status < 200 || g_web_sync.status >= 300) {
|
||||
sync_log_http_failure("sync", g_web_sync.status, response.data);
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_REQUEST_FAILED;
|
||||
*result = KSYNC_SYNC_REQUEST_FAILED;
|
||||
free(response.data);
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
@@ -1030,7 +1030,7 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
if(!storage_apply_sync_response_json(response.data)) {
|
||||
sync_log_http_failure("sync payload", g_web_sync.status, response.data);
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_PAYLOAD_FAILED;
|
||||
*result = KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
free(response.data);
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
@@ -1040,14 +1040,14 @@ sync_client_web_sync_poll(LyraSyncResult *result, int *changed)
|
||||
free(response.data);
|
||||
storage_purge_synced_deleted_data();
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_OK;
|
||||
*result = KSYNC_SYNC_OK;
|
||||
web_sync_reset();
|
||||
return 1;
|
||||
}
|
||||
|
||||
web_sync_reset();
|
||||
if(result != NULL)
|
||||
*result = LYRA_SYNC_REQUEST_FAILED;
|
||||
*result = KSYNC_SYNC_REQUEST_FAILED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1079,7 +1079,7 @@ sync_client_web_poll_remote_event(void)
|
||||
static int
|
||||
sync_kryon_http_request(const char *method, const char *url, const char *body,
|
||||
const char *const *headers, int header_count,
|
||||
LyraSyncBuffer *response, long *status, void *user)
|
||||
KsyncSyncBuffer *response, long *status, void *user)
|
||||
{
|
||||
(void)user;
|
||||
return sync_http_request(method, url, body, headers, header_count,
|
||||
@@ -1137,18 +1137,18 @@ sync_kryon_log_http_failure(const char *step, long status,
|
||||
sync_log_http_failure(step, status, response);
|
||||
}
|
||||
|
||||
static LyraSyncConfig
|
||||
static KsyncSyncConfig
|
||||
sync_kryon_config(const char *base_url, const InbeSyncAccount *account)
|
||||
{
|
||||
LyraSyncConfig cfg;
|
||||
KsyncSyncConfig cfg;
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.base_url = base_url;
|
||||
cfg.account = account;
|
||||
cfg.client_id = storage_sync_client_id();
|
||||
cfg.signature_context = "inbe-sync-v1";
|
||||
cfg.user_header_name = "X-Inbe-User";
|
||||
cfg.signature_header_name = "X-Inbe-Signature";
|
||||
cfg.signature_context = "ksync-sync-v1";
|
||||
cfg.user_header_name = "X-Ksync-User";
|
||||
cfg.signature_header_name = "X-Ksync-Signature";
|
||||
cfg.http_request = sync_kryon_http_request;
|
||||
cfg.get_text = sync_kryon_get_text;
|
||||
cfg.set_text = sync_kryon_set_text;
|
||||
@@ -1188,40 +1188,40 @@ sync_client_clear_auth_token(void)
|
||||
storage_set_setting_text(INBE_SYNC_AUTH_TOKEN_EXPIRES_KEY, "");
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_sync(const char *base_url)
|
||||
{
|
||||
InbeSyncAccount account;
|
||||
LyraSyncConfig cfg;
|
||||
KsyncSyncConfig cfg;
|
||||
|
||||
if(!sync_client_url_valid(base_url))
|
||||
return LYRA_SYNC_INVALID_URL;
|
||||
return KSYNC_SYNC_INVALID_URL;
|
||||
if(!sync_account_load(&account))
|
||||
return LYRA_SYNC_NO_ACCOUNT;
|
||||
return KSYNC_SYNC_NO_ACCOUNT;
|
||||
cfg = sync_kryon_config(base_url, &account);
|
||||
return RunLyraSync(&cfg);
|
||||
return RunKsyncSync(&cfg);
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_register_alias(const char *base_url, const char *alias)
|
||||
{
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
(void)base_url;
|
||||
(void)alias;
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
#else
|
||||
InbeSyncAccount account;
|
||||
SyncBuffer body = {0};
|
||||
LyraSyncResult result;
|
||||
KsyncSyncResult result;
|
||||
char response[512];
|
||||
char saved_alias[40];
|
||||
|
||||
if(!sync_client_url_valid(base_url))
|
||||
return LYRA_SYNC_INVALID_URL;
|
||||
return KSYNC_SYNC_INVALID_URL;
|
||||
if(alias == NULL || alias[0] == '\0')
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
if(!sync_account_load(&account))
|
||||
return LYRA_SYNC_NO_ACCOUNT;
|
||||
return KSYNC_SYNC_NO_ACCOUNT;
|
||||
|
||||
if(!sync_buffer_append(&body, "{\"user_id_hash\":", strlen("{\"user_id_hash\":")) ||
|
||||
!sync_buffer_append_json_string(&body, account.public_id) ||
|
||||
@@ -1229,52 +1229,52 @@ sync_client_register_alias(const char *base_url, const char *alias)
|
||||
!sync_buffer_append_json_string(&body, alias) ||
|
||||
!sync_buffer_append(&body, "}", 1)) {
|
||||
free(body.data);
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
}
|
||||
TraceLog(LOG_INFO, "SYNC: alias request alias=@%s", alias);
|
||||
result = sync_client_bearer_request(base_url, "POST", INBE_ACCOUNT_ALIAS_PATH,
|
||||
body.data, response, sizeof(response));
|
||||
free(body.data);
|
||||
if(result != LYRA_SYNC_OK)
|
||||
if(result != KSYNC_SYNC_OK)
|
||||
return result;
|
||||
if(FindLyraSyncJSONString(response, "alias", saved_alias,
|
||||
if(FindKsyncSyncJSONString(response, "alias", saved_alias,
|
||||
sizeof(saved_alias))) {
|
||||
storage_set_setting_text("sync_account_alias", saved_alias);
|
||||
TraceLog(LOG_INFO, "SYNC: alias response stored @%s", saved_alias);
|
||||
} else {
|
||||
TraceLog(LOG_WARNING, "SYNC: alias response missing alias field");
|
||||
}
|
||||
return LYRA_SYNC_OK;
|
||||
return KSYNC_SYNC_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
static LyraSyncResult
|
||||
static KsyncSyncResult
|
||||
sync_client_bearer_request(const char *base_url, const char *method, const char *path,
|
||||
const char *body, char *out, size_t out_size)
|
||||
{
|
||||
InbeSyncAccount account;
|
||||
LyraSyncConfig cfg;
|
||||
KsyncSyncConfig cfg;
|
||||
|
||||
if(!sync_account_load(&account))
|
||||
return LYRA_SYNC_NO_ACCOUNT;
|
||||
return KSYNC_SYNC_NO_ACCOUNT;
|
||||
cfg = sync_kryon_config(base_url, &account);
|
||||
return RequestLyraSyncBearer(&cfg, method, path, body, out, out_size);
|
||||
return RequestKsyncSyncBearer(&cfg, method, path, body, out, out_size);
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_send_friend_request(const char *base_url, const char *target)
|
||||
{
|
||||
SyncBuffer body = {0};
|
||||
LyraSyncResult result;
|
||||
KsyncSyncResult result;
|
||||
char normalized[80];
|
||||
|
||||
if(!sync_client_normalize_friend_target(target, normalized, sizeof(normalized)))
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
if(!sync_buffer_append(&body, "{\"target\":", strlen("{\"target\":")) ||
|
||||
!sync_buffer_append_json_string(&body, normalized) ||
|
||||
!sync_buffer_append(&body, "}", 1)) {
|
||||
free(body.data);
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
}
|
||||
TraceLog(LOG_INFO, "SYNC: friend request target=%s", normalized);
|
||||
result = sync_client_bearer_request(base_url, "POST", INBE_FRIEND_REQUESTS_PATH,
|
||||
@@ -1283,56 +1283,56 @@ sync_client_send_friend_request(const char *base_url, const char *target)
|
||||
return result;
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_get_friend_requests(const char *base_url, char *out, size_t out_size)
|
||||
{
|
||||
return sync_client_bearer_request(base_url, "GET", INBE_FRIEND_REQUESTS_PATH,
|
||||
NULL, out, out_size);
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_get_friends(const char *base_url, char *out, size_t out_size)
|
||||
{
|
||||
return sync_client_bearer_request(base_url, "GET", INBE_FRIENDS_PATH,
|
||||
NULL, out, out_size);
|
||||
}
|
||||
|
||||
static LyraSyncResult
|
||||
static KsyncSyncResult
|
||||
sync_client_friend_request_action(const char *base_url, const char *request_id,
|
||||
const char *action)
|
||||
{
|
||||
char path[256];
|
||||
|
||||
if(request_id == NULL || request_id[0] == '\0' || action == NULL)
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
if(snprintf(path, sizeof(path), "%s/%s/%s", INBE_FRIEND_REQUESTS_PATH,
|
||||
request_id, action) >= (int)sizeof(path))
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
return sync_client_bearer_request(base_url, "POST", path, "{}", NULL, 0);
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_accept_friend_request(const char *base_url, const char *request_id)
|
||||
{
|
||||
return sync_client_friend_request_action(base_url, request_id, "accept");
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_decline_friend_request(const char *base_url, const char *request_id)
|
||||
{
|
||||
return sync_client_friend_request_action(base_url, request_id, "decline");
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_remove_friend(const char *base_url, const char *friend_user_id)
|
||||
{
|
||||
char path[192];
|
||||
|
||||
if(friend_user_id == NULL || friend_user_id[0] == '\0')
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
if(snprintf(path, sizeof(path), "%s/%s", INBE_FRIENDS_PATH,
|
||||
friend_user_id) >= (int)sizeof(path))
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
return sync_client_bearer_request(base_url, "DELETE", path, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
@@ -1367,7 +1367,7 @@ sync_url_append_query(char *url, size_t url_size, const char *key, const char *v
|
||||
return 1;
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_get_friend_stats(const char *base_url, const char *app,
|
||||
const char *practice, const char *metric,
|
||||
char *out, size_t out_size)
|
||||
@@ -1378,7 +1378,7 @@ sync_client_get_friend_stats(const char *base_url, const char *app,
|
||||
if(!sync_url_append_query(path, sizeof(path), "app", app != NULL ? app : "inbe") ||
|
||||
!sync_url_append_query(path, sizeof(path), "practice", practice) ||
|
||||
!sync_url_append_query(path, sizeof(path), "metric", metric))
|
||||
return LYRA_SYNC_PAYLOAD_FAILED;
|
||||
return KSYNC_SYNC_PAYLOAD_FAILED;
|
||||
return sync_client_bearer_request(base_url, "GET", path, NULL, out, out_size);
|
||||
}
|
||||
|
||||
@@ -1403,7 +1403,7 @@ sync_client_test_friend_stats_path(const char *app, const char *practice,
|
||||
}
|
||||
#endif
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_wait_for_remote_event(const char *base_url)
|
||||
{
|
||||
#if ANDROID_BUILD
|
||||
@@ -1416,13 +1416,13 @@ sync_client_wait_for_remote_event(const char *base_url)
|
||||
long status = 0;
|
||||
|
||||
if(!sync_client_url_valid(base_url))
|
||||
return LYRA_SYNC_INVALID_URL;
|
||||
return KSYNC_SYNC_INVALID_URL;
|
||||
if(!sync_account_load(&account))
|
||||
return LYRA_SYNC_NO_ACCOUNT;
|
||||
return KSYNC_SYNC_NO_ACCOUNT;
|
||||
if(!sync_load_valid_auth_token(token, sizeof(token)))
|
||||
return LYRA_SYNC_AUTH_FAILED;
|
||||
return KSYNC_SYNC_AUTH_FAILED;
|
||||
if(!sync_join_ws_url(ws_url, sizeof(ws_url), base_url, INBE_SYNC_WS_PATH))
|
||||
return LYRA_SYNC_INVALID_URL;
|
||||
return KSYNC_SYNC_INVALID_URL;
|
||||
snprintf(auth_header, sizeof(auth_header), "Authorization: Bearer %s", token);
|
||||
headers[0] = auth_header;
|
||||
|
||||
@@ -1431,21 +1431,21 @@ sync_client_wait_for_remote_event(const char *base_url)
|
||||
if(status == 401)
|
||||
sync_client_clear_auth_token();
|
||||
free(response.data);
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
}
|
||||
if(status != 101) {
|
||||
TraceLog(LOG_WARNING, "SYNC: websocket connect failed http=%ld url=%s", status, ws_url);
|
||||
if(status == 401)
|
||||
sync_client_clear_auth_token();
|
||||
free(response.data);
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
}
|
||||
if(response.data != NULL && strstr(response.data, "\"type\":\"sync_changed\"") != NULL) {
|
||||
free(response.data);
|
||||
return LYRA_SYNC_OK;
|
||||
return KSYNC_SYNC_OK;
|
||||
}
|
||||
free(response.data);
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
#elif !defined(__EMSCRIPTEN__)
|
||||
InbeSyncAccount account;
|
||||
char token[4096];
|
||||
@@ -1459,19 +1459,19 @@ sync_client_wait_for_remote_event(const char *base_url)
|
||||
size_t message_len = 0;
|
||||
|
||||
if(!sync_client_url_valid(base_url))
|
||||
return LYRA_SYNC_INVALID_URL;
|
||||
return KSYNC_SYNC_INVALID_URL;
|
||||
if(!sync_account_load(&account))
|
||||
return LYRA_SYNC_NO_ACCOUNT;
|
||||
return KSYNC_SYNC_NO_ACCOUNT;
|
||||
if(!sync_load_valid_auth_token(token, sizeof(token)))
|
||||
return LYRA_SYNC_AUTH_FAILED;
|
||||
return KSYNC_SYNC_AUTH_FAILED;
|
||||
if(!sync_join_ws_url(ws_url, sizeof(ws_url), base_url, INBE_SYNC_WS_PATH))
|
||||
return LYRA_SYNC_INVALID_URL;
|
||||
return KSYNC_SYNC_INVALID_URL;
|
||||
snprintf(auth_header, sizeof(auth_header), "Authorization: Bearer %s", token);
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
if(curl == NULL)
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
curl_headers = curl_slist_append(curl_headers, auth_header);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, ws_url);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L);
|
||||
@@ -1490,7 +1490,7 @@ sync_client_wait_for_remote_event(const char *base_url)
|
||||
sync_client_clear_auth_token();
|
||||
curl_slist_free_all(curl_headers);
|
||||
curl_easy_cleanup(curl);
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
}
|
||||
curl_slist_free_all(curl_headers);
|
||||
|
||||
@@ -1513,16 +1513,16 @@ sync_client_wait_for_remote_event(const char *base_url)
|
||||
}
|
||||
if(code == CURLE_GOT_NOTHING) {
|
||||
curl_easy_cleanup(curl);
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
}
|
||||
if(code != CURLE_OK) {
|
||||
TraceLog(LOG_WARNING, "SYNC: websocket recv failed code=%d", (int)code);
|
||||
curl_easy_cleanup(curl);
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
}
|
||||
if(meta != NULL && (meta->flags & CURLWS_CLOSE)) {
|
||||
curl_easy_cleanup(curl);
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
}
|
||||
if(meta != NULL && !(meta->flags & CURLWS_TEXT))
|
||||
continue;
|
||||
@@ -1537,27 +1537,27 @@ sync_client_wait_for_remote_event(const char *base_url)
|
||||
continue;
|
||||
if(strstr(message, "\"type\":\"sync_changed\"") != NULL) {
|
||||
curl_easy_cleanup(curl);
|
||||
return LYRA_SYNC_OK;
|
||||
return KSYNC_SYNC_OK;
|
||||
}
|
||||
message_len = 0;
|
||||
message[0] = '\0';
|
||||
}
|
||||
#else
|
||||
(void)base_url;
|
||||
return LYRA_SYNC_REQUEST_FAILED;
|
||||
return KSYNC_SYNC_REQUEST_FAILED;
|
||||
#endif
|
||||
}
|
||||
|
||||
LyraSyncResult
|
||||
KsyncSyncResult
|
||||
sync_client_delete_account(const char *base_url)
|
||||
{
|
||||
InbeSyncAccount account;
|
||||
LyraSyncConfig cfg;
|
||||
KsyncSyncConfig cfg;
|
||||
|
||||
if(!sync_client_url_valid(base_url))
|
||||
return LYRA_SYNC_INVALID_URL;
|
||||
return KSYNC_SYNC_INVALID_URL;
|
||||
if(!sync_account_load(&account))
|
||||
return LYRA_SYNC_NO_ACCOUNT;
|
||||
return KSYNC_SYNC_NO_ACCOUNT;
|
||||
cfg = sync_kryon_config(base_url, &account);
|
||||
return DeleteLyraSyncAccount(&cfg);
|
||||
return DeleteKsyncSyncAccount(&cfg);
|
||||
}
|
||||
+46
-12
@@ -1,32 +1,66 @@
|
||||
#ifndef INBE_SYNC_CLIENT_H
|
||||
#define INBE_SYNC_CLIENT_H
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include("ksync_sync.h")
|
||||
#include "ksync_sync.h"
|
||||
#else
|
||||
#include "lyra_sync.h"
|
||||
#define KsyncSyncResult LyraSyncResult
|
||||
#define KSYNC_SYNC_OK LYRA_SYNC_OK
|
||||
#define KSYNC_SYNC_INVALID_URL LYRA_SYNC_INVALID_URL
|
||||
#define KSYNC_SYNC_NO_ACCOUNT LYRA_SYNC_NO_ACCOUNT
|
||||
#define KSYNC_SYNC_PAYLOAD_FAILED LYRA_SYNC_PAYLOAD_FAILED
|
||||
#define KSYNC_SYNC_CHALLENGE_FAILED LYRA_SYNC_CHALLENGE_FAILED
|
||||
#define KSYNC_SYNC_SIGN_FAILED LYRA_SYNC_SIGN_FAILED
|
||||
#define KSYNC_SYNC_REQUEST_FAILED LYRA_SYNC_REQUEST_FAILED
|
||||
#define KSYNC_SYNC_AUTH_FAILED LYRA_SYNC_AUTH_FAILED
|
||||
#define KsyncSyncBuffer LyraSyncBuffer
|
||||
#define KsyncSyncConfig LyraSyncConfig
|
||||
#define AppendKsyncSyncBuffer AppendLyraSyncBuffer
|
||||
#define AppendKsyncSyncBufferJSONString AppendLyraSyncBufferJSONString
|
||||
#define FreeKsyncSyncBuffer FreeLyraSyncBuffer
|
||||
#define FindKsyncSyncJSONString FindLyraSyncJSONString
|
||||
#define FindKsyncSyncJSONInt64 FindLyraSyncJSONInt64
|
||||
#define GetKsyncSyncResultName GetLyraSyncResultName
|
||||
#define IsKsyncSyncURLValid IsLyraSyncURLValid
|
||||
#define NormalizeKsyncSyncURL NormalizeLyraSyncURL
|
||||
#define JoinKsyncSyncURL JoinLyraSyncURL
|
||||
#define JoinKsyncSyncWebSocketURL JoinLyraSyncWebSocketURL
|
||||
#define ClearKsyncSyncAuthToken ClearLyraSyncAuthToken
|
||||
#define LoginKsyncSync LoginLyraSync
|
||||
#define RunKsyncSync RunLyraSync
|
||||
#define RequestKsyncSyncBearer RequestLyraSyncBearer
|
||||
#define DeleteKsyncSyncAccount DeleteLyraSyncAccount
|
||||
#endif
|
||||
#else
|
||||
#include "ksync_sync.h"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int sync_client_url_valid(const char *url);
|
||||
int sync_client_normalize_url(const char *input, char *out, size_t out_size);
|
||||
int sync_client_normalize_friend_target(const char *target, char *out, size_t out_size);
|
||||
LyraSyncResult sync_client_sync(const char *base_url);
|
||||
LyraSyncResult sync_client_register_alias(const char *base_url, const char *alias);
|
||||
LyraSyncResult sync_client_send_friend_request(const char *base_url, const char *target);
|
||||
LyraSyncResult sync_client_get_friend_requests(const char *base_url, char *out, size_t out_size);
|
||||
LyraSyncResult sync_client_get_friends(const char *base_url, char *out, size_t out_size);
|
||||
LyraSyncResult sync_client_accept_friend_request(const char *base_url, const char *request_id);
|
||||
LyraSyncResult sync_client_decline_friend_request(const char *base_url, const char *request_id);
|
||||
LyraSyncResult sync_client_remove_friend(const char *base_url, const char *friend_user_id);
|
||||
LyraSyncResult sync_client_get_friend_stats(const char *base_url, const char *app,
|
||||
KsyncSyncResult sync_client_sync(const char *base_url);
|
||||
KsyncSyncResult sync_client_register_alias(const char *base_url, const char *alias);
|
||||
KsyncSyncResult sync_client_send_friend_request(const char *base_url, const char *target);
|
||||
KsyncSyncResult sync_client_get_friend_requests(const char *base_url, char *out, size_t out_size);
|
||||
KsyncSyncResult sync_client_get_friends(const char *base_url, char *out, size_t out_size);
|
||||
KsyncSyncResult sync_client_accept_friend_request(const char *base_url, const char *request_id);
|
||||
KsyncSyncResult sync_client_decline_friend_request(const char *base_url, const char *request_id);
|
||||
KsyncSyncResult sync_client_remove_friend(const char *base_url, const char *friend_user_id);
|
||||
KsyncSyncResult sync_client_get_friend_stats(const char *base_url, const char *app,
|
||||
const char *practice, const char *metric,
|
||||
char *out, size_t out_size);
|
||||
LyraSyncResult sync_client_wait_for_remote_event(const char *base_url);
|
||||
LyraSyncResult sync_client_delete_account(const char *base_url);
|
||||
KsyncSyncResult sync_client_wait_for_remote_event(const char *base_url);
|
||||
KsyncSyncResult sync_client_delete_account(const char *base_url);
|
||||
void sync_client_clear_auth_token(void);
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
int sync_client_web_start_remote_events(const char *base_url);
|
||||
int sync_client_web_poll_remote_event(void);
|
||||
int sync_client_web_sync_start(const char *base_url);
|
||||
int sync_client_web_sync_poll(LyraSyncResult *result, int *changed);
|
||||
int sync_client_web_sync_poll(KsyncSyncResult *result, int *changed);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -281,7 +281,8 @@ test_import_export_clear(void)
|
||||
exported = LoadFileText(export_path);
|
||||
check_true("read exported key", exported != NULL);
|
||||
if(exported != NULL) {
|
||||
check_true("export uses generic key header",
|
||||
check_true("export uses accepted key header",
|
||||
strstr(exported, "ksync-account-key-v1\n") == exported ||
|
||||
strstr(exported, "lyra-account-key-v1\n") == exported);
|
||||
check_true("export includes public key", strstr(exported, "\npublic_key=") != NULL);
|
||||
UnloadFileText(exported);
|
||||
|
||||
@@ -338,7 +338,7 @@ remote_snapshot_response(void)
|
||||
"00Z\"}],"
|
||||
"\"sessions\":[{\"id\":\"remote-session\",\"started_at\":\"2026-06-"
|
||||
"24T10:00:00Z\","
|
||||
"\"local_date\":20260624,\"topic\":2,\"activity\":2,\"source\":\"lyra-"
|
||||
"\"local_date\":20260624,\"topic\":2,\"activity\":2,\"source\":\"ksync-"
|
||||
"test\","
|
||||
"\"rounds_hash\":202,\"deleted_at\":0,\"updated_at\":\"2026-06-24T10:"
|
||||
"00:00Z\","
|
||||
@@ -361,7 +361,7 @@ deleted_only_remote_snapshot_response(void)
|
||||
"\"habit_days\":[],"
|
||||
"\"sessions\":[{\"id\":\"deleted-session\",\"started_at\":\"2026-06-"
|
||||
"24T10:00:00Z\","
|
||||
"\"local_date\":20260624,\"topic\":2,\"activity\":3,\"source\":\"lyra-"
|
||||
"\"local_date\":20260624,\"topic\":2,\"activity\":3,\"source\":\"ksync-"
|
||||
"test\","
|
||||
"\"rounds_hash\":202,\"deleted_at\":1782300000,\"updated_at\":\"2026-"
|
||||
"06-24T10:00:00Z\","
|
||||
@@ -414,7 +414,7 @@ remote_clean_v3_response(void)
|
||||
"\"habit_days\":[{\"habit_id\":\"clean-habit\",\"local_date\":20260624,"
|
||||
"\"completed\":true,\"count\":5,\"updated_at\":\"2026-06-24T10:00:00Z\"}],"
|
||||
"\"sessions\":[{\"id\":\"clean-session\",\"started_at\":\"2026-06-24T10:00:00Z\","
|
||||
"\"local_date\":20260624,\"topic\":2,\"activity\":2,\"source\":\"lyra-test\","
|
||||
"\"local_date\":20260624,\"topic\":2,\"activity\":2,\"source\":\"ksync-test\","
|
||||
"\"rounds_hash\":505,\"deleted_at\":0,\"updated_at\":\"2026-06-24T10:00:00Z\","
|
||||
"\"rounds\":[{\"round_index\":0,\"hold_seconds\":44}]}],"
|
||||
"\"meditation_logs\":[]"
|
||||
@@ -436,7 +436,7 @@ remote_tiny_session_snapshot_response(void)
|
||||
"\"habit_days\":[],"
|
||||
"\"sessions\":[{\"id\":\"tiny-remote-session\",\"started_at\":\"2026-06-24T10:"
|
||||
"05:00Z\","
|
||||
"\"local_date\":20260624,\"topic\":1,\"activity\":1,\"source\":\"lyra-"
|
||||
"\"local_date\":20260624,\"topic\":1,\"activity\":1,\"source\":\"ksync-"
|
||||
"test\","
|
||||
"\"rounds_hash\":404,\"deleted_at\":0,\"updated_at\":\"2026-06-24T10:"
|
||||
"05:00Z\","
|
||||
|
||||
Vendored
+1
-1
Submodule vendor/kryon updated: c26b7ec943...7e8f316eb5.
Reference in new issue
Block a user