dns: use alloca instead of malloc to fix memleak in dns_send_answer()
[project/mdnsd.git] / cache.h
1 /*
2  * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 2.1
6  * as published by the Free Software Foundation
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #ifndef _CACHE_H__
15 #define _CACHE_H__
16
17 #include <libubox/avl.h>
18 #include <libubox/list.h>
19
20 #include "dns.h"
21
22 struct cache_type {
23         struct avl_node avl;
24
25         char *key;
26         char *val;
27 };
28
29 struct cache_entry {
30         struct avl_node avl;
31
32         char *entry;
33         char *host;
34         uint32_t ttl;
35         time_t time;
36 };
37
38 struct cache_record {
39         struct avl_node avl;
40
41         char *record;
42         uint16_t type;
43         uint32_t ttl;
44         int port;
45         char *txt;
46         uint8_t *rdata;
47         uint16_t rdlength;
48         time_t time;
49 };
50
51 extern struct avl_tree records, entries, types;
52
53 extern int cache_init(void);
54 extern void cache_scan(void);
55 extern void cache_cleanup(void);
56 extern void cache_answer(struct uloop_fd *u, uint8_t *base, int blen,
57                 char *name, struct dns_answer *a, uint8_t *rdata);
58 extern int cache_host_is_known(char *record);
59 extern char* cache_lookup_name(const char *key);
60
61 #endif