5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 2000 - 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
25 Silc ID Cache Entry object.
27 This is one entry in the SILC ID Cache system. Contents of this is
28 allocated outside the ID cache system, however, all the fields are
29 filled with ID cache utility functions. The ID cache system does not
30 allocate any of these fields nor free them. The system assumes that
31 the type of the ID in a specific ID Cache context are of the same
32 type. One should not mix different types of ID's (eg. Client ID and
33 Server ID) to the same ID Cache context.
38 The data that is usually used to find the data from the cache.
39 For example for Client ID's this is nickname.
47 Time when this cache entry expires. This is normal time() value
48 plus the validity. Cache entry has expired if current time is
49 more than value in this field. If this value is zero (0) the
54 Any caller specified context.
65 /* Forward declaration for SILC ID Cache object. */
66 typedef struct SilcIDCacheStruct *SilcIDCache;
68 /* Forward declaration for ID Cache List */
69 typedef struct SilcIDCacheListStruct *SilcIDCacheList;
71 /* Destructor callback that is called when an cache entry expires or is
72 purged from the ID cache. The application must not free cache entry
73 because the library will do it automatically. The appliation, however,
74 is responsible of freeing any data in the entry. */
75 typedef void (*SilcIDCacheDestructor)(SilcIDCache cache,
76 SilcIDCacheEntry entry);
78 #define SILC_ID_CACHE_ANY ((void *)1)
80 #define SILC_ID_CACHE_EXPIRE 3600
81 #define SILC_ID_CACHE_EXPIRE_DEF (time(NULL) + SILC_ID_CACHE_EXPIRE)
84 SilcIDCache silc_idcache_alloc(uint32 count, SilcIdType id_type,
85 SilcIDCacheDestructor destructor);
86 void silc_idcache_free(SilcIDCache cache);
87 bool silc_idcache_add(SilcIDCache cache, unsigned char *data,
88 uint32 data_len, void *id, void *context, int expire);
89 bool silc_idcache_del(SilcIDCache cache, SilcIDCacheEntry old);
90 bool silc_idcache_del_by_id(SilcIDCache cache, void *id);
91 bool silc_idcache_del_by_context(SilcIDCache cache, void *context);
92 bool silc_idcache_del_all(SilcIDCache cache);
93 bool silc_idcache_purge(SilcIDCache cache);
94 bool silc_idcache_purge_by_context(SilcIDCache cache, void *context);
95 bool silc_idcache_get_all(SilcIDCache cache, SilcIDCacheList *ret);
96 bool silc_idcache_find_by_id(SilcIDCache cache, void *id,
97 SilcIDCacheEntry *ret);
98 bool silc_idcache_find_by_context(SilcIDCache cache, void *context,
99 SilcIDCacheEntry *ret);
100 bool silc_idcache_find_by_data(SilcIDCache cache, unsigned char *data,
101 unsigned int data_len, SilcIDCacheList *ret);
102 bool silc_idcache_find_by_data_one(SilcIDCache cache, unsigned char *data,
103 unsigned int data_len,
104 SilcIDCacheEntry *ret);
105 int silc_idcache_list_count(SilcIDCacheList list);
106 bool silc_idcache_list_first(SilcIDCacheList list, SilcIDCacheEntry *ret);
107 bool silc_idcache_list_next(SilcIDCacheList list, SilcIDCacheEntry *ret);
108 void silc_idcache_list_free(SilcIDCacheList list);