Moved silc_client_ch[u]mode[_char] to client library from silc/.
[silc.git] / lib / silccore / idcache.h
1 /*
2
3   idcache.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 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    Silc ID Cache Entry object.
26
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.
31
32    char *data
33
34       The data that is usually used to find the data from the cache.
35       For example for Client ID's this is nickname.
36
37    SilcIdType type
38
39       Type of the ID.
40
41    void *id
42
43       The actual ID.
44
45    unsigned long expire
46
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, or if this field has been set to
50       zero (0) value.
51
52    void *context
53
54       Any caller specified context.
55
56 */
57 typedef struct {
58   char *data;
59   SilcIdType type;
60   void *id;
61   unsigned long expire;
62   void *context;
63 } *SilcIDCacheEntry;
64
65 /* Forward declaration for SILC ID Cache object. */
66 typedef struct SilcIDCacheStruct *SilcIDCache;
67
68 /* Forward declaration for ID Cache List */
69 typedef struct SilcIDCacheListStruct *SilcIDCacheList;
70
71 #define SILC_ID_CACHE_ANY ((void *)1)
72
73 #define SILC_ID_CACHE_EXPIRE 3600
74
75 /* Prototypes */
76 SilcIDCache silc_idcache_alloc(unsigned int count);
77 void silc_idcache_free(SilcIDCache cache);
78 void silc_idcache_sort_by_data(SilcIDCache cache);
79 int silc_idcache_find_by_data(SilcIDCache cache, char *data, 
80                               SilcIDCacheList *ret);
81 int silc_idcache_find_by_data_one(SilcIDCache cache, char *data,
82                                   SilcIDCacheEntry *ret);
83 int silc_idcache_find_by_data_loose(SilcIDCache cache, char *data, 
84                                     SilcIDCacheList *ret);
85 int silc_idcache_find_by_id(SilcIDCache cache, void *id, SilcIdType type,
86                             SilcIDCacheList *ret);
87 int silc_idcache_find_by_id_one(SilcIDCache cache, void *id, SilcIdType type, 
88                                 SilcIDCacheEntry *ret);
89 int silc_idcache_find_by_context(SilcIDCache cache, void *context, 
90                                  SilcIDCacheEntry *ret);
91 int silc_idcache_add(SilcIDCache cache, char *data, SilcIdType id_type,
92                      void *id, void *context, int sort);
93 int silc_idcache_del(SilcIDCache cache, SilcIDCacheEntry old);
94 int silc_idcache_del_by_data(SilcIDCache cache, char *data);
95 int silc_idcache_del_by_id(SilcIDCache cache, SilcIdType type, void *id);
96 int silc_idcache_del_all(SilcIDCache cache);
97 int silc_idcache_purge(SilcIDCache cache);
98 int silc_idcache_list_count(SilcIDCacheList list);
99 int silc_idcache_list_first(SilcIDCacheList list, SilcIDCacheEntry *ret);
100 int silc_idcache_list_next(SilcIDCacheList list, SilcIDCacheEntry *ret);
101 void silc_idcache_list_free(SilcIDCacheList list);
102
103 #endif