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