aboutsummaryrefslogtreecommitdiffstats
path: root/src/map.h
blob: fa8669de30aa6af52186341ee75bb9fe0821753b (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef RSPAMD_MAP_H
#define RSPAMD_MAP_H

#include "config.h"
#include "mem_pool.h"
#include "radix.h"

enum fetch_proto {
	PROTO_FILE,
	PROTO_HTTP,
};

struct map_cb_data {
	int state;
	void *prev_data;
	void *cur_data;
};

struct file_map_data {
	const char *filename;
	struct stat st;
};

struct http_map_data {
	struct in_addr addr;
	uint16_t port;
	char *path;
	char *host;
	time_t last_checked;
	gboolean chunked;
	u_char read_buf[BUFSIZ];
	uint32_t rlen;
	uint32_t chunk;
	uint32_t chunk_read;
};

typedef u_char* (*map_cb_t)(memory_pool_t *pool, u_char *chunk, size_t len, struct map_cb_data *data);
typedef void (*map_fin_cb_t)(memory_pool_t *pool, struct map_cb_data *data);

struct rspamd_map {
	memory_pool_t *pool;
	enum fetch_proto protocol;
	map_cb_t read_callback;
	map_fin_cb_t fin_callback;
	void **user_data;
	struct event ev;
	struct timeval tv;
	void *map_data;
};

gboolean add_map (const char *map_line, map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data);
void start_map_watch (void);

/* Common callbacks */
u_char* read_radix_list (memory_pool_t *pool, u_char *chunk, size_t len, struct map_cb_data *data);
void fin_radix_list (memory_pool_t *pool, struct map_cb_data *data);
u_char* read_host_list (memory_pool_t *pool, u_char *chunk, size_t len, struct map_cb_data *data);
void fin_host_list (memory_pool_t *pool, struct map_cb_data *data);

#endif