2003-10-23 04:09:17 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-10-25 23:20:13 +04:00
|
|
|
#include <ctype.h>
|
2003-10-23 04:09:17 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/wimp.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2003-10-25 23:20:13 +04:00
|
|
|
#include "netsurf/content/content.h"
|
|
|
|
#include "netsurf/desktop/browser.h"
|
2003-10-23 04:09:17 +04:00
|
|
|
#include "netsurf/desktop/401login.h"
|
|
|
|
#include "netsurf/desktop/gui.h"
|
|
|
|
#include "netsurf/riscos/gui.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
#include "netsurf/utils/messages.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_AUTH
|
|
|
|
|
2003-10-23 04:09:17 +04:00
|
|
|
static void get_unamepwd(void);
|
|
|
|
|
2003-10-26 14:40:50 +03:00
|
|
|
static wimp_window *dialog_401_template;
|
2003-10-23 04:09:17 +04:00
|
|
|
extern wimp_w dialog_401li;
|
|
|
|
|
|
|
|
struct login LOGIN;
|
|
|
|
|
|
|
|
static char *uname;
|
|
|
|
static char* url;
|
|
|
|
static char *pwd;
|
2003-10-25 23:20:13 +04:00
|
|
|
static struct browser_window *bwin;
|
2003-10-23 04:09:17 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the 401 login window template.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_401login_init(void)
|
|
|
|
{
|
2003-12-31 20:09:03 +03:00
|
|
|
char name[20] = "login";
|
2003-10-23 04:09:17 +04:00
|
|
|
int context, window_size, data_size;
|
|
|
|
char *data;
|
2003-12-30 01:50:43 +03:00
|
|
|
os_error *e;
|
|
|
|
|
2003-12-31 20:09:03 +03:00
|
|
|
/* find required buffer sizes */
|
2003-12-30 01:50:43 +03:00
|
|
|
e = xwimp_load_template(wimp_GET_SIZE, 0, 0, wimp_NO_FONTS,
|
|
|
|
name, 0, &window_size, &data_size, &context);
|
|
|
|
if (e) {
|
|
|
|
die(e->errmess);
|
|
|
|
}
|
2003-10-23 04:09:17 +04:00
|
|
|
assert(context != 0);
|
|
|
|
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401_template = xcalloc((unsigned int) window_size, 1);
|
2003-10-23 04:09:17 +04:00
|
|
|
data = xcalloc((unsigned int) data_size, 1);
|
|
|
|
|
|
|
|
/* load */
|
2003-10-26 14:40:50 +03:00
|
|
|
wimp_load_template(dialog_401_template, data, data + data_size,
|
2003-10-23 04:09:17 +04:00
|
|
|
wimp_NO_FONTS, name, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2003-10-25 23:20:13 +04:00
|
|
|
void gui_401login_open(struct browser_window *bw, struct content *c, char *realm) {
|
|
|
|
|
|
|
|
char *murl, *host;
|
|
|
|
|
|
|
|
murl = c->url;
|
|
|
|
host = get_host_from_url(murl);
|
2003-12-26 19:21:46 +03:00
|
|
|
assert(host);
|
2003-10-25 23:20:13 +04:00
|
|
|
bwin = bw;
|
|
|
|
|
|
|
|
ro_gui_401login_open(host, realm, murl);
|
|
|
|
|
|
|
|
xfree(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-23 04:09:17 +04:00
|
|
|
/**
|
|
|
|
* Open a 401 login window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_401login_open(char *host, char* realm, char *fetchurl)
|
|
|
|
{
|
|
|
|
url = xstrdup(fetchurl);
|
2003-10-26 14:40:50 +03:00
|
|
|
uname = xcalloc(1, 256);
|
|
|
|
pwd = xcalloc(1, 256);
|
|
|
|
uname[0] = pwd[0] = 0;
|
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 =
|
2003-10-25 23:20:13 +04:00
|
|
|
xstrdup(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 =
|
2003-10-26 03:09:27 +03:00
|
|
|
xstrdup(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 =
|
2003-10-23 04:09:17 +04:00
|
|
|
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 =
|
2003-10-23 04:09:17 +04:00
|
|
|
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 */
|
2003-10-26 14:40:50 +03:00
|
|
|
dialog_401li = wimp_create_window(dialog_401_template);
|
2003-10-23 04:09:17 +04:00
|
|
|
ro_gui_dialog_open(dialog_401li);
|
2003-10-26 14:40:50 +03:00
|
|
|
wimp_set_caret_position(dialog_401li, ICON_401LOGIN_USERNAME,
|
|
|
|
-1, -1, -1, 0);
|
2003-10-23 04:09:17 +04:00
|
|
|
}
|
|
|
|
|
2003-12-26 21:18:17 +03:00
|
|
|
bool ro_gui_401login_keypress(wimp_key *key) {
|
|
|
|
|
2003-12-27 01:12:39 +03:00
|
|
|
switch (key->c) {
|
|
|
|
case wimp_KEY_RETURN:
|
|
|
|
get_unamepwd();
|
|
|
|
ro_gui_dialog_close(dialog_401li);
|
2004-02-25 18:12:58 +03:00
|
|
|
browser_window_go(bwin, url);
|
2003-12-27 01:12:39 +03:00
|
|
|
return true;
|
|
|
|
case wimp_KEY_ESCAPE:
|
|
|
|
ro_gui_dialog_close(dialog_401li);
|
2003-12-27 03:35:54 +03:00
|
|
|
return true;
|
2003-12-27 01:12:39 +03:00
|
|
|
default: break;
|
2003-12-26 21:18:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
*/
|
|
|
|
void ro_gui_401login_click(wimp_pointer *pointer) {
|
|
|
|
|
|
|
|
if (pointer->buttons == wimp_CLICK_MENU) return;
|
|
|
|
|
|
|
|
switch (pointer->i) {
|
|
|
|
case ICON_401LOGIN_LOGIN:
|
2003-10-26 15:41:51 +03:00
|
|
|
get_unamepwd();
|
|
|
|
ro_gui_dialog_close(dialog_401li);
|
2004-02-25 18:12:58 +03:00
|
|
|
browser_window_go(bwin, url);
|
2003-10-23 04:09:17 +04:00
|
|
|
break;
|
|
|
|
case ICON_401LOGIN_CANCEL:
|
2003-10-26 15:41:51 +03:00
|
|
|
ro_gui_dialog_close(dialog_401li);
|
2003-10-23 04:09:17 +04:00
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void get_unamepwd() {
|
|
|
|
|
2003-10-25 23:20:13 +04:00
|
|
|
char *lidets = xcalloc(strlen(uname)+strlen(pwd)+2, sizeof(char));
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2003-10-25 23:20:13 +04:00
|
|
|
sprintf(lidets, "%s:%s", uname, pwd);
|
2003-10-23 04:09:17 +04:00
|
|
|
|
2003-10-25 23:20:13 +04:00
|
|
|
login_list_add(url, lidets);
|
2003-10-23 04:09:17 +04:00
|
|
|
}
|
2004-01-05 05:10:59 +03:00
|
|
|
|
|
|
|
#endif
|