diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/errors.h | 75 | ||||
-rw-r--r-- | utils/filename.c | 32 | ||||
-rw-r--r-- | utils/hashtable.c | 10 | ||||
-rw-r--r-- | utils/idna.c | 38 | ||||
-rwxr-xr-x | utils/jenkins-build.sh | 22 | ||||
-rw-r--r-- | utils/log.c | 284 | ||||
-rw-r--r-- | utils/log.h | 68 | ||||
-rw-r--r-- | utils/messages.c | 89 | ||||
-rw-r--r-- | utils/nsoption.c | 17 | ||||
-rw-r--r-- | utils/nsurl/nsurl.c | 6 | ||||
-rw-r--r-- | utils/nsurl/parse.c | 27 | ||||
-rw-r--r-- | utils/nsurl/private.h | 32 | ||||
-rw-r--r-- | utils/useragent.c | 3 | ||||
-rw-r--r-- | utils/utf8.c | 5 |
14 files changed, 495 insertions, 213 deletions
diff --git a/utils/errors.h b/utils/errors.h index b9e157c66..9a0a9bc04 100644 --- a/utils/errors.h +++ b/utils/errors.h @@ -27,58 +27,37 @@ * Enumeration of error codes */ typedef enum { - NSERROR_OK, /**< No error */ - - NSERROR_UNKNOWN, /**< Unknown error - DO *NOT* USE */ - - NSERROR_NOMEM, /**< Memory exhaustion */ - - NSERROR_NO_FETCH_HANDLER, /**< No fetch handler for URL scheme */ - - NSERROR_NOT_FOUND, /**< Requested item not found */ - - NSERROR_NOT_DIRECTORY, /**< Missing directory */ - - NSERROR_SAVE_FAILED, /**< Failed to save data */ - - NSERROR_CLONE_FAILED, /**< Failed to clone handle */ - - NSERROR_INIT_FAILED, /**< Initialisation failed */ - - NSERROR_MNG_ERROR, /**< An MNG error occurred */ - - NSERROR_BAD_ENCODING, /**< The character set is unknown */ - - NSERROR_NEED_DATA, /**< More data needed */ - - NSERROR_ENCODING_CHANGE, /**< The character changed */ - - NSERROR_BAD_PARAMETER, /**< Bad Parameter */ - - NSERROR_INVALID, /**< Invalid data */ - - NSERROR_BOX_CONVERT, /**< Box conversion failed */ - - NSERROR_STOPPED, /**< Content conversion stopped */ - - NSERROR_DOM, /**< DOM call returned error */ - - NSERROR_CSS, /**< CSS call returned error */ - + NSERROR_OK, /**< No error */ + NSERROR_UNKNOWN, /**< Unknown error - DO *NOT* USE */ + NSERROR_NOMEM, /**< Memory exhaustion */ + NSERROR_NO_FETCH_HANDLER, /**< No fetch handler for URL scheme */ + NSERROR_NOT_FOUND, /**< Requested item not found */ + NSERROR_NOT_DIRECTORY, /**< Missing directory */ + NSERROR_SAVE_FAILED, /**< Failed to save data */ + NSERROR_CLONE_FAILED, /**< Failed to clone handle */ + NSERROR_INIT_FAILED, /**< Initialisation failed */ + NSERROR_BMP_ERROR, /**< A BMP error occurred */ + NSERROR_GIF_ERROR, /**< A GIF error occurred */ + NSERROR_ICO_ERROR, /**< A ICO error occurred */ + NSERROR_PNG_ERROR, /**< A PNG error occurred */ + NSERROR_SPRITE_ERROR, /**< A RISC OS Sprite error occurred */ + NSERROR_SVG_ERROR, /**< A SVG error occurred */ + NSERROR_BAD_ENCODING, /**< The character set is unknown */ + NSERROR_NEED_DATA, /**< More data needed */ + NSERROR_ENCODING_CHANGE, /**< The character changed */ + NSERROR_BAD_PARAMETER, /**< Bad Parameter */ + NSERROR_INVALID, /**< Invalid data */ + NSERROR_BOX_CONVERT, /**< Box conversion failed */ + NSERROR_STOPPED, /**< Content conversion stopped */ + NSERROR_DOM, /**< DOM call returned error */ + NSERROR_CSS, /**< CSS call returned error */ NSERROR_CSS_BASE, /**< CSS base sheet failed */ - - NSERROR_BAD_URL, /**< Bad URL */ - - NSERROR_BAD_CONTENT, /**< Bad Content */ - + NSERROR_BAD_URL, /**< Bad URL */ + NSERROR_BAD_CONTENT, /**< Bad Content */ NSERROR_FRAME_DEPTH, /**< Exceeded frame depth */ - NSERROR_PERMISSION, /**< Permission error */ - - NSERROR_NOSPACE, /**< Insufficient space */ - + NSERROR_NOSPACE, /**< Insufficient space */ NSERROR_BAD_SIZE, /**< Bad size */ - NSERROR_NOT_IMPLEMENTED, /**< Functionality is not implemented */ } nserror; 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/jenkins-build.sh b/utils/jenkins-build.sh index b6ca21dd7..6fd6a777a 100755 --- a/utils/jenkins-build.sh +++ b/utils/jenkins-build.sh @@ -147,6 +147,23 @@ case ${TARGET} in ;; + "amigaos3") + case ${HOST} in + "m68k-unknown-amigaos") + ;; + + *) + echo "Target \"${TARGET}\" cannot be built on \"${HOST})\"" + exit 1 + ;; + + esac + + PKG_SRC=NetSurf_Amiga/netsurf + PKG_SFX=.lha + ;; + + "atari") case ${HOST} in "m68k-atari-mint") @@ -291,6 +308,11 @@ case ${TARGET} in export GCCSDK_INSTALL_CROSSBIN=/opt/netsurf/${HOST}/cross/bin ;; + "m68k-unknown-amigaos") + export GCCSDK_INSTALL_ENV=/opt/netsurf/${HOST}/env + export GCCSDK_INSTALL_CROSSBIN=/opt/netsurf/${HOST}/cross/bin + ;; + *) echo "Target \"${TARGET}\" cannot be built on \"${HOST})\"" exit 1 diff --git a/utils/log.c b/utils/log.c index 15a7a9e75..e267b3179 100644 --- a/utils/log.c +++ b/utils/log.c @@ -1,9 +1,5 @@ /* - * Copyright 2007 Rob Kendrick <rjek@netsurf-browser.org> - * Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net> - * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net> - * Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk> - * Copyright 2004 John Tytgat <joty@netsurf-browser.org> + * Copyright 2017 Vincent Sanders <vince@netsurf-browser.org> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -24,6 +20,7 @@ #include <stdio.h> #include "utils/config.h" +#include "utils/nsoption.h" #include "utils/sys_time.h" #include "utils/utsname.h" #include "desktop/version.h" @@ -36,6 +33,154 @@ bool verbose_log = false; /** The stream to which logging is sent */ static FILE *logfile; +/** Subtract the `struct timeval' values X and Y + * + * \param result The timeval structure to store the result in + * \param x The first value + * \param y The second value + * \return 1 if the difference is negative, otherwise 0. + */ +static int +timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) +{ + /* Perform the carry for the later subtraction by updating y. */ + if (x->tv_usec < y->tv_usec) { + int nsec = (int)(y->tv_usec - x->tv_usec) / 1000000 + 1; + y->tv_usec -= 1000000 * nsec; + y->tv_sec += nsec; + } + if ((int)(x->tv_usec - y->tv_usec) > 1000000) { + int nsec = (int)(x->tv_usec - y->tv_usec) / 1000000; + y->tv_usec += 1000000 * nsec; + y->tv_sec -= nsec; + } + + /* Compute the time remaining to wait. + tv_usec is certainly positive. */ + result->tv_sec = x->tv_sec - y->tv_sec; + result->tv_usec = x->tv_usec - y->tv_usec; + + /* Return 1 if result is negative. */ + return x->tv_sec < y->tv_sec; +} + +/** + * Obtain a formatted string suitable for prepending to a log message + * + * \return formatted string of the time since first log call + */ +static const char *nslog_gettime(void) +{ + static struct timeval start_tv; + static char buff[32]; + + struct timeval tv; + struct timeval now_tv; + + if (!timerisset(&start_tv)) { + gettimeofday(&start_tv, NULL); + } + gettimeofday(&now_tv, NULL); + + timeval_subtract(&tv, &now_tv, &start_tv); + + snprintf(buff, sizeof(buff),"(%ld.%06ld)", + (long)tv.tv_sec, (long)tv.tv_usec); + + return buff; +} + +#ifdef WITH_NSLOG + +NSLOG_DEFINE_CATEGORY(netsurf, "NetSurf default logging"); +NSLOG_DEFINE_CATEGORY(llcache, "Low level cache"); +NSLOG_DEFINE_CATEGORY(fetch, "objet fetching"); +NSLOG_DEFINE_CATEGORY(plot, "rendering system"); +NSLOG_DEFINE_CATEGORY(schedule, "scheduler"); +NSLOG_DEFINE_CATEGORY(fbtk, "Framebuffer toolkit"); +NSLOG_DEFINE_CATEGORY(layout, "Layout"); + +static void +netsurf_render_log(void *_ctx, + nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + fprintf(logfile, + "%s %.*s:%i %.*s: ", + nslog_gettime(), + ctx->filenamelen, + ctx->filename, + ctx->lineno, + ctx->funcnamelen, + ctx->funcname); + + vfprintf(logfile, fmt, args); + + /* Log entries aren't newline terminated add one for clarity */ + fputc('\n', logfile); +} + +/* exported interface documented in utils/log.h */ +nserror +nslog_set_filter(const char *filter) +{ + nslog_error err; + nslog_filter_t *filt = NULL; + + err = nslog_filter_from_text(filter, &filt); + if (err != NSLOG_NO_ERROR) { + if (err == NSLOG_NO_MEMORY) + return NSERROR_NOMEM; + else + return NSERROR_INVALID; + } + + err = nslog_filter_set_active(filt, NULL); + filt = nslog_filter_unref(filt); + if (err != NSLOG_NO_ERROR) { + return NSERROR_NOSPACE; + } + + return NSERROR_OK; +} + +#else + +void +nslog_log(const char *file, const char *func, int ln, const char *format, ...) +{ + va_list ap; + + if (verbose_log) { + fprintf(logfile, + "%s %s:%i %s: ", + nslog_gettime(), + file, + ln, + func); + + va_start(ap, format); + + vfprintf(logfile, format, ap); + + va_end(ap); + + fputc('\n', logfile); + } +} + +/* exported interface documented in utils/log.h */ +nserror +nslog_set_filter(const char *filter) +{ + (void)(filter); + return NSERROR_OK; +} + + +#endif + nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) { struct utsname utsname; @@ -59,9 +204,9 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) /* ensure we actually show logging */ verbose_log = true; } else if (((*pargc) > 2) && - (argv[1][0] == '-') && - (argv[1][1] == 'V') && - (argv[1][2] == 0)) { + (argv[1][0] == '-') && + (argv[1][1] == 'V') && + (argv[1][2] == 0)) { int argcmv; /* verbose logging to file */ @@ -82,7 +227,7 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) /* ensure we actually show logging */ verbose_log = true; } - } else if (verbose_log == true) { + } else { /* default is logging to stderr */ logfile = stderr; } @@ -96,94 +241,65 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) verbose_log = false; } +#ifdef WITH_NSLOG + + if (nslog_set_filter(verbose_log ? + NETSURF_BUILTIN_VERBOSE_FILTER : + NETSURF_BUILTIN_LOG_FILTER) != NSERROR_OK) { + ret = NSERROR_INIT_FAILED; + verbose_log = false; + } else if (nslog_set_render_callback(netsurf_render_log, NULL) != NSLOG_NO_ERROR) { + ret = NSERROR_INIT_FAILED; + verbose_log = false; + } else if (nslog_uncork() != NSLOG_NO_ERROR) { + ret = NSERROR_INIT_FAILED; + verbose_log = false; + } + +#endif + /* sucessfull logging initialisation so log system info */ if (ret == NSERROR_OK) { - LOG("NetSurf version '%s'", netsurf_version); + NSLOG(netsurf, INFO, "NetSurf version '%s'", netsurf_version); if (uname(&utsname) < 0) { - LOG("Failed to extract machine information"); + NSLOG(netsurf, INFO, + "Failed to extract machine information"); } else { - LOG("NetSurf on <%s>, node <%s>, release <%s>, version <%s>, machine <%s>", - utsname.sysname, - utsname.nodename, - utsname.release, - utsname.version, - utsname.machine); + NSLOG(netsurf, INFO, + "NetSurf on <%s>, node <%s>, release <%s>, version <%s>, machine <%s>", + utsname.sysname, + utsname.nodename, + utsname.release, + utsname.version, + utsname.machine); } } return ret; } -#ifndef NDEBUG - -/* Subtract the `struct timeval' values X and Y, - storing the result in RESULT. - Return 1 if the difference is negative, otherwise 0. -*/ - -static int -timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) +/* exported interface documented in utils/log.h */ +nserror +nslog_set_filter_by_options() { - /* Perform the carry for the later subtraction by updating y. */ - if (x->tv_usec < y->tv_usec) { - int nsec = (int)(y->tv_usec - x->tv_usec) / 1000000 + 1; - y->tv_usec -= 1000000 * nsec; - y->tv_sec += nsec; - } - if ((int)(x->tv_usec - y->tv_usec) > 1000000) { - int nsec = (int)(x->tv_usec - y->tv_usec) / 1000000; - y->tv_usec += 1000000 * nsec; - y->tv_sec -= nsec; - } - - /* Compute the time remaining to wait. - tv_usec is certainly positive. */ - result->tv_sec = x->tv_sec - y->tv_sec; - result->tv_usec = x->tv_usec - y->tv_usec; - - /* Return 1 if result is negative. */ - return x->tv_sec < y->tv_sec; + if (verbose_log) + return nslog_set_filter(nsoption_charp(verbose_filter)); + else + return nslog_set_filter(nsoption_charp(log_filter)); } -/** - * Obtain a formatted string suitable for prepending to a log message - * - * \return formatted string of the time since first log call - */ -static const char *nslog_gettime(void) +/* exported interface documented in utils/log.h */ +void +nslog_finalise() { - static struct timeval start_tv; - static char buff[32]; - - struct timeval tv; - struct timeval now_tv; - - if (!timerisset(&start_tv)) { - gettimeofday(&start_tv, NULL); + NSLOG(netsurf, INFO, + "Finalising logging, please report any further messages"); + verbose_log = true; + if (logfile != stderr) { + fclose(logfile); + logfile = stderr; } - gettimeofday(&now_tv, NULL); - - timeval_subtract(&tv, &now_tv, &start_tv); - - snprintf(buff, sizeof(buff),"(%ld.%06ld)", - (long)tv.tv_sec, (long)tv.tv_usec); - - return buff; -} - -void nslog_log(const char *file, const char *func, int ln, const char *format, ...) -{ - va_list ap; - - fprintf(logfile, "%s %s:%i %s: ", nslog_gettime(), file, ln, func); - - va_start(ap, format); - - vfprintf(logfile, format, ap); - - va_end(ap); - - fputc('\n', logfile); -} - +#ifdef WITH_NSLOG + nslog_cleanup(); #endif +} diff --git a/utils/log.h b/utils/log.h index 708016b18..b773ec4a2 100644 --- a/utils/log.h +++ b/utils/log.h @@ -17,8 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _NETSURF_LOG_H_ -#define _NETSURF_LOG_H_ +#ifndef NETSURF_LOG_H +#define NETSURF_LOG_H #include <stdio.h> #include <stdbool.h> @@ -43,9 +43,59 @@ typedef bool(nslog_ensure_t)(FILE *fptr); */ extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv); -#ifdef NDEBUG -# define LOG(format, ...) ((void) 0) -#else +/** + * Shut down the logging system. + * + * Shuts down the logging subsystem, resetting to verbose logging and output + * to stderr. Note, if logging is done after calling this, it will be sent + * to stderr without filtering. + */ +extern void nslog_finalise(void); + +/** + * Set the logging filter. + * + * Compiles and enables the given logging filter. + */ +extern nserror nslog_set_filter(const char *filter); + +/** + * Set the logging filter according to the options. + */ +extern nserror nslog_set_filter_by_options(void); + +/* ensure a logging level is defined */ +#ifndef NETSURF_LOG_LEVEL +#define NETSURF_LOG_LEVEL INFO +#endif + +#define NSLOG_LVL(level) NSLOG_LEVEL_ ## level +#define NSLOG_EVL(level) NSLOG_LVL(level) +#define NSLOG_COMPILED_MIN_LEVEL NSLOG_EVL(NETSURF_LOG_LEVEL) + +#ifdef WITH_NSLOG + +#include <nslog/nslog.h> + +NSLOG_DECLARE_CATEGORY(netsurf); +NSLOG_DECLARE_CATEGORY(llcache); +NSLOG_DECLARE_CATEGORY(fetch); +NSLOG_DECLARE_CATEGORY(plot); +NSLOG_DECLARE_CATEGORY(schedule); +NSLOG_DECLARE_CATEGORY(fbtk); +NSLOG_DECLARE_CATEGORY(layout); + +#else /* WITH_NSLOG */ + +enum nslog_level { + NSLOG_LEVEL_DEEPDEBUG = 0, + NSLOG_LEVEL_DEBUG = 1, + NSLOG_LEVEL_VERBOSE = 2, + NSLOG_LEVEL_INFO = 3, + NSLOG_LEVEL_WARNING = 4, + NSLOG_LEVEL_ERROR = 5, + NSLOG_LEVEL_CRITICAL = 6 +}; extern void nslog_log(const char *file, const char *func, int ln, const char *format, ...) __attribute__ ((format (printf, 4, 5))); @@ -60,13 +110,13 @@ extern void nslog_log(const char *file, const char *func, int ln, const char *fo # define LOG_LN __LINE__ # endif -#define LOG(format, args...) \ +#define NSLOG(catname, level, logmsg, args...) \ do { \ - if (verbose_log) { \ - nslog_log(__FILE__, LOG_FN, LOG_LN, format , ##args); \ + if (NSLOG_LEVEL_##level >= NSLOG_COMPILED_MIN_LEVEL) { \ + nslog_log(__FILE__, LOG_FN, LOG_LN, logmsg , ##args); \ } \ } while(0) -#endif +#endif /* WITH_NSLOG */ #endif diff --git a/utils/messages.c b/utils/messages.c index 0c558cdfc..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; @@ -338,6 +345,10 @@ const char *messages_get_errorcode(nserror code) /* Requested item not found */ return messages_get_ctx("NotFound", messages_hash); + case NSERROR_NOT_DIRECTORY: + /* Missing directory */ + return messages_get_ctx("NotDirectory", messages_hash); + case NSERROR_SAVE_FAILED: /* Failed to save data */ return messages_get_ctx("SaveFailed", messages_hash); @@ -350,9 +361,29 @@ const char *messages_get_errorcode(nserror code) /* Initialisation failed */ return messages_get_ctx("InitFailed", messages_hash); - case NSERROR_MNG_ERROR: - /* An MNG error occurred */ - return messages_get_ctx("MNGError", messages_hash); + case NSERROR_BMP_ERROR: + /* A BMP error occurred */ + return messages_get_ctx("BMPError", messages_hash); + + case NSERROR_GIF_ERROR: + /* A GIF error occurred */ + return messages_get_ctx("GIFError", messages_hash); + + case NSERROR_ICO_ERROR: + /* A ICO error occurred */ + return messages_get_ctx("ICOError", messages_hash); + + case NSERROR_PNG_ERROR: + /* A PNG error occurred */ + return messages_get_ctx("PNGError", messages_hash); + + case NSERROR_SPRITE_ERROR: + /* A RISC OS Sprite error occurred */ + return messages_get_ctx("SpriteError", messages_hash); + + case NSERROR_SVG_ERROR: + /* A SVG error occurred */ + return messages_get_ctx("SVGError", messages_hash); case NSERROR_BAD_ENCODING: /* The character set is unknown */ @@ -398,12 +429,40 @@ const char *messages_get_errorcode(nserror code) /* Bad URL */ return messages_get_ctx("BadURL", messages_hash); - default: + case NSERROR_BAD_CONTENT: + /* Bad Content */ + return messages_get_ctx("BadContent", messages_hash); + + case NSERROR_FRAME_DEPTH: + /* Exceeded frame depth */ + return messages_get_ctx("FrameDepth", messages_hash); + + case NSERROR_PERMISSION: + /* Permission error */ + return messages_get_ctx("PermissionError", messages_hash); + + case NSERROR_BAD_SIZE: + /* Bad size */ + return messages_get_ctx("BadSize", messages_hash); + + case NSERROR_NOSPACE: + /* Insufficient space */ + return messages_get_ctx("NoSpace", messages_hash); + + case NSERROR_NOT_IMPLEMENTED: + /* Functionality is not implemented */ + return messages_get_ctx("NotImplemented", messages_hash); + case NSERROR_UNKNOWN: - break; + /* Unknown error */ + return messages_get_ctx("Unknown", messages_hash); } - /* Unknown error */ + /* The switch has no default, so the compiler should tell us when we + * forget to add messages for new error codes. As such, we should + * never get here. + */ + assert(0); return messages_get_ctx("Unknown", messages_hash); } diff --git a/utils/nsoption.c b/utils/nsoption.c index 8f05a911b..09529a0d0 100644 --- a/utils/nsoption.c +++ b/utils/nsoption.c @@ -187,7 +187,7 @@ static void nsoption_validate(struct nsoption_s *opts, struct nsoption_s *defs) break; } } - if (black == true) { + if (black == true && defs != NULL) { for (cloop = NSOPTION_SYS_COLOUR_START; cloop <= NSOPTION_SYS_COLOUR_END; cloop++) { @@ -209,6 +209,9 @@ static void nsoption_validate(struct nsoption_s *opts, struct nsoption_s *defs) opts[NSOPTION_max_retried_fetches].value.u) > 60) && (opts[NSOPTION_max_retried_fetches].value.u > 1)) opts[NSOPTION_max_retried_fetches].value.u--; + + /* We ignore the result because we can't fail to validate. Yay */ + (void)nslog_set_filter_by_options(); } /** @@ -648,11 +651,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 +722,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 +803,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; @@ -818,6 +823,8 @@ nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts) } *pargc -= (idx - 1); + nsoption_validate(opts, nsoptions_default); + return NSERROR_OK; } 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/nsurl/private.h b/utils/nsurl/private.h index 89d7ed49e..bc6737cd6 100644 --- a/utils/nsurl/private.h +++ b/utils/nsurl/private.h @@ -187,28 +187,44 @@ static inline void nsurl__components_destroy(struct nsurl_components *c) static inline void nsurl__dump(const nsurl *url) { if (url->components.scheme) - LOG(" Scheme: %s", lwc_string_data(url->components.scheme)); + NSLOG(netsurf, INFO,netsurf, INFO, + " Scheme: %s", + lwc_string_data(url->components.scheme)); if (url->components.username) - LOG("Username: %s", lwc_string_data(url->components.username)); + NSLOG(netsurf, INFO, + "Username: %s", + lwc_string_data(url->components.username)); if (url->components.password) - LOG("Password: %s", lwc_string_data(url->components.password)); + NSLOG(netsurf, INFO, + "Password: %s", + lwc_string_data(url->components.password)); if (url->components.host) - LOG(" Host: %s", lwc_string_data(url->components.host)); + NSLOG(netsurf, INFO, + " Host: %s", + lwc_string_data(url->components.host)); if (url->components.port) - LOG(" Port: %s", lwc_string_data(url->components.port)); + NSLOG(netsurf, INFO, + " Port: %s", + lwc_string_data(url->components.port)); if (url->components.path) - LOG(" Path: %s", lwc_string_data(url->components.path)); + NSLOG(netsurf, INFO, + " Path: %s", + lwc_string_data(url->components.path)); if (url->components.query) - LOG(" Query: %s", lwc_string_data(url->components.query)); + NSLOG(netsurf, INFO, + " Query: %s", + lwc_string_data(url->components.query)); if (url->components.fragment) - LOG("Fragment: %s", lwc_string_data(url->components.fragment)); + NSLOG(netsurf, INFO, + "Fragment: %s", + lwc_string_data(url->components.fragment)); } #endif 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); |