summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--common.h2
-rw-r--r--libsurf-webext.c37
-rw-r--r--surf.c26
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
s=13&d=retro' width='13' height='13' alt='Gravatar' /> Markus Teich 2-8/+48 2015-02-03surf: see hover URL without changing titleGravatar Greg Reagle 1-0/+10 2015-02-03Some cleanup in style.Gravatar Christoph Lohmann 1-2/+2 2015-01-26Describe the web page indicators too.Gravatar Christoph Lohmann 1-0/+1 2015-01-26It wasn't really clear what was meant with site indicators in the manpage.Gravatar Christoph Lohmann 1-0/+1 2015-01-26surf: documented indicators in man pageGravatar Greg Reagle 1-0/+50 2015-01-20fix stylesheet interna.Gravatar Markus Teich 1-19/+12 2015-01-20Only plumb some URI, when it's ASCII.Gravatar Christoph Lohmann 1-1/+10 2015-01-20Oh my blob!Gravatar Christoph Lohmann 1-0/+1 2015-01-19Data: is part of the browser too.Gravatar Christoph Lohmann 1-0/+1 2015-01-19file:// should be handled in surf too.Gravatar Christoph Lohmann 1-0/+1 2015-01-19Remove the debugging from the testing.Gravatar Christoph Lohmann 1-1/+0 2015-01-19Add some description for the plumb feature.Gravatar Christoph Lohmann 1-0/+3 2015-01-19Add plumbing functionality.Gravatar Christoph Lohmann 2-2/+28 2015-01-18Add a comment about how the styles are iterated.Gravatar Christoph Lohmann 1-0/+4 2015-01-18My CMD was too short. :OGravatar Christoph Lohmann 1-1/+1 2015-01-17Add the manpage changes for the disk cache support.Gravatar Christoph Lohmann 1-1/+7 2015-01-17Adding disk cache support for soup.Gravatar Christoph Lohmann 2-9/+40 2015-01-17Fix extra newline, and add -g where other switches are forwarded.Gravatar Ben Woolley 1-1/+3 2015-01-17Newer libc want _DEFAULT_SOURCE.Gravatar Christoph Lohmann 1-1/+1 2015-01-17Major styles update.Gravatar Christoph Lohmann 3-11/+84 2015-01-02Fix a typo in surf manual.Gravatar Jakukyo Friel 1-1/+1 2014-09-28Minor style change.Gravatar Christoph Lohmann 1-1/+1 2014-09-28Make »Copy image address« work.Gravatar Christoph Lohmann 1-3/+10 2014-08-07Mention xdotool in SEE ALSO too.Gravatar Christoph Lohmann 1-1/+2 2014-08-07Fix the manpage about xid.Gravatar Christoph Lohmann 1-1/+3