Asterisk - The Open Source Telephony Project GIT-master-6144b6b
Loading...
Searching...
No Matches
iostream.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2015, Digium, Inc.
5 *
6 * Timo Teräs <timo.teras@iki.fi>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19#include "asterisk.h"
20
21#include "asterisk/iostream.h" /* for DO_SSL */
22
23#include <fcntl.h> /* for O_NONBLOCK */
24#ifdef DO_SSL
25#include <openssl/err.h> /* for ERR_error_string */
26#include <openssl/opensslv.h> /* for OPENSSL_VERSION_NUMBER */
27#include <openssl/ssl.h> /* for SSL_get_error, SSL_free, SSL_... */
28#endif
29#include <sys/socket.h> /* for shutdown, SHUT_RDWR */
30#include <sys/time.h> /* for timeval */
31
32#include "asterisk/astobj2.h" /* for ao2_alloc_options, ao2_alloc_... */
33#include "asterisk/logger.h" /* for ast_debug, ast_log, LOG_ERROR */
34#include "asterisk/strings.h" /* for asterisk/threadstorage.h */
35#include "asterisk/threadstorage.h" /* for ast_threadstorage_get, AST_TH... */
36#include "asterisk/time.h" /* for ast_remaining_ms, ast_tvnow */
37#include "asterisk/utils.h" /* for ast_wait_for_input, ast_wait_... */
38
41 struct timeval start;
42 int fd;
47 char *rbufhead;
48 char rbuf[2048];
50};
51
52#if defined(DO_SSL)
53AST_THREADSTORAGE(err2str_threadbuf);
54#define ERR2STR_BUFSIZE 128
55
56static const char *ssl_error_to_string(int sslerr, int ret)
57{
58 switch (sslerr) {
59 case SSL_ERROR_SSL:
60 return "Internal SSL error";
61 case SSL_ERROR_SYSCALL:
62 if (!ret) {
63 return "System call EOF";
64 } else if (ret == -1) {
65 char *buf;
66
67 buf = ast_threadstorage_get(&err2str_threadbuf, ERR2STR_BUFSIZE);
68 if (!buf) {
69 return "Unknown";
70 }
71
72 snprintf(buf, ERR2STR_BUFSIZE, "Underlying BIO error: %s", strerror(errno));
73 return buf;
74 } else {
75 return "System call other";
76 }
77 default:
78 break;
79 }
80
81 return "Unknown";
82}
83#endif
84
86{
87 return stream->fd;
88}
89
90int ast_iostream_wait_for_input(struct ast_iostream *stream, int timeout)
91{
92#if defined(DO_SSL)
93 /* Because SSL is read in blocks, it's possible that the last time we read we
94 got more than we asked for and it is now buffered inside OpenSSL. If that
95 is the case, calling ast_wait_for_input() will block until the fd is ready
96 for reading again, which might never happen. */
97 if (stream->ssl && SSL_pending(stream->ssl)) {
98 return 1;
99 }
100#endif
101 return ast_wait_for_input(stream->fd, timeout);
102}
103
105{
106 ast_fd_set_flags(stream->fd, O_NONBLOCK);
107}
108
110{
111 ast_fd_clear_flags(stream->fd, O_NONBLOCK);
112}
113
115{
116 return stream->ssl;
117}
118
120{
121 ast_assert(stream != NULL);
122
123 stream->timeout = -1;
124 stream->timeout_reset = -1;
125}
126
127void ast_iostream_set_timeout_inactivity(struct ast_iostream *stream, int timeout)
128{
129 ast_assert(stream != NULL);
130
131 stream->start.tv_sec = 0;
132 stream->timeout = timeout;
133 stream->timeout_reset = timeout;
134}
135
136void ast_iostream_set_timeout_idle_inactivity(struct ast_iostream *stream, int timeout, int timeout_reset)
137{
138 ast_assert(stream != NULL);
139
140 stream->start.tv_sec = 0;
141 stream->timeout = timeout;
142 stream->timeout_reset = timeout_reset;
143}
144
145void ast_iostream_set_timeout_sequence(struct ast_iostream *stream, struct timeval start, int timeout)
146{
147 ast_assert(stream != NULL);
148
149 stream->start = start;
150 stream->timeout = timeout;
151 stream->timeout_reset = timeout;
152}
153
154void ast_iostream_set_exclusive_input(struct ast_iostream *stream, int exclusive_input)
155{
156 ast_assert(stream != NULL);
157
158 stream->exclusive_input = exclusive_input;
159}
160
161int ast_iostream_set_sni_hostname(struct ast_iostream *stream, const char *sni_hostname)
162{
163 ast_assert(stream != NULL);
164
165 ast_free(stream->sni_hostname);
166 stream->sni_hostname = ast_strdup(sni_hostname);
167
168 return stream->sni_hostname ? 0 : -1;
169}
170
171static ssize_t iostream_read(struct ast_iostream *stream, void *buf, size_t size)
172{
173 struct timeval start;
174 int ms;
175 int res;
176
177 if (stream->start.tv_sec) {
178 start = stream->start;
179 } else {
180 start = ast_tvnow();
181 }
182
183#if defined(DO_SSL)
184 if (stream->ssl) {
185 for (;;) {
186 int sslerr;
187 char err[256];
188 res = SSL_read(stream->ssl, buf, size);
189 if (0 < res) {
190 /* We read some payload data. */
191 stream->timeout = stream->timeout_reset;
192 return res;
193 }
194 sslerr = SSL_get_error(stream->ssl, res);
195 switch (sslerr) {
196 case SSL_ERROR_ZERO_RETURN:
197 /* Report EOF for a shutdown */
198 ast_debug(1, "TLS clean shutdown alert reading data\n");
199 return 0;
200 case SSL_ERROR_WANT_READ:
201 if (!stream->exclusive_input) {
202 /* We cannot wait for data now. */
203 errno = EAGAIN;
204 return -1;
205 }
206 while ((ms = ast_remaining_ms(start, stream->timeout))) {
207 res = ast_wait_for_input(stream->fd, ms);
208 if (0 < res) {
209 /* Socket is ready to be read. */
210 break;
211 }
212 if (res < 0) {
213 if (errno == EINTR || errno == EAGAIN) {
214 /* Try again. */
215 continue;
216 }
217 ast_debug(1, "TLS socket error waiting for read data: %s\n",
218 strerror(errno));
219 return -1;
220 }
221 }
222 break;
223 case SSL_ERROR_WANT_WRITE:
224 while ((ms = ast_remaining_ms(start, stream->timeout))) {
225 res = ast_wait_for_output(stream->fd, ms);
226 if (0 < res) {
227 /* Socket is ready to be written. */
228 break;
229 }
230 if (res < 0) {
231 if (errno == EINTR || errno == EAGAIN) {
232 /* Try again. */
233 continue;
234 }
235 ast_debug(1, "TLS socket error waiting for write space: %s\n",
236 strerror(errno));
237 return -1;
238 }
239 }
240 break;
241 case SSL_ERROR_SYSCALL:
242 /* Some non-recoverable I/O error occurred. The OpenSSL error queue may
243 * contain more information on the error. For socket I/O on Unix systems,
244 * consult errno for details. */
245 ast_debug(1, "TLS non-recoverable I/O error occurred: %s, %s\n", ERR_error_string(sslerr, err),
246 ssl_error_to_string(sslerr, res));
247 return -1;
248 default:
249 /* Report EOF for an undecoded SSL or transport error. */
250 ast_debug(1, "TLS transport or SSL error reading data: %s, %s\n", ERR_error_string(sslerr, err),
251 ssl_error_to_string(sslerr, res));
252 return -1;
253 }
254 if (!ms) {
255 /* Report EOF for a timeout */
256 ast_debug(1, "TLS timeout reading data\n");
257 return 0;
258 }
259 }
260 }
261#endif /* defined(DO_SSL) */
262
263 for (;;) {
264 res = read(stream->fd, buf, size);
265 if (0 <= res) {
266 /* Got data or we cannot wait for it. */
267 stream->timeout = stream->timeout_reset;
268 return res;
269 }
270 if (!stream->exclusive_input) {
271 return res;
272 }
273 if (errno != EINTR && errno != EAGAIN) {
274 /* Not a retryable error. */
275 ast_debug(1, "TCP socket error reading data: %s\n",
276 strerror(errno));
277 return -1;
278 }
279 ms = ast_remaining_ms(start, stream->timeout);
280 if (!ms) {
281 /* Report EOF for a timeout */
282 ast_debug(1, "TCP timeout reading data\n");
283 return 0;
284 }
285 ast_wait_for_input(stream->fd, ms);
286 }
287}
288
289ssize_t ast_iostream_read(struct ast_iostream *stream, void *buffer, size_t count)
290{
291 if (!count) {
292 /* You asked for no data you got no data. */
293 return 0;
294 }
295
296 if (!stream || stream->fd == -1) {
297 errno = EBADF;
298 return -1;
299 }
300
301 /* Get any remains from the read buffer */
302 if (stream->rbuflen) {
303 size_t r = count;
304 if (r > stream->rbuflen) {
305 r = stream->rbuflen;
306 }
307 memcpy(buffer, stream->rbufhead, r);
308 stream->rbuflen -= r;
309 stream->rbufhead += r;
310 return r;
311 }
312
313 return iostream_read(stream, buffer, count);
314}
315
316ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buffer, size_t size)
317{
318 size_t remaining = size;
319 ssize_t accum_size = 0;
320 ssize_t len;
321 char *newline;
322
323 for (;;) {
324 /* Search for newline */
325 newline = memchr(stream->rbufhead, '\n', stream->rbuflen);
326 if (newline) {
327 len = newline - stream->rbufhead + 1;
328 if (len > remaining - 1) {
329 len = remaining - 1;
330 }
331 break;
332 }
333
334 /* Enough buffered line data to fill request buffer? */
335 if (stream->rbuflen >= remaining - 1) {
336 len = remaining - 1;
337 break;
338 }
339 if (stream->rbuflen) {
340 /* Put leftover buffered line data into request buffer */
341 memcpy(buffer + accum_size, stream->rbufhead, stream->rbuflen);
342 remaining -= stream->rbuflen;
343 accum_size += stream->rbuflen;
344 stream->rbuflen = 0;
345 }
346 stream->rbufhead = stream->rbuf;
347
348 len = iostream_read(stream, stream->rbuf, sizeof(stream->rbuf));
349 if (len == 0) {
350 /* Nothing new was read. Return whatever we have accumulated. */
351 break;
352 }
353 if (len < 0) {
354 if (accum_size) {
355 /* We have an accumulated buffer so return that instead. */
356 len = 0;
357 break;
358 }
359 return len;
360 }
361 stream->rbuflen += len;
362 }
363
364 /* Return read buffer string length */
365 memcpy(buffer + accum_size, stream->rbufhead, len);
366 buffer[accum_size + len] = 0;
367 stream->rbuflen -= len;
368 stream->rbufhead += len;
369
370 return accum_size + len;
371}
372
373ssize_t ast_iostream_discard(struct ast_iostream *stream, size_t size)
374{
375 char buf[1024];
376 size_t remaining = size;
377 ssize_t ret;
378
379 while (remaining) {
380 ret = ast_iostream_read(stream, buf, remaining > sizeof(buf) ? sizeof(buf) : remaining);
381 if (ret <= 0) {
382 return ret;
383 }
384 remaining -= ret;
385 }
386
387 return size;
388}
389
390ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t size)
391{
392 struct timeval start;
393 int ms;
394 int res;
395 int written;
396 int remaining;
397
398 if (!size) {
399 /* You asked to write no data you wrote no data. */
400 return 0;
401 }
402
403 if (!stream || stream->fd == -1) {
404 errno = EBADF;
405 return -1;
406 }
407
408 if (stream->start.tv_sec) {
409 start = stream->start;
410 } else {
411 start = ast_tvnow();
412 }
413
414#if defined(DO_SSL)
415 if (stream->ssl) {
416 written = 0;
417 remaining = size;
418 for (;;) {
419 int sslerr;
420 char err[256];
421 res = SSL_write(stream->ssl, buffer + written, remaining);
422 if (res == remaining) {
423 /* Everything was written. */
424 return size;
425 }
426 if (0 < res) {
427 /* Successfully wrote part of the buffer. Try to write the rest. */
428 written += res;
429 remaining -= res;
430 continue;
431 }
432 sslerr = SSL_get_error(stream->ssl, res);
433 switch (sslerr) {
434 case SSL_ERROR_ZERO_RETURN:
435 ast_debug(1, "TLS clean shutdown alert writing data\n");
436 if (written) {
437 /* Report partial write. */
438 return written;
439 }
440 errno = EBADF;
441 return -1;
442 case SSL_ERROR_WANT_READ:
443 ms = ast_remaining_ms(start, stream->timeout);
444 if (!ms) {
445 /* Report partial write. */
446 ast_debug(1, "TLS timeout writing data (want read)\n");
447 return written;
448 }
449 ast_wait_for_input(stream->fd, ms);
450 break;
451 case SSL_ERROR_WANT_WRITE:
452 ms = ast_remaining_ms(start, stream->timeout);
453 if (!ms) {
454 /* Report partial write. */
455 ast_debug(1, "TLS timeout writing data (want write)\n");
456 return written;
457 }
458 ast_wait_for_output(stream->fd, ms);
459 break;
460 default:
461 /* Undecoded SSL or transport error. */
462 ast_debug(1, "TLS transport or SSL error writing data: %s, %s\n", ERR_error_string(sslerr, err),
463 ssl_error_to_string(sslerr, res));
464 if (written) {
465 /* Report partial write. */
466 return written;
467 }
468 errno = EBADF;
469 return -1;
470 }
471 }
472 }
473#endif /* defined(DO_SSL) */
474
475 written = 0;
476 remaining = size;
477 for (;;) {
478 res = write(stream->fd, buffer + written, remaining);
479 if (res == remaining) {
480 /* Yay everything was written. */
481 return size;
482 }
483 if (0 < res) {
484 /* Successfully wrote part of the buffer. Try to write the rest. */
485 written += res;
486 remaining -= res;
487 continue;
488 }
489 if (errno != EINTR && errno != EAGAIN) {
490 /* Not a retryable error. */
491 ast_debug(1, "TCP socket error writing: %s\n", strerror(errno));
492 if (written) {
493 return written;
494 }
495 return -1;
496 }
497 ms = ast_remaining_ms(start, stream->timeout);
498 if (!ms) {
499 /* Report partial write. */
500 ast_debug(1, "TCP timeout writing data\n");
501 return written;
502 }
503 ast_wait_for_output(stream->fd, ms);
504 }
505}
506
507ssize_t ast_iostream_printf(struct ast_iostream *stream, const char *format, ...)
508{
509 char sbuf[512], *buf = sbuf;
510 int len, len2, ret = -1;
511 va_list va;
512
513 va_start(va, format);
514 len = vsnprintf(buf, sizeof(sbuf), format, va);
515 va_end(va);
516
517 if (len > sizeof(sbuf) - 1) {
518 /* Add one to the string length to accommodate the NULL byte */
519 size_t buf_len = len + 1;
520
521 buf = ast_malloc(buf_len);
522 if (!buf) {
523 return -1;
524 }
525 va_start(va, format);
526 len2 = vsnprintf(buf, buf_len, format, va);
527 va_end(va);
528 if (len2 != len) {
529 goto error;
530 }
531 }
532
533 if (ast_iostream_write(stream, buf, len) == len)
534 ret = len;
535
536error:
537 if (buf != sbuf) {
538 ast_free(buf);
539 }
540
541 return ret;
542}
543
545{
546 if (!stream) {
547 errno = EBADF;
548 return -1;
549 }
550
551 if (stream->fd != -1) {
552#if defined(DO_SSL)
553 if (stream->ssl) {
554 int res;
555
556 /*
557 * According to the TLS standard, it is acceptable for an
558 * application to only send its shutdown alert and then
559 * close the underlying connection without waiting for
560 * the peer's response (this way resources can be saved,
561 * as the process can already terminate or serve another
562 * connection).
563 */
564 res = SSL_shutdown(stream->ssl);
565 if (res < 0) {
566 int sslerr = SSL_get_error(stream->ssl, res);
567 char err[256];
568 ast_log(LOG_ERROR, "SSL_shutdown() failed: %s, %s\n",
569 ERR_error_string(sslerr, err), ssl_error_to_string(sslerr, res));
570 }
571
572#if !(defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x2070000L)) && (OPENSSL_VERSION_NUMBER >= 0x10100000L)
573 if (!SSL_is_server(stream->ssl)) {
574#else
575 if (!stream->ssl->server) {
576#endif
577 /* For client threads, ensure that the error stack is cleared */
578#if defined(LIBRESSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x10100000L)
579#if OPENSSL_VERSION_NUMBER >= 0x10000000L
580 ERR_remove_thread_state(NULL);
581#else
582 ERR_remove_state(0);
583#endif /* OPENSSL_VERSION_NUMBER >= 0x10000000L */
584#endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */
585 }
586
587 SSL_free(stream->ssl);
588 stream->ssl = NULL;
589 }
590#endif /* defined(DO_SSL) */
591
592 /*
593 * Issuing shutdown() is necessary here to avoid a race
594 * condition where the last data written may not appear
595 * in the TCP stream. See ASTERISK-23548
596 */
597 shutdown(stream->fd, SHUT_RDWR);
598 if (close(stream->fd)) {
599 ast_log(LOG_ERROR, "close() failed: %s\n", strerror(errno));
600 }
601 stream->fd = -1;
602 }
603 ao2_t_ref(stream, -1, "Closed ast_iostream");
604
605 return 0;
606}
607
608static void iostream_dtor(void *cookie)
609{
610 struct ast_iostream *stream = cookie;
611
612 ast_free(stream->sni_hostname);
613 ast_assert(stream->fd == -1);
614}
615
617{
618 struct ast_iostream *stream;
619
620 stream = ao2_alloc_options(sizeof(*stream), iostream_dtor,
622 if (stream) {
623 stream->timeout = -1;
624 stream->timeout_reset = -1;
625 stream->fd = *fd;
626 *fd = -1;
627 }
628
629 return stream;
630}
631
632int ast_iostream_start_tls(struct ast_iostream **pstream, SSL_CTX *ssl_ctx, int client)
633{
634#ifdef DO_SSL
635 struct ast_iostream *stream = *pstream;
636 int (*ssl_setup)(SSL *) = client ? SSL_connect : SSL_accept;
637 int res;
638 struct timeval rcv_timeout, snd_timeout;
639 struct timeval timeout;
640 socklen_t len;
641
642 stream->ssl = SSL_new(ssl_ctx);
643 if (!stream->ssl) {
644 ast_log(LOG_ERROR, "Unable to create new SSL connection\n");
645 errno = ENOMEM;
646 return -1;
647 }
648
649 /*
650 * This function takes struct ast_iostream **, so it can chain
651 * SSL over any ast_iostream. For now we assume it's a file descriptor.
652 * But later this should instead use BIO wrapper to tie SSL to another
653 * ast_iostream.
654 */
655 SSL_set_fd(stream->ssl, stream->fd);
656
657 if (client && !ast_strlen_zero(stream->sni_hostname)) {
658 if (!SSL_set_tlsext_host_name(stream->ssl, stream->sni_hostname)) {
659 ast_log(LOG_ERROR, "Unable to set SNI hostname '%s'\n",
660 stream->sni_hostname);
661 errno = EIO;
662 return -1;
663 }
664 }
665
666 /* Get current socket timeout values */
667 len = sizeof(rcv_timeout);
668 getsockopt(stream->fd, SOL_SOCKET, SO_RCVTIMEO, &rcv_timeout, &len);
669 len = sizeof(snd_timeout);
670 getsockopt(stream->fd, SOL_SOCKET, SO_SNDTIMEO, &snd_timeout, &len);
671
672 /* Set socket timeout for SSL handshake to prevent hanging connections and allow SSL handshake to timeout */
673 timeout.tv_sec = 30; /* 30 second timeout for SSL handshake */
674 timeout.tv_usec = 0;
675 setsockopt(stream->fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
676 setsockopt(stream->fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
677
678 res = ssl_setup(stream->ssl);
679 if (res <= 0) {
680 int sslerr = SSL_get_error(stream->ssl, res);
681 char err[256];
682
683 ast_log(LOG_ERROR, "Problem setting up ssl connection: %s, %s\n",
684 ERR_error_string(sslerr, err), ssl_error_to_string(sslerr, res));
685 errno = EIO;
686 return -1;
687 }
688
689 /* Restore socket timeouts from SSL handshake */
690 setsockopt(stream->fd, SOL_SOCKET, SO_RCVTIMEO, &rcv_timeout, sizeof(rcv_timeout));
691 setsockopt(stream->fd, SOL_SOCKET, SO_SNDTIMEO, &snd_timeout, sizeof(snd_timeout));
692
693 return 0;
694#else
695 ast_log(LOG_ERROR, "SSL not enabled in this build\n");
696 errno = ENOTSUP;
697 return -1;
698#endif
699}
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
#define ast_log
Definition astobj2.c:42
#define ao2_t_ref(o, delta, tag)
Definition astobj2.h:460
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
void ast_iostream_blocking(struct ast_iostream *stream)
Make an iostream blocking.
Definition iostream.c:109
ssize_t ast_iostream_printf(struct ast_iostream *stream, const char *format,...)
Write a formatted string to an iostream.
Definition iostream.c:507
ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buffer, size_t size)
Read a LF-terminated string from an iostream.
Definition iostream.c:316
ssize_t ast_iostream_discard(struct ast_iostream *stream, size_t size)
Discard the specified number of bytes from an iostream.
Definition iostream.c:373
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t size)
Write data to an iostream.
Definition iostream.c:390
void ast_iostream_set_timeout_inactivity(struct ast_iostream *stream, int timeout)
Set the iostream inactivity timeout timer.
Definition iostream.c:127
struct ast_iostream * ast_iostream_from_fd(int *fd)
Create an iostream from a file descriptor.
Definition iostream.c:616
void ast_iostream_set_timeout_idle_inactivity(struct ast_iostream *stream, int timeout, int timeout_reset)
Set the iostream inactivity & idle timeout timers.
Definition iostream.c:136
SSL * ast_iostream_get_ssl(struct ast_iostream *stream)
Get a pointer to an iostream's OpenSSL SSL structure.
Definition iostream.c:114
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream's file descriptor.
Definition iostream.c:85
int ast_iostream_start_tls(struct ast_iostream **pstream, SSL_CTX *ssl_ctx, int client)
Begin TLS on an iostream.
Definition iostream.c:632
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.
Definition iostream.c:154
int ast_iostream_set_sni_hostname(struct ast_iostream *stream, const char *sni_hostname)
Set the iostream's SNI hostname for TLS client connections.
Definition iostream.c:161
ssize_t ast_iostream_read(struct ast_iostream *stream, void *buffer, size_t count)
Read data from an iostream.
Definition iostream.c:289
static ssize_t iostream_read(struct ast_iostream *stream, void *buf, size_t size)
Definition iostream.c:171
void ast_iostream_set_timeout_sequence(struct ast_iostream *stream, struct timeval start, int timeout)
Set the iostream I/O sequence timeout timer.
Definition iostream.c:145
void ast_iostream_nonblock(struct ast_iostream *stream)
Make an iostream non-blocking.
Definition iostream.c:104
int ast_iostream_close(struct ast_iostream *stream)
Close an iostream.
Definition iostream.c:544
void ast_iostream_set_timeout_disable(struct ast_iostream *stream)
Disable the iostream timeout timer.
Definition iostream.c:119
int ast_iostream_wait_for_input(struct ast_iostream *stream, int timeout)
Wait for input on the iostream's file descriptor.
Definition iostream.c:90
static void iostream_dtor(void *cookie)
Definition iostream.c:608
Generic abstraction for input/output streams.
struct ssl_ctx_st SSL_CTX
Definition iostream.h:38
struct ssl_st SSL
Definition iostream.h:37
int errno
#define NULL
Definition resample.c:96
String manipulation functions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
char * sni_hostname
Definition iostream.c:49
int exclusive_input
Definition iostream.c:45
char * rbufhead
Definition iostream.c:47
char rbuf[2048]
Definition iostream.c:48
int timeout_reset
Definition iostream.c:44
struct timeval start
Definition iostream.c:41
SSL * ssl
Definition iostream.c:40
Definitions to aid in the use of thread local storage.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
Time-related functions and macros.
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition utils.c:2315
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159
int error(const char *format,...)
Utility functions.
#define ast_assert(a)
Definition utils.h:779
int ast_wait_for_input(int fd, int ms)
Definition utils.c:1732
int ast_wait_for_output(int fd, int ms)
Definition utils.c:1742
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
Definition utils.h:1079
#define ast_fd_clear_flags(fd, flags)
Clear flags on the given file descriptor.
Definition utils.h:1095