71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen#ifndef SERVER_CONNECTION_H
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen#define SERVER_CONNECTION_H
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
8ad7aa4ddf9e37fc1aefdf84f90071f49fc2619cTimo Sirainen#define SERVER_EXIT_CODE_DISCONNECTED 1000
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstruct doveadm_server;
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenstruct server_connection;
8c5d1951a2e5bced3bfcb7fc6c2fac8d4bf47341Timo Sirainenstruct ssl_iostream;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
956b8eea7ae479a38b25175447fc8eac2df30480Timo Sirainentypedef void server_cmd_callback_t(int exit_code, const char *error,
956b8eea7ae479a38b25175447fc8eac2df30480Timo Sirainen void *context);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenint server_connection_create(struct doveadm_server *server,
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen struct server_connection **conn_r);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenvoid server_connection_destroy(struct server_connection **conn);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Return the server given to create() */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstruct doveadm_server *
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenserver_connection_get_server(struct server_connection *conn);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenvoid server_connection_cmd(struct server_connection *conn, const char *line,
32c779d5d0b3dabc697408e6b5d9d2e652180b33Timo Sirainen struct istream *cmd_input,
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen server_cmd_callback_t *callback, void *context);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Returns TRUE if no command is being processed */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenbool server_connection_is_idle(struct server_connection *conn);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
07ce366ac19bc96be354d26a04305de300c6fe3eTimo Sirainen/* Extract iostreams from connection. Afterwards the server_connection simply
07ce366ac19bc96be354d26a04305de300c6fe3eTimo Sirainen waits for itself to be destroyed. */
07ce366ac19bc96be354d26a04305de300c6fe3eTimo Sirainenvoid server_connection_extract(struct server_connection *conn,
07ce366ac19bc96be354d26a04305de300c6fe3eTimo Sirainen struct istream **istream_r,
8c5d1951a2e5bced3bfcb7fc6c2fac8d4bf47341Timo Sirainen struct ostream **ostream_r,
8c5d1951a2e5bced3bfcb7fc6c2fac8d4bf47341Timo Sirainen struct ssl_iostream **ssl_iostream_r);
0a9cb42cbb135e3200cbfbb657820304cca8ecb8Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen#endif