1 | /* |
---|
2 | * |
---|
3 | * Copyright (C) 1988, 1989 by the Massachusetts Institute of Technology |
---|
4 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
5 | * For copying information, see the file mit-copyright.h in this release. |
---|
6 | * |
---|
7 | */ |
---|
8 | /* |
---|
9 | * |
---|
10 | * dispatch.c -- Procedure to do the dispatching on an RPC call. |
---|
11 | * This contains the procedure table. |
---|
12 | * |
---|
13 | * $Id: dispatch.c,v 1.14 2007-08-09 20:41:33 amb Exp $ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <stdlib.h> |
---|
17 | #include "rpc.h" |
---|
18 | #include <discuss/interface.h> |
---|
19 | #include <discuss/tfile.h> |
---|
20 | #include <discuss/acl.h> |
---|
21 | #include "ansi.h" |
---|
22 | |
---|
23 | #ifndef lint |
---|
24 | static const char rcsid_dispatch_c[] = |
---|
25 | "$Id: dispatch.c,v 1.14 2007-08-09 20:41:33 amb Exp $"; |
---|
26 | #endif |
---|
27 | |
---|
28 | extern bool recvbool(); |
---|
29 | extern char *recvstr(); |
---|
30 | extern tfile recvfile(); |
---|
31 | extern char rpc_caller []; |
---|
32 | struct proc_table procs[] = { |
---|
33 | 0, {0, 0, 0, 0, 0, 0, 0, 0}, /* unused */ |
---|
34 | 4, {STRTYPE, TFILETYPE, STRTYPE, INTTYPE, 0, 0, 0, 0}, /* add_trn */ |
---|
35 | 2, {STRTYPE, INTTYPE, 0, 0, 0, 0, 0, 0}, /* get_trn_info */ |
---|
36 | 2, {STRTYPE, INTTYPE, 0, 0, 0, 0, 0, 0}, /* delete_trn */ |
---|
37 | 2, {STRTYPE, INTTYPE, 0, 0, 0, 0, 0, 0}, /* retrieve_trn */ |
---|
38 | 3, {STRTYPE, STRTYPE, BOOLTYPE, 0, 0, 0, 0, 0}, /* create_mtg */ |
---|
39 | 1, {STRTYPE, 0, 0, 0, 0, 0, 0, 0}, /* old_get_mtg_info */ |
---|
40 | 0, { 0, 0, 0, 0, 0, 0, 0, 0}, /* start_mtg_info */ |
---|
41 | 0, { 0, 0, 0, 0, 0, 0, 0, 0}, /* next_mtg_info */ |
---|
42 | 3, {STRTYPE, INTTYPE, TFILETYPE, 0, 0, 0, 0, 0}, /* get_trn */ |
---|
43 | 1, {STRTYPE, 0, 0, 0, 0, 0, 0, 0}, /* remove_mtg */ |
---|
44 | 1, {STRTYPE, 0, 0, 0, 0, 0, 0, 0}, /* get_mtg_info */ |
---|
45 | 1, {STRTYPE, 0, 0, 0, 0, 0, 0, 0}, /* get_acl */ |
---|
46 | 2, {STRTYPE, STRTYPE, 0, 0, 0, 0, 0, 0}, /* get_access */ |
---|
47 | 3, {STRTYPE, STRTYPE, STRTYPE, 0, 0, 0, 0, 0}, /* set_access */ |
---|
48 | 2, {STRTYPE, STRTYPE, STRTYPE, 0, 0, 0, 0, 0}, /* delete_access */ |
---|
49 | 0, {0, 0, 0, 0, 0, 0, 0, 0}, /* whoami */ |
---|
50 | 2, {STRTYPE, INTTYPE, 0, 0, 0, 0, 0, 0}, /* get_trn_info2 */ |
---|
51 | 0, {0, 0, 0, 0, 0, 0, 0, 0}, /* get_server_version */ |
---|
52 | 3, {STRTYPE, INTTYPE, INTTYPE, 0, 0, 0, 0, 0}, /* set_trn_flags */ |
---|
53 | 5, {STRTYPE, TFILETYPE, STRTYPE, STRTYPE, INTTYPE, 0, 0, 0, 0}, /* add_trn2 */ |
---|
54 | 2, {STRTYPE, INTTYPE, 0, 0, 0, 0, 0, 0} /* get_trn_info3 */ |
---|
55 | }; |
---|
56 | |
---|
57 | int numprocs = sizeof (procs) / sizeof (procs [0]); |
---|
58 | |
---|
59 | dispatch (procno) |
---|
60 | int procno; |
---|
61 | { |
---|
62 | char *c1,*c2,*c3; |
---|
63 | char *modes; |
---|
64 | int i1,i2; |
---|
65 | bool b1; |
---|
66 | tfile t1,mem_tfile(); |
---|
67 | int result; |
---|
68 | dsc_acl *list; |
---|
69 | trn_info tinfo; |
---|
70 | trn_info2 tinfo2; |
---|
71 | trn_info3 tinfo3; |
---|
72 | mtg_info minfo; |
---|
73 | |
---|
74 | switch (procno) { |
---|
75 | |
---|
76 | /* add_trn (mtg_name, source_file, subject, reply_trn, result_trn, result) */ |
---|
77 | case ADD_TRN: |
---|
78 | c1 = recvstr(); /* mtg_name */ |
---|
79 | t1 = recvfile(); /* source_file */ |
---|
80 | c2 = recvstr(); /* subject */ |
---|
81 | i1 = recvint(); /* reply_trn */ |
---|
82 | add_trn (c1, t1, c2, i1, &i2, &result); |
---|
83 | startreply(); |
---|
84 | sendint(i2); |
---|
85 | sendint(result); |
---|
86 | sendreply(); |
---|
87 | |
---|
88 | tdestroy(t1); |
---|
89 | free(c1); |
---|
90 | free(c2); |
---|
91 | break; |
---|
92 | |
---|
93 | /* get_trn_info (mtg_name, trn, info, result) */ |
---|
94 | case GET_TRN_INFO: |
---|
95 | c1 = recvstr(); /* mtg_name */ |
---|
96 | i1 = recvint(); /* trn */ |
---|
97 | get_trn_info (c1, i1, &tinfo, &result); |
---|
98 | startreply(); |
---|
99 | send_trn_info(&tinfo); |
---|
100 | sendint(result); |
---|
101 | sendreply(); |
---|
102 | |
---|
103 | free(tinfo.subject); |
---|
104 | free(tinfo.author); |
---|
105 | free(c1); |
---|
106 | break; |
---|
107 | |
---|
108 | /* delete_trn (mtg_name, trn, result) */ |
---|
109 | case DELETE_TRN: |
---|
110 | c1 = recvstr(); /* mtg_name */ |
---|
111 | i1 = recvint(); /* trn */ |
---|
112 | delete_trn (c1, i1, &result); |
---|
113 | startreply(); |
---|
114 | sendint(result); |
---|
115 | sendreply(); |
---|
116 | free(c1); |
---|
117 | break; |
---|
118 | |
---|
119 | /* retrieve_trn (mtg_name, trn, result) */ |
---|
120 | case RETRIEVE_TRN: |
---|
121 | c1 = recvstr(); /* mtg_name */ |
---|
122 | i1 = recvint(); /* trn */ |
---|
123 | retrieve_trn (c1, i1, &result); |
---|
124 | startreply(); |
---|
125 | sendint(result); |
---|
126 | sendreply(); |
---|
127 | free(c1); |
---|
128 | break; |
---|
129 | |
---|
130 | /* create_mtg (location, long_mtg_name, public, result) */ |
---|
131 | case CREATE_MTG: |
---|
132 | c1 = recvstr(); /* location */ |
---|
133 | c2 = recvstr(); /* long_mtg_name */ |
---|
134 | b1 = recvbool(); /* public flag */ |
---|
135 | create_mtg (c1, c2, b1, &result); |
---|
136 | startreply(); |
---|
137 | sendint(result); |
---|
138 | sendreply(); |
---|
139 | free(c1); |
---|
140 | free(c2); |
---|
141 | break; |
---|
142 | |
---|
143 | /* get_mtg_info (mtg_name, info, result) */ |
---|
144 | case GET_MTG_INFO: |
---|
145 | c1 = recvstr(); /* mtg_name */ |
---|
146 | get_mtg_info (c1, &minfo, &result); |
---|
147 | startreply(); |
---|
148 | send_mtg_info(&minfo); |
---|
149 | sendint(result); |
---|
150 | sendreply(); |
---|
151 | |
---|
152 | free(minfo.location); |
---|
153 | free(minfo.long_name); |
---|
154 | free(minfo.chairman); |
---|
155 | free(minfo.access_modes); |
---|
156 | free(c1); |
---|
157 | break; |
---|
158 | |
---|
159 | /* old_get_mtg_info (mtg_name, info, result) */ |
---|
160 | case OLD_GET_MTG_INFO: |
---|
161 | c1 = recvstr(); /* mtg_name */ |
---|
162 | get_mtg_info (c1, &minfo, &result); |
---|
163 | startreply(); |
---|
164 | old_send_mtg_info(&minfo); |
---|
165 | sendint(result); |
---|
166 | sendreply(); |
---|
167 | |
---|
168 | free(minfo.location); |
---|
169 | free(minfo.long_name); |
---|
170 | free(minfo.chairman); |
---|
171 | free(minfo.access_modes); |
---|
172 | free(c1); |
---|
173 | break; |
---|
174 | |
---|
175 | /* get_trn (mtg_name, trn, dest_file, result) */ |
---|
176 | case GET_TRN: |
---|
177 | c1 = recvstr(); /* mtg_name */ |
---|
178 | i1 = recvint(); /* trn */ |
---|
179 | t1 = recvfile (); /* dest_file */ |
---|
180 | get_trn (c1, i1, t1, &result); |
---|
181 | tdestroy (t1); |
---|
182 | startreply(); |
---|
183 | sendint(result); |
---|
184 | sendreply(); |
---|
185 | free(c1); |
---|
186 | break; |
---|
187 | |
---|
188 | /* remove_mtg (mtg_name, result) */ |
---|
189 | case REMOVE_MTG: |
---|
190 | c1 = recvstr(); /* mtg_name */ |
---|
191 | remove_mtg (c1, &result); |
---|
192 | startreply(); |
---|
193 | sendint(result); |
---|
194 | sendreply(); |
---|
195 | free(c1); |
---|
196 | break; |
---|
197 | |
---|
198 | /* updated_mtg (mtg_name, date_attended, last, updated, result) */ |
---|
199 | case UPDATED_MTG: |
---|
200 | c1 = recvstr(); /* mtg_name */ |
---|
201 | i1 = recvint(); /* date_attended */ |
---|
202 | i2 = recvint(); /* last */ |
---|
203 | updated_mtg (c1, i1, i2, &b1, &result); |
---|
204 | startreply(); |
---|
205 | sendbool(b1); |
---|
206 | sendint (result); |
---|
207 | sendreply(); |
---|
208 | free(c1); |
---|
209 | |
---|
210 | break; |
---|
211 | /* get_acl (mtg_name) */ |
---|
212 | case GET_ACL: |
---|
213 | c1 = recvstr(); /* mtg_name */ |
---|
214 | get_acl (c1, &result, &list); |
---|
215 | startreply(); |
---|
216 | sendint(result); |
---|
217 | send_acl(list); |
---|
218 | sendreply(); |
---|
219 | acl_destroy(list); |
---|
220 | free(c1); |
---|
221 | break; |
---|
222 | |
---|
223 | /* get_access(mtg_name, princ_name) */ |
---|
224 | case GET_ACCESS: |
---|
225 | c1 = recvstr(); |
---|
226 | c2 = recvstr(); |
---|
227 | get_access(c1, c2, &modes, &result); |
---|
228 | startreply(); |
---|
229 | sendstr(modes); |
---|
230 | sendint(result); |
---|
231 | sendreply(); |
---|
232 | free(modes); |
---|
233 | free(c1); |
---|
234 | free(c2); |
---|
235 | |
---|
236 | break; |
---|
237 | /* set_access(mtg_name, princ_name, mode) */ |
---|
238 | case SET_ACCESS: |
---|
239 | c1 = recvstr(); |
---|
240 | c2 = recvstr(); |
---|
241 | c3 = recvstr(); |
---|
242 | set_access(c1, c2, c3, &result); |
---|
243 | startreply(); |
---|
244 | sendint(result); |
---|
245 | sendreply(); |
---|
246 | free(c1); |
---|
247 | free(c2); |
---|
248 | free(c3); |
---|
249 | break; |
---|
250 | |
---|
251 | case DELETE_ACCESS: |
---|
252 | c1 = recvstr(); |
---|
253 | c2 = recvstr(); |
---|
254 | delete_access(c1, c2, &result); |
---|
255 | startreply(); |
---|
256 | sendint(result); |
---|
257 | sendreply(); |
---|
258 | free(c1); |
---|
259 | free(c2); |
---|
260 | break; |
---|
261 | |
---|
262 | case WHO_AM_I: |
---|
263 | startreply(); |
---|
264 | sendstr(rpc_caller); |
---|
265 | sendreply(); |
---|
266 | break; |
---|
267 | |
---|
268 | /* get_trn_info2 (mtg_name, trn, info, result) */ |
---|
269 | case GET_TRN_INFO2: |
---|
270 | c1 = recvstr(); /* mtg_name */ |
---|
271 | i1 = recvint(); /* trn */ |
---|
272 | get_trn_info2 (c1, i1, &tinfo2, &result); |
---|
273 | startreply(); |
---|
274 | send_trn_info2(&tinfo2); |
---|
275 | sendint(result); |
---|
276 | sendreply(); |
---|
277 | |
---|
278 | free(tinfo2.subject); |
---|
279 | free(tinfo2.author); |
---|
280 | free(c1); |
---|
281 | break; |
---|
282 | |
---|
283 | /* get_server_version (version_number, result) */ |
---|
284 | case GET_SERVER_VERSION: |
---|
285 | startreply(); |
---|
286 | sendint(SERVER_3); /* Includes get_trn_info3 */ |
---|
287 | sendint(0); /* Success */ |
---|
288 | sendreply(); |
---|
289 | break; |
---|
290 | |
---|
291 | /* set_trn_flags (mtg_name, trn, flags, result) */ |
---|
292 | case SET_TRN_FLAGS: |
---|
293 | c1 = recvstr(); /* mtg_name */ |
---|
294 | i1 = recvint(); /* trn */ |
---|
295 | i2 = recvint(); /* flags */ |
---|
296 | set_trn_flags (c1, i1, i2, &result); |
---|
297 | startreply(); |
---|
298 | sendint(result); |
---|
299 | sendreply(); |
---|
300 | |
---|
301 | free(c1); |
---|
302 | break; |
---|
303 | |
---|
304 | /* add_trn2 (mtg_name, source_file, subject, signature, reply_trn, result_trn, result) */ |
---|
305 | case ADD_TRN2: |
---|
306 | c1 = recvstr(); /* mtg_name */ |
---|
307 | t1 = recvfile(); /* source_file */ |
---|
308 | c2 = recvstr(); /* subject */ |
---|
309 | c3 = recvstr(); /* signature */ |
---|
310 | i1 = recvint(); /* reply_trn */ |
---|
311 | add_trn2 (c1, t1, c2, c3, i1, &i2, &result); |
---|
312 | startreply(); |
---|
313 | sendint(i2); |
---|
314 | sendint(result); |
---|
315 | sendreply(); |
---|
316 | |
---|
317 | tdestroy(t1); |
---|
318 | free(c1); |
---|
319 | free(c2); |
---|
320 | free(c3); |
---|
321 | break; |
---|
322 | |
---|
323 | /* get_trn_info3 (mtg_name, trn, info, result) */ |
---|
324 | case GET_TRN_INFO3: |
---|
325 | c1 = recvstr(); /* mtg_name */ |
---|
326 | i1 = recvint(); /* trn */ |
---|
327 | get_trn_info3 (c1, i1, &tinfo3, &result); |
---|
328 | startreply(); |
---|
329 | send_trn_info3(&tinfo3); |
---|
330 | sendint(result); |
---|
331 | sendreply(); |
---|
332 | |
---|
333 | free(tinfo3.subject); |
---|
334 | free(tinfo3.author); |
---|
335 | free(tinfo3.signature); |
---|
336 | free(c1); |
---|
337 | break; |
---|
338 | } |
---|
339 | return; /* all done for now */ |
---|
340 | } |
---|
341 | |
---|
342 | /* |
---|
343 | * |
---|
344 | * send_trn_info -- send a trn_info struct. |
---|
345 | * |
---|
346 | */ |
---|
347 | send_trn_info(tinfo) |
---|
348 | trn_info *tinfo; |
---|
349 | { |
---|
350 | sendint (tinfo -> version); |
---|
351 | sendint (tinfo -> current); |
---|
352 | sendint (tinfo -> prev); |
---|
353 | sendint (tinfo -> next); |
---|
354 | sendint (tinfo -> pref); |
---|
355 | sendint (tinfo -> nref); |
---|
356 | sendint (tinfo -> fref); |
---|
357 | sendint (tinfo -> lref); |
---|
358 | sendint (tinfo -> chain_index); |
---|
359 | sendint (tinfo -> date_entered); |
---|
360 | sendint (tinfo -> num_lines); |
---|
361 | sendint (tinfo -> num_chars); |
---|
362 | sendstr (tinfo -> subject); |
---|
363 | sendstr (tinfo -> author); |
---|
364 | } |
---|
365 | |
---|
366 | /* |
---|
367 | * |
---|
368 | * send_trn_info2 -- send a trn_info2 struct. |
---|
369 | * |
---|
370 | */ |
---|
371 | send_trn_info2(tinfo) |
---|
372 | trn_info2 *tinfo; |
---|
373 | { |
---|
374 | sendint (tinfo -> version); |
---|
375 | sendint (tinfo -> current); |
---|
376 | sendint (tinfo -> prev); |
---|
377 | sendint (tinfo -> next); |
---|
378 | sendint (tinfo -> pref); |
---|
379 | sendint (tinfo -> nref); |
---|
380 | sendint (tinfo -> fref); |
---|
381 | sendint (tinfo -> lref); |
---|
382 | sendint (tinfo -> chain_index); |
---|
383 | sendint (tinfo -> date_entered); |
---|
384 | sendint (tinfo -> num_lines); |
---|
385 | sendint (tinfo -> num_chars); |
---|
386 | sendstr (tinfo -> subject); |
---|
387 | sendstr (tinfo -> author); |
---|
388 | sendint (tinfo -> flags); |
---|
389 | } |
---|
390 | |
---|
391 | /* |
---|
392 | * |
---|
393 | * send_trn_info3 -- send a trn_info3 struct. |
---|
394 | * |
---|
395 | */ |
---|
396 | send_trn_info3(tinfo) |
---|
397 | trn_info3 *tinfo; |
---|
398 | { |
---|
399 | sendint (tinfo -> version); |
---|
400 | sendint (tinfo -> current); |
---|
401 | sendint (tinfo -> prev); |
---|
402 | sendint (tinfo -> next); |
---|
403 | sendint (tinfo -> pref); |
---|
404 | sendint (tinfo -> nref); |
---|
405 | sendint (tinfo -> fref); |
---|
406 | sendint (tinfo -> lref); |
---|
407 | sendint (tinfo -> chain_index); |
---|
408 | sendint (tinfo -> date_entered); |
---|
409 | sendint (tinfo -> num_lines); |
---|
410 | sendint (tinfo -> num_chars); |
---|
411 | sendstr (tinfo -> subject); |
---|
412 | sendstr (tinfo -> author); |
---|
413 | sendint (tinfo -> flags); |
---|
414 | sendstr (tinfo -> signature); |
---|
415 | } |
---|
416 | |
---|
417 | /* |
---|
418 | * |
---|
419 | * send_mtg_info -- Send a mtg info struct. |
---|
420 | * |
---|
421 | */ |
---|
422 | old_send_mtg_info(minfo) |
---|
423 | mtg_info *minfo; |
---|
424 | { |
---|
425 | sendint (minfo -> version); |
---|
426 | sendstr (minfo -> location); |
---|
427 | sendstr (minfo -> long_name); |
---|
428 | sendstr (minfo -> chairman); |
---|
429 | sendint (minfo -> first); |
---|
430 | sendint (minfo -> last); |
---|
431 | sendint (minfo -> lowest); |
---|
432 | sendint (minfo -> highest); |
---|
433 | sendint (minfo -> date_created); |
---|
434 | sendint (minfo -> date_modified); |
---|
435 | sendbool (minfo -> public_flag); |
---|
436 | } |
---|
437 | |
---|
438 | /* |
---|
439 | * |
---|
440 | * send_mtg_info -- Send a mtg info struct. |
---|
441 | * |
---|
442 | */ |
---|
443 | send_mtg_info(minfo) |
---|
444 | mtg_info *minfo; |
---|
445 | { |
---|
446 | sendint (minfo -> version); |
---|
447 | sendstr (minfo -> location); |
---|
448 | sendstr (minfo -> long_name); |
---|
449 | sendstr (minfo -> chairman); |
---|
450 | sendint (minfo -> first); |
---|
451 | sendint (minfo -> last); |
---|
452 | sendint (minfo -> lowest); |
---|
453 | sendint (minfo -> highest); |
---|
454 | sendint (minfo -> date_created); |
---|
455 | sendint (minfo -> date_modified); |
---|
456 | sendbool (minfo -> public_flag); |
---|
457 | sendstr (minfo -> access_modes); |
---|
458 | } |
---|
459 | |
---|
460 | /* |
---|
461 | * send_acl -- Send an access control list. |
---|
462 | */ |
---|
463 | send_acl(acl) |
---|
464 | dsc_acl *acl; |
---|
465 | { |
---|
466 | register dsc_acl_entry *ae; |
---|
467 | register int n; |
---|
468 | |
---|
469 | if (!acl) { |
---|
470 | sendint(0); |
---|
471 | return; |
---|
472 | } |
---|
473 | |
---|
474 | sendint (acl->acl_length); |
---|
475 | for (ae=acl->acl_entries, n=acl->acl_length; |
---|
476 | n; |
---|
477 | --n, ++ae) { |
---|
478 | sendstr(ae->modes); |
---|
479 | sendstr(ae->principal); |
---|
480 | } |
---|
481 | } |
---|