From 346baf80d8a0785d48a2faeae0af42258e22150d Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Wed, 25 Oct 2017 22:25:41 +0200 Subject: Use libnslog. Get rid of LOG() macro calls and replace with calls to NSLOG. --- content/fetchers/httplib_kolibri.c | 79 ++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 41 deletions(-) (limited to 'content/fetchers/httplib_kolibri.c') diff --git a/content/fetchers/httplib_kolibri.c b/content/fetchers/httplib_kolibri.c index 18055d1ae..93dfce2be 100644 --- a/content/fetchers/httplib_kolibri.c +++ b/content/fetchers/httplib_kolibri.c @@ -27,7 +27,7 @@ struct httpfetcher *head = NULL; void add_to_poll(struct httpfetcher *newfetcher) { - LOG("-=- add: newfetcher 0x%x, newfetcher->handle 0x%x", newfetcher, newfetcher->handle); + NSLOG(fetch, DEBUG, "-=- add: newfetcher 0x%x, newfetcher->handle 0x%x", newfetcher, newfetcher->handle); struct httpfetcher *t = head; assert(newfetcher->next == NULL); @@ -46,7 +46,7 @@ void add_to_poll(struct httpfetcher *newfetcher) { struct httpfetcher* remove_from_poll(struct http_msg *donehttp) { struct httpfetcher *t = head, *p = head; - LOG("-=- remove: (->handle) donehttp 0x%x", donehttp); + NSLOG(fetch, DEBUG, "-=- remove: (->handle) donehttp 0x%x", donehttp); while(t) { if (t->handle == donehttp) { @@ -74,14 +74,14 @@ bool init_fetcher(lwc_string *scheme) { bool supported_scheme; assert(lwc_string_isequal(scheme, corestring_lwc_http, &supported_scheme) == lwc_error_ok); - LOG("Initializing http library!"); + NSLOG(fetch, DEBUG, "Initializing http library!"); debug_board_printf("---- [NETSURF] Trying to initialize http library.\n"); if(kolibri_http_init() == 0) { - LOG("[INFO] Loaded http.obj library successfully.\n"); + NSLOG(fetch, DEBUG, "[INFO] Loaded http.obj library successfully.\n"); debug_board_printf("---- [NETSURF] Successfully initialized http library.\n"); } else { - LOG("[ERROR] Could not load http.obj library.\n"); + NSLOG(fetch, ERROR, "[ERROR] Could not load http.obj library.\n"); debug_board_printf("---- [NETSURF] Could not initialize http library. Exiting.\n"); assert(0 && 1); return false; @@ -105,23 +105,20 @@ void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, struct http_msg* request = NULL; - LOG("[SETUP] Our target URL: %s", nsurl_access(url)); - LOG("[SETUP] POST urlencoded data: %s", post_urlenc); + NSLOG(fetch, DEBUG, "[SETUP] Our target URL: %s", nsurl_access(url)); + NSLOG(fetch, DEBUG, "[SETUP] POST urlencoded data: %s", post_urlenc); int i = 0; for(i = 0; headers[i] != NULL; i++) - LOG("[SETUP] -- Headers : %s", headers[i]); + NSLOG(fetch, DEBUG, "[SETUP] -- Headers : %s", headers[i]); if(post_multipart != NULL) { struct fetch_multipart_data *printer = post_multipart; while(printer != NULL) { - LOG("Multipart POST : (%s = %s)\n", printer->name, printer->value); + NSLOG(fetch, DEBUG, "Multipart POST : (%s = %s)\n", printer->name, printer->value); /* debug_board_printf("Multipart POST : (%s = %s)\n", printer->name, printer->value); */ printer = printer->next; } - - LOG("[WARNING] We dont support POST multipart yet!\n"); - LOG("[NETSURF ERROR] We dont support POST multipart yet!\n"); char *boundary = "--------Netsurf------------KolibriOS----Multipart----"; int lenb = strlen(boundary); char *contenttype = "multipart/form-data; boundary=--------Netsurf------------KolibriOS----Multipart----"; @@ -208,8 +205,8 @@ void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, /* debug_board_printf("TERMINATING NULL tmp = %u\n", tmp); */ - LOG("Multipart request content length : %d", contentlen); - LOG("Multipart request content: %s", content); + NSLOG(fetch, DEBUG, "Multipart request content length : %d", contentlen); + NSLOG(fetch, DEBUG, "Multipart request content: %s", content); request = http_post_asm(nsurl_access(url), NULL, 1<<8, *headers, contenttype, contentlen - 1); @@ -219,28 +216,28 @@ void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, /* LOG("--- Sending data : with length %u\n", contentlen); */ datasent = http_send_asm(request, content, contentlen - 1); /* debug_board_printf("--- Sent %d bytes of data.\n", datasent); */ - LOG("--- Sent %d bytes of multipart post data.\n", datasent); + NSLOG(fetch, DEBUG, "--- Sent %d bytes of multipart post data.\n", datasent); } } else if(post_urlenc) { - LOG("http_post: %s", nsurl_access(url)); + NSLOG(fetch, DEBUG, "http_post: %s", nsurl_access(url)); request = http_post_asm(nsurl_access(url), NULL, 0, *headers, "application/x-www-form-urlencoded", strlen(post_urlenc)); if(request != NULL) { int datasent = 0; /* Send all the data here itself. Move this later to polling maybe. */ /* debug_board_printf("--- Sending data : %s with length %u\n", post_urlenc, strlen(post_urlenc)); */ datasent = http_send_asm(request, post_urlenc, strlen(post_urlenc)); - LOG("--- Sent %d bytes of urlencoded data.\n", datasent); + NSLOG(fetch, DEBUG, "--- Sent %d bytes of urlencoded data.\n", datasent); } } else { /* Do a GET */ - LOG("http_get: %s", nsurl_access(url)); + NSLOG(fetch, DEBUG, "http_get: %s", nsurl_access(url)); request = http_get_asm(nsurl_access(url), NULL, 0, *headers); } if(request == NULL) { - LOG("Failed to allocate http buffer. Could be multiple reasons for failure (like DNS resolution)", request); + NSLOG(fetch, ERROR, "Failed to allocate http buffer. Could be multiple reasons for failure (like DNS resolution)", request); return NULL; } @@ -264,14 +261,14 @@ void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, } bool start_fetch(void *httpf) { - LOG("-=- start_fetch : httpf: 0x%x", httpf); + NSLOG(fetch, DEBUG, "-=- start_fetch : httpf: 0x%x", httpf); add_to_poll((struct httpfetcher *) httpf); return true; } bool abort_fetch(void *httpf) { - LOG("aborting fetch 0x%x", ((struct httpfetcher *)httpf)->owner); + NSLOG(fetch, DEBUG, "aborting fetch 0x%x", ((struct httpfetcher *)httpf)->owner); remove_from_poll(((struct httpfetcher *) httpf)->handle); fetch_remove_from_queues(((struct httpfetcher *)httpf)->owner); fetch_free(((struct httpfetcher *)httpf)->owner); @@ -279,10 +276,10 @@ bool abort_fetch(void *httpf) { } bool free_fetch(void *httpf) { - LOG("free_fetch called for 0x%x", ((struct httpfetcher *)httpf)->owner); + NSLOG(fetch, DEBUG, "free_fetch called for 0x%x", ((struct httpfetcher *)httpf)->owner); http_disconnect_asm((((struct httpfetcher *)httpf)->handle)); - LOG("Freeing fetch 0x%x", ((struct httpfetcher *)httpf)->owner); + NSLOG(fetch, DEBUG, "Freeing fetch 0x%x", ((struct httpfetcher *)httpf)->owner); http_free_asm((((struct httpfetcher *)httpf)->handle)); free((struct httpfetcher *)httpf); @@ -297,20 +294,20 @@ void poll_fetch(lwc_string *scheme) { struct httpfetcher *t = head; while(t != NULL) { - LOG("-- Polling for t 0x%x, http_msg 0x%x, fetch 0x%x [ hcbdone = %s ]", t, t->handle, t->owner, t->headercbdone == true ? "true" : "false"); - LOG("--- http_msg struct at : %x", t->handle); - LOG("--- Header starts at : %x", &(t->handle->http_header)); - LOG("--- Header Length: %d", t->handle->header_length); - LOG("--- Content starts at : %x", &(t->handle->content_ptr)); - LOG("--- Content Length (received / total): %d / %d", t->handle->content_received, t->handle->content_length); - LOG("--- ^ was for url : %s", nsurl_access(t->url)); + NSLOG(fetch, DEBUG, "-- Polling for t 0x%x, http_msg 0x%x, fetch 0x%x [ hcbdone = %s ]", t, t->handle, t->owner, t->headercbdone == true ? "true" : "false"); + NSLOG(fetch, DEBUG, "--- http_msg struct at : %x", t->handle); + NSLOG(fetch, DEBUG, "--- Header starts at : %x", &(t->handle->http_header)); + NSLOG(fetch, DEBUG, "--- Header Length: %d", t->handle->header_length); + NSLOG(fetch, DEBUG, "--- Content starts at : %x", &(t->handle->content_ptr)); + 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)); int ret = http_receive_asm(t->handle); if(t->handle->flags & HTTP_ERRORS) { fetch_msg msg; msg.type = FETCH_ERROR; - LOG("---- [ERROR] http_msg -> flags = 0x%x", t->handle->flags); + NSLOG(fetch, ERROR, "---- 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"); fetch_send_callback(&msg, t->owner); @@ -319,8 +316,8 @@ void poll_fetch(lwc_string *scheme) { if(t->headercbdone == false) { if (t->handle->flags & HTTP_GOT_HEADER) { - LOG("---- Received all HTTP Headers."); - LOG("---- response status code = %d", t->handle->status); + NSLOG(fetch, DEBUG, "---- Received all HTTP Headers."); + NSLOG(fetch, DEBUG, "---- response status code = %d", t->handle->status); fetch_set_http_code(t->owner, t->handle->status); if(t->handle->status >= 200 && t->handle->status < 300) { @@ -343,7 +340,7 @@ void poll_fetch(lwc_string *scheme) { char *xx = (char *) malloc(j - plen + 1); strncpy(xx, ptr + plen, j-plen); xx[j-plen] = '\0'; - LOG("Headerline: %s", xx); + NSLOG(fetch, DEBUG, "Headerline: %s", xx); fetch_send_callback(&msg, t->owner); free(xx); @@ -374,7 +371,7 @@ void poll_fetch(lwc_string *scheme) { newlocation[lenloc]='\0'; msg.data.redirect = newlocation; - LOG("---- [3xx] : Redirect to %s", msg.data.redirect); + NSLOG(fetch, INFO, "---- [3xx] : Redirect to %s", msg.data.redirect); fetch_send_callback(&msg, t->owner); t->headercbdone = true; t = remove_from_poll(t->handle); @@ -386,7 +383,7 @@ void poll_fetch(lwc_string *scheme) { else { fetch_msg msg; msg.type = FETCH_ERROR; - LOG(" ---- [ERROR] Unhandled HTTP Code : %d", t->handle->status); + NSLOG(fetch, DEBUG, " ---- [ERROR] Unhandled HTTP Code : %d", t->handle->status); fetch_send_callback(&msg, t->owner); t->headercbdone = true; fetch_remove_from_queues(t->owner); @@ -398,16 +395,16 @@ void poll_fetch(lwc_string *scheme) { } } else { - LOG("---- Headers not received yet."); + NSLOG(fetch, DEBUG, "---- Headers not received yet."); } } else if(ret == -1) { /* If data was received send it to netsurf core with FETCH_DATA */ - LOG("Calledback vs received : %u vs %u!", t->datalen_cb_done, t->handle->content_received); + NSLOG(fetch, DEBUG, "Calledback vs received : %u vs %u!", t->datalen_cb_done, t->handle->content_received); if(t->handle->content_received > t->datalen_cb_done) { fetch_msg msg; - LOG("Doing a data callback\n"); + NSLOG(fetch, DEBUG, "Doing a data callback\n"); msg.type = FETCH_DATA; msg.data.header_or_data.buf = (const uint8_t *) (t->handle->content_ptr + t->datalen_cb_done); msg.data.header_or_data.len = t->handle->content_received - t->datalen_cb_done; @@ -432,7 +429,7 @@ void poll_fetch(lwc_string *scheme) { msg.data.header_or_data.buf = NULL; msg.data.header_or_data.len = 0; fetch_send_callback(&msg, t->owner); - LOG("---- FETCH_FINISHED for fetch 0x%x", t->owner); + NSLOG(fetch, DEBUG, "---- FETCH_FINISHED for fetch 0x%x", t->owner); struct httpfetcher *tnext = t->next; fetch_remove_from_queues(t->owner); @@ -443,7 +440,7 @@ void poll_fetch(lwc_string *scheme) { continue; } - LOG("Main loop: t going from 0x%x to 0x%x", t->owner, t->next != NULL ? t->next->owner : NULL); + NSLOG(fetch, DEBUG, "Main loop: t going from 0x%x to 0x%x", t->owner, t->next != NULL ? t->next->owner : NULL); t = t->next; } } -- cgit v1.2.3