bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi#ifndef PROGRAM_CLIENT_H
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi#define PROGRAM_CLIENT_H
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
1acc8d6538864577b8f40cc4e1ca922a62f52327Aki Tuomi#include "restrict-access.h"
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomi#include "net.h"
1acc8d6538864577b8f40cc4e1ca922a62f52327Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct program_client;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct program_client_settings {
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi unsigned int client_connect_timeout_msecs;
17541ea25593c656060199715051db2c1eef221dAki Tuomi unsigned int input_idle_timeout_msecs;
1acc8d6538864577b8f40cc4e1ca922a62f52327Aki Tuomi /* initialize with
1acc8d6538864577b8f40cc4e1ca922a62f52327Aki Tuomi restrict_access_init(&set.restrict_set);
1acc8d6538864577b8f40cc4e1ca922a62f52327Aki Tuomi */
1acc8d6538864577b8f40cc4e1ca922a62f52327Aki Tuomi struct restrict_access_settings restrict_set;
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomi const char *dns_client_socket_path;
1acc8d6538864577b8f40cc4e1ca922a62f52327Aki Tuomi const char *home;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
1acc8d6538864577b8f40cc4e1ca922a62f52327Aki Tuomi bool allow_root:1;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi bool debug:1;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi bool drop_stderr:1;
e9853e8d860bd8c2b003f30deeba6716a093d7e3Stephan Bosch /* use o_stream_dot, which is mainly useful to make sure that an
e9853e8d860bd8c2b003f30deeba6716a093d7e3Stephan Bosch unexpectedly closed connection doesn't cause the partial input to
e9853e8d860bd8c2b003f30deeba6716a093d7e3Stephan Bosch be accepted as valid and complete program input. This is always
e9853e8d860bd8c2b003f30deeba6716a093d7e3Stephan Bosch enabled for 'net' program clients, which may likely encounter
e9853e8d860bd8c2b003f30deeba6716a093d7e3Stephan Bosch unexpected connection termination. */
a371ea8bd48d45548cd7aa16d4f5aeb38ba48c91Aki Tuomi bool use_dotstream:1;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi};
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomitypedef void program_client_fd_callback_t(void *context, struct istream *input);
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomitypedef void program_client_callback_t(int, void *);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct program_client *program_client_local_create(const char *bin_path,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *const *args,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const struct program_client_settings *set);
9f29dfcbf3812c4f88ffb1c99b5a56b2e8091ea4Aki Tuomistruct program_client *program_client_unix_create(const char *socket_path,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *const *args,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const struct program_client_settings *set, bool noreply);
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomistruct program_client *program_client_net_create(const char *host, in_port_t port,
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomi const char *const *args,
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomi const struct program_client_settings *set, bool noreply);
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomistruct program_client *
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomiprogram_client_net_create_ips(const struct ip_addr *ips, size_t ips_count,
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomi in_port_t port, const char *const *args,
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomi const struct program_client_settings *set,
366f669495b4b507084e43a56c0a9d201f120b7dAki Tuomi bool noreply);
4a197212360f75bfc89254bfd5bc4a31151fe4b4Timo Sirainenint program_client_create(const char *uri, const char *const *args,
4a197212360f75bfc89254bfd5bc4a31151fe4b4Timo Sirainen const struct program_client_settings *set,
4a197212360f75bfc89254bfd5bc4a31151fe4b4Timo Sirainen bool noreply, struct program_client **pc_r,
4a197212360f75bfc89254bfd5bc4a31151fe4b4Timo Sirainen const char **error_r);
80521bcdd28b22818480a6e6e1ae84230e19c1baAki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid program_client_destroy(struct program_client **_pclient);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid program_client_set_input(struct program_client *pclient,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi struct istream *input);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid program_client_set_output(struct program_client *pclient,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi struct ostream *output);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid program_client_set_output_seekable(struct program_client *pclient,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *temp_prefix);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct istream *program_client_get_output_seekable(struct program_client *pclient);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomivoid program_client_switch_ioloop(struct program_client *pclient);
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* Program provides side-channel output through an extra fd */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid program_client_set_extra_fd(struct program_client *pclient, int fd,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi program_client_fd_callback_t * callback, void *context);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi#define program_client_set_extra_fd(pclient, fd, callback, context) \
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi program_client_set_extra_fd(pclient, fd + \
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi CALLBACK_TYPECHECK(callback, \
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi void (*)(typeof(context), struct istream *input)), \
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi (program_client_fd_callback_t *)callback, context)
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid program_client_set_env(struct program_client *pclient,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *name, const char *value);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi/* Since script service cannot return system exit code, the exit value shall be
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi -1, 0, or 1. -1 is internal error, 0 is failure and 1 is success */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomiint program_client_run(struct program_client *pclient);
1be27c35ea17fccd83c54e2acc66eb8c44d1a8feAki Tuomivoid program_client_run_async(struct program_client *pclient,
1be27c35ea17fccd83c54e2acc66eb8c44d1a8feAki Tuomi program_client_callback_t *, void*);
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi#define program_client_run_async(pclient, callback, context) \
1be27c35ea17fccd83c54e2acc66eb8c44d1a8feAki Tuomi program_client_run_async(pclient, (program_client_callback_t*)callback, \
1be27c35ea17fccd83c54e2acc66eb8c44d1a8feAki Tuomi (char*)context + CALLBACK_TYPECHECK(callback, \
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi void (*)(int, typeof(context))))
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi#endif