Add rxgk client options to vl and pt utilities
[openafs.git] / src / ptserver / display.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 #include <roken.h>
15
16 #include "ptserver.h"
17 #include "display.h"
18
19 static char *
20 pr_TimeToString(time_t clock)
21 {
22     struct tm *tm;
23     static char buffer[32];
24     static int this_year = 0;
25
26     if (clock == 0)
27         return "time-not-set  ";
28     if (!this_year) {
29         time_t now = time(0);
30         tm = localtime(&now);
31         this_year = tm->tm_year;
32     }
33     tm = localtime(&clock);
34     if (tm->tm_year != this_year)
35         strftime(buffer, 32, "%m/%d/%Y %H:%M:%S", tm);
36     else
37         strftime(buffer, 32, "%m/%d %H:%M:%S", tm);
38     return buffer;
39 }
40
41 #define host(a) (hostOrder ? (a) : ntohl(a))
42
43 #define PRINT_COMMON_FIELDS(e)                                             \
44 do {                                                                       \
45     int i;                                                                 \
46     if ((e)->cellid)                                                       \
47         fprintf(f, "cellid == %d\n", host((e)->cellid));                   \
48     for (i = 0; i < sizeof((e)->reserved) / sizeof((e)->reserved[0]); i++) \
49         if ((e)->reserved[i])                                              \
50             fprintf(f, "reserved field [%d] not zero: %d\n", i,            \
51                     host((e)->reserved[i]));                               \
52     fprintf(f, "%*s", indent, "");                                         \
53     fprintf(f, "Entry at %d: flags 0x%x, id %di, next %d.\n", ea,          \
54             host((e)->flags), host((e)->id), host((e)->next));             \
55 } while (0)
56
57 #define PRINT_IDS(e)                                                       \
58 do {                                                                       \
59     int i;                                                                 \
60     int newline = 0;                                                       \
61     for (i = 0; i < sizeof((e)->entries)/sizeof((e)->entries[0]); i++) {   \
62         if ((e)->entries[i] == 0)                                          \
63             break;                                                         \
64         if (i == 0)                                                        \
65             fprintf(f, "%*sids ", indent, "");                             \
66         else if (newline == 0)                                             \
67             fprintf(f, "%*s", indent + 4, "");                             \
68         if (host((e)->entries[i]) == PRBADID)                              \
69             fprintf(f, " EMPTY");                                          \
70         else                                                               \
71             fprintf(f, "%6d", host((e)->entries[i]));                      \
72         newline = 1;                                                       \
73         if (i % 10 == 9) {                                                 \
74             fprintf(f, "\n");                                              \
75             newline = 0;                                                   \
76         } else                                                             \
77             fprintf(f, " ");                                               \
78     }                                                                      \
79     if (newline)                                                           \
80         fprintf(f, "\n");                                                  \
81 } while (0)
82
83 /* regular entry */
84 int
85 pr_PrintEntry(FILE *f, int hostOrder, afs_int32 ea, struct prentry *e,
86               int indent)
87 {
88     /* In case we are given the wrong type of entry. */
89     if ((host(e->flags) & PRTYPE) == PRCONT) {
90         struct contentry c;
91         memcpy(&c, e, sizeof(c));
92         return pr_PrintContEntry(f, hostOrder, ea, &c, indent);
93     }
94
95     PRINT_COMMON_FIELDS(e);
96     fprintf(f, "%*s", indent, "");
97     fprintf(f, "c:%s ", pr_TimeToString(host(e->createTime)));
98     fprintf(f, "a:%s ", pr_TimeToString(host(e->addTime)));
99     fprintf(f, "r:%s ", pr_TimeToString(host(e->removeTime)));
100     fprintf(f, "n:%s\n", pr_TimeToString(host(e->changeTime)));
101     PRINT_IDS(e);
102     fprintf(f, "%*s", indent, "");
103     fprintf(f, "hash (id %d name %d).  Owner %di, creator %di\n",
104             host(e->nextID), host(e->nextName), host(e->owner),
105             host(e->creator));
106     fprintf(f, "%*s", indent, "");
107 #if defined(SUPERGROUPS)
108     fprintf(f, "quota groups %d, foreign users %d.  Mem: %d, cntsg: %d\n",
109             host(e->ngroups), host(e->nusers), host(e->count),
110             host(e->instance));
111 #else
112     fprintf(f, "quota groups %d, foreign users %d.  Mem: %d, inst: %d\n",
113             host(e->ngroups), host(e->nusers), host(e->count),
114             host(e->instance));
115 #endif
116     fprintf(f, "%*s", indent, "");
117 #if defined(SUPERGROUPS)
118     fprintf(f, "Owned chain %d, next owned %d, nextsg %d, sg (%d %d).\n",
119             host(e->owned), host(e->nextOwned), host(e->parent),
120             host(e->sibling), host(e->child));
121 #else
122     fprintf(f, "Owned chain %d, next owned %d, inst ptrs(%d %d %d).\n",
123             host(e->owned), host(e->nextOwned), host(e->parent),
124             host(e->sibling), host(e->child));
125 #endif
126     fprintf(f, "%*s", indent, "");
127     if (strlen(e->name) >= PR_MAXNAMELEN)
128         fprintf(f, "NAME TOO LONG: ");
129     fprintf(f, "Name is '%.*s'\n", PR_MAXNAMELEN, e->name);
130     return 0;
131 }
132
133 int
134 pr_PrintContEntry(FILE *f, int hostOrder, afs_int32 ea, struct contentry *c, int indent)
135 {
136     PRINT_COMMON_FIELDS(c);
137     /* Print the reserved fields for compatibility with older versions.
138      * They should always be zero, checked in PRINT_COMMON_FIELDS(). */
139     fprintf(f, "%*s", indent, "");
140     fprintf(f, "c:%s ", pr_TimeToString(host((c)->reserved[0])));
141     fprintf(f, "a:%s ", pr_TimeToString(host((c)->reserved[1])));
142     fprintf(f, "r:%s ", pr_TimeToString(host((c)->reserved[2])));
143     fprintf(f, "n:%s\n", pr_TimeToString(host((c)->reserved[3])));
144     PRINT_IDS(c);
145     return 0;
146 }