2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <apr_general.h>
25 #include <apr_errno.h>
26 #include <apr_pools.h>
27 #include <apr_network_io.h>
32 guest_state_connecting, /* Connecting to socket. */
33 guest_state_request, /* Waiting or reading the request. */
34 guest_state_reply, /* Sending the reply. */
35 guest_state_dead /* Connection is dead. */
38 struct guest_description {
39 apr_pool_t *pool; /* Pool for lifetime of guest connection. */
41 apr_pool_t *rpool; /* Pool for lifetime of single req/resp. */
43 const char *name; /* "driver-name" */
44 const char *sock_path; /* Full path to socket. */
45 int sock; /* Real socket. */
46 apr_socket_t *aprsock; /* APR socket. */
47 apr_pollfd_t pollfd; /* APR poll descriptor. */
48 enum guest_state state; /* State of the connection. */
49 int counter; /* Used in reread_socket_dir. */
51 unsigned request_max; /* Max. length of request buffer. */
52 unsigned request_posn; /* Position in request buffer. */
53 char *request; /* Request buffer. */
55 unsigned reply_size; /* Size of reply buffer. */
56 unsigned reply_posn; /* Position in reply buffer. */
57 char *reply; /* Reply buffer. */
59 /* Increments every time guest does something bad, decremented once per min */
61 struct timespec last_penalty_decr;
73 long i; /* For int, bool types. */
74 char *str; /* For string type. */
79 extern const char *conf_file;
80 extern char *socket_dir;
81 extern char *guests_file;
83 extern int verbose_set_on_cmdline;
84 extern int foreground;
85 extern int foreground_set_on_cmdline;
86 extern int messages_to_stderr;
87 extern apr_pool_t *pool; /* pool for global memory allocation */
89 extern void initialize (void);
92 extern void init_syslog (void);
93 extern void error (const char *fs, ...)
94 __attribute__((format (printf,1,2)));
95 extern void perrorf (const char *fs, ...)
96 __attribute__((format (printf,1,2)));
97 extern void warning (const char *fs, ...)
98 __attribute__((format (printf,1,2)));
99 extern void pwarningf (const char *fs, ...)
100 __attribute__((format (printf,1,2)));
101 extern void debug (const char *fs, ...)
102 __attribute__((format (printf,1,2)));
103 extern void message (const char *fs, ...)
104 __attribute__((format (printf,1,2)));
105 extern void paprerror (apr_status_t r, const char *fs, ...)
106 __attribute__((format (printf,2,3)));
108 /* configuration.c */
109 extern void read_main_conf_file (void);
111 /* monitor_sockets.c */
112 extern int sockets_inotify_fd;
113 extern void monitor_socket_dir (void);
116 extern apr_hash_t *commands;
117 extern void execute_command (const struct timespec *now, struct guest_description *hval, const char *command);
118 extern int get_args (apr_array_header_t *args, const char *argfs, ...);
119 extern void send_error (struct guest_description *hval, int code);
120 extern void send_reply (struct guest_description *hval, int code, const char *fs, ...)
121 __attribute__((format (printf,3,4)));
123 typedef void (*command_fn) (struct guest_description *hval, const char *cmd, apr_array_header_t *args);
125 #define REGISTER_COMMAND(name) \
126 static void register_##name (void) __attribute__((constructor)); \
129 register_##name (void) \
134 if (commands == NULL) \
135 commands = apr_hash_make (pool); \
137 /* The assignment below just causes a warning \
138 * if the callback has the wrong type. \
140 command_fn cb = name; \
141 apr_hash_set (commands, #name, APR_HASH_KEY_STRING, cb); \
144 #endif /* HOSTINFOD_H */