35 #include <openssl/bio.h> 36 #include <openssl/ssl.h> 37 #include <openssl/err.h> 46 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL 52 #include <openssl/crypto.h> 54 static void openssl_lock(
int mode,
int type,
const char *file,
int line)
56 if (mode & CRYPTO_LOCK)
61 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000 62 static unsigned long openssl_thread_id(
void)
64 return (intptr_t) pthread_self();
74 SSL_load_error_strings();
76 if (!CRYPTO_get_locking_callback()) {
79 for (i = 0; i < CRYPTO_num_locks(); i++)
81 CRYPTO_set_locking_callback(openssl_lock);
82 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000 83 CRYPTO_set_id_callback(openssl_thread_id);
98 if (CRYPTO_get_locking_callback() == openssl_lock) {
100 CRYPTO_set_locking_callback(
NULL);
101 for (i = 0; i < CRYPTO_num_locks(); i++)
120 SSL_shutdown(c->
ssl);
124 SSL_CTX_free(c->
ctx);
127 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL 128 if (c->url_bio_method)
129 BIO_meth_free(c->url_bio_method);
137 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL 139 BIO_set_data(b,
NULL);
154 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL 155 #define GET_BIO_DATA(x) BIO_get_data(x) 157 #define GET_BIO_DATA(x) (x)->ptr 166 BIO_clear_retry_flags(b);
178 BIO_clear_retry_flags(b);
186 if (cmd == BIO_CTRL_FLUSH) {
187 BIO_clear_retry_flags(b);
198 #if OPENSSL_VERSION_NUMBER < 0x1010000fL 200 .type = BIO_TYPE_SOURCE_SINK,
201 .name =
"urlprotocol bio",
224 p->
ctx = SSL_CTX_new(c->
listen ? TLSv1_server_method() : TLSv1_client_method());
247 SSL_CTX_set_verify(p->
ctx, SSL_VERIFY_PEER,
NULL);
254 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL 255 p->url_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK,
"urlprotocol bio");
262 bio = BIO_new(p->url_bio_method);
263 BIO_set_data(bio, c->
tcp);
268 SSL_set_bio(p->
ssl, bio, bio);
270 SSL_set_tlsext_host_name(p->
ssl, c->
host);
271 ret = c->
listen ? SSL_accept(p->
ssl) : SSL_connect(p->
ssl);
276 }
else if (ret < 0) {
290 int ret = SSL_read(c->
ssl, buf, size);
301 int ret = SSL_write(c->
ssl, buf, size);
329 .priv_data_class = &tls_class,
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define URL_PROTOCOL_FLAG_NETWORK
int avpriv_unlock_avformat(void)
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
static int url_bio_bwrite(BIO *b, const char *buf, int len)
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int url_bio_bread(BIO *b, char *buf, int len)
miscellaneous OS support macros and functions.
static int url_bio_bputs(BIO *b, const char *str)
CRITICAL_SECTION pthread_mutex_t
const URLProtocol ff_tls_openssl_protocol
#define AVERROR_EOF
End of file.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int pthread_mutex_init(pthread_mutex_t *m, void *attr)
static int pthread_mutex_unlock(pthread_mutex_t *m)
void ff_openssl_init(void)
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
int avpriv_lock_avformat(void)
static const AVOption options[]
static int pthread_mutex_destroy(pthread_mutex_t *m)
void ff_openssl_deinit(void)
static const AVClass tls_class
#define TLS_COMMON_OPTIONS(pstruct, options_field)
static int tls_write(URLContext *h, const uint8_t *buf, int size)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static int url_bio_destroy(BIO *b)
static int pthread_mutex_lock(pthread_mutex_t *m)
static int print_tls_error(URLContext *h, int ret)
static int tls_read(URLContext *h, uint8_t *buf, int size)
Describe the class of an AVClass context structure.
static int tls_close(URLContext *h)
int ffurl_close(URLContext *h)
Close the resource accessed by the URLContext h, and free the memory used by it.
common internal api header.
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
static BIO_METHOD url_bio_method
static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
unbuffered private I/O API
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...
static int url_bio_create(BIO *b)