www.pudn.com > RadiusSrv.rar > dict.cpp, change:2003-10-22,size:1061b


#include "libRadius.h" 
 
static DICT_ATTR	*dictionary_attributes = NULL; 
static DICT_VALUE	*dictionary_values = NULL; 
 
static DICT_ATTR *base_attributes[256]; 
 
/* 
 *	Associate a value with an attribute and return it. 
 */ 
DICT_VALUE * dict_valbyattr(int attr, int val) 
{ 
	DICT_VALUE	*v; 
 
	for (v = dictionary_values; v; v = v->next) { 
		if (v->attr == attr && v->value == val) 
			return v; 
	} 
 
	return NULL; 
} 
 
/* 
 *	Get an attribute by its numerical value. 
 */ 
DICT_ATTR * dict_attrbyvalue(int val) 
{ 
	DICT_ATTR	*a; 
 
	/* 
	 *	If it's an on-the-wire base attribute, return 
	 *	the cached value for it. 
	 */ 
	if ((val >= 0) && (val < 256)) { 
		return base_attributes[val]; 
	} 
 
	for (a = dictionary_attributes; a; a = a->next) { 
		if (a->attr == val) 
			return a; 
	} 
 
	return NULL; 
} 
 
/* 
 *	Get an attribute by its name. 
 */ 
DICT_ATTR * dict_attrbyname(const char *name) 
{ 
	DICT_ATTR	*a; 
 
	for (a = dictionary_attributes; a; a = a->next) { 
		if (strcmp(a->name, name) == 0) 
			return a; 
	} 
 
	return NULL; 
}