commit f6120e0535c0dddb1261c725bbfd00b49d1dfbbf
parent 936a5b7a2eb4a3de6a61a9be4b30fb8f1a354e55
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Tue, 23 Sep 2025 15:56:33 +0100
cleanned up http handling and started work on html parsing
Diffstat:
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/cmd/lav/lav.ha b/cmd/lav/lav.ha
@@ -6,6 +6,8 @@ use net;
use net::dial;
use net::uri;
use encoding::utf8;
+use format::xml;
+use memio;
use http;
@@ -25,14 +27,28 @@ export fn main() void = {
defer io::close(sock)!;
let res = http::get(sock, "/")!;
- let response = match(http::parseres(res)) {
+ let html = "";
+
+ let response = match(http::parseres(res, &html)) {
case let r: http::response => yield r;
case => fmt::fatal("failed to parse response");
};
defer (http::freeres(&response));
+ let f = memio::dynamic_from(strings::toutf8(html));
+
+ let par = match (xml::parse(&f.stream)) {
+ case let p: xml::parser => yield &p;
+ case let e: xml::error => fmt::fatalf("{}", xml::strerror(e));
+ };
+ defer xml::parser_finish(par);
- fmt::printfln("{}", response.status)!;
- for (let attribute .. response.attributes) {
- fmt::printfln("{}: {}", attribute[0], attribute[1])!;
+ for (let i = 0z; i < 10; i += 1) {
+ match(xml::scan(par)) {
+ case let tok: xml::elementstart => fmt::printf("<{}>", tok)!;
+ case let tok: xml::elementend => fmt::printf("</{}>", tok)!;
+ case let tok: xml::text => fmt::printf("{}", tok)!;
+ case let attr: xml::attribute => fmt::printf("({} {})\n", attr.0, attr.1)!;
+ case => yield;
+ };
};
};
diff --git a/http/http.ha b/http/http.ha
@@ -36,7 +36,7 @@ export fn freeres(res: *response) void = {
};
};
-export fn parseres(res: str) (response | invalid) = {
+export fn parseres(res: str, html: *str) (response | invalid) = {
let header = strings::index(res, "\r\n\r\n") as size;
let lines = strings::split(strings::sub(res, 0, header), "\r\n")!;
defer free(lines);
@@ -74,5 +74,6 @@ export fn parseres(res: str) (response | invalid) = {
free(split);
};
+ *html = strings::sub(res, header + 4, strings::end);
return response;
};
diff --git a/lav b/lav
Binary files differ.