Coverage Report

Created: 2026-08-31 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib/idna.h
Line
Count
Source
1
#ifndef IDNA_H
2
#define IDNA_H
3
4
#define IDNA_DNS_MAX_LABEL_LENGTH 63
5
#define IDNA_DNS_MAX_NAME_LENGTH 254
6
7
struct unicode_code_point_data;
8
9
/*
10
 * Bidi Checking
11
 */
12
13
enum idna_bidi_check_state {
14
  IDNA_BIDI_CHECK_STATE_START = 0,
15
  IDNA_BIDI_CHECK_STATE_RTL,
16
  IDNA_BIDI_CHECK_STATE_LTR,
17
};
18
19
struct idna_bidi_check_context {
20
  bool rtl_label:1;
21
  bool valid:1;
22
};
23
24
struct idna_bidi_checker {
25
  enum idna_bidi_check_state state;
26
  struct idna_bidi_check_context *ctx;
27
28
  bool en_present:1;
29
  bool an_present:1;
30
  bool label_can_end:1;
31
};
32
33
static inline void
34
idna_bidi_checker_context_init(struct idna_bidi_check_context *ctx_r)
35
0
{
36
0
  i_zero(ctx_r);
37
0
  ctx_r->valid = TRUE;
38
0
  ctx_r->rtl_label = FALSE;
39
0
}
40
41
void idna_bidi_checker_init(struct idna_bidi_checker *ibc_r,
42
          struct idna_bidi_check_context *ctx);
43
void idna_bidi_checker_reset(struct idna_bidi_checker *ibc);
44
45
void idna_bidi_checker_input(struct idna_bidi_checker *ibc, uint32_t cp,
46
           const struct unicode_code_point_data **cp_data);
47
int idna_bidi_checker_finish(struct idna_bidi_checker *ibc);
48
49
/*
50
 * Code point context checker
51
 */
52
53
struct idna_context_checker {
54
  struct {
55
    unsigned int state;
56
    bool ccc_virama;
57
  } rule_200c;
58
  struct {
59
    bool ccc_virama;
60
  } rule_200d;
61
  struct {
62
    unsigned int state;
63
  } rule_00b7;
64
  struct {
65
    unsigned int state;
66
  } rule_0375;
67
  struct {
68
    bool script_hebrew;
69
  } rule_05f3;
70
  struct {
71
    bool seen_cp;
72
    bool seen_script;
73
  } rule_30fb;
74
  struct {
75
    bool seen_basic;
76
    bool seen_extended;
77
  } rule_0660;
78
79
  bool other:1;
80
};
81
82
void idna_context_checker_init(struct idna_context_checker *icc_r, bool other);
83
void idna_context_checker_reset(struct idna_context_checker *icc);
84
85
bool idna_context_checker_has_rule(struct idna_context_checker *icc,
86
           uint32_t cp);
87
88
int idna_context_checker_input(struct idna_context_checker *icc, uint32_t cp,
89
             const struct unicode_code_point_data **cp_data,
90
             const char **error_r);
91
int idna_context_checker_finish(struct idna_context_checker *icc,
92
        const char **error_r);
93
94
/* UnicodeĀ® Technical Standard #46, Section 4:
95
 *
96
 * Input:
97
 */
98
enum idna_process_flags {
99
  /* A boolean flag: UseSTD3ASCIIRules - inverted */
100
  IDNA_PROCESS_FLAG_IGNORE_STD3_ASCII_RULES = BIT(0),
101
  /* A boolean flag: CheckHyphens */
102
  IDNA_PROCESS_FLAG_CHECK_HYPHENS = BIT(1),
103
  /* A boolean flag: CheckBidi - inverted */
104
  IDNA_PROCESS_FLAG_IGNORE_BIDI = BIT(2),
105
  /* A boolean flag: CheckJoiners - inverted */
106
  IDNA_PROCESS_FLAG_IGNORE_JOINERS = BIT(3),
107
  /* A boolean flag: Transitional_Processing - always FALSE
108
     NOT IMPLEMENTED (deprecated) */
109
  /* A boolean flag: VerifyDnsLength - always TRUE
110
     NOT IMPLEMENTED (not useful) */
111
  /* A boolean flag: IgnoreInvalidPunycode - always FALSE
112
     NOT IMPLEMENTED (not useful) */
113
};
114
115
/* Check validity of domain name with respect to IDNA rules and (optionally)
116
   normalize the domain name fully to Unicode and/or ASCII. The t_unicode_r and
117
   to_ascii_r arguments may be NULL, indicating that these results are not
118
   requested. Returns -1 upon error and 0 otherwise. If -1 is returned, error_r
119
   is set to the error message. */
120
int idna_process_domain_name(const char *domain_name,
121
           enum idna_process_flags flags,
122
           const char **to_unicode_r, const char **to_ascii_r,
123
           const char **error_r);
124
125
#endif