[vlc-commits] http: add Basic authentication realm helper

Rémi Denis-Courmont git at videolan.org
Tue Aug 30 20:54:41 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug 30 21:33:17 2016 +0300| [68bb513baa1e1bcf626865f3936edf58cf751089] | committer: Rémi Denis-Courmont

http: add Basic authentication realm helper

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=68bb513baa1e1bcf626865f3936edf58cf751089
---

 modules/access/http/message.c  | 18 ++++++++++++++++++
 modules/access/http/message.h  |  2 ++
 modules/access/http/resource.c |  8 ++++++++
 modules/access/http/resource.h |  1 +
 4 files changed, 29 insertions(+)

diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index 6efda5e..b9a41d0 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -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)
 {
diff --git a/modules/access/http/message.h b/modules/access/http/message.h
index 0c34e85..9693496 100644
--- a/modules/access/http/message.h
+++ b/modules/access/http/message.h
@@ -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.
  *
diff --git a/modules/access/http/resource.c b/modules/access/http/resource.c
index c8363fb..5863314 100644
--- a/modules/access/http/resource.c
+++ b/modules/access/http/resource.c
@@ -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);
+}
diff --git a/modules/access/http/resource.h b/modules/access/http/resource.h
index 1a5b21e..22b5aba 100644
--- a/modules/access/http/resource.h
+++ b/modules/access/http/resource.h
@@ -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



More information about the vlc-commits mailing list