Annotation of 43BSDReno/contrib/isode-beta/acsap/dse.py, revision 1.1.1.1

1.1       root        1: -- dse.py - help out co-resident DSE
                      2: 
                      3: -- $Header: /f/osi/acsap/RCS/dse.py,v 7.2 90/07/09 14:31:05 mrose Exp $
                      4: --
                      5: --
                      6: -- $Log:       dse.py,v $
                      7: -- Revision 7.2  90/07/09  14:31:05  mrose
                      8: -- sync
                      9: -- 
                     10: -- Revision 7.1  89/12/04  08:44:12  mrose
                     11: -- touch-up
                     12: -- 
                     13: -- Revision 7.0  89/11/23  21:22:09  mrose
                     14: -- Release 6.0
                     15: -- 
                     16: 
                     17: --
                     18: --                               NOTICE
                     19: --
                     20: --    Acquisition, use, and distribution of this module and related
                     21: --    materials are subject to the restrictions of a license agreement.
                     22: --    Consult the Preface in the User's Manual for the full terms of
                     23: --    this agreement.
                     24: --
                     25: --
                     26: 
                     27: 
                     28: DSE DEFINITIONS ::=
                     29: %{
                     30: #ifndef        lint
                     31: static char *rcsid = "$Header: /f/osi/acsap/RCS/dse.py,v 7.2 90/07/09 14:31:05 mrose Exp $";
                     32: #endif
                     33: 
                     34: #include <stdio.h>
                     35: #include "psap.h"
                     36: #include "isoaddrs.h"
                     37: #include "tailor.h"
                     38: 
                     39: /* Encoding on "unrealNS" addresses based on
                     40: 
                     41:        "An interim approach to use of Network Addresses",
                     42:        S.E. Kille, January 16, 1989
                     43: 
                     44:  */
                     45: 
                     46: /*  */
                     47: 
                     48: #define        getstr(ss,sl,ds,dl,dn,w) \
                     49:        if (sl > dn) { \
                     50:            advise (NULLCP, "%s too long", w); \
                     51:            return NOTOK; \
                     52:        } \
                     53:        bcopy (ss, ds, dl = sl);
                     54: 
                     55: %}
                     56: 
                     57: BEGIN
                     58: 
                     59: ENCODER        build
                     60: 
                     61: PSAPaddr
                     62:     %{
                     63:        register int    n;
                     64:        struct PSAPaddr *pa = (struct PSAPaddr *) parm;
                     65:        struct SSAPaddr *sa = &pa -> pa_addr;
                     66:        struct TSAPaddr *ta = &sa -> sa_addr;
                     67:        register struct NSAPaddr *na,
                     68:                                 *ca;
                     69:     %}
                     70:     ::=
                     71:        SEQUENCE {
                     72:            pSelector[0]
                     73:                OCTET STRING
                     74:                [[ o pa -> pa_selector $ pa -> pa_selectlen ]]
                     75:                OPTIONAL << pa -> pa_selectlen >>,
                     76: 
                     77:            sSelector[1]
                     78:                OCTET STRING
                     79:                [[ o sa -> sa_selector $ sa -> sa_selectlen ]]
                     80:                OPTIONAL << sa -> sa_selectlen >>,
                     81: 
                     82:            tSelector[2]
                     83:                OCTET STRING
                     84:                [[ o ta -> ta_selector $ ta -> ta_selectlen ]]
                     85:                OPTIONAL << ta -> ta_selectlen >>,
                     86: 
                     87:            nAddress[3]
                     88:                SET OF
                     89:                    %{
                     90:                        if ((ca = na2norm (na)) == NULLNA) {
                     91:                            advise (NULLCP,
                     92:                                    "unable to normalize address, check logs");
                     93:                            return NOTOK;
                     94:                        }
                     95:                    %}
                     96:                <<na = ta -> ta_addrs, n = ta -> ta_naddr; n > 0; na++, n-->>
                     97:                    OCTET STRING
                     98:                    [[ o ca -> na_address $ ca -> na_addrlen ]]
                     99:        }
                    100: 
                    101: 
                    102: DECODER        parse
                    103: 
                    104: PSAPaddr
                    105:     %{
                    106:        struct PSAPaddr *pa = (struct PSAPaddr *) parm;
                    107:        struct SSAPaddr *sa = &pa -> pa_addr;
                    108:        struct TSAPaddr *ta = &sa -> sa_addr;
                    109:     %}
                    110:     ::=
                    111:     %{
                    112:        bzero ((char *) pa, sizeof *pa);
                    113:     %}    
                    114:        SEQUENCE {
                    115:            pSelector[0]
                    116:                OCTET STRING
                    117:                %{
                    118:                    getstr ($$, $$_len, pa -> pa_selector, pa -> pa_selectlen,
                    119:                            sizeof pa -> pa_selector, "psap selector");
                    120:                %}
                    121:                OPTIONAL,
                    122: 
                    123: 
                    124:            sSelector[1]
                    125:                OCTET STRING
                    126:                %{
                    127:                    getstr ($$, $$_len, sa -> sa_selector, sa -> sa_selectlen,
                    128:                            sizeof sa -> sa_selector, "ssap selector");
                    129:                %}
                    130:                OPTIONAL,
                    131: 
                    132:            tSelector[2]
                    133:                OCTET STRING
                    134:                %{
                    135:                    getstr ($$, $$_len, ta -> ta_selector, ta -> ta_selectlen,
                    136:                            sizeof ta -> ta_selector, "tsap selector");
                    137:                %}
                    138:                OPTIONAL,
                    139: 
                    140:            nAddress[3]
                    141:                SET OF
                    142:                    %{
                    143:                        if (ta -> ta_naddr >= NTADDR) {
                    144:                            advise (NULLCP, "too many network addresses");
                    145:                            return NOTOK;
                    146:                        }
                    147:                    %}
                    148:                    NSAPaddr
                    149:                    [[ p (char *) &ta -> ta_addrs[ta -> ta_naddr++] ]]
                    150:        }
                    151: 
                    152: NSAPaddr
                    153:     %{
                    154:        struct NSAPaddr *na = (struct NSAPaddr *) parm;
                    155:     %}
                    156:     ::=
                    157:        OCTET STRING
                    158:        %{
                    159:            if (($$_len == 8)
                    160:                    && (($$[0] == 0x36) || ($$[0] == 0x37))) {
                    161:                int     xlen;                   /* SEK - X121 form */
                    162:                register char   *cp,
                    163:                                *cp2,
                    164:                                *dp;
                    165:                char    nsap[14];
                    166: 
                    167:                dp = nsap;
                    168:                for (cp2 = (cp = $$ + 1) + 7; cp < cp2; cp++) {
                    169:                    register int     j;
                    170: 
                    171:                    if ((j = ((*cp & 0xf0) >> 4)) > 9)
                    172:                        goto concrete;
                    173:                    *dp++ = j + '0';
                    174: 
                    175:                    if ((j = (*cp & 0x0f)) > 9) {
                    176:                        if (j != 0x0f)
                    177:                            goto concrete;
                    178:                    }
                    179:                    else
                    180:                        *dp++ = j + '0';
                    181:                }
                    182: 
                    183:                for (cp = nsap, xlen = 14; *cp == '0'; cp++, xlen--)
                    184:                    continue;
                    185:                na -> na_dtelen = xlen;
                    186:                for (cp2 = na -> na_dte; xlen-- > 0; )
                    187:                        *cp2++ = *cp++;
                    188:                *cp2 = NULL;
                    189: #ifdef BRIDGE_X25
                    190:                na -> na_type = bridgediscrim (na) ? NA_BRG : NA_X25;
                    191: #else
                    192:                na -> na_type = NA_X25;
                    193: #endif
                    194:                na -> na_subnet = SUBNET_INT_X25;
                    195:            }
                    196:            else {
                    197:                register struct ts_interim *ts,
                    198:                                           *tp;
                    199: 
                    200:                tp = NULL;
                    201:                for (ts = ts_interim; ts -> ts_name; ts++)
                    202:                    if ($$_len > ts -> ts_length
                    203:                            && (tp == NULL
                    204:                                    || ts -> ts_length > tp -> ts_length)
                    205:                            && bcmp ($$, ts -> ts_prefix,
                    206:                                     ts -> ts_length) == 0)
                    207:                        tp = ts;
                    208:                if (tp) {
                    209:                    int     i,
                    210:                            ilen,
                    211:                            rlen;
                    212:                    register char   *cp,
                    213:                                    *dp,
                    214:                                    *ep;
                    215:                    char    nsap[NASIZE * 2 + 1];
                    216: 
                    217:                    dp = nsap;
                    218:                    for (cp = $$ + tp -> ts_length, ep = $$ + $$_len;
                    219:                             cp < ep;
                    220:                             cp++) {
                    221:                        register int     j;
                    222: 
                    223:                        if ((j = ((*cp & 0xf0) >> 4)) > 9) {
                    224: concrete: ;
                    225:                            LLOG (addr_log, LLOG_EXCEPTIONS,
                    226:                                  ("invalid concrete encoding"));
                    227:                            goto realNS;
                    228:                        }
                    229:                        *dp++ = j + '0';
                    230: 
                    231:                        if ((j = (*cp & 0x0f)) > 9) {
                    232:                            if (j != 0x0f)
                    233:                                goto concrete;
                    234:                        }
                    235:                        else
                    236:                            *dp++ = j + '0';
                    237:                    }
                    238:                    *dp = NULL;
                    239: 
                    240:                    cp = nsap;
                    241:                    na -> na_subnet = tp -> ts_subnet;
                    242:                    switch (na -> na_type = tp -> ts_syntax) {
                    243:                        case NA_NSAP:
                    244:                            goto unrealNS;
                    245: 
                    246:                        case NA_X25:
                    247:                            if (strlen (cp) < 1) {
                    248:                                LLOG (addr_log, LLOG_EXCEPTIONS,
                    249:                                      ("missing DTE+CUDF indicator: %s",
                    250:                                       nsap));
                    251:                                goto realNS;
                    252:                            }
                    253:                            (void) sscanf (cp, "%1d", &i);
                    254:                            cp += 1;
                    255:                            switch (i) {
                    256:                                case 0: /* DTE only */
                    257:                                    break;
                    258: 
                    259:                                case 1: /* DTE+PID */
                    260:                                case 2: /* DTE+CUDF */
                    261:                                    if (strlen (cp) < 1) {
                    262:                                        LLOG (addr_log, LLOG_EXCEPTIONS,
                    263:                                              ("missing DTE+CUDF indicator: %s",
                    264:                                               nsap));
                    265:                                        goto realNS;
                    266:                                    }
                    267:                                    (void) sscanf (cp, "%1d", &ilen);
                    268:                                    cp += 1;
                    269:                                    rlen = ilen * 3;
                    270:                                    if (strlen (cp) < rlen) {
                    271:                                        LLOG (addr_log, LLOG_EXCEPTIONS,
                    272:                                              ("bad DTE+CUDF length: %s",
                    273:                                               nsap));
                    274:                                        goto realNS;
                    275:                                    }
                    276:                                    if (i == 1) {
                    277:                                        if (ilen > NPSIZE) {
                    278:                                            LLOG (addr_log,
                    279:                                                  LLOG_EXCEPTIONS,
                    280:                                                  ("PID too long: %s",
                    281:                                                   nsap));
                    282:                                            goto realNS;
                    283:                                        }
                    284:                                        dp = na -> na_pid;
                    285:                                        na -> na_pidlen = ilen;
                    286:                                    }
                    287:                                    else {
                    288:                                        if (ilen > CUDFSIZE) {
                    289:                                            LLOG (addr_log,
                    290:                                                  LLOG_EXCEPTIONS,
                    291:                                                  ("CUDF too long: %s",
                    292:                                                   nsap));
                    293:                                            goto realNS;
                    294:                                        }
                    295:                                        dp = na -> na_cudf;
                    296:                                        na -> na_cudflen = ilen;
                    297:                                    }
                    298:                                    for (; rlen > 0; rlen -= 3) {
                    299:                                        (void) sscanf (cp, "%3d", &i);
                    300:                                        cp += 3;
                    301: 
                    302:                                        if (i > 255) {
                    303:                                            LLOG (addr_log,
                    304:                                                  LLOG_EXCEPTIONS,
                    305:                                                  ("invalid PID/CUDF: %s",
                    306:                                                   nsap));
                    307:                                            goto realNS;
                    308:                                        }
                    309:                                        *dp++ = i & 0xff;
                    310:                                    }
                    311:                                    break;
                    312: 
                    313:                                default:
                    314:                                    LLOG (addr_log, LLOG_EXCEPTIONS,
                    315:                                          ("invalid DTE+CUDF indicator: %s",
                    316:                                           nsap));
                    317:                                    goto realNS;
                    318:                                }
                    319:                            (void) strcpy (na -> na_dte, cp);
                    320:                            na -> na_dtelen = strlen (na -> na_dte);
                    321: 
                    322: #ifdef BRIDGE_X25
                    323:                            if (bridgediscrim (na))
                    324:                                na -> na_type = NA_BRG;
                    325: #endif
                    326:                            break;
                    327: 
                    328:                        case NA_TCP:
                    329:                            if (strlen (cp) < 12) {
                    330:                                LLOG (addr_log, LLOG_EXCEPTIONS,
                    331:                                      ("missing IP address: %s", nsap));
                    332:                                goto realNS;
                    333:                            }
                    334:                            {
                    335:                                int         q[4];
                    336: 
                    337:                                (void) sscanf (cp, "%3d%3d%3d%3d", q,
                    338:                                               q + 1, q + 2, q + 3);
                    339:                                (void) sprintf (na -> na_domain,
                    340:                                                "%d.%d.%d.%d",
                    341:                                                q[0], q[1], q[2], q[3]);
                    342:                            }
                    343:                            cp += 12;
                    344: 
                    345:                            if (*cp) {
                    346:                                if (strlen (cp) < 5) {
                    347:                                    LLOG (addr_log, LLOG_EXCEPTIONS,
                    348:                                          ("missing port: %s", nsap));
                    349:                                    goto realNS;
                    350:                                }
                    351:                                (void) sscanf (cp, "%5d", &i);
                    352:                                cp += 5;
                    353:                                na -> na_port = htons ((u_short) i);
                    354: 
                    355:                                if (*cp) {
                    356:                                    if (strlen (cp) < 5) {
                    357:                                        LLOG (addr_log, LLOG_EXCEPTIONS,
                    358:                                              ("missing tset: %s", nsap));
                    359:                                        goto realNS;
                    360:                                    }
                    361:                                    (void) sscanf (cp, "%5d", &i);
                    362:                                    cp += 5;
                    363:                                    na -> na_tset = (u_short) i;
                    364: 
                    365:                                    if (*cp)
                    366:                                        LLOG (addr_log, LLOG_EXCEPTIONS,
                    367:                                              ("extra TCP information: %s",
                    368:                                               nsap));
                    369:                                }
                    370:                            }
                    371:                            break;
                    372: 
                    373:                        default:
                    374:                            LLOG (addr_log, LLOG_NOTICE,
                    375:                                  ("unknown syntax %d for DSP: %s",
                    376:                                   ts -> ts_syntax, nsap));
                    377:                            goto realNS;
                    378:                        }
                    379:                }
                    380:                else {
                    381: realNS: ;
                    382:                    na -> na_type = NA_NSAP;
                    383:                    na -> na_subnet = SUBNET_REALNS;
                    384: unrealNS: ;
                    385:                    getstr ($$, $$_len, na -> na_address, na -> na_addrlen,
                    386:                            sizeof na -> na_address, "NSAP address");
                    387:                }
                    388:            }
                    389:        %}
                    390: 
                    391: 
                    392: PRINTER        print
                    393: 
                    394: PSAPaddr ::=
                    395:        SEQUENCE {
                    396:            pSelector[0]
                    397:                OCTET STRING
                    398:                OPTIONAL,
                    399: 
                    400:            sSelector[1]
                    401:                OCTET STRING
                    402:                OPTIONAL,
                    403: 
                    404:            tSelector[2]
                    405:                OCTET STRING
                    406:                OPTIONAL,
                    407: 
                    408:            nAddress[3]
                    409:                SET OF
                    410:                    OCTET STRING
                    411:        }
                    412: 
                    413: END

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.