doveadm-util.c revision 250a06cde50c4004ac1cc72279b75a229a7f90f5
5e0ce63bb65db34d7f48b34bbb5545fa791781c4Timo Sirainen/* Copyright (c) 2009-2013 Dovecot authors, see the included COPYING file */
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainenbool doveadm_verbose = FALSE, doveadm_debug = FALSE, doveadm_server = FALSE;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* some doveadm plugins have dependencies to mail plugins. we can load
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen only those whose dependencies have been loaded earlier, the rest are
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen modules = module_dir_load_missing(modules, DOVEADM_MODULEDIR,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenbool doveadm_has_unloaded_plugin(const char *name)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen /* first check that it's not actually loaded */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen for (module = modules; module != NULL; module = module->next) {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (strcmp(module_get_plugin_name(module), name) == 0)
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen plugin_name = module_file_get_name(d->d_name);
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen if (strncmp(plugin_name, name, name_len) == 0 &&
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen strcmp(plugin_name + name_len, "_plugin") == 0)) {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen return t_strflocaltime("%Y-%m-%d %H:%M:%S", timestamp);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainenconst char *doveadm_plugin_getenv(const char *name)
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainen const char *const *envs;
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainen unsigned int i, count;
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainen if (!array_is_created(&doveadm_settings->plugin_envs))
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen envs = array_get(&doveadm_settings->plugin_envs, &count);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenparse_hostport(const char *str, unsigned int default_port,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const char *p;
af81f402ddc897c74c1e85abd02879612ce44882Timo Sirainen /* host:port */
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen if (p == NULL || str_to_uint(p+1, port_r) < 0)
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen /* there is any '/' character (unlikely to be found from host names),
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen assume ':' is part of a file path */
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainenint doveadm_connect_with_default_port(const char *path,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen if (parse_hostport(path, default_port, &host, &port) &&
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* it's a host:port, connect via TCP */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen ret = net_gethostbyname(host, &ips, &ips_count);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen fd = net_connect_ip_blocking(&ips[0], port, NULL);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen i_fatal("net_connect_unix(%s) failed: %m", path);