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 i

⟦0ae06273b⟧ TextFile

    Length: 6977 (0x1b41)
    Types: TextFile
    Names: »isoentity.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/acsap/isoentity.c« 

TextFile

/* isoentity.c - application entity titles -- sequential lookup utilities  */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/acsap/RCS/isoentity.c,v 6.0 89/03/18 23:24:42 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/acsap/RCS/isoentity.c,v 6.0 89/03/18 23:24:42 mrose Rel $
 *
 *
 * $Log:	isoentity.c,v $
 * Revision 6.0  89/03/18  23:24:42  mrose
 * Release 5.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 <ctype.h>
#include <stdio.h>
#include "psap.h"
#include "isoaddrs.h"
#include "tailor.h"

/* \f

   DATA */

static char *isoentities = "isoentities";

static FILE *servf = NULL;
static int   stayopen = 0;

static int   mask;
static int   vecp;
static char  buffer[BUFSIZ + 1];
static char *vec[NVEC + NSLACK + 1];

static struct isoentity ies;


struct nsap_entry {
    char   *ns_service;

    IFP	    ns_parse;
};

int	tcpparse (), x25parse (), nsapparse (); 

struct nsap_entry _nsap_entries[] = {
    "NS", nsapparse,
    "TCP", tcpparse,
    "X.25", x25parse,

    NULL
};

/* \f

 */

int	setisoentity (f)
int	f;
{
    if (servf == NULL)
	servf = fopen (isodefile (isoentities), "r");
    else
	rewind (servf);
    stayopen |= f;

    return (servf != NULL);
}


int	endisoentity () {
    if (servf && !stayopen) {
	(void) fclose (servf);
	servf = NULL;
    }

    return 1;
}

/* \f

 */

struct isoentity   *getisoentity () {
    static char  descriptor[BUFSIZ];

    if (servf == NULL
	    && (servf = fopen (isodefile (isoentities), "r")) == NULL)
	return NULL;

    while (_startisoentity (descriptor) == OK)
	if (_stopisoentity (descriptor, (struct isoentity *) NULL) == OK)
	    return (&ies);

    return NULL;
}

/* \f

 */

int	_startisoentity (descriptor)
char   *descriptor;
{
    register char  *cp,
		   *dp;
    char   *ep;
    register struct isoentity  *ie = &ies;

    bzero ((char *) ie, sizeof *ie);

    ep = (dp = buffer) + sizeof buffer;
    while (fgets (dp, ep - dp, servf) != NULL) {
	if (*buffer == '#')
	    continue;
	if (cp = index (buffer, '\n')) {
	    *cp-- = NULL;
	    if (*cp == '\\') {
		if ((dp = cp) + 1 >= ep)
		    dp = buffer;
		continue;
	    }
	}

	switch (vecp = str2vecX (buffer, vec, 5 + 1, &mask, NULL)) {
	    case 3:			/* no address */
	    case 4:			/* new-style */
	    case 6:			/* old-style */
	        break;

	    default:
		continue;
	}

	(void) sprintf (descriptor, "%s-%s", vec[0], vec[1]);

	return OK;
    }

    return DONE;
}

/* \f

 */

int	_stopisoentity (descriptor, iep)
char   *descriptor;
struct isoentity *iep;
{
    register int    i;
    register char **ap;
    register struct nsap_entry *ns;
    register struct isoentity  *ie = &ies;
    OID		oid = &ie -> ie_identifier;
    struct PSAPaddr *pa = &ie -> ie_addr;
    struct SSAPaddr *sa = &pa -> pa_addr;
    struct TSAPaddr *ta = &sa -> sa_addr;
    struct NSAPaddr *na = ta -> ta_addrs;
    static unsigned int elements[NELEM + 1];

    if (strcmp (vec[2], "NULL") == 0)
	elements[i = 0] = 0;
    else
	if ((i = str2elem (vec[2], elements)) <= 1)
	    return NOTOK;
    oid -> oid_elements = elements;
    oid -> oid_nelem = i;
    ie -> ie_descriptor = descriptor;

    if (vecp == 3)		/* no address */
	goto out;

    if (vecp == 4) {		/* new-style */
	struct PSAPaddr *pz;

	if (pz = str2paddr (vec[3]))
	    *pa = *pz;		/* struct copy */
	goto out;
    }

    pa -> pa_selectlen = str2sel (vec[3], (mask & (1 << 3)) ? 1 : 0,
				pa -> pa_selector, PSSIZE);
    sa -> sa_selectlen = str2sel (vec[4], (mask & (1 << 4)) ? 1 : 0,
				sa -> sa_selector, SSSIZE);
    ta -> ta_selectlen = str2sel (vec[5], (mask & (1 << 5)) ? 1 : 0,
				ta -> ta_selector, TSSIZE);

    if (vecp == 6)
	goto again;

    ap = vec + 6;
    for (;;) {
	if (ta -> ta_naddr < NTADDR)
	    for (ns = _nsap_entries; ns -> ns_service; ns++)
		if (strcmp (ns -> ns_service, *ap) == 0) {
		    bzero ((char *) na, sizeof *na);
		    if ((*ns -> ns_parse) (na, ap + 1) == OK)
			na++, ta -> ta_naddr++;
		    else
			bzero ((char *) na, sizeof *na);
		    break;
		}

again: ;
	if (fgets (buffer, sizeof buffer, servf) == NULL)
	    break;
	if (*buffer == '#')
	    goto again;	/* yuk! */
	if ((vecp = str2vec (buffer, vec)) == 0)
	    break;
	if (vecp < 2)
	    goto again;
	ap = vec;
    }
out: ;

    if (iep)
	*iep = *ie;	/* struct copy */

    return OK;
}

/* \f

 */

int	_scanisoentity ()
{
    for (;;) {
	if (fgets (buffer, sizeof buffer, servf) == NULL)
	    break;
	if (*buffer == '#')
	    continue; /* yuk! */
	if ((vecp = str2vec (buffer, vec)) == 0)
	    break;
    }
}

/* \f

 */

_printent (ie)
register struct isoentity  *ie;
{
    LLOG (addr_log, LLOG_DEBUG,
	  ("Entity:  %s (%s)", ie -> ie_descriptor,
	   oid2ode (&ie -> ie_identifier)));

    (void) ll_printf (addr_log, "Address: %s\n",
		      paddr2str (&ie -> ie_addr, NULLNA));

    (void) ll_printf (addr_log, "///////\n");

    (void) ll_sync (addr_log);
}

/* \f

   OLD-STYLE */

/* \f

 */

static int  nsapparse (na, args)
register struct NSAPaddr *na;
char  **args;
{
    char   *cp;

    na -> na_type = NA_NSAP;

    if ((cp = *args++) == NULL) {
	na -> na_addrlen = 0;
	return OK;
    }

    na -> na_addrlen = implode ((u_char *) na -> na_address, cp, strlen (cp));

    return OK;
}

/* \f

 */

static int  tcpparse (na, args)
register struct NSAPaddr *na;
char  **args;
{
    int	    i;

    if (*args == NULL)
	return NOTOK;

    na -> na_type = NA_TCP;
    na -> na_subnet = SUBNET_INTERNET;

    (void) strncpy (na -> na_domain, *args++, sizeof na -> na_domain);
    if (*args && (i = atoi (*args++)) > 0) {
	na -> na_port = htons ((u_short) i);

	if (*args)
	    na -> na_tset = atoi (*args++);
    }

    return OK;
}

/* \f

 */

static int  x25parse (na, args)
register struct NSAPaddr *na;
char  **args;
{
    register char *cp;

    if (*args == NULL)
      return NOTOK;

    for (cp = *args; *cp; cp++)
      if (!isxdigit (*cp))
          return NOTOK;
    if (cp - *args > (NSAP_DTELEN + 1) /* Maximum X.121 DTE address length */ )
      return NOTOK;

    (void) strcpy (na -> na_dte, *args++);
    na -> na_dtelen = strlen (na -> na_dte);

    /* The only optional argument is the Protocol ID.
     * This may be a hex string (e.g. 03010100) or a (quoted) string.
     */
    if (*args) {
#ifdef	DEBUG
	int	len;

	if ((len = strlen (*args)) != NPSIZE * 2)
	    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
		  ("invalid PID string \"%s\" length %d (should be %d)",
		   *args, len, NPSIZE * 2));
#endif

/* bogus use of -1 for "quoted" argument, really should be told if quoted or
   not */
	na -> na_pidlen = str2sel (*args, -1, na -> na_pid, NPSIZE);
    }

#ifdef	BRIDGE_X25
    na -> na_type = bridgediscrim (na) ? NA_BRG : NA_X25;
#else
    na -> na_type = NA_X25;
#endif
    na -> na_subnet = SUBNET_INTL_X25;

    return OK;
}