summaryrefslogtreecommitdiffstats
path: root/src/lib-storage/mail-search-register.h
blob: 16e9427d50e606e66a7499d56e5e1ba984bcdce0 (plain)
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
#ifndef MAIL_SEARCH_REGISTER_H
#define MAIL_SEARCH_REGISTER_H

struct mail_search_arg;
struct mail_search_build_context;

struct mail_search_register_arg {
	const char *key;

	/* returns parsed arg or NULL if error. error message is set to ctx. */
	struct mail_search_arg *
		(*build)(struct mail_search_build_context *ctx);
};

typedef struct mail_search_arg *
mail_search_register_fallback_t(struct mail_search_build_context *ctx,
				const char *key);

struct mail_search_register *mail_search_register_init(void);
void mail_search_register_deinit(struct mail_search_register **reg);

void mail_search_register_add(struct mail_search_register *reg,
			      const struct mail_search_register_arg *arg,
			      unsigned int count);
/* Register a fallback handler. It's responsible for giving also the
   "unknown key" error. */
void mail_search_register_fallback(struct mail_search_register *reg,
				   mail_search_register_fallback_t *fallback);

/* Return all registered args sorted. */
const struct mail_search_register_arg *
mail_search_register_get(struct mail_search_register *reg,
			 unsigned int *count_r);

/* Find key's registered arg, or NULL if not found. */
const struct mail_search_register_arg *
mail_search_register_find(struct mail_search_register *reg, const char *key);
/* Get registered fallback arg. Returns FALSE if fallback hasn't been
   registered. */
bool mail_search_register_get_fallback(struct mail_search_register *reg,
				       mail_search_register_fallback_t **fallback_r);

struct mail_search_register *mail_search_register_get_imap(void);
struct mail_search_register *mail_search_register_get_human(void);

#endif