Re: [FFmpeg-devel] [PATCH v7 1/1] avformat: Add IPFS protocol support.

2022-02-21 Thread Tomas Härdin
tor 2022-02-17 klockan 15:26 +0100 skrev Mark Gaiser:
> > 
> > > +
> > > +    // Test $IPFS_GATEWAY.
> > > +    if (getenv("IPFS_GATEWAY") != NULL) {
> > > +    if (snprintf(c->gateway_buffer, sizeof(c-
> > > >gateway_buffer),
> > > "%s",
> > > + getenv("IPFS_GATEWAY")) >= sizeof(c-
> > > > gateway_buffer)) {
> > > +    av_log(h, AV_LOG_ERROR, "The IPFS_GATEWAY
> > > environment
> > > variable exceeds the maximum length. We allow a max of %li
> > > characters\n", sizeof(c->gateway_buffer));
> > 
> > nit: seems a bit weird to break the if but not the av_log()
> > Also this should be %zu not %li
> > 
> 
> The compiler doesn't complain about this one.
> How do you know %zu is right? I used this table and it knows nothing
> about
> %z...
> https://www.cplusplus.com/reference/cstdio/printf/

sizeof() returns size_t

/Tomas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v7 1/1] avformat: Add IPFS protocol support.

2022-02-17 Thread Mark Gaiser
On Thu, Feb 17, 2022 at 2:57 PM Tomas Härdin  wrote:

> > +IPFSGatewayContext *c = h->priv_data;
> > +char ipfs_full_data_folder[PATH_MAX];
> > +char ipfs_gateway_file[PATH_MAX];
> > +struct stat st;
> > +int stat_ret = 0;
> > +int ret = AVERROR(EINVAL);
> > +FILE *gateway_file = NULL;
> > +
> > +// Set the first character of c->gateway_buffer to 0.
> > +c->gateway_buffer[0] = '\0';
>
> unnecessary
>

Hmm, interesting. I tried to be secure and not let any potential strlen
trip when there is garbage data in c->gateway_buffer.
Just to set it in a function that always overwrites it anyhow ;)
Aka, useless.

>
> > +
> > +// Test $IPFS_GATEWAY.
> > +if (getenv("IPFS_GATEWAY") != NULL) {
> > +if (snprintf(c->gateway_buffer, sizeof(c->gateway_buffer),
> > "%s",
> > + getenv("IPFS_GATEWAY")) >= sizeof(c-
> > >gateway_buffer)) {
> > +av_log(h, AV_LOG_ERROR, "The IPFS_GATEWAY environment
> > variable exceeds the maximum length. We allow a max of %li
> > characters\n", sizeof(c->gateway_buffer));
>
> nit: seems a bit weird to break the if but not the av_log()
> Also this should be %zu not %li
>

The compiler doesn't complain about this one.
How do you know %zu is right? I used this table and it knows nothing about
%z...
https://www.cplusplus.com/reference/cstdio/printf/

Anyhow, I'm certainly not doubting you so changing it (and all other %li
occurrences). Other sites seem to indicate it's for printing size_t .

So.. erm... the next version can finally be merged?


> /Tomas
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v7 1/1] avformat: Add IPFS protocol support.

2022-02-17 Thread Tomas Härdin
> +    IPFSGatewayContext *c = h->priv_data;
> +    char ipfs_full_data_folder[PATH_MAX];
> +    char ipfs_gateway_file[PATH_MAX];
> +    struct stat st;
> +    int stat_ret = 0;
> +    int ret = AVERROR(EINVAL);
> +    FILE *gateway_file = NULL;
> +
> +    // Set the first character of c->gateway_buffer to 0.
> +    c->gateway_buffer[0] = '\0';

unnecessary

> +
> +    // Test $IPFS_GATEWAY.
> +    if (getenv("IPFS_GATEWAY") != NULL) {
> +    if (snprintf(c->gateway_buffer, sizeof(c->gateway_buffer),
> "%s",
> + getenv("IPFS_GATEWAY")) >= sizeof(c-
> >gateway_buffer)) {
> +    av_log(h, AV_LOG_ERROR, "The IPFS_GATEWAY environment
> variable exceeds the maximum length. We allow a max of %li
> characters\n", sizeof(c->gateway_buffer));

nit: seems a bit weird to break the if but not the av_log()
Also this should be %zu not %li

/Tomas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v7 1/1] avformat: Add IPFS protocol support.

2022-02-16 Thread Mark Gaiser
This patch adds support for:
- ffplay ipfs://
- ffplay ipns://

IPFS data can be played from so called "ipfs gateways".
A gateway is essentially a webserver that gives access to the
distributed IPFS network.

This protocol support (ipfs and ipns) therefore translates
ipfs:// and ipns:// to a http:// url. This resulting url is
then handled by the http protocol. It could also be https
depending on the gateway provided.

To use this protocol, a gateway must be provided.
If you do nothing it will try to find it in your
$HOME/.ipfs/gateway file. The ways to set it manually are:
1. Define a -gateway  to the gateway.
2. Define $IPFS_GATEWAY with the full http link to the gateway.
3. Define $IPFS_PATH and point it to the IPFS data path.
4. Have IPFS running in your local user folder (under $HOME/.ipfs).

Signed-off-by: Mark Gaiser 
---
 configure |   2 +
 doc/protocols.texi|  30 
 libavformat/Makefile  |   2 +
 libavformat/ipfsgateway.c | 312 ++
 libavformat/protocols.c   |   2 +
 5 files changed, 348 insertions(+)
 create mode 100644 libavformat/ipfsgateway.c

diff --git a/configure b/configure
index 5b19a35f59..6ff09e7974 100755
--- a/configure
+++ b/configure
@@ -3585,6 +3585,8 @@ udp_protocol_select="network"
 udplite_protocol_select="network"
 unix_protocol_deps="sys_un_h"
 unix_protocol_select="network"
+ipfs_protocol_select="https_protocol"
+ipns_protocol_select="https_protocol"
 
 # external library protocols
 libamqp_protocol_deps="librabbitmq"
diff --git a/doc/protocols.texi b/doc/protocols.texi
index d207df0b52..7c9c0a4808 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -2025,5 +2025,35 @@ decoding errors.
 
 @end table
 
+@section ipfs
+
+InterPlanetary File System (IPFS) protocol support. One can access files 
stored 
+on the IPFS network through so called gateways. Those are http(s) endpoints.
+This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to be send 
+to such a gateway. Users can (and should) host their own node which means this 
+protocol will use your local machine gateway to access files on the IPFS 
network.
+
+If a user doesn't have a node of their own then the public gateway dweb.link 
is 
+used by default.
+
+You can use this protocol in 2 ways. Using IPFS:
+@example
+ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
+@end example
+
+Or the IPNS protocol (IPNS is mutable IPFS):
+@example
+ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
+@end example
+
+You can also change the gateway to be used:
+
+@table @option
+
+@item gateway
+Defines the gateway to use. When nothing is provided the protocol will first 
try 
+your local gateway. If that fails dweb.link will be used.
+
+@end table
 
 @c man end PROTOCOLS
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 3dc6a479cc..4edce8420f 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -656,6 +656,8 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) += srtpproto.o 
srtp.o
 OBJS-$(CONFIG_SUBFILE_PROTOCOL)  += subfile.o
 OBJS-$(CONFIG_TEE_PROTOCOL)  += teeproto.o tee_common.o
 OBJS-$(CONFIG_TCP_PROTOCOL)  += tcp.o
+OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfsgateway.o
+OBJS-$(CONFIG_IPNS_PROTOCOL) += ipfsgateway.o
 TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
 TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
 TLS-OBJS-$(CONFIG_MBEDTLS)   += tls_mbedtls.o
diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c
new file mode 100644
index 00..35456c00c4
--- /dev/null
+++ b/libavformat/ipfsgateway.c
@@ -0,0 +1,312 @@
+/*
+ * IPFS and IPNS protocol support through IPFS Gateway.
+ * Copyright (c) 2022 Mark Gaiser
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+#include "libavutil/tree.h"
+#include 
+#if HAVE_IO_H
+#include 
+#endif
+#if HAVE_UNISTD_H
+#include 
+#endif
+#include "os_support.h"
+#include "url.h"
+#include 
+#include 
+
+typedef struct IPFSGatewayContext {
+AVClass *class;
+URLContext *inner;
+// Is filled by the -gateway