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 | initialize_dsc_error_table(); |
---|
48 | for (i = 1; i < argc; i++) { |
---|
49 | if (*argv[i] == '-') |
---|
50 | switch (argv[i][1]) { |
---|
51 | case 'd': |
---|
52 | case 'a': |
---|
53 | continue; |
---|
54 | |
---|
55 | case 't': |
---|
56 | if (++i < argc) |
---|
57 | subject = argv[i]; |
---|
58 | continue; |
---|
59 | |
---|
60 | case 's': |
---|
61 | if (++i < argc) |
---|
62 | signature = argv[i]; |
---|
63 | continue; |
---|
64 | |
---|
65 | default: |
---|
66 | goto lusage; |
---|
67 | } |
---|
68 | if (*usr_mtg != '\0') |
---|
69 | goto lusage; /* only one meeting name */ |
---|
70 | |
---|
71 | usr_mtg = argv[i]; |
---|
72 | } |
---|
73 | |
---|
74 | if (*usr_mtg == '\0') |
---|
75 | goto lusage; |
---|
76 | |
---|
77 | |
---|
78 | (void) strcpy (filename, "/tmp/DSXXXXXX"); |
---|
79 | (void) mktemp (filename); |
---|
80 | |
---|
81 | d = open (filename, O_RDWR | O_CREAT, 0700); |
---|
82 | if (d < 0) { |
---|
83 | (void) fprintf (stderr, "Cannot open temp file\n"); |
---|
84 | exit (1); |
---|
85 | } |
---|
86 | |
---|
87 | for (;;) { |
---|
88 | nread = read (0, buffer, 512); |
---|
89 | if (nread < 0) { |
---|
90 | (void) fprintf (stderr, "Cannot read stdin\n"); |
---|
91 | } |
---|
92 | write (d, buffer, nread); |
---|
93 | if (nread == 0) |
---|
94 | break; |
---|
95 | } |
---|
96 | |
---|
97 | lseek (d, 0, SEEK_SET); /* rewind temp */ |
---|
98 | |
---|
99 | tf = unix_tfile (d); |
---|
100 | |
---|
101 | strcpy (host, "discuss@"); |
---|
102 | resolve_mtg (usr_mtg, &host[8], mtg_name); |
---|
103 | |
---|
104 | init_rpc(); |
---|
105 | set_module (host, &fatal_err, &result); |
---|
106 | if (fatal_err) { |
---|
107 | (void) fprintf (stderr, "%s\n", error_message(result)); |
---|
108 | exit(1); |
---|
109 | } |
---|
110 | if (result) { |
---|
111 | (void) fprintf (stderr, "Warning: %s\n", error_message(result)); |
---|
112 | } |
---|
113 | |
---|
114 | if (signature[0] == '\0') { |
---|
115 | add_trn (mtg_name, tf, subject, 0, &result_trn, &result); |
---|
116 | } else { |
---|
117 | if (get_server_version() < SERVER_2) |
---|
118 | add_trn (mtg_name, tf, subject, 0, &result_trn, &result); |
---|
119 | else |
---|
120 | add_trn2(mtg_name, tf, subject, signature, 0, &result_trn, &result); |
---|
121 | } |
---|
122 | |
---|
123 | if (result != 0) { |
---|
124 | (void) fprintf (stderr, "%s\n", error_message(result)); |
---|
125 | exit_code = 1; |
---|
126 | goto bye; |
---|
127 | } |
---|
128 | |
---|
129 | (void) printf ("Transaction [%04d] added to %s\n", result_trn, |
---|
130 | mtg_name); |
---|
131 | exit_code = 0; |
---|
132 | |
---|
133 | bye: |
---|
134 | (void) close (d); |
---|
135 | tdestroy (tf); |
---|
136 | (void) unlink (filename); |
---|
137 | |
---|
138 | term_rpc(); |
---|
139 | exit (exit_code); |
---|
140 | |
---|
141 | lusage: |
---|
142 | (void) fprintf (stderr, "Usage: dspipe {mtgname} -t {topic} -s {signature}\n"); |
---|
143 | exit (1); |
---|
144 | } |
---|
145 | |
---|
146 | /* |
---|
147 | * |
---|
148 | * resolve_mtg: Procedure to resolve a user meeting name into its host |
---|
149 | * an pathname. |
---|
150 | * |
---|
151 | */ |
---|
152 | resolve_mtg (usr_string, host, mtg_name) |
---|
153 | char *usr_string,*host,*mtg_name; |
---|
154 | { |
---|
155 | char *colon; |
---|
156 | int host_len; |
---|
157 | |
---|
158 | colon = strchr (usr_string, ':'); |
---|
159 | |
---|
160 | if (colon == 0) { |
---|
161 | (void) strcpy (mtg_name, usr_string); |
---|
162 | gethostname (host, 50); |
---|
163 | return; |
---|
164 | } |
---|
165 | |
---|
166 | host_len = colon - usr_string; |
---|
167 | memmove (host, usr_string, host_len); |
---|
168 | host [host_len] = '\0'; |
---|
169 | (void) strcpy (mtg_name, colon+1); |
---|
170 | return; |
---|
171 | } |
---|