From 5b4f160b9440172108e3806cdc30fa080a6c3c7e Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Tue, 10 Jun 2008 11:48:05 -0400 Subject: - keep track of whether a map is "secure" or not, returning that information when we're asked for information --- src/map.c | 45 +++++++++++++++++++++++++++++++++++++-------- src/map.h | 12 ++++++++---- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/map.c b/src/map.c index a009571..ad4c5df 100644 --- a/src/map.c +++ b/src/map.c @@ -55,6 +55,7 @@ struct { /* Map name and order. */ char *name; time_t last_changed; + bool_t secure; /* Individual map entries. */ struct map_entry { /* Links to previous and next nodes in the @@ -205,6 +206,7 @@ static bool_t map_data_foreach_entry(struct plugin_state *state, bool_t all, const char *id, bool_t (*fn)(const char *domain, const char *map, + bool_t secure, const char *key, unsigned int key_len, const char *value, unsigned int value_len, const char *id, void *cbdata), @@ -225,6 +227,7 @@ map_data_foreach_entry(struct plugin_state *state, ((id != NULL) && (strcmp(id, entry->id) == 0))) { if (!(*fn)(domain->name, map->name, + map->secure, entry->key, entry->key_len, entry->value, @@ -243,6 +246,7 @@ map_data_foreach_entry(struct plugin_state *state, bool_t map_data_foreach_entry_id(struct plugin_state *state, const char *id, bool_t (*fn)(const char *domain, const char *map, + bool_t secure, const char *key, unsigned int key_len, const char *value, @@ -260,6 +264,7 @@ bool_t map_data_foreach_map(struct plugin_state *state, const char *domain_name, bool_t (*fn)(const char *domain, const char *map, + bool_t secure, void *backend_data, void *cbdata), void *cbdata) @@ -276,8 +281,8 @@ map_data_foreach_map(struct plugin_state *state, const char *domain_name, } for (j = 0; j < domain->n_maps; j++) { map = &domain->maps[j]; - if (!(*fn)(domain->name, map->name, map->backend_data, - cbdata)) { + if (!(*fn)(domain->name, map->name, map->secure, + map->backend_data, cbdata)) { return FALSE; } } @@ -303,9 +308,16 @@ map_supports_domain(struct plugin_state *state, bool_t map_supports_map(struct plugin_state *state, const char *domain_name, const char *map_name, - bool_t *supported) + bool_t *supported, bool_t *secure) { - *supported = (map_data_find_map(state, domain_name, map_name) != NULL); + struct map *map; + map = map_data_find_map(state, domain_name, map_name); + if (supported != NULL) { + *supported = (map != NULL); + } + if (secure != NULL) { + *secure = map && map->secure; + } return TRUE; } @@ -352,14 +364,21 @@ map_order(struct plugin_state *state, bool_t map_match(struct plugin_state *state, const char *domain_name, const char *map_name, + bool_t *secure, unsigned int key_len, char *key, unsigned int *value_len, char **value) { + struct map *map; struct map_entry *entry; - entry = map_data_find_entry(state, domain_name, map_name, key_len, key); + map = map_data_find_map(state, domain_name, map_name); + if (map == NULL) { + return FALSE; + } + entry = map_data_find_map_entry(state, map, key_len, key); if (entry == NULL) { return FALSE; } + *secure = map->secure; *value_len = entry->value_len; *value = entry->value; return TRUE; @@ -370,6 +389,7 @@ map_match(struct plugin_state *state, bool_t map_first(struct plugin_state *state, const char *domain_name, const char *map_name, + bool_t *secure, unsigned int *first_key_len, char **first_key, unsigned int *first_value_len, char **first_value) { @@ -383,6 +403,7 @@ map_first(struct plugin_state *state, if (entry == NULL) { return FALSE; } + *secure = map->secure; *first_key_len = entry->key_len; *first_key = entry->key; *first_value_len = entry->value_len; @@ -395,17 +416,22 @@ map_first(struct plugin_state *state, * key in the map. */ bool_t map_next(struct plugin_state *state, - const char *domain_name, const char *map_name, + const char *domain_name, const char *map_name, bool_t *secure, unsigned int prev_len, const char *prev, unsigned int *next_key_len, char **next_key, unsigned int *next_value_len, char **next_value) { + struct map *map; struct map_entry *entry; - entry = map_data_find_entry(state, domain_name, map_name, - prev_len, prev); + map = map_data_find_map(state, domain_name, map_name); + if (map == NULL) { + return FALSE; + } + entry = map_data_find_map_entry(state, map, prev_len, prev); if ((entry == NULL) || (entry->next == NULL)) { return FALSE; } + *secure = map->secure; *next_key_len = entry->next->key_len; *next_key = entry->next->key; *next_value_len = entry->next->value_len; @@ -523,6 +549,7 @@ void map_data_set_map(struct plugin_state *state, const char *domain_name, const char *map_name, + bool_t secure, void *backend_data, void (*free_backend_data)(void *backend_data)) { @@ -578,6 +605,7 @@ map_data_set_map(struct plugin_state *state, map = &maps[domain->n_maps]; memset(map, 0, sizeof(*map)); map->name = strdup(map_name); + map->secure = secure; map->backend_data = backend_data; map->free_backend_data = free_backend_data; if (map->name != NULL) { @@ -597,6 +625,7 @@ map_data_set_map(struct plugin_state *state, } else { /* There's already a map there, we just need to update the * data we're keeping track of for the backend. */ + map->secure = secure; if (map->free_backend_data != NULL) { map->free_backend_data(map->backend_data); } diff --git a/src/map.h b/src/map.h index 1850921..e5aeda1 100644 --- a/src/map.h +++ b/src/map.h @@ -33,17 +33,18 @@ bool_t map_supports_domain(struct plugin_state *state, bool_t map_supports_map(struct plugin_state *state, const char *domain, const char *map, - bool_t *supported); + bool_t *supported, + bool_t *secure); bool_t map_match(struct plugin_state *state, - const char *domain, const char *map, + const char *domain, const char *map, bool_t *secure, unsigned int key_len, char *key, unsigned int *value_len, char **value); bool_t map_first(struct plugin_state *state, - const char *domain, const char *map, + const char *domain, const char *map, bool_t *secure, unsigned int *first_key_len, char **first_key, unsigned int *first_value_len, char **first_value); bool_t map_next(struct plugin_state *state, - const char *domain, const char *map, + const char *domain, const char *map, bool_t *secure, unsigned int prev_len, const char *prev, unsigned int *next_key_len, char **next_key, unsigned int *next_value_len, char **next_value); @@ -57,6 +58,7 @@ void map_data_unset_map(struct plugin_state *state, const char *domain_name, const char *map_name); void map_data_set_map(struct plugin_state *state, const char *domain_name, const char *map_name, + bool_t secure, void *backend_data, void (*free_backend_data)(void *p)); void map_data_unset_entry_key(struct plugin_state *state, const char *domain_name, const char *map_name, @@ -75,6 +77,7 @@ bool_t map_data_check_entry(struct plugin_state *state, bool_t map_data_foreach_entry_id(struct plugin_state *state, const char *id, bool_t (*fn)(const char *domain, const char *map, + bool_t secure, const char *key, unsigned int key_len, const char *value, @@ -84,6 +87,7 @@ bool_t map_data_foreach_entry_id(struct plugin_state *state, const char *id, bool_t map_data_foreach_map(struct plugin_state *state, const char *domain_name, bool_t (*fn)(const char *domain, const char *map, + bool_t secure, void *backend_data, void *cbdata), void *cbdata); -- cgit