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