]> andersk Git - moira.git/blame - clients/mrtest/mrtest.c
sms -> moira
[moira.git] / clients / mrtest / mrtest.c
CommitLineData
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
13static 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>
8defc06b 20#include <moira.h>
6e6374cb 21#include <ss.h>
22
23int ss;
58b825a4 24int recursion = 0;
da971797 25extern ss_request_table moira_test;
59af7b90 26extern int sending_version_no;
6e6374cb 27
28#ifndef __SABER__
29main(argc, argv)
30 int argc;
31 char **argv;
32#else __SABER__
da971797 33moira()
6e6374cb 34#endif __SABER__
35{
36 int status;
37 char *whoami;
38
39#ifndef __SABER__
40 whoami = argv[0];
41#else
da971797 42 whoami = "mrtest";
6e6374cb 43#endif __SABER__
44
45 init_ss_err_tbl();
6e6374cb 46
da971797 47 ss = ss_create_invocation("moira", "2.0", (char *)NULL,
48 &moira_test, &status);
6e6374cb 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
61test_noop()
62{
8defc06b 63 int status = mr_noop();
972d0244 64 if (status) ss_perror(ss, status, "");
6e6374cb 65}
66
59af7b90 67test_new()
68{
8defc06b 69 sending_version_no = MR_VERSION_2;
59af7b90 70}
71
72test_old()
73{
8defc06b 74 sending_version_no = MR_VERSION_1;
59af7b90 75}
76
011e0a54 77test_connect(argc, argv)
78int argc;
79char *argv[];
6e6374cb 80{
1b93a421 81 char *server = "", *index();
011e0a54 82 int status;
83
94551bbc 84 if (argc > 1) {
85 server = argv[1];
94551bbc 86 }
8defc06b 87 status = mr_connect(server);
972d0244 88 if (status) ss_perror(ss, status, "");
6e6374cb 89}
90
91test_disconnect()
92{
8defc06b 93 int status = mr_disconnect();
972d0244 94 if (status) ss_perror(ss, status, "");
6e6374cb 95}
96
66848930 97test_host()
98{
99 char host[BUFSIZ];
100 int status;
101
102 bzero(host, sizeof(host));
103
8defc06b 104 if (status = mr_host(host, sizeof(host) - 1))
972d0244 105 ss_perror(ss, status, "");
66848930 106 else
107 printf("You are connected to host %s\n", host);
108}
109
6e6374cb 110test_auth()
111{
59af7b90 112 int status;
113
8defc06b 114 status = mr_auth("mrtest");
972d0244 115 if (status) ss_perror(ss, status, "");
6e6374cb 116}
117
58b825a4 118test_script(argc, argv)
119int argc;
120char *argv[];
121{
122 FILE *inp;
123 char input[BUFSIZ], *cp, *index();
124 int status, oldstdout, oldstderr;
125
126 if (recursion > 8) {
127 ss_perror(ss, 0, "too many levels deep in script files\n");
128 return;
129 }
130
131 if (argc < 2) {
132 ss_perror(ss, 0, "Usage: script input_file [ output_file ]");
133 return;
134 }
135
136 inp = fopen(argv[1], "r");
137 if (inp == NULL) {
138 ss_perror(ss, 0, "Cannot open input file %s", argv[1]);
139 return;
140 }
141
142 if (argc == 3) {
143 printf("Redirecting output to %s\n", argv[2]);
144 fflush(stdout);
145 oldstdout = dup(1);
146 close(1);
147 status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664);
148 if (status != 1) {
149 close(status);
150 dup2(oldstdout, 1);
151 argc = 2;
152 ss_perror(ss, errno, "Unable to redirect output to %s\n", argv[2]);
153 } else {
154 fflush(stderr);
155 oldstderr = dup(2);
156 close(2);
157 dup2(1, 2);
158 }
159 }
160
161 recursion++;
162
163 for(;;) {
164 if (fgets(input, BUFSIZ, inp) == NULL)
165 break;
166 if ((cp = index(input, '\n')) != (char *)NULL)
167 *cp = 0;
6a592314 168 if (input[0] == 0) {
169 printf("\n");
170 continue;
171 }
58b825a4 172 if (input[0] == '%') {
173 for (cp = &input[1]; *cp && isspace(*cp); cp++);
174 printf("Comment: %s\n", cp);
175 continue;
176 }
177 printf("Executing: %s\n", input);
178 ss_execute_line(ss, input, &status);
179 if (status == SS_ET_COMMAND_NOT_FOUND) {
180 printf("Bad command: %s\n", input);
181 }
182 }
183
184 recursion--;
185
186 fclose(inp);
187 if (argc == 3) {
188 fflush(stdout);
189 close(1);
190 dup2(oldstdout, 1);
191 close(oldstdout);
192 fflush(stderr);
193 close(2);
194 dup2(oldstderr, 2);
195 close(oldstderr);
196 }
197}
198
6e6374cb 199char *concat(str1, str2)
200 char *str1, *str2;
201{
202 char *rtn;
203 extern char *malloc();
204
205 if (!str1) {
206 int len = strlen(str2) + 1 ;
207 rtn = malloc(len);
208 bcopy(str2, rtn, len);
209 } else {
210 int len1 = strlen(str1);
211 int len2 = strlen(str2) + 1;
212 rtn = malloc(len1+len2);
213 bcopy(str1, rtn, len1);
214 bcopy(str2, rtn+len1, len2);
215 }
216 return rtn;
217}
218
6e6374cb 219static int count;
220
221
222print_reply(argc, argv)
223 int argc;
224 char **argv;
225{
226 int i;
227 for (i = 0; i < argc; i++) {
228 if (i != 0) printf(", ");
229 printf("%s", argv[i]);
230 }
231 printf("\n");
232 count++;
8defc06b 233 return(MR_CONT);
6e6374cb 234}
235
236test_query(argc, argv)
237 int argc;
238 char **argv;
239{
240 int status;
241 if (argc < 2) {
242 ss_perror(ss, 0, "Usage: query handle [ args ... ]");
243 return;
244 }
59af7b90 245
6e6374cb 246 count = 0;
8defc06b 247 status = mr_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
303cb414 248 printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
972d0244 249 if (status) ss_perror(ss, status, "");
6e6374cb 250}
251
252test_access(argc, argv)
253 int argc;
254 char **argv;
255{
256 int status;
257 if (argc < 2) {
258 ss_perror(ss, 0, "Usage: access handle [ args ... ]");
259 return;
260 }
8defc06b 261 status = mr_access(argv[1], argc-2, argv+2);
972d0244 262 if (status) ss_perror(ss, status, "");
6e6374cb 263}
fc3ac28e 264
265
266test_dcm(argc, argv)
267 int argc;
268 char **argv;
269{
270 int status;
271
8defc06b 272 if (status = mr_do_update())
fc3ac28e 273 ss_perror(ss, status, " while triggering dcm");
274}
093b57b1 275
276
277test_motd(argc, argv)
278 int argc;
279 char **argv;
280{
281 int status;
282 char *motd;
283
8defc06b 284 if (status = mr_motd(&motd))
093b57b1 285 ss_perror(ss, status, " while getting motd");
286 if (motd)
287 printf("%s\n", motd);
288 else
289 printf("No message of the day.\n");
290}
This page took 0.106548 seconds and 5 git commands to generate.