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

1.1     ! root        1: /*
        !             2:  * this is the example use of rosap taken from the manual
        !             3:  */
        !             4: #include <stdio.h>
        !             5: #include "generic.h"
        !             6: #include <isode/rosap.h>
        !             7: 
        !             8: #define error fprintf
        !             9: 
        !            10: int    ros_indication();
        !            11: 
        !            12: static FILE    *dfp;
        !            13: main(argc, argv, envp)
        !            14: int    argc;
        !            15: char   **argv, **envp;
        !            16: {
        !            17:     int        result, sd;
        !            18:     int        res;
        !            19: 
        !            20:     struct AcSAPstart  acss;
        !            21:     register struct AcSAPstart *acs = &acss;
        !            22:     struct AcSAPindication     acis;
        !            23:     register struct AcSAPindication    *aci = &acis;
        !            24:     register struct AcSAPabort *aca = &aci->aci_abort;
        !            25:     register struct PSAPstart *ps = &acs->acs_start;
        !            26:     struct RoSAPindication rois;
        !            27:     register struct RoSAPindication    *roi = &rois;
        !            28:     register struct RoSAPpreject       *rop = &roi->roi_preject;
        !            29:     int        servicetype = RoP;
        !            30: 
        !            31:     if (AcInit(argc, argv, acs, aci) == NOTOK)
        !            32:        fprintf(stderr, "initialisation fails: %s", AcErrString(aca->aca_reason));
        !            33: 
        !            34:     sd = acs->acs_sd;
        !            35:     ACSFREE(acs);
        !            36: 
        !            37:     /* would have read command line arguments here */
        !            38: 
        !            39:     if (AcAssocResponse(sd, ACS_ACCEPT, ACS_USER_NULL, NULLOID, NULLAEI,
        !            40:                &ps->ps_called, NULLPC, ps->ps_defctxresult,
        !            41:                ps->ps_prequirements, ps->ps_srequirements,
        !            42:                SERIAL_NONE, ps->ps_settings, &ps->ps_connect,
        !            43:                NULLPEP, 0, aci) == NOTOK)
        !            44:        fprintf(stderr, "A-ASSOCIATE.RESPONSE: %s", AcErrString(aca->aca_reason));
        !            45:     if (acs->acs_ninfo > 0) {
        !            46:        if (acs->acs_info[0] == NULLPE) {
        !            47:            fprintf(stderr, "A-ASSOCIATE.RESPONSE: NULL User data\n");
        !            48:            exit(1);
        !            49:        }
        !            50:        if ((servicetype = num2prim(acs->acs_info[0])) == NOTOK) {
        !            51:            if (acs->acs_info[0]->pe_errno != PE_ERR_NONE) {
        !            52:                fprintf(stderr, "A-ASSOCIATE.RESPONSE: Bad User data\n");
        !            53:                exit(1);
        !            54:            }
        !            55:        }
        !            56:     }
        !            57: 
        !            58:     switch (servicetype) {
        !            59:        case RoP:
        !            60:            if (RoSetService (sd, RoPService, &rois) == NOTOK)
        !            61:                error ("RoSetService: %s", RoErrString (rop -> rop_reason));
        !            62:            break;
        !            63: 
        !            64:        case RoS:
        !            65:            if (RoSetService (sd, RoSService, &rois) == NOTOK)
        !            66:                error ("RoSetService: %s", RoErrString (rop -> rop_reason));
        !            67:            break;
        !            68: 
        !            69:        case RoRt:
        !            70:            if (RoSetService (sd, RoRtService, &rois) == NOTOK)
        !            71:                error ("RoSetService: %s", RoErrString (rop -> rop_reason));
        !            72:            break;
        !            73: 
        !            74:        default:
        !            75:            fprintf(stderr, "Unknown service type %d\n", servicetype);
        !            76:            exit(1);
        !            77:     }
        !            78: 
        !            79: 
        !            80: #ifdef SHOW_BUG
        !            81:     if (RoSetIndications(sd, ros_indication, roi) == NOTOK)
        !            82:        fprintf(stderr, "RoSetIndications: %s", RoErrString(rop->rop_reason));
        !            83:     
        !            84:      for(;;)
        !            85:        pause();
        !            86: #else
        !            87:     dfp = freopen("/dev/console", "w", stdout);
        !            88:     fprintf(dfp, "Got to here\n");
        !            89:     for (;;) {
        !            90:        switch (res = RoWaitRequest(sd, NOTOK, roi)) {
        !            91:        case NOTOK:
        !            92:            fprintf(stderr,"RoWaitRequest: %s\n", RoErrString(rop->rop_reason));
        !            93:            exit(1);
        !            94: 
        !            95:        case OK:
        !            96:            fprintf(dfp, "got a request %d\n", res);
        !            97:            ros_indication(sd, roi);
        !            98:            break;
        !            99:        
        !           100:        case DONE:
        !           101:            fprintf(dfp, "Done\n");
        !           102:            ros_indication(sd, roi);
        !           103:            exit(0);    /* should never get to here */
        !           104:        }
        !           105:     }
        !           106: #endif
        !           107: 
        !           108:     fprintf(dfp, "Finished\n");
        !           109:    
        !           110: }
        !           111: /*
        !           112:  * Request/Reply loop of ROS server. Called when data arrives like a signal
        !           113:  * routine
        !           114:  */
        !           115: static int
        !           116: ros_indication(sd, roi)
        !           117: int    sd;
        !           118: register struct RoSAPindication        *roi;
        !           119: {
        !           120: 
        !           121:     fprintf(dfp, "ros_indication got called\n");
        !           122:     switch (roi->roi_type) {
        !           123:     case ROI_INVOKE:
        !           124:        ros_invoke(sd, &roi->roi_invoke);
        !           125:        break;
        !           126: 
        !           127:     case ROI_RESULT:
        !           128:        ros_result(sd, &roi->roi_result);
        !           129:        break;
        !           130: 
        !           131:     case ROI_ERROR:
        !           132:        ros_error(sd, &roi->roi_error);
        !           133:        break;
        !           134: 
        !           135: 
        !           136:     case ROI_UREJECT:
        !           137:        ros_ureject(sd, &roi->roi_ureject);
        !           138:        break;
        !           139: 
        !           140:     case ROI_PREJECT:
        !           141:        ros_preject(sd, &roi->roi_preject);
        !           142:        break;
        !           143: 
        !           144:     case ROI_FINISH:
        !           145:        ros_finish(sd, &roi->roi_finish);
        !           146:        break;
        !           147: 
        !           148:     default:
        !           149:        fprintf(dfp, "unknown indication type=%d", roi->roi_type);
        !           150:     }
        !           151: }
        !           152: 
        !           153: extern int     OP1();
        !           154: 
        !           155: 
        !           156: 
        !           157: /* OPERATIONS are numbered APDU_OPx, where each is a unique integer.  Further,
        !           158:    APDU_UNKNOWN is used as a tag different than any valid operation.
        !           159: 
        !           160:    ERRORS are numbered ERROR_xyz, where each is a unique integer.
        !           161:    ERROR_MISTYPED is used to signal an argument error to an operation.
        !           162:    Further, ERROR_UNKNOWN is used as a tag to indicate that the operation
        !           163:    succeeded.
        !           164: 
        !           165:    Finally, note that rox -> rox_args is updated in place by these routines.
        !           166:    If the routine returns ERROR_UNKNOWN, then rox_args contains the results
        !           167:    of the operation.  If the routine returns ERROR_MISTYPED, then rox_args is
        !           168:    untouched.  Otherwise, if the routine returns any other value, then
        !           169:    rox_args contains the parameters of the error which occurred.  Obviously,
        !           170:    each routine calls ROXFREE prior to setting rox_args to a new value.
        !           171:  */
        !           172: 
        !           173: static struct dispatch {
        !           174:     int     ds_operation;
        !           175:     IFP     ds_vector;
        !           176: }       dispatches[] = {
        !           177:     APDU_OP1,   OP1,
        !           178:     APDU_ERR,   OP1,
        !           179:     APDU_URJ,   OP1,
        !           180: 
        !           181:     /* APDU_OPn,   OPn, */
        !           182: 
        !           183:     APDU_UNKNOWN
        !           184: };
        !           185: 
        !           186: 
        !           187: static int  ros_invoke (sd, rox)
        !           188: int     sd;
        !           189: register struct RoSAPinvoke *rox;
        !           190: {
        !           191:     int     result;
        !           192:     register struct dispatch   *ds;
        !           193:     struct RoSAPindication  rois;
        !           194:     register struct RoSAPindication *roi = &rois;
        !           195:     register struct RoSAPpreject   *rop = &roi -> roi_preject;
        !           196: 
        !           197:     for (ds = dispatches; ds -> ds_operation != APDU_UNKNOWN; ds++)
        !           198:        if (ds -> ds_operation == rox -> rox_op)
        !           199:            break;
        !           200: 
        !           201:     if (ds -> ds_operation == APDU_UNKNOWN) {
        !           202:        if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_UNRECOG,
        !           203:                    ROS_NOPRIO, roi) == NOTOK)
        !           204:            error (dfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason));
        !           205:        goto out;
        !           206:     }
        !           207: 
        !           208:     if (rox -> rox_nolinked == 0) {
        !           209:        if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_LINKED,
        !           210:                    ROS_NOPRIO, roi) == NOTOK)
        !           211:            error (dfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason));
        !           212:        goto out;
        !           213:     }
        !           214: 
        !           215:     switch (result = (*ds -> ds_vector) (rox)) {
        !           216:        case ERROR_UNKNOWN: 
        !           217:            if (RoResultRequest (sd, rox -> rox_id, rox -> rox_op,
        !           218:                        rox -> rox_args, ROS_NOPRIO, roi) == NOTOK)
        !           219:                error (dfp, "RO-RESULT.REQUEST: %s",
        !           220:                        RoErrString (rop -> rop_reason));
        !           221:            break;
        !           222: 
        !           223:        default: 
        !           224:            if (RoErrorRequest (sd, rox -> rox_id, result, rox -> rox_args,
        !           225:                        ROS_NOPRIO, roi) == NOTOK)
        !           226:                error (dfp, "RO-ERROR.REQUEST: %s",
        !           227:                        RoErrString (rop -> rop_reason));
        !           228:            break;
        !           229: 
        !           230:        case ERROR_MISTYPED: 
        !           231:            if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_MISTYPED,
        !           232:                        ROS_NOPRIO, roi) == NOTOK)
        !           233:                error (dfp, "RO-U-REJECT.REQUEST: %s",
        !           234:                        RoErrString (rop -> rop_reason));
        !           235:            break;
        !           236:     }
        !           237: 
        !           238: out: ;
        !           239:     ROXFREE (rox);
        !           240: }
        !           241: 
        !           242: 
        !           243: static int  ros_result (sd, ror)
        !           244: int     sd;
        !           245: register struct RoSAPresult *ror;
        !           246: {
        !           247:     struct RoSAPindication  rois;
        !           248:     register struct RoSAPindication *roi = &rois;
        !           249:     register struct RoSAPpreject   *rop = &roi -> roi_preject;
        !           250: 
        !           251:     if (RoURejectRequest (sd, &ror -> ror_id, ROS_RRP_UNRECOG, ROS_NOPRIO, roi)
        !           252:            == NOTOK)
        !           253:        error (dfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason));
        !           254: 
        !           255:     RORFREE (ror);
        !           256: }
        !           257: 
        !           258: 
        !           259: static int  ros_error (sd, roe)
        !           260: int     sd;
        !           261: register struct RoSAPerror *roe;
        !           262: {
        !           263:     struct RoSAPindication  rois;
        !           264:     register struct RoSAPindication *roi = &rois;
        !           265:     register struct RoSAPpreject   *rop = &roi -> roi_preject;
        !           266: 
        !           267:     if (RoURejectRequest (sd, &roe -> roe_id, ROS_REP_UNRECOG, ROS_NOPRIO, roi)
        !           268:            == NOTOK)
        !           269:        error (dfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason));
        !           270: 
        !           271:     ROEFREE (roe);
        !           272: }
        !           273: 
        !           274: 
        !           275: static int  ros_ureject (sd, rou)
        !           276: int     sd;
        !           277: register struct RoSAPureject *rou;
        !           278: {
        !           279: /* handle rejection here... */
        !           280: }
        !           281: 
        !           282: 
        !           283: static int  ros_preject (sd, rop)
        !           284: int     sd;
        !           285: register struct RoSAPpreject *rop;
        !           286: {
        !           287:     if (ROS_FATAL (rop -> rop_reason))
        !           288:        error (dfp, "RO-REJECT-P.INDICATION: %s", RoErrString (rop -> rop_reason));
        !           289: 
        !           290: /* handle temporary failure here... */
        !           291: }
        !           292: 
        !           293: static int  ros_finish (sd, acf)
        !           294: int     sd;
        !           295: struct AcSAPfinish *acf;
        !           296: {
        !           297:     struct AcSAPindication  acis;
        !           298:     register struct AcSAPabort *aca = &acis.aci_abort;
        !           299: 
        !           300:     ACFFREE (acf);
        !           301: 
        !           302:     if (AcRelResponse (sd, ACS_ACCEPT, ACR_NORMAL, NULLPEP, 0, &acis) == NOTOK)
        !           303:        error (dfp, "A-RELEASE.RESPONSE: %s", AcErrString (aca -> aca_reason));
        !           304: 
        !           305:     error (dfp, "association released");
        !           306: 
        !           307:     exit(0);
        !           308: }
        !           309: 
        !           310: OP1(rox)
        !           311: register struct RoSAPinvoke *rox;
        !           312: {
        !           313:     fprintf(dfp, "Invocation\nid %d", rox->rox_id);
        !           314:     if (!rox->rox_nolinked)
        !           315:        fprintf(dfp, " linked to %d", rox->rox_linkid);
        !           316:     fprintf(dfp, " operation %d\n", rox->rox_op);
        !           317:     /* print the pe */
        !           318: 
        !           319:     switch (rox->rox_op) {
        !           320:     case APDU_OP1:
        !           321:        return (ERROR_UNKNOWN);
        !           322: 
        !           323:     case APDU_ERR:
        !           324:        return (ERROR_ERROR);
        !           325: 
        !           326:     case APDU_URJ:
        !           327:        return (ERROR_MISTYPED);
        !           328: 
        !           329:     default:
        !           330:        fprintf(dfp, "\nunknown operation %d\n", rox->rox_op);
        !           331:     }
        !           332:     return (ERROR_ERROR);
        !           333: }

unix.superglobalmegacorp.com

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