Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/common/dict.h
blob: ee231e1da0a56c40d2931404d42972d156a60991 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
   dict.h - dictionary functions
   This file is part of the nss-pam-ldapd library.

   Copyright (C) 2007, 2008, 2009 Arthur de Jong

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301 USA
*/

#ifndef COMMON__DICT_H
#define COMMON__DICT_H

#include "compat/attrs.h"

/*
   These functions provide a mapping between a case insensitive
   string and a pointer.
*/
typedef struct dictionary DICT;

/* Create a new instance of a dictionary. Returns NULL
   in case of memory allocation errors. */
DICT *dict_new(void)
  LIKE_MALLOC MUST_USE;

/* Add a relation in the dictionary. The key is duplicated
   and can be reused by the caller. The pointer is just stored.
   This function returns non-0 in case of memory allocation
   errors. If the key was previously in use the value
   is replaced. All key comparisons are case insensitive. */
int dict_put(DICT *dict,const char *key,void *value);

/* Look up a key in the dictionary and return the associated
   value. NULL is returned if the key is not found in the dictionary.
   All key comparisons are case insensitive. */
void *dict_get(DICT *dict,const char *key)
  MUST_USE;

/* Delete a key-value association from the dictionary.
   All key comparisons are case insensitive. */
/*void dict_del(DICT *dict,const char *key);*/

/* Remove the dictionary from memory. All allocated storage
   for the dictionary and the keys is freed.
   Note that values are not freed. This is the responsibility
   of the caller. */
void dict_free(DICT *dict);

/* Return the keys of the dict as a list of strings.
   The caller should free the memory with a single call to free(). */
const char **dict_keys(DICT *dict)
  MUST_USE;

#endif /* COMMON__DICT_H */