summaryrefslogtreecommitdiffstats
path: root/src/lib-ldap/ldap-iterator.c
blob: d825f6cee98fb6da8cdbf70e9b4f130efc119565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "array.h"
#include "ldap-private.h"

struct ldap_search_iterator* ldap_search_iterator_init(struct ldap_result *result)
{
	struct ldap_search_iterator *iter;

	i_assert(result->openldap_ret == LDAP_SUCCESS);
	i_assert(result->error_string == NULL);

	iter = p_new(result->pool, struct ldap_search_iterator, 1);
	iter->result = result;
	return iter;
}

const struct ldap_entry *ldap_search_iterator_next(struct ldap_search_iterator *iter)
{
	if (iter->idx >= array_count(&iter->result->entries))
		return NULL;
	return array_idx(&iter->result->entries, iter->idx++);
}

void ldap_search_iterator_deinit(struct ldap_search_iterator **iter)
{
	*iter = NULL;
}