38#include "utilities/qstring.h"
39#include "utilities/qencode.h"
62qlisttbl_t *
qparse_queries(qlisttbl_t *tbl,
const char *query,
char equalchar,
63 char sepchar,
int *count) {
64 if (tbl == NULL && (tbl =
qlisttbl(0)) == NULL) {
73 char *newquery = strdup(query);
74 while (newquery && *newquery) {
75 char *value = _q_makeword(newquery, sepchar);
76 char *name =
qstrtrim(_q_makeword(value, equalchar));
80 if (tbl->putstr(tbl, name, value) ==
true) {
126 const char URLCHARTBL[16*16] = {
127 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
128 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
129 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
'-',
'.',
'/',
130 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':', 0 , 0 , 0 , 0 , 0 ,
131 '@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
132 'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z', 0 ,
'\\',0 , 0 ,
'_',
133 00 ,
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
134 'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z', 0 , 0 , 0 , 0 , 0 ,
135 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
136 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
137 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
138 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
139 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
140 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
141 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
142 00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
151 char *pszEncStr = (
char *) malloc((size * 3) + 1);
152 if (pszEncStr == NULL)
155 char *pszEncPt = pszEncStr;
156 char *pBinPt = (
char *) bin;
157 const char *pBinEnd = (bin + size - 1);
158 for (; pBinPt <= pBinEnd; pBinPt++) {
159 unsigned char c = *pBinPt;
160 if (URLCHARTBL[c] != 0) {
161 *pszEncPt++ = *pBinPt;
163 unsigned char cUpper4 = (c >> 4);
164 unsigned char cLower4 = (c & 0x0F);
169 (cUpper4 +
'0') : ((cUpper4 - 0x0A) +
'a');
172 (cLower4 +
'0') : ((cLower4 - 0x0A) +
'a');
197 char *pEncPt, *pBinPt = str;
198 for (pEncPt = str; *pEncPt !=
'\0'; pEncPt++) {
205 *pBinPt++ = _q_x2c(*(pEncPt + 1), *(pEncPt + 2));
217 return (pBinPt - str);
250 const char B64CHARTBL[64] = {
251 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
252 'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'a',
'b',
'c',
'd',
'e',
'f',
253 'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
254 'w',
'x',
'y',
'z',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'+',
'/'
262 char *pszB64 = (
char *) malloc(
263 4 * ((size / 3) + ((size % 3 == 0) ? 0 : 1)) + 1);
264 if (pszB64 == NULL) {
268 char *pszB64Pt = pszB64;
269 unsigned char *pBinPt, *pBinEnd = (
unsigned char *) (bin + size - 1);
270 unsigned char szIn[3] = { 0, 0, 0 };
272 for (pBinPt = (
unsigned char *) bin, nOffset = 0; pBinPt <= pBinEnd;
273 pBinPt++, nOffset++) {
274 int nIdxOfThree = nOffset % 3;
275 szIn[nIdxOfThree] = *pBinPt;
276 if (nIdxOfThree < 2 && pBinPt < pBinEnd)
279 *pszB64Pt++ = B64CHARTBL[((szIn[0] & 0xFC) >> 2)];
280 *pszB64Pt++ = B64CHARTBL[(((szIn[0] & 0x03) << 4)
281 | ((szIn[1] & 0xF0) >> 4))];
284 B64CHARTBL[(((szIn[1] & 0x0F) << 2)
285 | ((szIn[2] & 0xC0) >> 6))] :
287 *pszB64Pt++ = (nIdxOfThree >= 2) ? B64CHARTBL[(szIn[2] & 0x3F)] :
'=';
289 memset((
void *) szIn, 0,
sizeof(szIn));
309 const char B64MAPTBL[16 * 16] = {
310 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
311 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
312 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
313 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
314 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
315 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
316 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
317 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
318 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
319 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
320 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
321 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
322 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
323 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
324 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
325 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
328 char *pEncPt, *pBinPt = str;
331 for (pEncPt = str; *pEncPt !=
'\0'; pEncPt++) {
332 char cByte = B64MAPTBL[(
unsigned char) (*pEncPt)];
336 if (nIdxOfFour == 0) {
338 }
else if (nIdxOfFour == 1) {
341 *pBinPt++ = ((cLastByte << 2) | (cByte >> 4));
343 }
else if (nIdxOfFour == 2) {
346 *pBinPt++ = ((cLastByte << 4) | (cByte >> 2));
351 *pBinPt++ = ((cLastByte << 6) | cByte);
359 return (pBinPt - str);
394 const char HEXCHARTBL[16] = {
395 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
398 char *pHexStr = (
char *) malloc(
sizeof(
char) * ((size * 2) + 1));
402 unsigned char *pSrc = (
unsigned char *) bin;
403 char *pHexPt = pHexStr;
405 for (i = 0; i < size; i++) {
406 *pHexPt++ = HEXCHARTBL[(pSrc[i] >> 4)];
407 *pHexPt++ = HEXCHARTBL[(pSrc[i] & 0x0F)];
427 const char HEXMAPTBL[16*16] = {
428 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
429 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
430 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
431 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
432 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
433 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
434 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
435 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
436 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
437 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
438 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
439 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
440 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
441 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
442 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
443 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
446 char *pEncPt, *pBinPt = str;
447 for (pEncPt = str; *pEncPt !=
'\0'; pEncPt += 2) {
448 *pBinPt++ = (HEXMAPTBL[(
unsigned char) (*pEncPt)] << 4)
449 + HEXMAPTBL[(
unsigned char) (*(pEncPt + 1))];
453 return (pBinPt - str);
size_t qbase64_decode(char *str)
Decode BASE64 encoded string.
char * qurl_encode(const void *bin, size_t size)
Encode data using URL encoding(Percent encoding) algorithm.
char * qbase64_encode(const void *bin, size_t size)
Encode data using BASE64 algorithm.
qlisttbl_t * qparse_queries(qlisttbl_t *tbl, const char *query, char equalchar, char sepchar, int *count)
Parse URL encoded query string.
size_t qhex_decode(char *str)
Decode Hexadecimal encoded data.
size_t qurl_decode(char *str)
Decode URL encoded string.
char * qhex_encode(const void *bin, size_t size)
Encode data to Hexadecimal digit format.
qlisttbl_t * qlisttbl(int options)
Create a new Q_LIST linked-list container.
char * qstrtrim(char *str)
Remove white spaces(including CR, LF) from head and tail of the string.