Decodes percent-encoded byte string |value| with length |valuelen| and returns the decoded byte string in allocated buffer. The return value is NULL terminated. The caller must free the returned string. */
| 363 | value is NULL terminated. The caller must free the returned |
| 364 | string. */ |
| 365 | static char *percent_decode(const uint8_t *value, size_t valuelen) { |
| 366 | char *res; |
| 367 | |
| 368 | res = malloc(valuelen + 1); |
| 369 | if (valuelen > 3) { |
| 370 | size_t i, j; |
| 371 | for (i = 0, j = 0; i < valuelen - 2;) { |
| 372 | if (value[i] != '%' || !isxdigit(value[i + 1]) || |
| 373 | !isxdigit(value[i + 2])) { |
| 374 | res[j++] = (char)value[i++]; |
| 375 | continue; |
| 376 | } |
| 377 | res[j++] = |
| 378 | (char)((hex_to_uint(value[i + 1]) << 4) + hex_to_uint(value[i + 2])); |
| 379 | i += 3; |
| 380 | } |
| 381 | memcpy(&res[j], &value[i], 2); |
| 382 | res[j + 2] = '\0'; |
| 383 | } else { |
| 384 | memcpy(res, value, valuelen); |
| 385 | res[valuelen] = '\0'; |
| 386 | } |
| 387 | return res; |
| 388 | } |
| 389 | |
| 390 | /* a callback of type "nghttp2_data_source_read_callback2" */ |
| 391 | static nghttp2_ssize file_read_callback(nghttp2_session *session, |
no test coverage detected