Annotation of 43BSDReno/contrib/isode-beta/rosap/test/rosrtbinit.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <ctype.h>
        !             3: #include "generic.h"           /* defines OPERATIONS and ERRORS */
        !             4: #include <isode/rtsap.h>
        !             5: #include <isode/rosap.h>
        !             6: #include <isode/isoservent.h>
        !             7: 
        !             8: #define error  printf
        !             9: 
        !            10:                                /* e.g., "directory" */
        !            11: static char *myservice = "ROSRTBTEST";
        !            12: 
        !            13:                                /* e.g., "directory services" */
        !            14: static char *mycontext = "isode chic read";
        !            15: static char *mypci = "isode chic read pci";
        !            16: 
        !            17: 
        !            18: #define INVOKE 1       /* do a RoInvokeRequest */
        !            19: #define INTREQ 2       /* do a RoIntrRequest */
        !            20: #define INVERR 3       /* request an error */
        !            21: #define INVURJ 4       /* request a user reject */
        !            22: #define INVPRJ 5       /* request a provider reject */
        !            23: 
        !            24: #define TIMEOUT        30      /* seconds before RtWait times out */
        !            25: 
        !            26: extern struct isoservent       *getisoserventbyname();
        !            27: extern PE      mkpelist();
        !            28: 
        !            29: main (argc, argv, envp)
        !            30: int    argc;
        !            31: char  **argv,
        !            32:       **envp;
        !            33: {
        !            34:     int            sd;
        !            35: #if 0
        !            36:     struct SSAPref sfs;
        !            37:     register struct SSAPref *sf;
        !            38:     register struct PSAPaddr *pa;
        !            39:     struct AcSAPconnect accs;
        !            40:     register struct AcSAPconnect   *acc = &accs;
        !            41:     struct AcSAPrelease acrs;
        !            42:     register struct AcSAPrelease   *acr = &acrs;
        !            43:     struct AcSAPindication  acis;
        !            44:     register struct AcSAPindication *aci = &acis;
        !            45:     register struct AcSAPabort *aca = &aci -> aci_abort;
        !            46:     register AEI aei;
        !            47:     register OID ctx, pci;
        !            48:     struct PSAPctxlist pcs;
        !            49:     register struct PSAPctxlist *pc = &pcs;
        !            50: #endif
        !            51:     struct RtSAPaddr   rtas;
        !            52:     struct isoservent   *is;
        !            53:     struct SSAPaddr     *psa;
        !            54:     struct RtSAPindication  rtis;
        !            55:     register struct RtSAPindication *rti = &rtis;
        !            56:     struct RtSAPconnect rtcs;
        !            57:     register struct RtSAPconnect   *rtc = &rtcs;
        !            58:     register struct RtSAPabort *rta = &rti -> rti_abort;
        !            59:     struct RoSAPindication  rois;
        !            60:     register struct RoSAPpreject   *rop = &rois.roi_preject;
        !            61: 
        !            62:     if ((is = getisoserventbyname(myservice, "rtsap")) == NULL) {
        !            63:         fprintf(stderr, "can't find %s/rosap", myservice);
        !            64:         exit(1);
        !            65:     }
        !            66:     rtas.rta_port = is->is_port;
        !            67:     if (argc < 2) {
        !            68:         fprintf(stderr, "Need an arguement of a hostname\n");
        !            69:         exit(1);
        !            70:     }
        !            71:     /* This is an different to the manual which is wrong! 
        !            72:      */
        !            73:     if ((is = getisoserventbyname("rts", "ssap")) == NULL) {
        !            74:         fprintf(stderr, "can't find ssap/rts");
        !            75:         exit(1);
        !            76:     }
        !            77:     if ((psa = is2saddr(argv[1], NULLCP, (struct isoservent *) is)) == NULLSA) {        fprintf(stderr, "Can't compute address to %s\n", argv[1]);
        !            78:         exit(2);
        !            79:     }
        !            80:  
        !            81:     rtas.rta_addr = *psa; /* struct copy */
        !            82:  
        !            83:     fprintf(stderr, "RT-OPEN.REQUEST:\n");
        !            84:     if (RtBeginRequest (&rtas, RTS_TWA, RTS_INITIATOR, NULLPE, rtc, rti)
        !            85:            == NOTOK)
        !            86:        fprintf(stderr, "RT-OPEN.REQUEST: %s", RtErrString (rta -> rta_reason));
        !            87: 
        !            88:     if (rtc -> rtc_result != RTS_ACCEPT)
        !            89:        fprintf(stderr, "association rejected: %s",
        !            90:        RtErrString (rta->rta_reason));
        !            91: 
        !            92:     sd = rtc -> rtc_sd;
        !            93:     RTCFREE (rtc);
        !            94: 
        !            95:     if (RoSetService (sd, RoRtService, &rois) == NOTOK)
        !            96:        error ("RoSetService: %s", RoErrString (rop -> rop_reason));
        !            97: 
        !            98:     invoke (sd, INVOKE);       /* invoke the operations, etc. */
        !            99:     
        !           100:     invoke (sd, INTREQ);       /* invoke the operations, etc. */
        !           101: 
        !           102:     invoke (sd, INVERR);       /* invoke the operations, etc. */
        !           103: 
        !           104:     invoke (sd, INVURJ);       /* invoke the operations, etc. */
        !           105: 
        !           106:     invoke (sd, INVPRJ);       /* invoke the operations, etc. */
        !           107: 
        !           108:     /* All this appears to be neccessary because you need the turn to terminate
        !           109:      * nicely. But we don't have the turn, I presume the responder has kept it
        !           110:      * from when they replyed to our request
        !           111:      */
        !           112: 
        !           113:     if (RtPTurnRequest(sd, 0, &rtis) == NOTOK) {
        !           114:        fprintf(stderr, "SEND_PLS:RT-PLEASE-TURN.REQUEST: %s\n",
        !           115:            RtErrString (rtis.rti_abort.rta_reason));
        !           116:        exit(6);
        !           117:     }
        !           118:     if (RtWaitRequest(sd, TIMEOUT, &rtis) == NOTOK) {
        !           119:        fprintf(stderr, "RtWaitRequest: %s\n",
        !           120:            RtErrString (rtis.rti_abort.rta_reason));
        !           121:        exit(1);
        !           122:     }
        !           123:     switch (rtis.rti_type) {
        !           124:     case RTI_TURN:
        !           125:        /* Okay we got it */
        !           126:        break;
        !           127: 
        !           128:     default:
        !           129:        fprintf(stderr, "unexpected response %d\n", rtis.rti_type);
        !           130:        exit(6);
        !           131:     }
        !           132: 
        !           133:     /* Now we can close */
        !           134:     fprintf (stderr, "RT-CLOSE.REQUEST:\n");
        !           135:     if (RtEndRequest (sd, &rtis) == NOTOK)
        !           136:        fprintf (stderr, "RT-CLOSE.REQUEST: %s\n",
        !           137:            RtErrString (rtis.rti_abort.rta_reason));
        !           138: 
        !           139:     exit (0);
        !           140: }
        !           141: 
        !           142: /*
        !           143:  * Test example
        !           144:  */
        !           145: invoke(sd, type)
        !           146: int    sd;
        !           147: int    type;   /* of invocation */
        !           148: {
        !           149:     int        invoke;
        !           150:     struct RoSAPindication     rind;
        !           151:     int        res;
        !           152:     PE data;
        !           153: 
        !           154:     invoke = 1;
        !           155: 
        !           156:     data = mkpelist(2);
        !           157:     switch (type) {
        !           158:     case INVOKE:
        !           159:        res = RoInvokeRequest(sd, APDU_OP1, ROS_SYNC, data, invoke, NULLIP,
        !           160:        ROS_NOPRIO, &rind);
        !           161:        break;
        !           162: 
        !           163:     case INTREQ:
        !           164:        res = RoIntrRequest(sd, APDU_OP1, data, invoke, NULLIP, ROS_NOPRIO,
        !           165:        &rind);
        !           166:        break;
        !           167: 
        !           168:     case INVERR:
        !           169:        res = RoInvokeRequest(sd, APDU_ERR, ROS_SYNC, data, invoke, NULLIP,
        !           170:        ROS_NOPRIO, &rind);
        !           171:        break;
        !           172: 
        !           173:     case INVURJ:
        !           174:        res = RoInvokeRequest(sd, APDU_URJ, ROS_SYNC, data, invoke, NULLIP,
        !           175:        ROS_NOPRIO, &rind);
        !           176:        break;
        !           177: 
        !           178:     case INVPRJ:
        !           179:        res = RoInvokeRequest(sd, APDU_PRJ, ROS_SYNC, data, invoke, NULLIP,
        !           180:        ROS_NOPRIO, &rind);
        !           181:        break;
        !           182: 
        !           183:     default:
        !           184:        fprintf(stderr, "invoke called with illegal type %d\n", type);
        !           185:        exit(1);
        !           186: 
        !           187:     }
        !           188: 
        !           189:     switch (res) {
        !           190:     case NOTOK:
        !           191:        if (rind.roi_type == ROI_PREJECT)
        !           192:            error("RO-INVOKE.REQUEST: %s\n",
        !           193:                RoErrString(rind.roi_preject.rop_reason));
        !           194:        else
        !           195:            error("RO-INVOKE.REQUEST:failed: unexpected returned type %d\n",
        !           196:                rind.roi_type);
        !           197:        exit(1);
        !           198:     
        !           199:     case OK:
        !           200:        break;
        !           201: 
        !           202:     default:
        !           203:        error("RO-INVOKE.REQUEST:failed(%d): unexpected returned type %d\n",
        !           204:            res, rind.roi_type);
        !           205:        exit(2);
        !           206: 
        !           207:     }
        !           208: 
        !           209:     switch (rind.roi_type) {
        !           210:     case ROI_RESULT:
        !           211:        if (rind.roi_result.ror_id == invoke)
        !           212:            printf("Result received\n");
        !           213:        else
        !           214:            printf("Result for wrong request %d\n", rind.roi_result.ror_id);
        !           215:        break;
        !           216:     
        !           217:     case ROI_ERROR:
        !           218:        if (rind.roi_error.roe_id == invoke)
        !           219:            printf("Error received\n");
        !           220:        else
        !           221:            printf("Error for wrong request %d\n", rind.roi_error.roe_id);
        !           222:        break;
        !           223: 
        !           224:     case ROI_UREJECT:
        !           225:        if (rind.roi_ureject.rou_id == invoke)
        !           226:            printf("User Reject received reason %d\n",
        !           227:                rind.roi_ureject.rou_reason);
        !           228:        else
        !           229:            printf("User Reject for wrong request %d\n",
        !           230:                rind.roi_ureject.rou_id);
        !           231:        break;
        !           232: 
        !           233:     case ROI_PREJECT:
        !           234:        if (rind.roi_preject.rop_id == invoke)
        !           235:            printf("Provider Reject received %s\n",
        !           236:            RoErrString(rind.roi_preject.rop_reason));
        !           237:        else
        !           238:            printf("Provider Reject for wrong request %d\n",
        !           239:                rind.roi_preject.rop_id);
        !           240:        break;
        !           241: 
        !           242:     default:
        !           243:        printf("Unexpected reply received %d\n", rind.roi_type);
        !           244:        break;
        !           245:     }
        !           246:     pe_free(data);
        !           247: 
        !           248: }
        !           249: /*
        !           250:  * General routines useful for supporting the tests of rtsap library routines
        !           251:  */
        !           252: 
        !           253: #define PE_SIZE                3       /* size to build pe's for testing transfer */
        !           254: #define MKMASK 0x7
        !           255: #define MKSHIFT 6
        !           256: 
        !           257: extern PE      mkpe();
        !           258: /*
        !           259:  * Generate a randomish list of PElement s for use as ANY or SET  OF ANY ....
        !           260:  */
        !           261: PE
        !           262: mkpelist(i)
        !           263: int    i;
        !           264: {
        !           265:     PE pe, fpe = NULL;
        !           266: 
        !           267:     fpe = pe_alloc(PE_CLASS_PRIV, PE_FORM_CONS, i);
        !           268:     while (i > 0) {
        !           269:        pe = mkpe(i);
        !           270:        pe->pe_next = fpe->pe_cons;
        !           271:        fpe->pe_cons = pe;
        !           272:        i--;
        !           273:     }
        !           274:     return (fpe);
        !           275: }
        !           276: 
        !           277: /*
        !           278:  * generate a randomish PElement
        !           279:  */
        !           280: PE
        !           281: mkpe(i)
        !           282: {
        !           283:     int        id, class;
        !           284:     PE         pe;
        !           285: 
        !           286:     id = i * i + 1;
        !           287:     class = PE_CLASS_PRIV;
        !           288:     switch ((i*i >> MKSHIFT) & MKMASK) {
        !           289:     case 5:
        !           290:     case 0:
        !           291:        pe = flag2prim(i & 0x1, class, id);
        !           292:        break;
        !           293:     
        !           294:     case 6:
        !           295:     case 1:
        !           296:        pe = num2prim(i, class, id);
        !           297:        break;
        !           298: 
        !           299:     case 7:
        !           300:     case 2:
        !           301:        pe = str2prim("mkpelist:testdata", 17, class, id);
        !           302:        break;
        !           303: 
        !           304:     case 3:
        !           305:        pe = strb2bitstr("\021\0245\375\0124", 4, class, id);
        !           306:        break;
        !           307:     
        !           308:     case 4:
        !           309:        pe = mkpelist(i - 1);
        !           310:        break;
        !           311: 
        !           312:     default:
        !           313:        fprintf(stderr, "mkpe:internal error %d case not handled\n",
        !           314:            (i*i >> MKSHIFT) & MKMASK);
        !           315:        exit(2);
        !           316:     }
        !           317: 
        !           318:     return (pe);
        !           319: }
        !           320: /*
        !           321:  * Dump a bunch of hex digits printing out those that are printable
        !           322:  * Print out a given length of octets as hex (with the ASCII characters
        !           323:  * given if they have any
        !           324:  */
        !           325: fpclen(fp, s, len)
        !           326: register FILE  *fp;
        !           327: register char  *s;
        !           328: register int   len;
        !           329: {
        !           330:        register int    cnt = 0;
        !           331: 
        !           332:        while (len-- > 0) {
        !           333:                if (cnt % 8 == 0)
        !           334:                        fprintf(fp, "\n%d:", cnt/8 + 1);
        !           335:                if (isprint(*s&0x7f))
        !           336:                        fprintf(fp, "\t%02x(%c)", *s&0xff, *s&0x7f);
        !           337:                else
        !           338:                        fprintf(fp, "\t%02x", *s&0xff);
        !           339:                s++;
        !           340:                cnt++;
        !           341:        }
        !           342:        fputc('\n', fp);
        !           343: }
        !           344: 

unix.superglobalmegacorp.com

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