1 /*
2  * This file is part of the Sofia-SIP package
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  *
6  * Contact: Pekka Pessi <pekka.pessi@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 
25 #ifndef SOFIA_RESOLV_SRES_CACHE_H
26 /** Defined when <sofia-resolv/sres_cache.h> has been included. */
27 #define SOFIA_RESOLV_SRES_CACHE_H
28 /**
29  * @file sofia-resolv/sres_cache.h Sofia DNS Resolver Cache.
30  *
31  * @author Pekka Pessi <Pekka.Pessi@nokia.com>,
32  *
33  * @par Include Context
34  * @code
35  * #include <sys/types.h>
36  * #include <sys/socket.h>
37  * #include <netinet/in.h>
38  * #include <sofia-resolv/sres_cache.h>
39  * @endcode
40  *
41  */
42 
43 #include "sofia-resolv/sres_config.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #ifndef SRES_CACHE_T
50 #define SRES_CACHE_T
51 /** Opaque type of DNS cache object. */
52 typedef struct sres_cache sres_cache_t;
53 #endif
54 
55 #ifndef SRES_RECORD_T
56 #define SRES_RECORD_T
57 /** Type representing any DNS record. */
58 typedef union sres_record sres_record_t;
59 #endif
60 
61 enum {
62   /** Cache cleanup interval in seconds. */
63   SRES_CACHE_TIMER_INTERVAL = 5,
64 #define SRES_CACHE_TIMER_INTERVAL (SRES_CACHE_TIMER_INTERVAL)
65 };
66 
67 /** Create a resolver cache object. */
68 SRESPUBFUN sres_cache_t *sres_cache_new(int n);
69 
70 /** Increase reference count on a resolver cache object. */
71 SRESPUBFUN sres_cache_t *sres_cache_ref(sres_cache_t *);
72 
73 /** Decrease the reference count on a resolver cache object. */
74 SRESPUBFUN void sres_cache_unref(sres_cache_t *);
75 
76 /** Get a list of matching records from cache. */
77 SRESPUBFUN int sres_cache_get(sres_cache_t *cache,
78 			      uint16_t type,
79 			      char const *domain,
80 			      sres_record_t ***return_cached);
81 
82 /** Free answers not matching with type */
83 SRESPUBFUN int sres_cache_filter(sres_cache_t *cache,
84 				 sres_record_t **answers,
85 				 uint16_t type);
86 
87 /** Free the list records. */
88 SRESPUBFUN void sres_cache_free_answers(sres_cache_t *, sres_record_t **);
89 
90 /** Free and zero one record. */
91 SRESPUBFUN void sres_cache_free_one(sres_cache_t *, sres_record_t *answer);
92 
93 /** Copy list of records */
94 SRESPUBFUN
95 sres_record_t **sres_cache_copy_answers(sres_cache_t *, sres_record_t **);
96 
97 /** Remove old records from cache.  */
98 SRESPUBFUN void sres_cache_clean(sres_cache_t *cache, time_t now);
99 
100 /** Allocate a cache record */
101 SRESPUBFUN
102 sres_record_t *sres_cache_alloc_record(sres_cache_t *cache,
103 				       sres_record_t const *template,
104 				       size_t extra);
105 
106 /** Free a record that has not been stored. */
107 SRESPUBFUN void sres_cache_free_record(sres_cache_t *cache, void *rr);
108 
109 /** Store a record to cache */
110 SRESPUBFUN void sres_cache_store(sres_cache_t *, sres_record_t *, time_t now);
111 
112 /** Modify the priority in the specified SRV record */
113 SRESPUBFUN int sres_cache_set_srv_priority(sres_cache_t *,
114 					   char const *domain,
115 					   char const *target,
116 					   uint16_t port,
117 					   uint32_t newttl,
118 					   uint16_t newprio);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif /* SOFIA_RESOLV_SRES_CACHED_H */
125