]>
Commit | Line | Data |
---|---|---|
6e6374cb | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
c801de4c | 7 | * For copying and distribution information, please see the file |
8 | * <mit-copyright.h>. | |
6e6374cb | 9 | * |
6e6374cb | 10 | */ |
11 | ||
12 | #ifndef lint | |
13 | static char *rcsid_test_c = "$Header$"; | |
14 | #endif lint | |
15 | ||
c801de4c | 16 | #include <mit-copyright.h> |
6e6374cb | 17 | #include <stdio.h> |
58b825a4 | 18 | #include <sys/file.h> |
19 | #include <ctype.h> | |
6e6374cb | 20 | #include <sms.h> |
21 | #include <ss.h> | |
22 | ||
23 | int ss; | |
58b825a4 | 24 | int recursion = 0; |
6e6374cb | 25 | extern ss_request_table sms_test; |
59af7b90 | 26 | extern int sending_version_no; |
6e6374cb | 27 | |
28 | #ifndef __SABER__ | |
29 | main(argc, argv) | |
30 | int argc; | |
31 | char **argv; | |
32 | #else __SABER__ | |
33 | sms() | |
34 | #endif __SABER__ | |
35 | { | |
36 | int status; | |
37 | char *whoami; | |
38 | ||
39 | #ifndef __SABER__ | |
40 | whoami = argv[0]; | |
41 | #else | |
42 | whoami = "sms"; | |
43 | #endif __SABER__ | |
44 | ||
45 | init_ss_err_tbl(); | |
6e6374cb | 46 | |
59af7b90 | 47 | ss = ss_create_invocation("sms", "2.0", (char *)NULL, |
6e6374cb | 48 | &sms_test, &status); |
49 | if (status != 0) { | |
50 | com_err(whoami, status, "Unable to create invocation"); | |
51 | exit(1); | |
52 | } | |
53 | ss_listen(ss, &status); | |
54 | if (status != 0) { | |
55 | com_err(whoami, status, 0); | |
56 | exit(1); | |
57 | } | |
a4b41593 | 58 | exit(0); |
6e6374cb | 59 | } |
60 | ||
61 | test_noop() | |
62 | { | |
63 | int status = sms_noop(); | |
64 | if (status) ss_perror(ss, status, 0); | |
65 | } | |
66 | ||
59af7b90 | 67 | test_new() |
68 | { | |
69 | sending_version_no = SMS_VERSION_2; | |
70 | } | |
71 | ||
72 | test_old() | |
73 | { | |
74 | sending_version_no = SMS_VERSION_1; | |
75 | } | |
76 | ||
011e0a54 | 77 | test_connect(argc, argv) |
78 | int argc; | |
79 | char *argv[]; | |
6e6374cb | 80 | { |
94551bbc | 81 | char *server = "", serverbuf[256], *index(); |
011e0a54 | 82 | int status; |
83 | ||
94551bbc | 84 | if (argc > 1) { |
85 | server = argv[1]; | |
86 | if (index(server, ':') == NULL) { | |
87 | server = serverbuf; | |
88 | sprintf(serverbuf, "%s:%s", argv[1], "sms_db"); | |
89 | } | |
90 | } | |
011e0a54 | 91 | status = sms_connect(server); |
6e6374cb | 92 | if (status) ss_perror(ss, status, 0); |
93 | } | |
94 | ||
95 | test_disconnect() | |
96 | { | |
97 | int status = sms_disconnect(); | |
98 | if (status) ss_perror(ss, status, 0); | |
99 | } | |
100 | ||
66848930 | 101 | test_host() |
102 | { | |
103 | char host[BUFSIZ]; | |
104 | int status; | |
105 | ||
106 | bzero(host, sizeof(host)); | |
107 | ||
108 | if (status = sms_host(host, sizeof(host) - 1)) | |
109 | ss_perror(ss, status, 0); | |
110 | else | |
111 | printf("You are connected to host %s\n", host); | |
112 | } | |
113 | ||
6e6374cb | 114 | test_auth() |
115 | { | |
59af7b90 | 116 | int status; |
117 | ||
118 | status = sms_auth("smstest"); | |
6e6374cb | 119 | if (status) ss_perror(ss, status, 0); |
120 | } | |
121 | ||
58b825a4 | 122 | test_script(argc, argv) |
123 | int argc; | |
124 | char *argv[]; | |
125 | { | |
126 | FILE *inp; | |
127 | char input[BUFSIZ], *cp, *index(); | |
128 | int status, oldstdout, oldstderr; | |
129 | ||
130 | if (recursion > 8) { | |
131 | ss_perror(ss, 0, "too many levels deep in script files\n"); | |
132 | return; | |
133 | } | |
134 | ||
135 | if (argc < 2) { | |
136 | ss_perror(ss, 0, "Usage: script input_file [ output_file ]"); | |
137 | return; | |
138 | } | |
139 | ||
140 | inp = fopen(argv[1], "r"); | |
141 | if (inp == NULL) { | |
142 | ss_perror(ss, 0, "Cannot open input file %s", argv[1]); | |
143 | return; | |
144 | } | |
145 | ||
146 | if (argc == 3) { | |
147 | printf("Redirecting output to %s\n", argv[2]); | |
148 | fflush(stdout); | |
149 | oldstdout = dup(1); | |
150 | close(1); | |
151 | status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664); | |
152 | if (status != 1) { | |
153 | close(status); | |
154 | dup2(oldstdout, 1); | |
155 | argc = 2; | |
156 | ss_perror(ss, errno, "Unable to redirect output to %s\n", argv[2]); | |
157 | } else { | |
158 | fflush(stderr); | |
159 | oldstderr = dup(2); | |
160 | close(2); | |
161 | dup2(1, 2); | |
162 | } | |
163 | } | |
164 | ||
165 | recursion++; | |
166 | ||
167 | for(;;) { | |
168 | if (fgets(input, BUFSIZ, inp) == NULL) | |
169 | break; | |
170 | if ((cp = index(input, '\n')) != (char *)NULL) | |
171 | *cp = 0; | |
6a592314 | 172 | if (input[0] == 0) { |
173 | printf("\n"); | |
174 | continue; | |
175 | } | |
58b825a4 | 176 | if (input[0] == '%') { |
177 | for (cp = &input[1]; *cp && isspace(*cp); cp++); | |
178 | printf("Comment: %s\n", cp); | |
179 | continue; | |
180 | } | |
181 | printf("Executing: %s\n", input); | |
182 | ss_execute_line(ss, input, &status); | |
183 | if (status == SS_ET_COMMAND_NOT_FOUND) { | |
184 | printf("Bad command: %s\n", input); | |
185 | } | |
186 | } | |
187 | ||
188 | recursion--; | |
189 | ||
190 | fclose(inp); | |
191 | if (argc == 3) { | |
192 | fflush(stdout); | |
193 | close(1); | |
194 | dup2(oldstdout, 1); | |
195 | close(oldstdout); | |
196 | fflush(stderr); | |
197 | close(2); | |
198 | dup2(oldstderr, 2); | |
199 | close(oldstderr); | |
200 | } | |
201 | } | |
202 | ||
6e6374cb | 203 | char *concat(str1, str2) |
204 | char *str1, *str2; | |
205 | { | |
206 | char *rtn; | |
207 | extern char *malloc(); | |
208 | ||
209 | if (!str1) { | |
210 | int len = strlen(str2) + 1 ; | |
211 | rtn = malloc(len); | |
212 | bcopy(str2, rtn, len); | |
213 | } else { | |
214 | int len1 = strlen(str1); | |
215 | int len2 = strlen(str2) + 1; | |
216 | rtn = malloc(len1+len2); | |
217 | bcopy(str1, rtn, len1); | |
218 | bcopy(str2, rtn+len1, len2); | |
219 | } | |
220 | return rtn; | |
221 | } | |
222 | ||
6e6374cb | 223 | static int count; |
224 | ||
225 | ||
226 | print_reply(argc, argv) | |
227 | int argc; | |
228 | char **argv; | |
229 | { | |
230 | int i; | |
231 | for (i = 0; i < argc; i++) { | |
232 | if (i != 0) printf(", "); | |
233 | printf("%s", argv[i]); | |
234 | } | |
235 | printf("\n"); | |
236 | count++; | |
fc3ac28e | 237 | return(SMS_CONT); |
6e6374cb | 238 | } |
239 | ||
240 | test_query(argc, argv) | |
241 | int argc; | |
242 | char **argv; | |
243 | { | |
244 | int status; | |
245 | if (argc < 2) { | |
246 | ss_perror(ss, 0, "Usage: query handle [ args ... ]"); | |
247 | return; | |
248 | } | |
59af7b90 | 249 | |
6e6374cb | 250 | count = 0; |
251 | status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL); | |
303cb414 | 252 | printf("%d tuple%s\n", count, ((count == 1) ? "" : "s")); |
6e6374cb | 253 | if (status) ss_perror(ss, status, 0); |
254 | } | |
255 | ||
256 | test_access(argc, argv) | |
257 | int argc; | |
258 | char **argv; | |
259 | { | |
260 | int status; | |
261 | if (argc < 2) { | |
262 | ss_perror(ss, 0, "Usage: access handle [ args ... ]"); | |
263 | return; | |
264 | } | |
265 | status = sms_access(argv[1], argc-2, argv+2); | |
266 | if (status) ss_perror(ss, status, 0); | |
267 | } | |
fc3ac28e | 268 | |
269 | ||
270 | test_dcm(argc, argv) | |
271 | int argc; | |
272 | char **argv; | |
273 | { | |
274 | int status; | |
275 | ||
276 | if (status = sms_do_update()) | |
277 | ss_perror(ss, status, " while triggering dcm"); | |
278 | } | |
093b57b1 | 279 | |
280 | ||
281 | test_motd(argc, argv) | |
282 | int argc; | |
283 | char **argv; | |
284 | { | |
285 | int status; | |
286 | char *motd; | |
287 | ||
288 | if (status = sms_motd(&motd)) | |
289 | ss_perror(ss, status, " while getting motd"); | |
290 | if (motd) | |
291 | printf("%s\n", motd); | |
292 | else | |
293 | printf("No message of the day.\n"); | |
294 | } |