|
|
1.1 ! root 1: /* ! 2: * this is the example use of rtsap taken from the manual ! 3: */ ! 4: #include <stdio.h> ! 5: #include <isode/rtsap.h> ! 6: #include "support.h" ! 7: ! 8: int rts_indication(); ! 9: ! 10: FILE *errfp; ! 11: main(argc, argv, envp) ! 12: int argc; ! 13: char **argv, **envp; ! 14: { ! 15: int result, sd; ! 16: int res; ! 17: ! 18: struct RtSAPstart rtss; ! 19: register struct RtSAPstart *rts = &rtss; ! 20: struct RtSAPindication rtis; ! 21: register struct RtSAPindication *rti = &rtis; ! 22: register struct AcSAPstart *acs = &rts->rts_start; ! 23: register struct PSAPstart *ps = &acs->acs_start; ! 24: register struct RtSAPabort *rta = &rti -> rti_abort; ! 25: ! 26: errfp = freopen("/dev/console", "w", stdout); ! 27: fprintf(errfp, "Got to here\n"); ! 28: ! 29: if (RtInit(argc, argv, rts, rti) == NOTOK) ! 30: fprintf(errfp, "initialisation fails: %s", ! 31: RtErrString(rta->rta_reason)); ! 32: ! 33: sd = rts->rts_sd; ! 34: RTSFREE(rts); ! 35: ! 36: /* would have read command line arguments here */ ! 37: ! 38: if (RtOpenResponse(sd, ACS_ACCEPT, NULLOID, NULLAEI, ! 39: &ps->ps_called, NULLPC, ps->ps_defctxresult, ! 40: NULLPE, rti) == NOTOK) ! 41: fprintf(errfp, "RT-OPEN.RESPONSE: %s", ! 42: RtErrString(rti->rti_abort.rta_reason)); ! 43: ! 44: #ifdef DO_ASYNC ! 45: if (RtSetIndications(sd, rts_indication, rti) == NOTOK) ! 46: fprintf(stderr, "RoSetIndications: %s", ! 47: RtErrString(rti->rti_abort.rta_reason)); ! 48: for(;;) ! 49: pause(); ! 50: #else ! 51: ! 52: oper(sd, SIMP_RCV); ! 53: ! 54: oper(sd, CPLX_RCV); ! 55: ! 56: oper(sd, SEND_PLS); ! 57: ! 58: oper(sd, RCV_GIVE); ! 59: ! 60: oper(sd, SIMP_SEND); ! 61: ! 62: oper(sd, CPLX_SEND); ! 63: ! 64: oper(sd, RCV_PLS); ! 65: ! 66: oper(sd, SEND_GIVE); ! 67: ! 68: oper(sd, CPLX_RCV); ! 69: ! 70: oper(sd, RCV_CLOSE); ! 71: ! 72: #endif ! 73: fprintf(errfp, "Finished\n"); ! 74: ! 75: } ! 76: #if 0 ! 77: /* ! 78: * Request/Reply loop of ROS server. Called when data arrives like a signal ! 79: * handler routine ! 80: */ ! 81: static int ! 82: rts_indication(sd, rti) ! 83: int sd; ! 84: register struct RtSAPindication *rti; ! 85: { ! 86: ! 87: fprintf(errfp, "rts_indication got called\n"); ! 88: switch (rti->roi_type) { ! 89: case ROI_INVOKE: ! 90: rts_invoke(sd, &rti->roi_invoke); ! 91: break; ! 92: ! 93: case ROI_RESULT: ! 94: rts_result(sd, &rti->roi_result); ! 95: break; ! 96: ! 97: case ROI_ERROR: ! 98: rts_error(sd, &rti->roi_error); ! 99: break; ! 100: ! 101: ! 102: case ROI_UREJECT: ! 103: rts_ureject(sd, &rti->roi_ureject); ! 104: break; ! 105: ! 106: case ROI_PREJECT: ! 107: rts_preject(sd, &rti->roi_preject); ! 108: break; ! 109: ! 110: case ROI_FINISH: ! 111: rts_finish(sd, &rti->roi_finish); ! 112: break; ! 113: ! 114: default: ! 115: fprintf(errfp, "unknown indication type=%d", rti->roi_type); ! 116: } ! 117: } ! 118: ! 119: extern int OP1(); ! 120: ! 121: ! 122: ! 123: /* OPERATIONS are numbered APDU_OPx, where each is a unique integer. Further, ! 124: APDU_UNKNOWN is used as a tag different than any valid operation. ! 125: ! 126: ERRORS are numbered ERROR_xyz, where each is a unique integer. ! 127: ERROR_MISTYPED is used to signal an argument fprintf to an operation. ! 128: Further, ERROR_UNKNOWN is used as a tag to indicate that the operation ! 129: succeeded. ! 130: ! 131: Finally, note that rox -> rox_args is updated in place by these routines. ! 132: If the routine returns ERROR_UNKNOWN, then rox_args contains the results ! 133: of the operation. If the routine returns ERROR_MISTYPED, then rox_args is ! 134: untouched. Otherwise, if the routine returns any other value, then ! 135: rox_args contains the parameters of the fprintf which occurred. Obviously, ! 136: each routine calls ROXFREE prior to setting rox_args to a new value. ! 137: */ ! 138: ! 139: static struct dispatch { ! 140: int ds_operation; ! 141: IFP ds_vector; ! 142: } dispatches[] = { ! 143: APDU_OP1, OP1, ! 144: APDU_ERR, OP1, ! 145: APDU_URJ, OP1, ! 146: ! 147: /* APDU_OPn, OPn, */ ! 148: ! 149: APDU_UNKNOWN ! 150: }; ! 151: ! 152: ! 153: static int rts_invoke (sd, rox) ! 154: int sd; ! 155: register struct RoSAPinvoke *rox; ! 156: { ! 157: int result; ! 158: register struct dispatch *ds; ! 159: struct RoSAPindication rois; ! 160: register struct RoSAPindication *rti = &rois; ! 161: register struct RoSAPpreject *rop = &rti -> roi_preject; ! 162: ! 163: for (ds = dispatches; ds -> ds_operation != APDU_UNKNOWN; ds++) ! 164: if (ds -> ds_operation == rox -> rox_op) ! 165: break; ! 166: ! 167: if (ds -> ds_operation == APDU_UNKNOWN) { ! 168: if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_UNRECOG, ! 169: ROS_NOPRIO, rti) == NOTOK) ! 170: fprintf (errfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason)); ! 171: goto out; ! 172: } ! 173: ! 174: if (rox -> rox_nolinked == 0) { ! 175: if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_LINKED, ! 176: ROS_NOPRIO, rti) == NOTOK) ! 177: fprintf (errfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason)); ! 178: goto out; ! 179: } ! 180: ! 181: switch (result = (*ds -> ds_vector) (rox)) { ! 182: case ERROR_UNKNOWN: ! 183: if (RoResultRequest (sd, rox -> rox_id, rox -> rox_op, ! 184: rox -> rox_args, ROS_NOPRIO, rti) == NOTOK) ! 185: fprintf (errfp, "RO-RESULT.REQUEST: %s", ! 186: RoErrString (rop -> rop_reason)); ! 187: break; ! 188: ! 189: default: ! 190: if (RoErrorRequest (sd, rox -> rox_id, result, rox -> rox_args, ! 191: ROS_NOPRIO, rti) == NOTOK) ! 192: fprintf (errfp, "RO-ERROR.REQUEST: %s", ! 193: RoErrString (rop -> rop_reason)); ! 194: break; ! 195: ! 196: case ERROR_MISTYPED: ! 197: if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_MISTYPED, ! 198: ROS_NOPRIO, rti) == NOTOK) ! 199: fprintf (errfp, "RO-U-REJECT.REQUEST: %s", ! 200: RoErrString (rop -> rop_reason)); ! 201: break; ! 202: } ! 203: ! 204: out: ; ! 205: ROXFREE (rox); ! 206: } ! 207: ! 208: ! 209: static int rts_result (sd, ror) ! 210: int sd; ! 211: register struct RoSAPresult *ror; ! 212: { ! 213: struct RoSAPindication rois; ! 214: register struct RoSAPindication *rti = &rois; ! 215: register struct RoSAPpreject *rop = &rti -> roi_preject; ! 216: ! 217: if (RoURejectRequest (sd, &ror -> ror_id, ROS_RRP_UNRECOG, ROS_NOPRIO, rti) ! 218: == NOTOK) ! 219: fprintf (errfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason)); ! 220: ! 221: RORFREE (ror); ! 222: } ! 223: ! 224: ! 225: static int rts_error (sd, roe) ! 226: int sd; ! 227: register struct RoSAPerror *roe; ! 228: { ! 229: struct RoSAPindication rois; ! 230: register struct RoSAPindication *rti = &rois; ! 231: register struct RoSAPpreject *rop = &rti -> roi_preject; ! 232: ! 233: if (RoURejectRequest (sd, &roe -> roe_id, ROS_REP_UNRECOG, ROS_NOPRIO, rti) ! 234: == NOTOK) ! 235: fprintf (errfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason)); ! 236: ! 237: ROEFREE (roe); ! 238: } ! 239: ! 240: ! 241: static int rts_ureject (sd, rou) ! 242: int sd; ! 243: register struct RoSAPureject *rou; ! 244: { ! 245: /* handle rejection here... */ ! 246: } ! 247: ! 248: ! 249: static int rts_preject (sd, rop) ! 250: int sd; ! 251: register struct RoSAPpreject *rop; ! 252: { ! 253: if (ROS_FATAL (rop -> rop_reason)) ! 254: fprintf (errfp, "RO-REJECT-P.INDICATION: %s", RoErrString (rop -> rop_reason)); ! 255: ! 256: /* handle temporary failure here... */ ! 257: } ! 258: ! 259: static int rts_finish (sd, acf) ! 260: int sd; ! 261: struct AcSAPfinish *acf; ! 262: { ! 263: struct AcSAPindication acis; ! 264: register struct AcSAPabort *aca = &acis.aci_abort; ! 265: ! 266: ACFFREE (acf); ! 267: ! 268: if (AcRelResponse (sd, ACS_ACCEPT, ACR_NORMAL, NULLPEP, 0, &acis) == NOTOK) ! 269: fprintf (errfp, "A-RELEASE.RESPONSE: %s", AcErrString (aca -> aca_reason)); ! 270: ! 271: fprintf (errfp, "association released"); ! 272: ! 273: exit(0); ! 274: } ! 275: ! 276: OP1(rox) ! 277: register struct RoSAPinvoke *rox; ! 278: { ! 279: fprintf(errfp, "Invocation\nid %d", rox->rox_id); ! 280: if (!rox->rox_nolinked) ! 281: fprintf(errfp, " linked to %d", rox->rox_linkid); ! 282: fprintf(errfp, " operation %d\n", rox->rox_op); ! 283: /* print the pe */ ! 284: ! 285: switch (rox->rox_op) { ! 286: case APDU_OP1: ! 287: return (ERROR_UNKNOWN); ! 288: ! 289: case APDU_ERR: ! 290: return (ERROR_ERROR); ! 291: ! 292: case APDU_URJ: ! 293: return (ERROR_MISTYPED); ! 294: ! 295: default: ! 296: fprintf(errfp, "\nunknown operation %d\n", rox->rox_op); ! 297: } ! 298: return (ERROR_ERROR); ! 299: } ! 300: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.