]> andersk Git - moira.git/blame - clients/mrtest/mrtest.c
improve parsing of arguement to connect
[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>
6e6374cb 20#include <sms.h>
21#include <ss.h>
22
23int ss;
58b825a4 24int recursion = 0;
6e6374cb 25extern ss_request_table sms_test;
59af7b90 26extern int sending_version_no;
6e6374cb 27
28#ifndef __SABER__
29main(argc, argv)
30 int argc;
31 char **argv;
32#else __SABER__
33sms()
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 }
a4b41593 60 exit(0);
6e6374cb 61}
62
63test_noop()
64{
65 int status = sms_noop();
66 if (status) ss_perror(ss, status, 0);
67}
68
59af7b90 69test_new()
70{
71 sending_version_no = SMS_VERSION_2;
72}
73
74test_old()
75{
76 sending_version_no = SMS_VERSION_1;
77}
78
011e0a54 79test_connect(argc, argv)
80int argc;
81char *argv[];
6e6374cb 82{
94551bbc 83 char *server = "", serverbuf[256], *index();
011e0a54 84 int status;
85
94551bbc 86 if (argc > 1) {
87 server = argv[1];
88 if (index(server, ':') == NULL) {
89 server = serverbuf;
90 sprintf(serverbuf, "%s:%s", argv[1], "sms_db");
91 }
92 }
011e0a54 93 status = sms_connect(server);
6e6374cb 94 if (status) ss_perror(ss, status, 0);
95}
96
97test_disconnect()
98{
99 int status = sms_disconnect();
100 if (status) ss_perror(ss, status, 0);
101}
102
103test_auth()
104{
59af7b90 105 int status;
106
107 status = sms_auth("smstest");
6e6374cb 108 if (status) ss_perror(ss, status, 0);
109}
110
58b825a4 111test_script(argc, argv)
112int argc;
113char *argv[];
114{
115 FILE *inp;
116 char input[BUFSIZ], *cp, *index();
117 int status, oldstdout, oldstderr;
118
119 if (recursion > 8) {
120 ss_perror(ss, 0, "too many levels deep in script files\n");
121 return;
122 }
123
124 if (argc < 2) {
125 ss_perror(ss, 0, "Usage: script input_file [ output_file ]");
126 return;
127 }
128
129 inp = fopen(argv[1], "r");
130 if (inp == NULL) {
131 ss_perror(ss, 0, "Cannot open input file %s", argv[1]);
132 return;
133 }
134
135 if (argc == 3) {
136 printf("Redirecting output to %s\n", argv[2]);
137 fflush(stdout);
138 oldstdout = dup(1);
139 close(1);
140 status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664);
141 if (status != 1) {
142 close(status);
143 dup2(oldstdout, 1);
144 argc = 2;
145 ss_perror(ss, errno, "Unable to redirect output to %s\n", argv[2]);
146 } else {
147 fflush(stderr);
148 oldstderr = dup(2);
149 close(2);
150 dup2(1, 2);
151 }
152 }
153
154 recursion++;
155
156 for(;;) {
157 if (fgets(input, BUFSIZ, inp) == NULL)
158 break;
159 if ((cp = index(input, '\n')) != (char *)NULL)
160 *cp = 0;
6a592314 161 if (input[0] == 0) {
162 printf("\n");
163 continue;
164 }
58b825a4 165 if (input[0] == '%') {
166 for (cp = &input[1]; *cp && isspace(*cp); cp++);
167 printf("Comment: %s\n", cp);
168 continue;
169 }
170 printf("Executing: %s\n", input);
171 ss_execute_line(ss, input, &status);
172 if (status == SS_ET_COMMAND_NOT_FOUND) {
173 printf("Bad command: %s\n", input);
174 }
175 }
176
177 recursion--;
178
179 fclose(inp);
180 if (argc == 3) {
181 fflush(stdout);
182 close(1);
183 dup2(oldstdout, 1);
184 close(oldstdout);
185 fflush(stderr);
186 close(2);
187 dup2(oldstderr, 2);
188 close(oldstderr);
189 }
190}
191
6e6374cb 192char *concat(str1, str2)
193 char *str1, *str2;
194{
195 char *rtn;
196 extern char *malloc();
197
198 if (!str1) {
199 int len = strlen(str2) + 1 ;
200 rtn = malloc(len);
201 bcopy(str2, rtn, len);
202 } else {
203 int len1 = strlen(str1);
204 int len2 = strlen(str2) + 1;
205 rtn = malloc(len1+len2);
206 bcopy(str1, rtn, len1);
207 bcopy(str2, rtn+len1, len2);
208 }
209 return rtn;
210}
211
6e6374cb 212static int count;
213
214
215print_reply(argc, argv)
216 int argc;
217 char **argv;
218{
219 int i;
220 for (i = 0; i < argc; i++) {
221 if (i != 0) printf(", ");
222 printf("%s", argv[i]);
223 }
224 printf("\n");
225 count++;
fc3ac28e 226 return(SMS_CONT);
6e6374cb 227}
228
229test_query(argc, argv)
230 int argc;
231 char **argv;
232{
233 int status;
234 if (argc < 2) {
235 ss_perror(ss, 0, "Usage: query handle [ args ... ]");
236 return;
237 }
59af7b90 238
6e6374cb 239 count = 0;
240 status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
303cb414 241 printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
6e6374cb 242 if (status) ss_perror(ss, status, 0);
243}
244
245test_access(argc, argv)
246 int argc;
247 char **argv;
248{
249 int status;
250 if (argc < 2) {
251 ss_perror(ss, 0, "Usage: access handle [ args ... ]");
252 return;
253 }
254 status = sms_access(argv[1], argc-2, argv+2);
255 if (status) ss_perror(ss, status, 0);
256}
fc3ac28e 257
258
259test_dcm(argc, argv)
260 int argc;
261 char **argv;
262{
263 int status;
264
265 if (status = sms_do_update())
266 ss_perror(ss, status, " while triggering dcm");
267}
This page took 0.090401 seconds and 5 git commands to generate.