Add some subscription (a.k.a. "follow") functionality
[blerg.git] / database / database.h
1 /* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
2  * BSD-style license.  Please see the COPYING file for details.
3  */
4 #ifndef _DATABASE_H
5 #define _DATABASE_H
6
7 #include <stdint.h>
8 #include <time.h>
9
10 #define VALID_CHAR(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
11 #define WHITESPACE(c) (c == ' ' || c == '\t' || c == '\n' || c == '\r')
12
13 struct record {
14         uint32_t offset;
15         uint16_t length;
16         uint16_t flags;
17         time_t timestamp;
18 };
19
20 struct meta {
21         uint64_t sequence;
22 };
23
24 struct blerg {
25         int meta_fd;
26         int index_fd;
27         int data_fd;
28         char *name;
29         char *base_path;
30         struct meta *meta;
31         struct record *index;
32         char *data;
33         int current_segment;
34         int data_size;
35 };
36
37 int blerg_exists(const char *);
38 struct blerg *blerg_open(const char *);
39 int blerg_close(struct blerg *);
40 int blerg_store(struct blerg *, const char *, int);
41 int blerg_fetch(struct blerg *, int, char **, int *);
42 uint64_t blerg_get_record_count(struct blerg *);
43 time_t blerg_get_timestamp(struct blerg *blerg, int record);
44
45 #endif //_DATABASE_H