summaryrefslogtreecommitdiffstats
path: root/src/map.c
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-04-02 18:20:46 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-04-02 18:20:46 -0400
commita1a2c09c608cd58aa8189c9f21c4619045700d06 (patch)
treecebd2feb8c9645e1d3b5cdde57e914d16a466d89 /src/map.c
parent22ff4ffb24db349456ffdd207c5b5c9119d85e49 (diff)
downloadslapi-nis-a1a2c09c608cd58aa8189c9f21c4619045700d06.tar.gz
slapi-nis-a1a2c09c608cd58aa8189c9f21c4619045700d06.tar.xz
slapi-nis-a1a2c09c608cd58aa8189c9f21c4619045700d06.zip
- remove ldap'isms from the map structures
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c143
1 files changed, 45 insertions, 98 deletions
diff --git a/src/map.c b/src/map.c
index c09cff0..a15e11b 100644
--- a/src/map.c
+++ b/src/map.c
@@ -23,15 +23,10 @@ struct {
char *name;
struct map {
char *name;
- char *search_base;
- int search_scope;
- char *entry_filter;
- char *key_attribute;
- char *value_format;
time_t last_changed;
struct entry {
struct entry *prev, *next;
- char *dn;
+ char *id;
char *key;
unsigned int key_len;
char *value;
@@ -107,8 +102,8 @@ map_data_find_entry(struct plugin_state *state,
key);
}
static struct entry *
-map_data_find_map_entry_dn(struct plugin_state *state,
- struct map *map, const char *dn)
+map_data_find_map_entry_id(struct plugin_state *state,
+ struct map *map, const char *id)
{
int i;
struct entry *entry;
@@ -116,22 +111,22 @@ map_data_find_map_entry_dn(struct plugin_state *state,
return NULL;
}
for (entry = map->entries; entry != NULL; entry = entry->next) {
- if (strcmp(entry->dn, dn) == 0) {
+ if (strcmp(entry->id, id) == 0) {
return entry;
}
}
return NULL;
}
static struct entry *
-map_data_find_entry_dn(struct plugin_state *state,
+map_data_find_entry_id(struct plugin_state *state,
const char *domain_name, const char *map_name,
- const char *dn)
+ const char *id)
{
- return map_data_find_map_entry_dn(state,
+ return map_data_find_map_entry_id(state,
map_data_find_map(state,
domain_name,
map_name),
- dn);
+ id);
}
/* Query function: check if we have a record for the domain. Return that
@@ -276,15 +271,10 @@ map_data_unset_map(struct plugin_state *state,
if (i < domain->n_maps) {
/* ... free the map's contents. */
free(map.name);
- free(map.search_base);
- map.search_scope = -1;
- free(map.entry_filter);
- free(map.key_attribute);
- free(map.value_format);
map.last_changed = 0;
for (entry = map.entries; entry != NULL; entry = next) {
next = entry->next;
- free(entry->dn);
+ free(entry->id);
entry->key_len = 0;
free(entry->key);
entry->value_len = 0;
@@ -314,20 +304,31 @@ map_data_unset_map(struct plugin_state *state,
}
}
}
-
-/* Add a map from the configuration, adding a domain for it if necessary. */
+/* Remove all of the entries in a map. */
+static void
+map_data_clear_map(struct plugin_state *state, struct map *map)
+{
+ struct entry *entry, *next;
+ /* Clear the old entries list. */
+ for (entry = map->entries; entry != NULL; entry = next) {
+ next = entry->next;
+ free(entry->id);
+ entry->key_len = 0;
+ free(entry->key);
+ entry->value_len = 0;
+ free(entry->value);
+ free(entry);
+ }
+ map->entries = NULL;
+}
+/* Add a map structure, adding a domain for it if necessary. */
static void
map_data_set_map(struct plugin_state *state,
const char *domain_name,
- const char *map_name,
- const char *search_base,
- int search_scope,
- const char *entry_filter,
- const char *key_attribute,
- const char *value_format)
+ const char *map_name)
{
struct domain *domain, *domains;
- struct map *map, *maps, map_template;
+ struct map *map, *maps;
struct entry *entry, *next;
int i;
/* Locate the domain for this map. */
@@ -371,48 +372,7 @@ map_data_set_map(struct plugin_state *state,
}
}
/* We need to either create a new map entry or mess with an old one. */
- if (map != NULL) {
- /* Overwrite map data. */
- memset(&map_template, 0, sizeof(map_template));
- map_template.name = map->name;
- map_template.search_base = strdup(search_base);
- map_template.search_scope = search_scope;
- map_template.entry_filter = strdup(entry_filter);
- map_template.key_attribute = strdup(key_attribute);
- map_template.value_format = strdup(value_format);
- if ((map_template.name != NULL) &&
- (map_template.search_base != NULL) &&
- (map_template.entry_filter != NULL) &&
- (map_template.key_attribute != NULL) &&
- (map_template.value_format != NULL)) {
- /* Free the old search configuration. */
- free(map->search_base);
- free(map->entry_filter);
- free(map->key_attribute);
- free(map->value_format);
- /* Clear the old entries list. */
- for (entry = map->entries;
- entry != NULL;
- entry = next) {
- next = entry->next;
- free(entry->dn);
- entry->key_len = 0;
- free(entry->key);
- entry->value_len = 0;
- free(entry->value);
- free(entry);
- }
- /* Actually overwrite the map data. */
- *map = map_template;
- } else {
- free(map_template.search_base);
- free(map_template.entry_filter);
- free(map_template.key_attribute);
- free(map_template.value_format);
- /* XXX */
- return;
- }
- } else {
+ if (map == NULL) {
/* Allocate space. */
maps = malloc(sizeof(*map) * (domain->n_maps + 1));
if (maps != NULL) {
@@ -420,16 +380,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->search_base = strdup(search_base);
- map->search_scope = search_scope;
- map->entry_filter = strdup(entry_filter);
- map->key_attribute = strdup(key_attribute);
- map->value_format = strdup(value_format);
- if ((map->name != NULL) &&
- (map->search_base != NULL) &&
- (map->entry_filter != NULL) &&
- (map->key_attribute != NULL) &&
- (map->value_format != NULL)) {
+ if (map->name != NULL) {
/* Copy in existing data. */
memcpy(maps, domain->maps,
sizeof(*map) * domain->n_maps);
@@ -439,10 +390,6 @@ map_data_set_map(struct plugin_state *state,
domain->n_maps++;
} else {
free(map->name);
- free(map->search_base);
- free(map->entry_filter);
- free(map->key_attribute);
- free(map->value_format);
free(maps);
/* XXX */
return;
@@ -470,7 +417,7 @@ map_data_unset_map_entry(struct plugin_state *state,
if (map->entries == entry) {
map->entries = next;
}
- free(entry->dn);
+ free(entry->id);
free(entry->key);
free(entry->value);
free(entry);
@@ -492,32 +439,32 @@ map_data_unset_entry(struct plugin_state *state,
}
static void
-map_data_unset_entry_dn(struct plugin_state *state,
+map_data_unset_entry_id(struct plugin_state *state,
const char *domain_name,
const char *map_name,
- const char *dn)
+ const char *id)
{
struct map *map;
struct entry *entry;
map = map_data_find_map(state, domain_name, map_name);
- entry = map_data_find_map_entry_dn(state, map, dn);
+ entry = map_data_find_map_entry_id(state, map, id);
map_data_unset_map_entry(state, map, entry);
}
static void
-map_data_set_entry_dn(struct plugin_state *state,
- const char *domain_name,
- const char *map_name,
- const char *dn,
- unsigned int key_len,
- char *key,
- unsigned int value_len,
- char *value)
+map_data_set_entry(struct plugin_state *state,
+ const char *domain_name,
+ const char *map_name,
+ const char *id,
+ unsigned int key_len,
+ char *key,
+ unsigned int value_len,
+ char *value)
{
struct map *map;
struct entry *entry;
map = map_data_find_map(state, domain_name, map_name);
- entry = map_data_find_map_entry_dn(state, map, dn);
+ entry = map_data_find_map_entry_id(state, map, id);
if (entry != NULL) {
free(entry->key);
free(entry->value);
@@ -529,7 +476,7 @@ map_data_set_entry_dn(struct plugin_state *state,
entry = malloc(sizeof(*entry));
if (entry != NULL) {
memset(entry, 0, sizeof(*entry));
- entry->dn = strdup(dn);
+ entry->id = strdup(id);
entry->key = key;
entry->key_len = key_len;
entry->value = value;