Standardize License information
[openafs.git] / src / libadmin / samples / cm_client_config.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 /*
11  * This file contains sample code for the client admin interface 
12  */
13
14 #ifdef AFS_NT40_ENV
15 #include <winsock2.h>
16 #include <pthread.h>
17 #endif
18 #include <afs/afs_Admin.h>
19 #include <afs/afs_clientAdmin.h>
20 #include <afs/afs_utilAdmin.h>
21
22 void Usage()
23 {
24     fprintf(stderr,
25             "Usage: cm_client_config <host> <port>\n");
26     exit(1);
27 }
28
29 void ParseArgs(
30     int argc,
31     char *argv[],
32     char **srvrName,
33     long *srvrPort)
34 {
35     char **argp = argv;
36
37     if (!*(++argp))
38         Usage();
39     *srvrName = *(argp++);
40     if (!*(argp))
41         Usage();
42     *srvrPort = strtol(*(argp++), NULL, 0);
43     if (*srvrPort <= 0 || *srvrPort >= 65536)
44         Usage();
45     if (*(argp))
46         Usage();
47 }
48
49 int main(int argc, char *argv[])
50 {
51     int rc;
52     afs_status_t st = 0;
53     struct rx_connection *conn;
54     char *srvrName;
55     long srvrPort;
56     void *cellHandle;
57     afs_ClientConfig_t config;
58
59     ParseArgs(argc, argv, &srvrName, &srvrPort);
60
61     rc = afsclient_Init(&st);
62     if (!rc) {
63         fprintf(stderr, "afsclient_Init, status %d\n", st);
64         exit(1);
65     }
66
67     rc = afsclient_NullCellOpen(&cellHandle, &st);
68     if (!rc) {
69         fprintf(stderr, "afsclient_NullCellsOpen, status %d\n", st);
70         exit(1);
71     }
72
73     rc = afsclient_CMStatOpenPort(cellHandle, srvrName, srvrPort, &conn, &st);
74     if (!rc) {
75         fprintf(stderr, "afsclient_CMStatOpenPort, status %d\n", st);
76         exit(1);
77     }
78
79     rc = util_CMClientConfig(conn, &config, &st);
80     if (!rc) {
81         fprintf(stderr, "util_CMClientConfig, status %d\n", st);
82         exit(1);
83     }
84
85     rc = afsclient_CMStatClose(conn, &st);
86     if (!rc) {
87         fprintf(stderr, "afsclient_CMStatClose, status %d\n", st);
88         exit(1);
89     }
90
91     rc = afsclient_CellClose(cellHandle, &st);
92     if (!rc) {
93         fprintf(stderr, "afsclient_CellClose, status %d\n", st);
94         exit(1);
95     }
96
97     
98     printf("\nClient configuration for %s (port %d):\n\n",
99            srvrName, srvrPort);
100     printf("    clientVersion:  %d\n", config.clientVersion);
101     printf("    serverVersion:  %d\n", config.serverVersion);
102     printf("    nChunkFiles:    %d\n", config.c.config_v1.nChunkFiles);
103     printf("    nStatCaches:    %d\n", config.c.config_v1.nStatCaches);
104     printf("    nDataCaches:    %d\n", config.c.config_v1.nDataCaches);
105     printf("    nVolumeCaches:  %d\n", config.c.config_v1.nVolumeCaches);
106     printf("    firstChunkSize: %d\n", config.c.config_v1.firstChunkSize);
107     printf("    otherChunkSize: %d\n", config.c.config_v1.otherChunkSize);
108     printf("    cacheSize:      %d\n", config.c.config_v1.cacheSize);
109     printf("    setTime:        %d\n", config.c.config_v1.setTime);
110     printf("    memCache:       %d\n", config.c.config_v1.memCache);
111     printf("\n");
112
113     exit(0);
114 }