]> andersk Git - moira.git/blame - clients/mrtest/mrtest.c
fix some previously uninitialized fields in the log files &
[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
7 *
6e6374cb 8 */
9
10#ifndef lint
11static char *rcsid_test_c = "$Header$";
12#endif lint
13
14#include <stdio.h>
58b825a4 15#include <sys/file.h>
16#include <ctype.h>
6e6374cb 17#include <sms.h>
18#include <ss.h>
19
20int ss;
58b825a4 21int recursion = 0;
6e6374cb 22extern ss_request_table sms_test;
59af7b90 23extern int sending_version_no;
6e6374cb 24
25#ifndef __SABER__
26main(argc, argv)
27 int argc;
28 char **argv;
29#else __SABER__
30sms()
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
59af7b90 46 ss = ss_create_invocation("sms", "2.0", (char *)NULL,
6e6374cb 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
59test_noop()
60{
61 int status = sms_noop();
62 if (status) ss_perror(ss, status, 0);
63}
64
59af7b90 65test_new()
66{
67 sending_version_no = SMS_VERSION_2;
68}
69
70test_old()
71{
72 sending_version_no = SMS_VERSION_1;
73}
74
6e6374cb 75test_connect()
76{
77 int status = sms_connect();
78 if (status) ss_perror(ss, status, 0);
79}
80
81test_disconnect()
82{
83 int status = sms_disconnect();
84 if (status) ss_perror(ss, status, 0);
85}
86
87test_auth()
88{
59af7b90 89 int status;
90
91 status = sms_auth("smstest");
6e6374cb 92 if (status) ss_perror(ss, status, 0);
93}
94
58b825a4 95test_script(argc, argv)
96int argc;
97char *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;
6a592314 145 if (input[0] == 0) {
146 printf("\n");
147 continue;
148 }
58b825a4 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
6e6374cb 176char *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
6e6374cb 196static int count;
197
198
199print_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++;
fc3ac28e 210 return(SMS_CONT);
6e6374cb 211}
212
213test_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 }
59af7b90 222
6e6374cb 223 count = 0;
224 status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
303cb414 225 printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
6e6374cb 226 if (status) ss_perror(ss, status, 0);
227}
228
229test_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}
fc3ac28e 241
242
243test_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}
This page took 0.094601 seconds and 5 git commands to generate.