2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#ifndef CLIENT_H
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define CLIENT_H
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#include "net.h"
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct smtp_reply;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct client;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct client_command_context;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct client_state {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct istream *data_input;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uoff_t data_size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct client {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct client *prev, *next;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch char *session_id;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const struct setting_parser_info *user_set_info;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const struct submission_settings *set;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct smtp_server_connection *conn;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch enum smtp_server_state last_state;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct client_state state;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct mail_storage_service_user *service_user;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct mail_user *user;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* IMAP URLAUTH context (RFC4467) for BURL (RFC4468) */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct imap_urlauth_context *urlauth_ctx;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct smtp_client_connection *proxy_conn;
961a5c472495203d4714a059a192fb0bf72d56d5Stephan Bosch struct timeout *to_quit;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct smtp_server_stats stats;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch bool standalone:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch bool xclient_sent:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch bool disconnected:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch bool destroyed:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch bool anvil_sent:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschextern struct client *submission_clients;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschextern unsigned int submission_client_count;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct client *client_create(int fd_in, int fd_out,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *session_id, struct mail_user *user,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct mail_storage_service_user *service_user,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const struct submission_settings *set,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *helo,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const unsigned char *pdata,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch unsigned int pdata_len);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid client_destroy(struct client *client, const char *prefix,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *reason) ATTR_NULL(2, 3);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid client_disconnect(struct client *client, const char *prefix,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *reason);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschtypedef void (*client_input_callback_t)(struct client *context);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschconst char *client_state_get_name(struct client *client);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschbool client_proxy_is_ready(struct client *client);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschbool client_proxy_is_disconnected(struct client *client);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschuoff_t client_get_max_mail_size(struct client *client);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint client_input_read(struct client *client);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint client_handle_input(struct client *client);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid clients_destroy_all(void);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#endif