| 303 | static char *web_json_get_string(const char *json, const char *key); |
| 304 | |
| 305 | static char *web_url_encode(const char *s) { |
| 306 | static const char hex[] = "0123456789ABCDEF"; |
| 307 | web_buf b = {0}; |
| 308 | for (const unsigned char *p = (const unsigned char *)s; p && *p; p++) { |
| 309 | unsigned char c = *p; |
| 310 | if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { |
| 311 | web_buf_append(&b, (const char *)&c, 1); |
| 312 | } else { |
| 313 | char e[3] = {'%', hex[c >> 4], hex[c & 15]}; |
| 314 | web_buf_append(&b, e, 3); |
| 315 | } |
| 316 | } |
| 317 | return web_buf_take(&b); |
| 318 | } |
| 319 | |
| 320 | static void web_random_bytes(unsigned char *buf, size_t len) { |
| 321 | int fd = open("/dev/urandom", O_RDONLY); |
no test coverage detected