avformat/urldecode: add the ability to not decode plus sign to space

Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Marton Balint 2020-02-04 23:44:28 +01:00
parent 6a7b5226e1
commit 8224f1e0ba
3 changed files with 6 additions and 5 deletions

View File

@ -255,7 +255,7 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth,
if (state->auth_type == HTTP_AUTH_BASIC) { if (state->auth_type == HTTP_AUTH_BASIC) {
int auth_b64_len, len; int auth_b64_len, len;
char *ptr, *decoded_auth = ff_urldecode(auth); char *ptr, *decoded_auth = ff_urldecode(auth, 1);
if (!decoded_auth) if (!decoded_auth)
return NULL; return NULL;
@ -275,7 +275,7 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth,
av_strlcat(ptr, "\r\n", len - (ptr - authstr)); av_strlcat(ptr, "\r\n", len - (ptr - authstr));
av_free(decoded_auth); av_free(decoded_auth);
} else if (state->auth_type == HTTP_AUTH_DIGEST) { } else if (state->auth_type == HTTP_AUTH_DIGEST) {
char *username = ff_urldecode(auth), *password; char *username = ff_urldecode(auth, 1), *password;
if (!username) if (!username)
return NULL; return NULL;

View File

@ -32,7 +32,7 @@
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "urldecode.h" #include "urldecode.h"
char *ff_urldecode(const char *url) char *ff_urldecode(const char *url, int decode_plus_sign)
{ {
int s = 0, d = 0, url_len = 0; int s = 0, d = 0, url_len = 0;
char c; char c;
@ -74,7 +74,7 @@ char *ff_urldecode(const char *url)
dest[d++] = c2; dest[d++] = c2;
dest[d++] = c3; dest[d++] = c3;
} }
} else if (c == '+') { } else if (c == '+' && decode_plus_sign) {
dest[d++] = ' '; dest[d++] = ' ';
} else { } else {
dest[d++] = c; dest[d++] = c;

View File

@ -26,10 +26,11 @@
* in that case the original string is duplicated. * in that case the original string is duplicated.
* *
* @param url a string to be decoded. * @param url a string to be decoded.
* @param decode_plus_sign if nonzero plus sign is decoded to space
* @return new string with the URL decoded or NULL if decoding failed. * @return new string with the URL decoded or NULL if decoding failed.
* Note that the returned string should be explicitly freed when not * Note that the returned string should be explicitly freed when not
* used anymore. * used anymore.
*/ */
char *ff_urldecode(const char *url); char *ff_urldecode(const char *url, int decode_plus_sign);
#endif /* AVFORMAT_URLDECODE_H */ #endif /* AVFORMAT_URLDECODE_H */