Tilde Friends
ssb.db.h
1#pragma once
2
10#include "ssb.h"
11
12#include "quickjs.h"
13
14#include <stdbool.h>
15
17typedef struct _tf_ssb_t tf_ssb_t;
18
24
29
38bool tf_ssb_db_message_content_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_t* out_size);
39
46bool tf_ssb_db_blob_has(sqlite3* db, const char* id);
47
56bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_t* out_size);
57
65typedef void(tf_ssb_db_blob_get_callback_t)(bool found, const uint8_t* data, size_t size, void* user_data);
66
74void tf_ssb_db_blob_get_async(tf_ssb_t* ssb, const char* id, tf_ssb_db_blob_get_callback_t* callback, void* user_data);
75
82typedef void(tf_ssb_db_store_message_callback_t)(const char* id, bool stored, void* user_data);
83
96 tf_ssb_t* ssb, JSContext* context, const char* id, JSValue val, const char* signature, int flags, tf_ssb_db_store_message_callback_t* callback, void* user_data);
97
104typedef void(tf_ssb_db_blob_store_callback_t)(const char* id, bool is_new, void* user_data);
105
114void 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);
115
125bool 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);
126
134JSValue tf_ssb_db_get_message_by_id(tf_ssb_t* ssb, const char* id, bool is_keys);
135
154bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* author, int32_t sequence, char* out_message_id, size_t out_message_id_size, char* out_previous,
155 size_t out_previous_size, double* out_timestamp, char** out_content, char* out_hash, size_t out_hash_size, char* out_signature, size_t out_signature_size, int* out_flags);
156
166bool tf_ssb_db_get_latest_message_by_author(tf_ssb_t* ssb, const char* author, int32_t* out_sequence, char* out_message_id, size_t out_message_id_size);
167
177JSValue 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);
178
185bool tf_ssb_db_check(sqlite3* db, const char* author);
186
194
203bool tf_ssb_db_identity_create(tf_ssb_t* ssb, const char* user, uint8_t* out_public_key, uint8_t* out_private_key);
204
212bool tf_ssb_db_identity_delete(tf_ssb_t* ssb, const char* user, const char* public_key);
213
221bool tf_ssb_db_identity_add(tf_ssb_t* ssb, const char* user, const char* public_key, const char* private_key);
222
233bool tf_ssb_db_identity_get_active(sqlite3* db, const char* user, const char* package_owner, const char* package_name, char* out_identity, size_t out_identity_size);
234
242void tf_ssb_db_identity_visit(tf_ssb_t* ssb, const char* user, void (*callback)(const char* identity, void* user_data), void* user_data);
243
250void tf_ssb_db_identity_visit_all(tf_ssb_t* ssb, void (*callback)(const char* identity, void* user_data), void* user_data);
251
258const char* tf_ssb_db_get_user_for_identity(tf_ssb_t* ssb, const char* public_key);
259
269bool 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);
270
284 JSContext* context, const char* previous, const char* author, int32_t sequence, double timestamp, const char* hash, const char* content, const char* signature, int flags);
285
288{
298 int depth;
300 char id[k_id_base64_len];
302
311const char** tf_ssb_db_following_deep_ids(tf_ssb_t* ssb, const char** ids, int count, int depth);
312
322tf_ssb_following_t* tf_ssb_db_following_deep(tf_ssb_t* ssb, const char** ids, int count, int depth, bool include_blocks);
323
330const char** tf_ssb_db_get_all_visible_identities(tf_ssb_t* ssb, int depth);
331
336{
338 char address[256];
340 int port;
342 char pubkey[k_id_base64_len];
348
356
364void tf_ssb_db_forget_stored_connection(tf_ssb_t* ssb, const char* address, int port, const char* pubkey);
365
374bool tf_ssb_db_get_account_password_hash(tf_ssb_t* ssb, const char* name, char* out_password, size_t password_size);
375
385bool tf_ssb_db_set_account_password(uv_loop_t* loop, sqlite3* db, JSContext* context, const char* name, const char* password);
386
396bool tf_ssb_db_register_account(uv_loop_t* loop, sqlite3* db, JSContext* context, const char* name, const char* password);
397
405const char* tf_ssb_db_get_property(tf_ssb_t* ssb, const char* id, const char* key);
406
415bool tf_ssb_db_set_property(tf_ssb_t* ssb, const char* id, const char* key, const char* value);
416
424bool tf_ssb_db_remove_property(tf_ssb_t* ssb, const char* id, const char* key);
425
434bool tf_ssb_db_remove_value_from_array_property(tf_ssb_t* ssb, const char* id, const char* key, const char* value);
435
444bool tf_ssb_db_add_value_to_array_property(tf_ssb_t* ssb, const char* id, const char* key, const char* value);
445
453void tf_ssb_db_resolve_index_async(tf_ssb_t* ssb, const char* host, void (*callback)(const char* path, void* user_data), void* user_data);
454
463bool tf_ssb_db_verify(tf_ssb_t* ssb, const char* id, int32_t debug_sequence, bool fix);
464
473bool tf_ssb_db_user_has_permission(tf_ssb_t* ssb, sqlite3* db, const char* id, const char* permission);
474
482bool tf_ssb_db_get_global_setting_bool(sqlite3* db, const char* name, bool* out_value);
483
491bool tf_ssb_db_get_global_setting_int64(sqlite3* db, const char* name, int64_t* out_value);
492
501bool tf_ssb_db_get_global_setting_string(sqlite3* db, const char* name, char* out_value, size_t size);
502
510bool tf_ssb_db_set_global_setting_from_string(sqlite3* db, const char* name, char* value);
511
518const char* tf_ssb_db_get_profile(sqlite3* db, const char* id);
519
526const char* tf_ssb_db_get_profile_name(sqlite3* db, const char* id);
527
540bool tf_ssb_db_generate_invite(sqlite3* db, const char* id, const char* host, int port, int use_count, int expires_seconds, char* out_invite, size_t size);
541
548bool tf_ssb_db_use_invite(sqlite3* db, const char* id);
549
559bool tf_ssb_db_is_account_familiar(sqlite3* db, const char* id, int depth);
560
571int tf_ssb_sqlite_authorizer(void* user_data, int action_code, const char* arg0, const char* arg1, const char* arg2, const char* arg3);
572
579bool tf_ssb_db_has_invite(sqlite3* db, const char* id);
580
585{
587 const char** identity;
589 const char** name;
591 int count;
593 char active_identity[k_id_base64_len];
595
604tf_ssb_identity_info_t* tf_ssb_db_get_identity_info(tf_ssb_t* ssb, const char* user, const char* package_owner, const char* package_name);
605
611void tf_ssb_db_add_blob_wants(sqlite3* db, const char* id);
612
struct JSContext JSContext
Definition: api.js.h:10
struct uv_loop_s uv_loop_t
Definition: http.h:33
struct _tf_ssb_t tf_ssb_t
Definition: httpd.js.h:38
bool tf_ssb_db_user_has_permission(tf_ssb_t *ssb, sqlite3 *db, const char *id, const char *permission)
const char * tf_ssb_db_get_profile_name(sqlite3 *db, const char *id)
tf_ssb_following_t * tf_ssb_db_following_deep(tf_ssb_t *ssb, const char **ids, int count, int depth, bool include_blocks)
const char * tf_ssb_db_get_profile(sqlite3 *db, const char *id)
bool tf_ssb_db_remove_value_from_array_property(tf_ssb_t *ssb, const char *id, const char *key, const char *value)
struct _tf_ssb_identity_info_t tf_ssb_identity_info_t
bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t *ssb, const char *author, int32_t sequence, char *out_message_id, size_t out_message_id_size, char *out_previous, size_t out_previous_size, double *out_timestamp, char **out_content, char *out_hash, size_t out_hash_size, char *out_signature, size_t out_signature_size, int *out_flags)
bool tf_ssb_db_use_invite(sqlite3 *db, const char *id)
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)
void tf_ssb_db_identity_visit(tf_ssb_t *ssb, const char *user, void(*callback)(const char *identity, void *user_data), void *user_data)
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)
bool tf_ssb_db_message_content_get(tf_ssb_t *ssb, const char *id, uint8_t **out_blob, size_t *out_size)
bool tf_ssb_db_get_account_password_hash(tf_ssb_t *ssb, const char *name, char *out_password, size_t password_size)
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_store_message(tf_ssb_t *ssb, JSContext *context, const char *id, JSValue val, const char *signature, int flags, tf_ssb_db_store_message_callback_t *callback, 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)
int tf_ssb_db_identity_get_count_for_user(tf_ssb_t *ssb, const char *user)
const char ** tf_ssb_db_get_all_visible_identities(tf_ssb_t *ssb, int depth)
bool tf_ssb_db_generate_invite(sqlite3 *db, const char *id, const char *host, int port, int use_count, int expires_seconds, char *out_invite, size_t size)
bool tf_ssb_db_remove_property(tf_ssb_t *ssb, const char *id, const char *key)
bool tf_ssb_db_blob_get(tf_ssb_t *ssb, const char *id, uint8_t **out_blob, size_t *out_size)
const char ** tf_ssb_db_following_deep_ids(tf_ssb_t *ssb, const char **ids, int count, int depth)
void tf_ssb_db_identity_visit_all(tf_ssb_t *ssb, void(*callback)(const char *identity, void *user_data), void *user_data)
void() tf_ssb_db_store_message_callback_t(const char *id, bool stored, void *user_data)
Definition: ssb.db.h:82
void tf_ssb_db_init(tf_ssb_t *ssb)
void tf_ssb_db_init_reader(sqlite3 *db)
void tf_ssb_db_resolve_index_async(tf_ssb_t *ssb, const char *host, void(*callback)(const char *path, void *user_data), void *user_data)
bool tf_ssb_db_blob_has(sqlite3 *db, const char *id)
bool tf_ssb_db_check(sqlite3 *db, const char *author)
int tf_ssb_sqlite_authorizer(void *user_data, int action_code, const char *arg0, const char *arg1, const char *arg2, const char *arg3)
bool tf_ssb_db_set_global_setting_from_string(sqlite3 *db, const char *name, char *value)
bool tf_ssb_db_get_latest_message_by_author(tf_ssb_t *ssb, const char *author, int32_t *out_sequence, char *out_message_id, size_t out_message_id_size)
void() tf_ssb_db_blob_get_callback_t(bool found, const uint8_t *data, size_t size, void *user_data)
Definition: ssb.db.h:65
bool tf_ssb_db_has_invite(sqlite3 *db, const char *id)
tf_ssb_identity_info_t * tf_ssb_db_get_identity_info(tf_ssb_t *ssb, const char *user, const char *package_owner, const char *package_name)
const char * tf_ssb_db_get_user_for_identity(tf_ssb_t *ssb, const char *public_key)
bool tf_ssb_db_set_property(tf_ssb_t *ssb, const char *id, const char *key, const char *value)
bool tf_ssb_db_verify(tf_ssb_t *ssb, const char *id, int32_t debug_sequence, bool fix)
JSValue tf_ssb_format_message(JSContext *context, const char *previous, const char *author, int32_t sequence, double timestamp, const char *hash, const char *content, const char *signature, int flags)
struct _tf_ssb_following_t tf_ssb_following_t
bool tf_ssb_db_add_value_to_array_property(tf_ssb_t *ssb, const char *id, const char *key, const char *value)
JSValue tf_ssb_db_get_message_by_id(tf_ssb_t *ssb, const char *id, bool is_keys)
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)
bool tf_ssb_db_set_account_password(uv_loop_t *loop, sqlite3 *db, JSContext *context, const char *name, const char *password)
void tf_ssb_db_add_blob_wants(sqlite3 *db, const char *id)
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)
void() tf_ssb_db_blob_store_callback_t(const char *id, bool is_new, void *user_data)
Definition: ssb.db.h:104
bool tf_ssb_db_is_account_familiar(sqlite3 *db, const char *id, int depth)
bool tf_ssb_db_register_account(uv_loop_t *loop, sqlite3 *db, JSContext *context, const char *name, const char *password)
bool tf_ssb_db_identity_create(tf_ssb_t *ssb, const char *user, uint8_t *out_public_key, uint8_t *out_private_key)
bool tf_ssb_db_get_global_setting_int64(sqlite3 *db, const char *name, int64_t *out_value)
bool tf_ssb_db_get_global_setting_string(sqlite3 *db, const char *name, char *out_value, size_t size)
struct _tf_ssb_db_stored_connection_t tf_ssb_db_stored_connection_t
void tf_ssb_db_blob_get_async(tf_ssb_t *ssb, const char *id, tf_ssb_db_blob_get_callback_t *callback, void *user_data)
bool tf_ssb_db_identity_delete(tf_ssb_t *ssb, const char *user, const char *public_key)
bool tf_ssb_db_get_global_setting_bool(sqlite3 *db, const char *name, bool *out_value)
bool tf_ssb_db_identity_get_active(sqlite3 *db, const char *user, const char *package_owner, const char *package_name, char *out_identity, size_t out_identity_size)
const char * tf_ssb_db_get_property(tf_ssb_t *ssb, const char *id, const char *key)
struct sqlite3 sqlite3
Definition: ssb.h:97
function hash()
Definition: client.js:1161
Definition: ssb.db.h:336
char address[256]
Definition: ssb.db.h:338
char pubkey[k_id_base64_len]
Definition: ssb.db.h:342
int port
Definition: ssb.db.h:340
int64_t last_success
Definition: ssb.db.h:346
int64_t last_attempt
Definition: ssb.db.h:344
Definition: ssb.db.h:288
int depth
Definition: ssb.db.h:298
int followed_by_count
Definition: ssb.db.h:294
int blocking_count
Definition: ssb.db.h:292
int blocked_by_count
Definition: ssb.db.h:296
int following_count
Definition: ssb.db.h:290
Definition: ssb.db.h:585
char active_identity[k_id_base64_len]
Definition: ssb.db.h:593
int count
Definition: ssb.db.h:591
const char ** identity
Definition: ssb.db.h:587
const char ** name
Definition: ssb.db.h:589