1 #ifndef POP3C_CLIENT_H 2 #define POP3C_CLIENT_H 3 4 #include "net.h" 5 #include "pop3c-settings.h" 6 #include "iostream-ssl.h" 7 8 enum pop3c_capability { 9 POP3C_CAPABILITY_PIPELINING = 0x01, 10 POP3C_CAPABILITY_TOP = 0x02, 11 POP3C_CAPABILITY_UIDL = 0x04 12 }; 13 14 enum pop3c_command_state { 15 POP3C_COMMAND_STATE_OK, 16 POP3C_COMMAND_STATE_ERR, 17 POP3C_COMMAND_STATE_DISCONNECTED 18 }; 19 20 enum pop3c_client_ssl_mode { 21 POP3C_CLIENT_SSL_MODE_NONE, 22 POP3C_CLIENT_SSL_MODE_IMMEDIATE, 23 POP3C_CLIENT_SSL_MODE_STARTTLS 24 }; 25 26 struct pop3c_client_settings { 27 const char *host; 28 in_port_t port; 29 30 const char *master_user; 31 const char *username; 32 const char *password; 33 34 const char *dns_client_socket_path; 35 const char *temp_path_prefix; 36 37 enum pop3c_client_ssl_mode ssl_mode; 38 enum pop3c_features parsed_features; 39 struct ssl_iostream_settings ssl_set; 40 41 const char *rawlog_dir; 42 const char *ssl_crypto_device; 43 bool debug; 44 }; 45 46 typedef void pop3c_login_callback_t(enum pop3c_command_state state, 47 const char *reply, void *context); 48 typedef void pop3c_cmd_callback_t(enum pop3c_command_state state, 49 const char *reply, void *context); 50 51 struct pop3c_client * 52 pop3c_client_init(const struct pop3c_client_settings *set, 53 struct event *event_parent); 54 void pop3c_client_deinit(struct pop3c_client **client); 55 56 void pop3c_client_login(struct pop3c_client *client, 57 pop3c_login_callback_t *callback, void *context); 58 59 bool pop3c_client_is_connected(struct pop3c_client *client); 60 enum pop3c_capability 61 pop3c_client_get_capabilities(struct pop3c_client *client); 62 63 /* Returns 0 if received +OK reply, reply contains the text without the +OK. 64 Returns -1 if received -ERR reply or disconnected. */ 65 int pop3c_client_cmd_line(struct pop3c_client *client, const char *cmdline, 66 const char **reply_r); 67 /* Start the command asynchronously. Call the callback when finished. */ 68 struct pop3c_client_cmd * 69 pop3c_client_cmd_line_async(struct pop3c_client *client, const char *cmdline, 70 pop3c_cmd_callback_t *callback, void *context); 71 /* Send a command, don't care if it succeeds or not. */ 72 void pop3c_client_cmd_line_async_nocb(struct pop3c_client *client, 73 const char *cmdline); 74 /* Returns 0 and stream if succeeded, -1 and error if received -ERR reply or 75 disconnected. */ 76 int pop3c_client_cmd_stream(struct pop3c_client *client, const char *cmdline, 77 struct istream **input_r, const char **error_r); 78 /* Start the command asynchronously. Call the callback when finished. */ 79 struct istream * 80 pop3c_client_cmd_stream_async(struct pop3c_client *client, const char *cmdline, 81 pop3c_cmd_callback_t *callback, void *context); 82 /* Wait for the next async command to finish. It's an error to call this when 83 there are no pending async commands. */ 84 void pop3c_client_wait_one(struct pop3c_client *client); 85 86 #endif 87