]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/tls.c
rtpproto: Check for the right feature when reading a sockaddr_in6
[ffmpeg] / libavformat / tls.c
index f89a717b7ad165571f29f2f660b09c5496723368..fecf096b021ab2dd52b4dc65d97eff5157bb21a0 100644 (file)
@@ -73,7 +73,7 @@ static int do_tls_poll(URLContext *h, int ret)
     struct pollfd p = { c->fd, 0, 0 };
 #if CONFIG_GNUTLS
     if (ret != GNUTLS_E_AGAIN && ret != GNUTLS_E_INTERRUPTED) {
-        av_log(NULL, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret));
+        av_log(h, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret));
         return AVERROR(EIO);
     }
     if (gnutls_record_get_direction(c->session))
@@ -87,7 +87,7 @@ static int do_tls_poll(URLContext *h, int ret)
     } else if (ret == SSL_ERROR_WANT_WRITE) {
         p.events = POLLOUT;
     } else {
-        av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
+        av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
         return AVERROR(EIO);
     }
 #endif
@@ -97,7 +97,7 @@ static int do_tls_poll(URLContext *h, int ret)
         int n = poll(&p, 1, 100);
         if (n > 0)
             break;
-        if (url_interrupt_cb())
+        if (ff_check_interrupt(&h->interrupt_callback))
             return AVERROR(EINTR);
     }
     return 0;
@@ -111,6 +111,8 @@ static int tls_open(URLContext *h, const char *uri, int flags)
     char buf[200], host[200];
     int numerichost = 0;
     struct addrinfo hints = { 0 }, *ai = NULL;
+    const char *proxy_path;
+    int use_proxy;
 
     ff_tls_init();
 
@@ -123,7 +125,23 @@ static int tls_open(URLContext *h, const char *uri, int flags)
         freeaddrinfo(ai);
     }
 
-    ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE);
+    proxy_path = getenv("http_proxy");
+    use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), host) &&
+                proxy_path != NULL && av_strstart(proxy_path, "http://", NULL);
+
+    if (use_proxy) {
+        char proxy_host[200], proxy_auth[200], dest[200];
+        int proxy_port;
+        av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth),
+                     proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0,
+                     proxy_path);
+        ff_url_join(dest, sizeof(dest), NULL, NULL, host, port, NULL);
+        ff_url_join(buf, sizeof(buf), "httpproxy", proxy_auth, proxy_host,
+                    proxy_port, "/%s", dest);
+    }
+
+    ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE,
+                     &h->interrupt_callback, NULL);
     if (ret)
         goto fail;
     c->fd = ffurl_get_file_handle(c->tcp);
@@ -146,15 +164,15 @@ static int tls_open(URLContext *h, const char *uri, int flags)
             goto fail;
     }
 #elif CONFIG_OPENSSL
-    c->ctx = SSL_CTX_new(SSLv3_client_method());
+    c->ctx = SSL_CTX_new(TLSv1_client_method());
     if (!c->ctx) {
-        av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
+        av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
         ret = AVERROR(EIO);
         goto fail;
     }
     c->ssl = SSL_new(c->ctx);
     if (!c->ssl) {
-        av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
+        av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
         ret = AVERROR(EIO);
         goto fail;
     }
@@ -166,7 +184,7 @@ static int tls_open(URLContext *h, const char *uri, int flags)
         if (ret > 0)
             break;
         if (ret == 0) {
-            av_log(NULL, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n");
+            av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n");
             ret = AVERROR(EIO);
             goto fail;
         }
@@ -191,7 +209,7 @@ static int tls_read(URLContext *h, uint8_t *buf, int size)
         if (ret > 0)
             return ret;
         if (ret == 0)
-            return AVERROR(EIO);
+            return AVERROR_EOF;
         if ((ret = do_tls_poll(h, ret)) < 0)
             return ret;
     }
@@ -206,7 +224,7 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size)
         if (ret > 0)
             return ret;
         if (ret == 0)
-            return AVERROR(EIO);
+            return AVERROR_EOF;
         if ((ret = do_tls_poll(h, ret)) < 0)
             return ret;
     }
@@ -228,7 +246,7 @@ URLProtocol ff_tls_protocol = {
     .url_open       = tls_open,
     .url_read       = tls_read,
     .url_write      = tls_write,
-    .url_seek       = NULL,
     .url_close      = tls_close,
     .priv_data_size = sizeof(TLSContext),
+    .flags          = URL_PROTOCOL_FLAG_NETWORK,
 };