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
|
|
|
|
2007-05-06 10:11:00 +04:00
|
|
|
#include <libxml/encoding.h>
|
|
|
|
#include <libxml/globals.h>
|
|
|
|
#include <libxml/xmlversion.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"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/fetch.h"
|
2010-04-12 00:21:13 +04:00
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/netsurf.h"
|
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/gui.h"
|
2010-03-30 00:03:44 +04:00
|
|
|
#include "desktop/options.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
|
|
|
|
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-03-28 16:56:39 +04:00
|
|
|
static void *netsurf_lwc_alloc(void *ptr, size_t len, void *pw)
|
2008-10-17 00:49:12 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
return realloc(ptr, len);
|
2008-10-17 00:49:12 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2004-06-15 22:59:54 +04:00
|
|
|
struct utsname utsname;
|
|
|
|
|
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
|
|
|
|
* SIGPIPE, anyway, so may as well just ignore them all. */
|
2010-01-31 03:36:02 +03:00
|
|
|
|
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
|
|
|
|
2009-03-02 22:26:11 +03:00
|
|
|
#if !((defined(__SVR4) && defined(__sun)) || defined(__NetBSD__) || \
|
2010-01-31 03:36:02 +03:00
|
|
|
defined(__OpenBSD__) || defined(_WIN32))
|
2004-06-15 22:59:54 +04:00
|
|
|
stdout = stderr;
|
2007-06-16 02:07:11 +04:00
|
|
|
#endif
|
2004-07-29 02:38:17 +04:00
|
|
|
|
2010-03-30 22:20:48 +04:00
|
|
|
if (((*pargc) > 1) &&
|
2010-03-30 00:03:44 +04:00
|
|
|
((*pargv)[1][0] == '-') &&
|
|
|
|
((*pargv)[1][1] == 'v') &&
|
|
|
|
((*pargv)[1][2] == 0)) {
|
2010-01-31 03:36:02 +03:00
|
|
|
int argcmv;
|
|
|
|
verbose_log = true;
|
2010-03-30 00:03:44 +04:00
|
|
|
for (argcmv = 2; argcmv < (*pargc); argcmv++) {
|
|
|
|
(*pargv)[argcmv - 1] = (*pargv)[argcmv];
|
2010-01-31 03:36:02 +03:00
|
|
|
}
|
2010-03-30 00:03:44 +04:00
|
|
|
(*pargc)--;
|
2010-01-31 03:36:02 +03:00
|
|
|
|
|
|
|
#ifndef HAVE_STDOUT
|
|
|
|
gui_stdout();
|
|
|
|
#endif
|
2007-05-31 02:27:58 +04:00
|
|
|
}
|
|
|
|
|
2004-07-29 02:38:17 +04:00
|
|
|
#ifdef _MEMDEBUG_H_
|
|
|
|
memdebug_memdebug("memdump");
|
|
|
|
#endif
|
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));
|
|
|
|
options_read(options);
|
|
|
|
|
2010-04-12 02:40:41 +04:00
|
|
|
if (messages != NULL) {
|
|
|
|
LOG(("Using '%s' as Messages file", messages));
|
|
|
|
messages_load(messages);
|
|
|
|
}
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
lwc_initialise(netsurf_lwc_alloc, NULL, 0);
|
2010-03-30 00:03:44 +04:00
|
|
|
|
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();
|
2010-03-30 00:03:44 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/** \todo The frontend needs to provide the llcache_query_handler */
|
|
|
|
llcache_initialise(NULL, NULL);
|
2010-03-30 00:03:44 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
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)
|
|
|
|
{
|
2006-09-02 19:52:41 +04:00
|
|
|
LOG(("Closing GUI"));
|
2004-06-15 22:59:54 +04:00
|
|
|
gui_quit();
|
2006-09-02 19:52:41 +04:00
|
|
|
LOG(("Closing fetches"));
|
2004-07-30 20:16:07 +04:00
|
|
|
fetch_quit();
|
2006-09-02 19:52:41 +04:00
|
|
|
LOG(("Closing utf8"));
|
2005-07-11 22:10:10 +04:00
|
|
|
utf8_finalise();
|
2006-12-09 01:38:46 +03:00
|
|
|
LOG(("Destroying URLdb"));
|
|
|
|
urldb_destroy();
|
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
|
|
|
|
|
|
|
|