You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-10-06 05:47:18 +02:00
avformat/tls: use ff_parse_opts_from_query_string() to set URL parameters
Note that this changes the code to work the same way as other protocols where an URL parameter can override an AVOption. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
@@ -1984,8 +1984,14 @@ The required syntax for a TLS/SSL url is:
|
||||
tls://@var{hostname}:@var{port}[?@var{options}]
|
||||
@end example
|
||||
|
||||
The following parameters can be set via command line options
|
||||
(or in code via @code{AVOption}s):
|
||||
@var{options} contains a list of &-separated options of the form
|
||||
@var{key}=@var{val}. Standard percent-encoding (and using the plus sign for
|
||||
space) can be used to escape keys and values.
|
||||
|
||||
Options can also can be specified via command line options (or in code via
|
||||
@code{AVOption}s).
|
||||
|
||||
The list of supported options follows.
|
||||
|
||||
@table @option
|
||||
|
||||
|
@@ -31,41 +31,6 @@
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/parseutils.h"
|
||||
|
||||
static int set_options(TLSShared *c, const char *uri)
|
||||
{
|
||||
char buf[1024];
|
||||
const char *p = strchr(uri, '?');
|
||||
if (!p)
|
||||
return 0;
|
||||
|
||||
if (!c->ca_file && av_find_info_tag(buf, sizeof(buf), "cafile", p)) {
|
||||
c->ca_file = av_strdup(buf);
|
||||
if (!c->ca_file)
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
if (!c->verify && av_find_info_tag(buf, sizeof(buf), "verify", p)) {
|
||||
char *endptr = NULL;
|
||||
c->verify = strtol(buf, &endptr, 10);
|
||||
if (buf == endptr)
|
||||
c->verify = 1;
|
||||
}
|
||||
|
||||
if (!c->cert_file && av_find_info_tag(buf, sizeof(buf), "cert", p)) {
|
||||
c->cert_file = av_strdup(buf);
|
||||
if (!c->cert_file)
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
if (!c->key_file && av_find_info_tag(buf, sizeof(buf), "key", p)) {
|
||||
c->key_file = av_strdup(buf);
|
||||
if (!c->key_file)
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
|
||||
{
|
||||
int port;
|
||||
@@ -77,17 +42,18 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV
|
||||
int use_proxy;
|
||||
int ret;
|
||||
|
||||
ret = set_options(c, uri);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
p = strchr(uri, '?');
|
||||
if (p) {
|
||||
ret = ff_parse_opts_from_query_string(c, p, 1);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (c->listen && !c->is_dtls)
|
||||
snprintf(opts, sizeof(opts), "?listen=1");
|
||||
|
||||
av_url_split(NULL, 0, NULL, 0, c->underlying_host, sizeof(c->underlying_host), &port, NULL, 0, uri);
|
||||
|
||||
p = strchr(uri, '?');
|
||||
|
||||
if (!p) {
|
||||
p = opts;
|
||||
} else {
|
||||
|
@@ -174,17 +174,6 @@ static void handle_handshake_error(URLContext *h, int ret)
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_options(TLSContext *tls_ctxc, const char *uri)
|
||||
{
|
||||
char buf[1024];
|
||||
const char *p = strchr(uri, '?');
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
if (!tls_ctxc->priv_key_pw && av_find_info_tag(buf, sizeof(buf), "key_password", p))
|
||||
tls_ctxc->priv_key_pw = av_strdup(buf);
|
||||
}
|
||||
|
||||
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
|
||||
{
|
||||
TLSContext *tls_ctx = h->priv_data;
|
||||
@@ -192,9 +181,6 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
|
||||
uint32_t verify_res_flags;
|
||||
int ret;
|
||||
|
||||
// parse additional options
|
||||
parse_options(tls_ctx, uri);
|
||||
|
||||
if ((ret = ff_tls_open_underlying(shr, h, uri, options)) < 0)
|
||||
goto fail;
|
||||
|
||||
|
Reference in New Issue
Block a user