]>
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(); | |
46 | init_sms_err_tbl(); | |
47 | init_krb_err_tbl(); | |
48 | ||
59af7b90 | 49 | ss = ss_create_invocation("sms", "2.0", (char *)NULL, |
6e6374cb | 50 | &sms_test, &status); |
51 | if (status != 0) { | |
52 | com_err(whoami, status, "Unable to create invocation"); | |
53 | exit(1); | |
54 | } | |
55 | ss_listen(ss, &status); | |
56 | if (status != 0) { | |
57 | com_err(whoami, status, 0); | |
58 | exit(1); | |
59 | } | |
60 | } | |
61 | ||
62 | test_noop() | |
63 | { | |
64 | int status = sms_noop(); | |
65 | if (status) ss_perror(ss, status, 0); | |
66 | } | |
67 | ||
59af7b90 | 68 | test_new() |
69 | { | |
70 | sending_version_no = SMS_VERSION_2; | |
71 | } | |
72 | ||
73 | test_old() | |
74 | { | |
75 | sending_version_no = SMS_VERSION_1; | |
76 | } | |
77 | ||
011e0a54 | 78 | test_connect(argc, argv) |
79 | int argc; | |
80 | char *argv[]; | |
6e6374cb | 81 | { |
011e0a54 | 82 | char *server = ""; |
83 | int status; | |
84 | ||
85 | if (argc > 1) | |
86 | server = argv[1]; | |
87 | status = sms_connect(server); | |
6e6374cb | 88 | if (status) ss_perror(ss, status, 0); |
89 | } | |
90 | ||
91 | test_disconnect() | |
92 | { | |
93 | int status = sms_disconnect(); | |
94 | if (status) ss_perror(ss, status, 0); | |
95 | } | |
96 | ||
97 | test_auth() | |
98 | { | |
59af7b90 | 99 | int status; |
100 | ||
101 | status = sms_auth("smstest"); | |
6e6374cb | 102 | if (status) ss_perror(ss, status, 0); |
103 | } | |
104 | ||
58b825a4 | 105 | test_script(argc, argv) |
106 | int argc; | |
107 | char *argv[]; | |
108 | { | |
109 | FILE *inp; | |
110 | char input[BUFSIZ], *cp, *index(); | |
111 | int status, oldstdout, oldstderr; | |
112 | ||
113 | if (recursion > 8) { | |
114 | ss_perror(ss, 0, "too many levels deep in script files\n"); | |
115 | return; | |
116 | } | |
117 | ||
118 | if (argc < 2) { | |
119 | ss_perror(ss, 0, "Usage: script input_file [ output_file ]"); | |
120 | return; | |
121 | } | |
122 | ||
123 | inp = fopen(argv[1], "r"); | |
124 | if (inp == NULL) { | |
125 | ss_perror(ss, 0, "Cannot open input file %s", argv[1]); | |
126 | return; | |
127 | } | |
128 | ||
129 | if (argc == 3) { | |
130 | printf("Redirecting output to %s\n", argv[2]); | |
131 | fflush(stdout); | |
132 | oldstdout = dup(1); | |
133 | close(1); | |
134 | status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664); | |
135 | if (status != 1) { | |
136 | close(status); | |
137 | dup2(oldstdout, 1); | |
138 | argc = 2; | |
139 | ss_perror(ss, errno, "Unable to redirect output to %s\n", argv[2]); | |
140 | } else { | |
141 | fflush(stderr); | |
142 | oldstderr = dup(2); | |
143 | close(2); | |
144 | dup2(1, 2); | |
145 | } | |
146 | } | |
147 | ||
148 | recursion++; | |
149 | ||
150 | for(;;) { | |
151 | if (fgets(input, BUFSIZ, inp) == NULL) | |
152 | break; | |
153 | if ((cp = index(input, '\n')) != (char *)NULL) | |
154 | *cp = 0; | |
6a592314 | 155 | if (input[0] == 0) { |
156 | printf("\n"); | |
157 | continue; | |
158 | } | |
58b825a4 | 159 | if (input[0] == '%') { |
160 | for (cp = &input[1]; *cp && isspace(*cp); cp++); | |
161 | printf("Comment: %s\n", cp); | |
162 | continue; | |
163 | } | |
164 | printf("Executing: %s\n", input); | |
165 | ss_execute_line(ss, input, &status); | |
166 | if (status == SS_ET_COMMAND_NOT_FOUND) { | |
167 | printf("Bad command: %s\n", input); | |
168 | } | |
169 | } | |
170 | ||
171 | recursion--; | |
172 | ||
173 | fclose(inp); | |
174 | if (argc == 3) { | |
175 | fflush(stdout); | |
176 | close(1); | |
177 | dup2(oldstdout, 1); | |
178 | close(oldstdout); | |
179 | fflush(stderr); | |
180 | close(2); | |
181 | dup2(oldstderr, 2); | |
182 | close(oldstderr); | |
183 | } | |
184 | } | |
185 | ||
6e6374cb | 186 | char *concat(str1, str2) |
187 | char *str1, *str2; | |
188 | { | |
189 | char *rtn; | |
190 | extern char *malloc(); | |
191 | ||
192 | if (!str1) { | |
193 | int len = strlen(str2) + 1 ; | |
194 | rtn = malloc(len); | |
195 | bcopy(str2, rtn, len); | |
196 | } else { | |
197 | int len1 = strlen(str1); | |
198 | int len2 = strlen(str2) + 1; | |
199 | rtn = malloc(len1+len2); | |
200 | bcopy(str1, rtn, len1); | |
201 | bcopy(str2, rtn+len1, len2); | |
202 | } | |
203 | return rtn; | |
204 | } | |
205 | ||
6e6374cb | 206 | static int count; |
207 | ||
208 | ||
209 | print_reply(argc, argv) | |
210 | int argc; | |
211 | char **argv; | |
212 | { | |
213 | int i; | |
214 | for (i = 0; i < argc; i++) { | |
215 | if (i != 0) printf(", "); | |
216 | printf("%s", argv[i]); | |
217 | } | |
218 | printf("\n"); | |
219 | count++; | |
fc3ac28e | 220 | return(SMS_CONT); |
6e6374cb | 221 | } |
222 | ||
223 | test_query(argc, argv) | |
224 | int argc; | |
225 | char **argv; | |
226 | { | |
227 | int status; | |
228 | if (argc < 2) { | |
229 | ss_perror(ss, 0, "Usage: query handle [ args ... ]"); | |
230 | return; | |
231 | } | |
59af7b90 | 232 | |
6e6374cb | 233 | count = 0; |
234 | status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL); | |
303cb414 | 235 | printf("%d tuple%s\n", count, ((count == 1) ? "" : "s")); |
6e6374cb | 236 | if (status) ss_perror(ss, status, 0); |
237 | } | |
238 | ||
239 | test_access(argc, argv) | |
240 | int argc; | |
241 | char **argv; | |
242 | { | |
243 | int status; | |
244 | if (argc < 2) { | |
245 | ss_perror(ss, 0, "Usage: access handle [ args ... ]"); | |
246 | return; | |
247 | } | |
248 | status = sms_access(argv[1], argc-2, argv+2); | |
249 | if (status) ss_perror(ss, status, 0); | |
250 | } | |
fc3ac28e | 251 | |
252 | ||
253 | test_dcm(argc, argv) | |
254 | int argc; | |
255 | char **argv; | |
256 | { | |
257 | int status; | |
258 | ||
259 | if (status = sms_do_update()) | |
260 | ss_perror(ss, status, " while triggering dcm"); | |
261 | } |