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>
45 #define RXPD_COMMANDS \
46 RXPD_CMD(CHECK, "data against regular expressions") \
47 RXPD_CMD(APPEND, "new rules to a list") \
48 RXPD_CMD(PREPEND, "new rules in front of a list") \
49 RXPD_CMD(REMOVE, "rules from a list") \
50 RXPD_CMD(REPLACE, "a rule in a list with new rules") \
51 RXPD_CMD(DELETE, "a list from memory") \
52 RXPD_CMD(LOAD, "a list from disk") \
53 RXPD_CMD(SAVE, "a list to disk") \
54 RXPD_CMD(FETCH, "a list from a remote server") \
55 RXPD_CMD(EXPIRE, "aged rules from a list") \
56 RXPD_CMD(DUMP, "rules in a list") \
57 RXPD_CMD(LIST, "all existing lists") \
58 RXPD_CMD(VERSION, "of this rxpd is "PACKAGE_VERSION) \
59 RXPD_CMD(HELP, "is what you see right now") \
60 RXPD_CMD(SHUTDOWN, "the daemon")
62 #define RXPD_CMD(cmd, _) RXPD_CMD_##cmd,
63 enum rxpd_cmd_e {RXPD_COMMANDS};
67 * characters which are absolutely not allowed in rule filenames
68 * for finer control use policies, note that this are arbitary
69 * decisions also reserving some chars for later extension
71 #define RXPD_FILE_ILG_CHARS "@&?<>|/: \t\n\r*?\\"
78 struct rxpd_connection;
88 struct rxpd_file* policy;
91 //FILE* -l log log hits to logfile
104 rxpd_log (struct rxpd_base*, int level, const char* fmt, ...);
107 rxpd_die (const char* fmt, ...);
110 rxpd_malloc (size_t size);
113 rxpd_strdup (const char* str);
126 rxpd_rule_new (const char* buf);
129 rxpd_rule_delete (struct rxpd_rule*);
136 psplay node; // key points to basename part of filename
137 const char* filename; // full filename
138 //TODO later struct stat last_stat;
139 struct rxpd_base* base;
144 rxpd_file_new (struct rxpd_base* base, const char* filename);
147 rxpd_file_delete (struct rxpd_file* file);
150 rxpd_file_rules_delete (struct rxpd_file* self);
153 rxpd_file_load (struct rxpd_file* self);
156 rxpd_file_save (struct rxpd_file* self);
159 rxpd_file_cmp (const void* A, const void* B);
169 struct rxpd_base* base;
171 int (*rxpd_socket_addr)(struct rxpd_connection* conn, char* dst, const char* pfx, size_t size);
176 rxpd_socket_new_tcp4 (struct rxpd_base* base, const char* addr, unsigned short port);
179 rxpd_socket_tcp4addr (struct rxpd_connection* conn, char* dst, const char* pfx, size_t size);
182 //struct rxpd_socket*
183 //rxpd_socket_new_unix (struct rxpd_base* base, const char* name);
186 rxpd_socket_delete (struct rxpd_socket* self);
189 rxpd_socket_accept (void* ptr);
192 rxpd_socket_spawn (struct rxpd_socket* self);
195 rxpd_socket_join (struct rxpd_socket* self);
199 enum rxpd_buffer_state_e
201 RXPD_OK, // operational
202 RXPD_EOF, // connection closed
203 RXPD_ERROR // some other error
208 struct rxpd_connection* conn;
209 enum rxpd_buffer_state_e state;
216 rxpd_buffer_init (struct rxpd_buffer* self, struct rxpd_connection* conn);
219 rxpd_buffer_readline (struct rxpd_buffer* self, int again);
222 rxpd_buffer_printf (struct rxpd_buffer* self, const char* fmt, ...);
224 inline static enum rxpd_buffer_state_e
225 rxpd_buffer_state (struct rxpd_buffer* self)
232 struct rxpd_connection
236 struct rxpd_file* file;
237 struct rxpd_socket* socket;
241 struct rxpd_buffer in;
242 struct rxpd_buffer out;
246 struct rxpd_connection*
247 rxpd_connection_new (struct rxpd_socket* socket);
250 rxpd_connection_delete (struct rxpd_connection* self);
252 struct rxpd_connection*
253 rxpd_connection_spawn (struct rxpd_connection* self);
256 rxpd_connection_readline (struct rxpd_connection* self);
259 rxpd_connection_check_policy (struct rxpd_connection* self, char* line);
262 rxpd_connection_parse_cmd (void* ptr);
264 /* generate prototypes for each defined command */
265 #define RXPD_CMD(cmd, _) void rxpd_connection_cmd_##cmd (int fd, short event, void* ptr);