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