projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Integer type name change.
[silc.git]
/
lib
/
silccore
/
silcidcache.c
diff --git
a/lib/silccore/silcidcache.c
b/lib/silccore/silcidcache.c
index 245e4dfb1c40e49334d9480fe17d5dc90862cc22..a28c6833034bc19cc92c0d2073593b1612f6cb94 100644
(file)
--- a/
lib/silccore/silcidcache.c
+++ b/
lib/silccore/silcidcache.c
@@
-87,9
+87,10
@@
struct SilcIDCacheStruct {
struct SilcIDCacheListStruct {
SilcIDCacheEntry cache[64];
SilcIDCacheEntry *cache_dyn;
struct SilcIDCacheListStruct {
SilcIDCacheEntry cache[64];
SilcIDCacheEntry *cache_dyn;
- uint32 cache_dyn_count;
- uint32 cache_count;
- uint32 pos;
+ SilcUInt32 cache_dyn_count;
+ SilcUInt32 cache_count;
+ SilcUInt32 pos;
+ bool dyn;
};
/* Allocates new ID cache object. The initial amount of allocated entries
};
/* Allocates new ID cache object. The initial amount of allocated entries
@@
-97,7
+98,7
@@
struct SilcIDCacheListStruct {
The `id_type' defines the types of the ID's that will be saved to the
cache. */
The `id_type' defines the types of the ID's that will be saved to the
cache. */
-SilcIDCache silc_idcache_alloc(
ui
nt32 count, SilcIdType id_type,
+SilcIDCache silc_idcache_alloc(
SilcUI
nt32 count, SilcIdType id_type,
SilcIDCacheDestructor destructor)
{
SilcIDCache cache;
SilcIDCacheDestructor destructor)
{
SilcIDCache cache;
@@
-106,9
+107,9
@@
SilcIDCache silc_idcache_alloc(uint32 count, SilcIdType id_type,
cache = silc_calloc(1, sizeof(*cache));
cache->id_table = silc_hash_table_alloc(count, silc_hash_id,
cache = silc_calloc(1, sizeof(*cache));
cache->id_table = silc_hash_table_alloc(count, silc_hash_id,
- (void *)(
ui
nt32)id_type,
+ (void *)(
SilcUI
nt32)id_type,
silc_hash_id_compare,
silc_hash_id_compare,
- (void *)(
ui
nt32)id_type,
+ (void *)(
SilcUI
nt32)id_type,
silc_idcache_destructor, NULL,
FALSE);
cache->name_table = silc_hash_table_alloc(count, silc_hash_string, NULL,
silc_idcache_destructor, NULL,
FALSE);
cache->name_table = silc_hash_table_alloc(count, silc_hash_string, NULL,
@@
-141,10
+142,9
@@
void silc_idcache_free(SilcIDCache cache)
the entry never expires from the cache. */
bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
the entry never expires from the cache. */
bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
- void *context, int expire)
+ void *context, int expire
, SilcIDCacheEntry *ret
)
{
SilcIDCacheEntry c;
{
SilcIDCacheEntry c;
- uint32 curtime = time(NULL);
SILC_LOG_DEBUG(("Adding cache entry"));
SILC_LOG_DEBUG(("Adding cache entry"));
@@
-152,7
+152,7
@@
bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
c = silc_calloc(1, sizeof(*c));
c->id = id;
c->name = name;
c = silc_calloc(1, sizeof(*c));
c->id = id;
c->name = name;
- c->expire =
(expire ? (curtime + SILC_ID_CACHE_EXPIRE) : 0)
;
+ c->expire =
expire
;
c->context = context;
/* Add the new entry to the hash tables */
c->context = context;
/* Add the new entry to the hash tables */
@@
-172,6
+172,9
@@
bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
silc_hash_table_rehash(cache->context_table, 0);
}
silc_hash_table_rehash(cache->context_table, 0);
}
+ if (ret)
+ *ret = c;
+
return TRUE;
}
return TRUE;
}
@@
-197,6
+200,8
@@
bool silc_idcache_del(SilcIDCache cache, SilcIDCacheEntry old)
ret = silc_hash_table_del(cache->context_table, old->context);
if (old->id)
ret = silc_hash_table_del(cache->id_table, old->id);
ret = silc_hash_table_del(cache->context_table, old->context);
if (old->id)
ret = silc_hash_table_del(cache->id_table, old->id);
+ else
+ silc_free(old);
return ret;
}
return ret;
}
@@
-262,6
+267,8
@@
bool silc_idcache_del_by_context(SilcIDCache cache, void *context)
ret = silc_hash_table_del(cache->context_table, c->context);
if (c->id)
ret = silc_hash_table_del_by_context(cache->id_table, c->id, c);
ret = silc_hash_table_del(cache->context_table, c->context);
if (c->id)
ret = silc_hash_table_del_by_context(cache->id_table, c->id, c);
+ else
+ silc_free(c);
return ret;
}
return ret;
}
@@
-289,7
+296,7
@@
static void silc_idcache_purge_foreach(void *key, void *context,
void *user_context)
{
SilcIDCache cache = (SilcIDCache)user_context;
void *user_context)
{
SilcIDCache cache = (SilcIDCache)user_context;
-
ui
nt32 curtime = time(NULL);
+
SilcUI
nt32 curtime = time(NULL);
SilcIDCacheEntry c = (SilcIDCacheEntry)context;
if (c->expire && c->expire < curtime) {
SilcIDCacheEntry c = (SilcIDCacheEntry)context;
if (c->expire && c->expire < curtime) {
@@
-499,7
+506,7
@@
static void silc_idcache_list_add(SilcIDCacheList list, SilcIDCacheEntry cache)
/* Try to add to static cache */
if (!list->cache_dyn_count)
/* Try to add to static cache */
if (!list->cache_dyn_count)
- for (i = 0; i <
sizeof(list->cache
); i++) {
+ for (i = 0; i <
(sizeof(list->cache) / sizeof(list->cache[0])
); i++) {
if (!list->cache[i]) {
list->cache[i] = cache;
list->cache_count++;
if (!list->cache[i]) {
list->cache[i] = cache;
list->cache_count++;
@@
-519,17
+526,17
@@
static void silc_idcache_list_add(SilcIDCacheList list, SilcIDCacheEntry cache)
if (i >= list->cache_dyn_count) {
int k;
if (i >= list->cache_dyn_count) {
int k;
- i
+= 5
;
+ i
= list->cache_dyn_count
;
list->cache_dyn = silc_realloc(list->cache_dyn,
list->cache_dyn = silc_realloc(list->cache_dyn,
- sizeof(*list->cache
) * (i
));
+ sizeof(*list->cache
_dyn) * (i + 5
));
/* NULL the reallocated area */
/* NULL the reallocated area */
- for (k =
list->cache_dyn_count; k < i
; k++)
+ for (k =
i; k < (i + 5)
; k++)
list->cache_dyn[k] = NULL;
list->cache_dyn[k] = NULL;
- list->cache_dyn[list->cache_dyn_count] = cache;
- list->cache_dyn_count = i;
+ list->cache_dyn[i] = cache;
list->cache_count++;
list->cache_count++;
+ list->cache_dyn_count += 5;
}
}
}
}
@@
-559,25
+566,25
@@
bool silc_idcache_list_first(SilcIDCacheList list, SilcIDCacheEntry *ret)
bool silc_idcache_list_next(SilcIDCacheList list, SilcIDCacheEntry *ret)
{
bool silc_idcache_list_next(SilcIDCacheList list, SilcIDCacheEntry *ret)
{
- int dyn = FALSE;
list->pos++;
list->pos++;
- if (list->pos >= sizeof(list->cache)) {
+ if (!list->dyn &&
+ list->pos >= (sizeof(list->cache) / sizeof(list->cache[0]))) {
list->pos = 0;
list->pos = 0;
- dyn = TRUE;
+
list->
dyn = TRUE;
}
}
- if (dyn && list->pos >= list->cache_dyn_count)
+ if (
list->
dyn && list->pos >= list->cache_dyn_count)
return FALSE;
return FALSE;
- if (!dyn && !list->cache[list->pos])
+ if (!
list->
dyn && !list->cache[list->pos])
return FALSE;
return FALSE;
- if (dyn && !list->cache_dyn[list->pos])
+ if (
list->
dyn && !list->cache_dyn[list->pos])
return FALSE;
if (ret) {
return FALSE;
if (ret) {
- if (!dyn)
+ if (!
list->
dyn)
*ret = list->cache[list->pos];
else
*ret = list->cache_dyn[list->pos];
*ret = list->cache[list->pos];
else
*ret = list->cache_dyn[list->pos];