Enable GUI option for 'custom command' connection. Don't g_free strings in
[platform/upstream/evolution-data-server.git] / camel / camel-block-file.h
1 /*
2  * Copyright (C) 2001 Ximian Inc.
3  *
4  * Authors: Michael Zucchi <notzed@ximian.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef _CAMEL_BLOCK_FILE_H
22 #define _CAMEL_BLOCK_FILE_H
23
24 #include <camel/camel-object.h>
25 #include <glib.h>
26 #include <e-util/e-msgport.h>
27 #include <stdio.h>
28
29 typedef guint32 camel_block_t;  /* block offset, absolute, bottom BLOCK_SIZE_BITS always 0 */
30 typedef guint32 camel_key_t;    /* this is a bitfield of (block offset:BLOCK_SIZE_BITS) */
31
32 typedef struct _CamelBlockRoot CamelBlockRoot;
33 typedef struct _CamelBlock CamelBlock;
34 typedef struct _CamelBlockFile CamelBlockFile;
35 typedef struct _CamelBlockFileClass CamelBlockFileClass;
36
37 #define CAMEL_BLOCK_FILE_SYNC (1<<0)
38
39 #define CAMEL_BLOCK_SIZE (1024)
40 #define CAMEL_BLOCK_SIZE_BITS (10) /* # bits to contain block_size bytes */
41
42 #define CAMEL_BLOCK_DIRTY (1<<0)
43 #define CAMEL_BLOCK_DETACHED (1<<1)
44
45 struct _CamelBlockRoot {
46         char version[8];        /* version number */
47
48         guint32 flags;          /* flags for file */
49         guint32 block_size;     /* block size of this file */
50         camel_block_t free;     /* free block list */
51         camel_block_t last;     /* pointer to end of blocks */
52
53         /* subclasses tack on, but no more than CAMEL_BLOCK_SIZE! */
54 };
55
56 /* LRU cache of blocks */
57 struct _CamelBlock {
58         struct _CamelBlock *next;
59         struct _CamelBlock *prev;
60
61         camel_block_t id;
62         guint32 flags;
63         guint32 refcount;
64         guint32 align00;
65
66         unsigned char data[CAMEL_BLOCK_SIZE];
67 };
68
69 struct _CamelBlockFile {
70         CamelObject parent;
71
72         struct _CamelBlockFilePrivate *priv;
73
74         char version[8];
75         char *path;
76         int flags;
77
78         int fd;
79         size_t block_size;
80
81         CamelBlockRoot *root;
82         CamelBlock *root_block;
83
84         /* make private? */
85         int block_cache_limit;
86         int block_cache_count;
87         EDList block_cache;
88         GHashTable *blocks;
89 };
90
91 struct _CamelBlockFileClass {
92         CamelObjectClass parent;
93
94         int (*validate_root)(CamelBlockFile *);
95         int (*init_root)(CamelBlockFile *);
96 };
97
98 CamelType camel_block_file_get_type(void);
99
100 CamelBlockFile *camel_block_file_new(const char *path, int flags, const char version[8], size_t block_size);
101 int camel_block_file_rename(CamelBlockFile *bs, const char *path);
102 int camel_block_file_delete(CamelBlockFile *kf);
103
104 CamelBlock *camel_block_file_new_block(CamelBlockFile *bs);
105 int camel_block_file_free_block(CamelBlockFile *bs, camel_block_t id);
106 CamelBlock *camel_block_file_get_block(CamelBlockFile *bs, camel_block_t id);
107 void camel_block_file_detach_block(CamelBlockFile *bs, CamelBlock *bl);
108 void camel_block_file_attach_block(CamelBlockFile *bs, CamelBlock *bl);
109 void camel_block_file_touch_block(CamelBlockFile *bs, CamelBlock *bl);
110 void camel_block_file_unref_block(CamelBlockFile *bs, CamelBlock *bl);
111 int camel_block_file_sync_block(CamelBlockFile *bs, CamelBlock *bl);
112 int camel_block_file_sync(CamelBlockFile *bs);
113
114 /* ********************************************************************** */
115
116 typedef struct _CamelKeyFile CamelKeyFile;
117 typedef struct _CamelKeyFileClass CamelKeyFileClass;
118
119 struct _CamelKeyFile {
120         CamelObject parent;
121
122         struct _CamelKeyFilePrivate *priv;
123
124         FILE *fp;
125         char *path;
126         int flags;
127         off_t last;
128 };
129
130 struct _CamelKeyFileClass {
131         CamelObjectClass parent;
132 };
133
134 CamelType      camel_key_file_get_type(void);
135
136 CamelKeyFile * camel_key_file_new(const char *path, int flags, const char version[8]);
137 int            camel_key_file_rename(CamelKeyFile *kf, const char *path);
138 int            camel_key_file_delete(CamelKeyFile *kf);
139
140 int            camel_key_file_write(CamelKeyFile *kf, camel_block_t *parent, size_t len, camel_key_t *records);
141 int            camel_key_file_read(CamelKeyFile *kf, camel_block_t *start, size_t *len, camel_key_t **records);
142
143
144 #endif /* ! _CAMEL_BLOCK_FILE_H */