Start development on 386BSD 0.0
[unix-history] / .ref-BSD-4_3_Net_2 / usr / src / contrib / isode / rosap / test / rospinit.c
CommitLineData
dd8036b5
C
1#include <stdio.h>
2#include "generic.h" /* defines OPERATIONS and ERRORS */
3#include <isode/rosap.h>
4
5#define error printf
6
7 /* e.g., "directory" */
8static char *myservice = "ROSPTEST";
9
10 /* e.g., "directory services" */
11static char *mycontext = "isode chic read";
12static char *mypci = "isode chic read pci";
13
14
15#define INVOKE 1 /* do a RoInvokeRequest */
16#define INTREQ 2 /* do a RoIntrRequest */
17#define INVERR 3 /* request an error */
18#define INVURJ 4 /* request a user reject */
19#define INVPRJ 5 /* request a provider reject */
20
21main (argc, argv, envp)
22int argc;
23char **argv,
24 **envp;
25{
26 int sd;
27 struct SSAPref sfs;
28 register struct SSAPref *sf;
29 register struct PSAPaddr *pa;
30 struct AcSAPconnect accs;
31 register struct AcSAPconnect *acc = &accs;
32 struct AcSAPrelease acrs;
33 register struct AcSAPrelease *acr = &acrs;
34 struct AcSAPindication acis;
35 register struct AcSAPindication *aci = &acis;
36 register struct AcSAPabort *aca = &aci -> aci_abort;
37 struct RoSAPindication rois;
38 register struct RoSAPpreject *rop = &rois.roi_preject;
39 register AEI aei;
40 register OID ctx, pci;
41 struct PSAPctxlist pcs;
42 register struct PSAPctxlist *pc = &pcs;
43 int servicetype = RoP;
44
45 if ((aei = str2aei (argv[1], myservice)) == NULLAEI)
46 error ("%s-%s: unknown application-entity", argv[1], myservice);
47 if ((pa = aei2addr (aei)) == NULLPA)
48 error ("address translation failed");
49 if ((ctx = ode2oid (mycontext)) == NULLOID)
50 error ("%s: unknown object descriptor", mycontext);
51 if ((ctx = oid_cpy (ctx)) == NULLOID)
52 error ("oid_cpy");
53 if ((pci = ode2oid (mypci)) == NULLOID)
54 error ("%s: unknown object descriptor", mypci);
55 if ((pci = oid_cpy (pci)) == NULLOID)
56 error ("oid_cpy");
57 pc -> pc_nctx = 1;
58 pc -> pc_ctx[0].pc_id = 1;
59 pc -> pc_ctx[0].pc_asn = pci;
60 pc -> pc_ctx[0].pc_atn = NULLOID;
61
62
63 if ((sf = addr2ref (PLocalHostName ())) == NULL) {
64 sf = &sfs;
65 (void) bzero ((char *) sf, sizeof *sf);
66 }
67
68 if (AcAssocRequest (ctx, NULLAEI, NULLAEI, NULLPA, pa, pc, NULLOID,
69 0, ROS_MYREQUIRE, SERIAL_NONE, 0, sf, NULLPEP, 0, NULLQOS,
70 acc, aci)
71 == NOTOK)
72 error ("A-ASSOCIATE.REQUEST: %s", AcErrString (aca -> aca_reason));
73
74 if (acc -> acc_result != ACS_ACCEPT)
75 error ("association rejected: %s", AcErrString (aca -> aca_reason));
76
77 sd = acc -> acc_sd;
78
79 if (RoSetService (sd, RoPService, &rois) == NOTOK)
80 error ("RoSetService: %s", RoErrString (rop -> rop_reason));
81
82 invoke (sd, INVOKE); /* invoke the operations, etc. */
83
84 invoke (sd, INTREQ); /* invoke the operations, etc. */
85
86 invoke (sd, INVERR); /* invoke the operations, etc. */
87
88 invoke (sd, INVURJ); /* invoke the operations, etc. */
89
90 invoke (sd, INVPRJ); /* invoke the operations, etc. */
91
92 if (AcRelRequest (sd, ACF_NORMAL, NULLPEP, 0, NOTOK, acr, aci) == NOTOK)
93 error ("A-RELEASE.REQUEST: %s", AcErrString (aca -> aca_reason));
94
95 if (!acr -> acr_affirmative) {
96 (void) AcUAbortRequest (sd, NULLPEP, 0, aci);
97 error ("release rejected by peer: %d", acr -> acr_reason);
98 }
99
100 ACRFREE (acr);
101
102 exit (0);
103}
104
105/*
106 * Test example
107 */
108invoke(sd, type)
109int sd;
110int type; /* of invocation */
111{
112 int invoke;
113 struct RoSAPindication rind;
114 int res;
115
116 invoke = 1;
117
118 switch (type) {
119 case INVOKE:
120 res = RoInvokeRequest(sd, APDU_OP1, ROS_SYNC, NULLPE, invoke, NULLIP,
121 ROS_NOPRIO, &rind);
122 break;
123
124 case INTREQ:
125 res = RoIntrRequest(sd, APDU_OP1, NULLPE, invoke, NULLIP, ROS_NOPRIO,
126 &rind);
127 break;
128
129 case INVERR:
130 res = RoInvokeRequest(sd, APDU_ERR, ROS_SYNC, NULLPE, invoke, NULLIP,
131 ROS_NOPRIO, &rind);
132 break;
133
134 case INVURJ:
135 res = RoInvokeRequest(sd, APDU_URJ, ROS_SYNC, NULLPE, invoke, NULLIP,
136 ROS_NOPRIO, &rind);
137 break;
138
139 case INVPRJ:
140 res = RoInvokeRequest(sd, APDU_PRJ, ROS_SYNC, NULLPE, invoke, NULLIP,
141 ROS_NOPRIO, &rind);
142 break;
143
144 default:
145 fprintf(stderr, "invoke called with illegal type %d\n", type);
146 exit(1);
147
148 }
149
150 switch (res) {
151 case NOTOK:
152 if (rind.roi_type == ROI_PREJECT)
153 error("RO-INVOKE.REQUEST: %s\n",
154 RoErrString(rind.roi_preject.rop_reason));
155 else
156 error("RO-INVOKE.REQUEST:failed: unexpected returned type %d\n",
157 rind.roi_type);
158 exit(1);
159
160 case OK:
161 break;
162
163 default:
164 error("RO-INVOKE.REQUEST:failed(%d): unexpected returned type %d\n",
165 res, rind.roi_type);
166 exit(2);
167
168 }
169
170 switch (rind.roi_type) {
171 case ROI_RESULT:
172 if (rind.roi_result.ror_id == invoke)
173 printf("Result received\n");
174 else
175 printf("Result for wrong request %d\n", rind.roi_result.ror_id);
176 break;
177
178 case ROI_ERROR:
179 if (rind.roi_error.roe_id == invoke)
180 printf("Error received\n");
181 else
182 printf("Error for wrong request %d\n", rind.roi_error.roe_id);
183 break;
184
185 case ROI_UREJECT:
186 if (rind.roi_ureject.rou_id == invoke)
187 printf("User Reject received reason %d\n",
188 rind.roi_ureject.rou_reason);
189 else
190 printf("User Reject for wrong request %d\n",
191 rind.roi_ureject.rou_id);
192 break;
193
194 case ROI_PREJECT:
195 if (rind.roi_preject.rop_id == invoke)
196 printf("Provider Reject received %s\n",
197 RoErrString(rind.roi_preject.rop_reason));
198 else
199 printf("Provider Reject for wrong request %d\n",
200 rind.roi_preject.rop_id);
201 break;
202
203 default:
204 printf("Unexpected reply received %d\n", rind.roi_type);
205 break;
206 }
207
208}