b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#ifndef SMTP_CLIENT_CONNECTION_H
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#define SMTP_CLIENT_CONNECTION_H
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#include "net.h"
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#include "smtp-common.h"
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#include "smtp-client-command.h"
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschenum smtp_capability;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschstruct smtp_reply;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschstruct smtp_client;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschstruct smtp_client_command;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschenum smtp_client_connection_ssl_mode {
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_SSL_MODE_NONE = 0,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_SSL_MODE_IMMEDIATE,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_SSL_MODE_STARTTLS
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch};
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschenum smtp_client_connection_state {
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* No connection */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_CONNECTION_STATE_DISCONNECTED = 0,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Trying to connect */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_CONNECTION_STATE_CONNECTING,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Connected, performing handshake */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_CONNECTION_STATE_HANDSHAKING,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Handshake ready, trying to authenticate */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_CONNECTION_STATE_AUTHENTICATING,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Authenticated, ready to accept commands */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_CONNECTION_STATE_READY,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Involved in active transaction */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_CONNECTION_STATE_TRANSACTION
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch};
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschextern const char *const smtp_client_connection_state_names[];
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschstruct smtp_client_connection *
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschsmtp_client_connection_create(struct smtp_client *client,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch enum smtp_protocol protocol, const char *host, in_port_t port,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch enum smtp_client_connection_ssl_mode ssl_mode,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const struct smtp_client_settings *set)
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch ATTR_NULL(5);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_ref(struct smtp_client_connection *conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_unref(struct smtp_client_connection **_conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_close(struct smtp_client_connection **_conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_cork(struct smtp_client_connection *conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_uncork(struct smtp_client_connection *conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_connect(struct smtp_client_connection *conn,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch smtp_client_command_callback_t login_callback, void *login_context);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_disconnect(struct smtp_client_connection *conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_send_xclient(struct smtp_client_connection *conn,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch struct smtp_proxy_data *xclient);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_connection_switch_ioloop(struct smtp_client_connection *conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschenum smtp_capability
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschsmtp_client_connection_get_capabilities(struct smtp_client_connection *conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschuoff_t smtp_client_connection_get_size_capability(
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch struct smtp_client_connection *conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschenum smtp_client_connection_state
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschsmtp_client_connection_get_state(struct smtp_client_connection *conn);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#endif