]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: url: Add functions that obtain the effective port for the URL.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 21 Jan 2018 14:54:18 +0000 (15:54 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 09:07:37 +0000 (11:07 +0200)
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

index cb0f0affe9d5a203166db57c4f807ea9fb5ebe3b..5eb311c8d83d4db7c7c5a4ad6a4a01056cd40da7 100644 (file)
@@ -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
  */