summaryrefslogtreecommitdiff
path: root/src/libtidbit/tidbit.h
blob: ee831110f2445db4bce5d8e99a423c738b100509 (plain)
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
/* Tidbit
 * Copyright (C) 2010 Charlie Brej tidbit@brej.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef _TIDBIT_H_
#define _TIDBIT_H_

#define TIDBIT_RECORD_MAX_SIZE 2048
#define TIDBIT_RECORD_SIGNATURE_SIZE 1024
#define TIDBIT_RECORD_SIGNATURE_BYTES (TIDBIT_RECORD_SIGNATURE_SIZE / 8)

typedef struct _TidbitDatabase TidbitDatabase, *PtrTidbitDatabase;
typedef struct _TidbitKey TidbitKey, *PtrTidbitKey;
typedef struct _TidbitQuery TidbitQuery, *PtrTidbitQuery;
typedef struct _TidbitRecord TidbitRecord, *PtrTidbitRecord;
typedef struct _TidbitGuid TidbitGuid, *PtrTidbitGuid;
typedef struct _TidbitGuidSet TidbitGuidSet, *PtrTidbitGuidSet;

typedef enum{
TIDBIT_QUERY_EXP_TYPE_EQ = '=',  // FIXME These need a propper system
TIDBIT_QUERY_EXP_TYPE_NE = '!' | '=' << 8,
TIDBIT_QUERY_EXP_TYPE_GT = '>',
TIDBIT_QUERY_EXP_TYPE_GE = '>' | '=' << 8,
TIDBIT_QUERY_EXP_TYPE_LT = '<',
TIDBIT_QUERY_EXP_TYPE_LE = '<' | '=' << 8,
} TidbitQueryExpType;


PtrTidbitKey tidbit_key_get (char* application, char* agent);
void tidbit_key_ref (PtrTidbitKey key);
void tidbit_key_unref (PtrTidbitKey key);

PtrTidbitRecord tidbit_record_new (char* table_name);
void tidbit_record_ref (PtrTidbitRecord record);
void tidbit_record_unref (PtrTidbitRecord record);
void tidbit_record_set_ttl (PtrTidbitRecord record, int seconds, int days, int years);
void tidbit_record_add_element (PtrTidbitRecord record, char* key, char* value);
char* tidbit_record_get_element_value_by_key (PtrTidbitRecord record, char* key);
void tidbit_record_sign (PtrTidbitRecord record, PtrTidbitKey key);

void tidbit_database_ref (PtrTidbitDatabase database);
void tidbit_database_unref (PtrTidbitDatabase database);
unsigned int tidbit_database_insert_record (PtrTidbitDatabase database, PtrTidbitRecord record);
PtrTidbitRecord tidbit_database_fetch_record (PtrTidbitDatabase database, PtrTidbitGuid guid);
PtrTidbitGuidSet tidbit_database_query (PtrTidbitDatabase database, PtrTidbitQuery query);

PtrTidbitDatabase tidbit_database_dbus_new (void);
PtrTidbitDatabase tidbit_database_mem_new (void);
PtrTidbitDatabase tidbit_database_http_new (void);
PtrTidbitDatabase tidbit_database_fork_new (PtrTidbitDatabase sub_a, PtrTidbitDatabase sub_b, int caching);
PtrTidbitDatabase tidbit_database_default_new (void);

PtrTidbitQuery tidbit_query_new (char* table_name);
void tidbit_query_ref (PtrTidbitQuery query);
void tidbit_query_unref (PtrTidbitQuery query);
void tidbit_query_add_exp (PtrTidbitQuery query, char* key, char* value, TidbitQueryExpType type);


#endif