prototyping-20040623
[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(FILE *f, int hostOrder, int indent, struct prentry *e, int n)
66 {
67     int i;
68     int newline;
69
70     newline = 0;
71     for (i = 0; i < n; i++) {
72         if (e->entries[i] == 0)
73             break;
74
75         if (i == 0)
76             fprintf(f, "%*sids ", indent, "");
77         else if (newline == 0)
78             fprintf(f, "%*s", indent + 4, "");
79
80         if (host(e->entries[i]) == PRBADID)
81             fprintf(f, " EMPTY");
82         else
83             fprintf(f, "%6d", host(e->entries[i]));
84         newline = 1;
85         if (i % 10 == 9) {
86             fprintf(f, "\n");
87             newline = 0;
88         } else
89             fprintf(f, " ");
90     }
91     if (newline)
92         fprintf(f, "\n");
93 }
94
95 int
96 pr_PrintEntry(FILE *f, int hostOrder, afs_int32 ea, struct prentry *e, int indent)
97 {
98     int i;
99
100     if (e->cellid)
101         fprintf(f, "cellid == %d\n", host(e->cellid));
102     for (i = 0; i < sizeof(e->reserved) / sizeof(e->reserved[0]); i++)
103         if (e->reserved[i])
104             fprintf(f, "reserved field [%d] not zero: %d\n", i,
105                     host(e->reserved[i]));
106
107     fprintf(f, "%*s", indent, "");
108     fprintf(f, "Entry at %d: flags 0x%x, id %di, next %d.\n", ea,
109             host(e->flags), host(e->id), host(e->next));
110 #ifdef PR_REMEMBER_TIMES
111     fprintf(f, "%*s", indent, "");
112     fprintf(f, "c:%s ", pr_TimeToString(host(e->createTime)));
113     fprintf(f, "a:%s ", pr_TimeToString(host(e->addTime)));
114     fprintf(f, "r:%s ", pr_TimeToString(host(e->removeTime)));
115     fprintf(f, "n:%s\n", pr_TimeToString(host(e->changeTime)));
116 #endif
117     if (host(e->flags) & PRCONT)
118         PrintEntries(f, hostOrder, indent, e, COSIZE);
119     else {                      /* regular entry */
120         PrintEntries(f, hostOrder, indent, e, PRSIZE);
121         fprintf(f, "%*s", indent, "");
122         fprintf(f, "hash (id %d name %d).  Owner %di, creator %di\n",
123                 host(e->nextID), host(e->nextName), host(e->owner),
124                 host(e->creator));
125         fprintf(f, "%*s", indent, "");
126 #if defined(SUPERGROUPS)
127         fprintf(f, "quota groups %d, foreign users %d.  Mem: %d, cntsg: %d\n",
128                 host(e->ngroups), host(e->nusers), host(e->count),
129                 host(e->instance));
130 #else
131         fprintf(f, "quota groups %d, foreign users %d.  Mem: %d, inst: %d\n",
132                 host(e->ngroups), host(e->nusers), host(e->count),
133                 host(e->instance));
134 #endif
135         fprintf(f, "%*s", indent, "");
136 #if defined(SUPERGROUPS)
137         fprintf(f, "Owned chain %d, next owned %d, nextsg %d, sg (%d %d).\n",
138                 host(e->owned), host(e->nextOwned), host(e->parent),
139                 host(e->sibling), host(e->child));
140 #else
141         fprintf(f, "Owned chain %d, next owned %d, inst ptrs(%d %d %d).\n",
142                 host(e->owned), host(e->nextOwned), host(e->parent),
143                 host(e->sibling), host(e->child));
144 #endif
145         fprintf(f, "%*s", indent, "");
146         if (strlen(e->name) >= PR_MAXNAMELEN)
147             fprintf(f, "NAME TOO LONG: ");
148         fprintf(f, "Name is '%.*s'\n", PR_MAXNAMELEN, e->name);
149     }
150     return 0;
151 }