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