oid.c

来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 926 行 · 第 1/2 页

C
926
字号
/* oid.c - Object Identifier routines */#ifndef lintstatic char *rcsid = "$Header: /xtel/isode/isode/dsap/common/RCS/oid.c,v 9.0 1992/06/16 12:12:39 isode Rel $";#endif/* * $Header: /xtel/isode/isode/dsap/common/RCS/oid.c,v 9.0 1992/06/16 12:12:39 isode Rel $ * * * $Log: oid.c,v $ * Revision 9.0  1992/06/16  12:12:39  isode * Release 8.0 * *//* *                                NOTICE * *    Acquisition, use, and distribution of this module and related *    materials are subject to the restrictions of a license agreement. *    Consult the Preface in the User's Manual for the full terms of *    this agreement. * *//* LINTLIBRARY */#include "quipu/util.h"#include "quipu/entry.h"#include "cmd_srch.h"#include "tailor.h"extern char chrcnv [];extern LLog * log_dsap;FILE * f_table;static char * get_entry ();static add_entry ();char * get_oid();static char * name2gen ();int add_entry_aux ();oid_table       OIDTable [TABLESIZE];oid_table_attr  attrOIDTable [TABLESIZE];objectclass     ocOIDTable [TABLESIZE];int NumEntries          = 0;int attrNumEntries      = 0;int ocNumEntries        = 0;unsigned attr_index = 0;#define GEN  1#define ATTR 2#define OC   3#define	PBUCKETS	128#define	PHASH(nm) \    (((nm)[1]) ? (((chrcnv[((nm)[0])] - chrcnv[((nm)[1])]) & 0x1f) + ((chrcnv[(nm)[2]]) & 0x5f)) \	       : (chrcnv[(nm)[0]]) & 0x7f)struct pair {    char   *p_name;    caddr_t p_value;    int     p_type;    struct pair *p_chain;};struct aliases {	char * a_full;	char * a_alias;};static struct aliases Palias[LOTS];static int Palias_next = 0;static struct pair *Pbuckets[PBUCKETS];static char allow_single_oid = FALSE;IFP oc_load = NULLIFP;IFP oc_macro_add = NULLIFP;int load_oid_table (table)char * table;{register char * name;char filename [FILNSIZE];register char * extension;char *isodetable;        if (NumEntries != 0)		return OK;    /* already loaded */	isodetable = isodefile(table, 0);	(void) strcpy (filename,isodetable);	extension = &filename[strlen(isodetable)];	(void) strcpy (extension,".gen");	if (( f_table = fopen (filename,"r")) == (FILE *) NULL) {	    bad_file: ;		LLOG (log_dsap, LLOG_EXCEPTIONS, ("file %s",filename));		return NOTOK;	}	while (1) {     /* break out */		if ( (name = get_entry ()) == NULLCP)			break;		allow_single_oid = TRUE;		if (! add_entry (name,GEN)) {		    bad_entry:;			LLOG (log_dsap,LLOG_EXCEPTIONS,			      ("Can't add entry to oid table"));			return NOTOK;	        }		allow_single_oid = FALSE;	}	(void) fclose (f_table);	(void) strcpy (extension,".at");	if (( f_table = fopen (filename,"r")) == (FILE *) NULL)		goto bad_file;	while (1) {     /* break out */		if ( (name = get_entry ()) == NULLCP)			break;		if (!add_entry (name,ATTR))			goto bad_entry;	}	(void) fclose (f_table);	(void) strcpy (extension,".oc");	if (( f_table = fopen (filename,"r")) == (FILE *) NULL)	    goto bad_file;	while (1) {     /* break out */		if ( (name = get_entry ()) == NULLCP)			break;		if (!add_entry (name,OC))			goto bad_entry;	}	(void) fclose (f_table);	return OK;}add_entry_aux (a,b,c,d)char * a;caddr_t b;int c;char * d;{    int	    i;    register struct pair *p;    for (p = Pbuckets[PHASH (a)];	p && lexequ (p -> p_name, a);	p = p -> p_chain) 	    ; /* NO-OP */    if ( p ) {	LLOG (log_dsap,LLOG_FATAL,("duplicate OID '%s'",a));	return FALSE;    }    if ((p = (struct pair *) calloc (1, sizeof *p)) == NULL) {	SLOG (log_dsap, LLOG_EXCEPTIONS, NULLCP,	      ("calloc of oid hash structure failed"));	return FALSE;    }    p -> p_name = a;    p -> p_value = b;    p -> p_type = c;    p -> p_chain = Pbuckets[i = PHASH (p -> p_name)];    Pbuckets[i] = p;    if (d != NULLCP) {	for (p = Pbuckets[PHASH (d)];	     p && lexequ (p -> p_name, d);	     p = p -> p_chain) 		; /* NO-OP */	if ( p ) {		LLOG (log_dsap,LLOG_FATAL,("duplicate alias OID '%s'",d));		return FALSE;	}	if ((p = (struct pair *) calloc (1, sizeof *p)) == NULL) {		SLOG (log_dsap, LLOG_EXCEPTIONS, NULLCP,	      	   	   ("calloc of alias hash structure failed"));		return FALSE;    	}	Palias[Palias_next].a_full = a;	Palias[Palias_next++].a_alias = d;    	p -> p_name = d;    	p -> p_value = b;    	p -> p_type = c;    	p -> p_chain = Pbuckets[i = PHASH (p -> p_name)];    	Pbuckets[i] = p;    }    return TRUE;}static add_entry (newname,towho)char * newname;int towho;{register char *nptr, *ptr, *sep;OID oid;oid_table * Current;char * alias = NULLCP;	if ((nptr = index (newname,SEPERATOR)) == 0) {		LLOG (log_dsap,LLOG_FATAL,("oid missing in %s",newname));		return FALSE;	}	*nptr = 0;	if ((sep = index (newname,COMMA)) != 0) {		*sep++ = 0;		alias = strdup(newname);		newname = sep;	} 	switch (towho) {		case GEN:			Current = &OIDTable[NumEntries];			Current->ot_name = strdup(newname);			if (!add_entry_aux (Current->ot_name,(caddr_t)&OIDTable[NumEntries],GEN,alias))				return FALSE;			break;		case ATTR:			Current = &attrOIDTable[attrNumEntries].oa_ot;			Current->ot_name = strdup(newname);			if (!add_entry_aux (Current->ot_name,(caddr_t)&attrOIDTable[attrNumEntries],ATTR,alias))				return FALSE;			break;		case OC:			Current = &ocOIDTable[ocNumEntries].oc_ot;			Current->ot_name = strdup(newname);			if (!add_entry_aux (Current->ot_name,(caddr_t)&ocOIDTable[ocNumEntries],OC,alias))				return FALSE;			break;		}	*nptr = SEPERATOR;	nptr++;	if ((sep = index (nptr,SEPERATOR)) != 0)		*sep++ = 0;	if ((ptr = index (nptr,COMMA)) != 0) {		char * p;		*ptr++ = 0;		if (( p = get_oid (ptr)) == NULLCP) {			LLOG (log_dsap,LLOG_FATAL,("invalid alias oid '%s'",ptr));			return FALSE;		}		if ((oid = str2oid (p)) == NULLOID)			Current->ot_aliasoid = NULLOID;		else			Current->ot_aliasoid = oid_cpy (oid);	} 	ptr = get_oid (nptr);	if (ptr == NULLCP) {		LLOG (log_dsap,LLOG_FATAL,("invalid oid '%s'",nptr));		return FALSE;	}	Current->ot_stroid = strdup(ptr);	oid = str2oid (Current->ot_stroid);	if (oid == NULLOID)		Current->ot_oid = NULLOID;		/* only reason for failure is generic oid of length 1 */	else		Current->ot_oid = oid_cpy (oid);	/* now do special work for at and oc types */	switch (towho) {		case GEN:			NumEntries++;   /* nothing else to do */			break;		case ATTR:			if (sep == 0) {				LLOG (log_dsap,LLOG_FATAL,("syntax missing in %s",newname));				return FALSE;			} else {				if (( ptr = index (sep,SEPERATOR)) != NULLCP) {					*ptr++ = 0;					if (lexequ (ptr,"FILE") != 0) {						LLOG (log_dsap,LLOG_FATAL,("FILE syntax expected, '%s' found",ptr));						return FALSE;					} else {						attrOIDTable[attrNumEntries].oa_syntax = str2syntax(sep);						attrOIDTable[attrNumEntries].oa_syntax += AV_WRITE_FILE;						attrNumEntries++;					}				} else {					attrOIDTable[attrNumEntries].oa_syntax = str2syntax(sep);					attrNumEntries++;				}			}			break;		case OC:			if (oc_load != NULLIFP) {				if ((*oc_load)(sep,ptr) == OK)					ocNumEntries++;			}			else				ocNumEntries++;	}	return TRUE;}char * get_oid (str)char * str;{static char * buffer = NULLCP;register char * ptr;register char * dotptr;register char * soid;char deref = FALSE;char got_dot = FALSE;      if (buffer == NULLCP)	      buffer = smalloc (LINESIZE);        ptr = buffer;      if ( ! isdigit(*str))	      if ((dotptr = index (str,DOT)) == 0)		      return (name2gen(str));	while (*str != 0) {	        if (*str == DOT)		    got_dot = TRUE;		if ( (! isdigit (*str)) && (*str != DOT) ) {			if ((dotptr = index (str,DOT)) == 0) {				*--ptr = 0;				return (buffer);			} else				got_dot = TRUE;			*dotptr = 0;			*ptr = 0;			if ((soid = name2gen(str)) == NULLCP) {				*dotptr = DOT;				return (NULLCP);			}			*dotptr = DOT;			str = dotptr;			if (deref) {				if ((dotptr = rindex (soid,DOT)) == 0)					return (NULLCP); /* invalid */				if ((strncmp (soid,buffer,strlen(buffer))) != 0)					return (NULLCP);  /* inconsistent */			}			deref = TRUE;			(void) strcpy (buffer,soid);			ptr = buffer + strlen (soid);			}		else 			*ptr++ = *str++;	}	if ( !got_dot && !allow_single_oid )		return NULLCP;	*ptr = 0;	return (buffer);}static char * name2gen (nodename)char * nodename;{#ifdef NOT_ANY_MOREregister int i;register oid_table * tblptr = &OIDTable[0];	for (i=0;i<NumEntries;i++,tblptr++) {		if (lexequ (tblptr->ot_name, nodename) == 0)			return (tblptr->ot_stroid);	}	return (NULLCP);#endifstruct pair *p;oid_table * ot;	for (p = Pbuckets[PHASH (nodename)];		p && lexequ (p -> p_name, nodename);     		p = p -> p_chain) 			; /* NO-OP */	if (p != NULL)		switch (p -> p_type) {		    case GEN: 			ot = (oid_table *) p->p_value;			return (ot->ot_stroid);		    default: 			return (NULLCP);		    }	return NULLCP;}static char * soid2gen (soid)char * soid;{register int i;register oid_table * tblptr = &OIDTable[0];	for (i=0;i<NumEntries;i++,tblptr++) {		if (strcmp (tblptr->ot_stroid, soid) == 0)			return (tblptr->ot_name);	}	return (NULLCP);}static char * get_line (){static char * buffer;static int buflen;register char * buf;register char * ptr;register int done;register int left;register int size;        if (buffer == NULLCP) {	      buffer = smalloc (LINESIZE);	      buflen = LINESIZE;	}        buf = buffer, ptr = buffer;	left = buflen;	/* read line, ignore comments, join lines in '/' found */	do {		done = TRUE;		if (fgets (buf, left, f_table) == NULLCP)			return (NULLCP);		StripSpace (buf);		if (*buf != 0) {			size = strlen(buf);			ptr += size - 1;			left -= size;			if (*ptr == '\\') {				buf = ptr;				done = FALSE;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?