summaryrefslogtreecommitdiff
path: root/surf.c
diff options
context:
space:
mode:
Diffstat (limited to 'surf.c')
-rw-r--r--surf.c71
1 files changed, 57 insertions, 14 deletions
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();