diff options
Diffstat (limited to 'nslcd')
-rw-r--r-- | nslcd/Makefile.am | 3 | ||||
-rw-r--r-- | nslcd/cfg.h | 2 | ||||
-rw-r--r-- | nslcd/dict.c | 151 | ||||
-rw-r--r-- | nslcd/dict.h | 71 |
4 files changed, 2 insertions, 225 deletions
diff --git a/nslcd/Makefile.am b/nslcd/Makefile.am index 201ff0b..5d0cd44 100644 --- a/nslcd/Makefile.am +++ b/nslcd/Makefile.am @@ -31,7 +31,6 @@ nslcd_SOURCES = nslcd.c ../nslcd.h ../nslcd-common.h \ pagectrl.c pagectrl.h \ util.c util.h \ cfg.c cfg.h \ - dict.c dict.h \ alias.c ether.c group.c host.c netgroup.c network.c \ passwd.c protocol.c rpc.c service.c shadow.c -nslcd_LDADD = @nslcd_LIBS@ ../common/libtio.a +nslcd_LDADD = @nslcd_LIBS@ ../common/libtio.a ../common/libdict.a diff --git a/nslcd/cfg.h b/nslcd/cfg.h index b9009f9..67a6f98 100644 --- a/nslcd/cfg.h +++ b/nslcd/cfg.h @@ -27,7 +27,7 @@ #define _CFG_H #include "ldap-nss.h" -#include "dict.h" +#include "common/dict.h" #include "compat/attrs.h" /* maximum number of URIs */ diff --git a/nslcd/dict.c b/nslcd/dict.c deleted file mode 100644 index 84c30d7..0000000 --- a/nslcd/dict.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - dict.c - dictionary functions - This file is part of the nss-ldapd library. - - Copyright (C) 2007 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 -*/ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <strings.h> - -#include "dict.h" - -struct dict_entry { - const char *key; - void *value; - struct dict_entry *next; -}; - -struct dictionary { - struct dict_entry *head; - struct dict_entry *ptr; /* for searching */ -}; - -static struct dict_entry *dict_entry_new(const char *key) -{ - struct dict_entry *entry; - entry=(struct dict_entry *)malloc(sizeof(struct dict_entry)); - if (entry==NULL) - return NULL; - entry->key=strdup(key); - if (entry->key==NULL) - { - free(entry); - return NULL; - } - entry->value=NULL; - return entry; -} - -static void dict_entry_free(struct dict_entry *entry) -{ - /* free key */ - free((void *)entry->key); - /* free entry */ - free(entry); -} - -static struct dict_entry *dict_entry_find( - DICT *dict,const char *key) -{ - struct dict_entry *ptr; - for (ptr=dict->head;ptr!=NULL;ptr=ptr->next) - { - if (strcasecmp(ptr->key,key)==0) - return ptr; - } - return NULL; -} - -DICT *dict_new(void) -{ - struct dictionary *dict; - dict=(struct dictionary *)malloc(sizeof(struct dictionary)); - if (dict==NULL) - return NULL; - dict->head=NULL; - dict->ptr=NULL; - return dict; -} - -int dict_put(DICT *dict,const char *key,void *value) -{ - struct dict_entry *entry; - /* ignore setting of value to NULL */ - if (value==NULL) - return 0; /* probably do dict_del(dict,key) */ - entry=dict_entry_find(dict,key); - if (entry==NULL) - { - /* create new entry and insert it in the list */ - entry=dict_entry_new(key); - if (entry==NULL) - return -1; - /* insert entry in list */ - entry->next=dict->head; - dict->head=entry; - } - /* set value */ - entry->value=value; - return 0; -} - -void *dict_get(DICT *dict,const char *key) -{ - struct dict_entry *entry; - entry=dict_entry_find(dict,key); - if (entry==NULL) - return NULL; - return entry->value; -} - -void dict_free(DICT *dict) -{ - struct dict_entry *ptr,*nxt; - /* free all entries */ - ptr=dict->head; - while (ptr!=NULL) - { - nxt=ptr->next; - dict_entry_free(ptr); - ptr=nxt; - } - /* clear some references */ - dict->head=NULL; - dict->ptr=NULL; - /* free struct itself */ - free(dict); -} - -void dict_values_first(DICT *dict) -{ - dict->ptr=dict->head; -} - -void *dict_values_next(DICT *dict) -{ - struct dict_entry *ptr; - ptr=dict->ptr; - if (dict->ptr!=NULL) - dict->ptr=dict->ptr->next; - return ptr; -} diff --git a/nslcd/dict.h b/nslcd/dict.h deleted file mode 100644 index 104c5a7..0000000 --- a/nslcd/dict.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - dict.h - dictionary functions - This file is part of the nss-ldapd library. - - Copyright (C) 2007 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 _DICT_H -#define _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(LEGACYDICT *dict,const char *key);*/ - -/* Remove the dictionary from memory. All allocated storage - for the dictionary and the keys is freed. */ -void dict_free(DICT *dict); - -/* Function for looping over all dictionary values. - This resets the search to the beginning of the dictionary. - This is required before calling dict_values_next(); */ -void dict_values_first(DICT *dict); - -/* Function for looping over all dictionary values. - This returns a stored value. NULL is returned when all - stored values have been returned. */ -void *dict_values_next(DICT *dict) - MUST_USE; - -#endif /* _DICT_H */ |