Haiku: Update for new HTTP auth API.

This commit is contained in:
Michael Drake 2018-08-13 17:43:41 +01:00 committed by Michael Drake
parent 6144993c8a
commit e41e558c5f
3 changed files with 39 additions and 14 deletions

View File

@ -35,7 +35,12 @@ extern bool nsbeos_done;
extern bool replicated; extern bool replicated;
int gui_init_replicant(int argc, char** argv); int gui_init_replicant(int argc, char** argv);
extern "C" void gui_401login_open(struct nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw); extern "C" void nserror gui_401login_open(nsurl *url, const char *realm,
const char *username, const char *password,
nserror (*cb)(const char *username,
const char *password,
void *pw),
void *cbpw);
extern "C" void nsbeos_gui_poll(void); extern "C" void nsbeos_gui_poll(void);

View File

@ -44,7 +44,9 @@ extern "C" {
class LoginAlert : public BAlert { class LoginAlert : public BAlert {
public: public:
LoginAlert(nserror (*callback)(bool proceed, void *pw), LoginAlert(nserror (*callback)(const char *username,
const char *password,
void *pw),
void *callbaclpw, void *callbaclpw,
nsurl *url, nsurl *url,
const char *host, const char *host,
@ -57,7 +59,9 @@ private:
nsurl* fUrl; /**< URL being fetched */ nsurl* fUrl; /**< URL being fetched */
BString fHost; /**< Host for user display */ BString fHost; /**< Host for user display */
BString fRealm; /**< Authentication realm */ BString fRealm; /**< Authentication realm */
nserror (*fCallback)(bool proceed, void *pw); nserror (*fCallback)(const char *username,
const char *password,
void *pw);
void *fCallbackPw; void *fCallbackPw;
BTextControl *fUserControl; BTextControl *fUserControl;
@ -66,13 +70,17 @@ private:
static void create_login_window(nsurl *host, static void create_login_window(nsurl *host,
lwc_string *realm, const char *fetchurl, lwc_string *realm, const char *fetchurl,
nserror (*cb)(bool proceed, void *pw), void *cbpw); nserror (*cb)(const char *username,
const char *password,
void *pw), void *cbpw);
#define TC_H 25 #define TC_H 25
#define TC_MARGIN 10 #define TC_MARGIN 10
LoginAlert::LoginAlert(nserror (*callback)(bool proceed, void *pw), LoginAlert::LoginAlert(nserror (*callback)(const char *username,
const char *password,
void *pw),
void *callbackpw, void *callbackpw,
nsurl *url, nsurl *url,
const char *host, const char *host,
@ -164,8 +172,12 @@ LoginAlert::MessageReceived(BMessage *message)
} }
extern "C" void gui_401login_open(nsurl *url, const char *realm, extern "C" nserror gui_401login_open(nsurl *url, const char *realm,
nserror (*cb)(bool proceed, void *pw), void *cbpw) const char *username, const char *password,
nserror (*cb)(const char *username,
const char *password,
void *pw),
void *cbpw)
{ {
lwc_string *host; lwc_string *host;
@ -174,12 +186,17 @@ extern "C" void gui_401login_open(nsurl *url, const char *realm,
create_login_window(url, host, realm, cb, cbpw); create_login_window(url, host, realm, cb, cbpw);
free(host); free(host);
return NSERROR_OK;
} }
//void create_login_window(struct browser_window *bw, const char *host, //void create_login_window(struct browser_window *bw, const char *host,
// const char *realm, const char *fetchurl) // const char *realm, const char *fetchurl)
static void create_login_window(nsurl *url, lwc_string *host, static void create_login_window(nsurl *url, lwc_string *host,
const char *realm, nserror (*cb)(bool proceed, void *pw), const char *realm, nserror (*cb)(
const char *username,
const char *password,
void *pw),
void *cbpw) void *cbpw)
{ {
BString r("Secure Area"); BString r("Secure Area");

View File

@ -655,23 +655,26 @@ void nsbeos_dispatch_event(BMessage *message)
{ {
nsurl* url; nsurl* url;
BString realm; BString realm;
BString auth; BString username;
BString password;
void* cbpw; void* cbpw;
nserror (*cb)(bool proceed, void* pw); nserror (*cb)(const char *username,
const char *password,
void *pw);
if (message->FindPointer("URL", (void**)&url) < B_OK) if (message->FindPointer("URL", (void**)&url) < B_OK)
break; break;
if (message->FindString("Realm", &realm) < B_OK) if (message->FindString("Realm", &realm) < B_OK)
break; break;
if (message->FindString("Auth", &auth) < B_OK) if (message->FindString("User", &username) < B_OK)
break;
if (message->FindString("Pass", &password) < B_OK)
break; break;
if (message->FindPointer("callback", (void**)&cb) < B_OK) if (message->FindPointer("callback", (void**)&cb) < B_OK)
break; break;
if (message->FindPointer("callback_pw", (void**)&cbpw) < B_OK) if (message->FindPointer("callback_pw", (void**)&cbpw) < B_OK)
break; break;
//printf("login to '%s' with '%s'\n", url.String(), auth.String()); cb(username.String(), password.String(), cbpw);
urldb_set_auth_details(url, realm.String(), auth.String());
cb(true, cbpw);
break; break;
} }
default: default: