2
0
Fork 0
lighttpd2/src/main/tests.c

59 lines
1.1 KiB
C
Raw Normal View History

2008-07-08 16:51:03 +00:00
#include <stdio.h>
#include <lighttpd/base.h>
#include <lighttpd/config_parser.h>
int request_test() {
liChunkQueue *cq;
liRequest req;
liHandlerResult res;
2009-07-09 20:17:24 +00:00
cq = li_chunkqueue_new();
li_request_init(&req, cq);
2009-07-09 20:17:24 +00:00
li_chunkqueue_append_mem(cq, CONST_STR_LEN(
"GET / HTTP/1.1\r\n"
2008-08-04 22:25:42 +00:00
"Host: www.example.com\r\n"
"\r\n"
2008-08-04 22:25:42 +00:00
"abc"
));
2009-07-09 20:17:24 +00:00
res = li_http_request_parse(NULL, NULL, &req.parser_ctx);
if (res != LI_HANDLER_GO_ON) {
fprintf(stderr, "Parser return %i", res);
}
assert(req.http_method == LI_HTTP_METHOD_GET);
2008-08-04 22:25:42 +00:00
assert(cq->length == 3);
2009-07-09 20:17:24 +00:00
li_request_clear(&req);
li_chunkqueue_free(cq);
2008-08-04 22:25:42 +00:00
return res == LI_HANDLER_GO_ON ? 0 : 1;
}
int main() {
liServer *srv;
2008-07-08 16:51:03 +00:00
2008-07-25 20:38:42 +00:00
guint32 ip, netmask;
2009-07-09 20:17:24 +00:00
assert(li_parse_ipv4("10.0.3.8/24", &ip, &netmask, NULL));
2008-07-25 20:38:42 +00:00
printf("parsed ip: %s\n", inet_ntoa(*(struct in_addr*) &ip));
printf("parsed netmask: %s\n", inet_ntoa(*(struct in_addr*) &netmask));
guint8 ipv6[16];
guint network;
GString *s;
2009-07-09 20:17:24 +00:00
assert(li_parse_ipv6("::ffff:192.168.0.1/80", ipv6, &network, NULL));
s = li_ipv6_tostring(ipv6);
2008-07-25 20:38:42 +00:00
printf("parsed ipv6: %s/%u\n", s->str, network);
2008-08-04 22:25:42 +00:00
request_test();
2008-07-25 20:38:42 +00:00
return 0;
2009-07-09 20:17:24 +00:00
srv = li_server_new();
2008-08-04 22:25:42 +00:00
return 0;
}