From def0cfce51794a243814c8e5ca68033177e64382 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Sun, 29 Oct 2017 19:34:34 +0100 Subject: Remove from poll on abort. Fix loglevels --- content/fetchers/httplib_kolibri.c | 91 +++++++++++++++----------------------- 1 file changed, 35 insertions(+), 56 deletions(-) (limited to 'content/fetchers/httplib_kolibri.c') diff --git a/content/fetchers/httplib_kolibri.c b/content/fetchers/httplib_kolibri.c index 9036ee28e..efeb5a924 100644 --- a/content/fetchers/httplib_kolibri.c +++ b/content/fetchers/httplib_kolibri.c @@ -25,47 +25,42 @@ struct httpfetcher { struct httpfetcher *next; }; -struct httpfetcher *head = NULL; +static struct httpfetcher *head = NULL; -void add_to_poll(struct httpfetcher *newfetcher) { +static void add_to_poll(struct httpfetcher *newfetcher) { - NSLOG(fetch, ERROR, "(head:0x%x) newfetcher 0x%x, newfetcher->handle 0x%x", head, newfetcher, newfetcher->handle); + NSLOG(fetch, DEBUG, "(head:0x%x) newfetcher 0x%x, newfetcher->handle 0x%x", head, newfetcher, newfetcher->handle); struct httpfetcher *t = head; while(t) { - NSLOG(fetch, ERROR, "ll node = 0x%x", t); + NSLOG(fetch, DEBUG, "ll node = 0x%x, ->next 0x%x", t, t->next); t=t->next; } if(head == NULL) { head = newfetcher; assert(head->next == NULL); - NSLOG(fetch, ERROR, "(head:0x%x) ADDED newfetcher 0x%x, newfetcher->handle 0x%x", head, head, head->handle); + NSLOG(fetch, DEBUG, "(head:0x%x) ADDED newfetcher 0x%x, newfetcher->handle 0x%x", head, head, head->handle); } else { t = head; while(t->next != NULL) { - NSLOG(fetch, ERROR, "-- Looping t 0x%x, t->handle 0x%x", t->next, t->next->handle); + NSLOG(fetch, DEBUG, "-- Looping t 0x%x, t->handle 0x%x", t->next, t->next->handle); t = t->next; } t->next = newfetcher; - NSLOG(fetch, ERROR, "(head:0x%x) ADDED newfetcher 0x%x, newfetcher->handle 0x%x, nn 0x%x", head, t->next, t->next->handle, t->next->next); + NSLOG(fetch, DEBUG, "(head:0x%x) ADDED newfetcher 0x%x, newfetcher->handle 0x%x, nn 0x%x", head, t->next, t->next->handle, t->next->next); } - struct httpfetcher *xx = head; - while(xx) { - NSLOG(fetch, ERROR, "ll node = 0x%x", xx); - xx=xx->next; - } } -struct httpfetcher* remove_from_poll(struct httpfetcher *removee) { +static struct httpfetcher* remove_from_poll(struct httpfetcher *removee) { struct httpfetcher *t = head, *p = head; - NSLOG(fetch, ERROR, "(head=0x%x), remove: 0x%x , removee->handle: 0x%x", head, removee, removee->handle); + NSLOG(fetch, DEBUG, "(head=0x%x), remove: 0x%x , removee->handle: 0x%x", head, removee, removee->handle); while(t) { - NSLOG(fetch, ERROR, "BEFORE REMOVE ll node = 0x%x", t); + NSLOG(fetch, DEBUG, "BEFORE REMOVE ll node = 0x%x, next 0x%x", t, t->next); t=t->next; } @@ -76,21 +71,11 @@ struct httpfetcher* remove_from_poll(struct httpfetcher *removee) { p = t->next; head = p; - struct httpfetcher *xx = head; - while(xx) { - NSLOG(fetch, ERROR, "ll node = 0x%x", xx); - xx=xx->next; - } return head; break; } else { p->next = t->next; - struct httpfetcher *xx = head; - while(xx) { - NSLOG(fetch, ERROR, "ll node = 0x%x", xx); - xx=xx->next; - } return t->next; break; } @@ -103,27 +88,27 @@ struct httpfetcher* remove_from_poll(struct httpfetcher *removee) { return head; } -bool init_fetcher(lwc_string *scheme) { +static bool init_fetcher(lwc_string *scheme) { bool supported_scheme; assert(lwc_string_isequal(scheme, corestring_lwc_http, &supported_scheme) == lwc_error_ok); - NSLOG(fetch, DEBUG, "Initializing http library!"); + NSLOG(fetch, INFO, "Initializing http library!"); debug_board_printf("---- [NETSURF] Trying to initialize http library.\n"); + if(kolibri_http_init() == 0) { - NSLOG(fetch, DEBUG, "[INFO] Loaded http.obj library successfully.\n"); + NSLOG(fetch, INFO, "[INFO] Loaded http.obj library successfully.\n"); debug_board_printf("---- [NETSURF] Successfully initialized http library.\n"); } else { - NSLOG(fetch, ERROR, "[ERROR] Could not load http.obj library.\n"); + NSLOG(fetch, ERROR, "Could not load http.obj library.\n"); debug_board_printf("---- [NETSURF] Could not initialize http library. Exiting.\n"); - assert(0 && 1); return false; } return supported_scheme; } -bool supported_url_check(const struct nsurl *url) { +static bool supported_url_check(const struct nsurl *url) { bool supported; lwc_string *url_scheme = nsurl_get_component(url, NSURL_SCHEME); assert(lwc_string_isequal(url_scheme, corestring_lwc_http, &supported) == lwc_error_ok); @@ -131,7 +116,7 @@ bool supported_url_check(const struct nsurl *url) { return supported; } -void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, +static void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, bool only_2xx, bool downgrade_tls, const char *post_urlenc, const struct fetch_multipart_data *post_multipart, const char **headers) { @@ -293,41 +278,42 @@ void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, return newfetcher; } -bool start_fetch(void *httpf) { +static bool start_fetch(void *httpf) { assert(((struct httpfetcher *)httpf)->owner != NULL); - NSLOG(fetch, ERROR, "httpf: 0x%x", httpf); - add_to_poll((struct httpfetcher *) httpf); + NSLOG(fetch, DEBUG, "httpf: 0x%x", httpf); + add_to_poll((struct httpfetcher *) httpf); struct httpfetcher *wrapper = httpf; assert(((struct httpfetcher *)httpf)->owner != NULL); - NSLOG(fetch, ERROR, "END OF add_to_poll: httpf: 0x%x, httpf->handle 0x%x, httpf->next 0x%x", wrapper, wrapper->handle, *wrapper ); + NSLOG(fetch, DEBUG, "END OF add_to_poll: httpf: 0x%x, httpf->handle 0x%x, httpf->next 0x%x", wrapper, wrapper->handle, wrapper->next); return true; } -bool abort_fetch(void *httpf) { - NSLOG(fetch, ERROR, "aborting fetch 0x%x,", ((struct httpfetcher *)httpf)->owner); +static bool abort_fetch(void *httpf) { + NSLOG(fetch, DEBUG, "aborting httpf 0x%x, httpf->handle 0x%x, httpf->next 0x%x", ((struct httpfetcher *)httpf), ((struct httpfetcher *)httpf)->handle, ((struct httpfetcher *)httpf)->next); + + remove_from_poll(httpf); - // remove_from_poll((struct httpfetcher *) httpf); fetch_remove_from_queues(((struct httpfetcher *)httpf)->owner); + fetch_free(((struct httpfetcher *)httpf)->owner); return true; } -bool free_fetch(void *httpf) { - NSLOG(fetch, ERROR, "free_fetch fetch 0x%x", ((struct httpfetcher *)httpf)->owner); +static void free_fetch(void *httpf) { + NSLOG(fetch, DEBUG, "free_fetch httpf 0x%x", ((struct httpfetcher *)httpf)); + http_disconnect_asm((((struct httpfetcher *)httpf)->handle)); http_free_asm((((struct httpfetcher *)httpf)->handle)); free((struct httpfetcher *)httpf); - - return true; } -void poll_fetch(lwc_string *scheme) { +static void poll_fetch(lwc_string *scheme) { bool supported_scheme; assert(lwc_string_isequal(scheme, corestring_lwc_http, &supported_scheme) == lwc_error_ok); assert(supported_scheme); @@ -344,19 +330,12 @@ void poll_fetch(lwc_string *scheme) { NSLOG(fetch, DEBUG, "--- Content Length (received / total): %d / %d", t->handle->content_received, t->handle->content_length); NSLOG(fetch, DEBUG, "--- ^ was for url : %s", nsurl_access(t->url)); - struct httpfetcher *xx = head; - while(xx) { - NSLOG(fetch, ERROR, "ll node poller = 0x%x", xx); - xx=xx->next; - } - NSLOG(fetch, ERROR, "ll node poller breakage --"); - int ret = http_receive_asm(t->handle); if(t->handle->flags & HTTP_ERRORS) { fetch_msg msg; msg.type = FETCH_ERROR; - NSLOG(fetch, ERROR, "---- http_msg -> flags = 0x%x", t->handle->flags); + NSLOG(fetch, DEBUG, "---- http_msg -> flags = 0x%x", t->handle->flags); msg.data.header_or_data.buf = (const uint8_t *) "HTTPLIB ERROR"; msg.data.header_or_data.len = strlen("HTTPLIB ERROR"); struct httpfetcher *t2 = remove_from_poll(t); @@ -423,12 +402,12 @@ void poll_fetch(lwc_string *scheme) { newlocation[lenloc]='\0'; msg.data.redirect = newlocation; - NSLOG(fetch, INFO, "---- [3xx] : Redirect to %s", msg.data.redirect); + NSLOG(fetch, DEBUG, "---- [3xx] : Redirect to %s", msg.data.redirect); struct httpfetcher *t2 = remove_from_poll(t); fetch_send_callback(&msg, t->owner); t->headercbdone = true; t = t2; - NSLOG(fetch, INFO, "---- DID [3xx] : Redirect to %s", msg.data.redirect); + NSLOG(fetch, DEBUG, "---- DID [3xx] : Redirect to %s", msg.data.redirect); /* t = t->next; */ /* t = head; */ continue; @@ -437,7 +416,7 @@ void poll_fetch(lwc_string *scheme) { else { fetch_msg msg; msg.type = FETCH_ERROR; - NSLOG(fetch, DEBUG, " ---- [ERROR] Unhandled HTTP Code : %d", t->handle->status); + NSLOG(fetch, ERROR, " ---- Unhandled HTTP Code : %d", t->handle->status); fetch_send_callback(&msg, t->owner); t->headercbdone = true; fetch_remove_from_queues(t->owner); @@ -500,7 +479,7 @@ void poll_fetch(lwc_string *scheme) { } } -void finalize_fetcher(lwc_string *scheme) { +static void finalize_fetcher(lwc_string *scheme) { bool supported_scheme; assert(lwc_string_isequal(scheme, corestring_lwc_http, &supported_scheme) == lwc_error_ok); lwc_string_unref(scheme); -- cgit v1.2.3