From: Stephan Bosch Date: Sun, 21 Jan 2018 14:54:18 +0000 (+0100) Subject: lib-http: url: Add functions that obtain the effective port for the URL. X-Git-Tag: 2.3.1~99 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71c28aac43dd17aaa692a904e81ad286dd992e4f;p=thirdparty%2Fdovecot%2Fcore.git 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. --- 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 */