[project @ 2005-12-31 04:34:38 by rjw]
Allow multiple login windows. Plug memory leaks. svn path=/import/netsurf/; revision=1911
This commit is contained in:
parent
6d36a1c81e
commit
ad82fceb2e
|
@ -5,7 +5,6 @@
|
|||
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
||||
*/
|
||||
|
||||
/** \todo plug leaks; check strdup() return values */
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
@ -16,7 +15,8 @@
|
|||
#include "netsurf/desktop/browser.h"
|
||||
#include "netsurf/desktop/401login.h"
|
||||
#include "netsurf/desktop/gui.h"
|
||||
#include "netsurf/riscos/gui.h"
|
||||
#include "netsurf/riscos/dialog.h"
|
||||
#include "netsurf/riscos/wimp_event.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/messages.h"
|
||||
#include "netsurf/utils/url.h"
|
||||
|
@ -24,15 +24,22 @@
|
|||
|
||||
#ifdef WITH_AUTH
|
||||
|
||||
static void get_unamepwd(void);
|
||||
static void ro_gui_401login_close(wimp_w w);
|
||||
static bool ro_gui_401login_apply(wimp_w w);
|
||||
static void ro_gui_401login_open(struct browser_window *bw, char *host,
|
||||
char *realm, char *fetchurl);
|
||||
|
||||
|
||||
static wimp_window *dialog_401_template;
|
||||
extern wimp_w dialog_401li;
|
||||
|
||||
static char uname[256];
|
||||
static char *url;
|
||||
static char pwd[256];
|
||||
static struct browser_window *bwin;
|
||||
struct session_401 {
|
||||
char *host;
|
||||
char *realm;
|
||||
char uname[256];
|
||||
char *url;
|
||||
char pwd[256];
|
||||
struct browser_window *bwin;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
@ -53,9 +60,8 @@ void gui_401login_open(struct browser_window *bw, struct content *c, char *realm
|
|||
murl = c->url;
|
||||
res = url_host(murl, &host);
|
||||
assert(res == URL_FUNC_OK);
|
||||
bwin = bw;
|
||||
|
||||
ro_gui_401login_open(bw->window->window, host, realm, murl);
|
||||
ro_gui_401login_open(bw, host, realm, murl);
|
||||
|
||||
free(host);
|
||||
}
|
||||
|
@ -65,83 +71,117 @@ void gui_401login_open(struct browser_window *bw, struct content *c, char *realm
|
|||
* Open a 401 login window.
|
||||
*/
|
||||
|
||||
void ro_gui_401login_open(wimp_w parent, char *host, char* realm, char *fetchurl)
|
||||
void ro_gui_401login_open(struct browser_window *bw, char *host, char *realm,
|
||||
char *fetchurl)
|
||||
{
|
||||
url = strdup(fetchurl);
|
||||
if (!url) {
|
||||
struct session_401 *session;
|
||||
wimp_w w;
|
||||
|
||||
session = calloc(1, sizeof(struct session_401));
|
||||
if (!session) {
|
||||
warn_user("NoMemory", 0);
|
||||
return;
|
||||
}
|
||||
uname[0] = pwd[0] = 0;
|
||||
|
||||
session->url = strdup(fetchurl);
|
||||
if (!session->url) {
|
||||
free(session);
|
||||
warn_user("NoMemory", 0);
|
||||
return;
|
||||
}
|
||||
session->uname[0] = '\0';
|
||||
session->pwd[0] = '\0';
|
||||
session->host = strdup(host);
|
||||
session->realm = strdup(realm);
|
||||
session->bwin = bw;
|
||||
if ((!session->host) || (!session->realm)) {
|
||||
free(session->host);
|
||||
free(session->realm);
|
||||
free(session);
|
||||
}
|
||||
|
||||
/* fill in download window icons */
|
||||
dialog_401_template->icons[ICON_401LOGIN_HOST].data.indirected_text.text =
|
||||
strdup(host);
|
||||
session->host;
|
||||
dialog_401_template->icons[ICON_401LOGIN_HOST].data.indirected_text.size =
|
||||
strlen(host) + 1;
|
||||
dialog_401_template->icons[ICON_401LOGIN_REALM].data.indirected_text.text =
|
||||
strdup(realm);
|
||||
session->realm;
|
||||
dialog_401_template->icons[ICON_401LOGIN_REALM].data.indirected_text.size =
|
||||
strlen(realm) + 1;
|
||||
dialog_401_template->icons[ICON_401LOGIN_USERNAME].data.indirected_text.text =
|
||||
uname;
|
||||
session->uname;
|
||||
dialog_401_template->icons[ICON_401LOGIN_USERNAME].data.indirected_text.size =
|
||||
256;
|
||||
dialog_401_template->icons[ICON_401LOGIN_PASSWORD].data.indirected_text.text =
|
||||
pwd;
|
||||
session->pwd;
|
||||
dialog_401_template->icons[ICON_401LOGIN_PASSWORD].data.indirected_text.size =
|
||||
256;
|
||||
|
||||
/* create and open the window */
|
||||
dialog_401li = wimp_create_window(dialog_401_template);
|
||||
ro_gui_dialog_open_persistent(parent, dialog_401li, false);
|
||||
w = wimp_create_window(dialog_401_template);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
bool ro_gui_401login_keypress(wimp_key *key)
|
||||
{
|
||||
switch (key->c) {
|
||||
case wimp_KEY_RETURN:
|
||||
get_unamepwd();
|
||||
ro_gui_dialog_close(dialog_401li);
|
||||
browser_window_go(bwin, url, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
void ro_gui_401login_close(wimp_w w) {
|
||||
os_error *error;
|
||||
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);
|
||||
|
||||
ro_gui_wimp_event_finalise(w);
|
||||
|
||||
error = xwimp_delete_window(w);
|
||||
if (error)
|
||||
LOG(("xwimp_delete_window: 0x%x: %s",
|
||||
error->errnum, error->errmess));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* 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)
|
||||
bool ro_gui_401login_apply(wimp_w w)
|
||||
{
|
||||
if (pointer->buttons == wimp_CLICK_MENU)
|
||||
return;
|
||||
struct session_401 *session;
|
||||
char *lidets;
|
||||
|
||||
switch (pointer->i) {
|
||||
case ICON_401LOGIN_LOGIN:
|
||||
get_unamepwd();
|
||||
ro_gui_dialog_close(dialog_401li);
|
||||
browser_window_go(bwin, url, 0);
|
||||
break;
|
||||
case ICON_401LOGIN_CANCEL:
|
||||
ro_gui_dialog_close(dialog_401li);
|
||||
break;
|
||||
}
|
||||
}
|
||||
session = (struct session_401 *)ro_gui_wimp_event_get_user_data(w);
|
||||
|
||||
assert(session);
|
||||
|
||||
void get_unamepwd(void)
|
||||
{
|
||||
char *lidets = calloc(strlen(uname)+strlen(pwd)+2, sizeof(char));
|
||||
lidets = calloc(strlen(session->uname) + strlen(session->pwd) + 2,
|
||||
sizeof(char));
|
||||
if (!lidets) {
|
||||
LOG(("Insufficient memory for calloc"));
|
||||
warn_user("NoMemory", 0);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
sprintf(lidets, "%s:%s", uname, pwd);
|
||||
sprintf(lidets, "%s:%s", session->uname, session->pwd);
|
||||
|
||||
login_list_add(url, lidets);
|
||||
login_list_add(session->url, lidets);
|
||||
browser_window_go(session->bwin, session->url, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue