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