Annotation of 43BSDReno/contrib/isode-beta/doc/manual/ryinitiator-c.c, revision 1.1.1.1

1.1       root        1: /* ryinitiator.c - generic interactive initiator */
                      2: 
                      3: #include <stdio.h>
                      4: #include <varargs.h>
                      5: #include "ryinitiator.h"
                      6: 
                      7: /*    DATA */
                      8: 
                      9: static char *myname = "ryinitiator";
                     10: 
                     11: 
                     12: extern char *isodeversion;
                     13: 
                     14: /*    INITIATOR */
                     15: 
                     16: ryinitiator (argc, argv, myservice, mycontext, mypci, ops, dispatches, quit)
                     17: int    argc;
                     18: char  **argv,
                     19:        *myservice,
                     20:        *mycontext,
                     21:        *mypci;
                     22: struct RyOperation ops[];
                     23: struct dispatch *dispatches;
                     24: IFP    quit;
                     25: {
                     26:     int            iloop,
                     27:            sd;
                     28:     char    buffer[BUFSIZ],
                     29:           *vec[NVEC + 1];
                     30:     register struct dispatch   *ds;
                     31:     struct SSAPref sfs;
                     32:     register struct SSAPref *sf;
                     33:     register struct PSAPaddr *pa;
                     34:     struct AcSAPconnect accs;
                     35:     register struct AcSAPconnect   *acc = &accs;
                     36:     struct AcSAPindication  acis;
                     37:     register struct AcSAPindication *aci = &acis;
                     38:     register struct AcSAPabort *aca = &aci -> aci_abort;
                     39:     AEI            aei;
                     40:     OID            ctx,
                     41:            pci;
                     42:     struct PSAPctxlist pcs;
                     43:     register struct PSAPctxlist *pc = &pcs;
                     44:     struct RoSAPindication rois;
                     45:     register struct RoSAPindication *roi = &rois;
                     46:     register struct RoSAPpreject *rop = &roi -> roi_preject;
                     47: 
                     48:     if (myname = rindex (argv[0], '/'))
                     49:        myname++;
                     50:     if (myname == NULL || *myname == NULL)
                     51:        myname = argv[0];
                     52: 
                     53:     if (argc < 2)
                     54:        adios (NULLCP, "usage: %s host [operation [ arguments ... ]]", myname);
                     55: 
                     56:     if ((aei = _str2aei (argv[1], myservice, mycontext, 0)) == NULLAEI)
                     57:        adios (NULLCP, "unable to resolve service: %s", PY_pepy);
                     58:     if ((pa = aei2addr (aei)) == NULLPA)
                     59:        adios (NULLCP, "address translation failed");
                     60: 
                     61:     if ((ctx = ode2oid (mycontext)) == NULLOID)
                     62:        adios (NULLCP, "%s: unknown object descriptor", mycontext);
                     63:     if ((ctx = oid_cpy (ctx)) == NULLOID)
                     64:        adios (NULLCP, "out of memory");
                     65:     if ((pci = ode2oid (mypci)) == NULLOID)
                     66:        adios (NULLCP, "%s: unknown object descriptor", mypci);
                     67:     if ((pci = oid_cpy (pci)) == NULLOID)
                     68:        adios (NULLCP, "out of memory");
                     69:     pc -> pc_nctx = 1;
                     70:     pc -> pc_ctx[0].pc_id = 1;
                     71:     pc -> pc_ctx[0].pc_asn = pci;
                     72:     pc -> pc_ctx[0].pc_atn = NULLOID;
                     73: 
                     74:     if ((sf = addr2ref (PLocalHostName ())) == NULL) {
                     75:        sf = &sfs;
                     76:        (void) bzero ((char *) sf, sizeof *sf);
                     77:     }
                     78: 
                     79:     if (argc < 3) {
                     80:        printf ("%s", myname);
                     81:        if (sf -> sr_ulen > 2)
                     82:            printf (" running on host %s", sf -> sr_udata + 2);
                     83:        if (sf -> sr_clen > 2)
                     84:            printf (" at %s", sf -> sr_cdata + 2);
                     85:        printf (" [%s, ", oid2ode (ctx));
                     86:        printf ("%s]\n", oid2ode (pci));
                     87:        printf ("using %s\n", isodeversion);
                     88: 
                     89:        printf ("%s... ", argv[1]);
                     90:        (void) fflush (stdout);
                     91:     
                     92:        iloop = 1;
                     93:     }
                     94:     else {
                     95:        for (ds = dispatches; ds -> ds_name; ds++)
                     96:            if (strcmp (ds -> ds_name, argv[2]) == 0)
                     97:                break;
                     98:        if (ds -> ds_name == NULL)
                     99:            adios (NULLCP, "unknown operation \"%s\"", argv[2]);
                    100: 
                    101:        iloop = 0;
                    102:     }
                    103: 
                    104:     if (AcAssocRequest (ctx, NULLAEI, aei, NULLPA, pa, pc, NULLOID,
                    105:                0, ROS_MYREQUIRE, SERIAL_NONE, 0, sf, NULLPEP, 0, NULLQOS,
                    106:                acc, aci)
                    107:            == NOTOK)
                    108:        acs_adios (aca, "A-ASSOCIATE.REQUEST");
                    109: 
                    110:     if (acc -> acc_result != ACS_ACCEPT) {
                    111:        if (iloop)
                    112:            printf ("failed\n");
                    113: 
                    114:        adios (NULLCP, "association rejected: [%s]",
                    115:                AcErrString (acc -> acc_result));
                    116:     }
                    117:     if (iloop) {
                    118:        printf ("connected\n");
                    119:        (void) fflush (stdout);
                    120:     }
                    121: 
                    122:     sd = acc -> acc_sd;
                    123:     ACCFREE (acc);
                    124: 
                    125:     if (RoSetService (sd, RoPService, roi) == NOTOK)
                    126:        ros_adios (rop, "set RO/PS fails");
                    127: 
                    128:     if (iloop) {
                    129:        for (;;) {
                    130:            if (getline (buffer) == NOTOK)
                    131:                break;
                    132: 
                    133:            if (str2vec (buffer, vec) < 1)
                    134:                continue;
                    135: 
                    136:            for (ds = dispatches; ds -> ds_name; ds++)
                    137:                if (strcmp (ds -> ds_name, vec[0]) == 0)
                    138:                    break;
                    139:            if (ds -> ds_name == NULL) {
                    140:                advise (NULLCP, "unknown operation \"%s\"", vec[0]);
                    141:                continue;
                    142:            }
                    143: 
                    144:            invoke (sd, ops, ds, vec + 1);
                    145:        }
                    146:     }
                    147:     else
                    148:        invoke (sd, ops, ds, argv + 3);
                    149: 
                    150:     (*quit) (sd, (struct dispatch *) NULL, (char **) NULL, (caddr_t *) NULL);
                    151: }
                    152: 
                    153: /*  */
                    154: 
                    155: static invoke (sd, ops, ds, args)
                    156: int    sd;
                    157: struct RyOperation ops[];
                    158: register struct dispatch *ds;
                    159: char  **args;
                    160: {
                    161:     int            result;
                    162:     caddr_t in;
                    163:     struct RoSAPindication  rois;
                    164:     register struct RoSAPindication *roi = &rois;
                    165:     register struct RoSAPpreject   *rop = &roi -> roi_preject;
                    166: 
                    167:     in = NULL;
                    168:     if (ds -> ds_argument && (*ds -> ds_argument) (sd, ds, args, &in) == NOTOK)
                    169:        return;
                    170: 
                    171:     switch (result = RyStub (sd, ops, ds -> ds_operation, RyGenID (sd), NULLIP,
                    172:                    in, ds -> ds_result, ds -> ds_error, ROS_SYNC, roi)) {
                    173:        case NOTOK:             /* failure */
                    174:            if (ROS_FATAL (rop -> rop_reason))
                    175:                ros_adios (rop, "STUB");
                    176:            ros_advise (rop, "STUB");
                    177:            break;
                    178: 
                    179:        case OK:                /* got a result/error response */
                    180:            break;
                    181: 
                    182:        case DONE:              /* got RO-END? */
                    183:            adios (NULLCP, "got RO-END.INDICATION");
                    184:            /* NOTREACHED */
                    185: 
                    186:        default:
                    187:            adios (NULLCP, "unknown return from RyStub=%d", result);
                    188:            /* NOTREACHED */
                    189:     }
                    190: 
                    191:     if (ds -> ds_free && in)
                    192:        (void) (*ds -> ds_free) (in);
                    193: }
                    194: 
                    195: /*  */
                    196: 
                    197: static int  getline (buffer)
                    198: char   *buffer;
                    199: {
                    200:     register int    i;
                    201:     register char  *cp,
                    202:                    *ep;
                    203:     static int  sticky = 0;
                    204: 
                    205:     if (sticky) {
                    206:        sticky = 0;
                    207:        return NOTOK;
                    208:     }
                    209: 
                    210:     printf ("%s> ", myname);
                    211:     (void) fflush (stdout);
                    212: 
                    213:     for (ep = (cp = buffer) + BUFSIZ - 1; (i = getchar ()) != '\n';) {
                    214:        if (i == EOF) {
                    215:            printf ("\n");
                    216:            clearerr (stdin);
                    217:            if (cp != buffer) {
                    218:                sticky++;
                    219:                break;
                    220:            }
                    221: 
                    222:            return NOTOK;
                    223:        }
                    224: 
                    225:        if (cp < ep)
                    226:            *cp++ = i;
                    227:     }
                    228:     *cp = NULL;
                    229: 
                    230:     return OK;
                    231: }
                    232: 
                    233: /*  */
                    234: 
                    235: void   ros_adios (rop, event)
                    236: register struct RoSAPpreject *rop;
                    237: char   *event;
                    238: {
                    239:     ros_advise (rop, event);
                    240: 
                    241:     _exit (1);
                    242: }
                    243: 
                    244: 
                    245: void   ros_advise (rop, event)
                    246: register struct RoSAPpreject *rop;
                    247: char   *event;
                    248: {
                    249:     char    buffer[BUFSIZ];
                    250: 
                    251:     if (rop -> rop_cc > 0)
                    252:        (void) sprintf (buffer, "[%s] %*.*s", RoErrString (rop -> rop_reason),
                    253:                rop -> rop_cc, rop -> rop_cc, rop -> rop_data);
                    254:     else
                    255:        (void) sprintf (buffer, "[%s]", RoErrString (rop -> rop_reason));
                    256: 
                    257:     advise (NULLCP, "%s: %s", event, buffer);
                    258: }
                    259: 
                    260: /*  */
                    261: 
                    262: void   acs_adios (aca, event)
                    263: register struct AcSAPabort *aca;
                    264: char   *event;
                    265: {
                    266:     acs_advise (aca, event);
                    267: 
                    268:     _exit (1);
                    269: }
                    270: 
                    271: 
                    272: void   acs_advise (aca, event)
                    273: register struct AcSAPabort *aca;
                    274: char   *event;
                    275: {
                    276:     char    buffer[BUFSIZ];
                    277: 
                    278:     if (aca -> aca_cc > 0)
                    279:        (void) sprintf (buffer, "[%s] %*.*s",
                    280:                AcErrString (aca -> aca_reason),
                    281:                aca -> aca_cc, aca -> aca_cc, aca -> aca_data);
                    282:     else
                    283:        (void) sprintf (buffer, "[%s]", AcErrString (aca -> aca_reason));
                    284: 
                    285:        advise (NULLCP, "%s: %s (source %d)", event, buffer,
                    286:                aca -> aca_source);
                    287: }
                    288: 
                    289: /*  */
                    290: 
                    291: #ifndef        lint
                    292: void   _advise ();
                    293: 
                    294: 
                    295: void   adios (va_alist)
                    296: va_dcl
                    297: {
                    298:     va_list ap;
                    299: 
                    300:     va_start (ap);
                    301: 
                    302:     _advise (ap);
                    303: 
                    304:     va_end (ap);
                    305: 
                    306:     _exit (1);
                    307: }
                    308: #else
                    309: /* VARARGS */
                    310: 
                    311: void   adios (what, fmt)
                    312: char   *what,
                    313:        *fmt;
                    314: {
                    315:     adios (what, fmt);
                    316: }
                    317: #endif
                    318: 
                    319: 
                    320: #ifndef        lint
                    321: void   advise (va_alist)
                    322: va_dcl
                    323: {
                    324:     va_list ap;
                    325: 
                    326:     va_start (ap);
                    327: 
                    328:     _advise (ap);
                    329: 
                    330:     va_end (ap);
                    331: }
                    332: 
                    333: 
                    334: static void  _advise (ap)
                    335: va_list        ap;
                    336: {
                    337:     char    buffer[BUFSIZ];
                    338: 
                    339:     asprintf (buffer, ap);
                    340: 
                    341:     (void) fflush (stdout);
                    342: 
                    343:     fprintf (stderr, "%s: ", myname);
                    344:     (void) fputs (buffer, stderr);
                    345:     (void) fputc ('\n', stderr);
                    346: 
                    347:     (void) fflush (stderr);
                    348: }
                    349: #else
                    350: /* VARARGS */
                    351: 
                    352: void   advise (what, fmt)
                    353: char   *what,
                    354:        *fmt;
                    355: {
                    356:     advise (what, fmt);
                    357: }
                    358: #endif

unix.superglobalmegacorp.com

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