|
|
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: FILE *dfp;
13: main(argc, argv, envp)
14: int argc;
15: char **argv, **envp;
16: {
17: int result, sd;
18: int res;
19:
20: #if 0
21: struct SSAPstart sss;
22: register struct SSAPstart *ss = &sss;
23: struct SSAPindication sis;
24: register struct SSAPindication *si = &sis;
25: register struct SSAPabort *sa = &si->si_abort;
26: struct SSAPref ref;
27: #endif
28:
29: struct RoSAPindication rois;
30: register struct RoSAPindication *roi = &rois;
31: register struct RoSAPpreject *rop = &roi->roi_preject;
32: struct RoSAPstart ross;
33:
34: dfp = freopen("/dev/console", "w", stdout);
35: fprintf(dfp, "Got to here\n");
36:
37: #if 0
38: if (SInit(argc, argv, ss, si) == NOTOK)
39: fprintf(dfp, "initialisation fails: %s", SErrString(sa->sa_reason));
40:
41: sd = ss->ss_sd;
42:
43: /* would have read command line arguments here */
44:
45:
46: /* This is rather an elegant scheme but there is no point in doing
47: * all this in line, a function would be more appropriate apart from
48: * the number of arguments required.
49: */
50: #define dotoken(requires, shift, bit, type) \
51: { \
52: if (sss.ss_requirements & requires) \
53: switch (sss.ss_settings & (ST_MASK << shift)) { \
54: case ST_CALL_VALUE << shift: \
55: sss.ss_settings &= ~(ST_MASK << shift); \
56: sss.ss_settings |= ST_INIT_VALUE << shift; \
57: break; \
58: \
59: case ST_RESP_VALUE: \
60: case ST_INIT_VALUE: \
61: break; \
62: \
63: default: \
64: fprintf(stderr, "bad token setting for %s (%d)\n", type, \
65: sss.ss_settings & (ST_MASK << shift)); \
66: } \
67: }
68: /* expand out the above for each case */
69: dotokens();
70:
71: #undef dotoken
72: bzero((char *) &ref, sizeof (ref));
73: if (SConnResponse(sd, ref, NULLSA, SC_ACCEPT, sss.ss_requirements,
74: sss.ss_settings, sss.ss_isn, NULLCP, 0, si) == NOTOK) {
75: fprintf(dfp, "A-ASSOCIATE.RESPONSE: %s",
76: SErrString(sis.si_abort.sa_reason));
77: exit(4);
78: }
79: #endif
80:
81: if (RoInit(argc, argv, &ross, &rois) == NOTOK) {
82: fprintf(dfp, "initialisation fails: %s", RoErrString(rop->rop_reason));
83: exit(1);
84: }
85:
86: sd = ross.ros_sd;
87:
88: ROSFREE(&ross)
89:
90: if (RoBeginResponse(sd, ROS_ACCEPT, NULLPE, &rois) == NOTOK) {
91: fprintf(dfp, "RO-BEGIN.RESPONSE fails: %s",
92: RoErrString(rop->rop_reason));
93: exit(2);
94: }
95:
96: if (RoSetService (sd, RoSService, &rois) == NOTOK) {
97: error ("RoSetService: %s", RoErrString (rop -> rop_reason));
98: exit(3);
99: }
100:
101: #ifdef SHOW_BUG
102: if (RoSetIndications(sd, ros_indication, roi) == NOTOK)
103: fprintf(dfp, "RoSetIndications: %s", RoErrString(rop->rop_reason));
104:
105: for(;;)
106: pause();
107: #else
108: dfp = freopen("/dev/console", "w", stdout);
109: fprintf(dfp, "Got to here\n");
110: for (;;) {
111: switch (res = RoWaitRequest(sd, NOTOK, roi)) {
112: case NOTOK:
113: fprintf(dfp,"RoWaitRequest: %s\n", RoErrString(rop->rop_reason));
114: exit(1);
115:
116: case OK:
117: fprintf(dfp, "got a request %d\n", res);
118: ros_indication(sd, roi);
119: break;
120:
121: case DONE:
122: fprintf(dfp, "Done\n");
123: ros_indication(sd, roi);
124: exit(0); /* should never get to here */
125: }
126: }
127: #endif
128:
129:
130: }
131: /*
132: * Request/Reply loop of ROS server. Called when data arrives like a signal
133: * routine
134: */
135: static int
136: ros_indication(sd, roi)
137: int sd;
138: register struct RoSAPindication *roi;
139: {
140:
141: fprintf(dfp, "ros_indication %d\n", roi->roi_type);
142: switch (roi->roi_type) {
143: case ROI_INVOKE:
144: ros_invoke(sd, &roi->roi_invoke);
145: break;
146:
147: case ROI_RESULT:
148: ros_result(sd, &roi->roi_result);
149: break;
150:
151: case ROI_ERROR:
152: ros_error(sd, &roi->roi_error);
153: break;
154:
155:
156: case ROI_UREJECT:
157: ros_ureject(sd, &roi->roi_ureject);
158: break;
159:
160: case ROI_PREJECT:
161: ros_preject(sd, &roi->roi_preject);
162: break;
163:
164: case ROI_FINISH:
165: ros_finish(sd, &roi->roi_finish);
166: break;
167:
168: case ROI_END:
169: ros_end(sd, &roi->roi_end);
170: break;
171:
172: default:
173: fprintf(dfp, "unknown indication type=%d", roi->roi_type);
174: }
175: }
176:
177: extern int OP1();
178:
179:
180:
181: /* OPERATIONS are numbered APDU_OPx, where each is a unique integer. Further,
182: APDU_UNKNOWN is used as a tag different than any valid operation.
183:
184: ERRORS are numbered ERROR_xyz, where each is a unique integer.
185: ERROR_MISTYPED is used to signal an argument error to an operation.
186: Further, ERROR_UNKNOWN is used as a tag to indicate that the operation
187: succeeded.
188:
189: Finally, note that rox -> rox_args is updated in place by these routines.
190: If the routine returns ERROR_UNKNOWN, then rox_args contains the results
191: of the operation. If the routine returns ERROR_MISTYPED, then rox_args is
192: untouched. Otherwise, if the routine returns any other value, then
193: rox_args contains the parameters of the error which occurred. Obviously,
194: each routine calls ROXFREE prior to setting rox_args to a new value.
195: */
196:
197: static struct dispatch {
198: int ds_operation;
199: IFP ds_vector;
200: } dispatches[] = {
201: APDU_OP1, OP1,
202: APDU_ERR, OP1,
203: APDU_URJ, OP1,
204:
205: /* APDU_OPn, OPn, */
206:
207: APDU_UNKNOWN
208: };
209:
210:
211: static int ros_invoke (sd, rox)
212: int sd;
213: register struct RoSAPinvoke *rox;
214: {
215: int result;
216: register struct dispatch *ds;
217: struct RoSAPindication rois;
218: register struct RoSAPindication *roi = &rois;
219: register struct RoSAPpreject *rop = &roi -> roi_preject;
220:
221: for (ds = dispatches; ds -> ds_operation != APDU_UNKNOWN; ds++)
222: if (ds -> ds_operation == rox -> rox_op)
223: break;
224:
225: if (ds -> ds_operation == APDU_UNKNOWN) {
226: if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_UNRECOG,
227: ROS_NOPRIO, roi) == NOTOK)
228: error (dfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason));
229: goto out;
230: }
231:
232: if (rox -> rox_nolinked == 0) {
233: if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_LINKED,
234: ROS_NOPRIO, roi) == NOTOK)
235: error (dfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason));
236: goto out;
237: }
238:
239: switch (result = (*ds -> ds_vector) (rox)) {
240: case ERROR_UNKNOWN:
241: if (RoResultRequest (sd, rox -> rox_id, rox -> rox_op,
242: rox -> rox_args, ROS_NOPRIO, roi) == NOTOK)
243: error (dfp, "RO-RESULT.REQUEST: %s\n",
244: RoErrString (rop -> rop_reason));
245: fprintf (dfp, "RO-RESULT.REQUEST:done\n");
246: break;
247:
248: default:
249: if (RoErrorRequest (sd, rox -> rox_id, result, rox -> rox_args,
250: ROS_NOPRIO, roi) == NOTOK)
251: error (dfp, "RO-ERROR.REQUEST: %s\n",
252: RoErrString (rop -> rop_reason));
253: break;
254:
255: case ERROR_MISTYPED:
256: if (RoURejectRequest (sd, &rox -> rox_id, ROS_IP_MISTYPED,
257: ROS_NOPRIO, roi) == NOTOK)
258: error (dfp, "RO-U-REJECT.REQUEST: %s\n",
259: RoErrString (rop -> rop_reason));
260: break;
261: }
262:
263: out: ;
264: ROXFREE (rox);
265: }
266:
267:
268: static int ros_result (sd, ror)
269: int sd;
270: register struct RoSAPresult *ror;
271: {
272: struct RoSAPindication rois;
273: register struct RoSAPindication *roi = &rois;
274: register struct RoSAPpreject *rop = &roi -> roi_preject;
275:
276: if (RoURejectRequest (sd, &ror -> ror_id, ROS_RRP_UNRECOG, ROS_NOPRIO, roi)
277: == NOTOK)
278: error (dfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason));
279:
280: RORFREE (ror);
281: }
282:
283:
284: static int ros_error (sd, roe)
285: int sd;
286: register struct RoSAPerror *roe;
287: {
288: struct RoSAPindication rois;
289: register struct RoSAPindication *roi = &rois;
290: register struct RoSAPpreject *rop = &roi -> roi_preject;
291:
292: if (RoURejectRequest (sd, &roe -> roe_id, ROS_REP_UNRECOG, ROS_NOPRIO, roi)
293: == NOTOK)
294: error (dfp, "RO-U-REJECT.REQUEST: %s", RoErrString (rop -> rop_reason));
295:
296: ROEFREE (roe);
297: }
298:
299:
300: static int ros_ureject (sd, rou)
301: int sd;
302: register struct RoSAPureject *rou;
303: {
304: /* handle rejection here... */
305: }
306:
307:
308: static int ros_preject (sd, rop)
309: int sd;
310: register struct RoSAPpreject *rop;
311: {
312: if (ROS_FATAL (rop -> rop_reason))
313: error (dfp, "RO-REJECT-P.INDICATION: %s", RoErrString (rop -> rop_reason));
314:
315: /* handle temporary failure here... */
316: }
317:
318: static int ros_finish (sd, acf)
319: int sd;
320: struct AcSAPfinish *acf;
321: {
322: struct AcSAPindication acis;
323: register struct AcSAPabort *aca = &acis.aci_abort;
324:
325: ACFFREE (acf);
326:
327: if (AcRelResponse (sd, ACS_ACCEPT, ACR_NORMAL, NULLPEP, 0, &acis) == NOTOK)
328: error (dfp, "A-RELEASE.RESPONSE: %s", AcErrString (aca -> aca_reason));
329:
330: error (dfp, "association released");
331:
332: exit(0);
333: }
334:
335: static int
336: ros_end(sd, roe)
337: int sd;
338: struct RoSAPend *roe;
339: {
340: #if 0
341: struct SSAPindication sis;
342:
343: if (SRelResponse(sd, SC_ACCEPT, NULLCP, 0, &sis) == NOTOK) {
344: fprintf(dfp, "S-RELEASE.REPONSE: failed: %s\n",
345: SErrString(sis.si_abort.sa_reason));
346: exit(6);
347: }
348: #endif
349: struct RoSAPindication rois;
350:
351: fprintf(dfp, "RO-END.RESPONSE:\n");
352: if (RoEndResponse(sd, &rois) == NOTOK) {
353: fprintf(dfp, "RO-END.RESPONSE: failed: %s\n",
354: RoErrString(rois.roi_preject.rop_reason));
355: exit(6);
356: }
357:
358: exit(0);
359: }
360:
361: OP1(rox)
362: register struct RoSAPinvoke *rox;
363: {
364: fprintf(dfp, "Invocation\nid %d", rox->rox_id);
365: if (!rox->rox_nolinked)
366: fprintf(dfp, " linked to %d", rox->rox_linkid);
367: fprintf(dfp, " operation %d\n", rox->rox_op);
368: /* print the pe */
369:
370: switch (rox->rox_op) {
371: case APDU_OP1:
372: return (ERROR_UNKNOWN);
373:
374: case APDU_ERR:
375: return (ERROR_ERROR);
376:
377: case APDU_URJ:
378: return (ERROR_MISTYPED);
379:
380: default:
381: fprintf(dfp, "\nunknown operation %d\n", rox->rox_op);
382: }
383: return (ERROR_ERROR);
384: }
385:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.