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