diff mbox series

[FFmpeg-devel] avformat/gopher: Add support for Gopher over TLS.

Message ID 20210222181412.28003-1-parazyd@dyne.org
State Superseded
Headers show
Series [FFmpeg-devel] avformat/gopher: Add support for Gopher over TLS.
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Ivan J. Feb. 22, 2021, 6:14 p.m. UTC
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 geomyidae(8),
and clients like curl(1), clic(1), and hurl(1).

Signed-off-by: parazyd <parazyd@dyne.org>
---
 libavformat/gopher.c    | 39 +++++++++++++++++++++++++++------------
 libavformat/protocols.c |  1 +
 2 files changed, 28 insertions(+), 12 deletions(-)

Comments

Ivan J. Feb. 26, 2021, 11:13 a.m. UTC | #1
As for the test cases, curl has implemented their local test units[0]
that test gophers.

After applying the patch and compiling, the ffmpeg implementation can
be tested with the following:

1) No encryption:

	$ ./ffplay gopher://parazyd.org/9/pub/dev/random/1593154977112.webm
	$ ./ffplay gopher://adamsgaard.dk/9/npub/alien-love.mkv
	$ ./ffplay gopher://codemadness.org/9/paste/warmelul.mkv

2) TLS with trusted certificate:

	$ ./ffplay gophers://parazyd.org/9/pub/dev/random/1593154977112.webm
	$ ./ffplay gophers://adamsgaard.dk/9/npub/alien-love.mkv
	$ ./ffplay gophers://codemadness.org/9/paste/warmelul.mkv

[0] https://github.com/curl/curl/commit/48b85c46f16f04e803e00b0bad42a4fa0295f517

Best regards,
Ivan
Ivan J. Feb. 28, 2021, 9:35 p.m. UTC | #2
Pinging for review.

Best regards,
Ivan
diff mbox series

Patch

diff --git a/libavformat/gopher.c b/libavformat/gopher.c
index 8b6d14a1f7..c9326080db 100644
--- a/libavformat/gopher.c
+++ b/libavformat/gopher.c
@@ -75,19 +75,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,13 +114,24 @@  static int gopher_read(URLContext *h, uint8_t *buf, int size)
     return len;
 }
 
-
 const URLProtocol ff_gopher_protocol = {
-    .name           = "gopher",
-    .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,
+    .name              = "gopher",
+    .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,tcp"
+};
+
+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"
 };
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index 7df18fbb3b..9e77dc2506 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -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;