summaryrefslogtreecommitdiff
path: root/desktop/netsurf.c
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-06 11:25:11 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-06 11:26:47 +0100
commit8469f4cc8e62e80a3165a1d4f13b62b5b4a04720 (patch)
tree707b46c3cf0b373b53adf8c54d290e4c546ebb2c /desktop/netsurf.c
parent9c9c26a308995c22210c90e3772e86f49a1948b9 (diff)
downloadnetsurf-8469f4cc8e62e80a3165a1d4f13b62b5b4a04720.tar.gz
netsurf-8469f4cc8e62e80a3165a1d4f13b62b5b4a04720.tar.bz2
Reimplement handling of BAD_AUTH inside browser_window
We now handle authentication requests via an `about:` page which presents a nice form built into the browser window. In order to do this, we add internal navigation as a concept to the browser window and we strip the 401login support from all frontends except monkey. The 401login callback is now intended for password safe type support rather than an immediately interactive prompt. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'desktop/netsurf.c')
-rw-r--r--desktop/netsurf.c200
1 files changed, 0 insertions, 200 deletions
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index 706ca7be0..0928442dc 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -98,206 +98,6 @@ static void netsurf_lwc_iterator(lwc_string *str, void *pw)
(int)lwc_string_length(str), lwc_string_data(str));
}
-/**
- * Build a "username:password" from components.
- *
- * \param[in] username The username component.
- * \param[in] password The password component.
- * \param[out] userpass_out Returns combined string on success.
- * Owned by caller.
- * \return NSERROR_OK, or appropriate error code.
- */
-static nserror netsurf__build_userpass(
- const char *username,
- const char *password,
- char **userpass_out)
-{
- char *userpass;
- size_t len;
-
- len = strlen(username) + 1 + strlen(password) + 1;
-
- userpass = malloc(len);
- if (userpass == NULL) {
- return NSERROR_NOMEM;
- }
-
- snprintf(userpass, len, "%s:%s", username, password);
-
- *userpass_out = userpass;
- return NSERROR_OK;
-}
-
-/**
- * Unpack a "username:password" to components.
- *
- * \param[in] userpass The input string to split.
- * \param[in] username_out Returns username on success. Owned by caller.
- * \param[out] password_out Returns password on success. Owned by caller.
- * \return NSERROR_OK, or appropriate error code.
- */
-static nserror netsurf__unpack_userpass(
- const char *userpass,
- char **username_out,
- char **password_out)
-{
- const char *tmp;
- char *username;
- char *password;
- size_t len;
-
- if (userpass == NULL) {
- username = malloc(1);
- password = malloc(1);
- if (username == NULL || password == NULL) {
- free(username);
- free(password);
- return NSERROR_NOMEM;
- }
- username[0] = '\0';
- password[0] = '\0';
-
- *username_out = username;
- *password_out = password;
- return NSERROR_OK;
- }
-
- tmp = strchr(userpass, ':');
- if (tmp == NULL) {
- return NSERROR_BAD_PARAMETER;
- } else {
- size_t len2;
- len = tmp - userpass;
- len2 = strlen(++tmp);
-
- username = malloc(len + 1);
- password = malloc(len2 + 1);
- if (username == NULL || password == NULL) {
- free(username);
- free(password);
- return NSERROR_NOMEM;
- }
- memcpy(username, userpass, len);
- username[len] = '\0';
- memcpy(password, tmp, len2 + 1);
- }
-
- *username_out = username;
- *password_out = password;
- return NSERROR_OK;
-}
-
-/**
- * Contect for login callbacks to front ends.
- */
-struct auth_data {
- char *realm;
- nsurl *url;
-
- browser_window_query_callback cb;
- void *pw;
-};
-
-/**
- * Callback function passed to front ends for handling logins.
- *
- * \param[in] username The username.
- * \param[in] password The password.
- * \param[in] cbpw Our context.
- * \return NSERROR_OK, or appropriate error code.
- */
-static nserror netsurf__handle_login_response(
- const char *username,
- const char *password,
- void *cbpw)
-{
- struct auth_data *ctx = cbpw;
- bool proceed = false;
- nserror err;
-
- if (username != NULL && password != NULL) {
- char *userpass;
-
- err = netsurf__build_userpass(username, password, &userpass);
- if (err != NSERROR_OK) {
- return err;
- }
-
- urldb_set_auth_details(ctx->url, ctx->realm, userpass);
- free(userpass);
- proceed = true;
- }
-
- err = ctx->cb(proceed, ctx->pw);
- nsurl_unref(ctx->url);
- free(ctx->realm);
- free(ctx);
- return err;
-}
-
-/* Cheeky */
-nserror netsurf__handle_login(const char * realm, nsurl *url,
- browser_window_query_callback cb, void *cbpw);
-/**
- * Helper for getting front end to handle logins.
- *
- * \param[in] query Query descriptor
- * \param[in] pw Private data
- * \param[in] cb Continuation callback
- * \param[in] cbpw Private data for continuation
- * \return NSERROR_OK, or appropriate error code.
- */
-nserror netsurf__handle_login(const char * realm, nsurl *url,
- browser_window_query_callback cb, void *cbpw)
-{
- struct auth_data *ctx;
- char *username;
- char *password;
- nserror err;
-
- NSLOG(llcache, INFO, "HTTP Auth for: %s: %s",
- realm, nsurl_access(url));
-
- ctx = malloc(sizeof(*ctx));
- if (ctx == NULL) {
- return NSERROR_NOMEM;
- }
-
- ctx->realm = strdup(realm);
- if (ctx->realm == NULL) {
- free(ctx);
- return NSERROR_NOMEM;
- }
- ctx->url = nsurl_ref(url);
- ctx->cb = cb;
- ctx->pw = cbpw;
-
- err = netsurf__unpack_userpass(
- urldb_get_auth_details(ctx->url, ctx->realm),
- &username, &password);
- if (err != NSERROR_OK) {
- nsurl_unref(ctx->url);
- free(ctx->realm);
- free(ctx);
- return err;
- }
-
- err = guit->misc->login(ctx->url, ctx->realm, username, password,
- netsurf__handle_login_response, ctx);
- free(username);
- free(password);
- if (err != NSERROR_OK) {
- ctx->cb(false, ctx->pw);
- nsurl_unref(ctx->url);
- free(ctx->realm);
- free(ctx);
- return err;
- }
-
- return NSERROR_OK;
-}
-
-
/* exported interface documented in netsurf/netsurf.h */
nserror netsurf_init(const char *store_path)
{