diff options
Diffstat (limited to 'src/map.c')
-rw-r--r-- | src/map.c | 68 |
1 files changed, 57 insertions, 11 deletions
@@ -3,6 +3,7 @@ #endif #include <sys/types.h> +#include <pthread.h> #include <search.h> #include <stdlib.h> #include <string.h> @@ -22,21 +23,32 @@ /* The singleton for the cache. */ struct { + char *master; struct domain { char *name; struct map { + /* Map name and order. */ char *name; time_t last_changed; + /* Individual map entries. */ struct map_entry { + /* Links to previous and next nodes in the + * list. */ struct map_entry *prev, *next; + /* The name of the backend entry for this + * entry, and the names of others which + * contributed to the value. */ char *id, **related_ids; + /* Key and value. */ char *key; unsigned int key_len; char *value; unsigned int value_len; } *entries; + /* Search trees to speed up searches for entries. */ void *key_tree; void *id_tree; + /* Callback data supplied by the map writer. */ void *backend_data; void (*free_backend_data)(void *backend_data); } *maps; @@ -45,6 +57,18 @@ struct { int n_domains; } map_data; +static void * +xmemdup(char *region, int size) +{ + char *ret; + ret = malloc(size + 1); + if (ret != NULL) { + memcpy(ret, region, size); + ret[size] = '\0'; + } + return ret; +} + /* Comparison functions used by the tree storage facility. */ static int t_compare_entry_by_id(const void *p1, const void *p2) @@ -130,12 +154,9 @@ map_data_find_entry(struct plugin_state *state, const char *domain_name, const char *map_name, unsigned int key_len, const char *key) { - return map_data_find_map_entry(state, - map_data_find_map(state, - domain_name, - map_name), - key_len, - key); + struct map *map; + map = map_data_find_map(state, domain_name, map_name); + return map_data_find_map_entry(state, map, key_len, key); } static struct map_entry * @@ -345,6 +366,27 @@ map_supports_map(struct plugin_state *state, return TRUE; } +/* Query function: return the name of this master. */ +int +map_master_name(struct plugin_state *state, const char **master) +{ + char *tmp, hostname[HOST_NAME_MAX + 1]; + if (backend_read_master_name(state, &tmp) == 0) { + free(map_data.master); + map_data.master = strdup(tmp); + backend_free_master_name(state, tmp); + } else { + memset(hostname, '\0', sizeof(hostname)); + if (gethostname(hostname, sizeof(hostname)) != 0) { + snprintf(hostname, sizeof(hostname), "%s", "localhost"); + } + free(map_data.master); + map_data.master = strdup(hostname); + } + *master = map_data.master; + return 0; +} + /* Query function: return an indication of the map's age. Should never * decrease. */ PRBool @@ -456,8 +498,9 @@ void map_data_clear_map(struct plugin_state *state, const char *domain_name, const char *map_name) { - map_data_clear_map_map(state, - map_data_find_map(state, domain_name, map_name)); + struct map *map; + map = map_data_find_map(state, domain_name, map_name); + map_data_clear_map_map(state, map); } /* Remove a map from the configuration, removing its domain record if the map @@ -730,18 +773,21 @@ map_data_set_entry(struct plugin_state *state, /* XXX */ } } + map->last_changed = time(NULL); } - map->last_changed = time(NULL); } -void +int map_startup(struct plugin_state *state) { backend_startup(state); + return 0; } -void +int map_init(struct slapi_pblock *pb, struct plugin_state *state) { + memset(&map_data, 0, sizeof(map_data)); backend_init(pb, state); + return 0; } |