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
50
51
52
53
54
55
56
57
58
59
|
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <fhp/fhp.h>
#define UNUSED(a) ((void) (a))
static const char *
str_test_basic =
"GET / HTTP/1.1\r\n"
"Host: pablotron.org\r\n"
"Connection: close\r\n"
"\r\n";
static bool
test_basic_cb(
fhp_t *fhp,
fhp_token_t token,
uint8_t * const buf,
size_t len
) {
UNUSED(fhp);
UNUSED(buf);
fprintf(stderr, "test_basic_cb(): token = %u, len = %lu\n", token, len);
// return success
return true;
}
static void
test_basic(void) {
char buf[1024];
fhp_err_t err;
fhp_t fhp;
if ((err = fhp_init(&fhp, test_basic_cb, NULL)) != FHP_OK) {
fhp_strerror(err, buf, sizeof(buf));
fprintf(stderr, "ERROR: fhp_init(): %s\n", buf);
exit(EXIT_FAILURE);
}
size_t len = strlen(str_test_basic);
if ((err = fhp_push(&fhp, (uint8_t*) str_test_basic, len)) != FHP_OK) {
fhp_strerror(err, buf, sizeof(buf));
fprintf(stderr, "ERROR: fhp_push(): %s\n", buf);
exit(EXIT_FAILURE);
}
}
int main(int argc, char *argv[]) {
UNUSED(argc);
UNUSED(argv);
test_basic();
return EXIT_SUCCESS;
}
|