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