[vlc-commits] http: factor and document vlc_http_authority()
Rémi Denis-Courmont
git at videolan.org
Sun Oct 4 13:30:45 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct 4 13:38:05 2020 +0300| [e7e7f6c72145d489edf2ba89d290449fe1e3ea47] | committer: Rémi Denis-Courmont
http: factor and document vlc_http_authority()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e7e7f6c72145d489edf2ba89d290449fe1e3ea47
---
modules/access/http/message.c | 12 ++++++++++++
modules/access/http/message.h | 10 ++++++++++
modules/access/http/resource.c | 12 ------------
modules/access/http/tunnel.c | 11 -----------
4 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index d6df07769e..d31a58520e 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -568,6 +568,18 @@ error:
/* Header helpers */
+char *vlc_http_authority(const char *host, unsigned port)
+{
+ static const char *const formats[4] = { "%s", "[%s]", "%s:%u", "[%s]:%u" };
+ const bool brackets = strchr(host, ':') != NULL;
+ const char *fmt = formats[brackets + 2 * (port != 0)];
+ char *authority;
+
+ if (unlikely(asprintf(&authority, fmt, host, port) == -1))
+ return NULL;
+ return authority;
+}
+
static int vlc_http_istoken(int c)
{ /* IETF RFC7230 §3.2.6 */
return (c >= '0' && c <= '9')
diff --git a/modules/access/http/message.h b/modules/access/http/message.h
index eec3bad9e4..0f91468cd9 100644
--- a/modules/access/http/message.h
+++ b/modules/access/http/message.h
@@ -75,6 +75,16 @@ void vlc_http_msg_destroy(struct vlc_http_msg *);
int vlc_http_msg_add_header(struct vlc_http_msg *, const char *name,
const char *fmt, ...) VLC_FORMAT(3,4);
+/**
+ * Formats an authority.
+ *
+ * @param host host name (cannot be NULL)
+ * @param port port number (0 for unspecified)
+ * @return the formatted authority as a heap-allocated nul-terminated string,
+ * or NULL on allocation failure
+ */
+char *vlc_http_authority(const char *host, unsigned port);
+
/**
* Sets the agent field.
*
diff --git a/modules/access/http/resource.c b/modules/access/http/resource.c
index 9a28bb50f3..5f5406a11c 100644
--- a/modules/access/http/resource.c
+++ b/modules/access/http/resource.c
@@ -165,18 +165,6 @@ void vlc_http_res_destroy(struct vlc_http_resource *res)
free(res);
}
-static char *vlc_http_authority(const char *host, unsigned port)
-{
- static const char *const formats[4] = { "%s", "[%s]", "%s:%u", "[%s]:%u" };
- const bool brackets = strchr(host, ':') != NULL;
- const char *fmt = formats[brackets + 2 * (port != 0)];
- char *authority;
-
- if (unlikely(asprintf(&authority, fmt, host, port) == -1))
- return NULL;
- return authority;
-}
-
int vlc_http_res_init(struct vlc_http_resource *restrict res,
const struct vlc_http_resource_cbs *cbs,
struct vlc_http_mgr *mgr,
diff --git a/modules/access/http/tunnel.c b/modules/access/http/tunnel.c
index b9c3c4bca0..ba6e3cb7b2 100644
--- a/modules/access/http/tunnel.c
+++ b/modules/access/http/tunnel.c
@@ -35,17 +35,6 @@
#include "conn.h"
#include "transport.h"
-static char *vlc_http_authority(const char *host, unsigned port)
-{
- static const char *const formats[2] = { "%s:%u", "[%s]:%u" };
- const bool brackets = strchr(host, ':') != NULL;
- char *authority;
-
- if (unlikely(asprintf(&authority, formats[brackets], host, port) == -1))
- return NULL;
- return authority;
-}
-
static struct vlc_http_msg *vlc_http_tunnel_open(struct vlc_http_conn *conn,
const char *hostname,
unsigned port,
More information about the vlc-commits
mailing list