1 /*
2  * Copyright (c) 2016, Vsevolod Stakhov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *	 * Redistributions of source code must retain the above copyright
8  *	   notice, this list of conditions and the following disclaimer.
9  *	 * Redistributions in binary form must reproduce the above copyright
10  *	   notice, this list of conditions and the following disclaimer in the
11  *	   documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 
25 
26 #ifndef INCLUDE_CACHE_H_
27 #define INCLUDE_CACHE_H_
28 
29 #include "config.h"
30 #include <stdint.h>
31 
32 #ifndef MAXKEYLEN
33 #define MAXKEYLEN 250
34 #endif
35 
36 struct config_file;
37 struct mlfi_priv;
38 
39 enum rmilter_query_type {
40 	RMILTER_QUERY_GREYLIST = 0,
41 	RMILTER_QUERY_WHITELIST,
42 	RMILTER_QUERY_RATELIMIT,
43 	RMILTER_QUERY_ID,
44 };
45 
46 enum rmilter_publish_type {
47 	RMILTER_PUBLISH_COPY = 0,
48 	RMILTER_PUBLISH_SPAM,
49 };
50 
51 /**
52  * Query cache (preferring redis) for the specified key
53  * @param cfg
54  * @param type type of query
55  * @param key key to check
56  * @param keylen length of the key
57  * @param data data returned by a server (must be freed by a caller)
58  * @param datalen pointer to length of data (out)
59  * @param priv pointer to useful information from milter protocol
60  * @return
61  */
62 bool rmilter_query_cache (struct config_file *cfg, enum rmilter_query_type type,
63 		const unsigned char *key, size_t keylen,
64 		unsigned char **data, size_t *datalen, struct mlfi_priv *priv);
65 
66 bool rmilter_set_cache (struct config_file *cfg, enum rmilter_query_type type ,
67 		const unsigned char *key, size_t keylen,
68 		const unsigned char *data, size_t datalen, unsigned expire, struct mlfi_priv *priv);
69 
70 bool rmilter_delete_cache (struct config_file *cfg, enum rmilter_query_type type ,
71 		const unsigned char *key, size_t keylen, struct mlfi_priv *priv);
72 
73 int rmilter_publish_cache (struct config_file *cfg, enum rmilter_publish_type type,
74 		const unsigned char *channel, size_t channel_len,
75 		const unsigned char *data, size_t datalen, struct mlfi_priv *priv);
76 
77 #endif /* INCLUDE_CACHE_H_ */
78