DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T m

⟦33a0c1a61⟧ TextFile

    Length: 4736 (0x1280)
    Types: TextFile
    Names: »mibaccess.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦e83f91978⟧ »EurOpenD22/isode/osimis-2.0.tar.Z« 
        └─⟦d846658bd⟧ 
            └─⟦this⟧ »osimis/sma/mibaccess.c« 

TextFile

/*
 * Copyright (c) 1988 University College London
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the Department of Computer Science, University College London.
 * The name of the University may not be used to
 * endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/* mibaccess.c - routines to handle the MIB tree structure */

/*
 * By Simon Walton, October 1988
 */

#include <stdio.h>
#include "isode/rosap.h"
#include "msap.h"
#include "smi.h"

extern char * malloc();
extern int  (*idtype2moinit())();
extern int  (*idtype2model())();
extern OID oid_copy();
struct ManagedObject * create_MO();
void delete_MO();

static struct ManagedObject * find1comp(start, key)
MO_ID * key;
struct ManagedObject * start;
{
register struct ManagedObject * cnode = start->subordinate;
register int i;
while (cnode != NULL)
	{
	if (
	     ( (i = key -> rdnlen) == 0 ||
		( i == cnode -> rdnlen &&
		 bcmp(key -> rdnval, cnode -> rdnval, i) == 0 )
	     )  &&
	    (oid_cmp(&cnode -> rdntype, &key -> rdntype) == 0)
	   ) return (cnode);
	cnode = cnode->sibling;
	}
return (NULL);  /* can't find it */
}

static struct ManagedObject * forc1comp(start, key)
MO_ID * key;
struct ManagedObject * start;
{
struct ManagedObject * last = NULL, * new;
register struct ManagedObject * cnode = start->subordinate;
register int i;
while ( cnode != NULL)
	{
	if (
	     ( (i = key -> rdnlen) == 0 ||
		( i == cnode -> rdnlen &&
		 bcmp(key -> rdnval, cnode -> rdnval, i) == 0 )
	     )  &&
	    (oid_cmp(&cnode -> rdntype, &key -> rdntype) == 0)
	   ) return (cnode);
	cnode = (last=cnode) -> sibling;
	}
/* can't find so create */
if ( (new = create_MO(key)) == NULL) return (NULL);
if (last != NULL) last -> sibling = new;
    else start -> subordinate = new;    /* created new level */
new -> parent = start;
return (new);
}

/* findcomp - Finds node who's pathname is 'key' in tree pointed to
 *  by 'start', if it exists, otherwise returns NULL. First
 *  component of pathname is looked for in level below 'start'.
 *  Returns a pointer to node whoes id is last component of
 *  pathname.
 */
struct ManagedObject * findcomp(start, key)
MO_ID * key;
struct ManagedObject * start;
{
register struct ManagedObject * part;
if (key == NULL) return (start);     /* found it */
if ( (part = find1comp(start, key)) == NULL) return (NULL);
return (findcomp(part, key -> Next));
}

/*  forccomp - Finds node who's pathname is 'key'. If it does not exist
 * then it is created. Returns NULL if out of memory, otherwise as above.
 */
struct ManagedObject * forccomp(start, key)
MO_ID * key;
struct ManagedObject * start;
{
register struct ManagedObject * part;
if (key == NULL) return (start);     /* end of path */
if ( (part = forc1comp(start, key)) == NULL) return (NULL);
return (forccomp(part, key -> Next));
}

void deletecomp(start, key)
struct ManagedObject * start;
MO_ID * key;
{
struct ManagedObject * m, ** r;
if ( (m = findcomp(start, key)) == NULL) return;
for( r = &m -> parent -> subordinate; *r != NULL; r = &(*r) -> sibling)
    if ( *r == m)
	{
	*r = m -> sibling;  /* unlink MO */
	delete_MO(m);    /* now free */
	break;
	}
return;
}

static struct ManagedObject * create_MO(id)
MO_ID * id;
{
int (*mo_init)();
register struct ManagedObject * newmo;
register int i;
if ((mo_init = idtype2moinit(&id -> rdntype)) == NULLIFP)
    {
#ifdef DEBUG
    fprintf(stderr, "Can't find MO initialize routine\n");
#endif DEBUG
    return (NULL);
    }
if ((newmo = (struct ManagedObject *)malloc(sizeof(*newmo)) )
    == NULL) return (NULL);
if (oid_copy(&id -> rdntype, &newmo -> rdntype) == NULL) return (NULL);
i = newmo -> rdnlen = id -> rdnlen;
bcopy(id -> rdnval, newmo ->rdnval, i);
newmo -> sibling = 0; newmo -> subordinate = 0;
if ((mo_init)(newmo) == 1) return (newmo);
#ifdef DEBUG
fprintf(stderr,"New MO initialize failed\n");
#endif DEBUG
return (NULL);
}

static void delete_MO(m)
struct ManagedObject * m;
{
struct ManagedObject * p, * q;
IFP mo_del;
for(p = m -> subordinate; p != NULL; p = q) {
    q = p -> sibling;
    delete_MO(p);
}
if ( (mo_del = idtype2model(&m -> rdntype)) != NULLIFP)
    (mo_del)(m);
free((char*) m -> rdntype.oid_elements);
free((char*) m);
}