5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2007 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; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcapputil/SILC ID Cache Interface
24 * SILC ID Cache is an cache for all kinds of ID's used in the SILC
25 * protocol. Application can save here the ID's it uses and the interface
26 * provides fast retrieval of the ID's from the cache.
28 * SILC ID Cache is not thread-safe. If the same cache context must be
29 * used in multithreaded environment concurrency control must be employed.
36 /****s* silcapputil/SilcIDCacheAPI/SilcIDCacheEntry
40 * typedef struct SilcIDCacheEntryStruct { ... } SilcIDCacheEntry;
44 * This is an entry in the SILC ID Cache system. This context is
45 * allocated by adding new entry to ID cache by calling silc_idcache_add.
46 * Each of the fields in the structure are allocated by the caller.
50 typedef struct SilcIDCacheEntryStruct {
51 struct SilcIDCacheEntryStruct *next;
52 void *id; /* Associated ID */
53 char *name; /* Associated entry name */
54 void *context; /* Associated context */
58 /****s* silcapputil/SilcIDCacheAPI/SilcIDCache
62 * typedef struct SilcIDCacheStruct *SilcIDCache;
66 * This context is the actual ID Cache and is allocated by
67 * silc_idcache_alloc and given as argument usually to all
68 * silc_idcache_* functions. It is freed by the
69 * silc_idcache_free function.
72 typedef struct SilcIDCacheStruct *SilcIDCache;
74 /****f* silcapputil/SilcIDCacheAPI/SilcIDCacheDestructor
78 * typedef void (*SilcIDCacheDestructor)(SilcIDCache cache,
79 * const SilcIDCacheEntry entry,
80 * void *destructor_context,
85 * Destructor callback given as argument to silc_idcache_alloc. This
86 * is called when an entry is deleted from the cache. Application
87 * must free the contents of the `entry'.
90 typedef void (*SilcIDCacheDestructor)(SilcIDCache cache,
91 const SilcIDCacheEntry entry,
92 void *destructor_context,
97 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_alloc
101 * SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
102 * SilcIDCacheDestructor destructor,
103 * void *destructor_context,
104 * SilcBool delete_id, SilcBool delete_name);
108 * Allocates new ID cache object. The initial amount of allocated entries
109 * can be sent as argument. If `count' is 0 the system uses default values.
110 * The `id_type' defines the types of the ID's that will be saved to the
114 SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
115 SilcIDCacheDestructor destructor,
116 void *destructor_context);
118 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_free
122 * void silc_idcache_free(SilcIDCache cache);
126 * Frees ID cache context and all cache entries.
129 void silc_idcache_free(SilcIDCache cache);
131 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_add
136 * silc_idcache_add(SilcIDCache cache, char *name, void *id, void *context);
140 * Add new entry to the cache. Returns the allocated cache entry if the
141 * entry was added successfully, or NULL if error occurred. The `name' is
142 * the name associated with the ID, the `id' the actual ID and the
143 * `context' a caller specific context. The caller is responsible of
144 * freeing the `name' and `id' when the entry is deleted.
148 silc_idcache_add(SilcIDCache cache, char *name, void *id, void *context);
150 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_del
154 * SilcBool silc_idcache_del(SilcIDCache cache, SilcIDCacheEntry entry,
155 * void *app_context);
159 * Delete cache entry from cache. Returns TRUE if the entry was deleted.
160 * The destructor will be called for the entry. The `app_context' is
161 * delivered to the destructor.
164 SilcBool silc_idcache_del(SilcIDCache cache, SilcIDCacheEntry entry,
167 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_del_by_id
171 * SilcBool silc_idcache_del_by_id(SilcIDCache cache, void *id,
172 * void *app_context);
176 * Delete cache entry by ID. Returns TRUE if the entry was deleted.
177 * The destructor will be called for the entry. The `app_context' is
178 * delivered to the destructor.
181 SilcBool silc_idcache_del_by_id(SilcIDCache cache, void *id,
184 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_del_by_context
188 * SilcBool silc_idcache_del_by_context(SilcIDCache cache, void *context);
192 * Deletes cachen entry by the user specified context. Returns TRUE
193 * if the entry was deleted. The destructor will be called for the
194 * entry. The `app_context' is delivered to the destructor.
197 SilcBool silc_idcache_del_by_context(SilcIDCache cache, void *context,
200 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_update
204 * SilcBool silc_idcache_update(SilcIDCache cache, SilcIDCacheEntry entry,
205 * void *new_id, char *new_name,
206 * SilcBool free_old_name);
210 * Updates cache `entry' with new values. If the `new_id' is non-NULL
211 * then the new value will be copied over the old value in the `entry'
212 * unless the ID doesn't exist, when the `new_id' will be stored in `entry'.
213 * If the `new_name' is non-NULL then the `entry' will be updated with
214 * `new_name'. The caller is responsible of freeing the old name if it
215 * was updated with new one. The old ID value does not need to be freed
216 * as the new value is copied over the old value. If the `free_old_name'
217 * is TRUE the library will free the old name from the entry.
220 SilcBool silc_idcache_update(SilcIDCache cache, SilcIDCacheEntry entry,
221 void *new_id, char *new_name,
222 SilcBool free_old_name);
224 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_update_by_context
229 * silc_idcache_update_by_context(SilcIDCache cache, void *context,
230 * void *new_id, char *new_name,
231 * SilcBool free_old_name);
235 * Same as silc_idcache_update but finds the corrent ID cache entry by
236 * the `context' added to the ID cache.
239 SilcBool silc_idcache_update_by_context(SilcIDCache cache, void *context,
240 void *new_id, char *new_name,
241 SilcBool free_old_name);
243 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_get_all
247 * SilcBool silc_idcache_get_all(SilcIDCache cache, SilcList *ret_list);
251 * Returns all cache entries into the SilcList `ret_list' pointer. Each
252 * entry in the list is SilcIDCacheEntry. Returns FALSE if the cache
256 SilcBool silc_idcache_get_all(SilcIDCache cache, SilcList *ret_list);
258 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_find_by_id
262 * SilcBool silc_idcache_find_by_id(SilcIDCache cache, void *id,
263 * SilcList *ret_list);
267 * Find ID Cache entry by ID. This may return multiple entries.
268 * The entires are returned into the `ret_list' SilcList context.
269 * Returns TRUE if entry was found.
273 * If this function is used to find Client ID (SilcClientID), only the
274 * hash portion of the Client ID is compared. Use the function
275 * silc_idcache_find_by_id_one to find exact match for Client ID (full
276 * ID is compared and not only the hash).
278 * Comparing only the hash portion of Client ID allows searching of
279 * Client ID's by nickname, because the hash is based on the nickname.
280 * As nicknames are not unique, multiple entries may be found.
283 SilcBool silc_idcache_find_by_id(SilcIDCache cache, void *id,
286 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_find_by_id_one
290 * SilcBool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
291 * SilcIDCacheEntry *ret);
295 * Find ID Cache entry by ID. Returns only one entry from the cache
296 * and the found entry is considered to be exact match. Returns TRUE
297 * if the entry was found.
300 SilcBool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
301 SilcIDCacheEntry *ret);
303 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_find_by_context
307 * SilcBool silc_idcache_find_by_context(SilcIDCache cache, void *context,
308 * SilcIDCacheEntry *ret);
312 * Find cache entry by user specified context. Returns TRUE if the
316 SilcBool silc_idcache_find_by_context(SilcIDCache cache, void *context,
317 SilcIDCacheEntry *ret);
319 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_find_by_name
323 * SilcBool silc_idcache_find_by_name(SilcIDCache cache, char *name,
324 * SilcList *ret_list);
328 * Find cache entries by the name associated with the ID. This may
329 * return multiple entries to the `ret_list' SilcList context. Returns
330 * TRUE if the entry was found.
333 SilcBool silc_idcache_find_by_name(SilcIDCache cache, char *name,
336 /****f* silcapputil/SilcIDCacheAPI/silc_idcache_find_by_name_one
340 * SilcBool silc_idcache_find_by_name_one(SilcIDCache cache, char *name,
341 * SilcIDCacheEntry *ret);
345 * Find cache entry by the name associated with the ID. This returns
346 * one entry and the found entry is considered to be exact match.
347 * Returns TRUE if the entry was found.
350 SilcBool silc_idcache_find_by_name_one(SilcIDCache cache, char *name,
351 SilcIDCacheEntry *ret);
353 #endif /* SILCIDCACHE_H */