summaryrefslogtreecommitdiff
path: root/frontends/monkey
diff options
context:
space:
mode:
Diffstat (limited to 'frontends/monkey')
-rw-r--r--frontends/monkey/401login.c32
-rw-r--r--frontends/monkey/bitmap.c112
-rw-r--r--frontends/monkey/browser.c596
-rw-r--r--frontends/monkey/browser.h14
-rw-r--r--frontends/monkey/cert.c32
-rw-r--r--frontends/monkey/dispatch.c110
-rw-r--r--frontends/monkey/download.c46
-rw-r--r--frontends/monkey/farmer.py363
-rw-r--r--frontends/monkey/fetch.c12
-rw-r--r--frontends/monkey/filetype.c4
-rw-r--r--frontends/monkey/layout.c62
-rw-r--r--frontends/monkey/main.c486
-rw-r--r--frontends/monkey/plot.c258
-rw-r--r--frontends/monkey/schedule.c288
14 files changed, 1481 insertions, 934 deletions
diff --git a/frontends/monkey/401login.c b/frontends/monkey/401login.c
index 8b4d33d7d..090f18984 100644
--- a/frontends/monkey/401login.c
+++ b/frontends/monkey/401login.c
@@ -24,11 +24,11 @@
#include "monkey/401login.h"
typedef struct monkey401 {
- struct monkey401 *r_next, *r_prev;
- uint32_t num;
- lwc_string *host; /* Ignore */
- nserror (*cb)(bool,void*);
- void *pw;
+ struct monkey401 *r_next, *r_prev;
+ uint32_t num;
+ lwc_string *host; /* Ignore */
+ nserror (*cb)(bool,void*);
+ void *pw;
} monkey401_t;
static monkey401_t *m4_ring = NULL;
@@ -37,19 +37,19 @@ static uint32_t m4_ctr = 0;
void gui_401login_open(nsurl *url, const char *realm,
nserror (*cb)(bool proceed, void *pw), void *cbpw)
{
- monkey401_t *m4t = calloc(sizeof(*m4t), 1);
- if (m4t == NULL) {
- cb(false, cbpw);
- return;
- }
- m4t->cb = cb;
- m4t->pw = cbpw;
- m4t->num = m4_ctr++;
+ monkey401_t *m4t = calloc(sizeof(*m4t), 1);
+ if (m4t == NULL) {
+ cb(false, cbpw);
+ return;
+ }
+ m4t->cb = cb;
+ m4t->pw = cbpw;
+ m4t->num = m4_ctr++;
- RING_INSERT(m4_ring, m4t);
+ RING_INSERT(m4_ring, m4t);
- fprintf(stdout, "401LOGIN OPEN M4 %u URL %s REALM %s\n",
- m4t->num, nsurl_access(url), realm);
+ fprintf(stdout, "401LOGIN OPEN M4 %u URL %s REALM %s\n",
+ m4t->num, nsurl_access(url), realm);
}
diff --git a/frontends/monkey/bitmap.c b/frontends/monkey/bitmap.c
index 3313e1123..83b8566b6 100644
--- a/frontends/monkey/bitmap.c
+++ b/frontends/monkey/bitmap.c
@@ -26,125 +26,125 @@
#include "monkey/bitmap.h"
struct bitmap {
- void *ptr;
- size_t rowstride;
- int width;
- int height;
- unsigned int state;
+ void *ptr;
+ size_t rowstride;
+ int width;
+ int height;
+ unsigned int state;
};
static void *bitmap_create(int width, int height, unsigned int state)
{
- struct bitmap *ret = calloc(sizeof(*ret), 1);
- if (ret == NULL)
- return NULL;
+ struct bitmap *ret = calloc(sizeof(*ret), 1);
+ if (ret == NULL)
+ return NULL;
- ret->width = width;
- ret->height = height;
- ret->state = state;
+ ret->width = width;
+ ret->height = height;
+ ret->state = state;
- ret->ptr = calloc(width, height * 4);
+ ret->ptr = calloc(width, height * 4);
- if (ret->ptr == NULL) {
- free(ret);
- return NULL;
- }
+ if (ret->ptr == NULL) {
+ free(ret);
+ return NULL;
+ }
- return ret;
+ return ret;
}
static void bitmap_destroy(void *bitmap)
{
- struct bitmap *bmap = bitmap;
- free(bmap->ptr);
- free(bmap);
+ struct bitmap *bmap = bitmap;
+ free(bmap->ptr);
+ free(bmap);
}
static void bitmap_set_opaque(void *bitmap, bool opaque)
{
- struct bitmap *bmap = bitmap;
+ struct bitmap *bmap = bitmap;
- if (opaque)
- bmap->state |= (BITMAP_OPAQUE);
- else
- bmap->state &= ~(BITMAP_OPAQUE);
+ if (opaque)
+ bmap->state |= (BITMAP_OPAQUE);
+ else
+ bmap->state &= ~(BITMAP_OPAQUE);
}
static bool bitmap_test_opaque(void *bitmap)
{
- return false;
+ return false;
}
static bool bitmap_get_opaque(void *bitmap)
{
- struct bitmap *bmap = bitmap;
+ struct bitmap *bmap = bitmap;
- return (bmap->state & BITMAP_OPAQUE) == BITMAP_OPAQUE;
+ return (bmap->state & BITMAP_OPAQUE) == BITMAP_OPAQUE;
}
static unsigned char *bitmap_get_buffer(void *bitmap)
{
- struct bitmap *bmap = bitmap;
+ struct bitmap *bmap = bitmap;
- return (unsigned char *)(bmap->ptr);
+ return (unsigned char *)(bmap->ptr);
}
static size_t bitmap_get_rowstride(void *bitmap)
{
- struct bitmap *bmap = bitmap;
- return bmap->width * 4;
+ struct bitmap *bmap = bitmap;
+ return bmap->width * 4;
}
static size_t bitmap_get_bpp(void *bitmap)
{
- /* OMG?! */
- return 4;
+ /* OMG?! */
+ return 4;
}
static bool bitmap_save(void *bitmap, const char *path, unsigned flags)
{
- return true;
+ return true;
}
static void bitmap_modified(void *bitmap)
{
- struct bitmap *bmap = bitmap;
- bmap->state |= BITMAP_MODIFIED;
+ struct bitmap *bmap = bitmap;
+ bmap->state |= BITMAP_MODIFIED;
}
static int bitmap_get_width(void *bitmap)
{
- struct bitmap *bmap = bitmap;
- return bmap->width;
+ struct bitmap *bmap = bitmap;
+ return bmap->width;
}
static int bitmap_get_height(void *bitmap)
{
- struct bitmap *bmap = bitmap;
- return bmap->height;
+ struct bitmap *bmap = bitmap;
+ return bmap->height;
}
static nserror bitmap_render(struct bitmap *bitmap,
struct hlcache_handle *content)
{
- fprintf(stdout, "GENERIC BITMAP RENDER\n");
- return NSERROR_OK;
+ fprintf(stdout, "GENERIC BITMAP RENDER\n");
+ return NSERROR_OK;
}
static struct gui_bitmap_table bitmap_table = {
- .create = bitmap_create,
- .destroy = bitmap_destroy,
- .set_opaque = bitmap_set_opaque,
- .get_opaque = bitmap_get_opaque,
- .test_opaque = bitmap_test_opaque,
- .get_buffer = bitmap_get_buffer,
- .get_rowstride = bitmap_get_rowstride,
- .get_width = bitmap_get_width,
- .get_height = bitmap_get_height,
- .get_bpp = bitmap_get_bpp,
- .save = bitmap_save,
- .modified = bitmap_modified,
- .render = bitmap_render,
+ .create = bitmap_create,
+ .destroy = bitmap_destroy,
+ .set_opaque = bitmap_set_opaque,
+ .get_opaque = bitmap_get_opaque,
+ .test_opaque = bitmap_test_opaque,
+ .get_buffer = bitmap_get_buffer,
+ .get_rowstride = bitmap_get_rowstride,
+ .get_width = bitmap_get_width,
+ .get_height = bitmap_get_height,
+ .get_bpp = bitmap_get_bpp,
+ .save = bitmap_save,
+ .modified = bitmap_modified,
+ .render = bitmap_render,
};
struct gui_bitmap_table *monkey_bitmap_table = &bitmap_table;
diff --git a/frontends/monkey/browser.c b/frontends/monkey/browser.c
index 3bf0dd036..1fbbbf0b1 100644
--- a/frontends/monkey/browser.c
+++ b/frontends/monkey/browser.c
@@ -42,287 +42,306 @@ static struct gui_window *gw_ring = NULL;
/* exported function documented in monkey/browser.h */
nserror monkey_warn_user(const char *warning, const char *detail)
{
- fprintf(stderr, "WARN %s %s\n", warning, detail);
- return NSERROR_OK;
+ fprintf(stderr, "WARN %s %s\n", warning, detail);
+ return NSERROR_OK;
}
struct gui_window *
monkey_find_window_by_num(uint32_t win_num)
{
- struct gui_window *ret = NULL;
+ struct gui_window *ret = NULL;
- RING_ITERATE_START(struct gui_window, gw_ring, c_ring) {
- if (c_ring->win_num == win_num) {
- ret = c_ring;
- RING_ITERATE_STOP(gw_ring, c_ring);
- }
- } RING_ITERATE_END(gw_ring, c_ring);
+ RING_ITERATE_START(struct gui_window, gw_ring, c_ring) {
+ if (c_ring->win_num == win_num) {
+ ret = c_ring;
+ RING_ITERATE_STOP(gw_ring, c_ring);
+ }
+ } RING_ITERATE_END(gw_ring, c_ring);
- return ret;
-}
-
-
-/**
- * callback from core to reformat a window.
- */
-static void monkey_window_reformat(struct gui_window *gw)
-{
- browser_window_reformat(gw->bw, false, gw->width, gw->height);
+ return ret;
}
void
monkey_kill_browser_windows(void)
{
- while (gw_ring != NULL) {
- browser_window_destroy(gw_ring->bw);
- }
+ while (gw_ring != NULL) {
+ browser_window_destroy(gw_ring->bw);
+ }
}
static struct gui_window *
gui_window_create(struct browser_window *bw,
- struct gui_window *existing,
- gui_window_create_flags flags)
+ struct gui_window *existing,
+ gui_window_create_flags flags)
{
- struct gui_window *ret = calloc(sizeof(*ret), 1);
- if (ret == NULL)
- return NULL;
+ struct gui_window *ret = calloc(sizeof(*ret), 1);
+ if (ret == NULL)
+ return NULL;
- ret->win_num = win_ctr++;
- ret->bw = bw;
+ ret->win_num = win_ctr++;
+ ret->bw = bw;
- ret->width = 800;
- ret->height = 600;
+ ret->width = 800;
+ ret->height = 600;
- 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);
+ 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);
- RING_INSERT(gw_ring, ret);
+ RING_INSERT(gw_ring, ret);
- return ret;
+ return ret;
}
static void
gui_window_destroy(struct gui_window *g)
{
- fprintf(stdout, "WINDOW DESTROY WIN %u\n", g->win_num);
- RING_REMOVE(gw_ring, g);
- free(g);
+ fprintf(stdout, "WINDOW DESTROY WIN %u\n", g->win_num);
+ RING_REMOVE(gw_ring, g);
+ free(g);
}
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);
-}
-
-static void
-gui_window_redraw_window(struct gui_window *g)
-{
- fprintf(stdout, "WINDOW REDRAW WIN %u\n", g->win_num);
+ fprintf(stdout, "WINDOW TITLE WIN %u STR %s\n", g->win_num, title);
}
-static void
+/**
+ * Find the current dimensions of a monkey browser window content area.
+ *
+ * \param g The gui window to measure content area of.
+ * \param width receives width of window
+ * \param height receives height of window
+ * \param scaled whether to return scaled values
+ * \return NSERROR_OK on sucess and width and height updated.
+ */
+static nserror
gui_window_get_dimensions(struct gui_window *g, int *width, int *height,
bool scaled)
{
- fprintf(stdout, "WINDOW GET_DIMENSIONS WIN %u WIDTH %d HEIGHT %d\n",
- g->win_num, g->width, g->height);
- *width = g->width;
- *height = g->height;
+ fprintf(stdout, "WINDOW GET_DIMENSIONS WIN %u WIDTH %d HEIGHT %d\n",
+ g->win_num, g->width, g->height);
+ *width = g->width;
+ *height = g->height;
+
+ return NSERROR_OK;
}
static void
gui_window_new_content(struct gui_window *g)
{
- fprintf(stdout, "WINDOW NEW_CONTENT WIN %u\n", g->win_num);
+ fprintf(stdout, "WINDOW NEW_CONTENT WIN %u\n", g->win_num);
}
static void
gui_window_set_icon(struct gui_window *g, struct hlcache_handle *icon)
{
- fprintf(stdout, "WINDOW NEW_ICON WIN %u\n", g->win_num);
+ fprintf(stdout, "WINDOW NEW_ICON WIN %u\n", g->win_num);
}
static void
gui_window_start_throbber(struct gui_window *g)
{
- fprintf(stdout, "WINDOW START_THROBBER WIN %u\n", g->win_num);
+ fprintf(stdout, "WINDOW START_THROBBER WIN %u\n", g->win_num);
}
static void
gui_window_stop_throbber(struct gui_window *g)
{
- fprintf(stdout, "WINDOW STOP_THROBBER WIN %u\n", g->win_num);
+ fprintf(stdout, "WINDOW STOP_THROBBER WIN %u\n", g->win_num);
}
-static void
-gui_window_set_scroll(struct gui_window *g, int sx, int sy)
+
+/**
+ * Set the scroll position of a monkey browser window.
+ *
+ * Scrolls the viewport to ensure the specified rectangle of the
+ * content is shown.
+ *
+ * \param gw gui window to scroll
+ * \param rect The rectangle to ensure is shown.
+ * \return NSERROR_OK on success or apropriate error code.
+ */
+static nserror
+gui_window_set_scroll(struct gui_window *gw, const struct rect *rect)
{
- g->scrollx = sx;
- g->scrolly = sy;
- fprintf(stdout, "WINDOW SET_SCROLL WIN %u X %d Y %d\n", g->win_num, sx, sy);
+ gw->scrollx = rect->x0;
+ gw->scrolly = rect->y0;
+
+ fprintf(stdout, "WINDOW SET_SCROLL WIN %u X %d Y %d\n",
+ gw->win_num, rect->x0, rect->y0);
+ return NSERROR_OK;
}
-static void
-gui_window_update_box(struct gui_window *g, const struct rect *rect)
+
+/**
+ * Invalidates an area of a monkey browser window
+ *
+ * \param gw gui_window
+ * \param rect area to redraw or NULL for the entire window area
+ * \return NSERROR_OK on success or appropriate error code
+ */
+static nserror
+monkey_window_invalidate_area(struct gui_window *gw, const struct rect *rect)
{
- fprintf(stdout, "WINDOW UPDATE_BOX WIN %u X %d Y %d WIDTH %d HEIGHT %d\n",
- g->win_num, rect->x0, rect->y0,
- (rect->x1 - rect->x0), (rect->y1 - rect->y0));
-
+ fprintf(stdout, "WINDOW INVALIDATE_AREA WIN %u", gw->win_num);
+
+ if (rect != NULL) {
+ fprintf(stdout,
+ " X %d Y %d WIDTH %d HEIGHT %d\n",
+ rect->x0, rect->y0,
+ (rect->x1 - rect->x0), (rect->y1 - rect->y0));
+ } else {
+ fprintf(stdout," ALL\n");
+ }
+
+ return NSERROR_OK;
}
static void
gui_window_update_extent(struct gui_window *g)
{
- int width, height;
+ int width, height;
- if (browser_window_get_extents(g->bw, false, &width, &height) != NSERROR_OK)
- return;
+ if (browser_window_get_extents(g->bw, false, &width, &height) != NSERROR_OK)
+ return;
- fprintf(stdout, "WINDOW UPDATE_EXTENT WIN %u WIDTH %d HEIGHT %d\n",
- g->win_num, width, height);
+ fprintf(stdout, "WINDOW UPDATE_EXTENT WIN %u WIDTH %d HEIGHT %d\n",
+ g->win_num, width, height);
}
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);
+ fprintf(stdout, "WINDOW SET_STATUS WIN %u STR %s\n", g->win_num, text);
}
static void
gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
{
- const char *ptr_name = "UNKNOWN";
+ const char *ptr_name = "UNKNOWN";
- switch (shape) {
- case GUI_POINTER_POINT:
- ptr_name = "POINT";
- break;
- case GUI_POINTER_CARET:
- ptr_name = "CARET";
- break;
- case GUI_POINTER_UP:
- ptr_name = "UP";
- break;
- case GUI_POINTER_DOWN:
- ptr_name = "DOWN";
- break;
- case GUI_POINTER_LEFT:
- ptr_name = "LEFT";
- break;
- case GUI_POINTER_RIGHT:
- ptr_name = "RIGHT";
- break;
- case GUI_POINTER_LD:
- ptr_name = "LD";
- break;
- case GUI_POINTER_RD:
- ptr_name = "RD";
- break;
- case GUI_POINTER_LU:
- ptr_name = "LU";
- break;
- case GUI_POINTER_RU:
- ptr_name = "RU";
- break;
- case GUI_POINTER_CROSS:
- ptr_name = "CROSS";
- break;
- case GUI_POINTER_MOVE:
- ptr_name = "MOVE";
- break;
- case GUI_POINTER_WAIT:
- ptr_name = "WAIT";
- break;
- case GUI_POINTER_HELP:
- ptr_name = "HELP";
- break;
- case GUI_POINTER_MENU:
- ptr_name = "MENU";
- break;
- case GUI_POINTER_PROGRESS:
- ptr_name = "PROGRESS";
- break;
- case GUI_POINTER_NO_DROP:
- ptr_name = "NO_DROP";
- break;
- case GUI_POINTER_NOT_ALLOWED:
- ptr_name = "NOT_ALLOWED";
- break;
- case GUI_POINTER_DEFAULT:
- ptr_name = "DEFAULT";
- break;
- default:
- break;
- }
- fprintf(stdout, "WINDOW SET_POINTER WIN %u POINTER %s\n", g->win_num, ptr_name);
+ switch (shape) {
+ case GUI_POINTER_POINT:
+ ptr_name = "POINT";
+ break;
+ case GUI_POINTER_CARET:
+ ptr_name = "CARET";
+ break;
+ case GUI_POINTER_UP:
+ ptr_name = "UP";
+ break;
+ case GUI_POINTER_DOWN:
+ ptr_name = "DOWN";
+ break;
+ case GUI_POINTER_LEFT:
+ ptr_name = "LEFT";
+ break;
+ case GUI_POINTER_RIGHT:
+ ptr_name = "RIGHT";
+ break;
+ case GUI_POINTER_LD:
+ ptr_name = "LD";
+ break;
+ case GUI_POINTER_RD:
+ ptr_name = "RD";
+ break;
+ case GUI_POINTER_LU:
+ ptr_name = "LU";
+ break;
+ case GUI_POINTER_RU:
+ ptr_name = "RU";
+ break;
+ case GUI_POINTER_CROSS:
+ ptr_name = "CROSS";
+ break;
+ case GUI_POINTER_MOVE:
+ ptr_name = "MOVE";
+ break;
+ case GUI_POINTER_WAIT:
+ ptr_name = "WAIT";
+ break;
+ case GUI_POINTER_HELP:
+ ptr_name = "HELP";
+ break;
+ case GUI_POINTER_MENU:
+ ptr_name = "MENU";
+ break;
+ case GUI_POINTER_PROGRESS:
+ ptr_name = "PROGRESS";
+ break;
+ case GUI_POINTER_NO_DROP:
+ ptr_name = "NO_DROP";
+ break;
+ case GUI_POINTER_NOT_ALLOWED:
+ ptr_name = "NOT_ALLOWED";
+ break;
+ case GUI_POINTER_DEFAULT:
+ ptr_name = "DEFAULT";
+ break;
+ default:
+ break;
+ }
+ fprintf(stdout, "WINDOW SET_POINTER WIN %u POINTER %s\n", g->win_num, ptr_name);
}
static nserror
gui_window_set_url(struct gui_window *g, nsurl *url)
{
- fprintf(stdout, "WINDOW SET_URL WIN %u URL %s\n", g->win_num, nsurl_access(url));
- return NSERROR_OK;
+ fprintf(stdout, "WINDOW SET_URL WIN %u URL %s\n", g->win_num, nsurl_access(url));
+ return NSERROR_OK;
}
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",
- g->win_num, g->scrollx, g->scrolly);
- *sx = g->scrollx;
- *sy = g->scrolly;
- return true;
+ fprintf(stdout, "WINDOW GET_SCROLL WIN %u X %d Y %d\n",
+ g->win_num, g->scrollx, g->scrolly);
+ *sx = g->scrollx;
+ *sy = g->scrolly;
+ return true;
}
static bool
gui_window_scroll_start(struct gui_window *g)
{
- fprintf(stdout, "WINDOW SCROLL_START WIN %u\n", g->win_num);
- g->scrollx = g->scrolly = 0;
- return true;
+ fprintf(stdout, "WINDOW SCROLL_START WIN %u\n", g->win_num);
+ g->scrollx = g->scrolly = 0;
+ return true;
}
-static void
-gui_window_scroll_visible(struct gui_window *g, int x0, int y0,
- int x1, int y1)
-{
- fprintf(stdout, "WINDOW SCROLL_VISIBLE WIN %u X0 %d Y0 %d X1 %d Y1 %d\n",
- g->win_num, x0, y0, x1, y1);
-}
static void
gui_window_place_caret(struct gui_window *g, int x, int y, int height,
- const struct rect *clip)
+ const struct rect *clip)
{
- fprintf(stdout, "WINDOW PLACE_CARET WIN %u X %d Y %d HEIGHT %d\n",
- g->win_num, x, y, height);
+ fprintf(stdout, "WINDOW PLACE_CARET WIN %u X %d Y %d HEIGHT %d\n",
+ g->win_num, x, y, height);
}
static void
gui_window_remove_caret(struct gui_window *g)
{
- fprintf(stdout, "WINDOW REMOVE_CARET WIN %u\n", g->win_num);
+ fprintf(stdout, "WINDOW REMOVE_CARET WIN %u\n", g->win_num);
}
static bool
gui_window_drag_start(struct gui_window *g, gui_drag_type type,
const struct rect *rect)
{
- fprintf(stdout, "WINDOW SCROLL_START WIN %u TYPE %i\n", g->win_num, type);
- return false;
+ fprintf(stdout, "WINDOW SCROLL_START WIN %u TYPE %i\n", g->win_num, type);
+ return false;
}
static nserror
gui_window_save_link(struct gui_window *g, nsurl *url, const char *title)
{
- fprintf(stdout, "WINDOW SAVE_LINK WIN %u URL %s TITLE %s\n",
- g->win_num, nsurl_access(url), title);
- return NSERROR_OK;
+ fprintf(stdout, "WINDOW SAVE_LINK WIN %u URL %s TITLE %s\n",
+ g->win_num, nsurl_access(url), title);
+ return NSERROR_OK;
}
@@ -332,182 +351,180 @@ gui_window_save_link(struct gui_window *g, nsurl *url, const char *title)
static void
monkey_window_handle_new(int argc, char **argv)
{
- nsurl *url = NULL;
- nserror error = NSERROR_OK;
-
- if (argc > 3)
- return;
-
- if (argc == 3) {
- error = nsurl_create(argv[2], &url);
- }
- if (error == NSERROR_OK) {
- error = browser_window_create(BW_CREATE_HISTORY,
- url,
- NULL,
- NULL,
- NULL);
- if (url != NULL) {
- nsurl_unref(url);
- }
- }
- if (error != NSERROR_OK) {
- monkey_warn_user(messages_get_errorcode(error), 0);
- }
+ nsurl *url = NULL;
+ nserror error = NSERROR_OK;
+
+ if (argc > 3)
+ return;
+
+ if (argc == 3) {
+ error = nsurl_create(argv[2], &url);
+ }
+ if (error == NSERROR_OK) {
+ error = browser_window_create(BW_CREATE_HISTORY,
+ url,
+ NULL,
+ NULL,
+ NULL);
+ if (url != NULL) {
+ nsurl_unref(url);
+ }
+ }
+ if (error != NSERROR_OK) {
+ monkey_warn_user(messages_get_errorcode(error), 0);
+ }
}
static void
monkey_window_handle_destroy(int argc, char **argv)
{
- struct gui_window *gw;
- uint32_t nr = atoi((argc > 2) ? argv[2] : "-1");
+ struct gui_window *gw;
+ uint32_t nr = atoi((argc > 2) ? argv[2] : "-1");
- gw = monkey_find_window_by_num(nr);
+ gw = monkey_find_window_by_num(nr);
- if (gw == NULL) {
- fprintf(stdout, "ERROR WINDOW NUM BAD\n");
- } else {
- browser_window_destroy(gw->bw);
- }
+ if (gw == NULL) {
+ fprintf(stdout, "ERROR WINDOW NUM BAD\n");
+ } else {
+ browser_window_destroy(gw->bw);
+ }
}
static void
monkey_window_handle_go(int argc, char **argv)
{
- struct gui_window *gw;
- nsurl *url;
- nsurl *ref_url = NULL;
- nserror error;
+ struct gui_window *gw;
+ nsurl *url;
+ nsurl *ref_url = NULL;
+ nserror error;
- if (argc < 4 || argc > 5) {
- fprintf(stdout, "ERROR WINDOW GO ARGS BAD\n");
- return;
- }
+ if (argc < 4 || argc > 5) {
+ fprintf(stdout, "ERROR WINDOW GO ARGS BAD\n");
+ return;
+ }
- gw = monkey_find_window_by_num(atoi(argv[2]));
+ gw = monkey_find_window_by_num(atoi(argv[2]));
- if (gw == NULL) {
- fprintf(stdout, "ERROR WINDOW NUM BAD\n");
- return;
- }
-
- error = nsurl_create(argv[3], &url);
- if (error == NSERROR_OK) {
- if (argc == 5) {
- error = nsurl_create(argv[4], &ref_url);
- }
-
- if (error == NSERROR_OK) {
- error = browser_window_navigate(gw->bw,
- url,
- ref_url,
- BW_NAVIGATE_HISTORY,
- NULL,
- NULL,
- NULL);
- if (ref_url != NULL) {
- nsurl_unref(ref_url);
- }
- }
- nsurl_unref(url);
- }
-
- if (error != NSERROR_OK) {
- monkey_warn_user(messages_get_errorcode(error), 0);
- }
+ if (gw == NULL) {
+ fprintf(stdout, "ERROR WINDOW NUM BAD\n");
+ return;
+ }
+
+ error = nsurl_create(argv[3], &url);
+ if (error == NSERROR_OK) {
+ if (argc == 5) {
+ error = nsurl_create(argv[4], &ref_url);
+ }
+
+ if (error == NSERROR_OK) {
+ error = browser_window_navigate(gw->bw,
+ url,
+ ref_url,
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ NULL,
+ NULL);
+ if (ref_url != NULL) {
+ nsurl_unref(ref_url);
+ }
+ }
+ nsurl_unref(url);
+ }
+
+ if (error != NSERROR_OK) {
+ monkey_warn_user(messages_get_errorcode(error), 0);
+ }
}
static void
monkey_window_handle_redraw(int argc, char **argv)
{
- struct gui_window *gw;
- struct rect clip;
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = monkey_plotters
- };
+ struct gui_window *gw;
+ struct rect clip;
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = monkey_plotters
+ };
- if (argc != 3 && argc != 7) {
- fprintf(stdout, "ERROR WINDOW REDRAW ARGS BAD\n");
- return;
- }
+ if (argc != 3 && argc != 7) {
+ fprintf(stdout, "ERROR WINDOW REDRAW ARGS BAD\n");
+ return;
+ }
- gw = monkey_find_window_by_num(atoi(argv[2]));
+ gw = monkey_find_window_by_num(atoi(argv[2]));
- if (gw == NULL) {
- fprintf(stdout, "ERROR WINDOW NUM BAD\n");
- return;
- }
+ if (gw == NULL) {
+ fprintf(stdout, "ERROR WINDOW NUM BAD\n");
+ return;
+ }
- clip.x0 = 0;
- clip.y0 = 0;
- clip.x1 = gw->width;
- clip.y1 = gw->height;
+ clip.x0 = 0;
+ clip.y0 = 0;
+ clip.x1 = gw->width;
+ clip.y1 = gw->height;
- if (argc == 7) {
- clip.x0 = atoi(argv[3]);
- clip.y0 = atoi(argv[4]);
- clip.x1 = atoi(argv[5]);
- clip.y1 = atoi(argv[6]);
- }
+ if (argc == 7) {
+ clip.x0 = atoi(argv[3]);
+ clip.y0 = atoi(argv[4]);
+ clip.x1 = atoi(argv[5]);
+ clip.y1 = atoi(argv[6]);
+ }
- LOG("Issue redraw");
- fprintf(stdout, "WINDOW REDRAW WIN %d START\n", atoi(argv[2]));
- browser_window_redraw(gw->bw, gw->scrollx, gw->scrolly, &clip, &ctx);
- fprintf(stdout, "WINDOW REDRAW WIN %d STOP\n", atoi(argv[2]));
+ NSLOG(netsurf, INFO, "Issue redraw");
+ fprintf(stdout, "WINDOW REDRAW WIN %d START\n", atoi(argv[2]));
+ browser_window_redraw(gw->bw, gw->scrollx, gw->scrolly, &clip, &ctx);
+ fprintf(stdout, "WINDOW REDRAW WIN %d STOP\n", atoi(argv[2]));
}
static void
monkey_window_handle_reload(int argc, char **argv)
{
- struct gui_window *gw;
- if (argc != 3 && argc != 4) {
- fprintf(stdout, "ERROR WINDOW RELOAD ARGS BAD\n");
- }
+ struct gui_window *gw;
+ if (argc != 3 && argc != 4) {
+ fprintf(stdout, "ERROR WINDOW RELOAD ARGS BAD\n");
+ }
- gw = monkey_find_window_by_num(atoi(argv[2]));
+ gw = monkey_find_window_by_num(atoi(argv[2]));
- if (gw == NULL) {
- fprintf(stdout, "ERROR WINDOW NUM BAD\n");
- } else {
- browser_window_reload(gw->bw, argc == 4);
- }
+ if (gw == NULL) {
+ fprintf(stdout, "ERROR WINDOW NUM BAD\n");
+ } else {
+ browser_window_reload(gw->bw, argc == 4);
+ }
}
void
monkey_window_handle_command(int argc, char **argv)
{
- if (argc == 1)
- return;
+ if (argc == 1)
+ return;
- if (strcmp(argv[1], "NEW") == 0) {
- monkey_window_handle_new(argc, argv);
- } else if (strcmp(argv[1], "DESTROY") == 0) {
- monkey_window_handle_destroy(argc, argv);
- } else if (strcmp(argv[1], "GO") == 0) {
- monkey_window_handle_go(argc, argv);
- } else if (strcmp(argv[1], "REDRAW") == 0) {
- monkey_window_handle_redraw(argc, argv);
- } else if (strcmp(argv[1], "RELOAD") == 0) {
- monkey_window_handle_reload(argc, argv);
- } else {
- fprintf(stdout, "ERROR WINDOW COMMAND UNKNOWN %s\n", argv[1]);
- }
+ if (strcmp(argv[1], "NEW") == 0) {
+ monkey_window_handle_new(argc, argv);
+ } else if (strcmp(argv[1], "DESTROY") == 0) {
+ monkey_window_handle_destroy(argc, argv);
+ } else if (strcmp(argv[1], "GO") == 0) {
+ monkey_window_handle_go(argc, argv);
+ } else if (strcmp(argv[1], "REDRAW") == 0) {
+ monkey_window_handle_redraw(argc, argv);
+ } else if (strcmp(argv[1], "RELOAD") == 0) {
+ monkey_window_handle_reload(argc, argv);
+ } else {
+ fprintf(stdout, "ERROR WINDOW COMMAND UNKNOWN %s\n", argv[1]);
+ }
}
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,
+ .invalidate = monkey_window_invalidate_area,
.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,
@@ -518,7 +535,6 @@ static struct gui_window_table window_table = {
.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,
diff --git a/frontends/monkey/browser.h b/frontends/monkey/browser.h
index 2b0340211..8cbbb947d 100644
--- a/frontends/monkey/browser.h
+++ b/frontends/monkey/browser.h
@@ -25,16 +25,16 @@ 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;
+ struct gui_window *r_next;
+ struct gui_window *r_prev;
- uint32_t win_num;
- struct browser_window *bw;
+ uint32_t win_num;
+ struct browser_window *bw;
- int width, height;
- int scrollx, scrolly;
+ int width, height;
+ int scrollx, scrolly;
- char *host; /* Ignore this, it's in case RING*() gets debugging for fetchers */
+ char *host; /* Ignore this, it's in case RING*() gets debugging for fetchers */
};
diff --git a/frontends/monkey/cert.c b/frontends/monkey/cert.c
index 710e71098..a19975527 100644
--- a/frontends/monkey/cert.c
+++ b/frontends/monkey/cert.c
@@ -25,11 +25,11 @@
#include "monkey/cert.h"
typedef struct monkey_cert {
- struct monkey_cert *r_next, *r_prev;
- uint32_t num;
- char *host; /* Ignore */
- nserror (*cb)(bool,void*);
- void *pw;
+ struct monkey_cert *r_next, *r_prev;
+ uint32_t num;
+ char *host; /* Ignore */
+ nserror (*cb)(bool,void*);
+ void *pw;
} monkey_cert_t;
static monkey_cert_t *cert_ring = NULL;
@@ -40,20 +40,20 @@ gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
unsigned long num, nserror (*cb)(bool proceed, void *pw),
void *cbpw)
{
- monkey_cert_t *m4t = calloc(sizeof(*m4t), 1);
- if (m4t == NULL) {
- return NSERROR_NOMEM;
- }
- m4t->cb = cb;
- m4t->pw = cbpw;
- m4t->num = cert_ctr++;
+ monkey_cert_t *m4t = calloc(sizeof(*m4t), 1);
+ if (m4t == NULL) {
+ return NSERROR_NOMEM;
+ }
+ m4t->cb = cb;
+ m4t->pw = cbpw;
+ m4t->num = cert_ctr++;
- RING_INSERT(cert_ring, m4t);
+ RING_INSERT(cert_ring, m4t);
- fprintf(stdout, "SSLCERT VERIFY CERT %u URL %s\n",
- m4t->num, nsurl_access(url));
+ fprintf(stdout, "SSLCERT VERIFY CERT %u URL %s\n",
+ m4t->num, nsurl_access(url));
- return NSERROR_OK;
+ return NSERROR_OK;
}
diff --git a/frontends/monkey/dispatch.c b/frontends/monkey/dispatch.c
index 563534d64..e60325cf1 100644
--- a/frontends/monkey/dispatch.c
+++ b/frontends/monkey/dispatch.c
@@ -28,9 +28,9 @@
#include "monkey/dispatch.h"
typedef struct cmdhandler {
- struct cmdhandler *r_next, *r_prev;
- const char *cmd;
- handle_command_fn fn;
+ struct cmdhandler *r_next, *r_prev;
+ const char *cmd;
+ handle_command_fn fn;
} monkey_cmdhandler_t;
static monkey_cmdhandler_t *handler_ring = NULL;
@@ -38,68 +38,68 @@ static monkey_cmdhandler_t *handler_ring = NULL;
nserror
monkey_register_handler(const char *cmd, handle_command_fn fn)
{
- monkey_cmdhandler_t *ret = calloc(sizeof(*ret), 1);
- if (ret == NULL) {
- LOG("Unable to allocate handler");
- return NSERROR_NOMEM;
- }
- ret->cmd = strdup(cmd);
- ret->fn = fn;
- RING_INSERT(handler_ring, ret);
- return NSERROR_OK;
+ monkey_cmdhandler_t *ret = calloc(sizeof(*ret), 1);
+ if (ret == NULL) {
+ NSLOG(netsurf, INFO, "Unable to allocate handler");
+ return NSERROR_NOMEM;
+ }
+ ret->cmd = strdup(cmd);
+ ret->fn = fn;
+ RING_INSERT(handler_ring, ret);
+ return NSERROR_OK;
}
void
monkey_process_command(void)
{
- char buffer[PATH_MAX];
- int argc = 0;
- char **argv = NULL;
- char *p, *r = NULL;
- handle_command_fn fn = NULL;
- char **nargv;
+ char buffer[PATH_MAX];
+ int argc = 0;
+ char **argv = NULL;
+ char *p, *r = NULL;
+ handle_command_fn fn = NULL;
+ char **nargv;
- if (fgets(buffer, PATH_MAX, stdin) == NULL) {
- /* end of input or read error so issue QUIT */
- sprintf(buffer, "QUIT\n");
- }
+ if (fgets(buffer, PATH_MAX, stdin) == NULL) {
+ /* end of input or read error so issue QUIT */
+ sprintf(buffer, "QUIT\n");
+ }
- /* remove newline */
- buffer[strlen(buffer) - 1] = '\0';
+ /* remove newline */
+ buffer[strlen(buffer) - 1] = '\0';
- argv = malloc(sizeof *argv);
- if (argv == NULL) {
- return;
- }
- argc = 1;
- *argv = buffer;
+ argv = malloc(sizeof *argv);
+ if (argv == NULL) {
+ return;
+ }
+ argc = 1;
+ *argv = buffer;
- for (p = r = buffer; *p != '\0'; p++) {
- if (*p == ' ') {
- 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';
- }
- }
+ for (p = r = buffer; *p != '\0'; p++) {
+ if (*p == ' ') {
+ 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';
+ }
+ }
- RING_ITERATE_START(monkey_cmdhandler_t, handler_ring, handler) {
- if (strcmp(argv[0], handler->cmd) == 0) {
- fn = handler->fn;
- RING_ITERATE_STOP(handler_ring, handler);
- }
- } RING_ITERATE_END(handler_ring, handler);
+ RING_ITERATE_START(monkey_cmdhandler_t, handler_ring, handler) {
+ if (strcmp(argv[0], handler->cmd) == 0) {
+ fn = handler->fn;
+ RING_ITERATE_STOP(handler_ring, handler);
+ }
+ } RING_ITERATE_END(handler_ring, handler);
- if (fn != NULL) {
- fn(argc, argv);
- }
+ if (fn != NULL) {
+ fn(argc, argv);
+ }
- free(argv);
+ free(argv);
}
diff --git a/frontends/monkey/download.c b/frontends/monkey/download.c
index f2e1cbfbf..5c9ce1b53 100644
--- a/frontends/monkey/download.c
+++ b/frontends/monkey/download.c
@@ -30,11 +30,11 @@
static uint32_t dwin_ctr = 0;
struct gui_download_window {
- struct gui_download_window *r_next;
- struct gui_download_window *r_prev;
- struct gui_window *g;
- uint32_t dwin_num;
- char *host; /* ignore */
+ struct gui_download_window *r_next;
+ struct gui_download_window *r_prev;
+ struct gui_window *g;
+ uint32_t dwin_num;
+ char *host; /* ignore */
};
static struct gui_download_window *dw_ring = NULL;
@@ -43,44 +43,44 @@ static struct gui_download_window *
gui_download_window_create(download_context *ctx,
struct gui_window *parent)
{
- struct gui_download_window *ret = calloc(sizeof(*ret), 1);
- if (ret == NULL)
- return NULL;
- ret->g = parent;
- ret->dwin_num = dwin_ctr++;
+ struct gui_download_window *ret = calloc(sizeof(*ret), 1);
+ if (ret == NULL)
+ return NULL;
+ ret->g = parent;
+ ret->dwin_num = dwin_ctr++;
- RING_INSERT(dw_ring, ret);
+ RING_INSERT(dw_ring, ret);
- fprintf(stdout, "DOWNLOAD_WINDOW CREATE DWIN %u WIN %u\n",
- ret->dwin_num, parent->win_num);
+ fprintf(stdout, "DOWNLOAD_WINDOW CREATE DWIN %u WIN %u\n",
+ ret->dwin_num, parent->win_num);
- return ret;
+ return ret;
}
static nserror
gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
- fprintf(stdout, "DOWNLOAD_WINDOW DATA DWIN %u SIZE %u DATA %s\n",
- dw->dwin_num, size, data);
- return NSERROR_OK;
+ fprintf(stdout, "DOWNLOAD_WINDOW DATA DWIN %u SIZE %u DATA %s\n",
+ dw->dwin_num, size, data);
+ return NSERROR_OK;
}
static void
gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
- fprintf(stdout, "DOWNLOAD_WINDOW ERROR DWIN %u ERROR %s\n",
- dw->dwin_num, error_msg);
+ fprintf(stdout, "DOWNLOAD_WINDOW ERROR DWIN %u ERROR %s\n",
+ dw->dwin_num, error_msg);
}
static void
gui_download_window_done(struct gui_download_window *dw)
{
- fprintf(stdout, "DOWNLOAD_WINDOW DONE DWIN %u\n",
- dw->dwin_num);
- RING_REMOVE(dw_ring, dw);
- free(dw);
+ fprintf(stdout, "DOWNLOAD_WINDOW DONE DWIN %u\n",
+ dw->dwin_num);
+ RING_REMOVE(dw_ring, dw);
+ free(dw);
}
static struct gui_download_table download_table = {
diff --git a/frontends/monkey/farmer.py b/frontends/monkey/farmer.py
new file mode 100644
index 000000000..d4b4b1e21
--- /dev/null
+++ b/frontends/monkey/farmer.py
@@ -0,0 +1,363 @@
+#!/usr/bin/python
+
+# Copyright 2017 Daniel Silverstone <dsilvers@digital-scurf.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/>.
+
+"""
+Monkey Farmer
+
+The monkey farmer is a wrapper around `nsmonkey` which can be used to simplify
+access to the monkey behaviours and ultimately to write useful tests in an
+expressive but not overcomplicated DSLish way. Tests are, ultimately, still
+Python code.
+
+"""
+
+import asyncore
+import os
+import socket
+import subprocess
+import time
+
+#monkey_cmd = ['./nsmonkey', '--accept_language=fr']
+monkey_cmd = ['./nsmonkey']
+
+class MonkeyFarmer(asyncore.dispatcher):
+ def __init__(self, online, quiet=False):
+ (mine, monkeys) = socket.socketpair()
+
+ asyncore.dispatcher.__init__(self, sock=mine)
+
+ self.monkey = subprocess.Popen(
+ monkey_cmd,
+ stdin=monkeys,
+ stdout=monkeys,
+ close_fds=[mine])
+
+ monkeys.close()
+
+ self.buffer = ""
+ self.incoming = ""
+ self.lines = []
+ self.scheduled = []
+ self.deadmonkey = False
+ self.online = online
+ self.quiet = quiet
+
+ def handle_connect(self):
+ pass
+
+ def handle_read(self):
+ got = self.recv(8192)
+ if got == "" or got is None:
+ self.deadmonkey = True
+ return
+ self.incoming += got
+ if "\n" in self.incoming:
+ lines = self.incoming.split("\n")
+ self.incoming = lines.pop()
+ self.lines = lines
+
+ def writable(self):
+ return (len(self.buffer) > 0)
+
+ def handle_write(self):
+ sent = self.send(self.buffer)
+ self.buffer = self.buffer[sent:]
+
+ def tell_monkey(self, *args):
+ cmd = (" ".join(args))
+ if not self.quiet:
+ print ">>> %s" % cmd
+ self.buffer += "%s\n" % cmd
+
+ def monkey_says(self, line):
+ if not self.quiet:
+ print "<<< %s" % line
+ self.online(line)
+
+ def schedule_event(self, event, secs=None, when=None):
+ assert(secs is not None or when is not None)
+ if when is None:
+ when = time.time() + secs
+ self.scheduled.append((when, event))
+ self.scheduled.sort(lambda a,b: cmp(a[0],b[0]))
+
+ def unschedule_event(self, event):
+ self.scheduled = [x for x in self.scheduled if x[1] != event]
+
+ def loop(self, once=False):
+ if len(self.lines) > 0:
+ self.monkey_says(self.lines.pop(0))
+ if once:
+ return
+ while not self.deadmonkey:
+ now = time.time()
+ while len(self.scheduled) > 0 and now >= self.scheduled[0][0]:
+ func = self.scheduled[0][1]
+ self.scheduled.pop(0)
+ func(self)
+ now = time.time()
+ if len(self.scheduled) > 0:
+ next = self.scheduled[0][0]
+ asyncore.loop(timeout=next-now, count=1)
+ else:
+ asyncore.loop(count=1)
+ if len(self.lines) > 0:
+ self.monkey_says(self.lines.pop(0))
+ if once:
+ break
+
+class Browser:
+ def __init__(self, quiet=False):
+ self.farmer = MonkeyFarmer(online=self.on_monkey_line, quiet=quiet)
+ self.windows = {}
+ self.current_draw_target = None
+
+ def pass_options(self, *opts):
+ if len(opts) > 0:
+ self.farmer.tell_monkey("OPTIONS " + (" ".join(opts)))
+
+ def on_monkey_line(self, line):
+ parts = line.split(" ")
+ handler = getattr(self, "handle_" + parts[0], None)
+ if handler is not None:
+ handler(*parts[1:])
+
+ def quit(self):
+ self.farmer.tell_monkey("QUIT")
+
+ def quit_and_wait(self):
+ self.quit()
+ self.farmer.loop()
+
+ def handle_GENERIC(self, what, *args):
+ pass
+
+ def handle_WINDOW(self, action, _win, winid, *args):
+ if action == "NEW":
+ new_win = BrowserWindow(self, winid, *args)
+ self.windows[winid] = new_win
+ else:
+ win = self.windows.get(winid, None)
+ if win is None:
+ print " Unknown window id %s" % winid
+ else:
+ win.handle(action, *args)
+
+ def handle_PLOT(self, *args):
+ if self.current_draw_target is not None:
+ self.current_draw_target.handle_plot(*args)
+
+ def new_window(self, url=None):
+ if url is None:
+ self.farmer.tell_monkey("WINDOW NEW")
+ else:
+ self.farmer.tell_monkey("WINDOW NEW %s" % url)
+ wins_known = set(self.windows.keys())
+ while len(set(self.windows.keys()).difference(wins_known)) == 0:
+ self.farmer.loop(once=True)
+ poss_wins = set(self.windows.keys()).difference(wins_known)
+ return self.windows[poss_wins.pop()]
+
+
+class BrowserWindow:
+ def __init__(self, browser, winid, _for, coreid, _existing, otherid, _newtab, newtab, _clone, clone):
+ self.alive = True
+ self.browser = browser
+ self.winid = winid
+ self.coreid = coreid
+ self.existing = browser.windows.get(otherid, None)
+ self.newtab = newtab == "TRUE"
+ self.clone = clone == "TRUE"
+ self.width = 0
+ self.height = 0
+ self.title = ""
+ self.throbbing = False
+ self.scrollx = 0
+ self.scrolly = 0
+ self.content_width = 0
+ self.content_height = 0
+ self.status = ""
+ self.pointer = ""
+ self.scale = 1.0
+ self.url = ""
+ self.plotted = []
+ self.plotting = False
+
+ def kill(self):
+ self.browser.farmer.tell_monkey("WINDOW DESTROY %s" % self.winid)
+
+ def go(self, url, referer = None):
+ if referer is None:
+ self.browser.farmer.tell_monkey("WINDOW GO %s %s" % (
+ self.winid, url))
+ else:
+ self.browser.farmer.tell_monkey("WINDOW GO %s %s %s" % (
+ self.winid, url, referer))
+
+ def reload(self):
+ self.browser.farmer.tell_monkey("WINDOW RELOAD %s" % self.winid)
+
+ def redraw(self, coords=None):
+ if coords is None:
+ self.browser.farmer.tell_monkey("WINDOW REDRAW %s" % self.winid)
+ else:
+ self.browser.farmer.tell_monkey("WINDOW REDRAW %s %s" % (
+ self.winid, (" ".join(coords))))
+
+ def handle(self, action, *args):
+ handler = getattr(self, "handle_window_" + action, None)
+ if handler is not None:
+ handler(*args)
+
+ def handle_window_SIZE(self, _width, width, _height, height):
+ self.width = int(width)
+ self.height = int(height)
+
+ def handle_window_DESTROY(self):
+ self.alive = False
+
+ def handle_window_TITLE(self, _str, *title):
+ self.title = " ".join(title)
+
+ def handle_window_REDRAW(self):
+ pass
+
+ def handle_window_GET_DIMENSIONS(self, _width, width, _height, height):
+ self.width = width
+ self.height = height
+
+ def handle_window_NEW_CONTENT(self):
+ pass
+
+ def handle_window_NEW_ICON(self):
+ pass
+
+ def handle_window_START_THROBBER(self):
+ self.throbbing = True
+
+ def handle_window_STOP_THROBBER(self):
+ self.throbbing = False
+
+ def handle_window_SET_SCROLL(self, _x, x, _y, y):
+ self.scrollx = int(x)
+ self.scrolly = int(y)
+
+ def handle_window_UPDATE_BOX(self, _x, x, _y, y, _width, width, _height, height):
+ x = int(x)
+ y = int(y)
+ width = int(width)
+ height = int(height)
+ pass
+
+ def handle_window_UPDATE_EXTENT(self, _width, width, _height, height):
+ self.content_width = int(width)
+ self.content_height = int(height)
+
+ def handle_window_SET_STATUS(self, _str, *status):
+ self.status = (" ".join(status))
+
+ def handle_window_SET_POINTER(self, _ptr, ptr):
+ self.pointer = ptr
+
+ def handle_window_SET_SCALE(self, _scale, scale):
+ self.scale = float(scale)
+
+ def handle_window_SET_URL(self, _url, url):
+ self.url = url
+
+ def handle_window_GET_SCROLL(self, _x, x, _y, y):
+ self.scrollx = int(x)
+ self.scrolly = int(y)
+
+ def handle_window_SCROLL_START(self):
+ self.scrollx = 0
+ self.scrolly = 0
+
+ def handle_window_REDRAW(self, act):
+ if act == "START":
+ self.browser.current_draw_target = self
+ self.plotted = []
+ self.plotting = True
+ else:
+ self.browser.current_draw_target = None
+ self.plotting = False
+
+ def load_page(self, url=None, referer=None):
+ if url is not None:
+ self.go(url, referer)
+ self.wait_loaded()
+
+ def reload(self):
+ self.browser.farmer.tell_monkey("WINDOW RELOAD %s" % self.winid)
+ self.wait_loaded()
+
+ def wait_loaded(self):
+ while not self.throbbing:
+ self.browser.farmer.loop(once=True)
+ while self.throbbing:
+ self.browser.farmer.loop(once=True)
+
+ def handle_plot(self, *args):
+ self.plotted.append(args)
+
+ def redraw(self, coords=None):
+ if coords is None:
+ self.browser.farmer.tell_monkey("WINDOW REDRAW %s" % self.winid)
+ else:
+ self.browser.farmer.tell_monkey("WINDOW REDRAW %s %s" % (
+ self.winid, (" ".join(coords))))
+ while not self.plotting:
+ self.browser.farmer.loop(once=True)
+ while self.plotting:
+ self.browser.farmer.loop(once=True)
+ return self.plotted
+
+
+# Simple test is as follows...
+
+browser = Browser(quiet=True)
+
+win = browser.new_window()
+
+fname = "test/js/inline-doc-write-simple.html"
+full_fname = os.path.join(os.getcwd(), fname)
+
+browser.pass_options("--enable_javascript=0")
+win.load_page("file://" + full_fname)
+
+print("Loaded, URL is %s" % win.url)
+
+cmds = win.redraw()
+print("Received %d plot commands" % len(cmds))
+for cmd in cmds:
+ if cmd[0] == "TEXT":
+ print "%s %s -> %s" % (cmd[2], cmd[4], (" ".join(cmd[6:])))
+
+
+browser.pass_options("--enable_javascript=1")
+win.load_page("file://" + full_fname)
+
+print("Loaded, URL is %s" % win.url)
+
+cmds = win.redraw()
+print("Received %d plot commands" % len(cmds))
+for cmd in cmds:
+ if cmd[0] == "TEXT":
+ print "%s %s -> %s" % (cmd[2], cmd[4], (" ".join(cmd[6:])))
+
+browser.quit_and_wait()
diff --git a/frontends/monkey/fetch.c b/frontends/monkey/fetch.c
index 4985329db..256d79b59 100644
--- a/frontends/monkey/fetch.c
+++ b/frontends/monkey/fetch.c
@@ -36,18 +36,18 @@ extern char **respaths;
static nsurl *gui_get_resource_url(const char *path)
{
- char buf[PATH_MAX];
- nsurl *url = NULL;
+ char buf[PATH_MAX];
+ nsurl *url = NULL;
- netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
+ netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
- return url;
+ return url;
}
static struct gui_fetch_table fetch_table = {
- .filetype = monkey_fetch_filetype,
+ .filetype = monkey_fetch_filetype,
- .get_resource_url = gui_get_resource_url,
+ .get_resource_url = gui_get_resource_url,
};
struct gui_fetch_table *monkey_fetch_table = &fetch_table;
diff --git a/frontends/monkey/filetype.c b/frontends/monkey/filetype.c
index 20bd1edad..65c84f9bd 100644
--- a/frontends/monkey/filetype.c
+++ b/frontends/monkey/filetype.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdbool.h>
+#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
@@ -85,7 +86,8 @@ void monkey_fetch_filetype_init(const char *mimefile)
fh = fopen(mimefile, "r");
if (fh == NULL) {
- LOG("Unable to open a mime.types file, so using a minimal one for you.");
+ NSLOG(netsurf, INFO,
+ "Unable to open a mime.types file, so using a minimal one for you.");
return;
}
diff --git a/frontends/monkey/layout.c b/frontends/monkey/layout.c
index 4bcc51b68..0d6a3b4dc 100644
--- a/frontends/monkey/layout.c
+++ b/frontends/monkey/layout.c
@@ -30,11 +30,11 @@
#include "monkey/layout.h"
static nserror nsfont_width(const plot_font_style_t *fstyle,
- const char *string, size_t length,
- int *width)
+ const char *string, size_t length,
+ int *width)
{
- *width = (fstyle->size * utf8_bounded_length(string, length)) / FONT_SIZE_SCALE;
- return NSERROR_OK;
+ *width = (fstyle->size * utf8_bounded_length(string, length)) / PLOT_STYLE_SCALE;
+ return NSERROR_OK;
}
/**
@@ -50,14 +50,14 @@ static nserror nsfont_width(const plot_font_style_t *fstyle,
*/
static nserror nsfont_position_in_string(const plot_font_style_t *fstyle,
- const char *string, size_t length,
- int x, size_t *char_offset, int *actual_x)
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x)
{
- *char_offset = x / (fstyle->size / FONT_SIZE_SCALE);
- if (*char_offset > length)
- *char_offset = length;
- *actual_x = *char_offset * (fstyle->size / FONT_SIZE_SCALE);
- return NSERROR_OK;
+ *char_offset = x / (fstyle->size / PLOT_STYLE_SCALE);
+ if (*char_offset > length)
+ *char_offset = length;
+ *actual_x = *char_offset * (fstyle->size / PLOT_STYLE_SCALE);
+ return NSERROR_OK;
}
@@ -85,27 +85,27 @@ static nserror nsfont_position_in_string(const plot_font_style_t *fstyle,
*/
static nserror nsfont_split(const plot_font_style_t *fstyle,
- const char *string, size_t length,
- int x, size_t *char_offset, int *actual_x)
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x)
{
- int c_off = *char_offset = x / (fstyle->size / FONT_SIZE_SCALE);
- if (*char_offset > length) {
- *char_offset = length;
- } else {
- while (*char_offset > 0) {
- if (string[*char_offset] == ' ')
- break;
- (*char_offset)--;
- }
- if (*char_offset == 0) {
- *char_offset = c_off;
- while (*char_offset < length && string[*char_offset] != ' ') {
- (*char_offset)++;
- }
- }
- }
- *actual_x = *char_offset * (fstyle->size / FONT_SIZE_SCALE);
- return NSERROR_OK;
+ int c_off = *char_offset = x / (fstyle->size / PLOT_STYLE_SCALE);
+ if (*char_offset > length) {
+ *char_offset = length;
+ } else {
+ while (*char_offset > 0) {
+ if (string[*char_offset] == ' ')
+ break;
+ (*char_offset)--;
+ }
+ if (*char_offset == 0) {
+ *char_offset = c_off;
+ while (*char_offset < length && string[*char_offset] != ' ') {
+ (*char_offset)++;
+ }
+ }
+ }
+ *actual_x = *char_offset * (fstyle->size / PLOT_STYLE_SCALE);
+ return NSERROR_OK;
}
static struct gui_layout_table layout_table = {
diff --git a/frontends/monkey/main.c b/frontends/monkey/main.c
index 0059ff047..53cde5a72 100644
--- a/frontends/monkey/main.c
+++ b/frontends/monkey/main.c
@@ -66,8 +66,8 @@ static bool monkey_done = false;
*/
static void die(const char * const error)
{
- fprintf(stderr, "DIE %s\n", error);
- exit(EXIT_FAILURE);
+ fprintf(stderr, "DIE %s\n", error);
+ exit(EXIT_FAILURE);
}
/** obtain language from environment
@@ -78,29 +78,29 @@ static void die(const char * const error)
*/
static const char *get_language(void)
{
- const char *lang;
+ const char *lang;
- lang = getenv("LANGUAGE");
- if ((lang != NULL) && (lang[0] != '\0')) {
- return lang;
- }
+ lang = getenv("LANGUAGE");
+ if ((lang != NULL) && (lang[0] != '\0')) {
+ return lang;
+ }
- lang = getenv("LC_ALL");
- if ((lang != NULL) && (lang[0] != '\0')) {
- return lang;
- }
+ lang = getenv("LC_ALL");
+ if ((lang != NULL) && (lang[0] != '\0')) {
+ return lang;
+ }
- lang = getenv("LC_MESSAGES");
- if ((lang != NULL) && (lang[0] != '\0')) {
- return lang;
- }
+ lang = getenv("LC_MESSAGES");
+ if ((lang != NULL) && (lang[0] != '\0')) {
+ return lang;
+ }
- lang = getenv("LANG");
- if ((lang != NULL) && (lang[0] != '\0')) {
- return lang;
- }
+ lang = getenv("LANG");
+ if ((lang != NULL) && (lang[0] != '\0')) {
+ return lang;
+ }
- return NULL;
+ return NULL;
}
@@ -120,92 +120,97 @@ static const char *get_language(void)
*/
static const char * const *get_languagev(void)
{
- static const char *langv[LANGV_SIZE];
- int langidx = 0; /* index of next entry in vector */
- static char langs[LANGS_SIZE];
- char *curp; /* next language parameter in langs string */
- const char *lange; /* language from environment variable */
- int lang_len;
- char *cln; /* colon in lange */
-
- /* return cached vector */
- if (langv[0] != NULL) {
- return &langv[0];
- }
-
- curp = &langs[0];
-
- lange = get_language();
-
- if (lange != NULL) {
- lang_len = strlen(lange) + 1;
- if (lang_len < (LANGS_SIZE - 2)) {
- memcpy(curp, lange, lang_len);
- while ((curp[0] != 0) &&
- (langidx < (LANGV_SIZE - 2))) {
- /* avoid using strchrnul as it is not portable */
- cln = strchr(curp, ':');
- if (cln == NULL) {
- langv[langidx++] = curp;
- curp += lang_len;
- break;
- } else {
- if ((cln - curp) > 1) {
- /* only place non empty entries in vector */
- langv[langidx++] = curp;
- }
- *cln++ = 0; /* null terminate */
- lang_len -= (cln - curp);
- curp = cln;
+ static const char *langv[LANGV_SIZE];
+ int langidx = 0; /* index of next entry in vector */
+ static char langs[LANGS_SIZE];
+ char *curp; /* next language parameter in langs string */
+ const char *lange; /* language from environment variable */
+ int lang_len;
+ char *cln; /* colon in lange */
+
+ /* return cached vector */
+ if (langv[0] != NULL) {
+ return &langv[0];
}
- }
- }
- }
- /* ensure C language is present */
- langv[langidx++] = curp;
- *curp++ = 'C';
- *curp++ = 0;
- langv[langidx] = NULL;
+ curp = &langs[0];
+
+ lange = get_language();
+
+ if (lange != NULL) {
+ lang_len = strlen(lange) + 1;
+ if (lang_len < (LANGS_SIZE - 2)) {
+ memcpy(curp, lange, lang_len);
+ while ((curp[0] != 0) &&
+ (langidx < (LANGV_SIZE - 2))) {
+ /* avoid using strchrnul as it is not portable */
+ cln = strchr(curp, ':');
+ if (cln == NULL) {
+ langv[langidx++] = curp;
+ curp += lang_len;
+ break;
+ } else {
+ if ((cln - curp) > 1) {
+ /* only place non empty entries in vector */
+ langv[langidx++] = curp;
+ }
+ *cln++ = 0; /* null terminate */
+ lang_len -= (cln - curp);
+ curp = cln;
+ }
+ }
+ }
+ }
- return &langv[0];
+ /* ensure C language is present */
+ langv[langidx++] = curp;
+ *curp++ = 'C';
+ *curp++ = 0;
+ langv[langidx] = NULL;
+
+ return &langv[0];
}
/* Stolen from gtk/gui.c */
static char **
nsmonkey_init_resource(const char *resource_path)
{
- const char * const *langv;
- char **pathv; /* resource path string vector */
- char **respath; /* resource paths vector */
+ const char * 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 = get_languagev();
+ langv = get_languagev();
- respath = filepath_generate(pathv, langv);
+ respath = filepath_generate(pathv, langv);
- filepath_free_strvec(pathv);
+ filepath_free_strvec(pathv);
- return respath;
+ return respath;
}
static void monkey_quit(void)
{
- urldb_save_cookies(nsoption_charp(cookie_jar));
- urldb_save(nsoption_charp(url_file));
- monkey_fetch_filetype_fin();
+ urldb_save_cookies(nsoption_charp(cookie_jar));
+ urldb_save(nsoption_charp(url_file));
+ monkey_fetch_filetype_fin();
}
static nserror gui_launch_url(struct nsurl *url)
{
- fprintf(stdout, "GENERIC LAUNCH URL %s\n", nsurl_access(url));
- return NSERROR_OK;
+ fprintf(stdout, "GENERIC LAUNCH URL %s\n", nsurl_access(url));
+ return NSERROR_OK;
}
static void quit_handler(int argc, char **argv)
{
- monkey_done = true;
+ monkey_done = true;
+}
+
+static void monkey_options_handle_command(int argc, char **argv)
+{
+ nsoption_commandline(&argc, argv, nsoptions);
}
/**
@@ -216,12 +221,12 @@ static void quit_handler(int argc, char **argv)
*/
static nserror set_defaults(struct nsoption_s *defaults)
{
- /* Set defaults for absent option strings */
- nsoption_setnull_charp(cookie_file, strdup("~/.netsurf/Cookies"));
- nsoption_setnull_charp(cookie_jar, strdup("~/.netsurf/Cookies"));
- nsoption_setnull_charp(url_file, strdup("~/.netsurf/URLs"));
+ /* Set defaults for absent option strings */
+ nsoption_setnull_charp(cookie_file, strdup("~/.netsurf/Cookies"));
+ nsoption_setnull_charp(cookie_jar, strdup("~/.netsurf/Cookies"));
+ nsoption_setnull_charp(url_file, strdup("~/.netsurf/URLs"));
- return NSERROR_OK;
+ return NSERROR_OK;
}
@@ -230,170 +235,177 @@ static nserror set_defaults(struct nsoption_s *defaults)
*/
static bool nslog_stream_configure(FILE *fptr)
{
- /* set log stream to be non-buffering */
- setbuf(fptr, NULL);
+ /* set log stream to be non-buffering */
+ setbuf(fptr, NULL);
- return true;
+ return true;
}
static struct gui_misc_table monkey_misc_table = {
- .schedule = monkey_schedule,
- .warning = monkey_warn_user,
+ .schedule = monkey_schedule,
+ .warning = monkey_warn_user,
- .quit = monkey_quit,
- .launch_url = gui_launch_url,
- .cert_verify = gui_cert_verify,
- .login = gui_401login_open,
+ .quit = monkey_quit,
+ .launch_url = gui_launch_url,
+ .cert_verify = gui_cert_verify,
+ .login = gui_401login_open,
};
static void monkey_run(void)
{
- fd_set read_fd_set, write_fd_set, exc_fd_set;
- int max_fd;
- int rdy_fd;
- int schedtm;
- struct timeval tv;
- struct timeval* timeout;
-
- while (!monkey_done) {
-
- /* clears fdset */
- fetch_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
-
- /* add stdin to the set */
- if (max_fd < 0) {
- max_fd = 0;
- }
- FD_SET(0, &read_fd_set);
- FD_SET(0, &exc_fd_set);
-
- /* discover the next scheduled event time */
- schedtm = monkey_schedule_run();
-
- /* setup timeout */
- switch (schedtm) {
- case -1:
- LOG("Iterate blocking");
- fprintf(stdout, "GENERIC POLL BLOCKING\n");
- timeout = NULL;
- break;
-
- case 0:
- LOG("Iterate immediate");
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- timeout = &tv;
- break;
-
- default:
- LOG("Iterate non-blocking");
- fprintf(stdout, "GENERIC POLL TIMED\n");
- tv.tv_sec = schedtm / 1000; /* miliseconds to seconds */
- tv.tv_usec = (schedtm % 1000) * 1000; /* remainder to microseconds */
- timeout = &tv;
- break;
- }
-
- rdy_fd = select(max_fd + 1,
- &read_fd_set,
- &write_fd_set,
- &exc_fd_set,
- timeout);
- if (rdy_fd < 0) {
- monkey_done = true;
- } else if (rdy_fd > 0) {
- if (FD_ISSET(0, &read_fd_set)) {
- monkey_process_command();
- }
- }
- }
-
+ fd_set read_fd_set, write_fd_set, exc_fd_set;
+ int max_fd;
+ int rdy_fd;
+ int schedtm;
+ struct timeval tv;
+ struct timeval* timeout;
+
+ while (!monkey_done) {
+
+ /* clears fdset */
+ fetch_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
+
+ /* add stdin to the set */
+ if (max_fd < 0) {
+ max_fd = 0;
+ }
+ FD_SET(0, &read_fd_set);
+ FD_SET(0, &exc_fd_set);
+
+ /* discover the next scheduled event time */
+ schedtm = monkey_schedule_run();
+
+ /* setup timeout */
+ switch (schedtm) {
+ case -1:
+ NSLOG(netsurf, INFO, "Iterate blocking");
+ fprintf(stdout, "GENERIC POLL BLOCKING\n");
+ timeout = NULL;
+ break;
+
+ case 0:
+ NSLOG(netsurf, INFO, "Iterate immediate");
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ timeout = &tv;
+ break;
+
+ default:
+ NSLOG(netsurf, INFO, "Iterate non-blocking");
+ fprintf(stdout, "GENERIC POLL TIMED %d\n", schedtm);
+ tv.tv_sec = schedtm / 1000; /* miliseconds to seconds */
+ tv.tv_usec = (schedtm % 1000) * 1000; /* remainder to microseconds */
+ timeout = &tv;
+ break;
+ }
+
+ rdy_fd = select(max_fd + 1,
+ &read_fd_set,
+ &write_fd_set,
+ &exc_fd_set,
+ timeout);
+ if (rdy_fd < 0) {
+ monkey_done = true;
+ } else if (rdy_fd > 0) {
+ if (FD_ISSET(0, &read_fd_set)) {
+ monkey_process_command();
+ }
+ }
+ }
}
int
main(int argc, char **argv)
{
- char *messages;
- char *options;
- char buf[PATH_MAX];
- nserror ret;
- struct netsurf_table monkey_table = {
- .misc = &monkey_misc_table,
- .window = monkey_window_table,
- .download = monkey_download_table,
- .fetch = monkey_fetch_table,
- .bitmap = monkey_bitmap_table,
- .layout = monkey_layout_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");
-
- /* initialise logging. Not fatal if it fails but not much we can do
- * about it either.
- */
- nslog_init(nslog_stream_configure, &argc, argv);
-
- /* user options setup */
- ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
- if (ret != NSERROR_OK) {
- die("Options failed to initialise");
- }
- options = filepath_find(respaths, "Choices");
- nsoption_read(options, nsoptions);
- free(options);
- nsoption_commandline(&argc, argv, nsoptions);
-
- messages = filepath_find(respaths, "Messages");
- ret = messages_add_from_file(messages);
- if (ret != NSERROR_OK) {
- LOG("Messages failed to load");
- }
-
- /* common initialisation */
- ret = netsurf_init(NULL);
- free(messages);
- if (ret != NSERROR_OK) {
- die("NetSurf failed to initialise");
- }
-
- filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
- monkey_fetch_filetype_init(buf);
-
- urldb_load(nsoption_charp(url_file));
- urldb_load_cookies(nsoption_charp(cookie_file));
-
- ret = monkey_register_handler("QUIT", quit_handler);
- if (ret != NSERROR_OK) {
- die("quit handler failed to register");
- }
-
- ret = monkey_register_handler("WINDOW", monkey_window_handle_command);
- if (ret != NSERROR_OK) {
- die("window handler fialed to register");
- }
-
- fprintf(stdout, "GENERIC STARTED\n");
- monkey_run();
-
- fprintf(stdout, "GENERIC CLOSING_DOWN\n");
- monkey_kill_browser_windows();
-
- netsurf_exit();
- fprintf(stdout, "GENERIC FINISHED\n");
-
- /* finalise options */
- nsoption_finalise(nsoptions, nsoptions_default);
-
- return 0;
+ char *messages;
+ char *options;
+ char buf[PATH_MAX];
+ nserror ret;
+ struct netsurf_table monkey_table = {
+ .misc = &monkey_misc_table,
+ .window = monkey_window_table,
+ .download = monkey_download_table,
+ .fetch = monkey_fetch_table,
+ .bitmap = monkey_bitmap_table,
+ .layout = monkey_layout_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":./frontends/monkey/res");
+
+ /* initialise logging. Not fatal if it fails but not much we can do
+ * about it either.
+ */
+ nslog_init(nslog_stream_configure, &argc, argv);
+
+ /* user options setup */
+ ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
+ if (ret != NSERROR_OK) {
+ die("Options failed to initialise");
+ }
+ options = filepath_find(respaths, "Choices");
+ nsoption_read(options, nsoptions);
+ free(options);
+ nsoption_commandline(&argc, argv, nsoptions);
+
+ messages = filepath_find(respaths, "Messages");
+ ret = messages_add_from_file(messages);
+ if (ret != NSERROR_OK) {
+ NSLOG(netsurf, INFO, "Messages failed to load");
+ }
+
+ /* common initialisation */
+ ret = netsurf_init(NULL);
+ free(messages);
+ if (ret != NSERROR_OK) {
+ die("NetSurf failed to initialise");
+ }
+
+ filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
+ monkey_fetch_filetype_init(buf);
+
+ urldb_load(nsoption_charp(url_file));
+ urldb_load_cookies(nsoption_charp(cookie_file));
+
+ ret = monkey_register_handler("QUIT", quit_handler);
+ if (ret != NSERROR_OK) {
+ die("quit handler failed to register");
+ }
+
+ ret = monkey_register_handler("WINDOW", monkey_window_handle_command);
+ if (ret != NSERROR_OK) {
+ die("window handler failed to register");
+ }
+
+ ret = monkey_register_handler("OPTIONS", monkey_options_handle_command);
+ if (ret != NSERROR_OK) {
+ die("options handler failed to register");
+ }
+
+ fprintf(stdout, "GENERIC STARTED\n");
+ monkey_run();
+
+ fprintf(stdout, "GENERIC CLOSING_DOWN\n");
+ monkey_kill_browser_windows();
+
+ netsurf_exit();
+ fprintf(stdout, "GENERIC FINISHED\n");
+
+ /* finalise options */
+ nsoption_finalise(nsoptions, nsoptions_default);
+
+ /* finalise logging */
+ nslog_finalise();
+
+ return 0;
}
diff --git a/frontends/monkey/plot.c b/frontends/monkey/plot.c
index bd94e7551..2fc9a3cb6 100644
--- a/frontends/monkey/plot.c
+++ b/frontends/monkey/plot.c
@@ -19,82 +19,248 @@
#include <stdio.h>
#include "utils/utils.h"
+#include "utils/errors.h"
#include "netsurf/plotters.h"
-static bool
-monkey_plot_disc(int x, int y, int radius, const plot_style_t *style)
+/**
+ * \brief Sets a clip rectangle for subsequent plot operations.
+ *
+ * \param ctx The current redraw context.
+ * \param clip The rectangle to limit all subsequent plot
+ * operations within.
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
{
- return true;
+ fprintf(stdout,
+ "PLOT CLIP X0 %d Y0 %d X1 %d Y1 %d\n",
+ clip->x0, clip->y0, clip->x1, clip->y1);
+ return NSERROR_OK;
}
-static bool
-monkey_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
+
+/**
+ * Plots an arc
+ *
+ * plot an arc segment around (x,y), anticlockwise from angle1
+ * to angle2. Angles are measured anticlockwise from
+ * horizontal, in degrees.
+ *
+ * \param ctx The current redraw context.
+ * \param style Style controlling the arc plot.
+ * \param x The x coordinate of the arc.
+ * \param y The y coordinate of the arc.
+ * \param radius The radius of the arc.
+ * \param angle1 The start angle of the arc.
+ * \param angle2 The finish angle of the arc.
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_arc(const struct redraw_context *ctx,
+ const plot_style_t *style,
+ int x, int y, int radius, int angle1, int angle2)
{
- return true;
+ fprintf(stdout,
+ "PLOT ARC X %d Y %d RADIUS %d ANGLE1 %d ANGLE2 %d\n",
+ x, y, radius, angle1, angle2);
+ return NSERROR_OK;
}
-static bool
-monkey_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
+
+/**
+ * Plots a circle
+ *
+ * Plot a circle centered on (x,y), which is optionally filled.
+ *
+ * \param ctx The current redraw context.
+ * \param style Style controlling the circle plot.
+ * \param x x coordinate of circle centre.
+ * \param y y coordinate of circle centre.
+ * \param radius circle radius.
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_disc(const struct redraw_context *ctx,
+ const plot_style_t *style,
+ int x, int y, int radius)
{
- return true;
+ fprintf(stdout,
+ "PLOT DISC X %d Y %d RADIUS %d\n",
+ x, y, radius);
+ return NSERROR_OK;
}
-static bool
-monkey_plot_text(int x, int y, const char *text, size_t length,
- const plot_font_style_t *fstyle)
+/**
+ * Plots a line
+ *
+ * plot a line from (x0,y0) to (x1,y1). Coordinates are at
+ * centre of line width/thickness.
+ *
+ * \param ctx The current redraw context.
+ * \param style Style controlling the line plot.
+ * \param line A rectangle defining the line to be drawn
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_line(const struct redraw_context *ctx,
+ const plot_style_t *style,
+ const struct rect *line)
{
- fprintf(stdout, "PLOT TEXT X %d Y %d STR %*s\n", x, y, (int)length, text);
- return true;
+ fprintf(stdout,
+ "PLOT LINE X0 %d Y0 %d X1 %d Y1 %d\n",
+ line->x0, line->y0, line->x1, line->y1);
+ return NSERROR_OK;
}
-static bool
-monkey_plot_bitmap(int x, int y,
- int width, int height,
- struct bitmap *bitmap, colour bg,
- bitmap_flags_t flags)
+
+/**
+ * Plots a rectangle.
+ *
+ * The rectangle can be filled an outline or both controlled
+ * by the plot style The line can be solid, dotted or
+ * dashed. Top left corner at (x0,y0) and rectangle has given
+ * width and height.
+ *
+ * \param ctx The current redraw context.
+ * \param style Style controlling the rectangle plot.
+ * \param rect A rectangle defining the line to be drawn
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_rectangle(const struct redraw_context *ctx,
+ const plot_style_t *style,
+ const struct rect *rect)
{
- fprintf(stdout, "PLOT BITMAP X %d Y %d WIDTH %d HEIGHT %d\n",
- x, y, width, height);
- return true;
+ fprintf(stdout,
+ "PLOT RECT X0 %d Y0 %d X1 %d Y1 %d\n",
+ rect->x0, rect->y0, rect->x1, rect->y1);
+ return NSERROR_OK;
}
-static bool
-monkey_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
+
+/**
+ * Plot a polygon
+ *
+ * Plots a filled polygon with straight lines between
+ * points. The lines around the edge of the ploygon are not
+ * plotted. The polygon is filled with the non-zero winding
+ * rule.
+ *
+ * \param ctx The current redraw context.
+ * \param style Style controlling the polygon plot.
+ * \param p verticies of polygon
+ * \param n number of verticies.
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_polygon(const struct redraw_context *ctx,
+ const plot_style_t *style,
+ const int *p,
+ unsigned int n)
{
- fprintf(stdout, "PLOT RECT X0 %d Y0 %d X1 %d Y1 %d\n",
- x0, y0, x1, y1);
- return true;
+ fprintf(stdout,
+ "PLOT POLYGON VERTICIES %d\n",
+ n);
+ return NSERROR_OK;
}
-static bool
-monkey_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
+
+/**
+ * Plots a path.
+ *
+ * Path plot consisting of cubic Bezier curves. Line and fill colour is
+ * controlled by the plot style.
+ *
+ * \param ctx The current redraw context.
+ * \param pstyle Style controlling the path plot.
+ * \param p elements of path
+ * \param n nunber of elements on path
+ * \param transform A transform to apply to the path.
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_path(const struct redraw_context *ctx,
+ const plot_style_t *pstyle,
+ const float *p,
+ unsigned int n,
+ const float transform[6])
{
- fprintf(stdout, "PLOT LINE X0 %d Y0 %d X1 %d Y1 %d\n",
- x0, y0, x1, y1);
- return true;
+ fprintf(stdout,
+ "PLOT PATH VERTICIES %d WIDTH %f\n",
+ n, plot_style_fixed_to_float(pstyle->stroke_width));
+ return NSERROR_OK;
}
-static bool
-monkey_plot_path(const float *p,
- unsigned int n,
- colour fill,
- float width,
- colour c,
- const float transform[6])
+/**
+ * Plot a bitmap
+ *
+ * Tiled plot of a bitmap image. (x,y) gives the top left
+ * coordinate of an explicitly placed tile. From this tile the
+ * image can repeat in all four directions -- up, down, left
+ * and right -- to the extents given by the current clip
+ * rectangle.
+ *
+ * The bitmap_flags say whether to tile in the x and y
+ * directions. If not tiling in x or y directions, the single
+ * image is plotted. The width and height give the dimensions
+ * the image is to be scaled to.
+ *
+ * \param ctx The current redraw context.
+ * \param bitmap The bitmap to plot
+ * \param x The x coordinate to plot the bitmap
+ * \param y The y coordiante to plot the bitmap
+ * \param width The width of area to plot the bitmap into
+ * \param height The height of area to plot the bitmap into
+ * \param bg the background colour to alpha blend into
+ * \param flags the flags controlling the type of plot operation
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_bitmap(const struct redraw_context *ctx,
+ struct bitmap *bitmap,
+ int x, int y,
+ int width,
+ int height,
+ colour bg,
+ bitmap_flags_t flags)
{
- return true;
+ fprintf(stdout,
+ "PLOT BITMAP X %d Y %d WIDTH %d HEIGHT %d\n",
+ x, y, width, height);
+ return NSERROR_OK;
}
-static bool
-monkey_plot_clip(const struct rect *clip)
+
+/**
+ * Text plotting.
+ *
+ * \param ctx The current redraw context.
+ * \param fstyle plot style for this text
+ * \param x x coordinate
+ * \param y y coordinate
+ * \param text UTF-8 string to plot
+ * \param length length of string, in bytes
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror
+monkey_plot_text(const struct redraw_context *ctx,
+ const struct plot_font_style *fstyle,
+ int x,
+ int y,
+ const char *text,
+ size_t length)
{
- fprintf(stdout, "PLOT CLIP X0 %d Y0 %d X1 %d Y1 %d\n",
- clip->x0, clip->y0, clip->x1, clip->y1);
- return true;
+ fprintf(stdout,
+ "PLOT TEXT X %d Y %d STR %*s\n",
+ x, y, (int)length, text);
+ return NSERROR_OK;
}
+
+/** monkey plotter operations table */
static const struct plotter_table plotters = {
.clip = monkey_plot_clip,
.arc = monkey_plot_arc,
@@ -105,7 +271,7 @@ static const struct plotter_table plotters = {
.path = monkey_plot_path,
.bitmap = monkey_plot_bitmap,
.text = monkey_plot_text,
- .option_knockout = true,
+ .option_knockout = true,
};
const struct plotter_table* monkey_plotters = &plotters;
diff --git a/frontends/monkey/schedule.c b/frontends/monkey/schedule.c
index 8c638c0b9..3d76997f4 100644
--- a/frontends/monkey/schedule.c
+++ b/frontends/monkey/schedule.c
@@ -24,12 +24,6 @@
#include "monkey/schedule.h"
-#ifdef DEBUG_SCHEDULER
-#define SRLOG(x...) LOG(x)
-#else
-#define SRLOG(x...) ((void) 0)
-#endif
-
/* linked list of scheduled callbacks */
static struct nscallback *schedule_list = NULL;
@@ -38,10 +32,10 @@ static struct nscallback *schedule_list = NULL;
*/
struct nscallback
{
- struct nscallback *next;
- struct timeval tv;
- void (*callback)(void *p);
- void *p;
+ struct nscallback *next;
+ struct timeval tv;
+ void (*callback)(void *p);
+ void *p;
};
/**
@@ -54,170 +48,164 @@ struct nscallback
*/
static nserror schedule_remove(void (*callback)(void *p), void *p)
{
- struct nscallback *cur_nscb;
- struct nscallback *prev_nscb;
- struct nscallback *unlnk_nscb;
-
- /* check there is something on the list to remove */
- if (schedule_list == NULL) {
- return NSERROR_OK;
- }
-
- SRLOG("removing %p, %p", callback, p);
-
- cur_nscb = schedule_list;
- prev_nscb = NULL;
-
- while (cur_nscb != NULL) {
- if ((cur_nscb->callback == callback) &&
- (cur_nscb->p == p)) {
- /* item to remove */
-
- SRLOG("callback entry %p removing %p(%p)",
- cur_nscb, cur_nscb->callback, cur_nscb->p);
-
- /* remove callback */
- unlnk_nscb = cur_nscb;
- cur_nscb = unlnk_nscb->next;
-
- if (prev_nscb == NULL) {
- schedule_list = cur_nscb;
- } else {
- prev_nscb->next = cur_nscb;
- }
- free (unlnk_nscb);
- } else {
- /* move to next element */
- prev_nscb = cur_nscb;
- cur_nscb = prev_nscb->next;
- }
- }
-
- return NSERROR_OK;
+ struct nscallback *cur_nscb;
+ struct nscallback *prev_nscb;
+ struct nscallback *unlnk_nscb;
+
+ /* check there is something on the list to remove */
+ if (schedule_list == NULL) {
+ return NSERROR_OK;
+ }
+
+ NSLOG(schedule, DEBUG, "removing %p, %p", callback, p);
+
+ cur_nscb = schedule_list;
+ prev_nscb = NULL;
+
+ while (cur_nscb != NULL) {
+ if ((cur_nscb->callback == callback) &&
+ (cur_nscb->p == p)) {
+ /* item to remove */
+
+ NSLOG(schedule, DEBUG, "callback entry %p removing %p(%p)",
+ cur_nscb, cur_nscb->callback, cur_nscb->p);
+
+ /* remove callback */
+ unlnk_nscb = cur_nscb;
+ cur_nscb = unlnk_nscb->next;
+
+ if (prev_nscb == NULL) {
+ schedule_list = cur_nscb;
+ } else {
+ prev_nscb->next = cur_nscb;
+ }
+ free (unlnk_nscb);
+ } else {
+ /* move to next element */
+ prev_nscb = cur_nscb;
+ cur_nscb = prev_nscb->next;
+ }
+ }
+
+ return NSERROR_OK;
}
-/* exported function documented in framebuffer/schedule.h */
+/* exported function documented in monkey/schedule.h */
nserror monkey_schedule(int tival, void (*callback)(void *p), void *p)
{
- struct nscallback *nscb;
- struct timeval tv;
- nserror ret;
+ struct nscallback *nscb;
+ struct timeval tv;
+ nserror ret;
- /* ensure uniqueness of the callback and context */
- ret = schedule_remove(callback, p);
- if ((tival < 0) || (ret != NSERROR_OK)) {
- return ret;
- }
+ /* ensure uniqueness of the callback and context */
+ ret = schedule_remove(callback, p);
+ if ((tival < 0) || (ret != NSERROR_OK)) {
+ return ret;
+ }
- SRLOG("Adding %p(%p) in %d", callback, p, tival);
+ NSLOG(schedule, DEBUG, "Adding %p(%p) in %d", callback, p, tival);
- tv.tv_sec = tival / 1000; /* miliseconds to seconds */
- tv.tv_usec = (tival % 1000) * 1000; /* remainder to microseconds */
+ tv.tv_sec = tival / 1000; /* miliseconds to seconds */
+ tv.tv_usec = (tival % 1000) * 1000; /* remainder to microseconds */
- nscb = calloc(1, sizeof(struct nscallback));
+ nscb = calloc(1, sizeof(struct nscallback));
- gettimeofday(&nscb->tv, NULL);
- timeradd(&nscb->tv, &tv, &nscb->tv);
+ gettimeofday(&nscb->tv, NULL);
+ timeradd(&nscb->tv, &tv, &nscb->tv);
- nscb->callback = callback;
- nscb->p = p;
+ nscb->callback = callback;
+ nscb->p = p;
- /* add to list front */
- nscb->next = schedule_list;
- schedule_list = nscb;
+ /* add to list front */
+ nscb->next = schedule_list;
+ schedule_list = nscb;
- return NSERROR_OK;
+ return NSERROR_OK;
}
-/* exported function documented in framebuffer/schedule.h */
+/* exported function documented in monkey/schedule.h */
int monkey_schedule_run(void)
{
- struct timeval tv;
- struct timeval nexttime;
- struct timeval rettime;
- struct nscallback *cur_nscb;
- struct nscallback *prev_nscb;
- struct nscallback *unlnk_nscb;
-
- if (schedule_list == NULL)
- return -1;
-
- /* reset enumeration to the start of the list */
- cur_nscb = schedule_list;
- prev_nscb = NULL;
- nexttime = cur_nscb->tv;
-
- gettimeofday(&tv, NULL);
-
- while (cur_nscb != NULL) {
- if (timercmp(&tv, &cur_nscb->tv, >)) {
- /* scheduled time */
-
- /* remove callback */
- unlnk_nscb = cur_nscb;
-
- if (prev_nscb == NULL) {
- schedule_list = unlnk_nscb->next;
- } else {
- prev_nscb->next = unlnk_nscb->next;
- }
-
- unlnk_nscb->callback(unlnk_nscb->p);
-
- free(unlnk_nscb);
-
- /* need to deal with callback modifying the list. */
- if (schedule_list == NULL)
- return -1; /* no more callbacks scheduled */
-
- /* reset enumeration to the start of the list */
- cur_nscb = schedule_list;
- prev_nscb = NULL;
- nexttime = cur_nscb->tv;
- } else {
- /* if the time to the event is sooner than the
- * currently recorded soonest event record it
- */
- if (timercmp(&nexttime, &cur_nscb->tv, >)) {
+ struct timeval tv;
+ struct timeval nexttime;
+ struct timeval rettime;
+ struct nscallback *cur_nscb;
+ struct nscallback *prev_nscb;
+ struct nscallback *unlnk_nscb;
+
+ if (schedule_list == NULL)
+ return -1;
+
+ /* reset enumeration to the start of the list */
+ cur_nscb = schedule_list;
+ prev_nscb = NULL;
nexttime = cur_nscb->tv;
- }
- /* move to next element */
- prev_nscb = cur_nscb;
- cur_nscb = prev_nscb->next;
- }
- }
-
- /* make rettime relative to now */
- timersub(&nexttime, &tv, &rettime);
- SRLOG("returning time to next event as %ldms",
- (rettime.tv_sec * 1000) + (rettime.tv_usec / 1000));
-
- /* return next event time in milliseconds (24days max wait) */
- return (rettime.tv_sec * 1000) + (rettime.tv_usec / 1000);
+ gettimeofday(&tv, NULL);
+
+ while (cur_nscb != NULL) {
+ if (timercmp(&tv, &cur_nscb->tv, >)) {
+ /* scheduled time */
+
+ /* remove callback */
+ unlnk_nscb = cur_nscb;
+
+ if (prev_nscb == NULL) {
+ schedule_list = unlnk_nscb->next;
+ } else {
+ prev_nscb->next = unlnk_nscb->next;
+ }
+
+ unlnk_nscb->callback(unlnk_nscb->p);
+
+ free(unlnk_nscb);
+
+ /* need to deal with callback modifying the list. */
+ if (schedule_list == NULL)
+ return -1; /* no more callbacks scheduled */
+
+ /* reset enumeration to the start of the list */
+ cur_nscb = schedule_list;
+ prev_nscb = NULL;
+ nexttime = cur_nscb->tv;
+ } else {
+ /* if the time to the event is sooner than the
+ * currently recorded soonest event record it
+ */
+ if (timercmp(&nexttime, &cur_nscb->tv, >)) {
+ nexttime = cur_nscb->tv;
+ }
+ /* move to next element */
+ prev_nscb = cur_nscb;
+ cur_nscb = prev_nscb->next;
+ }
+ }
+
+ /* make rettime relative to now */
+ timersub(&nexttime, &tv, &rettime);
+
+ NSLOG(schedule, DEBUG, "returning time to next event as %ldms",
+ (long)((rettime.tv_sec * 1000) + (rettime.tv_usec / 1000)));
+
+ /* return next event time in milliseconds (24days max wait) */
+ return (rettime.tv_sec * 1000) + (rettime.tv_usec / 1000);
}
void monkey_schedule_list(void)
{
- struct timeval tv;
- struct nscallback *cur_nscb;
+ struct timeval tv;
+ struct nscallback *cur_nscb;
- gettimeofday(&tv, NULL);
+ gettimeofday(&tv, NULL);
- LOG("schedule list at %lld:%ld", (long long)tv.tv_sec, tv.tv_usec);
+ NSLOG(netsurf, INFO, "schedule list at %lld:%ld",
+ (long long)tv.tv_sec, tv.tv_usec);
- cur_nscb = schedule_list;
+ cur_nscb = schedule_list;
- while (cur_nscb != NULL) {
- LOG("Schedule %p at %lld:%ld",
- cur_nscb, (long long)cur_nscb->tv.tv_sec, cur_nscb->tv.tv_usec);
- cur_nscb = cur_nscb->next;
- }
+ while (cur_nscb != NULL) {
+ NSLOG(netsurf, INFO, "Schedule %p at %lld:%ld", cur_nscb,
+ (long long)cur_nscb->tv.tv_sec, cur_nscb->tv.tv_usec);
+ cur_nscb = cur_nscb->next;
+ }
}
-
-
-/*
- * Local Variables:
- * c-basic-offset:2
- * End:
- */