From 02541c314678aa1ee6eb485ca9dce66a46693aac Mon Sep 17 00:00:00 2001 From: Quentin Rameau Date: Tue, 9 Oct 2018 12:27:59 +0200 Subject: Send message size inside messages through pipes --- common.h | 2 +- libsurf-webext.c | 37 +++++++++++++++++++++---------------- surf.c | 26 +++++++++++++++++--------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/common.h b/common.h index 527c4f7..2778029 100644 --- a/common.h +++ b/common.h @@ -1,3 +1,3 @@ -#define MSGBUFSZ 32 +#define MSGBUFSZ 8 void die(char *, ...); diff --git a/libsurf-webext.c b/libsurf-webext.c index 684d4a5..ec9a235 100644 --- a/libsurf-webext.c +++ b/libsurf-webext.c @@ -41,59 +41,64 @@ newpage(WebKitWebPage *page) static void msgsurf(Page *p, const char *s) { - char msg[MSGBUFSZ]; + static char msg[MSGBUFSZ]; + size_t sln = strlen(s); int ret; - msg[0] = p ? p->id : 0; - ret = snprintf(&msg[1], sizeof(msg) - 1, "%s", s); - if (ret >= sizeof(msg)) { + if ((ret = snprintf(msg, sizeof(msg), "%c%c%s", + 2 + sln, p ? p->id : 0, s)) + >= sizeof(msg)) { fprintf(stderr, "webext: message too long: %d\n", ret); return; } - if (pipeout) { - if (write(pipeout, msg, sizeof(msg)) < 0) - fprintf(stderr, "webext: error sending: %s\n", msg); - } + if (pipeout && write(pipeout, msg, sizeof(msg)) < 0) + fprintf(stderr, "webext: error sending: %.*s\n", ret-2, msg+2); } static gboolean readpipe(GIOChannel *s, GIOCondition c, gpointer unused) { - char msg[MSGBUFSZ]; - gsize msgsz; + static char msg[MSGBUFSZ], msgsz; WebKitDOMDOMWindow *view; GError *gerr = NULL; glong wh, ww; Page *p; - if (g_io_channel_read_chars(s, msg, LENGTH(msg), &msgsz, &gerr) != + if (g_io_channel_read_chars(s, msg, LENGTH(msg), NULL, &gerr) != G_IO_STATUS_NORMAL) { fprintf(stderr, "webext: error reading pipe: %s\n", gerr->message); g_error_free(gerr); return TRUE; } - msg[msgsz] = '\0'; + if ((msgsz = msg[0]) < 3) { + fprintf(stderr, "webext: message too short: %d\n", msgsz); + return TRUE; + } for (p = pages; p; p = p->next) { - if (p->id == msg[0]) + if (p->id == msg[1]) break; } if (!p || !(view = webkit_dom_document_get_default_view( webkit_web_page_get_dom_document(p->webpage)))) return TRUE; - switch (msg[1]) { + switch (msg[2]) { case 'h': + if (msgsz != 4) + return TRUE; ww = webkit_dom_dom_window_get_inner_width(view); webkit_dom_dom_window_scroll_by(view, - (ww / 100) * msg[2], 0); + (ww / 100) * msg[3], 0); break; case 'v': + if (msgsz != 4) + return TRUE; wh = webkit_dom_dom_window_get_inner_height(view); webkit_dom_dom_window_scroll_by(view, - 0, (wh / 100) * msg[2]); + 0, (wh / 100) * msg[3]); break; } diff --git a/surf.c b/surf.c index d48fbc9..2b54e3c 100644 --- a/surf.c +++ b/surf.c @@ -1209,20 +1209,22 @@ newview(Client *c, WebKitWebView *rv) static gboolean readpipe(GIOChannel *s, GIOCondition ioc, gpointer unused) { - char msg[MSGBUFSZ]; - gsize msgsz; + static char msg[MSGBUFSZ], msgsz; GError *gerr = NULL; - if (g_io_channel_read_chars(s, msg, sizeof(msg), &msgsz, &gerr) != + if (g_io_channel_read_chars(s, msg, sizeof(msg), NULL, &gerr) != G_IO_STATUS_NORMAL) { fprintf(stderr, "surf: error reading pipe: %s\n", gerr->message); g_error_free(gerr); return TRUE; } - msg[msgsz] = '\0'; + if ((msgsz = msg[0]) < 3) { + fprintf(stderr, "surf: message too short: %d\n", msgsz); + return TRUE; + } - switch (msg[1]) { + switch (msg[2]) { case 'i': close(pipein[1]); close(pipeout[0]); @@ -1843,12 +1845,18 @@ zoom(Client *c, const Arg *a) static void msgext(Client *c, char type, const Arg *a) { - char msg[MSGBUFSZ] = { c->pageid, type, a->i, '\0' }; + static char msg[MSGBUFSZ]; + int ret; - if (pipeout[1]) { - if (write(pipeout[1], msg, sizeof(msg)) < 0) - fprintf(stderr, "surf: error sending: %s\n", msg); + if ((ret = snprintf(msg, sizeof(msg), "%c%c%c%c", + 4, c->pageid, type, a->i)) + >= sizeof(msg)) { + fprintf(stderr, "surf: message too long: %d\n", ret); + return; } + + if (pipeout[1] && write(pipeout[1], msg, sizeof(msg)) < 0) + fprintf(stderr, "surf: error sending: %.*s\n", ret-2, msg+2); } void -- cgit v1.2.3 From b9cd3bb0bc3e897a44c8637b0da0fe0e28fa21c6 Mon Sep 17 00:00:00 2001 From: Quentin Rameau Date: Wed, 6 Feb 2019 10:22:15 +0100 Subject: Makefile: fix a typo for the webext CFLAGS Thanks to Justin Keogh for spotting this --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cdbd8ad..90df791 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ libsurf-webext.so: $(WEBEXTOBJ) $(CC) -shared -Wl,-soname,$@ $(LDFLAGS) -o $@ $< $(WEBEXTLIBS) -lc surf: $(OBJ) - $(CC) $(SURFLDLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) + $(CC) $(SURFLDFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) clean: rm -f surf $(OBJ) -- cgit v1.2.3 From 890b2fc3960b76086a9c2b645d0592135f7d5284 Mon Sep 17 00:00:00 2001 From: Quentin Rameau Date: Wed, 6 Feb 2019 10:27:01 +0100 Subject: Makefile: include common to webext --- Makefile | 21 +++++++++++++-------- config.mk | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 90df791..0e322d6 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,11 @@ include config.mk -SRC = surf.c common.c -OBJ = $(SRC:.c=.o) +SRC = surf.c +CSRC = common.c WEBEXTSRC = libsurf-webext.c +OBJ = $(SRC:.c=.o) +COBJ = $(CSRC:.c=.o) WEBEXTOBJ = $(WEBEXTSRC:.c=.o) all: options libsurf-webext.so surf @@ -25,18 +27,21 @@ config.h: cp config.def.h $@ $(OBJ): config.h common.h config.mk +$(COBJ): config.h common.h config.mk +$(WEBEXTOBJ): config.h common.h config.mk -$(WEBEXTOBJ): $(WEBEXTSRC) config.h common.h config.mk +$(WEBEXTOBJ): $(WEBEXTSRC) $(CC) $(WEBEXTCFLAGS) $(CFLAGS) -c $(WEBEXTSRC) -libsurf-webext.so: $(WEBEXTOBJ) - $(CC) -shared -Wl,-soname,$@ $(LDFLAGS) -o $@ $< $(WEBEXTLIBS) -lc +libsurf-webext.so: $(WEBEXTOBJ) $(COBJ) + $(CC) -shared -Wl,-soname,$@ $(LDFLAGS) -o $@ \ + $(WEBEXTOBJ) $(COBJ) $(WEBEXTLIBS) -surf: $(OBJ) - $(CC) $(SURFLDFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) +surf: $(OBJ) $(COBJ) + $(CC) $(SURFLDFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(COBJ) $(LIBS) clean: - rm -f surf $(OBJ) + rm -f surf $(OBJ) $(OBJ) rm -f libsurf-webext.so $(WEBEXTOBJ) distclean: clean diff --git a/config.mk b/config.mk index fa22f30..5e68e38 100644 --- a/config.mk +++ b/config.mk @@ -24,7 +24,7 @@ LIBS = $(X11LIB) $(GTKLIB) -lgthread-2.0 # flags CPPFLAGS = -DVERSION=\"$(VERSION)\" -DWEBEXTDIR=\"$(LIBDIR)\" \ -D_DEFAULT_SOURCE -DGCR_API_SUBJECT_TO_CHANGE -SURFCFLAGS = $(INCS) $(CPPFLAGS) +SURFCFLAGS = $(INCS) $(CPPFLAGS) -fPIC WEBEXTCFLAGS = -fPIC $(WEBEXTINC) # compiler -- cgit v1.2.3 From bf46e40f3ac3ce6007f9f5c1cf482dde2ae35589 Mon Sep 17 00:00:00 2001 From: Leonardo Taccari Date: Thu, 7 Feb 2019 21:22:48 +0100 Subject: Makefile: fix a typo in clean: target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0e322d6..4f5253a 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ surf: $(OBJ) $(COBJ) $(CC) $(SURFLDFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(COBJ) $(LIBS) clean: - rm -f surf $(OBJ) $(OBJ) + rm -f surf $(OBJ) $(COBJ) rm -f libsurf-webext.so $(WEBEXTOBJ) distclean: clean -- cgit v1.2.3 From d068a3878b6b9f2841a49cd7948cdf9d62b55585 Mon Sep 17 00:00:00 2001 From: efe Date: Fri, 8 Feb 2019 17:56:26 -0500 Subject: Fix vertical scroll directions in the config file --- config.def.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.def.h b/config.def.h index 8cdc397..34265f6 100644 --- a/config.def.h +++ b/config.def.h @@ -146,8 +146,8 @@ static Key keys[] = { /* vertical and horizontal scrolling, in viewport percentage */ { MODKEY, GDK_KEY_j, scrollv, { .i = +10 } }, { MODKEY, GDK_KEY_k, scrollv, { .i = -10 } }, - { MODKEY, GDK_KEY_b, scrollv, { .i = +50 } }, - { MODKEY, GDK_KEY_space, scrollv, { .i = -50 } }, + { MODKEY, GDK_KEY_space, scrollv, { .i = +50 } }, + { MODKEY, GDK_KEY_b, scrollv, { .i = -50 } }, { MODKEY, GDK_KEY_i, scrollh, { .i = +10 } }, { MODKEY, GDK_KEY_u, scrollh, { .i = -10 } }, -- cgit v1.2.3