1 
2 /* (C)opyleft 2001-2002 Frank DENIS <j@pureftpd.org> */
3 
4 #ifndef __PUREDB_WRITE_H__
5 #define __PUREDB_WRITE_H__ 1
6 
7 #include <limits.h>
8 
9 #define PUREDBW_VERSION "PDB2"
10 #define PUREDBW_LIB_VERSION 1
11 
12 #ifndef PUREDB_U32_T
13 # if SHORT_MAX >= 2147483647
14 typedef unsigned short puredb_u32_t;
15 # elif INT_MAX >= 2147483647
16 typedef unsigned int puredb_u32_t;
17 # else
18 typedef unsigned long puredb_u32_t;
19 # endif
20 # define PUREDB_U32_T 1
21 #endif
22 
23 typedef struct Hash1_ {
24     puredb_u32_t hash;
25     puredb_u32_t offset_data;
26 } Hash1;
27 
28 typedef struct Hash0_ {
29     Hash1 *hash1_list;
30     size_t hash1_list_size;
31 } Hash0;
32 
33 typedef struct PureDBW_ {
34     FILE *fpindex;
35     FILE *fpdata;
36     char *file_index;
37     char *file_data;
38     char *file_final;
39     puredb_u32_t data_offset_counter;
40     puredb_u32_t offset_first_data;
41     Hash0 hash_table0[256];
42 } PureDBW;
43 
44 int puredbw_open(PureDBW * const dbw,
45                  const char * const file_index,
46                  const char * const file_data,
47                  const char * const file_final);
48 
49 int puredbw_close(PureDBW * const dbw);
50 
51 void puredbw_free(PureDBW * const dbw);
52 
53 int puredbw_add(PureDBW * const dbw,
54                 const char * const key, const size_t key_len,
55                 const char * const content, const size_t content_len);
56 
57 int puredbw_add_s(PureDBW * const dbw,
58                   const char * const key, const char * const content);
59 
60 #endif
61