diff --git a/httplib.h b/httplib.h index ab66dc8..cd9fca4 100644 --- a/httplib.h +++ b/httplib.h @@ -114,6 +114,14 @@ char * httplib_request_get_query_value(http_request * self, char * key); */ int httplib_is_valid_header(const char * key, const char * value); +/** + * Helper function to decode a percent encoded character. + * @param encoded a pointer to the first of the two characters in the string + * after the percent symbol, which make up the encoded character + * @return the decoded character + */ +char httplib_decode_hex(const char * encoded); + #define SOCKET_ERROR -1 #define BIND_ERROR -2 #define LISTEN_ERROR -3 diff --git a/httputil.c b/httputil.c index 1743df7..4a9800e 100644 --- a/httputil.c +++ b/httputil.c @@ -167,4 +167,12 @@ void httplib_tmp_increase(struct tmp * tmp) { void httplib_tmp_reset(struct tmp * tmp) { tmp->pos = 0; bzero(tmp->buf, tmp->size); +} + +char httplib_decode_hex(const char * encoded) { + char input[3]; + input[0] = encoded[0]; + input[1] = encoded[1]; + input[2] = '\0'; + return (char) strtoul(input, 0, 16); } \ No newline at end of file