Hostinfo day 3: Further work on the daemon.
[virt-hostinfo.git] / hostinfod / hostinfod.h
1 /* virt-hostinfo
2  * Copyright (C) 2009 Red Hat Inc.
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #ifndef HOSTINFOD_H
20 #define HOSTINFOD_H
21
22 #include <time.h>
23
24 #include <apr_general.h>
25 #include <apr_errno.h>
26 #include <apr_pools.h>
27 #include <apr_network_io.h>
28 #include <apr_poll.h>
29
30 enum guest_state {
31   guest_state_connecting,       /* Connecting to socket. */
32   guest_state_request,          /* Waiting or reading the request. */
33   guest_state_reply,            /* Sending the reply. */
34   guest_state_dead              /* Connection is dead. */
35 };
36
37 struct guest_description {
38   int counter;
39   apr_pool_t *pool;             /* Pool for lifetime of guest connection. */
40   const char *name;             /* "driver-name" */
41   const char *sock_path;        /* Full path to socket. */
42   int sock;                     /* Real socket. */
43   apr_socket_t *aprsock;        /* APR socket. */
44   apr_pollfd_t pollfd;          /* APR poll descriptor. */
45   enum guest_state state;       /* State of the connection. */
46
47   /* Increments every time guest does something bad, decremented once per min */
48   unsigned penalty;
49   time_t last_penalty_decr;
50
51   unsigned request_max;         /* Max. length of request buffer. */
52   unsigned request_posn;        /* Position in request buffer. */
53   char *request;                /* Request buffer. */
54
55   unsigned reply_alloc;         /* Allocated for reply buffer. */
56   unsigned reply_size;          /* Size used in reply buffer. */
57   unsigned reply_posn;          /* Position in reply buffer. */
58   char *reply;                  /* Reply buffer. */
59 };
60
61 /* main.c */
62 extern const char *conf_file;
63 extern char *socket_dir;
64 extern char *guests_file;
65 extern int verbose;
66 extern int verbose_set_on_cmdline;
67 extern int foreground;
68 extern int foreground_set_on_cmdline;
69 extern int messages_to_stderr;
70 extern apr_pool_t *pool;        /* pool for global memory allocation */
71
72 /* error.c */
73 extern void init_syslog (void);
74 extern void error (const char *fs, ...)
75   __attribute__((format (printf,1,2)));
76 extern void perrorf (const char *fs, ...)
77   __attribute__((format (printf,1,2)));
78 extern void warning (const char *fs, ...)
79   __attribute__((format (printf,1,2)));
80 extern void pwarningf (const char *fs, ...)
81   __attribute__((format (printf,1,2)));
82 extern void debug (const char *fs, ...)
83   __attribute__((format (printf,1,2)));
84 extern void message (const char *fs, ...)
85   __attribute__((format (printf,1,2)));
86 extern void paprerror (apr_status_t r, const char *fs, ...)
87   __attribute__((format (printf,2,3)));
88
89 /* configuration.c */
90 extern void read_main_conf_file (void);
91
92 /* monitor_sockets.c */
93 extern int sockets_inotify_fd;
94 extern void monitor_socket_dir (void);
95
96 /* commands.c */
97 extern void execute_command (time_t now, struct guest_description *hval, const char *command);
98
99 #endif /* HOSTINFOD_H */