From e211c19ca4729ad498a58ca6bbdf6b5ce9ef22ea Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 29 Nov 2010 17:49:01 -0700 Subject: use the new $UZBL_* env vars exclusively --- examples/config/config | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 855f7c2..144eb00 100644 --- a/examples/config/config +++ b/examples/config/config @@ -181,7 +181,7 @@ set ebind = @mode_bind global,-insert # --- Mouse bindings --------------------------------------------------------- # Middle click open in new window -@bind = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > $4; fi' \@SELECTED_URI +@bind = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' \@SELECTED_URI # --- Keyboard bindings ------------------------------------------------------ @@ -245,14 +245,14 @@ set ebind = @mode_bind global,-insert # Exit binding @cbind ZZ = exit # Dump config to stdout -@cbind !dump = sh "echo dump_config > $4" +@cbind !dump = sh 'echo dump_config > "$UZBL_FIFO"' # Reload all variables in the config -@cbind !reload = sh "sed '/^# === Post-load misc commands/,$d' $1 | grep '^set ' > $4" +@cbind !reload = sh "sed '/^# === Post-load misc commands/,$d' \"$UZBL_CONFIG\" | grep '^set ' > \"$UZBL_FIFO\"" # Use socat to directly inject commands into uzbl-core and view events # raised by uzbl-core: -@cbind t = sh 'xterm -e "socat unix-connect:$5 -"' -#@cbind t = sh 'urxvt -e socat unix-connect:$5 -' +@cbind t = sh "xterm -e 'socat unix-connect:\"$UZBL_SOCKET\" -'" +#@cbind t = sh "urxvt -e 'socat unix-connect:\"$UZBL_SOCKET\" -'" # Uri opening prompts @cbind o_ = uri %s @@ -267,24 +267,24 @@ set ebind = @mode_bind global,-insert @cbind gh = uri http://www.uzbl.org # Yanking & pasting binds -@cbind yu = sh 'echo -n $6 | xclip' +@cbind yu = sh 'echo -n "$UZBL_URL" | xclip' @cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI -@cbind yy = sh 'echo -n $7 | xclip' +@cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip' @cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI # Clone current window -@cbind c = sh 'uzbl-browser -u $6' +@cbind c = sh 'uzbl-browser -u "$UZBL_URL"' # Go the page from primary selection -@cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +@cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Go to the page in clipboard -@cbind P = sh 'echo "uri `xclip -selection clipboard -o | sed s/\\\@/%40/g`" > $4' +@cbind P = sh 'echo "uri `xclip -selection clipboard -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Start a new uzbl instance from the page in primary selection -@cbind 'p = sh 'exec uzbl-browser --uri $(xclip -o)' +@cbind 'p = sh 'exec uzbl-browser --uri "$(xclip -o)"' # paste primary selection into keycmd at the cursor position -@bind = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > $4' +@bind = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Bookmark inserting binds -@cbind b_ = sh 'echo `printf "$6 %s"` >> $XDG_DATA_HOME/uzbl/bookmarks' +@cbind b_ = sh 'echo `printf "$UZBL_URL %s"` >> "$XDG_DATA_HOME"/uzbl/bookmarks' # Or use a script to insert a bookmark. @cbind B = spawn @scripts_dir/insert_bookmark.sh @@ -319,12 +319,12 @@ set formfiller = spawn @scripts_dir/formfiller.sh @cbind gN = event NEW_TAB_NEXT @cbind go_ = event NEW_TAB %s @cbind gO_ = event NEW_TAB_NEXT %s -@cbind gy = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' -@cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +@cbind gy = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' +@cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Clone current tab -@cbind gd = sh 'echo "event NEW_TAB $6" > $4' -@cbind gD = sh 'echo "event NEW_TAB_NEXT $6" > $4' +@cbind gd = sh 'echo "event NEW_TAB $UZBL_URL" > "$UZBL_FIFO"' +@cbind gD = sh 'echo "event NEW_TAB_NEXT $UZBL_URL" > "$UZBL_FIFO"' # Closing / resting @cbind gC = exit -- cgit v1.2.3 From 0faed45023a73e446f606871b2480a317e4d8d2d Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 29 Nov 2010 17:55:07 -0700 Subject: $UZBL_URL -> $UZBL_URI (for consistency with the rest of our interface) --- examples/config/config | 10 +++++----- examples/data/scripts/formfiller.sh | 2 +- examples/data/scripts/history.sh | 2 +- examples/data/scripts/insert_bookmark.sh | 4 ++-- examples/data/scripts/session.sh | 2 +- examples/data/scripts/userscript.sh | 6 +++--- examples/data/scripts/userscripts.sh | 2 +- src/callbacks.c | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 144eb00..22414ad 100644 --- a/examples/config/config +++ b/examples/config/config @@ -267,13 +267,13 @@ set ebind = @mode_bind global,-insert @cbind gh = uri http://www.uzbl.org # Yanking & pasting binds -@cbind yu = sh 'echo -n "$UZBL_URL" | xclip' +@cbind yu = sh 'echo -n "$UZBL_URI" | xclip' @cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI @cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip' @cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI # Clone current window -@cbind c = sh 'uzbl-browser -u "$UZBL_URL"' +@cbind c = sh 'uzbl-browser -u "$UZBL_URI"' # Go the page from primary selection @cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Go to the page in clipboard @@ -284,7 +284,7 @@ set ebind = @mode_bind global,-insert @bind = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Bookmark inserting binds -@cbind b_ = sh 'echo `printf "$UZBL_URL %s"` >> "$XDG_DATA_HOME"/uzbl/bookmarks' +@cbind b_ = sh 'echo `printf "$UZBL_URI %s"` >> "$XDG_DATA_HOME"/uzbl/bookmarks' # Or use a script to insert a bookmark. @cbind B = spawn @scripts_dir/insert_bookmark.sh @@ -323,8 +323,8 @@ set formfiller = spawn @scripts_dir/formfiller.sh @cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Clone current tab -@cbind gd = sh 'echo "event NEW_TAB $UZBL_URL" > "$UZBL_FIFO"' -@cbind gD = sh 'echo "event NEW_TAB_NEXT $UZBL_URL" > "$UZBL_FIFO"' +@cbind gd = sh 'echo "event NEW_TAB $UZBL_URI" > "$UZBL_FIFO"' +@cbind gD = sh 'echo "event NEW_TAB_NEXT $UZBL_URI" > "$UZBL_FIFO"' # Closing / resting @cbind gC = exit diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 0f04f8a..c6822e6 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -55,7 +55,7 @@ MODELINE="> vim:ft=formfiller" action=$1 -domain=$(echo $UZBL_URL | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') +domain=$(echo $UZBL_URI | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') if [ "$action" != 'edit' -a "$action" != 'new' -a "$action" != 'load' -a "$action" != 'add' -a "$action" != 'once' ]; then action="new" diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh index 167aed7..266d65d 100755 --- a/examples/data/scripts/history.sh +++ b/examples/data/scripts/history.sh @@ -4,4 +4,4 @@ [ -w "$UZBL_HISTORY_FILE" ] || [ ! -a "$UZBL_HISTORY_FILE" ] || exit 1 -echo $(date +'%Y-%m-%d %H:%M:%S')" $UZBL_URL $UZBL_TITLE" >> $UZBL_HISTORY_FILE +echo $(date +'%Y-%m-%d %H:%M:%S')" $UZBL_URI $UZBL_TITLE" >> $UZBL_HISTORY_FILE diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 294d314..f67e67a 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -7,9 +7,9 @@ which zenity >/dev/null 2>&1 || exit 2 -tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URL:") +tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URI:") exitstatus=$? [ $exitstatus -eq 0 ] || exit $exitstatus # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags -echo "$UZBL_URL $tags" >> "$UZBL_BOOKMARKS_FILE" +echo "$UZBL_URI $tags" >> "$UZBL_BOOKMARKS_FILE" diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index c69b7e3..c5c4172 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -54,7 +54,7 @@ case $act in echo "session manager: endinstance must be called from uzbl" exit 1 fi - [ "$UZBL_URL" != "(null)" ] && echo "$UZBL_URL" >> "$UZBL_SESSION_FILE" + [ "$UZBL_URI" != "(null)" ] && echo "$UZBL_URI" >> "$UZBL_SESSION_FILE" echo exit > "$UZBL_FIFO" ;; diff --git a/examples/data/scripts/userscript.sh b/examples/data/scripts/userscript.sh index 1e76fd2..fd95fdc 100755 --- a/examples/data/scripts/userscript.sh +++ b/examples/data/scripts/userscript.sh @@ -3,7 +3,7 @@ if [ $# = "3" ] then UZBL_FIFO=$1 - UZBL_URL=$2 + UZBL_URI=$2 SCRIPT=$3 else SCRIPT=$8 @@ -16,7 +16,7 @@ SHOULD_RUN=false # Assume this script will not be included for INCLUDE in `echo "$META" | grep "^\s*\/\/\s*@include"`; do # Munge into grep pattern INCLUDE="`echo "$INCLUDE" | sed -e 's/^\s*\/\/\s*@include\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`" - if echo "$UZBL_URL" | grep -x "$INCLUDE"; then + if echo "$UZBL_URI" | grep -x "$INCLUDE"; then SHOULD_RUN=true break fi @@ -26,7 +26,7 @@ done for EXCLUDE in `echo "$META" | grep "^\s*\/\/\s*@exclude"`; do # Munge into grep pattern EXCLUDE="`echo "$EXCLUDE" | sed -e 's/^\s*\/\/\s*@exclude\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`" - if echo "$UZBL_URL" | grep -x "$EXCLUDE"; then + if echo "$UZBL_URI" | grep -x "$EXCLUDE"; then SHOULD_RUN=false break fi diff --git a/examples/data/scripts/userscripts.sh b/examples/data/scripts/userscripts.sh index 2c66ed8..4f76c90 100755 --- a/examples/data/scripts/userscripts.sh +++ b/examples/data/scripts/userscripts.sh @@ -4,5 +4,5 @@ scripts_dir="$XDG_DATA_HOME/uzbl/userscripts" for SCRIPT in $(grep -rlx "\s*//\s*==UserScript==\s*" "$scripts_dir") do - $XDG_DATA_HOME/uzbl/scripts/userscript.sh "$UZBL_FIFO" "$UZBL_URL" "$SCRIPT" + $XDG_DATA_HOME/uzbl/scripts/userscript.sh "$UZBL_FIFO" "$UZBL_URI" "$SCRIPT" done diff --git a/src/callbacks.c b/src/callbacks.c index 2637810..4f0e4ac 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -437,7 +437,7 @@ load_status_change_cb (WebKitWebView* web_view, GParamSpec param_spec) { g_free (uzbl.state.uri); GString* newuri = g_string_new (webkit_web_frame_get_uri (frame)); uzbl.state.uri = g_string_free (newuri, FALSE); - g_setenv("UZBL_URL", uzbl.state.uri, TRUE); + g_setenv("UZBL_URI", uzbl.state.uri, TRUE); send_event(LOAD_COMMIT, webkit_web_frame_get_uri (frame), NULL); break; -- cgit v1.2.3 From e1bff5432860622327dc8d81b8f9ef374588c5cb Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 30 Nov 2010 20:20:02 -0700 Subject: remove parseenv(). it's not documented, it doesn't do anything that @(echo $X)@ can't, and it's not very efficient (it iterates through the entire environment every time an event is sent) --- examples/config/config | 10 ++++++---- src/events.c | 13 ++----------- src/uzbl-core.c | 42 ++++-------------------------------------- src/uzbl-core.h | 3 --- 4 files changed, 12 insertions(+), 56 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 22414ad..e282bb9 100644 --- a/examples/config/config +++ b/examples/config/config @@ -3,8 +3,10 @@ # === Core settings ========================================================== -# Install location prefix. -set prefix = /usr/local +# common directory locations +set prefix = @(echo $PREFIX)@ +set data_home = @(echo $XDG_DATA_HOME)@ +set cache_home = @(echo $XDG_CACHE_HOME)@ # Interface paths. set fifo_dir = /tmp @@ -34,13 +36,13 @@ set set_mode = set mode = set set_status = set status_message = # Spawn path shortcuts. In spawn the first dir+path match is used in "dir1:dir2:dir3:executable" -set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scripts +set scripts_dir = @data_home/uzbl:@prefix/share/uzbl/examples/data:scripts # === Hardcoded handlers ===================================================== # These handlers can't be moved to the new event system yet as we don't # support events that can wait for a response from a script. -set cookie_handler = talk_to_socket $XDG_CACHE_HOME/uzbl/cookie_daemon_socket +set cookie_handler = talk_to_socket @cache_home/uzbl/cookie_daemon_socket set scheme_handler = sync_spawn @scripts_dir/scheme.py set authentication_handler = sync_spawn @scripts_dir/auth.py diff --git a/src/events.c b/src/events.c index 20e3675..3b42b3f 100644 --- a/src/events.c +++ b/src/events.c @@ -136,24 +136,16 @@ send_event_stdout(GString *msg) { void send_event(int type, const gchar *details, const gchar *custom_event) { GString *event_message = g_string_new(""); - gchar *buf, *p_val = NULL; - - /* expand shell vars */ - if(details) { - buf = g_strdup(details); - p_val = parseenv(buf ? g_strchug(buf) : " "); - g_free(buf); - } /* check for custom events */ if(custom_event) { g_string_printf(event_message, "EVENT [%s] %s %s\n", - uzbl.state.instance_name, custom_event, p_val); + uzbl.state.instance_name, custom_event, details); } /* check wether we support the internal event */ else if(type < LAST_EVENT) { g_string_printf(event_message, "EVENT [%s] %s %s\n", - uzbl.state.instance_name, event_table[type], p_val); + uzbl.state.instance_name, event_table[type], details); } if(event_message->str) { @@ -163,7 +155,6 @@ send_event(int type, const gchar *details, const gchar *custom_event) { g_string_free(event_message, TRUE); } - g_free(p_val); } /* Transform gdk key events to our own events */ diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 3a04027..5adc4e1 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -414,36 +414,6 @@ find_existing_file(gchar* path_list) { return NULL; } - -/* Returns a new string with environment $variables expanded */ -gchar* -parseenv (gchar* string) { - extern char** environ; - gchar* tmpstr = NULL, * out; - int i = 0; - - if(!string) - return NULL; - - out = g_strdup(string); - while (environ[i] != NULL) { - gchar** env = g_strsplit (environ[i], "=", 2); - gchar* envname = g_strconcat ("$", env[0], NULL); - - if (g_strrstr (string, envname) != NULL) { - tmpstr = out; - out = str_replace(envname, env[1], out); - g_free (tmpstr); - } - - g_free (envname); - g_strfreev (env); // somebody said this breaks uzbl - i++; - } - - return out; -} - void clean_up(void) { if(uzbl.info.pid_str) { @@ -695,9 +665,8 @@ set_var(WebKitWebView *page, GArray *argv, GString *result) { gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2); if (split[0] != NULL) { - gchar *value = parseenv(split[1] ? g_strchug(split[1]) : " "); + gchar *value = split[1] ? g_strchug(split[1]) : " "; set_var_value(g_strstrip(split[0]), value); - g_free(value); } g_strfreev(split); } @@ -927,14 +896,12 @@ void include(WebKitWebView *page, GArray *argv, GString *result) { (void) page; (void) result; - gchar *pe = NULL, - *path = NULL; + gchar *path = argv_idx(argv, 0); - if(!argv_idx(argv, 0)) + if(!path) return; - pe = parseenv(argv_idx(argv, 0)); - if((path = find_existing_file(pe))) { + if((path = find_existing_file(path))) { if(!for_each_line_in_file(path, parse_cmd_line_cb, NULL)) { gchar *tmp = g_strdup_printf("File %s can not be read.", path); send_event(COMMAND_ERROR, tmp, NULL); @@ -944,7 +911,6 @@ include(WebKitWebView *page, GArray *argv, GString *result) { send_event(FILE_INCLUDED, path, NULL); g_free(path); } - g_free(pe); } void diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b5a502e..6c926c6 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -228,9 +228,6 @@ itos(int val); gchar* strfree(gchar *str); -gchar* -parseenv (gchar* string); - void clean_up(void); -- cgit v1.2.3 From 4fbba2d523ba65b2dad15cf264eb168157cf0f15 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 29 Nov 2010 20:11:54 -0700 Subject: remove the positional arguments entirely (breaks backward compatibility) --- examples/config/config | 8 ++-- examples/data/scripts/auth.py | 2 +- examples/data/scripts/scheme.py | 2 +- src/uzbl-core.c | 90 +++++++++++++++-------------------------- src/uzbl-core.h | 4 +- 5 files changed, 41 insertions(+), 65 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 22414ad..3c1a2fe 100644 --- a/examples/config/config +++ b/examples/config/config @@ -47,7 +47,7 @@ set authentication_handler = sync_spawn @scripts_dir/auth.py # === Dynamic event handlers ================================================= # Open link in new window -@on_event NEW_WINDOW sh 'uzbl-browser ${8:+-u "$8"}' %r +@on_event NEW_WINDOW sh 'uzbl-browser ${1:+-u "$1"}' %r # Open in current window #@on_event NEW_WINDOW uri %s # Open in new tab @@ -181,7 +181,7 @@ set ebind = @mode_bind global,-insert # --- Mouse bindings --------------------------------------------------------- # Middle click open in new window -@bind = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' \@SELECTED_URI +@bind = sh 'if [ "$1" ]; then uzbl-browser -u "$1"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' \@SELECTED_URI # --- Keyboard bindings ------------------------------------------------------ @@ -268,9 +268,9 @@ set ebind = @mode_bind global,-insert # Yanking & pasting binds @cbind yu = sh 'echo -n "$UZBL_URI" | xclip' -@cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI +@cbind yU = sh 'echo -n "$1" | xclip' \@SELECTED_URI @cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip' -@cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI +@cbind yY = sh 'echo -n "$1" | xclip' \@SELECTED_URI # Clone current window @cbind c = sh 'uzbl-browser -u "$UZBL_URI"' diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py index 9c1b4fc..592a2c6 100755 --- a/examples/data/scripts/auth.py +++ b/examples/data/scripts/auth.py @@ -46,7 +46,7 @@ def getText(authInfo, authHost, authRealm): return rv, output if __name__ == '__main__': - rv, output = getText(sys.argv[8], sys.argv[9], sys.argv[10]) + rv, output = getText(sys.argv[1], sys.argv[2], sys.argv[3]) if (rv == gtk.RESPONSE_OK): print output; else: diff --git a/examples/data/scripts/scheme.py b/examples/data/scripts/scheme.py index 0916466..4b0b7ca 100755 --- a/examples/data/scripts/scheme.py +++ b/examples/data/scripts/scheme.py @@ -13,7 +13,7 @@ def detach_open(cmd): print 'USED' if __name__ == '__main__': - uri = sys.argv[8] + uri = sys.argv[1] u = urlparse.urlparse(uri) if u.scheme == 'mailto': detach_open(['xterm', '-e', 'mail', u.path]) diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 3a04027..dcdd4c7 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -1209,30 +1209,19 @@ sharg_append(GArray *a, const gchar *str) { g_array_append_val(a, s); } -// make sure that the args string you pass can properly be interpreted (eg properly escaped against whitespace, quotes etc) +/* make sure that the args string you pass can properly be interpreted (eg + * properly escaped against whitespace, quotes etc) */ gboolean -run_command (const gchar *command, const guint npre, const gchar **args, - const gboolean sync, char **output_stdout) { - //command [args] +run_command (const gchar *command, const gchar **args, const gboolean sync, + char **output_stdout) { GError *err = NULL; GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); - gchar *pid = itos(getpid()); - gchar *xwin = itos(uzbl.xwin); guint i; sharg_append(a, command); - for (i = 0; i < npre; i++) /* add n args before the default vars */ - sharg_append(a, args[i]); - sharg_append(a, uzbl.state.config_file); - sharg_append(a, pid); - sharg_append(a, xwin); - sharg_append(a, uzbl.comm.fifo_path); - sharg_append(a, uzbl.comm.socket_path); - sharg_append(a, uzbl.state.uri); - sharg_append(a, uzbl.gui.main_title); - - for (i = npre; i < g_strv_length((gchar**)args); i++) + + for (i = 0; i < g_strv_length((gchar**)args); i++) sharg_append(a, args[i]); gboolean result; @@ -1263,8 +1252,6 @@ run_command (const gchar *command, const guint npre, const gchar **args, g_printerr("error on run_command: %s\n", err->message); g_error_free (err); } - g_free (pid); - g_free (xwin); g_array_free (a, TRUE); return result; } @@ -1307,75 +1294,64 @@ split_quoted(const gchar* src, const gboolean unquote) { } void -spawn(WebKitWebView *web_view, GArray *argv, GString *result) { - (void)web_view; (void)result; +_spawn(GArray *argv, char **output_stdout) { gchar *path = NULL; + gchar *arg_car = argv_idx(argv, 0); + const gchar **arg_cdr = &g_array_index(argv, const gchar *, 1); - //TODO: allow more control over argument order so that users can have some arguments before the default ones from run_command, and some after - if (argv_idx(argv, 0) && - ((path = find_existing_file(argv_idx(argv, 0)))) ) { - run_command(path, 0, - ((const gchar **) (argv->data + sizeof(gchar*))), - FALSE, NULL); + if (arg_car && (path = find_existing_file(arg_car))) { + run_command(path, arg_cdr, (output_stdout != NULL), output_stdout); g_free(path); } } void -spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - gchar *path = NULL; - if (argv_idx(argv, 0) && - ((path = find_existing_file(argv_idx(argv, 0)))) ) { - run_command(path, 0, - ((const gchar **) (argv->data + sizeof(gchar*))), - TRUE, &uzbl.comm.sync_stdout); - g_free(path); - } + _spawn(argv, NULL); } void -spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; + + _spawn(argv, &uzbl.comm.sync_stdout); +} + +void +_spawn_sh(GArray *argv, char **output_stdout) { if (!uzbl.behave.shell_cmd) { g_printerr ("spawn_sh: shell_cmd is not set!\n"); return; } - guint i; - gchar *spacer = g_strdup(""); - g_array_insert_val(argv, 1, spacer); + gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE); + gchar *cmdname = g_strdup(cmd[0]); + g_array_insert_val(argv, 1, cmdname); for (i = 1; i < g_strv_length(cmd); i++) g_array_prepend_val(argv, cmd[i]); - if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, FALSE, NULL); - g_free (spacer); + if (cmd) run_command(cmd[0], (const gchar **) argv->data, + (output_stdout != NULL), output_stdout); + g_free (cmdname); g_strfreev (cmd); } void -spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - if (!uzbl.behave.shell_cmd) { - g_printerr ("spawn_sh_sync: shell_cmd is not set!\n"); - return; - } - guint i; - gchar *spacer = g_strdup(""); - g_array_insert_val(argv, 1, spacer); - gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE); + _spawn_sh(argv, NULL); +} - for (i = 1; i < g_strv_length(cmd); i++) - g_array_prepend_val(argv, cmd[i]); +void +spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) { + (void)web_view; (void)result; - if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, - TRUE, &uzbl.comm.sync_stdout); - g_free (spacer); - g_strfreev (cmd); + _spawn_sh(argv, &uzbl.comm.sync_stdout); } void diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b5a502e..412d9fc 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -262,8 +262,8 @@ void close_uzbl (WebKitWebView *page, GArray *argv, GString *result); gboolean -run_command(const gchar *command, const guint npre, - const gchar **args, const gboolean sync, char **output_stdout); +run_command(const gchar *command, const gchar **args, const gboolean sync, + char **output_stdout); void spawn(WebKitWebView *web_view, GArray *argv, GString *result); -- cgit v1.2.3 From 59adc0787f7b77922c671964e471d0fd2dd7fc90 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 13:47:09 -0700 Subject: let webkit handle downloads (breaks backward compatibility) --- README | 9 ++- examples/config/config | 1 + examples/data/scripts/download.sh | 34 +++++------ src/callbacks.c | 125 ++++++++++++++++++++++++++++++++++++-- src/callbacks.h | 5 +- src/events.c | 7 ++- src/events.h | 3 +- src/uzbl-core.c | 1 + src/uzbl-core.h | 1 + 9 files changed, 154 insertions(+), 32 deletions(-) (limited to 'examples/config') diff --git a/README b/README index 34556f2..6dddb35 100644 --- a/README +++ b/README @@ -668,8 +668,13 @@ Events have this format: * `EVENT [uzbl_instance_name] TITLE_CHANGED title_name`: When the title of the page (and hence maybe, the window title) changed. `title_name` is the new title. -* `EVENT [uzbl_instance_name] DOWNLOAD_REQUEST download_uri`: When content needs - to be downloaded, `download_uri` is the URI to get. +* `EVENT [uzbl_instance_name] DOWNLOAD_STARTED destination_path`: A download + has been started, the file will be saved to `destination_path`. +* `EVENT [uzbl_instance_name] DOWNLOAD_PROGRESS destination_path progress`: + While a download is active this event notifies you of the progress. + `progress` is a decimal between 0 and 1. +* `EVENT [uzbl_instance_name] DOWNLOAD_COMPLETE destination_path`: The + download being saved to `destination_path` is now complete. * `EVENT [uzbl_instance_name] LINK_HOVER uri`: The mouse hovers over the link `uri`. * `EVENT [uzbl_instance_name] LINK_UNHOVER uri`: The mouse leaves the link diff --git a/examples/config/config b/examples/config/config index 855f7c2..64e1c94 100644 --- a/examples/config/config +++ b/examples/config/config @@ -43,6 +43,7 @@ set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scri set cookie_handler = talk_to_socket $XDG_CACHE_HOME/uzbl/cookie_daemon_socket set scheme_handler = sync_spawn @scripts_dir/scheme.py set authentication_handler = sync_spawn @scripts_dir/auth.py +set download_handler = sync_spawn @scripts_dir/download.sh # === Dynamic event handlers ================================================= diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 606aa62..c6d95f7 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -1,26 +1,26 @@ #!/bin/sh -# just an example of how you could handle your downloads -# try some pattern matching on the uri to determine what we should do +# +# uzbl's example configuration sets this script up as its download_handler. +# when uzbl starts a download it runs this script. +# if the script prints a file path to stdout, uzbl will save the download to +# that path. +# if nothing is printed to stdout, the download will be cancelled. . $UZBL_UTIL_DIR/uzbl-args.sh . $UZBL_UTIL_DIR/uzbl-dir.sh -# Some sites block the default wget --user-agent.. -GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR" +# the URL that is being downloaded +uri=$1 -url="$1" +# a filename suggested by the server or based on the URL +suggested_filename=${2:-$(echo "$uri" | sed 's/\W/-/g')} -http_proxy="$2" -export http_proxy +# the mimetype of the file being downloaded +content_type=$3 -if [ -z "$url" ]; then - echo "you must supply a url! ($url)" - exit 1 -fi +# the size of the downloaded file in bytes. this is not always accurate, since +# the server might not have sent a size with its response headers. +total_size=$4 -# only changes the dir for the $get sub process -if echo "$url" | grep -E '.*\.torrent' >/dev/null; then - ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") -else - ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") -fi +# just save the file to the default directory with the suggested name +echo $UZBL_DOWNLOAD_DIR/$suggested_filename diff --git a/src/callbacks.c b/src/callbacks.c index f596472..803428d 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -771,13 +771,128 @@ create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer us return NULL; } +void +download_progress_cb(WebKitDownload *download, GParamSpec *pspec, gpointer user_data) { + (void) pspec; (void) user_data; + + gdouble progress; + g_object_get(download, "progress", &progress, NULL); + + const gchar *dest_uri = webkit_download_get_destination_uri(download); + const gchar *dest_path = dest_uri + strlen("file://"); + + gchar *details = g_strdup_printf("%s %.2lf", dest_path, progress); + send_event(DOWNLOAD_PROGRESS, details, NULL); + g_free(details); +} + +void +download_status_cb(WebKitDownload *download, GParamSpec *pspec, gpointer user_data) { + (void) pspec; (void) user_data; + + WebKitDownloadStatus status; + g_object_get(download, "status", &status, NULL); + + switch(status) { + case WEBKIT_DOWNLOAD_STATUS_CREATED: + case WEBKIT_DOWNLOAD_STATUS_STARTED: + case WEBKIT_DOWNLOAD_STATUS_ERROR: + case WEBKIT_DOWNLOAD_STATUS_CANCELLED: + return; /* these are irrelevant */ + case WEBKIT_DOWNLOAD_STATUS_FINISHED: + { + const gchar *dest_uri = webkit_download_get_destination_uri(download); + const gchar *dest_path = dest_uri + strlen("file://"); + send_event(DOWNLOAD_COMPLETE, dest_path, NULL); + } + } +} + gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) { - (void) web_view; - (void) user_data; +download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_data) { + (void) web_view; (void) user_data; - send_event(DOWNLOAD_REQ, webkit_download_get_uri ((WebKitDownload*)download), NULL); - return (FALSE); + /* get the URI being downloaded */ + const gchar *uri = webkit_download_get_uri(download); + + if (uzbl.state.verbose) + printf("Download requested -> %s\n", uri); + + if (!uzbl.behave.download_handler) { + webkit_download_cancel(download); + return FALSE; /* reject downloads when there's no download handler */ + } + + /* get a reasonable suggestion for a filename */ + const gchar *suggested_filename; + g_object_get(download, "suggested-filename", &suggested_filename, NULL); + + /* get the mimetype of the download */ + const gchar *content_type; + WebKitNetworkResponse *r = webkit_download_get_network_response(download); + /* downloads can be initiated from the context menu, in that case there is + no network response yet and trying to get one would crash. */ + if(WEBKIT_IS_NETWORK_RESPONSE(r)) { + SoupMessage *m = webkit_network_response_get_message(r); + SoupMessageHeaders *h; + g_object_get(m, "response-headers", &h, NULL); + content_type = soup_message_headers_get_one(h, "Content-Type"); + } else + content_type = "application/octet-stream"; + + /* get the filesize of the download, as given by the server. + (this may be inaccurate, there's nothing we can do about that.) */ + unsigned int total_size = webkit_download_get_total_size(download); + + gchar *ev = g_strdup_printf("'%s' '%s' '%s' %d", uri, suggested_filename, + content_type, total_size); + run_handler(uzbl.behave.download_handler, ev); + g_free(ev); + + /* no response, cancel the download */ + if(!uzbl.comm.sync_stdout) { + webkit_download_cancel(download); + return FALSE; + } + + /* no response, cancel the download */ + if(uzbl.comm.sync_stdout[0] == 0) { + webkit_download_cancel(download); + uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); + return FALSE; + } + + /* we got a response, it's the path we should download the file to */ + gchar *destination_path = uzbl.comm.sync_stdout; + uzbl.comm.sync_stdout = NULL; + + /* presumably people don't need newlines in their filenames. */ + char *p = strchr(destination_path, '\n'); + if ( p != NULL ) *p = '\0'; + + /* set up progress callbacks */ + g_signal_connect(download, "notify::status", G_CALLBACK(download_status_cb), NULL); + g_signal_connect(download, "notify::progress", G_CALLBACK(download_progress_cb), NULL); + + /* convert relative path to absolute path */ + if(destination_path[0] != '/') { + gchar *rel_path = destination_path; + gchar *cwd = g_get_current_dir(); + destination_path = g_strconcat(cwd, "/", destination_path, NULL); + g_free(cwd); + g_free(rel_path); + } + + send_event(DOWNLOAD_STARTED, destination_path, NULL); + + /* convert absolute path to file:// URI */ + gchar *destination_uri = g_strconcat("file://", destination_path, NULL); + g_free(destination_path); + + webkit_download_set_destination_uri(download, destination_uri); + g_free(destination_uri); + + return TRUE; } gboolean diff --git a/src/callbacks.h b/src/callbacks.h index a4258f2..40fa80d 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -133,9 +133,6 @@ cmd_load_start(); WebKitWebSettings* view_settings(); -gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); - void toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result); @@ -197,7 +194,7 @@ request_starting_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitWebRes create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data); gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); +download_cb (WebKitWebView *web_view, WebKitDownload *download, gpointer user_data); void populate_popup_cb(WebKitWebView *v, GtkMenu *m, void *c); diff --git a/src/events.c b/src/events.c index 20e3675..55775a8 100644 --- a/src/events.c +++ b/src/events.c @@ -22,7 +22,6 @@ const char *event_table[LAST_EVENT] = { "REQUEST_STARTING" , "KEY_PRESS" , "KEY_RELEASE" , - "DOWNLOAD_REQUEST" , "COMMAND_EXECUTED" , "LINK_HOVER" , "TITLE_CHANGED" , @@ -45,10 +44,12 @@ const char *event_table[LAST_EVENT] = { "PLUG_CREATED" , "COMMAND_ERROR" , "BUILTINS" , - "PTR_MOVE" "PTR_MOVE" , "SCROLL_VERT" , - "SCROLL_HORIZ" + "SCROLL_HORIZ" , + "DOWNLOAD_STARTED" , + "DOWNLOAD_PROGRESS", + "DOWNLOAD_COMPLETE" }; void diff --git a/src/events.h b/src/events.h index bc7960d..4b04dd2 100644 --- a/src/events.h +++ b/src/events.h @@ -7,7 +7,7 @@ enum event_type { LOAD_START, LOAD_COMMIT, LOAD_FINISH, LOAD_ERROR, REQUEST_STARTING, - KEY_PRESS, KEY_RELEASE, DOWNLOAD_REQ, COMMAND_EXECUTED, + KEY_PRESS, KEY_RELEASE, COMMAND_EXECUTED, LINK_HOVER, TITLE_CHANGED, GEOMETRY_CHANGED, WEBINSPECTOR, NEW_WINDOW, SELECTION_CHANGED, VARIABLE_SET, FIFO_SET, SOCKET_SET, @@ -16,6 +16,7 @@ enum event_type { FOCUS_LOST, FOCUS_GAINED, FILE_INCLUDED, PLUG_CREATED, COMMAND_ERROR, BUILTINS, PTR_MOVE, SCROLL_VERT, SCROLL_HORIZ, + DOWNLOAD_STARTED, DOWNLOAD_PROGRESS, DOWNLOAD_COMPLETE, /* must be last entry */ LAST_EVENT diff --git a/src/uzbl-core.c b/src/uzbl-core.c index cb20fd7..c960936 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -93,6 +93,7 @@ const struct var_name_to_ptr_t { { "cookie_handler", PTR_V_STR(uzbl.behave.cookie_handler, 1, cmd_set_cookie_handler)}, { "authentication_handler", PTR_V_STR(uzbl.behave.authentication_handler, 1, set_authentication_handler)}, { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, NULL)}, + { "download_handler", PTR_V_STR(uzbl.behave.download_handler, 1, NULL)}, { "fifo_dir", PTR_V_STR(uzbl.behave.fifo_dir, 1, cmd_fifo_dir)}, { "socket_dir", PTR_V_STR(uzbl.behave.socket_dir, 1, cmd_socket_dir)}, { "http_debug", PTR_V_INT(uzbl.behave.http_debug, 1, cmd_http_debug)}, diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b5a502e..a62c3a6 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -133,6 +133,7 @@ typedef struct { gchar* fantasy_font_family; gchar* cursive_font_family; gchar* scheme_handler; + gchar* download_handler; gboolean show_status; gboolean forward_keys; gboolean status_top; -- cgit v1.2.3 From 5ab073d90e3c66a53e116c78299c657a13847d5c Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 14:55:47 -0700 Subject: display active downloads in the status bar --- examples/config/config | 4 ++- examples/data/plugins/downloads.py | 69 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 examples/data/plugins/downloads.py (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 64e1c94..a8547d2 100644 --- a/examples/config/config +++ b/examples/config/config @@ -105,7 +105,9 @@ set name_section = \@[\@NAME]\@ set status_section = \@status_message set selected_section = \@[\@SELECTED_URI]\@ -set status_format = @mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @scroll_section @selected_section +set download_section = \@downloads + +set status_format = @mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @scroll_section @selected_section @download_section set title_format_long = \@keycmd_prompt \@raw_modcmd \@raw_keycmd \@TITLE - Uzbl browser <\@NAME> \@SELECTED_URI diff --git a/examples/data/plugins/downloads.py b/examples/data/plugins/downloads.py new file mode 100644 index 0000000..7bf32d7 --- /dev/null +++ b/examples/data/plugins/downloads.py @@ -0,0 +1,69 @@ +# this plugin does a very simple display of download progress. to use it, add +# @downloads to your status_format. + +import os +ACTIVE_DOWNLOADS = {} + +# after a download's status has changed this is called to update the status bar +def update_download_section(uzbl): + global ACTIVE_DOWNLOADS + + if len(ACTIVE_DOWNLOADS): + # add a newline before we list downloads + result = ' downloads:' + for path in ACTIVE_DOWNLOADS: + # add each download + fn = os.path.basename(path) + progress, = ACTIVE_DOWNLOADS[path] + + dl = " %s (%d%%)" % (fn, progress * 100) + + # replace entities to make sure we don't break our markup + # (this could be done with an @[]@ expansion in uzbl, but then we + # can't use the above to make a new line) + dl = dl.replace("&", "&").replace("<", "<") + result += dl + else: + result = '' + + # and the result gets saved to an uzbl variable that can be used in + # status_format + if uzbl.config.get('downloads', '') != result: + uzbl.config['downloads'] = result + +def download_started(uzbl, destination_path): + # add to the list of active downloads + global ACTIVE_DOWNLOADS + ACTIVE_DOWNLOADS[destination_path] = (0.0,) + + # update the progress + update_download_section(uzbl) + +def download_progress(uzbl, args): + # parse the arguments + s = args.rindex(' ') + destination_path = args[:s] + progress = float(args[s+1:]) + + # update the progress + global ACTIVE_DOWNLOADS + ACTIVE_DOWNLOADS[destination_path] = (progress,) + + # update the status bar variable + update_download_section(uzbl) + +def download_complete(uzbl, destination_path): + # remove from the list of active downloads + global ACTIVE_DOWNLOADS + del ACTIVE_DOWNLOADS[destination_path] + + # update the status bar variable + update_download_section(uzbl) + +# plugin init hook +def init(uzbl): + connect_dict(uzbl, { + 'DOWNLOAD_STARTED': download_started, + 'DOWNLOAD_PROGRESS': download_progress, + 'DOWNLOAD_COMPLETE': download_complete, + }) -- cgit v1.2.3 From 123e73552c199e1efad6c2fb15e2d7128bc2b7e2 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 15:17:15 -0700 Subject: removed DOWNLOAD_REQUEST from the example config there's always one thing i forget to commit :( --- examples/config/config | 3 --- 1 file changed, 3 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index a8547d2..372b5cc 100644 --- a/examples/config/config +++ b/examples/config/config @@ -54,9 +54,6 @@ set download_handler = sync_spawn @scripts_dir/download.sh # Open in new tab #@on_event NEW_WINDOW event NEW_TAB %s -# Download handler -@on_event DOWNLOAD_REQUEST spawn @scripts_dir/download.sh %s \@proxy_url - # Load start handler @on_event LOAD_START @set_status wait # Reset the keycmd on navigation -- cgit v1.2.3 From a6c6ff660337fcb479e29e600ca48f7a89dc6b90 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sat, 4 Dec 2010 14:40:55 -0700 Subject: fix the t binds --- examples/config/config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 48aacfc..66e1a46 100644 --- a/examples/config/config +++ b/examples/config/config @@ -253,8 +253,8 @@ set ebind = @mode_bind global,-insert # Use socat to directly inject commands into uzbl-core and view events # raised by uzbl-core: -@cbind t = sh "xterm -e 'socat unix-connect:\"$UZBL_SOCKET\" -'" -#@cbind t = sh "urxvt -e 'socat unix-connect:\"$UZBL_SOCKET\" -'" +@cbind t = sh 'xterm -e "socat unix-connect:\"$UZBL_SOCKET\" -"' +#@cbind t = sh 'urxvt -e socat unix-connect:"$UZBL_SOCKET" -' # Uri opening prompts @cbind o_ = uri %s -- cgit v1.2.3 From e8ef799cf5293aa19bebd7315596014e77037a57 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 6 Dec 2010 13:59:33 -0700 Subject: add per-site-settings example configuration with pipermail navigation userscript --- examples/config/config | 4 +-- examples/data/per-site-settings | 3 ++ examples/data/scripts/pipermail.js | 71 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 examples/data/per-site-settings create mode 100644 examples/data/scripts/pipermail.js (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 66e1a46..c5a0e86 100644 --- a/examples/config/config +++ b/examples/config/config @@ -64,8 +64,8 @@ set download_handler = sync_spawn @scripts_dir/download.sh # Load commit handlers @on_event LOAD_COMMIT @set_status recv -# Userscript support. Add all scripts to $XDG_DATA_HOME/uzbl/userscripts -#@on_event LOAD_COMMIT spawn @scripts_dir/userscripts.sh +# Userscripts/per-site-settings. See the script and the example configuration for details +#@on_event LOAD_COMMIT spawn @scripts_dir/per-site-settings.py @data_home/uzbl/per-site-settings # Load finish handlers @on_event LOAD_FINISH @set_status done diff --git a/examples/data/per-site-settings b/examples/data/per-site-settings new file mode 100644 index 0000000..78bade4 --- /dev/null +++ b/examples/data/per-site-settings @@ -0,0 +1,3 @@ +.* + .*/\d+-\w+/(thread|subject|author|date).html + script @data_home/uzbl/scripts/pipermail.js diff --git a/examples/data/scripts/pipermail.js b/examples/data/scripts/pipermail.js new file mode 100644 index 0000000..5ec4aa4 --- /dev/null +++ b/examples/data/scripts/pipermail.js @@ -0,0 +1,71 @@ +// this is a userscript inspired by "Pipermail Navigation Links" by Michael +// Stone . + +// it adds previous month/next month navigation links in pipermail mailing +// list archives. + +// we wrap the whole thing in a function (that gets called immediately) so +// that this script doesn't interfere with any javascript in the page. +(function() { + +// figure out what page we're looking at right now +var urlparts = document.location.toString().split("/"); +var currView = urlparts[urlparts.length-1].split("#")[0]; +var currDate = urlparts[urlparts.length-2].split("-"); + +// figure out the URLs to the next month and previous month +var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', + 'August', 'September', 'October', 'November', 'December' ]; + +var thisMonth = currDate[1]; +var prevMonth; +var nextMonth; + +var thisYear = currDate[0]; +var prevYear = thisYear; +var nextYear = thisYear; + +if(thisMonth == 'January') { + prevMonth = "December"; + nextMonth = "February"; + prevYear = parseInt(thisYear) - 1; +} else if(thisMonth == 'December') { + prevMonth = "November"; + nextMonth = "January"; + nextYear = parseInt(thisYear) + 1; +} else { + var monthNum = months.indexOf(thisMonth); + prevMonth = months[monthNum - 1]; + nextMonth = months[monthNum + 1]; +} + +var prevHref = "../" + prevYear + "-" + prevMonth + "/" + currView; +var nextHref = "../" + nextYear + "-" + nextMonth + "/" + currView; + +// find the navigation header and footer +var selector = "a[href='date.html#start']"; + +// if we're on a "date" page then the date link isn't displayed +if(currView == "date.html") + selector = "a[href='author.html#start']"; + +var navLinks = document.querySelectorAll(selector); + +// append the prev/next links to the navigation header and footer +for(var i = 0; i < navLinks.length; i++) { + var victim = navLinks[i].parentNode; + + var prevEl = document.createElement("a"); + prevEl.textContent = "[ prev month ]"; + prevEl.href = prevHref; + + var nextEl = document.createElement("a"); + nextEl.textContent = "[ next month ]"; + nextEl.href = nextHref; + + victim.appendChild(prevEl); + victim.appendChild(document.createTextNode(" ")); + victim.appendChild(nextEl); +} + +})(); -- cgit v1.2.3 From f8c065feb6d420994c159073c0fce10ef6adc876 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sat, 11 Dec 2010 13:50:47 +0100 Subject: Quote URI when using middle click to open in new window @SELECTED_URI is not encoded, so a URI with spaces would expand to more than one parameter. --- examples/config/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index c5a0e86..a6651bf 100644 --- a/examples/config/config +++ b/examples/config/config @@ -183,7 +183,7 @@ set ebind = @mode_bind global,-insert # --- Mouse bindings --------------------------------------------------------- # Middle click open in new window -@bind = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' \@SELECTED_URI +@bind = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' '\@SELECTED_URI' # --- Keyboard bindings ------------------------------------------------------ -- cgit v1.2.3 From 6e66dca749831fdf8497442208cdcc6ff9518cf3 Mon Sep 17 00:00:00 2001 From: keis Date: Fri, 3 Dec 2010 02:01:52 +0100 Subject: bring it all together add script that loads all cookies from a file by calling add_cookie disable cookie_handler in config call load_cookies.sh from config don't start cookie daemon in uzbl-browser --- examples/config/config | 3 ++- examples/data/scripts/load_cookies.sh | 22 ++++++++++++++++++++++ src/uzbl-browser | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 examples/data/scripts/load_cookies.sh (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index c5a0e86..213bb88 100644 --- a/examples/config/config +++ b/examples/config/config @@ -42,7 +42,7 @@ set scripts_dir = @data_home/uzbl:@prefix/share/uzbl/examples/data:scripts # These handlers can't be moved to the new event system yet as we don't # support events that can wait for a response from a script. -set cookie_handler = talk_to_socket @cache_home/uzbl/cookie_daemon_socket +#set cookie_handler = talk_to_socket @cache_home/uzbl/cookie_daemon_socket set scheme_handler = sync_spawn @scripts_dir/scheme.py set authentication_handler = sync_spawn @scripts_dir/auth.py set download_handler = sync_spawn @scripts_dir/download.sh @@ -391,6 +391,7 @@ set stack = @mode_config stack set default_mode = command # === Post-load misc commands ================================================ +sync_spawn @scripts_dir/load_cookies.sh # Set the "home" page. set uri = uzbl.org/doesitwork/@COMMIT diff --git a/examples/data/scripts/load_cookies.sh b/examples/data/scripts/load_cookies.sh new file mode 100755 index 0000000..a192d3b --- /dev/null +++ b/examples/data/scripts/load_cookies.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if [ "$1" != "" ]; then + cookie_file=$1 +else + cookie_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt +fi + +echo $cookie_file + +awk -F \\t ' +BEGIN { + scheme["TRUE"] = "https"; + scheme["FALSE"] = "http"; +} +$0 ~ /^#HttpOnly_/ { +printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", substr($1,length("#HttpOnly_"),length($1)), $3, $6, $7, scheme[$4], $5) +} +$0 !~ /^#/ { +printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $3, $6, $7, scheme[$4], $5) +} +' $cookie_file > $UZBL_FIFO diff --git a/src/uzbl-browser b/src/uzbl-browser index 3c9562d..faa2829 100755 --- a/src/uzbl-browser +++ b/src/uzbl-browser @@ -68,7 +68,7 @@ fi # we could also check if its pid file exists to avoid having to spawn it. #if [ ! -f "$XDG_CACHE_HOME"/uzbl/cookie_daemon_socket.pid ] #then - ${UZBL_COOKIE_DAEMON:-uzbl-cookie-manager} +# ${UZBL_COOKIE_DAEMON:-uzbl-cookie-manager} #fi # uzbl-event-manager will exit if one is already running. -- cgit v1.2.3 From 46ddb58bcd2c0e7e3be27ed903ddce91eb14cc85 Mon Sep 17 00:00:00 2001 From: keis Date: Sun, 12 Dec 2010 16:52:38 +0100 Subject: basic blacklisting in cookies plugin --- examples/config/config | 4 ++++ examples/data/plugins/cookies.py | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 213bb88..29f5fbc 100644 --- a/examples/config/config +++ b/examples/config/config @@ -122,6 +122,10 @@ set progress.pending = set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MICRO}) (@(+uname -sm)@ [@ARCH_UZBL]) (Commit @COMMIT) +# === Configure cookie blacklist ======================================================== +# Drop google analytics tracking cookies +#request BLACKLIST_COOKIE name '^__utm.$' + # === Key binding configuration ============================================== # --- Internal modmapping and ignoring --------------------------------------- diff --git a/examples/data/plugins/cookies.py b/examples/data/plugins/cookies.py index 225a6af..0264471 100644 --- a/examples/data/plugins/cookies.py +++ b/examples/data/plugins/cookies.py @@ -4,6 +4,8 @@ from collections import defaultdict import os, re +symbolic = {'domain': 0, 'path':1, 'name':2, 'value':3, 'scheme':4, 'expires':5} + _splitquoted = re.compile("( |\\\".*?\\\"|'.*?')") def splitquoted(text): return [str(p.strip('\'"')) for p in _splitquoted.split(text) if p.strip()] @@ -88,7 +90,13 @@ xdg_data_home = os.environ.get('XDG_DATA_HOME', os.path.join(os.environ['HOME'], DefaultStore = TextStore(os.path.join(xdg_data_home, 'uzbl/cookies.txt')) SessionStore = ListStore() -def expires_with_session(cookie): +def accept_cookie(uzbl, cookie): + for component, match in uzbl.cookie_blacklist: + if match(cookie[component]) is not None: + return False + return True + +def expires_with_session(uzbl, cookie): return cookie[5] == '' def get_recipents(uzbl): @@ -102,11 +110,14 @@ def get_store(uzbl, session=False): return DefaultStore def add_cookie(uzbl, cookie): - for u in get_recipents(uzbl): - u.send('add_cookie %s' % cookie) - splitted = splitquoted(cookie) - get_store(uzbl, expires_with_session(splitted)).add_cookie(cookie, splitted) + if accept_cookie(uzbl, splitted): + for u in get_recipents(uzbl): + u.send('add_cookie %s' % cookie) + + get_store(uzbl, expires_with_session(uzbl, splitted)).add_cookie(cookie, splitted) + else: + uzbl.send('delete_cookie %s' % cookie) def delete_cookie(uzbl, cookie): for u in get_recipents(uzbl): @@ -114,15 +125,28 @@ def delete_cookie(uzbl, cookie): splitted = splitquoted(cookie) if len(splitted) == 6: - get_store(uzbl, expires_with_session(splitted)).delete_cookie(cookie, splitted) + get_store(uzbl, expires_with_session(uzbl, splitted)).delete_cookie(cookie, splitted) else: for store in set([get_store(uzbl, session) for session in (True, False)]): store.delete_cookie(cookie, splitted) +def blacklist(uzbl, arg): + component, regexp = splitquoted(arg) + try: + component = symbolic[component] + except KeyError: + component = int(component) + assert component <= 5 + uzbl.cookie_blacklist.append((component, re.compile(regexp).match)) + def init(uzbl): connect_dict(uzbl, { 'ADD_COOKIE': add_cookie, 'DELETE_COOKIE': delete_cookie, + 'BLACKLIST_COOKIE': blacklist + }) + export_dict(uzbl, { + 'cookie_blacklist' : [] }) for cookie in get_store(uzbl, True): -- cgit v1.2.3 From a24bd9a761773aad6a9512da5c3524f07c32d689 Mon Sep 17 00:00:00 2001 From: keis Date: Fri, 17 Dec 2010 23:42:02 +0100 Subject: use sync_spawn_exec to load cookies --- examples/config/config | 2 +- examples/data/scripts/load_cookies.sh | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 29f5fbc..caf68a1 100644 --- a/examples/config/config +++ b/examples/config/config @@ -395,7 +395,7 @@ set stack = @mode_config stack set default_mode = command # === Post-load misc commands ================================================ -sync_spawn @scripts_dir/load_cookies.sh +sync_spawn_exec @scripts_dir/load_cookies.sh # Set the "home" page. set uri = uzbl.org/doesitwork/@COMMIT diff --git a/examples/data/scripts/load_cookies.sh b/examples/data/scripts/load_cookies.sh index a192d3b..f4c6886 100755 --- a/examples/data/scripts/load_cookies.sh +++ b/examples/data/scripts/load_cookies.sh @@ -1,13 +1,11 @@ #!/bin/sh -if [ "$1" != "" ]; then - cookie_file=$1 +if [ "$8" != "" ]; then + cookie_file=$8 else cookie_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt fi -echo $cookie_file - awk -F \\t ' BEGIN { scheme["TRUE"] = "https"; @@ -19,4 +17,4 @@ printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", substr($1,lengt $0 !~ /^#/ { printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $3, $6, $7, scheme[$4], $5) } -' $cookie_file > $UZBL_FIFO +' $cookie_file -- cgit v1.2.3 From 6ade80cd01d0473dc1268d35a9db89dc03b1b9e9 Mon Sep 17 00:00:00 2001 From: keis Date: Sat, 18 Dec 2010 23:07:33 +0100 Subject: put session cookies in file --- examples/config/config | 1 + examples/data/plugins/cookies.py | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index caf68a1..e755be1 100644 --- a/examples/config/config +++ b/examples/config/config @@ -396,6 +396,7 @@ set default_mode = command # === Post-load misc commands ================================================ sync_spawn_exec @scripts_dir/load_cookies.sh +sync_spawn_exec @scripts_dir/load_cookies.sh @data_home/uzbl/session-cookies.txt # Set the "home" page. set uri = uzbl.org/doesitwork/@COMMIT diff --git a/examples/data/plugins/cookies.py b/examples/data/plugins/cookies.py index a4ae530..8fb9b32 100644 --- a/examples/data/plugins/cookies.py +++ b/examples/data/plugins/cookies.py @@ -88,7 +88,7 @@ class TextStore(object): xdg_data_home = os.environ.get('XDG_DATA_HOME', os.path.join(os.environ['HOME'], '.local/share')) DefaultStore = TextStore(os.path.join(xdg_data_home, 'uzbl/cookies.txt')) -SessionStore = ListStore() +SessionStore = TextStore(os.path.join(xdg_data_home, 'uzbl/session-cookies.txt')) def accept_cookie(uzbl, cookie): for component, match in uzbl.cookie_blacklist: @@ -148,6 +148,3 @@ def init(uzbl): export_dict(uzbl, { 'cookie_blacklist' : [] }) - - for cookie in get_store(uzbl, True): - uzbl.send('add_cookie %s' % cookie) -- cgit v1.2.3 From 2744b6baf031d53201679fba0768c31520f09a84 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Thu, 23 Dec 2010 21:24:00 -0700 Subject: remove cookie_handler from the example config. --- examples/config/config | 1 - 1 file changed, 1 deletion(-) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index e755be1..96b2034 100644 --- a/examples/config/config +++ b/examples/config/config @@ -42,7 +42,6 @@ set scripts_dir = @data_home/uzbl:@prefix/share/uzbl/examples/data:scripts # These handlers can't be moved to the new event system yet as we don't # support events that can wait for a response from a script. -#set cookie_handler = talk_to_socket @cache_home/uzbl/cookie_daemon_socket set scheme_handler = sync_spawn @scripts_dir/scheme.py set authentication_handler = sync_spawn @scripts_dir/auth.py set download_handler = sync_spawn @scripts_dir/download.sh -- cgit v1.2.3