]> git.sesse.net Git - ffmpeg/commitdiff
avformat/gopher: Add support for Gopher over TLS
authorparazyd <parazyd@dyne.org>
Sun, 28 Feb 2021 22:47:05 +0000 (23:47 +0100)
committerMarton Balint <cus@passwd.hu>
Thu, 11 Mar 2021 22:47:19 +0000 (23:47 +0100)
This commit adds a "gophers" handler to the gopher protocol. gophers
is a community-adopted protocol that acts the same way like normal
gopher with the added TLS encapsulation.

The gophers protocol is supported by gopher servers like geomydae(8),
and clients like curl(1), clic(1), and hurl(1).

This commit also adds compilation guards to both gopher and gophers,
since now there are two protocols in the file it makes sense to
have this addition.

Signed-off-by: parazyd <parazyd@dyne.org>
Signed-off-by: Marton Balint <cus@passwd.hu>
Changelog
configure
doc/general_contents.texi
doc/protocols.texi
libavformat/Makefile
libavformat/gopher.c
libavformat/protocols.c
libavformat/version.h

index b28a8c59f1dce6433045f5d31c78589c5cddc27c..73deaf6b0f4358873aafdde856a0f2c9cbbe0f97 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -81,6 +81,7 @@ version <next>:
 - TTML subtitle encoder and muxer
 - identity video filter
 - msad video filter
+- gophers protocol
 
 
 version 4.3:
index 1c0888ffa6c288b79d1a8c8c636796a917817bbd..13f8e0580b5c90053c5cc39d2c1df785974b2a2e 100755 (executable)
--- a/configure
+++ b/configure
@@ -3450,6 +3450,7 @@ ffrtmphttp_protocol_conflict="librtmp_protocol"
 ffrtmphttp_protocol_select="http_protocol"
 ftp_protocol_select="tcp_protocol"
 gopher_protocol_select="tcp_protocol"
+gophers_protocol_select="tls_protocol"
 http_protocol_select="tcp_protocol"
 http_protocol_suggest="zlib"
 httpproxy_protocol_select="tcp_protocol"
index 58c9bcf747a4f1a93da228f07210ac6d88fd3418..33ece6e884060f3237d9c206df6713d13ed6a840 100644 (file)
@@ -1371,6 +1371,7 @@ performance on systems without hardware floating point support).
 @item file         @tab X
 @item FTP          @tab X
 @item Gopher       @tab X
+@item Gophers      @tab X
 @item HLS          @tab X
 @item HTTP         @tab X
 @item HTTPS        @tab X
index c0b511b7a4cdb8031cdfd2f0de6f7733d864b49a..2b2fab875281ff35c85cb4b0df9dfc80ddfe167e 100644 (file)
@@ -341,6 +341,12 @@ operation. ff* tools may produce incomplete content due to server limitations.
 
 Gopher protocol.
 
+@section gophers
+
+Gophers protocol.
+
+The Gopher protocol with TLS encapsulation.
+
 @section hls
 
 Read Apple HTTP Live Streaming compliant segmented stream as
index 0504f47f88f2c6598393778a6126888a80a92438..8ce53d5a8c1fe65227774ab8314b0efed3e85f80 100644 (file)
@@ -621,6 +621,7 @@ OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL)       += rtmphttp.o
 OBJS-$(CONFIG_FILE_PROTOCOL)             += file.o
 OBJS-$(CONFIG_FTP_PROTOCOL)              += ftp.o urldecode.o
 OBJS-$(CONFIG_GOPHER_PROTOCOL)           += gopher.o
+OBJS-$(CONFIG_GOPHERS_PROTOCOL)          += gopher.o
 OBJS-$(CONFIG_HLS_PROTOCOL)              += hlsproto.o
 OBJS-$(CONFIG_HTTP_PROTOCOL)             += http.o httpauth.o urldecode.o
 OBJS-$(CONFIG_HTTPPROXY_PROTOCOL)        += http.o httpauth.o urldecode.o
index 7c88ab01a83a4abbb659515bb58cdcce660b1256..9bbe171640359cc6c4f4e65c230737e3ea953d26 100644 (file)
@@ -2,6 +2,7 @@
  * Gopher protocol
  *
  * Copyright (c) 2009 Toshimitsu Kimura
+ * Copyright (c) 2021 parazyd <parazyd@dyne.org>
  *
  * based on libavformat/http.c, Copyright (c) 2000, 2001 Fabrice Bellard
  *
@@ -22,6 +23,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
+
 #include "libavutil/avstring.h"
 #include "avformat.h"
 #include "internal.h"
@@ -75,19 +78,23 @@ static int gopher_close(URLContext *h)
 static int gopher_open(URLContext *h, const char *uri, int flags)
 {
     GopherContext *s = h->priv_data;
-    char hostname[1024], auth[1024], path[1024], buf[1024];
+    char proto[10], hostname[1024], auth[1024], path[1024], buf[1024];
     int port, err;
+    const char *lower_proto = "tcp";
 
     h->is_streamed = 1;
 
     /* needed in any case to build the host string */
-    av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
-                 path, sizeof(path), uri);
+    av_url_split(proto, sizeof(proto), auth, sizeof(auth),
+                 hostname, sizeof(hostname), &port, path, sizeof(path), uri);
 
     if (port < 0)
         port = 70;
 
-    ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
+    if (!strcmp(proto, "gophers"))
+        lower_proto = "tls";
+
+    ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
 
     s->hd = NULL;
     err = ffurl_open_whitelist(&s->hd, buf, AVIO_FLAG_READ_WRITE,
@@ -110,6 +117,7 @@ static int gopher_read(URLContext *h, uint8_t *buf, int size)
     return len;
 }
 
+#if CONFIG_GOPHER_PROTOCOL
 const URLProtocol ff_gopher_protocol = {
     .name              = "gopher",
     .url_open          = gopher_open,
@@ -120,3 +128,17 @@ const URLProtocol ff_gopher_protocol = {
     .flags             = URL_PROTOCOL_FLAG_NETWORK,
     .default_whitelist = "gopher,tcp"
 };
+#endif /* CONFIG_GOPHER_PROTOCOL */
+
+#if CONFIG_GOPHERS_PROTOCOL
+const URLProtocol ff_gophers_protocol = {
+    .name              = "gophers",
+    .url_open          = gopher_open,
+    .url_read          = gopher_read,
+    .url_write         = gopher_write,
+    .url_close         = gopher_close,
+    .priv_data_size    = sizeof(GopherContext),
+    .flags             = URL_PROTOCOL_FLAG_NETWORK,
+    .default_whitelist = "gopher,gophers,tcp,tls"
+};
+#endif /* CONFIG_GOPHERS_PROTOCOL */
index 7df18fbb3b98316cc96ef3add705bce250ec3418..9e77dc250624e640ef1bb1ef6734b3c89120f376 100644 (file)
@@ -34,6 +34,7 @@ extern const URLProtocol ff_ffrtmphttp_protocol;
 extern const URLProtocol ff_file_protocol;
 extern const URLProtocol ff_ftp_protocol;
 extern const URLProtocol ff_gopher_protocol;
+extern const URLProtocol ff_gophers_protocol;
 extern const URLProtocol ff_hls_protocol;
 extern const URLProtocol ff_http_protocol;
 extern const URLProtocol ff_httpproxy_protocol;
index 2a2804582ca99f069ffd9daf09866cd2341fd407..6f55726afd14d1d570ac021514323204a20fb57c 100644 (file)
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
-#define LIBAVFORMAT_VERSION_MINOR  72
+#define LIBAVFORMAT_VERSION_MINOR  73
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \