2 rxpd.h - regex policy daemon
5 2007, Christian Thaeter <ct@pipapo.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
43 #define RXPD_COMMANDS \
44 RXPD_CMD(CHECK, "data against regular expressions") \
45 RXPD_CMD(APPEND, "new rules to a list") \
46 RXPD_CMD(PREPEND, "new rules in front of a list") \
47 RXPD_CMD(REMOVE, "rules from a list") \
48 RXPD_CMD(REPLACE, "a rule in a list with new rules") \
49 RXPD_CMD(LOAD, "a list from disk") \
50 RXPD_CMD(SAVE, "a list to disk") \
51 RXPD_CMD(EXPIRE, "aged rules from a list") \
52 RXPD_CMD(DUMP, "rules in a list") \
53 RXPD_CMD(LIST, "all existing lists") \
54 RXPD_CMD(VERSION, "of this rxpd is "PACKAGE_STRING) \
55 RXPD_CMD(HELP, "is what you see right now") \
56 RXPD_CMD(SHUTDOWN, "the daemon")
58 #define RXPD_CMD(cmd, _) RXPD_CMD_##cmd,
59 enum rxpd_cmd_e {RXPD_COMMANDS};
63 * characters which are absolutely not allowed in rule filenames
64 * for finer control use policies
66 #define RXPD_FILE_ILG_CHARS "/: \t\n*?\\"
73 struct rxpd_connection;
83 struct rxpd_file* policy;
84 struct event_base* eventbase;
87 //FILE* -l log log hits to logfile
94 rxpd_init (struct event_base* eventbase);
100 rxpd_log (struct rxpd_base*, int level, const char* fmt, ...);
103 rxpd_die (const char* fmt, ...);
106 rxpd_malloc (size_t size);
109 rxpd_strdup (const char* str);
122 rxpd_rule_new (const char* buf);
125 rxpd_rule_delete (struct rxpd_rule*);
132 psplay node; // key points to basename part of filename
133 const char* filename; // full filename
134 //TODO later struct stat last_stat;
135 struct rxpd_base* base;
140 rxpd_file_new (struct rxpd_base* base, const char* filename);
143 rxpd_file_delete (PSplay file);
146 rxpd_file_load (struct rxpd_file* self);
149 rxpd_file_save (struct rxpd_file* self);
152 rxpd_file_cmp (const void* A, const void* B);
162 struct rxpd_base* base;
163 int (*rxpd_socket_addr)(struct rxpd_connection* conn, char* dst, const char* pfx, size_t size);
168 rxpd_socket_new_tcp4 (struct rxpd_base* base, const char* addr, unsigned short port);
171 rxpd_socket_tcp4addr (struct rxpd_connection* conn, char* dst, const char* pfx, size_t size);
174 //struct rxpd_socket*
175 //rxpd_socket_new_unix (struct rxpd_base* base, const char* name);
178 rxpd_socket_delete (struct rxpd_socket* self);
181 rxpd_socket_accept (int sock, short event, void* ptr);
184 rxpd_socket_schedule (struct rxpd_socket* self);
187 rxpd_socket_suspend (struct rxpd_socket* self);
192 enum rxpd_buffer_state_e
194 RXPD_OK, // operational
195 RXPD_EOF, // connection closed
196 RXPD_ERROR // some other error
201 struct rxpd_connection* conn;
202 enum rxpd_buffer_state_e state;
209 rxpd_buffer_init (struct rxpd_buffer* self, struct rxpd_connection* conn);
212 rxpd_buffer_readline (struct rxpd_buffer* self, int again);
215 rxpd_buffer_printf (struct rxpd_buffer* self, const char* fmt, ...);
217 inline static enum rxpd_buffer_state_e
218 rxpd_buffer_state (struct rxpd_buffer* self)
225 struct rxpd_connection
229 struct rxpd_file* file;
230 struct rxpd_socket* socket;
234 struct rxpd_buffer in;
235 struct rxpd_buffer out;
239 struct rxpd_connection*
240 rxpd_connection_new (struct rxpd_socket* socket, int accept_fd);
243 rxpd_connection_delete (struct rxpd_connection* self);
245 struct rxpd_connection*
246 rxpd_connection_schedule (struct rxpd_connection* self);
249 rxpd_connection_readline (struct rxpd_connection* self);
252 rxpd_connection_check_policy (struct rxpd_connection* self, char* line);
255 rxpd_connection_parse_cmd (int fd, short event, void* ptr);
257 /* generate prototypes for each defined command */
258 #define RXPD_CMD(cmd, _) void rxpd_connection_cmd_##cmd (int fd, short event, void* ptr);