2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#ifndef MAIL_HOST_H
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#define MAIL_HOST_H
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
bdd36cfdba3ff66d25570a9ff568d69e1eb543cfTimo Sirainen#include "net.h"
33d70dcbb6bf10fd47aa62f29ca8e5f92d116ae4Aki Tuomi#include "user-directory.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenstruct mail_host_list;
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomistruct mail_vhost {
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi unsigned int hash;
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi struct mail_host *host;
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi};
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi/* mail_tags aren't removed/freed before mail_hosts_deinit(), so it's safe
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi to add pointers to them. */
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomistruct mail_tag {
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi /* "" = no tag */
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi char *name;
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi ARRAY(struct mail_vhost) vhosts;
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi /* temporary user -> host associations */
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi struct user_directory *users;
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi};
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki TuomiARRAY_DEFINE_TYPE(mail_tag, struct mail_tag *);
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct mail_host {
87842f621233257b7a7945d994ba931508b34877Timo Sirainen struct mail_host_list *list;
87842f621233257b7a7945d994ba931508b34877Timo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int user_count;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int vhost_count;
a5ddfd7a8b473f73135b93d5e081e470a87f0f7eTimo Sirainen /* server up/down. down=TRUE has effectively the same result as if
a5ddfd7a8b473f73135b93d5e081e470a87f0f7eTimo Sirainen vhost_count=0. */
a5ddfd7a8b473f73135b93d5e081e470a87f0f7eTimo Sirainen bool down;
a5ddfd7a8b473f73135b93d5e081e470a87f0f7eTimo Sirainen time_t last_updown_change;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct ip_addr ip;
cfc891de6eeafd4bf17baa030360acd5447182d9Timo Sirainen char *ip_str;
9de5eb9e1ac3a07c4197a60fdefd412d6cc78eb2Timo Sirainen char *hostname;
ae32667c54480d329eed994b3defab89cd76c077Timo Sirainen struct mail_tag *tag;
8752573c44bcd139ae3ecc6d8e917c2c60bcb89fTimo Sirainen
8752573c44bcd139ae3ecc6d8e917c2c60bcb89fTimo Sirainen /* host was recently changed and ring hasn't synced yet since */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool desynced:1;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen};
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo SirainenARRAY_DEFINE_TYPE(mail_host, struct mail_host *);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenstruct mail_host *
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainenmail_host_add_ip(struct mail_host_list *list, const struct ip_addr *ip,
e3751d40053ce9ad5001284f1bc8a0e5ba42ce10Timo Sirainen const char *tag_name);
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenstruct mail_host *
9de5eb9e1ac3a07c4197a60fdefd412d6cc78eb2Timo Sirainenmail_host_add_hostname(struct mail_host_list *list, const char *hostname,
e3751d40053ce9ad5001284f1bc8a0e5ba42ce10Timo Sirainen const struct ip_addr *ip, const char *tag_name);
9de5eb9e1ac3a07c4197a60fdefd412d6cc78eb2Timo Sirainenstruct mail_host *
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenmail_host_lookup(struct mail_host_list *list, const struct ip_addr *ip);
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenstruct mail_host *
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainenmail_host_get_by_hash(struct mail_host_list *list, unsigned int hash,
e3751d40053ce9ad5001284f1bc8a0e5ba42ce10Timo Sirainen const char *tag_name);
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenint mail_hosts_parse_and_add(struct mail_host_list *list,
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen const char *hosts_string);
4af552f09aad93a2ae09efa6024f4ec6bb11f499Aki Tuomiconst char *mail_host_get_tag(const struct mail_host *host);
e3751d40053ce9ad5001284f1bc8a0e5ba42ce10Timo Sirainenvoid mail_host_set_tag(struct mail_host *host, const char *tag_name);
b3abfd0ac256ffa0cbfd74c3793eac4e83d41f78Martti Rannanjärvivoid mail_host_set_down(struct mail_host *host, bool down, time_t timestamp,
b3abfd0ac256ffa0cbfd74c3793eac4e83d41f78Martti Rannanjärvi const char *log_prefix);
b3abfd0ac256ffa0cbfd74c3793eac4e83d41f78Martti Rannanjärvivoid mail_host_set_vhost_count(struct mail_host *host, unsigned int vhost_count,
b3abfd0ac256ffa0cbfd74c3793eac4e83d41f78Martti Rannanjärvi const char *log_prefix);
87842f621233257b7a7945d994ba931508b34877Timo Sirainenvoid mail_host_remove(struct mail_host *host);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
8752573c44bcd139ae3ecc6d8e917c2c60bcb89fTimo Sirainenvoid mail_hosts_set_synced(struct mail_host_list *list);
131cb5910775213d5bc0dcf75e4fddda6f8c5a11Timo Sirainenunsigned int mail_hosts_hash(struct mail_host_list *list);
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainenbool mail_hosts_have_usable(struct mail_host_list *list);
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenconst ARRAY_TYPE(mail_host) *mail_hosts_get(struct mail_host_list *list);
ae32667c54480d329eed994b3defab89cd76c077Timo Sirainenbool mail_hosts_have_tags(struct mail_host_list *list);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomiconst ARRAY_TYPE(mail_tag) *mail_hosts_get_tags(struct mail_host_list *list);
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomistruct mail_tag *
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomimail_tag_find(struct mail_host_list *list, const char *tag_name);
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomistruct user *
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomimail_hosts_find_user(struct mail_host_list *list, const char *tag_name,
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi unsigned int username_hash);
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomistruct mail_host_list *
00cc7eb569710722af0e0af652034b9fc22c57dfMartti Rannanjärvimail_hosts_init(unsigned int user_expire_secs,
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomi user_free_hook_t *user_free_hook);
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenvoid mail_hosts_deinit(struct mail_host_list **list);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainenstruct mail_host_list *mail_hosts_dup(const struct mail_host_list *src);
b44033e45e9f48f8a6e1ac5905234fec5de6d6ccAki Tuomivoid mail_hosts_sort_users(struct mail_host_list *list);
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#endif