From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 56370407EE for ; Mon, 31 Jan 2022 13:53:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 338AC68B2C1; Mon, 31 Jan 2022 15:52:50 +0200 (EET) Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4220068B2A1 for ; Mon, 31 Jan 2022 15:52:40 +0200 (EET) Received: by mail-ej1-f43.google.com with SMTP id p15so43245188ejc.7 for ; Mon, 31 Jan 2022 05:52:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xE9rwGGevlx8dvZ2AB2CGckbUl0Ep8xLorz/+5jKgYs=; b=ktgBeUPaCM3APx48906dtNxqGpIL0dsGYKKBFbFiC/EPnQDCCF/oe/pum9XJHbYTST 1263BlWvdtY2xeNuqlvMsuzvZq24COLl6tvRGYok5bqFn/SWgiQmKh+LjMQtwLiyVJQm 6tGBw+S0qhhT5z+o1DGM7PGWPKH/FWx0mAfAb3veyNTm20EmmACQ7GDpriflhhLt7+Gy oV87p3PBp40AVK7JJ8NeDFeA2CJ4Vjul3Y1tIvmitU0GijRdDBHgPFf7ntlGiwK5gumf Qv1ks1gQTM5tJSRYL3JvIY89HjZFWsSyOoUS9weKzFN4NWOlRc8dZQxlyPreO8GD0ZH0 TXWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xE9rwGGevlx8dvZ2AB2CGckbUl0Ep8xLorz/+5jKgYs=; b=oVsp9/djQhEgI3exsuFdXvqk0bKj5fKOfI6nEv0Vu17QiG7d6w/udIIO4A/B/Os8Cm 2nry3MAR6qRFk+QGUS1s+F3BLkYpVsrMPehpKj8F6yfNA01Iw1q4a3EJsbSbrGaonD8Q sD4MhmpyUq5cXsF3tVj40PoFP4k/YjJhoa0cYeWiM4dz12lwPz0EWAUDFYMHwRXJvg9H 3NPyc/JJ9nn5XF5OLk772zZiabG0//zhcdTmDairFlnVi8RAmrsd9zdER61QW/tWNR2K HPC/Ihp5McnUJBakFdxaPqWg0BQO6bzWoP++ZFj84rj7gAC9xkyjfrh6wSST5kjlbdr9 uLow== X-Gm-Message-State: AOAM533Ol9jgTnLUB2v2NP3B8dBebaVX02zeNwQy1Z6J5wHqe04cGF5K Q19Zm9+9pja9R7x7rH5+OxhPbkiufq1iVg== X-Google-Smtp-Source: ABdhPJwlXExAHFS1U77lqlL6b0w+nggSpepdm4sBNq9smrD5kmvuZJNCBxqie+AA9QackIKcvA31AA== X-Received: by 2002:a17:907:7f91:: with SMTP id qk17mr11435946ejc.686.1643637159374; Mon, 31 Jan 2022 05:52:39 -0800 (PST) Received: from localhost.localdomain (ip60-253-211-87.adsl2.static.versatel.nl. [87.211.253.60]) by smtp.gmail.com with ESMTPSA id l19sm5431885ejq.139.2022.01.31.05.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 05:52:38 -0800 (PST) From: Mark Gaiser To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 Jan 2022 14:51:14 +0100 Message-Id: <20220131135116.14035-4-markg85@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131135116.14035-1-markg85@gmail.com> References: <20220131135116.14035-1-markg85@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] Merge IPNS and IPFS handling. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Mark Gaiser Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Only the open function needs to detect which one is used. Signed-off-by: Mark Gaiser --- libavformat/ipfs.c | 99 +++++++++++----------------------------------- 1 file changed, 22 insertions(+), 77 deletions(-) diff --git a/libavformat/ipfs.c b/libavformat/ipfs.c index 8daf032dd2..22487c6cc8 100644 --- a/libavformat/ipfs.c +++ b/libavformat/ipfs.c @@ -1,6 +1,6 @@ /* * IPFS protocol. - * Copyright (c) 2021 Mark Gaiser + * Copyright (c) 2022 Mark Gaiser * * This file is part of FFmpeg. * @@ -47,23 +47,30 @@ typedef struct Context { static int ipfs_open(URLContext *h, const char *uri, int flags, AVDictionary **options) { const char *gatewaysuffix; + const char *protocolPathSuffix = "ipfs/"; int ret = 0; Context *c = h->priv_data; + int isIpfs = (av_strstart(uri, "ipfs://", &gatewaysuffix) || av_strstart(uri, "ipfs:", &gatewaysuffix)); + int isIpns = (av_strstart(uri, "ipns://", &gatewaysuffix) || av_strstart(uri, "ipns:", &gatewaysuffix)); - if (!av_strstart(uri, "ipfs://", &gatewaysuffix) && - !av_strstart(uri, "ipfs:", &gatewaysuffix)) { - av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); + if (!isIpfs && !isIpns) { ret = AVERROR(EINVAL); + av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); goto err; } - - char* ipfs_gateway = "http://localhost:8080/"; - - c->fulluri = malloc(strlen(ipfs_gateway)+strlen(gatewaysuffix) + 1); - - strcpy(c->fulluri, ipfs_gateway); + + // If we have IPNS, update the protocol + if (isIpns) { + protocolPathSuffix = "ipns/"; + } + + // Concatenate the url. This ends up with something like: http://localhost:8080/ipfs/Qm..... + c->fulluri = malloc(strlen(c->gateway) + strlen(protocolPathSuffix) + strlen(gatewaysuffix) + 1); + strcpy(c->fulluri, c->gateway); + strcat(c->fulluri, protocolPathSuffix); strcat(c->fulluri, gatewaysuffix); + // Pass the URL back to FFMpeg's protocol handler. if ((ret = ffurl_open_whitelist(&c->inner, c->fulluri, flags, &h->interrupt_callback, options, h->protocol_whitelist, h->protocol_blacklist, h)) < 0) { @@ -105,72 +112,10 @@ static int ipfs_close(URLContext *h) return ret; } -static int ipns_open(URLContext *h, const char *uri, int flags, AVDictionary **options) -{ - const char *gatewaysuffix; - int ret = 0; - Context *c = h->priv_data; - - if (!av_strstart(uri, "ipns://", &gatewaysuffix) && - !av_strstart(uri, "ipns:", &gatewaysuffix)) { - av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); - ret = AVERROR(EINVAL); - goto err; - } - - char* ipfs_gateway = "https://ipfs.io/ipns/"; - - c->fulluri = malloc(strlen(ipfs_gateway)+strlen(gatewaysuffix) + 1); - - strcpy(c->fulluri, ipfs_gateway); - strcat(c->fulluri, gatewaysuffix); - - if ((ret = ffurl_open_whitelist(&c->inner, c->fulluri, flags, - &h->interrupt_callback, options, - h->protocol_whitelist, h->protocol_blacklist, h)) < 0) { - av_log(h, AV_LOG_ERROR, "Unable to open resource: %s\n", c->fulluri); - goto err; - } - -err: - return ret; -} - -static int ipns_read(URLContext *h, unsigned char *buf, int size) -{ - Context *c = h->priv_data; - int ret; - - ret = ffurl_read(c->inner, buf, size); - - return ret; -} - -static int64_t ipns_seek(URLContext *h, int64_t pos, int whence) -{ - Context *c = h->priv_data; - int64_t ret; - - ret = ffurl_seek(c->inner, pos, whence); - - return ret; -} - -static int ipns_close(URLContext *h) -{ - Context *c = h->priv_data; - int ret; - - ret = ffurl_closep(&c->inner); - - return ret; -} - #define OFFSET(x) offsetof(Context, x) -#define D AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { - {"gateway", "The gateway to ask for IPFS data.", OFFSET(gateway), AV_OPT_TYPE_BINARY, .flags = D }, + {"gateway", "The gateway to ask for IPFS data.", OFFSET(gateway), AV_OPT_TYPE_STRING, {.str = "http://localhost:8080/"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, {NULL}, }; @@ -193,10 +138,10 @@ const URLProtocol ff_ipfs_protocol = { const URLProtocol ff_ipns_protocol = { .name = "ipns", - .url_open2 = ipns_open, - .url_read = ipns_read, - .url_seek = ipns_seek, - .url_close = ipns_close, + .url_open2 = ipfs_open, + .url_read = ipfs_read, + .url_seek = ipfs_seek, + .url_close = ipfs_close, .priv_data_size = sizeof(Context), .priv_data_class = &ipfs_context_class, }; -- 2.35.1 _______________________________________________ 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".