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