From fbf3bbced3165bc67364f20d4ff6c1f994beac3b Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Sun, 3 May 2009 22:33:58 +0100 Subject: Added str_replace function. To be used for adding variables to user agent. --- uzbl.c | 22 ++++++++++++++++++++++ uzbl.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/uzbl.c b/uzbl.c index edd0b38..af414ed 100644 --- a/uzbl.c +++ b/uzbl.c @@ -132,6 +132,28 @@ itos(int val) { return g_strdup(tmp); } +static char * +str_replace (const char* search, const char* replace, const char* string) { + char newstring[512]; + char tempstring[512]; + unsigned int i = 0; + + memset (newstring, 0, sizeof (newstring)); + + for (i = 0; i < strlen (string) - strlen (search); i ++) { + memset (tempstring, 0, sizeof (tempstring)); + strncpy (tempstring, string + i, sizeof (search) + 1); + + if (strcmp (tempstring, search) == 0) { + strncpy (newstring, string, i); + strcat (newstring, replace); + strcat (newstring, string + i + sizeof (search) + 1); + } + } + + return (char *)newstring; +} + /* --- CALLBACKS --- */ static gboolean 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: */ -- cgit v1.2.3 From b6a39ed3eba72d2c3fea3ae9ed28ff7510a05e1f Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Sun, 3 May 2009 23:13:34 +0100 Subject: Added hacky variable suppot (currently "%webkit-major%", "%webkit-minor%" and "%webkit-micro%", alas no "%kernver%" or "%commit%" yet) to user agent. I'm tired and it's late. I've probably done this in a very poor way which would be infinitely better. Now I am going to go and sleep. When I wake up and come on IRC, tell me how bad the code is :P --- examples/configs/sampleconfig | 2 +- examples/configs/sampleconfig-dev | 2 +- uzbl.c | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/configs/sampleconfig b/examples/configs/sampleconfig index e4fd3a6..4fcdead 100644 --- a/examples/configs/sampleconfig +++ b/examples/configs/sampleconfig @@ -56,6 +56,6 @@ 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%) max_conns = max_conns_per_host = diff --git a/examples/configs/sampleconfig-dev b/examples/configs/sampleconfig-dev index 7ce220f..9c4664e 100644 --- a/examples/configs/sampleconfig-dev +++ b/examples/configs/sampleconfig-dev @@ -57,7 +57,7 @@ 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%) max_conns = max_conns_per_host = diff --git a/uzbl.c b/uzbl.c index af414ed..8e25903 100644 --- a/uzbl.c +++ b/uzbl.c @@ -134,20 +134,20 @@ itos(int val) { static char * str_replace (const char* search, const char* replace, const char* string) { - char newstring[512]; - char tempstring[512]; + char newstring[1024]; + char tempstring[1024]; unsigned int i = 0; memset (newstring, 0, sizeof (newstring)); for (i = 0; i < strlen (string) - strlen (search); i ++) { memset (tempstring, 0, sizeof (tempstring)); - strncpy (tempstring, string + i, sizeof (search) + 1); + strncpy (tempstring, string + i, strlen (search)); if (strcmp (tempstring, search) == 0) { strncpy (newstring, string, i); strcat (newstring, replace); - strcat (newstring, string + i + sizeof (search) + 1); + strcat (newstring, string + i + strlen (search)); } } @@ -981,6 +981,14 @@ 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)); + + useragent = malloc(1024); + strcpy(useragent, newagent); g_object_set(G_OBJECT(soup_session), SOUP_SESSION_USER_AGENT, useragent, NULL); } -- cgit v1.2.3 From 390f12bc918c8e5b4054a0475493197088848660 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Mon, 4 May 2009 09:00:26 +0100 Subject: Fixed GLib errors / possible segfault in networking options loading. --- uzbl.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/uzbl.c b/uzbl.c index 8e25903..dce8bba 100644 --- a/uzbl.c +++ b/uzbl.c @@ -894,7 +894,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); @@ -962,11 +962,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); -- cgit v1.2.3 From e9cfdd0f9cef05fe25201d493efa763ee13447d3 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Mon, 4 May 2009 09:04:09 +0100 Subject: Replaced str_replace to be far, far nicer. --- uzbl.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/uzbl.c b/uzbl.c index dce8bba..3037484 100644 --- a/uzbl.c +++ b/uzbl.c @@ -134,24 +134,7 @@ itos(int val) { static char * str_replace (const char* search, const char* replace, const char* string) { - char newstring[1024]; - char tempstring[1024]; - unsigned int i = 0; - - memset (newstring, 0, sizeof (newstring)); - - for (i = 0; i < strlen (string) - strlen (search); i ++) { - memset (tempstring, 0, sizeof (tempstring)); - strncpy (tempstring, string + i, strlen (search)); - - if (strcmp (tempstring, search) == 0) { - strncpy (newstring, string, i); - strcat (newstring, replace); - strcat (newstring, string + i + strlen (search)); - } - } - - return (char *)newstring; + return g_strjoinv (replace, g_strsplit(string, search, -1)); } /* --- CALLBACKS --- */ -- cgit v1.2.3 From 62d317e0d10e849c4ec358ce501ad4909b579cbb Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Mon, 4 May 2009 09:38:20 +0100 Subject: Added KERNVER, ACH, and COMMIT variables to user agent. --- Makefile | 2 +- uzbl.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 52d96b6..906436f 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 -DKERNVER="\"$(shell uname -r)\"" -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/uzbl.c b/uzbl.c index 3037484..ae7c755 100644 --- a/uzbl.c +++ b/uzbl.c @@ -971,6 +971,9 @@ settings_init () { 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)); + strcpy(newagent, str_replace("%kernver%", KERNVER, newagent)); + strcpy(newagent, str_replace("%arch%", ARCH, newagent)); + strcpy(newagent, str_replace("%commit%", COMMIT, newagent)); useragent = malloc(1024); strcpy(useragent, newagent); -- cgit v1.2.3 From d3dc638149202de26529abd97b39c1a287f72a54 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Mon, 4 May 2009 10:39:06 +0100 Subject: Now supports all values uname() can grab in the user agent. See sampleconfig for all variables. --- CHECKLIST | 3 ++- Makefile | 2 +- examples/configs/sampleconfig | 2 ++ examples/configs/sampleconfig-dev | 2 ++ uzbl.c | 22 ++++++++++++++++++++-- 5 files changed, 27 insertions(+), 4 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 906436f..622a79a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CPPFLAGS=$(shell pkg-config --cflags gtk+-2.0 webkit-1.0) -Wall -W -DKERNVER="\"$(shell uname -r)\"" -DARCH="\"$(shell uname -m)\"" -DCOMMIT="\"$(shell git log | head -n1 | sed "s/.* //")\"" +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 4fcdead..ef3f0a8 100644 --- a/examples/configs/sampleconfig +++ b/examples/configs/sampleconfig @@ -57,5 +57,7 @@ proxy_server = #values 0-3 http_debug = 0 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 9c4664e..443dbb0 100644 --- a/examples/configs/sampleconfig-dev +++ b/examples/configs/sampleconfig-dev @@ -58,6 +58,8 @@ S = script alert("hi"); #values 0-3 http_debug = 0 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 ae7c755..39417cf 100644 --- a/uzbl.c +++ b/uzbl.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -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; @@ -971,8 +975,22 @@ settings_init () { 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)); - strcpy(newagent, str_replace("%kernver%", KERNVER, newagent)); - strcpy(newagent, str_replace("%arch%", ARCH, 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); -- cgit v1.2.3 From f6c8d8a2a226f3d256f8b2d53ed84897862208a6 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Mon, 4 May 2009 10:45:56 +0100 Subject: Added %commit% variable to sample config files, as I forgot to do it just now :p --- examples/configs/sampleconfig | 2 +- examples/configs/sampleconfig-dev | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/configs/sampleconfig b/examples/configs/sampleconfig index 5c8226d..9ef069c 100644 --- a/examples/configs/sampleconfig +++ b/examples/configs/sampleconfig @@ -58,6 +58,6 @@ proxy_server = http_debug = 0 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%]) +#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 8749fe8..580234e 100644 --- a/examples/configs/sampleconfig-dev +++ b/examples/configs/sampleconfig-dev @@ -59,7 +59,7 @@ S = script alert("hi"); http_debug = 0 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%]) +#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 = -- cgit v1.2.3 From 5dd608fafd034183f84403e8c429dc08359dbd18 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Mon, 4 May 2009 12:02:44 +0100 Subject: Corrected options, removed verbose option as it's not used anywhere. --- uzbl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/uzbl.c b/uzbl.c index 57c2de4..37e2b44 100644 --- a/uzbl.c +++ b/uzbl.c @@ -77,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 */ @@ -105,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 } }; -- cgit v1.2.3