aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-05-04 19:32:39 +0200
committerGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-05-04 19:32:39 +0200
commit542882181c84cf9467efdd75eac2d41774f004a9 (patch)
treebb7a119d4f4ca5f1dfdc6860706b98c25ffd8cbf
parentf7fceec2f70e598e9311593aa7272198bca8863a (diff)
parent5dd608fafd034183f84403e8c429dc08359dbd18 (diff)
Merge branch 'bar/experimental' into experimental
-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.c56
-rw-r--r--uzbl.h3
6 files changed, 57 insertions, 15 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..9ef069c 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%]) (Commit %commit%)
max_conns =
max_conns_per_host =
diff --git a/examples/configs/sampleconfig-dev b/examples/configs/sampleconfig-dev
index 25f66be..580234e 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%]) (Commit %commit%)
max_conns =
max_conns_per_host =
diff --git a/uzbl.c b/uzbl.c
index 50ce805..37e2b44 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>
@@ -76,7 +77,6 @@ static gchar searchtx[500] = "\0";
static gchar* uri = NULL;
static gchar* config_file = NULL;
static gchar config_file_path[500];
-static gboolean verbose = FALSE;
static gchar* instance_name = NULL;
/* settings from config: group behaviour */
@@ -92,6 +92,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;
@@ -101,10 +104,9 @@ static GHashTable* commands;
/* commandline arguments (set initial values for the state variables) */
static GOptionEntry entries[] =
{
- { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", NULL },
- { "name", 'n', 0, G_OPTION_ARG_STRING, &instance_name, "Name of the current instance", NULL },
- { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
- { "config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file", NULL },
+ { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", "URI" },
+ { "name", 'n', 0, G_OPTION_ARG_STRING, &instance_name, "Name of the current instance", "NAME" },
+ { "config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file", "FILE" },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
@@ -132,6 +134,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 +881,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 +949,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 +970,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: */