2003-06-30 05:44:03 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2007-05-05 23:11:00 -07:00
|
|
|
* Copyright 2007 James Bursa <bursa@users.sourceforge.net>
|
2004-07-26 13:13:45 -07:00
|
|
|
* Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk>
|
2007-08-08 09:16:03 -07: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 07:24:02 -07:00
|
|
|
*/
|
|
|
|
|
2008-10-13 16:32:21 -07:00
|
|
|
#include <locale.h>
|
2007-10-31 08:39:55 -07:00
|
|
|
#include <signal.h>
|
2003-11-06 11:41:41 -08:00
|
|
|
#include <stdbool.h>
|
2004-09-26 22:21:00 -07:00
|
|
|
#include <stdio.h>
|
2003-11-06 11:41:41 -08:00
|
|
|
#include <stdlib.h>
|
2010-01-30 16:36:02 -08:00
|
|
|
|
2007-05-05 23:11:00 -07:00
|
|
|
#include <libxml/encoding.h>
|
|
|
|
#include <libxml/globals.h>
|
|
|
|
#include <libxml/xmlversion.h>
|
2010-01-30 16:36:02 -08:00
|
|
|
|
2010-03-28 05:56:39 -07:00
|
|
|
#include <libwapcaplet/libwapcaplet.h>
|
|
|
|
|
2007-05-30 15:39:54 -07:00
|
|
|
#include "utils/config.h"
|
2010-01-30 16:36:02 -08:00
|
|
|
#include "utils/utsname.h"
|
2007-05-30 15:39:54 -07:00
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "content/fetchcache.h"
|
2010-03-28 05:56:39 -07:00
|
|
|
#include "content/llcache.h"
|
2007-05-30 15:39:54 -07:00
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/netsurf.h"
|
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/utils.h"
|
2002-09-11 07:24:02 -07:00
|
|
|
|
2003-11-06 11:41:41 -08:00
|
|
|
bool netsurf_quit = false;
|
2007-05-30 15:27:58 -07:00
|
|
|
bool verbose_log = false;
|
2002-09-11 07:24:02 -07:00
|
|
|
|
2010-03-28 05:56:39 -07:00
|
|
|
static void *netsurf_lwc_alloc(void *ptr, size_t len, void *pw)
|
2008-10-16 13:49:12 -07:00
|
|
|
{
|
2010-03-28 05:56:39 -07:00
|
|
|
return realloc(ptr, len);
|
2008-10-16 13:49:12 -07:00
|
|
|
}
|
|
|
|
|
2003-11-06 11:41:41 -08:00
|
|
|
/**
|
|
|
|
* Initialise components used by gui NetSurf.
|
|
|
|
*/
|
|
|
|
|
2002-09-11 07:24:02 -07:00
|
|
|
void netsurf_init(int argc, char** argv)
|
|
|
|
{
|
2004-06-15 11:59:54 -07:00
|
|
|
struct utsname utsname;
|
|
|
|
|
2010-01-30 16:36:02 -08:00
|
|
|
#ifdef HAVE_SIGPIPE
|
2007-10-31 08:39:55 -07: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-30 16:36:02 -08:00
|
|
|
|
2007-10-31 08:39:55 -07:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2010-01-30 16:36:02 -08:00
|
|
|
#endif
|
2007-10-31 08:39:55 -07:00
|
|
|
|
2009-03-02 11:26:11 -08:00
|
|
|
#if !((defined(__SVR4) && defined(__sun)) || defined(__NetBSD__) || \
|
2010-01-30 16:36:02 -08:00
|
|
|
defined(__OpenBSD__) || defined(_WIN32))
|
2004-06-15 11:59:54 -07:00
|
|
|
stdout = stderr;
|
2007-06-15 15:07:11 -07:00
|
|
|
#endif
|
2004-07-28 15:38:17 -07:00
|
|
|
|
2007-05-30 15:27:58 -07:00
|
|
|
if ((argc > 1) && (argv[1][0] == '-') && (argv[1][1] == 'v') && (argv[1][2] == 0)) {
|
2010-01-30 16:36:02 -08:00
|
|
|
int argcmv;
|
|
|
|
verbose_log = true;
|
|
|
|
for (argcmv = 2; argcmv < argc; argcmv++) {
|
|
|
|
argv[argcmv - 1] = argv[argcmv];
|
|
|
|
}
|
|
|
|
argc--;
|
|
|
|
|
|
|
|
#ifndef HAVE_STDOUT
|
|
|
|
gui_stdout();
|
|
|
|
#endif
|
2007-05-30 15:27:58 -07:00
|
|
|
}
|
|
|
|
|
2004-07-28 15:38:17 -07:00
|
|
|
#ifdef _MEMDEBUG_H_
|
|
|
|
memdebug_memdebug("memdump");
|
|
|
|
#endif
|
2004-06-15 11:59:54 -07:00
|
|
|
LOG(("version '%s'", netsurf_version));
|
2007-06-15 15:07:11 -07:00
|
|
|
if (uname(&utsname) < 0)
|
2004-07-28 16:07:52 -07:00
|
|
|
LOG(("Failed to extract machine information"));
|
2004-06-15 11:59:54 -07:00
|
|
|
else
|
|
|
|
LOG(("NetSurf on <%s>, node <%s>, release <%s>, version <%s>, "
|
2004-07-28 15:38:17 -07:00
|
|
|
"machine <%s>", utsname.sysname,
|
2004-06-15 11:59:54 -07:00
|
|
|
utsname.nodename, utsname.release,
|
|
|
|
utsname.version, utsname.machine));
|
2005-07-11 11:10:10 -07:00
|
|
|
|
2010-03-28 05:56:39 -07:00
|
|
|
lwc_initialise(netsurf_lwc_alloc, NULL, 0);
|
2004-07-09 10:03:35 -07:00
|
|
|
url_init();
|
2004-06-15 11:59:54 -07:00
|
|
|
gui_init(argc, argv);
|
2008-10-13 16:32:21 -07:00
|
|
|
setlocale(LC_ALL, "C");
|
2004-06-15 11:59:54 -07:00
|
|
|
fetch_init();
|
2010-03-28 05:56:39 -07:00
|
|
|
/** \todo The frontend needs to provide the llcache_query_handler */
|
|
|
|
llcache_initialise(NULL, NULL);
|
2004-09-26 22:21:00 -07:00
|
|
|
gui_init2(argc, argv);
|
2002-11-03 01:39:53 -08:00
|
|
|
}
|
|
|
|
|
2010-03-28 05:56:39 -07:00
|
|
|
|
2003-11-06 11:41:41 -08:00
|
|
|
/**
|
2010-03-28 05:56:39 -07:00
|
|
|
* Gui NetSurf main loop.
|
2003-11-06 11:41:41 -08:00
|
|
|
*/
|
2010-03-28 05:56:39 -07:00
|
|
|
int netsurf_main_loop(void)
|
2002-09-11 07:24:02 -07:00
|
|
|
{
|
2010-03-28 05:56:39 -07:00
|
|
|
while (!netsurf_quit) {
|
|
|
|
gui_poll(fetch_active);
|
|
|
|
fetch_poll();
|
|
|
|
llcache_poll();
|
2008-07-07 07:05:29 -07:00
|
|
|
}
|
2002-09-11 07:24:02 -07:00
|
|
|
|
2010-03-28 05:56:39 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2002-09-11 07:24:02 -07:00
|
|
|
|
2003-11-06 11:41:41 -08:00
|
|
|
/**
|
|
|
|
* Clean up components used by gui NetSurf.
|
|
|
|
*/
|
2002-10-15 03:41:12 -07:00
|
|
|
|
2003-11-06 11:41:41 -08:00
|
|
|
void netsurf_exit(void)
|
|
|
|
{
|
2006-09-02 08:52:41 -07:00
|
|
|
LOG(("Closing GUI"));
|
2004-06-15 11:59:54 -07:00
|
|
|
gui_quit();
|
2006-09-02 08:52:41 -07:00
|
|
|
LOG(("Closing fetches"));
|
2004-07-30 09:16:07 -07:00
|
|
|
fetch_quit();
|
2006-09-02 08:52:41 -07:00
|
|
|
LOG(("Closing utf8"));
|
2005-07-11 11:10:10 -07:00
|
|
|
utf8_finalise();
|
2006-12-08 14:38:46 -08:00
|
|
|
LOG(("Destroying URLdb"));
|
|
|
|
urldb_destroy();
|
2006-09-02 08:52:41 -07:00
|
|
|
LOG(("Exited successfully"));
|
2002-09-11 07:24:02 -07:00
|
|
|
}
|
2004-07-05 13:19:52 -07:00
|
|
|
|
|
|
|
|