55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen#ifndef DOVEADM_CMD_H
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen#define DOVEADM_CMD_H
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen
50e4970035d1278597d13cac6c5ae26e7af93025Timo Sirainen#include "net.h"
50e4970035d1278597d13cac6c5ae26e7af93025Timo Sirainen
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi#define DOVEADM_CMD_PARAMS_START .parameters = (const struct doveadm_cmd_param[]){
14102a0c5db8828ca8c7751ec96587fadc97a0bcTimo Sirainen#define DOVEADM_CMD_PARAM(optP, nameP, typeP, flagP ) { .short_opt = optP, .name = nameP, .type = typeP, .flags = flagP },
14102a0c5db8828ca8c7751ec96587fadc97a0bcTimo Sirainen#define DOVEADM_CMD_PARAMS_END { .short_opt = '\0', .name = NULL, .type = CMD_PARAM_BOOL, .flags = CMD_PARAM_FLAG_NONE } }
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomistruct doveadm_cmd_ver2;
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomistruct doveadm_cmd_context;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomistruct doveadm_mail_cmd_context;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainentypedef void doveadm_command_t(int argc, char *argv[]);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomitypedef enum {
05128fda80748e107bccdece0a3d23551e99e8f3Timo Sirainen CMD_PARAM_BOOL = 0, /* value will contain 1 (not pointer) */
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi CMD_PARAM_INT64, /* ditto but contains number (not pointer) */
79ec87ea6861e2dd447f69ab44a7cc4e4fce3fddAki Tuomi CMD_PARAM_IP, /* value contains struct ip_addr */
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi CMD_PARAM_STR, /* value contains const char* */
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi CMD_PARAM_ARRAY, /* value contains const char*[] */
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi CMD_PARAM_ISTREAM /* value contains struct istream* */
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi} doveadm_cmd_param_t;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomitypedef enum {
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi CMD_PARAM_FLAG_NONE = 0x0,
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi CMD_PARAM_FLAG_POSITIONAL = 0x1,
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi CMD_PARAM_FLAG_DO_NOT_EXPOSE = 0x2,
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi} doveadm_cmd_param_flag_t;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
3fd8086f71f25a68e33993e24123b10b671dac67Aki Tuomitypedef enum {
3fd8086f71f25a68e33993e24123b10b671dac67Aki Tuomi CMD_FLAG_NONE = 0x0,
bd13998cde153abdb189593ad4229bf73bc2dd34Aki Tuomi CMD_FLAG_HIDDEN = 0x1,
bd13998cde153abdb189593ad4229bf73bc2dd34Aki Tuomi CMD_FLAG_NO_PRINT = 0x2,
3fd8086f71f25a68e33993e24123b10b671dac67Aki Tuomi} doveadm_cmd_flag_t;
3fd8086f71f25a68e33993e24123b10b671dac67Aki Tuomi
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomistruct doveadm_cmd_param {
14102a0c5db8828ca8c7751ec96587fadc97a0bcTimo Sirainen char short_opt;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi const char *name;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi doveadm_cmd_param_t type;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi bool value_set;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi struct {
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi bool v_bool;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi int64_t v_int64;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi const char* v_string;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi ARRAY_TYPE(const_string) v_array;
79ec87ea6861e2dd447f69ab44a7cc4e4fce3fddAki Tuomi struct ip_addr v_ip;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi struct istream* v_istream;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi } value;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi doveadm_cmd_param_flag_t flags;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi};
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki TuomiARRAY_DEFINE_TYPE(doveadm_cmd_param_arr_t, struct doveadm_cmd_param);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomitypedef void doveadm_command_ver2_t(struct doveadm_cmd_context *cctx);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenstruct doveadm_cmd {
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen doveadm_command_t *cmd;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen const char *name;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen const char *short_usage;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen};
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomistruct doveadm_cmd_ver2 {
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi doveadm_command_ver2_t *cmd;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi doveadm_command_t *old_cmd;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi struct doveadm_mail_cmd_context *(*mail_cmd)(void);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi const char *name;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi const char *usage;
3fd8086f71f25a68e33993e24123b10b671dac67Aki Tuomi doveadm_cmd_flag_t flags;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi const struct doveadm_cmd_param *parameters;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi};
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomistruct doveadm_cmd_context {
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomi const struct doveadm_cmd_ver2 *cmd; /* for help */
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomi
79bbb900ffba886779474dfb04c41408f0ba0602Timo Sirainen int argc;
2029c2cb37d7308e74329c9a15b6cf07a3468314Timo Sirainen const struct doveadm_cmd_param *argv;
50e4970035d1278597d13cac6c5ae26e7af93025Timo Sirainen
50e4970035d1278597d13cac6c5ae26e7af93025Timo Sirainen const char *username;
50e4970035d1278597d13cac6c5ae26e7af93025Timo Sirainen struct ip_addr local_ip, remote_ip;
50e4970035d1278597d13cac6c5ae26e7af93025Timo Sirainen in_port_t local_port, remote_port;
1b58508a918279d773ef32518f5d5d933023c252Stephan Bosch
6fc40674e5a33787ae7fcd47a77a77ea20977994Aki Tuomi enum doveadm_client_type conn_type;
1b58508a918279d773ef32518f5d5d933023c252Stephan Bosch struct istream *input;
1b58508a918279d773ef32518f5d5d933023c252Stephan Bosch struct ostream *output;
79bbb900ffba886779474dfb04c41408f0ba0602Timo Sirainen};
79bbb900ffba886779474dfb04c41408f0ba0602Timo Sirainen
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo SirainenARRAY_DEFINE_TYPE(doveadm_cmd, struct doveadm_cmd);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenextern ARRAY_TYPE(doveadm_cmd) doveadm_cmds;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki TuomiARRAY_DEFINE_TYPE(doveadm_cmd_ver2, struct doveadm_cmd_ver2);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomiextern ARRAY_TYPE(doveadm_cmd_ver2) doveadm_cmds_ver2;
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenextern struct doveadm_cmd doveadm_cmd_dump;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenextern struct doveadm_cmd doveadm_cmd_pw;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenextern struct doveadm_cmd doveadm_cmd_mailbox_mutf7;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenextern struct doveadm_cmd doveadm_cmd_sis_deduplicate;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenextern struct doveadm_cmd doveadm_cmd_sis_find;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenextern struct doveadm_cmd doveadm_cmd_zlibconnect;
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_cmd(const struct doveadm_cmd *cmd);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenconst struct doveadm_cmd *
36a052b7bd94ccb47abbb6b15c1380f03780ba20Timo Sirainendoveadm_cmd_find_with_args(const char *cmd_name, int *argc,
36a052b7bd94ccb47abbb6b15c1380f03780ba20Timo Sirainen const char *const *argv[]);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_auth_commands(void);
a13b1245bee0b6524b4aeb3c8fd9e34af648b746Aki Tuomivoid doveadm_register_auth_server_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_director_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_proxy_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_log_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_instance_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_mount_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_replicator_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_dict_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_register_fs_commands(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_cmds_init(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainenvoid doveadm_cmds_deinit(void);
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomivoid doveadm_cmd_ver2_to_cmd_wrapper(struct doveadm_cmd_context *cctx);
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomivoid doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomivoid doveadm_cmd_register_ver2(struct doveadm_cmd_ver2 *cmd);
7d500ecf27acc5b65615ee9e72d6da6bacf799d2Timo Sirainenconst struct doveadm_cmd_ver2 *
6a8c95b0693c93601e948e06bfe1f89abdd43307Timo Sirainendoveadm_cmd_find_with_args_ver2(const char *cmd_name, int *argc,
6a8c95b0693c93601e948e06bfe1f89abdd43307Timo Sirainen const char *const *argv[]);
7a8ef11587fd50d5888223fc3d91911775a21ba5Aki Tuomiconst struct doveadm_cmd_ver2 *doveadm_cmd_find_ver2(const char *cmd_name);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi/* Returns FALSE if cmd_name doesn't exist, TRUE if it exists. */
79bbb900ffba886779474dfb04c41408f0ba0602Timo Sirainenbool doveadm_cmd_try_run_ver2(const char *cmd_name,
36a052b7bd94ccb47abbb6b15c1380f03780ba20Timo Sirainen int argc, const char *const argv[],
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomi struct doveadm_cmd_context *cctx);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi/* Returns 0 if success, -1 if parameters were invalid. */
36a052b7bd94ccb47abbb6b15c1380f03780ba20Timo Sirainenint doveadm_cmd_run_ver2(int argc, const char *const argv[],
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomi struct doveadm_cmd_context *cctx);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomibool doveadm_cmd_param_bool(const struct doveadm_cmd_context *cctx,
db8b229230860a6c12daa0017a49396986368897Aki Tuomi const char *name, bool *value_r);
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomibool doveadm_cmd_param_int64(const struct doveadm_cmd_context *cctx,
db8b229230860a6c12daa0017a49396986368897Aki Tuomi const char *name, int64_t *value_r);
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomibool doveadm_cmd_param_str(const struct doveadm_cmd_context *cctx,
db8b229230860a6c12daa0017a49396986368897Aki Tuomi const char *name, const char **value_r);
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomibool doveadm_cmd_param_ip(const struct doveadm_cmd_context *cctx,
db8b229230860a6c12daa0017a49396986368897Aki Tuomi const char *name, struct ip_addr *value_r);
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomibool doveadm_cmd_param_array(const struct doveadm_cmd_context *cctx,
4afc67eb96f8d6b7dc94d63d3c7fe4f556c4fceeTimo Sirainen const char *name, const char *const **value_r);
aaa1b6bb4cd2d7f8f4e7977d61176ea1c8f7e32bAki Tuomibool doveadm_cmd_param_istream(const struct doveadm_cmd_context *cctx,
db8b229230860a6c12daa0017a49396986368897Aki Tuomi const char *name, struct istream **value_r);
14af7be4aa26d55c341cd6efe32bb2add2c39830Aki Tuomi
1e8a6a8708b612eee65f83ef6874aab94b15eb50Timo Sirainenvoid doveadm_cmd_params_clean(ARRAY_TYPE(doveadm_cmd_param_arr_t) *pargv);
2029c2cb37d7308e74329c9a15b6cf07a3468314Timo Sirainenvoid doveadm_cmd_params_null_terminate_arrays(ARRAY_TYPE(doveadm_cmd_param_arr_t) *pargv);
1e8a6a8708b612eee65f83ef6874aab94b15eb50Timo Sirainen
53309922d2ec3321e011966e8f2b210821ecd5e3Timo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_service_stop_ver2;
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_service_status_ver2;
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_process_status_ver2;
68cc278710182485b6c09e9a9ff8db90a727f343Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_stop_ver2;
68cc278710182485b6c09e9a9ff8db90a727f343Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_reload_ver2;
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_stats_dump_ver2;
6ef83bcdc4e40d6b387857e5f7d58cd86c71ec50Timo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_oldstats_reset_ver2;
6ef83bcdc4e40d6b387857e5f7d58cd86c71ec50Timo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_oldstats_dump_ver2;
6ef83bcdc4e40d6b387857e5f7d58cd86c71ec50Timo Sirainenextern struct doveadm_cmd_ver2 doveadm_cmd_oldstats_top_ver2;
7616a1520f0d8ee5cc96f6b044c7fde1a9f9798cAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_penalty_ver2;
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_kick_ver2;
99819adc9638200bc2ec1b68da9d2c68e8435740Aki Tuomiextern struct doveadm_cmd_ver2 doveadm_cmd_who_ver2;
68cc278710182485b6c09e9a9ff8db90a727f343Aki Tuomi
55accf49e32ff93bfdd92961cb54ccc8c329147cTimo Sirainen#endif