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