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 | * |
---|
10 | * dspipe.c -- Program to pipe stdin into a Discuss meeting. |
---|
11 | * |
---|
12 | */ |
---|
13 | |
---|
14 | #include <discuss/tfile.h> |
---|
15 | #include <discuss/interface.h> |
---|
16 | #include <discuss/dsc_et.h> |
---|
17 | #include <rpc.h> |
---|
18 | #include <sys/file.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <string.h> |
---|
21 | #include <fcntl.h> |
---|
22 | #include <sys/types.h> |
---|
23 | #include <unistd.h> |
---|
24 | |
---|
25 | tfile unix_tfile(); |
---|
26 | char *mktemp(); |
---|
27 | |
---|
28 | #ifndef lint |
---|
29 | static char rcsid[] = "$Id: dspipe.c,v 1.11 2002-04-06 15:18:51 zacheiss Exp $"; |
---|
30 | #endif |
---|
31 | |
---|
32 | main (argc,argv) |
---|
33 | int argc; |
---|
34 | char **argv; |
---|
35 | { |
---|
36 | char *usr_mtg = ""; |
---|
37 | char *subject = ""; |
---|
38 | char *signature = ""; |
---|
39 | char mtg_name [100],host[70]; |
---|
40 | int result; |
---|
41 | int fatal_err; |
---|
42 | trn_nums result_trn; |
---|
43 | char filename [40], buffer [512]; |
---|
44 | tfile tf; |
---|
45 | int i,nread,d,exit_code; |
---|
46 | |
---|
47 | #if defined(__APPLE__) && defined(__MACH__) |
---|
48 | add_error_table(&et_dsc_error_table); |
---|
49 | #else |
---|
50 | initialize_dsc_error_table(); |
---|
51 | #endif |
---|
52 | for (i = 1; i < argc; i++) { |
---|
53 | if (*argv[i] == '-') |
---|
54 | switch (argv[i][1]) { |
---|
55 | case 'd': |
---|
56 | case 'a': |
---|
57 | continue; |
---|
58 | |
---|
59 | case 't': |
---|
60 | if (++i < argc) |
---|
61 | subject = argv[i]; |
---|
62 | continue; |
---|
63 | |
---|
64 | case 's': |
---|
65 | if (++i < argc) |
---|
66 | signature = argv[i]; |
---|
67 | continue; |
---|
68 | |
---|
69 | default: |
---|
70 | goto lusage; |
---|
71 | } |
---|
72 | if (*usr_mtg != '\0') |
---|
73 | goto lusage; /* only one meeting name */ |
---|
74 | |
---|
75 | usr_mtg = argv[i]; |
---|
76 | } |
---|
77 | |
---|
78 | if (*usr_mtg == '\0') |
---|
79 | goto lusage; |
---|
80 | |
---|
81 | |
---|
82 | (void) strcpy (filename, "/tmp/DSXXXXXX"); |
---|
83 | (void) mktemp (filename); |
---|
84 | |
---|
85 | d = open (filename, O_RDWR | O_CREAT, 0700); |
---|
86 | if (d < 0) { |
---|
87 | (void) fprintf (stderr, "Cannot open temp file\n"); |
---|
88 | exit (1); |
---|
89 | } |
---|
90 | |
---|
91 | for (;;) { |
---|
92 | nread = read (0, buffer, 512); |
---|
93 | if (nread < 0) { |
---|
94 | (void) fprintf (stderr, "Cannot read stdin\n"); |
---|
95 | } |
---|
96 | write (d, buffer, nread); |
---|
97 | if (nread == 0) |
---|
98 | break; |
---|
99 | } |
---|
100 | |
---|
101 | lseek (d, 0, SEEK_SET); /* rewind temp */ |
---|
102 | |
---|
103 | tf = unix_tfile (d); |
---|
104 | |
---|
105 | strcpy (host, "discuss@"); |
---|
106 | resolve_mtg (usr_mtg, &host[8], mtg_name); |
---|
107 | |
---|
108 | init_rpc(); |
---|
109 | set_module (host, &fatal_err, &result); |
---|
110 | if (fatal_err) { |
---|
111 | (void) fprintf (stderr, "%s\n", error_message(result)); |
---|
112 | exit(1); |
---|
113 | } |
---|
114 | if (result) { |
---|
115 | (void) fprintf (stderr, "Warning: %s\n", error_message(result)); |
---|
116 | } |
---|
117 | |
---|
118 | if (signature[0] == '\0') { |
---|
119 | add_trn (mtg_name, tf, subject, 0, &result_trn, &result); |
---|
120 | } else { |
---|
121 | if (get_server_version() < SERVER_2) |
---|
122 | add_trn (mtg_name, tf, subject, 0, &result_trn, &result); |
---|
123 | else |
---|
124 | add_trn2(mtg_name, tf, subject, signature, 0, &result_trn, &result); |
---|
125 | } |
---|
126 | |
---|
127 | if (result != 0) { |
---|
128 | (void) fprintf (stderr, "%s\n", error_message(result)); |
---|
129 | exit_code = 1; |
---|
130 | goto bye; |
---|
131 | } |
---|
132 | |
---|
133 | (void) printf ("Transaction [%04d] added to %s\n", result_trn, |
---|
134 | mtg_name); |
---|
135 | exit_code = 0; |
---|
136 | |
---|
137 | bye: |
---|
138 | (void) close (d); |
---|
139 | tdestroy (tf); |
---|
140 | (void) unlink (filename); |
---|
141 | |
---|
142 | term_rpc(); |
---|
143 | exit (exit_code); |
---|
144 | |
---|
145 | lusage: |
---|
146 | (void) fprintf (stderr, "Usage: dspipe {mtgname} -t {topic} -s {signature}\n"); |
---|
147 | exit (1); |
---|
148 | } |
---|
149 | |
---|
150 | /* |
---|
151 | * |
---|
152 | * resolve_mtg: Procedure to resolve a user meeting name into its host |
---|
153 | * an pathname. |
---|
154 | * |
---|
155 | */ |
---|
156 | resolve_mtg (usr_string, host, mtg_name) |
---|
157 | char *usr_string,*host,*mtg_name; |
---|
158 | { |
---|
159 | char *colon; |
---|
160 | int host_len; |
---|
161 | |
---|
162 | colon = strchr (usr_string, ':'); |
---|
163 | |
---|
164 | if (colon == 0) { |
---|
165 | (void) strcpy (mtg_name, usr_string); |
---|
166 | gethostname (host, 50); |
---|
167 | return; |
---|
168 | } |
---|
169 | |
---|
170 | host_len = colon - usr_string; |
---|
171 | memmove (host, usr_string, host_len); |
---|
172 | host [host_len] = '\0'; |
---|
173 | (void) strcpy (mtg_name, colon+1); |
---|
174 | return; |
---|
175 | } |
---|