More RAII in the auth code.
This commit is contained in:
+5
-8
@@ -48,7 +48,7 @@ struct AuthHost_t
|
|||||||
struct AuthDialogData_t
|
struct AuthDialogData_t
|
||||||
{
|
{
|
||||||
const AuthParse_t *auth_parse;
|
const AuthParse_t *auth_parse;
|
||||||
const DilloUrl *url;
|
std::unique_ptr< const DilloUrl > url;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -538,7 +538,7 @@ static void Auth_do_auth_dialog_cb(const char *user, const char *password,
|
|||||||
data = (AuthDialogData_t *)vData;
|
data = (AuthDialogData_t *)vData;
|
||||||
|
|
||||||
/* find or create the host */
|
/* find or create the host */
|
||||||
if (!(host = Auth_host_by_url(data->url))) {
|
if (!(host = Auth_host_by_url(data->url.get()))) {
|
||||||
/* create a new host */
|
/* create a new host */
|
||||||
host = std::make_unique< AuthHost_t >().release();
|
host = std::make_unique< AuthHost_t >().release();
|
||||||
host->scheme = dStrdup(URL_SCHEME(data->url));
|
host->scheme = dStrdup(URL_SCHEME(data->url));
|
||||||
@@ -606,7 +606,6 @@ static int Auth_do_auth_dialog(const AuthParse_t *auth_parse,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *title, *msg;
|
char *title, *msg;
|
||||||
AuthDialogData_t *data;
|
|
||||||
const char *typestr = auth_parse->type == DIGEST ? "Digest" : "Basic";
|
const char *typestr = auth_parse->type == DIGEST ? "Digest" : "Basic";
|
||||||
|
|
||||||
_MSG("auth.c: Auth_do_auth_dialog: realm = '%s'\n", auth_parse->realm);
|
_MSG("auth.c: Auth_do_auth_dialog: realm = '%s'\n", auth_parse->realm);
|
||||||
@@ -615,13 +614,11 @@ static int Auth_do_auth_dialog(const AuthParse_t *auth_parse,
|
|||||||
msg = dStrconcat("The server at ", URL_HOST(url), " requires a username"
|
msg = dStrconcat("The server at ", URL_HOST(url), " requires a username"
|
||||||
" and password for \"", auth_parse->realm, "\".\n\n"
|
" and password for \"", auth_parse->realm, "\".\n\n"
|
||||||
"Authentication scheme: ", typestr, NULL);
|
"Authentication scheme: ", typestr, NULL);
|
||||||
data = std::make_unique< AuthDialogData_t >().release();
|
auto data = std::make_unique< AuthDialogData_t >();
|
||||||
data->auth_parse = auth_parse;
|
data->auth_parse = auth_parse;
|
||||||
data->url = a_Url_dup(url).release();
|
data->url = a_Url_dup(url);
|
||||||
ret = a_Dialog_user_password(title, msg, Auth_do_auth_dialog_cb, data);
|
ret = a_Dialog_user_password(title, msg, Auth_do_auth_dialog_cb, data.get());
|
||||||
dFree(title); dFree(msg);
|
dFree(title); dFree(msg);
|
||||||
delete const_cast< DilloUrl * >( data->url );
|
|
||||||
delete data;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user