source: trunk/athena/bin/discuss/mclient/mkds.c @ 23271

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