Initial revision
[silc.git] / lib / silccore / idcache.h
1 /*
2
3   idcache.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
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.
13   
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.
18
19 */
20
21 #ifndef IDCACHE_H
22 #define IDCACHE_H
23
24 /* 
25    SilcIDCache structure.
26
27    char *data
28
29       The data that is usually used to find the data from the cache.
30       For example for Client ID's this is nickname.
31
32    SilcIdType type
33
34       Type of the ID.
35
36    void *id
37
38       The actual ID.
39
40    unsigned long expire
41
42       Time when this cache entry expires.  This is normal time() value
43       plus the validity.  Cache entry has expired if current time is
44       more than value in this field, or if this field has been set to
45       zero (0) value.
46
47    void *context
48
49       Any caller specified context.
50
51 */
52 typedef struct {
53   char *data;
54   SilcIdType type;
55   void *id;
56   unsigned long expire;
57   void *context;
58 } SilcIDCache;
59
60 #define SILC_ID_CACHE_EXPIRE 3600
61
62 /* Prototypes */
63 void silc_idcache_sort_by_data(SilcIDCache *cache, unsigned int count);
64 int silc_idcache_find_by_data(SilcIDCache *cache, unsigned int cache_count,
65                               char *data, SilcIDCache **ret);
66 int silc_idcache_find_by_id(SilcIDCache *cache, unsigned int cache_count, 
67                             void *id, SilcIdType type, SilcIDCache **ret);
68 int silc_idcache_add(SilcIDCache **cache, unsigned int cache_count,
69                      char *data, SilcIdType id_type, void *id, 
70                      void *context);
71 int silc_idcache_del(SilcIDCache *cache, SilcIDCache *old);
72 int silc_idcache_del_by_data(SilcIDCache *cache, unsigned int cache_count,
73                              char *data);
74 int silc_idcache_del_by_id(SilcIDCache *cache, unsigned int cache_count,
75                            SilcIdType type, void *id);
76 int silc_idcache_del_all(SilcIDCache **cache, unsigned int cache_count);
77 int silc_idcache_purge(SilcIDCache *cache, unsigned int cache_count);
78
79 #endif