mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-20 21:00:41 +08:00
avformat: Add ff_format_check_set_url()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include "demux.h"
|
#include "demux.h"
|
||||||
#include "mux.h"
|
#include "mux.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "url.h"
|
||||||
|
|
||||||
void ff_free_stream(AVStream **pst)
|
void ff_free_stream(AVStream **pst)
|
||||||
{
|
{
|
||||||
@@ -868,6 +869,37 @@ void ff_format_set_url(AVFormatContext *s, char *url)
|
|||||||
s->url = url;
|
s->url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ff_format_check_set_url(AVFormatContext *s, const char *url)
|
||||||
|
{
|
||||||
|
URLComponents uc;
|
||||||
|
av_assert0(url);
|
||||||
|
char proto[64];
|
||||||
|
|
||||||
|
int ret = ff_url_decompose(&uc, url, NULL);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
av_strlcpy(proto, uc.scheme, FFMIN(sizeof(proto), uc.url_component_end_scheme - uc.scheme));
|
||||||
|
|
||||||
|
if (s->protocol_whitelist && av_match_list(proto, s->protocol_whitelist, ',') <= 0) {
|
||||||
|
av_log(s, AV_LOG_ERROR, "Protocol '%s' not on whitelist '%s'!\n", proto, s->protocol_whitelist);
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s->protocol_blacklist && av_match_list(proto, s->protocol_blacklist, ',') > 0) {
|
||||||
|
av_log(s, AV_LOG_ERROR, "Protocol '%s' on blacklist '%s'!\n", proto, s->protocol_blacklist);
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
url = av_strdup(url);
|
||||||
|
if (!url)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
av_freep(&s->url);
|
||||||
|
s->url = url;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
|
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|||||||
@@ -630,6 +630,16 @@ int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf
|
|||||||
*/
|
*/
|
||||||
void ff_format_set_url(AVFormatContext *s, char *url);
|
void ff_format_set_url(AVFormatContext *s, char *url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set AVFormatContext url field to a av_strdup of the provided pointer. The pointer must
|
||||||
|
* point to a valid string. The existing url field is freed if necessary.
|
||||||
|
*
|
||||||
|
* Checks protocol_whitelist/blacklist
|
||||||
|
*
|
||||||
|
* @returns a AVERROR code or non negative on success
|
||||||
|
*/
|
||||||
|
int ff_format_check_set_url(AVFormatContext *s, const char *url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a positive value if the given url has one of the given
|
* Return a positive value if the given url has one of the given
|
||||||
* extensions, negative AVERROR on error, 0 otherwise.
|
* extensions, negative AVERROR on error, 0 otherwise.
|
||||||
|
|||||||
Reference in New Issue
Block a user