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"
|
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"
|
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-04-28 02:14:52 +04:00
|
|
|
static void netsurf_lwc_iterator(lwc_string *str, void *pw)
|
|
|
|
{
|
|
|
|
LOG(("%.*s", (int) lwc_string_length(str), lwc_string_data(str)));
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
gui_401login_open(query->url, query->data.auth.realm, cb, cbpw);
|
|
|
|
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:
|
|
|
|
gui_cert_verify(query->url, query->data.ssl.certs,
|
|
|
|
query->data.ssl.num, cb, cbpw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
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-07-28 19:22:44 +04:00
|
|
|
messages_load(messages);
|
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-04-15 03:03:49 +04:00
|
|
|
llcache_initialise(netsurf_llcache_query_handler, 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();
|
2010-04-27 10:48:09 +04:00
|
|
|
LOG(("Finalising high-level cache"));
|
|
|
|
hlcache_finalise();
|
|
|
|
LOG(("Finalising low-level cache"));
|
|
|
|
llcache_finalise();
|
2010-04-28 02:14:52 +04:00
|
|
|
LOG(("Remaining lwc strings:"));
|
|
|
|
lwc_iterate_strings(netsurf_lwc_iterator, NULL);
|
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
|
|
|
|
|
|
|
|