diff options
Diffstat (limited to 'src/rexmpp_tcp.h')
-rw-r--r-- | src/rexmpp_tcp.h | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/src/rexmpp_tcp.h b/src/rexmpp_tcp.h index e4a6dff..8ee32a0 100644 --- a/src/rexmpp_tcp.h +++ b/src/rexmpp_tcp.h @@ -19,13 +19,16 @@ #ifndef REXMPP_TCP_H #define REXMPP_TCP_H +#include <sys/time.h> +#include <stdbool.h> + +#include "rexmpp.h" +#include "rexmpp_dns.h" + #define REXMPP_TCP_MAX_CONNECTION_ATTEMPTS 20 #define REXMPP_TCP_IPV6_DELAY_MS 50 #define REXMPP_TCP_CONN_DELAY_MS 250 -typedef enum rexmpp_tcp_conn_resolution_status -rexmpp_tcp_conn_resolution_status_t; - /** @brief Resolution status. */ @@ -40,7 +43,8 @@ enum rexmpp_tcp_conn_resolution_status { REXMPP_CONN_RESOLUTION_FAILURE }; -typedef enum rexmpp_tcp_conn_error rexmpp_tcp_conn_error_t; +typedef enum rexmpp_tcp_conn_resolution_status +rexmpp_tcp_conn_resolution_status_t; /** @brief Connection errors. @@ -59,6 +63,8 @@ enum rexmpp_tcp_conn_error { REXMPP_CONN_ERROR }; +typedef enum rexmpp_tcp_conn_error rexmpp_tcp_conn_error_t; + typedef struct rexmpp_tcp_connection rexmpp_tcp_conn_t; /** @brief A connection establishment structure. */ @@ -68,19 +74,13 @@ struct rexmpp_tcp_connection { /** @brief A port we are connecting to. */ uint16_t port; - /** @brief Resolver channel. */ - ares_channel resolver_channel; - /** @brief Resolver error is stored here when - ::REXMPP_CONN_RESOLVER_ERROR is returned. */ - int resolver_error; - /** @brief State of A record resolution. */ enum rexmpp_tcp_conn_resolution_status resolution_v4; /** @brief Status of A record resolution, as returned by the resolver. */ int resolver_status_v4; - /** @brief AF_INET (IPv4) hostent structure. */ - struct hostent *addr_v4; + /** @brief Resolved A records. */ + rexmpp_dns_result_t *resolved_v4; /** @brief The AF_INET address number we are currently at. */ int addr_cur_v4; @@ -89,8 +89,8 @@ struct rexmpp_tcp_connection { /** @brief Status of AAAA record resolution, as returned by the resolver. */ int resolver_status_v6; - /** @brief AF_INET6 (IPv6) hostent structure. */ - struct hostent *addr_v6; + /** @brief Resolved AAAA records. */ + rexmpp_dns_result_t *resolved_v6; /** @brief The AF_INET6 address number we are currently at. */ int addr_cur_v6; @@ -99,14 +99,18 @@ struct rexmpp_tcp_connection { /** @brief The number of connection attempts so far. */ int connection_attempts; - /** @brief Next scheduled connection time. */ - struct timeval next_connection_time; + /** @brief Next scheduled connection time (monotonic). */ + struct timespec next_connection_time; /** @brief File descriptor of a connected socket. */ int fd; + /** @brief Whether the A or AAAA records used to establish the final + connection were verified with DNSSEC. */ + bool dns_secure; }; /** @brief Initiates a connection. + @param[in] s ::rexmpp @param[out] conn An allocated connection structure. @param[in] host A host to connect to. This could be a domain name, or a textual representation of an IPv4 or an IPv6 address. @@ -114,19 +118,22 @@ struct rexmpp_tcp_connection { @returns A ::rexmpp_tcp_conn_error state. */ rexmpp_tcp_conn_error_t -rexmpp_tcp_conn_init (rexmpp_tcp_conn_t *conn, +rexmpp_tcp_conn_init (rexmpp_t *s, + rexmpp_tcp_conn_t *conn, const char *host, uint16_t port); /** @brief Continues a connection process. + @param[in] s ::rexmpp @param[in,out] conn An active connection structure. @param[in] read_fds File descriptors available for reading from. @param[in] write_fds File descriptors available for writing to. @returns A ::rexmpp_tcp_conn_error state. */ rexmpp_tcp_conn_error_t -rexmpp_tcp_conn_proceed (rexmpp_tcp_conn_t *conn, +rexmpp_tcp_conn_proceed (rexmpp_t *s, + rexmpp_tcp_conn_t *conn, fd_set *read_fds, fd_set *write_fds); @@ -151,6 +158,7 @@ int rexmpp_tcp_conn_finish (rexmpp_tcp_conn_t *conn); File descriptors are only added to an @c fd_set, so the ones it already contains will not be lost. + @param[in] s ::rexmpp @param[in] conn An active connection structure. @param[out] read_fds File descriptors a connection process is interested in reading from. @@ -158,20 +166,23 @@ int rexmpp_tcp_conn_finish (rexmpp_tcp_conn_t *conn); interested in writing to. @returns Maximum file descriptor number, plus 1. */ -int rexmpp_tcp_conn_fds (rexmpp_tcp_conn_t *conn, +int rexmpp_tcp_conn_fds (rexmpp_t *s, + rexmpp_tcp_conn_t *conn, fd_set *read_fds, fd_set *write_fds); /** @brief Reports timeouts. + @param[in] s ::rexmpp @param[in] conn An active connection structure. @param[in] max_tv An existing maximum timeout. - @param[out] tv A timeval structure to store a new timeout in. + @param[out] tv A timespec structure to store a new timeout in. @returns A pointer to either max_tv or tv, depending on which one is smaller. */ -struct timeval *rexmpp_tcp_conn_timeout (rexmpp_tcp_conn_t *conn, - struct timeval *max_tv, - struct timeval *tv); +struct timespec *rexmpp_tcp_conn_timeout (rexmpp_t *s, + rexmpp_tcp_conn_t *conn, + struct timespec *max_tv, + struct timespec *tv); #endif |