+/*
+ rxpd.h - regex policy daemon
+
+ Copyright (C)
+ 2007, Christian Thaeter <ct@pipapo.org>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
#ifndef RXPD_H
#define RXPD_H
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "llist.h"
+#include "psplay.h"
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
#include <unistd.h>
#include <regex.h>
-#include <>
-#include "llist.h"
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <event.h>
-#define RXPD_COMMANDS \
-{ \
- RXPD_CMD(CHECK), \
- RXPD_CMD(APPEND), \
- RXPD_CMD(PREPEND), \
- RXPD_CMD(REMOVE), \
- RXPD_CMD(REPLACE), \
- RXPD_CMD(LOAD), \
- RXPD_CMD(SAVE), \
- RXPD_CMD(DUMP), \
- RXPD_CMD(LIST), \
- RXPD_CMD(END) \
-}
+#define RXPD_COMMANDS \
+ RXPD_CMD(CHECK) \
+ RXPD_CMD(APPEND) \
+ RXPD_CMD(PREPEND) \
+ RXPD_CMD(REMOVE) \
+ RXPD_CMD(REPLACE) \
+ RXPD_CMD(LOAD) \
+ RXPD_CMD(SAVE) \
+ RXPD_CMD(DUMP) \
+ RXPD_CMD(LIST) \
+ RXPD_CMD(SHUTDOWN)
-#define RXPD_CMD(cmd) RXPD_CMD_##cmd
-enum RXPD_COMMANDS;
+#define RXPD_CMD(cmd) RXPD_CMD_##cmd,
+enum rxpd_cmd_e {RXPD_COMMANDS};
#undef RXPD_CMD
-struct base
+struct rxpd_base;
+struct rxpd_file;
+struct rxpd_rule;
+struct rxpd_socket;
+struct rxpd_buffer;
+struct rxpd_connection;
+
+struct rxpd_base
{
char* rulesdir;
- void* files;
+ psplayroot files;
+
+ llist sockets_pending;
+ llist sockets_active;
+ llist connections_pending;
+ llist connections_active;
};
-struct file
+struct rxpd_base*
+rxpd_init (char* rulesdir);
+
+void
+rxpd_destroy (void);
+
+
+
+//
+struct rxpd_rule
{
- char* filename;
- struct stat last_stat;
+ llist node;
+ char* string;
+ regex_t rx;
+};
+
+struct rxpd_rule*
+rxpd_rule_new (const char* buf);
+
+void
+rxpd_rule_delete (struct rxpd_rule*);
+
+
+
+//
+struct rxpd_file
+{
+ psplay node; // key points to basename part of filename
+ const char* filename; // full filename
+ //TODO later struct stat last_stat;
llist rules;
};
+struct rxpd_file*
+rxpd_file_new (struct rxpd_base* base, const char* filename);
+
+void
+rxpd_file_delete (PSplay file);
+
+int
+rxpd_file_load (struct rxpd_file* self);
+
+int
+rxpd_file_cmp (const void* A, const void* B);
-struct rule
+
+//
+
+struct rxpd_socket
{
- char* string;
- char* regex;
- regex_t rx;
llist node;
+ int fd;
+ struct event ev;
+ struct rxpd_base* base;
};
+struct rxpd_socket*
+rxpd_socket_new_tcp4 (struct rxpd_base* base, const char* addr, unsigned short port);
+
+//struct rxpd_socket*
+//rxpd_socket_new_unix (struct rxpd_base* base, const char* name);
+
+void
+rxpd_socket_delete (struct rxpd_socket* self);
+
+void
+rxpd_socket_accept (int sock, short event, void* ptr);
+
+struct rxpd_socket*
+rxpd_socket_schedule (struct rxpd_socket* self);
+
+struct rxpd_socket*
+rxpd_socket_suspend (struct rxpd_socket* self);
+
+
+//
+
+enum rxpd_buffer_state_e
+ {
+ RXPD_OK, // operational
+ RXPD_EOF, // connection closed
+ RXPD_ERROR // some other error
+ };
+
+struct rxpd_buffer
+{
+ struct rxpd_connection* conn;
+ enum rxpd_buffer_state_e state;
+ char* eol;
+ char* eob;
+ char buffer[4096];
+};
+
+struct rxpd_buffer*
+rxpd_buffer_init (struct rxpd_buffer* self, struct rxpd_connection* conn);
+
+char*
+rxpd_buffer_readline (struct rxpd_buffer* self, int again);
+
+inline static enum rxpd_buffer_state_e
+rxpd_buffer_state (struct rxpd_buffer* self)
+{
+ return self->state;
+}
+
+
+//
+struct rxpd_connection
+{
+ llist node;
+ int fd;
+ struct event ev;
+ struct rxpd_base* base;
+ struct rxpd_file* file;
+ llist tmp_list;
+
+ struct sockaddr peer_addr;
+
+ struct rxpd_buffer in;
+ struct rxpd_buffer out;
+};
+
+
+struct rxpd_connection*
+rxpd_connection_new (struct rxpd_base* base, int accept_fd);
+
+void
+rxpd_connection_delete (struct rxpd_connection* self);
+
+
+struct rxpd_connection*
+rxpd_connection_schedule (struct rxpd_connection* self);
+
+
+struct rxpd_connection*
+rxpd_connection_suspend (struct rxpd_connection* self);
+
+
+int
+rxpd_connection_readline (struct rxpd_connection* self);
+
+void
+rxpd_connection_parse_cmd (int fd, short event, void* ptr);
+
+/* generate prototypes for each defined command */
+#define RXPD_CMD(cmd) void rxpd_connection_cmd_##cmd (int fd, short event, void* ptr);
+RXPD_COMMANDS
+#undef RXPD_CMD
#endif