From e1806cf413fbafa7dfef273ca4ced37e1918d080 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Sun, 10 Jan 2010 02:39:50 +0100 Subject: authentication_handler implementaion Authentication handler allows to delegate http authentication to external program. It introduces one new configuration variable: authentication_handler. Note that this commit does not affect uzbl behaviour unless this variable is set. Also updated README documentation, default config and added example authentication script. --- src/callbacks.c | 11 +++++++++++ src/callbacks.h | 3 +++ src/uzbl-core.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/uzbl-core.h | 8 ++++++++ 4 files changed, 78 insertions(+) (limited to 'src') diff --git a/src/callbacks.c b/src/callbacks.c index dab92c1..b2f05cf 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -26,6 +26,17 @@ set_proxy_url() { return; } +void +set_authentication_handler() { + if (uzbl.behave.authentication_handler) + soup_session_remove_feature_by_type + (uzbl.net.soup_session, (GType) WEBKIT_TYPE_SOUP_AUTH_DIALOG); + else + soup_session_add_feature_by_type + (uzbl.net.soup_session, (GType) WEBKIT_TYPE_SOUP_AUTH_DIALOG); + return; +} + void set_icon() { if(file_exists(uzbl.gui.icon)) { diff --git a/src/callbacks.h b/src/callbacks.h index 3f318f2..7fe5c19 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -12,6 +12,9 @@ cmd_set_status(); void set_proxy_url(); +void +set_authentication_handler(); + void set_icon(); diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 8a053f6..cd907f4 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -101,6 +101,7 @@ const struct var_name_to_ptr_t { { "forward_keys", PTR_V_INT(uzbl.behave.forward_keys, 1, NULL)}, { "download_handler", PTR_V_STR(uzbl.behave.download_handler, 1, NULL)}, { "cookie_handler", PTR_V_STR(uzbl.behave.cookie_handler, 1, NULL)}, + { "authentication_handler", PTR_V_STR(uzbl.behave.authentication_handler, 1, set_authentication_handler)}, { "new_window", PTR_V_STR(uzbl.behave.new_window, 1, NULL)}, { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, NULL)}, { "fifo_dir", PTR_V_STR(uzbl.behave.fifo_dir, 1, cmd_fifo_dir)}, @@ -2316,6 +2317,61 @@ settings_init () { init_connect_socket(); g_signal_connect_after(n->soup_session, "request-started", G_CALLBACK(handle_cookies), NULL); + g_signal_connect(n->soup_session, "authenticate", G_CALLBACK(handle_authentication), NULL); +} + +void handle_authentication (SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, gpointer user_data) { + + (void) user_data; + + if(uzbl.behave.authentication_handler) { + char *username, *password; + gchar *info, *host, *realm; + int number_of_endls=0; + gchar *p; + + soup_session_pause_message(session, msg); + + /* Sanitize strings */ + info = g_strdup(soup_auth_get_info(auth)); + host = g_strdup(soup_auth_get_host(auth)); + realm = g_strdup(soup_auth_get_realm(auth)); + for (p = info; *p; p++) if (*p == '\'') *p = '\"'; + for (p = host; *p; p++) if (*p == '\'') *p = '\"'; + for (p = realm; *p; p++) if (*p == '\'') *p = '\"'; + + GString *s = g_string_new (""); + g_string_printf(s, "'%s' '%s' '%s' '%s'", + info, host, realm, retrying?"TRUE":"FALSE"); + + run_handler(uzbl.behave.authentication_handler, s->str); + + username = uzbl.comm.sync_stdout; + + for (p = uzbl.comm.sync_stdout; *p; p++) { + if (*p == '\n') { + *p = '\0'; + if (++number_of_endls == 1) + password = p + 1; + } + } + + /* If stdout was correct (contains exactly two lines of text) do + * authenticate. Otherwise fail. */ + if (number_of_endls == 2) { + soup_auth_authenticate(auth, username, password); + } else { + g_free(username); + g_free(password); + } + + soup_session_unpause_message(session, msg); + + g_string_free(s, TRUE); + g_free(info); + g_free(host); + g_free(realm); + } } void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer user_data){ diff --git a/src/uzbl-core.h b/src/uzbl-core.h index df9eb1a..998ea1d 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -122,6 +122,7 @@ typedef struct { gchar* socket_dir; gchar* download_handler; gchar* cookie_handler; + gchar* authentication_handler; gchar* new_window; gchar* default_font_family; gchar* monospace_font_family; @@ -389,6 +390,13 @@ run_external_js (WebKitWebView * web_view, GArray *argv, GString *result); void eval_js(WebKitWebView * web_view, gchar *script, GString *result); +void +handle_authentication (SoupSession *session, + SoupMessage *msg, + SoupAuth *auth, + gboolean retrying, + gpointer user_data); + void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer user_data); -- cgit v1.2.3 From 8a6ceac5f1853afe72064dda42cc8bb6a64b4b41 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Sun, 10 Jan 2010 21:20:20 +0100 Subject: fix double free in authentication_handler Don't g_free username and password as we don't allocate memory for these strings. --- src/uzbl-core.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index cd907f4..462feb5 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -2357,13 +2357,9 @@ void handle_authentication (SoupSession *session, SoupMessage *msg, SoupAuth *au } /* If stdout was correct (contains exactly two lines of text) do - * authenticate. Otherwise fail. */ - if (number_of_endls == 2) { + * authenticate. */ + if (number_of_endls == 2) soup_auth_authenticate(auth, username, password); - } else { - g_free(username); - g_free(password); - } soup_session_unpause_message(session, msg); -- cgit v1.2.3 From 54ed45392b4602fd22c0869afee5a57ab92ecfc2 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Tue, 12 Jan 2010 14:07:36 +0100 Subject: Strip leading whitespaces from uri. --- src/uzbl-core.c | 7 +++++++ src/uzbl-core.h | 1 + 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 462feb5..c9b3825 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -2534,6 +2534,13 @@ initialize(int argc, char *argv[]) { void load_uri_imp(gchar *uri) { GString* newuri; + + /* Strip leading whitespaces */ + while (*uri) { + if (!isspace(*uri)) break; + uri++; + } + if (g_strstr_len (uri, 11, "javascript:") != NULL) { eval_js(uzbl.gui.web_view, uri, NULL); return; diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 998ea1d..875feae 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include -- cgit v1.2.3 From d8ba750b6a6c070b8dcadd96944a096a52267fcf Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Tue, 12 Jan 2010 14:16:54 +0100 Subject: better way to check WebKit version use webkit_major_version(), webkit_minor_version() and webkit_micro_version() functions to obtain webkit version instead of accessing WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION and WEBKIT_MICRO_VERSION directly. WEBKIT_M*_VERSION are defined in header files included by uzbl code, so they contain WebKit version that uzbl was compiled against. webkit_m*_version() functions return WebKit version that is realy used at the moment. --- src/uzbl-core.c | 6 +++--- tests/test-expand.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index c9b3825..3e164c6 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -2518,9 +2518,9 @@ initialize(int argc, char *argv[]) { } event_buffer_timeout(10); - uzbl.info.webkit_major = WEBKIT_MAJOR_VERSION; - uzbl.info.webkit_minor = WEBKIT_MINOR_VERSION; - uzbl.info.webkit_micro = WEBKIT_MICRO_VERSION; + uzbl.info.webkit_major = webkit_major_version(); + uzbl.info.webkit_minor = webkit_minor_version(); + uzbl.info.webkit_micro = webkit_micro_version(); uzbl.info.arch = ARCH; uzbl.info.commit = COMMIT; diff --git a/tests/test-expand.c b/tests/test-expand.c index ef07c80..01af401 100644 --- a/tests/test-expand.c +++ b/tests/test-expand.c @@ -72,11 +72,11 @@ test_useragent (void) { void test_WEBKIT_VERSION (void) { GString* expected = g_string_new(""); - g_string_append(expected, itos(WEBKIT_MAJOR_VERSION)); + g_string_append(expected, itos(webkit_major_version())); g_string_append(expected, " "); - g_string_append(expected, itos(WEBKIT_MINOR_VERSION)); + g_string_append(expected, itos(webkit_minor_version())); g_string_append(expected, " "); - g_string_append(expected, itos(WEBKIT_MICRO_VERSION)); + g_string_append(expected, itos(webkit_micro_version())); g_assert_cmpstr(expand("@WEBKIT_MAJOR @WEBKIT_MINOR @WEBKIT_MICRO", 0), ==, g_string_free(expected, FALSE)); } -- cgit v1.2.3