Add helper function for percent encoding

This commit is contained in:
Timo Ley 2022-06-26 19:05:36 +02:00
parent 23c2911ce0
commit a52cc51ed8
2 changed files with 16 additions and 0 deletions

View file

@ -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

View file

@ -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);
}