Blame common/dict.h

Packit 6bd9ab
/*
Packit 6bd9ab
   dict.h - dictionary functions
Packit 6bd9ab
   This file is part of the nss-pam-ldapd library.
Packit 6bd9ab
Packit 6bd9ab
   Copyright (C) 2007, 2008, 2009, 2010, 2012 Arthur de Jong
Packit 6bd9ab
Packit 6bd9ab
   This library is free software; you can redistribute it and/or
Packit 6bd9ab
   modify it under the terms of the GNU Lesser General Public
Packit 6bd9ab
   License as published by the Free Software Foundation; either
Packit 6bd9ab
   version 2.1 of the License, or (at your option) any later version.
Packit 6bd9ab
Packit 6bd9ab
   This library is distributed in the hope that it will be useful,
Packit 6bd9ab
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6bd9ab
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6bd9ab
   Lesser General Public License for more details.
Packit 6bd9ab
Packit 6bd9ab
   You should have received a copy of the GNU Lesser General Public
Packit 6bd9ab
   License along with this library; if not, write to the Free Software
Packit 6bd9ab
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 6bd9ab
   02110-1301 USA
Packit 6bd9ab
*/
Packit 6bd9ab
Packit 6bd9ab
#ifndef COMMON__DICT_H
Packit 6bd9ab
#define COMMON__DICT_H
Packit 6bd9ab
Packit 6bd9ab
#include "compat/attrs.h"
Packit 6bd9ab
Packit 6bd9ab
/*
Packit 6bd9ab
   These functions provide a mapping between a string and a pointer.
Packit 6bd9ab
*/
Packit 6bd9ab
typedef struct dictionary DICT;
Packit 6bd9ab
Packit 6bd9ab
/* Create a new instance of a dictionary. Returns NULL
Packit 6bd9ab
   in case of memory allocation errors. */
Packit 6bd9ab
DICT *dict_new(void)
Packit 6bd9ab
  LIKE_MALLOC MUST_USE;
Packit 6bd9ab
Packit 6bd9ab
/* Add a relation in the dictionary. The key is duplicated
Packit 6bd9ab
   and can be reused by the caller. The pointer is just stored.
Packit 6bd9ab
   This function returns non-zero in case of memory allocation
Packit 6bd9ab
   errors. If the key was previously in use the value
Packit 6bd9ab
   is replaced. All key comparisons are case sensitive. */
Packit 6bd9ab
int dict_put(DICT *dict, const char *key, void *value);
Packit 6bd9ab
Packit 6bd9ab
/* Look up a key in the dictionary and return the associated
Packit 6bd9ab
   value. NULL is returned if the key is not found in the dictionary.
Packit 6bd9ab
   All key comparisons are case sensitive. */
Packit 6bd9ab
void *dict_get(DICT *dict, const char *key)
Packit 6bd9ab
  MUST_USE;
Packit 6bd9ab
Packit 6bd9ab
/* Get a key from the dictionary that has a value set. The caller does
Packit 6bd9ab
   not need to free the returned value (it is freed when dict_free()
Packit 6bd9ab
   is called). */
Packit 6bd9ab
const char *dict_getany(DICT *dict);
Packit 6bd9ab
Packit 6bd9ab
/* Delete a key-value association from the dictionary.
Packit 6bd9ab
   All key comparisons are case sensitive. */
Packit 6bd9ab
/*void dict_del(DICT *dict, const char *key);*/
Packit 6bd9ab
Packit 6bd9ab
/* Remove the dictionary from memory. All allocated storage
Packit 6bd9ab
   for the dictionary and the keys is freed.
Packit 6bd9ab
   Note that values are not freed. This is the responsibility
Packit 6bd9ab
   of the caller. */
Packit 6bd9ab
void dict_free(DICT *dict);
Packit 6bd9ab
Packit 6bd9ab
/* Return the keys of the dict as a list of strings.
Packit 6bd9ab
   The caller should free the memory with a single call to free(). */
Packit 6bd9ab
const char **dict_keys(DICT *dict)
Packit 6bd9ab
  MUST_USE;
Packit 6bd9ab
Packit 6bd9ab
#endif /* COMMON__DICT_H */