Documentation fixes.
[virt-hostinfo.git] / hostinfod / hostinfod.h
index 99a1efb..8bb48e6 100644 (file)
 #ifndef HOSTINFOD_H
 #define HOSTINFOD_H
 
+#include <time.h>
+
 #include <apr_general.h>
+#include <apr_errno.h>
+#include <apr_pools.h>
+#include <apr_network_io.h>
+#include <apr_poll.h>
+#include <apr_hash.h>
+
+#include <libvirt/libvirt.h>
+
+enum guest_state {
+  guest_state_connecting,      /* Connecting to socket. */
+  guest_state_request,         /* Waiting or reading the request. */
+  guest_state_reply,           /* Sending the reply. */
+  guest_state_dead             /* Connection is dead. */
+};
+
+struct guest_description {
+  apr_pool_t *pool;            /* Pool for lifetime of guest connection. */
+
+  apr_pool_t *rpool;           /* Pool for lifetime of single req/resp. */
+
+  const char *name;            /* "driver-name" */
+  const char *sock_path;       /* Full path to socket. */
+  int sock;                    /* Real socket. */
+  apr_socket_t *aprsock;       /* APR socket. */
+  apr_pollfd_t pollfd;         /* APR poll descriptor. */
+  enum guest_state state;      /* State of the connection. */
+  int counter;                 /* Used in reread_socket_dir. */
+
+  unsigned request_max;                /* Max. length of request buffer. */
+  unsigned request_posn;       /* Position in request buffer. */
+  char *request;               /* Request buffer. */
+
+  unsigned reply_size;         /* Size of reply buffer. */
+  unsigned reply_posn;         /* Position in reply buffer. */
+  char *reply;                 /* Reply buffer. */
+
+  /* Increments every time guest does something bad, decremented once per min */
+  unsigned penalty;
+  struct timespec last_penalty_decr;
+
+  /* Hash records last time each command was run by this guest. */
+  apr_hash_t *lasttime;
+};
+
+enum arg_type {
+  arg_type_string,
+  arg_type_int,
+  arg_type_bool,
+};
+
+struct arg {
+  enum arg_type type;
+  union {
+    long i;                    /* For int, bool types. */
+    char *str;                 /* For string type. */
+  } u;
+};
 
 /* main.c */
 extern const char *conf_file;
-extern const char *socket_dir;
+extern char *socket_dir;
 extern char *guests_file;
-extern int socket_dir_set_on_cmdline;
-extern int debug;
-extern int debug_set_on_cmdline;
+extern char *libvirt_uri;
+extern int libvirt_uri_set_on_cmdline;
 extern int verbose;
 extern int verbose_set_on_cmdline;
 extern int foreground;
 extern int foreground_set_on_cmdline;
+extern int messages_to_stderr;
 extern apr_pool_t *pool;       /* pool for global memory allocation */
+extern void initialize (void);
+extern struct timespec *diff_timespec (struct timespec *r, const struct timespec *a, const struct timespec *b); /* r = a - b */
+
+/* error.c */
+extern void init_syslog (void);
+extern void error (const char *fs, ...)
+  __attribute__((format (printf,1,2)));
+extern void perrorf (const char *fs, ...)
+  __attribute__((format (printf,1,2)));
+extern void warning (const char *fs, ...)
+  __attribute__((format (printf,1,2)));
+extern void pwarningf (const char *fs, ...)
+  __attribute__((format (printf,1,2)));
+extern void debug (const char *fs, ...)
+  __attribute__((format (printf,1,2)));
+extern void message (const char *fs, ...)
+  __attribute__((format (printf,1,2)));
+extern void paprerror (apr_status_t r, const char *fs, ...)
+  __attribute__((format (printf,2,3)));
 
 /* configuration.c */
 extern void read_main_conf_file (void);
+extern void check_guests_file (struct guest_description *hval, const char *cmd, double *interval, int *enabled);
+
+/* monitor_sockets.c */
+extern int sockets_inotify_fd;
+extern void monitor_socket_dir (void);
+
+/* commands.c */
+extern apr_hash_t *commands;
+extern void execute_command (const struct timespec *now, struct guest_description *hval, const char *command);
+extern int get_args (apr_array_header_t *args, const char *argfs, ...);
+extern void send_error (struct guest_description *hval, int code);
+extern void send_reply (struct guest_description *hval, int code, const char *fs, ...)
+  __attribute__((format (printf,3,4)));
+
+typedef void (*command_fn) (struct guest_description *hval, const char *cmd, apr_array_header_t *args);
+
+#define REGISTER_COMMAND(name)                                         \
+  static void register_##name (void) __attribute__((constructor));     \
+                                                                       \
+  static void                                                          \
+  register_##name (void)                                               \
+  {                                                                    \
+    if (pool == NULL)                                                  \
+      initialize ();                                                   \
+                                                                       \
+    if (commands == NULL)                                              \
+      commands = apr_hash_make (pool);                                 \
+                                                                       \
+    /* The assignment below just causes a warning                      \
+     * if the callback has the wrong type.                             \
+     */                                                                        \
+    command_fn cb = name;                                              \
+    apr_hash_set (commands, #name, APR_HASH_KEY_STRING, cb);           \
+  }
+
+/* virt.c */
+extern void init_libvirt (void);
+extern virConnectPtr conn;
+extern virNodeInfo nodeinfo;
 
 #endif /* HOSTINFOD_H */