From 777776de3515b6721381d2230c4182b6401cdce1 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Sun, 21 Jan 2018 15:54:18 +0100 Subject: [PATCH] lib-http: url: Add functions that obtain the effective port for the URL. When no port is set for the URL, it is set to 0. These functions substitute the applicable default. --- src/lib-http/http-url.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib-http/http-url.h b/src/lib-http/http-url.h index cb0f0affe9..5eb311c8d8 100644 --- a/src/lib-http/http-url.h +++ b/src/lib-http/http-url.h @@ -4,6 +4,8 @@ #include "net.h" #include "uri-util.h" +#include "http-common.h" + struct http_request_target; struct http_url { @@ -51,6 +53,22 @@ int http_url_request_target_parse(const char *request_target, const char *host_header, pool_t pool, struct http_request_target *target, const char **error_r); +/* + * HTTP URL evaluation + */ + +static inline in_port_t http_url_get_port_default(const struct http_url *url, + in_port_t default_port) +{ + return (url->port != 0 ? url->port : default_port); +} + +static inline in_port_t http_url_get_port(const struct http_url *url) +{ + return http_url_get_port_default(url, + (url->have_ssl ? HTTPS_DEFAULT_PORT : HTTP_DEFAULT_PORT)); +} + /* * HTTP URL manipulation */ -- 2.47.3