Error when fetching tags and direction isn't 1 or -1
[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         uint64_t subscription_mark;
23 };
24
25 struct blerg {
26         int meta_fd;
27         int index_fd;
28         int data_fd;
29         char *name;
30         char *base_path;
31         struct meta *meta;
32         struct record *index;
33         char *data;
34         int current_segment;
35         int data_size;
36 };
37
38 int blerg_exists(const char *);
39 struct blerg *blerg_open(const char *);
40 int blerg_close(struct blerg *);
41 int blerg_store(struct blerg *, const char *, int);
42 int blerg_fetch(struct blerg *, int, char **, int *);
43 uint64_t blerg_get_record_count(struct blerg *);
44 time_t blerg_get_timestamp(struct blerg *blerg, int record);
45 int blerg_set_subscription_mark(struct blerg *blerg);
46 uint64_t blerg_get_subscription_mark(struct blerg *blerg);
47
48 #endif //_DATABASE_H