Annotation of 43BSDReno/contrib/isode-beta/rosap/test/rossinit.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <ctype.h>
                      3: #include <isode/rosap.h>
                      4: #include <isode/isoservent.h>
                      5: #include "generic.h"           /* defines OPERATIONS and ERRORS */
                      6: 
                      7:                                /* e.g., "directory" */
                      8: static char *myservice = "ROSSTEST";
                      9: 
                     10:                                /* e.g., "directory services" */
                     11: static char *mycontext = "isode chic read";
                     12: static char *mypci = "isode chic read pci";
                     13: 
                     14: 
                     15: #define INVOKE 1       /* do a RoInvokeRequest */
                     16: #define INTREQ 2       /* do a RoIntrRequest */
                     17: #define INVERR 3       /* request an error */
                     18: #define INVURJ 4       /* request a user reject */
                     19: #define INVPRJ 5       /* request a provider reject */
                     20: 
                     21: static requirements = SR_NEGOTIATED|SR_HALFDUPLEX;
                     22: extern struct isoservent       *getisoserventbyname();
                     23: extern struct SSAPaddr         *is2saddr();
                     24: 
                     25: extern PE mkpelist();
                     26: 
                     27: main (argc, argv, envp)
                     28: int    argc;
                     29: char  **argv,
                     30:       **envp;
                     31: {
                     32:     int            sd;
                     33:     struct isoservent  *is;
                     34:     struct RoSAPindication  rois;
                     35:     register struct RoSAPpreject   *rop = &rois.roi_preject;
                     36:     struct SSAPaddr    *psa;
                     37: 
                     38:     struct RoSAPaddr   roas;
                     39:     struct RoSAPconnect        rocs;
                     40: 
                     41:     if ((is = getisoserventbyname(myservice, "rosap")) == NULL) {
                     42:        fprintf(stderr, "can't find %s/rosap", myservice);
                     43:        exit(1);
                     44:     }
                     45:     roas.roa_port = is->is_port;
                     46:     if (argc < 2) {
                     47:        fprintf(stderr, "Need an arguement of a hostname\n");
                     48:        exit(1);
                     49:     }
                     50:     /* This is an undescribed strangeness. why look something up if you
                     51:      * never use it ??? Do the people who write ISODE documentation never
                     52:      * expect anyone to try and read it ?
                     53:      */
                     54:     if ((is = getisoserventbyname("ros", "ssap")) == NULL) {
                     55:        fprintf(stderr, "can't find ssap/ros");
                     56:        exit(1);
                     57:     }
                     58:     if ((psa = is2saddr(argv[1], NULLCP, (struct isoservent *) is)) == NULLSA) {
                     59:        fprintf(stderr, "Can't compute address to %s\n", argv[1]);
                     60:        exit(2);
                     61:     }
                     62: 
                     63:     roas.roa_addr = *psa; /* struct copy */
                     64: 
                     65:     if (RoBeginRequest(&roas, NULLPE, &rocs, &rois) == NOTOK) {
                     66:        fprintf(stderr, "RoBeginRequest:failed:%s\n",
                     67:            RoErrString (rop -> rop_reason));
                     68:        exit(1);
                     69:     }
                     70:     if (rocs.roc_result != ROS_ACCEPT) {
                     71:        fprintf(stderr, "Association has been rejected %s\n",
                     72:        RoErrString(rocs.roc_result));
                     73:        exit(2);
                     74:     }
                     75:     sd = rocs.roc_sd;
                     76: 
                     77:     printf("RoBeginRequest succeeded\n");
                     78: 
                     79:     ROCFREE(&rocs);
                     80: 
                     81:     if (RoSetService (sd, RoSService, &rois) == NOTOK)
                     82:         fprintf(stderr, "RoSetService: %s", RoErrString (rop -> rop_reason));
                     83: 
                     84:     printf("RoSetService succeeded\n");
                     85: 
                     86:     invoke (sd, INVOKE);       /* invoke the operations, etc. */
                     87:     
                     88:     invoke (sd, INTREQ);       /* invoke the operations, etc. */
                     89: 
                     90:     invoke (sd, INVERR);       /* invoke the operations, etc. */
                     91: 
                     92:     invoke (sd, INVURJ);       /* invoke the operations, etc. */
                     93: 
                     94:     invoke (sd, INVPRJ);       /* invoke the operations, etc. */
                     95: 
                     96:     if (RoEndRequest(sd, 0, &rois) == NOTOK) {
                     97:         fprintf(stderr, "RoEndRequest: %s", RoErrString (rop -> rop_reason));
                     98:        exit(3);
                     99:     }
                    100: 
                    101:     exit (0);
                    102: }
                    103: 
                    104: /*
                    105:  * Test example
                    106:  */
                    107: invoke(sd, type)
                    108: int    sd;
                    109: int    type;   /* of invocation */
                    110: {
                    111:     int        invoke;
                    112:     struct RoSAPindication     rind;
                    113:     int        res;
                    114:     PE data;
                    115: 
                    116:     invoke = 1;
                    117: 
                    118:     printf("invoke %d\n",type);
                    119:     data = mkpelist(1);
                    120:     /* ROS over Session needs a non null args */
                    121:     switch (type) {
                    122:     case INVOKE:
                    123:        res = RoInvokeRequest(sd, APDU_OP1, ROS_SYNC, data, invoke, NULLIP,
                    124:        ROS_NOPRIO, &rind);
                    125:        break;
                    126: 
                    127:     case INTREQ:
                    128:        res = RoIntrRequest(sd, APDU_OP1, data, invoke, NULLIP, ROS_NOPRIO,
                    129:        &rind);
                    130:        break;
                    131: 
                    132:     case INVERR:
                    133:        res = RoInvokeRequest(sd, APDU_ERR, ROS_SYNC, data, invoke, NULLIP,
                    134:        ROS_NOPRIO, &rind);
                    135:        break;
                    136: 
                    137:     case INVURJ:
                    138:        res = RoInvokeRequest(sd, APDU_URJ, ROS_SYNC, data, invoke, NULLIP,
                    139:        ROS_NOPRIO, &rind);
                    140:        break;
                    141: 
                    142:     case INVPRJ:
                    143:        res = RoInvokeRequest(sd, APDU_PRJ, ROS_SYNC, data, invoke, NULLIP,
                    144:        ROS_NOPRIO, &rind);
                    145:        break;
                    146: 
                    147:     default:
                    148:        fprintf(stderr, "invoke called with illegal type %d\n", type);
                    149:        exit(1);
                    150: 
                    151:     }
                    152: 
                    153:     switch (res) {
                    154:     case NOTOK:
                    155:        if (rind.roi_type == ROI_PREJECT)
                    156:            fprintf(stderr, "RO-INVOKE.REQUEST: %s\n",
                    157:                RoErrString(rind.roi_preject.rop_reason));
                    158:        else
                    159:            fprintf(stderr, "RO-INVOKE.REQUEST:failed: unexpected returned type %d\n",
                    160:                rind.roi_type);
                    161:        exit(1);
                    162:     
                    163:     case OK:
                    164:        break;
                    165: 
                    166:     default:
                    167:        fprintf(stderr, "RO-INVOKE.REQUEST:failed(%d): unexpected returned type %d\n",
                    168:            res, rind.roi_type);
                    169:        exit(2);
                    170: 
                    171:     }
                    172: 
                    173:     switch (rind.roi_type) {
                    174:     case ROI_RESULT:
                    175:        if (rind.roi_result.ror_id == invoke)
                    176:            printf("Result received\n");
                    177:        else
                    178:            printf("Result for wrong request %d\n", rind.roi_result.ror_id);
                    179:        break;
                    180:     
                    181:     case ROI_ERROR:
                    182:        if (rind.roi_error.roe_id == invoke)
                    183:            printf("Error received\n");
                    184:        else
                    185:            printf("Error for wrong request %d\n", rind.roi_error.roe_id);
                    186:        break;
                    187: 
                    188:     case ROI_UREJECT:
                    189:        if (rind.roi_ureject.rou_id == invoke)
                    190:            printf("User Reject received reason %d\n",
                    191:                rind.roi_ureject.rou_reason);
                    192:        else
                    193:            printf("User Reject for wrong request %d\n",
                    194:                rind.roi_ureject.rou_id);
                    195:        break;
                    196: 
                    197:     case ROI_PREJECT:
                    198:        if (rind.roi_preject.rop_id == invoke)
                    199:            printf("Provider Reject received %s\n",
                    200:            RoErrString(rind.roi_preject.rop_reason));
                    201:        else
                    202:            printf("Provider Reject for wrong request %d\n",
                    203:                rind.roi_preject.rop_id);
                    204:        break;
                    205: 
                    206:     default:
                    207:        printf("Unexpected reply received %d\n", rind.roi_type);
                    208:        break;
                    209:     }
                    210: 
                    211: }
                    212: /*
                    213:  * General routines useful for supporting the tests of rtsap library routines
                    214:  */
                    215: 
                    216: #define PE_SIZE                3       /* size to build pe's for testing transfer */
                    217: #define MKMASK 0x7
                    218: #define MKSHIFT 6
                    219: 
                    220: extern PE      mkpe();
                    221: /*
                    222:  * Generate a randomish list of PElement s for use as ANY or SET  OF ANY ....
                    223:  */
                    224: PE
                    225: mkpelist(i)
                    226: int    i;
                    227: {
                    228:     PE pe, fpe = NULL;
                    229: 
                    230:     fpe = pe_alloc(PE_CLASS_PRIV, PE_FORM_CONS, i);
                    231:     while (i > 0) {
                    232:        pe = mkpe(i);
                    233:        pe->pe_next = fpe->pe_cons;
                    234:        fpe->pe_cons = pe;
                    235:        i--;
                    236:     }
                    237:     return (fpe);
                    238: }
                    239: 
                    240: /*
                    241:  * generate a randomish PElement
                    242:  */
                    243: PE
                    244: mkpe(i)
                    245: {
                    246:     int        id, class;
                    247:     PE         pe;
                    248: 
                    249:     id = i * i + 1;
                    250:     class = PE_CLASS_PRIV;
                    251:     switch ((i*i >> MKSHIFT) & MKMASK) {
                    252:     case 5:
                    253:     case 0:
                    254:        pe = flag2prim(i & 0x1, class, id);
                    255:        break;
                    256:     
                    257:     case 6:
                    258:     case 1:
                    259:        pe = num2prim(i, class, id);
                    260:        break;
                    261: 
                    262:     case 7:
                    263:     case 2:
                    264:        pe = str2prim("mkpelist:testdata", 17, class, id);
                    265:        break;
                    266: 
                    267:     case 3:
                    268:        pe = strb2bitstr("\021\0245\375\0124", 4, class, id);
                    269:        break;
                    270:     
                    271:     case 4:
                    272:        pe = mkpelist(i - 1);
                    273:        break;
                    274: 
                    275:     default:
                    276:        fprintf(stderr, "mkpe:internal error %d case not handled\n",
                    277:            (i*i >> MKSHIFT) & MKMASK);
                    278:        exit(2);
                    279:     }
                    280: 
                    281:     return (pe);
                    282: }
                    283: /*
                    284:  * Dump a bunch of hex digits printing out those that are printable
                    285:  * Print out a given length of octets as hex (with the ASCII characters
                    286:  * given if they have any
                    287:  */
                    288: fpclen(fp, s, len)
                    289: register FILE  *fp;
                    290: register char  *s;
                    291: register int   len;
                    292: {
                    293:        register int    cnt = 0;
                    294: 
                    295:        while (len-- > 0) {
                    296:                if (cnt % 8 == 0)
                    297:                        fprintf(fp, "\n%d:", cnt/8 + 1);
                    298:                if (isprint(*s&0x7f))
                    299:                        fprintf(fp, "\t%02x(%c)", *s&0xff, *s&0x7f);
                    300:                else
                    301:                        fprintf(fp, "\t%02x", *s&0xff);
                    302:                s++;
                    303:                cnt++;
                    304:        }
                    305:        fputc('\n', fp);
                    306: }
                    307: 

unix.superglobalmegacorp.com

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