summaryrefslogtreecommitdiffstats
path: root/squarkdb.h
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-08-09 15:07:26 +0300
committerTimo Teräs <timo.teras@iki.fi>2010-08-09 15:07:26 +0300
commitb5a5dd614101000f653e6ecb96ab34ae3f44353f (patch)
tree5b9cb2a8b9d56eefc2e044d8845bb5fbedb6ba49 /squarkdb.h
parent02e7cfc6b4603be8ff3b69abbfad50193aaee845 (diff)
downloadsquark-b5a5dd614101000f653e6ecb96ab34ae3f44353f.tar.bz2
squark-b5a5dd614101000f653e6ecb96ab34ae3f44353f.tar.xz
squarkdb: cmph based url database for squark filtering
Implement basics of squarkdb which will be used by squark-filter to categorize URIs. Implementation is based on libcmph and uses file format suitable to be mmap:ed from squark-filter. Lua code is used to create the squark database from standard domain / url blacklists.
Diffstat (limited to 'squarkdb.h')
-rw-r--r--squarkdb.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/squarkdb.h b/squarkdb.h
new file mode 100644
index 0000000..2f96155
--- /dev/null
+++ b/squarkdb.h
@@ -0,0 +1,50 @@
+#ifndef SQUARKDB_H
+#define SQUARKDB_H
+
+#include <stdint.h>
+
+#define SQDB_SECTION_STRINGS 0
+#define SQDB_SECTION_CATEGORIES 1
+#define SQDB_SECTION_INDEX 2
+#define SQDB_SECTION_INDEX_MPH 3
+#define SQDB_SECTION_KEYWORD 4
+#define SQDB_SECTION_KEYWORD_MPH 5
+#define SQDB_SECTION_MAX 8
+
+struct sqdb {
+ int fd;
+ void * mmap_base;
+ size_t file_length;
+};
+
+struct sqdb_section {
+ u_int32_t offset;
+ u_int32_t length;
+};
+
+struct sqdb_header {
+ char description[116];
+ u_int32_t num_sections;
+ u_int32_t version;
+ u_int32_t magic;
+ struct sqdb_section section[SQDB_SECTION_MAX];
+};
+
+struct sqdb_index_entry {
+ u_int32_t has_subdomains : 1;
+ u_int32_t has_paths : 1;
+ u_int32_t category : 6;
+ u_int32_t parent : 24;
+ u_int32_t component;
+};
+
+const char *sqdb_section_names[SQDB_SECTION_MAX];
+
+int sqdb_create(struct sqdb *db, const char *fn);
+int sqdb_open(struct sqdb *db, const char *fn);
+void sqdb_close(struct sqdb *db);
+
+void *sqdb_section_create(struct sqdb *db, int id, u_int32_t size);
+void *sqdb_section_get(struct sqdb *db, int id, u_int32_t *size);
+
+#endif