1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <time.h>
#define CLIENT_NAME_MAX 32
#define CLIENT_SECRET_LEN 33
#define MAX_BACKUPS_DISPLAY 50
enum BackupStatus {
STATUS_RUNNING,
STATUS_FINISHED,
STATUS_INTERRUPTED,
};
const char *backup_status_to_db_string(enum BackupStatus status);
enum BackupStatus backup_status_from_db_string(const char *str);
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;
enum BackupStatus status;
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;
enum BackupStatus status;
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);
|