| 35 | #include "urldecode.h" |
| 36 | |
| 37 | static size_t urldecode(char *dest, const char *url, size_t url_len, int decode_plus_sign) |
| 38 | { |
| 39 | size_t s = 0, d = 0; |
| 40 | char c; |
| 41 | |
| 42 | while (s < url_len) { |
| 43 | c = url[s++]; |
| 44 | |
| 45 | if (c == '%' && s + 1 < url_len) { |
| 46 | char c2 = url[s++]; |
| 47 | char c3 = url[s++]; |
| 48 | if (av_isxdigit(c2) && av_isxdigit(c3)) { |
| 49 | c2 = av_tolower(c2); |
| 50 | c3 = av_tolower(c3); |
| 51 | |
| 52 | if (c2 <= '9') |
| 53 | c2 = c2 - '0'; |
| 54 | else |
| 55 | c2 = c2 - 'a' + 10; |
| 56 | |
| 57 | if (c3 <= '9') |
| 58 | c3 = c3 - '0'; |
| 59 | else |
| 60 | c3 = c3 - 'a' + 10; |
| 61 | |
| 62 | dest[d++] = 16 * c2 + c3; |
| 63 | |
| 64 | } else { /* %zz or something other invalid */ |
| 65 | dest[d++] = c; |
| 66 | dest[d++] = c2; |
| 67 | dest[d++] = c3; |
| 68 | } |
| 69 | } else if (c == '+' && decode_plus_sign) { |
| 70 | dest[d++] = ' '; |
| 71 | } else { |
| 72 | dest[d++] = c; |
| 73 | } |
| 74 | |
| 75 | } |
| 76 | |
| 77 | return d; |
| 78 | } |
| 79 | |
| 80 | char *ff_urldecode(const char *url, int decode_plus_sign) |
| 81 | { |
no test coverage detected