22#include <sys/select.h>
56#define LANGS_SIZE 4096
70static void die(
const char *
const error)
87 lang = getenv(
"LANGUAGE");
88 if ((lang != NULL) && (lang[0] !=
'\0')) {
92 lang = getenv(
"LC_ALL");
93 if ((lang != NULL) && (lang[0] !=
'\0')) {
97 lang = getenv(
"LC_MESSAGES");
98 if ((lang != NULL) && (lang[0] !=
'\0')) {
102 lang = getenv(
"LANG");
103 if ((lang != NULL) && (lang[0] !=
'\0')) {
137 if (langv[0] != NULL) {
146 lang_len = strlen(lange) + 1;
148 memcpy(curp, lange, lang_len);
149 while ((curp[0] != 0) &&
152 cln = strchr(curp,
':');
154 langv[langidx++] = curp;
158 if ((cln - curp) > 1) {
160 langv[langidx++] = curp;
163 lang_len -= (cln - curp);
171 langv[langidx++] = curp;
174 langv[langidx] = NULL;
192 const char *
const *langv;
222 if (search_term != NULL) {
279 fd_set read_fd_set, write_fd_set, exc_fd_set;
284 struct timeval* timeout;
292 fetch_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
298 FD_SET(0, &read_fd_set);
299 FD_SET(0, &exc_fd_set);
304 NSLOG(netsurf, INFO,
"Iterate blocking");
310 NSLOG(netsurf, INFO,
"Iterate immediate");
317 NSLOG(netsurf, INFO,
"Iterate non-blocking");
319 tv.tv_sec = schedtm / 1000;
320 tv.tv_usec = (schedtm % 1000) * 1000;
325 rdy_fd = select(max_fd + 1,
331 NSLOG(netsurf, CRITICAL,
"Unable to select: %s", strerror(errno));
333 }
else if (rdy_fd > 0) {
334 if (FD_ISSET(0, &read_fd_set)) {
341#if (!defined(NDEBUG) && defined(HAVE_EXECINFO))
343static void *backtrace_buffer[4096];
346__assert_fail(
const char *__assertion,
const char *__file,
347 unsigned int __line,
const char *__function)
351 "MONKEY: Assertion failure!\n"
352 "%s:%d: %s: Assertion `%s` failed.\n",
353 __file, __line, __function, __assertion);
355 frames = backtrace(&backtrace_buffer[0], 4096);
356 if (frames > 0 && frames < 4096) {
357 fprintf(stderr,
"Backtrace:\n");
359 backtrace_symbols_fd(&backtrace_buffer[0], frames, 2);
366signal_handler(
int sig)
369 fprintf(stderr,
"Caught signal %s (%d)\n",
370 ((sig == SIGSEGV) ?
"SIGSEGV" :
371 ((sig == SIGILL) ?
"SIGILL" :
372 ((sig == SIGFPE) ?
"SIGFPE" :
373 ((sig == SIGBUS) ?
"SIGBUS" :
374 "unknown signal")))),
376 frames = backtrace(&backtrace_buffer[0], 4096);
377 if (frames > 0 && frames < 4096) {
378 fprintf(stderr,
"Backtrace:\n");
380 backtrace_symbols_fd(&backtrace_buffer[0], frames, 2);
405#if (!defined(NDEBUG) && defined(HAVE_EXECINFO))
407 signal(SIGSEGV, signal_handler);
408 signal(SIGILL, signal_handler);
409 signal(SIGFPE, signal_handler);
411 signal(SIGBUS, signal_handler);
416 die(
"NetSurf operation table failed registration");
421 setbuf(stdout, NULL);
422 setbuf(stderr, NULL);
435 die(
"Options failed to initialise");
445 NSLOG(netsurf, INFO,
"Messages failed to load");
452 die(
"NetSurf failed to initialise");
462 for (
char **s =
respaths; *s != NULL; s++) {
469 die(
"quit handler failed to register");
474 die(
"window handler failed to register");
479 die(
"options handler failed to register");
484 die(
"login handler failed to register");
void monkey_login_handle_command(int argc, char **argv)
Low-level source data cache backing store interface.
struct gui_llcache_table * filesystem_llcache_table
nserror gui_401login_open(struct nsurl *url, const char *realm, const char *username, const char *password, nserror(*cb)(const char *username, const char *password, void *pw), void *cbpw)
nserror fetch_fdset(fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, int *maxfd_out)
Get the set of file descriptors the fetchers are currently using.
Fetching of data from a URL (interface).
Unified cookie database public interface.
void urldb_save_cookies(const char *filename)
Save persistent cookies to file.
void urldb_load_cookies(const char *filename)
Load a cookie file into the database.
void monkey_process_command(void)
nserror monkey_register_handler(const char *cmd, handle_command_fn fn)
void monkey_free_handlers(void)
nserror
Enumeration of error codes.
char ** filepath_path_to_strvec(const char *path)
Convert a colon separated list of path elements into a string vector.
char * filepath_find(char **respathv, const char *filename)
Searches an array of resource paths for a file.
char * filepath_sfinddef(char **respathv, char *filepath, const char *filename, const char *def)
Searches an array of resource paths for a file optionally forcing a default.
void filepath_free_strvec(char **pathv)
Free a string vector.
char ** filepath_generate(char *const *pathv, const char *const *langv)
Merge two string vectors into a resource search path vector.
Utility routines to obtain paths to file resources.
struct gui_bitmap_table * monkey_bitmap_table
void monkey_kill_browser_windows(void)
struct gui_window_table * monkey_window_table
void monkey_window_handle_command(int argc, char **argv)
struct gui_download_table * monkey_download_table
struct gui_fetch_table * monkey_fetch_table
struct gui_layout_table * monkey_layout_table
Interface to platform-specific miscellaneous browser operation table.
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
Initialise the logging system.
void nslog_finalise(void)
Shut down the logging system.
#define NSLOG(catname, level, logmsg, args...)
nserror messages_add_from_file(const char *path)
Read keys and values from messages file into the standard Messages hash.
Localised message support (interface).
void monkey_fetch_filetype_fin(void)
void monkey_fetch_filetype_init(const char *mimefile)
char ** respaths
resource search path vector
static void monkey_run(void)
#define LANGV_SIZE
maximum number of languages in language vector
static nserror gui_launch_url(struct nsurl *url)
int main(int argc, char **argv)
Normal entry point from OS.
static nserror set_defaults(struct nsoption_s *defaults)
Set option defaults for monkey frontend.
static bool nslog_stream_configure(FILE *fptr)
Ensures output logging stream is correctly configured.
static void monkey_options_handle_command(int argc, char **argv)
static const char * get_language(void)
obtain language from environment
#define LANGS_SIZE
maximum length of all strings in language vector
static void die(const char *const error)
Cause an abnormal program termination.
static const char *const * get_languagev(void)
provide a string vector of languages in preference order
static void monkey_quit(void)
static struct gui_misc_table monkey_misc_table
static char ** nsmonkey_init_resource(const char *resource_path)
Create an array of valid paths to search for resources.
static void quit_handler(int argc, char **argv)
static nserror gui_present_cookies(const char *search_term)
nserror monkey_schedule(int tival, void(*callback)(void *p), void *p)
Schedule a callback.
int monkey_schedule_run(void)
Process scheduled callbacks up to current time.
NetSurf core interface registration, construction and destruction.
void netsurf_exit(void)
Finalise NetSurf core.
nserror netsurf_init(const char *store_path)
Initialise netsurf core.
nserror netsurf_register(struct netsurf_table *table)
Register operation table.
NetSurf URL handling (interface).
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
struct nsurl nsurl
NetSurf URL object.
int moutf(enum monkey_output_type mout_type, const char *fmt,...)
Interface to utility string handling.
Graphical user interface browser misc function table.
nserror(* schedule)(int t, void(*callback)(void *p), void *p)
Schedule a callback.
NetSurf operation function table.
struct gui_misc_table * misc
Browser table.
BSD style timeval macros.
Unified URL information database public interface.
nserror urldb_save(const char *filename)
Export the current database to file.
nserror urldb_load(const char *filename)
Import an URL database from file, replacing any existing database.
struct nsoption_s * nsoptions_default
global default option table.
static struct nsoption_s defaults[]
The table of compiled in default options.
nserror nsoption_read(const char *path, struct nsoption_s *opts)
Read choices file and set them in the passed table.
struct nsoption_s * nsoptions
global active option table.
nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts)
Process commandline and set options approriately.
nserror nsoption_init(nsoption_set_default_t *set_defaults, struct nsoption_s **popts, struct nsoption_s **pdefs)
Initialise option system.
nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
Finalise option system.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
#define nsoption_setnull_charp(OPTION, VALUE)
set string option in default table if currently unset