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