5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2005 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* silccore/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.
33 /****s* silccore/SilcIDCacheAPI/SilcIDCacheEntry
37 * typedef struct SilcIDCacheEntryStruct { ... } SilcIDCacheEntry;
41 * This is an entry in the SILC ID Cache system. This context is
42 * allocated by adding new entry to ID cache by calling silc_idcache_add.
43 * Each of the fields in the structure are allocated by the caller.
47 typedef struct SilcIDCacheEntryStruct {
48 struct SilcIDCacheEntryStruct *next;
49 void *id; /* Associated ID */
50 char *name; /* Associated entry name */
51 void *context; /* Associated context */
55 /****s* silccore/SilcIDCacheAPI/SilcIDCache
59 * typedef struct SilcIDCacheStruct *SilcIDCache;
63 * This context is the actual ID Cache and is allocated by
64 * silc_idcache_alloc and given as argument usually to all
65 * silc_idcache_* functions. It is freed by the
66 * silc_idcache_free function.
69 typedef struct SilcIDCacheStruct *SilcIDCache;
71 /****f* silccore/SilcIDCacheAPI/SilcIDCacheDestructor
75 * typedef void (*SilcIDCacheDestructor)(SilcIDCache cache,
76 * const SilcIDCacheEntry entry,
77 * void *destructor_context,
82 * Destructor callback given as argument to silc_idcache_alloc. This
83 * is called when an entry is deleted from the cache. Application
84 * must free the contents of the `entry'.
87 typedef void (*SilcIDCacheDestructor)(SilcIDCache cache,
88 const SilcIDCacheEntry entry,
89 void *destructor_context,
94 /****f* silccore/SilcIDCacheAPI/silc_idcache_alloc
98 * SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
99 * SilcIDCacheDestructor destructor,
100 * void *destructor_context,
101 * SilcBool delete_id, SilcBool delete_name);
105 * Allocates new ID cache object. The initial amount of allocated entries
106 * can be sent as argument. If `count' is 0 the system uses default values.
107 * The `id_type' defines the types of the ID's that will be saved to the
111 SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
112 SilcIDCacheDestructor destructor,
113 void *destructor_context);
115 /****f* silccore/SilcIDCacheAPI/silc_idcache_free
119 * void silc_idcache_free(SilcIDCache cache);
123 * Frees ID cache context and all cache entries.
126 void silc_idcache_free(SilcIDCache cache);
128 /****f* silccore/SilcIDCacheAPI/silc_idcache_add
133 * silc_idcache_add(SilcIDCache cache, char *name, void *id, void *context);
137 * Add new entry to the cache. Returns the allocated cache entry if the
138 * entry was added successfully, or NULL if error occurred. The `name' is
139 * the name associated with the ID, the `id' the actual ID and the
140 * `context' a caller specific context.
142 * The `name', `id' and `context' pointers will be stored in the cache,
143 * and if the caller frees these pointers the caller is also responsible
144 * of deleting the cache entry.
148 silc_idcache_add(SilcIDCache cache, char *name, void *id, void *context);
150 /****f* silccore/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* silccore/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* silccore/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* silccore/SilcIDCacheAPI/silc_idcache_update_id
204 * SilcBool silc_idcache_update(SilcIDCache cache, SilcIDCacheEntry entry,
205 * void *old_id, void *new_id,
206 * char *old_name, char *new_name);
210 * Updates cache `entry' with new values. If the `new_id' is non-NULL
211 * then the `entry' will be updated with `new_id'. If the `new_name' is
212 * non-NULL then the `entry' will be updated with `new_name'. The
213 * caller is responsible of freeing the old values that was added with
217 SilcBool silc_idcache_update(SilcIDCache cache, SilcIDCacheEntry entry,
218 void *old_id, void *new_id,
219 char *old_name, char *new_name);
221 /****f* silccore/SilcIDCacheAPI/silc_idcache_get_all
225 * SilcBool silc_idcache_get_all(SilcIDCache cache, SilcList *ret_list);
229 * Returns all cache entries into the SilcList `ret_list' pointer. Each
230 * entry in the list is SilcIDCacheEntry. Returns FALSE if the cache
234 SilcBool silc_idcache_get_all(SilcIDCache cache, SilcList *ret_list);
236 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_id
240 * SilcBool silc_idcache_find_by_id(SilcIDCache cache, void *id,
241 * SilcList *ret_list);
245 * Find ID Cache entry by ID. This may return multiple entries.
246 * The entires are returned into the `ret_list' SilcList context.
247 * Returns TRUE if entry was found.
251 * If this function is used to find Client ID (SilcClientID), only the
252 * hash portion of the Client ID is compared. Use the function
253 * silc_idcache_find_by_id_one to find exact match for Client ID (full
254 * ID is compared and not only the hash).
256 * Comparing only the hash portion of Client ID allows searching of
257 * Client ID's by nickname, because the hash is based on the nickname.
258 * As nicknames are not unique, multiple entries may be found.
261 SilcBool silc_idcache_find_by_id(SilcIDCache cache, void *id,
264 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_id_one
268 * SilcBool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
269 * SilcIDCacheEntry *ret);
273 * Find ID Cache entry by ID. Returns only one entry from the cache
274 * and the found entry is considered to be exact match. Returns TRUE
275 * if the entry was found.
278 SilcBool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
279 SilcIDCacheEntry *ret);
281 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_context
285 * SilcBool silc_idcache_find_by_context(SilcIDCache cache, void *context,
286 * SilcIDCacheEntry *ret);
290 * Find cache entry by user specified context. Returns TRUE if the
294 SilcBool silc_idcache_find_by_context(SilcIDCache cache, void *context,
295 SilcIDCacheEntry *ret);
297 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_name
301 * SilcBool silc_idcache_find_by_name(SilcIDCache cache, char *name,
302 * SilcList *ret_list);
306 * Find cache entries by the name associated with the ID. This may
307 * return multiple entries to the `ret_list' SilcList context. Returns
308 * TRUE if the entry was found.
311 SilcBool silc_idcache_find_by_name(SilcIDCache cache, char *name,
314 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_name_one
318 * SilcBool silc_idcache_find_by_name_one(SilcIDCache cache, char *name,
319 * SilcIDCacheEntry *ret);
323 * Find cache entry by the name associated with the ID. This returns
324 * one entry and the found entry is considered to be exact match.
325 * Returns TRUE if the entry was found.
328 SilcBool silc_idcache_find_by_name_one(SilcIDCache cache, char *name,
329 SilcIDCacheEntry *ret);
331 #endif /* SILCIDCACHE_H */