Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
#include "asterisk.h"
#include "asterisk/iostream.h"
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include "asterisk/astobj2.h"
#include "asterisk/logger.h"
#include "asterisk/strings.h"
#include "asterisk/threadstorage.h"
#include "asterisk/time.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
struct | ast_iostream |
Functions | |
int | ast_iostream_close (struct ast_iostream *stream) |
Close an iostream. More... | |
ssize_t | ast_iostream_discard (struct ast_iostream *stream, size_t size) |
Discard the specified number of bytes from an iostream. More... | |
struct ast_iostream * | ast_iostream_from_fd (int *fd) |
Create an iostream from a file descriptor. More... | |
int | ast_iostream_get_fd (struct ast_iostream *stream) |
Get an iostream's file descriptor. More... | |
SSL * | ast_iostream_get_ssl (struct ast_iostream *stream) |
Get a pointer to an iostream's OpenSSL SSL structure. More... | |
ssize_t | ast_iostream_gets (struct ast_iostream *stream, char *buffer, size_t size) |
Read a LF-terminated string from an iostream. More... | |
void | ast_iostream_nonblock (struct ast_iostream *stream) |
Make an iostream non-blocking. More... | |
ssize_t | ast_iostream_printf (struct ast_iostream *stream, const char *format,...) |
Write a formatted string to an iostream. More... | |
ssize_t | ast_iostream_read (struct ast_iostream *stream, void *buffer, size_t count) |
Read data from an iostream. More... | |
void | ast_iostream_set_exclusive_input (struct ast_iostream *stream, int exclusive_input) |
Set the iostream if it can exclusively depend upon the set timeouts. More... | |
int | ast_iostream_set_sni_hostname (struct ast_iostream *stream, const char *sni_hostname) |
Set the iostream's SNI hostname for TLS client connections. More... | |
void | ast_iostream_set_timeout_disable (struct ast_iostream *stream) |
Disable the iostream timeout timer. More... | |
void | ast_iostream_set_timeout_idle_inactivity (struct ast_iostream *stream, int timeout, int timeout_reset) |
Set the iostream inactivity & idle timeout timers. More... | |
void | ast_iostream_set_timeout_inactivity (struct ast_iostream *stream, int timeout) |
Set the iostream inactivity timeout timer. More... | |
void | ast_iostream_set_timeout_sequence (struct ast_iostream *stream, struct timeval start, int timeout) |
Set the iostream I/O sequence timeout timer. More... | |
int | ast_iostream_start_tls (struct ast_iostream **pstream, SSL_CTX *ssl_ctx, int client) |
Begin TLS on an iostream. More... | |
int | ast_iostream_wait_for_input (struct ast_iostream *stream, int timeout) |
Wait for input on the iostream's file descriptor. More... | |
ssize_t | ast_iostream_write (struct ast_iostream *stream, const void *buffer, size_t size) |
Write data to an iostream. More... | |
static void | iostream_dtor (void *cookie) |
static ssize_t | iostream_read (struct ast_iostream *stream, void *buf, size_t size) |
int ast_iostream_close | ( | struct ast_iostream * | stream | ) |
Close an iostream.
stream | A pointer to an iostream |
0 | success |
-1 | failure |
errno
may be set providing additional information on why the failure occurred. Definition at line 539 of file iostream.c.
References ao2_t_ref, ast_log, errno, ast_iostream::fd, LOG_ERROR, NULL, and ast_iostream::ssl.
Referenced by app_exec(), ast_tcptls_close_session_file(), ast_websocket_close(), auth_http_callback(), close_mansession_file(), generic_http_callback(), session_destroy_fn(), and session_instance_destructor().
ssize_t ast_iostream_discard | ( | struct ast_iostream * | stream, |
size_t | count | ||
) |
Discard the specified number of bytes from an iostream.
stream | A pointer to an iostream |
count | The number of bytes to discard. |
-1
is returned and errno
may be set indicating the error. Definition at line 368 of file iostream.c.
References ast_iostream_read(), and buf.
Referenced by http_body_discard_contents().
struct ast_iostream * ast_iostream_from_fd | ( | int * | fd | ) |
Create an iostream from a file descriptor.
fd | A pointer to an open file descriptor |
NULL
if allocation fails. Definition at line 611 of file iostream.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ast_iostream::fd, iostream_dtor(), ast_iostream::timeout, and ast_iostream::timeout_reset.
Referenced by app_exec(), ast_tcptls_client_create(), ast_tcptls_server_root(), auth_http_callback(), and generic_http_callback().
int ast_iostream_get_fd | ( | struct ast_iostream * | stream | ) |
Get an iostream's file descriptor.
stream | A pointer to an iostream |
-1 | if the iostream has no open file descriptor. |
Definition at line 85 of file iostream.c.
References ast_iostream::fd.
Referenced by action_waitevent(), ast_websocket_fd(), ast_websocket_uri_cb(), auth_http_callback(), eivr_comm(), get_input(), handle_kickmanconn(), handle_showmanconn(), httpd_helper_thread(), phoneprov_callback(), process_output(), and session_do().
SSL * ast_iostream_get_ssl | ( | struct ast_iostream * | stream | ) |
Get a pointer to an iostream's OpenSSL SSL
structure.
stream | A pointer to an iostream |
SSL
structure for the given iostream NULL | if TLS has not been initiated. |
NULL
. Definition at line 109 of file iostream.c.
References ast_iostream::ssl.
Referenced by ast_websocket_uri_cb(), handle_tcptls_connection(), and websocket_client_connect().
ssize_t ast_iostream_gets | ( | struct ast_iostream * | stream, |
char * | buffer, | ||
size_t | size | ||
) |
Read a LF-terminated string from an iostream.
stream | A pointer to an iostream |
buffer | Pointer to a buffer to store the read bytes. |
size | The total size of buffer in bytes. |
-1
will be returned and errno
may be set indicating the error. Definition at line 311 of file iostream.c.
References iostream_read(), len(), ast_iostream::rbuf, ast_iostream::rbufhead, and ast_iostream::rbuflen.
Referenced by eivr_comm(), http_body_discard_chunk_trailer_headers(), http_body_get_chunk_length(), http_request_headers_get(), httpd_process_request(), and websocket_client_handshake_get_response().
void ast_iostream_nonblock | ( | struct ast_iostream * | stream | ) |
Make an iostream non-blocking.
stream | A pointer to an iostream |
Definition at line 104 of file iostream.c.
References ast_fd_set_flags, and ast_iostream::fd.
Referenced by ast_websocket_set_nonblock(), httpd_helper_thread(), and session_do().
ssize_t ast_iostream_printf | ( | struct ast_iostream * | stream, |
const char * | format, | ||
... | |||
) |
Write a formatted string to an iostream.
stream | A pointer to an iostream |
format | A format string, as documented by printf(3) |
... | Arguments for the provided format string |
-1
if an error occurs. Note that if -1
is returned, the number of bytes written to the iostream is unspecified. Definition at line 502 of file iostream.c.
References ast_free, ast_iostream_write(), ast_malloc, buf, error(), and len().
Referenced by ast_http_send(), ast_websocket_uri_cb(), and websocket_client_handshake().
ssize_t ast_iostream_read | ( | struct ast_iostream * | stream, |
void * | buffer, | ||
size_t | count | ||
) |
Read data from an iostream.
stream | A pointer to an iostream |
buffer | Pointer to a buffer to store the read bytes. |
count | The number of bytes to read. |
Definition at line 284 of file iostream.c.
References errno, ast_iostream::fd, iostream_read(), ast_iostream::rbufhead, and ast_iostream::rbuflen.
Referenced by ast_iostream_discard(), get_input(), http_body_check_chunk_sync(), http_body_read_contents(), readmimefile(), and ws_safe_read().
void ast_iostream_set_exclusive_input | ( | struct ast_iostream * | stream, |
int | exclusive_input | ||
) |
Set the iostream if it can exclusively depend upon the set timeouts.
stream | A pointer to an iostream |
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. |
Definition at line 149 of file iostream.c.
References ast_assert, ast_iostream::exclusive_input, and NULL.
Referenced by ast_websocket_set_nonblock(), ast_websocket_uri_cb(), httpd_helper_thread(), and session_do().
int ast_iostream_set_sni_hostname | ( | struct ast_iostream * | stream, |
const char * | sni_hostname | ||
) |
Set the iostream's SNI hostname for TLS client connections.
stream | A pointer to an iostream |
sni_hostname | The hostname to use for SNI when in client mode |
0 | if the hostname was set successfully. |
-1 | if memory could not be allocated for the hostname. |
Definition at line 156 of file iostream.c.
References ast_assert, ast_free, ast_strdup, NULL, and ast_iostream::sni_hostname.
Referenced by ast_tcptls_client_create().
void ast_iostream_set_timeout_disable | ( | struct ast_iostream * | stream | ) |
Disable the iostream timeout timer.
stream | A pointer to an iostream |
Definition at line 114 of file iostream.c.
References ast_assert, NULL, ast_iostream::timeout, and ast_iostream::timeout_reset.
Referenced by ast_websocket_close(), ast_websocket_write(), send_string(), and session_do().
void ast_iostream_set_timeout_idle_inactivity | ( | struct ast_iostream * | stream, |
int | timeout, | ||
int | timeout_reset | ||
) |
Set the iostream inactivity & idle timeout timers.
stream | A pointer to an iostream |
timeout | Number of milliseconds to wait for initial data transfer with the peer. |
timeout_reset | Number of milliseconds to wait for subsequent data transfer with the peer. |
As an example, if you want to timeout a peer if they do not send an initial message within 5 seconds or if they do not send a message at least every 30 seconds, you would set timeout to 5000
and timeout_reset to 30000
.
Definition at line 131 of file iostream.c.
References ast_assert, NULL, ast_iostream::start, ast_iostream::timeout, and ast_iostream::timeout_reset.
Referenced by httpd_helper_thread().
void ast_iostream_set_timeout_inactivity | ( | struct ast_iostream * | stream, |
int | timeout | ||
) |
Set the iostream inactivity timeout timer.
stream | A pointer to an iostream |
timeout | Number of milliseconds to wait for data transfer with the peer. |
This is basically how much time we are willing to spend in an I/O call before we declare the peer unresponsive.
Definition at line 122 of file iostream.c.
References ast_assert, NULL, ast_iostream::start, ast_iostream::timeout, and ast_iostream::timeout_reset.
Referenced by ast_websocket_close(), and send_string().
void ast_iostream_set_timeout_sequence | ( | struct ast_iostream * | stream, |
struct timeval | start, | ||
int | timeout | ||
) |
Set the iostream I/O sequence timeout timer.
stream | A pointer to an iostream |
start | Time the I/O sequence timer starts. |
timeout | Number of milliseconds from the start time before timeout. |
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.
Definition at line 140 of file iostream.c.
References ast_assert, NULL, ast_iostream::start, ast_iostream::timeout, and ast_iostream::timeout_reset.
Referenced by ast_websocket_write(), and session_do().
int ast_iostream_start_tls | ( | struct ast_iostream ** | stream, |
SSL_CTX * | ctx, | ||
int | client | ||
) |
Begin TLS on an iostream.
stream | A pointer to an iostream pointer |
ctx | A pointer to an SSL_CTX which will be passed to SSL_new() |
client | Non-zero to indicate that we are the client, zero to indicate that we are the server. |
0 | success |
-1 | failure |
errno
may be set providing additional information on why the failure occurred. Definition at line 627 of file iostream.c.
References ast_log, ast_strlen_zero(), errno, ast_iostream::fd, LOG_ERROR, ast_iostream::sni_hostname, and ast_iostream::ssl.
Referenced by handle_tcptls_connection().
int ast_iostream_wait_for_input | ( | struct ast_iostream * | stream, |
int | timeout | ||
) |
Wait for input on the iostream's file descriptor.
stream | A pointer to an iostream |
timeout | the number of milliseconds to wait |
-1 | if error occurred |
0 | if the timeout expired |
1 | if the stream is ready for reading |
Definition at line 90 of file iostream.c.
References ast_wait_for_input(), ast_iostream::fd, and ast_iostream::ssl.
Referenced by ast_websocket_wait_for_input(), and ws_safe_read().
ssize_t ast_iostream_write | ( | struct ast_iostream * | stream, |
const void * | buffer, | ||
size_t | count | ||
) |
Write data to an iostream.
stream | A pointer to an iostream |
buffer | Pointer to a buffer from which to read bytes. |
count | The number of bytes from buffer to write. |
-1
and may set errno
to indicate the error. Definition at line 385 of file iostream.c.
References ast_debug, ast_remaining_ms(), ast_tvnow(), ast_wait_for_input(), ast_wait_for_output(), errno, ast_iostream::fd, ast_iostream::ssl, ast_iostream::start, and ast_iostream::timeout.
Referenced by ast_http_send(), ast_iostream_printf(), ast_websocket_close(), ast_websocket_write(), process_output(), send_eivr_event(), and send_string().
|
static |
Definition at line 603 of file iostream.c.
References ast_assert, ast_free, ast_iostream::fd, and ast_iostream::sni_hostname.
Referenced by ast_iostream_from_fd().
|
static |
Definition at line 166 of file iostream.c.
References ast_debug, ast_remaining_ms(), ast_tvnow(), ast_wait_for_input(), ast_wait_for_output(), buf, errno, ast_iostream::exclusive_input, ast_iostream::fd, ast_iostream::ssl, ast_iostream::start, ast_iostream::timeout, and ast_iostream::timeout_reset.
Referenced by ast_iostream_gets(), and ast_iostream_read().