1 | /* |
---|
2 | * Copyright (c) 1998 Sendmail, Inc. All rights reserved. |
---|
3 | * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. |
---|
4 | * Copyright (c) 1988, 1993 |
---|
5 | * The Regents of the University of California. All rights reserved. |
---|
6 | * |
---|
7 | * By using this file, you agree to the terms and conditions set |
---|
8 | * forth in the LICENSE file which can be found at the top level of |
---|
9 | * the sendmail distribution. |
---|
10 | * |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef lint |
---|
14 | static char sccsid[] = "@(#)stab.c 8.19 (Berkeley) 5/19/1998"; |
---|
15 | #endif /* not lint */ |
---|
16 | |
---|
17 | # include "sendmail.h" |
---|
18 | |
---|
19 | /* |
---|
20 | ** STAB -- manage the symbol table |
---|
21 | ** |
---|
22 | ** Parameters: |
---|
23 | ** name -- the name to be looked up or inserted. |
---|
24 | ** type -- the type of symbol. |
---|
25 | ** op -- what to do: |
---|
26 | ** ST_ENTER -- enter the name if not |
---|
27 | ** already present. |
---|
28 | ** ST_FIND -- find it only. |
---|
29 | ** |
---|
30 | ** Returns: |
---|
31 | ** pointer to a STAB entry for this name. |
---|
32 | ** NULL if not found and not entered. |
---|
33 | ** |
---|
34 | ** Side Effects: |
---|
35 | ** can update the symbol table. |
---|
36 | */ |
---|
37 | |
---|
38 | # define STABSIZE 2003 |
---|
39 | |
---|
40 | static STAB *SymTab[STABSIZE]; |
---|
41 | |
---|
42 | STAB * |
---|
43 | stab(name, type, op) |
---|
44 | char *name; |
---|
45 | int type; |
---|
46 | int op; |
---|
47 | { |
---|
48 | register STAB *s; |
---|
49 | register STAB **ps; |
---|
50 | register int hfunc; |
---|
51 | register char *p; |
---|
52 | int len; |
---|
53 | extern char lower __P((char)); |
---|
54 | |
---|
55 | if (tTd(36, 5)) |
---|
56 | printf("STAB: %s %d ", name, type); |
---|
57 | |
---|
58 | /* |
---|
59 | ** Compute the hashing function |
---|
60 | */ |
---|
61 | |
---|
62 | hfunc = type; |
---|
63 | for (p = name; *p != '\0'; p++) |
---|
64 | hfunc = ((hfunc << 1) ^ (lower(*p) & 0377)) % STABSIZE; |
---|
65 | |
---|
66 | if (tTd(36, 9)) |
---|
67 | printf("(hfunc=%d) ", hfunc); |
---|
68 | |
---|
69 | ps = &SymTab[hfunc]; |
---|
70 | if (type == ST_MACRO || type == ST_RULESET) |
---|
71 | { |
---|
72 | while ((s = *ps) != NULL && |
---|
73 | (s->s_type != type || strcmp(name, s->s_name))) |
---|
74 | ps = &s->s_next; |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | while ((s = *ps) != NULL && |
---|
79 | (s->s_type != type || strcasecmp(name, s->s_name))) |
---|
80 | ps = &s->s_next; |
---|
81 | } |
---|
82 | |
---|
83 | /* |
---|
84 | ** Dispose of the entry. |
---|
85 | */ |
---|
86 | |
---|
87 | if (s != NULL || op == ST_FIND) |
---|
88 | { |
---|
89 | if (tTd(36, 5)) |
---|
90 | { |
---|
91 | if (s == NULL) |
---|
92 | printf("not found\n"); |
---|
93 | else |
---|
94 | { |
---|
95 | long *lp = (long *) s->s_class; |
---|
96 | |
---|
97 | printf("type %d val %lx %lx %lx %lx\n", |
---|
98 | s->s_type, lp[0], lp[1], lp[2], lp[3]); |
---|
99 | } |
---|
100 | } |
---|
101 | return (s); |
---|
102 | } |
---|
103 | |
---|
104 | /* |
---|
105 | ** Make a new entry and link it in. |
---|
106 | */ |
---|
107 | |
---|
108 | if (tTd(36, 5)) |
---|
109 | printf("entered\n"); |
---|
110 | |
---|
111 | /* determine size of new entry */ |
---|
112 | #if _FFR_MEMORY_MISER |
---|
113 | switch (type) |
---|
114 | { |
---|
115 | case ST_CLASS: |
---|
116 | len = sizeof s->s_class; |
---|
117 | break; |
---|
118 | |
---|
119 | case ST_ADDRESS: |
---|
120 | len = sizeof s->s_address; |
---|
121 | break; |
---|
122 | |
---|
123 | case ST_MAILER: |
---|
124 | len = sizeof s->s_mailer; |
---|
125 | |
---|
126 | case ST_ALIAS: |
---|
127 | len = sizeof s->s_alias; |
---|
128 | break; |
---|
129 | |
---|
130 | case ST_MAPCLASS: |
---|
131 | len = sizeof s->s_mapclass; |
---|
132 | break; |
---|
133 | |
---|
134 | case ST_MAP: |
---|
135 | len = sizeof s->s_map; |
---|
136 | break; |
---|
137 | |
---|
138 | case ST_HOSTSIG: |
---|
139 | len = sizeof s->s_hostsig; |
---|
140 | break; |
---|
141 | |
---|
142 | case ST_NAMECANON: |
---|
143 | len = sizeof s->s_namecanon; |
---|
144 | break; |
---|
145 | |
---|
146 | case ST_MACRO: |
---|
147 | len = sizeof s->s_macro; |
---|
148 | break; |
---|
149 | |
---|
150 | case ST_RULESET: |
---|
151 | len = sizeof s->s_ruleset; |
---|
152 | break; |
---|
153 | |
---|
154 | case ST_SERVICE: |
---|
155 | len = sizeof s->s_service; |
---|
156 | break; |
---|
157 | |
---|
158 | case ST_HEADER: |
---|
159 | len = sizeof s->s_header; |
---|
160 | break; |
---|
161 | |
---|
162 | default: |
---|
163 | if (type >= ST_MCI) |
---|
164 | len = sizeof s->s_mci; |
---|
165 | else |
---|
166 | { |
---|
167 | syserr("stab: unknown symbol type %d", type); |
---|
168 | len = sizeof s->s_value; |
---|
169 | } |
---|
170 | break; |
---|
171 | } |
---|
172 | len += sizeof *s - sizeof s->s_value; |
---|
173 | #else |
---|
174 | len = sizeof *s; |
---|
175 | #endif |
---|
176 | |
---|
177 | /* make new entry */ |
---|
178 | s = (STAB *) xalloc(len); |
---|
179 | bzero((char *) s, len); |
---|
180 | s->s_name = newstr(name); |
---|
181 | s->s_type = type; |
---|
182 | s->s_len = len; |
---|
183 | |
---|
184 | /* link it in */ |
---|
185 | *ps = s; |
---|
186 | |
---|
187 | return (s); |
---|
188 | } |
---|
189 | /* |
---|
190 | ** STABAPPLY -- apply function to all stab entries |
---|
191 | ** |
---|
192 | ** Parameters: |
---|
193 | ** func -- the function to apply. It will be given one |
---|
194 | ** parameter (the stab entry). |
---|
195 | ** arg -- an arbitrary argument, passed to func. |
---|
196 | ** |
---|
197 | ** Returns: |
---|
198 | ** none. |
---|
199 | */ |
---|
200 | |
---|
201 | void |
---|
202 | stabapply(func, arg) |
---|
203 | void (*func)__P((STAB *, int)); |
---|
204 | int arg; |
---|
205 | { |
---|
206 | register STAB **shead; |
---|
207 | register STAB *s; |
---|
208 | |
---|
209 | for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++) |
---|
210 | { |
---|
211 | for (s = *shead; s != NULL; s = s->s_next) |
---|
212 | { |
---|
213 | if (tTd(36, 90)) |
---|
214 | printf("stabapply: trying %d/%s\n", |
---|
215 | s->s_type, s->s_name); |
---|
216 | func(s, arg); |
---|
217 | } |
---|
218 | } |
---|
219 | } |
---|