From 8babf8b26e23ffdd8094c810295061effde153dd Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 23 Nov 2020 22:19:54 +0100 Subject: Fixed some XML/HTML parsing bugs --- apps/browser.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'apps') diff --git a/apps/browser.c b/apps/browser.c index 0b53797..7f4fc6e 100644 --- a/apps/browser.c +++ b/apps/browser.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -63,7 +64,7 @@ void parse(void *data, u32 len, char *out) enum xml_error err = xml_parse(&parser, buffer, len, tokens, 128); if (err != XML_SUCCESS) { - printf("XML parse error: %d\n", err); + printf("\nXML parse error: %d\n", err); return; } @@ -74,10 +75,13 @@ void parse(void *data, u32 len, char *out) name[0] = '\0'; switch (token->type) { case XML_START_TAG: - print_indent(out, indent++); memcpy(&name, (u8 *)buffer + token->start_pos, token->end_pos - token->start_pos); name[token->end_pos - token->start_pos] = '\0'; + if (html_self_closing(name)) + print_indent(out, indent); + else + print_indent(out, indent++); strcat(out, name); strcat(out, "\n"); break; @@ -108,12 +112,12 @@ void parse(void *data, u32 len, char *out) break; } } - if (strlen(clean_name)) { - print_indent(out, indent++); - strcat(out, clean_name); - strcat(out, "\n"); - indent--; - } + if (!strlen(clean_name)) + break; + print_indent(out, indent++); + strcat(out, clean_name); + strcat(out, "\n"); + indent--; break; default: break; @@ -144,7 +148,7 @@ void on_submit(void *event, struct element *box) struct element_label *c = code_label->data; struct socket *socket = net_open(S_TCP); - if (socket && net_connect(socket, ip, 8000)) { + if (socket && net_connect(socket, ip, 80)) { net_send(socket, query, strlen(query)); char buf[4096] = { 0 }; char parsed[4096] = { 0 }; -- cgit v1.2.3