* Escape unsafe characters in path in order to pass them safely to the HTTP * request. Insipred by the algorithm in GNU wget: * - escape "%" characters not followed by two hex digits * - escape all "unsafe" characters except which are also "reserved" * - pass through everything else */
| 1501 | * - pass through everything else |
| 1502 | */ |
| 1503 | static void bprint_escaped_path(AVBPrint *bp, const char *path) |
| 1504 | { |
| 1505 | #define NEEDS_ESCAPE(ch) \ |
| 1506 | ((ch) <= ' ' || (ch) >= '\x7f' || \ |
| 1507 | (ch) == '"' || (ch) == '%' || (ch) == '<' || (ch) == '>' || (ch) == '\\' || \ |
| 1508 | (ch) == '^' || (ch) == '`' || (ch) == '{' || (ch) == '}' || (ch) == '|') |
| 1509 | while (*path) { |
| 1510 | char buf[1024]; |
| 1511 | char *q = buf; |
| 1512 | while (*path && q - buf < sizeof(buf) - 4) { |
| 1513 | if (path[0] == '%' && av_isxdigit(path[1]) && av_isxdigit(path[2])) { |
| 1514 | *q++ = *path++; |
| 1515 | *q++ = *path++; |
| 1516 | *q++ = *path++; |
| 1517 | } else if (NEEDS_ESCAPE(*path)) { |
| 1518 | q += snprintf(q, 4, "%%%02X", (uint8_t)*path++); |
| 1519 | } else { |
| 1520 | *q++ = *path++; |
| 1521 | } |
| 1522 | } |
| 1523 | av_bprint_append_data(bp, buf, q - buf); |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | static int http_connect(URLContext *h, const char *path, const char *local_path, |
| 1528 | const char *hoststr, const char *auth, |
no test coverage detected