2003-10-23 04:09:17 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-10-23 04:09:17 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2006-02-19 21:26:23 +03:00
|
|
|
#include <stdbool.h>
|
2003-10-23 04:09:17 +04:00
|
|
|
#include <string.h>
|
2008-07-27 02:29:15 +04:00
|
|
|
#include <oslib/wimp.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/401login.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "riscos/dialog.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_AUTH
|
|
|
|
|
2006-09-06 18:44:42 +04:00
|
|
|
#define ICON_401LOGIN_LOGIN 0
|
|
|
|
#define ICON_401LOGIN_CANCEL 1
|
|
|
|
#define ICON_401LOGIN_HOST 2
|
|
|
|
#define ICON_401LOGIN_REALM 3
|
|
|
|
#define ICON_401LOGIN_USERNAME 4
|
|
|
|
#define ICON_401LOGIN_PASSWORD 5
|
|
|
|
|
2005-12-31 07:34:38 +03:00
|
|
|
static void ro_gui_401login_close(wimp_w w);
|
|
|
|
static bool ro_gui_401login_apply(wimp_w w);
|
2006-02-23 18:06:54 +03:00
|
|
|
static void ro_gui_401login_open(struct browser_window *bw, const char *host,
|
|
|
|
const char *realm, const char *fetchurl);
|
2005-12-31 07:34:38 +03:00
|
|
|
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2003-10-26 14:40:50 +03:00
|
|
|
static wimp_window *dialog_401_template;
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2005-12-31 07:34:38 +03:00
|
|
|
struct session_401 {
|
2006-02-19 21:26:23 +03:00
|
|
|
char *host; /**< Host for user display */
|
|
|
|
char *realm; /**< Authentication realm */
|
|
|
|
char uname[256]; /**< Buffer for username */
|
|
|
|
char *url; /**< URL being fetched */
|
|
|
|
char pwd[256]; /**< Buffer for password */
|
|
|
|
struct browser_window *bwin; /**< Browser window handle */
|
2005-12-31 07:34:38 +03:00
|
|
|
};
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2004-05-09 00:44:00 +04:00
|
|
|
|
2003-10-23 04:09:17 +04:00
|
|
|
/**
|
|
|
|
* Load the 401 login window template.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_401login_init(void)
|
|
|
|
{
|
2004-05-09 00:44:00 +04:00
|
|
|
dialog_401_template = ro_gui_dialog_load_template("login");
|
2003-10-23 04:09:17 +04:00
|
|
|
}
|
|
|
|
|
2004-05-09 00:44:00 +04:00
|
|
|
|
2006-02-19 21:26:23 +03:00
|
|
|
/**
|
|
|
|
* Open the login dialog
|
|
|
|
*/
|
|
|
|
void gui_401login_open(struct browser_window *bw, struct content *c,
|
2006-02-23 18:06:54 +03:00
|
|
|
const char *realm)
|
2004-06-20 23:49:40 +04:00
|
|
|
{
|
|
|
|
char *murl, *host;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2003-10-25 23:20:13 +04:00
|
|
|
|
2004-06-20 23:49:40 +04:00
|
|
|
murl = c->url;
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_host(murl, &host);
|
|
|
|
assert(res == URL_FUNC_OK);
|
2003-10-25 23:20:13 +04:00
|
|
|
|
2005-12-31 07:34:38 +03:00
|
|
|
ro_gui_401login_open(bw, host, realm, murl);
|
2003-10-25 23:20:13 +04:00
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
free(host);
|
2003-10-25 23:20:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-23 04:09:17 +04:00
|
|
|
/**
|
|
|
|
* Open a 401 login window.
|
|
|
|
*/
|
|
|
|
|
2006-02-23 18:06:54 +03:00
|
|
|
void ro_gui_401login_open(struct browser_window *bw, const char *host,
|
|
|
|
const char *realm, const char *fetchurl)
|
2003-10-23 04:09:17 +04:00
|
|
|
{
|
2005-12-31 07:34:38 +03:00
|
|
|
struct session_401 *session;
|
|
|
|
wimp_w w;
|
2006-02-19 21:26:23 +03:00
|
|
|
|
2005-12-31 07:34:38 +03:00
|
|
|
session = calloc(1, sizeof(struct session_401));
|
|
|
|
if (!session) {
|
2005-01-02 01:14:06 +03:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
2005-12-31 07:34:38 +03:00
|
|
|
|
|
|
|
session->url = strdup(fetchurl);
|
|
|
|
if (!session->url) {
|
2006-02-19 21:26:23 +03:00
|
|
|
free(session);
|
2005-12-31 07:34:38 +03:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
session->uname[0] = '\0';
|
|
|
|
session->pwd[0] = '\0';
|
|
|
|
session->host = strdup(host);
|
2006-05-15 03:35:15 +04:00
|
|
|
session->realm = strdup(realm ? realm : "Secure Area");
|
2005-12-31 07:34:38 +03:00
|
|
|
session->bwin = bw;
|
|
|
|
if ((!session->host) || (!session->realm)) {
|
2006-02-19 21:26:23 +03:00
|
|
|
free(session->host);
|
|
|
|
free(session->realm);
|
|
|
|
free(session);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
2005-12-31 07:34:38 +03:00
|
|
|
}
|
2003-10-23 04:09:17 +04:00
|
|
|
|
|
|
|
/* fill in download window icons */
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401_template->icons[ICON_401LOGIN_HOST].data.indirected_text.text =
|
2005-12-31 07:34:38 +03:00
|
|
|
session->host;
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401_template->icons[ICON_401LOGIN_HOST].data.indirected_text.size =
|
2003-10-23 04:09:17 +04:00
|
|
|
strlen(host) + 1;
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401_template->icons[ICON_401LOGIN_REALM].data.indirected_text.text =
|
2005-12-31 07:34:38 +03:00
|
|
|
session->realm;
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401_template->icons[ICON_401LOGIN_REALM].data.indirected_text.size =
|
2003-10-23 04:09:17 +04:00
|
|
|
strlen(realm) + 1;
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401_template->icons[ICON_401LOGIN_USERNAME].data.indirected_text.text =
|
2005-12-31 07:34:38 +03:00
|
|
|
session->uname;
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401_template->icons[ICON_401LOGIN_USERNAME].data.indirected_text.size =
|
|
|
|
256;
|
|
|
|
dialog_401_template->icons[ICON_401LOGIN_PASSWORD].data.indirected_text.text =
|
2005-12-31 07:34:38 +03:00
|
|
|
session->pwd;
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401_template->icons[ICON_401LOGIN_PASSWORD].data.indirected_text.size =
|
|
|
|
256;
|
2003-10-23 04:09:17 +04:00
|
|
|
|
|
|
|
/* create and open the window */
|
2005-12-31 07:34:38 +03:00
|
|
|
w = wimp_create_window(dialog_401_template);
|
2006-02-19 21:26:23 +03:00
|
|
|
|
2005-12-31 07:34:38 +03:00
|
|
|
ro_gui_wimp_event_register_text_field(w, ICON_401LOGIN_USERNAME);
|
|
|
|
ro_gui_wimp_event_register_text_field(w, ICON_401LOGIN_PASSWORD);
|
|
|
|
ro_gui_wimp_event_register_cancel(w, ICON_401LOGIN_CANCEL);
|
|
|
|
ro_gui_wimp_event_register_ok(w, ICON_401LOGIN_LOGIN,
|
|
|
|
ro_gui_401login_apply);
|
|
|
|
ro_gui_wimp_event_register_close_window(w, ro_gui_401login_close);
|
|
|
|
ro_gui_wimp_event_set_user_data(w, session);
|
|
|
|
|
|
|
|
ro_gui_dialog_open_persistent(bw->window->window, w, false);
|
2003-10-23 04:09:17 +04:00
|
|
|
}
|
|
|
|
|
2006-02-19 21:26:23 +03:00
|
|
|
/**
|
|
|
|
* Handle closing of login dialog
|
|
|
|
*/
|
|
|
|
void ro_gui_401login_close(wimp_w w)
|
|
|
|
{
|
2005-12-31 07:34:38 +03:00
|
|
|
os_error *error;
|
2006-02-19 21:26:23 +03:00
|
|
|
struct session_401 *session;
|
|
|
|
|
|
|
|
session = (struct session_401 *)ro_gui_wimp_event_get_user_data(w);
|
|
|
|
|
|
|
|
assert(session);
|
|
|
|
|
|
|
|
free(session->host);
|
|
|
|
free(session->realm);
|
|
|
|
free(session->url);
|
|
|
|
free(session);
|
2005-12-31 07:34:38 +03:00
|
|
|
|
|
|
|
error = xwimp_delete_window(w);
|
2006-09-06 18:44:42 +04:00
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_delete_window: 0x%x:%s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
}
|
|
|
|
ro_gui_wimp_event_finalise(w);
|
2003-12-26 21:18:17 +03:00
|
|
|
}
|
|
|
|
|
2005-12-31 07:34:38 +03:00
|
|
|
|
2003-10-23 04:09:17 +04:00
|
|
|
/* Login Clicked -> create a new fetch request, specifying uname & pwd
|
|
|
|
* CURLOPT_USERPWD takes a string "username:password"
|
|
|
|
*/
|
2005-12-31 07:34:38 +03:00
|
|
|
bool ro_gui_401login_apply(wimp_w w)
|
2004-06-20 23:49:40 +04:00
|
|
|
{
|
2005-12-31 07:34:38 +03:00
|
|
|
struct session_401 *session;
|
2006-02-19 21:26:23 +03:00
|
|
|
char *auth;
|
2004-06-20 23:49:40 +04:00
|
|
|
|
2006-02-19 21:26:23 +03:00
|
|
|
session = (struct session_401 *)ro_gui_wimp_event_get_user_data(w);
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2006-02-19 21:26:23 +03:00
|
|
|
assert(session);
|
|
|
|
|
|
|
|
auth = malloc(strlen(session->uname) + strlen(session->pwd) + 2);
|
|
|
|
if (!auth) {
|
|
|
|
LOG(("calloc failed"));
|
2005-01-02 06:58:21 +03:00
|
|
|
warn_user("NoMemory", 0);
|
2005-12-31 07:34:38 +03:00
|
|
|
return false;
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2006-02-19 21:26:23 +03:00
|
|
|
sprintf(auth, "%s:%s", session->uname, session->pwd);
|
|
|
|
|
2006-04-10 03:21:13 +04:00
|
|
|
urldb_set_auth_details(session->url, session->realm, auth);
|
2006-02-19 21:26:23 +03:00
|
|
|
|
|
|
|
free(auth);
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2006-04-22 22:24:18 +04:00
|
|
|
browser_window_go(session->bwin, session->url, 0, true);
|
2005-12-31 07:34:38 +03:00
|
|
|
return true;
|
2003-10-23 04:09:17 +04:00
|
|
|
}
|
2004-01-05 05:10:59 +03:00
|
|
|
|
|
|
|
#endif
|