summaryrefslogtreecommitdiff
path: root/usr.sbin/popa3d/database.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-08-19 13:05:58 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-08-19 13:05:58 +0000
commita6a38350f779ddf3a6febf67dda7714fe368e492 (patch)
treeb8ffbc248c20776618b1d6aa93ec16abb19e78d1 /usr.sbin/popa3d/database.c
parent580e400b41d341c2ad1bfe153d5ca6553351703a (diff)
libexec is the wrong place for popa3d, since it can be started WITHOUT inetd
Diffstat (limited to 'usr.sbin/popa3d/database.c')
-rw-r--r--usr.sbin/popa3d/database.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/usr.sbin/popa3d/database.c b/usr.sbin/popa3d/database.c
new file mode 100644
index 00000000000..c342cca54d2
--- /dev/null
+++ b/usr.sbin/popa3d/database.c
@@ -0,0 +1,88 @@
+/* $OpenBSD: database.c,v 1.1 2001/08/19 13:05:57 deraadt Exp $ */
+
+/*
+ * Message database management.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "params.h"
+#include "database.h"
+
+struct db_main db;
+
+void db_init(void)
+{
+ db.head = db.tail = NULL;
+ db.total_count = 0;
+ db.total_size = 0;
+ db.flags = 0;
+#if POP_SUPPORT_LAST
+ db.last = 0;
+#endif
+}
+
+int db_add(struct db_message *msg)
+{
+ struct db_message *entry;
+
+ if (db.total_count >= MAX_MAILBOX_MESSAGES) return 1;
+
+ entry = malloc(sizeof(struct db_message));
+ if (!entry) return 1;
+
+ memcpy(entry, msg, sizeof(struct db_message));
+ entry->next = NULL;
+ entry->flags = 0;
+
+ if (db.tail)
+ db.tail = db.tail->next = entry;
+ else
+ db.tail = db.head = entry;
+
+ if (++db.total_count <= 0) return 1;
+ if ((db.total_size += entry->size) < 0 || entry->size < 0) return 1;
+
+ return 0;
+}
+
+int db_delete(struct db_message *msg)
+{
+ if (msg->flags & MSG_DELETED) return 1;
+
+ msg->flags |= MSG_DELETED;
+
+ db.visible_count--;
+ db.visible_size -= msg->size;
+ db.flags |= DB_DIRTY;
+
+ return 0;
+}
+
+int db_fix(void)
+{
+ int size;
+ struct db_message *entry;
+ int index;
+
+ db.visible_count = db.total_count;
+ db.visible_size = db.total_size;
+
+ if (!db.total_count) return 0;
+
+ size = sizeof(struct db_message *) * db.total_count;
+ if (size <= 0) return 1;
+ if (size / sizeof(struct db_message *) != db.total_count) return 1;
+
+ db.array = malloc(size);
+ if (!db.array) return 1;
+
+ entry = db.head;
+ index = 0;
+ do {
+ db.array[index++] = entry;
+ } while ((entry = entry->next));
+
+ return 0;
+}