summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.mk2
-rw-r--r--surf.143
-rw-r--r--surf.c71
3 files changed, 79 insertions, 37 deletions
diff --git a/config.mk b/config.mk
index 1c7d2d2..c620341 100644
--- a/config.mk
+++ b/config.mk
@@ -13,7 +13,7 @@ GTKLIB=$(shell pkg-config --libs gtk+-2.0 webkit-1.0)
# includes and libs
INCS = -I. -I/usr/include ${GTKINC}
-LIBS = -L/usr/lib -lc ${GTKLIB}
+LIBS = -L/usr/lib -lc ${GTKLIB} -lgthread-2.0
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\"
diff --git a/surf.1 b/surf.1
index 9c2959b..b6684cd 100644
--- a/surf.1
+++ b/surf.1
@@ -1,43 +1,36 @@
.TH SURF 1 surf\-VERSION
.SH NAME
-surf \- simple webkit based browser
+surf \- simple webkit-based browser
.SH SYNOPSIS
.B surf
.RB [ \-ehvx ]
-.RB [ \-f " FILE"]
-.RB [ \-u " URI"]
+.RB "URI"
.SH DESCRIPTION
-surf is a simple webbrowser which is based on webkit/gtk+. It is able
-to display websites and follow links. It supports the Xembedded protocol
-which makes it possible to embed it into another application. Furthermore
-one can point surf to another URI by setting it's XProperties.
+surf is a simple Web browser based on WebKit/GTK+. It is able
+to display websites and follow links. It supports the XEmbed protocol
+which makes it possible to embed it in another application. Furthermore,
+one can point surf to another URI by setting its XProperties.
.SH OPTIONS
.TP
.B \-e
-prints xid to standard output and waits until some application reparent the
+Prints xid to standard output and waits until an application reparents the
window.
.TP
-.B \-f FILE
-Sets the browsers URI to FILE. Also it's possible to read from stdin.
-.TP
.B \-h
-prints usage information to standard output, then exits.
-.TP
-.B \-u URI
-Sets the browsers URI.
+Prints usage information to standard output, then exits.
.TP
.B \-v
-prints version information to standard output, then exits.
+Prints version information to standard output, then exits.
.TP
.B \-x
-prints xid to standard output. This can be used to script the browser by using
-xprop
+Prints xid to standard output. This can be used to script the browser by using
+.BR xprop(1).
.SH USAGE
.TP
-.B Ctrl\-Left
+.B Ctrl\-h
Walks back the history.
.TP
-.B Ctrl\-Right
+.B Ctrl\-l
Walks forward the history.
.TP
.B Ctrl\-/
@@ -46,13 +39,19 @@ Opens the search-bar.
.B Ctrl\-g
Opens the URL-bar.
.TP
+.B Ctrl\-p
+Loads URI from primary selection.
+.TP
.B Ctrl\-r
Reloads the website.
.TP
.B Ctrl\-Shift\-r
Reloads the website without using cache.
+.TP
+.B Ctrl\-y
+Copies current URI to primary selection.
.SH SEE ALSO
-.BR dmenu (1)
-.BR xprop (1)
+.BR dmenu(1)
+.BR xprop(1)
.SH BUGS
Please report them!
diff --git a/surf.c b/surf.c
index fb277cc..2778bee 100644
--- a/surf.c
+++ b/surf.c
@@ -38,6 +38,14 @@ typedef struct Client {
struct Client *next;
} Client;
+typedef struct Cookie {
+ char *name;
+ char *value;
+ char *domain;
+ char *path;
+ struct Cookie *next;
+} Cookie;
+
typedef struct {
guint mod;
guint keyval;
@@ -59,7 +67,9 @@ typedef struct {
} KeySet;
SoupCookieJar *cookiejar;
+SoupSession *session;
Client *clients = NULL;
+Cookie *cookies = NULL;
gboolean embed = FALSE;
gboolean showxid = FALSE;
gboolean ignore_once = FALSE;
@@ -67,6 +77,7 @@ extern char *optarg;
extern int optind;
static void cleanup(void);
+static void proccookies(SoupMessage *m, Client *c);
static void clipboard(Client *c, const Arg *arg);
static void destroyclient(Client *c);
static void destroywin(GtkWidget* w, Client *c);
@@ -88,8 +99,12 @@ static WebKitWebView *newwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c)
static void pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d);
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
static void progresschange(WebKitWebView *view, gint p, Client *c);
+static void request(SoupSession *s, SoupMessage *m, Client *c);
+static void setcookie(char *name, char *val, char *dom, char *path, long exp);
static void reload(Client *c, const Arg *arg);
static void setup(void);
+static void titlechange(WebKitWebView* view, WebKitWebFrame* frame,
+ const gchar* title, Client *c);
static void searchtext(Client *c, const Arg *arg);
static void showsearch(Client *c, const Arg *arg);
static void showurl(Client *c, const Arg *arg);
@@ -108,6 +123,20 @@ cleanup(void) {
}
void
+proccookies(SoupMessage *m, Client *c) {
+ GSList *l;
+ SoupCookie *co;
+ long t;
+
+ for (l = soup_cookies_from_response(m); l; l = l->next){
+ co = (SoupCookie *)l->data;
+ t = co->expires ? soup_date_to_time_t(co->expires) : 0;
+ setcookie(co->name, co->value, co->domain, co->value, t);
+ }
+ g_slist_free(l);
+}
+
+void
clipboard(Client *c, const Arg *arg) {
gboolean paste = *(gboolean *)arg;
if(paste)
@@ -228,7 +257,6 @@ keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
fprintf(stderr, "keypress(): Unknown Keypressmode\n");
break;
}
-
if(n < LENGTH(keysets)) {
matchkeys:
for(m = 0; m < keysets[n].numkeys; m++) {
@@ -309,7 +337,7 @@ loaduri(Client *c, const Arg *arg) {
const gchar *uri = (gchar *)arg->v;
if(!uri)
uri = gtk_entry_get_text(GTK_ENTRY(c->urlbar));
- u = g_strrstr(uri, ":") ? g_strdup(uri)
+ u = g_strrstr(uri, "://") ? g_strdup(uri)
: g_strdup_printf("http://%s", uri);
webkit_web_view_load_uri(c->view, u);
c->progress = 0;
@@ -360,6 +388,7 @@ newclient(void) {
g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c);
g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
+ g_signal_connect_after(session, "request-started", G_CALLBACK(request), c);
/* urlbar */
c->urlbar = gtk_entry_new();
@@ -424,6 +453,7 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
unsigned long ldummy;
unsigned char *buf = NULL;
Arg arg;
+
if(((XEvent *)e)->type == PropertyNotify) {
ev = &((XEvent *)e)->xproperty;
if(ev->atom == urlprop && ev->state == PropertyNewValue) {
@@ -449,6 +479,12 @@ progresschange(WebKitWebView* view, gint p, Client *c) {
}
void
+request(SoupSession *s, SoupMessage *m, Client *c) {
+ soup_message_add_header_handler(m, "got-headers", "Set-Cookie",
+ G_CALLBACK(proccookies), c);
+}
+
+void
reload(Client *c, const Arg *arg) {
gboolean nocache = *(gboolean *)arg;
if(nocache)
@@ -457,8 +493,15 @@ reload(Client *c, const Arg *arg) {
webkit_web_view_reload(c->view);
}
-void setup(void) {
+void
+setcookie(char *name, char *val, char *dom, char *path, long exp) {
+ printf("%s %s %s %s %li\n", name, val, dom, path, exp);
+}
+
+void
+setup() {
dpy = GDK_DISPLAY();
+ session = webkit_get_default_session();
urlprop = XInternAtom(dpy, "_SURF_URL", False);
}
@@ -507,7 +550,7 @@ titlechange(WebKitWebView *v, WebKitWebFrame *f, const gchar *t, Client *c) {
void
usage() {
fputs("surf - simple browser\n", stderr);
- die("usage: surf [-e] [-x] [-u uri] [-f file]\n");
+ die("usage: surf [-e] [-x] [uri]\n");
}
void
@@ -558,22 +601,22 @@ int main(int argc, char *argv[]) {
showxid = TRUE;
embed = TRUE;
break;
- case 'u':
- c = newclient();
- arg.v = optarg;
- loaduri(c, &arg);
- break;
- case 'f':
- c = newclient();
- loadfile(c, optarg);
- break;
case 'v':
die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
break;
default:
usage();
}
- if(optind != argc)
+ if(optind + 1 == argc) {
+ c = newclient();
+ arg.v = argv[optind];
+ if(strchr("./", argv[optind][0]) || strcmp("-", argv[optind]) == 0)
+ loadfile(c, argv[optind]);
+ else
+ loaduri(c, &arg);
+
+ }
+ else if(optind != argc)
usage();
if(!clients)
newclient();