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 | * $Source: /afs/dev.mit.edu/source/repository/athena/bin/discuss/mclient/mkds.c,v $ |
---|
10 | * $Header: /afs/dev.mit.edu/source/repository/athena/bin/discuss/mclient/mkds.c,v 1.19 1998-03-24 22:26:23 ghudson Exp $ |
---|
11 | * $Locker: $ |
---|
12 | * |
---|
13 | * $Log: not supported by cvs2svn $ |
---|
14 | * Revision 1.18 1994/03/25 16:55:49 miki |
---|
15 | * replaced rindex with strrchr |
---|
16 | * |
---|
17 | * Revision 1.17 93/05/20 12:54:08 miki |
---|
18 | * ported to Solaris2.1 |
---|
19 | * |
---|
20 | * Revision 1.16 90/12/01 22:41:38 eichin |
---|
21 | * initialized nbsrc.spare, added "%" as a local meeting name |
---|
22 | * |
---|
23 | * Revision 1.15 89/06/03 00:31:10 srz |
---|
24 | * Added standard copyright notice. |
---|
25 | * |
---|
26 | * Revision 1.14 89/06/03 00:27:03 srz |
---|
27 | * Ken's include file changes. |
---|
28 | * |
---|
29 | * Revision 1.13 89/02/25 16:54:47 srz |
---|
30 | * Added declaration of interrupt. |
---|
31 | * |
---|
32 | * Revision 1.12 87/10/24 02:39:01 wesommer |
---|
33 | * Robustified. |
---|
34 | * |
---|
35 | * Allowed to work on non-local meetings. |
---|
36 | * |
---|
37 | * Revision 1.11 87/04/25 10:12:03 spook |
---|
38 | * Changed not to break if announcement of new meeting fails. |
---|
39 | * |
---|
40 | * Revision 1.10 87/04/12 00:13:47 spook |
---|
41 | * Removed unused variables. |
---|
42 | * |
---|
43 | * Revision 1.9 87/04/10 23:18:01 spook |
---|
44 | * Added checks for EOF on input. |
---|
45 | * |
---|
46 | * Revision 1.8 87/04/09 00:12:43 rfrench |
---|
47 | * Fixed small bug in new interface. |
---|
48 | * |
---|
49 | * Revision 1.7 87/04/08 21:40:57 rfrench |
---|
50 | * Changed interface to deal with new dsc_announce_mtg function. |
---|
51 | * |
---|
52 | * Revision 1.5 87/03/22 04:51:58 spook |
---|
53 | * Rewritten for new interfaces. |
---|
54 | * |
---|
55 | * Revision 1.4 87/02/12 21:40:57 spook |
---|
56 | * Rob's changes; removed "../include" stuff, other frobs. |
---|
57 | * |
---|
58 | * Revision 1.3 86/12/05 20:06:12 rfrench |
---|
59 | * General cleanup; default directory /usr/spool/discuss |
---|
60 | * |
---|
61 | * Revision 1.2 86/11/24 20:07:21 rfrench |
---|
62 | * Initial (working) revision |
---|
63 | * |
---|
64 | */ |
---|
65 | |
---|
66 | #ifndef lint |
---|
67 | static char rcsid_mkds_c[] = |
---|
68 | "$Header: /afs/dev.mit.edu/source/repository/athena/bin/discuss/mclient/mkds.c,v 1.19 1998-03-24 22:26:23 ghudson Exp $"; |
---|
69 | #endif lint |
---|
70 | |
---|
71 | #include <discuss/discuss.h> |
---|
72 | #if 0 |
---|
73 | #include "dsc_et.h" |
---|
74 | #include "config.h" |
---|
75 | #include "interface.h" |
---|
76 | #include "rpc.h" |
---|
77 | #include "globals.h" |
---|
78 | #endif |
---|
79 | #include <sys/time.h> |
---|
80 | #include <sys/file.h> |
---|
81 | #include <stdio.h> |
---|
82 | #include <ctype.h> |
---|
83 | #include <string.h> |
---|
84 | #include <netdb.h> |
---|
85 | #include <pwd.h> |
---|
86 | #include <errno.h> |
---|
87 | #ifdef SOLARIS |
---|
88 | #include <fcntl.h> |
---|
89 | #endif |
---|
90 | |
---|
91 | #define cupper(x) (islower(x)?toupper(x):(x)) |
---|
92 | #define clower(x) (isupper(x)?tolower(x):(x)) |
---|
93 | |
---|
94 | char default_dir[] = "/var/spool/discuss"; |
---|
95 | char *whoami; |
---|
96 | int interrupt = 0; |
---|
97 | |
---|
98 | char *getenv(), *malloc(); |
---|
99 | |
---|
100 | char *strtrim(); |
---|
101 | |
---|
102 | main(argc,argv) |
---|
103 | int argc; |
---|
104 | char *argv[]; |
---|
105 | { |
---|
106 | extern tfile unix_tfile(); |
---|
107 | name_blk nbsrc,nbdest; |
---|
108 | char long_name[100],short_name[100],username[50],mtg_path[100]; |
---|
109 | char mtg_host[100]; |
---|
110 | char *default_host; |
---|
111 | char temp_file[64]; |
---|
112 | char ann_mtg[100]; |
---|
113 | int public = 0,error = 1,result,remove=0,delmtg=0; |
---|
114 | int fd,txn_no; |
---|
115 | tfile tf; |
---|
116 | char hostname[256]; |
---|
117 | |
---|
118 | init_dsc_err_tbl(); |
---|
119 | |
---|
120 | nbsrc.user_id = malloc(132); |
---|
121 | |
---|
122 | (void) sprintf(temp_file,"/tmp/mtg%d.%d",getuid(),getpid()); |
---|
123 | |
---|
124 | whoami = strrchr(argv[0],'/'); |
---|
125 | if (whoami) |
---|
126 | whoami++; |
---|
127 | else |
---|
128 | whoami = argv[0]; |
---|
129 | |
---|
130 | if (argc > 1) { |
---|
131 | fprintf(stderr,"Usage: %s\n",whoami); |
---|
132 | exit (1); |
---|
133 | } |
---|
134 | |
---|
135 | if (!strcmp(whoami,"rmds")) |
---|
136 | remove++; |
---|
137 | else if (strcmp(whoami, "mkds")) { |
---|
138 | fprintf(stderr, |
---|
139 | "This program must be run as 'mkds' or 'rmds'.\n"); |
---|
140 | exit(1); |
---|
141 | } |
---|
142 | |
---|
143 | gethostname(hostname, 256); |
---|
144 | { |
---|
145 | struct hostent *hp; |
---|
146 | char *h; |
---|
147 | hp = gethostbyname(hostname); |
---|
148 | h = (hp ? hp->h_name : hostname); |
---|
149 | default_host = malloc(strlen(h)+1); |
---|
150 | strcpy(default_host, h); |
---|
151 | } |
---|
152 | printf("Meeting host: [default %s]: ", default_host); |
---|
153 | if (!gets(mtg_host)) |
---|
154 | exit(1); |
---|
155 | strcpy(mtg_host, strtrim(mtg_host)); |
---|
156 | if (mtg_host[0] == '\0') |
---|
157 | strcpy(mtg_host, default_host); |
---|
158 | if (mtg_host[0] == '%') |
---|
159 | strcpy(mtg_host, ""); |
---|
160 | else { |
---|
161 | struct hostent *hp; |
---|
162 | hp = gethostbyname(mtg_host); |
---|
163 | if (!hp) { |
---|
164 | fprintf(stderr, "Unknown host %s\n", mtg_host); |
---|
165 | exit(1); |
---|
166 | } |
---|
167 | strcpy(mtg_host, hp->h_name); |
---|
168 | } |
---|
169 | printf("\nMeeting location [default %s]: ", default_dir); |
---|
170 | if (!gets(mtg_path)) |
---|
171 | exit(1); |
---|
172 | strcpy(mtg_path, strtrim(mtg_path)); |
---|
173 | if (!mtg_path[0]) |
---|
174 | strcpy(mtg_path, default_dir); |
---|
175 | if (!remove) { |
---|
176 | printf("\nLong meeting name: "); |
---|
177 | if (!gets(long_name)) |
---|
178 | exit(1); |
---|
179 | strcpy(long_name, strtrim(long_name)); |
---|
180 | if (long_name[0] == '\0') { |
---|
181 | printf("No long meeting name supplied.\n"); |
---|
182 | exit(1); |
---|
183 | } |
---|
184 | } |
---|
185 | printf("\nShort meeting name: "); |
---|
186 | if (!gets(short_name)) |
---|
187 | exit(1); |
---|
188 | strcpy(short_name, strtrim(short_name)); |
---|
189 | if(short_name[0] == '\0') { |
---|
190 | printf("No short meeting name supplied.\n"); |
---|
191 | exit(1); |
---|
192 | } |
---|
193 | |
---|
194 | (void) strcpy(mtg_path, strtrim(mtg_path)); |
---|
195 | (void) strcat(mtg_path,"/"); |
---|
196 | (void) strcat(mtg_path, short_name); |
---|
197 | nbsrc.pathname = malloc(strlen(mtg_path) + 1); |
---|
198 | strcpy(nbsrc.pathname, mtg_path); |
---|
199 | |
---|
200 | nbsrc.hostname = malloc(strlen(mtg_host) + 1); |
---|
201 | strcpy(nbsrc.hostname, mtg_host); |
---|
202 | |
---|
203 | (void) strcpy (username, getpwuid(getuid())->pw_name); |
---|
204 | (void) strcpy (nbsrc.user_id, username); |
---|
205 | |
---|
206 | if (remove) { |
---|
207 | dsc_remove_mtg(&nbsrc,&result); |
---|
208 | if (result) |
---|
209 | (void) fprintf(stderr,"Can't remove meeting: %s\n", |
---|
210 | error_message(result)); |
---|
211 | error = result; |
---|
212 | goto kaboom; |
---|
213 | } |
---|
214 | |
---|
215 | printf("\n"); |
---|
216 | public = getyn("Should this meeting be public [y]? ",'Y'); |
---|
217 | |
---|
218 | dsc_create_mtg(mtg_host, mtg_path, long_name, public, 0, |
---|
219 | &result); |
---|
220 | if (result) { |
---|
221 | if (result == ECONNREFUSED) |
---|
222 | fprintf(stderr, "%s doesn't appear to be running a discuss server", mtg_host); |
---|
223 | else fprintf(stderr, "%s. Can't create meeting.\n", |
---|
224 | error_message(result)); |
---|
225 | goto kaboom; |
---|
226 | } |
---|
227 | |
---|
228 | if (!public && |
---|
229 | getyn("Should specified users be allowed to participate? [y]", 'Y')) { |
---|
230 | char username[140]; |
---|
231 | |
---|
232 | printf("Enter the usernames you wish to participate; \n\ |
---|
233 | End with . on a line by itself\n\n"); |
---|
234 | for (;;) { |
---|
235 | printf("User name: "); |
---|
236 | fflush(stdout); |
---|
237 | if (!gets(username)) break; |
---|
238 | strcpy(username, strtrim(username)); |
---|
239 | if (strcmp(username, ".") == 0) break; |
---|
240 | if (strcmp(username,"*") != 0 && |
---|
241 | strchr(username, '@') == 0) { |
---|
242 | strcat(username, "@"); |
---|
243 | strcat(username, local_realm()); |
---|
244 | } |
---|
245 | dsc_set_access (&nbsrc, username, "aorsw", &result); |
---|
246 | if (result) { |
---|
247 | fprintf (stderr, "Can't add participant: %s\n", |
---|
248 | error_message(result)); |
---|
249 | } |
---|
250 | } |
---|
251 | } |
---|
252 | clearerr(stdin); |
---|
253 | |
---|
254 | delmtg = 1; |
---|
255 | |
---|
256 | nbsrc.date_attended = time(0); |
---|
257 | nbsrc.last = 0; |
---|
258 | nbsrc.status = 0; |
---|
259 | nbsrc.aliases = (char **) calloc(3, sizeof(char *)); |
---|
260 | nbsrc.aliases[0] = malloc(strlen(long_name)+1); |
---|
261 | strcpy(nbsrc.aliases[0], long_name); |
---|
262 | nbsrc.aliases[1] = malloc(strlen(short_name)+1); |
---|
263 | strcpy(nbsrc.aliases[1], short_name); |
---|
264 | nbsrc.aliases[2] = (char *)NULL; |
---|
265 | |
---|
266 | nbsrc.spare = ""; |
---|
267 | |
---|
268 | dsc_update_mtg_set(username,&nbsrc,1,&result); |
---|
269 | if (result) { |
---|
270 | fprintf(stderr, "mkds: Can't set meeting name: %s", |
---|
271 | error_message(result)); |
---|
272 | goto kaboom; |
---|
273 | } |
---|
274 | |
---|
275 | printf("\nYou must now enter the initial transaction.\n"); |
---|
276 | printf( |
---|
277 | "This transaction will serve as an introduction to the meeting.\n"); |
---|
278 | |
---|
279 | (void) unlink(temp_file); |
---|
280 | |
---|
281 | if (edit(temp_file, getenv("EDITOR"))) { |
---|
282 | (void) fprintf(stderr, |
---|
283 | "Error during edit; transaction not entered.\n"); |
---|
284 | goto kaboom; |
---|
285 | } |
---|
286 | |
---|
287 | fd = open(temp_file,O_RDONLY,0); |
---|
288 | if (fd < 0) { |
---|
289 | (void) fprintf(stderr,"No file; not entered.\n"); |
---|
290 | goto kaboom; |
---|
291 | } |
---|
292 | tf = unix_tfile(fd); |
---|
293 | |
---|
294 | dsc_add_trn(&nbsrc, tf, "Reason for this meeting", 0, &txn_no, |
---|
295 | &result); |
---|
296 | if (result) { |
---|
297 | fprintf(stderr, "mkds: Error adding transaction: %s", |
---|
298 | error_message(result)); |
---|
299 | goto kaboom; |
---|
300 | } |
---|
301 | (void) printf("Transaction [%04d] entered in the %s meeting.\n", |
---|
302 | txn_no,long_name); |
---|
303 | |
---|
304 | (void) close(fd); |
---|
305 | |
---|
306 | printf("\n"); |
---|
307 | if (getyn("Would you like to announce this meeting [y]? ",'Y')) { |
---|
308 | printf("\n"); |
---|
309 | for (;;) { |
---|
310 | printf("Announce in what meeting? "); |
---|
311 | if (!gets(ann_mtg)) |
---|
312 | exit(1); |
---|
313 | dsc_get_mtg(nbsrc.user_id,strtrim(ann_mtg), |
---|
314 | &nbdest,&result); |
---|
315 | if (!result) |
---|
316 | break; |
---|
317 | fprintf(stderr, "Meeting not found in search path.\n"); |
---|
318 | } |
---|
319 | |
---|
320 | fd = open(temp_file,O_RDONLY,0); |
---|
321 | if (fd < 0) { |
---|
322 | (void) fprintf(stderr,"Temporary file disappeared!\n"); |
---|
323 | goto kaboom; |
---|
324 | } |
---|
325 | |
---|
326 | tf = unix_tfile(fd); |
---|
327 | |
---|
328 | dsc_announce_mtg(&nbsrc, &nbdest, public, tf, |
---|
329 | &txn_no, &result); |
---|
330 | |
---|
331 | if (result) { |
---|
332 | (void) fprintf(stderr, |
---|
333 | "mkds: Error adding transaction: %s\n", |
---|
334 | error_message(result)); |
---|
335 | (void) fprintf(stderr, |
---|
336 | "Use the announce_meeting (anm) request in discuss.\n"); |
---|
337 | } |
---|
338 | else (void) printf("Transaction [%04d] entered in the %s meeting.\n", |
---|
339 | txn_no, nbdest.aliases[0]); |
---|
340 | |
---|
341 | (void) close(fd); |
---|
342 | } |
---|
343 | |
---|
344 | error = 0; |
---|
345 | |
---|
346 | kaboom: |
---|
347 | |
---|
348 | (void) unlink(temp_file); |
---|
349 | |
---|
350 | if (error && delmtg) { |
---|
351 | fprintf(stderr,"\nError encountered - deleting meeting.\n"); |
---|
352 | remove_mtg(mtg_path,&result); |
---|
353 | if (result) |
---|
354 | perror("Can't delete meeting"); |
---|
355 | } |
---|
356 | term_rpc(); |
---|
357 | exit(!error); |
---|
358 | } |
---|
359 | |
---|
360 | getyn(prompt,def) |
---|
361 | char *prompt,def; |
---|
362 | { |
---|
363 | char yn_inp[128]; |
---|
364 | |
---|
365 | for (;;) { |
---|
366 | (void) printf("%s ",prompt); |
---|
367 | if (!gets(yn_inp)) |
---|
368 | exit(1); |
---|
369 | if (yn_inp[0] == '\0') |
---|
370 | yn_inp[0] = def; |
---|
371 | if (cupper(yn_inp[0]) == 'Y' || cupper(yn_inp[0]) == 'N') |
---|
372 | return (cupper(yn_inp[0]) == 'Y'); |
---|
373 | printf("Please enter 'Yes' or 'No'\n\n"); |
---|
374 | } |
---|
375 | } |
---|
376 | #include <ctype.h> |
---|
377 | |
---|
378 | char *strtrim(cp) |
---|
379 | register char *cp; |
---|
380 | { |
---|
381 | register int c; |
---|
382 | register char *cp1; |
---|
383 | |
---|
384 | while ((c = *cp) && isspace (c)) cp++; |
---|
385 | cp1 = cp; |
---|
386 | while (*cp1) cp1++; |
---|
387 | do { |
---|
388 | cp1--; |
---|
389 | } while (cp1 > cp && isspace (*cp1)); |
---|
390 | cp1++; |
---|
391 | *cp1 = '\0'; |
---|
392 | return cp; |
---|
393 | } |
---|