diff options
Diffstat (limited to 'include/asterisk')
-rw-r--r-- | include/asterisk/iostream.h | 118 | ||||
-rw-r--r-- | include/asterisk/tcptls.h | 92 |
2 files changed, 121 insertions, 89 deletions
diff --git a/include/asterisk/iostream.h b/include/asterisk/iostream.h new file mode 100644 index 000000000..c641ffb37 --- /dev/null +++ b/include/asterisk/iostream.h @@ -0,0 +1,118 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 1999 - 2015, Digium, Inc. + * + * Timo Teräs <timo.teras@iki.fi> + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +#ifndef _ASTERISK_IOSTREAM_H +#define _ASTERISK_IOSTREAM_H + +/*! + * \file iostream.h + * + * \brief Generic abstraction for input/output streams. + */ + +#if defined(HAVE_OPENSSL) +#define DO_SSL /* comment in/out if you want to support ssl */ +#endif + +#ifdef DO_SSL +#include <openssl/ssl.h> +#include <openssl/err.h> +#include <openssl/x509v3.h> +#else +/* declare dummy types so we can define a pointer to them */ +typedef struct {} SSL; +typedef struct {} SSL_CTX; +#endif /* DO_SSL */ + +struct ast_iostream; + +/*! + * \brief Disable the iostream timeout timer. + * + * \param stream iostream control data. + * + * \return Nothing + */ +void ast_iostream_set_timeout_disable(struct ast_iostream *stream); + +/*! + * \brief Set the iostream inactivity timeout timer. + * + * \param stream iostream control data. + * \param timeout Number of milliseconds to wait for data transfer with the peer. + * + * \details This is basically how much time we are willing to spend + * in an I/O call before we declare the peer unresponsive. + * + * \note Setting timeout to -1 disables the timeout. + * \note Setting this timeout replaces the I/O sequence timeout timer. + * + * \return Nothing + */ +void ast_iostream_set_timeout_inactivity(struct ast_iostream *stream, int timeout); + +void ast_iostream_set_timeout_idle_inactivity(struct ast_iostream *stream, int timeout, int timeout_reset); + +/*! + * \brief Set the iostream I/O sequence timeout timer. + * + * \param stream iostream control data. + * \param start Time the I/O sequence timer starts. + * \param timeout Number of milliseconds from the start time before timeout. + * + * \details This is how much time are we willing to allow the peer + * to complete an operation that can take several I/O calls. The + * main use is as an authentication timer with us. + * + * \note Setting timeout to -1 disables the timeout. + * \note Setting this timeout replaces the inactivity timeout timer. + * + * \return Nothing + */ +void ast_iostream_set_timeout_sequence(struct ast_iostream *stream, struct timeval start, int timeout); + +/*! + * \brief Set the iostream if it can exclusively depend upon the set timeouts. + * + * \param stream iostream control data. + * \param exclusive_input TRUE if stream can exclusively wait for fd input. + * Otherwise, the stream will not wait for fd input. It will wait while + * trying to send data. + * + * \note The stream timeouts still need to be set. + * + * \return Nothing + */ +void ast_iostream_set_exclusive_input(struct ast_iostream *stream, int exclusive_input); + +int ast_iostream_get_fd(struct ast_iostream *stream); +void ast_iostream_nonblock(struct ast_iostream *stream); + +SSL* ast_iostream_get_ssl(struct ast_iostream *stream); + +ssize_t ast_iostream_read(struct ast_iostream *stream, void *buf, size_t count); +ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buf, size_t count); +ssize_t ast_iostream_discard(struct ast_iostream *stream, size_t count); +ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buf, size_t count); +ssize_t ast_iostream_printf(struct ast_iostream *stream, const void *fmt, ...); + +struct ast_iostream* ast_iostream_from_fd(int *fd); +int ast_iostream_start_tls(struct ast_iostream **stream, SSL_CTX *ctx, int client); +int ast_iostream_close(struct ast_iostream *stream); + +#endif /* _ASTERISK_IOSTREAM_H */ diff --git a/include/asterisk/tcptls.h b/include/asterisk/tcptls.h index 3c5f4504c..883cb9229 100644 --- a/include/asterisk/tcptls.h +++ b/include/asterisk/tcptls.h @@ -57,20 +57,7 @@ #include "asterisk/netsock2.h" #include "asterisk/utils.h" - -#if defined(HAVE_OPENSSL) && (defined(HAVE_FUNOPEN) || defined(HAVE_FOPENCOOKIE)) -#define DO_SSL /* comment in/out if you want to support ssl */ -#endif - -#ifdef DO_SSL -#include <openssl/ssl.h> -#include <openssl/err.h> -#include <openssl/x509v3.h> -#else -/* declare dummy types so we can define a pointer to them */ -typedef struct {} SSL; -typedef struct {} SSL_CTX; -#endif /* DO_SSL */ +#include "asterisk/iostream.h" /*! SSL support */ #define AST_CERTFILE "asterisk.pem" @@ -153,72 +140,10 @@ struct ast_tcptls_session_args { const char *name; }; -struct ast_tcptls_stream; - -/*! - * \brief Disable the TCP/TLS stream timeout timer. - * - * \param stream TCP/TLS stream control data. - * - * \return Nothing - */ -void ast_tcptls_stream_set_timeout_disable(struct ast_tcptls_stream *stream); - -/*! - * \brief Set the TCP/TLS stream inactivity timeout timer. - * - * \param stream TCP/TLS stream control data. - * \param timeout Number of milliseconds to wait for data transfer with the peer. - * - * \details This is basically how much time we are willing to spend - * in an I/O call before we declare the peer unresponsive. - * - * \note Setting timeout to -1 disables the timeout. - * \note Setting this timeout replaces the I/O sequence timeout timer. - * - * \return Nothing - */ -void ast_tcptls_stream_set_timeout_inactivity(struct ast_tcptls_stream *stream, int timeout); - -/*! - * \brief Set the TCP/TLS stream I/O sequence timeout timer. - * - * \param stream TCP/TLS stream control data. - * \param start Time the I/O sequence timer starts. - * \param timeout Number of milliseconds from the start time before timeout. - * - * \details This is how much time are we willing to allow the peer - * to complete an operation that can take several I/O calls. The - * main use is as an authentication timer with us. - * - * \note Setting timeout to -1 disables the timeout. - * \note Setting this timeout replaces the inactivity timeout timer. - * - * \return Nothing - */ -void ast_tcptls_stream_set_timeout_sequence(struct ast_tcptls_stream *stream, struct timeval start, int timeout); - -/*! - * \brief Set the TCP/TLS stream I/O if it can exclusively depend upon the set timeouts. - * - * \param stream TCP/TLS stream control data. - * \param exclusive_input TRUE if stream can exclusively wait for fd input. - * Otherwise, the stream will not wait for fd input. It will wait while - * trying to send data. - * - * \note The stream timeouts still need to be set. - * - * \return Nothing - */ -void ast_tcptls_stream_set_exclusive_input(struct ast_tcptls_stream *stream, int exclusive_input); - /*! \brief * describes a server instance */ struct ast_tcptls_session_instance { - FILE *f; /*!< fopen/funopen result */ - int fd; /*!< the socket returned by accept() */ - SSL *ssl; /*!< ssl state */ int client; struct ast_sockaddr remote_address; struct ast_tcptls_session_args *parent; @@ -228,20 +153,12 @@ struct ast_tcptls_session_instance { * extra data. */ struct ast_str *overflow_buf; - /*! ao2 FILE stream cookie object associated with f. */ - struct ast_tcptls_stream *stream_cookie; + /*! ao2 stream object associated with this session. */ + struct ast_iostream *stream; /*! ao2 object private data of parent->worker_fn */ void *private_data; }; -#if defined(HAVE_FUNOPEN) -#define HOOK_T int -#define LEN_T int -#else -#define HOOK_T ssize_t -#define LEN_T size_t -#endif - /*! * \brief attempts to connect and start tcptls session, on error the tcptls_session's * ref count is decremented, fd and file are closed, and NULL is returned. @@ -297,7 +214,4 @@ void ast_ssl_teardown(struct ast_tls_config *cfg); */ int ast_tls_read_conf(struct ast_tls_config *tls_cfg, struct ast_tcptls_session_args *tls_desc, const char *varname, const char *value); -HOOK_T ast_tcptls_server_read(struct ast_tcptls_session_instance *ser, void *buf, size_t count); -HOOK_T ast_tcptls_server_write(struct ast_tcptls_session_instance *ser, const void *buf, size_t count); - #endif /* _ASTERISK_TCPTLS_H */ |