From 75018632a9b953aafeae6f4e8aea607fd1d89dca Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 6 Sep 2017 18:28:12 +0100 Subject: Use coccinelle to change logging macro calls in c files for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done @@ expression E; @@ -LOG(E); +NSLOG(netsurf, INFO, E); @@ expression E, E1; @@ -LOG(E, E1); +NSLOG(netsurf, INFO, E, E1); @@ expression E, E1, E2; @@ -LOG(E, E1, E2); +NSLOG(netsurf, INFO, E, E1, E2); @@ expression E, E1, E2, E3; @@ -LOG(E, E1, E2, E3); +NSLOG(netsurf, INFO, E, E1, E2, E3); @@ expression E, E1, E2, E3, E4; @@ -LOG(E, E1, E2, E3, E4); +NSLOG(netsurf, INFO, E, E1, E2, E3, E4); @@ expression E, E1, E2, E3, E4, E5; @@ -LOG(E, E1, E2, E3, E4, E5); +NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5); @@ expression E, E1, E2, E3, E4, E5, E6; @@ -LOG(E, E1, E2, E3, E4, E5, E6); +NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6); @@ expression E, E1, E2, E3, E4, E5, E6, E7; @@ -LOG(E, E1, E2, E3, E4, E5, E6, E7); +NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7); --- utils/filename.c | 32 +++++++++++++++++++++----------- utils/hashtable.c | 10 ++++++---- utils/idna.c | 38 +++++++++++++++++++++++++++----------- utils/messages.c | 25 ++++++++++++++++--------- utils/nsoption.c | 10 ++++++---- utils/nsurl/nsurl.c | 6 ++++-- utils/nsurl/parse.c | 27 ++++++++++++++------------- utils/useragent.c | 3 ++- utils/utf8.c | 5 +++-- 9 files changed, 99 insertions(+), 57 deletions(-) (limited to 'utils') diff --git a/utils/filename.c b/utils/filename.c index 9c95901a1..01a403fd9 100644 --- a/utils/filename.c +++ b/utils/filename.c @@ -84,7 +84,8 @@ const char *filename_request(void) /* no available slots - create a new directory */ dir = filename_create_directory(NULL); if (dir == NULL) { - LOG("Failed to create a new directory."); + NSLOG(netsurf, INFO, + "Failed to create a new directory."); return NULL; } i = 63; @@ -182,10 +183,12 @@ bool filename_initialise(void) for (start = directory; *start != '\0'; start++) { if (*start == '/') { *start = '\0'; - LOG("Creating \"%s\"", directory); + NSLOG(netsurf, INFO, "Creating \"%s\"", directory); ret = nsmkdir(directory, S_IRWXU); if (ret != 0 && errno != EEXIST) { - LOG("Failed to create directory \"%s\"", directory); + NSLOG(netsurf, INFO, + "Failed to create directory \"%s\"", + directory); free(directory); return false; } @@ -194,7 +197,7 @@ bool filename_initialise(void) } } - LOG("Temporary directory location: %s", directory); + NSLOG(netsurf, INFO, "Temporary directory location: %s", directory); ret = nsmkdir(directory, S_IRWXU); free(directory); @@ -280,7 +283,8 @@ bool filename_flush_directory(const char *folder, int depth) child[sizeof(child) - 1] = '\0'; if (stat(child, &statbuf) == -1) { - LOG("Unable to stat %s: %s", child, strerror(errno)); + NSLOG(netsurf, INFO, "Unable to stat %s: %s", child, + strerror(errno)); continue; } @@ -348,7 +352,8 @@ bool filename_flush_directory(const char *folder, int depth) filename_delete_recursive(child); if (remove(child)) - LOG("Failed to remove '%s'", child); + NSLOG(netsurf, INFO, "Failed to remove '%s'", + child); else changed = true; } else { @@ -387,7 +392,8 @@ bool filename_delete_recursive(char *folder) child[sizeof(child) - 1] = '\0'; if (stat(child, &statbuf) == -1) { - LOG("Unable to stat %s: %s", child, strerror(errno)); + NSLOG(netsurf, INFO, "Unable to stat %s: %s", child, + strerror(errno)); continue; } @@ -399,7 +405,7 @@ bool filename_delete_recursive(char *folder) } if (remove(child)) { - LOG("Failed to remove '%s'", child); + NSLOG(netsurf, INFO, "Failed to remove '%s'", child); closedir(parent); return false; } @@ -465,7 +471,7 @@ static struct directory *filename_create_directory(const char *prefix) /* allocate a new directory */ new_dir = malloc(sizeof(struct directory)); if (new_dir == NULL) { - LOG("No memory for malloc()"); + NSLOG(netsurf, INFO, "No memory for malloc()"); return NULL; } @@ -499,7 +505,9 @@ static struct directory *filename_create_directory(const char *prefix) * whilst we are running if there is an error, so we * don't report this yet and try to create the * structure normally. */ - LOG("Failed to create optimised structure '%s'", filename_directory); + NSLOG(netsurf, INFO, + "Failed to create optimised structure '%s'", + filename_directory); } } @@ -519,7 +527,9 @@ static struct directory *filename_create_directory(const char *prefix) if (!is_dir(filename_directory)) { if (nsmkdir(filename_directory, S_IRWXU)) { - LOG("Failed to create directory '%s'", filename_directory); + NSLOG(netsurf, INFO, + "Failed to create directory '%s'", + filename_directory); return NULL; } } diff --git a/utils/hashtable.c b/utils/hashtable.c index af100dfc9..3a1711da0 100644 --- a/utils/hashtable.c +++ b/utils/hashtable.c @@ -81,7 +81,7 @@ struct hash_table *hash_create(unsigned int chains) struct hash_table *r = malloc(sizeof(struct hash_table)); if (r == NULL) { - LOG("Not enough memory for hash table."); + NSLOG(netsurf, INFO, "Not enough memory for hash table."); return NULL; } @@ -89,7 +89,8 @@ struct hash_table *hash_create(unsigned int chains) r->chain = calloc(chains, sizeof(struct hash_entry *)); if (r->chain == NULL) { - LOG("Not enough memory for %d hash table chains.", chains); + NSLOG(netsurf, INFO, + "Not enough memory for %d hash table chains.", chains); free(r); return NULL; } @@ -134,7 +135,7 @@ bool hash_add(struct hash_table *ht, const char *key, const char *value) e = malloc(sizeof(struct hash_entry)); if (e == NULL) { - LOG("Not enough memory for hash entry."); + NSLOG(netsurf, INFO, "Not enough memory for hash entry."); return false; } @@ -144,7 +145,8 @@ bool hash_add(struct hash_table *ht, const char *key, const char *value) v = strlen(value) ; e->pairing = malloc(v + e->key_length + 2); if (e->pairing == NULL) { - LOG("Not enough memory for string duplication."); + NSLOG(netsurf, INFO, + "Not enough memory for string duplication."); free(e); return false; } diff --git a/utils/idna.c b/utils/idna.c index 34cc40f83..572882ecb 100644 --- a/utils/idna.c +++ b/utils/idna.c @@ -63,17 +63,17 @@ static nserror punycode_status_to_nserror(enum punycode_status status) break; case punycode_bad_input: - LOG("Bad input"); + NSLOG(netsurf, INFO, "Bad input"); ret = NSERROR_BAD_ENCODING; break; case punycode_big_output: - LOG("Output too big"); + NSLOG(netsurf, INFO, "Output too big"); ret = NSERROR_BAD_SIZE; break; case punycode_overflow: - LOG("Overflow"); + NSLOG(netsurf, INFO, "Overflow"); ret = NSERROR_NOSPACE; break; @@ -437,7 +437,8 @@ static bool idna__is_valid(int32_t *label, size_t len) /* 2. Check characters 3 and 4 are not '--'. */ if ((label[2] == 0x002d) && (label[3] == 0x002d)) { - LOG("Check failed: characters 2 and 3 are '--'"); + NSLOG(netsurf, INFO, + "Check failed: characters 2 and 3 are '--'"); return false; } @@ -447,7 +448,8 @@ static bool idna__is_valid(int32_t *label, size_t len) if ((unicode_props->category == UTF8PROC_CATEGORY_MN) || (unicode_props->category == UTF8PROC_CATEGORY_MC) || (unicode_props->category == UTF8PROC_CATEGORY_ME)) { - LOG("Check failed: character 0 is a combining mark"); + NSLOG(netsurf, INFO, + "Check failed: character 0 is a combining mark"); return false; } @@ -456,14 +458,20 @@ static bool idna__is_valid(int32_t *label, size_t len) /* 4. Check characters not DISALLOWED by RFC5892 */ if (idna_prop == IDNA_P_DISALLOWED) { - LOG("Check failed: character %" PRIsizet " (%x) is DISALLOWED", i, label[i]); + NSLOG(netsurf, INFO, + "Check failed: character %"PRIsizet" (%x) is DISALLOWED", + i, + label[i]); return false; } /* 5. Check CONTEXTJ characters conform to defined rules */ if (idna_prop == IDNA_P_CONTEXTJ) { if (idna__contextj_rule(label, i, len) == false) { - LOG("Check failed: character %" PRIsizet " (%x) does not conform to CONTEXTJ rule", i, label[i]); + NSLOG(netsurf, INFO, + "Check failed: character %"PRIsizet" (%x) does not conform to CONTEXTJ rule", + i, + label[i]); return false; } } @@ -472,14 +480,20 @@ static bool idna__is_valid(int32_t *label, size_t len) /** \todo optionally we can check conformance to this rule */ if (idna_prop == IDNA_P_CONTEXTO) { if (idna__contexto_rule(label[i]) == false) { - LOG("Check failed: character %" PRIsizet " (%x) has no CONTEXTO rule defined", i, label[i]); + NSLOG(netsurf, INFO, + "Check failed: character %"PRIsizet" (%x) has no CONTEXTO rule defined", + i, + label[i]); return false; } } /* 7. Check characters are not UNASSIGNED */ if (idna_prop == IDNA_P_UNASSIGNED) { - LOG("Check failed: character %" PRIsizet " (%x) is UNASSIGNED", i, label[i]); + NSLOG(netsurf, INFO, + "Check failed: character %"PRIsizet" (%x) is UNASSIGNED", + i, + label[i]); return false; } @@ -588,7 +602,8 @@ static bool idna__verify(const char *label, size_t len) return true; } - LOG("Re-encoded ACE label %s does not match input", ace); + NSLOG(netsurf, INFO, "Re-encoded ACE label %s does not match input", + ace); free(ace); return false; @@ -641,7 +656,8 @@ idna_encode(const char *host, size_t len, char **ace_host, size_t *ace_len) /* This is already a DNS-valid ASCII string */ if ((idna__is_ace(host, label_len) == true) && (idna__verify(host, label_len) == false)) { - LOG("Cannot verify ACE label %s", host); + NSLOG(netsurf, INFO, + "Cannot verify ACE label %s", host); return NSERROR_BAD_URL; } strncpy(fqdn_p, host, label_len); diff --git a/utils/messages.c b/utils/messages.c index be53eccd0..e2d45e9da 100644 --- a/utils/messages.c +++ b/utils/messages.c @@ -74,7 +74,8 @@ message_process_line(struct hash_table *hash, uint8_t *ln, int lnlen) value = colon + 1; if (hash_add(hash, (char *)ln, (char *)value) == false) { - LOG("Unable to add %s:%s to hash table", ln, value); + NSLOG(netsurf, INFO, "Unable to add %s:%s to hash table", ln, + value); return NSERROR_INVALID; } return NSERROR_OK; @@ -97,7 +98,9 @@ static nserror messages_load_ctx(const char *path, struct hash_table **ctx) fp = gzopen(path, "r"); if (!fp) { - LOG("Unable to open messages file \"%.100s\": %s", path, strerror(errno)); + NSLOG(netsurf, INFO, + "Unable to open messages file \"%.100s\": %s", path, + strerror(errno)); return NSERROR_NOT_FOUND; } @@ -112,7 +115,9 @@ static nserror messages_load_ctx(const char *path, struct hash_table **ctx) nctx = *ctx; } if (nctx == NULL) { - LOG("Unable to create hash table for messages file %s", path); + NSLOG(netsurf, INFO, + "Unable to create hash table for messages file %s", + path); gzclose(fp); return NSERROR_NOMEM; } @@ -131,7 +136,9 @@ static nserror messages_load_ctx(const char *path, struct hash_table **ctx) value = colon + 1; if (hash_add(nctx, s, value) == false) { - LOG("Unable to add %s:%s to hash table of %s", s, value, path); + NSLOG(netsurf, INFO, + "Unable to add %s:%s to hash table of %s", s, + value, path); gzclose(fp); if (*ctx == NULL) { hash_destroy(nctx); @@ -202,7 +209,7 @@ nserror messages_add_from_file(const char *path) return NSERROR_BAD_PARAMETER; } - LOG("Loading Messages from '%s'", path); + NSLOG(netsurf, INFO, "Loading Messages from '%s'", path); err = messages_load_ctx(path, &messages_hash); @@ -225,7 +232,7 @@ nserror messages_add_from_inline(const uint8_t *data, size_t data_size) messages_hash = hash_create(HASH_SIZE); } if (messages_hash == NULL) { - LOG("Unable to create hash table"); + NSLOG(netsurf, INFO, "Unable to create hash table"); return NSERROR_NOMEM; } @@ -238,7 +245,7 @@ nserror messages_add_from_inline(const uint8_t *data, size_t data_size) ret = inflateInit2(&strm, 32 + MAX_WBITS); if (ret != Z_OK) { - LOG("inflateInit returned %d", ret); + NSLOG(netsurf, INFO, "inflateInit returned %d", ret); return NSERROR_INVALID; } @@ -271,7 +278,7 @@ nserror messages_add_from_inline(const uint8_t *data, size_t data_size) } if (used == sizeof(s)) { /* entire buffer used and no newline */ - LOG("Overlength line"); + NSLOG(netsurf, INFO, "Overlength line"); used = 0; } } while (ret != Z_STREAM_END); @@ -279,7 +286,7 @@ nserror messages_add_from_inline(const uint8_t *data, size_t data_size) inflateEnd(&strm); if (ret != Z_STREAM_END) { - LOG("inflate returned %d", ret); + NSLOG(netsurf, INFO, "inflate returned %d", ret); return NSERROR_INVALID; } return NSERROR_OK; diff --git a/utils/nsoption.c b/utils/nsoption.c index 8f05a911b..15f89ca5d 100644 --- a/utils/nsoption.c +++ b/utils/nsoption.c @@ -648,11 +648,12 @@ nsoption_read(const char *path, struct nsoption_s *opts) fp = fopen(path, "r"); if (!fp) { - LOG("Failed to open file '%s'", path); + NSLOG(netsurf, INFO, "Failed to open file '%s'", path); return NSERROR_NOT_FOUND; } - LOG("Successfully opened '%s' for Options file", path); + NSLOG(netsurf, INFO, "Successfully opened '%s' for Options file", + path); while (fgets(s, NSOPTION_MAX_LINE_LEN, fp)) { char *colon, *value; @@ -718,7 +719,8 @@ nsoption_write(const char *path, fp = fopen(path, "w"); if (!fp) { - LOG("failed to open file '%s' for writing", path); + NSLOG(netsurf, INFO, "failed to open file '%s' for writing", + path); return NSERROR_NOT_FOUND; } @@ -798,7 +800,7 @@ nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts) /* arg+arglen is the option to set, val is the value */ - LOG("%.*s = %s", arglen, arg, val); + NSLOG(netsurf, INFO, "%.*s = %s", arglen, arg, val); for (entry_loop = 0; entry_loop < NSOPTION_LISTEND; diff --git a/utils/nsurl/nsurl.c b/utils/nsurl/nsurl.c index 7166a2707..3b0af9328 100644 --- a/utils/nsurl/nsurl.c +++ b/utils/nsurl/nsurl.c @@ -230,7 +230,8 @@ lwc_string *nsurl_get_component(const nsurl *url, nsurl_component part) lwc_string_ref(url->components.fragment) : NULL; default: - LOG("Unsupported value passed to part param."); + NSLOG(netsurf, INFO, + "Unsupported value passed to part param."); assert(0); } @@ -296,7 +297,8 @@ bool nsurl_has_component(const nsurl *url, nsurl_component part) return false; default: - LOG("Unsupported value passed to part param."); + NSLOG(netsurf, INFO, + "Unsupported value passed to part param."); assert(0); } diff --git a/utils/nsurl/parse.c b/utils/nsurl/parse.c index 7474a612d..ce6f4435d 100644 --- a/utils/nsurl/parse.c +++ b/utils/nsurl/parse.c @@ -451,19 +451,19 @@ static void nsurl__get_string_markers(const char * const url_s, } #ifdef NSURL_DEBUG - LOG("marker.start: %i", marker.start); - LOG("marker.scheme_end: %i", marker.scheme_end); - LOG("marker.authority: %i", marker.authority); + NSLOG(netsurf, INFO, "marker.start: %i", marker.start); + NSLOG(netsurf, INFO, "marker.scheme_end: %i", marker.scheme_end); + NSLOG(netsurf, INFO, "marker.authority: %i", marker.authority); - LOG("marker.colon_first: %i", marker.colon_first); - LOG("marker.at: %i", marker.at); - LOG("marker.colon_last: %i", marker.colon_last); + NSLOG(netsurf, INFO, "marker.colon_first: %i", marker.colon_first); + NSLOG(netsurf, INFO, "marker.at: %i", marker.at); + NSLOG(netsurf, INFO, "marker.colon_last: %i", marker.colon_last); - LOG("marker.path: %i", marker.path); - LOG("marker.query: %i", marker.query); - LOG("marker.fragment: %i", marker.fragment); + NSLOG(netsurf, INFO, "marker.path: %i", marker.path); + NSLOG(netsurf, INFO, "marker.query: %i", marker.query); + NSLOG(netsurf, INFO, "marker.fragment: %i", marker.fragment); - LOG("marker.end: %i", marker.end); + NSLOG(netsurf, INFO, "marker.end: %i", marker.end); #endif /* Got all the URL components pegged out now */ @@ -485,8 +485,8 @@ static size_t nsurl__remove_dot_segments(char *path, char *output) while (*path_pos != '\0') { #ifdef NSURL_DEBUG - LOG(" in:%s", path_pos); - LOG("out:%.*s", output_pos - output, output); + NSLOG(netsurf, INFO, " in:%s", path_pos); + NSLOG(netsurf, INFO, "out:%.*s", output_pos - output, output); #endif if (*path_pos == '.') { if (*(path_pos + 1) == '.' && @@ -1324,7 +1324,8 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined) assert(rel != NULL); #ifdef NSURL_DEBUG - LOG("base: \"%s\", rel: \"%s\"", nsurl_access(base), rel); + NSLOG(netsurf, INFO, "base: \"%s\", rel: \"%s\"", nsurl_access(base), + rel); #endif /* Peg out the URL sections */ diff --git a/utils/useragent.c b/utils/useragent.c index 72e45aada..b528dce4f 100644 --- a/utils/useragent.c +++ b/utils/useragent.c @@ -65,7 +65,8 @@ user_agent_build_string(void) core_user_agent_string = ua_string; - LOG("Built user agent \"%s\"", core_user_agent_string); + NSLOG(netsurf, INFO, "Built user agent \"%s\"", + core_user_agent_string); } /* This is a function so that later we can override it trivially */ diff --git a/utils/utf8.c b/utils/utf8.c index 5c930cd13..f0ac0c9b2 100644 --- a/utils/utf8.c +++ b/utils/utf8.c @@ -468,7 +468,8 @@ bool utf8_save_text(const char *utf8_text, const char *path) ret = guit->utf8->utf8_to_local(utf8_text, strlen(utf8_text), &conv); if (ret != NSERROR_OK) { - LOG("failed to convert to local encoding, return %d", ret); + NSLOG(netsurf, INFO, + "failed to convert to local encoding, return %d", ret); return false; } @@ -476,7 +477,7 @@ bool utf8_save_text(const char *utf8_text, const char *path) if (out) { int res = fputs(conv, out); if (res < 0) { - LOG("Warning: writing data failed"); + NSLOG(netsurf, INFO, "Warning: writing data failed"); } res = fputs("\n", out); -- cgit v1.2.3