2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2007-05-06 10:11:00 +04:00
|
|
|
* Copyright 2007 James Bursa <bursa@users.sourceforge.net>
|
2004-07-27 00:13:45 +04:00
|
|
|
* Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-09-11 18:24:02 +04:00
|
|
|
*/
|
|
|
|
|
2008-10-14 03:32:21 +04:00
|
|
|
#include <locale.h>
|
2007-10-31 18:39:55 +03:00
|
|
|
#include <signal.h>
|
2003-11-06 22:41:41 +03:00
|
|
|
#include <stdbool.h>
|
2004-09-27 09:21:00 +04:00
|
|
|
#include <stdio.h>
|
2003-11-06 22:41:41 +03:00
|
|
|
#include <stdlib.h>
|
2010-01-31 03:36:02 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
#include <libwapcaplet/libwapcaplet.h>
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2010-01-31 03:36:02 +03:00
|
|
|
#include "utils/utsname.h"
|
2011-05-17 01:16:44 +04:00
|
|
|
#include "content/content_factory.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/fetch.h"
|
2010-04-12 00:21:13 +04:00
|
|
|
#include "content/hlcache.h"
|
2011-09-04 10:28:09 +04:00
|
|
|
#include "content/mimesniff.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
2011-02-26 04:19:11 +03:00
|
|
|
#include "css/css.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "image/image.h"
|
2011-09-07 13:15:33 +04:00
|
|
|
#include "image/image_cache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/netsurf.h"
|
2010-04-15 03:03:49 +04:00
|
|
|
#include "desktop/401login.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/gui.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2011-01-20 16:51:41 +03:00
|
|
|
#include "desktop/searchweb.h"
|
2012-06-11 02:17:30 +04:00
|
|
|
|
|
|
|
#include "javascript/js.h"
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "render/html.h"
|
|
|
|
#include "render/textplain.h"
|
2012-07-22 18:48:55 +04:00
|
|
|
#include "utils/corestrings.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/utils.h"
|
2010-03-30 00:03:44 +04:00
|
|
|
#include "utils/messages.h"
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2011-09-07 13:15:33 +04:00
|
|
|
/** speculative pre-conversion small image size
|
|
|
|
*
|
|
|
|
* Experimenting by visiting every page from default page in order and
|
|
|
|
* then netsurf homepage
|
|
|
|
*
|
|
|
|
* 0 : Cache hit/miss/speculative miss/fail 604/147/ 0/0 (80%/19%/ 0%/ 0%)
|
|
|
|
* 2048 : Cache hit/miss/speculative miss/fail 622/119/ 17/0 (82%/15%/ 2%/ 0%)
|
|
|
|
* 4096 : Cache hit/miss/speculative miss/fail 656/109/ 25/0 (83%/13%/ 3%/ 0%)
|
|
|
|
* 8192 : Cache hit/miss/speculative miss/fail 648/104/ 40/0 (81%/13%/ 5%/ 0%)
|
|
|
|
* ALL : Cache hit/miss/speculative miss/fail 775/ 0/161/0 (82%/ 0%/17%/ 0%)
|
|
|
|
*/
|
|
|
|
#define SPECULATE_SMALL 4096
|
|
|
|
|
|
|
|
/* the time between cache clean runs in ms */
|
|
|
|
#define IMAGE_CACHE_CLEAN_TIME (10 * 1000)
|
|
|
|
|
2011-09-10 04:55:39 +04:00
|
|
|
#define HL_CACHE_CLEAN_TIME (2 * IMAGE_CACHE_CLEAN_TIME)
|
2011-09-08 16:04:57 +04:00
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
bool netsurf_quit = false;
|
2007-05-31 02:27:58 +04:00
|
|
|
bool verbose_log = false;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2010-04-28 02:14:52 +04:00
|
|
|
static void netsurf_lwc_iterator(lwc_string *str, void *pw)
|
|
|
|
{
|
2012-07-22 23:24:33 +04:00
|
|
|
LOG(("[%3u] %.*s", str->refcnt, (int) lwc_string_length(str), lwc_string_data(str)));
|
2010-04-28 02:14:52 +04:00
|
|
|
}
|
|
|
|
|
2010-04-15 03:03:49 +04:00
|
|
|
/**
|
|
|
|
* Dispatch a low-level cache query to the frontend
|
|
|
|
*
|
|
|
|
* \param query Query descriptor
|
|
|
|
* \param pw Private data
|
|
|
|
* \param cb Continuation callback
|
|
|
|
* \param cbpw Private data for continuation
|
|
|
|
* \return NSERROR_OK
|
|
|
|
*/
|
|
|
|
static nserror netsurf_llcache_query_handler(const llcache_query *query,
|
|
|
|
void *pw, llcache_query_response cb, void *cbpw)
|
|
|
|
{
|
|
|
|
switch (query->type) {
|
|
|
|
case LLCACHE_QUERY_AUTH:
|
2012-10-11 14:20:02 +04:00
|
|
|
gui_401login_open(query->url, query->data.auth.realm, cb, cbpw);
|
2010-04-15 03:03:49 +04:00
|
|
|
break;
|
|
|
|
case LLCACHE_QUERY_REDIRECT:
|
|
|
|
/** \todo Need redirect query dialog */
|
|
|
|
/* For now, do nothing, as this query type isn't emitted yet */
|
|
|
|
break;
|
|
|
|
case LLCACHE_QUERY_SSL:
|
2012-10-11 14:20:02 +04:00
|
|
|
gui_cert_verify(query->url, query->data.ssl.certs,
|
2010-04-15 03:03:49 +04:00
|
|
|
query->data.ssl.num, cb, cbpw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-10 04:55:39 +04:00
|
|
|
#define MINIMUM_MEMORY_CACHE_SIZE (2 * 1024 * 1024)
|
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
/**
|
|
|
|
* Initialise components used by gui NetSurf.
|
|
|
|
*/
|
|
|
|
|
2010-03-30 00:03:44 +04:00
|
|
|
nserror netsurf_init(int *pargc,
|
|
|
|
char ***pargv,
|
|
|
|
const char *options,
|
|
|
|
const char *messages)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror error;
|
2004-06-15 22:59:54 +04:00
|
|
|
struct utsname utsname;
|
2011-03-19 00:58:29 +03:00
|
|
|
nserror ret = NSERROR_OK;
|
2011-09-08 16:04:57 +04:00
|
|
|
struct hlcache_parameters hlcache_parameters = {
|
|
|
|
.bg_clean_time = HL_CACHE_CLEAN_TIME,
|
|
|
|
.cb = netsurf_llcache_query_handler,
|
|
|
|
};
|
2011-09-07 13:15:33 +04:00
|
|
|
struct image_cache_parameters image_cache_parameters = {
|
|
|
|
.bg_clean_time = IMAGE_CACHE_CLEAN_TIME,
|
|
|
|
.speculative_small = SPECULATE_SMALL
|
|
|
|
};
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2010-01-31 03:36:02 +03:00
|
|
|
#ifdef HAVE_SIGPIPE
|
2007-10-31 18:39:55 +03:00
|
|
|
/* Ignore SIGPIPE - this is necessary as OpenSSL can generate these
|
|
|
|
* and the default action is to terminate the app. There's no easy
|
|
|
|
* way of determining the cause of the SIGPIPE (other than using
|
|
|
|
* sigaction() and some mechanism for getting the file descriptor
|
|
|
|
* out of libcurl). However, we expect nothing else to generate a
|
2013-05-23 12:29:00 +04:00
|
|
|
* SIGPIPE, anyway, so may as well just ignore them all.
|
|
|
|
*/
|
2007-10-31 18:39:55 +03:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2010-01-31 03:36:02 +03:00
|
|
|
#endif
|
2007-10-31 18:39:55 +03:00
|
|
|
|
2004-06-15 22:59:54 +04:00
|
|
|
LOG(("version '%s'", netsurf_version));
|
2007-06-16 02:07:11 +04:00
|
|
|
if (uname(&utsname) < 0)
|
2004-07-29 03:07:52 +04:00
|
|
|
LOG(("Failed to extract machine information"));
|
2004-06-15 22:59:54 +04:00
|
|
|
else
|
|
|
|
LOG(("NetSurf on <%s>, node <%s>, release <%s>, version <%s>, "
|
2004-07-29 02:38:17 +04:00
|
|
|
"machine <%s>", utsname.sysname,
|
2004-06-15 22:59:54 +04:00
|
|
|
utsname.nodename, utsname.release,
|
|
|
|
utsname.version, utsname.machine));
|
2005-07-11 22:10:10 +04:00
|
|
|
|
2010-03-30 00:03:44 +04:00
|
|
|
LOG(("Using '%s' for Options file", options));
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_read(options);
|
2012-10-17 17:20:18 +04:00
|
|
|
gui_options_init_defaults();
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2010-07-28 19:22:44 +04:00
|
|
|
messages_load(messages);
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
/* corestrings init */
|
|
|
|
error = corestrings_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
|
2011-09-10 04:55:39 +04:00
|
|
|
/* set up cache limits based on the memory cache size option */
|
2012-03-22 13:34:34 +04:00
|
|
|
hlcache_parameters.limit = nsoption_int(memory_cache_size);
|
2011-09-10 04:55:39 +04:00
|
|
|
|
|
|
|
if (hlcache_parameters.limit < MINIMUM_MEMORY_CACHE_SIZE) {
|
|
|
|
hlcache_parameters.limit = MINIMUM_MEMORY_CACHE_SIZE;
|
|
|
|
LOG(("Setting minimum memory cache size to %d",
|
|
|
|
hlcache_parameters.limit));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* image cache is 25% of total memory cache size */
|
|
|
|
image_cache_parameters.limit = (hlcache_parameters.limit * 25) / 100;
|
|
|
|
|
|
|
|
/* image cache hysteresis is 20% of teh image cache size */
|
|
|
|
image_cache_parameters.hysteresis = (image_cache_parameters.limit * 20) / 100;
|
|
|
|
|
|
|
|
/* account for image cache use from total */
|
|
|
|
hlcache_parameters.limit -= image_cache_parameters.limit;
|
|
|
|
|
2011-09-07 13:15:33 +04:00
|
|
|
/* image handler bitmap cache */
|
|
|
|
error = image_cache_init(&image_cache_parameters);
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* content handler initialisation */
|
2011-09-16 02:47:50 +04:00
|
|
|
error = nscss_init();
|
2011-05-07 00:40:09 +04:00
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
error = html_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
error = image_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
error = textplain_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
|
2011-09-07 13:15:33 +04:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
error = mimesniff_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
url_init();
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2008-10-14 03:32:21 +04:00
|
|
|
setlocale(LC_ALL, "C");
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2004-06-15 22:59:54 +04:00
|
|
|
fetch_init();
|
2011-03-13 21:26:46 +03:00
|
|
|
|
|
|
|
/* Initialise the hlcache and allow it to init the llcache for us */
|
2011-09-08 16:04:57 +04:00
|
|
|
hlcache_initialise(&hlcache_parameters);
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2011-01-30 16:40:47 +03:00
|
|
|
/* Initialize system colours */
|
|
|
|
gui_system_colour_init();
|
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_commandline(pargc, *pargv);
|
2011-03-19 00:58:29 +03:00
|
|
|
|
2012-01-02 01:42:38 +04:00
|
|
|
js_initialise();
|
|
|
|
|
2011-03-19 00:58:29 +03:00
|
|
|
return ret;
|
2002-11-03 12:39:53 +03:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
/**
|
2010-03-28 16:56:39 +04:00
|
|
|
* Gui NetSurf main loop.
|
2003-11-06 22:41:41 +03:00
|
|
|
*/
|
2010-03-28 16:56:39 +04:00
|
|
|
int netsurf_main_loop(void)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
while (!netsurf_quit) {
|
|
|
|
gui_poll(fetch_active);
|
2010-04-12 00:21:13 +04:00
|
|
|
hlcache_poll();
|
2008-07-07 18:05:29 +04:00
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
/**
|
|
|
|
* Clean up components used by gui NetSurf.
|
|
|
|
*/
|
2002-10-15 14:41:12 +04:00
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
void netsurf_exit(void)
|
|
|
|
{
|
2011-03-13 23:20:31 +03:00
|
|
|
hlcache_stop();
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
LOG(("Closing GUI"));
|
2004-06-15 22:59:54 +04:00
|
|
|
gui_quit();
|
2012-06-30 00:37:32 +04:00
|
|
|
|
|
|
|
LOG(("Finalising JavaScript"));
|
|
|
|
js_finalise();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2011-01-20 16:51:41 +03:00
|
|
|
LOG(("Closing search and related resources"));
|
|
|
|
search_web_cleanup();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2010-12-16 03:03:57 +03:00
|
|
|
LOG(("Finalising high-level cache"));
|
|
|
|
hlcache_finalise();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
LOG(("Closing fetches"));
|
2004-07-30 20:16:07 +04:00
|
|
|
fetch_quit();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
mimesniff_fini();
|
|
|
|
|
2011-09-07 13:15:33 +04:00
|
|
|
/* dump any remaining cache entries */
|
|
|
|
image_cache_fini();
|
|
|
|
|
2011-09-16 02:47:50 +04:00
|
|
|
/* Clean up after content handlers */
|
2011-05-17 01:16:44 +04:00
|
|
|
content_factory_fini();
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
LOG(("Closing utf8"));
|
2005-07-11 22:10:10 +04:00
|
|
|
utf8_finalise();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2006-12-09 01:38:46 +03:00
|
|
|
LOG(("Destroying URLdb"));
|
|
|
|
urldb_destroy();
|
2011-01-30 16:40:47 +03:00
|
|
|
|
|
|
|
LOG(("Destroying System colours"));
|
|
|
|
gui_system_colour_finalize();
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
corestrings_fini();
|
2010-04-28 02:14:52 +04:00
|
|
|
LOG(("Remaining lwc strings:"));
|
|
|
|
lwc_iterate_strings(netsurf_lwc_iterator, NULL);
|
2011-01-30 16:40:47 +03:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
LOG(("Exited successfully"));
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
2004-07-06 00:19:52 +04:00
|
|
|
|
|
|
|
|