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 t

⟦ffab0819f⟧ TextFile

    Length: 7822 (0x1e8e)
    Types: TextFile
    Names: »tsapinitiate.c«

Derivation

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

TextFile

/* tsapinitiate.c - TPM: initiator */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/tsap/RCS/tsapinitiate.c,v 6.0 89/03/18 23:45:31 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/tsap/RCS/tsapinitiate.c,v 6.0 89/03/18 23:45:31 mrose Rel $
 *
 *
 * $Log:	tsapinitiate.c,v $
 * Revision 6.0  89/03/18  23:45:31  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 <stdio.h>
#include <signal.h>
#include "tpkt.h"
#include "isoservent.h"
#include "tailor.h"


static struct nsapent {
    int	    ns_type;
    int	    ns_stack;

    IFP	    ns_open;
}     nsaps[] = {
#ifdef	TCP
    NA_TCP, TS_TCP, tcpopen,
#endif
#ifdef	X25
    NA_X25, TS_X25, x25open,
#endif
#ifdef  CONS
    NA_NSAP, TS_CONS, consopen,
#endif
#ifdef BRIDGE_X25
    NA_BRG, TS_BRG, bridgeopen,
#endif
#ifdef	TP4
    NA_NSAP, TS_TP4, tp4open,
#endif

    NOTOK, TS_NONE, NULL
};


struct TSAPaddr *newtaddr (), *ta2norm ();

/* \f

   T-(ASYN-)CONNECT.REQUEST */

int     TAsynConnRequest (calling, called, expedited, data, cc, qos,
			  tc, td, async)
struct TSAPaddr *calling,
		*called;
int	expedited,
	cc,
	async;
char   *data;
struct QOStype *qos;
struct TSAPconnect *tc;
struct TSAPdisconnect *td;
{
    register int  n;
    SBV     smask;
    int     result;
    register struct NSAPaddr *na;
    register struct nsapent *ns;

    isodetailor (NULLCP, 0);

#ifdef	notdef
    missingP (calling);
#endif
    missingP (called);
    if ((n = called -> ta_naddr) <= 0)
	return tsaplose (td, DR_PARAMETER, NULLCP,
			 "no NSAP addresses in called parameter");
    if (n > NTADDR)
	return tsaplose (td, DR_PARAMETER, NULLCP,
			 "too many NSAP addresses in called parameter");

    if ((called = ta2norm (called)) == NULLTA)
	return tsaplose (td, DR_PARAMETER, "invalid called parameter");
    for (na = called -> ta_addrs, n = called -> ta_naddr - 1;
	     n >= 0;
	     na++, n--) {
      for (ns = nsaps; ns -> ns_open; ns++)
          if (ns -> ns_type == na -> na_type && (ns -> ns_stack & ts_stacks))
              break;
      if (ns -> ns_open)
          break;
    }  
    if (!ns -> ns_open)
      return tsaplose (td, DR_PARAMETER, NULLCP,
              "no supported NSAP addresses in called parameter");

    toomuchP (data, cc, TS_SIZE, "initial");
#ifdef	notdef
    missingP (qos);
#endif
    missingP (td);

    smask = sigioblock ();

    result = TConnRequestAux (calling, called, expedited, data, cc, qos,
			      tc, td, async);

    (void) sigiomask (smask);

    return result;
}

/* \f

 */

static int  TConnRequestAux (calling, called, expedited, data, cc, qos,
			     tc, td, async)
struct TSAPaddr *calling,
		*called;
char    *data;
int	expedited,
	cc,
	async;
struct QOStype *qos;
register struct TSAPconnect *tc;
register struct TSAPdisconnect *td;
{
    int	    result;
    register int n;
    register struct NSAPaddr *na;
    register int l;
    register struct NSAPaddr *la;
    register struct tsapblk *tb;
    register struct TSAPdisconnect *te = td;
    struct TSAPdisconnect tds;

    if ((tb = newtblk ()) == NULL)
	return tsaplose (td, DR_CONGEST, NULLCP, "out of memory");

    if (calling == NULLTA) {
	static struct TSAPaddr tas;

	calling = &tas;
	bzero ((char *) calling, sizeof *calling);
    }
    if (called -> ta_selectlen > 0 && calling -> ta_selectlen == 0) {
	calling -> ta_port = htons ((u_short) (0x8000 | (getpid () & 0x7fff)));
	calling -> ta_selectlen = sizeof calling -> ta_port;
    }

    if (qos)
	tb -> tb_qos = *qos;	/* struct copy */

    for (na = called -> ta_addrs, n = called -> ta_naddr - 1;
	     n >= 0;
	    na++, n--) {
	register struct nsapent *ns;

	for (l = calling -> ta_naddr - 1, la = calling -> ta_addrs;
		l >= 0;
		la++, l--)
	    if (la -> na_type == na -> na_type)
		break;
	if (l < 0)
	    la = NULLNA;

        for (ns = nsaps; ns -> ns_open; ns++)
          if (ns -> ns_type == na -> na_type && (ns -> ns_stack & ts_stacks))
                break;
        if (!ns -> ns_open)
	    continue;
	switch (ns -> ns_type) {
	    case NA_NSAP:
		if ((result = (*ns -> ns_open) (tb, calling, la, called, na,
				    te, async)) == NOTOK) {
		    te = &tds;
		    continue;
		}
		break;

	    default:
		if ((result = (*ns -> ns_open) (tb, la, na, te, async))
			== NOTOK) {
		    te = &tds;
		    continue;
		}
		break;
	}

	break;
    }
    if (tb -> tb_fd == NOTOK)
	goto out;
    if (te != td)
	*td = *te;	/* struct copy */

    tb -> tb_initiating = *newtaddr (calling, la);	/* struct copy */
    tb -> tb_responding = *newtaddr (called, na);	/* struct copy */

    if ((*tb -> tb_connPfnx) (tb, expedited, data, cc, td) == NOTOK)
	goto out;

    if (async) {
	tc -> tc_sd = tb -> tb_fd;
	if (result == OK)
	    return OK;
    }
    if ((result = (*tb -> tb_retryPfnx) (tb, async, tc, td)) == DONE && !async)
	result = OK;
    return result;

out: ;
    freetblk (tb);

    return NOTOK;
}

/* \f

   T-ASYN-RETRY.REQUEST (pseudo) */

int	TAsynRetryRequest (sd, tc, td)
int	sd;
struct TSAPconnect *tc;
struct TSAPdisconnect *td;
{
    SBV     smask;
    int     result;
    register struct tsapblk *tb;

    missingP (tc);
    missingP (td);

    smask = sigioblock ();

    if ((tb = findtblk (sd)) == NULL) {
	(void) sigiomask (smask);
	return tsaplose (td, DR_PARAMETER, NULLCP,
		"invalid transport descriptor");
    }
    if (tb -> tb_flags & TB_CONN) {
	(void) sigiomask (smask);
	return tsaplose (td, DR_OPERATION, NULLCP,
		"transport descriptor connected");
    }

    result = (*tb -> tb_retryPfnx) (tb, 1, tc, td);

    (void) sigiomask (smask);

    return result;
}

/* \f

 */

static struct TSAPaddr *newtaddr (ta, na)
register struct TSAPaddr *ta;
register struct NSAPaddr *na;
{
    static struct TSAPaddr tzs;
    register struct TSAPaddr *tz = &tzs;
    register struct NSAPaddr *nz = tz -> ta_addrs;

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

    if (tz -> ta_selectlen = ta -> ta_selectlen)
	bcopy (ta -> ta_selector, tz -> ta_selector, ta -> ta_selectlen);
    if (na) {
	*nz = *na;
	tz -> ta_naddr = 1;
    }

    return tz;
}

/* \f

 */

struct TSAPaddr *ta2norm (ta)
register struct TSAPaddr *ta;
{
    register int    n,
		   *ip;
    static struct TSAPaddr tzs;
    register struct TSAPaddr *tz = &tzs;
    register struct NSAPaddr *na,
			     *ca;

    SLOG (addr_log, LLOG_TRACE, NULLCP,
	  ("ta2norm %s", taddr2str (ta)));

    for (na = ta -> ta_addrs, n = ta -> ta_naddr - 1; n >= 0; na++, n--)
	if (na -> na_subnet == 0)
	    switch (na -> na_type) {
	        case NA_NSAP:
		    na -> na_subnet = SUBNET_REALNS;
		    break;

		case NA_TCP:
		    na -> na_subnet = SUBNET_INTERNET;
		    break;

		case NA_X25:
		case NA_BRG:
		    na -> na_subnet = SUBNET_INTL_X25;
		    break;

		default:
		    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
			  ("ta2norm: invalid NSAP address at offset %d",
			   na - ta -> ta_addrs));
		    return NULLTA;
	    }

    bzero ((char *) tz, sizeof *tz);
    bcopy (ta -> ta_selector, tz -> ta_selector,
	   tz -> ta_selectlen = ta -> ta_selectlen);
    ca = tz -> ta_addrs;

    for (ip = ts_communities; *ip; ip++)
	for (na = ta -> ta_addrs, n = ta -> ta_naddr - 1;
	         n >= 0;
	         na++, n--)
	    if (*ip == na -> na_subnet) {
		*ca++ = *na;		/* struct copy */
		tz -> ta_naddr++;
	    }

    for (na = ta -> ta_addrs, n = ta -> ta_naddr - 1; n >= 0; na++, n--) {
	for (ip = ts_communities; *ip; ip++)
	    if (*ip == na -> na_subnet)
		break;
	if (!*ip) {
	    *ca++ = *na;		/* struct copy */
	    tz -> ta_naddr++;
	}
    }

    SLOG (addr_log, LLOG_TRACE, NULLCP,
	  ("ta2norm returns %s", taddr2str (tz)));

    return tz;
}

/* \f

 */