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