reindent-20030715
[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
13 RCSID
14     ("$Header$");
15
16 #include <afs/stds.h>
17 #include <sys/types.h>
18 #ifdef AFS_NT40_ENV
19 #include <winsock2.h>
20 #else
21 #include <netinet/in.h>
22 #endif
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #else
26 #ifdef HAVE_STRINGS_H
27 #include <strings.h>
28 #endif
29 #endif
30 #include <stdio.h>
31 #include "ptserver.h"
32
33
34 #ifdef PR_REMEMBER_TIMES
35
36 # include <time.h>
37
38
39 static char *
40 pr_TimeToString(time_t clock)
41 {
42     struct tm *tm;
43     static char buffer[32];
44     static int this_year = 0;
45
46     if (clock == 0)
47         return "time-not-set  ";
48     if (!this_year) {
49         time_t now = time(0);
50         tm = localtime(&now);
51         this_year = tm->tm_year;
52     }
53     tm = localtime(&clock);
54     if (tm->tm_year != this_year)
55         strftime(buffer, 32, "%m/%d/%Y %T", tm);
56     else
57         strftime(buffer, 32, "%m/%d %T", tm);
58     return buffer;
59 }
60 #endif
61
62 #define host(a) (hostOrder ? (a) : ntohl(a))
63
64 static void
65 PrintEntries(f, hostOrder, indent, e, n)
66      FILE *f;
67      int hostOrder;             /* structures in host order */
68      int indent;
69      struct prentry *e;
70      int n;
71 {
72     int i;
73     int newline;
74
75     newline = 0;
76     for (i = 0; i < n; i++) {
77         if (e->entries[i] == 0)
78             break;
79
80         if (i == 0)
81             fprintf(f, "%*sids ", indent, "");
82         else if (newline == 0)
83             fprintf(f, "%*s", indent + 4, "");
84
85         if (host(e->entries[i]) == PRBADID)
86             fprintf(f, " EMPTY");
87         else
88             fprintf(f, "%6d", host(e->entries[i]));
89         newline = 1;
90         if (i % 10 == 9) {
91             fprintf(f, "\n");
92             newline = 0;
93         } else
94             fprintf(f, " ");
95     }
96     if (newline)
97         fprintf(f, "\n");
98 }
99
100 int
101 pr_PrintEntry(f, hostOrder, ea, e, indent)
102      FILE *f;
103      int hostOrder;             /* structures in host order */
104      afs_int32 ea;
105      struct prentry *e;
106      int indent;
107 {
108     int i;
109
110     if (e->cellid)
111         fprintf(f, "cellid == %d\n", host(e->cellid));
112     for (i = 0; i < sizeof(e->reserved) / sizeof(e->reserved[0]); i++)
113         if (e->reserved[i])
114             fprintf(f, "reserved field [%d] not zero: %d\n", i,
115                     host(e->reserved[i]));
116
117     fprintf(f, "%*s", indent, "");
118     fprintf(f, "Entry at %d: flags 0x%x, id %di, next %d.\n", ea,
119             host(e->flags), host(e->id), host(e->next));
120 #ifdef PR_REMEMBER_TIMES
121     fprintf(f, "%*s", indent, "");
122     fprintf(f, "c:%s ", pr_TimeToString(host(e->createTime)));
123     fprintf(f, "a:%s ", pr_TimeToString(host(e->addTime)));
124     fprintf(f, "r:%s ", pr_TimeToString(host(e->removeTime)));
125     fprintf(f, "n:%s\n", pr_TimeToString(host(e->changeTime)));
126 #endif
127     if (host(e->flags) & PRCONT)
128         PrintEntries(f, hostOrder, indent, e, COSIZE);
129     else {                      /* regular entry */
130         PrintEntries(f, hostOrder, indent, e, PRSIZE);
131         fprintf(f, "%*s", indent, "");
132         fprintf(f, "hash (id %d name %d).  Owner %di, creator %di\n",
133                 host(e->nextID), host(e->nextName), host(e->owner),
134                 host(e->creator));
135         fprintf(f, "%*s", indent, "");
136 #if defined(SUPERGROUPS)
137         fprintf(f, "quota groups %d, foreign users %d.  Mem: %d, cntsg: %d\n",
138                 host(e->ngroups), host(e->nusers), host(e->count),
139                 host(e->instance));
140 #else
141         fprintf(f, "quota groups %d, foreign users %d.  Mem: %d, inst: %d\n",
142                 host(e->ngroups), host(e->nusers), host(e->count),
143                 host(e->instance));
144 #endif
145         fprintf(f, "%*s", indent, "");
146 #if defined(SUPERGROUPS)
147         fprintf(f, "Owned chain %d, next owned %d, nextsg %d, sg (%d %d).\n",
148                 host(e->owned), host(e->nextOwned), host(e->parent),
149                 host(e->sibling), host(e->child));
150 #else
151         fprintf(f, "Owned chain %d, next owned %d, inst ptrs(%d %d %d).\n",
152                 host(e->owned), host(e->nextOwned), host(e->parent),
153                 host(e->sibling), host(e->child));
154 #endif
155         fprintf(f, "%*s", indent, "");
156         if (strlen(e->name) >= PR_MAXNAMELEN)
157             fprintf(f, "NAME TOO LONG: ");
158         fprintf(f, "Name is '%.*s'\n", PR_MAXNAMELEN, e->name);
159     }
160     return 0;
161 }