1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "mail-search.h"
#include "mail-search-register.h"
struct mail_search_register {
ARRAY(struct mail_search_register_arg) args;
mail_search_register_fallback_t *fallback;
bool args_sorted:1;
};
struct mail_search_register *mail_search_register_init(void)
{
struct mail_search_register *reg;
reg = i_new(struct mail_search_register, 1);
i_array_init(®->args, 64);
return reg;
}
void mail_search_register_deinit(struct mail_search_register **_reg)
{
struct mail_search_register *reg = *_reg;
*_reg = NULL;
array_free(®->args);
i_free(reg);
}
void mail_search_register_add(struct mail_search_register *reg,
const struct mail_search_register_arg *arg,
unsigned int count)
{
array_append(®->args, arg, count);
reg->args_sorted = FALSE;
}
void mail_search_register_fallback(struct mail_search_register *reg,
mail_search_register_fallback_t *fallback)
{
reg->fallback = fallback;
}
static int
mail_search_register_arg_cmp(const struct mail_search_register_arg *arg1,
const struct mail_search_register_arg *arg2)
{
return strcmp(arg1->key, arg2->key);
}
const struct mail_search_register_arg *
mail_search_register_get(struct mail_search_register *reg,
unsigned int *count_r)
{
if (!reg->args_sorted) {
array_sort(®->args, mail_search_register_arg_cmp);
reg->args_sorted = TRUE;
}
return array_get(®->args, count_r);
}
const struct mail_search_register_arg *
mail_search_register_find(struct mail_search_register *reg, const char *key)
{
struct mail_search_register_arg arg;
if (!reg->args_sorted) {
array_sort(®->args, mail_search_register_arg_cmp);
reg->args_sorted = TRUE;
}
arg.key = key;
return array_bsearch(®->args, &arg, mail_search_register_arg_cmp);
}
bool mail_search_register_get_fallback(struct mail_search_register *reg,
mail_search_register_fallback_t **fallback_r)
{
if (reg->fallback == NULL)
return FALSE;
*fallback_r = reg->fallback;
return TRUE;
}
|