aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CHECKLIST3
-rw-r--r--Makefile2
-rw-r--r--examples/configs/sampleconfig4
-rw-r--r--examples/configs/sampleconfig-dev4
-rw-r--r--uzbl.c48
-rw-r--r--uzbl.h3
6 files changed, 54 insertions, 10 deletions
diff --git a/CHECKLIST b/CHECKLIST
index 66f7bf6..292f9ab 100644
--- a/CHECKLIST
+++ b/CHECKLIST
@@ -34,4 +34,5 @@ Also testers and interested people can use this list to see what uzbl is about,
* searching:
/_ = search %s <-- hilight all
; = search <-- jump over all hits
-* run javascript on curent page through "script" command. \ No newline at end of file
+* run javascript on curent page through "script" command.
+* variable replacement in user agent. \ No newline at end of file
diff --git a/Makefile b/Makefile
index 52d96b6..622a79a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CPPFLAGS=$(shell pkg-config --cflags gtk+-2.0 webkit-1.0) -Wall -W
+CPPFLAGS=$(shell pkg-config --cflags gtk+-2.0 webkit-1.0) -Wall -W -DARCH="\"$(shell uname -m)\"" -DCOMMIT="\"$(shell git log | head -n1 | sed "s/.* //")\""
LDFLAGS=$(shell pkg-config --libs gtk+-2.0 webkit-1.0)
all: uzbl uzblctrl
diff --git a/examples/configs/sampleconfig b/examples/configs/sampleconfig
index f60e459..5c8226d 100644
--- a/examples/configs/sampleconfig
+++ b/examples/configs/sampleconfig
@@ -56,6 +56,8 @@ S = script alert("hi");
proxy_server =
#values 0-3
http_debug = 0
-user-agent = uzbl
+user-agent = uzbl (Webkit %webkit-major%.%webkit-minor%.%webkit-micro%)
+# Example user agent containing everything:
+#user-agent = Uzbl (Webkit %webkit-major%.%webkit-minor%.%webkit-micro%) (%sysname% %nodename% %kernrel% %kernver% %arch-system% [%arch-uzbl%])
max_conns =
max_conns_per_host =
diff --git a/examples/configs/sampleconfig-dev b/examples/configs/sampleconfig-dev
index 25f66be..8749fe8 100644
--- a/examples/configs/sampleconfig-dev
+++ b/examples/configs/sampleconfig-dev
@@ -57,7 +57,9 @@ S = script alert("hi");
#proxy_server = http://127.0.0.1:8118
#values 0-3
http_debug = 0
-user-agent = uzbl
+user-agent = uzbl (Webkit %webkit-major%.%webkit-minor%.%webkit-micro%)
+# Example user agent containing everything:
+#user-agent = Uzbl (Webkit %webkit-major%.%webkit-minor%.%webkit-micro%) (%sysname% %nodename% %kernrel% %kernver% %arch-system% [%arch-uzbl%])
max_conns =
max_conns_per_host =
diff --git a/uzbl.c b/uzbl.c
index 50ce805..57c2de4 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -40,6 +40,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
+#include <sys/utsname.h>
#include <webkit/webkit.h>
#include <stdio.h>
#include <string.h>
@@ -92,6 +93,9 @@ static gchar* modkey = NULL;
static guint modmask = 0;
static guint http_debug = 0;
+/* System info */
+static struct utsname unameinfo;
+
/* settings from config: group bindings, key -> action */
static GHashTable* bindings;
@@ -132,6 +136,11 @@ itos(int val) {
return g_strdup(tmp);
}
+static char *
+str_replace (const char* search, const char* replace, const char* string) {
+ return g_strjoinv (replace, g_strsplit(string, search, -1));
+}
+
/* --- CALLBACKS --- */
static gboolean
@@ -874,7 +883,7 @@ settings_init () {
if (config_file) {
config = g_key_file_new ();
res = g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, NULL);
- if(res) {
+ if (res) {
printf ("Config %s loaded\n", config_file);
} else {
fprintf (stderr, "Config %s loading failed\n", config_file);
@@ -942,11 +951,13 @@ settings_init () {
}
/* networking options */
- proxy_url = g_key_file_get_value (config, "network", "proxy_server", NULL);
- http_debug = g_key_file_get_integer (config, "network", "http_debug", NULL);
- useragent = g_key_file_get_value (config, "network", "user-agent", NULL);
- max_conns = g_key_file_get_integer (config, "network", "max_conns", NULL);
- max_conns_host = g_key_file_get_integer (config, "network", "max_conns_per_host", NULL);
+ if (res) {
+ proxy_url = g_key_file_get_value (config, "network", "proxy_server", NULL);
+ http_debug = g_key_file_get_integer (config, "network", "http_debug", NULL);
+ useragent = g_key_file_get_value (config, "network", "user-agent", NULL);
+ max_conns = g_key_file_get_integer (config, "network", "max_conns", NULL);
+ max_conns_host = g_key_file_get_integer (config, "network", "max_conns_per_host", NULL);
+ }
if(proxy_url){
g_object_set(G_OBJECT(soup_session), SOUP_SESSION_PROXY_URI, soup_uri_new(proxy_url), NULL);
@@ -961,6 +972,31 @@ settings_init () {
}
if(useragent){
+ char* newagent = malloc(1024);
+
+ strcpy(newagent, str_replace("%webkit-major%", itos(WEBKIT_MAJOR_VERSION), useragent));
+ strcpy(newagent, str_replace("%webkit-minor%", itos(WEBKIT_MINOR_VERSION), newagent));
+ strcpy(newagent, str_replace("%webkit-micro%", itos(WEBKIT_MICRO_VERSION), newagent));
+
+ if (uname (&unameinfo) == -1) {
+ printf("Error getting uname info. Not replacing system-related user agent variables.\n");
+ } else {
+ strcpy(newagent, str_replace("%sysname%", unameinfo.sysname, newagent));
+ strcpy(newagent, str_replace("%nodename%", unameinfo.nodename, newagent));
+ strcpy(newagent, str_replace("%kernrel%", unameinfo.release, newagent));
+ strcpy(newagent, str_replace("%kernver%", unameinfo.version, newagent));
+ strcpy(newagent, str_replace("%arch-system%", unameinfo.machine, newagent));
+
+ #ifdef _GNU_SOURCE
+ strcpy(newagent, str_replace("%domainname%", unameinfo.domainname, newagent));
+ #endif
+ }
+
+ strcpy(newagent, str_replace("%arch-uzbl%", ARCH, newagent));
+ strcpy(newagent, str_replace("%commit%", COMMIT, newagent));
+
+ useragent = malloc(1024);
+ strcpy(useragent, newagent);
g_object_set(G_OBJECT(soup_session), SOUP_SESSION_USER_AGENT, useragent, NULL);
}
diff --git a/uzbl.h b/uzbl.h
index f81e3f6..529fae5 100644
--- a/uzbl.h
+++ b/uzbl.h
@@ -122,4 +122,7 @@ search_text (WebKitWebView *page, const char *param);
static void
run_js (WebKitWebView * web_view, const gchar *param);
+static char *
+str_replace (const char* search, const char* replace, const char* string);
+
/* vi: set et ts=4: */