FreeBSD/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c
/*
 * Insert an entry in a list - entries are lexicographicaly order by asn_oid.
 * Returns 1 on success, -1 if list is not initialized, 0 if a matching oid already
 * exists. Error cheking is left to calling function.
 */
Insert an entry in a list - entries are lexicographicaly order by asn_oid.
Returns 1 on success, -1 if list is not initialized, 0 if a matching oid already
exists. Error cheking is left to calling function.
Insert an entry in a list - entries are lexicographicaly order by asn_oid . Returns 1 on success - 1 if list is not initialized 0 if a matching oid already exists . Error cheking is left to calling function .
static int
snmp_mapping_insert(struct snmp_mapping *headp, struct snmp_oid2str *entry)
{
	int32_t rc;
	struct snmp_oid2str *temp, *prev;
	if (entry == NULL)
		return(-1);
	if ((prev = SLIST_FIRST(headp)) == NULL ||
	    asn_compare_oid(&(entry->var), &(prev->var)) < 0) {
		SLIST_INSERT_HEAD(headp, entry, link);
		return (1);
	} else
		rc = -1;	
	SLIST_FOREACH(temp, headp, link) {
		if ((rc = asn_compare_oid(&(entry->var), &(temp->var))) <= 0)
			break;
		prev = temp;
		rc = -1;
	}
	switch (rc) {
	    case 0:
		if (strncmp(temp->string, entry->string, entry->strlen)) {
			syslog(LOG_INFO, "Matching OIDs with different string "
			    "mappings: old - %s, new - %s", temp->string,
			    entry->string);
			return (-1);
		}
		return (0);
	    case 1:
		SLIST_INSERT_AFTER(temp, entry, link);
		break;
	    case -1:
		SLIST_INSERT_AFTER(prev, entry, link);
		break;
	    default:
		return (-1);
	}
	return (1);
}
static int snmp_mapping_insert ( struct snmp_mapping * headp , struct snmp_oid2str * entry ) { int32_t rc ; struct snmp_oid2str * temp , * prev ; if ( entry == NULL ) return ( -1 ) ; if ( ( prev = SLIST_FIRST ( headp ) ) == NULL || asn_compare_oid ( & ( entry -> var ) , & ( prev -> var ) ) < 0 ) { SLIST_INSERT_HEAD ( headp , entry , link ) ; return ( 1 ) ; } else rc = -1 ; SLIST_FOREACH ( temp , headp , link ) { if ( ( rc = asn_compare_oid ( & ( entry -> var ) , & ( temp -> var ) ) ) <= 0 ) break ; prev = temp ; rc = -1 ; } switch ( rc ) { case 0 : if ( strncmp ( temp -> string , entry -> string , entry -> strlen ) ) { syslog ( LOG_INFO , " " " " , temp -> string , entry -> string ) ; return ( -1 ) ; } return ( 0 ) ; case 1 : SLIST_INSERT_AFTER ( temp , entry , link ) ; break ; case -1 : SLIST_INSERT_AFTER ( prev , entry , link ) ; break ; default : return ( -1 ) ; } return ( 1 ) ; }
Insert an entry in a list - entries are lexicographicaly order by asn_oid.
Insert an entry in a list - entries are lexicographicaly order by asn_oid .
/* Make the compiler happy. */ /* Ops, matching OIDs - hope the rest info also matches. */ /*
		 * Ok, we have that already.
		 * As long as the strings match - don't complain.
		 */ /* NOTREACHED */