58 char ipfs_full_data_folder[
PATH_MAX];
63 FILE *gateway_file =
NULL;
64 char *env_ipfs_gateway, *env_ipfs_path;
68 if (env_ipfs_gateway !=
NULL) {
69 int printed =
snprintf(
c->gateway_buffer,
sizeof(
c->gateway_buffer),
70 "%s", env_ipfs_gateway);
72 if (printed >=
sizeof(
c->gateway_buffer)) {
74 "The IPFS_GATEWAY environment variable "
75 "exceeds the maximum length. "
76 "We allow a max of %zu characters\n",
77 sizeof(
c->gateway_buffer));
90 if (env_ipfs_path ==
NULL) {
97 if (env_home ==
NULL) {
105 ipfs_full_data_folder,
sizeof(ipfs_full_data_folder),
106 "%s/.ipfs/", env_home);
108 if (printed >=
sizeof(ipfs_full_data_folder)) {
110 "The IPFS data path exceeds the "
111 "max path length (%zu)\n",
112 sizeof(ipfs_full_data_folder));
119 stat_ret = stat(ipfs_full_data_folder, &st);
123 "Unable to find IPFS folder. We tried:\n"
124 "- $IPFS_PATH, which was empty.\n"
125 "- $HOME/.ipfs (full uri: %s) which doesn't exist.\n",
126 ipfs_full_data_folder);
132 ipfs_full_data_folder,
sizeof(ipfs_full_data_folder),
133 "%s", env_ipfs_path);
135 if (printed >=
sizeof(ipfs_full_data_folder)) {
137 "The IPFS_PATH environment variable "
138 "exceeds the maximum length. "
139 "We allow a max of %zu characters\n",
140 sizeof(
c->gateway_buffer));
147 if (
snprintf(ipfs_gateway_file,
sizeof(ipfs_gateway_file),
"%sgateway",
148 ipfs_full_data_folder)
149 >=
sizeof(ipfs_gateway_file)) {
151 "The IPFS gateway file path exceeds "
152 "the max path length (%zu)\n",
153 sizeof(ipfs_gateway_file));
162 "The IPFS gateway file (full uri: %s) doesn't exist. "
163 "Is the gateway enabled?\n",
170 if (!fgets(
c->gateway_buffer,
sizeof(
c->gateway_buffer) - 1, gateway_file)) {
178 c->gateway_buffer[strcspn(
c->gateway_buffer,
"\r\n")] = 0;
182 if (*
c->gateway_buffer ==
'\0') {
184 "The IPFS gateway file (full uri: %s) appears to be empty. "
185 "Is the gateway started?\n",
197 fclose(gateway_file);
204 const char *ipfs_cid;
205 char *fulluri =
NULL;
215 if (!is_ipfs && !is_ipns) {
224 if (strlen(ipfs_cid) < 1) {
231 if (
c->gateway !=
NULL) {
232 if (
snprintf(
c->gateway_buffer,
sizeof(
c->gateway_buffer),
"%s",
234 >=
sizeof(
c->gateway_buffer)) {
236 "The -gateway parameter is too long. "
237 "We allow a max of %zu characters\n",
238 sizeof(
c->gateway_buffer));
249 "IPFS does not appear to be running.\n\n"
250 "Installing IPFS locally is recommended to "
251 "improve performance and reliability, "
252 "and not share all your activity with a single IPFS gateway.\n"
253 "There are multiple options to define this gateway.\n"
254 "1. Call ffmpeg with a gateway param, "
255 "without a trailing slash: -gateway <url>.\n"
256 "2. Define an $IPFS_GATEWAY environment variable with the "
257 "full HTTP URL to the gateway "
258 "without trailing forward slash.\n"
259 "3. Define an $IPFS_PATH environment variable "
260 "and point it to the IPFS data path "
261 "- this is typically ~/.ipfs\n");
271 "The gateway URL didn't start with http:// or "
272 "https:// and is therefore invalid.\n");
286 (
c->gateway_buffer[strlen(
c->gateway_buffer) - 1] ==
'/') ?
"" :
"/",
287 (is_ipns) ?
"ipns/" :
"ipfs/",
299 h->protocol_whitelist,
300 h->protocol_blacklist,
h);
329#define OFFSET(x) offsetof(IPFSGatewayContext, x)
337 .class_name =
"IPFS Gateway",
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
char * av_asprintf(const char *fmt,...)
#define flags(name, subs,...)
static char * getenv_utf8(const char *varname)
static void freeenv_utf8(char *var)
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_stristart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str independent of case.
#define LIBAVUTIL_VERSION_INT
const URLProtocol ff_ipfs_gateway_protocol
const URLProtocol ff_ipns_gateway_protocol
static int ipfs_read(URLContext *h, unsigned char *buf, int size)
static int64_t ipfs_seek(URLContext *h, int64_t pos, int whence)
static int ipfs_close(URLContext *h)
static int translate_ipfs_to_http(URLContext *h, const char *uri, int flags, AVDictionary **options)
static const AVClass ipfs_gateway_context_class
static int populate_ipfs_gateway(URLContext *h)
FILE * avpriv_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
Memory handling functions.
miscellaneous OS support macros and functions.
Describe the class of an AVClass context structure.
char gateway_buffer[PATH_MAX]
unbuffered private I/O API
static int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h.
static int ffurl_read(URLContext *h, uint8_t *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.