/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "nscd_db.h"
/*
* This file implements the database functionality used by the
* switch and configuration components. The implementation is
* based on hash and has table. If the need arises in the future,
* the code in this file can be changed to use other algorithms.
* The following lists the functions implemented:
*
* _nscd_add_db_entry
* _nscd_delete_db_entry
* _nscd_get_db_entry
* _nscd_alloc_db
* _nscd_free_db
* _nscd_walk_db
* _nscd_delete_db_entry_cookie
*/
/*
* This structure defines an instance of the hash entry
* which implements the nscd database entry. The
* db_entry field should always be the first one in
* the structure.
*/
typedef struct nscd_hash {
} nscd_hash_t;
/*
* This structure defines a nscd database which
* is implemented as an array of nscd_hash_t.
*/
struct nscd_db_s {
};
/*
* This cookie structure is used to iterate through the
* database entries contained in a nscd database.
*/
struct cookie {
};
/*
* FUNCTION: calc_hash
*
* Calculate a hash for a string based on the elf_hash
* algorithm, hash is case insensitive. Uses tolower
* instead of _tolower because of I18N.
*/
static unsigned long
const char *str)
{
unsigned int hval = 0;
char ch;
unsigned int g;
if ((g = (hval & 0xf0000000)) != 0)
hval ^= g >> 24;
hval &= ~g;
}
return ((unsigned long)hval);
}
/*
* FUNCTION: scan_hash
*
* Scan a hash table for a matching hash entry. Assume 'str' is
* not NULL. If option is NSCD_GET_NEXT_DB_ENTRY and id_num
* is less than zero, then treats the option as NSCD_GET_FIRST_DB_ENTRY.
*/
static const nscd_hash_t *
int type,
const char *str,
const nscd_hash_t *idx_p,
int id_num)
{
int id_matched = 0;
switch (option) {
case NSCD_GET_FIRST_DB_ENTRY:
return (idx_p);
case NSCD_GET_EXACT_DB_ENTRY:
return (idx_p);
break;
case NSCD_GET_NEXT_DB_ENTRY:
if (id_num < 0)
return (idx_p);
if (id_matched == 1)
return (idx_p);
id_matched = 1;
break;
}
}
}
}
return (NULL);
}
/*
* FUNCTION: _nscd_get_db_entry
*
* Find a nscd database entry from a nscd database.
*/
const nscd_db_entry_t *
int type,
const char *str,
int id_num)
{
unsigned long hash;
return (NULL);
}
/*
* FUNCTION: _nscd_add_db_entry
*
* Add a nscd database entry to a nscd database. This function
* is not MT safe. The caller should lock the database to
* prevent concurrent updates done by other threads.
*/
const char *str,
{
int i;
unsigned long hash;
/* find the bucket */
/* can not replace nothing */
if (option == NSCD_ADD_DB_ENTRY_REPLACE)
return (NSCD_DB_ENTRY_NOT_FOUND);
switch (option) {
case NSCD_ADD_DB_ENTRY_FIRST:
goto add_entry;
goto cont;
goto cont;
goto add_entry;
}
goto cont;
break;
break;
return (NSCD_DB_ENTRY_FOUND);
}
if (option == NSCD_ADD_DB_ENTRY_LAST ||
goto add_entry;
}
}
cont:
}
/*
* the nscd_entry_t field should be the first field
* in a nscd_hash_t
*/
/* update the prev link list */
else
/* update the next link list */
return (NSCD_SUCCESS);
}
/*
* FUNCTION: _nscd_delete_db_entry
*
* Delete a nscd database entry from a nscd database. This
* function is not MT safe. The caller should lock the
* database to prevent concurrent updates done by other
* threads.
*/
int type,
const char *str,
int id_num)
{
int i;
int del_more = 0;
unsigned long hash;
/* find the bucket */
/* delete nothing always works */
return (NSCD_SUCCESS);
goto cont;
goto cont;
switch (option) {
case NSCD_DEL_FIRST_DB_ENTRY:
del_more = 0;
break;
case NSCD_DEL_EXACT_DB_ENTRY:
del_more = 0;
} else
goto cont;
break;
case NSCD_DEL_ALL_DB_ENTRY:
break;
}
else
if (del_more == 0)
break;
/*
* only when option == NSCD_DEL_ALL_DB_ENTRY
* will we get here. next_p should be set to
* idx_p->next_p beforehand
*/
continue;
cont:
}
return (NSCD_SUCCESS);
}
/*
* FUNCTION: _nscd_alloc_db_entry
*
* Allocate and return the memory for a database entry
* so the caller can insert data and then add it to the
* database.
*/
int type,
const char *name,
int dataSize,
int num_data,
int num_array)
{
int size;
void *p;
/* first part: hash data structure and name string */
/* second part: pointer array to data */
/* third part: actual data */
/* allocate the memory */
return (NULL);
/* init the entry based on caller's input */
}
/*
* FUNCTION: _nscd_delete_db_entry_cookie
*
* Delete a database entry using the information from
* the input 'cookie'.
*/
void
void **cookie)
{
struct cookie *c;
/* snaity check */
return;
c = *cookie;
/* more snaity check */
return;
/* retrieve the hash entry from the cookie */
/*
* Need to update c->hash as well, in case
* the cookie is also used in a walk-db
* loop. This is to make sure that the
* next _nscd_walk_db() call will
* find the (updated) next hash entry in line.
*/
/*
* make sure the current bucket will be
* walked again if _nscd_walk_db is
* called next
*/
c->idx--;
} else {
}
/* delete the entry */
}
/*
* FUNCTION: _nscd_alloc_db
*
* Allocate the space for a nscd database.
*
* The input argument, size, indicates the size of the database.
* NSCD_DB_SIZE_LARGE specifies an bucket array of size 67,
* NSCD_DB_SIZE_MEDIUM specifies an bucket array of size 37,
* NSCD_DB_SIZE_SMALL specifies an bucket array of size 13,
* NSCD_DB_SIZE_TINY specifies an bucket array of size 3.
*/
int size)
{
int sz;
/* allocate the database */
return (NULL);
/* allocate the bucket array */
if (size == NSCD_DB_SIZE_LARGE)
sz = 67;
else if (size == NSCD_DB_SIZE_MEDIUM)
sz = 37;
else if (size == NSCD_DB_SIZE_SMALL)
sz = 13;
else if (size == NSCD_DB_SIZE_TINY)
sz = 3;
sizeof (nscd_hash_t *));
return (NULL);
}
return (db);
}
/*
* FUNCTION: _nscd_free_db
*
* Delete a nscd database.
*/
void
{
int i;
/*
* find non-empty buckets and for each one of them,
* delete all the database entries in it's link list
*/
for (i = 0; i < db->array_size; i++) {
}
}
/* free the bucket array */
}
/*
* FUNCTION: _nscd_walk_db
*
* Iterate through the database entries contained in
* a nscd database and return one entry at a time.
* The cookie structure is used to indicate the
* location of the returned entry for the next call
* to this function. For the very first call, *cookie
* should be set to NULL. For subsequent calls, the one
* returned by the previous call sould be used.
*/
void **cookie)
{
struct cookie *c;
/* sanity check */
return (NULL);
c = *cookie;
/*
* More sanity check. _nscd_delete_db_entry_cookie()
* could change c->idx to -1.
*/
return (NULL);
/* is there a next entry ? */
/* yes, return it */
}
} else {
if (c == NULL)
return (NULL);
c->idx = -1;
}
/* find the first non-empty bucket */
break;
}
/* no (more) non-empty bucket, we are done */
free(c);
return (NULL);
}
*cookie = c;
}