Coverage Report

Created: 2026-12-01 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib-url/http-url.h
Line
Count
Source
1
#ifndef HTTP_URL_H
2
#define HTTP_URL_H
3
4
#include "net.h"
5
#include "uri-util.h"
6
7
#define HTTP_DEFAULT_PORT 80
8
#define HTTPS_DEFAULT_PORT 443
9
10
enum http_request_target_format {
11
  HTTP_REQUEST_TARGET_FORMAT_ORIGIN = 0,
12
  HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
13
  HTTP_REQUEST_TARGET_FORMAT_AUTHORITY,
14
  HTTP_REQUEST_TARGET_FORMAT_ASTERISK
15
};
16
17
/* Adding a field here also means updating http_url_equals() and any
18
   settings code that hashes this type. */
19
struct http_url {
20
  /* server */
21
  struct uri_host host;
22
  in_port_t port;
23
24
  /* userinfo (not parsed by default) */
25
  const char *user;
26
  const char *password;
27
28
  /* path */
29
  const char *enc_path; /* encoded */
30
  const char *path;
31
32
  /* ?query (still encoded) */
33
  const char *enc_query;
34
35
  /* #fragment (still encoded) */
36
  const char *enc_fragment;
37
38
  bool have_ssl:1;
39
};
40
41
/*
42
 * HTTP URL parsing
43
 */
44
45
enum http_url_parse_flags {
46
  /* Scheme part 'http:' is already parsed externally. This implies that
47
     this is an absolute HTTP URL. */
48
  HTTP_URL_PARSE_SCHEME_EXTERNAL  = 0x01,
49
  /* Allow '#fragment' part in HTTP URL */
50
  HTTP_URL_ALLOW_FRAGMENT_PART = 0x02,
51
  /* Allow 'user:password@' part in HTTP URL */
52
  HTTP_URL_ALLOW_USERINFO_PART = 0x04,
53
  /* Allow URL to contain %00 */
54
  HTTP_URL_ALLOW_PCT_NUL = 0x08,
55
};
56
57
int http_url_parse(const char *url, struct http_url *base,
58
       enum http_url_parse_flags flags, pool_t pool,
59
       struct http_url **url_r, const char **error_r);
60
61
/*
62
 * HTTP URL evaluation
63
 */
64
65
static inline in_port_t
66
http_url_get_port_default(const struct http_url *url, in_port_t default_port)
67
0
{
68
0
  return (url->port != 0 ? url->port : default_port);
69
0
}
Unexecuted instantiation: sasl-server-mech-oauth2.c:http_url_get_port_default
Unexecuted instantiation: oauth2.c:http_url_get_port_default
Unexecuted instantiation: settings-parser.c:http_url_get_port_default
Unexecuted instantiation: http-url.c:http_url_get_port_default
70
71
static inline in_port_t http_url_get_port(const struct http_url *url)
72
0
{
73
0
  return http_url_get_port_default(
74
0
    url, (url->have_ssl ? HTTPS_DEFAULT_PORT : HTTP_DEFAULT_PORT));
75
0
}
Unexecuted instantiation: sasl-server-mech-oauth2.c:http_url_get_port
Unexecuted instantiation: oauth2.c:http_url_get_port
Unexecuted instantiation: settings-parser.c:http_url_get_port
Unexecuted instantiation: http-url.c:http_url_get_port
76
77
/* Initializer for an unset URL, e.g. a settings default. */
78
#define HTTP_URL_INIT_EMPTY { .host = { .name = NULL } }
79
80
/* TRUE if the URL is unset, i.e. all-zero. Only meaningful for URLs that
81
   came from http_url_parse() with base == NULL, or that were
82
   zero-initialised. Does not tolerate url == NULL. */
83
static inline bool http_url_is_empty(const struct http_url *url)
84
0
{
85
0
  return url->host.name == NULL;
86
0
}
Unexecuted instantiation: sasl-server-mech-oauth2.c:http_url_is_empty
Unexecuted instantiation: oauth2.c:http_url_is_empty
Unexecuted instantiation: settings-parser.c:http_url_is_empty
Unexecuted instantiation: http-url.c:http_url_is_empty
87
88
bool http_url_equals(const struct http_url *url1, const struct http_url *url2);
89
90
/*
91
 * HTTP URL manipulation
92
 */
93
94
void http_url_init_authority_from(struct http_url *dest,
95
          const struct http_url *src);
96
void http_url_copy_authority(pool_t pool, struct http_url *dest,
97
           const struct http_url *src);
98
struct http_url *
99
http_url_clone_authority(pool_t pool, const struct http_url *src);
100
101
void http_url_copy(pool_t pool, struct http_url *dest,
102
       const struct http_url *src);
103
void http_url_copy_with_userinfo(pool_t pool, struct http_url *dest,
104
         const struct http_url *src);
105
106
struct http_url *http_url_clone(pool_t pool,const struct http_url *src);
107
struct http_url *
108
http_url_clone_with_userinfo(pool_t pool, const struct http_url *src);
109
110
/*
111
 * HTTP URL construction
112
 */
113
114
const char *http_url_create(const struct http_url *url);
115
116
const char *http_url_create_host(const struct http_url *url);
117
const char *http_url_create_authority(const struct http_url *url);
118
const char *http_url_create_target(const struct http_url *url);
119
120
void http_url_escape_path(string_t *out, const char *data);
121
void http_url_escape_param(string_t *out, const char *data);
122
123
#endif