aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cache.c36
-rw-r--r--src/cache.h3
-rw-r--r--src/lib-compat.c6
-rw-r--r--src/rcyn-client.c7
-rw-r--r--src/rcyn-protocol.txt4
5 files changed, 30 insertions, 26 deletions
diff --git a/src/cache.c b/src/cache.c
index c8e7550..0759f1f 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -255,10 +255,12 @@ cache_search(
) {
item_t *item;
- item = search(cache, key);
- if (item) {
- hit(cache, item);
- return (int)item->value;
+ if (cache) {
+ item = search(cache, key);
+ if (item) {
+ hit(cache, item);
+ return (int)item->value;
+ }
}
return -ENOENT;
}
@@ -281,18 +283,23 @@ cache_resize(
) {
cache_t *c = *cache, *nc;
- if (c)
- while (c->used > newsize)
- drop_lre(c);
+ if (newsize == 0) {
+ free(c);
+ nc = NULL;
+ } else {
+ if (c)
+ while (c->used > newsize)
+ drop_lre(c);
- nc = realloc(c, newsize - 1 + sizeof *c);
- if (nc == NULL)
- return -ENOMEM;
+ nc = realloc(c, newsize - 1 + sizeof *c);
+ if (nc == NULL)
+ return -ENOMEM;
- nc->count = newsize;
- if (!c) {
- nc->cacheid = 0;
- nc->used = 0;
+ nc->count = newsize;
+ if (!c) {
+ nc->cacheid = 0;
+ nc->used = 0;
+ }
}
*cache = nc;
return 0;
@@ -308,4 +315,3 @@ cache_create(
}
-
diff --git a/src/cache.h b/src/cache.h
index 4ddaa1e..dd37d92 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -56,6 +56,3 @@ cache_create(
cache_t **cache,
uint32_t size
);
-
-
-
diff --git a/src/lib-compat.c b/src/lib-compat.c
index 175ec5f..8f27cf3 100644
--- a/src/lib-compat.c
+++ b/src/lib-compat.c
@@ -147,7 +147,7 @@ struct cynara_admin;
int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin)
{
- return from_status(rcyn_open((rcyn_t**)pp_cynara_admin, rcyn_Admin, 0, 0));
+ return from_status(rcyn_open((rcyn_t**)pp_cynara_admin, rcyn_Admin, 1, 0));
}
int cynara_admin_finish(struct cynara_admin *p_cynara_admin)
@@ -409,7 +409,7 @@ int cynara_async_initialize(cynara_async **pp_cynara, const cynara_async_configu
if (p_cynara == NULL)
ret = CYNARA_API_OUT_OF_MEMORY;
else {
- ret = from_status(rcyn_open(&p_cynara->rcyn, rcyn_Check, p_conf ? p_conf->szcache : 0, 0));
+ ret = from_status(rcyn_open(&p_cynara->rcyn, rcyn_Check, p_conf ? p_conf->szcache : 1, 0));
if (ret != CYNARA_API_SUCCESS)
free(p_cynara);
else {
@@ -557,7 +557,7 @@ int cynara_configuration_set_cache_size(cynara_configuration *p_conf,
int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf)
{
- return from_status(rcyn_open((rcyn_t**)pp_cynara, rcyn_Check, p_conf ? p_conf->szcache : 0, 0));
+ return from_status(rcyn_open((rcyn_t**)pp_cynara, rcyn_Check, p_conf ? p_conf->szcache : 1, 0));
}
int cynara_finish(cynara *p_cynara)
diff --git a/src/rcyn-client.c b/src/rcyn-client.c
index 769c6c0..152dc87 100644
--- a/src/rcyn-client.c
+++ b/src/rcyn-client.c
@@ -38,6 +38,7 @@
#include "socket.h"
#define MIN_CACHE_SIZE 400
+#define CACHESIZE(x) ((x) >= MIN_CACHE_SIZE ? (x) : (x) ? MIN_CACHE_SIZE : 0)
struct asreq;
typedef struct asreq asreq_t;
@@ -440,7 +441,7 @@ rcyn_open(
strcpy((char*)(rcyn+1), socketspec);
/* record type and weakly create cache */
- cache_create(&rcyn->cache, cache_size < MIN_CACHE_SIZE ? MIN_CACHE_SIZE : cache_size);
+ cache_create(&rcyn->cache, CACHESIZE(cache_size));
rcyn->type = type;
rcyn->socketspec = socketspec;
rcyn->async.controlcb = NULL;
@@ -550,7 +551,7 @@ check_or_test(
rc = wait_pending_reply(rcyn);
if (rc >= 0) {
rc = status_check(rcyn, &expire);
- if (rc >= 0)
+ if (rcyn->cache && rc >= 0)
cache_put(rcyn->cache, key, rc, expire);
}
}
@@ -689,7 +690,7 @@ rcyn_cache_resize(
rcyn_t *rcyn,
uint32_t size
) {
- return cache_resize(&rcyn->cache, size < MIN_CACHE_SIZE ? MIN_CACHE_SIZE : size);
+ return cache_resize(&rcyn->cache, CACHESIZE(size));
}
void
diff --git a/src/rcyn-protocol.txt b/src/rcyn-protocol.txt
index 582a912..b2f1ae6 100644
--- a/src/rcyn-protocol.txt
+++ b/src/rcyn-protocol.txt
@@ -57,9 +57,9 @@ register agent (agent):
c->s agent NAME [ARGS...]
s->c done|error ...
-asking (agent ask CLIENT SESSION USER PERMISSION):
+ask agent (agent):
- s->c ask CLIENT SESSION USER PERMISSION
+ s->c ask NAME VALUE CLIENT SESSION USER PERMISSION
c->s done | ([yes|no] [always|session|one-time|EXPIRE])