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_mtg.c -- Routines to implement the various lisp requests related |
---|
11 | * to meeting manipulation. |
---|
12 | * |
---|
13 | */ |
---|
14 | |
---|
15 | #include <stdio.h> |
---|
16 | #include <sys/file.h> |
---|
17 | #include <signal.h> |
---|
18 | #include <string.h> |
---|
19 | #include <sys/wait.h> |
---|
20 | #include <ctype.h> |
---|
21 | #include <sys/time.h> |
---|
22 | #include <netdb.h> |
---|
23 | #include "errno.h" |
---|
24 | #include "rpc_et.h" |
---|
25 | #include "edsc.h" |
---|
26 | |
---|
27 | name_blk *meetings_list = NULL; |
---|
28 | int meetings_list_count; |
---|
29 | |
---|
30 | do_gmi(args) |
---|
31 | char *args; |
---|
32 | { |
---|
33 | char *cp = args, *mtg_name, delim; |
---|
34 | name_blk nb; |
---|
35 | mtg_info m_info; |
---|
36 | char mtime[30]; |
---|
37 | int code; |
---|
38 | struct cache_meeting *curr; |
---|
39 | |
---|
40 | /* First, we get the meeting name */ |
---|
41 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
42 | printf(";Missing meeting name\n"); |
---|
43 | return; |
---|
44 | } |
---|
45 | |
---|
46 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
47 | if (code != 0) { |
---|
48 | printf(";%s\n", error_message(code)); |
---|
49 | return; |
---|
50 | } |
---|
51 | |
---|
52 | #ifdef EDSC_CACHE |
---|
53 | if (curr = search_cache_meetings(&nb)) { |
---|
54 | /* |
---|
55 | * The meeting is already cached, but we'll refresh the cache |
---|
56 | * information because we don't know if it's up to date. |
---|
57 | */ |
---|
58 | dsc_get_mtg_info(&nb,&m_info,&code); |
---|
59 | if (code != 0) { |
---|
60 | while (code == MTG_MOVED) |
---|
61 | handle_moved_meeting(&nb, &m_info, &code, |
---|
62 | nb.aliases[0], TRUE); |
---|
63 | if (code != 0) { |
---|
64 | printf(";%s\n", error_message(code)); |
---|
65 | dsc_destroy_name_blk(&nb); |
---|
66 | return; |
---|
67 | } |
---|
68 | } |
---|
69 | if (curr->m_info.last != m_info.last) |
---|
70 | cache_it(&nb, curr->m_info.last); |
---|
71 | dsc_destroy_mtg_info(&curr->m_info); |
---|
72 | curr->m_info = m_info; |
---|
73 | curr->meeting_code = code; |
---|
74 | } else { |
---|
75 | /* |
---|
76 | * The meeting isn't cached yet; just pull it into the |
---|
77 | * cache and we'll use the meeting information from there. |
---|
78 | */ |
---|
79 | curr = get_cache_meeting(&nb); |
---|
80 | curr->ref_count--; |
---|
81 | m_info = curr->m_info; |
---|
82 | if (curr->meeting_code != 0) { |
---|
83 | printf(";%s\n", error_message(curr->meeting_code)); |
---|
84 | dsc_destroy_name_blk(&nb); |
---|
85 | return; |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | #else |
---|
90 | dsc_get_mtg_info(&nb,&m_info,&code); |
---|
91 | if (code != 0) { |
---|
92 | while (code == MTG_MOVED) |
---|
93 | handle_moved_meeting(&nb, &m_info, &code, |
---|
94 | nb.aliases[0], TRUE); |
---|
95 | if (code != 0) { |
---|
96 | printf(";%s\n", error_message(code)); |
---|
97 | dsc_destroy_name_blk(&nb); |
---|
98 | return; |
---|
99 | } |
---|
100 | } |
---|
101 | #endif |
---|
102 | |
---|
103 | strcpy(mtime, short_time(&m_info.date_created)); |
---|
104 | printf("(\"%s\" \"%s\" \"%s\" %d %d %d %d \"%s\" \"%s\" %d \"%s\" %d)\n", |
---|
105 | m_info.location, |
---|
106 | m_info.long_name, |
---|
107 | m_info.chairman, |
---|
108 | m_info.first, |
---|
109 | m_info.last, |
---|
110 | m_info.lowest, |
---|
111 | m_info.highest, |
---|
112 | mtime, |
---|
113 | short_time(&m_info.date_modified), |
---|
114 | m_info.public_flag, |
---|
115 | m_info.access_modes, |
---|
116 | nb.last); |
---|
117 | |
---|
118 | dsc_destroy_name_blk(&nb); |
---|
119 | #ifndef EDSC_CACHE |
---|
120 | dsc_destroy_mtg_info(&m_info); |
---|
121 | #endif |
---|
122 | } |
---|
123 | |
---|
124 | handle_moved_meeting(nb, m_info, code, name, update) |
---|
125 | name_blk *nb; |
---|
126 | mtg_info *m_info; |
---|
127 | int *code; |
---|
128 | char *name; |
---|
129 | int update; |
---|
130 | { |
---|
131 | /* Meeting has moved. In this case, dsc_public.m_info.long_name |
---|
132 | * should contain the hostname/pathname for the meeting. |
---|
133 | * We should update our information to reflect this change. |
---|
134 | */ |
---|
135 | |
---|
136 | char *old_hostname, *old_pathname, *new_host, *new_path; |
---|
137 | int dummy; |
---|
138 | |
---|
139 | old_hostname = nb->hostname; |
---|
140 | old_pathname = nb->pathname; |
---|
141 | |
---|
142 | nb->hostname = new_host = malloc(strlen(m_info->long_name)+1); |
---|
143 | strcpy(nb->hostname, m_info->long_name); |
---|
144 | |
---|
145 | nb->pathname = new_path = malloc(strlen(m_info->location)+1); |
---|
146 | strcpy(nb->pathname, m_info->location); |
---|
147 | |
---|
148 | dsc_get_mtg_info(nb, m_info, code); |
---|
149 | if (*code != 0 && *code != MTG_MOVED) { |
---|
150 | printf(";Error checking moved meeting %s", name); |
---|
151 | } else { |
---|
152 | printf("-Warning: %s moved to %s:%s\n", |
---|
153 | name, new_host, new_path); |
---|
154 | if (update) { |
---|
155 | /* Delete old meeting */ |
---|
156 | nb->hostname = old_hostname; |
---|
157 | nb->pathname = old_pathname; |
---|
158 | nb->status |= DSC_ST_DELETED; |
---|
159 | dsc_update_mtg_set(user_id, nb, 1, &dummy); |
---|
160 | nb->status &= ~(DSC_ST_DELETED); |
---|
161 | free(nb->hostname); |
---|
162 | nb->hostname = new_host; |
---|
163 | free(nb->pathname); |
---|
164 | nb->pathname = new_path; |
---|
165 | dsc_update_mtg_set(user_id, nb, 1, &dummy); |
---|
166 | } else { |
---|
167 | free(old_hostname); |
---|
168 | free(old_pathname); |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | #define MAX_ERR_LIST 20 |
---|
175 | |
---|
176 | do_gml(args) |
---|
177 | char *args; |
---|
178 | { |
---|
179 | name_blk *nbp; |
---|
180 | char **aliases; |
---|
181 | int code, i; |
---|
182 | int first; |
---|
183 | bool updated; |
---|
184 | |
---|
185 | if (meetings_list) |
---|
186 | dsc_destroy_mtg_set(meetings_list, meetings_list_count); |
---|
187 | dsc_expand_mtg_set(user_id, "*", &meetings_list, &meetings_list_count, |
---|
188 | &code); |
---|
189 | if (code) { |
---|
190 | printf(";%s\n", error_message(code)); |
---|
191 | return; |
---|
192 | } |
---|
193 | |
---|
194 | set_warning_hook(bit_bucket); |
---|
195 | putchar('('); |
---|
196 | |
---|
197 | first = TRUE; |
---|
198 | for (i = 0; i < meetings_list_count; i++) { |
---|
199 | nbp = &meetings_list[i]; |
---|
200 | |
---|
201 | dsc_updated_mtg(nbp, &updated, &code); |
---|
202 | if (first) { |
---|
203 | first = FALSE; |
---|
204 | } else |
---|
205 | putchar(' '); |
---|
206 | |
---|
207 | if (code == NO_SUCH_TRN) { |
---|
208 | printf("(1"); |
---|
209 | } else if (code) { |
---|
210 | if ((code == RPC_HOST_UNKNOWN) || (code == ETIMEDOUT) || |
---|
211 | (code == ECONNREFUSED) || (code == ECONNRESET) || |
---|
212 | (code == ENETDOWN) || (code == ENETUNREACH)) |
---|
213 | printf("(\"%s: %s\"", error_message(code), |
---|
214 | nbp->hostname); |
---|
215 | else |
---|
216 | printf("(\"%s\"", error_message(code)); |
---|
217 | code = 0; |
---|
218 | } else |
---|
219 | printf("(%d", updated ? 1 : 0); |
---|
220 | aliases = nbp -> aliases; |
---|
221 | while (*aliases) { |
---|
222 | printf(" \"%s\"", *(aliases++)); |
---|
223 | } |
---|
224 | |
---|
225 | printf(")"); |
---|
226 | } |
---|
227 | |
---|
228 | printf(")\n"); |
---|
229 | } |
---|
230 | |
---|
231 | do_ss(args) |
---|
232 | char *args; |
---|
233 | { |
---|
234 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
235 | trn_nums trn_num; |
---|
236 | name_blk nb; |
---|
237 | int code; |
---|
238 | |
---|
239 | /* First, we get the transaction number */ |
---|
240 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
241 | printf(";Missing trn number\n"); |
---|
242 | return; |
---|
243 | } |
---|
244 | |
---|
245 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
246 | printf(";Missing meeting name\n"); |
---|
247 | return; |
---|
248 | } |
---|
249 | |
---|
250 | trn_num = atoi(trn_string); |
---|
251 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
252 | if (code != 0) { |
---|
253 | printf(";%s\n", error_message(code)); |
---|
254 | return; |
---|
255 | } |
---|
256 | |
---|
257 | nb.last = trn_num; |
---|
258 | dsc_update_mtg_set (user_id, &nb, 1, &code); |
---|
259 | if (code != 0) { |
---|
260 | printf(";%s\n", error_message(code)); |
---|
261 | dsc_destroy_name_blk(&nb); |
---|
262 | return; |
---|
263 | } |
---|
264 | dsc_destroy_name_blk(&nb); |
---|
265 | printf("()\n"); |
---|
266 | } |
---|
267 | |
---|
268 | /* |
---|
269 | * Get meeting number |
---|
270 | */ |
---|
271 | do_gmn(args) |
---|
272 | char *args; |
---|
273 | { |
---|
274 | char *cp = args, *mtg_name, delim; |
---|
275 | |
---|
276 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
277 | printf(";Missing meeting name\n"); |
---|
278 | return; |
---|
279 | } |
---|
280 | |
---|
281 | } |
---|
282 | |
---|
283 | do_am(args) |
---|
284 | char *args; |
---|
285 | { |
---|
286 | char *cp = args, delim, *host, *path; |
---|
287 | char **aliases; |
---|
288 | name_blk nb, temp_nb; |
---|
289 | int code,j; |
---|
290 | |
---|
291 | if (get_word(&cp, &host, " ", &delim) < 0) { |
---|
292 | printf(";Missing hostname\n"); |
---|
293 | return; |
---|
294 | } |
---|
295 | |
---|
296 | if (get_word(&cp, &path, ")", &delim) < 0) { |
---|
297 | printf(";Missing pathname\n"); |
---|
298 | return; |
---|
299 | } |
---|
300 | hostpath_to_nb (host, path, &nb, &code); |
---|
301 | if (code != 0) { |
---|
302 | printf(";%s\n", error_message(code)); |
---|
303 | return; |
---|
304 | } |
---|
305 | for (j = 0; nb.aliases[j] != NULL; j++) { |
---|
306 | dsc_get_mtg (user_id, nb.aliases[j], &temp_nb, &code); |
---|
307 | if (code == 0) { |
---|
308 | printf(";Meeting %s already exists.\n", nb.aliases[j]); |
---|
309 | dsc_destroy_name_blk(&nb); |
---|
310 | return; |
---|
311 | } |
---|
312 | } |
---|
313 | dsc_update_mtg_set(user_id, &nb, 1, &code); |
---|
314 | if (code) { |
---|
315 | dsc_destroy_name_blk(&nb); |
---|
316 | printf(";%s\n", error_message(code)); |
---|
317 | return; |
---|
318 | } |
---|
319 | |
---|
320 | printf("(1 "); |
---|
321 | aliases = nb.aliases; |
---|
322 | while (*aliases) { |
---|
323 | printf(" \"%s\"", *(aliases++)); |
---|
324 | } |
---|
325 | printf(")\n"); |
---|
326 | dsc_destroy_name_blk(&nb); |
---|
327 | |
---|
328 | /* |
---|
329 | * Update the meetings list. |
---|
330 | */ |
---|
331 | if (meetings_list) |
---|
332 | dsc_destroy_mtg_set(meetings_list, meetings_list_count); |
---|
333 | dsc_expand_mtg_set(user_id, "*", &meetings_list, &meetings_list_count, |
---|
334 | &code); |
---|
335 | if (code) { |
---|
336 | meetings_list = NULL; |
---|
337 | } |
---|
338 | } |
---|
339 | |
---|
340 | do_dm(args) |
---|
341 | char *args; |
---|
342 | { |
---|
343 | char *cp = args, delim, *mtg_name; |
---|
344 | name_blk nb; |
---|
345 | int code; |
---|
346 | |
---|
347 | /* |
---|
348 | * Parse out the meeting name |
---|
349 | */ |
---|
350 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
351 | printf(";Missing meeting name\n"); |
---|
352 | return; |
---|
353 | } |
---|
354 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
355 | if (code != 0) { |
---|
356 | printf(";%s\n", error_message(code)); |
---|
357 | return; |
---|
358 | } |
---|
359 | |
---|
360 | nb.status |= DSC_ST_DELETED; |
---|
361 | dsc_update_mtg_set(user_id, &nb, 1, &code); |
---|
362 | dsc_destroy_name_blk(&nb); |
---|
363 | if (code != 0) { |
---|
364 | printf(";%s\n", error_message(code)); |
---|
365 | return; |
---|
366 | } |
---|
367 | printf("(\"%s\")\n", mtg_name); |
---|
368 | } |
---|
369 | |
---|
370 | /* |
---|
371 | * Utility subroutines go here... |
---|
372 | */ |
---|
373 | |
---|
374 | hostpath_to_nb (host, path, nbp, code) |
---|
375 | char *host, *path; |
---|
376 | name_blk *nbp; |
---|
377 | int *code; |
---|
378 | { |
---|
379 | struct hostent *hp; |
---|
380 | mtg_info m_info; |
---|
381 | char *short_name; |
---|
382 | |
---|
383 | nbp -> hostname = nbp -> pathname = nbp -> user_id = nbp -> spare = NULL; |
---|
384 | nbp -> date_attended = nbp -> last = nbp -> status = 0; |
---|
385 | |
---|
386 | hp = gethostbyname (host); |
---|
387 | if (hp != NULL) |
---|
388 | host = hp -> h_name; /* use canonical if possible */ |
---|
389 | nbp -> hostname = malloc((unsigned)strlen(host)+1); |
---|
390 | strcpy(nbp -> hostname,host); |
---|
391 | nbp -> pathname = malloc((unsigned)strlen(path)+1); |
---|
392 | strcpy(nbp -> pathname, path); |
---|
393 | nbp -> user_id = malloc((unsigned)strlen(user_id)+1); |
---|
394 | strcpy(nbp -> user_id, user_id); |
---|
395 | nbp -> aliases = (char **)NULL; |
---|
396 | dsc_get_mtg_info(nbp, &m_info, code); |
---|
397 | short_name = strrchr(path,'/'); |
---|
398 | if (!short_name) |
---|
399 | short_name = strrchr(path,':'); |
---|
400 | while (*code == MTG_MOVED) |
---|
401 | handle_moved_meeting(nbp, &m_info, code, short_name, FALSE); |
---|
402 | if (*code) { |
---|
403 | if (*code == NO_ACCESS) { |
---|
404 | *code = CANT_ATTEND; /* friendlier error msg */ |
---|
405 | } |
---|
406 | goto punt; |
---|
407 | } |
---|
408 | nbp -> aliases = (char **)calloc(3, sizeof(char *)); |
---|
409 | nbp -> aliases[0] = malloc(strlen(m_info.long_name)+1); |
---|
410 | strcpy(nbp -> aliases[0], m_info.long_name); |
---|
411 | nbp -> aliases[1] = malloc(strlen(short_name)); |
---|
412 | strcpy(nbp -> aliases[1],short_name+1); |
---|
413 | nbp -> aliases[2] = (char *)NULL; |
---|
414 | *(nbp->spare = malloc(1)) = '\0'; |
---|
415 | free(m_info.location); |
---|
416 | free(m_info.chairman); |
---|
417 | free(m_info.long_name); |
---|
418 | |
---|
419 | return; |
---|
420 | |
---|
421 | punt: |
---|
422 | dsc_destroy_name_blk (nbp); |
---|
423 | return; |
---|
424 | } |
---|