summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/Makefile11
-rw-r--r--libavformat/httpauth.c23
-rw-r--r--libavformat/rtmpproto.c249
-rw-r--r--libavformat/urldecode.c87
-rw-r--r--libavformat/urldecode.h35
-rw-r--r--libavformat/version.h2
6 files changed, 304 insertions, 103 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 985da20ef0..f9604fcc24 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -299,9 +299,10 @@ OBJS-$(CONFIG_RTPDEC) += rdt.o \
rtpdec_svq3.o \
rtpdec_vp8.o \
rtpdec_xiph.o
-OBJS-$(CONFIG_RTSP_DEMUXER) += rtsp.o rtspdec.o httpauth.o
+OBJS-$(CONFIG_RTSP_DEMUXER) += rtsp.o rtspdec.o httpauth.o \
+ urldecode.o
OBJS-$(CONFIG_RTSP_MUXER) += rtsp.o rtspenc.o httpauth.o \
- rtpenc_chain.o
+ rtpenc_chain.o urldecode.o
OBJS-$(CONFIG_SAMI_DEMUXER) += samidec.o
OBJS-$(CONFIG_SAP_DEMUXER) += sapdec.o
OBJS-$(CONFIG_SAP_MUXER) += sapenc.o rtpenc_chain.o
@@ -379,9 +380,9 @@ OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL) += rtmphttp.o
OBJS-$(CONFIG_FILE_PROTOCOL) += file.o
OBJS-$(CONFIG_GOPHER_PROTOCOL) += gopher.o
OBJS-$(CONFIG_HLS_PROTOCOL) += hlsproto.o
-OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o httpauth.o
-OBJS-$(CONFIG_HTTPPROXY_PROTOCOL) += http.o httpauth.o
-OBJS-$(CONFIG_HTTPS_PROTOCOL) += http.o httpauth.o
+OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o httpauth.o urldecode.o
+OBJS-$(CONFIG_HTTPPROXY_PROTOCOL) += http.o httpauth.o urldecode.o
+OBJS-$(CONFIG_HTTPS_PROTOCOL) += http.o httpauth.o urldecode.o
OBJS-$(CONFIG_MMSH_PROTOCOL) += mmsh.o mms.o asf.o
OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.o mms.o asf.o
OBJS-$(CONFIG_MD5_PROTOCOL) += md5proto.o
diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c
index 86cdac7f07..646f909a0d 100644
--- a/libavformat/httpauth.c
+++ b/libavformat/httpauth.c
@@ -25,6 +25,7 @@
#include "internal.h"
#include "libavutil/random_seed.h"
#include "libavutil/md5.h"
+#include "urldecode.h"
#include "avformat.h"
#include <ctype.h>
@@ -251,18 +252,28 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth,
return NULL;
if (state->auth_type == HTTP_AUTH_BASIC) {
- int auth_b64_len = AV_BASE64_SIZE(strlen(auth));
- int len = auth_b64_len + 30;
- char *ptr;
+ int auth_b64_len, len;
+ char *ptr, *decoded_auth = ff_urldecode(auth);
+
+ if (!decoded_auth)
+ return NULL;
+
+ auth_b64_len = AV_BASE64_SIZE(strlen(decoded_auth));
+ len = auth_b64_len + 30;
+
authstr = av_malloc(len);
- if (!authstr)
+ if (!authstr) {
+ av_free(decoded_auth);
return NULL;
+ }
+
snprintf(authstr, len, "Authorization: Basic ");
ptr = authstr + strlen(authstr);
- av_base64_encode(ptr, auth_b64_len, auth, strlen(auth));
+ av_base64_encode(ptr, auth_b64_len, decoded_auth, strlen(decoded_auth));
av_strlcat(ptr, "\r\n", len - (ptr - authstr));
+ av_free(decoded_auth);
} else if (state->auth_type == HTTP_AUTH_DIGEST) {
- char *username = av_strdup(auth), *password;
+ char *username = ff_urldecode(auth), *password;
if (!username)
return NULL;
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 2ebb998187..31a8639215 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -880,75 +880,104 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
return 0;
}
-/**
- * Parse received packet and possibly perform some action depending on
- * the packet contents.
- * @return 0 for no errors, negative values for serious errors which prevent
- * further communications, positive values for uncritical errors
- */
-static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
+static int handle_chunk_size(URLContext *s, RTMPPacket *pkt)
+{
+ RTMPContext *rt = s->priv_data;
+ int ret;
+
+ if (pkt->data_size != 4) {
+ av_log(s, AV_LOG_ERROR,
+ "Chunk size change packet is not 4 bytes long (%d)\n",
+ pkt->data_size);
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (!rt->is_input) {
+ if ((ret = ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size,
+ rt->prev_pkt[1])) < 0)
+ return ret;
+ }
+
+ rt->chunk_size = AV_RB32(pkt->data);
+ if (rt->chunk_size <= 0) {
+ av_log(s, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size);
+ return AVERROR_INVALIDDATA;
+ }
+ av_log(s, AV_LOG_DEBUG, "New chunk size = %d\n", rt->chunk_size);
+
+ return 0;
+}
+
+static int handle_ping(URLContext *s, RTMPPacket *pkt)
+{
+ RTMPContext *rt = s->priv_data;
+ int t, ret;
+
+ t = AV_RB16(pkt->data);
+ if (t == 6) {
+ if ((ret = gen_pong(s, rt, pkt)) < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int handle_client_bw(URLContext *s, RTMPPacket *pkt)
{
+ RTMPContext *rt = s->priv_data;
+
+ if (pkt->data_size < 4) {
+ av_log(s, AV_LOG_ERROR,
+ "Client bandwidth report packet is less than 4 bytes long (%d)\n",
+ pkt->data_size);
+ return AVERROR_INVALIDDATA;
+ }
+
+ rt->client_report_size = AV_RB32(pkt->data);
+ if (rt->client_report_size <= 0) {
+ av_log(s, AV_LOG_ERROR, "Incorrect client bandwidth %d\n",
+ rt->client_report_size);
+ return AVERROR_INVALIDDATA;
+
+ }
+ av_log(s, AV_LOG_DEBUG, "Client bandwidth = %d\n", rt->client_report_size);
+ rt->client_report_size >>= 1;
+
+ return 0;
+}
+
+static int handle_server_bw(URLContext *s, RTMPPacket *pkt)
+{
+ RTMPContext *rt = s->priv_data;
+
+ rt->server_bw = AV_RB32(pkt->data);
+ if (rt->server_bw <= 0) {
+ av_log(s, AV_LOG_ERROR, "Incorrect server bandwidth %d\n",
+ rt->server_bw);
+ return AVERROR_INVALIDDATA;
+ }
+ av_log(s, AV_LOG_DEBUG, "Server bandwidth = %d\n", rt->server_bw);
+
+ return 0;
+}
+
+static int handle_invoke(URLContext *s, RTMPPacket *pkt)
+{
+ RTMPContext *rt = s->priv_data;
int i, t;
const uint8_t *data_end = pkt->data + pkt->data_size;
int ret;
-#ifdef DEBUG
- ff_rtmp_packet_dump(s, pkt);
-#endif
+ //TODO: check for the messages sent for wrong state?
+ if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
+ uint8_t tmpstr[256];
- switch (pkt->type) {
- case RTMP_PT_CHUNK_SIZE:
- if (pkt->data_size != 4) {
- av_log(s, AV_LOG_ERROR,
- "Chunk size change packet is not 4 bytes long (%d)\n", pkt->data_size);
- return -1;
- }
- if (!rt->is_input)
- if ((ret = ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size,
- rt->prev_pkt[1])) < 0)
- return ret;
- rt->chunk_size = AV_RB32(pkt->data);
- if (rt->chunk_size <= 0) {
- av_log(s, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size);
- return -1;
- }
- av_log(s, AV_LOG_DEBUG, "New chunk size = %d\n", rt->chunk_size);
- break;
- case RTMP_PT_PING:
- t = AV_RB16(pkt->data);
- if (t == 6)
- if ((ret = gen_pong(s, rt, pkt)) < 0)
- return ret;
- break;
- case RTMP_PT_CLIENT_BW:
- if (pkt->data_size < 4) {
- av_log(s, AV_LOG_ERROR,
- "Client bandwidth report packet is less than 4 bytes long (%d)\n",
- pkt->data_size);
- return -1;
- }
- av_log(s, AV_LOG_DEBUG, "Client bandwidth = %d\n", AV_RB32(pkt->data));
- rt->client_report_size = AV_RB32(pkt->data) >> 1;
- break;
- case RTMP_PT_SERVER_BW:
- rt->server_bw = AV_RB32(pkt->data);
- if (rt->server_bw <= 0) {
- av_log(s, AV_LOG_ERROR, "Incorrect server bandwidth %d\n", rt->server_bw);
- return AVERROR(EINVAL);
- }
- av_log(s, AV_LOG_DEBUG, "Server bandwidth = %d\n", rt->server_bw);
- break;
- case RTMP_PT_INVOKE:
- //TODO: check for the messages sent for wrong state?
- if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
- uint8_t tmpstr[256];
-
- if (!ff_amf_get_field_value(pkt->data + 9, data_end,
- "description", tmpstr, sizeof(tmpstr)))
- av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
- return -1;
- } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) {
- switch (rt->state) {
+ if (!ff_amf_get_field_value(pkt->data + 9, data_end,
+ "description", tmpstr, sizeof(tmpstr)))
+ av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
+ return -1;
+ } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) {
+ switch (rt->state) {
case STATE_HANDSHAKED:
if (!rt->is_input) {
if ((ret = gen_release_stream(s, rt)) < 0)
@@ -996,35 +1025,73 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
}
rt->state = STATE_READY;
break;
- }
- } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) {
- const uint8_t* ptr = pkt->data + 11;
- uint8_t tmpstr[256];
-
- for (i = 0; i < 2; i++) {
- t = ff_amf_tag_size(ptr, data_end);
- if (t < 0)
- return 1;
- ptr += t;
- }
- t = ff_amf_get_field_value(ptr, data_end,
- "level", tmpstr, sizeof(tmpstr));
- if (!t && !strcmp(tmpstr, "error")) {
- if (!ff_amf_get_field_value(ptr, data_end,
- "description", tmpstr, sizeof(tmpstr)))
- av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
- return -1;
- }
- t = ff_amf_get_field_value(ptr, data_end,
- "code", tmpstr, sizeof(tmpstr));
- if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) rt->state = STATE_PLAYING;
- if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED;
- if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED;
- if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING;
- } else if (!memcmp(pkt->data, "\002\000\010onBWDone", 11)) {
- if ((ret = gen_check_bw(s, rt)) < 0)
- return ret;
}
+ } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) {
+ const uint8_t* ptr = pkt->data + 11;
+ uint8_t tmpstr[256];
+
+ for (i = 0; i < 2; i++) {
+ t = ff_amf_tag_size(ptr, data_end);
+ if (t < 0)
+ return 1;
+ ptr += t;
+ }
+ t = ff_amf_get_field_value(ptr, data_end,
+ "level", tmpstr, sizeof(tmpstr));
+ if (!t && !strcmp(tmpstr, "error")) {
+ if (!ff_amf_get_field_value(ptr, data_end,
+ "description", tmpstr, sizeof(tmpstr)))
+ av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
+ return -1;
+ }
+ t = ff_amf_get_field_value(ptr, data_end,
+ "code", tmpstr, sizeof(tmpstr));
+ if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) rt->state = STATE_PLAYING;
+ if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED;
+ if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED;
+ if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING;
+ } else if (!memcmp(pkt->data, "\002\000\010onBWDone", 11)) {
+ if ((ret = gen_check_bw(s, rt)) < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+/**
+ * Parse received packet and possibly perform some action depending on
+ * the packet contents.
+ * @return 0 for no errors, negative values for serious errors which prevent
+ * further communications, positive values for uncritical errors
+ */
+static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
+{
+ int ret;
+
+#ifdef DEBUG
+ ff_rtmp_packet_dump(s, pkt);
+#endif
+
+ switch (pkt->type) {
+ case RTMP_PT_CHUNK_SIZE:
+ if ((ret = handle_chunk_size(s, pkt)) < 0)
+ return ret;
+ break;
+ case RTMP_PT_PING:
+ if ((ret = handle_ping(s, pkt)) < 0)
+ return ret;
+ break;
+ case RTMP_PT_CLIENT_BW:
+ if ((ret = handle_client_bw(s, pkt)) < 0)
+ return ret;
+ break;
+ case RTMP_PT_SERVER_BW:
+ if ((ret = handle_server_bw(s, pkt)) < 0)
+ return ret;
+ break;
+ case RTMP_PT_INVOKE:
+ if ((ret = handle_invoke(s, pkt)) < 0)
+ return ret;
break;
case RTMP_PT_VIDEO:
case RTMP_PT_AUDIO:
diff --git a/libavformat/urldecode.c b/libavformat/urldecode.c
new file mode 100644
index 0000000000..b1009037a8
--- /dev/null
+++ b/libavformat/urldecode.c
@@ -0,0 +1,87 @@
+/*
+ * Simple URL decoding function
+ * Copyright (c) 2012 Antti Seppälä
+ *
+ * References:
+ * RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
+ * T. Berners-Lee et al. The Internet Society, 2005
+ *
+ * based on http://www.icosaedro.it/apache/urldecode.c
+ * from Umberto Salsi (salsi@icosaedro.it)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <ctype.h>
+#include <string.h>
+
+#include "libavutil/mem.h"
+#include "libavutil/avstring.h"
+#include "urldecode.h"
+
+char *ff_urldecode(const char *url)
+{
+ int s = 0, d = 0, url_len = 0;
+ char c;
+ char *dest = NULL;
+
+ if (!url)
+ return NULL;
+
+ url_len = strlen(url) + 1;
+ dest = av_malloc(url_len);
+
+ if (!dest)
+ return NULL;
+
+ while (s < url_len) {
+ c = url[s++];
+
+ if (c == '%' && s + 2 < url_len) {
+ char c2 = url[s++];
+ char c3 = url[s++];
+ if (isxdigit(c2) && isxdigit(c3)) {
+ c2 = av_tolower(c2);
+ c3 = av_tolower(c3);
+
+ if (c2 <= '9')
+ c2 = c2 - '0';
+ else
+ c2 = c2 - 'a' + 10;
+
+ if (c3 <= '9')
+ c3 = c3 - '0';
+ else
+ c3 = c3 - 'a' + 10;
+
+ dest[d++] = 16 * c2 + c3;
+
+ } else { /* %zz or something other invalid */
+ dest[d++] = c;
+ dest[d++] = c2;
+ dest[d++] = c3;
+ }
+ } else if (c == '+') {
+ dest[d++] = ' ';
+ } else {
+ dest[d++] = c;
+ }
+
+ }
+
+ return dest;
+}
diff --git a/libavformat/urldecode.h b/libavformat/urldecode.h
new file mode 100644
index 0000000000..cb81ebc6f7
--- /dev/null
+++ b/libavformat/urldecode.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_URLDECODE_H
+#define AVFORMAT_URLDECODE_H
+
+/**
+ * Decodes an URL from its percent-encoded form back into normal
+ * representation. This function returns the decoded URL in a string.
+ * The URL to be decoded does not necessarily have to be encoded but
+ * in that case the original string is duplicated.
+ *
+ * @param url a string to be decoded.
+ * @return new string with the URL decoded or NULL if decoding failed.
+ * Note that the returned string should be explicitly freed when not
+ * used anymore.
+ */
+char *ff_urldecode(const char *url);
+
+#endif /* AVFORMAT_URLDECODE_H */
diff --git a/libavformat/version.h b/libavformat/version.h
index 547cce352c..6bb2643388 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MINOR 20
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \