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 | * $Id: mkds.c,v 1.21 1999-01-22 23:10:10 ghudson Exp $ |
---|
10 | * |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef lint |
---|
14 | static char rcsid_mkds_c[] = |
---|
15 | "$Id: mkds.c,v 1.21 1999-01-22 23:10:10 ghudson Exp $"; |
---|
16 | #endif lint |
---|
17 | |
---|
18 | #include <discuss/discuss.h> |
---|
19 | #if 0 |
---|
20 | #include "dsc_et.h" |
---|
21 | #include "config.h" |
---|
22 | #include "interface.h" |
---|
23 | #include "rpc.h" |
---|
24 | #include "globals.h" |
---|
25 | #endif |
---|
26 | #include <sys/time.h> |
---|
27 | #include <sys/file.h> |
---|
28 | #include <stdio.h> |
---|
29 | #include <stdlib.h> |
---|
30 | #include <ctype.h> |
---|
31 | #include <string.h> |
---|
32 | #include <netdb.h> |
---|
33 | #include <pwd.h> |
---|
34 | #include <errno.h> |
---|
35 | #ifdef SOLARIS |
---|
36 | #include <fcntl.h> |
---|
37 | #endif |
---|
38 | |
---|
39 | #define cupper(x) (islower(x)?toupper(x):(x)) |
---|
40 | #define clower(x) (isupper(x)?tolower(x):(x)) |
---|
41 | |
---|
42 | char default_dir[] = "/var/spool/discuss"; |
---|
43 | char *whoami; |
---|
44 | int interrupt = 0; |
---|
45 | |
---|
46 | extern const char *local_realm(); |
---|
47 | |
---|
48 | char *strtrim(); |
---|
49 | |
---|
50 | main(argc,argv) |
---|
51 | int argc; |
---|
52 | char *argv[]; |
---|
53 | { |
---|
54 | extern tfile unix_tfile(); |
---|
55 | name_blk nbsrc,nbdest; |
---|
56 | char long_name[100],short_name[100],username[50],mtg_path[100]; |
---|
57 | char mtg_host[100]; |
---|
58 | char *default_host; |
---|
59 | char temp_file[64]; |
---|
60 | char ann_mtg[100]; |
---|
61 | int public = 0,error = 1,result,remove=0,delmtg=0; |
---|
62 | int fd,txn_no; |
---|
63 | tfile tf; |
---|
64 | char hostname[256]; |
---|
65 | |
---|
66 | init_dsc_err_tbl(); |
---|
67 | |
---|
68 | nbsrc.user_id = malloc(132); |
---|
69 | |
---|
70 | (void) sprintf(temp_file,"/tmp/mtg%d.%d",getuid(),getpid()); |
---|
71 | |
---|
72 | whoami = strrchr(argv[0],'/'); |
---|
73 | if (whoami) |
---|
74 | whoami++; |
---|
75 | else |
---|
76 | whoami = argv[0]; |
---|
77 | |
---|
78 | if (argc > 1) { |
---|
79 | fprintf(stderr,"Usage: %s\n",whoami); |
---|
80 | exit (1); |
---|
81 | } |
---|
82 | |
---|
83 | if (!strcmp(whoami,"rmds")) |
---|
84 | remove++; |
---|
85 | else if (strcmp(whoami, "mkds")) { |
---|
86 | fprintf(stderr, |
---|
87 | "This program must be run as 'mkds' or 'rmds'.\n"); |
---|
88 | exit(1); |
---|
89 | } |
---|
90 | |
---|
91 | gethostname(hostname, 256); |
---|
92 | { |
---|
93 | struct hostent *hp; |
---|
94 | char *h; |
---|
95 | hp = gethostbyname(hostname); |
---|
96 | h = (hp ? hp->h_name : hostname); |
---|
97 | default_host = malloc(strlen(h)+1); |
---|
98 | strcpy(default_host, h); |
---|
99 | } |
---|
100 | printf("Meeting host: [default %s]: ", default_host); |
---|
101 | if (!gets(mtg_host)) |
---|
102 | exit(1); |
---|
103 | strcpy(mtg_host, strtrim(mtg_host)); |
---|
104 | if (mtg_host[0] == '\0') |
---|
105 | strcpy(mtg_host, default_host); |
---|
106 | if (mtg_host[0] == '%') |
---|
107 | strcpy(mtg_host, ""); |
---|
108 | else { |
---|
109 | struct hostent *hp; |
---|
110 | hp = gethostbyname(mtg_host); |
---|
111 | if (!hp) { |
---|
112 | fprintf(stderr, "Unknown host %s\n", mtg_host); |
---|
113 | exit(1); |
---|
114 | } |
---|
115 | strcpy(mtg_host, hp->h_name); |
---|
116 | } |
---|
117 | printf("\nMeeting location [default %s]: ", default_dir); |
---|
118 | if (!gets(mtg_path)) |
---|
119 | exit(1); |
---|
120 | strcpy(mtg_path, strtrim(mtg_path)); |
---|
121 | if (!mtg_path[0]) |
---|
122 | strcpy(mtg_path, default_dir); |
---|
123 | if (!remove) { |
---|
124 | printf("\nLong meeting name: "); |
---|
125 | if (!gets(long_name)) |
---|
126 | exit(1); |
---|
127 | strcpy(long_name, strtrim(long_name)); |
---|
128 | if (long_name[0] == '\0') { |
---|
129 | printf("No long meeting name supplied.\n"); |
---|
130 | exit(1); |
---|
131 | } |
---|
132 | } |
---|
133 | printf("\nShort meeting name: "); |
---|
134 | if (!gets(short_name)) |
---|
135 | exit(1); |
---|
136 | strcpy(short_name, strtrim(short_name)); |
---|
137 | if(short_name[0] == '\0') { |
---|
138 | printf("No short meeting name supplied.\n"); |
---|
139 | exit(1); |
---|
140 | } |
---|
141 | |
---|
142 | (void) strcpy(mtg_path, strtrim(mtg_path)); |
---|
143 | (void) strcat(mtg_path,"/"); |
---|
144 | (void) strcat(mtg_path, short_name); |
---|
145 | nbsrc.pathname = malloc(strlen(mtg_path) + 1); |
---|
146 | strcpy(nbsrc.pathname, mtg_path); |
---|
147 | |
---|
148 | nbsrc.hostname = malloc(strlen(mtg_host) + 1); |
---|
149 | strcpy(nbsrc.hostname, mtg_host); |
---|
150 | |
---|
151 | (void) strcpy (username, getpwuid(getuid())->pw_name); |
---|
152 | (void) strcpy (nbsrc.user_id, username); |
---|
153 | |
---|
154 | if (remove) { |
---|
155 | dsc_remove_mtg(&nbsrc,&result); |
---|
156 | if (result) |
---|
157 | (void) fprintf(stderr,"Can't remove meeting: %s\n", |
---|
158 | error_message(result)); |
---|
159 | error = result; |
---|
160 | goto kaboom; |
---|
161 | } |
---|
162 | |
---|
163 | printf("\n"); |
---|
164 | public = getyn("Should this meeting be public [y]? ",'Y'); |
---|
165 | |
---|
166 | dsc_create_mtg(mtg_host, mtg_path, long_name, public, 0, |
---|
167 | &result); |
---|
168 | if (result) { |
---|
169 | if (result == ECONNREFUSED) |
---|
170 | fprintf(stderr, "%s doesn't appear to be running a discuss server", mtg_host); |
---|
171 | else fprintf(stderr, "%s. Can't create meeting.\n", |
---|
172 | error_message(result)); |
---|
173 | goto kaboom; |
---|
174 | } |
---|
175 | |
---|
176 | if (!public && |
---|
177 | getyn("Should specified users be allowed to participate? [y]", 'Y')) { |
---|
178 | char username[140]; |
---|
179 | |
---|
180 | printf("Enter the usernames you wish to participate; \n\ |
---|
181 | End with . on a line by itself\n\n"); |
---|
182 | for (;;) { |
---|
183 | printf("User name: "); |
---|
184 | fflush(stdout); |
---|
185 | if (!gets(username)) break; |
---|
186 | strcpy(username, strtrim(username)); |
---|
187 | if (strcmp(username, ".") == 0) break; |
---|
188 | if (strcmp(username,"*") != 0 && |
---|
189 | strchr(username, '@') == 0) { |
---|
190 | strcat(username, "@"); |
---|
191 | strcat(username, local_realm()); |
---|
192 | } |
---|
193 | dsc_set_access (&nbsrc, username, "aorsw", &result); |
---|
194 | if (result) { |
---|
195 | fprintf (stderr, "Can't add participant: %s\n", |
---|
196 | error_message(result)); |
---|
197 | } |
---|
198 | } |
---|
199 | } |
---|
200 | clearerr(stdin); |
---|
201 | |
---|
202 | delmtg = 1; |
---|
203 | |
---|
204 | nbsrc.date_attended = time(0); |
---|
205 | nbsrc.last = 0; |
---|
206 | nbsrc.status = 0; |
---|
207 | nbsrc.aliases = (char **) calloc(3, sizeof(char *)); |
---|
208 | nbsrc.aliases[0] = malloc(strlen(long_name)+1); |
---|
209 | strcpy(nbsrc.aliases[0], long_name); |
---|
210 | nbsrc.aliases[1] = malloc(strlen(short_name)+1); |
---|
211 | strcpy(nbsrc.aliases[1], short_name); |
---|
212 | nbsrc.aliases[2] = (char *)NULL; |
---|
213 | |
---|
214 | nbsrc.spare = ""; |
---|
215 | |
---|
216 | dsc_update_mtg_set(username,&nbsrc,1,&result); |
---|
217 | if (result) { |
---|
218 | fprintf(stderr, "mkds: Can't set meeting name: %s", |
---|
219 | error_message(result)); |
---|
220 | goto kaboom; |
---|
221 | } |
---|
222 | |
---|
223 | printf("\nYou must now enter the initial transaction.\n"); |
---|
224 | printf( |
---|
225 | "This transaction will serve as an introduction to the meeting.\n"); |
---|
226 | |
---|
227 | (void) unlink(temp_file); |
---|
228 | |
---|
229 | if (edit(temp_file, getenv("EDITOR"))) { |
---|
230 | (void) fprintf(stderr, |
---|
231 | "Error during edit; transaction not entered.\n"); |
---|
232 | goto kaboom; |
---|
233 | } |
---|
234 | |
---|
235 | fd = open(temp_file,O_RDONLY,0); |
---|
236 | if (fd < 0) { |
---|
237 | (void) fprintf(stderr,"No file; not entered.\n"); |
---|
238 | goto kaboom; |
---|
239 | } |
---|
240 | tf = unix_tfile(fd); |
---|
241 | |
---|
242 | dsc_add_trn(&nbsrc, tf, "Reason for this meeting", 0, &txn_no, |
---|
243 | &result); |
---|
244 | if (result) { |
---|
245 | fprintf(stderr, "mkds: Error adding transaction: %s", |
---|
246 | error_message(result)); |
---|
247 | goto kaboom; |
---|
248 | } |
---|
249 | (void) printf("Transaction [%04d] entered in the %s meeting.\n", |
---|
250 | txn_no,long_name); |
---|
251 | |
---|
252 | (void) close(fd); |
---|
253 | |
---|
254 | printf("\n"); |
---|
255 | if (getyn("Would you like to announce this meeting [y]? ",'Y')) { |
---|
256 | printf("\n"); |
---|
257 | for (;;) { |
---|
258 | printf("Announce in what meeting? "); |
---|
259 | if (!gets(ann_mtg)) |
---|
260 | exit(1); |
---|
261 | dsc_get_mtg(nbsrc.user_id,strtrim(ann_mtg), |
---|
262 | &nbdest,&result); |
---|
263 | if (!result) |
---|
264 | break; |
---|
265 | fprintf(stderr, "Meeting not found in search path.\n"); |
---|
266 | } |
---|
267 | |
---|
268 | fd = open(temp_file,O_RDONLY,0); |
---|
269 | if (fd < 0) { |
---|
270 | (void) fprintf(stderr,"Temporary file disappeared!\n"); |
---|
271 | goto kaboom; |
---|
272 | } |
---|
273 | |
---|
274 | tf = unix_tfile(fd); |
---|
275 | |
---|
276 | dsc_announce_mtg(&nbsrc, &nbdest, public, tf, |
---|
277 | &txn_no, &result); |
---|
278 | |
---|
279 | if (result) { |
---|
280 | (void) fprintf(stderr, |
---|
281 | "mkds: Error adding transaction: %s\n", |
---|
282 | error_message(result)); |
---|
283 | (void) fprintf(stderr, |
---|
284 | "Use the announce_meeting (anm) request in discuss.\n"); |
---|
285 | } |
---|
286 | else (void) printf("Transaction [%04d] entered in the %s meeting.\n", |
---|
287 | txn_no, nbdest.aliases[0]); |
---|
288 | |
---|
289 | (void) close(fd); |
---|
290 | } |
---|
291 | |
---|
292 | error = 0; |
---|
293 | |
---|
294 | kaboom: |
---|
295 | |
---|
296 | (void) unlink(temp_file); |
---|
297 | |
---|
298 | if (error && delmtg) { |
---|
299 | fprintf(stderr,"\nError encountered - deleting meeting.\n"); |
---|
300 | remove_mtg(mtg_path,&result); |
---|
301 | if (result) |
---|
302 | perror("Can't delete meeting"); |
---|
303 | } |
---|
304 | term_rpc(); |
---|
305 | exit(!error); |
---|
306 | } |
---|
307 | |
---|
308 | getyn(prompt,def) |
---|
309 | char *prompt,def; |
---|
310 | { |
---|
311 | char yn_inp[128]; |
---|
312 | |
---|
313 | for (;;) { |
---|
314 | (void) printf("%s ",prompt); |
---|
315 | if (!gets(yn_inp)) |
---|
316 | exit(1); |
---|
317 | if (yn_inp[0] == '\0') |
---|
318 | yn_inp[0] = def; |
---|
319 | if (cupper(yn_inp[0]) == 'Y' || cupper(yn_inp[0]) == 'N') |
---|
320 | return (cupper(yn_inp[0]) == 'Y'); |
---|
321 | printf("Please enter 'Yes' or 'No'\n\n"); |
---|
322 | } |
---|
323 | } |
---|
324 | #include <ctype.h> |
---|
325 | |
---|
326 | char *strtrim(cp) |
---|
327 | register char *cp; |
---|
328 | { |
---|
329 | register int c; |
---|
330 | register char *cp1; |
---|
331 | |
---|
332 | while ((c = *cp) && isspace (c)) cp++; |
---|
333 | cp1 = cp; |
---|
334 | while (*cp1) cp1++; |
---|
335 | do { |
---|
336 | cp1--; |
---|
337 | } while (cp1 > cp && isspace (*cp1)); |
---|
338 | cp1++; |
---|
339 | *cp1 = '\0'; |
---|
340 | return cp; |
---|
341 | } |
---|