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
|
#pragma once
#include "global.h"
struct db_name_id{
char *name;
i64 id;
};
struct db_room_list{
i64 count;
struct db_name_id *list;
};
struct db_message{
i64 msgid;
i64 roomid,userid,timestamp;
i64 replyid; // message this is a reply to, or -1 if normal message
char *message;
};
struct db_message_list{
i64 count;
struct db_message *list;
};
struct db_user_list{
i64 count;
struct db_name_id *list;
};
struct db_strings_list{
i64 count;
char **list;
};
void db_init(void);
void db_reinit(void); // intended for forked threads
void db_close(void);
struct db_name_id db_create_room(void);
bool db_delete_room(i64 roomid);
bool db_add_member(i64 roomid,i64 userid);
bool db_remove_member(i64 roomid,i64 userid);
bool db_is_member(i64 roomid,i64 userid);
struct db_user_list db_list_members(i64 roomid);
i64 db_find_room(const char *name); // -1 if not found
char* db_get_roomname(i64 roomid);
struct db_room_list db_list_rooms(i64 userid);
i64 db_create_user(const char *name,const char *pass);
bool db_set_username(i64 userid,const char *name);
bool db_set_pass(i64 userid,const char *pass);
char* db_get_username(i64 userid);
bool db_check_pass(i64 userid,const char *pass);
bool db_delete_user(i64 userid);
i64 db_find_user(const char *name); // -1 if not found
struct db_strings_list db_user_tokens(i64 userid);
bool db_add_token(i64 userid,const char *token);
bool db_delete_token(i64 userid,const char *token);
i64 db_create_message(i64 roomid,i64 userid,i64 timestamp,i64 replyid,const char *message); // returns msgid
struct db_message_list db_get_messages(i64 roomid,i64 count); // gets latest `count` messages in rev. chron. order
// if beforeid<0, same as db_get_messages
struct db_message_list db_get_messages_before(i64 roomid,i64 count,i64 beforeid);
struct db_message db_get_message(i64 msgid); // returns {msgid=-1} if nonexistent
void db_nullify_name_id(struct db_name_id ni);
void db_nullify_room_list(struct db_room_list rl);
void db_nullify_user_list(struct db_user_list ul);
void db_nullify_message(struct db_message ml);
void db_nullify_message_list(struct db_message_list ml);
void db_nullify_strings_list(struct db_strings_list sl);
|