summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorAndriy Gelman <andriy.gelman@gmail.com>2020-12-19 22:32:04 -0500
committerAndriy Gelman <andriy.gelman@gmail.com>2020-12-21 01:27:33 -0500
commitcd97e1ff4d70a49efc38ce3bc3d759d300b37b51 (patch)
treeb7b1df0a9a5d3eda7804e0b2611601b1830c72a5 /libavformat
parent6e96e3d970c5500bfc48d2428119fe995eb230c1 (diff)
avformat/libamqp: parse vhost in uri
Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/libamqp.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/libavformat/libamqp.c b/libavformat/libamqp.c
index 81df724a6d..c3b9c484ea 100644
--- a/libavformat/libamqp.c
+++ b/libavformat/libamqp.c
@@ -62,10 +62,10 @@ static const AVOption options[] = {
static int amqp_proto_open(URLContext *h, const char *uri, int flags)
{
int ret, server_msg;
- char hostname[STR_LEN], credentials[STR_LEN];
+ char hostname[STR_LEN], credentials[STR_LEN], path[STR_LEN];
int port;
- const char *user, *password = NULL;
- const char *user_decoded, *password_decoded;
+ const char *user, *password = NULL, *vhost;
+ const char *user_decoded, *password_decoded, *vhost_decoded;
char *p;
amqp_rpc_reply_t broker_reply;
struct timeval tval = { 0 };
@@ -76,7 +76,7 @@ static int amqp_proto_open(URLContext *h, const char *uri, int flags)
h->max_packet_size = s->pkt_size;
av_url_split(NULL, 0, credentials, sizeof(credentials),
- hostname, sizeof(hostname), &port, NULL, 0, uri);
+ hostname, sizeof(hostname), &port, path, sizeof(path), uri);
if (port < 0)
port = 5672;
@@ -109,8 +109,27 @@ static int amqp_proto_open(URLContext *h, const char *uri, int flags)
return AVERROR(ENOMEM);
}
+ /* skip query for now */
+ p = strchr(path, '?');
+ if (p)
+ *p = '\0';
+
+ vhost = path;
+ if (*vhost == '\0')
+ vhost = "/";
+ else
+ vhost++; /* skip leading '/' */
+
+ vhost_decoded = ff_urldecode(vhost, 0);
+ if (!vhost_decoded) {
+ av_freep(&user_decoded);
+ av_freep(&password_decoded);
+ return AVERROR(ENOMEM);
+ }
+
s->conn = amqp_new_connection();
if (!s->conn) {
+ av_freep(&vhost_decoded);
av_freep(&user_decoded);
av_freep(&password_decoded);
av_log(h, AV_LOG_ERROR, "Error creating connection\n");
@@ -136,7 +155,7 @@ static int amqp_proto_open(URLContext *h, const char *uri, int flags)
goto destroy_connection;
}
- broker_reply = amqp_login(s->conn, "/", 0, s->pkt_size, 0,
+ broker_reply = amqp_login(s->conn, vhost_decoded, 0, s->pkt_size, 0,
AMQP_SASL_METHOD_PLAIN, user_decoded, password_decoded);
if (broker_reply.reply_type != AMQP_RESPONSE_NORMAL) {
@@ -195,6 +214,7 @@ static int amqp_proto_open(URLContext *h, const char *uri, int flags)
}
}
+ av_freep(&vhost_decoded);
av_freep(&user_decoded);
av_freep(&password_decoded);
return 0;
@@ -206,6 +226,7 @@ close_connection:
destroy_connection:
amqp_destroy_connection(s->conn);
+ av_freep(&vhost_decoded);
av_freep(&user_decoded);
av_freep(&password_decoded);
return AVERROR_EXTERNAL;