|
|
1.1 root 1: /* aetbuild.c - build/print the isoentities database for -ldbm access */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/support/RCS/aetbuild.c,v 7.0 89/11/23 22:27:06 mrose Rel $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/support/RCS/aetbuild.c,v 7.0 89/11/23 22:27:06 mrose Rel $
9: *
10: *
11: * $Log: aetbuild.c,v $
12: * Revision 7.0 89/11/23 22:27:06 mrose
13: * Release 6.0
14: *
15: */
16:
17: /*
18: * NOTICE
19: *
20: * Acquisition, use, and distribution of this module and related
21: * materials are subject to the restrictions of a license agreement.
22: * Consult the Preface in the User's Manual for the full terms of
23: * this agreement.
24: *
25: */
26:
27:
28: #include <dbm.h>
29: #undef NULL
30: #include <stdio.h>
31: #include <varargs.h>
32: #include "psap.h"
33: #include "isoaddrs.h"
34: #include "tailor.h"
35:
36: /* DATA */
37:
38: struct dbm_entry {
39: struct isoentity dbm_entity;
40:
41: unsigned int dbm_elements[NELEM + 1];
42: };
43:
44:
45: static char *isoentities = "isoentities";
46:
47:
48: static char *myname = "aetbuild";
49:
50: static int buildsw = 0;
51: static int printsw = 0;
52: static int verbose = 0;
53:
54: static char dirfile[BUFSIZ];
55: static char pagfile[BUFSIZ];
56:
57:
58: void adios (), advise ();
59:
60: /* MAIN */
61:
62: /* ARGSUSED */
63:
64: main (argc, argv, envp)
65: int argc;
66: char **argv,
67: **envp;
68: {
69: arginit (argv);
70:
71: if (buildsw)
72: build_db ();
73:
74: if (printsw)
75: print_db ();
76:
77: exit (0);
78: }
79:
80: /* BUILD */
81:
82: static build_db ()
83: {
84: int fd;
85: char *cp,
86: buffer[BUFSIZ];
87: register struct isoentity *ie;
88: struct dbm_entry entry;
89: datum key,
90: value,
91: test;
92:
93: cp = isodefile (myname, 0);
94:
95: (void) sprintf (dirfile, "%s.dir", cp);
96: (void) sprintf (pagfile, "%s.pag", cp);
97: if (access (dirfile, 0x00) != NOTOK || access (pagfile, 0x00) != NOTOK)
98: adios (NULLCP, "%s already exists!", cp);
99:
100: if ((fd = creat (dirfile, 0644)) == NOTOK)
101: adios (dirfile, "unable to create");
102: (void) close (fd);
103:
104: if ((fd = creat (pagfile, 0644)) == NOTOK) {
105: advise (pagfile, "unable to create");
106: goto out1;
107: }
108: (void) close (fd);
109:
110: if (dbminit (cp) < 0) {
111: advise (cp, "unable to initialize database");
112: goto out2;
113: }
114:
115: while (ie = getisoentity ()) {
116: entry.dbm_entity = *ie; /* struct copy */
117: bcopy ((char *) ie -> ie_identifier.oid_elements,
118: (char *) entry.dbm_elements, sizeof entry.dbm_elements);
119:
120: key.dsize = strlen (key.dptr = ie -> ie_descriptor) + 1;
121: test = fetch (key);
122: if (test.dptr) {
123: if (verbose)
124: advise (NULLCP, "skipping duplicate entry for \"%s\"",
125: key.dptr);
126:
127: continue;
128: }
129:
130: value.dptr = (char *) &entry, value.dsize = sizeof entry;
131: if (store (key, value) < 0)
132: adios (cp, "store failed on");
133:
134: if (verbose)
135: advise (NULLCP, "storing entry for \"%s\"", key.dptr);
136: }
137:
138: #ifdef sun
139: if (dbmclose () < 0) {
140: advise (cp, "dmbclose failed on");
141: goto out2;
142: }
143: #endif
144:
145: cp = isodefile (isoentities, 0);
146:
147: (void) sprintf (buffer, "%s.pag", cp);
148: if (rename (pagfile, buffer) == NOTOK) {
149: advise (buffer, "unable to rename %s to", pagfile);
150: goto out2;
151: }
152:
153: (void) sprintf (buffer, "%s.dir", cp);
154: if (rename (dirfile, buffer) == NOTOK)
155: adios (buffer, "unable to rename %s to", dirfile);
156:
157: return;
158:
159: out2: ;
160: (void) unlink (pagfile);
161:
162: out1: ;
163: (void) unlink (dirfile);
164:
165: exit (1);
166: }
167:
168: /* PRINT */
169:
170: static print_db ()
171: {
172: char *cp;
173: struct dbm_entry *entry;
174: register struct isoentity *ie;
175: AEI aei;
176: datum key,
177: value;
178:
179: if (dbminit (cp = isodefile (isoentities, 0)) < 0)
180: adios (cp, "unable to initialize");
181:
182: for (key = firstkey (); key.dptr; key = nextkey (key)) {
183: value = fetch (key);
184: if ((entry = (struct dbm_entry *) value.dptr) == NULL) {
185: advise (NULLCP, "unable to find value for key %s", key.dptr);
186: continue;
187: }
188:
189: if (value.dsize != sizeof *entry)
190: adios (NULLCP, "%s dbm corrupt!", cp);
191:
192: ie = &entry -> dbm_entity;
193: ie -> ie_identifier.oid_elements = entry -> dbm_elements;
194: ie -> ie_descriptor = key.dptr;
195:
196: printf ("Entity: %s (%s)\n", ie -> ie_descriptor,
197: oid2ode (&ie -> ie_identifier));
198:
199: if (aei = oid2aei (&ie -> ie_identifier))
200: printf ("AE info: %s\n", sprintaei (aei));
201: printf ("Address: %s\n\n", paddr2str (&ie -> ie_addr, NULLNA));
202: }
203:
204: #ifdef sun
205: if (dbmclose () < 0)
206: adios (cp, "dmbclose failed on");
207: #endif
208: }
209:
210: /* ARGINIT */
211:
212: static arginit (vec)
213: char **vec;
214: {
215: register char *ap;
216:
217: if (myname = rindex (*vec, '/'))
218: myname++;
219: if (myname == NULL || *myname == NULL)
220: myname = *vec;
221:
222: isodetailor (myname, 1);
223:
224: for (vec++; ap = *vec; vec++) {
225: if (*ap == '-')
226: switch (*++ap) {
227: case 'b':
228: buildsw++;
229: continue;
230:
231: case 'p':
232: printsw++;
233: continue;
234:
235: case 'v':
236: verbose++;
237: continue;
238:
239: default:
240: adios (NULLCP, "-%s: unknown switch", ap);
241: }
242:
243: adios (NULLCP, "usage: %s [switches]", myname);
244: }
245:
246: (void) umask (0022);
247:
248: if (buildsw == 0 && printsw == 0)
249: buildsw++;
250: }
251:
252: /* DSAP */
253:
254: /* ARGSUSED */
255:
256: AEI str2aei_dse (designator, qualifier)
257: char *designator,
258: *qualifier;
259: {
260: return NULLAEI;
261: }
262:
263:
264: /* ARGSUSED */
265:
266: struct PSAPaddr *aei2addr_dse (aei)
267: AEI aei;
268: {
269: return NULLPA;
270: }
271:
272: /* ERRORS */
273:
274: #ifndef lint
275: void _advise ();
276:
277:
278: void adios (va_alist)
279: va_dcl
280: {
281: va_list ap;
282:
283: va_start (ap);
284:
285: _advise (ap);
286:
287: va_end (ap);
288:
289: _exit (1);
290: }
291: #else
292: /* VARARGS */
293:
294: void adios (what, fmt)
295: char *what,
296: *fmt;
297: {
298: adios (what, fmt);
299: }
300: #endif
301:
302:
303: #ifndef lint
304: void advise (va_alist)
305: va_dcl
306: {
307: va_list ap;
308:
309: va_start (ap);
310:
311: _advise (ap);
312:
313: va_end (ap);
314: }
315:
316:
317: static void _advise (ap)
318: va_list ap;
319: {
320: char buffer[BUFSIZ];
321:
322: asprintf (buffer, ap);
323:
324: (void) fflush (stdout);
325:
326: fprintf (stderr, "%s: ", myname);
327: (void) fputs (buffer, stderr);
328: (void) fputc ('\n', stderr);
329:
330: (void) fflush (stderr);
331: }
332: #else
333: /* VARARGS */
334:
335: void advise (what, fmt)
336: char *what,
337: *fmt;
338: {
339: advise (what, fmt);
340: }
341: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.