1 | /* |
---|
2 | * |
---|
3 | * Copyright (C) 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 | * do_stuff () -- Routines to implement the various lisp requests. |
---|
11 | * |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <sys/file.h> |
---|
16 | #include <signal.h> |
---|
17 | #include <string.h> |
---|
18 | #include <sys/wait.h> |
---|
19 | #include <ctype.h> |
---|
20 | #include <sys/time.h> |
---|
21 | #include <netdb.h> |
---|
22 | #include <discuss/discuss.h> |
---|
23 | |
---|
24 | #define PROTOCOL_VERSION "21" |
---|
25 | |
---|
26 | extern char *user_id; |
---|
27 | extern tfile stdout_tf; |
---|
28 | extern int bit_bucket(); |
---|
29 | extern int errno; |
---|
30 | extern char *do_quote(); |
---|
31 | tfile unix_tfile(); |
---|
32 | |
---|
33 | extern char *malloc(); |
---|
34 | |
---|
35 | do_gmi(args) |
---|
36 | char *args; |
---|
37 | { |
---|
38 | char *cp = args, *mtg_name, delim; |
---|
39 | name_blk nb; |
---|
40 | mtg_info m_info; |
---|
41 | char mtime[30]; |
---|
42 | int code; |
---|
43 | |
---|
44 | /* First, we get the meeting name */ |
---|
45 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
46 | printf("; Missing meeting name\n"); |
---|
47 | return; |
---|
48 | } |
---|
49 | |
---|
50 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
51 | if (code != 0) { |
---|
52 | printf(";%s\n", error_message(code)); |
---|
53 | return; |
---|
54 | } |
---|
55 | |
---|
56 | dsc_get_mtg_info(&nb,&m_info,&code); |
---|
57 | if (code != 0) { |
---|
58 | printf(";%s\n", error_message(code)); |
---|
59 | dsc_destroy_name_blk(&nb); |
---|
60 | return; |
---|
61 | } |
---|
62 | |
---|
63 | strcpy(mtime, short_time(&m_info.date_created)); |
---|
64 | printf("(\"%s\" \"%s\" \"%s\" %d %d %d %d \"%s\" \"%s\" %d \"%s\" %d)\n", |
---|
65 | m_info.location, |
---|
66 | m_info.long_name, |
---|
67 | m_info.chairman, |
---|
68 | m_info.first, |
---|
69 | m_info.last, |
---|
70 | m_info.lowest, |
---|
71 | m_info.highest, |
---|
72 | mtime, |
---|
73 | short_time(&m_info.date_modified), |
---|
74 | m_info.public_flag, |
---|
75 | m_info.access_modes, |
---|
76 | nb.last); |
---|
77 | |
---|
78 | dsc_destroy_name_blk(&nb); |
---|
79 | dsc_destroy_mtg_info(&m_info); |
---|
80 | } |
---|
81 | |
---|
82 | do_gti(args) |
---|
83 | char *args; |
---|
84 | { |
---|
85 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
86 | trn_nums trn_num; |
---|
87 | name_blk nb; |
---|
88 | trn_info2 t_info; |
---|
89 | int code; |
---|
90 | |
---|
91 | /* First, we get the transaction number */ |
---|
92 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
93 | printf("; Missing trn number\n"); |
---|
94 | return; |
---|
95 | } |
---|
96 | |
---|
97 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
98 | printf("; Missing meeting name\n"); |
---|
99 | return; |
---|
100 | } |
---|
101 | |
---|
102 | trn_num = atoi(trn_string); |
---|
103 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
104 | if (code != 0) { |
---|
105 | printf(";%s\n", error_message(code)); |
---|
106 | return; |
---|
107 | } |
---|
108 | |
---|
109 | dsc_get_trn_info2(&nb,trn_num,&t_info,&code); |
---|
110 | if (code != 0) { |
---|
111 | printf(";%s\n", error_message(code)); |
---|
112 | dsc_destroy_name_blk(&nb); |
---|
113 | return; |
---|
114 | } |
---|
115 | |
---|
116 | t_info.subject = do_quote(t_info.subject); |
---|
117 | printf("(%d %d %d %d %d %d %d %d \"%s\" %d %d \"%s\" \"%s\" %d)\n", |
---|
118 | t_info.current, |
---|
119 | t_info.prev, |
---|
120 | t_info.next, |
---|
121 | t_info.pref, |
---|
122 | t_info.nref, |
---|
123 | t_info.fref, |
---|
124 | t_info.lref, |
---|
125 | t_info.chain_index, |
---|
126 | short_time(&t_info.date_entered), |
---|
127 | t_info.num_lines, |
---|
128 | t_info.num_chars, |
---|
129 | t_info.subject, |
---|
130 | t_info.author, |
---|
131 | t_info.flags); |
---|
132 | |
---|
133 | dsc_destroy_name_blk(&nb); |
---|
134 | dsc_destroy_trn_info(&t_info); |
---|
135 | } |
---|
136 | |
---|
137 | do_gt(args) |
---|
138 | char *args; |
---|
139 | { |
---|
140 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
141 | trn_nums trn_num; |
---|
142 | name_blk nb; |
---|
143 | trn_info2 tinfo; |
---|
144 | tfile tf; |
---|
145 | char *plural; |
---|
146 | char line[255]; |
---|
147 | int code; |
---|
148 | |
---|
149 | /* First, we get the transaction number */ |
---|
150 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
151 | printf("; Missing trn number\n"); |
---|
152 | return; |
---|
153 | } |
---|
154 | |
---|
155 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
156 | printf("; Missing meeting name\n"); |
---|
157 | return; |
---|
158 | } |
---|
159 | |
---|
160 | trn_num = atoi(trn_string); |
---|
161 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
162 | if (code != 0) { |
---|
163 | printf(";%s\n", error_message(code)); |
---|
164 | return; |
---|
165 | } |
---|
166 | |
---|
167 | dsc_get_trn_info2(&nb,trn_num,&tinfo,&code); |
---|
168 | if (code != 0) { |
---|
169 | printf(";%s\n", error_message(code)); |
---|
170 | dsc_destroy_name_blk(&nb); |
---|
171 | return; |
---|
172 | } |
---|
173 | |
---|
174 | if (tinfo.num_lines != 1) |
---|
175 | plural = "s"; |
---|
176 | else |
---|
177 | plural = ""; |
---|
178 | |
---|
179 | |
---|
180 | if (tinfo.subject [0] == '\0') |
---|
181 | tinfo.num_lines--; |
---|
182 | |
---|
183 | printf("(%d)\n", |
---|
184 | tinfo.num_lines+3); |
---|
185 | |
---|
186 | tf = stdout_tf; |
---|
187 | |
---|
188 | (void) sprintf (line, "[%04d]%c %s %s %s (%d line%s)\n", |
---|
189 | tinfo.current, tinfo.flags & TRN_FLAG1 ? 'F' : ' ', |
---|
190 | tinfo.author, mtg_name, |
---|
191 | short_time (&tinfo.date_entered), |
---|
192 | tinfo.num_lines, plural); |
---|
193 | twrite (tf, line, strlen (line), &code); |
---|
194 | if (tinfo.subject [0] != '\0') { |
---|
195 | twrite (tf, "Subject: ", 9, &code); |
---|
196 | twrite (tf, tinfo.subject, strlen (tinfo.subject), &code); |
---|
197 | twrite (tf, "\n", 1, &code); |
---|
198 | } |
---|
199 | |
---|
200 | dsc_get_trn(&nb, trn_num, tf, &code); |
---|
201 | if (code != 0) return; |
---|
202 | |
---|
203 | if (tinfo.pref == 0 && tinfo.nref == 0) |
---|
204 | (void) sprintf (line, "--[%04d]--\n", tinfo.current); |
---|
205 | else if (tinfo.pref == 0) |
---|
206 | (void) sprintf (line, "--[%04d]-- (nref = [%04d])\n", |
---|
207 | tinfo.current, tinfo.nref); |
---|
208 | else if (tinfo.nref == 0) |
---|
209 | (void) sprintf (line, "--[%04d]-- (pref = [%04d])\n", |
---|
210 | tinfo.current, tinfo.pref); |
---|
211 | else |
---|
212 | (void) sprintf (line, |
---|
213 | "--[%04d]-- (pref = [%04d], nref = [%04d])\n", |
---|
214 | tinfo.current, tinfo.pref, tinfo.nref); |
---|
215 | twrite (tf, line, strlen (line), &code); |
---|
216 | |
---|
217 | dsc_destroy_name_blk(&nb); |
---|
218 | dsc_destroy_trn_info(&tinfo); |
---|
219 | } |
---|
220 | |
---|
221 | do_gtf(args) |
---|
222 | char *args; |
---|
223 | { |
---|
224 | char *cp = args, *mtg_name, delim, *trn_string, *output_fn; |
---|
225 | trn_nums trn_num; |
---|
226 | name_blk nb; |
---|
227 | trn_info2 tinfo; |
---|
228 | tfile tf; |
---|
229 | int fd; |
---|
230 | char *plural; |
---|
231 | char line[255]; |
---|
232 | int code; |
---|
233 | |
---|
234 | /* First, get the output filename */ |
---|
235 | if (get_word(&cp, &output_fn, " ", &delim) < 0) { |
---|
236 | printf("; Missing output filename\n"); |
---|
237 | return; |
---|
238 | } |
---|
239 | |
---|
240 | /* Now, we get the transaction number */ |
---|
241 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
242 | printf("; Missing trn number\n"); |
---|
243 | return; |
---|
244 | } |
---|
245 | |
---|
246 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
247 | printf("; Missing meeting name\n"); |
---|
248 | return; |
---|
249 | } |
---|
250 | |
---|
251 | trn_num = atoi(trn_string); |
---|
252 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
253 | if (code != 0) { |
---|
254 | printf(";%s\n", error_message(code)); |
---|
255 | return; |
---|
256 | } |
---|
257 | |
---|
258 | if ((fd = open(output_fn, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0) { |
---|
259 | printf("; Can't open %s: %s\n", output_fn, error_message(errno)); |
---|
260 | return; |
---|
261 | } |
---|
262 | tf = unix_tfile(fd); |
---|
263 | |
---|
264 | dsc_get_trn_info2(&nb,trn_num,&tinfo,&code); |
---|
265 | if (code != 0) { |
---|
266 | printf(";%s\n", error_message(code)); |
---|
267 | dsc_destroy_name_blk(&nb); |
---|
268 | return; |
---|
269 | } |
---|
270 | |
---|
271 | if (tinfo.num_lines != 1) |
---|
272 | plural = "s"; |
---|
273 | else |
---|
274 | plural = ""; |
---|
275 | |
---|
276 | |
---|
277 | if (tinfo.subject [0] == '\0') |
---|
278 | tinfo.num_lines--; |
---|
279 | |
---|
280 | (void) sprintf (line, "[%04d]%c %s %s %s (%d line%s)\n", |
---|
281 | tinfo.current, tinfo.flags & TRN_FLAG1 ? 'F' : ' ', |
---|
282 | tinfo.author, mtg_name, |
---|
283 | short_time (&tinfo.date_entered), |
---|
284 | tinfo.num_lines, plural); |
---|
285 | twrite (tf, line, strlen (line), &code); |
---|
286 | if (tinfo.subject [0] != '\0') { |
---|
287 | twrite (tf, "Subject: ", 9, &code); |
---|
288 | twrite (tf, tinfo.subject, strlen (tinfo.subject), &code); |
---|
289 | twrite (tf, "\n", 1, &code); |
---|
290 | } |
---|
291 | |
---|
292 | dsc_get_trn(&nb, trn_num, tf, &code); |
---|
293 | if (code != 0) { |
---|
294 | printf(";%s\n", error_message(code)); |
---|
295 | dsc_destroy_name_blk(&nb); |
---|
296 | return; |
---|
297 | } |
---|
298 | |
---|
299 | if (tinfo.pref == 0 && tinfo.nref == 0) |
---|
300 | (void) sprintf (line, "--[%04d]--\n", tinfo.current); |
---|
301 | else if (tinfo.pref == 0) |
---|
302 | (void) sprintf (line, "--[%04d]-- (nref = [%04d])\n", |
---|
303 | tinfo.current, tinfo.nref); |
---|
304 | else if (tinfo.nref == 0) |
---|
305 | (void) sprintf (line, "--[%04d]-- (pref = [%04d])\n", |
---|
306 | tinfo.current, tinfo.pref); |
---|
307 | else |
---|
308 | (void) sprintf (line, |
---|
309 | "--[%04d]-- (pref = [%04d], nref = [%04d])\n", |
---|
310 | tinfo.current, tinfo.pref, tinfo.nref); |
---|
311 | twrite (tf, line, strlen (line), &code); |
---|
312 | |
---|
313 | tclose(tf, &code); |
---|
314 | (void) close(fd); |
---|
315 | if (code != 0) { |
---|
316 | printf(";%s\n", error_message(code)); |
---|
317 | dsc_destroy_name_blk(&nb); |
---|
318 | return; |
---|
319 | } |
---|
320 | |
---|
321 | tinfo.subject = do_quote(tinfo.subject); |
---|
322 | printf("(%d %d %d %d %d %d %d %d \"%s\" %d %d \"%s\" \"%s\" %d)\n", |
---|
323 | tinfo.current, |
---|
324 | tinfo.prev, |
---|
325 | tinfo.next, |
---|
326 | tinfo.pref, |
---|
327 | tinfo.nref, |
---|
328 | tinfo.fref, |
---|
329 | tinfo.lref, |
---|
330 | tinfo.chain_index, |
---|
331 | short_time(&tinfo.date_entered), |
---|
332 | tinfo.num_lines, |
---|
333 | tinfo.num_chars, |
---|
334 | tinfo.subject, |
---|
335 | tinfo.author, |
---|
336 | tinfo.flags); |
---|
337 | |
---|
338 | dsc_destroy_name_blk(&nb); |
---|
339 | dsc_destroy_trn_info(&tinfo); |
---|
340 | } |
---|
341 | |
---|
342 | do_grt(args) |
---|
343 | char *args; |
---|
344 | { |
---|
345 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
346 | trn_nums trn_num; |
---|
347 | name_blk nb; |
---|
348 | trn_info tinfo; |
---|
349 | tfile tf; |
---|
350 | int code; |
---|
351 | |
---|
352 | /* First, we get the transaction number */ |
---|
353 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
354 | printf("; Missing trn number\n"); |
---|
355 | return; |
---|
356 | } |
---|
357 | |
---|
358 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
359 | printf("; Missing meeting name\n"); |
---|
360 | return; |
---|
361 | } |
---|
362 | |
---|
363 | trn_num = atoi(trn_string); |
---|
364 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
365 | if (code != 0) { |
---|
366 | printf(";%s\n", error_message(code)); |
---|
367 | return; |
---|
368 | } |
---|
369 | |
---|
370 | dsc_get_trn_info(&nb,trn_num,&tinfo,&code); |
---|
371 | if (code != 0) { |
---|
372 | printf(";%s\n", error_message(code)); |
---|
373 | dsc_destroy_name_blk(&nb); |
---|
374 | return; |
---|
375 | } |
---|
376 | |
---|
377 | printf("(%d)\n", |
---|
378 | tinfo.num_chars); |
---|
379 | |
---|
380 | tf = stdout_tf; |
---|
381 | dsc_get_trn(&nb, trn_num, tf, &code); |
---|
382 | |
---|
383 | dsc_destroy_name_blk(&nb); |
---|
384 | dsc_destroy_trn_info(&tinfo); |
---|
385 | } |
---|
386 | |
---|
387 | do_gml(args) |
---|
388 | char *args; |
---|
389 | { |
---|
390 | name_blk *set,*nbp; |
---|
391 | char **aliases; |
---|
392 | int code, n_matches, i; |
---|
393 | int first; |
---|
394 | bool updated; |
---|
395 | |
---|
396 | dsc_expand_mtg_set(user_id, "*", &set, &n_matches, &code); |
---|
397 | if (code) { |
---|
398 | printf(";%s", error_message(code)); |
---|
399 | return; |
---|
400 | } |
---|
401 | |
---|
402 | set_warning_hook(bit_bucket); |
---|
403 | putchar('('); |
---|
404 | |
---|
405 | first = TRUE; |
---|
406 | for (i = 0; i < n_matches; i++) { |
---|
407 | nbp = &set[i]; |
---|
408 | |
---|
409 | dsc_updated_mtg(nbp, &updated, &code); |
---|
410 | if (code != 0) { /* meeting lost trns */ |
---|
411 | updated = TRUE; |
---|
412 | code = 0; |
---|
413 | } |
---|
414 | |
---|
415 | if (first) { |
---|
416 | first = FALSE; |
---|
417 | } else |
---|
418 | putchar(' '); |
---|
419 | |
---|
420 | printf("(%d", updated ? 1 : 0); |
---|
421 | aliases = nbp -> aliases; |
---|
422 | while (*aliases) { |
---|
423 | printf(" \"%s\"", *(aliases++)); |
---|
424 | } |
---|
425 | |
---|
426 | printf(")"); |
---|
427 | } |
---|
428 | |
---|
429 | printf(")\n"); |
---|
430 | dsc_destroy_mtg_set(set, n_matches); |
---|
431 | } |
---|
432 | |
---|
433 | do_gcm(args) |
---|
434 | char *args; |
---|
435 | { |
---|
436 | name_blk *set,*nbp; |
---|
437 | char **aliases; |
---|
438 | int code, n_matches, i; |
---|
439 | int first; |
---|
440 | bool updated; |
---|
441 | |
---|
442 | dsc_expand_mtg_set(user_id, "*", &set, &n_matches, &code); |
---|
443 | if (code) { |
---|
444 | printf(";%s", error_message(code)); |
---|
445 | return; |
---|
446 | } |
---|
447 | |
---|
448 | set_warning_hook(bit_bucket); |
---|
449 | putchar('('); |
---|
450 | |
---|
451 | first = TRUE; |
---|
452 | for (i = 0; i < n_matches; i++) { |
---|
453 | nbp = &set[i]; |
---|
454 | |
---|
455 | dsc_updated_mtg(nbp, &updated, &code); |
---|
456 | if (code != 0) { /* meeting lost trns */ |
---|
457 | updated = TRUE; |
---|
458 | code = 0; |
---|
459 | } |
---|
460 | |
---|
461 | if (!updated) |
---|
462 | continue; |
---|
463 | |
---|
464 | if (first) { |
---|
465 | first = FALSE; |
---|
466 | } else |
---|
467 | putchar(' '); |
---|
468 | |
---|
469 | printf("(%d", updated ? 1 : 0); |
---|
470 | aliases = nbp -> aliases; |
---|
471 | while (*aliases) { |
---|
472 | printf(" \"%s\"", *(aliases++)); |
---|
473 | } |
---|
474 | |
---|
475 | printf(")"); |
---|
476 | } |
---|
477 | |
---|
478 | printf(")\n"); |
---|
479 | dsc_destroy_mtg_set(set, n_matches); |
---|
480 | } |
---|
481 | |
---|
482 | do_ss(args) |
---|
483 | char *args; |
---|
484 | { |
---|
485 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
486 | trn_nums trn_num; |
---|
487 | name_blk nb; |
---|
488 | int code; |
---|
489 | |
---|
490 | /* First, we get the transaction number */ |
---|
491 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
492 | printf("; Missing trn number\n"); |
---|
493 | return; |
---|
494 | } |
---|
495 | |
---|
496 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
497 | printf("; Missing meeting name\n"); |
---|
498 | return; |
---|
499 | } |
---|
500 | |
---|
501 | trn_num = atoi(trn_string); |
---|
502 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
503 | if (code != 0) { |
---|
504 | printf(";%s\n", error_message(code)); |
---|
505 | return; |
---|
506 | } |
---|
507 | |
---|
508 | nb.last = trn_num; |
---|
509 | dsc_update_mtg_set (user_id, &nb, 1, &code); |
---|
510 | if (code != 0) { |
---|
511 | printf(";%s\n", error_message(code)); |
---|
512 | dsc_destroy_name_blk(&nb); |
---|
513 | return; |
---|
514 | } |
---|
515 | |
---|
516 | dsc_destroy_name_blk(&nb); |
---|
517 | } |
---|
518 | |
---|
519 | do_at(args) |
---|
520 | char *args; |
---|
521 | { |
---|
522 | char *cp = args, *mtg_name, *file_name, delim, *trn_string; |
---|
523 | trn_nums trn_num,new_trn_num; |
---|
524 | name_blk nb; |
---|
525 | char subject[1000]; |
---|
526 | tfile tf; |
---|
527 | int fd, code; |
---|
528 | |
---|
529 | /* First, we get the transaction number */ |
---|
530 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
531 | printf("; Missing trn number\n"); |
---|
532 | return; |
---|
533 | } |
---|
534 | |
---|
535 | if (get_word(&cp, &file_name, " ", &delim) < 0) { |
---|
536 | printf(";Missing file name\n"); |
---|
537 | return; |
---|
538 | } |
---|
539 | |
---|
540 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
541 | printf(";Missing meeting name\n"); |
---|
542 | return; |
---|
543 | } |
---|
544 | |
---|
545 | trn_num = atoi(trn_string); |
---|
546 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
547 | if (code != 0) { |
---|
548 | printf(";%s\n", error_message(code)); |
---|
549 | return; |
---|
550 | } |
---|
551 | |
---|
552 | /* Read the subject */ |
---|
553 | if (gets(subject) == NULL) { |
---|
554 | printf(";End of file\n"); |
---|
555 | exit(1); |
---|
556 | } |
---|
557 | |
---|
558 | fd = open(file_name, O_RDONLY, 0); |
---|
559 | if (fd < 0) { |
---|
560 | printf(";Can't read transaction. %s\n", error_message(errno)); |
---|
561 | goto punt; |
---|
562 | } |
---|
563 | |
---|
564 | tf = unix_tfile(fd); |
---|
565 | dsc_add_trn(&nb, tf, subject, trn_num, &new_trn_num, &code); |
---|
566 | if (code != 0) { |
---|
567 | printf(";%s\n", error_message(code)); |
---|
568 | } else { |
---|
569 | printf("(%d)\n", new_trn_num); |
---|
570 | } |
---|
571 | |
---|
572 | close(fd); |
---|
573 | punt: |
---|
574 | dsc_destroy_name_blk(&nb); |
---|
575 | } |
---|
576 | |
---|
577 | do_nut(args) |
---|
578 | char *args; |
---|
579 | { |
---|
580 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
581 | trn_nums trn_num,cur_trn; |
---|
582 | name_blk nb; |
---|
583 | mtg_info m_info; |
---|
584 | trn_info t_info; |
---|
585 | int code,i; |
---|
586 | |
---|
587 | /* First, we get the transaction number */ |
---|
588 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
589 | printf("; Missing trn number\n"); |
---|
590 | return; |
---|
591 | } |
---|
592 | |
---|
593 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
594 | printf("; Missing meeting name\n"); |
---|
595 | return; |
---|
596 | } |
---|
597 | |
---|
598 | trn_num = atoi(trn_string); |
---|
599 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
600 | if (code != 0) { |
---|
601 | printf(";%s\n", error_message(code)); |
---|
602 | return; |
---|
603 | } |
---|
604 | |
---|
605 | dsc_get_mtg_info (&nb, &m_info, &code); |
---|
606 | if (code != 0) { |
---|
607 | printf(";%s\n", error_message(code)); |
---|
608 | return; |
---|
609 | } |
---|
610 | |
---|
611 | if (trn_num < m_info.first) { |
---|
612 | printf("(%d)\n", m_info.first); |
---|
613 | goto done2; |
---|
614 | } |
---|
615 | if (trn_num > m_info.last) { |
---|
616 | printf("(0)\n"); |
---|
617 | goto done2; |
---|
618 | } |
---|
619 | |
---|
620 | /* Now we try to find the next transaction. If the transaction |
---|
621 | is not deleted, we can do this in one step */ |
---|
622 | dsc_get_trn_info(&nb,trn_num,&t_info,&code); |
---|
623 | if (code == 0) { |
---|
624 | printf("(%d)\n", t_info.next); |
---|
625 | goto done; |
---|
626 | } |
---|
627 | |
---|
628 | /* Hmm. Deleted transaction. Try the next five transactions, hoping |
---|
629 | to get a non-deleted one */ |
---|
630 | for (i = 1; i <= 5; i++) { |
---|
631 | dsc_get_trn_info(&nb,trn_num+i,&t_info,&code); |
---|
632 | if (code == 0) { |
---|
633 | printf("(%d)\n", t_info.current); |
---|
634 | goto done; |
---|
635 | } |
---|
636 | } |
---|
637 | |
---|
638 | /* Hmmm. Try the first 5 transactions in the meeting, in case we |
---|
639 | hit a big gap after transaction [0001]. */ |
---|
640 | cur_trn = m_info.first; |
---|
641 | for (i = 0; i < 5; i++) { |
---|
642 | dsc_get_trn_info(&nb, cur_trn, &t_info, &code); |
---|
643 | if (code != 0) { |
---|
644 | printf(";%s\n", error_message(code)); |
---|
645 | goto done2; |
---|
646 | } |
---|
647 | if (t_info.next > trn_num) { |
---|
648 | printf("(%d)\n", t_info.next); |
---|
649 | goto done; |
---|
650 | } |
---|
651 | cur_trn = t_info.next; |
---|
652 | dsc_destroy_trn_info(&t_info); |
---|
653 | } |
---|
654 | |
---|
655 | /* Ok. We bite the bullet and loop until we can find something. */ |
---|
656 | code = DELETED_TRN; |
---|
657 | trn_num += 6; |
---|
658 | while (code == DELETED_TRN) { |
---|
659 | dsc_get_trn_info (&nb, trn_num, &t_info, &code); |
---|
660 | if (code == 0) { |
---|
661 | printf("(%d)\n", trn_num); |
---|
662 | goto done; |
---|
663 | } else if (code == DELETED_TRN) |
---|
664 | trn_num++; |
---|
665 | else { |
---|
666 | printf(";%s\n", error_message(code)); |
---|
667 | goto done2; |
---|
668 | } |
---|
669 | } |
---|
670 | |
---|
671 | done: |
---|
672 | dsc_destroy_trn_info(&t_info); |
---|
673 | done2: |
---|
674 | dsc_destroy_name_blk(&nb); |
---|
675 | dsc_destroy_mtg_info(&m_info); |
---|
676 | } |
---|
677 | |
---|
678 | do_grtn(args) |
---|
679 | char *args; |
---|
680 | { |
---|
681 | char *cp = args, *mtg_name, delim; |
---|
682 | name_blk nb; |
---|
683 | mtg_info m_info; |
---|
684 | trn_info2 t_info; |
---|
685 | int code, rnd_num, i; |
---|
686 | int randrp_retry = 15; |
---|
687 | struct timeval tv; |
---|
688 | int pid = getpid(); |
---|
689 | int active_transactions, rnd_trn; |
---|
690 | |
---|
691 | /* First, we get the meeting name */ |
---|
692 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
693 | printf("; Missing meeting name\n"); |
---|
694 | return; |
---|
695 | } |
---|
696 | |
---|
697 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
698 | if (code != 0) { |
---|
699 | printf(";%s\n", error_message(code)); |
---|
700 | return; |
---|
701 | } |
---|
702 | |
---|
703 | dsc_get_mtg_info(&nb,&m_info,&code); |
---|
704 | if (code != 0) { |
---|
705 | printf(";%s\n", error_message(code)); |
---|
706 | dsc_destroy_name_blk(&nb); |
---|
707 | return; |
---|
708 | } |
---|
709 | |
---|
710 | gettimeofday(&tv, (struct timezone *) NULL); |
---|
711 | srandom(tv.tv_sec ^ tv.tv_usec ^ pid); |
---|
712 | |
---|
713 | for (i=1;i<=randrp_retry;i++) { |
---|
714 | do { |
---|
715 | rnd_num = random(); |
---|
716 | active_transactions = (m_info.last - m_info.first); |
---|
717 | if (active_transactions != 0) { |
---|
718 | rnd_trn = (m_info.first + |
---|
719 | (rnd_num % active_transactions)); |
---|
720 | } else { |
---|
721 | rnd_trn = m_info.first; |
---|
722 | } |
---|
723 | dsc_get_trn_info2(&nb, rnd_trn, &t_info, &code); |
---|
724 | } while (code != 0); |
---|
725 | if (!t_info.pref) break; |
---|
726 | } |
---|
727 | |
---|
728 | t_info.subject = do_quote(t_info.subject); |
---|
729 | printf("(%d %d %d %d %d %d %d %d \"%s\" %d %d \"%s\" \"%s\" %d)\n", |
---|
730 | t_info.current, |
---|
731 | t_info.prev, |
---|
732 | t_info.next, |
---|
733 | t_info.pref, |
---|
734 | t_info.nref, |
---|
735 | t_info.fref, |
---|
736 | t_info.lref, |
---|
737 | t_info.chain_index, |
---|
738 | short_time(&t_info.date_entered), |
---|
739 | t_info.num_lines, |
---|
740 | t_info.num_chars, |
---|
741 | t_info.subject, |
---|
742 | t_info.author, |
---|
743 | t_info.flags); |
---|
744 | |
---|
745 | dsc_destroy_name_blk(&nb); |
---|
746 | dsc_destroy_mtg_info(&m_info); |
---|
747 | } |
---|
748 | |
---|
749 | do_sfl(args) |
---|
750 | char *args; |
---|
751 | { |
---|
752 | char *cp = args, *mtg_name, delim, *trn_string, *flags_string; |
---|
753 | trn_nums trn_num; |
---|
754 | int flags; |
---|
755 | name_blk nb; |
---|
756 | int code; |
---|
757 | |
---|
758 | /* First, we get flag we should be setting */ |
---|
759 | if (get_word(&cp, &flags_string, " ", &delim) < 0) { |
---|
760 | printf("; Missing flags entry\n"); |
---|
761 | return; |
---|
762 | } |
---|
763 | |
---|
764 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
765 | printf("; Missing trn number\n"); |
---|
766 | return; |
---|
767 | } |
---|
768 | |
---|
769 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
770 | printf("; Missing meeting name\n"); |
---|
771 | return; |
---|
772 | } |
---|
773 | trn_num = atoi(trn_string); |
---|
774 | flags = atoi(flags_string); |
---|
775 | |
---|
776 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
777 | if (code != 0) { |
---|
778 | printf(";%s\n", error_message(code)); |
---|
779 | return; |
---|
780 | } |
---|
781 | |
---|
782 | dsc_set_trn_flags(&nb, trn_num, flags, &code); |
---|
783 | |
---|
784 | dsc_destroy_name_blk(&nb); |
---|
785 | |
---|
786 | if (code != 0) { |
---|
787 | printf(";%s\n", error_message(code)); |
---|
788 | return; |
---|
789 | } |
---|
790 | |
---|
791 | printf("()\n"); |
---|
792 | } |
---|
793 | |
---|
794 | do_am(args) |
---|
795 | char *args; |
---|
796 | { |
---|
797 | char *cp = args, delim, *host, *path; |
---|
798 | name_blk nb, temp_nb; |
---|
799 | int code,j; |
---|
800 | |
---|
801 | if (get_word(&cp, &host, " ", &delim) < 0) { |
---|
802 | printf("; Missing hostname\n"); |
---|
803 | return; |
---|
804 | } |
---|
805 | |
---|
806 | if (get_word(&cp, &path, ")", &delim) < 0) { |
---|
807 | printf("; Missing pathname\n"); |
---|
808 | return; |
---|
809 | } |
---|
810 | hostpath_to_nb (host, path, &nb, &code); |
---|
811 | if (code != 0) { |
---|
812 | printf(";%s\n", error_message(code)); |
---|
813 | return; |
---|
814 | } |
---|
815 | for (j = 0; nb.aliases[j] != NULL; j++) { |
---|
816 | dsc_get_mtg (user_id, nb.aliases[j], &temp_nb, &code); |
---|
817 | if (code == 0) { |
---|
818 | printf("; Meeting %s already exists.\n", nb.aliases[j]); |
---|
819 | dsc_destroy_name_blk(&nb); |
---|
820 | return; |
---|
821 | } |
---|
822 | } |
---|
823 | dsc_update_mtg_set(user_id, &nb, 1, &code); |
---|
824 | dsc_destroy_name_blk(&nb); |
---|
825 | if (code) { |
---|
826 | printf(";%s\n", error_message(code)); |
---|
827 | return; |
---|
828 | } |
---|
829 | |
---|
830 | printf("()\n"); |
---|
831 | } |
---|
832 | |
---|
833 | do_dm(args) |
---|
834 | char *args; |
---|
835 | { |
---|
836 | char *cp = args, delim, *mtg_name; |
---|
837 | name_blk nb; |
---|
838 | int code; |
---|
839 | |
---|
840 | /* |
---|
841 | * Parse out the meeting name |
---|
842 | */ |
---|
843 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
844 | printf("; Missing meeting name\n"); |
---|
845 | return; |
---|
846 | } |
---|
847 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
848 | if (code != 0) { |
---|
849 | printf(";%s\n", error_message(code)); |
---|
850 | return; |
---|
851 | } |
---|
852 | |
---|
853 | nb.status |= DSC_ST_DELETED; |
---|
854 | dsc_update_mtg_set(user_id, &nb, 1, &code); |
---|
855 | dsc_destroy_name_blk(&nb); |
---|
856 | if (code != 0) { |
---|
857 | printf(";%s\n", error_message(code)); |
---|
858 | return; |
---|
859 | } |
---|
860 | printf("()\n"); |
---|
861 | } |
---|
862 | |
---|
863 | do_gpv(args) |
---|
864 | char *args; |
---|
865 | { |
---|
866 | printf("(%s)\n", PROTOCOL_VERSION); |
---|
867 | } |
---|
868 | |
---|
869 | /* |
---|
870 | * Utility subroutines go here... |
---|
871 | */ |
---|
872 | |
---|
873 | hostpath_to_nb (host, path, nbp, code) |
---|
874 | char *host, *path; |
---|
875 | name_blk *nbp; |
---|
876 | int *code; |
---|
877 | { |
---|
878 | struct hostent *hp; |
---|
879 | mtg_info m_info; |
---|
880 | char *short_name; |
---|
881 | |
---|
882 | nbp -> hostname = nbp -> pathname = nbp -> user_id = nbp -> spare = NULL; |
---|
883 | nbp -> date_attended = nbp -> last = nbp -> status = 0; |
---|
884 | |
---|
885 | hp = gethostbyname (host); |
---|
886 | if (hp != NULL) |
---|
887 | host = hp -> h_name; /* use canonical if possible */ |
---|
888 | nbp -> hostname = malloc((unsigned)strlen(host)+1); |
---|
889 | strcpy(nbp -> hostname,host); |
---|
890 | nbp -> pathname = malloc((unsigned)strlen(path)+1); |
---|
891 | strcpy(nbp -> pathname, path); |
---|
892 | nbp -> user_id = malloc((unsigned)strlen(user_id)+1); |
---|
893 | strcpy(nbp -> user_id, user_id); |
---|
894 | nbp -> aliases = (char **)NULL; |
---|
895 | dsc_get_mtg_info(nbp, &m_info, code); |
---|
896 | if (*code) { |
---|
897 | if (*code == NO_ACCESS) { |
---|
898 | *code = CANT_ATTEND; /* friendlier error msg */ |
---|
899 | } |
---|
900 | goto punt; |
---|
901 | } |
---|
902 | short_name = strrchr(path,'/'); |
---|
903 | if (!short_name) |
---|
904 | short_name = strrchr(path,':'); |
---|
905 | nbp -> aliases = (char **)calloc(3, sizeof(char *)); |
---|
906 | nbp -> aliases[0] = malloc(strlen(m_info.long_name)+1); |
---|
907 | strcpy(nbp -> aliases[0], m_info.long_name); |
---|
908 | nbp -> aliases[1] = malloc(strlen(short_name)); |
---|
909 | strcpy(nbp -> aliases[1],short_name+1); |
---|
910 | nbp -> aliases[2] = (char *)NULL; |
---|
911 | *(nbp->spare = malloc(1)) = '\0'; |
---|
912 | free(m_info.location); |
---|
913 | free(m_info.chairman); |
---|
914 | free(m_info.long_name); |
---|
915 | |
---|
916 | return; |
---|
917 | |
---|
918 | punt: |
---|
919 | dsc_destroy_name_blk (nbp); |
---|
920 | return; |
---|
921 | } |
---|