Commit 68bb513b authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

http: add Basic authentication realm helper

parent 3a9cf31c
......@@ -954,6 +954,24 @@ int vlc_http_msg_add_cookies(struct vlc_http_msg *m,
return val;
}
char *vlc_http_msg_get_basic_realm(const struct vlc_http_msg *m)
{
const char *auth;
/* TODO: Support other authentication schemes. */
/* NOTE: In principles, RFC7235 allows for multiple authentication schemes,
* including multiple times Basic with a different realm each. There are no
* UI paradigms though. */
auth = vlc_http_msg_get_token(m, "WWW-Authenticate", "Basic");
if (auth == NULL)
return NULL;
auth += 5;
auth += strspn(auth, " "); /* 1*SP */
return vlc_http_get_token_value(auth, "realm");
}
int vlc_http_msg_add_creds_basic(struct vlc_http_msg *m, bool proxy,
const char *username, const char *password)
{
......
......@@ -148,6 +148,8 @@ void vlc_http_msg_get_cookies(const struct vlc_http_msg *,
int vlc_http_msg_add_cookies(struct vlc_http_msg *,
struct vlc_http_cookie_jar_t *);
char *vlc_http_msg_get_basic_realm(const struct vlc_http_msg *);
/**
* Adds Basic credentials.
*
......
......@@ -356,3 +356,11 @@ int vlc_http_res_set_login(struct vlc_http_resource *res,
return 0;
}
char *vlc_http_res_get_basic_realm(struct vlc_http_resource *res)
{
int status = vlc_http_res_get_status(res);
if (status != 401)
return NULL;
return vlc_http_msg_get_basic_realm(res->response);
}
......@@ -98,6 +98,7 @@ struct block_t *vlc_http_res_read(struct vlc_http_resource *);
int vlc_http_res_set_login(struct vlc_http_resource *res,
const char *username, const char *password);
char *vlc_http_res_get_basic_realm(struct vlc_http_resource *res);
/** @} */
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment