summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-05-09 15:16:55 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-05-09 15:16:55 -0400
commit9072067335cbd7e873a380e392a16983a440e288 (patch)
tree9ff21a54bbabedf4433e54b5d12e588c7fc91492 /src
parent04db20825eeeb042e5688bcdf1ebc17925f40fd9 (diff)
downloadslapi-nis-9072067335cbd7e873a380e392a16983a440e288.tar.gz
slapi-nis-9072067335cbd7e873a380e392a16983a440e288.tar.xz
slapi-nis-9072067335cbd7e873a380e392a16983a440e288.zip
- add foreach for entries to the map
- add visited ID list as an additional argument when setting entries - actually make a copy of the visited and unique ID when setting entries
Diffstat (limited to 'src')
-rw-r--r--src/backend.c2
-rw-r--r--src/map.c143
-rw-r--r--src/map.h22
3 files changed, 151 insertions, 16 deletions
diff --git a/src/backend.c b/src/backend.c
index e4839e6..b52b7f0 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -42,7 +42,7 @@ backend_map_entry_cb(Slapi_Entry *e, void *callback_data)
data->domain, data->map,
key[i], dn, value[j]);
map_data_set_entry(data->state, data->domain, data->map,
- dn,
+ dn, NULL,
-1, strdup(key[i]),
-1, strdup(value[j]));
}
diff --git a/src/map.c b/src/map.c
index 10be1be..387dfbf 100644
--- a/src/map.c
+++ b/src/map.c
@@ -27,7 +27,7 @@ struct {
time_t last_changed;
struct entry {
struct entry *prev, *next;
- char *id;
+ char *id, **visited_ids;
char *key;
unsigned int key_len;
char *value;
@@ -99,7 +99,7 @@ map_data_find_entry(struct plugin_state *state,
{
return map_data_find_map_entry(state,
map_data_find_map(state,
- domain_name,
+ domain_name,
map_name),
key_len,
key);
@@ -121,6 +121,118 @@ map_data_find_map_entry_id(struct plugin_state *state,
return NULL;
}
+static PRBool
+map_id_in_id_list(const char *id, char **id_list)
+{
+ while ((*id_list) != NULL) {
+ if (strcmp(id, (*id_list)) == 0) {
+ return TRUE;
+ }
+ id_list++;
+ }
+ return FALSE;
+}
+
+static char **
+map_id_dup_id_list(const char **in_id_list)
+{
+ int i, l;
+ char **ret, *s;
+ for (i = 0, l = 0; (in_id_list[i] != NULL); i++) {
+ l += (strlen(in_id_list[i]) + 1);
+ }
+ if (i == 0) {
+ return NULL;
+ }
+ ret = malloc((i + 1) * sizeof(char *) + l);
+ if (ret != NULL) {
+ s = (char *) &ret[i + 1];
+ for (i = 0; (in_id_list[i] != NULL); i++) {
+ ret[i] = s;
+ strcpy(s, in_id_list[i]);
+ s += (strlen(s) + 1);
+ }
+ ret[i] = NULL;
+ }
+ return ret;
+}
+
+static void
+map_id_free_id_list(char **id_list)
+{
+ free(id_list);
+}
+
+static PRBool
+map_data_foreach_entry(struct plugin_state *state,
+ PRBool all, const char *id, const char *visited_id,
+ PRBool (*fn)(const char *domain, const char *map,
+ const char *key, unsigned int key_len,
+ const char *value, unsigned int value_len,
+ const char *id, void *cbdata),
+ void *cbdata)
+{
+ int i, j;
+ struct domain *domain;
+ struct map *map;
+ struct entry *entry;
+ for (i = 0; i < map_data.n_domains; i++) {
+ domain = &map_data.domains[i];
+ for (j = 0; j < domain->n_maps; j++) {
+ map = &domain->maps[j];
+ for (entry = map->entries;
+ entry != NULL;
+ entry = entry->next) {
+ if (all ||
+ ((id != NULL) &&
+ (strcmp(id, entry->id) == 0)) ||
+ ((visited_id != NULL) &&
+ (map_id_in_id_list(visited_id,
+ entry->visited_ids)))) {
+ if (!(*fn)(domain->name, map->name,
+ entry->key,
+ entry->key_len,
+ entry->value,
+ entry->value_len,
+ entry->id, cbdata)) {
+ return FALSE;
+ }
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+
+PRBool
+map_data_foreach_entry_id(struct plugin_state *state, const char *id,
+ PRBool (*fn)(const char *domain, const char *map,
+ const char *key,
+ unsigned int key_len,
+ const char *value,
+ unsigned int value_len,
+ const char *id, void *cbdata),
+ void *cbdata)
+{
+ return map_data_foreach_entry(state, FALSE, id, NULL, fn, cbdata);
+}
+
+PRBool
+map_data_foreach_entry_visited_id(struct plugin_state *state,
+ const char *visited_id,
+ PRBool (*fn)(const char *domain,
+ const char *map,
+ const char *key,
+ unsigned int key_len,
+ const char *value,
+ unsigned int value_len,
+ const char *id, void *cbdata),
+ void *cbdata)
+{
+ return map_data_foreach_entry(state, FALSE, NULL, visited_id,
+ fn, cbdata);
+}
+
/* Query function: check if we have a record for the domain. Return that
* information in "supported", and return TRUE unless we ran into internal
* errors. */
@@ -461,6 +573,7 @@ map_data_set_entry(struct plugin_state *state,
const char *domain_name,
const char *map_name,
const char *id,
+ const char **visited_ids,
unsigned int key_len,
char *key,
unsigned int value_len,
@@ -484,24 +597,25 @@ map_data_set_entry(struct plugin_state *state,
entry->key_len = key_len;
entry->value = value;
entry->value_len = value_len;
+ free(entry->id);
+ entry->id = strdup(id);
+ map_id_free_id_list(entry->visited_ids);
+ entry->visited_ids = map_id_dup_id_list(visited_ids);
} else {
entry = malloc(sizeof(*entry));
if (entry != NULL) {
memset(entry, 0, sizeof(*entry));
+ entry->key = key;
+ entry->key_len = key_len;
+ entry->value = value;
+ entry->value_len = value_len;
entry->id = strdup(id);
- if (entry->id != NULL) {
- entry->key = key;
- entry->key_len = key_len;
- entry->value = value;
- entry->value_len = value_len;
- entry->next = map->entries;
- if (map->entries != NULL) {
- map->entries->prev = entry;
- }
- map->entries = entry;
- } else {
- /* XXX */
+ entry->visited_ids = map_id_dup_id_list(visited_ids);
+ entry->next = map->entries;
+ if (map->entries != NULL) {
+ map->entries->prev = entry;
}
+ map->entries = entry;
} else {
/* XXX */
}
@@ -515,6 +629,7 @@ map_startup(struct plugin_state *state)
{
backend_startup(state);
}
+
void
map_init(struct slapi_pblock *pb, struct plugin_state *state)
{
diff --git a/src/map.h b/src/map.h
index ec8e4ce..48ba5ae 100644
--- a/src/map.h
+++ b/src/map.h
@@ -42,6 +42,26 @@ void map_data_unset_entry_id(struct plugin_state *state,
const char *id);
void map_data_set_entry(struct plugin_state *state,
const char *domain_name, const char *map_name,
- const char *id,
+ const char *id, const char **visited_ids,
unsigned int key_len, char *key,
unsigned int value_len, char *value);
+PRBool map_data_foreach_entry_id(struct plugin_state *state, const char *id,
+ PRBool (*fn)(const char *domain,
+ const char *map,
+ const char *key,
+ unsigned int key_len,
+ const char *value,
+ unsigned int value_len,
+ const char *id, void *cbdata),
+ void *cbdata);
+PRBool map_data_foreach_entry_visited_id(struct plugin_state *state,
+ const char *visited_id,
+ PRBool (*fn)(const char *domain,
+ const char *map,
+ const char *key,
+ unsigned int key_len,
+ const char *value,
+ unsigned int value_len,
+ const char *id,
+ void *cbdata),
+ void *cbdata);