diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2026-02-21 11:14:42 +0100 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2026-02-21 11:14:42 +0100 |
| commit | 1b19afaa339f2f68520d61b634600ddeb04effb7 (patch) | |
| tree | 232ec9fdc03a8955a8c847b88a688306689d2633 /src/app.h | |
| parent | 0b6e8026a6b530c7d88607bfdf79b9692987abaa (diff) | |
Split up the rendering from the logic
Diffstat (limited to 'src/app.h')
| -rw-r--r-- | src/app.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/app.h b/src/app.h new file mode 100644 index 0000000..46d2c18 --- /dev/null +++ b/src/app.h @@ -0,0 +1,70 @@ +#pragma once + +#include <stddef.h> +#include <stdint.h> +#include <time.h> + +#define CLIENT_NAME_MAX 32 +#define CLIENT_SECRET_LEN 33 +#define BACKUP_STATUS_MAX 16 +#define MAX_BACKUPS_DISPLAY 50 + +struct App { + const char* dbname; + char session_secret[CLIENT_SECRET_LEN]; + const char *admin_user; + const char *admin_pass; +}; + +void app_startup(struct App *app); + +struct CreateClientResult { + int64_t id; + char* name; + char secret[CLIENT_SECRET_LEN]; +}; + +int create_client(struct App *app, char *name, struct CreateClientResult *result); +int delete_client(struct App *app, int64_t client_id); + +struct ListClientResultClient { + int64_t id; + char name[CLIENT_NAME_MAX]; + char secret[CLIENT_SECRET_LEN]; + struct timespec last_backup; + char status[BACKUP_STATUS_MAX]; // "OK", "RUNNING", "STALE", "FAILED", "INTERRUPTED" + int is_stale; +}; + +struct ListClientResult { + uint16_t clients_len; + // Right now this has to be exactly 16 elements long, but it could be longer in the future + struct ListClientResultClient clients[]; +}; + +int list_clients(struct App *app, struct ListClientResult *result); + +struct BackupRecord { + int64_t id; + char status[BACKUP_STATUS_MAX]; + struct timespec started; + struct timespec completed; +}; + +struct GetClientOnlyResult { + int found; + int64_t id; + char name[CLIENT_NAME_MAX]; + char secret[CLIENT_SECRET_LEN]; +}; + +struct GetBackupsResult { + uint16_t backups_len; // On input: max backups to fetch; On output: actual count + struct BackupRecord backups[]; +}; + +int get_client(struct App *app, int64_t client_id, struct GetClientOnlyResult *result); +int get_client_backups(struct App *app, int64_t client_id, struct GetBackupsResult *result); + +// Returns 0 on success, -1 on error, -2 on secret mismatch +int submit_report(struct App *app, char *client, char *secret, int is_finish); |
