1 #ifndef SMTP_CLIENT_CONNECTION_H
2 #define SMTP_CLIENT_CONNECTION_H
3 
4 #include "net.h"
5 #include "smtp-common.h"
6 
7 #include "smtp-client-command.h"
8 
9 enum smtp_capability;
10 
11 struct smtp_reply;
12 struct smtp_client;
13 struct smtp_client_capability_extra;
14 struct smtp_client_settings;
15 struct smtp_client_command;
16 
17 enum smtp_client_connection_ssl_mode {
18 	SMTP_CLIENT_SSL_MODE_NONE = 0,
19 	SMTP_CLIENT_SSL_MODE_IMMEDIATE,
20 	SMTP_CLIENT_SSL_MODE_STARTTLS
21 };
22 
23 enum smtp_client_connection_state {
24 	/* No connection */
25 	SMTP_CLIENT_CONNECTION_STATE_DISCONNECTED = 0,
26 	/* Trying to connect */
27 	SMTP_CLIENT_CONNECTION_STATE_CONNECTING,
28 	/* Connected, performing handshake */
29 	SMTP_CLIENT_CONNECTION_STATE_HANDSHAKING,
30 	/* Handshake ready, trying to authenticate */
31 	SMTP_CLIENT_CONNECTION_STATE_AUTHENTICATING,
32 	/* Authenticated, ready to accept commands */
33 	SMTP_CLIENT_CONNECTION_STATE_READY,
34 	/* Involved in active transaction */
35 	SMTP_CLIENT_CONNECTION_STATE_TRANSACTION
36 };
37 extern const char *const smtp_client_connection_state_names[];
38 
39 struct smtp_client_connection *
40 smtp_client_connection_create(struct smtp_client *client,
41 			      enum smtp_protocol protocol,
42 			      const char *host, in_port_t port,
43 			      enum smtp_client_connection_ssl_mode ssl_mode,
44 			      const struct smtp_client_settings *set)
45 			      ATTR_NULL(6);
46 struct smtp_client_connection *
47 smtp_client_connection_create_ip(struct smtp_client *client,
48 				 enum smtp_protocol protocol,
49 				 const struct ip_addr *ip, in_port_t port,
50 				 const char *hostname,
51 				 enum smtp_client_connection_ssl_mode ssl_mode,
52 				 const struct smtp_client_settings *set)
53 				 ATTR_NULL(5, 7);
54 struct smtp_client_connection *
55 smtp_client_connection_create_unix(struct smtp_client *client,
56 				   enum smtp_protocol protocol,
57 				   const char *path,
58 				   const struct smtp_client_settings *set)
59 				   ATTR_NULL(4);
60 
61 void smtp_client_connection_ref(struct smtp_client_connection *conn);
62 void smtp_client_connection_unref(struct smtp_client_connection **_conn);
63 void smtp_client_connection_close(struct smtp_client_connection **_conn);
64 
65 void smtp_client_connection_update_proxy_data(
66 	struct smtp_client_connection *conn,
67 	const struct smtp_proxy_data *proxy_data);
68 
69 void smtp_client_connection_cork(struct smtp_client_connection *conn);
70 void smtp_client_connection_uncork(struct smtp_client_connection *conn);
71 
72 void smtp_client_connection_connect(
73 	struct smtp_client_connection *conn,
74 	smtp_client_command_callback_t login_callback, void *login_context);
75 void smtp_client_connection_disconnect(struct smtp_client_connection *conn);
76 
77 void smtp_client_connection_switch_ioloop(struct smtp_client_connection *conn);
78 
79 enum smtp_capability
80 smtp_client_connection_get_capabilities(struct smtp_client_connection *conn);
81 uoff_t smtp_client_connection_get_size_capability(
82 	struct smtp_client_connection *conn);
83 void smtp_client_connection_accept_extra_capability(
84 	struct smtp_client_connection *conn,
85 	const struct smtp_client_capability_extra *cap);
86 const struct smtp_capability_extra *
87 smtp_client_connection_get_extra_capability(struct smtp_client_connection *conn,
88 					    const char *name);
89 
90 enum smtp_client_connection_state
91 smtp_client_connection_get_state(struct smtp_client_connection *conn);
92 
93 #endif
94