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 URL encoded query string.
|
|
char * | qurl_encode (const void *bin, size_t size) |
| Encode data using URL encoding(Percent encoding) algorithm.
|
|
size_t | qurl_decode (char *str) |
| Decode URL encoded string.
|
|
char * | qbase64_encode (const void *bin, size_t size) |
| Encode data using BASE64 algorithm.
|
|
size_t | qbase64_decode (char *str) |
| Decode BASE64 encoded string.
|
|
char * | qhex_encode (const void *bin, size_t size) |
| Encode data to Hexadecimal digit format.
|
|
size_t | qhex_decode (char *str) |
| Decode Hexadecimal encoded 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 URL encoded query string.
- Parameters
-
tbl | a pointer of qlisttbl_t container. NULL can be used to create new table. |
query | URL encoded string. |
equalchar | separater of key, value pair. |
sepchar | separater of line. |
count | if count is not NULL, a number of parsed entries are stored. |
- Returns
- qlisttbl container pointer, otherwise returns NULL.
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 URL encoded query string.
Definition at line 62 of file qencode.c.
◆ qurl_encode()
char * qurl_encode |
( |
const void * |
bin, |
|
|
size_t |
size |
|
) |
| |
Encode data using URL encoding(Percent encoding) algorithm.
- Parameters
-
bin | a pointer of input data. |
size | the length of input data. |
- Returns
- a malloced string pointer of URL encoded string in case of successful, otherwise returns NULL
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) algorithm.
size_t qurl_decode(char *str)
Decode URL encoded string.
Definition at line 125 of file qencode.c.
◆ qurl_decode()
size_t qurl_decode |
( |
char * |
str | ) |
|
Decode URL encoded string.
- Parameters
-
str | a pointer of URL encoded string. |
- Returns
- the length of bytes stored in the str memory in case of successful, otherwise returns NULL
- Note
- This modify str directly. And the 'str' is always terminated by NULL character.
Definition at line 192 of file qencode.c.
◆ qbase64_encode()
char * qbase64_encode |
( |
const void * |
bin, |
|
|
size_t |
size |
|
) |
| |
Encode data using BASE64 algorithm.
- Parameters
-
bin | a pointer of input data. |
size | the length of input data. |
- Returns
- a malloced string pointer of BASE64 encoded string in case of successful, otherwise returns NULL
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 BASE64 encoded string.
char * qbase64_encode(const void *bin, size_t size)
Encode data using BASE64 algorithm.
Definition at line 249 of file qencode.c.
◆ qbase64_decode()
size_t qbase64_decode |
( |
char * |
str | ) |
|
Decode BASE64 encoded string.
- Parameters
-
str | a pointer of Base64 encoded string. |
- Returns
- the length of bytes stored in the str memory in case of successful, otherwise returns NULL
- Note
- This modify str directly. And the 'str' is always terminated by NULL character.
Definition at line 308 of file qencode.c.
◆ qhex_encode()
char * qhex_encode |
( |
const void * |
bin, |
|
|
size_t |
size |
|
) |
| |
Encode data to Hexadecimal digit format.
- Parameters
-
bin | a pointer of input data. |
size | the length of input data. |
- Returns
- a malloced string pointer of Hexadecimal encoded string in case of successful, otherwise returns NULL
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 encoded data.
char * qhex_encode(const void *bin, size_t size)
Encode data to Hexadecimal digit format.
Definition at line 393 of file qencode.c.
◆ qhex_decode()
size_t qhex_decode |
( |
char * |
str | ) |
|
Decode Hexadecimal encoded data.
- Parameters
-
str | a pointer of Hexadecimal encoded string. |
- Returns
- the length of bytes stored in the str memory in case of successful, otherwise returns NULL
- Note
- This modify str directly. And the 'str' is always terminated by NULL character.
Definition at line 426 of file qencode.c.