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