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>
42 #define RXPD_COMMANDS \
54 #define RXPD_CMD(cmd) RXPD_CMD_##cmd,
55 enum rxpd_cmd_e {RXPD_COMMANDS};
59 * characters which are absolutely not allowed in rule filenames
60 * for finer control use policies
62 #define RXPD_FILE_ILG_CHARS "/: \t\n*?"
69 struct rxpd_connection;
79 struct rxpd_file* policy;
80 struct event_base* eventbase;
83 //FILE* -l log log hits to logfile
90 rxpd_init (struct event_base* eventbase);
96 rxpd_log (struct rxpd_base*, int level, const char* fmt, ...);
99 rxpd_die (const char* fmt, ...);
102 rxpd_malloc (size_t size);
105 rxpd_strdup (const char* str);
117 rxpd_rule_new (const char* buf);
120 rxpd_rule_delete (struct rxpd_rule*);
127 psplay node; // key points to basename part of filename
128 const char* filename; // full filename
129 //TODO later struct stat last_stat;
130 struct rxpd_base* base;
135 rxpd_file_new (struct rxpd_base* base, const char* filename);
138 rxpd_file_delete (PSplay file);
141 rxpd_file_load (struct rxpd_file* self);
144 rxpd_file_save (struct rxpd_file* self);
147 rxpd_file_cmp (const void* A, const void* B);
157 struct rxpd_base* base;
158 int (*rxpd_socket_addr)(struct rxpd_connection* conn, char* dst, const char* pfx, size_t size);
163 rxpd_socket_new_tcp4 (struct rxpd_base* base, const char* addr, unsigned short port);
166 rxpd_socket_tcp4addr (struct rxpd_connection* conn, char* dst, const char* pfx, size_t size);
169 //struct rxpd_socket*
170 //rxpd_socket_new_unix (struct rxpd_base* base, const char* name);
173 rxpd_socket_delete (struct rxpd_socket* self);
176 rxpd_socket_accept (int sock, short event, void* ptr);
179 rxpd_socket_schedule (struct rxpd_socket* self);
182 rxpd_socket_suspend (struct rxpd_socket* self);
187 enum rxpd_buffer_state_e
189 RXPD_OK, // operational
190 RXPD_EOF, // connection closed
191 RXPD_ERROR // some other error
196 struct rxpd_connection* conn;
197 enum rxpd_buffer_state_e state;
204 rxpd_buffer_init (struct rxpd_buffer* self, struct rxpd_connection* conn);
207 rxpd_buffer_readline (struct rxpd_buffer* self, int again);
209 inline static enum rxpd_buffer_state_e
210 rxpd_buffer_state (struct rxpd_buffer* self)
217 struct rxpd_connection
221 struct rxpd_file* file;
222 struct rxpd_socket* socket;
226 struct rxpd_buffer in;
227 struct rxpd_buffer out;
231 struct rxpd_connection*
232 rxpd_connection_new (struct rxpd_socket* socket, int accept_fd);
235 rxpd_connection_delete (struct rxpd_connection* self);
237 struct rxpd_connection*
238 rxpd_connection_schedule (struct rxpd_connection* self);
241 rxpd_connection_readline (struct rxpd_connection* self);
244 rxpd_connection_check_policy (struct rxpd_connection* self, char* line);
247 rxpd_connection_parse_cmd (int fd, short event, void* ptr);
249 /* generate prototypes for each defined command */
250 #define RXPD_CMD(cmd) void rxpd_connection_cmd_##cmd (int fd, short event, void* ptr);