Remove the RCSID macro
[openafs.git] / src / ubik / utst_client.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <afs/stds.h>
13
14
15 #include <sys/types.h>
16 #ifdef AFS_NT40_ENV
17 #include <winsock2.h>
18 #include <afsutil.h>
19 #else
20 #include <sys/file.h>
21 #include <netdb.h>
22 #include <netinet/in.h>
23 #endif
24 #include <time.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <rx/xdr.h>
28 #include <rx/rx.h>
29 #include <lock.h>
30 #include "ubik.h"
31 #include "utst_int.h"
32
33 /* main program */
34
35 #include "AFS_component_version_number.c"
36
37 int
38 main(int argc, char **argv)
39 {
40     register afs_int32 code;
41     struct ubik_client *cstruct = 0;
42     afs_int32 serverList[MAXSERVERS];
43     struct rx_connection *serverconns[MAXSERVERS];
44     struct rx_securityClass *sc;
45     register afs_int32 i;
46     afs_int32 temp;
47
48     if (argc == 1) {
49         printf
50             ("uclient: usage is 'uclient -servers ... [-try] [-get] [-inc] [-minc] [-trunc]\n");
51         exit(0);
52     }
53 #ifdef AFS_NT40_ENV
54     /* initialize winsock */
55     if (afs_winsockInit() < 0)
56         return -1;
57 #endif
58     /* first parse '-servers <server-1> <server-2> ... <server-n>' from command line */
59     code = ubik_ParseClientList(argc, argv, serverList);
60     if (code) {
61         printf("could not parse server list, code %d\n", code);
62         exit(1);
63     }
64     rx_Init(0);
65     sc = rxnull_NewClientSecurityObject();
66     for (i = 0; i < MAXSERVERS; i++) {
67         if (serverList[i]) {
68             serverconns[i] =
69                 rx_NewConnection(serverList[i], htons(3000), USER_SERVICE_ID,
70                                  sc, 0);
71         } else {
72             serverconns[i] = (struct rx_connection *)0;
73             break;
74         }
75     }
76
77     /* next, pass list of server rx_connections (in serverconns), and
78      * a place to put the returned client structure that we'll use in
79      * all of our rpc calls (via ubik_Calll) */
80     code = ubik_ClientInit(serverconns, &cstruct);
81
82     /* check code from init */
83     if (code) {
84         printf("ubik client init failed with code %d\n", code);
85         exit(1);
86     }
87
88     /* parse command line for our own operations */
89     for (i = 1; i < argc; i++) {
90         if (!strcmp(argv[i], "-inc")) {
91             /* use ubik_Call to do the work, finding an up server and handling
92              * the job of finding a sync site, if need be */
93             code = ubik_SAMPLE_Inc(cstruct, 0);
94             printf("return code is %d\n", code);
95         } else if (!strcmp(argv[i], "-try")) {
96             code = ubik_SAMPLE_Test(cstruct, 0);
97             printf("return code is %d\n", code);
98         } else if (!strcmp(argv[i], "-qget")) {
99             code = ubik_SAMPLE_QGet(cstruct, 0, &temp);
100             printf("got quick value %d (code %d)\n", temp, code);
101         } else if (!strcmp(argv[i], "-get")) {
102             code = ubik_SAMPLE_Get(cstruct, 0, &temp);
103             printf("got value %d (code %d)\n", temp, code);
104         } else if (!strcmp(argv[i], "-trunc")) {
105             code = ubik_SAMPLE_Trun(cstruct, 0);
106             printf("return code is %d\n", code);
107         } else if (!strcmp(argv[i], "-minc")) {
108             afs_int32 temp;
109             struct timeval tv;
110             tv.tv_sec = 1;
111             tv.tv_usec = 0;
112             printf("ubik_client: Running minc...\n");
113
114             while (1) {
115                 temp = 0;
116                 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
117                 if (code != 0) {
118                     printf("SAMPLE_Get #1 failed with code %ld\n", code);
119                 } else {
120                     printf("SAMPLE_Get #1 succeeded, got value %d\n", temp);
121                 }
122
123                 temp = 0;
124                 code = ubik_SAMPLE_Inc(cstruct, 0);
125                 if (code != 0) {
126                     printf("SAMPLE_Inc #1 failed with code %ld\n", 
127                            afs_cast_int32(code));
128                 } else {
129                     printf("SAMPLE_Inc #1 succeeded, incremented integer\n");
130                 }
131                 temp = 0;
132                 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
133                 if (code != 0) {
134                     printf("SAMPLE_Get #2 failed with code %ld\n", code);
135                 } else {
136                     printf("SAMPLE_Get #2 succeeded, got value %d\n", temp);
137                 }
138
139                 temp = 0;
140                 code = ubik_SAMPLE_Inc(cstruct, 0);
141                 if (code != 0)
142                     printf("SAMPLE_Inc #2 failed with code %ld\n", 
143                            afs_cast_int32(code));
144                 else
145                     printf("SAMPLE_Inc #2 succeeded, incremented integer\n");
146
147                 tv.tv_sec = 1;
148                 tv.tv_usec = 0;
149 #ifdef AFS_PTHREAD_ENV
150                 select(0, 0, 0, 0, &tv);
151 #else
152                 IOMGR_Select(0, 0, 0, 0, &tv);
153 #endif
154                 printf("Repeating the SAMPLE operations again...\n");
155             }
156         } else if (!strcmp(argv[i], "-mget")) {
157             afs_int32 temp;
158             struct timeval tv;
159             tv.tv_sec = 1;
160             tv.tv_usec = 0;
161             while (1) {
162                 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
163                 printf("got value %d (code %d)\n", temp, code);
164
165                 code = ubik_SAMPLE_Inc(cstruct, 0);
166                 printf("update return code is %d\n", code);
167
168                 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
169                 printf("got value %d (code %d)\n", temp, code);
170
171                 code = ubik_SAMPLE_Get(cstruct, 0, &temp);
172                 printf("got value %d (code %d)\n", temp, code);
173
174                 tv.tv_sec = 1;
175                 tv.tv_usec = 0;
176 #ifdef AFS_PTHREAD_ENV
177                 select(0, 0, 0, 0, &tv);
178 #else
179                 IOMGR_Select(0, 0, 0, 0, &tv);
180 #endif
181             }
182         }
183     }
184     return 0;
185 }