From: Mark Gaiser <markg85@gmail.com> To: "Tomas Härdin" <tjoppen@acc.umu.se> Cc: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH v6 1/1] avformat: Add IPFS protocol support. Date: Wed, 16 Feb 2022 13:44:23 +0100 Message-ID: <CAPd6JnE3YdpXW4GV6=c_iOJU=z89H1No_3LFH+qpHVNZ9KbG7Q@mail.gmail.com> (raw) In-Reply-To: <a21be0d2397f61e42bfe232c4bf2ccbb445fb09b.camel@acc.umu.se> On Wed, Feb 16, 2022 at 10:40 AM Tomas Härdin <tjoppen@acc.umu.se> wrote: > > > + // Test $IPFS_GATEWAY. > > + if (getenv("IPFS_GATEWAY") != NULL) { > > + snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s", > > + getenv("IPFS_GATEWAY")); > > might want to error check this one > > > + ret = 1; > > + goto err; > > + } else > > + av_log(h, AV_LOG_DEBUG, "$IPFS_GATEWAY is empty.\n"); > > + > > + // We need to know the IPFS folder to - eventually - read the > > contents of > > + // the "gateway" file which would tell us the gateway to use. > > + if (getenv("IPFS_PATH") == NULL) { > > + av_log(h, AV_LOG_DEBUG, "$IPFS_PATH is empty.\n"); > > + > > + // Try via the home folder. > > + if (getenv("HOME") == NULL) { > > + av_log(h, AV_LOG_ERROR, "$HOME appears to be empty.\n"); > > + ret = AVERROR(EINVAL); > > + goto err; > > + } > > + > > + // Verify the composed path fits. > > + if (snprintf(ipfs_full_data_folder, > > sizeof(ipfs_full_data_folder), > > + "%s/.ipfs/", getenv("HOME")) > > > sizeof(ipfs_full_data_folder)) { > > >= not > since snprintf() returns the number of character written sans > the terminating NUL > > > + av_log(h, AV_LOG_ERROR, "The IPFS data path exceeds the > > max path length (%li)\n", sizeof(ipfs_full_data_folder)); > > + ret = AVERROR(EINVAL); > > + goto err; > > + } > > + > > + // Stat the folder. > > + // It should exist in a default IPFS setup when run as local > > user. > > +#ifndef _WIN32 > > + stat_ret = stat(ipfs_full_data_folder, &st); > > +#else > > + stat_ret = win32_stat(ipfs_full_data_folder, &st); > > +#endif > > + if (stat_ret < 0) { > > + av_log(h, AV_LOG_INFO, "Unable to find IPFS folder. We > > tried:\n"); > > + av_log(h, AV_LOG_INFO, "- $IPFS_PATH, which was > > empty.\n"); > > + av_log(h, AV_LOG_INFO, "- $HOME/.ipfs (full uri: %s) > > which doesn't exist.\n", ipfs_full_data_folder); > > + ret = AVERROR(ENOENT); > > + goto err; > > + } > > + } else > > + snprintf(ipfs_full_data_folder, > > sizeof(ipfs_full_data_folder), "%s", > > + getenv("IPFS_PATH")); > > not checked > > > + > > + // Copy the fully composed gateway path into ipfs_gateway_file. > > + if (snprintf(ipfs_gateway_file, sizeof(gateway_file_data), > > "%sgateway", > > + ipfs_full_data_folder) > sizeof(ipfs_gateway_file)) > > { > > >= > > > + // At this point gateway_file_data contains at least something. > > + // Copy it into c->gateway_buffer. > > + if (snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s", > > + gateway_file_data) > 0) { > > + ret = 1; > > + goto err; > > + } else > > + av_log(h, AV_LOG_DEBUG, "Unknown error in the IPFS gateway > > file.\n"); > > why not read directly into c->gateway_buffer? > Yes! That would be cleaner, thank you for this suggestion! I didn't do that before because there was no buffer like this before. But now that it's there, I might as well use it. > > > + // Pppulate c->gateway_buffer with whatever is in c->gateway > > + if (c->gateway != NULL) > > + snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s", > > c->gateway); > > + else > > + c->gateway_buffer[0] = '\0'; > > + > > + // Only do the auto detection logic if the gateway_buffer is > > empty > > + if (c->gateway_buffer[0] == '\0') { > > these two ifs can be rolled together > Smart! > > > + // Concatenate the url. > > + // This ends up with something like: > > http://localhost:8080/ipfs/Qm..... > > + fulluri = av_asprintf("%s%s%s", c->gateway_buffer, > > + (is_ipns) ? "ipns/" : "ipfs/", > > + ipfs_cid); > > it is here that I mean you can stick in the / if necessary. that would > make the code much simpler > Would it? I specifically tried to keep gateway url adjustments in sanitize_ipfs_gateway. At this moment all that logic is in sanitize_ipfs_gateway. Are you sure you want me to pull out one part and have it here instead? Adding it here would essentially wrap the first argument in a ternary like: (c->gateway_buffer[strlen(c->gateway_buffer) - 1] == '/') ? "%s%s%s" : "%s/%s%s" I prefer to keep this in sanitize_ipfs_gateway. I'll wait for your response on this one to see if I need to move it or if it can stay as is. > > /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-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2022-02-16 12:44 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-13 18:18 [FFmpeg-devel] [PATCH v6 0/1] " Mark Gaiser 2022-02-13 18:18 ` [FFmpeg-devel] [PATCH v6 1/1] avformat: " Mark Gaiser 2022-02-16 9:40 ` Tomas Härdin 2022-02-16 12:44 ` Mark Gaiser [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CAPd6JnE3YdpXW4GV6=c_iOJU=z89H1No_3LFH+qpHVNZ9KbG7Q@mail.gmail.com' \ --to=markg85@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=tjoppen@acc.umu.se \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git