5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2006 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 new value will be copied over the old value in the `entry'.
212 * If the `new_name' is non-NULL then the `entry' will be updated with
213 * `new_name'. The caller is responsible of freeing the old name if it
214 * was updated with new one. The old ID value does not need to be freed
215 * as the new value is copied over the old value.
218 SilcBool silc_idcache_update(SilcIDCache cache, SilcIDCacheEntry entry,
219 void *old_id, void *new_id,
220 char *old_name, char *new_name);
222 /****f* silccore/SilcIDCacheAPI/silc_idcache_get_all
226 * SilcBool silc_idcache_get_all(SilcIDCache cache, SilcList *ret_list);
230 * Returns all cache entries into the SilcList `ret_list' pointer. Each
231 * entry in the list is SilcIDCacheEntry. Returns FALSE if the cache
235 SilcBool silc_idcache_get_all(SilcIDCache cache, SilcList *ret_list);
237 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_id
241 * SilcBool silc_idcache_find_by_id(SilcIDCache cache, void *id,
242 * SilcList *ret_list);
246 * Find ID Cache entry by ID. This may return multiple entries.
247 * The entires are returned into the `ret_list' SilcList context.
248 * Returns TRUE if entry was found.
252 * If this function is used to find Client ID (SilcClientID), only the
253 * hash portion of the Client ID is compared. Use the function
254 * silc_idcache_find_by_id_one to find exact match for Client ID (full
255 * ID is compared and not only the hash).
257 * Comparing only the hash portion of Client ID allows searching of
258 * Client ID's by nickname, because the hash is based on the nickname.
259 * As nicknames are not unique, multiple entries may be found.
262 SilcBool silc_idcache_find_by_id(SilcIDCache cache, void *id,
265 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_id_one
269 * SilcBool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
270 * SilcIDCacheEntry *ret);
274 * Find ID Cache entry by ID. Returns only one entry from the cache
275 * and the found entry is considered to be exact match. Returns TRUE
276 * if the entry was found.
279 SilcBool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
280 SilcIDCacheEntry *ret);
282 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_context
286 * SilcBool silc_idcache_find_by_context(SilcIDCache cache, void *context,
287 * SilcIDCacheEntry *ret);
291 * Find cache entry by user specified context. Returns TRUE if the
295 SilcBool silc_idcache_find_by_context(SilcIDCache cache, void *context,
296 SilcIDCacheEntry *ret);
298 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_name
302 * SilcBool silc_idcache_find_by_name(SilcIDCache cache, char *name,
303 * SilcList *ret_list);
307 * Find cache entries by the name associated with the ID. This may
308 * return multiple entries to the `ret_list' SilcList context. Returns
309 * TRUE if the entry was found.
312 SilcBool silc_idcache_find_by_name(SilcIDCache cache, char *name,
315 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_name_one
319 * SilcBool silc_idcache_find_by_name_one(SilcIDCache cache, char *name,
320 * SilcIDCacheEntry *ret);
324 * Find cache entry by the name associated with the ID. This returns
325 * one entry and the found entry is considered to be exact match.
326 * Returns TRUE if the entry was found.
329 SilcBool silc_idcache_find_by_name_one(SilcIDCache cache, char *name,
330 SilcIDCacheEntry *ret);
332 #endif /* SILCIDCACHE_H */