-
Notifications
You must be signed in to change notification settings - Fork 0
/
coder.c
55 lines (36 loc) · 765 Bytes
/
coder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "coder.h"
#include "helper.h"
#include "string.h"
listtable* parseQueries(listtable* tbl, const char* query, char equalchar, char sepchar, int* count) {
if (tbl == NULL && (tbl = listTable(0)) == NULL) {
return NULL;
}
if (query == NULL) {
return tbl;
}
int cnt = 0;
char* newquery = strdup(query);
while (newquery && *newquery) {
char* value = makeword(newquery, sepchar);
char* name = strTrim(makeword(value, equalchar));
urlDecode(name);
urlDecode(value);
if (tbl->putstr(tbl, name, value) == true) {
cnt++;
}
free(name);
free(value);
}
if (count != NULL) {
*count = cnt;
}
free(newquery);
return tbl;
}