Annotation of 43BSDReno/contrib/isode-beta/imisc/ryinitiator.c, revision 1.1

1.1     ! root        1: /* ryinitiator.c - generic interactive initiator */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/imisc/RCS/ryinitiator.c,v 7.2 90/07/09 14:38:52 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/imisc/RCS/ryinitiator.c,v 7.2 90/07/09 14:38:52 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       ryinitiator.c,v $
        !            12:  * Revision 7.2  90/07/09  14:38:52  mrose
        !            13:  * sync
        !            14:  * 
        !            15:  * Revision 7.1  90/07/01  21:04:09  mrose
        !            16:  * pepsy
        !            17:  * 
        !            18:  * Revision 7.0  89/11/23  21:57:42  mrose
        !            19:  * Release 6.0
        !            20:  * 
        !            21:  */
        !            22: 
        !            23: /*
        !            24:  *                               NOTICE
        !            25:  *
        !            26:  *    Acquisition, use, and distribution of this module and related
        !            27:  *    materials are subject to the restrictions of a license agreement.
        !            28:  *    Consult the Preface in the User's Manual for the full terms of
        !            29:  *    this agreement.
        !            30:  *
        !            31:  */
        !            32: 
        !            33: 
        !            34: #include <stdio.h>
        !            35: #include <varargs.h>
        !            36: #include "ryinitiator.h"
        !            37: 
        !            38: #undef TIMER
        !            39: #undef TMS
        !            40: #ifdef BSD42
        !            41: #define        TIMER
        !            42: #endif
        !            43: #ifdef SYS5
        !            44: #define        TIMER
        !            45: #ifndef        HPUX
        !            46: #include <sys/times.h>
        !            47: #define        TMS
        !            48: #endif
        !            49: #endif
        !            50: 
        !            51: /*    DATA */
        !            52: 
        !            53: static int count = 1;
        !            54: int    length = 536;
        !            55: 
        !            56: 
        !            57: #ifdef TIMER
        !            58: #define        DS_RESULT(ds)   (timing ? timing_result : (ds) -> ds_result)
        !            59: 
        !            60: static int timing = 0;
        !            61: 
        !            62: int    timing_result ();
        !            63: #else
        !            64: #define        DS_RESULT(ds)   ((ds) -> ds_result)
        !            65: #endif
        !            66: 
        !            67: static char *myname = "ryinitiator";
        !            68: 
        !            69: 
        !            70: extern char *isodeversion;
        !            71: 
        !            72: /*    INITIATOR */
        !            73: 
        !            74: /* ARGSUSED */
        !            75: 
        !            76: ryinitiator (argc, argv, myservice, mycontext, mypci, ops, dispatches, quit)
        !            77: int    argc;
        !            78: char  **argv,
        !            79:        *myservice,
        !            80:        *mycontext,
        !            81:        *mypci;
        !            82: struct RyOperation ops[];
        !            83: struct dispatch *dispatches;
        !            84: IFP    quit;
        !            85: {
        !            86:     int            iloop,
        !            87:            sd;
        !            88:     register char  *cp,
        !            89:                  **ap;
        !            90:     char    buffer[BUFSIZ],
        !            91:           *vec[NVEC + 1];
        !            92:     register struct dispatch   *ds;
        !            93:     struct QOStype qos;
        !            94:     struct SSAPref sfs;
        !            95:     register struct SSAPref *sf;
        !            96:     register struct PSAPaddr *pa;
        !            97:     struct AcSAPconnect accs;
        !            98:     register struct AcSAPconnect   *acc = &accs;
        !            99:     struct AcSAPindication  acis;
        !           100:     register struct AcSAPindication *aci = &acis;
        !           101:     register struct AcSAPabort *aca = &aci -> aci_abort;
        !           102:     AEI            aei;
        !           103:     OID            ctx,
        !           104:            pci;
        !           105:     struct PSAPctxlist pcs;
        !           106:     register struct PSAPctxlist *pc = &pcs;
        !           107:     struct RoSAPindication rois;
        !           108:     register struct RoSAPindication *roi = &rois;
        !           109:     register struct RoSAPpreject *rop = &roi -> roi_preject;
        !           110: 
        !           111:     if (myname = rindex (argv[0], '/'))
        !           112:        myname++;
        !           113:     if (myname == NULL || *myname == NULL)
        !           114:        myname = argv[0];
        !           115: 
        !           116:     isodetailor (myname, 1);
        !           117: 
        !           118:     qos.qos_reliability = HIGH_QUALITY;
        !           119: 
        !           120:     for (ap = argv + 1; cp = *ap; ap++) {
        !           121:        if (*cp != '-')
        !           122:            break;
        !           123: 
        !           124:        if (strcmp (cp, "-low") == 0) {
        !           125:            qos.qos_reliability = LOW_QUALITY;
        !           126:            continue;
        !           127:        }
        !           128:        if (strcmp (cp, "-high") == 0) {
        !           129:            qos.qos_reliability = HIGH_QUALITY;
        !           130:            continue;
        !           131:        }
        !           132:        if (strcmp (cp, "-c") == 0) {
        !           133:            if ((cp = *++ap) == NULL
        !           134:                    || sscanf (cp, "%d", &count) != 1
        !           135:                    || count < 1)
        !           136:                adios (NULLCP, "usage: %s -c count", myname);
        !           137: #ifdef TIMER
        !           138:            timing++;
        !           139: #endif
        !           140:            continue;
        !           141:        }
        !           142:        if (strcmp (cp, "-l") == 0) {
        !           143:            if ((cp = *++ap) == NULL
        !           144:                    || sscanf (cp, "%d", &length) != 1
        !           145:                    || length < 0)
        !           146:                adios (NULLCP, "usage: %s -l length", myname);
        !           147:            continue;
        !           148:        }
        !           149: 
        !           150:        adios (NULLCP, "%s: unknown switch", cp);
        !           151:     }
        !           152: 
        !           153:     if ((cp = *ap++) == NULL)
        !           154:        adios (NULLCP, "usage: %s host [operation [ arguments ... ]]", myname);
        !           155:        
        !           156:     if ((aei = _str2aei (cp, myservice, mycontext, 0)) == NULLAEI)
        !           157:        adios (NULLCP, "unable to resolve service: %s", PY_pepy);
        !           158:     if ((pa = aei2addr (aei)) == NULLPA)
        !           159:        adios (NULLCP, "address translation failed");
        !           160: 
        !           161:     if ((ctx = ode2oid (mycontext)) == NULLOID)
        !           162:        adios (NULLCP, "%s: unknown object descriptor", mycontext);
        !           163:     if ((ctx = oid_cpy (ctx)) == NULLOID)
        !           164:        adios (NULLCP, "out of memory");
        !           165:     if ((pci = ode2oid (mypci)) == NULLOID)
        !           166:        adios (NULLCP, "%s: unknown object descriptor", mypci);
        !           167:     if ((pci = oid_cpy (pci)) == NULLOID)
        !           168:        adios (NULLCP, "out of memory");
        !           169:     pc -> pc_nctx = 1;
        !           170:     pc -> pc_ctx[0].pc_id = 1;
        !           171:     pc -> pc_ctx[0].pc_asn = pci;
        !           172:     pc -> pc_ctx[0].pc_atn = NULLOID;
        !           173: 
        !           174:     if ((sf = addr2ref (PLocalHostName ())) == NULL) {
        !           175:        sf = &sfs;
        !           176:        (void) bzero ((char *) sf, sizeof *sf);
        !           177:     }
        !           178: 
        !           179:     if (*ap == NULL) {
        !           180:        printf ("%s", myname);
        !           181:        if (sf -> sr_ulen > 2)
        !           182:            printf (" running on host %s", sf -> sr_udata + 2);
        !           183:        if (sf -> sr_clen > 2)
        !           184:            printf (" at %s", sf -> sr_cdata + 2);
        !           185:        printf (" [%s, ", oid2ode (ctx));
        !           186:        printf ("%s]\n", oid2ode (pci));
        !           187:        printf ("using %s\n", isodeversion);
        !           188: 
        !           189:        printf ("%s... ", cp);
        !           190:        (void) fflush (stdout);
        !           191:     
        !           192:        iloop = 1;
        !           193:     }
        !           194:     else {
        !           195:        cp = *ap++;
        !           196:        for (ds = dispatches; ds -> ds_name; ds++)
        !           197:            if (strcmp (ds -> ds_name, cp) == 0)
        !           198:                break;
        !           199:        if (ds -> ds_name == NULL)
        !           200:            adios (NULLCP, "unknown operation \"%s\"", cp);
        !           201: 
        !           202:        iloop = 0;
        !           203:     }
        !           204: 
        !           205:     if (AcAssocRequest (ctx, NULLAEI, aei, NULLPA, pa, pc, NULLOID,
        !           206:                0, ROS_MYREQUIRE, SERIAL_NONE, 0, sf, NULLPEP, 0, &qos,
        !           207:                acc, aci)
        !           208:            == NOTOK)
        !           209:        acs_adios (aca, "A-ASSOCIATE.REQUEST");
        !           210: 
        !           211:     if (acc -> acc_result != ACS_ACCEPT) {
        !           212:        if (iloop)
        !           213:            printf ("failed\n");
        !           214: 
        !           215:        adios (NULLCP, "association rejected: [%s]",
        !           216:                AcErrString (acc -> acc_result));
        !           217:     }
        !           218:     if (iloop) {
        !           219:        printf ("connected\n");
        !           220:        (void) fflush (stdout);
        !           221:     }
        !           222: 
        !           223:     sd = acc -> acc_sd;
        !           224:     ACCFREE (acc);
        !           225: 
        !           226:     if (RoSetService (sd, RoPService, roi) == NOTOK)
        !           227:        ros_adios (rop, "set RO/PS fails");
        !           228: 
        !           229:     if (iloop) {
        !           230:        for (;;) {
        !           231:            if (getline (buffer) == NOTOK)
        !           232:                break;
        !           233: 
        !           234:            if (str2vec (buffer, vec) < 1)
        !           235:                continue;
        !           236: 
        !           237:            for (ds = dispatches; ds -> ds_name; ds++)
        !           238:                if (strcmp (ds -> ds_name, vec[0]) == 0)
        !           239:                    break;
        !           240:            if (ds -> ds_name == NULL) {
        !           241:                advise (NULLCP, "unknown operation \"%s\"", vec[0]);
        !           242:                continue;
        !           243:            }
        !           244: 
        !           245:            invoke (sd, ops, ds, vec + 1);
        !           246:        }
        !           247:     }
        !           248:     else
        !           249:        invoke (sd, ops, ds, ap);
        !           250: 
        !           251:     (*quit) (sd, (struct dispatch *) NULL, (char **) NULL, (caddr_t *) NULL);
        !           252: }
        !           253: 
        !           254: /*    INVOKE */
        !           255: 
        !           256: static invoke (sd, ops, ds, args)
        !           257: int    sd;
        !           258: struct RyOperation ops[];
        !           259: register struct dispatch *ds;
        !           260: char  **args;
        !           261: {
        !           262:     register int    i;
        !           263:     int            cc,
        !           264:            result;
        !           265:     caddr_t in;
        !           266:     struct RoSAPindication  rois;
        !           267:     register struct RoSAPindication *roi = &rois;
        !           268:     register struct RoSAPpreject   *rop = &roi -> roi_preject;
        !           269: 
        !           270:     in = NULL;
        !           271:     if (ds -> ds_argument && (*ds -> ds_argument) (sd, ds, args, &in) == NOTOK)
        !           272:        return;
        !           273: 
        !           274: #ifdef TIMER
        !           275:     if (timing) {
        !           276:        register struct RyOperation *ryo = ops;
        !           277:        PE      pe;
        !           278: 
        !           279:        cc = 0;
        !           280: 
        !           281:        for (; ryo -> ryo_name; ryo++)
        !           282:            if (ryo -> ryo_op == ds -> ds_operation)
        !           283:                break;
        !           284:        if (!ryo -> ryo_name || !ryo -> ryo_arg_mod)
        !           285:            goto nope;
        !           286: 
        !           287:        pe = NULLPE;
        !           288:        if (enc_f (ryo -> ryo_arg_index, ryo -> ryo_arg_mod, &pe, 1, NULL,
        !           289:                   NULLCP, in) != NOTOK)
        !           290:            cc = ps_get_abs (pe);
        !           291:        if (pe)
        !           292:            pe_free (pe);
        !           293: 
        !           294: nope: ;
        !           295:        timer (0, 0);
        !           296:     }
        !           297: #endif
        !           298: 
        !           299:     for (i = 0; i < count; i++)
        !           300:        switch (result = RyStub (sd, ops, ds -> ds_operation, RyGenID (sd),
        !           301:                                 NULLIP, in, DS_RESULT (ds), ds -> ds_error,
        !           302:                                 ROS_SYNC, roi)) {
        !           303:            case NOTOK:         /* failure */
        !           304:                if (ROS_FATAL (rop -> rop_reason))
        !           305:                    ros_adios (rop, "STUB");
        !           306:                ros_advise (rop, "STUB");
        !           307:                goto out;
        !           308: 
        !           309:            case OK:            /* got a result/error response */
        !           310:                break;
        !           311: 
        !           312:            case DONE:          /* got RO-END? */
        !           313:                adios (NULLCP, "got RO-END.INDICATION");
        !           314:                /* NOTREACHED */
        !           315: 
        !           316:            default:
        !           317:                adios (NULLCP, "unknown return from RyStub=%d", result);
        !           318:                /* NOTREACHED */
        !           319:        }
        !           320: 
        !           321: #ifdef TIMER
        !           322:     if (timing)
        !           323:        timer (cc, count);
        !           324: #endif
        !           325: 
        !           326: out: ;
        !           327:     if (ds -> ds_fr_mod && in)
        !           328:        fre_obj (in, ds -> ds_fr_mod -> md_dtab[ds -> ds_fr_index],
        !           329:                 ds -> ds_fr_mod);
        !           330: }
        !           331: 
        !           332: /*    INTERACTIVE */
        !           333: 
        !           334: static int  getline (buffer)
        !           335: char   *buffer;
        !           336: {
        !           337:     register int    i;
        !           338:     register char  *cp,
        !           339:                    *ep;
        !           340:     static int  sticky = 0;
        !           341: 
        !           342:     if (sticky) {
        !           343:        sticky = 0;
        !           344:        return NOTOK;
        !           345:     }
        !           346: 
        !           347:     printf ("%s> ", myname);
        !           348:     (void) fflush (stdout);
        !           349: 
        !           350:     for (ep = (cp = buffer) + BUFSIZ - 1; (i = getchar ()) != '\n';) {
        !           351:        if (i == EOF) {
        !           352:            printf ("\n");
        !           353:            clearerr (stdin);
        !           354:            if (cp != buffer) {
        !           355:                sticky++;
        !           356:                break;
        !           357:            }
        !           358: 
        !           359:            return NOTOK;
        !           360:        }
        !           361: 
        !           362:        if (cp < ep)
        !           363:            *cp++ = i;
        !           364:     }
        !           365:     *cp = NULL;
        !           366: 
        !           367:     return OK;
        !           368: }
        !           369: 
        !           370: /*    TIMER */
        !           371: 
        !           372: #ifdef TIMER
        !           373: 
        !           374: #ifndef        NBBY
        !           375: #define        NBBY    8
        !           376: #endif
        !           377: 
        !           378: 
        !           379: #ifndef        TMS
        !           380: static  timer (bytes, pkts)
        !           381: int     bytes,
        !           382:        pkts;
        !           383: {
        !           384:     long    ms;
        !           385:     float   bs,
        !           386:            ps;
        !           387:     struct timeval  stop,
        !           388:                     td;
        !           389:     static struct timeval   start;
        !           390: 
        !           391:     if (pkts == 0) {
        !           392:        (void) gettimeofday (&start, (struct timezone *) 0);
        !           393:        return;
        !           394:     }
        !           395:     else
        !           396:        (void) gettimeofday (&stop, (struct timezone  *) 0);
        !           397: 
        !           398:     tvsub (&td, &stop, &start);
        !           399:     ms = (td.tv_sec * 1000) + (td.tv_usec / 1000);
        !           400:     bs = (((float) bytes * pkts * NBBY * 1000) / (float) (ms ? ms : 1)) / NBBY;
        !           401:     ps = ((float) pkts * 1000) / (float) (ms ? ms : 1);
        !           402: 
        !           403:     printf ("%d operations in %d.%02d seconds (%.2f ops/s)",
        !           404:            pkts, td.tv_sec, td.tv_usec / 10000, ps);
        !           405:     if (bytes > 0)
        !           406:        printf ("; %d bytes/op for %.2f Kbytes/s", bytes, bs / 1024);
        !           407:     printf ("\n");
        !           408: }
        !           409: 
        !           410: 
        !           411: static  tvsub (tdiff, t1, t0)
        !           412: register struct timeval *tdiff,
        !           413:                        *t1,
        !           414:                        *t0;
        !           415: {
        !           416: 
        !           417:     tdiff -> tv_sec = t1 -> tv_sec - t0 -> tv_sec;
        !           418:     tdiff -> tv_usec = t1 -> tv_usec - t0 -> tv_usec;
        !           419:     if (tdiff -> tv_usec < 0)
        !           420:        tdiff -> tv_sec--, tdiff -> tv_usec += 1000000;
        !           421: }
        !           422: #else
        !           423: long   times ();
        !           424: 
        !           425: 
        !           426: static timer (bytes, pkts)
        !           427: int    bytes,
        !           428:        pkts;
        !           429: {
        !           430:     long    ms;
        !           431:     float   bs,
        !           432:            ps;
        !           433:     long    stop,
        !           434:            td,
        !           435:            secs,
        !           436:            msecs;
        !           437:     struct tms tm;
        !           438:     static long start;
        !           439: 
        !           440:     if (pkts == 0) {
        !           441:        start = times (&tm);
        !           442:        return;
        !           443:     }
        !           444:     else
        !           445:        stop = times (&tm);
        !           446: 
        !           447:     td = stop - start;
        !           448:     secs = td / 60, msecs = (td % 60) * 1000 / 60;
        !           449:     ms = (secs * 1000) +  msecs;
        !           450:     bs = (((float) bytes * pkts * NBBY * 1000) / (float) (ms ? ms : 1)) / NBBY;
        !           451:     ps = ((float) pkts * 1000) / (float) (ms ? ms : 1);
        !           452: 
        !           453:     printf ("%d operations in %d.%02d seconds (%.2f ops/s)",
        !           454:            pkts, secs, msecs / 10, ps);
        !           455:     if (bytes > 0)
        !           456:        printf ("; %d bytes/op for %.2f Kbytes/s", bytes, bs / 1024);
        !           457:     printf ("\n");
        !           458: }
        !           459: #endif
        !           460: #endif
        !           461: 
        !           462: /*  */
        !           463: 
        !           464: /* ARGSUSED */
        !           465: 
        !           466: static int    timing_result (sd, id, dummy, result, roi)
        !           467: int    sd,
        !           468:        id,
        !           469:        dummy;
        !           470: caddr_t result;
        !           471: struct RoSAPindication *roi;
        !           472: {
        !           473:     return OK;
        !           474: }
        !           475: 
        !           476: /*    ERRORS */
        !           477: 
        !           478: void   ros_adios (rop, event)
        !           479: register struct RoSAPpreject *rop;
        !           480: char   *event;
        !           481: {
        !           482:     ros_advise (rop, event);
        !           483: 
        !           484:     _exit (1);
        !           485: }
        !           486: 
        !           487: 
        !           488: void   ros_advise (rop, event)
        !           489: register struct RoSAPpreject *rop;
        !           490: char   *event;
        !           491: {
        !           492:     char    buffer[BUFSIZ];
        !           493: 
        !           494:     if (rop -> rop_cc > 0)
        !           495:        (void) sprintf (buffer, "[%s] %*.*s", RoErrString (rop -> rop_reason),
        !           496:                rop -> rop_cc, rop -> rop_cc, rop -> rop_data);
        !           497:     else
        !           498:        (void) sprintf (buffer, "[%s]", RoErrString (rop -> rop_reason));
        !           499: 
        !           500:     advise (NULLCP, "%s: %s", event, buffer);
        !           501: }
        !           502: 
        !           503: /*  */
        !           504: 
        !           505: void   acs_adios (aca, event)
        !           506: register struct AcSAPabort *aca;
        !           507: char   *event;
        !           508: {
        !           509:     acs_advise (aca, event);
        !           510: 
        !           511:     _exit (1);
        !           512: }
        !           513: 
        !           514: 
        !           515: void   acs_advise (aca, event)
        !           516: register struct AcSAPabort *aca;
        !           517: char   *event;
        !           518: {
        !           519:     char    buffer[BUFSIZ];
        !           520: 
        !           521:     if (aca -> aca_cc > 0)
        !           522:        (void) sprintf (buffer, "[%s] %*.*s",
        !           523:                AcErrString (aca -> aca_reason),
        !           524:                aca -> aca_cc, aca -> aca_cc, aca -> aca_data);
        !           525:     else
        !           526:        (void) sprintf (buffer, "[%s]", AcErrString (aca -> aca_reason));
        !           527: 
        !           528:        advise (NULLCP, "%s: %s (source %d)", event, buffer,
        !           529:                aca -> aca_source);
        !           530: }
        !           531: 
        !           532: /*  */
        !           533: 
        !           534: #ifndef        lint
        !           535: void   _advise ();
        !           536: 
        !           537: 
        !           538: void   adios (va_alist)
        !           539: va_dcl
        !           540: {
        !           541:     va_list ap;
        !           542: 
        !           543:     va_start (ap);
        !           544: 
        !           545:     _advise (ap);
        !           546: 
        !           547:     va_end (ap);
        !           548: 
        !           549:     _exit (1);
        !           550: }
        !           551: #else
        !           552: /* VARARGS */
        !           553: 
        !           554: void   adios (what, fmt)
        !           555: char   *what,
        !           556:        *fmt;
        !           557: {
        !           558:     adios (what, fmt);
        !           559: }
        !           560: #endif
        !           561: 
        !           562: 
        !           563: #ifndef        lint
        !           564: void   advise (va_alist)
        !           565: va_dcl
        !           566: {
        !           567:     va_list ap;
        !           568: 
        !           569:     va_start (ap);
        !           570: 
        !           571:     _advise (ap);
        !           572: 
        !           573:     va_end (ap);
        !           574: }
        !           575: 
        !           576: 
        !           577: static void  _advise (ap)
        !           578: va_list        ap;
        !           579: {
        !           580:     char    buffer[BUFSIZ];
        !           581: 
        !           582:     asprintf (buffer, ap);
        !           583: 
        !           584:     (void) fflush (stdout);
        !           585: 
        !           586:     fprintf (stderr, "%s: ", myname);
        !           587:     (void) fputs (buffer, stderr);
        !           588:     (void) fputc ('\n', stderr);
        !           589: 
        !           590:     (void) fflush (stderr);
        !           591: }
        !           592: #else
        !           593: /* VARARGS */
        !           594: 
        !           595: void   advise (what, fmt)
        !           596: char   *what,
        !           597:        *fmt;
        !           598: {
        !           599:     advise (what, fmt);
        !           600: }
        !           601: #endif
        !           602: 
        !           603: 
        !           604: #ifndef        lint
        !           605: void   ryr_advise (va_alist)
        !           606: va_dcl
        !           607: {
        !           608:     va_list ap;
        !           609: 
        !           610:     va_start (ap);
        !           611: 
        !           612:     _advise (ap);
        !           613: 
        !           614:     va_end (ap);
        !           615: }
        !           616: #else
        !           617: /* VARARGS */
        !           618: 
        !           619: void   ryr_advise (what, fmt)
        !           620: char   *what,
        !           621:        *fmt;
        !           622: {
        !           623:     ryr_advise (what, fmt);
        !           624: }
        !           625: #endif

unix.superglobalmegacorp.com

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