From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTP id 1E90C40815
	for <ffmpegdev@gitmailbox.com>; Mon, 31 Jan 2022 15:59:37 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B025E68B10A;
	Mon, 31 Jan 2022 17:59:35 +0200 (EET)
Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net
 [217.70.183.200])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 49A3568B07D
 for <ffmpeg-devel@ffmpeg.org>; Mon, 31 Jan 2022 17:59:29 +0200 (EET)
Received: from localhost (213-47-68-29.cable.dynamic.surfer.at [213.47.68.29])
 (Authenticated sender: michael@niedermayer.cc)
 by mail.gandi.net (Postfix) with ESMTPSA id 651892000D
 for <ffmpeg-devel@ffmpeg.org>; Mon, 31 Jan 2022 15:59:28 +0000 (UTC)
Date: Mon, 31 Jan 2022 16:59:27 +0100
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Message-ID: <20220131155927.GJ2829255@pb2>
References: <20220131135116.14035-1-markg85@gmail.com>
 <20220131135116.14035-2-markg85@gmail.com>
MIME-Version: 1.0
In-Reply-To: <20220131135116.14035-2-markg85@gmail.com>
Subject: Re: [FFmpeg-devel] [PATCH 1/5] Early version of IPFS protocol
 support.
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: multipart/mixed; boundary="===============2314986316406048172=="
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20220131155927.GJ2829255@pb2/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>


--===============2314986316406048172==
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature"; boundary="P+wE8RYtAhz/Wfro"
Content-Disposition: inline


--P+wE8RYtAhz/Wfro
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jan 31, 2022 at 02:51:12PM +0100, Mark Gaiser wrote:
> Signed-off-by: Mark Gaiser <markg85@gmail.com>
> ---
>  configure               |   1 +
>  doc/protocols.texi      |  30 ++++++
>  libavformat/Makefile    |   1 +
>  libavformat/ipfs.c      | 202 ++++++++++++++++++++++++++++++++++++++++
>  libavformat/protocols.c |   2 +
>  5 files changed, 236 insertions(+)
>  create mode 100644 libavformat/ipfs.c
>=20
> diff --git a/configure b/configure
> index 5b19a35f59..e466f924a3 100755
> --- a/configure
> +++ b/configure
> @@ -3585,6 +3585,7 @@ udp_protocol_select=3D"network"
>  udplite_protocol_select=3D"network"
>  unix_protocol_deps=3D"sys_un_h"
>  unix_protocol_select=3D"network"
> +ipfs_protocol_select=3D"https_protocol"
> =20
>  # external library protocols
>  libamqp_protocol_deps=3D"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.
> =20
>  @end table
> =20
> +@section ipfs
> +
> +InterPlanetary File System (IPFS) protocol support. One can access files=
 stored=20
> +on the IPFS network through so called gateways. Those are http(s) endpoi=
nts.
> +This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to b=
e send=20
> +to such a gateway. Users can (and should) host their own node which mean=
s this=20
> +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=20
> +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 f=
irst try=20
> +your local gateway. If that fails dweb.link will be used.
> +
> +@end table
> =20
>  @c man end PROTOCOLS
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 3dc6a479cc..983a77f4f2 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -656,6 +656,7 @@ OBJS-$(CONFIG_SRTP_PROTOCOL)             +=3D srtppro=
to.o srtp.o
>  OBJS-$(CONFIG_SUBFILE_PROTOCOL)          +=3D subfile.o
>  OBJS-$(CONFIG_TEE_PROTOCOL)              +=3D teeproto.o tee_common.o
>  OBJS-$(CONFIG_TCP_PROTOCOL)              +=3D tcp.o
> +OBJS-$(CONFIG_IPFS_PROTOCOL)             +=3D ipfs.o
>  TLS-OBJS-$(CONFIG_GNUTLS)                +=3D tls_gnutls.o
>  TLS-OBJS-$(CONFIG_LIBTLS)                +=3D tls_libtls.o
>  TLS-OBJS-$(CONFIG_MBEDTLS)               +=3D tls_mbedtls.o
> diff --git a/libavformat/ipfs.c b/libavformat/ipfs.c
> new file mode 100644
> index 0000000000..4cc65750ed
> --- /dev/null
> +++ b/libavformat/ipfs.c
> @@ -0,0 +1,202 @@
> +/*
> + * IPFS protocol.
> + * Copyright (c) 2021 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-1=
301 USA
> + */
> +
> +#include "libavutil/avassert.h"
> +#include "libavutil/avstring.h"
> +#include "libavutil/internal.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/tree.h"
> +#include "avformat.h"
> +#include <fcntl.h>
> +#if HAVE_IO_H
> +#include <io.h>
> +#endif
> +#if HAVE_UNISTD_H
> +#include <unistd.h>
> +#endif
> +#include <sys/stat.h>
> +#include <stdlib.h>
> +#include "os_support.h"
> +#include "url.h"
> +
> +typedef struct Context {
> +    AVClass *class;
> +    URLContext *inner;
> +    char *fulluri;
> +    char *gateway;
> +} Context;
> +
> +static int ipfs_open(URLContext *h, const char *uri, int flags, AVDictio=
nary **options)
> +{
> +    const char *gatewaysuffix;

> +    int ret =3D 0;

the initializuation seems redundant


> +    Context *c =3D h->priv_data;
> +   =20
> +    if (!av_strstart(uri, "ipfs://", &gatewaysuffix) &&
> +        !av_strstart(uri, "ipfs:", &gatewaysuffix)) {
> +        av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);
> +        ret =3D AVERROR(EINVAL);
> +        goto err;
> +    }
> +   =20
> +    char* ipfs_gateway =3D "https://ipfs.io/ipfs/";
> +   =20
> +    c->fulluri =3D malloc(strlen(ipfs_gateway)+strlen(gatewaysuffix) + 1=
);
> +   =20
> +    strcpy(c->fulluri, ipfs_gateway);
> +    strcat(c->fulluri, gatewaysuffix);

malloc() should be av_malloc() unless there is some API interaction requiri=
ng otherwise
also all the  cpy/cat stuff should use "secure" size checking variants
but maybe something like av_asprintf() could simplify this all

[...]

thx


--=20
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Elect your leaders based on what they did after the last election, not
based on what they say before an election.


--P+wE8RYtAhz/Wfro
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCYfgHXAAKCRBhHseHBAsP
q9PSAJ9AZNzgx84pwxjDnhlZqcTpJpZC7gCfQxxgI7rZok1gSODRc7rVkglq3dI=
=oaHg
-----END PGP SIGNATURE-----

--P+wE8RYtAhz/Wfro--

--===============2314986316406048172==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

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

--===============2314986316406048172==--