add URL filtering patch

This commit is contained in:
zcake 2021-01-14 11:24:24 +08:00
parent 67b142bde7
commit 557fed1b70
16 changed files with 60887 additions and 3 deletions

View File

@ -27,7 +27,7 @@ $(OBJ) $(WOBJ): config.h common.h config.mk
config.h:
cp config.def.h $@
$(OBJ): $(SRC)
$(OBJ): $(SRC) filters_compiled
$(CC) $(SURFCFLAGS) $(CFLAGS) -c $(SRC)
$(WLIB): $(WOBJ)
@ -37,7 +37,7 @@ $(WOBJ): $(WSRC)
$(CC) $(WEBEXTCFLAGS) $(CFLAGS) -c $(WSRC)
clean:
rm -f surf $(OBJ)
rm -f surf $(OBJ) filters_compiled filters
rm -f $(WLIB) $(WOBJ)
distclean: clean
@ -52,6 +52,13 @@ dist: distclean
gzip surf-$(VERSION).tar
rm -rf surf-$(VERSION)
filters_compiled: filters
sed -e '/#/d' -e '/^$$/d' -e 's|\\|\\\\|g' -e 's|$$|",|' -e 's|^|"|' < filters > $@
filters:
@echo creating $@ from filters.def
@cp filters.def $@
install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f surf $(DESTDIR)$(PREFIX)/bin

81
Makefile.orig Normal file
View File

@ -0,0 +1,81 @@
# surf - simple browser
# See LICENSE file for copyright and license details.
.POSIX:
include config.mk
SRC = surf.c
WSRC = webext-surf.c
OBJ = $(SRC:.c=.o)
WOBJ = $(WSRC:.c=.o)
WLIB = $(WSRC:.c=.so)
all: options surf $(WLIB)
options:
@echo surf build options:
@echo "CC = $(CC)"
@echo "CFLAGS = $(SURFCFLAGS) $(CFLAGS)"
@echo "WEBEXTCFLAGS = $(WEBEXTCFLAGS) $(CFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)"
surf: $(OBJ)
$(CC) $(SURFLDFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
$(OBJ) $(WOBJ): config.h common.h config.mk
config.h:
cp config.def.h $@
$(OBJ): $(SRC)
$(CC) $(SURFCFLAGS) $(CFLAGS) -c $(SRC)
$(WLIB): $(WOBJ)
$(CC) -shared -Wl,-soname,$@ $(LDFLAGS) -o $@ $? $(WEBEXTLIBS)
$(WOBJ): $(WSRC)
$(CC) $(WEBEXTCFLAGS) $(CFLAGS) -c $(WSRC)
clean:
rm -f surf $(OBJ)
rm -f $(WLIB) $(WOBJ)
distclean: clean
rm -f config.h surf-$(VERSION).tar.gz
dist: distclean
mkdir -p surf-$(VERSION)
cp -R LICENSE Makefile config.mk config.def.h README \
surf-open.sh arg.h TODO.md surf.png \
surf.1 $(SRC) $(CSRC) $(WSRC) surf-$(VERSION)
tar -cf surf-$(VERSION).tar surf-$(VERSION)
gzip surf-$(VERSION).tar
rm -rf surf-$(VERSION)
install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f surf $(DESTDIR)$(PREFIX)/bin
chmod 755 $(DESTDIR)$(PREFIX)/bin/surf
mkdir -p $(DESTDIR)$(LIBDIR)
cp -f $(WLIB) $(DESTDIR)$(LIBDIR)
for wlib in $(WLIB); do \
chmod 644 $(DESTDIR)$(LIBDIR)/$$wlib; \
done
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
sed "s/VERSION/$(VERSION)/g" < surf.1 > $(DESTDIR)$(MANPREFIX)/man1/surf.1
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/surf.1
cp -f surf-bookmark $(DESTDIR)$(PREFIX)/bin/
chmod 755 $(DESTDIR)$(PREFIX)/bin/surf-bookmark
cp -f surf-add $(DESTDIR)$(PREFIX)/bin/
chmod 755 $(DESTDIR)$(PREFIX)/bin/surf-add
cp -f surf-del $(DESTDIR)$(PREFIX)/bin/
chmod 755 $(DESTDIR)$(PREFIX)/bin/surf-del
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/surf
rm -f $(DESTDIR)$(MANPREFIX)/man1/surf.1
for wlib in $(WLIB); do \
rm -f $(DESTDIR)$(LIBDIR)/$$wlib; \
done
- rmdir $(DESTDIR)$(LIBDIR)
.PHONY: all options distclean clean dist install uninstall

27
Makefile.rej Normal file
View File

@ -0,0 +1,27 @@
--- Makefile
+++ Makefile
@@ -18,7 +18,14 @@ options:
@echo CC $<
@${CC} -c ${CFLAGS} $<
-${OBJ}: config.h config.mk
+${OBJ}: config.h config.mk filters_compiled
+
filters_compiled: filters
sed -e '/^$$/d' -e 's|\\|\\\\|g' -e 's|$$|",|' -e 's|^|"|' < filters > $@
filters:
@echo creating $@ from filters.def
@cp filters.def $@
config.h:
@echo creating $@ from config.def.h
@@ -30,7 +37,7 @@ surf: ${OBJ}
clean:
@echo cleaning
- @rm -f surf ${OBJ} surf-${VERSION}.tar.gz
+ @rm -f surf ${OBJ} surf-${VERSION}.tar.gz filters_compiled
dist: clean
@echo creating dist tarball

View File

@ -12,6 +12,13 @@ static char **plugindirs = (char*[]){
NULL
};
/* Regular expressions to match URLs that should not be loaded */
char *filter_patterns[] = {
#include "filters_compiled"
};
/* Define this for verbose filtering */
// #define FILTER_VERBOSE
/* Webkit default features */
/* Highest priority value will be used.
* Default parameters are priority 0

201
config.def.h.orig Normal file
View File

@ -0,0 +1,201 @@
/* modifier 0 means no modifier */
static int surfuseragent = 1; /* Append Surf version to default WebKit user agent */
static char *fulluseragent = ""; /* Or override the whole user agent string */
static char *scriptfile = "~/.surf/script.js";
static char *styledir = "~/.surf/styles/";
static char *certdir = "~/.surf/certificates/";
static char *cachedir = "~/.surf/cache/";
static char *cookiefile = "~/.surf/cookies.txt";
static char **plugindirs = (char*[]){
"~/.surf/plugins/",
LIBPREFIX "/mozilla/plugins/",
NULL
};
/* Webkit default features */
/* Highest priority value will be used.
* Default parameters are priority 0
* Per-uri parameters are priority 1
* Command parameters are priority 2
*/
static Parameter defconfig[ParameterLast] = {
/* parameter Arg value priority */
[AcceleratedCanvas] = { { .i = 1 }, },
[AccessMicrophone] = { { .i = 0 }, },
[AccessWebcam] = { { .i = 0 }, },
[Certificate] = { { .i = 0 }, },
[CaretBrowsing] = { { .i = 0 }, },
[CookiePolicies] = { { .v = "@Aa" }, },
[DefaultCharset] = { { .v = "UTF-8" }, },
[DiskCache] = { { .i = 1 }, },
[DNSPrefetch] = { { .i = 0 }, },
[Ephemeral] = { { .i = 0 }, },
[FileURLsCrossAccess] = { { .i = 0 }, },
[FontSize] = { { .i = 12 }, },
[FrameFlattening] = { { .i = 0 }, },
[Geolocation] = { { .i = 0 }, },
[HideBackground] = { { .i = 0 }, },
[Inspector] = { { .i = 0 }, },
[Java] = { { .i = 1 }, },
[JavaScript] = { { .i = 1 }, },
[KioskMode] = { { .i = 0 }, },
[LoadImages] = { { .i = 1 }, },
[MediaManualPlay] = { { .i = 1 }, },
[Plugins] = { { .i = 1 }, },
[PreferredLanguages] = { { .v = (char *[]){ NULL } }, },
[RunInFullscreen] = { { .i = 0 }, },
[ScrollBars] = { { .i = 1 }, },
[ShowIndicators] = { { .i = 1 }, },
[SiteQuirks] = { { .i = 1 }, },
[SmoothScrolling] = { { .i = 0 }, },
[SpellChecking] = { { .i = 0 }, },
[SpellLanguages] = { { .v = ((char *[]){ "en_US", NULL }) }, },
[StrictTLS] = { { .i = 1 }, },
[Style] = { { .i = 1 }, },
[WebGL] = { { .i = 0 }, },
[ZoomLevel] = { { .f = 1.0 }, },
};
static UriParameters uriparams[] = {
{ "(://|\\.)suckless\\.org(/|$)", {
[JavaScript] = { { .i = 0 }, 1 },
[Plugins] = { { .i = 0 }, 1 },
}, },
};
/* default window size: width, height */
static int winsize[] = { 800, 600 };
static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
WEBKIT_FIND_OPTIONS_WRAP_AROUND;
#define PROMPT_GO "Go:"
#define PROMPT_FIND "Find:"
/* SETPROP(readprop, setprop, prompt)*/
#define SETPROP(r, s, p) { \
.v = (const char *[]){ "/bin/sh", "-c", \
"prop=\"$(printf '%b' \"$(xprop -id $1 $2 " \
"| sed \"s/^$2(STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\")\" " \
"| dmenu -p \"$4\" -w $1)\" && xprop -id $1 -f $3 8s -set $3 \"$prop\"", \
"surf-setprop", winid, r, s, p, NULL \
} \
}
/* DOWNLOAD(URI, referer) */
#define DOWNLOAD(u, r) { \
.v = (const char *[]){ "st", "-e", "/bin/sh", "-c",\
"curl -g -L -J -O -A \"$1\" -b \"$2\" -c \"$2\"" \
" -e \"$3\" \"$4\"; read", \
"surf-download", useragent, cookiefile, r, u, NULL \
} \
}
/* PLUMB(URI) */
/* This called when some URI which does not begin with "about:",
* "http://" or "https://" should be opened.
*/
#define PLUMB(u) {\
.v = (const char *[]){ "/bin/sh", "-c", \
"xdg-open \"$0\"", u, NULL \
} \
}
/* VIDEOPLAY(URI) */
#define VIDEOPLAY(u) {\
.v = (const char *[]){ "/bin/sh", "-c", \
"mpv --really-quiet \"$0\"", u, NULL \
} \
}
/* styles */
/*
* The iteration will stop at the first match, beginning at the beginning of
* the list.
*/
static SiteSpecific styles[] = {
/* regexp file in $styledir */
{ ".*", "default.css" },
};
/* certificates */
/*
* Provide custom certificate for urls
*/
static SiteSpecific certs[] = {
/* regexp file in $certdir */
{ "://suckless\\.org/", "suckless.org.crt" },
};
#define MODKEY GDK_CONTROL_MASK
/* hotkeys */
/*
* If you use anything else but MODKEY and GDK_SHIFT_MASK, don't forget to
* edit the CLEANMASK() macro.
*/
static Key keys[] = {
/* modifier keyval function arg */
{ MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) },
{ MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
{ MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
{ 0, GDK_KEY_Escape, stop, { 0 } },
{ MODKEY, GDK_KEY_c, stop, { 0 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_r, reload, { .i = 1 } },
{ MODKEY, GDK_KEY_r, reload, { .i = 0 } },
{ MODKEY, GDK_KEY_l, navigate, { .i = +1 } },
{ MODKEY, GDK_KEY_h, navigate, { .i = -1 } },
/* vertical and horizontal scrolling, in viewport percentage */
{ MODKEY, GDK_KEY_j, scrollv, { .i = +10 } },
{ MODKEY, GDK_KEY_k, scrollv, { .i = -10 } },
{ 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 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } },
{ MODKEY, GDK_KEY_minus, zoom, { .i = -1 } },
{ MODKEY, GDK_KEY_plus, zoom, { .i = +1 } },
{ MODKEY, GDK_KEY_p, clipboard, { .i = 1 } },
{ MODKEY, GDK_KEY_y, clipboard, { .i = 0 } },
{ MODKEY, GDK_KEY_n, find, { .i = +1 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_n, find, { .i = -1 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_p, print, { 0 } },
{ MODKEY, GDK_KEY_t, showcert, { 0 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_a, togglecookiepolicy, { 0 } },
{ 0, GDK_KEY_F11, togglefullscreen, { 0 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_o, toggleinspector, { 0 } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_c, toggle, { .i = CaretBrowsing } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_f, toggle, { .i = FrameFlattening } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_g, toggle, { .i = Geolocation } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_s, toggle, { .i = JavaScript } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_i, toggle, { .i = LoadImages } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_v, toggle, { .i = Plugins } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } },
};
/* button definitions */
/* target can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */
static Button buttons[] = {
/* target event mask button function argument stop event */
{ OnLink, 0, 2, clicknewwindow, { .i = 0 }, 1 },
{ OnLink, MODKEY, 2, clicknewwindow, { .i = 1 }, 1 },
{ OnLink, MODKEY, 1, clicknewwindow, { .i = 1 }, 1 },
{ OnAny, 0, 8, clicknavigate, { .i = -1 }, 1 },
{ OnAny, 0, 9, clicknavigate, { .i = +1 }, 1 },
{ OnMedia, MODKEY, 1, clickexternplayer, { 0 }, 1 },
};

View File

@ -12,6 +12,13 @@ static char **plugindirs = (char*[]){
NULL
};
/* Regular expressions to match URLs that should not be loaded */
char *filter_patterns[] = {
#include "filters_compiled"
};
/* Define this for verbose filtering */
// #define FILTER_VERBOSE
/* Webkit default features */
/* Highest priority value will be used.
* Default parameters are priority 0

14526
filters Normal file

File diff suppressed because it is too large Load Diff

14526
filters.def Normal file

File diff suppressed because it is too large Load Diff

14520
filters_compiled Normal file

File diff suppressed because it is too large Load Diff

14590
hosts Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,154 @@
diff --git a/Makefile b/Makefile
index a9d4d1d..75fb004 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,14 @@ options:
@echo CC $<
@${CC} -c ${CFLAGS} $<
-${OBJ}: config.h config.mk
+${OBJ}: config.h config.mk filters_compiled
+
+filters_compiled: filters
+ sed -e '/^$$/d' -e 's|\\|\\\\|g' -e 's|$$|",|' -e 's|^|"|' < filters > $@
+
+filters:
+ @echo creating $@ from filters.def
+ @cp filters.def $@
config.h:
@echo creating $@ from config.def.h
@@ -30,7 +37,7 @@ surf: ${OBJ}
clean:
@echo cleaning
- @rm -f surf ${OBJ} surf-${VERSION}.tar.gz
+ @rm -f surf ${OBJ} surf-${VERSION}.tar.gz filters_compiled
dist: clean
@echo creating dist tarball
diff --git a/config.def.h b/config.def.h
index 80a0feb..3cc5131 100644
--- a/config.def.h
+++ b/config.def.h
@@ -21,6 +21,13 @@ static char *cafile = "/etc/ssl/certs/ca-certificates.crt";
static char *strictssl = FALSE; /* Refuse untrusted SSL connections */
static time_t sessiontime = 3600;
+/* Regular expressions to match URLs that should not be loaded */
+char *filter_patterns[] = {
+#include "filters_compiled"
+};
+/* Define this for verbose filtering */
+// #define FILTER_VERBOSE
+
/* Webkit default features */
static Bool enablescrollbars = TRUE;
static Bool enablespatialbrowsing = TRUE;
diff --git a/filters.def b/filters.def
new file mode 100644
index 0000000..77158de
--- /dev/null
+++ b/filters.def
@@ -0,0 +1,2 @@
+^eviladvertisments\.com$
+/favicon\.ico$
diff --git a/surf.c b/surf.c
index 7c78b4a..8d24197 100644
--- a/surf.c
+++ b/surf.c
@@ -20,6 +20,7 @@
#include <webkit/webkit.h>
#include <glib/gstdio.h>
#include <JavaScriptCore/JavaScript.h>
+#include <regex.h>
#include <sys/file.h>
#include <libgen.h>
#include <stdarg.h>
@@ -27,6 +28,7 @@
#include "arg.h"
char *argv0;
+regex_t *filter_expressions;
#define LENGTH(x) (sizeof x / sizeof x[0])
#define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
@@ -119,6 +121,8 @@ static void destroyclient(Client *c);
static void destroywin(GtkWidget* w, Client *c);
static void die(const char *errstr, ...);
static void eval(Client *c, const Arg *arg);
+static bool filter_init(void);
+static bool filter_request(const gchar *uri);
static void find(Client *c, const Arg *arg);
static void fullscreen(Client *c, const Arg *arg);
static void geopolicyrequested(WebKitWebView *v, WebKitWebFrame *f,
@@ -200,7 +204,7 @@ beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r,
gpointer d) {
const gchar *uri = webkit_network_request_get_uri(req);
- if(g_str_has_suffix(uri, "/favicon.ico"))
+ if(filter_request(uri))
webkit_network_request_set_uri(req, "about:blank");
}
@@ -473,6 +477,49 @@ die(const char *errstr, ...) {
exit(EXIT_FAILURE);
}
+static bool
+filter_init(void) {
+ bool errors = false;
+ char *errorbuf;
+
+ errorbuf = malloc(sizeof(char) * BUFSIZ);
+ filter_expressions = malloc(sizeof(regex_t) * LENGTH(filter_patterns));
+
+ for (off_t idx = 0; idx < LENGTH(filter_patterns); idx++) {
+ char *pat = filter_patterns[idx];
+ int err = regcomp(&filter_expressions[idx], pat,
+ REG_EXTENDED | REG_ICASE | REG_NOSUB);
+ if (err != 0) {
+ /* regerror always ends messages with 0x00 */
+ (void) regerror(err, &filter_expressions[idx], errorbuf, BUFSIZ);
+ fprintf(stderr, "Failed to compile \"%s\": %s\n", pat, errorbuf);
+ errors = true;
+ }
+ }
+
+ free(errorbuf);
+ return !errors;
+}
+
+static bool
+filter_request(const gchar *uri) {
+ if (!strcmp(uri, "about:blank"))
+ return false;
+ for (off_t idx = 0; idx < LENGTH(filter_patterns); idx++) {
+ if (regexec(&filter_expressions[idx], uri, 0, NULL, 0) == REG_NOMATCH) {
+ continue;
+ }
+#ifdef FILTER_VERBOSE
+ fprintf(stderr, "filtering \"%s\"\n", uri);
+#endif
+ return true;
+ }
+#ifdef FILTER_VERBOSE
+ fprintf(stderr, "not filtering \"%s\"\n", uri);
+#endif
+ return false;
+}
+
static void
find(Client *c, const Arg *arg) {
const char *s;
@@ -1152,6 +1199,10 @@ setup(void) {
g_free(new_proxy);
usingproxy = 1;
}
+
+ if (!filter_init()) {
+ die("Failed to compile one or more filter expressions\n");
+ }
}
static void

BIN
surf

Binary file not shown.

53
surf.c
View File

@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <regex.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
@ -179,6 +180,8 @@ static void spawn(Client *c, const Arg *a);
static void msgext(Client *c, char type, const Arg *a);
static void destroyclient(Client *c);
static void cleanup(void);
static bool filter_init(void);
static bool filter_request(const gchar *uri);
/* GTK/WebKit */
static WebKitWebView *newview(Client *c, WebKitWebView *rv);
@ -257,6 +260,7 @@ static Parameter *curconfig;
static int modparams[ParameterLast];
static int spair[2];
char *argv0;
regex_t *filter_expressions;
static ParamName loadtransient[] = {
Certificate,
@ -1711,7 +1715,7 @@ decideresource(WebKitPolicyDecision *d, Client *c)
webkit_response_policy_decision_get_response(r);
const gchar *uri = webkit_uri_response_get_uri(res);
if (g_str_has_suffix(uri, "/favicon.ico")) {
if(filter_request(uri)){
webkit_policy_decision_ignore(d);
return;
}
@ -1871,6 +1875,49 @@ zoom(Client *c, const Arg *a)
curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
}
static bool
filter_init(void) {
bool errors = false;
char *errorbuf;
errorbuf = malloc(sizeof(char) * BUFSIZ);
filter_expressions = malloc(sizeof(regex_t) * LENGTH(filter_patterns));
for (off_t idx = 0; idx < LENGTH(filter_patterns); idx++) {
char *pat = filter_patterns[idx];
int err = regcomp(&filter_expressions[idx], pat,
REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (err != 0) {
/* regerror always ends messages with 0x00 */
(void) regerror(err, &filter_expressions[idx], errorbuf, BUFSIZ);
fprintf(stderr, "Failed to compile \"%s\": %s\n", pat, errorbuf);
errors = true;
}
}
free(errorbuf);
return !errors;
}
static bool
filter_request(const gchar *uri) {
if (!strcmp(uri, "about:blank"))
return false;
for (off_t idx = 0; idx < LENGTH(filter_patterns); idx++) {
if (regexec(&filter_expressions[idx], uri, 0, NULL, 0) == REG_NOMATCH) {
continue;
}
#ifdef FILTER_VERBOSE
fprintf(stderr, "filtering \"%s\"\n", uri);
#endif
return true;
}
#ifdef FILTER_VERBOSE
fprintf(stderr, "not filtering \"%s\"\n", uri);
#endif
return false;
}
static void
msgext(Client *c, char type, const Arg *a)
{
@ -1977,6 +2024,10 @@ find(Client *c, const Arg *a)
if (strcmp(s, "") == 0)
webkit_find_controller_search_finish(c->finder);
}
if (!filter_init()) {
die("Failed to compile one or more filter expressions\n");
}
}
void

2159
surf.c.orig Normal file

File diff suppressed because it is too large Load Diff

28
surf.c.rej Normal file
View File

@ -0,0 +1,28 @@
--- surf.c
+++ surf.c
@@ -20,6 +20,7 @@
#include <webkit/webkit.h>
#include <glib/gstdio.h>
#include <JavaScriptCore/JavaScript.h>
+#include <regex.h>
#include <sys/file.h>
#include <libgen.h>
#include <stdarg.h>
@@ -120,6 +122,8 @@ static void destroyclient(Client *c);
static void destroywin(GtkWidget* w, Client *c);
static void die(const char *errstr, ...);
static void eval(Client *c, const Arg *arg);
+static bool filter_init(void);
+static bool filter_request(const gchar *uri);
static void find(Client *c, const Arg *arg);
static void fullscreen(Client *c, const Arg *arg);
static void geopolicyrequested(WebKitWebView *v, WebKitWebFrame *f,
@@ -201,7 +205,7 @@ beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r,
gpointer d) {
const gchar *uri = webkit_network_request_get_uri(req);
- if(g_str_has_suffix(uri, "/favicon.ico"))
+ if(filter_request(uri))
webkit_network_request_set_uri(req, "about:blank");
}

BIN
surf.o

Binary file not shown.