master-service.h revision c6335901c67a4c9365319190a111a2168f3b06f5
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan#ifndef MASTER_SERVICE_H
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan#define MASTER_SERVICE_H
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan#include "network.h"
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanenum master_service_flags {
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan /* stdin/stdout already contains a client which we want to serve */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan MASTER_SERVICE_FLAG_STD_CLIENT = 0x01,
c99f4a333122a3c56f6843f08607de4ead6d780aStephen Gallagher /* this process is currently running standalone without a master */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan MASTER_SERVICE_FLAG_STANDALONE = 0x02,
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan /* Log to configured log file instead of stderr. By default when
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan _FLAG_STANDALONE is set, logging is done to stderr. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR = 0x04,
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan /* Service is going to do multiple configuration lookups,
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan keep the connection to config service open. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN = 0x08
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan};
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanstruct master_service_connection {
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher int fd;
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher int listen_fd;
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher struct ip_addr remote_ip;
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher unsigned int remote_port;
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan bool ssl;
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan};
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivantypedef void
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallaghermaster_service_connection_callback_t(const struct master_service_connection *conn);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanstruct master_service;
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanconst char *master_service_getopt_string(void);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher/* Start service initialization. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagherstruct master_service *
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallaghermaster_service_init(const char *name, enum master_service_flags flags,
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher int argc, char *argv[]);
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher/* Parser command line option. Returns TRUE if processed. */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanbool master_service_parse_option(struct master_service *service,
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan int opt, const char *arg);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Finish service initialization. The caller should drop privileges
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan before calling this. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallaghervoid master_service_init_finish(struct master_service *service);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Clean environment from everything except TZ, USER and optionally HOME. */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanvoid master_service_env_clean(bool preserve_home);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Initialize logging. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallaghervoid master_service_init_log(struct master_service *service, const char *prefix,
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan unsigned int max_lines_per_sec);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher/* Set maximum number of clients we can handle. Default is given by master. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallaghervoid master_service_set_client_limit(struct master_service *service,
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher unsigned int client_limit);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Returns the maximum number of clients we can handle. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagherunsigned int master_service_get_client_limit(struct master_service *service);
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher/* Set maximum number of client connections we will handle before shutting
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan down. */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanvoid master_service_set_service_count(struct master_service *service,
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher unsigned int count);
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher/* Returns the number of client connections we will handle before shutting
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher down. The value is decreased only after connection has been closed. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagherunsigned int master_service_get_service_count(struct master_service *service);
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher/* Return the number of listener sockets. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagherunsigned int master_service_get_socket_count(struct master_service *service);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Returns configuration file path. */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanconst char *master_service_get_config_path(struct master_service *service);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Returns PACKAGE_VERSION or NULL if version_ignore=yes. This function is
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher useful mostly as parameter to module_dir_load(). */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanconst char *master_service_get_version_string(struct master_service *service);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Start the service. Blocks until finished */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanvoid master_service_run(struct master_service *service,
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan master_service_connection_callback_t *callback);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Stop a running service. */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanvoid master_service_stop(struct master_service *service);
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher/* Send command to anvil process, if we have fd to it. */
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallaghervoid master_service_anvil_send(struct master_service *service, const char *cmd);
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher/* Call whenever a client connection is destroyed. */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanvoid master_service_client_connection_destroyed(struct master_service *service);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan/* Deinitialize the service. */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanvoid master_service_deinit(struct master_service **service);
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan#endif
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan