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