Naut/plugins/webui/webui_store.h
ookami125 9474e6f31a webui: store category/tag taxonomy in the webui DB
Move the category + tag lists out of the daemon (labels.json + the
get/set_label_taxonomy RPCs) and into the webui's own SQLite DB
(categories, tags tables). The daemon no longer persists webui taxonomy;
per-torrent labels still flow through set_labels for Lua.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 22:05:22 -04:00

55 lines
2.5 KiB
C

/* webui_store.h — SQLite-backed persistence for all web-UI-owned state:
* accounts, the category/tag taxonomy, and RSS feeds/rules/indexers.
*
* Owned entirely by the webui plugin (the daemon persists none of this).
* Account passwords are PBKDF2-HMAC-SHA256 with a per-user random salt. All
* calls are thread-safe (the store serializes access to its SQLite handle). */
#ifndef NAUT_WEBUI_STORE_H
#define NAUT_WEBUI_STORE_H
#include <stdbool.h>
#include <stddef.h>
#include <jansson.h>
typedef struct webui_store webui_store;
/* Open (creating if needed) the account database at `path`. Returns NULL on
* failure. The schema is created/migrated on open. */
webui_store *webui_store_open(const char *path);
void webui_store_close(webui_store *s);
/* Number of accounts, or -1 on error. */
int webui_store_user_count(webui_store *s);
/* Number of admin accounts, or -1 on error. */
int webui_store_admin_count(webui_store *s);
bool webui_store_user_exists(webui_store *s, const char *username);
/* Verify a username/password pair (constant-time). On success, copies the
* account's role ("admin"/"user") into role_out. */
bool webui_store_verify(webui_store *s, const char *username,
const char *password, char *role_out, size_t role_sz);
/* Create an account. `role` must be "admin" or "user" (defaults to "user" if
* NULL/invalid). Returns false if the username already exists or on error. */
bool webui_store_create_user(webui_store *s, const char *username,
const char *password, const char *role);
bool webui_store_set_password(webui_store *s, const char *username,
const char *password);
/* Change an account's role ("admin"/"user"). */
bool webui_store_set_role(webui_store *s, const char *username, const char *role);
bool webui_store_delete_user(webui_store *s, const char *username);
/* Append {username, role, createdAt} objects (sorted by username) to the
* json array `out`. Returns false on error. */
bool webui_store_list_users(webui_store *s, json_t *out);
/* --- category / tag taxonomy (web-UI organization, owned here) ------------- *
* The save_* calls replace the whole list atomically; the load_* calls append
* to the (array) `out`. Categories are {name, savePath}; tags are strings. */
bool webui_store_save_categories(webui_store *s, json_t *cats);
bool webui_store_load_categories(webui_store *s, json_t *out);
bool webui_store_save_tags(webui_store *s, json_t *tags);
bool webui_store_load_tags(webui_store *s, json_t *out);
#endif /* NAUT_WEBUI_STORE_H */