Encoding/decoding APIs.
More...
Go to the source code of this file.
|
| qlisttbl_t * | qparse_queries (qlisttbl_t *tbl, const char *query, char equalchar, char sepchar, int *count) |
| | Parse a URL-encoded query string.
|
| char * | qurl_encode (const void *bin, size_t size) |
| | Encode data using URL encoding (percent encoding).
|
| size_t | qurl_decode (char *str) |
| | Decode a URL-encoded string.
|
| char * | qbase64_encode (const void *bin, size_t size) |
| | Encode data using BASE64.
|
| size_t | qbase64_decode (char *str) |
| | Decode a BASE64 string.
|
| char * | qhex_encode (const void *bin, size_t size) |
| | Encode data as hexadecimal digits.
|
| size_t | qhex_decode (char *str) |
| | Decode hexadecimal data.
|
Encoding/decoding APIs.
Definition in file qencode.c.
◆ qparse_queries()
| qlisttbl_t * qparse_queries |
( |
qlisttbl_t * | tbl, |
|
|
const char * | query, |
|
|
char | equalchar, |
|
|
char | sepchar, |
|
|
int * | count ) |
Parse a URL-encoded query string.
- Parameters
-
| tbl | qlisttbl_t pointer. If NULL, a new table is created. |
| query | URL-encoded string |
| equalchar | separator between key and value |
| sepchar | separator between entries |
| count | number of parsed entries is stored here if not NULL |
- Returns
- qlisttbl_t pointer on success, or NULL on failure.
cont char query = "category=love&str=%C5%A5%B5%F0%C4%DA%B4%F5&sort=asc";
qlisttbl_t *tbl =
qparse_queries(NULL, req->pszQueryString,
'=',
'&', NULL);
printf("category = %s\n", tbl->get_str(tbl, "category", false));
printf("str = %s\n", tbl->get_str(tbl, "str", false));
printf("sort = %s\n", tbl->get_str(tbl, "sort", false));
tbl->free(tbl);
qlisttbl_t * qparse_queries(qlisttbl_t *tbl, const char *query, char equalchar, char sepchar, int *count)
Parse a URL-encoded query string.
Definition at line 61 of file qencode.c.
◆ qurl_encode()
| char * qurl_encode |
( |
const void * | bin, |
|
|
size_t | size ) |
Encode data using URL encoding (percent encoding).
- Parameters
-
| bin | input data |
| size | length of the input data |
- Returns
- allocated URL-encoded string on success, or NULL on failure.
const char *text = "hello 'qLibc' world";
if(encstr == NULL) return -1;
printf("Original: %s\n", text);
printf("Encoded : %s\n", encstr);
printf("Decoded : %s (%zu bytes)\n", encstr, decsize);
free(encstr);
--[output]--
Original: hello 'qLibc' world
Encoded: hello%20%27qLibc%27%20world
Decoded: hello 'qLibc' world (19 bytes)
char * qurl_encode(const void *bin, size_t size)
Encode data using URL encoding (percent encoding).
size_t qurl_decode(char *str)
Decode a URL-encoded string.
Definition at line 123 of file qencode.c.
◆ qurl_decode()
| size_t qurl_decode |
( |
char * | str | ) |
|
Decode a URL-encoded string.
- Parameters
-
- Returns
- number of bytes stored in str.
- Note
- This function modifies str in place. The result is always null-terminated.
Definition at line 188 of file qencode.c.
◆ qbase64_encode()
| char * qbase64_encode |
( |
const void * | bin, |
|
|
size_t | size ) |
Encode data using BASE64.
- Parameters
-
| bin | input data |
| size | length of the input data |
- Returns
- allocated BASE64 string on success, or NULL on failure.
const char *text = "hello world";
if(encstr == NULL) return -1;
printf("Original: %s\n", text);
printf("Encoded : %s\n", encstr);
printf("Decoded : %s (%zu bytes)\n", encstr, decsize);
free(encstr);
--[output]--
Original: hello world
Encoded: aGVsbG8gd29ybGQ=
Decoded: hello world (11 bytes)
size_t qbase64_decode(char *str)
Decode a BASE64 string.
char * qbase64_encode(const void *bin, size_t size)
Encode data using BASE64.
Definition at line 244 of file qencode.c.
◆ qbase64_decode()
| size_t qbase64_decode |
( |
char * | str | ) |
|
Decode a BASE64 string.
- Parameters
-
- Returns
- number of bytes stored in str.
- Note
- This function modifies str in place. The result is always null-terminated.
Definition at line 301 of file qencode.c.
◆ qhex_encode()
| char * qhex_encode |
( |
const void * | bin, |
|
|
size_t | size ) |
Encode data as hexadecimal digits.
- Parameters
-
| bin | input data |
| size | length of the input data |
- Returns
- allocated hexadecimal string on success, or NULL on failure.
const char *text = "hello world";
if(encstr == NULL) return -1;
printf("Original: %s\n", text);
printf("Encoded : %s\n", encstr);
printf("Decoded : %s (%zu bytes)\n", encstr, decsize);
free(encstr);
return 0;
--[output]--
Original: hello world
Encoded : 68656c6c6f20776f726c64
Decoded : hello world (11 bytes)
size_t qhex_decode(char *str)
Decode hexadecimal data.
char * qhex_encode(const void *bin, size_t size)
Encode data as hexadecimal digits.
Definition at line 385 of file qencode.c.
◆ qhex_decode()
| size_t qhex_decode |
( |
char * | str | ) |
|
Decode hexadecimal data.
- Parameters
-
| str | hexadecimal-encoded string |
- Returns
- number of bytes stored in str.
- Note
- This function modifies str in place. The result is always null-terminated.
Definition at line 416 of file qencode.c.