1 |
// Copyright (C) 2003 Stephane Thiell |
2 |
// |
3 |
// This file is part of pxyscand (from pxys) |
4 |
// |
5 |
// This program is free software; you can redistribute it and/or |
6 |
// modify it under the terms of the GNU General Public License |
7 |
// as published by the Free Software Foundation; either version 2 |
8 |
// of the License, or (at your option) any later version. |
9 |
// |
10 |
// This program is distributed in the hope that it will be useful, |
11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
// GNU General Public License for more details. |
14 |
// |
15 |
// You should have received a copy of the GNU General Public License |
16 |
// along with this program; if not, write to the Free Software |
17 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
// |
19 |
#define RCSID "$Id: PXIPCacheT.cc,v 1.1.1.1 2003/12/30 17:09:00 mbuna Exp $" |
20 |
|
21 |
#include "PXIPCacheT.h" |
22 |
#include <peak/peak.h> |
23 |
|
24 |
// Specialized methods |
25 |
|
26 |
template<> |
27 |
PXIPCacheT<in_addr>::PXIPCacheT(const char *cachedir, uint32_t sig, int size, |
28 |
int expiredelay, size_t datasize) |
29 |
: mSig(sig), mExpireDelay(expiredelay) |
30 |
{ |
31 |
mCacheDir = peak_strdup(cachedir); |
32 |
mIPCache = ipcache_create_in4(size, datasize); |
33 |
} |
34 |
|
35 |
template<> |
36 |
PXIPCacheT<in6_addr>::PXIPCacheT(const char *cachedir, uint32_t sig, int size, |
37 |
int expiredelay, size_t datasize) |
38 |
: mSig(sig), mExpireDelay(expiredelay) |
39 |
{ |
40 |
mCacheDir = peak_strdup(cachedir); |
41 |
mIPCache = ipcache_create_in6(size, datasize); |
42 |
} |
43 |
|
44 |
template<> |
45 |
inline time_t |
46 |
PXIPCacheT<in_addr>::Get(const in_addr &addr, void **oinfo) |
47 |
{ |
48 |
this->Cleanup(); |
49 |
return ipcache_find_in4(mIPCache, &addr, oinfo); |
50 |
} |
51 |
|
52 |
template<> |
53 |
inline time_t |
54 |
PXIPCacheT<in6_addr>::Get(const in6_addr &addr, void **oinfo) |
55 |
{ |
56 |
this->Cleanup(); |
57 |
return ipcache_find_in6(mIPCache, &addr, oinfo); |
58 |
} |
59 |
|
60 |
template<> |
61 |
inline void |
62 |
PXIPCacheT<in_addr>::Put(const in_addr &addr, time_t t, const void *info) |
63 |
{ |
64 |
ipcache_add_in4(mIPCache, &addr, t, info); |
65 |
} |
66 |
|
67 |
template<> |
68 |
inline void |
69 |
PXIPCacheT<in6_addr>::Put(const in6_addr &addr, time_t t, const void *info) |
70 |
{ |
71 |
ipcache_add_in6(mIPCache, &addr, t, info); |
72 |
} |
73 |
|
74 |
template<> |
75 |
inline bool |
76 |
PXIPCacheT<in_addr>::Invalidate(const in_addr &addr) |
77 |
{ |
78 |
return ipcache_invalidate_in4(mIPCache, &addr) == 0; |
79 |
} |
80 |
|
81 |
template<> |
82 |
inline bool |
83 |
PXIPCacheT<in6_addr>::Invalidate(const in6_addr &addr) |
84 |
{ |
85 |
return ipcache_invalidate_in6(mIPCache, &addr) == 0; |
86 |
} |