[FFmpeg-devel] [PATCH 5/6] lavf/tls: factor ff_tls_process_underlying into its own function

Rodger Combs rodger.combs at gmail.com
Tue Jun 11 17:16:22 EEST 2019


---
 libavformat/tls.c | 45 +++++++++++++++++++++++++++------------------
 libavformat/tls.h |  1 +
 2 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/libavformat/tls.c b/libavformat/tls.c
index 10e0792e29..ccd551061d 100644
--- a/libavformat/tls.c
+++ b/libavformat/tls.c
@@ -51,6 +51,29 @@ static void set_options(TLSShared *c, const char *uri)
 
     if (!c->key_file && av_find_info_tag(buf, sizeof(buf), "key", p))
         c->key_file = av_strdup(buf);
+
+    if (av_find_info_tag(buf, sizeof(buf), "listen", p))
+        c->listen = 1;
+}
+
+int ff_tls_process_underlying(TLSShared *c, URLContext *parent, const char *uri, int *port)
+{
+    struct addrinfo hints = { 0 }, *ai = NULL;
+
+    set_options(c, uri);
+
+    av_url_split(NULL, 0, NULL, 0, c->underlying_host, sizeof(c->underlying_host), port, NULL, 0, uri);
+
+    hints.ai_flags = AI_NUMERICHOST;
+    if (!getaddrinfo(c->underlying_host, NULL, &hints, &ai)) {
+        c->numerichost = 1;
+        freeaddrinfo(ai);
+    }
+
+    if (!c->host && !(c->host = av_strdup(c->underlying_host)))
+        return AVERROR(ENOMEM);
+
+      return 0;
 }
 
 int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
@@ -58,37 +81,23 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV
     int port;
     const char *p;
     char buf[200], opts[50] = "";
-    struct addrinfo hints = { 0 }, *ai = NULL;
     const char *proxy_path;
     int use_proxy;
+    int ret;
 
-    set_options(c, uri);
+    if ((ret = ff_tls_process_underlying(c, parent, uri, &port)) < 0)
+        return ret;
 
     if (c->listen)
         snprintf(opts, sizeof(opts), "?listen=1");
 
-    av_url_split(NULL, 0, NULL, 0, c->underlying_host, sizeof(c->underlying_host), &port, NULL, 0, uri);
-
     p = strchr(uri, '?');
 
-    if (!p) {
+    if (!p)
         p = opts;
-    } else {
-        if (av_find_info_tag(opts, sizeof(opts), "listen", p))
-            c->listen = 1;
-    }
 
     ff_url_join(buf, sizeof(buf), "tcp", NULL, c->underlying_host, port, "%s", p);
 
-    hints.ai_flags = AI_NUMERICHOST;
-    if (!getaddrinfo(c->underlying_host, NULL, &hints, &ai)) {
-        c->numerichost = 1;
-        freeaddrinfo(ai);
-    }
-
-    if (!c->host && !(c->host = av_strdup(c->underlying_host)))
-        return AVERROR(ENOMEM);
-
     proxy_path = getenv("http_proxy");
     use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), c->underlying_host) &&
                 proxy_path && av_strstart(proxy_path, "http://", NULL);
diff --git a/libavformat/tls.h b/libavformat/tls.h
index beb19d6d55..a954f51733 100644
--- a/libavformat/tls.h
+++ b/libavformat/tls.h
@@ -51,6 +51,7 @@ typedef struct TLSShared {
     {"listen",     "Listen for incoming connections",     offsetof(pstruct, options_field . listen),    AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
     {"verifyhost", "Verify against a specific hostname",  offsetof(pstruct, options_field . host),      AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }
 
+int ff_tls_process_underlying(TLSShared *c, URLContext *parent, const char *uri, int *port);
 int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options);
 
 void ff_gnutls_init(void);
-- 
2.21.0



More information about the ffmpeg-devel mailing list