summaryrefslogtreecommitdiff
path: root/monkey
diff options
context:
space:
mode:
Diffstat (limited to 'monkey')
-rw-r--r--monkey/401login.c3
-rw-r--r--monkey/401login.h9
-rw-r--r--monkey/Makefile.defaults18
-rw-r--r--monkey/Makefile.target30
-rw-r--r--monkey/browser.c167
-rw-r--r--monkey/browser.h4
-rw-r--r--monkey/cert.c9
-rw-r--r--monkey/cert.h4
-rw-r--r--monkey/dispatch.c25
-rw-r--r--monkey/download.c25
-rw-r--r--monkey/fetch.c52
-rw-r--r--monkey/fetch.h19
-rw-r--r--monkey/filetype.c37
-rw-r--r--monkey/filetype.h5
-rw-r--r--monkey/main.c103
-rw-r--r--monkey/plot.c4
-rw-r--r--monkey/poll.c81
-rw-r--r--monkey/poll.h2
-rw-r--r--monkey/schedule.c26
-rw-r--r--monkey/schedule.h3
-rw-r--r--monkey/utils.c104
21 files changed, 360 insertions, 370 deletions
diff --git a/monkey/401login.c b/monkey/401login.c
index 605a21aa9..8b4d33d7d 100644
--- a/monkey/401login.c
+++ b/monkey/401login.c
@@ -16,12 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "desktop/401login.h"
#include "utils/ring.h"
#include <stdlib.h>
#include <stdio.h>
+#include "monkey/401login.h"
+
typedef struct monkey401 {
struct monkey401 *r_next, *r_prev;
uint32_t num;
diff --git a/monkey/401login.h b/monkey/401login.h
new file mode 100644
index 000000000..e78355ea2
--- /dev/null
+++ b/monkey/401login.h
@@ -0,0 +1,9 @@
+
+#include <stdbool.h>
+
+#include "utils/nsurl.h"
+#include "utils/errors.h"
+
+
+void gui_401login_open(nsurl *url, const char *realm,
+ nserror (*cb)(bool proceed, void *pw), void *cbpw);
diff --git a/monkey/Makefile.defaults b/monkey/Makefile.defaults
index 659c1e336..d6a90a3dc 100644
--- a/monkey/Makefile.defaults
+++ b/monkey/Makefile.defaults
@@ -2,12 +2,12 @@
# Monkey-specific options
# ----------------------------------------------------------------------------
- # How did I get mixed up with this fucking monkey anyhow?
- NETSURF_MONKEY_RESOURCES := $(PREFIX)/share/netsurf/
- NETSURF_MONKEY_BIN := $(PREFIX)/bin/
- NETSURF_USE_RSVG := NO
- NETSURF_USE_NSSVG := NO
- NETSURF_USE_ROSPRITE := NO
- NETSURF_USE_HARU_PDF := NO
- NETSURF_USE_LIBICONV_PLUG := NO
- CFLAGS += -O2
+# How did I get mixed up with this fucking monkey anyhow?
+NETSURF_MONKEY_RESOURCES := $(PREFIX)/share/netsurf/
+NETSURF_MONKEY_BIN := $(PREFIX)/bin/
+NETSURF_USE_RSVG := NO
+NETSURF_USE_NSSVG := NO
+NETSURF_USE_ROSPRITE := NO
+NETSURF_USE_HARU_PDF := NO
+
+CFLAGS += -O2
diff --git a/monkey/Makefile.target b/monkey/Makefile.target
index 6c60ca1c5..d3c974782 100644
--- a/monkey/Makefile.target
+++ b/monkey/Makefile.target
@@ -33,25 +33,19 @@ $(eval $(call pkg_config_find_and_add_enabled,JS,mozilla-js,JavaScript))
# no pkg-config for this library
$(eval $(call feature_enabled,WEBP,-DWITH_WEBP,-lwebp -lvpx,WebP (libwebp)))
-WARNFLAGS += -Werror
+CWARNFLAGS += -Werror
-MONKEYCFLAGS := -std=c99 -Dmonkey -Dnsmonkey \
- -D_BSD_SOURCE \
- -D_XOPEN_SOURCE=600 \
- -D_POSIX_C_SOURCE=200112L \
- -D_NETBSD_SOURCE \
- -DMONKEY_RESPATH=\"$(NETSURF_MONKEY_RESOURCES)\" \
- $(WARNFLAGS) -g \
- $(shell $(PKG_CONFIG) --cflags glib-2.0) \
- $(shell $(PKG_CONFIG) --cflags libdom libcurl) \
- $(shell $(PKG_CONFIG) --cflags openssl) \
- $(shell xml2-config --cflags)
+CFLAGS += -std=c99 -Dmonkey -Dnsmonkey -g \
+ -D_BSD_SOURCE \
+ -D_XOPEN_SOURCE=600 \
+ -D_POSIX_C_SOURCE=200112L \
+ -D_NETBSD_SOURCE \
+ -DMONKEY_RESPATH=\"$(NETSURF_MONKEY_RESOURCES)\" \
+ $(shell $(PKG_CONFIG) --cflags glib-2.0) \
+ $(shell $(PKG_CONFIG) --cflags libdom libcurl) \
+ $(shell $(PKG_CONFIG) --cflags openssl)
-MONKEYLDFLAGS := -lm $(shell $(PKG_CONFIG) --cflags --libs glib-2.0 lcms)
-
-
-CFLAGS += $(MONKEYCFLAGS)
-LDFLAGS += $(MONKEYLDFLAGS)
+LDFLAGS += -lm $(shell $(PKG_CONFIG) --cflags --libs glib-2.0)
# ---------------------------------------------------------------------------
# Windows flag setup
@@ -68,7 +62,7 @@ endif
# S_MONKEY are sources purely for the MONKEY build
S_MONKEY := main.c utils.c filetype.c schedule.c \
bitmap.c plot.c browser.c download.c thumbnail.c \
- 401login.c cert.c font.c poll.c dispatch.c
+ 401login.c cert.c font.c poll.c dispatch.c fetch.c
S_MONKEY := $(addprefix monkey/,$(S_MONKEY))
diff --git a/monkey/browser.c b/monkey/browser.c
index 09ecf4b11..0e488c578 100644
--- a/monkey/browser.c
+++ b/monkey/browser.c
@@ -64,19 +64,13 @@ monkey_find_window_by_content(hlcache_handle *content)
return ret;
}
-void
-monkey_window_process_reformats(void)
+
+/**
+ * callback from core to reformat a window.
+ */
+static void monkey_window_reformat(struct gui_window *gw)
{
- RING_ITERATE_START(struct gui_window, gw_ring, c_ring) {
- if (c_ring == NULL)
- RING_ITERATE_STOP(gw_ring, c_ring);
- if (c_ring->bw->reformat_pending) {
- browser_window_reformat(c_ring->bw,
- false,
- c_ring->width,
- c_ring->height);
- }
- } RING_ITERATE_END(gw_ring, c_ring);
+ browser_window_reformat(gw->bw, false, gw->width, gw->height);
}
void
@@ -87,9 +81,10 @@ monkey_kill_browser_windows(void)
}
}
-struct gui_window *
-gui_create_browser_window(struct browser_window *bw,
- struct browser_window *clone, bool new_tab)
+static struct gui_window *
+gui_window_create(struct browser_window *bw,
+ struct gui_window *existing,
+ gui_window_create_flags flags)
{
struct gui_window *ret = calloc(sizeof(*ret), 1);
if (ret == NULL)
@@ -101,8 +96,9 @@ gui_create_browser_window(struct browser_window *bw,
ret->width = 800;
ret->height = 600;
- fprintf(stdout, "WINDOW NEW WIN %u FOR %p CLONE %p NEWTAB %s\n",
- ret->win_num, bw, clone, new_tab ? "TRUE" : "FALSE");
+ fprintf(stdout, "WINDOW NEW WIN %u FOR %p EXISTING %p NEWTAB %s CLONE %s\n",
+ ret->win_num, bw, existing, flags & GW_CREATE_TAB ? "TRUE" : "FALSE",
+ flags & GW_CREATE_CLONE ? "TRUE" : "FALSE");
fprintf(stdout, "WINDOW SIZE WIN %u WIDTH %d HEIGHT %d\n",
ret->win_num, ret->width, ret->height);
@@ -111,7 +107,7 @@ gui_create_browser_window(struct browser_window *bw,
return ret;
}
-void
+static void
gui_window_destroy(struct gui_window *g)
{
fprintf(stdout, "WINDOW DESTROY WIN %u\n", g->win_num);
@@ -119,19 +115,19 @@ gui_window_destroy(struct gui_window *g)
free(g);
}
-void
+static void
gui_window_set_title(struct gui_window *g, const char *title)
{
fprintf(stdout, "WINDOW TITLE WIN %u STR %s\n", g->win_num, title);
}
-void
+static void
gui_window_redraw_window(struct gui_window *g)
{
fprintf(stdout, "WINDOW REDRAW WIN %u\n", g->win_num);
}
-void
+static void
gui_window_get_dimensions(struct gui_window *g, int *width, int *height,
bool scaled)
{
@@ -141,31 +137,31 @@ gui_window_get_dimensions(struct gui_window *g, int *width, int *height,
*height = g->height;
}
-void
+static void
gui_window_new_content(struct gui_window *g)
{
fprintf(stdout, "WINDOW NEW_CONTENT WIN %u\n", g->win_num);
}
-void
+static void
gui_window_set_icon(struct gui_window *g, hlcache_handle *icon)
{
fprintf(stdout, "WINDOW NEW_ICON WIN %u\n", g->win_num);
}
-void
+static void
gui_window_start_throbber(struct gui_window *g)
{
fprintf(stdout, "WINDOW START_THROBBER WIN %u\n", g->win_num);
}
-void
+static void
gui_window_stop_throbber(struct gui_window *g)
{
fprintf(stdout, "WINDOW STOP_THROBBER WIN %u\n", g->win_num);
}
-void
+static void
gui_window_set_scroll(struct gui_window *g, int sx, int sy)
{
g->scrollx = sx;
@@ -173,7 +169,7 @@ gui_window_set_scroll(struct gui_window *g, int sx, int sy)
fprintf(stdout, "WINDOW SET_SCROLL WIN %u X %d Y %d\n", g->win_num, sx, sy);
}
-void
+static void
gui_window_update_box(struct gui_window *g, const struct rect *rect)
{
fprintf(stdout, "WINDOW UPDATE_BOX WIN %u X %d Y %d WIDTH %d HEIGHT %d\n",
@@ -182,7 +178,7 @@ gui_window_update_box(struct gui_window *g, const struct rect *rect)
}
-void
+static void
gui_window_update_extent(struct gui_window *g)
{
if (!g->bw->current_content)
@@ -194,13 +190,13 @@ gui_window_update_extent(struct gui_window *g)
content_get_height(g->bw->current_content));
}
-void
+static void
gui_window_set_status(struct gui_window *g, const char *text)
{
fprintf(stdout, "WINDOW SET_STATUS WIN %u STR %s\n", g->win_num, text);
}
-void
+static void
gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
{
const char *ptr_name = "UNKNOWN";
@@ -269,20 +265,13 @@ gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
fprintf(stdout, "WINDOW SET_POINTER WIN %u POINTER %s\n", g->win_num, ptr_name);
}
-void
+static void
gui_window_set_url(struct gui_window *g, const char *url)
{
fprintf(stdout, "WINDOW SET_URL WIN %u URL %s\n", g->win_num, url);
}
-void
-gui_drag_save_object(gui_save_type type, hlcache_handle *c,
- struct gui_window *g)
-{
- /* Ignore? */
-}
-
-bool
+static bool
gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
{
fprintf(stdout, "WINDOW GET_SCROLL WIN %u X %d Y %d\n",
@@ -292,7 +281,7 @@ gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
return true;
}
-bool
+static bool
gui_window_scroll_start(struct gui_window *g)
{
fprintf(stdout, "WINDOW SCROLL_START WIN %u\n", g->win_num);
@@ -300,12 +289,7 @@ gui_window_scroll_start(struct gui_window *g)
return true;
}
-void
-gui_window_set_search_ico(hlcache_handle *ico)
-{
-}
-
-void
+static void
gui_window_scroll_visible(struct gui_window *g, int x0, int y0,
int x1, int y1)
{
@@ -313,46 +297,7 @@ gui_window_scroll_visible(struct gui_window *g, int x0, int y0,
g->win_num, x0, y0, x1, y1);
}
-void
-gui_drag_save_selection(struct gui_window *g, const char *selection)
-{
-}
-
-void
-gui_start_selection(struct gui_window *g)
-{
-}
-
-void
-gui_clear_selection(struct gui_window *g)
-{
-}
-
-/**
- * Core asks front end for clipboard contents.
- *
- * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core
- * \param length Byte length of UTF-8 text in buffer
- */
-void gui_get_clipboard(char **buffer, size_t *length)
-{
-}
-
-
-/**
- * Core tells front end to put given text in clipboard
- *
- * \param buffer UTF-8 text, owned by core
- * \param length Byte length of UTF-8 text in buffer
- * \param styles Array of styles given to text runs, owned by core, or NULL
- * \param n_styles Number of text run styles in array
- */
-void gui_set_clipboard(const char *buffer, size_t length,
- nsclipboard_styles styles[], int n_styles)
-{
-}
-
-void
+static void
gui_window_place_caret(struct gui_window *g, int x, int y, int height,
const struct rect *clip)
{
@@ -360,13 +305,13 @@ gui_window_place_caret(struct gui_window *g, int x, int y, int height,
g->win_num, x, y, height);
}
-void
+static void
gui_window_remove_caret(struct gui_window *g)
{
fprintf(stdout, "WINDOW REMOVE_CARET WIN %u\n", g->win_num);
}
-bool
+static bool
gui_window_drag_start(struct gui_window *g, gui_drag_type type,
const struct rect *rect)
{
@@ -374,15 +319,7 @@ gui_window_drag_start(struct gui_window *g, gui_drag_type type,
return false;
}
-void
-gui_create_form_select_menu(struct browser_window *bw,
- struct form_control *control)
-{
- fprintf(stdout, "WINDOW SELECT_MENU WIN %u\n",
- bw->window->win_num);
-}
-
-void
+static void
gui_window_save_link(struct gui_window *g, const char *url,
const char *title)
{
@@ -391,6 +328,7 @@ gui_window_save_link(struct gui_window *g, const char *url,
}
+
/**** Handlers ****/
static void
@@ -406,8 +344,7 @@ monkey_window_handle_new(int argc, char **argv)
error = nsurl_create(argv[2], &url);
}
if (error == NSERROR_OK) {
- error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
- BROWSER_WINDOW_HISTORY,
+ error = browser_window_create(BW_CREATE_HISTORY,
url,
NULL,
NULL,
@@ -466,8 +403,7 @@ monkey_window_handle_go(int argc, char **argv)
browser_window_navigate(gw->bw,
url,
ref_url,
- BROWSER_WINDOW_HISTORY |
- BROWSER_WINDOW_VERIFIABLE,
+ BW_NAVIGATE_HISTORY,
NULL,
NULL,
NULL);
@@ -559,3 +495,32 @@ monkey_window_handle_command(int argc, char **argv)
}
}
+
+static struct gui_window_table window_table = {
+ .create = gui_window_create,
+ .destroy = gui_window_destroy,
+ .redraw = gui_window_redraw_window,
+ .update = gui_window_update_box,
+ .get_scroll = gui_window_get_scroll,
+ .set_scroll = gui_window_set_scroll,
+ .get_dimensions = gui_window_get_dimensions,
+ .update_extent = gui_window_update_extent,
+ .reformat = monkey_window_reformat,
+
+ .set_title = gui_window_set_title,
+ .set_url = gui_window_set_url,
+ .set_icon = gui_window_set_icon,
+ .set_status = gui_window_set_status,
+ .set_pointer = gui_window_set_pointer,
+ .place_caret = gui_window_place_caret,
+ .remove_caret = gui_window_remove_caret,
+ .drag_start = gui_window_drag_start,
+ .save_link = gui_window_save_link,
+ .scroll_visible = gui_window_scroll_visible,
+ .scroll_start = gui_window_scroll_start,
+ .new_content = gui_window_new_content,
+ .start_throbber = gui_window_start_throbber,
+ .stop_throbber = gui_window_stop_throbber,
+};
+
+struct gui_window_table *monkey_window_table = &window_table;
diff --git a/monkey/browser.h b/monkey/browser.h
index 3ccbe7a91..959c6a1e6 100644
--- a/monkey/browser.h
+++ b/monkey/browser.h
@@ -22,6 +22,9 @@
#include "desktop/browser.h"
#include "content/hlcache.h"
+extern struct gui_window_table *monkey_window_table;
+extern struct gui_download_table *monkey_download_table;
+
struct gui_window {
struct gui_window *r_next;
struct gui_window *r_prev;
@@ -42,4 +45,5 @@ void monkey_window_process_reformats(void);
void monkey_window_handle_command(int argc, char **argv);
void monkey_kill_browser_windows(void);
+
#endif /* NETSURF_MONKEY_BROWSER_H */
diff --git a/monkey/cert.c b/monkey/cert.c
index 0aa01f3a7..6f2172743 100644
--- a/monkey/cert.c
+++ b/monkey/cert.c
@@ -16,12 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "desktop/gui.h"
-#include "utils/ring.h"
-
#include <stdlib.h>
#include <stdio.h>
+#include "utils/ring.h"
+#include "utils/nsurl.h"
+#include "desktop/gui.h"
+
+#include "monkey/cert.h"
+
typedef struct monkey_cert {
struct monkey_cert *r_next, *r_prev;
uint32_t num;
diff --git a/monkey/cert.h b/monkey/cert.h
new file mode 100644
index 000000000..2780f4f57
--- /dev/null
+++ b/monkey/cert.h
@@ -0,0 +1,4 @@
+void
+gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
+ unsigned long num, nserror (*cb)(bool proceed, void *pw),
+ void *cbpw);
diff --git a/monkey/dispatch.c b/monkey/dispatch.c
index c1b3edce4..ba15fbd13 100644
--- a/monkey/dispatch.c
+++ b/monkey/dispatch.c
@@ -55,20 +55,34 @@ monkey_process_command(void)
char **argv = NULL;
char *p, *r = NULL;
handle_command_fn fn = NULL;
+ char **nargv;
if (fgets(buffer, PATH_MAX, stdin) == NULL) {
netsurf_quit = true;
+ return;
}
-
- buffer[strlen(buffer)-1] = '\0';
+
+ /* remove newline */
+ buffer[strlen(buffer) - 1] = '\0';
argv = malloc(sizeof *argv);
+ if (argv == NULL) {
+ return;
+ }
argc = 1;
*argv = buffer;
for (p = r = buffer; *p != '\0'; p++) {
if (*p == ' ') {
- argv = realloc(argv, sizeof(*argv) * (argc + 1));
+ nargv = realloc(argv, sizeof(*argv) * (argc + 1));
+ if (nargv == NULL) {
+ /* reallocation of argument vector failed, try using what is
+ * already processed.
+ */
+ break;
+ } else {
+ argv = nargv;
+ }
argv[argc++] = r = p + 1;
*p = '\0';
}
@@ -81,6 +95,9 @@ monkey_process_command(void)
}
} RING_ITERATE_END(handler_ring, handler);
- if (fn != NULL)
+ if (fn != NULL) {
fn(argc, argv);
+ }
+
+ free(argv);
}
diff --git a/monkey/download.c b/monkey/download.c
index d706dd6e0..721f77ddc 100644
--- a/monkey/download.c
+++ b/monkey/download.c
@@ -16,11 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "desktop/browser.h"
-#include "monkey/browser.h"
+#include <stdio.h>
+
+#include "desktop/gui.h"
+#include "desktop/download.h"
#include "utils/ring.h"
-#include <stdio.h>
+#include "monkey/browser.h"
static uint32_t dwin_ctr = 0;
@@ -34,7 +36,7 @@ struct gui_download_window {
static struct gui_download_window *dw_ring = NULL;
-struct gui_download_window *
+static struct gui_download_window *
gui_download_window_create(download_context *ctx,
struct gui_window *parent)
{
@@ -52,7 +54,7 @@ gui_download_window_create(download_context *ctx,
return ret;
}
-nserror
+static nserror
gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
@@ -61,7 +63,7 @@ gui_download_window_data(struct gui_download_window *dw,
return NSERROR_OK;
}
-void
+static void
gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
@@ -69,7 +71,7 @@ gui_download_window_error(struct gui_download_window *dw,
dw->dwin_num, error_msg);
}
-void
+static void
gui_download_window_done(struct gui_download_window *dw)
{
fprintf(stdout, "DOWNLOAD_WINDOW DONE DWIN %u\n",
@@ -77,3 +79,12 @@ gui_download_window_done(struct gui_download_window *dw)
RING_REMOVE(dw_ring, dw);
free(dw);
}
+
+static struct gui_download_table download_table = {
+ .create = gui_download_window_create,
+ .data = gui_download_window_data,
+ .error = gui_download_window_error,
+ .done = gui_download_window_done,
+};
+
+struct gui_download_table *monkey_download_table = &download_table;
diff --git a/monkey/fetch.c b/monkey/fetch.c
new file mode 100644
index 000000000..88cb27dcf
--- /dev/null
+++ b/monkey/fetch.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * 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/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <limits.h>
+
+#include "desktop/gui.h"
+#include "utils/file.h"
+#include "utils/nsurl.h"
+#include "utils/filepath.h"
+
+#include "monkey/filetype.h"
+#include "monkey/fetch.h"
+
+extern char **respaths;
+
+
+static nsurl *gui_get_resource_url(const char *path)
+{
+ char buf[PATH_MAX];
+ nsurl *url = NULL;
+
+ netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
+
+ return url;
+}
+
+static struct gui_fetch_table fetch_table = {
+ .filetype = monkey_fetch_filetype,
+
+ .get_resource_url = gui_get_resource_url,
+};
+
+struct gui_fetch_table *monkey_fetch_table = &fetch_table;
diff --git a/monkey/fetch.h b/monkey/fetch.h
new file mode 100644
index 000000000..59e8696d1
--- /dev/null
+++ b/monkey/fetch.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * 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/>.
+ */
+
+struct gui_fetch_table *monkey_fetch_table;
diff --git a/monkey/filetype.c b/monkey/filetype.c
index f89f2358c..8c5037781 100644
--- a/monkey/filetype.c
+++ b/monkey/filetype.c
@@ -26,14 +26,15 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "gtk/filetype.h"
#include "content/fetch.h"
#include "utils/log.h"
#include "utils/hashtable.h"
+#include "monkey/filetype.h"
+
static struct hash_table *mime_hash = NULL;
-void gtk_fetch_filetype_init(const char *mimefile)
+void monkey_fetch_filetype_init(const char *mimefile)
{
struct stat statbuf;
FILE *fh = NULL;
@@ -143,12 +144,21 @@ void gtk_fetch_filetype_init(const char *mimefile)
fclose(fh);
}
-void gtk_fetch_filetype_fin(void)
+void monkey_fetch_filetype_fin(void)
{
hash_destroy(mime_hash);
}
-const char *fetch_filetype(const char *unix_path)
+/**
+ * Determine the MIME type of a local file.
+ *
+ * @note used in file fetcher
+ *
+ * \param unix_path Unix style path to file on disk
+ * \return Pointer to static MIME type string (should not be freed) not NULL.
+ * invalidated on next call to fetch_filetype.
+ */
+const char *monkey_fetch_filetype(const char *unix_path)
{
struct stat statbuf;
char *ext;
@@ -157,9 +167,16 @@ const char *fetch_filetype(const char *unix_path)
const char *type;
int l;
- stat(unix_path, &statbuf);
- if (S_ISDIR(statbuf.st_mode))
+ if (stat(unix_path, &statbuf) != 0) {
+ /* error calling stat, the file has probably become
+ * inacessible, this routine cannot fail so just
+ * return the default mime type.
+ */
+ return "text/plain";
+ }
+ if (S_ISDIR(statbuf.st_mode)) {
return "application/x-netsurf-directory";
+ }
l = strlen(unix_path);
if ((3 < l) && (strcasecmp(unix_path + l - 4, ",f79") == 0)) {
@@ -175,8 +192,9 @@ const char *fetch_filetype(const char *unix_path)
while (*ptr != '.' && *ptr != '/')
ptr--;
- if (*ptr != '.')
+ if (*ptr != '.') {
return "text/plain";
+ }
ext = strdup(ptr + 1); /* skip the . */
@@ -195,11 +213,6 @@ const char *fetch_filetype(const char *unix_path)
return type != NULL ? type : "text/plain";
}
-char *fetch_mimetype(const char *unix_path)
-{
- return strdup(fetch_filetype(unix_path));
-}
-
#ifdef TEST_RIG
int main(int argc, char *argv[])
diff --git a/monkey/filetype.h b/monkey/filetype.h
index 8bf98db7c..6c16db01b 100644
--- a/monkey/filetype.h
+++ b/monkey/filetype.h
@@ -17,5 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-void gtk_fetch_filetype_init(const char *mimefile);
-void gtk_fetch_filetype_fin(void);
+void monkey_fetch_filetype_init(const char *mimefile);
+void monkey_fetch_filetype_fin(void);
+const char *monkey_fetch_filetype(const char *unix_path);
diff --git a/monkey/main.c b/monkey/main.c
index 95432e3c7..08af69405 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -20,69 +20,57 @@
#include <stdio.h>
#include <stdlib.h>
-#include "monkey/filetype.h"
#include "utils/nsoption.h"
-#include "monkey/poll.h"
-#include "monkey/dispatch.h"
-#include "monkey/browser.h"
-
#include "content/urldb.h"
#include "content/fetchers/resource.h"
#include "desktop/gui.h"
#include "desktop/netsurf.h"
#include "utils/log.h"
#include "utils/filepath.h"
-#include "utils/url.h"
-static char **respaths; /** resource search path vector */
+#include "monkey/poll.h"
+#include "monkey/dispatch.h"
+#include "monkey/browser.h"
+#include "monkey/cert.h"
+#include "monkey/401login.h"
+#include "monkey/filetype.h"
+#include "monkey/fetch.h"
+#include "monkey/schedule.h"
+
+char **respaths; /** resource search path vector */
/* Stolen from gtk/gui.c */
static char **
nsmonkey_init_resource(const char *resource_path)
{
- const gchar * const *langv;
- char **pathv; /* resource path string vector */
- char **respath; /* resource paths vector */
+ const gchar * const *langv;
+ char **pathv; /* resource path string vector */
+ char **respath; /* resource paths vector */
- pathv = filepath_path_to_strvec(resource_path);
+ pathv = filepath_path_to_strvec(resource_path);
- langv = g_get_language_names();
+ langv = g_get_language_names();
- respath = filepath_generate(pathv, langv);
+ respath = filepath_generate(pathv, langv);
- filepath_free_strvec(pathv);
+ filepath_free_strvec(pathv);
- return respath;
-}
-
-void gui_quit(void)
-{
- urldb_save_cookies(nsoption_charp(cookie_jar));
- urldb_save(nsoption_charp(url_file));
- free(nsoption_charp(cookie_file));
- free(nsoption_charp(cookie_jar));
- gtk_fetch_filetype_fin();
+ return respath;
}
-nsurl *gui_get_resource_url(const char *path)
+static void monkey_quit(void)
{
- char buf[PATH_MAX];
- char *raw;
- nsurl *url = NULL;
-
- raw = path_to_url(filepath_sfind(respaths, buf, path));
- if (raw != NULL) {
- nsurl_create(raw, &url);
- free(raw);
- }
-
- return url;
+ urldb_save_cookies(nsoption_charp(cookie_jar));
+ urldb_save(nsoption_charp(url_file));
+ free(nsoption_charp(cookie_file));
+ free(nsoption_charp(cookie_jar));
+ monkey_fetch_filetype_fin();
}
-void
-gui_launch_url(const char *url)
+static nserror gui_launch_url(struct nsurl *url)
{
- fprintf(stdout, "GENERIC LAUNCH URL %s\n", url);
+ fprintf(stdout, "GENERIC LAUNCH URL %s\n", nsurl_access(url));
+ return NSERROR_OK;
}
static void quit_handler(int argc, char **argv)
@@ -113,6 +101,16 @@ static bool nslog_stream_configure(FILE *fptr)
return true;
}
+static struct gui_browser_table monkey_browser_table = {
+ .poll = monkey_poll,
+ .schedule = monkey_schedule,
+
+ .quit = monkey_quit,
+ .launch_url = gui_launch_url,
+ .cert_verify = gui_cert_verify,
+ .login = gui_401login_open,
+};
+
int
main(int argc, char **argv)
{
@@ -120,12 +118,23 @@ main(int argc, char **argv)
char *options;
char buf[PATH_MAX];
nserror ret;
+ struct netsurf_table monkey_table = {
+ .browser = &monkey_browser_table,
+ .window = monkey_window_table,
+ .download = monkey_download_table,
+ .fetch = monkey_fetch_table,
+ };
+
+ ret = netsurf_register(&monkey_table);
+ if (ret != NSERROR_OK) {
+ die("NetSurf operation table failed registration");
+ }
/* Unbuffer stdin/out/err */
setbuf(stdin, NULL);
setbuf(stdout, NULL);
setbuf(stderr, NULL);
-
+
/* Prep the search paths */
respaths = nsmonkey_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"MONKEY_RESPATH":./monkey/res");
@@ -146,27 +155,27 @@ main(int argc, char **argv)
/* common initialisation */
messages = filepath_find(respaths, "Messages");
- ret = netsurf_init(messages);
+ ret = netsurf_init(messages, NULL);
free(messages);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
-
+
filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
- gtk_fetch_filetype_init(buf);
-
+ monkey_fetch_filetype_init(buf);
+
urldb_load(nsoption_charp(url_file));
urldb_load_cookies(nsoption_charp(cookie_file));
-
+
monkey_prepare_input();
monkey_register_handler("QUIT", quit_handler);
monkey_register_handler("WINDOW", monkey_window_handle_command);
-
+
fprintf(stdout, "GENERIC STARTED\n");
netsurf_main_loop();
fprintf(stdout, "GENERIC CLOSING_DOWN\n");
monkey_kill_browser_windows();
-
+
netsurf_exit();
fprintf(stdout, "GENERIC FINISHED\n");
diff --git a/monkey/plot.c b/monkey/plot.c
index 76980ce5b..db4d6cd32 100644
--- a/monkey/plot.c
+++ b/monkey/plot.c
@@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "desktop/plotters.h"
-
#include <stdio.h>
+#include "desktop/plotters.h"
+
static bool
monkey_plot_disc(int x, int y, int radius, const plot_style_t *style)
{
diff --git a/monkey/poll.c b/monkey/poll.c
index 024005b89..e65f2d3e2 100644
--- a/monkey/poll.c
+++ b/monkey/poll.c
@@ -22,7 +22,7 @@
#include "desktop/gui.h"
#include "monkey/schedule.h"
#include "monkey/browser.h"
-#include "content/fetchers/curl.h"
+#include "content/fetchers.h"
#include "monkey/dispatch.h"
#include "monkey/poll.h"
@@ -88,60 +88,45 @@ monkey_prepare_input(void)
}
void
-gui_poll(bool active)
+monkey_poll(bool active)
{
- CURLMcode code;
fd_set read_fd_set, write_fd_set, exc_fd_set;
int max_fd;
GPollFD *fd_list[1000];
unsigned int fd_count = 0;
bool block = true;
-
- schedule_run();
- if (browser_reformat_pending)
- block = false;
-
- if (active) {
- FD_ZERO(&read_fd_set);
- FD_ZERO(&write_fd_set);
- FD_ZERO(&exc_fd_set);
- code = curl_multi_fdset(fetch_curl_multi,
- &read_fd_set,
- &write_fd_set,
- &exc_fd_set,
- &max_fd);
- assert(code == CURLM_OK);
- LOG(("maxfd from curl is %d", max_fd));
- for (int i = 0; i <= max_fd; i++) {
- if (FD_ISSET(i, &read_fd_set)) {
- GPollFD *fd = malloc(sizeof *fd);
- fd->fd = i;
- fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
- g_main_context_add_poll(0, fd, 0);
- fd_list[fd_count++] = fd;
- LOG(("Want to read %d", i));
- }
- if (FD_ISSET(i, &write_fd_set)) {
- GPollFD *fd = malloc(sizeof *fd);
- fd->fd = i;
- fd->events = G_IO_OUT | G_IO_ERR;
- g_main_context_add_poll(0, fd, 0);
- fd_list[fd_count++] = fd;
- LOG(("Want to write %d", i));
- }
- if (FD_ISSET(i, &exc_fd_set)) {
- GPollFD *fd = malloc(sizeof *fd);
- fd->fd = i;
- fd->events = G_IO_ERR;
- g_main_context_add_poll(0, fd, 0);
- fd_list[fd_count++] = fd;
- LOG(("Want to check %d", i));
- }
+ fetcher_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
+ for (int i = 0; i <= max_fd; i++) {
+ if (FD_ISSET(i, &read_fd_set)) {
+ GPollFD *fd = malloc(sizeof *fd);
+ fd->fd = i;
+ fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
+ g_main_context_add_poll(0, fd, 0);
+ fd_list[fd_count++] = fd;
+ LOG(("Want to read %d", i));
+ }
+ if (FD_ISSET(i, &write_fd_set)) {
+ GPollFD *fd = malloc(sizeof *fd);
+ fd->fd = i;
+ fd->events = G_IO_OUT | G_IO_ERR;
+ g_main_context_add_poll(0, fd, 0);
+ fd_list[fd_count++] = fd;
+ LOG(("Want to write %d", i));
+ }
+ if (FD_ISSET(i, &exc_fd_set)) {
+ GPollFD *fd = malloc(sizeof *fd);
+ fd->fd = i;
+ fd->events = G_IO_ERR;
+ g_main_context_add_poll(0, fd, 0);
+ fd_list[fd_count++] = fd;
+ LOG(("Want to check %d", i));
}
}
-
- LOG(("Iterate %sactive %sblocking", active?"":"in", block?"":"non-"));
+
+ schedule_run();
+
+ LOG(("Iterate %sblocking", block?"":"non-"));
if (block) {
fprintf(stdout, "GENERIC POLL BLOCKING\n");
}
@@ -152,9 +137,5 @@ gui_poll(bool active)
free(fd_list[i]);
}
- schedule_run();
-
- if (browser_reformat_pending)
- monkey_window_process_reformats();
}
diff --git a/monkey/poll.h b/monkey/poll.h
index 1aebe6856..4195958c9 100644
--- a/monkey/poll.h
+++ b/monkey/poll.h
@@ -21,4 +21,6 @@
void monkey_prepare_input(void);
+void monkey_poll(bool active);
+
#endif /* NETSURF_MONKEY_POLL_H */
diff --git a/monkey/schedule.c b/monkey/schedule.c
index dd789331c..e8ec1c6fa 100644
--- a/monkey/schedule.c
+++ b/monkey/schedule.c
@@ -20,8 +20,9 @@
#include <stdlib.h>
#include <stdbool.h>
-#include "utils/schedule.h"
-#include "gtk/schedule.h"
+#include "utils/errors.h"
+
+#include "monkey/schedule.h"
#undef DEBUG_MONKEY_SCHEDULE
@@ -74,7 +75,7 @@ nsgtk_schedule_kill_callback(void *_target, void *_match)
}
}
-void
+static void
schedule_remove(void (*callback)(void *p), void *p)
{
_nsgtk_callback_t cb_match = {
@@ -90,20 +91,27 @@ schedule_remove(void (*callback)(void *p), void *p)
nsgtk_schedule_kill_callback, &cb_match);
}
-void
-schedule(int t, void (*callback)(void *p), void *p)
+nserror monkey_schedule(int t, void (*callback)(void *p), void *p)
{
- const int msec_timeout = t * 10;
- _nsgtk_callback_t *cb = malloc(sizeof(_nsgtk_callback_t));
+ _nsgtk_callback_t *cb;
+
/* Kill any pending schedule of this kind. */
schedule_remove(callback, p);
+ if (t < 0) {
+ return NSERROR_OK;
+ }
+
+ cb = malloc(sizeof(_nsgtk_callback_t));
cb->callback = callback;
cb->context = p;
cb->callback_killed = false;
/* Prepend is faster right now. */
- LOG(("queued a callback to %p(%p) for %d msecs time", callback, p, msec_timeout));
+ LOG(("queued a callback to %p(%p) for %d msecs time", callback, p, t));
queued_callbacks = g_list_prepend(queued_callbacks, cb);
- g_timeout_add(msec_timeout, nsgtk_schedule_generic_callback, cb);
+ g_timeout_add(t, nsgtk_schedule_generic_callback, cb);
+
+ return NSERROR_OK;
+
}
bool
diff --git a/monkey/schedule.h b/monkey/schedule.h
index c63215e88..44ef9bf3b 100644
--- a/monkey/schedule.h
+++ b/monkey/schedule.h
@@ -19,7 +19,8 @@
#ifndef NETSURF_GTK_CALLBACK_H
#define NETSURF_GTK_CALLBACK_H 1
-typedef void (*gtk_callback)(void *p);
+nserror monkey_schedule(int t, void (*callback)(void *p), void *p);
+
bool schedule_run(void);
#endif /* NETSURF_GTK_CALLBACK_H */
diff --git a/monkey/utils.c b/monkey/utils.c
index 3e09106f7..e1a702f2f 100644
--- a/monkey/utils.c
+++ b/monkey/utils.c
@@ -22,92 +22,6 @@
#include "utils/config.h"
#include "utils/utils.h"
-#include "utils/url.h"
-#include "utils/utf8.h"
-
-char *path_to_url(const char *path)
-{
- int urllen;
- char *url;
-
- if (path == NULL) {
- return NULL;
- }
-
- urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
-
- url = malloc(urllen);
- if (url == NULL) {
- return NULL;
- }
-
- if (*path == '/') {
- path++; /* file: paths are already absolute */
- }
-
- snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path);
-
- return url;
-}
-
-char *url_to_path(const char *url)
-{
- char *path;
- char *respath;
- url_func_result res; /* result from url routines */
-
- res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- res = url_unescape(path, &respath);
- free(path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- return respath;
-}
-
-/**
- * Return the filename part of a full path
- *
- * \param path full path and filename
- * \return filename (will be freed with free())
- */
-
-char *filename_from_path(char *path)
-{
- char *leafname;
-
- leafname = strrchr(path, '/');
- if (!leafname)
- leafname = path;
- else
- leafname += 1;
-
- return strdup(leafname);
-}
-
-/**
- * Add a path component/filename to an existing path
- *
- * \param path buffer containing path + free space
- * \param length length of buffer "path"
- * \param newpart string containing path component to add to path
- * \return true on success
- */
-
-bool path_add_part(char *path, int length, const char *newpart)
-{
- if(path[strlen(path) - 1] != '/')
- strncat(path, "/", length);
-
- strncat(path, newpart, length);
-
- return true;
-}
void warn_user(const char *warning, const char *detail)
{
@@ -119,21 +33,3 @@ void die(const char * const error)
fprintf(stderr, "DIE %s\n", error);
exit(EXIT_FAILURE);
}
-
-utf8_convert_ret
-utf8_to_local_encoding(const char *string, size_t len,
- char **result)
-{
- *result = strndup(string, len);
- return (*result == NULL) ? UTF8_CONVERT_NOMEM : UTF8_CONVERT_OK;
-}
-
-utf8_convert_ret
-utf8_from_local_encoding(const char *string, size_t len,
- char **result)
-{
- *result = strndup(string, len);
- return (*result == NULL) ? UTF8_CONVERT_NOMEM : UTF8_CONVERT_OK;
-}
-
-