From 5423e908c9f5f12f599f6c9625ac9539be671695 Mon Sep 17 00:00:00 2001 From: Antti Seppälä Date: Wed, 25 Jul 2012 12:43:39 +0300 Subject: Support urlencoded http authentication credentials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It should be possible to specify usernames in http requests containing urlencoded characters. This patch adds support for decoding the auth strings. Signed-off-by: Antti Seppälä Signed-off-by: Martin Storsjö --- libavformat/urldecode.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 libavformat/urldecode.c (limited to 'libavformat/urldecode.c') diff --git a/libavformat/urldecode.c b/libavformat/urldecode.c new file mode 100644 index 0000000000..32460da4f9 --- /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 Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#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; +} -- cgit v1.2.3