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(DELETE, "a list from memory") \
50 RXPD_CMD(LOAD, "a list from disk") \
51 RXPD_CMD(SAVE, "a list to disk") \
52 RXPD_CMD(EXPIRE, "aged rules from a list") \
53 RXPD_CMD(DUMP, "rules in a list") \
54 RXPD_CMD(LIST, "all existing lists") \
55 RXPD_CMD(VERSION, "of this rxpd is "PACKAGE_VERSION) \
56 RXPD_CMD(HELP, "is what you see right now") \
57 RXPD_CMD(SHUTDOWN, "the daemon")
59 #define RXPD_CMD(cmd, _) RXPD_CMD_##cmd,
60 enum rxpd_cmd_e {RXPD_COMMANDS};
64 * characters which are absolutely not allowed in rule filenames
65 * for finer control use policies, note that this are arbitary
66 * decisions also reserving some chars for later extension
68 #define RXPD_FILE_ILG_CHARS "@&?<>|/: \t\n\r*?\\"
75 struct rxpd_connection;
85 struct rxpd_file* policy;
86 struct event_base* eventbase;
89 //FILE* -l log log hits to logfile
96 rxpd_init (struct event_base* eventbase);
102 rxpd_log (struct rxpd_base*, int level, const char* fmt, ...);
105 rxpd_die (const char* fmt, ...);
108 rxpd_malloc (size_t size);
111 rxpd_strdup (const char* str);
124 rxpd_rule_new (const char* buf);
127 rxpd_rule_delete (struct rxpd_rule*);
134 psplay node; // key points to basename part of filename
135 const char* filename; // full filename
136 //TODO later struct stat last_stat;
137 struct rxpd_base* base;
142 rxpd_file_new (struct rxpd_base* base, const char* filename);
145 rxpd_file_delete (struct rxpd_file* file);
148 rxpd_file_load (struct rxpd_file* self);
151 rxpd_file_save (struct rxpd_file* self);
154 rxpd_file_cmp (const void* A, const void* B);
164 struct rxpd_base* base;
165 int (*rxpd_socket_addr)(struct rxpd_connection* conn, char* dst, const char* pfx, size_t size);
170 rxpd_socket_new_tcp4 (struct rxpd_base* base, const char* addr, unsigned short port);
173 rxpd_socket_tcp4addr (struct rxpd_connection* conn, char* dst, const char* pfx, size_t size);
176 //struct rxpd_socket*
177 //rxpd_socket_new_unix (struct rxpd_base* base, const char* name);
180 rxpd_socket_delete (struct rxpd_socket* self);
183 rxpd_socket_accept (int sock, short event, void* ptr);
186 rxpd_socket_schedule (struct rxpd_socket* self);
189 rxpd_socket_suspend (struct rxpd_socket* self);
194 enum rxpd_buffer_state_e
196 RXPD_OK, // operational
197 RXPD_EOF, // connection closed
198 RXPD_ERROR // some other error
203 struct rxpd_connection* conn;
204 enum rxpd_buffer_state_e state;
211 rxpd_buffer_init (struct rxpd_buffer* self, struct rxpd_connection* conn);
214 rxpd_buffer_readline (struct rxpd_buffer* self, int again);
217 rxpd_buffer_printf (struct rxpd_buffer* self, const char* fmt, ...);
219 inline static enum rxpd_buffer_state_e
220 rxpd_buffer_state (struct rxpd_buffer* self)
227 struct rxpd_connection
231 struct rxpd_file* file;
232 struct rxpd_socket* socket;
236 struct rxpd_buffer in;
237 struct rxpd_buffer out;
241 struct rxpd_connection*
242 rxpd_connection_new (struct rxpd_socket* socket, int accept_fd);
245 rxpd_connection_delete (struct rxpd_connection* self);
247 struct rxpd_connection*
248 rxpd_connection_schedule (struct rxpd_connection* self);
251 rxpd_connection_readline (struct rxpd_connection* self);
254 rxpd_connection_check_policy (struct rxpd_connection* self, char* line);
257 rxpd_connection_parse_cmd (int fd, short event, void* ptr);
259 /* generate prototypes for each defined command */
260 #define RXPD_CMD(cmd, _) void rxpd_connection_cmd_##cmd (int fd, short event, void* ptr);