2011-09-03 05:09:31 +02:00
|
|
|
#ifndef _INCLUDE_DB_R_
|
|
|
|
#define _INCLUDE_DB_R_
|
|
|
|
|
2009-06-15 02:44:05 +00:00
|
|
|
#include "r_types.h"
|
2011-09-03 05:09:31 +02:00
|
|
|
#include "r_util.h"
|
|
|
|
|
|
|
|
// TODO: add support for network. (udp). memcache, with hooks
|
|
|
|
typedef struct r_pair_t {
|
|
|
|
char *dir;
|
|
|
|
RHashTable *ht;
|
|
|
|
RList *dbs;
|
|
|
|
} RPair;
|
|
|
|
|
2009-06-15 02:44:05 +00:00
|
|
|
#define R_DB_KEYS 256
|
|
|
|
|
2010-06-13 11:59:17 +02:00
|
|
|
typedef struct r_db_block_t {
|
2009-06-18 13:10:26 +00:00
|
|
|
void **data; /* { 0x80380, 0x80380, 0 } */
|
2009-06-15 02:44:05 +00:00
|
|
|
struct r_db_block_t *childs[256];
|
2010-06-13 11:59:17 +02:00
|
|
|
} RDatabaseBlock;
|
2009-06-15 02:44:05 +00:00
|
|
|
|
|
|
|
#define R_DB_INDEXOF(type, member) \
|
2011-09-03 05:09:31 +02:00
|
|
|
(int)((size_t)((&((type *)0)->member)))
|
2009-06-15 02:44:05 +00:00
|
|
|
|
2010-01-04 01:25:52 +01:00
|
|
|
typedef struct r_db_t {
|
2009-06-15 02:44:05 +00:00
|
|
|
int id_min;
|
|
|
|
int id_max;
|
|
|
|
struct r_db_block_t *blocks[R_DB_KEYS];
|
|
|
|
int blocks_sz[R_DB_KEYS];
|
|
|
|
void *cb_user;
|
2009-06-18 13:10:26 +00:00
|
|
|
int (*cb_free)(void *db, const void *item, void *user);
|
2010-01-26 01:28:33 +01:00
|
|
|
} RDatabase;
|
2009-06-15 02:44:05 +00:00
|
|
|
|
2010-01-04 01:25:52 +01:00
|
|
|
typedef struct r_db_iter_t {
|
2009-07-08 17:14:19 +00:00
|
|
|
struct r_db_t *db;
|
|
|
|
int key; /* key to be used */
|
|
|
|
int size; /* key size */
|
|
|
|
int path[256]; /* for each depth level */
|
|
|
|
int ptr; /* pointer in block nodes (repeated childs) */
|
|
|
|
void *cur;
|
2010-01-26 01:28:33 +01:00
|
|
|
} RDatabaseIter;
|
2009-07-08 17:14:19 +00:00
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
/* table */
|
2010-01-04 01:25:52 +01:00
|
|
|
typedef struct r_db_table_t {
|
2009-12-24 03:17:53 +01:00
|
|
|
char *name;
|
|
|
|
int nelems;
|
|
|
|
char *fmt;
|
|
|
|
char *args;
|
|
|
|
int *offset;
|
2010-01-26 01:28:33 +01:00
|
|
|
} RDatabaseTable;
|
2009-12-24 03:17:53 +01:00
|
|
|
|
2010-06-13 11:59:17 +02:00
|
|
|
#if 0
|
|
|
|
it = r_db_iterator (db);
|
|
|
|
while (r_db_iter_next(it)) {
|
|
|
|
f = (RAnalFcn*) r_db_iter_get (it);
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
#ifdef R_API
|
2009-06-15 02:44:05 +00:00
|
|
|
R_API struct r_db_t *r_db_new();
|
|
|
|
R_API struct r_db_block_t *r_db_block_new();
|
|
|
|
R_API int r_db_add_id(struct r_db_t *db, int off, int size);
|
|
|
|
R_API int r_db_add(struct r_db_t *db, void *b);
|
2009-07-22 17:30:21 +02:00
|
|
|
R_API int r_db_add_unique(struct r_db_t *db, void *b);
|
2009-07-08 13:49:55 +02:00
|
|
|
R_API void **r_db_get(struct r_db_t *db, int key, const ut8 *b);
|
2011-09-03 05:09:31 +02:00
|
|
|
R_API void *r_db_get_cur(void **ptr);
|
2009-06-18 13:10:26 +00:00
|
|
|
R_API int r_db_delete(struct r_db_t *db, const void *b);
|
|
|
|
R_API void **r_db_get_next(void **ptr);
|
2009-07-08 13:49:55 +02:00
|
|
|
R_API struct r_db_iter_t *r_db_iter(struct r_db_t *db, int key, const ut8 *b);
|
2009-07-08 17:14:19 +00:00
|
|
|
R_API void *r_db_iter_cur(struct r_db_iter_t *iter);
|
2010-06-13 11:59:17 +02:00
|
|
|
R_API int r_db_iter_next(struct r_db_iter_t *iter);
|
2009-07-08 17:14:19 +00:00
|
|
|
R_API void *r_db_iter_prev(struct r_db_iter_t *iter);
|
2009-09-25 04:04:51 +02:00
|
|
|
R_API struct r_db_iter_t *r_db_iter_new(struct r_db_t *db, int key);
|
2009-07-08 17:14:19 +00:00
|
|
|
R_API struct r_db_iter_t *r_db_iter_free(struct r_db_iter_t *iter);
|
2009-06-15 02:44:05 +00:00
|
|
|
R_API int r_db_free(struct r_db_t *db);
|
2009-07-08 13:49:55 +02:00
|
|
|
R_API int r_db_push(struct r_db_t *db, const ut8 *b);
|
2010-01-04 13:11:48 +01:00
|
|
|
R_API ut8 *r_db_pop(struct r_db_t *db);
|
2009-12-24 03:17:53 +01:00
|
|
|
#endif
|
2011-09-03 05:09:31 +02:00
|
|
|
|
|
|
|
#endif
|