key encoding gained a cache() method, allows caching of externally created encodings
This commit is contained in:
@@ -185,6 +185,31 @@ static bool encode(private_key_encoding_t *this, key_encoding_type_t type,
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of key_encoding_t.cache
|
||||||
|
*/
|
||||||
|
static void cache(private_key_encoding_t *this, key_encoding_type_t type,
|
||||||
|
void *cache, chunk_t encoding)
|
||||||
|
{
|
||||||
|
chunk_t *chunk;
|
||||||
|
|
||||||
|
if (type >= KEY_ENCODING_MAX || type < 0)
|
||||||
|
{
|
||||||
|
return free(encoding.ptr);
|
||||||
|
}
|
||||||
|
chunk = malloc_thing(chunk_t);
|
||||||
|
*chunk = encoding;
|
||||||
|
this->lock->write_lock(this->lock);
|
||||||
|
chunk = this->cache[type]->put(this->cache[type], cache, chunk);
|
||||||
|
this->lock->unlock(this->lock);
|
||||||
|
/* free an encoding already associated to the cache */
|
||||||
|
if (chunk)
|
||||||
|
{
|
||||||
|
free(chunk->ptr);
|
||||||
|
free(chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of key_encoding_t.clear_cache
|
* Implementation of key_encoding_t.clear_cache
|
||||||
*/
|
*/
|
||||||
@@ -262,6 +287,7 @@ key_encoding_t *key_encoding_create()
|
|||||||
|
|
||||||
this->public.encode = (bool(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t *encoding, ...))encode;
|
this->public.encode = (bool(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t *encoding, ...))encode;
|
||||||
this->public.get_cache = (bool(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t *encoding))get_cache;
|
this->public.get_cache = (bool(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t *encoding))get_cache;
|
||||||
|
this->public.cache = (void(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t encoding))cache;
|
||||||
this->public.clear_cache = (void(*)(key_encoding_t*, void *cache))clear_cache;
|
this->public.clear_cache = (void(*)(key_encoding_t*, void *cache))clear_cache;
|
||||||
this->public.add_encoder = (void(*)(key_encoding_t*, key_encoder_t encoder))add_encoder;
|
this->public.add_encoder = (void(*)(key_encoding_t*, key_encoder_t encoder))add_encoder;
|
||||||
this->public.remove_encoder = (void(*)(key_encoding_t*, key_encoder_t encoder))remove_encoder;
|
this->public.remove_encoder = (void(*)(key_encoding_t*, key_encoder_t encoder))remove_encoder;
|
||||||
|
|||||||
@@ -154,12 +154,25 @@ struct key_encoding_t {
|
|||||||
*
|
*
|
||||||
* @param type format of the key encoding
|
* @param type format of the key encoding
|
||||||
* @param cache key to use for caching, as given to encode()
|
* @param cache key to use for caching, as given to encode()
|
||||||
* @encoding encoding result, internal data
|
* @param encoding encoding result, internal data
|
||||||
* @return TRUE if cache entry found
|
* @return TRUE if cache entry found
|
||||||
*/
|
*/
|
||||||
bool (*get_cache)(key_encoding_t *this, key_encoding_type_t type,
|
bool (*get_cache)(key_encoding_t *this, key_encoding_type_t type,
|
||||||
void *cache, chunk_t *encoding);
|
void *cache, chunk_t *encoding);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache a key encoding created externally.
|
||||||
|
*
|
||||||
|
* After calling cache(), the passed encoding is owned by the key encoding
|
||||||
|
* facility.
|
||||||
|
*
|
||||||
|
* @param type format of the key encoding
|
||||||
|
* @param cache key to use for caching, as given to encode()
|
||||||
|
* @param encoding encoding to cache, gets owned by this
|
||||||
|
*/
|
||||||
|
void (*cache)(key_encoding_t *this, key_encoding_type_t type, void *cache,
|
||||||
|
chunk_t encoding);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a key encoder function.
|
* Register a key encoder function.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user