2021-08-22 15:34:28 -04:00
|
|
|
#pragma once
|
|
|
|
|
2023-01-17 19:37:45 -05:00
|
|
|
#include "ssb.h"
|
|
|
|
|
2023-05-21 17:36:51 -04:00
|
|
|
#include "quickjs.h"
|
|
|
|
|
2021-08-22 15:34:28 -04:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
typedef struct _tf_ssb_t tf_ssb_t;
|
|
|
|
|
|
|
|
void tf_ssb_db_init(tf_ssb_t* ssb);
|
2023-02-17 17:43:19 -05:00
|
|
|
void tf_ssb_db_init_reader(sqlite3* db);
|
2021-08-22 15:41:27 -04:00
|
|
|
bool tf_ssb_db_message_content_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_t* out_size);
|
2022-11-16 20:49:34 -05:00
|
|
|
bool tf_ssb_db_blob_has(tf_ssb_t* ssb, const char* id);
|
2021-08-22 15:41:27 -04:00
|
|
|
bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_t* out_size);
|
2023-07-18 19:46:15 -04:00
|
|
|
|
2023-07-19 21:02:50 -04:00
|
|
|
typedef void (tf_ssb_db_store_message_callback_t)(const char* id, bool stored, void* user_data);
|
|
|
|
void tf_ssb_db_store_message(tf_ssb_t* ssb, JSContext* context, const char* id, JSValue val, const char* signature, bool sequence_before_author, tf_ssb_db_store_message_callback_t* callback, void* user_data);
|
|
|
|
|
2023-07-18 19:46:15 -04:00
|
|
|
typedef void (tf_ssb_db_blob_store_callback_t)(const char* id, bool is_new, void* user_data);
|
|
|
|
void tf_ssb_db_blob_store_async(tf_ssb_t* ssb, const uint8_t* blob, size_t size, tf_ssb_db_blob_store_callback_t* callback, void* user_data);
|
2022-10-12 08:27:32 -04:00
|
|
|
bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* out_id, size_t out_id_size, bool* out_new);
|
2021-08-22 15:34:28 -04:00
|
|
|
|
2023-01-08 12:45:15 -05:00
|
|
|
JSValue tf_ssb_db_get_message_by_id( tf_ssb_t* ssb, const char* id, bool is_keys);
|
2022-02-11 20:44:11 -05:00
|
|
|
bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* author, int64_t sequence, char* out_message_id, size_t out_message_id_size, double* out_timestamp, char** out_content);
|
2021-08-22 15:41:27 -04:00
|
|
|
bool tf_ssb_db_get_latest_message_by_author(tf_ssb_t* ssb, const char* author, int64_t* out_sequence, char* out_message_id, size_t out_message_id_size);
|
2022-04-17 20:24:00 -04:00
|
|
|
JSValue tf_ssb_db_visit_query(tf_ssb_t* ssb, const char* query, const JSValue binds, void (*callback)(JSValue row, void* user_data), void* user_data);
|
2022-02-09 22:58:33 -05:00
|
|
|
|
|
|
|
typedef struct sqlite3 sqlite3;
|
2022-02-10 21:44:27 -05:00
|
|
|
bool tf_ssb_db_check(sqlite3* db, const char* author);
|
2022-07-13 21:01:14 -04:00
|
|
|
|
|
|
|
int tf_ssb_db_identity_get_count_for_user(tf_ssb_t* ssb, const char* user);
|
2022-10-14 08:27:34 -04:00
|
|
|
bool tf_ssb_db_identity_create(tf_ssb_t* ssb, const char* user, uint8_t* out_public_key, uint8_t* out_private_key);
|
2022-07-13 21:01:14 -04:00
|
|
|
bool tf_ssb_db_identity_add(tf_ssb_t* ssb, const char* user, const char* public_key, const char* private_key);
|
|
|
|
void tf_ssb_db_identity_visit(tf_ssb_t* ssb, const char* user, void (*callback)(const char* identity, void* user_data), void* user_data);
|
2022-07-31 15:01:08 -04:00
|
|
|
void tf_ssb_db_identity_visit_all(tf_ssb_t* ssb, void (*callback)(const char* identity, void* user_data), void* user_data);
|
2022-07-13 21:01:14 -04:00
|
|
|
bool tf_ssb_db_identity_get_private_key(tf_ssb_t* ssb, const char* user, const char* public_key, uint8_t* out_private_key, size_t private_key_size);
|
2022-08-14 22:23:45 -04:00
|
|
|
|
2023-01-08 12:45:15 -05:00
|
|
|
JSValue tf_ssb_format_message(
|
|
|
|
JSContext* context,
|
|
|
|
const char* previous,
|
|
|
|
const char* author,
|
|
|
|
int64_t sequence,
|
|
|
|
double timestamp,
|
|
|
|
const char* hash,
|
|
|
|
const char* content,
|
|
|
|
const char* signature,
|
|
|
|
bool sequence_before_author);
|
2023-11-02 20:45:30 -04:00
|
|
|
|
|
|
|
typedef struct _tf_ssb_following_t
|
|
|
|
{
|
|
|
|
char id[k_id_base64_len];
|
|
|
|
int following_count;
|
|
|
|
int blocking_count;
|
|
|
|
int followed_by_count;
|
|
|
|
int blocked_by_count;
|
|
|
|
} tf_ssb_following_t;
|
|
|
|
|
|
|
|
const char** tf_ssb_db_following_deep_ids(tf_ssb_t* ssb, const char** ids, int count, int depth);
|
|
|
|
tf_ssb_following_t* tf_ssb_db_following_deep(tf_ssb_t* ssb, const char** ids, int count, int depth);
|
2023-01-08 15:01:35 -05:00
|
|
|
const char** tf_ssb_db_get_all_visible_identities(tf_ssb_t* ssb, int depth);
|
2022-12-31 16:44:48 -05:00
|
|
|
|
2023-01-17 19:37:45 -05:00
|
|
|
typedef struct _tf_ssb_db_stored_connection_t
|
|
|
|
{
|
|
|
|
char address[256];
|
|
|
|
int port;
|
|
|
|
char pubkey[k_id_base64_len];
|
|
|
|
} tf_ssb_db_stored_connection_t;
|
|
|
|
|
|
|
|
tf_ssb_db_stored_connection_t* tf_ssb_db_get_stored_connections(tf_ssb_t* ssb, int* out_count);
|
|
|
|
void tf_ssb_db_forget_stored_connection(tf_ssb_t* ssb, const char* address, int port, const char* pubkey);
|
2023-08-16 18:43:08 -04:00
|
|
|
|
|
|
|
int tf_ssb_sqlite_authorizer(void* user_data, int action_code, const char* arg0, const char* arg1, const char* arg2, const char* arg3);
|