36 #include <openssl/ssl.h>
37 static int openssl_init;
39 #include <openssl/crypto.h>
42 static void openssl_lock(
int mode,
int type,
const char *file,
int line)
44 if (mode & CRYPTO_LOCK)
49 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
50 static unsigned long openssl_thread_id(
void)
52 return (intptr_t) pthread_self();
58 #include <gnutls/gnutls.h>
59 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
62 GCRY_THREAD_OPTION_PTHREAD_IMPL;
72 SSL_load_error_strings();
74 if (!CRYPTO_get_locking_callback()) {
77 for (i = 0; i < CRYPTO_num_locks(); i++)
79 CRYPTO_set_locking_callback(openssl_lock);
80 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
81 CRYPTO_set_id_callback(openssl_thread_id);
89 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
90 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
91 gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
105 if (CRYPTO_get_locking_callback() == openssl_lock) {
107 CRYPTO_set_locking_callback(
NULL);
108 for (i = 0; i < CRYPTO_num_locks(); i++)
116 gnutls_global_deinit();
129 if (!ff_network_inited_globally)
131 "network initialization. Please use "
132 "avformat_network_init(), this will "
133 "become mandatory later.\n");
135 if (WSAStartup(MAKEWORD(1,1), &wsaData))
143 int ev = write ? POLLOUT : POLLIN;
144 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
146 ret = poll(&p, 1, 100);
147 return ret < 0 ?
ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 :
AVERROR(EAGAIN);
160 int err = WSAGetLastError();
166 case WSAEPROTONOSUPPORT:
167 return AVERROR(EPROTONOSUPPORT);
170 case WSAECONNREFUSED:
181 if (addr->sa_family == AF_INET) {
182 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
184 #if HAVE_STRUCT_SOCKADDR_IN6
185 if (addr->sa_family == AF_INET6) {
205 }
while (timeout < 0 || runs-- > 0);
219 fd = socket(af, type | SOCK_CLOEXEC, proto);
220 if (fd == -1 && errno == EINVAL)
223 fd = socket(af, type, proto);
226 fcntl(fd, F_SETFD, FD_CLOEXEC);
233 socklen_t addrlen,
int timeout,
URLContext *h)
237 struct pollfd lp = { fd, POLLIN, 0 };
238 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse));
239 ret = bind(fd, addr, addrlen);
262 socklen_t addrlen,
int timeout,
URLContext *h,
265 struct pollfd p = {fd, POLLOUT, 0};
271 while ((ret = connect(fd, addr, addrlen))) {
283 optlen =
sizeof(ret);
284 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
292 "Connection to %s failed (%s), trying next address\n",
308 if (!strcmp(pattern,
"*"))
311 if (pattern[0] ==
'*')
313 if (pattern[0] ==
'.')
315 len_p = strlen(pattern);
316 len_h = strlen(hostname);
320 if (!strcmp(pattern, &hostname[len_h - len_p])) {
323 if (hostname[len_h - len_p - 1] ==
'.')
342 char *sep, *next =
NULL;
343 start += strspn(start,
" ,");
344 sep = start + strcspn(start,
" ,");
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int avpriv_unlock_avformat(void)
#define AV_LOG_WARNING
Something somehow does not look correct.
memory handling functions
static int match_host_pattern(const char *pattern, const char *hostname)
AVIOInterruptCB interrupt_callback
void ff_network_close(void)
static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout, AVIOInterruptCB *cb)
int ff_socket(int af, int type, int proto)
int ff_network_inited_globally
#define IN6_IS_ADDR_MULTICAST(a)
int ff_listen_bind(int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h)
Bind to a file descriptor and poll for a connection.
int ff_network_init(void)
CRITICAL_SECTION pthread_mutex_t
int ff_listen_connect(int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h, int will_try_next)
Connect to a file descriptor and poll for result.
Callback for checking whether to abort blocking functions.
#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 av_log(void *avcl, int level, const char *fmt,...)
int avpriv_lock_avformat(void)
int ff_is_multicast_address(struct sockaddr *addr)
static int pthread_mutex_destroy(pthread_mutex_t *m)
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
int ff_socket_nonblock(int socket, int enable)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static int pthread_mutex_lock(pthread_mutex_t *m)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrup a blocking function associated with cb.
char * av_strdup(const char *s)
Duplicate the string s.
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
common internal api header.
char * filename
specified URL
w32threads to pthreads wrapper
int ff_network_wait_fd(int fd, int write)
unbuffered private I/O API