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.
RevLine 
[176]1/*
[1936]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/*
[12459]9 *      $Id: mkds.c,v 1.23 1999-02-08 14:47:15 danw Exp $
[177]10 *
[176]11 */
12
13#ifndef lint
[1935]14static char rcsid_mkds_c[] =
[12459]15    "$Id: mkds.c,v 1.23 1999-02-08 14:47:15 danw Exp $";
16#endif /* lint */
[176]17
[1935]18#include <discuss/discuss.h>
19#if 0
[234]20#include "dsc_et.h"
21#include "config.h"
22#include "interface.h"
23#include "rpc.h"
24#include "globals.h"
[1935]25#endif
[176]26#include <sys/time.h>
27#include <sys/file.h>
28#include <stdio.h>
[12267]29#include <stdlib.h>
[176]30#include <ctype.h>
[1935]31#include <string.h>
[176]32#include <netdb.h>
[290]33#include <pwd.h>
[819]34#include <errno.h>
[12439]35#if HAVE_FCNTL_H
[6647]36#include <fcntl.h>
37#endif
[176]38
39#define cupper(x) (islower(x)?toupper(x):(x))
[234]40#define clower(x) (isupper(x)?tolower(x):(x))
[176]41
[11295]42char default_dir[] = "/var/spool/discuss";
[290]43char *whoami;
[1741]44int  interrupt = 0;
[290]45
[12267]46extern const char *local_realm();
[290]47
[819]48char *strtrim();
49
[176]50main(argc,argv)
51int argc;
52char *argv[];
53{
54        extern tfile unix_tfile();
[328]55        name_blk nbsrc,nbdest;
[819]56        char long_name[100],short_name[100],username[50],mtg_path[100];
57        char mtg_host[100];
58        char *default_host;
[347]59        char temp_file[64];
60        char ann_mtg[100];
[176]61        int public = 0,error = 1,result,remove=0,delmtg=0;
[819]62        int fd,txn_no;
[176]63        tfile tf;
[290]64        char hostname[256];
[176]65
[23271]66#if defined(__APPLE__) && defined(__MACH__)
67        add_error_table(&et_dsc_error_table);
68#else
[22864]69        initialize_dsc_error_table();
[23271]70#endif
[176]71
[328]72        nbsrc.user_id = malloc(132);
[290]73
[176]74        (void) sprintf(temp_file,"/tmp/mtg%d.%d",getuid(),getpid());
75
[7175]76        whoami = strrchr(argv[0],'/');
[176]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++;
[290]89        else if (strcmp(whoami, "mkds")) {
90                fprintf(stderr,
91                        "This program must be run as 'mkds' or 'rmds'.\n");
92                exit(1);
93        }
[176]94
[290]95        gethostname(hostname, 256);
[320]96        {
97                struct hostent *hp;
[819]98                char *h;
[320]99                hp = gethostbyname(hostname);
100                h = (hp ? hp->h_name : hostname);
[819]101                default_host = malloc(strlen(h)+1);
102                strcpy(default_host, h);
[320]103        }
[819]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);
[3900]110        if (mtg_host[0] == '%')
111                strcpy(mtg_host, "");
112        else {
[819]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);
[331]122        if (!gets(mtg_path))
123                exit(1);
[819]124        strcpy(mtg_path, strtrim(mtg_path));
[176]125        if (!mtg_path[0])
[290]126                strcpy(mtg_path, default_dir);
[176]127        if (!remove) {
128                printf("\nLong meeting name: ");
[331]129                if (!gets(long_name))
130                        exit(1);
[819]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                }
[176]136        }
[331]137        printf("\nShort meeting name: ");
138        if (!gets(short_name))
139                exit(1);
[819]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));
[176]147        (void) strcat(mtg_path,"/");
[819]148        (void) strcat(mtg_path, short_name);
149        nbsrc.pathname = malloc(strlen(mtg_path) + 1);
[328]150        strcpy(nbsrc.pathname, mtg_path);
[176]151
[819]152        nbsrc.hostname = malloc(strlen(mtg_host) + 1);
153        strcpy(nbsrc.hostname, mtg_host);
[176]154
[819]155        (void) strcpy (username, getpwuid(getuid())->pw_name);
156        (void) strcpy (nbsrc.user_id, username);
[290]157
[176]158        if (remove) {
[819]159                dsc_remove_mtg(&nbsrc,&result);
[176]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");
[290]168        public = getyn("Should this meeting be public [y]? ",'Y');
[176]169
[819]170        dsc_create_mtg(mtg_host, mtg_path, long_name, public, 0,
171                       &result);
[176]172        if (result) {
[819]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));
[176]177                goto kaboom;
178        }
179
[819]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 &&
[7175]193                            strchr(username, '@') == 0) {
[819]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       
[176]206        delmtg = 1;
207
[328]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;
[290]217
[3900]218        nbsrc.spare = "";
219               
[819]220        dsc_update_mtg_set(username,&nbsrc,1,&result);
[176]221        if (result) {
[290]222                fprintf(stderr, "mkds: Can't set meeting name: %s",
223                        error_message(result));
[176]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
[290]233        if (edit(temp_file, getenv("EDITOR"))) {
[176]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
[331]246        dsc_add_trn(&nbsrc, tf, "Reason for this meeting", 0, &txn_no,
247                    &result);
[176]248        if (result) {
[290]249                fprintf(stderr, "mkds: Error adding transaction: %s",
[176]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");
[819]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                }
[176]271
[819]272                fd = open(temp_file,O_RDONLY,0);
273                if (fd < 0) {
274                        (void) fprintf(stderr,"Temporary file disappeared!\n");
275                        goto kaboom;
276                }
[176]277
[819]278                tf = unix_tfile(fd);
[322]279
[819]280                dsc_announce_mtg(&nbsrc, &nbdest, public, tf,
281                                 &txn_no, &result);
[176]282
[819]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]);
[322]292
[819]293                (void) close(fd);
[176]294        }
[819]295               
[176]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);
[358]305                if (result)
306                     perror("Can't delete meeting");
[176]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);
[331]319                if (!gets(yn_inp))
320                        exit(1);
[176]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}
[819]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.